You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2013/09/23 21:52:22 UTC

[08/20] git commit: TS-2209 add support for lowercasing all substitutions in regex_remap

TS-2209 add support for lowercasing all substitutions in regex_remap


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/2c0ea4e4
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/2c0ea4e4
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/2c0ea4e4

Branch: refs/heads/5.0.x
Commit: 2c0ea4e4805343c06b61ccec224e0b0d671ac260
Parents: 2e4ee7b
Author: Bryan Call <bc...@apache.org>
Authored: Wed Sep 11 16:35:33 2013 -0700
Committer: Bryan Call <bc...@apache.org>
Committed: Wed Sep 11 16:35:33 2013 -0700

----------------------------------------------------------------------
 plugins/regex_remap/README         | 11 ++++++-----
 plugins/regex_remap/regex_remap.cc | 35 +++++++++++++++++++++------------
 2 files changed, 28 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2c0ea4e4/plugins/regex_remap/README
----------------------------------------------------------------------
diff --git a/plugins/regex_remap/README b/plugins/regex_remap/README
index d2e0c3c..2a98102 100644
--- a/plugins/regex_remap/README
+++ b/plugins/regex_remap/README
@@ -100,11 +100,12 @@ on the right hand side:
 You can also provide options, similar to how you configure your
 remap.config. The following options are available
 
-    @status=<nnn>               - Force the response code to <nnn>
-    @active_timeout=<nnn>       - Active timeout (in ms)
-    @no_activity_timeout=<nnn>  - No activity timeout (in ms)
-    @connect_timeout=<nnn>      - Connect timeouts (in ms)
-    @dns_timeout=<nnn>          - Connect timeouts (in ms)
+    @status=<nnn>                   - Force the response code to <nnn>
+    @active_timeout=<nnn>           - Active timeout (in ms)
+    @no_activity_timeout=<nnn>      - No activity timeout (in ms)
+    @connect_timeout=<nnn>          - Connect timeouts (in ms)
+    @dns_timeout=<nnn>              - Connect timeouts (in ms)
+    @lowercase_substitutions=<0|1>  - Turn on lowercasing all the substitutions
 
 
 For example, this can be useful to force a particular response for some

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2c0ea4e4/plugins/regex_remap/regex_remap.cc
----------------------------------------------------------------------
diff --git a/plugins/regex_remap/regex_remap.cc b/plugins/regex_remap/regex_remap.cc
index 13955a1..63778d7 100644
--- a/plugins/regex_remap/regex_remap.cc
+++ b/plugins/regex_remap/regex_remap.cc
@@ -179,6 +179,9 @@ class RemapRegex
         _connect_timeout = atoi(opt_val.c_str());
       } else if (opt.compare(start, 11, "dns_timeout") == 0) {
         _dns_timeout = atoi(opt_val.c_str());
+      } else if (opt.compare(start, 23, "lowercase_substitutions") == 0) {
+        _lowercase_substitutions = atoi(opt_val.c_str());
+        TSDebug(PLUGIN_NAME, "lowercasing %d", _lowercase_substitutions);
       } else {
         TSError("Unknown options: %s", opt.c_str());
       }
@@ -379,7 +382,7 @@ class RemapRegex
   // length of the string as written to dest (not including the trailing '0').
   int
   substitute(char dest[], const char *src, const int ovector[], const int lengths[],
-             TSRemapRequestInfo *rri, UrlComponents *req_url)
+             TSRemapRequestInfo *rri, UrlComponents *req_url, bool lowercase_substitutions)
   {
     if (_num_subs > 0) {
       char* p1 = dest;
@@ -387,6 +390,7 @@ class RemapRegex
       int prev = 0;
 
       for (int i=0; i < _num_subs; i++) {
+        char *start = p1;
         int ix = _sub_ix[i];
 
         memcpy(p1, p2, _sub_pos[i] - prev);
@@ -441,22 +445,20 @@ class RemapRegex
           // If one of the rules fetched a read-only string, copy it in.
           if (str && len > 0) {
             memcpy(p1, str, len);
-            if (ix == SUB_LOWER_PATH) {
-              TSDebug(PLUGIN_NAME, "lowercasing url: %.*s", len, str);
-              char *end = p1 + len;
-              while (p1 <= end) {
-                *p1 = tolower(*p1);
-                p1++;
-              }
-              p1 = end;
-            } else {
-              p1 += len;
-            }
+            p1 += len;
           }
         }
         p2 += (_sub_pos[i] - prev + 2);
         prev = _sub_pos[i] + 2;
+
+        if (lowercase_substitutions == true || ix == SUB_LOWER_PATH) {
+           while (start < p1) {
+             *start = tolower(*start);
+             start++;
+            }
+         }
       }
+
       memcpy(p1, p2, _subst_len - (p2 - _subst));
       p1 += _subst_len - (p2 - _subst);
       *p1 = 0; // Make sure it's NULL terminated (for safety).
@@ -489,6 +491,7 @@ class RemapRegex
   inline int no_activity_timeout_option() const  { return _no_activity_timeout; };
   inline int connect_timeout_option() const  { return _connect_timeout; };
   inline int dns_timeout_option() const  { return _dns_timeout; };
+  inline bool lowercase_substitutions_option() const  { return _lowercase_substitutions; };
 
  private:
   char* _rex_string;
@@ -505,6 +508,7 @@ class RemapRegex
   int _order;
   TSHttpStatus _status;
   bool _simple;
+  bool _lowercase_substitutions;
   int _active_timeout;
   int _no_activity_timeout;
   int _connect_timeout;
@@ -838,6 +842,11 @@ TSRemapDoRemap(void* ih, TSHttpTxn txnp, TSRemapRequestInfo *rri)
         TSDebug(PLUGIN_NAME, "Setting DNS timeout to %d", re->dns_timeout_option());
         TSHttpTxnDNSTimeoutSet(txnp, re->dns_timeout_option());
       }
+      bool lowercase_substitutions = false;
+      if (re->lowercase_substitutions_option() == true) {
+        TSDebug(PLUGIN_NAME, "Setting lowercasing substitutions on");
+        lowercase_substitutions = true;
+      }
 
       // Update profiling if requested
       if (ri->profile) {
@@ -849,7 +858,7 @@ TSRemapDoRemap(void* ih, TSHttpTxn txnp, TSRemapRequestInfo *rri)
         char* dest;
 
         dest = (char*)alloca(new_len+8);
-        dest_len = re->substitute(dest, match_buf, ovector, lengths, rri, &req_url);
+        dest_len = re->substitute(dest, match_buf, ovector, lengths, rri, &req_url, lowercase_substitutions);
 
         TSDebug(PLUGIN_NAME, "New URL is estimated to be %d bytes long, or less", new_len);
         TSDebug(PLUGIN_NAME, "New URL is %s (length %d)", dest, dest_len);