TS-2323: add class members to BUILD_TABLE_INFO

Add a constructor, destructor and reset() member function to
BUILD_TABLE_INFO.


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

Branch: refs/heads/master
Commit: 3e8668df535563ec50ebf3828b4d9da33f77e464
Parents: 812edfe
Author: James Peach <[email protected]>
Authored: Wed Oct 30 14:54:43 2013 -0700
Committer: James Peach <[email protected]>
Committed: Tue Nov 5 16:46:30 2013 -0800

----------------------------------------------------------------------
 proxy/http/remap/RemapConfig.cc | 34 +++++++++++++++++++++++++++++++++-
 proxy/http/remap/RemapConfig.h  | 11 +++++++++++
 proxy/http/remap/UrlRewrite.cc  | 26 +-------------------------
 3 files changed, 45 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3e8668df/proxy/http/remap/RemapConfig.cc
----------------------------------------------------------------------
diff --git a/proxy/http/remap/RemapConfig.cc b/proxy/http/remap/RemapConfig.cc
index 23b0425..0c6442b 100644
--- a/proxy/http/remap/RemapConfig.cc
+++ b/proxy/http/remap/RemapConfig.cc
@@ -25,6 +25,39 @@
 #include "libts.h"
 #include "HTTP.h"
 
+/**
+  Cleanup *char[] array - each item in array must be allocated via
+  ats_malloc or similar "x..." function.
+
+*/
+static void
+clear_xstr_array(char *v[], size_t vsize)
+{
+  for (unsigned i = 0; i < vsize; i++) {
+    v[i] = (char *)ats_free_null(v[i]);
+  }
+}
+
+BUILD_TABLE_INFO::BUILD_TABLE_INFO()
+  : remap_optflg(0), paramc(0), argc(0)
+{
+  memset(this->paramv, 0, sizeof(this->paramv));
+  memset(this->argv, 0, sizeof(this->argv));
+}
+
+BUILD_TABLE_INFO::~BUILD_TABLE_INFO()
+{
+  this->reset();
+}
+
+void
+BUILD_TABLE_INFO::reset()
+{
+  this->paramc = this->argc = 0;
+  clear_xstr_array(this->paramv, sizeof(this->paramv) / sizeof(char *));
+  clear_xstr_array(this->argv, sizeof(this->argv) / sizeof(char *));
+}
+
 static bool
 is_inkeylist(const char * key, ...)
 {
@@ -50,7 +83,6 @@ is_inkeylist(const char * key, ...)
   return false;
 }
 
-
 static const char *
 parse_define_directive(const char * directive, BUILD_TABLE_INFO * bti, char * 
errbuf, size_t errbufsize)
 {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3e8668df/proxy/http/remap/RemapConfig.h
----------------------------------------------------------------------
diff --git a/proxy/http/remap/RemapConfig.h b/proxy/http/remap/RemapConfig.h
index d0b9fe8..8ba9afb 100644
--- a/proxy/http/remap/RemapConfig.h
+++ b/proxy/http/remap/RemapConfig.h
@@ -41,12 +41,23 @@
 
 struct BUILD_TABLE_INFO
 {
+  BUILD_TABLE_INFO();
+  ~BUILD_TABLE_INFO();
+
   unsigned long remap_optflg;
   int paramc;
   int argc;
   char *paramv[BUILD_TABLE_MAX_ARGS];
   char *argv[BUILD_TABLE_MAX_ARGS];
   acl_filter_rule *rules_list;  // all rules defined in config files as 
.define_filter foobar @src_ip=.....
+
+  // Clear the argument vector.
+  void reset();
+
+private:
+  BUILD_TABLE_INFO(const BUILD_TABLE_INFO&); // disabled
+  BUILD_TABLE_INFO& operator=(const BUILD_TABLE_INFO&); // disabled
+
 };
 
 const char *

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3e8668df/proxy/http/remap/UrlRewrite.cc
----------------------------------------------------------------------
diff --git a/proxy/http/remap/UrlRewrite.cc b/proxy/http/remap/UrlRewrite.cc
index f442ed5..1046eac 100644
--- a/proxy/http/remap/UrlRewrite.cc
+++ b/proxy/http/remap/UrlRewrite.cc
@@ -83,19 +83,6 @@ SetHomePageRedirectFlag(url_mapping *new_mapping, URL 
&new_to_url)
 
   new_mapping->homePageRedirect = (from_path && !to_path) ? true : false;
 }
-/**
-  Cleanup *char[] array - each item in array must be allocated via
-  ats_malloc or similar "x..." function.
-
-*/
-static void
-clear_xstr_array(char *v[], int vsize)
-{
-  if (v && vsize > 0) {
-    for (int i = 0; i < vsize; i++)
-      v[i] = (char *)ats_free_null(v[i]);
-  }
-}
 
 static const char *
 process_filter_opt(url_mapping *mp, BUILD_TABLE_INFO *bti, char *errStrBuf, 
int errStrBufSize)
@@ -687,7 +674,6 @@ UrlRewrite::BuildTable()
   ink_assert(num_rules_redirect_temporary == 0);
   ink_assert(num_rules_forward_with_recv_port == 0);
 
-  memset(&bti, 0, sizeof(bti));
 
   forward_mappings.hash_lookup = 
ink_hash_table_create(InkHashTableKeyType_String);
   reverse_mappings.hash_lookup = 
ink_hash_table_create(InkHashTableKeyType_String);
@@ -695,18 +681,10 @@ UrlRewrite::BuildTable()
   temporary_redirects.hash_lookup = 
ink_hash_table_create(InkHashTableKeyType_String);
   forward_mappings_with_recv_port.hash_lookup = 
ink_hash_table_create(InkHashTableKeyType_String);
 
-  bti.paramc = (bti.argc = 0);
-  memset(bti.paramv, 0, sizeof(bti.paramv));
-  memset(bti.argv, 0, sizeof(bti.argv));
-
   if (!this->_parseRemapConfigFile(config_file_path, &bti)) {
     // XXX handle file reload error
   }
 
-  clear_xstr_array(bti.paramv, sizeof(bti.paramv) / sizeof(char *));
-  clear_xstr_array(bti.argv, sizeof(bti.argv) / sizeof(char *));
-  bti.paramc = (bti.argc = 0);
-
   // Add the mapping for backdoor urls if enabled.
   // This needs to be before the default PAC mapping for ""
   // since this is more specific
@@ -806,9 +784,7 @@ UrlRewrite::_parseRemapConfigFile(const char * 
config_file_path, BUILD_TABLE_INF
 
   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 *));
-    bti->paramc = (bti->argc = 0);
+    bti->reset();
 
     // Strip leading whitespace
     while (*cur_line && isascii(*cur_line) && isspace(*cur_line))

Reply via email to