From: Joe Orton Date: Wed, 8 Mar 2017 10:09:15 +0000 (+0000) Subject: Remove duplicate implementations of conditional section function. No X-Git-Tag: 2.5.0-alpha~578 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=60301274df94a8b32d85e7380de863762fc66c6b;p=thirdparty%2Fapache%2Fhttpd.git Remove duplicate implementations of conditional section function. No functional change. * server/core.c (start_cond_section): Factor out from start_if*. Adjust to use apr_strmemdup. (test_ifmod_section, test_iffile_section, test_ifdefine_section): Move container-specific tests into callbacks from start_if*. (core_cmds): Adjust -style conditional sections. Callback + * to test condition must be in cmd->info, matching function type + * test_conditional_section. */ +static const char *start_cond_section(cmd_parms *cmd, void *mconfig, const char *arg) { const char *endp = ap_strrchr_c(arg, '>'); int not = (arg[0] == '!'); - module *found; + int found; + test_cond_section_fn testfn = (test_cond_section_fn)cmd->info; if (endp == NULL) { return unclosed_directive(cmd); } - arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); + arg = apr_pstrmemdup(cmd->temp_pool, arg, endp - arg); if (not) { arg++; @@ -2789,7 +2795,7 @@ static const char *start_ifmod(cmd_parms *cmd, void *mconfig, const char *arg) return missing_container_arg(cmd); } - found = find_module(cmd->server, arg); + found = testfn(cmd, arg); if ((!not && found) || (not && !found)) { ap_directive_t *parent = NULL; @@ -2797,101 +2803,39 @@ static const char *start_ifmod(cmd_parms *cmd, void *mconfig, const char *arg) const char *retval; retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd, - ¤t, &parent, "cmd->name); *(ap_directive_t **)mconfig = current; return retval; } else { *(ap_directive_t **)mconfig = NULL; - return ap_soak_end_container(cmd, "cmd->name); } } +/* Callback to implement test for start_cond_section. */ +static int test_ifmod_section(cmd_parms *cmd, const char *arg) +{ + return find_module(cmd->server, arg) != NULL; +} + AP_DECLARE(int) ap_exists_config_define(const char *name) { return ap_array_str_contains(ap_server_config_defines, name); } -static const char *start_ifdefine(cmd_parms *cmd, void *dummy, const char *arg) +static int test_ifdefine_section(cmd_parms *cmd, const char *arg) { - const char *endp; - int defined; - int not = 0; - - endp = ap_strrchr_c(arg, '>'); - if (endp == NULL) { - return unclosed_directive(cmd); - } - - arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); - - if (arg[0] == '!') { - not = 1; - arg++; - } - - if (!arg[0]) { - return missing_container_arg(cmd); - } - - defined = ap_exists_config_define(arg); - if ((!not && defined) || (not && !defined)) { - ap_directive_t *parent = NULL; - ap_directive_t *current = NULL; - const char *retval; - - retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd, - ¤t, &parent, "'); - if (endp == NULL) { - return unclosed_directive(cmd); - } - - arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); - - if (arg[0] == '!') { - not = 1; - arg++; - } - - if (!arg[0]) { - return missing_container_arg(cmd); - } + apr_finfo_t sb; relative = ap_server_root_relative(cmd->temp_pool, arg); - file_exists = (apr_stat(&sb, relative, 0, cmd->pool) == APR_SUCCESS); - - if ((!not && file_exists) || (not && !file_exists)) { - ap_directive_t *parent = NULL; - ap_directive_t *current = NULL; - const char *retval; - - retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd, - ¤t, &parent, "pool) == APR_SUCCESS); } /* httpd.conf commands... beginning with the business */ @@ -4503,11 +4447,14 @@ AP_INIT_RAW_ARGS("