You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2013/08/08 07:18:36 UTC

git commit: TS-1823: add line continuation to remap.config

Updated Branches:
  refs/heads/master caf79a236 -> 1ddfc042f


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/1ddfc042
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/1ddfc042
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/1ddfc042

Branch: refs/heads/master
Commit: 1ddfc042fc8df6a92dc3c74718451db0a7ec3f93
Parents: caf79a2
Author: Jim Riggs <ji...@riggs.me>
Authored: Tue Aug 6 21:06:46 2013 -0500
Committer: James Peach <jp...@apache.org>
Committed: Wed Aug 7 22:05:30 2013 -0700

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


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1ddfc042/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index e33c204..7065312 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@
 Changes with Apache Traffic Server 3.5.0
 
 
+  *) [TS-1823] remap.config line continuation support
+    Author: Jim Riggs <ji...@riggs.me>
+
   *) [TS-1597] Document remap.config filters
     Author: Jim Riggs <ji...@riggs.me>
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1ddfc042/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/1ddfc042/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/1ddfc042/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;
 


Re: git commit: TS-1823: add line continuation to remap.config

Posted by Igor Galić <i....@brainsware.org>.

----- Original Message -----
> Updated Branches:
>   refs/heads/master caf79a236 -> 1ddfc042f
> 
> 
> 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



This is my new favourite commit message.

> Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
> Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/1ddfc042
> Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/1ddfc042
> Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/1ddfc042
> 
> Branch: refs/heads/master
> Commit: 1ddfc042fc8df6a92dc3c74718451db0a7ec3f93
> Parents: caf79a2
> Author: Jim Riggs <ji...@riggs.me>
> Authored: Tue Aug 6 21:06:46 2013 -0500
> Committer: James Peach <jp...@apache.org>
> Committed: Wed Aug 7 22:05:30 2013 -0700
> 
> ----------------------------------------------------------------------
>  CHANGES                        |  3 +++
>  lib/ts/MatcherUtils.cc         | 19 +++++++++++++------
>  lib/ts/MatcherUtils.h          |  2 +-
>  proxy/http/remap/UrlRewrite.cc | 10 +++++-----
>  4 files changed, 22 insertions(+), 12 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1ddfc042/CHANGES
> ----------------------------------------------------------------------
> diff --git a/CHANGES b/CHANGES
> index e33c204..7065312 100644
> --- a/CHANGES
> +++ b/CHANGES
> @@ -2,6 +2,9 @@
>  Changes with Apache Traffic Server 3.5.0
>  
>  
> +  *) [TS-1823] remap.config line continuation support
> +    Author: Jim Riggs <ji...@riggs.me>
> +
>    *) [TS-1597] Document remap.config filters
>      Author: Jim Riggs <ji...@riggs.me>
>  
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1ddfc042/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/1ddfc042/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/1ddfc042/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;
>  
> 
> 

-- 
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.galic@brainsware.org
URL: http://brainsware.org/
GPG: 6880 4155 74BD FD7C B515  2EA5 4B1D 9E08 A097 C9AE