Updated Branches:
  refs/heads/4.0.x a8002a3b6 -> c1e0681b2

TS-1823: add line continuation to remap.config

Add line continuation to remap.config using a backslash at the end
of a line as the continuation character.

The handling for continuation was made in tokLine() by adding an
optional third char parameter (`cont') which is the continuation
character. This should make it usable in other contexts outside of
remap.config also, for example other config file parsers.

This implementation is not very intelligent, as it only checks for the
backslash immediately preceding the newline and does not handle any
whitespace. The backslash and newline are converted into spaces, and
the next line is appended.

Example:

.definefilter foo \
  @action=allow \
  @src_ip=127.0.0.1

is read and parsed in UrlRewrite::BuildTable() as:

.definefilter foo     @action=allow     @src_ip=127.0.0.1


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

Branch: refs/heads/4.0.x
Commit: bd8d18b59a94ca990ea6235158540a661c7fc114
Parents: a8002a3
Author: Jim Riggs <j...@riggs.me>
Authored: Tue Aug 6 21:06:46 2013 -0500
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Wed Aug 21 10:50:59 2013 -0600

----------------------------------------------------------------------
 CHANGES                        |  6 ++++++
 lib/ts/MatcherUtils.cc         | 19 +++++++++++++------
 lib/ts/MatcherUtils.h          |  2 +-
 proxy/http/remap/UrlRewrite.cc | 10 +++++-----
 4 files changed, 25 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bd8d18b5/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index bca263a..35f799e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,12 @@ Changes with Apache Traffic Server 4.0.0
   *) [TS-2127] Move hostdb.config to var/trafficserver, together with with the
    host.db itself.
 
+  *) [TS-1823] remap.config line continuation support
+    Author: Jim Riggs <j...@riggs.me>
+
+  *) [TS-1597] Document remap.config filters
+    Author: Jim Riggs <j...@riggs.me>
+
   *) [TS-2132, TS-2131] ${libexecdir} and $(localstatedir} chowned
    needlessly chowned to to ATS' user.
    Author: Tomasz Kuzemko <tom...@kuzemko.net>

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bd8d18b5/lib/ts/MatcherUtils.cc
----------------------------------------------------------------------
diff --git a/lib/ts/MatcherUtils.cc b/lib/ts/MatcherUtils.cc
index 3b07a7b..2254738 100644
--- a/lib/ts/MatcherUtils.cc
+++ b/lib/ts/MatcherUtils.cc
@@ -232,16 +232,17 @@ ExtractIpRange(char *match_str, sockaddr* addr1, 
sockaddr* addr2)
   return NULL;
 }
 
-// char* tokLine(char* buf, char** last)
+// char* tokLine(char* buf, char** last, char cont)
 //
 //  Similar to strtok_r but only tokenizes on '\n'
 //   and will return tokens that are empty strings
 //
 char *
-tokLine(char *buf, char **last)
+tokLine(char *buf, char **last, char cont)
 {
   char *start;
   char *cur;
+  char *prev = NULL;
 
   if (buf != NULL) {
     start = cur = buf;
@@ -252,11 +253,17 @@ tokLine(char *buf, char **last)
 
   while (*cur != '\0') {
     if (*cur == '\n') {
-      *cur = '\0';
-      *last = cur;
-      return start;
+      if (cont != '\0' && prev != NULL && *prev == cont) {
+        *prev = ' ';
+        *cur = ' ';
+      }
+      else {
+        *cur = '\0';
+        *last = cur;
+        return start;
+      }
     }
-    cur++;
+    prev = cur++;
   }
 
   // Return the last line even if it does

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bd8d18b5/lib/ts/MatcherUtils.h
----------------------------------------------------------------------
diff --git a/lib/ts/MatcherUtils.h b/lib/ts/MatcherUtils.h
index de390a8..debaebb 100644
--- a/lib/ts/MatcherUtils.h
+++ b/lib/ts/MatcherUtils.h
@@ -64,7 +64,7 @@ inline char const* ExtractIpRange(
   return ExtractIpRange(match_str, ats_ip_sa_cast(addr1), 
ats_ip_sa_cast(addr2));
 }
 
-char *tokLine(char *buf, char **last);
+char *tokLine(char *buf, char **last, char cont = '\0');
 
 const char *processDurationString(char *str, int *seconds);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bd8d18b5/proxy/http/remap/UrlRewrite.cc
----------------------------------------------------------------------
diff --git a/proxy/http/remap/UrlRewrite.cc b/proxy/http/remap/UrlRewrite.cc
index 9bbf466..8b51897 100644
--- a/proxy/http/remap/UrlRewrite.cc
+++ b/proxy/http/remap/UrlRewrite.cc
@@ -1111,7 +1111,7 @@ UrlRewrite::BuildTable()
 
   Debug("url_rewrite", "[BuildTable] UrlRewrite::BuildTable()");
 
-  for (cur_line = tokLine(file_buf, &tok_state); cur_line != NULL;) {
+  for (cur_line = tokLine(file_buf, &tok_state, '\\'); cur_line != NULL;) {
     errStrBuf[0] = 0;
     clear_xstr_array(bti.paramv, sizeof(bti.paramv) / sizeof(char *));
     clear_xstr_array(bti.argv, sizeof(bti.argv) / sizeof(char *));
@@ -1122,7 +1122,7 @@ UrlRewrite::BuildTable()
       ++cur_line;
 
     if ((cur_line_size = strlen((char *) cur_line)) <= 0) {
-      cur_line = tokLine(NULL, &tok_state);
+      cur_line = tokLine(NULL, &tok_state, '\\');
       ++cln;
       continue;
     }
@@ -1135,7 +1135,7 @@ UrlRewrite::BuildTable()
     }
 
     if ((cur_line_size = strlen((char *) cur_line)) <= 0 || *cur_line == '#' 
|| *cur_line == '\0') {
-      cur_line = tokLine(NULL, &tok_state);
+      cur_line = tokLine(NULL, &tok_state, '\\');
       ++cln;
       continue;
     }
@@ -1171,7 +1171,7 @@ UrlRewrite::BuildTable()
         goto MAP_ERROR;
       }
       // We skip the rest of the parsing here.
-      cur_line = tokLine(NULL, &tok_state);
+      cur_line = tokLine(NULL, &tok_state, '\\');
       ++cln;
       continue;
     }
@@ -1483,7 +1483,7 @@ UrlRewrite::BuildTable()
 
     fromHost_lower_ptr = (char *)ats_free_null(fromHost_lower_ptr);
 
-    cur_line = tokLine(NULL, &tok_state);
+    cur_line = tokLine(NULL, &tok_state, '\\');
     ++cln;
     continue;
 

Reply via email to