From: Francesco Chemolli Date: Mon, 3 Aug 2015 13:56:30 +0000 (+0200) Subject: Removed httpHeaderIdByNameDef, small cleanups X-Git-Tag: merge-candidate-3-v1~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=383154d77b844b4e2d07d1155b6a3dc9b92906e1;p=thirdparty%2Fsquid.git Removed httpHeaderIdByNameDef, small cleanups --- diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index da33627083..3ffd29a5ba 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -274,10 +274,9 @@ HttpHdrCc::packInto(Packable * p) const void httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist) { - http_hdr_cc_type c; assert(cc); - for (c = CC_PUBLIC; c < CC_ENUM_END; ++c) + for (http_hdr_cc_type c = CC_PUBLIC; c < CC_ENUM_END; ++c) if (cc->isSet(c)) hist->count(c); } @@ -286,8 +285,8 @@ void httpHdrCcStatDumper(StoreEntry * sentry, int, double val, double, int count) { extern const HttpHeaderStat *dump_stat; /* argh! */ - const int id = (int) val; - const int valid_id = id >= 0 && id < CC_ENUM_END; + const int id = static_cast(val); + const int valid_id = id < CC_ENUM_END; const char *name = valid_id ? CcAttrs[id].name : "INVALID"; if (count || valid_id) diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 9763f4c5c3..c4f01ab7aa 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -72,7 +72,7 @@ */ -LookupTable headerLookupTable(HDR_BAD_HDR, headerTable); +const LookupTable headerLookupTable(HDR_BAD_HDR, headerTable); std::vector headerStatsTable(HDR_OTHER+1); /* @@ -282,9 +282,7 @@ httpHeaderInitModule(void) for (int i = 0; headerTable[i].name; ++i) assert(headerTable[i].id == i); - // use headerLookupTable in place of Headers - - /* create masks */ + /* create masks. XXX: migrate to std::vector? */ httpHeaderMaskInit(&ListHeadersMask, 0); httpHeaderCalcMask(&ListHeadersMask, ListHeadersArr, countof(ListHeadersArr)); @@ -996,9 +994,9 @@ HttpHeader::getByNameIfPresent(const char *name, String &result) const assert(name); /* First try the quick path */ - id = httpHeaderIdByNameDef(SBuf(name)); + id = headerLookupTable.lookup(SBuf(name)); - if (id != -1) { + if (id != HDR_BAD_HDR) { if (!has(id)) return false; result = getStrOrList(id); @@ -1726,18 +1724,6 @@ httpHeaderStoreReport(StoreEntry * e) storeAppendPrintf(e, "Hdr Fields Parsed: %d\n", HeaderEntryParsedCount); } -http_hdr_type -httpHeaderIdByNameDef(const SBuf &name) -{ - return headerLookupTable.lookup(name); -} - -http_hdr_type -httpHeaderIdByNameDef(const char *name, int name_len) -{ - return headerLookupTable.lookup(SBuf(name,name_len)); -} - int HttpHeader::hasListMember(http_hdr_type id, const char *member, const char separator) const { diff --git a/src/HttpHeader.h b/src/HttpHeader.h index a79467c06b..cafc130bda 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -9,6 +9,7 @@ #ifndef SQUID_HTTPHEADER_H #define SQUID_HTTPHEADER_H +#include "base/LookupTable.h" #include "http/RegisteredHeaders.h" /* because we pass a spec by value */ #include "HttpHeaderMask.h" @@ -23,7 +24,6 @@ class HttpHdrContRange; class HttpHdrRange; class HttpHdrSc; class Packable; -class StoreEntry; class SBuf; /** Possible owners of http header */ @@ -165,5 +165,8 @@ HttpHeader::chunked() const void httpHeaderInitModule(void); void httpHeaderCleanModule(void); +// for header string->id lookup, use headerLookupTable.lookup(hdr-as-sbuf); +extern const LookupTable headerLookupTable; + #endif /* SQUID_HTTPHEADER_H */ diff --git a/src/HttpHeaderTools.cc b/src/HttpHeaderTools.cc index f5a97998f9..a0f8c23b2b 100644 --- a/src/HttpHeaderTools.cc +++ b/src/HttpHeaderTools.cc @@ -417,7 +417,7 @@ HeaderManglers::dumpReplacement(StoreEntry * entry, const char *name) const headerMangler * HeaderManglers::track(const char *name) { - int id = httpHeaderIdByNameDef(SBuf(name)); + int id = headerLookupTable.lookup(SBuf(name)); if (id == HDR_BAD_HDR) { // special keyword or a custom header if (strcmp(name, "All") == 0) diff --git a/src/HttpHeaderTools.h b/src/HttpHeaderTools.h index 94a253d210..2d30f79fa9 100644 --- a/src/HttpHeaderTools.h +++ b/src/HttpHeaderTools.h @@ -24,7 +24,6 @@ class HeaderWithAcl; class HttpHeader; -class HttpHeaderFieldInfo; class HttpRequest; class StoreEntry; class String; @@ -115,8 +114,6 @@ public: int httpHeaderParseOffset(const char *start, int64_t * off); -http_hdr_type httpHeaderIdByNameDef(const SBuf &name); -http_hdr_type httpHeaderIdByNameDef(const char *name, int name_len); int httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive); int httpHeaderParseInt(const char *start, int *val); void httpHeaderPutStrf(HttpHeader * hdr, http_hdr_type id, const char *fmt,...) PRINTF_FORMAT_ARG3; diff --git a/src/acl/HttpHeaderData.cc b/src/acl/HttpHeaderData.cc index ff8cb14b59..8c010aa242 100644 --- a/src/acl/HttpHeaderData.cc +++ b/src/acl/HttpHeaderData.cc @@ -76,7 +76,7 @@ ACLHTTPHeaderData::parse() char* t = ConfigParser::strtokFile(); assert (t != NULL); hdrName = t; - hdrId = httpHeaderIdByNameDef(SBuf(hdrName)); + hdrId = headerLookupTable.lookup(SBuf(hdrName)); regex_rule->parse(); } diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 93a35b2097..8a9c3625b4 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -4608,7 +4608,7 @@ static void parse_HeaderWithAclList(HeaderWithAclList **headers) } HeaderWithAcl hwa; hwa.fieldName = fn; - hwa.fieldId = httpHeaderIdByNameDef(SBuf(fn)); + hwa.fieldId = headerLookupTable.lookup(SBuf(fn)); if (hwa.fieldId == HDR_BAD_HDR) hwa.fieldId = HDR_OTHER; diff --git a/src/enums.h b/src/enums.h index 6904a757d3..231ec58819 100644 --- a/src/enums.h +++ b/src/enums.h @@ -32,7 +32,6 @@ typedef enum { } peer_t; typedef enum { - CC_BADHDR = -1, CC_PUBLIC = 0, CC_PRIVATE, CC_NO_CACHE, @@ -47,7 +46,7 @@ typedef enum { CC_ONLY_IF_CACHED, CC_STALE_IF_ERROR, CC_OTHER, - CC_ENUM_END + CC_ENUM_END /* also used to mean "invalid" */ } http_hdr_cc_type; typedef enum { @@ -56,7 +55,7 @@ typedef enum { SC_MAX_AGE, SC_CONTENT, SC_OTHER, - SC_ENUM_END + SC_ENUM_END /* also used to mean "invalid" */ } http_hdr_sc_type; typedef enum _mem_status_t { diff --git a/src/external_acl.cc b/src/external_acl.cc index 23aee92b9d..4a5265c898 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -244,7 +244,7 @@ parse_header_token(external_acl_format::Pointer format, char *header, const Form } format->header = xstrdup(header); - format->header_id = httpHeaderIdByNameDef(SBuf(header)); + format->header_id = headerLookupTable.lookup(SBuf(header)); } void