From 1e45a68c140bc7ba6d6005bd296e1660817d62ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Malo?= Date: Sun, 15 Aug 2004 23:33:28 +0000 Subject: [PATCH] Extend the SetEnvIf directive to capture subexpressions of the matched value. Reviewed by: Paul J. Reder, Jeff Trawick git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@104674 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ STATUS | 7 +------ modules/metadata/mod_setenvif.c | 20 ++++++++++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGES b/CHANGES index b25c8fc727d..6c46685e832 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ Changes with Apache 2.0.51 + *) Extend the SetEnvIf directive to capture subexpressions of the + matched value. [André Malo] + *) Recursive Include directives no longer crash. The server stops including configuration files after a certain nesting level (128 as distributed). This is configurable at compile time using the diff --git a/STATUS b/STATUS index 3951bbcfae8..8af9bcada9e 100644 --- a/STATUS +++ b/STATUS @@ -1,5 +1,5 @@ APACHE 2.0 STATUS: -*-text-*- -Last modified at [$Date: 2004/08/15 22:42:13 $] +Last modified at [$Date: 2004/08/15 23:33:27 $] Release: @@ -290,11 +290,6 @@ PATCHES TO BACKPORT FROM 2.1 -1: brianp (we need a more robust solution than what's in 2.1 right now), jerenkrantz (should be fixed, but I don't have time to do this) - * Extend the SetEnvIf directive to capture subexpressions of the - matched value. - modules/metadata/mod_setenvif.c r1.42, r1.43 - +1: nd, rederpj, trawick - * Allow mod_dav to do weak entity comparison functions. modules/dav/main/util.c: r1.45 [ This one is under review. Don't merge. ] diff --git a/modules/metadata/mod_setenvif.c b/modules/metadata/mod_setenvif.c index 7608871d1b4..cf33c480605 100644 --- a/modules/metadata/mod_setenvif.c +++ b/modules/metadata/mod_setenvif.c @@ -319,8 +319,7 @@ static const char *add_setenvif_core(cmd_parms *cmd, void *mconfig, } else { new->preg = ap_pregcomp(cmd->pool, regex, - (REG_EXTENDED | REG_NOSUB - | (icase ? REG_ICASE : 0))); + (REG_EXTENDED | (icase ? REG_ICASE : 0))); if (new->preg == NULL) { return apr_pstrcat(cmd->pool, cmd->cmd->name, " regex could not be compiled.", NULL); @@ -458,6 +457,7 @@ static int match_headers(request_rec *r) apr_size_t val_len = 0; int i, j; char *last_name; + regmatch_t regm[AP_MAX_REG_MATCH]; if (!ap_get_module_config(r->request_config, &setenvif_module)) { ap_set_module_config(r->request_config, &setenvif_module, @@ -545,7 +545,8 @@ static int match_headers(request_rec *r) } if ((b->pattern && apr_strmatch(b->pattern, val, val_len)) || - (!b->pattern && !ap_regexec(b->preg, val, 0, NULL, 0))) { + (!b->pattern && !ap_regexec(b->preg, val, AP_MAX_REG_MATCH, regm, + 0))) { const apr_array_header_t *arr = apr_table_elts(b->features); elts = (const apr_table_entry_t *) arr->elts; @@ -554,7 +555,18 @@ static int match_headers(request_rec *r) apr_table_unset(r->subprocess_env, elts[j].key); } else { - apr_table_setn(r->subprocess_env, elts[j].key, elts[j].val); + if (!b->pattern) { + char *replaced = ap_pregsub(r->pool, elts[j].val, val, + AP_MAX_REG_MATCH, regm); + if (replaced) { + apr_table_setn(r->subprocess_env, elts[j].key, + replaced); + } + } + else { + apr_table_setn(r->subprocess_env, elts[j].key, + elts[j].val); + } } } } -- 2.47.2