-*- coding: utf-8 -*-
Changes with Apache 2.5.0
+ *) core: Support named groups and backreferences within the LocationMatch,
+ DirectoryMatch, FilesMatch and ProxyMatch directives. [Graham Leggett]
+
*) mod_authz_user: Support the expression parser within the require
directives. [Graham Leggett]
* 20130924.1 (2.5.0-dev) Add ap_proxy_connection_reusable()
* 20131112.0 (2.5.0-dev) Add parse_errorlog_arg to ap_errorlog_provider
* 20131112.1 (2.5.0-dev) Add suspend_connection and resume_connection hooks
+ * 20131112.2 (2.5.0-dev) Add ap_regname
*/
#define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20131112
#endif
-#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */
/**
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a
AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg,
char *errbuf, apr_size_t errbuf_size);
+/**
+ * Return an array of named regex backreferences
+ * @param preg The precompiled regex
+ * @param names The array to which the names will be added
+ * @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);
+
/** Destroy a pre-compiled regex.
* @param preg The pre-compiled regex to free.
*/
unsigned int allow_encoded_slashes_set : 1;
unsigned int decode_encoded_slashes_set : 1;
+
+ /** Named back references */
+ apr_array_header_t *refs;
+
} core_dir_config;
/* macro to implement off by default behaviour */
*/
const char *proxyname = r->filename + 6;
int j;
+ apr_pool_t *rxpool = NULL;
for (j = 0; j < num_sec; ++j)
{
entry_config = sec_proxy[j];
entry_proxy = ap_get_module_config(entry_config, &proxy_module);
- /* XXX: What about case insensitive matching ???
- * Compare regex, fnmatch or string as appropriate
- * If the entry doesn't relate, then continue
- */
- if (entry_proxy->r
- ? ap_regexec(entry_proxy->r, proxyname, 0, NULL, 0)
- : (entry_proxy->p_is_fnmatch
- ? apr_fnmatch(entry_proxy->p, proxyname, 0)
- : strncmp(proxyname, entry_proxy->p,
- strlen(entry_proxy->p)))) {
+ int nmatch = 0;
+ int i;
+ ap_regmatch_t *pmatch = NULL;
+
+ if (entry_proxy->r) {
+
+ if (entry_proxy->refs && entry_proxy->refs->nelts) {
+ if (!rxpool) {
+ apr_pool_create(&rxpool, r->pool);
+ }
+ nmatch = entry_proxy->refs->nelts;
+ pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
+ }
+
+ if (ap_regexec(entry_proxy->r, proxyname, nmatch, pmatch, 0)) {
+ continue;
+ }
+
+ for (i = 0; i < nmatch; i++) {
+ if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
+ ((const char **)entry_proxy->refs->elts)[i]) {
+ apr_table_setn(r->subprocess_env,
+ ((const char **)entry_proxy->refs->elts)[i],
+ apr_pstrndup(r->pool,
+ proxyname + pmatch[i].rm_so,
+ pmatch[i].rm_eo - pmatch[i].rm_so));
+ }
+ }
+ }
+
+ else if (
+ /* XXX: What about case insensitive matching ???
+ * Compare regex, fnmatch or string as appropriate
+ * If the entry doesn't relate, then continue
+ */
+ entry_proxy->p_is_fnmatch ? apr_fnmatch(entry_proxy->p,
+ proxyname, 0) :
+ strncmp(proxyname, entry_proxy->p,
+ strlen(entry_proxy->p))) {
continue;
}
per_dir_defaults = ap_merge_per_dir_configs(r->pool, per_dir_defaults,
r->per_dir_config = per_dir_defaults;
+ if (rxpool) {
+ apr_pool_destroy(rxpool);
+ }
+
return OK;
}
new->p = add->p;
new->p_is_fnmatch = add->p_is_fnmatch;
new->r = add->r;
+ new->refs = add->refs;
/* Put these in the dir config so they work inside <Location> */
new->raliases = apr_array_append(p, base->raliases, add->raliases);
conf->p = cmd->path;
conf->p_is_fnmatch = apr_fnmatch_test(conf->p);
+ if (r) {
+ conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
+ ap_regname(r, conf->refs, 1);
+ }
+
ap_add_per_proxy_conf(cmd->server, new_dir_conf);
if (*arg != '\0') {
unsigned int error_override_set:1;
unsigned int alias_set:1;
unsigned int add_forwarded_headers:1;
+
+ /** Named back references */
+ apr_array_header_t *refs;
+
} proxy_dir_conf;
/* if we interpolate env vars per-request, we'll need a per-request
conf->d_is_fnmatch = new->d_is_fnmatch;
conf->d_components = new->d_components;
conf->r = new->r;
+ conf->refs = new->refs;
conf->condition = new->condition;
if (new->opts & OPT_UNSET) {
conf->d = cmd->path;
conf->d_is_fnmatch = (apr_fnmatch_test(conf->d) != 0);
+ if (r) {
+ conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
+ ap_regname(r, conf->refs, 1);
+ }
+
/* Make this explicit - the "/" root has 0 elements, that is, we
* will always merge it, and it will always sort and merge first.
* All others are sorted and tested by the number of slashes.
conf->d_is_fnmatch = apr_fnmatch_test(conf->d) != 0;
conf->r = r;
+ if (r) {
+ conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
+ ap_regname(r, conf->refs, 1);
+ }
+
ap_add_per_url_conf(cmd->server, new_url_conf);
if (*arg != '\0') {
conf->d_is_fnmatch = apr_fnmatch_test(conf->d) != 0;
conf->r = r;
+ if (r) {
+ conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
+ ap_regname(r, conf->refs, 1);
+ }
+
ap_add_file_conf(cmd->pool, (core_dir_config *)mconfig, new_file_conf);
if (*arg != '\0') {
apr_size_t buflen;
char *buf;
unsigned int seg, startseg;
+ apr_pool_t *rxpool = NULL;
/* Invariant: from the first time filename_len is set until
* it goes out of scope, filename_len==strlen(r->filename)
*/
for (; sec_idx < num_sec; ++sec_idx) {
+ int nmatch = 0;
+ int i;
+ ap_regmatch_t *pmatch = NULL;
+
core_dir_config *entry_core;
entry_core = ap_get_core_module_config(sec_ent[sec_idx]);
continue;
}
- if (ap_regexec(entry_core->r, r->filename, 0, NULL, 0)) {
+ if (entry_core->refs && entry_core->refs->nelts) {
+ if (!rxpool) {
+ apr_pool_create(&rxpool, r->pool);
+ }
+ nmatch = entry_core->refs->nelts;
+ pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
+ }
+
+ if (ap_regexec(entry_core->r, r->filename, nmatch, pmatch, 0)) {
continue;
}
+ for (i = 0; i < nmatch; i++) {
+ if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
+ ((const char **)entry_core->refs->elts)[i]) {
+ apr_table_setn(r->subprocess_env,
+ ((const char **)entry_core->refs->elts)[i],
+ apr_pstrndup(r->pool,
+ r->filename + pmatch[i].rm_so,
+ pmatch[i].rm_eo - pmatch[i].rm_so));
+ }
+ }
+
/* If we haven't already continue'd above, we have a match.
*
* Calculate our full-context core opts & override.
last_walk->merged = now_merged;
}
+ if (rxpool) {
+ apr_pool_destroy(rxpool);
+ }
+
/* Whoops - everything matched in sequence, but either the original
* walk found some additional matches (which we need to truncate), or
* this walk found some additional matches.
int matches = cache->walked->nelts;
int cached_matches = matches;
walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
+ apr_pool_t *rxpool = NULL;
cached &= auth_internal_per_conf;
cache->cached = entry_uri;
* not slash terminated, then this uri must be slash
* terminated (or at the end of the string) to match.
*/
- if (entry_core->r
- ? ap_regexec(entry_core->r, r->uri, 0, NULL, 0)
- : (entry_core->d_is_fnmatch
+ if (entry_core->r) {
+
+ int nmatch = 0;
+ int i;
+ ap_regmatch_t *pmatch = NULL;
+
+ if (entry_core->refs && entry_core->refs->nelts) {
+ if (!rxpool) {
+ apr_pool_create(&rxpool, r->pool);
+ }
+ nmatch = entry_core->refs->nelts;
+ pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
+ }
+
+ if (ap_regexec(entry_core->r, r->uri, nmatch, pmatch, 0)) {
+ continue;
+ }
+
+ for (i = 0; i < nmatch; i++) {
+ if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
+ ((const char **)entry_core->refs->elts)[i]) {
+ apr_table_setn(r->subprocess_env,
+ ((const char **)entry_core->refs->elts)[i],
+ apr_pstrndup(r->pool,
+ r->uri + pmatch[i].rm_so,
+ pmatch[i].rm_eo - pmatch[i].rm_so));
+ }
+ }
+
+ }
+ else {
+
+ if ((entry_core->d_is_fnmatch
? apr_fnmatch(entry_core->d, cache->cached, APR_FNM_PATHNAME)
: (strncmp(entry_core->d, cache->cached, len)
|| (len > 0
&& entry_core->d[len - 1] != '/'
&& cache->cached[len] != '/'
&& cache->cached[len] != '\0')))) {
- continue;
+ continue;
+ }
+
}
/* If we merged this same section last time, reuse it
last_walk->merged = now_merged;
}
+ if (rxpool) {
+ apr_pool_destroy(rxpool);
+ }
+
/* Whoops - everything matched in sequence, but either the original
* walk found some additional matches (which we need to truncate), or
* this walk found some additional matches.
int matches = cache->walked->nelts;
int cached_matches = matches;
walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
+ apr_pool_t *rxpool = NULL;
cached &= auth_internal_per_conf;
cache->cached = test_file;
core_dir_config *entry_core;
entry_core = ap_get_core_module_config(sec_ent[sec_idx]);
- if (entry_core->r
- ? ap_regexec(entry_core->r, cache->cached , 0, NULL, 0)
- : (entry_core->d_is_fnmatch
- ? apr_fnmatch(entry_core->d, cache->cached, APR_FNM_PATHNAME)
- : strcmp(entry_core->d, cache->cached))) {
- continue;
+ if (entry_core->r) {
+
+ int nmatch = 0;
+ int i;
+ ap_regmatch_t *pmatch = NULL;
+
+ if (entry_core->refs && entry_core->refs->nelts) {
+ if (!rxpool) {
+ apr_pool_create(&rxpool, r->pool);
+ }
+ nmatch = entry_core->refs->nelts;
+ pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
+ }
+
+ if (ap_regexec(entry_core->r, cache->cached, nmatch, pmatch, 0)) {
+ continue;
+ }
+
+ for (i = 0; i < nmatch; i++) {
+ if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
+ ((const char **)entry_core->refs->elts)[i]) {
+ apr_table_setn(r->subprocess_env,
+ ((const char **)entry_core->refs->elts)[i],
+ apr_pstrndup(r->pool,
+ cache->cached + pmatch[i].rm_so,
+ pmatch[i].rm_eo - pmatch[i].rm_so));
+ }
+ }
+
+ }
+ else {
+ if ((entry_core->d_is_fnmatch
+ ? apr_fnmatch(entry_core->d, cache->cached, APR_FNM_PATHNAME)
+ : strcmp(entry_core->d, cache->cached))) {
+ continue;
+ }
}
/* If we merged this same section last time, reuse it
last_walk->merged = now_merged;
}
+ if (rxpool) {
+ apr_pool_destroy(rxpool);
+ }
+
/* Whoops - everything matched in sequence, but either the original
* walk found some additional matches (which we need to truncate), or
* this walk found some additional matches.
#include "httpd.h"
#include "apr_strings.h"
+#include "apr_tables.h"
#include "pcre.h"
#define APR_WANT_STRFUNC
const char *errorptr;
int erroffset;
int errcode = 0;
- int options = 0;
+ int options = PCRE_DUPNAMES;
if ((cflags & AP_REG_ICASE) != 0)
options |= PCRE_CASELESS;
}
}
+AP_DECLARE(int) ap_regname(const ap_regex_t *preg,
+ apr_array_header_t *names, int upper)
+{
+ int namecount;
+ int nameentrysize;
+ int i;
+ char *nametable;
+
+ pcre_fullinfo((const pcre *)preg->re_pcre, NULL,
+ PCRE_INFO_NAMECOUNT, &namecount);
+ pcre_fullinfo((const pcre *)preg->re_pcre, NULL,
+ PCRE_INFO_NAMEENTRYSIZE, &nameentrysize);
+ pcre_fullinfo((const pcre *)preg->re_pcre, NULL,
+ PCRE_INFO_NAMETABLE, &nametable);
+
+ for (i = 0; i < namecount; i++) {
+ const char *offset = nametable + i * nameentrysize;
+ int capture = ((offset[0] << 8) + offset[1]);
+ 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);
+ }
+ else {
+ ((const char **)names->elts)[capture] = offset + 2;
+ }
+ }
+
+ return namecount;
+}
+
/* End of pcreposix.c */