You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Paul Querna <ch...@force-elite.com> on 2005/05/04 21:34:00 UTC
[PATCH] Add AP_INIT_TAKE_ARGV
Attached is a patch that adds a new configuration command type.
It uses the traditional argv/argc. I grew tired of having to make
commands more complicated by using RAW_ARGS, when there is no need.
The patch includes changing 'IndexOptions' to use the new
AP_INIT_TAKE_ARGV, instead of RAW_ARGS. It also adds a minor MMN bump
for the new interface.
Comments/thoughts/flames/etc welcome...
-Paul
Re: [PATCH] Add AP_INIT_TAKE_ARGV
Posted by Brian Akins <ba...@web.turner.com>.
Paul Querna wrote:
> Attached is a patch that adds a new configuration command type.
>
What about key=value args? I kept writing the same parser over and over
so, I generalized it. This could be hacked to be included as normal parser:
/*in mod_util.h file*/
typedef struct{
const char *name;
util_option_fn_t *func;
} option_rec ;
const char *util_parse_options(apr_pool_t *pool, const char *config,
const option_rec *options, void *user_data);
/*in mod_util.c**/
static const option_rec *find_option(const char *name, const option_rec
*options)
{
while (options->name) {
if (!strcasecmp(name, options->name))
return options;
++options;
}
return NULL;
}
const char *util_parse_options(apr_pool_t *pool, const char *config,
const option_rec *options, void *user_data) {
char *key;
char *val;
const char *error;
const option_rec *option;
util_option_fn_t *func;
while(*config) {
key = ap_getword_conf(pool, &config);
if((val = strchr(key, '=')) != NULL) {
*val = '\0';
val++;
if(!*val) {
return "invalid value";
}
} else {
return "no = in option";
}
if((option = find_option(key, options)) == NULL) {
return apr_psprintf(pool, "no func for %s", key);
} else {
func = option->func;
if(func == NULL) {
return apr_psprintf(pool, "null func for %s", key);
} else {
error = func(pool, key, val, user_data);
if(error != NULL) {
return error;
}
}
}
}
return NULL;
}
To use it in another module:
static const char* set_min(apr_pool_t *pool, char *key, char* val, void*
user_data) {
my_conf *conf = (my_conf*)user_data;
conf->min = apr_atoi64(val);
return NULL;
}
....
static option_rec options[] = {
{ "max", set_max},
{ "min", set_min},
{NULL}
};
/*in config directive function*/
my_conf*conf =
ap_get_module_config(parms->server->module_config,
&my_module);
return util_parse_options(parms->pool, option, options, conf);
--
Brian Akins
Lead Systems Engineer
CNN Internet Technologies
Re: [PATCH] Add AP_INIT_TAKE_ARGV
Posted by Paul Querna <ch...@force-elite.com>.
William A. Rowe, Jr. wrote:
> so definitely ++1 in theory, without reviewing the code yet.
I have committed an updated version to trunk. It does have some issues
with the last argument being a "", but see the 'ap_getword_conf should
die.' email for details...
-Paul
Re: [PATCH] Add AP_INIT_TAKE_ARGV
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 02:34 PM 5/4/2005, Paul Querna wrote:
>Attached is a patch that adds a new configuration command type.
>
>It uses the traditional argv/argc. I grew tired of having to make
>commands more complicated by using RAW_ARGS, when there is no need.
>
>The patch includes changing 'IndexOptions' to use the new
>AP_INIT_TAKE_ARGV, instead of RAW_ARGS. It also adds a minor MMN bump
>for the new interface.
One goal is to be able to plug in an alternative xml-conf style
parser. Your proposal mapps much more nicely for xml configs;
<olddirective>
<args>foo bar bash</args>
</olddirective>
<newdirective>
<arg>foo</arg>
<arg>bar</arg>
<arg>bash</arg>
</newdirective>
so definitely ++1 in theory, without reviewing the code yet.