httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r989122 - in /httpd/httpd/branches/2.2.x: CHANGES STATUS modules/metadata/mod_headers.c
Date Wed, 25 Aug 2010 14:12:47 GMT
Author: jim
Date: Wed Aug 25 14:12:46 2010
New Revision: 989122

URL: http://svn.apache.org/viewvc?rev=989122&view=rev
Log:
  *) mod_headers: support global replace in Header Edit
       PR 46594 (not 47066 as incorrectly recorded in change log)
            trunk: http://svn.eu.apache.org/viewvc?view=revision&revision=894036
                        http://svn.apache.org/viewvc?view=revision&revision=966059
                             2.2.x: http://people.apache.org/~niq/patches/46594.patch
                                                           (newly updated to fold in r966059)
                                                                +1: niq, rpluem, jim


Modified:
    httpd/httpd/branches/2.2.x/CHANGES
    httpd/httpd/branches/2.2.x/STATUS
    httpd/httpd/branches/2.2.x/modules/metadata/mod_headers.c

Modified: httpd/httpd/branches/2.2.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/CHANGES?rev=989122&r1=989121&r2=989122&view=diff
==============================================================================
--- httpd/httpd/branches/2.2.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.2.x/CHANGES [utf-8] Wed Aug 25 14:12:46 2010
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.2.17
 
+  *) mod_headers: Enable multi-match-and-replace edit option
+     PR 46594 [Nick Kew]
+
   *) mod_log_config: Make ${cookie}C correctly match whole cookie names
      instead of substrings. PR 28037. [Dan Franklin <dan dan-franklin.com>,
      Stefan Fritsch]

Modified: httpd/httpd/branches/2.2.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/STATUS?rev=989122&r1=989121&r2=989122&view=diff
==============================================================================
--- httpd/httpd/branches/2.2.x/STATUS (original)
+++ httpd/httpd/branches/2.2.x/STATUS Wed Aug 25 14:12:46 2010
@@ -87,14 +87,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  *) mod_headers: support global replace in Header Edit
-     PR 46594 (not 47066 as incorrectly recorded in change log)
-     trunk: http://svn.eu.apache.org/viewvc?view=revision&revision=894036
-            http://svn.apache.org/viewvc?view=revision&revision=966059
-     2.2.x: http://people.apache.org/~niq/patches/46594.patch
-                              (newly updated to fold in r966059)
-     +1: niq, rpluem, jim
-
    * Core: fix symlinks ownership tests
      PR 36783
      Trunk patch: http://svn.apache.org/viewvc?view=revision&revision=632947

Modified: httpd/httpd/branches/2.2.x/modules/metadata/mod_headers.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/modules/metadata/mod_headers.c?rev=989122&r1=989121&r2=989122&view=diff
==============================================================================
--- httpd/httpd/branches/2.2.x/modules/metadata/mod_headers.c (original)
+++ httpd/httpd/branches/2.2.x/modules/metadata/mod_headers.c Wed Aug 25 14:12:46 2010
@@ -94,7 +94,8 @@ typedef enum {
     hdr_merge = 'g',            /* merge (merge, but avoid duplicates) */
     hdr_unset = 'u',            /* unset header */
     hdr_echo = 'e',             /* echo headers from request to response */
-    hdr_edit = 'r'              /* change value by regexp */
+    hdr_edit = 'r',             /* change value by regexp, match once */
+    hdr_edit_r = 'R'            /* change value by regexp, everymatch */
 } hdr_actions;
 
 /*
@@ -364,6 +365,7 @@ static char *parse_format_string(apr_poo
     /* No string to parse with unset and echo commands */
     if (hdr->action == hdr_unset ||
         hdr->action == hdr_edit ||
+        hdr->action == hdr_edit_r ||
         hdr->action == hdr_echo) {
         return NULL;
     }
@@ -413,11 +415,13 @@ static APR_INLINE const char *header_ino
         new->action = hdr_echo;
     else if (!strcasecmp(action, "edit"))
         new->action = hdr_edit;
+    else if (!strcasecmp(action, "edit*"))
+        new->action = hdr_edit_r;
     else
         return "first argument must be 'add', 'set', 'append', 'merge', "
-               "'unset', 'echo', or 'edit'.";
+               "'unset', 'echo', 'edit', or 'edit*'.";
 
-    if (new->action == hdr_edit) {
+    if (new->action == hdr_edit || new->action == hdr_edit_r) {
         if (subs == NULL) {
             return "Header edit requires a match and a substitution";
         }
@@ -558,6 +562,7 @@ static const char *process_regexp(header
     unsigned int nmatch = 10;
     ap_regmatch_t pmatch[10];
     const char *subs;
+    const char *remainder;
     char *ret;
     int diffsz;
     if (ap_regexec(hdr->regex, value, nmatch, pmatch, 0)) {
@@ -566,10 +571,17 @@ static const char *process_regexp(header
     }
     subs = ap_pregsub(pool, hdr->subs, value, nmatch, pmatch);
     diffsz = strlen(subs) - (pmatch[0].rm_eo - pmatch[0].rm_so);
+    if (hdr->action == hdr_edit) {
+        remainder = value + pmatch[0].rm_eo;
+    }
+    else { /* recurse to edit multiple matches if applicable */
+        remainder = process_regexp(hdr, value + pmatch[0].rm_eo, pool);
+        diffsz += strlen(remainder) - strlen(value + pmatch[0].rm_eo);
+    }
     ret = apr_palloc(pool, strlen(value) + 1 + diffsz);
     memcpy(ret, value, pmatch[0].rm_so);
     strcpy(ret + pmatch[0].rm_so, subs);
-    strcat(ret, value + pmatch[0].rm_eo);
+    strcat(ret, remainder);
     return ret;
 }
 
@@ -695,6 +707,7 @@ static void do_headers_fixup(request_rec
                          echo_header, (void *) &v, r->headers_in, NULL);
             break;
         case hdr_edit:
+        case hdr_edit_r:
             if (apr_table_get(headers, hdr->header)) {
                 edit_do ed;
 



Mime
View raw message