From: Francesco Chemolli Date: Tue, 4 Aug 2015 14:58:58 +0000 (+0200) Subject: Shuffle HeaderLookupTable to RegisteredHeaders.{h,cc} X-Git-Tag: merge-candidate-3-v2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d1ea2a1141c77a98a290e730bbad13ea6bbfc111;p=thirdparty%2Fsquid.git Shuffle HeaderLookupTable to RegisteredHeaders.{h,cc} --- diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index ca07b609c3..790f488346 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -60,8 +60,6 @@ * local constants and vars */ -const LookupTable headerLookupTable(HDR_BAD_HDR, headerTable); - // statistics counters for headers. clients must not allow HDR_BAD_HDR to be counted std::vector headerStatsTable(HDR_ENUM_END); @@ -998,7 +996,7 @@ HttpHeader::getByNameIfPresent(const char *name, String &result) const assert(name); /* First try the quick path */ - id = headerLookupTable.lookup(SBuf(name)); + id = HeaderLookupTable.lookup(SBuf(name)); if (id != HDR_BAD_HDR) { if (!has(id)) @@ -1528,7 +1526,7 @@ HttpHeaderEntry::parse(const char *field_start, const char *field_end) debugs(55, 9, "parsing HttpHeaderEntry: near '" << getStringPrefix(field_start, field_end-field_start) << "'"); /* is it a "known" field? */ - http_hdr_type id = headerLookupTable.lookup(SBuf(field_start,name_len)); + http_hdr_type id = HeaderLookupTable.lookup(SBuf(field_start,name_len)); debugs(55, 9, "got hdr id hdr: " << id); String name; diff --git a/src/HttpHeader.h b/src/HttpHeader.h index cafc130bda..453539d2da 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -165,8 +165,5 @@ 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 789445fe05..d67dd1911e 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 = headerLookupTable.lookup(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/acl/HttpHeaderData.cc b/src/acl/HttpHeaderData.cc index 8c010aa242..f1a1f53010 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 = headerLookupTable.lookup(SBuf(hdrName)); + hdrId = HeaderLookupTable.lookup(SBuf(hdrName)); regex_rule->parse(); } diff --git a/src/base/LookupTable.h b/src/base/LookupTable.h index 265d44e0d0..4803644be0 100644 --- a/src/base/LookupTable.h +++ b/src/base/LookupTable.h @@ -46,11 +46,13 @@ struct LookupTableRecord * */ -struct SBufCaseInsensitiveLess : public std::binary_function { +class SBufCaseInsensitiveLess : public std::binary_function { +public: bool operator() (const SBuf &x, const SBuf &y) const { return x.caseCmp(y) < 0; } }; + template > class LookupTable { diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 8a9c3625b4..164ae98006 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 = headerLookupTable.lookup(SBuf(fn)); + hwa.fieldId = HeaderLookupTable.lookup(SBuf(fn)); if (hwa.fieldId == HDR_BAD_HDR) hwa.fieldId = HDR_OTHER; diff --git a/src/external_acl.cc b/src/external_acl.cc index 4a5265c898..966ceef7cd 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 = headerLookupTable.lookup(SBuf(header)); + format->header_id = HeaderLookupTable.lookup(SBuf(header)); } void diff --git a/src/http/RegisteredHeaders.cc b/src/http/RegisteredHeaders.cc index aba759af23..718ab6036e 100644 --- a/src/http/RegisteredHeaders.cc +++ b/src/http/RegisteredHeaders.cc @@ -110,3 +110,4 @@ const HeaderTableRecord headerTable[] = { {nullptr, HDR_BAD_HDR, field_type::ftInvalid} /* end of table */ }; +const LookupTable HeaderLookupTable(HDR_BAD_HDR, headerTable); diff --git a/src/http/RegisteredHeaders.h b/src/http/RegisteredHeaders.h index 3a0baf0060..335d53b389 100644 --- a/src/http/RegisteredHeaders.h +++ b/src/http/RegisteredHeaders.h @@ -9,6 +9,8 @@ #ifndef SQUID_HTTP_REGISTEREDHEADERS_H #define SQUID_HTTP_REGISTEREDHEADERS_H +#include "base/LookupTable.h" + /// recognized or "known" header fields; and the RFC which defines them (or not) /// http://www.iana.org/assignments/message-headers/message-headers.xhtml typedef enum { @@ -142,8 +144,11 @@ public: field_type type; }; -/// header name->http_hdr_type lookup table. +/// header ID->namelookup table. extern const HeaderTableRecord headerTable[]; +/// for header name->id lookup, use HeaderLookupTable.lookup(hdr-as-sbuf); +extern const LookupTable HeaderLookupTable; + #endif /* SQUID_HTTP_REGISTEREDHEADERS_H */