1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-08 15:02:10 +03:00

drop the "container" param from ap_walk_config(). callers should simply

pass the first child, rather than expecting the walker to do it.
remove the nasty "static" variable inside ap_walk_config(). it now walks the
    tree provided with no worries about bumping up/down levels.
minor refactor between ap_walk_config() and ap_walk_config_sub() to clean up
    some logic and clarify the code.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85025 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Greg Stein
2000-04-24 12:27:02 +00:00
parent c2c13c67c3
commit b97ec4c63a
3 changed files with 40 additions and 47 deletions

View File

@@ -338,7 +338,8 @@ API_EXPORT(const char *) ap_build_config(configfile_t *cfp,
ap_pool_t *conf_pool, ap_pool_t *conf_pool,
ap_pool_t *temp_pool, ap_pool_t *temp_pool,
ap_directive_t **conftree); ap_directive_t **conftree);
API_EXPORT(const char *) ap_walk_config(ap_directive_t *conftree, cmd_parms *parms, void *config, int container); API_EXPORT(const char *) ap_walk_config(ap_directive_t *conftree,
cmd_parms *parms, void *config);
/* ap_check_cmd_context() definitions: */ /* ap_check_cmd_context() definitions: */
API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden); API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden);

View File

@@ -1320,7 +1320,7 @@ CORE_EXPORT_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy,
*/ */
cmd->limited = tog ? ~limited : limited; cmd->limited = tog ? ~limited : limited;
errmsg = ap_walk_config(NULL, cmd, cmd->context, 1); errmsg = ap_walk_config(cmd->directive->first_child, cmd, cmd->context);
cmd->limited = -1; cmd->limited = -1;
@@ -1388,7 +1388,7 @@ static const char *dirsection(cmd_parms *cmd, void *dummy, const char *arg)
conf = (core_dir_config *)ap_set_config_vectors(cmd, new_dir_conf, conf = (core_dir_config *)ap_set_config_vectors(cmd, new_dir_conf,
&core_module); &core_module);
errmsg = ap_walk_config(NULL, cmd, new_dir_conf, 1); errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_dir_conf);
if (errmsg != NULL) if (errmsg != NULL)
return errmsg; return errmsg;
@@ -1446,7 +1446,7 @@ static const char *urlsection(cmd_parms *cmd, void *dummy, const char *arg)
conf = (core_dir_config *)ap_set_config_vectors(cmd, new_url_conf, conf = (core_dir_config *)ap_set_config_vectors(cmd, new_url_conf,
&core_module); &core_module);
errmsg = ap_walk_config(NULL, cmd, new_url_conf, 1); errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_url_conf);
if (errmsg != NULL) if (errmsg != NULL)
return errmsg; return errmsg;
@@ -1513,7 +1513,7 @@ static const char *filesection(cmd_parms *cmd, core_dir_config *c,
conf = (core_dir_config *)ap_set_config_vectors(cmd, new_file_conf, conf = (core_dir_config *)ap_set_config_vectors(cmd, new_file_conf,
&core_module); &core_module);
errmsg = ap_walk_config(NULL, cmd, new_file_conf, 1); errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_file_conf);
if (errmsg != NULL) if (errmsg != NULL)
return errmsg; return errmsg;
@@ -1553,7 +1553,7 @@ static const char *start_ifmod(cmd_parms *cmd, void *dummy, char *arg)
found = ap_find_linked_module(arg); found = ap_find_linked_module(arg);
if ((!not && found) || (not && !found)) { if ((!not && found) || (not && !found)) {
return ap_walk_config(NULL, cmd, cmd->context, 1); return ap_walk_config(cmd->directive->first_child, cmd, cmd->context);
} }
return NULL; return NULL;
@@ -1594,7 +1594,7 @@ static const char *start_ifdefine(cmd_parms *cmd, void *dummy, char *arg)
defined = ap_exists_config_define(arg); defined = ap_exists_config_define(arg);
if ((!not && defined) || (not && !defined)) { if ((!not && defined) || (not && !defined)) {
return ap_walk_config(NULL, cmd, cmd->context, 1); return ap_walk_config(cmd->directive->first_child, cmd, cmd->context);
} }
return NULL; return NULL;
@@ -1642,7 +1642,8 @@ static const char *virtualhost_section(cmd_parms *cmd, void *dummy, char *arg)
cmd->server = s; cmd->server = s;
errmsg = ap_walk_config(NULL, cmd, s->lookup_defaults, 1); errmsg = ap_walk_config(cmd->directive->first_child, cmd,
s->lookup_defaults);
cmd->server = main_server; cmd->server = main_server;

