]> granicus.if.org Git - apache/commitdiff
Add Error directive for aborting startup or htaccess processing
authorJeff Trawick <trawick@apache.org>
Mon, 8 Nov 2010 13:15:17 +0000 (13:15 +0000)
committerJeff Trawick <trawick@apache.org>
Mon, 8 Nov 2010 13:15:17 +0000 (13:15 +0000)
with a specified error message.

Be nice and strip off any quotes, which aren't necessary.

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

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

diff --git a/CHANGES b/CHANGES
index f683bc55e5bac963a20c14a1611970fd12ccec8f..81d6db7ebeeb3b26afa06244f51640eb5cfd5c30 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,9 @@ Changes with Apache 2.3.9
      Fix a denial of service attack against mod_reqtimeout.
      [Stefan Fritsch]
 
+  *) core: Add Error directive for aborting startup or htaccess processing
+     with a specified error message.  [Jeff Trawick]
+
   *) mod_rewrite: Fix the RewriteEngine directive to work within a
      location. Previously, once RewriteEngine was switched on globally,
      it was impossible to switch off. [Graham Leggett]
index 878ecea993a5e3924ee02189463f315bf2d56aeb..c2bbd8ab4c378c2c7e00fae25de01b81606c5fed 100644 (file)
@@ -889,6 +889,43 @@ version 2.3.9.</compatibility>
 </usage>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>Error</name>
+<description>Abort configuration parsing with a custom error message</description>
+<syntax>Error <var>message</var></syntax>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context><context>.htaccess</context>
+</contextlist>
+<compatibility>2.3.9 and later</compatibility>
+
+<usage>
+    <p>If an error can be detected within the configuration, this
+    directive can be used to generate a custom error message, and halt
+    configuration parsing.  The typical use is for reporting required
+    modules which are missing from the configuration.</p>
+
+    <example><title>Example</title>
+      # ensure that mod_include is loaded<br />
+      &lt;IfModule !include_module&gt;<br />
+      Error mod_include is required by mod_foo.  Load it with LoadModule.<br />
+      &lt;/IfModule&gt;<br />
+      <br />
+      # ensure that exactly one of SSL,NOSSL is defined<br />
+      &lt;IfDefine SSL&gt;<br />
+      &lt;IfDefine NOSSL&gt;<br />
+      Error Both SSL and NOSSL are defined.  Define only one of them.<br />
+      &lt;/IfDefine&gt;<br />
+      &lt;/IfDefine&gt;<br />
+      &lt;IfDefine !SSL&gt;<br />
+      &lt;IfDefine !NOSSL&gt;<br />
+      Error Either SSL or NOSSL must be defined.<br />
+      &lt;/IfDefine&gt;<br />
+      &lt;/IfDefine&gt;<br />
+    </example>
+
+</usage>
+</directivesynopsis>
+
 <directivesynopsis>
 <name>ErrorDocument</name>
 <description>What the server will return to the client
index d41ff648f5b71bc91d832c6aac1609c6e93b28f0..cf0d6c6750b9402504a0ff752759c71eec516a51 100644 (file)
@@ -1092,6 +1092,25 @@ static const char *unset_define(cmd_parms *cmd, void *dummy,
     return NULL;
 }
 
+static const char *generate_error(cmd_parms *cmd, void *dummy,
+                                  const char *arg)
+{
+    if (!arg || !*arg) {
+        return "The Error directive was used with no message.";
+    }
+
+    if (*arg == '"' || *arg == '\'') { /* strip off quotes */
+        apr_size_t len = strlen(arg);
+        char last = *(arg + len - 1);
+
+        if (*arg == last) {
+            return apr_pstrndup(cmd->pool, arg + 1, len - 2);
+        }
+    }
+
+    return arg;
+}
+
 #ifdef GPROF
 static const char *set_gprof_dir(cmd_parms *cmd, void *dummy, const char *arg)
 {
@@ -3432,6 +3451,8 @@ AP_INIT_TAKE1("Define", set_define, NULL, RSRC_CONF,
               "Define the existence of a variable.  Same as passing -D to the command line."),
 AP_INIT_TAKE1("UnDefine", unset_define, NULL, RSRC_CONF,
               "Undefine the existence of a variable. Undo a Define."),
+AP_INIT_RAW_ARGS("Error", generate_error, NULL, OR_ALL,
+                 "Generate error message from within configuration"),
 AP_INIT_RAW_ARGS("<If", ifsection, NULL, OR_ALL,
   "Container for directives to be conditionally applied"),