From b97ec4c63a6f54c5fde6bb94e04a38149bd6c515 Mon Sep 17 00:00:00 2001 From: Greg Stein Date: Mon, 24 Apr 2000 12:27:02 +0000 Subject: [PATCH] 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 --- include/http_config.h | 3 +- modules/http/http_core.c | 15 +++++---- server/config.c | 69 +++++++++++++++++----------------------- 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/include/http_config.h b/include/http_config.h index 1be40d8518..3121e69b20 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -338,7 +338,8 @@ API_EXPORT(const char *) ap_build_config(configfile_t *cfp, ap_pool_t *conf_pool, ap_pool_t *temp_pool, 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: */ API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden); diff --git a/modules/http/http_core.c b/modules/http/http_core.c index f14f62254e..f503cac09c 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -1320,7 +1320,7 @@ CORE_EXPORT_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, */ 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; @@ -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, &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) 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, &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) 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, &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) return errmsg; @@ -1553,7 +1553,7 @@ static const char *start_ifmod(cmd_parms *cmd, void *dummy, char *arg) found = ap_find_linked_module(arg); 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; @@ -1594,7 +1594,7 @@ static const char *start_ifdefine(cmd_parms *cmd, void *dummy, char *arg) defined = ap_exists_config_define(arg); 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; @@ -1642,7 +1642,8 @@ static const char *virtualhost_section(cmd_parms *cmd, void *dummy, char *arg) 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; diff --git a/server/config.c b/server/config.c index c693d036a4..1f0b90cb26 100644 --- a/server/config.c +++ b/server/config.c @@ -900,67 +900,58 @@ static const char * ap_build_config_sub(ap_pool_t *p, ap_pool_t *temp_pool, 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) { - void *oldconfig; - const command_rec *cmd; 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))) { - retval = ap_pstrcat(parms->pool, "Invalid command '", - current->directive, - "', perhaps mis-spelled or defined by a module " - "not included in the server configuration", NULL); + return ap_pstrcat(parms->pool, "Invalid command '", + current->directive, + "', perhaps mis-spelled or defined by a module " + "not included in the server configuration", + NULL); } else { void *mconfig = ap_set_config_vectors(parms,config, mod); + const char *retval; 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 */ } - } while (retval && !strcmp(retval, DECLINE_CMD)); - parms->context = oldconfig; - - return retval; + } + /* NOTREACHED */ } -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 *current, + cmd_parms *parms, void *config) { - static ap_directive_t *current; + void *oldconfig = parms->context; - if (conftree != NULL) { - current = conftree; - } - if (container && current->first_child) { - current = current->first_child; - } + parms->context = config; - while (current != NULL) { + /* scan through all directives, executing each one */ + for (; current != NULL; current = current->next) { const char *errmsg; + parms->directive = current; + /* actually parse the command and execute the correct function */ 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; - - if (current->next == NULL) { - current = current->parent; - break; - } else { - current = current->next; - continue; - } + } } + parms->context = oldconfig; 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); if (errmsg == NULL) - errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults, 0); + errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults); if (errmsg) { ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "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); 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) { /* ### 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); if (errmsg == NULL) - errmsg = ap_walk_config(conftree, &parms, dc, 0); + errmsg = ap_walk_config(conftree, &parms, dc); ap_cfg_closefile(f); -- 2.40.0