From ec40c3c1977e2d48c0a0ba88851d396194de271b Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Thu, 9 Mar 2017 08:39:56 +0000 Subject: [PATCH] Add and : * server/core.c (test_ifdirective_section, test_ifsection_section): New callbacks. (core_cmds): Define new directives. * include/http_config.h, server/config.c (ap_exists_directive): New function. * include/ap_mmn.h: Bump MMN minor for above. * docs/manual/mod/core.xml: Add docs. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1786110 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 2 + docs/manual/mod/core.xml | 114 ++++++++++++++++++++++++++++++++++++--- include/ap_mmn.h | 3 +- include/http_config.h | 8 +++ server/config.c | 10 ++++ server/core.c | 17 ++++++ 6 files changed, 147 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 0b083fbb4e..22cf09ff49 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) Add and directives. [Joe Orton] + *) mod_http2: stream timeouts now change to vhost values once the request is parsed and processing starts. Initial values are taken from base server or SNI host as before. [Stefan Eissing] diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index c7f83b10af..8213a83daf 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -788,12 +788,12 @@ DefaultType None -

In its one parameter form, Define is equivalent - to passing the -D argument to httpd. It - can be used to toggle the use of - IfDefine sections - without needing to alter -D arguments in any startup - scripts.

+

In its one parameter form, Define is + equivalent to passing the -D argument to + httpd. It can be used to toggle the use of + IfDefine + sections without needing to alter -D arguments in any + startup scripts.

In addition to that, if the second parameter is given, a config variable is set to this value. The variable can be used in the configuration using @@ -2389,6 +2389,108 @@ presence or absence of a specific module + +IfDirective +Encloses directives that are processed conditional on the +presence or absence of a specific directive +<IfDirective [!]directive-name> ... + </IfDirective> +server configvirtual host +directory.htaccess + +All + + +

The <IfDirective test>...</IfDirective> + section is used to mark directives that are conditional on the presence of + a specific directive. The directives within an IfDirective section are only processed if the test + is true. If test is false, everything between the start and + end markers is ignored.

+ +

The test in the IfDirective section can be one of two forms:

+ +
    +
  • directive-name
  • + +
  • !directive-name
  • +
+ +

In the former case, the directives between the start and end + markers are only processed if a directive of the given name is + available at the time of processing. The second format reverses the test, + and only processes the directives if the directive-name is + not defined.

+ + This section should only be used if you need to have one + configuration file that works across multiple versions of + httpd, regardless of whether a particular + directive is available. In normal operation, directives need not + be placed in IfDirective + sections. +
+IfSection + + + +IfSection +Encloses directives that are processed conditional on the +presence or absence of a specific section directive +<IfSection [!]section-name> ... + </IfSection> +server configvirtual host +directory.htaccess + +All + + +

The <IfSection + test>...</IfSection> section is used + to mark directives that are conditional on the presence of a + specific section directive. A section directive is any directive + such as virtualhost which + encloses other directives, and has a directive name with a leading + "<". The sec + + The directives within an IfSection section are only processed if the test + is true. If test is false, everything between the start and + end markers is ignored.

+ +

The section-name specified must not include the + leading "<". The test in the IfSection section can be one of two + forms:

+ +
    +
  • section-name
  • +
  • !section-name
  • +
+ +

In the former case, the directives between the start and + end markers are only processed if a section directive of the given + name is available at the time of processing. The second format + reverses the test, and only processes the directives if the + section-name is not defined.

+ +

For example:

+ + +<IfSection VirtualHost> + ... +</IfSection> + + + This section should only be used if you need to have one + configuration file that works across multiple versions of httpd, + regardless of whether a particular section directive is + available. In normal operation, directives need not be placed in + IfSection sections. +
+IfDirective +
+ Include Includes other configuration files from within diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 31c9cd7a8a..fa75033f3a 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -550,6 +550,7 @@ * ap_get_http_token() and http_stricturi conf member. * Added ap_scan_vchar_obstext() * 20161018.2 (2.5.0-dev) add ap_set_conn_count() + * 20161018.3 (2.5.0-dev) add ap_exists_directive() */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -557,7 +558,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20161018 #endif -#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 3 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/http_config.h b/include/http_config.h index 2982a8d2e8..582cb243b5 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -991,6 +991,14 @@ AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process); */ AP_DECLARE(void) ap_show_directives(void); +/** + * Returns non-zero if a configuration directive of the given name has + * been registered by a module at the time of calling. + * @param p Pool for temporary allocations + * @param name Directive name + */ +AP_DECLARE(int) ap_exists_directive(apr_pool_t *p, const char *name); + /** * Show the preloaded module names. Used for httpd -l. */ diff --git a/server/config.c b/server/config.c index 8e591dfc7f..5af0e2d2de 100644 --- a/server/config.c +++ b/server/config.c @@ -2668,6 +2668,16 @@ AP_DECLARE(void) ap_show_modules(void) printf(" %s\n", ap_loaded_modules[n]->name); } +AP_DECLARE(int) ap_exists_directive(apr_pool_t *p, const char *name) +{ + char *lname = apr_pstrdup(p, name); + + ap_str_tolower(lname); + + return ap_config_hash && + apr_hash_get(ap_config_hash, lname, APR_HASH_KEY_STRING) != NULL; +} + AP_DECLARE(void *) ap_retained_data_get(const char *key) { void *retained; diff --git a/server/core.c b/server/core.c index a6db948c7a..612f585020 100644 --- a/server/core.c +++ b/server/core.c @@ -2838,6 +2838,17 @@ static int test_iffile_section(cmd_parms *cmd, const char *arg) return (apr_stat(&sb, relative, 0, cmd->pool) == APR_SUCCESS); } +static int test_ifdirective_section(cmd_parms *cmd, const char *arg) +{ + return ap_exists_directive(cmd->temp_pool, arg); +} + +static int test_ifsection_section(cmd_parms *cmd, const char *arg) +{ + const char *name = apr_pstrcat(cmd->temp_pool, "<", arg, NULL); + return ap_exists_directive(cmd->temp_pool, name); +} + /* httpd.conf commands... beginning with the business */ static const char *virtualhost_section(cmd_parms *cmd, void *dummy, @@ -4456,6 +4467,12 @@ AP_INIT_TAKE1("