[git] GnuPG - branch, master, updated. gnupg-2.1.5-22-g4698e5b

by Werner Koch cvs at cvs.gnupg.org
Mon Jun 22 21:03:52 CEST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  4698e5b203bd983503b5fd784fcd09dd3bc3a15e (commit)
       via  22147952b744958ec46d356e942540356ff7d93e (commit)
       via  d37f47081d41584efc0c397432811f9cfa5d5867 (commit)
      from  e0873a3372800d51c90ca656450f937dbae9c169 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4698e5b203bd983503b5fd784fcd09dd3bc3a15e
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Jun 22 21:01:10 2015 +0200

    gpg: Allow debug flag names for --debug.
    
    * g10/gpg.c (opts): Change arg for oDebug to a string.
    (debug_flags): New; factored out from set_debug.
    (set_debug): Remove "--debug-level help".  Use parse_debug_flag to
    print the used flags.
    (main): Use parse_debug_flag for oDebug.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/doc/gpg.texi b/doc/gpg.texi
index 83dbda7..6c5cc5d 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -2320,8 +2320,6 @@ a numeric value or by a keyword:
   All of the debug messages you can get. A value greater than 8 may be
   used instead of the keyword.  The creation of hash tracing files is
   only enabled if the keyword is used.
-  @item help
-  List all available debug flags (see @option{debug}) and stop.
 @end table
 
 How these messages are mapped to the actual debugging flags is not
@@ -2330,8 +2328,10 @@ however carefully selected to best aid in debugging.
 
 @item --debug @var{flags}
 @opindex debug
-Set debugging flags. All flags are or-ed and @var{flags} may
-be given in C syntax (e.g. 0x0042).
+Set debugging flags. All flags are or-ed and @var{flags} may be given
+in C syntax (e.g. 0x0042) or as a comma separated list of flag names.
+To get a list of all supported flags the single word "help" can be
+used.
 
 @item --debug-all
 @opindex debug-all
diff --git a/g10/gpg.c b/g10/gpg.c
index eebb668..f9d9be3 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -557,7 +557,7 @@ static ARGPARSE_OPTS opts[] = {
   ARGPARSE_s_s (oDisplayCharset, "charset", "@"),
   ARGPARSE_s_s (oOptions, "options", "@"),
 
-  ARGPARSE_p_u (oDebug, "debug", "@"),
+  ARGPARSE_s_s (oDebug, "debug", "@"),
   ARGPARSE_s_s (oDebugLevel, "debug-level", "@"),
   ARGPARSE_s_n (oDebugAll, "debug-all", "@"),
   ARGPARSE_s_n (oDebugIOLBF, "debug-iolbf", "@"),
@@ -820,6 +820,28 @@ static ARGPARSE_OPTS opts[] = {
 };
 
 
+/* The list of supported debug flags.  */
+static struct debug_flags_s debug_flags [] =
+  {
+    { DBG_PACKET_VALUE , "packet"  },
+    { DBG_MPI_VALUE    , "mpi"     },
+    { DBG_CRYPTO_VALUE , "crypto"  },
+    { DBG_FILTER_VALUE , "filter"  },
+    { DBG_IOBUF_VALUE  , "iobuf"   },
+    { DBG_MEMORY_VALUE , "memory"  },
+    { DBG_CACHE_VALUE  , "cache"   },
+    { DBG_MEMSTAT_VALUE, "memstat" },
+    { DBG_TRUST_VALUE  , "trust"   },
+    { DBG_HASHING_VALUE, "hashing" },
+    { DBG_CARD_IO_VALUE, "cardio"  },
+    { DBG_IPC_VALUE    , "ipc"     },
+    { DBG_CLOCK_VALUE  , "clock"   },
+    { DBG_LOOKUP_VALUE , "lookup"  },
+    { DBG_EXTPROG_VALUE, "extprog" },
+    { 0, NULL }
+  };
+
+
 #ifdef ENABLE_SELINUX_HACKS
 #define ALWAYS_ADD_KEYRINGS 1
 #else
@@ -1077,6 +1099,7 @@ set_opt_session_env (const char *name, const char *value)
                gpg_strerror (err));
 }
 
