From a80e2e3e157a7db09ce0356649ba5207fc2bd82e Mon Sep 17 00:00:00 2001 From: "Alan M. Carroll" Date: Fri, 19 Oct 2018 16:32:37 -0500 Subject: [PATCH] YAML: Inline BufferWriter formatting functions. --- include/tscore/CryptoHash.h | 14 ++-------- proxy/http/HttpConnectionCount.cc | 11 ++++++++ proxy/http/HttpConnectionCount.h | 12 +-------- proxy/http/HttpDebugNames.cc | 40 ++++++++++++++++++++++++++++ proxy/http/HttpDebugNames.h | 43 +++---------------------------- src/tscore/CryptoHash.cc | 12 +++++++++ 6 files changed, 70 insertions(+), 62 deletions(-) diff --git a/include/tscore/CryptoHash.h b/include/tscore/CryptoHash.h index b3334c03984..c9e1835f264 100644 --- a/include/tscore/CryptoHash.h +++ b/include/tscore/CryptoHash.h @@ -180,19 +180,9 @@ CryptoContext::finalize(CryptoHash &hash) return reinterpret_cast(_obj)->finalize(hash); } -} // namespace ats +ts::BufferWriter &bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, ats::CryptoHash const &hash); -namespace ts -{ -inline BufferWriter & -bwformat(BufferWriter &w, BWFSpec const &spec, ats::CryptoHash const &hash) -{ - BWFSpec local_spec{spec}; - if ('X' != local_spec._type) - local_spec._type = 'x'; - return bwformat(w, local_spec, std::string_view(reinterpret_cast(hash.u8), CRYPTO_HASH_SIZE)); -} -} // namespace ts +} // namespace ats using ats::CryptoHash; using ats::CryptoContext; diff --git a/proxy/http/HttpConnectionCount.cc b/proxy/http/HttpConnectionCount.cc index 7eae991ffa4..3b596354312 100644 --- a/proxy/http/HttpConnectionCount.cc +++ b/proxy/http/HttpConnectionCount.cc @@ -406,6 +406,17 @@ OutboundConnTrack::TxnState::Warn_Blocked(TxnConfig *config, int64_t sm_id, int namespace ts { +BufferWriter & +bwformat(BufferWriter &w, BWFSpec const &spec, OutboundConnTrack::MatchType type) +{ + if (spec.has_numeric_type()) { + bwformat(w, spec, static_cast(type)); + } else { + bwformat(w, spec, OutboundConnTrack::MATCH_TYPE_NAME[type]); + } + return w; +} + BufferWriter & bwformat(BufferWriter &w, BWFSpec const &spec, OutboundConnTrack::Group::Key const &key) { diff --git a/proxy/http/HttpConnectionCount.h b/proxy/http/HttpConnectionCount.h index 291e12acc56..2d4efddfd6d 100644 --- a/proxy/http/HttpConnectionCount.h +++ b/proxy/http/HttpConnectionCount.h @@ -430,17 +430,7 @@ Action *register_ShowConnectionCount(Continuation *, HTTPHdr *); namespace ts { -inline BufferWriter & -bwformat(BufferWriter &w, BWFSpec const &spec, OutboundConnTrack::MatchType type) -{ - if (spec.has_numeric_type()) { - bwformat(w, spec, static_cast(type)); - } else { - bwformat(w, spec, OutboundConnTrack::MATCH_TYPE_NAME[type]); - } - return w; -} - +BufferWriter &bwformat(BufferWriter &w, BWFSpec const &spec, OutboundConnTrack::MatchType type); BufferWriter &bwformat(BufferWriter &w, BWFSpec const &spec, OutboundConnTrack::Group::Key const &key); BufferWriter &bwformat(BufferWriter &w, BWFSpec const &spec, OutboundConnTrack::Group const &g); } // namespace ts diff --git a/proxy/http/HttpDebugNames.cc b/proxy/http/HttpDebugNames.cc index 91131edb1ba..7b104654088 100644 --- a/proxy/http/HttpDebugNames.cc +++ b/proxy/http/HttpDebugNames.cc @@ -476,3 +476,43 @@ HttpDebugNames::get_api_hook_name(TSHttpHookID t) return "unknown hook"; } + +ts::BufferWriter & +bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::ServerState_t state) +{ + if (spec.has_numeric_type()) { + return bwformat(w, spec, static_cast(state)); + } else { + return bwformat(w, spec, HttpDebugNames::get_server_state_name(state)); + } +} + +ts::BufferWriter & +bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::CacheAction_t state) +{ + if (spec.has_numeric_type()) { + return bwformat(w, spec, static_cast(state)); + } else { + return bwformat(w, spec, HttpDebugNames::get_cache_action_name(state)); + } +} + +ts::BufferWriter & +bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::StateMachineAction_t state) +{ + if (spec.has_numeric_type()) { + return bwformat(w, spec, static_cast(state)); + } else { + return bwformat(w, spec, HttpDebugNames::get_action_name(state)); + } +} + +ts::BufferWriter & +bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, TSHttpHookID id) +{ + if (spec.has_numeric_type()) { + return bwformat(w, spec, static_cast(id)); + } else { + return bwformat(w, spec, HttpDebugNames::get_api_hook_name(id)); + } +} diff --git a/proxy/http/HttpDebugNames.h b/proxy/http/HttpDebugNames.h index d94f1418e04..ec7a494082a 100644 --- a/proxy/http/HttpDebugNames.h +++ b/proxy/http/HttpDebugNames.h @@ -37,42 +37,7 @@ class HttpDebugNames static const char *get_server_state_name(HttpTransact::ServerState_t state); }; -inline ts::BufferWriter & -bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::ServerState_t state) -{ - if (spec.has_numeric_type()) { - return bwformat(w, spec, static_cast(state)); - } else { - return bwformat(w, spec, HttpDebugNames::get_server_state_name(state)); - } -} - -inline ts::BufferWriter & -bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::CacheAction_t state) -{ - if (spec.has_numeric_type()) { - return bwformat(w, spec, static_cast(state)); - } else { - return bwformat(w, spec, HttpDebugNames::get_cache_action_name(state)); - } -} - -inline ts::BufferWriter & -bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::StateMachineAction_t state) -{ - if (spec.has_numeric_type()) { - return bwformat(w, spec, static_cast(state)); - } else { - return bwformat(w, spec, HttpDebugNames::get_action_name(state)); - } -} - -inline ts::BufferWriter & -bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, TSHttpHookID id) -{ - if (spec.has_numeric_type()) { - return bwformat(w, spec, static_cast(id)); - } else { - return bwformat(w, spec, HttpDebugNames::get_api_hook_name(id)); - } -} +ts::BufferWriter &bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::ServerState_t state); +ts::BufferWriter &bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::CacheAction_t state); +ts::BufferWriter &bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, HttpTransact::StateMachineAction_t state); +ts::BufferWriter &bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, TSHttpHookID id); diff --git a/src/tscore/CryptoHash.cc b/src/tscore/CryptoHash.cc index f10eca0d2e1..fec88fb84e0 100644 --- a/src/tscore/CryptoHash.cc +++ b/src/tscore/CryptoHash.cc @@ -107,3 +107,15 @@ CryptoHash::toHexStr(char buffer[(CRYPTO_HASH_SIZE * 2) + 1]) const { return ink_code_to_hex_str(buffer, u8); } + +namespace ats +{ +ts::BufferWriter & +bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, ats::CryptoHash const &hash) +{ + ts::BWFSpec local_spec{spec}; + if ('X' != local_spec._type) + local_spec._type = 'x'; + return bwformat(w, local_spec, std::string_view(reinterpret_cast(hash.u8), CRYPTO_HASH_SIZE)); +} +} // namespace ats