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

Reply via email to