+
 /* Setup the debugging.  With a LEVEL of NULL only the active debug
    flags are propagated to the subsystems.  With LEVEL set, a specific
    set of debug flags is set; thus overriding all flags already
@@ -1084,24 +1107,6 @@ set_opt_session_env (const char *name, const char *value)
 static void
 set_debug (const char *level)
 {
-  static struct { unsigned short val; const char *name; } flags [] = {
-    { DBG_PACKET_VALUE , "packet" },
-    { DBG_MPI_VALUE    , "mpi" },
-    { DBG_CRYPTO_VALUE , "crypto" },
-    { DBG_FILTER_VALUE , "filter" },
-    { DBG_IOBUF_VALUE  , "iobuf" },
-    { DBG_MEMORY_VALUE , "memory" },
-    { DBG_CACHE_VALUE  , "cache" },
-    { DBG_MEMSTAT_VALUE, "memstat" },
-    { DBG_TRUST_VALUE  , "trust" },
-    { DBG_HASHING_VALUE, "hashing" },
-    { DBG_CARD_IO_VALUE, "cardio" },
-    { DBG_IPC_VALUE    , "ipc" },
-    { DBG_CLOCK_VALUE  , "clock" },
-    { DBG_LOOKUP_VALUE , "lookup"},
-    { DBG_EXTPROG_VALUE, "extprog" },
-    { 0, NULL }
-  };
   int numok = (level && digitp (level));
   int numlvl = numok? atoi (level) : 0;
   int i;
@@ -1127,26 +1132,10 @@ set_debug (const char *level)
       if (numok)
         opt.debug &= ~(DBG_HASHING_VALUE);
     }
-  else if (!strcmp (level, "help"))
-    {
-      es_printf ("Available debug flags:\n");
-      for (i=0; flags[i].name; i++)
-        es_printf (" %5hu %s\n", flags[i].val, flags[i].name);
-      g10_exit (0);
-    }
   else
     {
-      for (i=0; flags[i].name; i++)
-        if (!strcmp (level, flags[i].name))
-          {
-            opt.debug |= flags[i].val;
-            break;
-          }
-      if (!flags[i].name)
-        {
-          log_error (_("invalid debug-level '%s' given\n"), level);
-          g10_exit (2);
-        }
+      log_error (_("invalid debug-level '%s' given\n"), level);
+      g10_exit (2);
     }
 
   if (opt.debug & DBG_MEMORY_VALUE )
@@ -1162,13 +1151,7 @@ set_debug (const char *level)
   gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose);
 
   if (opt.debug)
-    {
-      log_info ("enabled debug flags:");
-      for (i=0; flags[i].name; i++)
-        if ((opt.debug & flags[i].val))
-          log_printf (" %s", flags[i].name);
-      log_printf ("\n");
-    }
+    parse_debug_flag (NULL, &opt.debug, debug_flags);
 }
 
 
@@ -2447,7 +2430,14 @@ main (int argc, char **argv)
 	    opt.list_options|=LIST_SHOW_KEYRING;
 	    break;
 
-	  case oDebug: opt.debug |= pargs.r.ret_ulong; break;
+	  case oDebug:
+            if (parse_debug_flag (pargs.r.ret_str, &opt.debug, debug_flags))
+              {
+                pargs.r_opt = ARGPARSE_INVALID_ARG;
+                pargs.err = ARGPARSE_PRINT_ERROR;
+              }
+            break;
+
 	  case oDebugAll: opt.debug = ~0; break;
           case oDebugLevel: debug_level = pargs.r.ret_str; break;
 

commit 22147952b744958ec46d356e942540356ff7d93e
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Jun 22 20:54:23 2015 +0200

    common: Add function parse_debug_flag
    
    * common/miscellaneous.c (parse_debug_flag): New.
    * common/util.h (struct debug_flags_s): New.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/miscellaneous.c b/common/miscellaneous.c
index 8e71071..e840895 100644
--- a/common/miscellaneous.c
+++ b/common/miscellaneous.c
@@ -29,6 +29,7 @@
 
 #include <config.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <errno.h>
 
 #include "util.h"
@@ -394,3 +395,83 @@ gnupg_compare_version (const char *a, const char *b)
               && a_micro == b_micro
               && strcmp (a_plvl, b_plvl) >= 0));
 }
+
+
+

+/* Parse an --debug style argument.  We allow the use of number values
+ * in the usual C notation or a string with comma separated keywords.
+ *
+ * Returns: 0 on success or -1 and ERRNO set on error.  On success the
+ *          supplied variable is updated by the parsed flags.
+ *
+ * If STRING is NULL the enabled debug flags are printed.
+ */
+int
+parse_debug_flag (const char *string, unsigned int *debugvar,
+                  const struct debug_flags_s *flags)
+
+{
+  unsigned long result = 0;
+  int i, j;
+
+  if (!string)
+    {
+      if (debugvar)
+        {
+          log_info ("enabled debug flags:");
+          for (i=0; flags[i].name; i++)
+            if ((*debugvar & flags[i].flag))
+              log_printf (" %s", flags[i].name);
+          log_printf ("\n");
+        }
+      return 0;
+    }
+
+  while (spacep (string))
+    string++;
+  if (*string == '-')
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  if (!strcmp (string, "?") || !strcmp (string, "help"))
+    {
+      log_info ("available debug flags:\n");
+      for (i=0; flags[i].name; i++)
+        log_info (" %5u %s\n", flags[i].flag, flags[i].name);
+      exit (0);
+    }
+  else if (digitp (string))
+    {
+      errno = 0;
+      result = strtoul (string, NULL, 0);
+      if (result == ULONG_MAX && errno == ERANGE)
+        return -1;
+    }
+  else
+    {
+      char **words;
+      words = strtokenize (string, ",");
+      if (!words)
+        return -1;
+      for (i=0; words[i]; i++)
+        {
+          if (*words[i])
+            {
+              for (j=0; flags[j].name; j++)
+                if (!strcmp (words[i], flags[j].name))
+                  {
+                    result |= flags[j].flag;
+                    break;
+                  }
+              if (!flags[j].name)
+                log_info (_("unknown debug flag '%s' ignored\n"), words[i]);
+            }
+        }
+      xfree (words);
+    }
+
+  *debugvar |= result;
+  return 0;
+}
diff --git a/common/util.h b/common/util.h
index 82e9887..d5ddc1f 100644
--- a/common/util.h
+++ b/common/util.h
@@ -389,6 +389,14 @@ int match_multistr (const char *multistr,const char *match);
 
 int gnupg_compare_version (const char *a, const char *b);
 
