Commit 88b7bb5e authored by William A. Rowe Jr's avatar William A. Rowe Jr
Browse files

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 <Marc.Stern approach.be>, 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
parent bbb60d6a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
                                                         -*- 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 <Marc.Stern approach.be>, 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 <phpdev ehrhardt.nl>]
+0 −17
Original line number Diff line number Diff line
@@ -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 ]
+21 −0
Original line number Diff line number Diff line
@@ -93,4 +93,25 @@
</usage>
</directivesynopsis>

<directivesynopsis>
<name>SubstituteInheritBefore</name>
<description>Change the merge order of inherited patterns</description>
<syntax>SubstituteInheritBefore on|off</syntax>
<default>SubstituteInheritBefore off</default>
<contextlist><context>directory</context>
<context>.htaccess</context></contextlist>
<override>FileInfo</override>
<compatibility>Available in httpd 2.2.32 and later</compatibility>

<usage>
    <p>Whether to apply the inherited <directive>Substitute</directive>
    patterns first (<code>on</code>), or after the ones of the current
    context (<code>off</code>).
    <directive>SubstituteInheritBefore</directive> is itself inherited,
    hence contexts that inherit it (those that don't specify their own
    <directive>SubstituteInheritBefore</directive> value) will apply the
    closest defined merge order.
</usage>
</directivesynopsis>

</modulesynopsis>
+24 −4
Original line number Diff line number Diff line
@@ -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->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}
};