TS-2316: header_rewrite: unify style Submitted by: Alexey Ivanov <[email protected]> Sponsored by: LinkedIn
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/f1ea0d7c Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/f1ea0d7c Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/f1ea0d7c Branch: refs/heads/5.0.x Commit: f1ea0d7ca95d03c2676ff12e764aa8702bb46bdc Parents: d314e59 Author: Alexey Ivanov <[email protected]> Authored: Sat Nov 2 19:33:07 2013 -0700 Committer: Alexey Ivanov <[email protected]> Committed: Sun Nov 10 18:07:53 2013 -0800 ---------------------------------------------------------------------- plugins/header_rewrite/condition.cc | 10 +++++----- plugins/header_rewrite/conditions.cc | 15 ++++++++++----- plugins/header_rewrite/conditions.h | 14 +------------- plugins/header_rewrite/factory.cc | 14 +++++++------- plugins/header_rewrite/matcher.h | 21 ++++++++++++++------- plugins/header_rewrite/operator.cc | 9 ++++++--- plugins/header_rewrite/operator.h | 2 +- plugins/header_rewrite/operators.cc | 9 ++++++--- plugins/header_rewrite/regex_helper.h | 3 ++- plugins/header_rewrite/ruleset.cc | 9 ++++++--- plugins/header_rewrite/ruleset.h | 12 ++++++++---- plugins/header_rewrite/statement.cc | 9 ++++++--- 12 files changed, 72 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/condition.cc ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/condition.cc b/plugins/header_rewrite/condition.cc index d7c05eb..bcece21 100644 --- a/plugins/header_rewrite/condition.cc +++ b/plugins/header_rewrite/condition.cc @@ -30,20 +30,20 @@ parse_matcher_op(std::string& arg) { switch (arg[0]) { case '=': - arg.erase(0,1); + arg.erase(0, 1); return MATCH_EQUAL; break; case '<': - arg.erase(0,1); + arg.erase(0, 1); return MATCH_LESS_THEN; break; case '>': - arg.erase(0,1); + arg.erase(0, 1); return MATCH_GREATER_THEN; break; case '/': - arg.erase(0,1); - arg.erase(arg.length() -1 , arg.length()); + arg.erase(0, 1); + arg.erase(arg.length() - 1, arg.length()); return MATCH_REGULAR_EXPRESSION; break; default: http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/conditions.cc ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index 6faac6f..173f94e 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -46,21 +46,24 @@ ConditionStatus::initialize(Parser& p) void -ConditionStatus::initialize_hooks() { +ConditionStatus::initialize_hooks() +{ add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK); add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK); } bool -ConditionStatus::eval(const Resources& res) { +ConditionStatus::eval(const Resources& res) +{ TSDebug(PLUGIN_NAME, "Evaluating STATUS()"); // TODO: It'd be nice to get the args here ... return static_cast<const Matchers<TSHttpStatus>*>(_matcher)->test(res.resp_status); } void -ConditionStatus::append_value(std::string& s, const Resources& res) { +ConditionStatus::append_value(std::string& s, const Resources& res) +{ s += boost::lexical_cast<std::string>(res.resp_status); TSDebug(PLUGIN_NAME, "Appending STATUS(%d) to evaluation value -> %s", res.resp_status, s.c_str()); } @@ -86,7 +89,8 @@ ConditionRandom::initialize(Parser& p) bool -ConditionRandom::eval(const Resources& /* res ATS_UNUSED */) { +ConditionRandom::eval(const Resources& /* res ATS_UNUSED */) +{ TSDebug(PLUGIN_NAME, "Evaluating RANDOM(%d)", _max); return static_cast<const Matchers<unsigned int>*>(_matcher)->test(rand_r(&_seed) % _max); } @@ -288,7 +292,8 @@ ConditionUrl::initialize(Parser& /* p ATS_UNUSED */) void -ConditionUrl::set_qualifier(const std::string& q) { +ConditionUrl::set_qualifier(const std::string& q) +{ Condition::set_qualifier(q); _url_qual = parse_url_qualifier(q); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/conditions.h ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/conditions.h b/plugins/header_rewrite/conditions.h index 904533d..1123100 100644 --- a/plugins/header_rewrite/conditions.h +++ b/plugins/header_rewrite/conditions.h @@ -188,19 +188,7 @@ private: }; - - - - - - - - - - - - - +// query class ConditionQuery : public Condition { public: http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/factory.cc ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/factory.cc b/plugins/header_rewrite/factory.cc index d7f0d6d..7810c8c 100644 --- a/plugins/header_rewrite/factory.cc +++ b/plugins/header_rewrite/factory.cc @@ -54,7 +54,7 @@ operator_factory(const std::string& op) } else if (op == "no-op") { o = new OperatorNoOp(); } else { - TSError("%s:unknown operator in header_rewrite: %s", PLUGIN_NAME, op.c_str()); + TSError("%s: unknown operator: %s", PLUGIN_NAME, op.c_str()); return NULL; } @@ -89,20 +89,20 @@ condition_factory(const std::string& cond) c = new ConditionAccess(); } else if (c_name == "HEADER") { // This condition adapts to the hook c = new ConditionHeader(); - }else if (c_name == "PATH"){ - c= new ConditionPath(); + } else if (c_name == "PATH") { + c = new ConditionPath(); } else if (c_name == "CLIENT-HEADER") { c = new ConditionHeader(true); - } else if (c_name == "QUERY") { - c = new ConditionQuery(); - } else if (c_name == "URL") { // This condition adapts to the hook + } else if (c_name == "QUERY") { + c = new ConditionQuery(); + } else if (c_name == "URL") { // This condition adapts to the hook c = new ConditionUrl(); } else if (c_name == "CLIENT-URL") { c = new ConditionUrl(true); } else if (c_name == "DBM") { c = new ConditionDBM(); } else { - TSError("%s: unknown condition in header_rewrite: %s", PLUGIN_NAME, c_name.c_str()); + TSError("%s: unknown condition: %s", PLUGIN_NAME, c_name.c_str()); return NULL; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/matcher.h ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/matcher.h b/plugins/header_rewrite/matcher.h index d9648c8..833bb84 100644 --- a/plugins/header_rewrite/matcher.h +++ b/plugins/header_rewrite/matcher.h @@ -51,7 +51,8 @@ public: TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Matcher"); } - virtual ~Matcher() { + virtual ~Matcher() + { TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for Matcher"); free_pdata(); } @@ -124,30 +125,36 @@ public: private: // For basic types - bool test_eq(const T t) const { + bool test_eq(const T t) const + { // std::cout << "Testing: " << t << " == " << _data << std::endl; return t == _data; } - bool test_lt(const T t) const { + bool test_lt(const T t) const + { // std::cout << "Testing: " << t << " < " << _data << std::endl; return t < _data; } - bool test_gt(const T t) const { + bool test_gt(const T t) const + { // std::cout << "Testing: " << t << " > " << _data << std::endl; return t > _data; } - bool test_reg(const unsigned int /* t ATS_UNUSED */) const { + bool test_reg(const unsigned int /* t ATS_UNUSED */) const + { // Not supported return false; } - bool test_reg(const TSHttpStatus /* t ATS_UNUSED */) const { + bool test_reg(const TSHttpStatus /* t ATS_UNUSED */) const + { // Not supported return false; } - bool test_reg(const std::string t) const { + bool test_reg(const std::string t) const + { TSDebug(PLUGIN_NAME, "Test regular expression %s : %s", _data.c_str(), t.c_str()); int ovector[OVECCOUNT]; if (helper.regexMatch(t.c_str(), t.length(), ovector) > 0) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/operator.cc ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/operator.cc b/plugins/header_rewrite/operator.cc index 77adbfd..4297c93 100644 --- a/plugins/header_rewrite/operator.cc +++ b/plugins/header_rewrite/operator.cc @@ -24,7 +24,8 @@ #include "operator.h" const OperModifiers -Operator::get_oper_modifiers() const { +Operator::get_oper_modifiers() const +{ if (_next) return static_cast<OperModifiers>(_mods | static_cast<Operator*>(_next)->get_oper_modifiers()); @@ -32,7 +33,8 @@ Operator::get_oper_modifiers() const { } void -Operator::initialize(Parser& p) { +Operator::initialize(Parser& p) +{ Statement::initialize(p); if (p.mod_exist("L")) { @@ -46,7 +48,8 @@ Operator::initialize(Parser& p) { } void -OperatorHeaders::initialize(Parser& p) { +OperatorHeaders::initialize(Parser& p) +{ Operator::initialize(p); _header = p.get_arg(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/operator.h ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/operator.h b/plugins/header_rewrite/operator.h index 6ef2e73..aba2f11 100644 --- a/plugins/header_rewrite/operator.h +++ b/plugins/header_rewrite/operator.h @@ -35,7 +35,7 @@ enum OperModifiers { OPER_NONE = 0, OPER_LAST = 1, OPER_NEXT = 2, - OPER_QSA=4 + OPER_QSA = 4 }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/operators.cc ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/operators.cc b/plugins/header_rewrite/operators.cc index 54ac221..3913dd9 100644 --- a/plugins/header_rewrite/operators.cc +++ b/plugins/header_rewrite/operators.cc @@ -27,7 +27,8 @@ // OperatorConfig void -OperatorSetConfig::initialize(Parser& p) { +OperatorSetConfig::initialize(Parser& p) +{ Operator::initialize(p); _config = p.get_arg(); @@ -121,13 +122,15 @@ OperatorSetStatusReason::initialize(Parser& p) void -OperatorSetStatusReason::initialize_hooks() { +OperatorSetStatusReason::initialize_hooks() +{ add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK); add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK); } void -OperatorSetStatusReason::exec(const Resources& res) const { +OperatorSetStatusReason::exec(const Resources& res) const +{ if (res.bufp && res.hdr_loc) { std::string reason; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/regex_helper.h ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/regex_helper.h b/plugins/header_rewrite/regex_helper.h index 5d5099a..5edbb10 100644 --- a/plugins/header_rewrite/regex_helper.h +++ b/plugins/header_rewrite/regex_helper.h @@ -25,7 +25,8 @@ const int OVECCOUNT = 30; // We support $1 - $9 only, and this needs to be 3x that -class regexHelper{ +class regexHelper +{ public: regexHelper(): regex(NULL),regexExtra(NULL),regexCcount(0) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/ruleset.cc ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/ruleset.cc b/plugins/header_rewrite/ruleset.cc index 4a32c8b..9c6bc06 100644 --- a/plugins/header_rewrite/ruleset.cc +++ b/plugins/header_rewrite/ruleset.cc @@ -29,7 +29,8 @@ // Class implementation (no reason to have these inline) // void -RuleSet::append(RuleSet* rule) { +RuleSet::append(RuleSet* rule) +{ RuleSet* tmp = this; TSReleaseAssert(rule->next == NULL); @@ -41,7 +42,8 @@ RuleSet::append(RuleSet* rule) { void -RuleSet::add_condition(Parser& p) { +RuleSet::add_condition(Parser& p) +{ Condition* c = condition_factory(p.get_op()); if (NULL != c) { @@ -65,7 +67,8 @@ RuleSet::add_condition(Parser& p) { void -RuleSet::add_operator(Parser& p) { +RuleSet::add_operator(Parser& p) +{ Operator* o = operator_factory(p.get_op()); if (NULL != o) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/ruleset.h ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/ruleset.h b/plugins/header_rewrite/ruleset.h index b530b7f..d106ef4 100644 --- a/plugins/header_rewrite/ruleset.h +++ b/plugins/header_rewrite/ruleset.h @@ -54,11 +54,13 @@ public: const TSHttpHookID get_hook() const { return _hook; } // Inline - const ResourceIDs get_all_resource_ids() const { + const ResourceIDs get_all_resource_ids() const + { return _ids; } - bool eval(const Resources& res) const { + bool eval(const Resources& res) const + { if (NULL == _cond) { return true; } else { @@ -66,11 +68,13 @@ public: } } - bool last() const { + bool last() const + { return _last; } - OperModifiers exec(const Resources& res) const { + OperModifiers exec(const Resources& res) const + { _oper->do_exec(res); return _opermods; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f1ea0d7c/plugins/header_rewrite/statement.cc ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/statement.cc b/plugins/header_rewrite/statement.cc index a9053ff..1538f52 100644 --- a/plugins/header_rewrite/statement.cc +++ b/plugins/header_rewrite/statement.cc @@ -52,7 +52,8 @@ Statement::get_resource_ids() const bool -Statement::set_hook(TSHttpHookID hook) { +Statement::set_hook(TSHttpHookID hook) +{ bool ret = std::find(_allowed_hooks.begin(), _allowed_hooks.end(), hook) != _allowed_hooks.end(); if (ret) @@ -64,7 +65,8 @@ Statement::set_hook(TSHttpHookID hook) { // This should be overridden for any Statement which only supports some hooks void -Statement::initialize_hooks() { +Statement::initialize_hooks() +{ add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK); add_allowed_hook(TS_HTTP_READ_REQUEST_PRE_REMAP_HOOK); add_allowed_hook(TS_HTTP_READ_REQUEST_HDR_HOOK); @@ -76,7 +78,8 @@ Statement::initialize_hooks() { // Parse URL qualifiers UrlQualifiers -Statement::parse_url_qualifier(const std::string& q) { +Statement::parse_url_qualifier(const std::string& q) +{ UrlQualifiers qual = URL_QUAL_NONE; if (q == "HOST")