+struct debug_flags_s
+{
+  unsigned int flag;
+  const char *name;
+};
+int parse_debug_flag (const char *string, unsigned int *debugvar,
+                      const struct debug_flags_s *flags);
+
 
 /*-- Simple replacement functions. */
 

commit d37f47081d41584efc0c397432811f9cfa5d5867
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Jun 22 19:28:33 2015 +0200

    common: Add function strtokenize.
    
    * common/stringhelp.c: Include assert.h.
    (strtokenize): New.
    * common/t-stringhelp.c (test_strtokenize): New.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/stringhelp.c b/common/stringhelp.c
index ca8ae0b..6714eb8 100644
--- a/common/stringhelp.c
+++ b/common/stringhelp.c
@@ -48,6 +48,7 @@
 # endif
 # include <windows.h>
 #endif
+#include <assert.h>
 
 #include "util.h"
 #include "common-defs.h"
@@ -1234,3 +1235,69 @@ strsplit (char *string, char delim, char replacement, int *count)
 
   return result;
 }
+
+
+/* Tokenize STRING using the set of delimiters in DELIM.  Leading
+ * spaces and tabs are removed from all tokens.  The caller must xfree
+ * the result.
+ *
+ * Returns: A malloced and NULL delimited array with the tokens.  On
+ *          memory error NULL is returned and ERRNO is set.
+ */
+char **
+strtokenize (const char *string, const char *delim)
+{
+  const char *s;
+  size_t fields;
+  size_t bytes, n;
+  char *buffer;
+  char *p, *px, *pend;
+  char **result;
+
+  /* Count the number of fields.  */
+  for (fields = 1, s = strpbrk (string, delim); s; s = strpbrk (s + 1, delim))
+    fields++;
+  fields++; /* Add one for the terminating NULL.  */
+
+  /* Allocate an array for all fields, a terminating NULL, and space
+     for a copy of the string.  */
+  bytes = fields * sizeof *result;
+  if (bytes / sizeof *result != fields)
+    {
+      gpg_err_set_errno (ENOMEM);
+      return NULL;
+    }
+  n = strlen (string) + 1;
+  bytes += n;
+  if (bytes < n)
+    {
+      gpg_err_set_errno (ENOMEM);
+      return NULL;
+    }
+  result = xtrymalloc (bytes);
+  if (!result)
+    return NULL;
+  buffer = (char*)(result + fields);
+
+  /* Copy and parse the string.  */
+  strcpy (buffer, string);
+  for (n = 0, p = buffer; (pend = strpbrk (p, delim)); p = pend + 1)
+    {
+      *pend = 0;
+      while (spacep (p))
+        p++;
+      for (px = pend - 1; px >= p && spacep (px); px--)
+        *px = 0;
+      result[n++] = p;
+    }
+  while (spacep (p))
+    p++;
+  for (px = p + strlen (p) - 1; px >= p && spacep (px); px--)
+    *px = 0;
+  result[n++] = p;
+  result[n] = NULL;
+
+  assert ((char*)(result + n + 1) == buffer);
+
+  return result;
+}
diff --git a/common/stringhelp.h b/common/stringhelp.h
index b9b51fd..ab16d16 100644
--- a/common/stringhelp.h
+++ b/common/stringhelp.h
@@ -145,6 +145,10 @@ char *xstrconcat (const char *s1, ...) GNUPG_GCC_A_SENTINEL(0);
 
 char **strsplit (char *string, char delim, char replacement, int *count);
 
