From a9ba1fd2474f04ff65f2c989a489298b795bd52f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Malo?= Date: Fri, 14 Feb 2003 20:04:39 +0000 Subject: [PATCH] Extend the SetEnvIf directive to capture subexpressions of the matched value. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@98659 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ modules/metadata/mod_setenvif.c | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 43891fbed6..2a9d220374 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) Extend the SetEnvIf directive to capture subexpressions of the + matched value. [André Malo] + *) Updated mod_ldap and mod_auth_ldap to support the Novell LDAP SDK and standardized the LDAP SSL support across the various LDAP SDKs. Isolated the SSL functionality to mod_ldap rather than speading it diff --git a/modules/metadata/mod_setenvif.c b/modules/metadata/mod_setenvif.c index 37c028d7a1..6b2d033967 100644 --- a/modules/metadata/mod_setenvif.c +++ b/modules/metadata/mod_setenvif.c @@ -351,8 +351,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); @@ -490,6 +489,7 @@ static int match_headers(request_rec *r) apr_size_t val_len = 0; int i, j; char *last_name; + regmatch_t regm[10]; if (!ap_get_module_config(r->request_config, &setenvif_module)) { ap_set_module_config(r->request_config, &setenvif_module, @@ -577,7 +577,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, b->preg->re_nsub + 1, + regm, 0))) { const apr_array_header_t *arr = apr_table_elts(b->features); elts = (const apr_table_entry_t *) arr->elts; @@ -586,7 +587,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, + b->preg->re_nsub + 1, 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.50.1