Return-Path: X-Original-To: apmail-httpd-cvs-archive@www.apache.org Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A9B61EFEF for ; Sat, 8 Dec 2012 14:49:35 +0000 (UTC) Received: (qmail 99131 invoked by uid 500); 8 Dec 2012 14:49:35 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 99078 invoked by uid 500); 8 Dec 2012 14:49:35 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 99066 invoked by uid 99); 8 Dec 2012 14:49:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Dec 2012 14:49:34 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Dec 2012 14:49:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 18EC023888E4; Sat, 8 Dec 2012 14:49:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: cvs@httpd.apache.org From: fabien@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121208144911.18EC023888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 + +Warning +Warn from configuration parsing with a custom message +Warning message +server configvirtual host +directory.htaccess + +2.5 and later + + +

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.

+ + +# Example +# tell when ReverseProxy is not set +<IfDefine !ReverseProxy> + Warning "reverse proxy is not started, hope this is okay!" +</IfDefine> + +<IfDefine ReverseProxy> + # define custom proxy configuration +</IfDefine> + + +
+
+ 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: ""); + + /* 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("