+/* Tokenize STRING using the set of delimiters in DELIM.  */
+char **strtokenize (const char *string, const char *delim);
+
+
 /*-- mapstrings.c --*/
 const char *map_static_macro_string (const char *string);
 
diff --git a/common/t-stringhelp.c b/common/t-stringhelp.c
index 6c47237..13f3afa 100644
--- a/common/t-stringhelp.c
+++ b/common/t-stringhelp.c
@@ -538,6 +538,146 @@ test_strsplit (void)
     }
 }
 
+
+
+static void
+test_strtokenize (void)
+{
+  struct {
+    const char *s;
+    const char *delim;
+    const char *fields_expected[10];
+  } tv[] = {
+    {
+      "", ":",
+      { "", NULL }
+    },
+    {
+      "a", ":",
+      { "a", NULL }
+    },
+    {
+      ":", ":",
+      { "", "", NULL }
+    },
+    {
+      "::", ":",
+      { "", "", "", NULL }
+    },
+    {
+      "a:b:c", ":",
+      { "a", "b", "c", NULL }
+    },
+    {
+      "a:b:", ":",
+      { "a", "b", "", NULL }
+    },
+    {
+      "a:b", ":",
+      { "a", "b", NULL }
+    },
+    {
+      "aa:b:cd", ":",
+      { "aa", "b", "cd", NULL }
+    },
+    {
+      "aa::b:cd", ":",
+      { "aa", "", "b", "cd", NULL }
+    },
+    {
+      "::b:cd", ":",
+      { "", "", "b", "cd", NULL }
+    },
+    {
+      "aa:   : b:cd ", ":",
+      { "aa", "", "b", "cd", NULL }
+    },
+    {
+      "  aa:   : b:  cd ", ":",
+      { "aa", "", "b", "cd", NULL }
+    },
+    {
+      "  ", ":",
+      { "", NULL }
+    },
+    {
+      "  :", ":",
+      { "", "", NULL }
+    },
+    {
+      "  : ", ":",
+      { "", "", NULL }
+    },
+    {
+      ": ", ":",
+      { "", "", NULL }
+    },
+    {
+      ": x ", ":",
+      { "", "x", NULL }
+    },
+    {
+      "a:bc:cde:fghi:jklmn::foo:", ":",
+      { "a", "bc", "cde", "fghi", "jklmn", "", "foo", "", NULL }
+    },
+    {
+      ",a,bc,,def,", ",",
+      { "", "a", "bc", "", "def", "", NULL }
+    },
+    {
+      " a ", " ",
+      { "", "a", "", NULL }
+    },
+    {
+      " ", " ",
+      { "", "", NULL }
+    },
+    {
+      "", " ",
+      { "", NULL }
+    }
+  };
+
+  int tidx;
+
+  for (tidx = 0; tidx < DIM(tv); tidx++)
+    {
+      char **fields;
+      int field_count;
+      int field_count_expected;
+      int i;
+
+      for (field_count_expected = 0;
+           tv[tidx].fields_expected[field_count_expected];
+           field_count_expected ++)
+        ;
+
+      fields = strtokenize (tv[tidx].s, tv[tidx].delim);
+      if (!fields)
+        fail (tidx * 1000);
+      else
+        {
+          for (field_count = 0; fields[field_count]; field_count++)
+            ;
+          if (field_count != field_count_expected)
+            fail (tidx * 1000);
+          else
+            {
+              for (i = 0; i < field_count_expected; i++)
+                if (strcmp (tv[tidx].fields_expected[i], fields[i]))
+                  {
+                    printf ("For field %d, expected '%s', but got '%s'\n",
+                            i, tv[tidx].fields_expected[i], fields[i]);
+                    fail (tidx * 1000 + i + 1);
+                  }
+            }
+          }
+
+      xfree (fields);
+    }
+}
+
+
 int
 main (int argc, char **argv)
 {
@@ -551,6 +691,7 @@ main (int argc, char **argv)
   test_make_filename_try ();
   test_make_absfilename_try ();
   test_strsplit ();
+  test_strtokenize ();
 
   xfree (home_buffer);
   return 0;

-----------------------------------------------------------------------

Summary of changes:
 common/miscellaneous.c |  81 ++++++++++++++++++++++++++++
 common/stringhelp.c    |  67 +++++++++++++++++++++++
 common/stringhelp.h    |   4 ++
 common/t-stringhelp.c  | 141 +++++++++++++++++++++++++++++++++++++++++++++++++
 common/util.h          |   8 +++
 doc/gpg.texi           |   8 +--
 g10/gpg.c              |  80 ++++++++++++----------------
 7 files changed, 340 insertions(+), 49 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list