From: William A. Rowe Jr Date: Thu, 30 Jun 2016 16:59:58 +0000 (+0000) Subject: mod_substitute: Allow to configure the patterns merge order with the new X-Git-Tag: 2.2.32~123 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2701d056827e8c7c60f89b0ed91c6aade0898c6c;p=thirdparty%2Fapache%2Fhttpd.git mod_substitute: Allow to configure the patterns merge order with the new SubstituteInheritBefore on|off directive (with default in 2.2 of 'off) Backports: r1684900, r1687539, r1687680, r1688331, r1688339, r1688340, r1688343, r1697013, r1697015 PR: 57641 Submitted by: [Marc.Stern , Yann Ylavic, William Rowe] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@1750835 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 201260085fb..8e4f62b1a24 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ -*- coding: utf-8 -*- Changes with Apache 2.2.32 + *) mod_substitute: Allow to configure the patterns merge order with the new + SubstituteInheritBefore on|off directive. PR 57641 + [Marc.Stern , Yann Ylavic, William Rowe] + *) abs: Include OPENSSL_Applink when compiling on Windows, to resolve failures under Visual Studio 2015 and other mismatched MSVCRT flavors. PR59630 [Jan Ehrhardt ] diff --git a/STATUS b/STATUS index a92cf1d43f6..0648b7bbc36 100644 --- a/STATUS +++ b/STATUS @@ -149,23 +149,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK: ylavic: while at it, I also included r1678763 which is only an optimization, but allows to keep code in sync with 2.4/trunk. - *) mod_substitute: Configure patterns merge order. PR 57641 - trunk patch: http://svn.apache.org/r1684900 - http://svn.apache.org/r1687539 - http://svn.apache.org/r1687680 - http://svn.apache.org/r1688331 - http://svn.apache.org/r1688339 - http://svn.apache.org/r1688340 - http://svn.apache.org/r1688343 - http://svn.apache.org/r1697013 - http://svn.apache.org/r1697015 - 2.2.x patch: http://home.apache.org/~ylavic/patches/httpd-2.2.x-SubstituteInheritBefore-v5.patch - +1: ylavic, rpluem, wrowe - rpluem: Doesn't that change the previous behaviour if SubstituteInheritBefore is not set? - ylavic: yes thanks, updated to v5 including r1697013 and r1697015, - the diff to v4 is: - http://home.apache.org/~ylavic/patches/httpd-2.2.x-SubstituteInheritBefore-v4_vs_v5.diff - PATCHES PROPOSED TO BACKPORT FROM TRUNK: [ New proposals should be added at the end of the list ] diff --git a/docs/manual/mod/mod_substitute.xml b/docs/manual/mod/mod_substitute.xml index 905e25ac742..de7b4124f73 100644 --- a/docs/manual/mod/mod_substitute.xml +++ b/docs/manual/mod/mod_substitute.xml @@ -93,4 +93,25 @@ + +SubstituteInheritBefore +Change the merge order of inherited patterns +SubstituteInheritBefore on|off +SubstituteInheritBefore off +directory +.htaccess +FileInfo +Available in httpd 2.2.32 and later + + +

Whether to apply the inherited Substitute + patterns first (on), or after the ones of the current + context (off). + SubstituteInheritBefore is itself inherited, + hence contexts that inherit it (those that don't specify their own + SubstituteInheritBefore value) will apply the + closest defined merge order. + + + diff --git a/modules/filters/mod_substitute.c b/modules/filters/mod_substitute.c index faa86ad0b67..fdb90594cd5 100644 --- a/modules/filters/mod_substitute.c +++ b/modules/filters/mod_substitute.c @@ -46,6 +46,7 @@ typedef struct subst_pattern_t { typedef struct { apr_array_header_t *patterns; + int inherit_before; } subst_dir_conf; typedef struct { @@ -59,21 +60,37 @@ typedef struct { static void *create_substitute_dcfg(apr_pool_t *p, char *d) { subst_dir_conf *dcfg = - (subst_dir_conf *) apr_pcalloc(p, sizeof(subst_dir_conf)); + (subst_dir_conf *) apr_palloc(p, sizeof(subst_dir_conf)); dcfg->patterns = apr_array_make(p, 10, sizeof(subst_pattern_t)); + dcfg->inherit_before = -1; return dcfg; } static void *merge_substitute_dcfg(apr_pool_t *p, void *basev, void *overv) { subst_dir_conf *a = - (subst_dir_conf *) apr_pcalloc(p, sizeof(subst_dir_conf)); + (subst_dir_conf *) apr_palloc(p, sizeof(subst_dir_conf)); subst_dir_conf *base = (subst_dir_conf *) basev; subst_dir_conf *over = (subst_dir_conf *) overv; - a->patterns = apr_array_append(p, over->patterns, - base->patterns); + a->inherit_before = (over->inherit_before != -1) + ? over->inherit_before + : base->inherit_before; + /* SubstituteInheritBefore wasn't the default behavior until 2.5.x, + * and may be re-disabled as desired; the original default behavior + * was to apply inherited subst patterns after locally scoped patterns. + * In later 2.2 and 2.4 versions, SubstituteInheritBefore may be toggled + * 'on' to follow the corrected/expected behavior, without violating POLS. + */ + if (a->inherit_before == 1) { + a->patterns = apr_array_append(p, base->patterns, + over->patterns); + } + else { + a->patterns = apr_array_append(p, over->patterns, + base->patterns); + } return a; } @@ -584,6 +601,9 @@ static void register_hooks(apr_pool_t *pool) static const command_rec substitute_cmds[] = { AP_INIT_TAKE1("Substitute", set_pattern, NULL, OR_ALL, "Pattern to filter the response content (s/foo/bar/[inf])"), + AP_INIT_FLAG("SubstituteInheritBefore", ap_set_flag_slot, + (void *)APR_OFFSETOF(subst_dir_conf, inherit_before), OR_FILEINFO, + "Apply inherited patterns before those of the current context"), {NULL} };