]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Implemented full setter/getter structure for HttpHdrCc::max_age refactoring.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 20 Sep 2011 21:35:03 +0000 (23:35 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 20 Sep 2011 21:35:03 +0000 (23:35 +0200)
src/HttpHdrCc.cc
src/HttpHdrCc.h
src/HttpReply.cc
src/refresh.cc

index 1fe637beb3fcc37fa5a1ccff9def3020995bbaca..dd30b593dcbbafce58407d41d53b2d1a931c934c 100644 (file)
@@ -164,11 +164,12 @@ HttpHdrCc::parse(const String & str)
         switch (type) {
 
         case CC_MAX_AGE:
-
-            if (!p || !httpHeaderParseInt(p, &cc->max_age)) {
+            int32_t ma;
+            if (!p || !httpHeaderParseInt(p, &ma)) {
                 debugs(65, 2, "cc: invalid max-age specs near '" << item << "'");
-                cc->max_age = -1;
-                EBIT_CLR(cc->mask, type);
+                cc->setMaxAge(-1);
+            } else {
+                cc->setMaxAge(ma);
             }
 
             break;
@@ -244,7 +245,7 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p)
             /* handle options with values */
 
             if (flag == CC_MAX_AGE)
-                packerPrintf(p, "=%d", (int) cc->max_age);
+                packerPrintf(p, "=%d", (int) cc->getMaxAge());
 
             if (flag == CC_S_MAXAGE)
                 packerPrintf(p, "=%d", (int) cc->s_maxage);
@@ -267,12 +268,14 @@ httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p)
 void
 HttpHdrCc::setMaxAge(int max_age_)
 {
-    max_age = max_age_;
 
-    if (max_age_ >= 0)
+    if (max_age_ >= 0) {
         EBIT_SET(mask, CC_MAX_AGE);
-    else
+        max_age = max_age_;
+    } else {
         EBIT_CLR(mask, CC_MAX_AGE);
+        max_age=-1;
+    }
 }
 
 void
@@ -298,3 +301,10 @@ httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int c
         storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n",
                           id, name, count, xdiv(count, dump_stat->ccParsedCount));
 }
+
+int32_t HttpHdrCc::getMaxAge() const
+{
+    return max_age;
+}
+
+
index 81ee399bf647ba9af61bd650cebdd96f84295063..b0571e1115cca5a254d40250f92bf80bea39ecf3 100644 (file)
@@ -49,32 +49,20 @@ public:
             max_stale(-1), stale_if_error(0),
             min_fresh(-1) {}
 
-    /// reset to the after-default-construction state.
     void clear();
-
-    /**parse the supplied string filling in HttpHdrCc's fields.
-     *
-     * \note: internal structures are not cleaned-up beforehand.
-     *        caller must explicitly clear() beforehand if he wants that
-     */
-    bool parse(const String &s);
-
-    /** set the max_age value
-     *
-     * \param max_age the new max age. Values <0 clear it.
-     */
+    bool parse(const String & s);
     void setMaxAge(int32_t max_age);
-
+    int32_t getMaxAge() const;
     MEMPROXY_CLASS(HttpHdrCc);
 
-    /// bit-mask for the various Cc directives, keyed on http_hdr_cc_type
     int32_t mask;
+private:
     int32_t max_age;
+public:
     int32_t s_maxage;
     int32_t max_stale;
     int32_t stale_if_error;
     int32_t min_fresh;
-    /// comma-separated string accumulating unknown Cache-control directives.
     String other;
 };
 
index 57d0449733707bad1ebfbe264f71d4c11a1542c7..fb6ef2923844888a6dbf629820e36514607f146a 100644 (file)
@@ -334,8 +334,8 @@ HttpReply::hdrExpirationTime()
             if (cache_control->s_maxage >= 0)
                 return date + cache_control->s_maxage;
 
-            if (cache_control->max_age >= 0)
-                return date + cache_control->max_age;
+            if (cache_control->getMaxAge() >= 0)
+                return date + cache_control->getMaxAge();
         } else {
             /*
              * Conservatively handle the case when we have a max-age
@@ -345,7 +345,7 @@ HttpReply::hdrExpirationTime()
             if (cache_control->s_maxage >= 0)
                 return squid_curtime;
 
-            if (cache_control->max_age >= 0)
+            if (cache_control->getMaxAge() >= 0)
                 return squid_curtime;
         }
     }
index af6acafb5764bcda64c5f0b548a135aaf740be36..704eb3d81f5cf4f5a4ac27fc083e0dc3240049a1 100644 (file)
@@ -335,19 +335,19 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta)
 
 #endif
         if (NULL != cc) {
-            if (cc->max_age > -1) {
+            if (cc->getMaxAge() >= 0) {
 #if USE_HTTP_VIOLATIONS
-                if (R->flags.ignore_reload && cc->max_age == 0) {
+                if (R->flags.ignore_reload && cc->getMaxAge() == 0) {
                     debugs(22, 3, "refreshCheck: MAYBE: client-max-age = 0 and ignore-reload");
                 } else
 #endif
                 {
-                    if (cc->max_age == 0) {
+                    if (cc->getMaxAge() == 0) {
                         debugs(22, 3, "refreshCheck: YES: client-max-age = 0");
                         return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE;
                     }
 
-                    if (age > cc->max_age) {
+                    if (age > cc->getMaxAge()) {
                         debugs(22, 3, "refreshCheck: YES: age > client-max-age");
                         return STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE;
                     }