]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Implemented HttpHdrCc::set and isSet to manipulate the mask
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 27 Sep 2011 10:40:29 +0000 (12:40 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 27 Sep 2011 10:40:29 +0000 (12:40 +0200)
src/HttpHdrCc.cc
src/HttpHdrCc.cci
src/HttpHdrCc.h
src/client_side_request.cc
src/http.cc

index 97bcff1a3e0d56b96b4e9b3b321d0163d397b9c1..f06b6e68c370f56da265778b452c46cf7ae49baa 100644 (file)
@@ -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);
 }
 
index ebe6666908324756c27ff9eeaecc4bbca8da3d9b..20825d8fd97c7f35212906a037640fc22ef41092 100644 (file)
@@ -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);
+}
index 6de04e0520e7d0a3ae86e1943942e62abbd580d6..bd6648dcfe410cf672cd421ce5fb92a5c731100a 100644 (file)
@@ -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;
index 862ccbf6d8627f2e1beb0fc3d8f854c324826d3f..f2ae6f5ccec08aac45544b9cd17d1fd6359688c0 100644 (file)
@@ -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++;
 
         /*
index 12c06b617f8966ec8338505d04762881f4382ac4..96c1f3690a68f1d95d5cc1b5c909dbe87b63f031 100644 (file)
@@ -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);