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 2016/06/27 18:07:47 UTC

[trafficserver] 01/02: TS-4449 Cleanup of coding style

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 56c0a6755398f283a11f4fc9f8581d3258b09524
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Tue May 17 12:20:32 2016 -0600

    TS-4449 Cleanup of coding style
---
 plugins/header_rewrite/condition.h       | 10 ++++---
 plugins/header_rewrite/conditions.cc     | 18 ++++++++-----
 plugins/header_rewrite/conditions.h      | 46 +++++++++++++++++---------------
 plugins/header_rewrite/expander.cc       |  6 +++--
 plugins/header_rewrite/header_rewrite.cc |  3 ++-
 plugins/header_rewrite/matcher.h         |  9 ++++++-
 plugins/header_rewrite/operator.cc       |  3 ++-
 plugins/header_rewrite/operator.h        | 10 +++----
 plugins/header_rewrite/operators.cc      |  3 ++-
 plugins/header_rewrite/parser.cc         |  5 ++--
 plugins/header_rewrite/parser.h          |  4 +++
 plugins/header_rewrite/regex_helper.cc   |  3 ++-
 plugins/header_rewrite/regex_helper.h    |  6 +++--
 plugins/header_rewrite/resources.cc      |  6 +++--
 plugins/header_rewrite/ruleset.cc        |  5 ++--
 plugins/header_rewrite/ruleset.h         |  5 ++--
 plugins/header_rewrite/statement.cc      |  5 ++--
 plugins/header_rewrite/statement.h       |  5 +++-
 plugins/header_rewrite/value.h           |  4 +++
 19 files changed, 101 insertions(+), 55 deletions(-)

diff --git a/plugins/header_rewrite/condition.h b/plugins/header_rewrite/condition.h
index 41a723d..84a9e04 100644
--- a/plugins/header_rewrite/condition.h
+++ b/plugins/header_rewrite/condition.h
@@ -59,18 +59,20 @@ public:
   {
     bool rt = eval(res);
 
-    if (_mods & COND_NOT)
+    if (_mods & COND_NOT) {
       rt = !rt;
+    }
 
     if (_next) {
       if (_mods & COND_OR) {
         return rt || (static_cast<Condition *>(_next)->do_eval(res));
       } else { // AND is the default
         // Short circuit if we're an AND and the first condition is FALSE.
-        if (rt)
+        if (rt) {
           return static_cast<Condition *>(_next)->do_eval(res);
-        else
+        } else {
           return false;
+        }
       }
     } else {
       return rt;
@@ -98,11 +100,13 @@ public:
   {
     return _matcher;
   }
+
   const MatcherOps
   get_cond_op() const
   {
     return _cond_op;
   }
+
   const std::string
   get_qualifier() const
   {
diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc
index d76e91f..d3e4afa 100644
--- a/plugins/header_rewrite/conditions.cc
+++ b/plugins/header_rewrite/conditions.cc
@@ -272,8 +272,9 @@ ConditionPath::append_value(std::string &s, const Resources &res)
     int path_length;
     const char *path = TSUrlPathGet(bufp, url_loc, &path_length);
 
-    if (path && path_length)
+    if (path && path_length) {
       s.append(path, path_length);
+    }
 
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc);
   }
@@ -434,8 +435,9 @@ ConditionDBM::append_value(std::string & /* s ATS_UNUSED */, const Resources & /
 {
   // std::string key;
 
-  // if (!_dbm)
+  // if (!_dbm) {
   //   return;
+  // }
 
   // _key.append_value(key, res);
   // if (key.size() > 0) {
@@ -495,23 +497,27 @@ ConditionCookie::append_value(std::string &s, const Resources &res)
   const int cookie_name_len     = _qualifier.length();
 
   // Sanity
-  if (bufp == NULL || hdr_loc == NULL)
+  if (bufp == NULL || hdr_loc == NULL) {
     return;
+  }
 
   // Find Cookie
   field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_COOKIE, TS_MIME_LEN_COOKIE);
-  if (field_loc == NULL)
+  if (field_loc == NULL) {
     return;
+  }
 
   // Get all cookies
   cookies = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, -1, &cookies_len);
-  if (cookies == NULL || cookies_len <= 0)
+  if (cookies == NULL || cookies_len <= 0) {
     goto out_release_field;
+  }
 
   // Find particular cookie's value
   error = get_cookie_value(cookies, cookies_len, cookie_name, cookie_name_len, &cookie_value, &cookie_value_len);
-  if (error == TS_ERROR)
+  if (error == TS_ERROR) {
     goto out_release_field;
+  }
 
   TSDebug(PLUGIN_NAME, "Appending COOKIE(%s) to evaluation value -> %.*s", cookie_name, cookie_value_len, cookie_value);
   s.append(cookie_value, cookie_value_len);
diff --git a/plugins/header_rewrite/conditions.h b/plugins/header_rewrite/conditions.h
index d6a195a..e733147 100644
--- a/plugins/header_rewrite/conditions.h
+++ b/plugins/header_rewrite/conditions.h
@@ -173,27 +173,31 @@ private:
     const char *start, *last, *end;
 
     // Sanity
-    if (buf == NULL || name == NULL || value == NULL || value_len == NULL)
+    if (buf == NULL || name == NULL || value == NULL || value_len == NULL) {
       return TS_ERROR;
+    }
 
     start = buf;
     end   = buf + buf_len;
 
     while (start < end) {
-      if (strncasecmp(start, name, name_len) != 0)
+      if (strncasecmp(start, name, name_len) != 0) {
         goto skip;
+      }
 
-      for (start += name_len; start < end && *start == ' '; start++)
-        ;
+      for (start += name_len; start < end && *start == ' '; start++) {
+      }
 
-      if (start == end || *start++ != '=')
+      if (start == end || *start++ != '=') {
         goto skip;
+      }
 
       while (start < end && *start == ' ') {
         start++;
       }
-      for (last = start; last < end && *last != ';'; last++)
-        ;
+
+      for (last = start; last < end && *last != ';'; last++) {
+      }
 
       *value_len = last - start;
       *value     = start;
@@ -201,15 +205,16 @@ private:
     skip:
       while (start < end) {
         char ch = *start++;
-        if (ch == ';' || ch == ',')
+        if (ch == ';' || ch == ',') {
           break;
+        }
       }
       while (start < end && *start == ' ') {
         start++;
       }
     }
     return TS_ERROR;
-  };
+  }
 };
 
 // header
