From: Graham Leggett Date: Fri, 3 Jan 2014 22:26:55 +0000 (+0000) Subject: Add a "MATCH_" prefix to variables set within X-Git-Tag: 2.5.0-alpha~4679 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fecd089c47b466a78161adc5e24915bfdd317ad;p=apache Add a "MATCH_" prefix to variables set within LocationMatch/DirectoryMatch/FilesMatch. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1555266 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index 6e3c2ff9c8..0fdbdd63a3 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -887,15 +887,15 @@ the contents of file-system directories matching a regular expression.

From 2.5.0 onwards, named groups and backreferences are captured and - written to the environment with the corresponding name in upper case. - This allows elements of paths to be referenced from within - expressions and modules like + written to the environment with the corresponding name prefixed with + "MATCH_" and in upper case. This allows elements of paths to be referenced + from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.

-<DirectoryMatch ^/var/www/combined/(?<SITENAME>[^/]+)> - require ldap-group cn=%{env:SITENAME},ou=combined,o=Example +<DirectoryMatch ^/var/www/combined/(?<sitename>[^/]+)> + require ldap-group cn=%{env:MATCH_SITENAME},ou=combined,o=Example </DirectoryMatch> @@ -1750,15 +1750,15 @@ filenames

would match most common Internet graphics formats.

From 2.5.0 onwards, named groups and backreferences are captured and - written to the environment with the corresponding name in upper case. - This allows elements of files to be referenced from within - expressions and modules like + written to the environment with the corresponding name prefixed with + "MATCH_" and in upper case. This allows elements of files to be referenced + from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.

-<FileMatch ^(?<SITENAME>[^/]+)> - require ldap-group cn=%{env:SITENAME},ou=combined,o=Example +<FileMatch ^(?<sitename>[^/]+)> + require ldap-group cn=%{env:MATCH_SITENAME},ou=combined,o=Example </FileMatch> @@ -2716,15 +2716,15 @@ matching URLs or /special/data.

From 2.5.0 onwards, named groups and backreferences are captured and - written to the environment with the corresponding name in upper case. - This allows elements of URLs to be referenced from within - expressions and modules like + written to the environment with the corresponding name prefixed with + "MATCH_" and in upper case. This allows elements of URLs to be referenced + from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.

-<LocationMatch ^/combined/(?<SITENAME>[^/]+)> - require ldap-group cn=%{env:SITENAME},ou=combined,o=Example +<LocationMatch ^/combined/(?<sitename>[^/]+)> + require ldap-group cn=%{env:MATCH_SITENAME},ou=combined,o=Example </LocationMatch> diff --git a/docs/manual/mod/mod_proxy.xml b/docs/manual/mod/mod_proxy.xml index cbec774005..8338c2f2c1 100644 --- a/docs/manual/mod/mod_proxy.xml +++ b/docs/manual/mod/mod_proxy.xml @@ -530,15 +530,15 @@ proxied resources using regular expressions.

From 2.5.0 onwards, named groups and backreferences are captured and - written to the environment with the corresponding name in upper case. - This allows elements of URLs to be referenced from within - expressions and modules like + written to the environment with the corresponding name prefixed with + "MATCH_" and in upper case. This allows elements of URLs to be referenced + from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.

-<ProxyMatch ^http://(?<SITENAME>[^/]+)> - require ldap-group cn=%{env:SITENAME},ou=combined,o=Example +<ProxyMatch ^http://(?<sitename>[^/]+)> + require ldap-group cn=%{env:MATCH_SITENAME},ou=combined,o=Example </ProxyMatch> diff --git a/include/ap_regex.h b/include/ap_regex.h index 8f0aedd322..be41226bee 100644 --- a/include/ap_regex.h +++ b/include/ap_regex.h @@ -77,6 +77,8 @@ extern "C" { #define AP_REG_NOMEM 0x20 /* nomem in our code */ #define AP_REG_DOTALL 0x40 /* perl's /s flag */ +#define AP_REG_MATCH "MATCH_" /** suggested prefix for ap_regname */ + /* Error values: */ enum { AP_REG_ASSERT = 1, /** internal error ? */ @@ -156,7 +158,8 @@ AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg, * @param upper If non zero, uppercase the names */ AP_DECLARE(int) ap_regname(const ap_regex_t *preg, - apr_array_header_t *names, int upper); + apr_array_header_t *names, const char *prefix, + int upper); /** Destroy a pre-compiled regex. * @param preg The pre-compiled regex to free. diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index d0bc8c79a5..9279cc81af 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -2275,7 +2275,7 @@ static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg) if (r) { conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *)); - ap_regname(r, conf->refs, 1); + ap_regname(r, conf->refs, AP_REG_MATCH, 1); } ap_add_per_proxy_conf(cmd->server, new_dir_conf); diff --git a/server/core.c b/server/core.c index f7bef0fe09..ff7c43dce0 100644 --- a/server/core.c +++ b/server/core.c @@ -2223,7 +2223,7 @@ static const char *dirsection(cmd_parms *cmd, void *mconfig, const char *arg) if (r) { conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *)); - ap_regname(r, conf->refs, 1); + ap_regname(r, conf->refs, AP_REG_MATCH, 1); } /* Make this explicit - the "/" root has 0 elements, that is, we @@ -2304,7 +2304,7 @@ static const char *urlsection(cmd_parms *cmd, void *mconfig, const char *arg) if (r) { conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *)); - ap_regname(r, conf->refs, 1); + ap_regname(r, conf->refs, AP_REG_MATCH, 1); } ap_add_per_url_conf(cmd->server, new_url_conf); @@ -2391,7 +2391,7 @@ static const char *filesection(cmd_parms *cmd, void *mconfig, const char *arg) if (r) { conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *)); - ap_regname(r, conf->refs, 1); + ap_regname(r, conf->refs, AP_REG_MATCH, 1); } ap_add_file_conf(cmd->pool, (core_dir_config *)mconfig, new_file_conf); diff --git a/server/util_pcre.c b/server/util_pcre.c index 41761487e4..4d2adef25b 100644 --- a/server/util_pcre.c +++ b/server/util_pcre.c @@ -258,7 +258,8 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff, } AP_DECLARE(int) ap_regname(const ap_regex_t *preg, - apr_array_header_t *names, int upper) + apr_array_header_t *names, const char *prefix, + int upper) { int namecount; int nameentrysize; @@ -278,10 +279,14 @@ AP_DECLARE(int) ap_regname(const ap_regex_t *preg, while (names->nelts <= capture) { apr_array_push(names); } - if (upper) { - char *name = ((char **)names->elts)[capture] = - apr_pstrdup(names->pool, offset + 2); - ap_str_toupper(name); + if (upper || prefix) { + char *name = ((char **) names->elts)[capture] = + prefix ? apr_pstrcat(names->pool, prefix, offset + 2, + NULL) : + apr_pstrdup(names->pool, offset + 2); + if (upper) { + ap_str_toupper(name); + } } else { ((const char **)names->elts)[capture] = offset + 2;