* keyserver.c (argsep): Move to misc.c.
authorDavid Shaw <dshaw@jabberwocky.com>
Sat, 14 Feb 2004 05:03:45 +0000 (05:03 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Sat, 14 Feb 2004 05:03:45 +0000 (05:03 +0000)
* main.h, misc.c (parse_options), export.c (parse_export_options),
import.c (parse_import_options), g10.c (main): Use it here to allow for
options with optional arguments.  Change all callers.

g10/ChangeLog
g10/export.c
g10/g10.c
g10/import.c
g10/keyserver.c
g10/main.h
g10/misc.c

index d0051dd..b60a6c6 100644 (file)
@@ -1,5 +1,11 @@
 2004-02-13  David Shaw  <dshaw@jabberwocky.com>
 
+       * keyserver.c (argsep): Move to misc.c.
+
+       * main.h, misc.c (parse_options), export.c (parse_export_options),
+       import.c (parse_import_options), g10.c (main): Use it here to
+       allow for options with optional arguments.  Change all callers.
+
        * import.c (check_prefs): Some language fixes.
        (sec_to_pub_keyblock, import_secret_one): Without knowing the
        number of MPIs there are, we cannot try and sk-to-pk-ize a key.
index c8a2be8..069c8e1 100644 (file)
@@ -45,11 +45,11 @@ parse_export_options(char *str,unsigned int *options,int noisy)
 {
   struct parse_options export_opts[]=
     {
-      {"include-non-rfc",EXPORT_INCLUDE_NON_RFC},
-      {"include-local-sigs",EXPORT_INCLUDE_LOCAL_SIGS},
-      {"include-attributes",EXPORT_INCLUDE_ATTRIBUTES},
-      {"include-sensitive-revkeys",EXPORT_INCLUDE_SENSITIVE_REVKEYS},
-      {NULL,0}
+      {"include-non-rfc",EXPORT_INCLUDE_NON_RFC,NULL},
+      {"include-local-sigs",EXPORT_INCLUDE_LOCAL_SIGS,NULL},
+      {"include-attributes",EXPORT_INCLUDE_ATTRIBUTES,NULL},
+      {"include-sensitive-revkeys",EXPORT_INCLUDE_SENSITIVE_REVKEYS,NULL},
+      {NULL,0,NULL}
       /* add tags for include revoked and disabled? */
     };
 
index 0749ff6..916934c 100644 (file)
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -2096,17 +2096,17 @@ main( int argc, char **argv )
            {
              struct parse_options lopts[]=
                {
-                 {"show-photos",LIST_SHOW_PHOTOS},
-                 {"show-policy-urls",LIST_SHOW_POLICY_URLS},
-                 {"show-notations",LIST_SHOW_NOTATIONS},
-                 {"show-keyserver-urls",LIST_SHOW_KEYSERVER_URLS},
-                 {"show-validity",LIST_SHOW_VALIDITY},
-                 {"show-long-keyids",LIST_SHOW_LONG_KEYIDS},
-                 {"show-unusable-uids",LIST_SHOW_UNUSABLE_UIDS},
-                 {"show-unusable-subkeys",LIST_SHOW_UNUSABLE_SUBKEYS},
-                 {"show-keyring",LIST_SHOW_KEYRING},
-                 {"show-sig-expire",LIST_SHOW_SIG_EXPIRE},
-                 {NULL,0}
+                 {"show-photos",LIST_SHOW_PHOTOS,NULL},
+                 {"show-policy-urls",LIST_SHOW_POLICY_URLS,NULL},
+                 {"show-notations",LIST_SHOW_NOTATIONS,NULL},
+                 {"show-keyserver-urls",LIST_SHOW_KEYSERVER_URLS,NULL},
+                 {"show-validity",LIST_SHOW_VALIDITY,NULL},
+                 {"show-long-keyids",LIST_SHOW_LONG_KEYIDS,NULL},
+                 {"show-unusable-uids",LIST_SHOW_UNUSABLE_UIDS,NULL},
+                 {"show-unusable-subkeys",LIST_SHOW_UNUSABLE_SUBKEYS,NULL},
+                 {"show-keyring",LIST_SHOW_KEYRING,NULL},
+                 {"show-sig-expire",LIST_SHOW_SIG_EXPIRE,NULL},
+                 {NULL,0,NULL}
                };
 
              if(!parse_options(pargs.r.ret_str,&opt.list_options,lopts,1))
@@ -2123,14 +2123,14 @@ main( int argc, char **argv )
            {
              struct parse_options vopts[]=
                {
-                 {"show-photos",VERIFY_SHOW_PHOTOS},
-                 {"show-policy-urls",VERIFY_SHOW_POLICY_URLS},
-                 {"show-notations",VERIFY_SHOW_NOTATIONS},
-                 {"show-keyserver-urls",VERIFY_SHOW_KEYSERVER_URLS},
-                 {"show-validity",VERIFY_SHOW_VALIDITY},
-                 {"show-long-keyids",VERIFY_SHOW_LONG_KEYIDS},
-                 {"show-unusable-uids",VERIFY_SHOW_UNUSABLE_UIDS},
-                 {NULL,0}
+                 {"show-photos",VERIFY_SHOW_PHOTOS,NULL},
+                 {"show-policy-urls",VERIFY_SHOW_POLICY_URLS,NULL},
+                 {"show-notations",VERIFY_SHOW_NOTATIONS,NULL},
+                 {"show-keyserver-urls",VERIFY_SHOW_KEYSERVER_URLS,NULL},
+                 {"show-validity",VERIFY_SHOW_VALIDITY,NULL},
+                 {"show-long-keyids",VERIFY_SHOW_LONG_KEYIDS,NULL},
+                 {"show-unusable-uids",VERIFY_SHOW_UNUSABLE_UIDS,NULL},
+                 {NULL,0,NULL}
                };
 
              if(!parse_options(pargs.r.ret_str,&opt.verify_options,vopts,1))
index 9b368f6..60b8ff2 100644 (file)
@@ -88,13 +88,13 @@ parse_import_options(char *str,unsigned int *options,int noisy)
 {
   struct parse_options import_opts[]=
     {
-      {"allow-local-sigs",IMPORT_ALLOW_LOCAL_SIGS},
-      {"repair-hkp-subkey-bug",IMPORT_REPAIR_PKS_SUBKEY_BUG},
-      {"repair-pks-subkey-bug",IMPORT_REPAIR_PKS_SUBKEY_BUG},
-      {"fast-import",IMPORT_FAST_IMPORT},
-      {"convert-sk-to-pk",IMPORT_SK2PK},
-      {"merge-only",IMPORT_MERGE_ONLY},
-      {NULL,0}
+      {"allow-local-sigs",IMPORT_ALLOW_LOCAL_SIGS,NULL},
+      {"repair-hkp-subkey-bug",IMPORT_REPAIR_PKS_SUBKEY_BUG,NULL},
+      {"repair-pks-subkey-bug",IMPORT_REPAIR_PKS_SUBKEY_BUG,NULL},
+      {"fast-import",IMPORT_FAST_IMPORT,NULL},
+      {"convert-sk-to-pk",IMPORT_SK2PK,NULL},
+      {"merge-only",IMPORT_MERGE_ONLY,NULL},
+      {NULL,0,NULL}
     };
 
   return parse_options(str,options,import_opts,noisy);
@@ -619,7 +619,7 @@ check_prefs(KBNODE keyblock)
          size_t fprlen=0;
          byte fpr[MAX_FINGERPRINT_LEN],*p;
          char username[(MAX_FINGERPRINT_LEN*2)+1];
-         int i;
+         unsigned int i;
 
          p=fingerprint_from_pk(keyblock->pkt->pkt.public_key,fpr,&fprlen);
          for(i=0;i<fprlen;i++,p++)
index 6328704..a651f71 100644 (file)
@@ -72,65 +72,6 @@ struct kopts
 static int keyserver_work(int action,STRLIST list,
                          KEYDB_SEARCH_DESC *desc,int count);
 
-static char *
-argsep(char **stringp,char **arg)
-{
-  char *tok,*next;
-
-  tok=*stringp;
-  *arg=NULL;
-
-  if(tok)
-    {
-      next=strpbrk(tok," ,=");
-
-      if(next)
-       {
-         int sawequals=0;
-
-         if(*next=='=')
-           sawequals=1;
-
-         *next++='\0';
-         *stringp=next;
-
-         /* what we need to do now is scan along starting with *next.
-            If the next character we see (ignoring spaces) is a =
-            sign, then there is an argument. */
-
-         while(*next)
-           {
-             if(*next=='=')
-               sawequals=1;
-             else if(*next!=' ')
-               break;
-             next++;
-           }
-
-         /* At this point, *next is either an empty string, or the
-            beginning of the next token (which is an argument if
-            sawequals is true). */
-
-         if(sawequals)
-           {
-             *arg=next;
-             next=strpbrk(*arg," ,");
-             if(next)
-               {
-                 *next++='\0';
-                 *stringp=next;
-               }
-             else
-               *stringp=NULL;
-           }
-       }
-      else
-       *stringp=NULL;
-    }
-
-  return tok;
-}
-
 void 
 parse_keyserver_options(char *options)
 {
index 3b87707..8476bd6 100644 (file)
@@ -106,8 +106,10 @@ struct parse_options
 {
   char *name;
   unsigned int bit;
+  char **value;
 };
 
+char *argsep(char **stringp,char **arg);
 int parse_options(char *str,unsigned int *options,
                  struct parse_options *opts,int noisy);
 
index 2a8e292..01f34b4 100644 (file)
@@ -669,13 +669,72 @@ compliance_failure(void)
   opt.compliance=CO_GNUPG;
 }
 
+char *
+argsep(char **stringp,char **arg)
+{
+  char *tok,*next;
+
+  tok=*stringp;
+  *arg=NULL;
+
+  if(tok)
+    {
+      next=strpbrk(tok," ,=");
+
+      if(next)
+       {
+         int sawequals=0;
+
+         if(*next=='=')
+           sawequals=1;
+
+         *next++='\0';
+         *stringp=next;
+
+         /* what we need to do now is scan along starting with *next.
+            If the next character we see (ignoring spaces) is a =
+            sign, then there is an argument. */
+
+         while(*next)
+           {
+             if(*next=='=')
+               sawequals=1;
+             else if(*next!=' ')
+               break;
+             next++;
+           }
+
+         /* At this point, *next is either an empty string, or the
+            beginning of the next token (which is an argument if
+            sawequals is true). */
+
+         if(sawequals)
+           {
+             *arg=next;
+             next=strpbrk(*arg," ,");
+             if(next)
+               {
+                 *next++='\0';
+                 *stringp=next;
+               }
+             else
+               *stringp=NULL;
+           }
+       }
+      else
+       *stringp=NULL;
+    }
+
+  return tok;
+}
+
 int
 parse_options(char *str,unsigned int *options,
              struct parse_options *opts,int noisy)
 {
-  char *tok;
+  char *tok,*arg;
 
-  while((tok=strsep(&str," ,")))
+  while((tok=argsep(&str,&arg)))
     {
       int i,rev=0;
       char *otok=tok;
@@ -715,6 +774,8 @@ parse_options(char *str,unsigned int *options,
                *options&=~opts[i].bit;
              else
                *options|=opts[i].bit;
+             if(opts[i].value)
+               *opts[i].value=arg?m_strdup(arg):NULL;
              break;
            }
        }