@@ -219,7 +224,7 @@ public:
   explicit ConditionHeader(bool client = false) : _client(client)
   {
     TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionHeader, client %d", client);
-  };
+  }
 
   void initialize(Parser &p);
   void append_value(std::string &s, const Resources &res);
@@ -237,7 +242,7 @@ private:
 class ConditionPath : public Condition
 {
 public:
-  explicit ConditionPath() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionPath"); };
+  explicit ConditionPath() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionPath"); }
   void initialize(Parser &p);
   void append_value(std::string &s, const Resources &res);
 
@@ -252,7 +257,7 @@ private:
 class ConditionQuery : public Condition
 {
 public:
-  explicit ConditionQuery() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionQuery"); };
+  explicit ConditionQuery() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionQuery"); }
   void initialize(Parser &p);
   void append_value(std::string &s, const Resources &res);
 
@@ -272,7 +277,7 @@ public:
   explicit ConditionUrl(const UrlType type) : _url_qual(URL_QUAL_NONE), _type(type)
   {
     TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionUrl");
-  };
+  }
 
   void initialize(Parser &p);
   void set_qualifier(const std::string &q);
@@ -316,7 +321,6 @@ protected:
 
 private:
   DISALLOW_COPY_AND_ASSIGN(ConditionDBM);
-
   // MDBM* _dbm;
   std::string _file;
   Value _key;
@@ -380,7 +384,7 @@ private:
 class ConditionNow : public Condition
 {
 public:
-  explicit ConditionNow() : _now_qual(NOW_QUAL_EPOCH) { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionNow"); };
+  explicit ConditionNow() : _now_qual(NOW_QUAL_EPOCH) { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionNow"); }
   void initialize(Parser &p);
   void set_qualifier(const std::string &q);
   void append_value(std::string &s, const Resources &res);
@@ -389,9 +393,9 @@ protected:
   bool eval(const Resources &res);
 
 private:
-  int64_t get_now_qualified(NowQualifiers qual) const;
-
   DISALLOW_COPY_AND_ASSIGN(ConditionNow);
+
+  int64_t get_now_qualified(NowQualifiers qual) const;
   NowQualifiers _now_qual;
 };
 
@@ -402,7 +406,7 @@ public:
   explicit ConditionGeo() : _geo_qual(GEO_QUAL_COUNTRY), _int_type(false)
   {
     TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionGeo");
-  };
+  }
 
   void initialize(Parser &p);
   void set_qualifier(const std::string &q);
@@ -414,6 +418,7 @@ public:
   {
     return _int_type;
   }
+
   void
   is_int_type(bool flag)
   {
@@ -424,11 +429,10 @@ protected:
   bool eval(const Resources &res);
 
 private:
-  int64_t get_geo_int(const sockaddr *addr) const;
-  const char *get_geo_string(const sockaddr *addr) const;
-
   DISALLOW_COPY_AND_ASSIGN(ConditionGeo);
 
+  int64_t get_geo_int(const sockaddr *addr) const;
+  const char *get_geo_string(const sockaddr *addr) const;
   GeoQualifiers _geo_qual;
   bool _int_type;
 };
diff --git a/plugins/header_rewrite/expander.cc b/plugins/header_rewrite/expander.cc
index 8c5238d..22dca9c 100644
--- a/plugins/header_rewrite/expander.cc
+++ b/plugins/header_rewrite/expander.cc
@@ -40,12 +40,14 @@ VariableExpander::expand(const Resources &res)
 
   while (true) {
     std::string::size_type start = result.find("%<");
-    if (start == std::string::npos)
+    if (start == std::string::npos) {
       break;
+    }
 
     std::string::size_type end = result.find(">", start);
-    if (end == std::string::npos)
+    if (end == std::string::npos) {
       break;
+    }
 
     std::string first_part = result.substr(0, start);
     std::string last_part  = result.substr(end + 1);
diff --git a/plugins/header_rewrite/header_rewrite.cc b/plugins/header_rewrite/header_rewrite.cc
index cb90018..b5e2edb 100644
--- a/plugins/header_rewrite/header_rewrite.cc
+++ b/plugins/header_rewrite/header_rewrite.cc
@@ -103,8 +103,9 @@ public:
   void
   release()
   {
-    if (1 >= ink_atomic_decrement(&_ref_count, 1))
+    if (1 >= ink_atomic_decrement(&_ref_count, 1)) {
       delete this;
+    }
   }
 
 private:
diff --git a/plugins/header_rewrite/matcher.h b/plugins/header_rewrite/matcher.h
index 4340a88..a388955 100644
--- a/plugins/header_rewrite/matcher.h
+++ b/plugins/header_rewrite/matcher.h
@@ -56,11 +56,13 @@ public:
   {
     _pdata = pdata;
   }
+
   void *
   get_pdata() const
   {
     return _pdata;
   }
+
   virtual void
   free_pdata()
   {
@@ -103,6 +105,7 @@ public:
   {
     return;
   }
+
   void
   setRegex(const TSHttpStatus /* t ATS_UNUSED */)
   {
@@ -113,8 +116,9 @@ public:
   set(const T d)
   {
     _data = d;
-    if (_op == MATCH_REGULAR_EXPRESSION)
+    if (_op == MATCH_REGULAR_EXPRESSION) {
       setRegex(d);
+    }
   }
 
   // Evaluate this matcher
@@ -149,12 +153,14 @@ private:
     // std::cout << "Testing: " << t << " == " << _data << std::endl;
     return t == _data;
   }
+
   bool
   test_lt(const T t) const
   {
     // std::cout << "Testing: " << t << " < " << _data << std::endl;
     return t < _data;
   }
+
   bool
   test_gt(const T t) const
   {
@@ -187,6 +193,7 @@ private:
     }
     return false;
   }
+
   T _data;
   regexHelper helper;
 };
diff --git a/plugins/header_rewrite/operator.cc b/plugins/header_rewrite/operator.cc
index 8368210..30de38d 100644
--- a/plugins/header_rewrite/operator.cc
+++ b/plugins/header_rewrite/operator.cc
@@ -26,8 +26,9 @@
 const OperModifiers
 Operator::get_oper_modifiers() const
 {
-  if (_next)
+  if (_next) {
     return static_cast<OperModifiers>(_mods | static_cast<Operator *>(_next)->get_oper_modifiers());
+  }
 
   return _mods;
 }
diff --git a/plugins/header_rewrite/operator.h b/plugins/header_rewrite/operator.h
index 88f59c2..c20ce63 100644
--- a/plugins/header_rewrite/operator.h
+++ b/plugins/header_rewrite/operator.h
@@ -45,18 +45,18 @@ class Operator : public Statement
 {
 public:
   Operator() : _mods(OPER_NONE) { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Operator"); }
+  const OperModifiers get_oper_modifiers() const;
+  virtual void initialize(Parser &p);
+
   void
   do_exec(const Resources &res) const
   {
     exec(res);
-    if (NULL != _next)
+    if (NULL != _next) {
       static_cast<Operator *>(_next)->do_exec(res);
+    }
   }
 
-  const OperModifiers get_oper_modifiers() const;
-
-  virtual void initialize(Parser &p);
-
 protected:
   virtual void exec(const Resources &res) const = 0;
 
diff --git a/plugins/header_rewrite/operators.cc b/plugins/header_rewrite/operators.cc
index 7b02899..3920797 100644
--- a/plugins/header_rewrite/operators.cc
+++ b/plugins/header_rewrite/operators.cc
@@ -612,8 +612,9 @@ void
 OperatorCounter::exec(const Resources & /* ATS_UNUSED res */) const
 {
   // Sanity
-  if (_counter == TS_ERROR)
+  if (_counter == TS_ERROR) {
     return;
+  }
 
   TSDebug(PLUGIN_NAME, "OperatorCounter::exec() invoked on counter %s", _counter_name.c_str());
   TSStatIntIncrement(_counter, 1);
diff --git a/plugins/header_rewrite/parser.cc b/plugins/header_rewrite/parser.cc
index 6069927..9e109ec 100644
--- a/plugins/header_rewrite/parser.cc
+++ b/plugins/header_rewrite/parser.cc
@@ -139,10 +139,11 @@ Parser::preprocess(std::vector<std::string> tokens)
     _op = tokens[0];
     if (tokens.size() > 1) {
       _arg = tokens[1];
-      if (tokens.size() > 2)
+      if (tokens.size() > 2) {
         _val = tokens[2];
-      else
+      } else {
         _val = "";
+      }
     } else {
       _arg = "";
       _val = "";
diff --git a/plugins/header_rewrite/parser.h b/plugins/header_rewrite/parser.h
index 7f1d1a7..44dcc8c 100644
--- a/plugins/header_rewrite/parser.h
+++ b/plugins/header_rewrite/parser.h
@@ -40,6 +40,7 @@ public:
   {
     return _empty;
   }
+
   bool
   is_cond() const
   {
@@ -51,6 +52,7 @@ public:
   {
     return _cond && (_op == s);
   }
+
   bool
   oper_op_is(const std::string s) const
   {
@@ -62,11 +64,13 @@ public:
   {
     return _op;
   }
+
   std::string &
   get_arg()
   {
     return _arg;
   }
+
   const std::string &
   get_value() const
   {
diff --git a/plugins/header_rewrite/regex_helper.cc b/plugins/header_rewrite/regex_helper.cc
index f399fdf..8335c84 100644
--- a/plugins/header_rewrite/regex_helper.cc
+++ b/plugins/header_rewrite/regex_helper.cc
@@ -34,8 +34,9 @@ regexHelper::setRegexMatch(const std::string &s)
   if ((regexExtra == NULL) && (errorStudy != 0)) {
     return false;
   }
-  if (pcre_fullinfo(regex, regexExtra, PCRE_INFO_CAPTURECOUNT, &regexCcount) != 0)
+  if (pcre_fullinfo(regex, regexExtra, PCRE_INFO_CAPTURECOUNT, &regexCcount) != 0) {
     return false;
+  }
   return true;
 }
 
diff --git a/plugins/header_rewrite/regex_helper.h b/plugins/header_rewrite/regex_helper.h
index 0307c5f..b4dcc04 100644
--- a/plugins/header_rewrite/regex_helper.h
+++ b/plugins/header_rewrite/regex_helper.h
@@ -36,11 +36,13 @@ public:
   regexHelper() : regex(NULL), regexExtra(NULL), regexCcount(0) {}
   ~regexHelper()
   {
-    if (regex)
+    if (regex) {
       pcre_free(regex);
+    }
 
-    if (regexExtra)
+    if (regexExtra) {
       pcre_free(regexExtra);
+    }
   }
 
   bool setRegexMatch(const std::string &s);
diff --git a/plugins/header_rewrite/resources.cc b/plugins/header_rewrite/resources.cc
index 6d6321a..b6bb2c7 100644
--- a/plugins/header_rewrite/resources.cc
+++ b/plugins/header_rewrite/resources.cc
@@ -110,13 +110,15 @@ void
 Resources::destroy()
 {
   if (bufp) {
-    if (hdr_loc)
+    if (hdr_loc) {
       TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
+    }
   }
 
   if (client_bufp && (client_bufp != bufp)) {
-    if (client_hdr_loc && (client_hdr_loc != hdr_loc)) // TODO: Is this check really necessary?
+    if (client_hdr_loc && (client_hdr_loc != hdr_loc)) { // TODO: Is this check really necessary?
       TSHandleMLocRelease(client_bufp, TS_NULL_MLOC, client_hdr_loc);
+    }
   }
 
   _ready = false;
diff --git a/plugins/header_rewrite/ruleset.cc b/plugins/header_rewrite/ruleset.cc
index 939e9bb..e7cf82e 100644
--- a/plugins/header_rewrite/ruleset.cc
+++ b/plugins/header_rewrite/ruleset.cc
@@ -34,8 +34,9 @@ RuleSet::append(RuleSet *rule)
 
   TSReleaseAssert(rule->next == NULL);
 
-  while (tmp->next)
-    tmp     = tmp->next;
+  while (tmp->next) {
+    tmp = tmp->next;
+  }
   tmp->next = rule;
 }
 
diff --git a/plugins/header_rewrite/ruleset.h b/plugins/header_rewrite/ruleset.h
index dd67ffa..514abe6 100644
--- a/plugins/header_rewrite/ruleset.h
+++ b/plugins/header_rewrite/ruleset.h
@@ -47,14 +47,15 @@ public:
 
   // No reason to inline these
   void append(RuleSet *rule);
-
   void add_condition(Parser &p);
   void add_operator(Parser &p);
+
   bool
   has_operator() const
   {
     return NULL != _oper;
   }
+
   bool
   has_condition() const
   {
@@ -66,13 +67,13 @@ public:
   {
     _hook = hook;
   }
+
   const TSHttpHookID
   get_hook() const
   {
     return _hook;
   }
 
-  // Inline
   const ResourceIDs
   get_all_resource_ids() const
   {
diff --git a/plugins/header_rewrite/statement.cc b/plugins/header_rewrite/statement.cc
index 59e76ac..d6d4458 100644
--- a/plugins/header_rewrite/statement.cc
+++ b/plugins/header_rewrite/statement.cc
@@ -27,8 +27,9 @@ Statement::append(Statement *stmt)
   Statement *tmp = this;
 
   TSReleaseAssert(stmt->_next == NULL);
-  while (tmp->_next)
-    tmp      = tmp->_next;
+  while (tmp->_next) {
+    tmp = tmp->_next;
+  }
   tmp->_next = stmt;
 }
 
diff --git a/plugins/header_rewrite/statement.h b/plugins/header_rewrite/statement.h
index b8dda6c..1f10de5 100644
--- a/plugins/header_rewrite/statement.h
+++ b/plugins/header_rewrite/statement.h
@@ -84,11 +84,13 @@ public:
   {
     _pdata = pdata;
   }
+
   void *
   get_pdata() const
   {
     return (_pdata);
   }
+
   virtual void
   free_pdata()
   {
@@ -118,11 +120,12 @@ public:
 
   virtual void
   initialize(Parser &)
-  { // Parser &p
+  {
     TSReleaseAssert(_initialized == false);
     initialize_hooks();
     _initialized = true;
   }
+
   bool
   initialized() const
   {
diff --git a/plugins/header_rewrite/value.h b/plugins/header_rewrite/value.h
index 62591c0..a9507ca 100644
--- a/plugins/header_rewrite/value.h
+++ b/plugins/header_rewrite/value.h
@@ -82,16 +82,19 @@ public:
   {
     return _value;
   }
+
   size_t
   size() const
   {
     return _value.size();
   }
+
   int
   get_int_value() const
   {
     return _int_value;
   }
+
   double
   get_float_value() const
   {
@@ -103,6 +106,7 @@ public:
   {
     return _value.empty();
   }
+
   bool
   need_expansion() const
   {

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.