From 1da82544c563f4615e74af4eb5a7d6add788b94d Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Wed, 5 Aug 2015 15:47:19 +0200 Subject: [PATCH] Rename http_hdr_cc_type to HttpHdrCcType and reference it by full qualifier. Remove module cleanup functions for HttpHeader, HttpHdrCc, HttpHdrSc. Remove useless includes. Rename Http::any_registered_header to Http::any_HdrType_enum_value. Remove useless assert()s in HttpHeaderEntry dtor and HttpHeader::parse. Clarify documentation for Http::HeaderLookupTable --- src/HttpHdrCc.cc | 100 +++++++++++++++---------------- src/HttpHdrCc.cci | 8 +-- src/HttpHdrCc.h | 102 ++++++++++++++++---------------- src/HttpHdrSc.cc | 8 +-- src/HttpHdrSc.h | 5 +- src/HttpHdrScTarget.cc | 1 - src/HttpHdrScTarget.h | 6 +- src/HttpHeader.cc | 42 +++++-------- src/HttpHeader.h | 1 - src/HttpHeaderStat.h | 4 +- src/HttpHeaderTools.cc | 2 +- src/acl/RequestHeaderStrategy.h | 1 - src/http.cc | 2 +- src/http/RegisteredHeaders.cc | 1 + src/http/RegisteredHeaders.h | 11 +++- src/main.cc | 1 - 16 files changed, 134 insertions(+), 161 deletions(-) diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index 3ffd29a5ba..610657ab0a 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -25,31 +25,31 @@ #include // invariant: row[j].id == j -static LookupTable::Record CcAttrs[] = { - {"public", CC_PUBLIC}, - {"private", CC_PRIVATE}, - {"no-cache", CC_NO_CACHE}, - {"no-store", CC_NO_STORE}, - {"no-transform", CC_NO_TRANSFORM}, - {"must-revalidate", CC_MUST_REVALIDATE}, - {"proxy-revalidate", CC_PROXY_REVALIDATE}, - {"max-age", CC_MAX_AGE}, - {"s-maxage", CC_S_MAXAGE}, - {"max-stale", CC_MAX_STALE}, - {"min-fresh", CC_MIN_FRESH}, - {"only-if-cached", CC_ONLY_IF_CACHED}, - {"stale-if-error", CC_STALE_IF_ERROR}, - {"Other,", CC_OTHER}, /* ',' will protect from matches */ - {nullptr, CC_ENUM_END} +static LookupTable::Record CcAttrs[] = { + {"public", HttpHdrCcType::CC_PUBLIC}, + {"private", HttpHdrCcType::CC_PRIVATE}, + {"no-cache", HttpHdrCcType::CC_NO_CACHE}, + {"no-store", HttpHdrCcType::CC_NO_STORE}, + {"no-transform", HttpHdrCcType::CC_NO_TRANSFORM}, + {"must-revalidate", HttpHdrCcType::CC_MUST_REVALIDATE}, + {"proxy-revalidate", HttpHdrCcType::CC_PROXY_REVALIDATE}, + {"max-age", HttpHdrCcType::CC_MAX_AGE}, + {"s-maxage", HttpHdrCcType::CC_S_MAXAGE}, + {"max-stale", HttpHdrCcType::CC_MAX_STALE}, + {"min-fresh", HttpHdrCcType::CC_MIN_FRESH}, + {"only-if-cached", HttpHdrCcType::CC_ONLY_IF_CACHED}, + {"stale-if-error", HttpHdrCcType::CC_STALE_IF_ERROR}, + {"Other,", HttpHdrCcType::CC_OTHER}, /* ',' will protect from matches */ + {nullptr, HttpHdrCcType::CC_ENUM_END} }; -LookupTable ccLookupTable(CC_OTHER,CcAttrs); -std::vector ccHeaderStats(CC_ENUM_END); +LookupTable ccLookupTable(HttpHdrCcType::CC_OTHER,CcAttrs); +std::vector ccHeaderStats(HttpHdrCcType::CC_ENUM_END); /// used to walk a table of http_header_cc_type structs -http_hdr_cc_type &operator++ (http_hdr_cc_type &aHeader) +HttpHdrCcType &operator++ (HttpHdrCcType &aHeader) { int tmp = (int)aHeader; - aHeader = (http_hdr_cc_type)(++tmp); + aHeader = (HttpHdrCcType)(++tmp); return aHeader; } @@ -58,17 +58,11 @@ void httpHdrCcInitModule(void) { // check invariant on initialization table - for (int j = 0; CcAttrs[j].name != nullptr; ++j) { - assert (CcAttrs[j].id == j); + for (unsigned int j = 0; CcAttrs[j].name != nullptr; ++j) { + assert (static_cast(CcAttrs[j].id) == j); } } -/// Module cleanup hook. -void -httpHdrCcCleanModule(void) -{ -} - void HttpHdrCc::clear() { @@ -97,11 +91,11 @@ HttpHdrCc::parse(const String & str) } /* find type */ - const http_hdr_cc_type type = ccLookupTable.lookup(SBuf(item,nlen)); + const HttpHdrCcType type = ccLookupTable.lookup(SBuf(item,nlen)); // ignore known duplicate directives if (isSet(type)) { - if (type != CC_OTHER) { + if (type != HttpHdrCcType::CC_OTHER) { debugs(65, 2, "hdr cc: ignoring duplicate cache-directive: near '" << item << "' in '" << str << "'"); ++ ccHeaderStats[type].repCount; continue; @@ -111,7 +105,7 @@ HttpHdrCc::parse(const String & str) /* special-case-parsing and attribute-setting */ switch (type) { - case CC_MAX_AGE: + case HttpHdrCcType::CC_MAX_AGE: if (!p || !httpHeaderParseInt(p, &max_age) || max_age < 0) { debugs(65, 2, "cc: invalid max-age specs near '" << item << "'"); clearMaxAge(); @@ -120,7 +114,7 @@ HttpHdrCc::parse(const String & str) } break; - case CC_S_MAXAGE: + case HttpHdrCcType::CC_S_MAXAGE: if (!p || !httpHeaderParseInt(p, &s_maxage) || s_maxage < 0) { debugs(65, 2, "cc: invalid s-maxage specs near '" << item << "'"); clearSMaxAge(); @@ -129,7 +123,7 @@ HttpHdrCc::parse(const String & str) } break; - case CC_MAX_STALE: + case HttpHdrCcType::CC_MAX_STALE: if (!p || !httpHeaderParseInt(p, &max_stale) || max_stale < 0) { debugs(65, 2, "cc: max-stale directive is valid without value"); maxStale(MAX_STALE_ANY); @@ -138,7 +132,7 @@ HttpHdrCc::parse(const String & str) } break; - case CC_MIN_FRESH: + case HttpHdrCcType::CC_MIN_FRESH: if (!p || !httpHeaderParseInt(p, &min_fresh) || min_fresh < 0) { debugs(65, 2, "cc: invalid min-fresh specs near '" << item << "'"); clearMinFresh(); @@ -147,7 +141,7 @@ HttpHdrCc::parse(const String & str) } break; - case CC_STALE_IF_ERROR: + case HttpHdrCcType::CC_STALE_IF_ERROR: if (!p || !httpHeaderParseInt(p, &stale_if_error) || stale_if_error < 0) { debugs(65, 2, "cc: invalid stale-if-error specs near '" << item << "'"); clearStaleIfError(); @@ -156,7 +150,7 @@ HttpHdrCc::parse(const String & str) } break; - case CC_PRIVATE: { + case HttpHdrCcType::CC_PRIVATE: { String temp; if (!p) { // Value parameter is optional. @@ -171,7 +165,7 @@ HttpHdrCc::parse(const String & str) } break; - case CC_NO_CACHE: { + case HttpHdrCcType::CC_NO_CACHE: { String temp; if (!p) { // On Requests, missing value parameter is expected syntax. @@ -189,26 +183,26 @@ HttpHdrCc::parse(const String & str) } break; - case CC_PUBLIC: + case HttpHdrCcType::CC_PUBLIC: Public(true); break; - case CC_NO_STORE: + case HttpHdrCcType::CC_NO_STORE: noStore(true); break; - case CC_NO_TRANSFORM: + case HttpHdrCcType::CC_NO_TRANSFORM: noTransform(true); break; - case CC_MUST_REVALIDATE: + case HttpHdrCcType::CC_MUST_REVALIDATE: mustRevalidate(true); break; - case CC_PROXY_REVALIDATE: + case HttpHdrCcType::CC_PROXY_REVALIDATE: proxyRevalidate(true); break; - case CC_ONLY_IF_CACHED: + case HttpHdrCcType::CC_ONLY_IF_CACHED: onlyIfCached(true); break; - case CC_OTHER: + case HttpHdrCcType::CC_OTHER: if (other.size()) other.append(", "); @@ -231,31 +225,31 @@ HttpHdrCc::packInto(Packable * p) const if (mask==0) return; - http_hdr_cc_type flag; + HttpHdrCcType flag; int pcount = 0; assert(p); - for (flag = CC_PUBLIC; flag < CC_ENUM_END; ++flag) { - if (isSet(flag) && flag != CC_OTHER) { + for (flag = HttpHdrCcType::CC_PUBLIC; flag < HttpHdrCcType::CC_ENUM_END; ++flag) { + if (isSet(flag) && flag != HttpHdrCcType::CC_OTHER) { /* print option name for all options */ p->appendf((pcount ? ", %s": "%s") , CcAttrs[flag].name); /* for all options having values, "=value" after the name */ switch (flag) { - case CC_MAX_AGE: + case HttpHdrCcType::CC_MAX_AGE: p->appendf("=%d", maxAge()); break; - case CC_S_MAXAGE: + case HttpHdrCcType::CC_S_MAXAGE: p->appendf("=%d", sMaxAge()); break; - case CC_MAX_STALE: + case HttpHdrCcType::CC_MAX_STALE: /* max-stale's value is optional. If we didn't receive it, don't send it */ if (maxStale()!=MAX_STALE_ANY) p->appendf("=%d", maxStale()); break; - case CC_MIN_FRESH: + case HttpHdrCcType::CC_MIN_FRESH: p->appendf("=%d", minFresh()); break; default: @@ -276,7 +270,7 @@ httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist) { assert(cc); - for (http_hdr_cc_type c = CC_PUBLIC; c < CC_ENUM_END; ++c) + for (HttpHdrCcType c = HttpHdrCcType::CC_PUBLIC; c < HttpHdrCcType::CC_ENUM_END; ++c) if (cc->isSet(c)) hist->count(c); } @@ -286,7 +280,7 @@ httpHdrCcStatDumper(StoreEntry * sentry, int, double val, double, int count) { extern const HttpHeaderStat *dump_stat; /* argh! */ const int id = static_cast(val); - const int valid_id = id < CC_ENUM_END; + const bool valid_id = id < HttpHdrCcType::CC_ENUM_END; const char *name = valid_id ? CcAttrs[id].name : "INVALID"; if (count || valid_id) diff --git a/src/HttpHdrCc.cci b/src/HttpHdrCc.cci index e910985d94..6303374354 100644 --- a/src/HttpHdrCc.cci +++ b/src/HttpHdrCc.cci @@ -12,14 +12,14 @@ #include "defines.h" bool -HttpHdrCc::isSet(http_hdr_cc_type id) const +HttpHdrCc::isSet(HttpHdrCcType id) const { - assert(id>=CC_PUBLIC && id < CC_ENUM_END); + assert(id>=HttpHdrCcType::CC_PUBLIC && id < HttpHdrCcType::CC_ENUM_END); return EBIT_TEST(mask,id); } void -HttpHdrCc::setMask(http_hdr_cc_type id, bool newval) +HttpHdrCc::setMask(HttpHdrCcType id, bool newval) { if (newval) EBIT_SET(mask,id); @@ -30,7 +30,7 @@ HttpHdrCc::setMask(http_hdr_cc_type id, bool newval) /// set a data member to a new value, and set the corresponding mask-bit. /// if setting is false, then the mask-bit is cleared. void -HttpHdrCc::setValue(int32_t &value, int32_t new_value, http_hdr_cc_type hdr, bool setting) +HttpHdrCc::setValue(int32_t &value, int32_t new_value, HttpHdrCcType hdr, bool setting) { if (setting) { if (new_value < 0) { diff --git a/src/HttpHdrCc.h b/src/HttpHdrCc.h index 0a8dd4c20a..d263adca5a 100644 --- a/src/HttpHdrCc.h +++ b/src/HttpHdrCc.h @@ -10,13 +10,12 @@ #define SQUID_HTTPHDRCC_H #include "dlink.h" -#include "enums.h" #include "mem/forward.h" #include "SquidString.h" class Packable; -typedef enum { +enum HttpHdrCcType : unsigned char { CC_PUBLIC = 0, CC_PRIVATE, CC_NO_CACHE, @@ -32,7 +31,7 @@ typedef enum { CC_STALE_IF_ERROR, CC_OTHER, CC_ENUM_END /* also used to mean "invalid" */ -} http_hdr_cc_type; +}; /** Http Cache-Control header representation * @@ -64,16 +63,16 @@ public: bool parse(const String & s); //manipulation for Cache-Control: public header - bool hasPublic() const {return isSet(CC_PUBLIC);} - bool Public() const {return isSet(CC_PUBLIC);} - void Public(bool v) {setMask(CC_PUBLIC,v);} - void clearPublic() {setMask(CC_PUBLIC,false);} + bool hasPublic() const {return isSet(HttpHdrCcType::CC_PUBLIC);} + bool Public() const {return isSet(HttpHdrCcType::CC_PUBLIC);} + void Public(bool v) {setMask(HttpHdrCcType::CC_PUBLIC,v);} + void clearPublic() {setMask(HttpHdrCcType::CC_PUBLIC,false);} //manipulation for Cache-Control: private header - bool hasPrivate() const {return isSet(CC_PRIVATE);} + bool hasPrivate() const {return isSet(HttpHdrCcType::CC_PRIVATE);} const String &Private() const {return private_;} void Private(const String &v) { - setMask(CC_PRIVATE,true); + setMask(HttpHdrCcType::CC_PRIVATE,true); if (!v.size()) return; // uses append for multi-line headers @@ -81,13 +80,13 @@ public: private_.append(","); private_.append(v); } - void clearPrivate() {setMask(CC_PRIVATE,false); private_.clean();} + void clearPrivate() {setMask(HttpHdrCcType::CC_PRIVATE,false); private_.clean();} //manipulation for Cache-Control: no-cache header - bool hasNoCache() const {return isSet(CC_NO_CACHE);} + bool hasNoCache() const {return isSet(HttpHdrCcType::CC_NO_CACHE);} const String &noCache() const {return no_cache;} void noCache(const String &v) { - setMask(CC_NO_CACHE,true); + setMask(HttpHdrCcType::CC_NO_CACHE,true); if (!v.size()) return; // uses append for multi-line headers @@ -95,73 +94,73 @@ public: no_cache.append(","); no_cache.append(v); } - void clearNoCache() {setMask(CC_NO_CACHE,false); no_cache.clean();} + void clearNoCache() {setMask(HttpHdrCcType::CC_NO_CACHE,false); no_cache.clean();} //manipulation for Cache-Control: no-store header - bool hasNoStore() const {return isSet(CC_NO_STORE);} - bool noStore() const {return isSet(CC_NO_STORE);} - void noStore(bool v) {setMask(CC_NO_STORE,v);} - void clearNoStore() {setMask(CC_NO_STORE,false);} + bool hasNoStore() const {return isSet(HttpHdrCcType::CC_NO_STORE);} + bool noStore() const {return isSet(HttpHdrCcType::CC_NO_STORE);} + void noStore(bool v) {setMask(HttpHdrCcType::CC_NO_STORE,v);} + void clearNoStore() {setMask(HttpHdrCcType::CC_NO_STORE,false);} //manipulation for Cache-Control: no-transform header - bool hasNoTransform() const {return isSet(CC_NO_TRANSFORM);} - bool noTransform() const {return isSet(CC_NO_TRANSFORM);} - void noTransform(bool v) {setMask(CC_NO_TRANSFORM,v);} - void clearNoTransform() {setMask(CC_NO_TRANSFORM,false);} + bool hasNoTransform() const {return isSet(HttpHdrCcType::CC_NO_TRANSFORM);} + bool noTransform() const {return isSet(HttpHdrCcType::CC_NO_TRANSFORM);} + void noTransform(bool v) {setMask(HttpHdrCcType::CC_NO_TRANSFORM,v);} + void clearNoTransform() {setMask(HttpHdrCcType::CC_NO_TRANSFORM,false);} //manipulation for Cache-Control: must-revalidate header - bool hasMustRevalidate() const {return isSet(CC_MUST_REVALIDATE);} - bool mustRevalidate() const {return isSet(CC_MUST_REVALIDATE);} - void mustRevalidate(bool v) {setMask(CC_MUST_REVALIDATE,v);} - void clearMustRevalidate() {setMask(CC_MUST_REVALIDATE,false);} + bool hasMustRevalidate() const {return isSet(HttpHdrCcType::CC_MUST_REVALIDATE);} + bool mustRevalidate() const {return isSet(HttpHdrCcType::CC_MUST_REVALIDATE);} + void mustRevalidate(bool v) {setMask(HttpHdrCcType::CC_MUST_REVALIDATE,v);} + void clearMustRevalidate() {setMask(HttpHdrCcType::CC_MUST_REVALIDATE,false);} //manipulation for Cache-Control: proxy-revalidate header - bool hasProxyRevalidate() const {return isSet(CC_PROXY_REVALIDATE);} - bool proxyRevalidate() const {return isSet(CC_PROXY_REVALIDATE);} - void proxyRevalidate(bool v) {setMask(CC_PROXY_REVALIDATE,v);} - void clearProxyRevalidate() {setMask(CC_PROXY_REVALIDATE,false);} + bool hasProxyRevalidate() const {return isSet(HttpHdrCcType::CC_PROXY_REVALIDATE);} + bool proxyRevalidate() const {return isSet(HttpHdrCcType::CC_PROXY_REVALIDATE);} + void proxyRevalidate(bool v) {setMask(HttpHdrCcType::CC_PROXY_REVALIDATE,v);} + void clearProxyRevalidate() {setMask(HttpHdrCcType::CC_PROXY_REVALIDATE,false);} //manipulation for Cache-Control: max-age header - bool hasMaxAge() const {return isSet(CC_MAX_AGE);} + bool hasMaxAge() const {return isSet(HttpHdrCcType::CC_MAX_AGE);} int32_t maxAge() const { return max_age;} - void maxAge(int32_t v) {setValue(max_age,v,CC_MAX_AGE); } - void clearMaxAge() {setValue(max_age,MAX_AGE_UNKNOWN,CC_MAX_AGE,false);} + void maxAge(int32_t v) {setValue(max_age,v,HttpHdrCcType::CC_MAX_AGE); } + void clearMaxAge() {setValue(max_age,MAX_AGE_UNKNOWN,HttpHdrCcType::CC_MAX_AGE,false);} //manipulation for Cache-Control: s-maxage header - bool hasSMaxAge() const {return isSet(CC_S_MAXAGE);} + bool hasSMaxAge() const {return isSet(HttpHdrCcType::CC_S_MAXAGE);} int32_t sMaxAge() const { return s_maxage;} - void sMaxAge(int32_t v) {setValue(s_maxage,v,CC_S_MAXAGE); } - void clearSMaxAge() {setValue(s_maxage,MAX_AGE_UNKNOWN,CC_S_MAXAGE,false);} + void sMaxAge(int32_t v) {setValue(s_maxage,v,HttpHdrCcType::CC_S_MAXAGE); } + void clearSMaxAge() {setValue(s_maxage,MAX_AGE_UNKNOWN,HttpHdrCcType::CC_S_MAXAGE,false);} //manipulation for Cache-Control: max-stale header - bool hasMaxStale() const {return isSet(CC_MAX_STALE);} + bool hasMaxStale() const {return isSet(HttpHdrCcType::CC_MAX_STALE);} int32_t maxStale() const { return max_stale;} // max-stale has a special value (MAX_STALE_ANY) which correspond to having // the directive without a numeric specification, and directs to consider the object // as always-expired. - void maxStale(int32_t v) {setValue(max_stale,v,CC_MAX_STALE);} - void clearMaxStale() {setValue(max_stale,MAX_STALE_UNKNOWN,CC_MAX_STALE,false);} + void maxStale(int32_t v) {setValue(max_stale,v,HttpHdrCcType::CC_MAX_STALE);} + void clearMaxStale() {setValue(max_stale,MAX_STALE_UNKNOWN,HttpHdrCcType::CC_MAX_STALE,false);} //manipulation for Cache-Control:min-fresh header - bool hasMinFresh() const {return isSet(CC_MIN_FRESH);} + bool hasMinFresh() const {return isSet(HttpHdrCcType::CC_MIN_FRESH);} int32_t minFresh() const { return min_fresh;} - void minFresh(int32_t v) {if (v < 0) return; setValue(min_fresh,v,CC_MIN_FRESH); } - void clearMinFresh() {setValue(min_fresh,MIN_FRESH_UNKNOWN,CC_MIN_FRESH,false);} + void minFresh(int32_t v) {if (v < 0) return; setValue(min_fresh,v,HttpHdrCcType::CC_MIN_FRESH); } + void clearMinFresh() {setValue(min_fresh,MIN_FRESH_UNKNOWN,HttpHdrCcType::CC_MIN_FRESH,false);} //manipulation for Cache-Control: only-if-cached header - bool hasOnlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);} - bool onlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);} - void onlyIfCached(bool v) {setMask(CC_ONLY_IF_CACHED,v);} - void clearOnlyIfCached() {setMask(CC_ONLY_IF_CACHED,false);} + bool hasOnlyIfCached() const {return isSet(HttpHdrCcType::CC_ONLY_IF_CACHED);} + bool onlyIfCached() const {return isSet(HttpHdrCcType::CC_ONLY_IF_CACHED);} + void onlyIfCached(bool v) {setMask(HttpHdrCcType::CC_ONLY_IF_CACHED,v);} + void clearOnlyIfCached() {setMask(HttpHdrCcType::CC_ONLY_IF_CACHED,false);} //manipulation for Cache-Control: stale-if-error header - bool hasStaleIfError() const {return isSet(CC_STALE_IF_ERROR);} + bool hasStaleIfError() const {return isSet(HttpHdrCcType::CC_STALE_IF_ERROR);} int32_t staleIfError() const { return stale_if_error;} - void staleIfError(int32_t v) {setValue(stale_if_error,v,CC_STALE_IF_ERROR); } - void clearStaleIfError() {setValue(stale_if_error,STALE_IF_ERROR_UNKNOWN,CC_STALE_IF_ERROR,false);} + void staleIfError(int32_t v) {setValue(stale_if_error,v,HttpHdrCcType::CC_STALE_IF_ERROR); } + void clearStaleIfError() {setValue(stale_if_error,STALE_IF_ERROR_UNKNOWN,HttpHdrCcType::CC_STALE_IF_ERROR,false);} /// check whether the attribute value supplied by id is set - _SQUID_INLINE_ bool isSet(http_hdr_cc_type id) const; + _SQUID_INLINE_ bool isSet(HttpHdrCcType id) const; void packInto(Packable * p) const; @@ -181,8 +180,8 @@ private: String no_cache; ///< List of headers sent as value for CC:no-cache="...". May be empty/undefined if the value is missing. /// low-level part of the public set method, performs no checks - _SQUID_INLINE_ void setMask(http_hdr_cc_type id, bool newval=true); - _SQUID_INLINE_ void setValue(int32_t &value, int32_t new_value, http_hdr_cc_type hdr, bool setting=true); + _SQUID_INLINE_ void setMask(HttpHdrCcType id, bool newval=true); + _SQUID_INLINE_ void setValue(int32_t &value, int32_t new_value, HttpHdrCcType hdr, bool setting=true); public: /**comma-separated representation of the header values which were @@ -195,7 +194,6 @@ class StatHist; class StoreEntry; void httpHdrCcInitModule(void); -void httpHdrCcCleanModule(void); void httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist); void httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int count); diff --git a/src/HttpHdrSc.cc b/src/HttpHdrSc.cc index cd58471ee7..a0661a595b 100644 --- a/src/HttpHdrSc.cc +++ b/src/HttpHdrSc.cc @@ -10,8 +10,7 @@ #include "squid.h" #include "base/LookupTable.h" -#include "dlink.h" -#include "HttpHdrSc.h" +//#include "HttpHdrSc.h" // pulled in by HttpHdrScTarget.h #include "HttpHeader.h" #include "HttpHeaderFieldStat.h" #include "HttpHeaderStat.h" @@ -54,11 +53,6 @@ httpHdrScInitModule(void) assert(i == ScAttrs[i].id); } -void -httpHdrScCleanModule(void) -{ -} - /* implementation */ /* creates an sc object from a 0-terminating string */ diff --git a/src/HttpHdrSc.h b/src/HttpHdrSc.h index b310e55f09..6075af953d 100644 --- a/src/HttpHdrSc.h +++ b/src/HttpHdrSc.h @@ -10,12 +10,12 @@ #define SQUID_HTTPHDRSURROGATECONTROL_H #include "dlink.h" -#include "mem/AllocatorProxy.h" +#include "mem/forward.h" #include "SquidString.h" class HttpHdrScTarget; -class StatHist; class Packable; +class StatHist; class StoreEntry; typedef enum { @@ -54,7 +54,6 @@ private: /* Http Surrogate Control Header Field */ void httpHdrScStatDumper(StoreEntry * sentry, int idx, double val, double size, int count); void httpHdrScInitModule (void); -void httpHdrScCleanModule (void); HttpHdrSc *httpHdrScParseCreate(String const &); void httpHdrScSetMaxAge(HttpHdrSc *, char const *, int); diff --git a/src/HttpHdrScTarget.cc b/src/HttpHdrScTarget.cc index dc9c0cf7c2..5699a7b72a 100644 --- a/src/HttpHdrScTarget.cc +++ b/src/HttpHdrScTarget.cc @@ -9,7 +9,6 @@ /* DEBUG: section 90 HTTP Cache Control Header */ #include "squid.h" -#include "HttpHdrSc.h" #include "HttpHdrScTarget.h" #include "StatHist.h" diff --git a/src/HttpHdrScTarget.h b/src/HttpHdrScTarget.h index 88a9c44883..e814be7884 100644 --- a/src/HttpHdrScTarget.h +++ b/src/HttpHdrScTarget.h @@ -9,12 +9,8 @@ #ifndef SQUID_HTTPHDRSURROGATECONTROLTARGET_H #define SQUID_HTTPHDRSURROGATECONTROLTARGET_H -#include "defines.h" -#include "dlink.h" +#include "defines.h" //for bit mask operations #include "HttpHdrSc.h" -#include "mem/forward.h" -#include "SquidString.h" -#include "typedefs.h" class Packable; class StatHist; diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 5bb87555d6..4550675aab 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -9,12 +9,12 @@ /* DEBUG: section 55 HTTP Header */ #include "squid.h" -#include "base/LookupTable.h" +//#include "base/LookupTable.h" // pulled by HttpHdrCc.h #include "base64.h" #include "globals.h" #include "HttpHdrCc.h" #include "HttpHdrContRange.h" -#include "HttpHdrSc.h" +#include "HttpHdrScTarget.h" // also includes HttpHdrSc.h #include "HttpHeader.h" #include "HttpHeaderFieldInfo.h" #include "HttpHeaderStat.h" @@ -24,7 +24,7 @@ #include "profiler/Profiler.h" #include "rfc1123.h" #include "SquidConfig.h" -#include "SquidString.h" +//#include "SquidString.h" // pulled by HttpHdrCc.h #include "StatHist.h" #include "Store.h" #include "StrList.h" @@ -294,13 +294,6 @@ httpHeaderInitModule(void) httpHeaderRegisterWithCacheManager(); } -void -httpHeaderCleanModule(void) -{ - httpHdrCcCleanModule(); - httpHdrScCleanModule(); -} - /* * HttpHeader Implementation */ @@ -369,11 +362,10 @@ HttpHeader::clean() HttpHeaderStats[owner].busyDestroyedCount += entries.size() > 0; } // if (owner <= hoReply) - for (std::vector::iterator i = entries.begin(); i != entries.end(); ++i) { - HttpHeaderEntry *e = *i; - if (e == NULL) + for(HttpHeaderEntry *e : entries) { + if (e == nullptr) continue; - if (e->id >= Http::HdrType::ENUM_END) { + if (!Http::any_valid_header(e->id)) { debugs(55, DBG_CRITICAL, "BUG: invalid entry (" << e->id << "). Ignored."); } else { if (owner <= hoReply) @@ -562,7 +554,7 @@ HttpHeader::parse(const char *header_start, size_t hdrLen) return reset(); } - if (e->id == Http::HdrType::CONTENT_LENGTH && (e2 = findEntry(e->id)) != NULL) { + if (e->id == Http::HdrType::CONTENT_LENGTH && (e2 = findEntry(e->id)) != nullptr) { if (e->value != e2->value) { int64_t l1, l2; debugs(55, warnOnError, "WARNING: found two conflicting content-length headers in {" << @@ -837,7 +829,7 @@ void HttpHeader::addEntry(HttpHeaderEntry * e) { assert(e); - assert(any_registered_header(e->id)); + assert(any_HdrType_enum_value(e->id)); assert(e->name.size()); debugs(55, 7, this << " adding entry: " << e->id << " at " << entries.size()); @@ -1445,7 +1437,7 @@ HttpHeader::getTimeOrTag(Http::HdrType id) const HttpHeaderEntry::HttpHeaderEntry(Http::HdrType anId, const char *aName, const char *aValue) { - assert(any_registered_header(anId)); + assert(any_HdrType_enum_value(anId)); id = anId; if (id != Http::HdrType::OTHER) @@ -1455,7 +1447,7 @@ HttpHeaderEntry::HttpHeaderEntry(Http::HdrType anId, const char *aName, const ch value = aValue; - if (anId != Http::HdrType::BAD_HDR) + if (id != Http::HdrType::BAD_HDR) ++ headerStatsTable[id].aliveCount; debugs(55, 9, "created HttpHeaderEntry " << this << ": '" << name << " : " << value ); @@ -1463,14 +1455,14 @@ HttpHeaderEntry::HttpHeaderEntry(Http::HdrType anId, const char *aName, const ch HttpHeaderEntry::~HttpHeaderEntry() { - assert(any_valid_header(id)); debugs(55, 9, "destroying entry " << this << ": '" << name << ": " << value << "'"); - // Http::HdrType::BAD_HDR is filtered out by assert_any_valid_header - assert(headerStatsTable[id].aliveCount); - -- headerStatsTable[id].aliveCount; + if (id != Http::HdrType::BAD_HDR) { + assert(headerStatsTable[id].aliveCount); + -- headerStatsTable[id].aliveCount; + id = Http::HdrType::BAD_HDR; // it already is BAD_HDR, no sense in resetting it + } - id = Http::HdrType::BAD_HDR; } /* parses and inits header entry, returns true/false */ @@ -1522,8 +1514,6 @@ HttpHeaderEntry::parse(const char *field_start, const char *field_end) if (id == Http::HdrType::BAD_HDR) id = Http::HdrType::OTHER; - assert(any_valid_header(id)); - /* set field name */ if (id == Http::HdrType::OTHER) name.limitInit(field_start, name_len); @@ -1623,7 +1613,7 @@ void httpHeaderFieldStatDumper(StoreEntry * sentry, int, double val, double, int count) { const int id = static_cast(val); - const bool valid_id = id < Http::HdrType::ENUM_END; + const bool valid_id = Http::any_valid_header(static_cast(id)); const char *name = valid_id ? Http::HeaderTable[id].name : "INVALID"; int visible = count > 0; /* for entries with zero count, list only those that belong to current type of message */ diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 21c7e9b951..2bd345d8a5 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -163,7 +163,6 @@ HttpHeader::chunked() const } void httpHeaderInitModule(void); -void httpHeaderCleanModule(void); #endif /* SQUID_HTTPHEADER_H */ diff --git a/src/HttpHeaderStat.h b/src/HttpHeaderStat.h index 546ebd602a..6610c7c9a4 100644 --- a/src/HttpHeaderStat.h +++ b/src/HttpHeaderStat.h @@ -28,7 +28,7 @@ public: { hdrUCountDistr.enumInit(32); /* not a real enum */ fieldTypeDistr.enumInit(Http::HdrType::ENUM_END); - ccTypeDistr.enumInit(CC_ENUM_END); + ccTypeDistr.enumInit(HttpHdrCcType::CC_ENUM_END); scTypeDistr.enumInit(SC_ENUM_END); } @@ -44,7 +44,7 @@ public: assert(label); hdrUCountDistr.enumInit(32); /* not a real enum */ fieldTypeDistr.enumInit(Http::HdrType::ENUM_END); - ccTypeDistr.enumInit(CC_ENUM_END); + ccTypeDistr.enumInit(HttpHdrCcType::CC_ENUM_END); scTypeDistr.enumInit(SC_ENUM_END); } diff --git a/src/HttpHeaderTools.cc b/src/HttpHeaderTools.cc index cfab7b876c..a8d6ac7dfa 100644 --- a/src/HttpHeaderTools.cc +++ b/src/HttpHeaderTools.cc @@ -454,7 +454,7 @@ const headerMangler * HeaderManglers::find(const HttpHeaderEntry &e) const { // a known header with a configured ACL list - if (e.id != Http::HdrType::OTHER && Http::any_registered_header(e.id) && + if (e.id != Http::HdrType::OTHER && Http::any_HdrType_enum_value(e.id) && known[e.id].access_list) return &known[e.id]; diff --git a/src/acl/RequestHeaderStrategy.h b/src/acl/RequestHeaderStrategy.h index b1fcd4170b..43b06825a9 100644 --- a/src/acl/RequestHeaderStrategy.h +++ b/src/acl/RequestHeaderStrategy.h @@ -15,7 +15,6 @@ #include "HttpRequest.h" template - class ACLRequestHeaderStrategy : public ACLStrategy { diff --git a/src/http.cc b/src/http.cc index 57a6e03c16..a73a971ed8 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1896,7 +1896,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request, #if 0 /* see bug 2330 */ /* Set no-cache if determined needed but not found */ if (request->flags.nocache) - EBIT_SET(cc->mask, CC_NO_CACHE); + EBIT_SET(cc->mask, HttpHdrCcType::CC_NO_CACHE); #endif /* Add max-age only without no-cache */ diff --git a/src/http/RegisteredHeaders.cc b/src/http/RegisteredHeaders.cc index 96fea1daa6..4ba8cf2cfb 100644 --- a/src/http/RegisteredHeaders.cc +++ b/src/http/RegisteredHeaders.cc @@ -13,6 +13,7 @@ namespace Http { + /* * A table with major attributes for every known field. * diff --git a/src/http/RegisteredHeaders.h b/src/http/RegisteredHeaders.h index 25f51c2b76..8555f3f8ac 100644 --- a/src/http/RegisteredHeaders.h +++ b/src/http/RegisteredHeaders.h @@ -150,11 +150,17 @@ public: /// header ID->namelookup table. extern const HeaderTableRecord HeaderTable[]; -/// for header name->id lookup, use HeaderLookupTable.lookup(hdr-as-sbuf); +/** LookupTable for HTTP Header name -> Http::HdrType lookup. + * + * use as HeaderLookupTable.lookup(header-as-sbuf). + * It will return Http::HdrType::HDR_BAD if the header is unknown/not registered, + * including the case of Http::HdrType::OTHER, which will have to be handled + * by the caller. + */ extern const LookupTable HeaderLookupTable; inline bool -any_registered_header (const Http::HdrType id) +any_HdrType_enum_value (const Http::HdrType id) { return (id == Http::HdrType::BAD_HDR || (id >= Http::HdrType::ACCEPT && id < Http::HdrType::ENUM_END)); } @@ -165,7 +171,6 @@ any_valid_header (const Http::HdrType id) return (id >= Http::HdrType::ACCEPT && id < Http::HdrType::ENUM_END); } - }; /* namespace Http */ std::ostream & diff --git a/src/main.cc b/src/main.cc index 9ca20c1796..6cb50cb991 100644 --- a/src/main.cc +++ b/src/main.cc @@ -2010,7 +2010,6 @@ SquidShutdown() fqdncacheFreeMemory(); asnFreeMemory(); clientdbFreeMemory(); - httpHeaderCleanModule(); statFreeMemory(); eventFreeMemory(); mimeFreeMemory(); -- 2.47.3