[git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.19-50-g8ea49cf

by Werner Koch cvs at cvs.gnupg.org
Tue Dec 18 18:44:13 CET 2012


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, STABLE-BRANCH-2-0 has been updated
       via  8ea49cf513e1fb47913473ec8bf22ff832878506 (commit)
      from  732f3d1d4786239db5f31f82cc04ec79326cc13c (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 8ea49cf513e1fb47913473ec8bf22ff832878506
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Dec 18 18:06:41 2012 +0100

    jnlib: Add meta option ignore-invalid-option.
    
    * jnlib/argparse.c (iio_item_def_s, IIO_ITEM_DEF): New.
    (initialize): Init field IIO_LIST.
    (ignore_invalid_option_p): New.
    (ignore_invalid_option_add): New.
    (ignore_invalid_option_clear): New.
    (optfile_parse): Implement meta option.
    --
    
    This option is currently of no use.  However, as soon as it has been
    deployed in all stable versions of GnuPG, it will allow the use of the
    same configuration file with an old and a new version of GnuPG.  For
    example: If a new version implements the option "foobar", and a user
    uses it in gpg.conf, an old version of gpg would bail out with the
    error "invalid option".  To avoid that the following line can be put
    above that option in gpg.conf
    
      ignore-invalid-option foobar
    
    This meta option may be given several times or several option names
    may be given as arguments (space delimited).  Note that this option is
    not available on the command line.
    
    (cherry-picked from commit 41d564333d35c923f473aa90625d91f8fe18cd0b)

diff --git a/jnlib/argparse.c b/jnlib/argparse.c
index c9b5384..dab4bba 100644
--- a/jnlib/argparse.c
+++ b/jnlib/argparse.c
@@ -1,6 +1,6 @@
 /* [argparse.c wk 17.06.97] Argument Parser for option handling
  * Copyright (C) 1998, 1999, 2000, 2001, 2006
- *               2007, 2008  Free Software Foundation, Inc.
+ *               2007, 2008, 2012  Free Software Foundation, Inc.
  *
  * This file is part of JNLIB.
  *
@@ -143,6 +143,16 @@ struct alias_def_s {
     const char *value; /* ptr into name */
 };
 
+
+/* Object to store the names for the --ignore-invalid-option option.
+   This is a simple linked list.  */
+typedef struct iio_item_def_s *IIO_ITEM_DEF;
+struct iio_item_def_s
+{
+  IIO_ITEM_DEF next;
+  char name[1];      /* String with the long option name.  */
+};
+
 static const char *(*strusage_handler)( int ) = NULL;
 
 static int  set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s);
@@ -162,6 +172,7 @@ initialize( ARGPARSE_ARGS *arg, const char *filename, unsigned *lineno )
       arg->internal.stopped = 0;
       arg->internal.aliases = NULL;
       arg->internal.cur_alias = NULL;
+      arg->internal.iio_list = NULL;
       arg->err = 0;
       arg->flags |= 1<<15; /* Mark as initialized.  */
       if ( *arg->argc < 0 )
@@ -244,6 +255,111 @@ store_alias( ARGPARSE_ARGS *arg, char *name, char *value )
 #endif
 }
 
