1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-28 02:12:46 +02:00

* main.h, misc.c (optsep, argsplit, optlen, parse_options): Simplify code

and properly handle a partial match against an option with an argument.

* keyserver-internal.h, keyserver.c (parse_keyserver_options): Use new
optsep and argsplit functions.
This commit is contained in:
David Shaw 2004-04-16 15:19:35 +00:00
parent 2936e539cc
commit 0a17966a21
5 changed files with 62 additions and 37 deletions

View File

@ -1,3 +1,12 @@
2004-04-16 David Shaw <dshaw@jabberwocky.com>
* main.h, misc.c (optsep, argsplit, optlen, parse_options):
Simplify code and properly handle a partial match against an
option with an argument.
* keyserver-internal.h, keyserver.c (parse_keyserver_options): Use
new optsep and argsplit functions.
2004-04-15 David Shaw <dshaw@jabberwocky.com> 2004-04-15 David Shaw <dshaw@jabberwocky.com>
* main.h, misc.c (argsplit): Refactor argsep into argsplit and * main.h, misc.c (argsplit): Refactor argsep into argsplit and

View File

@ -8,7 +8,7 @@
#include "iobuf.h" #include "iobuf.h"
#include "types.h" #include "types.h"
void parse_keyserver_options(char *options); int parse_keyserver_options(char *options);
struct keyserver_spec *parse_keyserver_uri(char *uri, struct keyserver_spec *parse_keyserver_uri(char *uri,
const char *configname, const char *configname,
unsigned int configlineno); unsigned int configlineno);

View File

@ -70,12 +70,13 @@ static struct parse_options keyserver_opts[]=
static int keyserver_work(int action,STRLIST list, static int keyserver_work(int action,STRLIST list,
KEYDB_SEARCH_DESC *desc,int count); KEYDB_SEARCH_DESC *desc,int count);
void int
parse_keyserver_options(char *options) parse_keyserver_options(char *options)
{ {
char *tok,*arg; int ret=1;
char *tok;
while((tok=argsep(&options,&arg))) while((tok=optsep(&options)))
{ {
if(tok[0]=='\0') if(tok[0]=='\0')
continue; continue;
@ -108,6 +109,7 @@ parse_keyserver_options(char *options)
{ {
/* All of the standard options have failed, so the option is /* All of the standard options have failed, so the option is
destined for a keyserver plugin. */ destined for a keyserver plugin. */
char *arg=argsplit(tok);
if(arg) if(arg)
{ {
@ -126,6 +128,8 @@ parse_keyserver_options(char *options)
add_to_strlist(&opt.keyserver_options.other,tok); add_to_strlist(&opt.keyserver_options.other,tok);
} }
} }
return ret;
} }
struct keyserver_spec * struct keyserver_spec *

View File

@ -108,8 +108,8 @@ struct parse_options
char **value; char **value;
}; };
char *argsplit(char **stringp); char *optsep(char **stringp);
char *argsep(char **stringp,char **arg); char *argsplit(char *string);
int parse_options(char *str,unsigned int *options, int parse_options(char *str,unsigned int *options,
struct parse_options *opts,int noisy); struct parse_options *opts,int noisy);

View File

@ -644,10 +644,10 @@ compliance_failure(void)
opt.compliance=CO_GNUPG; opt.compliance=CO_GNUPG;
} }
/* Break a string into option pieces. Accepts single word options and /* Break a string into successive option pieces. Accepts single word
key=value argument options. */ options and key=value argument options. */
char * char *
argsplit(char **stringp) optsep(char **stringp)
{ {
char *tok,*end; char *tok,*end;
@ -692,47 +692,59 @@ argsplit(char **stringp)
return tok; return tok;
} }
/* Break an option or key=value option into key and value */ /* Breaks an option value into key and value. Returns NULL if there
is no value. Note that "string" is modified to remove the =value
part. */
char * char *
argsep(char **stringp,char **arg) argsplit(char *string)
{ {
char *tok; char *equals,*arg=NULL;
*arg=NULL; equals=strchr(string,'=');
if(equals)
tok=argsplit(stringp);
if(tok)
{ {
char *equals; char *space;
equals=strchr(tok,'=');
if(equals) space=strchr(string,' ');
if(space)
{ {
char *space; *space='\0';
arg=space+1;
space=strchr(tok,' ');
if(space)
*space='\0';
else
*equals='\0';
space=strrchr(equals+1,' ');
if(space)
*arg=space+1;
else
*arg=NULL;
} }
else
{
*equals='\0';
arg=equals+1;
}
space=strrchr(arg,' ');
if(space)
arg=space+1;
} }
return tok; return arg;
}
/* Return the length of the initial token, leaving off any
argument. */
static size_t
optlen(const char *s)
{
char *end=strpbrk(s," =");
if(end)
return end-s;
else
return strlen(s);
} }
int int
parse_options(char *str,unsigned int *options, parse_options(char *str,unsigned int *options,
struct parse_options *opts,int noisy) struct parse_options *opts,int noisy)
{ {
char *tok,*arg; char *tok;
while((tok=argsep(&str,&arg))) while((tok=optsep(&str)))
{ {
int i,rev=0; int i,rev=0;
char *otok=tok; char *otok=tok;
@ -748,7 +760,7 @@ parse_options(char *str,unsigned int *options,
for(i=0;opts[i].name;i++) for(i=0;opts[i].name;i++)
{ {
size_t toklen=strlen(tok); size_t toklen=optlen(tok);
if(ascii_strncasecmp(opts[i].name,tok,toklen)==0) if(ascii_strncasecmp(opts[i].name,tok,toklen)==0)
{ {
@ -778,7 +790,7 @@ parse_options(char *str,unsigned int *options,
{ {
*options|=opts[i].bit; *options|=opts[i].bit;
if(opts[i].value) if(opts[i].value)
*opts[i].value=arg?m_strdup(arg):NULL; *opts[i].value=argsplit(tok);
} }
break; break;
} }