]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Removed httpHeaderIdByNameDef, small cleanups
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 3 Aug 2015 13:56:30 +0000 (15:56 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 3 Aug 2015 13:56:30 +0000 (15:56 +0200)
src/HttpHdrCc.cc
src/HttpHeader.cc
src/HttpHeader.h
src/HttpHeaderTools.cc
src/HttpHeaderTools.h
src/acl/HttpHeaderData.cc
src/cache_cf.cc
src/enums.h
src/external_acl.cc

index da33627083e9d05a2d3dc1590427289b9f052316..3ffd29a5baf916aae1cacfd26f3d30070d7078b9 100644 (file)
@@ -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<int>(val);
+    const int valid_id = id < CC_ENUM_END;
     const char *name = valid_id ? CcAttrs[id].name : "INVALID";
 
     if (count || valid_id)
index 9763f4c5c3bfaa88b43a978c7382e2bc620625ff..c4f01ab7aa913dd5c74ecd7fd3ff634735107998 100644 (file)
@@ -72,7 +72,7 @@
  */
 
 
-LookupTable<http_hdr_type, HeaderTableRecord> headerLookupTable(HDR_BAD_HDR, headerTable);
+const LookupTable<http_hdr_type, HeaderTableRecord> headerLookupTable(HDR_BAD_HDR, headerTable);
 std::vector<HttpHeaderFieldStat> 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<bool>? */
     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
 {
index a79467c06bd65e362f377479594753b6e5fbd93d..cafc130bda3f5cf86d87add05558020699941954 100644 (file)
@@ -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<http_hdr_type, HeaderTableRecord> headerLookupTable;
+
 #endif /* SQUID_HTTPHEADER_H */
 
index f5a97998f9a70c05627f84597b4d2a1e5d8eebdd..a0f8c23b2bbb0d01cce9b069219843a535f914e2 100644 (file)
@@ -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)
index 94a253d2109335579ad998fcb041ce05800c884c..2d30f79fa9f46fa4413d639ccb6511b405f1a3a7 100644 (file)
@@ -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;
index ff8cb14b59eafe133c29e4678acb3ad24657ae0c..8c010aa2428be5521934282902216f50eb6b0f4e 100644 (file)
@@ -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();
 }
 
index 93a35b2097fc6e909e8b63a549a51238bf0a7347..8a9c3625b4398f743e31e162310457687b86adcc 100644 (file)
@@ -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;
 
index 6904a757d3b07cbf34d18b90cdb21ef873659d1f..231ec58819d8af2031d4fb733fb385b087758e16 100644 (file)
@@ -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 {
index 23aee92b9d7d877f5185eb1c99fc63d8ae15806f..4a5265c8989c1083429258282b8ea0fe3bd99dba 100644 (file)
@@ -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