httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1032565 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/core.xml server/core.c
Date Mon, 08 Nov 2010 13:15:17 GMT
Author: trawick
Date: Mon Nov  8 13:15:17 2010
New Revision: 1032565

URL: http://svn.apache.org/viewvc?rev=1032565&view=rev
Log:
Add Error directive for aborting startup or htaccess processing
with a specified error message.

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

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/core.xml
    httpd/httpd/trunk/server/core.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1032565&r1=1032564&r2=1032565&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Mon Nov  8 13:15:17 2010
@@ -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]

Modified: httpd/httpd/trunk/docs/manual/mod/core.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/core.xml?rev=1032565&r1=1032564&r2=1032565&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/core.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/core.xml Mon Nov  8 13:15:17 2010
@@ -890,6 +890,43 @@ version 2.3.9.</compatibility>
 </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
 in case of an error</description>

Modified: httpd/httpd/trunk/server/core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core.c?rev=1032565&r1=1032564&r2=1032565&view=diff
==============================================================================
--- httpd/httpd/trunk/server/core.c (original)
+++ httpd/httpd/trunk/server/core.c Mon Nov  8 13:15:17 2010
@@ -1092,6 +1092,25 @@ static const char *unset_define(cmd_parm
     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
               "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"),
 



Mime
View raw message