From: Francesco Chemolli Date: Tue, 27 Sep 2011 10:40:29 +0000 (+0200) Subject: Implemented HttpHdrCc::set and isSet to manipulate the mask X-Git-Tag: BumpSslServerFirst.take01~126^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9517ad8a9b2b7538893e0d9678c641f328d5cd5;p=thirdparty%2Fsquid.git Implemented HttpHdrCc::set and isSet to manipulate the mask --- diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index 97bcff1a3e..f06b6e68c3 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -113,7 +113,6 @@ HttpHdrCc::parse(const String & str) http_hdr_cc_type type; int ilen; int nlen; - HttpHdrCc *cc=this; //TODO: remove after review /* iterate through comma separated list */ @@ -134,14 +133,14 @@ HttpHdrCc::parse(const String & str) type=i->second; // ignore known duplicate directives - if (EBIT_TEST(cc->mask, type)) { + if (isSet(type)) { if (type != CC_OTHER) { debugs(65, 2, "hdr cc: ignoring duplicate cache-directive: near '" << item << "' in '" << str << "'"); ++CcAttrs[type].stat.repCount; continue; } } else { - EBIT_SET(cc->mask, type); + set(type); } /* post-processing special cases */ @@ -151,53 +150,53 @@ HttpHdrCc::parse(const String & str) int32_t ma; if (!p || !httpHeaderParseInt(p, &ma)) { debugs(65, 2, "cc: invalid max-age specs near '" << item << "'"); - cc->setMaxAge(MAX_AGE_UNSET); + setMaxAge(MAX_AGE_UNSET); } else { - cc->setMaxAge(ma); + setMaxAge(ma); } break; case CC_S_MAXAGE: - if (!p || !httpHeaderParseInt(p, &cc->s_maxage)) { + if (!p || !httpHeaderParseInt(p, &s_maxage)) { debugs(65, 2, "cc: invalid s-maxage specs near '" << item << "'"); - cc->setSMaxAge(S_MAXAGE_UNSET); + setSMaxAge(S_MAXAGE_UNSET); } break; case CC_MAX_STALE: - if (!p || !httpHeaderParseInt(p, &cc->max_stale)) { + if (!p || !httpHeaderParseInt(p, &max_stale)) { debugs(65, 2, "cc: max-stale directive is valid without value"); - cc->setMaxStale(MAX_STALE_ALWAYS); + setMaxStale(MAX_STALE_ALWAYS); } break; case CC_MIN_FRESH: - if (!p || !httpHeaderParseInt(p, &cc->min_fresh)) { + if (!p || !httpHeaderParseInt(p, &min_fresh)) { debugs(65, 2, "cc: invalid min-fresh specs near '" << item << "'"); - cc->setMinFresh(MIN_FRESH_UNSET); + setMinFresh(MIN_FRESH_UNSET); } break; case CC_STALE_IF_ERROR: - if (!p || !httpHeaderParseInt(p, &cc->stale_if_error)) { + if (!p || !httpHeaderParseInt(p, &stale_if_error)) { debugs(65, 2, "cc: invalid stale-if-error specs near '" << item << "'"); - cc->setStaleIfError(STALE_IF_ERROR_UNSET); + setStaleIfError(STALE_IF_ERROR_UNSET); } break; case CC_OTHER: - if (cc->other.size()) - cc->other.append(", "); + if (other.size()) + other.append(", "); - cc->other.append(item, ilen); + other.append(item, ilen); break; @@ -207,7 +206,7 @@ HttpHdrCc::parse(const String & str) } } - return (cc->mask != 0); + return (mask != 0); } void @@ -218,7 +217,7 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p) assert(cc && p); for (flag = CC_PUBLIC; flag < CC_ENUM_END; ++flag) { - if (EBIT_TEST(cc->mask, flag) && flag != CC_OTHER) { + if (cc->isSet(flag) && flag != CC_OTHER) { /* print option name */ packerPrintf(p, (pcount ? ", %s": "%s") , CcAttrs[flag].name); @@ -253,7 +252,7 @@ httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist) assert(cc); for (c = CC_PUBLIC; c < CC_ENUM_END; ++c) - if (EBIT_TEST(cc->mask, c)) + if (cc->isSet(c)) statHistCount(hist, c); } diff --git a/src/HttpHdrCc.cci b/src/HttpHdrCc.cci index ebe6666908..20825d8fd9 100644 --- a/src/HttpHdrCc.cci +++ b/src/HttpHdrCc.cci @@ -36,10 +36,10 @@ HttpHdrCc::setMaxAge(int max_age_) { if (max_age_ >= 0) { - EBIT_SET(mask, CC_MAX_AGE); + set(CC_MAX_AGE); max_age = max_age_; } else { - EBIT_CLR(mask, CC_MAX_AGE); + set(CC_MAX_AGE,false); max_age=MAX_AGE_UNSET; } } @@ -54,10 +54,10 @@ void HttpHdrCc::setSMaxAge(int32_t s_maxage) { if (s_maxage >= 0) { - EBIT_SET(mask, CC_S_MAXAGE); + set(CC_S_MAXAGE); this->s_maxage=s_maxage; } else { - EBIT_CLR(mask, CC_S_MAXAGE); + set(CC_S_MAXAGE,false); this->s_maxage=S_MAXAGE_UNSET; } } @@ -72,10 +72,10 @@ void HttpHdrCc::setMaxStale(int32_t max_stale) { if (max_stale>=0 || max_stale==MAX_STALE_ALWAYS) { - EBIT_SET(mask,CC_MAX_STALE); + set(CC_MAX_STALE); this->max_stale=max_stale; } else { - EBIT_CLR(mask, CC_MAX_STALE); + set(CC_MAX_STALE,false); this->max_stale=MAX_STALE_UNSET; } } @@ -89,10 +89,10 @@ void HttpHdrCc::setStaleIfError(int32_t stale_if_error) { if (stale_if_error >= 0) { - EBIT_SET(mask, CC_STALE_IF_ERROR); + set(CC_STALE_IF_ERROR); this->stale_if_error=stale_if_error; } else { - EBIT_CLR(mask, CC_STALE_IF_ERROR); + set(CC_STALE_IF_ERROR,false); this->stale_if_error=STALE_IF_ERROR_UNSET; } } @@ -107,10 +107,10 @@ void HttpHdrCc::setMinFresh(int32_t min_fresh) { if (min_fresh >= 0) { - EBIT_SET(mask, CC_MIN_FRESH); + set(CC_MIN_FRESH); this->min_fresh=min_fresh; } else { - EBIT_CLR(mask, CC_MIN_FRESH); + set(CC_MIN_FRESH,false); this->min_fresh=MIN_FRESH_UNSET; } } @@ -120,3 +120,20 @@ HttpHdrCc::getMinFresh() const { return min_fresh; } + +bool +HttpHdrCc::isSet(http_hdr_cc_type id) const +{ + assert(id>=CC_PUBLIC && id < CC_ENUM_END); + return EBIT_TEST(mask,id); +} + +void +HttpHdrCc::set(http_hdr_cc_type id, bool newval) +{ + assert(id>=CC_PUBLIC && id < CC_ENUM_END); + if (newval) + EBIT_SET(mask,id); + else + EBIT_CLR(mask,id); +} diff --git a/src/HttpHdrCc.h b/src/HttpHdrCc.h index 6de04e0520..bd6648dcfe 100644 --- a/src/HttpHdrCc.h +++ b/src/HttpHdrCc.h @@ -62,6 +62,11 @@ public: /// parse a header-string and fill in appropriate values. bool parse(const String & s); + /// set an attribute value or clear it (by supplying false as the second argument) + _SQUID_INLINE_ void set(http_hdr_cc_type id, bool newval=true); + /// check whether the attribute value supplied by id is set + _SQUID_INLINE_ bool isSet(http_hdr_cc_type id) const; + /// max-age setter. Clear by setting to MAX_AGE_UNSET _SQUID_INLINE_ void setMaxAge(int32_t max_age); _SQUID_INLINE_ int32_t getMaxAge() const; diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 862ccbf6d8..f2ae6f5cce 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -195,7 +195,7 @@ ClientHttpRequest::onlyIfCached()const { assert(request); return request->cache_control && - EBIT_TEST(request->cache_control->mask, CC_ONLY_IF_CACHED); + request->cache_control->isSet(CC_ONLY_IF_CACHED); } /* @@ -1020,7 +1020,7 @@ clientInterpretRequestHeaders(ClientHttpRequest * http) } if (request->cache_control) - if (EBIT_TEST(request->cache_control->mask, CC_NO_CACHE)) + if (request->cache_control->isSet(CC_NO_CACHE)) no_cache++; /* diff --git a/src/http.cc b/src/http.cc index 12c06b617f..96c1f3690a 100644 --- a/src/http.cc +++ b/src/http.cc @@ -331,7 +331,6 @@ HttpStateData::cacheableReply() { HttpReply const *rep = finalReply(); HttpHeader const *hdr = &rep->header; - const int cc_mask = (rep->cache_control) ? rep->cache_control->mask : 0; const char *v; #if USE_HTTP_VIOLATIONS @@ -354,22 +353,23 @@ HttpStateData::cacheableReply() // RFC 2616: do not cache replies to responses with no-store CC directive if (request && request->cache_control && - EBIT_TEST(request->cache_control->mask, CC_NO_STORE) && + request->cache_control->isSet(CC_NO_STORE) && !REFRESH_OVERRIDE(ignore_no_store)) return 0; if (!ignoreCacheControl) { - if (EBIT_TEST(cc_mask, CC_PRIVATE)) { + const HttpHdrCc* cc=request->cache_control; + if (cc->isSet(CC_PRIVATE)) { if (!REFRESH_OVERRIDE(ignore_private)) return 0; } - if (EBIT_TEST(cc_mask, CC_NO_CACHE)) { + if (cc->isSet(CC_NO_CACHE)) { if (!REFRESH_OVERRIDE(ignore_no_cache)) return 0; } - if (EBIT_TEST(cc_mask, CC_NO_STORE)) { + if (cc->isSet(CC_NO_STORE)) { if (!REFRESH_OVERRIDE(ignore_no_store)) return 0; } @@ -382,7 +382,7 @@ HttpStateData::cacheableReply() * RFC 2068, sec 14.9.4 */ - if (!EBIT_TEST(cc_mask, CC_PUBLIC)) { + if (!request->cache_control->isSet(CC_PUBLIC)) { if (!REFRESH_OVERRIDE(ignore_auth)) return 0; } @@ -926,8 +926,8 @@ HttpStateData::haveParsedReplyHeaders() no_cache: if (!ignoreCacheControl && rep->cache_control) { - if (EBIT_TEST(rep->cache_control->mask, CC_PROXY_REVALIDATE) || - EBIT_TEST(rep->cache_control->mask, CC_MUST_REVALIDATE) || + if (rep->cache_control->isSet(CC_PROXY_REVALIDATE) || + rep->cache_control->isSet(CC_MUST_REVALIDATE) || rep->cache_control->getSMaxAge() != HttpHdrCc::S_MAXAGE_UNSET ) EBIT_SET(entry->flags, ENTRY_REVALIDATE); @@ -1771,7 +1771,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request, #endif /* Add max-age only without no-cache */ - if (cc->getMaxAge()==HttpHdrCc::MAX_AGE_UNSET && !EBIT_TEST(cc->mask, CC_NO_CACHE)) { + if (cc->getMaxAge()==HttpHdrCc::MAX_AGE_UNSET && !cc->isSet(CC_NO_CACHE)) { const char *url = entry ? entry->url() : urlCanonical(request); cc->setMaxAge(getMaxAge(url)); @@ -1780,7 +1780,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request, /* Enforce sibling relations */ if (flags.only_if_cached) - EBIT_SET(cc->mask, CC_ONLY_IF_CACHED); + cc->set(CC_ONLY_IF_CACHED); hdr_out->putCc(cc);