View File

@@ -900,67 +900,58 @@ static const char * ap_build_config_sub(ap_pool_t *p, ap_pool_t *temp_pool,
return NULL; return NULL;
} }
static const char *ap_walk_config_sub(ap_directive_t *current, static const char *ap_walk_config_sub(const ap_directive_t *current,
cmd_parms *parms, void *config) cmd_parms *parms, void *config)
{ {
void *oldconfig;
const command_rec *cmd;
module *mod = top_module; module *mod = top_module;
const char *retval;
parms->directive = current; while (1) {
const command_rec *cmd;
oldconfig = parms->context;
parms->context = config;
do {
if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) { if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) {
retval = ap_pstrcat(parms->pool, "Invalid command '", return ap_pstrcat(parms->pool, "Invalid command '",
current->directive, current->directive,
"', perhaps mis-spelled or defined by a module " "', perhaps mis-spelled or defined by a module "
"not included in the server configuration", NULL); "not included in the server configuration",
NULL);
} }
else { else {
void *mconfig = ap_set_config_vectors(parms,config, mod); void *mconfig = ap_set_config_vectors(parms,config, mod);
const char *retval;
retval = invoke_cmd(cmd, parms, mconfig, current->args); retval = invoke_cmd(cmd, parms, mconfig, current->args);
if (retval == NULL || strcmp(retval, DECLINE_CMD) != 0)
return retval;
mod = mod->next; /* Next time around, skip this one */ mod = mod->next; /* Next time around, skip this one */
} }
} while (retval && !strcmp(retval, DECLINE_CMD)); }
parms->context = oldconfig; /* NOTREACHED */
return retval;
} }
API_EXPORT(const char *) ap_walk_config(ap_directive_t *conftree, API_EXPORT(const char *) ap_walk_config(ap_directive_t *current,
cmd_parms *parms, void *config, cmd_parms *parms, void *config)
int container)
{ {
static ap_directive_t *current; void *oldconfig = parms->context;
if (conftree != NULL) { parms->context = config;
current = conftree;
}
if (container && current->first_child) {
current = current->first_child;
}
while (current != NULL) { /* scan through all directives, executing each one */
for (; current != NULL; current = current->next) {
const char *errmsg; const char *errmsg;
parms->directive = current;
/* actually parse the command and execute the correct function */ /* actually parse the command and execute the correct function */
errmsg = ap_walk_config_sub(current, parms, config); errmsg = ap_walk_config_sub(current, parms, config);
if (errmsg != NULL) if (errmsg != NULL) {
/* restore the context (just in case) */
parms->context = oldconfig;
return errmsg; return errmsg;
if (current->next == NULL) {
current = current->parent;
break;
} else {
current = current->next;
continue;
} }
} }
parms->context = oldconfig;
return NULL; return NULL;
} }
@@ -1135,7 +1126,7 @@ static void process_command_config(server_rec *s, ap_array_header_t *arr, ap_poo
errmsg = ap_build_config(cfp, p, ptemp, &conftree); errmsg = ap_build_config(cfp, p, ptemp, &conftree);
if (errmsg == NULL) if (errmsg == NULL)
errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults, 0); errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
if (errmsg) { if (errmsg) {
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"Syntax error in -C/-c directive:\n%s", errmsg); "Syntax error in -C/-c directive:\n%s", errmsg);
@@ -1179,7 +1170,7 @@ void ap_process_resource_config(server_rec *s, const char *fname, ap_pool_t *p,
errmsg = ap_build_config(cfp, p, ptemp, &conftree); errmsg = ap_build_config(cfp, p, ptemp, &conftree);
if (errmsg == NULL) if (errmsg == NULL)
errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults, 0); errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
if (errmsg != NULL) { if (errmsg != NULL) {
/* ### wrong line number. need to pull from ap_directive_t */ /* ### wrong line number. need to pull from ap_directive_t */
@@ -1236,7 +1227,7 @@ int ap_parse_htaccess(void **result, request_rec *r, int override,
errmsg = ap_build_config(f, r->pool, r->pool, &conftree); errmsg = ap_build_config(f, r->pool, r->pool, &conftree);
if (errmsg == NULL) if (errmsg == NULL)
errmsg = ap_walk_config(conftree, &parms, dc, 0); errmsg = ap_walk_config(conftree, &parms, dc);
ap_cfg_closefile(f); ap_cfg_closefile(f);