httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fab...@apache.org
Subject svn commit: r1418677 - in /httpd/httpd/trunk: docs/manual/mod/core.xml server/config.c server/core.c
Date Sat, 08 Dec 2012 14:49:10 GMT
Author: fabien
Date: Sat Dec  8 14:49:09 2012
New Revision: 1418677

URL: http://svn.apache.org/viewvc?rev=1418677&view=rev
Log:
Add minor 'Warning' directive as defined in current mod_macro.

* server/core.c: add 'Warning' directive by extending the 'Error'
  directive implementation. The 'Error' behavior is slightly changed
  so as to use verbose ap_log_error instead of returning the message.
* docs/manual/mod/core.xml: add documentation for 'Warning'.
* server/config.c: add comment about syntax vs configuration errors.

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

Modified: httpd/httpd/trunk/docs/manual/mod/core.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/core.xml?rev=1418677&r1=1418676&r2=1418677&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/core.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/core.xml Sat Dec  8 14:49:09 2012
@@ -4419,4 +4419,34 @@ for external processing, e.g. to a CGI s
 </usage>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>Warning</name>
+<description>Warn from configuration parsing with a custom message</description>
+<syntax>Warning <var>message</var></syntax>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context><context>.htaccess</context>
+</contextlist>
+<compatibility>2.5 and later</compatibility>
+
+<usage>
+    <p>If an issue can be detected from within the configuration, this
+    directive can be used to generate a custom warning message. The
+    configuration parsing is not halted. The typical use it to check
+    whether some user define options are set, and warn if not.</p>
+
+    <highlight language="config">
+# Example
+# tell when ReverseProxy is not set
+&lt;IfDefine !ReverseProxy&gt;
+  Warning "reverse proxy is not started, hope this is okay!"
+&lt;/IfDefine&gt;
+
+&lt;IfDefine ReverseProxy&gt;
+  # define custom proxy configuration
+&lt;/IfDefine&gt;
+    </highlight>
+
+</usage>
+</directivesynopsis>
+
 </modulesynopsis>

Modified: httpd/httpd/trunk/server/config.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/config.c?rev=1418677&r1=1418676&r2=1418677&view=diff
==============================================================================
--- httpd/httpd/trunk/server/config.c (original)
+++ httpd/httpd/trunk/server/config.c Sat Dec  8 14:49:09 2012
@@ -1811,6 +1811,9 @@ AP_DECLARE(const char *) ap_process_reso
 
     if (error) {
         if (parms.err_directive)
+            /* note: this may not be a 'syntactic' error per se.
+             * should it rather be "Configuration error ..."?
+             */
             return apr_psprintf(p, "Syntax error on line %d of %s: %s",
                                 parms.err_directive->line_num,
                                 parms.err_directive->filename, error);

Modified: httpd/httpd/trunk/server/core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core.c?rev=1418677&r1=1418676&r2=1418677&view=diff
==============================================================================
--- httpd/httpd/trunk/server/core.c (original)
+++ httpd/httpd/trunk/server/core.c Sat Dec  8 14:49:09 2012
@@ -1344,23 +1344,48 @@ static const char *unset_define(cmd_parm
     return NULL;
 }
 
-static const char *generate_error(cmd_parms *cmd, void *dummy,
-                                  const char *arg)
+static const char *generate_message(cmd_parms *cmd, void *dummy,
+                                    const char *arg)
 {
+    /* cast with 64-bit warning avoidance */
+    int level = (cmd->info==(void*)APLOG_ERR)? APLOG_ERR: APLOG_WARNING;
+
+    /* expect an argument */
     if (!arg || !*arg) {
-        return "The Error directive was used with no message.";
+        return "The Error or Warning directive was used with no message.";
     }
 
-    if (*arg == '"' || *arg == '\'') { /* strip off quotes */
+    /* set message, strip off quotes if necessary */
+    char * msg = (char *)arg;
+    if (*arg == '"' || *arg == '\'') {
         apr_size_t len = strlen(arg);
         char last = *(arg + len - 1);
 
         if (*arg == last) {
-            return apr_pstrndup(cmd->pool, arg + 1, len - 2);
+            msg = apr_pstrndup(cmd->pool, arg + 1, len - 2);
         }
     }
 
-    return arg;
+    /* get position information from wherever we can? */
+    ap_configfile_t * cf = cmd->config_file;
+    ap_directive_t const * ed1 = cmd->directive;
+    ap_directive_t const * ed2 = cmd->err_directive;
+
+    /* generate error or warning with a configuration file position.
+     * the log is displayed on the terminal as no log file is opened yet.
+     */
+    ap_log_error(APLOG_MARK, APLOG_NOERRNO|level, 0, NULL,
+		 "%s on line %d of %s", msg,
+		 cf? cf->line_number:
+		   ed1? ed1->line_num:
+		     ed2? ed2->line_num: -1,
+		 cf? cf->name:
+		   ed1? ed1->filename:
+		     ed2? ed2->filename: "<UNKNOWN>");
+
+    /* message displayed above, return will stop configuration processing */
+    return level==APLOG_ERR?
+        "Configuration processing stopped by Error directive": NULL;
 }
 
 #ifdef GPROF
@@ -3973,8 +3998,10 @@ AP_INIT_TAKE12("Define", set_define, NUL
               "Define a variable, optionally to a value.  Same as passing -D to the command
line."),
 AP_INIT_TAKE1("UnDefine", unset_define, NULL, EXEC_ON_READ|ACCESS_CONF|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("Error", generate_message, (void*) APLOG_ERR, OR_ALL,
+                 "Generate error message from within configuration."),
+AP_INIT_RAW_ARGS("Warning", generate_message, (void*) APLOG_WARNING, OR_ALL,
+                 "Generate warning message from within configuration."),
 AP_INIT_RAW_ARGS("<If", ifsection, COND_IF, OR_ALL,
   "Container for directives to be conditionally applied"),
 AP_INIT_RAW_ARGS("<ElseIf", ifsection, COND_ELSEIF, OR_ALL,



Mime
View raw message