]> granicus.if.org Git - apache/commitdiff
Allow the Define directive to undefine a variable by prefixing the
authorStefan Fritsch <sf@apache.org>
Sat, 30 Jan 2010 12:18:18 +0000 (12:18 +0000)
committerStefan Fritsch <sf@apache.org>
Sat, 30 Jan 2010 12:18:18 +0000 (12:18 +0000)
argument with a '!'.

PR: 35350

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@904768 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/core.xml
server/core.c

diff --git a/CHANGES b/CHANGES
index 4d1ca4bda4b73b9a9508f578f3ce88edee79ed23..af191baea339698b9ca3b369d12c518e8a04b2a9 100644 (file)
--- 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
index 2bfdcb1a27772da7c91cee14fa1c19c649806303..79e47416c6fabf6f3b9c6868b33a0235ad511ae5 100644 (file)
@@ -596,8 +596,8 @@ which no other media type configuration could be found.
 
 <directivesynopsis>
 <name>Define</name>
-<description>Define the existence of a variable</description>
-<syntax>Define <var>parameter-name</var></syntax>
+<description>Define or undefine the existence of a variable</description>
+<syntax>Define [!]<var>parameter-name</var></syntax>
 <contextlist><context>server config</context></contextlist>
 
 <usage>
@@ -606,6 +606,8 @@ which no other media type configuration could be found.
     <p>This directive can be used to toggle the use of <directive module="core"
     type="section">IfDefine</directive> sections without needing to alter
     <code>-D</code> arguments in any startup scripts.</p>
+    <p>If the parameter-name is prefixed with a <code>!</code>, the definition
+    of the argument is removed.</p>
 </usage>
 </directivesynopsis>
 
index 7edc0fe0b3f8eeea5f13e1c4e931e77d2be24f66..8d2e20579e2d734cc49013260c2c62fda82cc157 100644 (file)
@@ -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;
 }