]> granicus.if.org Git - apache/commitdiff
Merge r1684900, r1687539, r1687680, r1688331, r1688339, r1688340, r1688341, r1688343...
authorJim Jagielski <jim@apache.org>
Tue, 6 Oct 2015 12:40:06 +0000 (12:40 +0000)
committerJim Jagielski <jim@apache.org>
Tue, 6 Oct 2015 12:40:06 +0000 (12:40 +0000)
mod_substitute: Fix configuraton merge order.
PR 57641 [Marc.Stern]

mod_substitute: follow up r1684900.
Introduce the SubstituteInheritBefore directive to configure the merge order.
This allows to preserve 2.4 and earlier behaviour.

mod_substitute: follow up to r1687539.
Use tristate single inherit_before variable instead of two, according to
wrowe's advices.

mod_substitute: follow up to r1687680.
Fix dir config merger 'over'-write, thanks Bill (again).

Very difficult to read, and therefore was wrong.

Assert that the SubstituteInheritBefore option was explicitly toggled,
and do not default in 2.x to this legacy behavior.

Optimize in all cases that the members are all explicitly initialized.

Useful for 2.2 and 2.4, but trunk will require the subsequent patch.

Increase legibility of the max_line_length behavior, and adjust for
the requirement that all members are initialized explicitly due to
the previous patch.

Net -8 LoC, my usual specialty.

This didn't need to be reinvented; please use established helpers.

mod_substitute: follow up r1688339.
SubstituteInheritBefore is the default in 2.5.x but wasn't for ealier versions.

mod_substitute: follow up r1697013.
Update the doc.
Submitted by: niq, ylavic, ylavic, ylavic, wrowe, wrowe, wrowe, wrowe, ylavic, ylavic
Reviewed/backported by: jim

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1707039 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
docs/manual/mod/mod_substitute.xml
modules/filters/mod_substitute.c

diff --git a/CHANGES b/CHANGES
index 288b4659120e4fd2d1c1f8542cedfc942a7e34a7..40e8325ab3e96dde8fb70c5e72f6f28bf55ff2c4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,10 @@
 
 Changes with Apache 2.4.17
 
+  *) 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]
+
   *) mod_proxy: Fix ProxySourceAddress binding failure with AH00938.
      PR 56687.  [Arne de Bruijn <apache arbruijn.dds.nl>
 
diff --git a/STATUS b/STATUS
index c2741412fb1b149b7bc2a05be672624b1c9d1f54..d9a86a99060c2eb78806ae7d50edc8b6a7034877 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -110,19 +110,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-   * 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/r1688341
-                  http://svn.apache.org/r1688343
-                  http://svn.apache.org/r1697013
-                  http://svn.apache.org/r1697015
-     2.4.x patch: http://people.apache.org/~ylavic/httpd-2.4.x-SubstituteInheritBefore-v6.patch
-     +1: ylavic, wrowe, rjung
 
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
index 3eb5ed8afea62e30fed90c1ad6894590b26e4594..94757021015bc6095d9c48a8b74365a455a277dd 100644 (file)
@@ -163,4 +163,25 @@ Substitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
 </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.4.17 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>
index 9326348c5292263cbb7cc4440db04e482bca68e1..59f5bf3e32f8d4e60f55a2c467e6d4b39304f059 100644 (file)
@@ -57,6 +57,7 @@ typedef struct {
     apr_array_header_t *patterns;
     apr_size_t max_line_length;
     int max_line_length_set;
+    int inherit_before;
 } subst_dir_conf;
 
 typedef struct {
@@ -70,26 +71,43 @@ 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->max_line_length = AP_SUBST_MAX_LINE_LENGTH;
+    dcfg->max_line_length_set = 0;
+    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);
+    }
     a->max_line_length = over->max_line_length_set ?
-                         over->max_line_length : base->max_line_length;
-    a->max_line_length_set = over->max_line_length_set ?
-                             over->max_line_length_set : base->max_line_length_set;
+                             over->max_line_length : base->max_line_length;
+    a->max_line_length_set = over->max_line_length_set
+                           | base->max_line_length_set;
     return a;
 }
 
@@ -695,6 +713,9 @@ static const command_rec substitute_cmds[] = {
                   "Pattern to filter the response content (s/foo/bar/[inf])"),
     AP_INIT_TAKE1("SubstituteMaxLineLength", set_max_line_length, NULL, OR_FILEINFO,
                   "Maximum line length"),
+    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}
 };