From: Fabien Coelho Date: Sat, 8 Dec 2012 14:49:09 +0000 (+0000) Subject: Add minor 'Warning' directive as defined in current mod_macro. X-Git-Tag: 2.5.0-alpha~6058 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0886d3fcaf821b94f65c92d0907433162e23d948;p=apache 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. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1418677 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index 346da6036e..4e45fded99 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -4419,4 +4419,34 @@ for external processing, e.g. to a CGI script.

+ +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> + + +
+
+ diff --git a/server/config.c b/server/config.c index b8b5033aff..0483ce20cb 100644 --- a/server/config.c +++ b/server/config.c @@ -1811,6 +1811,9 @@ AP_DECLARE(const char *) ap_process_resource_config(server_rec *s, 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); diff --git a/server/core.c b/server/core.c index 279e3e3bd4..1f2aa66654 100644 --- a/server/core.c +++ b/server/core.c @@ -1344,23 +1344,48 @@ 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) +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, NULL, EXEC_ON_READ|ACCESS_CONF|RSRC_CONF, "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("