From 2d507c2fcdd5914d13a99399d80cbb9f85baf1d0 Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Sat, 30 Jan 2010 12:18:18 +0000 Subject: [PATCH] Allow the Define directive to undefine a variable by prefixing the argument with a '!'. PR: 35350 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@904768 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ docs/manual/mod/core.xml | 6 ++++-- server/core.c | 29 ++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 4d1ca4bda4..af191baea3 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.3.6 + *) Allow the Define directive to undefine a variable by prefixing the + argument with a '!'. PR 35350. [Stefan Fritsch] + *) Make ap_pregsub(), used by AliasMatch and friends, use the same syntax for regex backreferences as mod_rewrite and mod_include: Remove the use of '&' as an alias for '$0' and allow to escape any character with a diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index 2bfdcb1a27..79e47416c6 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -596,8 +596,8 @@ which no other media type configuration could be found. Define -Define the existence of a variable -Define parameter-name +Define or undefine the existence of a variable +Define [!]parameter-name server config @@ -606,6 +606,8 @@ which no other media type configuration could be found.

This directive can be used to toggle the use of IfDefine sections without needing to alter -D arguments in any startup scripts.

+

If the parameter-name is prefixed with a !, the definition + of the argument is removed.

diff --git a/server/core.c b/server/core.c index 7edc0fe0b3..8d2e20579e 100644 --- a/server/core.c +++ b/server/core.c @@ -1104,7 +1104,7 @@ static const char *set_access_name(cmd_parms *cmd, void *dummy, static const char *set_define(cmd_parms *cmd, void *dummy, const char *optarg) { - char **newv; + int remove = 0; const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -1112,8 +1112,31 @@ static const char *set_define(cmd_parms *cmd, void *dummy, return err; } - newv = (char **)apr_array_push(ap_server_config_defines); - *newv = apr_pstrdup(cmd->pool, optarg); + if (*optarg == '!') { + remove = 1; + optarg++; + } + + if (remove == 0 && !ap_exists_config_define(optarg)) { + char **newv = (char **)apr_array_push(ap_server_config_defines); + *newv = apr_pstrdup(cmd->pool, optarg); + } + else if (remove == 1) { + int i; + char **defines = (char **)ap_server_config_defines->elts; + for (i = 0; i < ap_server_config_defines->nelts; i++) { + if (strcmp(defines[i], optarg) == 0) { + if (i == ap_server_config_defines->nelts - 1) { + apr_array_pop(ap_server_config_defines); + break; + } + else { + defines[i] = apr_array_pop(ap_server_config_defines); + break; + } + } + } + } return NULL; } -- 2.40.0