+
+/* Return true if KEYWORD is in the ignore-invalid-option list.  */
+static int
+ignore_invalid_option_p (ARGPARSE_ARGS *arg, const char *keyword)
+{
+  IIO_ITEM_DEF item = arg->internal.iio_list;
+
+  for (; item; item = item->next)
+    if (!strcmp (item->name, keyword))
+      return 1;
+  return 0;
+}
+
+
+/* Add the keywords up to the next LF to the list of to be ignored
+   options.  After returning FP will either be at EOF or the next
+   character read wll be the first of a new line.  The function
+   returns 0 on success or true on malloc failure.  */
+static int
+ignore_invalid_option_add (ARGPARSE_ARGS *arg, FILE *fp)
+{
+  IIO_ITEM_DEF item;
+  int c;
+  char name[100];
+  int namelen = 0;
+  int ready = 0;
+  enum { skipWS, collectNAME, skipNAME, addNAME} state = skipWS;
+
+  while (!ready)
+    {
+      c = getc (fp);
+      if (c == '\n')
+        ready = 1;
+      else if (c == EOF)
+        {
+          c = '\n';
+          ready = 1;
+        }
+    again:
+      switch (state)
+        {
+        case skipWS:
+          if (!isascii (c) || !isspace(c))
+            {
+              namelen = 0;
+              state = collectNAME;
+              goto again;
+            }
+          break;
+
+        case collectNAME:
+          if (isspace (c))
+            {
+              state = addNAME;
+              goto again;
+            }
+          else if (namelen < DIM(name)-1)
+            name[namelen++] = c;
+          else /* Too long.  */
+            state = skipNAME;
+          break;
+
+        case skipNAME:
+          if (isspace (c))
+            {
+              state = skipWS;
+              goto again;
+            }
+          break;
+
+        case addNAME:
+          name[namelen] = 0;
+          if (!ignore_invalid_option_p (arg, name))
+            {
+              item = jnlib_malloc (sizeof *item + namelen);
+              if (!item)
+                return 1;
+              strcpy (item->name, name);
+              item->next = (IIO_ITEM_DEF)arg->internal.iio_list;
+              arg->internal.iio_list = item;
+            }
+          state = skipWS;
+          goto again;
+        }
+    }
+  return 0;
+}
+
+
+/* Clear the entire ignore-invalid-option list.  */
+static void
+ignore_invalid_option_clear (ARGPARSE_ARGS *arg)
+{
+  IIO_ITEM_DEF item, tmpitem;
+
+  for (item = arg->internal.iio_list; item; item = tmpitem)
+    {
+      tmpitem = item->next;
+      jnlib_free (item);
+    }
+  arg->internal.iio_list = NULL;
+}
+
+
+
 /****************
  * Get options from a file.
  * Lines starting with '#' are comment lines.
@@ -253,6 +369,10 @@ store_alias( ARGPARSE_ARGS *arg, char *name, char *value )
  * are not valid here.
  * The special keyword "alias" may be used to store alias definitions,
  * which are later expanded like long options.
+ * The option
+ *   ignore-invalid-option OPTIONNAMEs
+ * is recognized and updates a list of option which should be ignored if they
+ * are not defined.
  * Caller must free returned strings.
  * If called with FP set to NULL command line args are parse instead.
  *
@@ -299,9 +419,23 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
               idx = i;
               arg->r_opt = opts[idx].short_opt;
               if (!opts[idx].short_opt )
-                arg->r_opt = ((opts[idx].flags & ARGPARSE_OPT_COMMAND)
-                              ? ARGPARSE_INVALID_COMMAND
-                              : ARGPARSE_INVALID_OPTION);
+                {
+                  if (!strcmp (keyword, "ignore-invalid-option"))
+                    {
+                      /* No argument - ignore this meta option.  */
+                      state = i = 0;
+                      continue;
+                    }
+                  else if (ignore_invalid_option_p (arg, keyword))
+                    {
+                      /* This invalid option is in the iio list.  */
+                      state = i = 0;
+                      continue;
+                    }
+                  arg->r_opt = ((opts[idx].flags & ARGPARSE_OPT_COMMAND)
+                                ? ARGPARSE_INVALID_COMMAND
+                                : ARGPARSE_INVALID_OPTION);
+                }
               else if (!(opts[idx].flags & 7))
                 arg->r_type = 0; /* Does not take an arg. */
               else if ((opts[idx].flags & 8) )
@@ -389,6 +523,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
             }
           else if (c == EOF)
             {
+              ignore_invalid_option_clear (arg);
               if (ferror (fp))
                 arg->r_opt = ARGPARSE_READ_ERROR;
               else
@@ -422,6 +557,18 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
                   in_alias = 1;
                   state = 3;
                 }
+              else if (!strcmp (keyword, "ignore-invalid-option"))
+                {
+                  if (ignore_invalid_option_add (arg, fp))
+                    {
+                      arg->r_opt = ARGPARSE_OUT_OF_CORE;
+                      break;
+                    }
+                  state = i = 0;
+                  ++*lineno;
+                }
+              else if (ignore_invalid_option_p (arg, keyword))
+                state = 1; /* Process like a comment.  */
               else
                 {
                   arg->r_opt = ((opts[idx].flags & ARGPARSE_OPT_COMMAND)
@@ -551,7 +698,7 @@ find_long_option( ARGPARSE_ARGS *arg,
 	    return i;
 	}
     }
-    return -1;
+    return -1;  /* Not found.  */
 }
 
 int
diff --git a/jnlib/argparse.h b/jnlib/argparse.h
index b211e5f..a4203b5 100644
--- a/jnlib/argparse.h
+++ b/jnlib/argparse.h
@@ -49,6 +49,7 @@ typedef struct
     const char *last;
     void *aliases;
     const void *cur_alias;
+    void *iio_list;
   } internal;	    /* Private - do not change. */
 } ARGPARSE_ARGS;
 

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

Summary of changes:
 jnlib/argparse.c |  157 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 jnlib/argparse.h |    1 +
 2 files changed, 153 insertions(+), 5 deletions(-)


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




More information about the Gnupg-commits mailing list