Further simplyify log level values
authorAndre Heinecke <aheinecke@intevation.de>
Tue, 25 Sep 2018 12:07:01 +0000 (14:07 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Tue, 25 Sep 2018 12:07:01 +0000 (14:07 +0200)
--
As we only have 4 levels now remove the others and
only keep their values around for compatibility.

src/debug.h
src/eventsink.h
src/keycache.cpp
src/main.c
src/mimedataprovider.cpp
src/oomhelp.cpp
src/xmalloc.h

index 62ce37b..7b089ce 100644 (file)
@@ -49,18 +49,11 @@ extern "C" {
    544 -> OOM and Memory.
    800 -> Full debugging.
    */
-#define DBG_MEMORY         (1<<5) // 32
-#define DBG_MIME_PARSER    (1<<7) // 128 Unified as DBG_DATA
-#define DBG_MIME_DATA      (1<<8) // 256 Unified as DBG_DATA
-#define DBG_DATA           (DBG_MIME_PARSER | DBG_MIME_DATA)
-#define DBG_OOM_VAL        (1<<9) // 512 Unified as DBG_OOM
-#define DBG_OOM_EXTRA      (1<<10)// 1024 Unified as DBG_OOM
-#define DBG_TRACE          (1<<11)// 2048 Very verbose tracing.
-#define DBG_OOM            (DBG_OOM_VAL | DBG_OOM_EXTRA)
-
-#define debug_oom        ((opt.enable_debug & DBG_OOM) || \
-                          (opt.enable_debug & DBG_OOM_EXTRA))
-#define debug_oom_extra  (opt.enable_debug & DBG_OOM_EXTRA)
+#define DBG_OOM            (1<<1) // 2
+#define DBG_MEMORY         (1<<2) // 4
+#define DBG_TRACE          (1<<3) // 8
+#define DBG_DATA           (1<<4) // 16
+
 void log_debug (const char *fmt, ...) __attribute__ ((format (printf,1,2)));
 void log_error (const char *fmt, ...) __attribute__ ((format (printf,1,2)));
 void log_vdebug (const char *fmt, va_list a);
index 12b1b35..c5a58da 100644 (file)
@@ -45,7 +45,7 @@ class subcls : public parentcls                                          \
   inline STDMETHODIMP_(ULONG) AddRef (void)                              \
     {                                                                    \
       ++m_ref;                                                           \
-      if (debug_oom_extra)                                               \
+      if ((opt.enable_debug & DBG_OOM))                                               \
         log_debug ("%s:" #subcls ":%s: m_ref now %lu",                   \
                    SRCNAME,__func__, m_ref);                             \
       return m_ref;                                                      \
@@ -53,7 +53,7 @@ class subcls : public parentcls                                          \
   inline STDMETHODIMP_(ULONG) Release (void)                             \
     {                                                                    \
       ULONG count = --m_ref;                                             \
-      if (debug_oom_extra)                                               \
+      if ((opt.enable_debug & DBG_OOM))                                               \
         log_debug ("%s:" #subcls ":%s: mref now %lu",                    \
                    SRCNAME,__func__,count);                              \
       if (!count)                                                        \
@@ -92,7 +92,7 @@ STDMETHODIMP subcls::Invoke (DISPID dispid, REFIID riid, LCID lcid,      \
 
 #define EVENT_SINK_DEFAULT_DTOR_CODE(subcls)                             \
 {                                                                        \
-  if (debug_oom)                                                         \
+  if ((opt.enable_debug & DBG_OOM))                                                         \
     log_debug ("%s:" #subcls ":%s: dtor", SRCNAME, __func__);            \
   if (m_pCP)                                                             \
     m_pCP->Unadvise(m_cookie);                                           \
@@ -196,7 +196,7 @@ LPDISPATCH install_ ## subcls ## _sink (LPDISPATCH object)               \
       gpgol_release (sink);                                                  \
       return NULL;                                                       \
     }                                                                    \
-  if (debug_oom)                                                         \
+  if ((opt.enable_debug & DBG_OOM))                                                         \
     log_debug ("%s:%s:%s: Advice succeeded", SRCNAME, #subcls, __func__);\
   sink->m_cookie = cookie;                                               \
   sink->m_pCP = pCP;                                                     \
@@ -210,7 +210,7 @@ void detach_ ## subcls ## _sink (LPDISPATCH obj)                         \
   HRESULT hr;                                                            \
   subcls *sink;                                                          \
                                                                          \
-  if (debug_oom_extra)                                                   \
+  if ((opt.enable_debug & DBG_OOM))                                                   \
     log_debug ("%s:%s:%s: Called", SRCNAME, #subcls, __func__);          \
   hr = gpgol_queryInterface (obj, iidcls, (void**)&sink);                \
   if (hr != S_OK || !sink)                                               \
@@ -221,13 +221,13 @@ void detach_ ## subcls ## _sink (LPDISPATCH obj)                         \
     }                                                                    \
   if (sink->m_pCP)                                                       \
     {                                                                    \
-      if (debug_oom_extra)                                               \
+      if ((opt.enable_debug & DBG_OOM))                                               \
         log_debug ("%s:%s:%s: Unadvising", SRCNAME, #subcls, __func__);  \
       hr = sink->m_pCP->Unadvise (sink->m_cookie);                       \
       if (hr != S_OK)                                                    \
         log_error ("%s:%s:%s: Unadvice failed: hr=%#lx",                 \
                    SRCNAME, #subcls, __func__, hr);                      \
-      if (debug_oom_extra)                                               \
+      if ((opt.enable_debug & DBG_OOM))                                               \
         log_debug ("%s:%s:%s: Releasing connt point",                    \
                    SRCNAME, #subcls, __func__);                          \
       gpgol_release (sink->m_pCP);                                           \
@@ -235,7 +235,7 @@ void detach_ ## subcls ## _sink (LPDISPATCH obj)                         \
     }                                                                    \
   if (sink->m_object)                                                    \
     {                                                                    \
-      if (debug_oom_extra)                                               \
+      if ((opt.enable_debug & DBG_OOM))                                               \
         log_debug ("%s:%s:%s: Releasing actual object",                  \
                    SRCNAME, #subcls, __func__);                          \
       gpgol_release (sink->m_object);                                        \
index ca2a8a5..b62884b 100644 (file)
@@ -926,7 +926,7 @@ locate_secret (const char *addr, GpgME::Protocol proto)
       if (key.isRevoked() || key.isExpired() ||
           key.isDisabled() || key.isInvalid())
         {
-          if ((opt.enable_debug & DBG_MIME_PARSER))
+          if ((opt.enable_debug & DBG_DATA))
             {
               std::stringstream ss;
               ss << key;
index 987b5fd..30f22f7 100644 (file)
@@ -195,6 +195,57 @@ get_conf_bool (const char *name, int defaultVal)
   return ret;
 }
 
+static int
+dbg_compat (int oldval)
+{
+  // We broke the debug levels at some point
+  // This is cmpatibility code with the old
+  // levels.
+
+#define DBG_MEMORY_OLD     (1<<5) // 32
+#define DBG_MIME_PARSER_OLD (1<<7) // 128 Unified as DBG_DATA
+#define DBG_MIME_DATA_OLD   (1<<8) // 256 Unified in read_options
+#define DBG_OOM_OLD        (1<<9) // 512 Unified as DBG_OOM
+#define DBG_OOM_EXTRA_OLD  (1<<10)// 1024 Unified in read_options
+  int new_dbg = oldval;
+  if ((oldval & DBG_MEMORY_OLD))
+    {
+      new_dbg |= DBG_MEMORY;
+      new_dbg -= DBG_MEMORY_OLD;
+    }
+  if ((oldval & DBG_OOM_OLD))
+    {
+      new_dbg |= DBG_OOM;
+      new_dbg -= DBG_OOM_OLD;
+    }
+  if ((oldval & DBG_MIME_PARSER_OLD))
+    {
+      new_dbg |= DBG_DATA;
+      new_dbg -= DBG_MIME_PARSER_OLD;
+    }
+  if ((oldval & DBG_MIME_DATA_OLD))
+    {
+      new_dbg |= DBG_DATA;
+      new_dbg -= DBG_MIME_DATA_OLD;
+    }
+  if ((oldval & DBG_OOM_OLD))
+    {
+      new_dbg |= DBG_OOM;
+      new_dbg -= DBG_OOM_OLD;
+    }
+  if ((oldval & DBG_OOM_EXTRA_OLD))
+    {
+      new_dbg |= DBG_OOM;
+      new_dbg -= DBG_OOM_EXTRA_OLD;
+    }
+#undef DBG_MEMORY_OLD
+#undef DBG_MIME_PARSER_OLD
+#undef DBG_MIME_DATA_OLD
+#undef DBG_OOM_OLD
+#undef DBG_OOM_EXTRA_OLD
+  return new_dbg;
+}
+
 /* Read option settings from the Registry. */
 void
 read_options (void)
@@ -224,17 +275,20 @@ read_options (void)
               pend += strspn (pend, ", \t\n\r\f");
             }
           if (isascii (*p) && isdigit (*p))
-            opt.enable_debug |= strtoul (p, NULL, 0);
+            {
+              opt.enable_debug |= dbg_compat (strtoul (p, NULL, 0));
+
+            }
           else if (!strcmp (p, "memory"))
             opt.enable_debug |= DBG_MEMORY;
           else if (!strcmp (p, "mime-parser"))
-            opt.enable_debug |= DBG_MIME_PARSER;
+            opt.enable_debug |= DBG_DATA;
           else if (!strcmp (p, "mime-data"))
-            opt.enable_debug |= DBG_MIME_DATA;
+            opt.enable_debug |= DBG_DATA;
           else if (!strcmp (p, "oom"))
-            opt.enable_debug |= DBG_OOM_VAL;
+            opt.enable_debug |= DBG_OOM;
           else if (!strcmp (p, "oom-extra"))
-            opt.enable_debug |= DBG_OOM_EXTRA;
+            opt.enable_debug |= DBG_OOM;
           else
             log_debug ("invalid debug flag `%s' ignored", p);
         }
index cf66ddf..ad09c62 100644 (file)
@@ -578,7 +578,7 @@ MimeDataProvider::read(void *buffer, size_t size)
   log_data ("%s:%s: Reading: " SIZE_T_FORMAT "Bytes",
                  SRCNAME, __func__, size);
   ssize_t bRead = m_crypto_data.read (buffer, size);
-  if (opt.enable_debug & DBG_MIME_DATA && bRead)
+  if ((opt.enable_debug & DBG_DATA) && bRead)
     {
       std::string buf ((char *)buffer, bRead);
 
index 383960c..2b84b0e 100644 (file)
@@ -38,7 +38,7 @@ HRESULT
 gpgol_queryInterface (LPUNKNOWN pObj, REFIID riid, LPVOID FAR *ppvObj)
 {
   HRESULT ret = pObj->QueryInterface (riid, ppvObj);
-  if ((opt.enable_debug & DBG_OOM_EXTRA) && *ppvObj)
+  if ((opt.enable_debug & DBG_MEMORY) && *ppvObj)
     {
       memdbg_addRef (*ppvObj);
     }
index 5385419..e302a85 100644 (file)
@@ -30,7 +30,7 @@ extern "C" {
 /*-- common.c --*/
 #define xmalloc(VAR1) ({void *retval; \
   retval = _xmalloc(VAR1); \
-  if ((opt.enable_debug & DBG_OOM_EXTRA)) \
+  if ((opt.enable_debug & DBG_MEMORY)) \
   { \
     memdbg_alloc (retval); \
   } \
@@ -38,7 +38,7 @@ retval;})
 
 #define xcalloc(VAR1, VAR2) ({void *retval; \
   retval = _xcalloc(VAR1, VAR2); \
-  if ((opt.enable_debug & DBG_OOM_EXTRA)) \
+  if ((opt.enable_debug & DBG_MEMORY)) \
   { \
     memdbg_alloc (retval);\
   } \
@@ -46,7 +46,7 @@ retval;})
 
 #define xrealloc(VAR1, VAR2) ({void *retval; \
   retval = _xrealloc (VAR1, VAR2); \
-  if ((opt.enable_debug & DBG_OOM_EXTRA)) \
+  if ((opt.enable_debug & DBG_MEMORY)) \
   { \
     memdbg_alloc (retval);\
     memdbg_free ((void*)VAR1); \
@@ -55,7 +55,7 @@ retval;})
 
 #define xfree(VAR1) \
 { \
-  if (VAR1 && (opt.enable_debug & DBG_OOM_EXTRA) && !memdbg_free (VAR1)) \
+  if (VAR1 && (opt.enable_debug & DBG_MEMORY) && !memdbg_free (VAR1)) \
     log_debug ("%s:%s:%i %p freed here", \
                log_srcname (__FILE__), __func__, __LINE__, VAR1); \
   _xfree (VAR1); \
@@ -63,7 +63,7 @@ retval;})
 
 #define xstrdup(VAR1) ({char *retval; \
   retval = _xstrdup (VAR1); \
-  if ((opt.enable_debug & DBG_OOM_EXTRA)) \
+  if ((opt.enable_debug & DBG_MEMORY)) \
   { \
     memdbg_alloc ((void *)retval);\
   } \
@@ -71,7 +71,7 @@ retval;})
 
 #define xwcsdup(VAR1) ({wchar_t *retval; \
   retval = _xwcsdup (VAR1); \
-  if ((opt.enable_debug & DBG_OOM_EXTRA)) \
+  if ((opt.enable_debug & DBG_MEMORY)) \
   { \
     memdbg_alloc ((void *)retval);\
   } \