]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Finished implementing getters/setters for RequestFlags
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 13 Sep 2012 16:20:41 +0000 (18:20 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 13 Sep 2012 16:20:41 +0000 (18:20 +0200)
18 files changed:
src/HttpRequest.cc
src/RequestFlags.h
src/client_side_reply.cc
src/client_side_request.cc
src/forward.cc
src/http.cc
src/mime.cc
src/neighbors.cc
src/peer_digest.cc
src/peer_select.cc
src/refresh.cc
src/store.cc
src/store_client.cc
src/store_digest.cc
src/tests/testCoss.cc
src/tests/testNull.cc
src/tests/testRock.cc
src/tests/testUfs.cc

index 95067ca56ca7db75e1fa6514c4995bae30b3a685..bfe45e759f42483fa5ed0202561749032dddf26c 100644 (file)
@@ -611,7 +611,7 @@ HttpRequest::cacheable() const
 bool
 HttpRequest::conditional() const
 {
-    return flags.ims ||
+    return flags.hasIMS() ||
            header.has(HDR_IF_MATCH) ||
            header.has(HDR_IF_NONE_MATCH);
 }
index 382401c694ea6c86124cf509a8877c90fb1f4ed7..43685e5e8a3714dd279690f96cf2fec11545b9de 100644 (file)
@@ -35,8 +35,8 @@
 class RequestFlags {
 public:
     RequestFlags():
-        nocache(0), ims(0), auth(0), cachable(0),
-        hierarchical(0), loopdetect(false), proxy_keepalive(false), proxying_(false),
+        nocache(false), ims(false), auth_(false), cachable(false),
+        hierarchical_(false), loopdetect(false), proxy_keepalive(false), proxying_(false),
         refresh_(false), redirected(false), need_validation(false),
         fail_on_validation_err(false), stale_if_hit(false), nocache_hack(false), accelerated_(false),
         ignore_cc(false), intercepted_(false), hostVerified_(false), spoof_client_ip(false),
@@ -48,12 +48,6 @@ public:
         isRanged_(false)
     {}
 
-    unsigned int nocache :1; ///< whether the response to this request may be READ from cache
-    unsigned int ims :1;
-    unsigned int auth :1;
-    unsigned int cachable :1; ///< whether the response to thie request may be stored in the cache
-    unsigned int hierarchical :1;
-
     // When adding new flags, please update cloneAdaptationImmune() as needed.
     bool resetTCP() const;
     void setResetTCP();
@@ -170,7 +164,30 @@ public:
 
     bool loopDetect() const { return loopdetect; }
     void setLoopDetect() { loopdetect = 1; }
+
+    bool hierarchical() const { return hierarchical_; }
+    void setHierarchical() { hierarchical_=true; }
+    void clearHierarchical() { hierarchical_=true; }
+
+    bool isCachable() const { return cachable; }
+    void setCachable(bool newValue=true) { cachable = newValue; }
+    void setNotCachable() { cachable = false; }
+
+    bool hasAuth() const { return auth_; }
+    void markAuth() { auth_=true; }
+
+    bool hasIMS() const { return ims; }
+    void setIMS() { ims=true; }
+    void clearIMS() { ims=false; }
+
+    bool noCache() const { return nocache; }
+    void setNocache() { nocache=true;}
 private:
+    bool nocache :1; ///< whether the response to this request may be READ from cache
+    bool ims :1;
+    bool auth_ :1;
+    bool cachable :1; ///< whether the response to thie request may be stored in the cache
+    bool hierarchical_ :1;
     bool loopdetect :1;
     bool proxy_keepalive :1;
     bool proxying_ :1; /* this should be killed, also in httpstateflags */
index ae12a1fde1cafec58bdaa98548e7fe3e61267595..7b40cebb1a5eaba060a8f6585f8d214080fe9cb4 100644 (file)
@@ -398,7 +398,7 @@ clientReplyContext::handleIMSReply(StoreIOBuffer result)
 
         // if client sent IMS
 
-        if (http->request->flags.ims && !old_entry->modifiedSince(http->request)) {
+        if (http->request->flags.hasIMS() && !old_entry->modifiedSince(http->request)) {
             // forward the 304 from origin
             debugs(88, 3, "handleIMSReply: origin replied 304, revalidating existing entry and forwarding 304 to client");
             sendClientUpstreamResponse();
@@ -566,7 +566,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result)
              */
             http->logType = LOG_TCP_MISS;
             processMiss();
-        } else if (r->flags.nocache) {
+        } else if (r->flags.noCache()) {
             /*
              * This did not match a refresh pattern that overrides no-cache
              * we should honour the client no-cache header.
@@ -729,7 +729,7 @@ clientReplyContext::processConditional(StoreIOBuffer &result)
     if (r.header.has(HDR_IF_NONE_MATCH)) {
         if (!e->hasIfNoneMatchEtag(r)) {
             // RFC 2616: ignore IMS if If-None-Match did not match
-            r.flags.ims = 0;
+            r.flags.clearIMS();
             r.ims = -1;
             r.imslen = 0;
             r.header.delById(HDR_IF_MODIFIED_SINCE);
@@ -738,7 +738,7 @@ clientReplyContext::processConditional(StoreIOBuffer &result)
             return;
         }
 
-        if (!r.flags.ims) {
+        if (!r.flags.hasIMS()) {
             // RFC 2616: if If-None-Match matched and there is no IMS,
             // reply with 304 Not Modified or 412 Precondition Failed
             sendNotModifiedOrPreconditionFailedError();
@@ -749,7 +749,7 @@ clientReplyContext::processConditional(StoreIOBuffer &result)
         matchedIfNoneMatch = true;
     }
 
-    if (r.flags.ims) {
+    if (r.flags.hasIMS()) {
         // handle If-Modified-Since requests from the client
         if (e->modifiedSince(&r)) {
             http->logType = LOG_TCP_IMS_HIT;
@@ -1555,7 +1555,7 @@ clientReplyContext::identifyStoreObject()
 {
     HttpRequest *r = http->request;
 
-    if (r->flags.cachable || r->flags.isInternal()) {
+    if (r->flags.isCachable() || r->flags.isInternal()) {
         lookingforstore = 5;
         StoreEntry::getPublicByRequest (this, r);
     } else {
@@ -1586,7 +1586,7 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry)
     /** \li If the request has no-cache flag set or some no_cache HACK in operation we
       * 'invalidate' the cached IP entries for this request ???
       */
-    if (r->flags.nocache) {
+    if (r->flags.noCache()) {
 
 #if USE_DNSHELPER
         ipcacheInvalidate(r->GetHost());
@@ -1650,7 +1650,7 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry)
         return;
     }
 
-    if (r->flags.nocache) {
+    if (r->flags.noCache()) {
         debugs(85, 3, "clientProcessRequest2: no-cache REFRESH MISS");
         http->storeEntry(NULL);
         http->logType = LOG_TCP_CLIENT_REFRESH_MISS;
index 9e4547555c6cff747fd9991aaf9baf42acbb2ef5..db5200c060496c84234c89604ad507b6ac167344 100644 (file)
@@ -588,9 +588,9 @@ ClientRequestContext::hostHeaderVerifyFailed(const char *A, const char *B)
 
         // NP: it is tempting to use 'flags.nocache' but that is all about READing cache data.
         // The problems here are about WRITE for new cache content, which means flags.cachable
-        http->request->flags.cachable = 0; // MUST NOT cache (for now)
+        http->request->flags.setNotCachable(); // MUST NOT cache (for now)
         // XXX: when we have updated the cache key to base on raw-IP + URI this cacheable limit can go.
-        http->request->flags.hierarchical = 0; // MUST NOT pass to peers (for now)
+        http->request->flags.clearHierarchical(); // MUST NOT pass to peers (for now)
         // XXX: when we have sorted out the best way to relay requests properly to peers this hierarchical limit can go.
         http->doCallouts();
         return;
@@ -933,14 +933,14 @@ clientHierarchical(ClientHttpRequest * http)
      * neighbors support private keys
      */
 
-    if (request->flags.ims && !neighbors_do_private_keys)
+    if (request->flags.hasIMS() && !neighbors_do_private_keys)
         return 0;
 
     /*
      * This is incorrect: authenticating requests can be sent via a hierarchy
      * (they can even be cached if the correct headers are set on the reply)
      */
-    if (request->flags.auth)
+    if (request->flags.hasAuth())
         return 0;
 
     if (method == METHOD_TRACE)
@@ -988,7 +988,7 @@ clientCheckPinning(ClientHttpRequest * http)
         if (Comm::IsConnOpen(http_conn->pinning.serverConnection)) {
             if (http_conn->pinning.auth) {
                 request->flags.wantConnectionAuth();
-                request->flags.auth = 1;
+                request->flags.markAuth();
             } else {
                 request->flags.requestConnectionProxyAuth();
             }
@@ -1045,7 +1045,7 @@ clientInterpretRequestHeaders(ClientHttpRequest * http)
     request->ims = req_hdr->getTime(HDR_IF_MODIFIED_SINCE);
 
     if (request->ims > 0)
-        request->flags.ims = 1;
+        request->flags.setIMS();
 
     if (!request->flags.ignoringCacheControl()) {
         if (req_hdr->has(HDR_PRAGMA)) {
@@ -1069,7 +1069,7 @@ clientInterpretRequestHeaders(ClientHttpRequest * http)
         * SP1 or not so all 5.5 versions are treated 'normally').
         */
         if (Config.onoff.ie_refresh) {
-            if (http->flags.accel && request->flags.ims) {
+            if (http->flags.accel && request->flags.hasIMS()) {
                 if ((str = req_hdr->getStr(HDR_USER_AGENT))) {
                     if (strstr(str, "MSIE 5.01") != NULL)
                         no_cache=true;
@@ -1098,7 +1098,7 @@ clientInterpretRequestHeaders(ClientHttpRequest * http)
         else
 #endif
 
-            request->flags.nocache = 1;
+            request->flags.setNocache();
     }
 
     /* ignore range header in non-GETs or non-HEADs */
@@ -1134,12 +1134,12 @@ clientInterpretRequestHeaders(ClientHttpRequest * http)
     }
 
     if (req_hdr->has(HDR_AUTHORIZATION))
-        request->flags.auth = 1;
+        request->flags.markAuth();
 
     clientCheckPinning(http);
 
     if (request->login[0] != '\0')
-        request->flags.auth = 1;
+        request->flags.markAuth();
 
     if (req_hdr->has(HDR_VIA)) {
         String s = req_hdr->getList(HDR_VIA);
@@ -1173,17 +1173,17 @@ clientInterpretRequestHeaders(ClientHttpRequest * http)
 
 #endif
 
-    request->flags.cachable = http->request->cacheable();
+    request->flags.setCachable(http->request->cacheable());
 
     if (clientHierarchical(http))
-        request->flags.hierarchical = 1;
+        request->flags.setHierarchical();
 
     debugs(85, 5, "clientInterpretRequestHeaders: REQ_NOCACHE = " <<
-           (request->flags.nocache ? "SET" : "NOT SET"));
+           (request->flags.noCache() ? "SET" : "NOT SET"));
     debugs(85, 5, "clientInterpretRequestHeaders: REQ_CACHABLE = " <<
-           (request->flags.cachable ? "SET" : "NOT SET"));
+           (request->flags.isCachable() ? "SET" : "NOT SET"));
     debugs(85, 5, "clientInterpretRequestHeaders: REQ_HIERARCHICAL = " <<
-           (request->flags.hierarchical ? "SET" : "NOT SET"));
+           (request->flags.hierarchical() ? "SET" : "NOT SET"));
 
 }
 
@@ -1293,7 +1293,8 @@ void
 ClientRequestContext::checkNoCacheDone(const allow_t &answer)
 {
     acl_checklist = NULL;
-    http->request->flags.cachable = (answer == ACCESS_ALLOWED);
+    if (answer == ACCESS_ALLOWED)
+        http->request->flags.setCachable();
     http->doCallouts();
 }
 
@@ -1601,7 +1602,7 @@ ClientHttpRequest::doCallouts()
         if (!calloutContext->no_cache_done) {
             calloutContext->no_cache_done = true;
 
-            if (Config.accessList.noCache && request->flags.cachable) {
+            if (Config.accessList.noCache && request->flags.isCachable()) {
                 debugs(83, 3, HERE << "Doing calloutContext->checkNoCache()");
                 calloutContext->checkNoCache();
                 return;
index 97de1556b1ca5a80a6446a19bc15373f09719cc3..db682202d7e4514b58460626c0c0247d65521e95 100644 (file)
@@ -887,7 +887,7 @@ FwdState::connectDone(const Comm::ConnectionPointer &conn, comm_err_t status, in
     if (rePin) {
         debugs(17, 3, HERE << "repinning " << serverConn);
         request->clientConnectionManager->pinConnection(serverConn,
-                request, serverConn->getPeer(), request->flags.auth);
+                request, serverConn->getPeer(), request->flags.hasAuth());
         request->flags.markPinned();
     }
 
@@ -986,7 +986,7 @@ FwdState::connectStart()
             ++n_tries;
             request->flags.markPinned();
             if (pinned_connection->pinnedAuth())
-                request->flags.auth = 1;
+                request->flags.markAuth();
             comm_add_close_handler(serverConn->fd, fwdServerClosedWrapper, this);
             // the server may close the pinned connection before this request
             pconnRace = racePossible;
index 2dae9d75654534c1eb312a8749f029d44536fce0..2020cf369bb985f34a165c49a05fb406b5dada81 100644 (file)
@@ -379,7 +379,7 @@ HttpStateData::cacheableReply()
         }
     }
 
-    if (request->flags.auth || request->flags.authSent()) {
+    if (request->flags.hasAuth() || request->flags.authSent()) {
         /*
          * Responses to requests with authorization may be cached
          * only if a Cache-Control: public reply header is present.
@@ -1648,7 +1648,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request,
      */
     if (!we_do_ranges && request->multipartRangeRequest()) {
         /* don't cache the result */
-        request->flags.cachable = 0;
+        request->flags.setNotCachable();
         /* pretend it's not a range request */
         delete request->range;
         request->range = NULL;
@@ -1987,13 +1987,13 @@ HttpStateData::decideIfWeDoRanges (HttpRequest * request)
 
     int64_t roffLimit = request->getRangeOffsetLimit();
 
-    if (NULL == request->range || !request->flags.cachable
+    if (NULL == request->range || !request->flags.isCachable()
             || request->range->offsetLimitExceeded(roffLimit) || request->flags.connectionAuthWanted())
         result = false;
 
     debugs(11, 8, "decideIfWeDoRanges: range specs: " <<
            request->range << ", cachable: " <<
-           request->flags.cachable << "; we_do_ranges: " << result);
+           request->flags.isCachable() << "; we_do_ranges: " << result);
 
     return result;
 }
index 2d14023fd2d2caaf4e564fe2f83f6f7fc9d85444..d1450061c26894331aff2bd9bc4c27abeb71f879 100644 (file)
@@ -455,7 +455,7 @@ MimeIcon::created (StoreEntry *newEntry)
         return;
     }
 
-    flags.cachable = 1;
+    flags.setCachable();
     StoreEntry *e = storeCreateEntry(url,
                                      url,
                                      flags,
index 44932cb292565bee73ccdf7dfdbf64cd85905098..9ce567da67705c2f20fac65f6fbcd51332ac3087 100644 (file)
@@ -161,10 +161,10 @@ peerAllowedToUse(const CachePeer * p, HttpRequest * request)
     if (neighborType(p, request) == PEER_SIBLING) {
 #if PEER_MULTICAST_SIBLINGS
         if (p->type == PEER_MULTICAST && p->options.mcast_siblings &&
-                (request->flags.nocache || request->flags.refresh() || request->flags.loopDetect() || request->flags.validationNeeded()))
+                (request->flags.noCache() || request->flags.refresh() || request->flags.loopDetect() || request->flags.validationNeeded()))
             debugs(15, 2, "peerAllowedToUse(" << p->name << ", " << request->GetHost() << ") : multicast-siblings optimization match");
 #endif
-        if (request->flags.nocache)
+        if (request->flags.noCache())
             return false;
 
         if (request->flags.refresh())
@@ -230,7 +230,7 @@ peerWouldBePinged(const CachePeer * p, HttpRequest * request)
     /* the case below seems strange, but can happen if the
      * URL host is on the other side of a firewall */
     if (p->type == PEER_SIBLING)
-        if (!request->flags.hierarchical)
+        if (!request->flags.hierarchical())
             return 0;
 
     if (!peerAllowedToUse(p, request))
@@ -789,7 +789,7 @@ neighborsDigestSelect(HttpRequest * request)
     int p_rtt;
     int i;
 
-    if (!request->flags.hierarchical)
+    if (!request->flags.hierarchical())
         return NULL;
 
     storeKeyPublicByRequest(request);
index 18a0922f1316f94ea5cad967cafe76e04307013c..24a021d8be8ff10cab62d568505ea8063d57f351 100644 (file)
@@ -370,7 +370,7 @@ peerDigestRequest(PeerDigest * pd)
 
     pd_last_req_time = squid_curtime;
 
-    req->flags.cachable = 1;
+    req->flags.setCachable();
 
     /* the rest is based on clientProcessExpired() */
     req->flags.setRefresh();
index 6d78c61333d755161ebae0dcc81120a28bfd85f3..bd48ef4c4a5da415fc87a5e67ebb67a6a9cada33 100644 (file)
@@ -126,7 +126,7 @@ peerSelectIcpPing(HttpRequest * request, int direct, StoreEntry * entry)
     assert(direct != DIRECT_YES);
     debugs(44, 3, "peerSelectIcpPing: " << entry->url()  );
 
-    if (!request->flags.hierarchical && direct != DIRECT_NO)
+    if (!request->flags.hierarchical() && direct != DIRECT_NO)
         return 0;
 
     if (EBIT_TEST(entry->flags, KEY_PRIVATE) && !neighbors_do_private_keys)
@@ -492,7 +492,7 @@ peerSelectFoo(ps_state * ps)
         if (Config.onoff.prefer_direct)
             peerGetSomeDirect(ps);
 
-        if (request->flags.hierarchical || !Config.onoff.nonhierarchical_direct) {
+        if (request->flags.hierarchical() || !Config.onoff.nonhierarchical_direct) {
             peerGetSomeParent(ps);
             peerGetAllParents(ps);
         }
index 571e25073d5808fa83ede264340b48535dafc62e..ac9c7e84a48267b646b0a046eb014bfc2ad48607 100644 (file)
@@ -311,7 +311,7 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta)
     if (request && !request->flags.ignoringCacheControl()) {
         HttpHdrCc *cc = request->cache_control;
 
-        if (request->flags.ims && (R->flags.refresh_ims || Config.onoff.refresh_all_ims)) {
+        if (request->flags.hasIMS() && (R->flags.refresh_ims || Config.onoff.refresh_all_ims)) {
             /* The clients no-cache header is changed into a IMS query */
             debugs(22, 3, "refreshCheck: YES: refresh-ims");
             return STALE_FORCED_RELOAD;
@@ -331,7 +331,7 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta)
         } else {
             /* The clients no-cache header is not overridden on this request */
             debugs(22, 3, "refreshCheck: YES: client reload");
-            request->flags.nocache = 1;
+            request->flags.setNocache();
             return STALE_FORCED_RELOAD;
         }
 
index 941c2c005488417dd1b51c44fe021df8ea2da2af..48537763a8dd2371299dbf8c77b5004abce2aee9 100644 (file)
@@ -829,12 +829,12 @@ storeCreateEntry(const char *url, const char *log_url, const RequestFlags &flags
     mem = e->mem_obj;
     mem->method = method;
 
-    if (neighbors_do_private_keys || !flags.hierarchical)
+    if (neighbors_do_private_keys || !flags.hierarchical())
         e->setPrivateKey();
     else
         e->setPublicKey();
 
-    if (flags.cachable) {
+    if (flags.isCachable()) {
         EBIT_SET(e->flags, ENTRY_CACHABLE);
         EBIT_CLR(e->flags, RELEASE_REQUEST);
     } else {
index bd9949dd13844bc450cad274b3f05581a3667976..80f7e3d975f6b466054fbf09c205325752c11bed 100644 (file)
@@ -791,7 +791,7 @@ CheckQuickAbort2(StoreEntry * entry)
     assert(mem);
     debugs(90, 3, "CheckQuickAbort2: entry=" << entry << ", mem=" << mem);
 
-    if (mem->request && !mem->request->flags.cachable) {
+    if (mem->request && !mem->request->flags.isCachable()) {
         debugs(90, 3, "CheckQuickAbort2: YES !mem->request->flags.cachable");
         return 1;
     }
index b1133c83acb464140c81f0092845533f73a4497e..b2bd96b01f86329a5d4ea21375701c84448325bb 100644 (file)
@@ -392,7 +392,7 @@ storeDigestRewriteStart(void *datanotused)
     debugs(71, 2, "storeDigestRewrite: start rewrite #" << sd_state.rewrite_count + 1);
     /* make new store entry */
     url = internalLocalUri("/squid-internal-periodic/", StoreDigestFileName);
-    flags.cachable = 1;
+    flags.setCachable();
     e = storeCreateEntry(url, url, flags, METHOD_GET);
     assert(e);
     sd_state.rewrite_lock = e;
index d2cabb711f34157c3e6619e175fd71eb3248823e..d546faa3daf0d5fad724767b8b23d6bb26aee15e 100644 (file)
@@ -190,7 +190,7 @@ testCoss::testCossSearch()
     {
         /* Create "vary" base object */
         RequestFlags flags;
-        flags.cachable = 1;
+        flags.setCachable();
         StoreEntry *pe = storeCreateEntry("dummy url", "dummy log url", flags, METHOD_GET);
         HttpReply *rep = (HttpReply *) pe->getReply(); // bypass const
         rep->setHeaders(HTTP_OK, "dummy test object", "x-squid-internal/test", -1, -1, squid_curtime + 100000);
index 0e2bcf59d82eff7d25619f35855983699c1796b3..02d9a89758697356a454885520d99933d2125af9 100644 (file)
@@ -161,7 +161,7 @@ testNull::testNullSearch()
     {
         /* Create "vary" base object */
         RequestFlags flags;
-        flags.cachable = 1;
+        flags.setCachable();
         StoreEntry *pe = storeCreateEntry("dummy url", "dummy log url", flags, METHOD_GET);
         /* We are allowed to do this typecast */
         HttpReply *rep = (HttpReply *) pe->getReply(); // bypass const
index 9ba566665749b35b286c81cd932f917d22dba2cd..1ce93c8503987ceee3fcaffca74d50aef4ffd05b 100644 (file)
@@ -165,7 +165,7 @@ StoreEntry *
 testRock::createEntry(const int i)
 {
     RequestFlags flags;
-    flags.cachable = 1;
+    flags.setCachable();
     char url[64];
     snprintf(url, sizeof(url), "dummy url %i", i);
     url[sizeof(url) - 1] = '\0';
index 1213414642fa884af162115a93f985a45daa2e73..06c02a6bfe470225b67df5f11a6a59c3c29f4ab5 100644 (file)
@@ -142,7 +142,7 @@ testUfs::testUfsSearch()
     {
         /* Create "vary" base object */
         RequestFlags flags;
-        flags.cachable = 1;
+        flags.setCachable();
         StoreEntry *pe = storeCreateEntry("dummy url", "dummy log url", flags, METHOD_GET);
         HttpReply *rep = (HttpReply *) pe->getReply(); // bypass const
         rep->setHeaders(HTTP_OK, "dummy test object", "x-squid-internal/test", -1, -1, squid_curtime + 100000);