]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Made httpReplyHdrCacheInit() and httpRequestHdrCacheInit() into virtual
authorwessels <>
Fri, 16 Sep 2005 01:22:30 +0000 (01:22 +0000)
committerwessels <>
Fri, 16 Sep 2005 01:22:30 +0000 (01:22 +0000)
functions of HttpMsg class.  Made some old static functions members of
HttpRequest and HttpReply classes so that the new hdrCacheInit() can
be private (protected).

Also fixed a memory leak with HttpHdrCc, which I may or may not have
recently created.

src/HttpMsg.cc
src/HttpMsg.h
src/HttpReply.cc
src/HttpReply.h
src/HttpRequest.cc
src/HttpRequest.h
src/client_side.cc
src/client_side_reply.cc
src/client_side_request.cc
src/peer_digest.cc

index 48b418ad2acdf7e3f9abc8fc3234bbe146ee789c..722ebd0cc23c056c62a9e7e13e00483454632d17 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpMsg.cc,v 1.15 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpMsg.cc,v 1.16 2005/09/15 19:22:30 wessels Exp $
  *
  * DEBUG: section 74    HTTP Message
  * AUTHOR: Alex Rousskov
@@ -252,10 +252,7 @@ HttpMsg::httpMsgParseStep(const char *buf, int atEnd)
         if (!httpHeaderParse(&header, blk_start, blk_end))
             return httpMsgParseError();
 
-        if (rep)
-            httpReplyHdrCacheInit(rep);
-        else if (req)
-            httpRequestHdrCacheInit(req);
+        hdrCacheInit();
 
         *parse_end_ptr = parse_start;
 
@@ -327,4 +324,9 @@ void HttpMsg::packInto(Packer *p, bool full_uri) const
     packerAppend(p, "\r\n", 2);
 }
 
-
+void HttpMsg::hdrCacheInit()
+{
+    content_length = httpHeaderGetInt(&header, HDR_CONTENT_LENGTH);
+    assert(NULL == cache_control);
+    cache_control = httpHeaderGetCc(&header);
+}
index 4b122abb90b76d7ca5a1200048e35db5f1202c56..5f302a596175ee915360719905e2a4097db8b0f4 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpMsg.h,v 1.1 2005/09/13 17:45:05 wessels Exp $
+ * $Id: HttpMsg.h,v 1.2 2005/09/15 19:22:30 wessels Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -77,6 +77,7 @@ public:
 
 protected:
     virtual void packFirstLineInto(Packer * p, bool full_uri) const = 0;
+    virtual void hdrCacheInit();
 };
 
 
index 0b52f9e7e4f4ed706eb8eceec22c59b5024d1f87..9b9844571be184f832350bfd232f4c41f2eabfec 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpReply.cc,v 1.73 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpReply.cc,v 1.74 2005/09/15 19:22:30 wessels Exp $
  *
  * DEBUG: section 58    HTTP Reply (Response)
  * AUTHOR: Alex Rousskov
@@ -79,7 +79,7 @@ httpReplyCreate(void)
 HttpReply::HttpReply() : HttpMsg(hoReply), date (0), last_modified (0), expires (0), surrogate_control (NULL), content_range (NULL), keep_alive (0), protoPrefix("HTTP/")
 {
     httpBodyInit(&body);
-    httpReplyHdrCacheInit(this);
+    hdrCacheInit();
     httpStatusLineInit(&sline);
 }
 
@@ -129,6 +129,7 @@ httpReplyAbsorb(HttpReply * rep, HttpReply * new_rep)
     *rep = *new_rep;
     new_rep->header.entries.clean();
     /* cannot use Clean() on new reply now! */
+    new_rep->cache_control = NULL;     // helps with debugging
     httpReplyDoDestroy(new_rep);
 }
 
@@ -361,18 +362,18 @@ httpReplyValidatorsMatch(HttpReply const * rep, HttpReply const * otherRep)
 
 
 void
-httpReplyUpdateOnNotModified(HttpReply * rep, HttpReply const * freshRep)
+HttpReply::httpReplyUpdateOnNotModified(HttpReply const * freshRep)
 {
-    assert(rep && freshRep);
+    assert(freshRep);
     /* Can not update modified headers that don't match! */
-    assert (httpReplyValidatorsMatch(rep, freshRep));
+    assert (httpReplyValidatorsMatch(this, freshRep));
     /* clean cache */
-    httpReplyHdrCacheClean(rep);
+    httpReplyHdrCacheClean(this);
     /* update raw headers */
-    httpHeaderUpdate(&rep->header, &freshRep->header,
+    httpHeaderUpdate(&header, &freshRep->header,
                      (const HttpHeaderMask *) &Denied304HeadersMask);
     /* init cache */
-    httpReplyHdrCacheInit(rep);
+    hdrCacheInit();
 }
 
 
@@ -435,30 +436,25 @@ httpReplyHdrExpirationTime(const HttpReply * rep)
 
 /* sync this routine when you update HttpReply struct */
 void
-httpReplyHdrCacheInit(HttpReply * rep)
+HttpReply::hdrCacheInit()
 {
-    const HttpHeader *hdr = &rep->header;
-    const char *str;
-    rep->content_length = httpHeaderGetInt(hdr, HDR_CONTENT_LENGTH);
-    rep->date = httpHeaderGetTime(hdr, HDR_DATE);
-    rep->last_modified = httpHeaderGetTime(hdr, HDR_LAST_MODIFIED);
-    str = httpHeaderGetStr(hdr, HDR_CONTENT_TYPE);
+    HttpMsg::hdrCacheInit();
+
+    content_length = httpHeaderGetInt(&header, HDR_CONTENT_LENGTH);
+    date = httpHeaderGetTime(&header, HDR_DATE);
+    last_modified = httpHeaderGetTime(&header, HDR_LAST_MODIFIED);
+    surrogate_control = httpHeaderGetSc(&header);
+    content_range = httpHeaderGetContRange(&header);
+    keep_alive = httpMsgIsPersistent(sline.version, &header);
+    const char *str = httpHeaderGetStr(&header, HDR_CONTENT_TYPE);
 
     if (str)
-        rep->content_type.limitInit(str, strcspn(str, ";\t "));
+        content_type.limitInit(str, strcspn(str, ";\t "));
     else
-        rep->content_type = String();
-
-    rep->cache_control = httpHeaderGetCc(hdr);
-
-    rep->surrogate_control = httpHeaderGetSc(hdr);
-
-    rep->content_range = httpHeaderGetContRange(hdr);
-
-    rep->keep_alive = httpMsgIsPersistent(rep->sline.version, &rep->header);
+        content_type = String();
 
     /* be sure to set expires after date and cache-control */
-    rep->expires = httpReplyHdrExpirationTime(rep);
+    expires = httpReplyHdrExpirationTime(this);
 }
 
 /* sync this routine when you update HttpReply struct */
@@ -467,14 +463,20 @@ httpReplyHdrCacheClean(HttpReply * rep)
 {
     rep->content_type.clean();
 
-    if (rep->cache_control)
+    if (rep->cache_control) {
         httpHdrCcDestroy(rep->cache_control);
+        rep->cache_control = NULL;
+    }
 
-    if (rep->surrogate_control)
+    if (rep->surrogate_control) {
         httpHdrScDestroy(rep->surrogate_control);
+        rep->surrogate_control = NULL;
+    }
 
-    if (rep->content_range)
+    if (rep->content_range) {
         httpHdrContRangeDestroy(rep->content_range);
+        rep->content_range = NULL;
+    }
 }
 
 /*
index c2bd40b96b88a5292a94a4a9ed4a592a77de477b..ba23bb5a60a9b878ea2d91b0a67b6d6c7d57658e 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpReply.h,v 1.9 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpReply.h,v 1.10 2005/09/15 19:22:30 wessels Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -65,8 +65,6 @@ extern MemBuf *httpPackedReply(HttpVersion ver, http_status status, const char *
 extern MemBuf *httpPacked304Reply(const HttpReply * rep);
 /* construct a 304 reply and return it */
 extern HttpReply *httpReplyMake304(const HttpReply *rep);
-/* update when 304 reply is received for a cached object */
-extern void httpReplyUpdateOnNotModified(HttpReply * rep, HttpReply const * freshRep);
 /* header manipulation */
 extern int httpReplyContentLen(const HttpReply * rep);
 extern const char *httpReplyContentType(const HttpReply * rep);
@@ -75,7 +73,6 @@ extern int httpReplyHasCc(const HttpReply * rep, http_hdr_cc_type type);
 extern void httpRedirectReply(HttpReply *, http_status, const char *);
 extern int httpReplyBodySize(method_t, HttpReply const *);
 extern int httpReplyValidatorsMatch (HttpReply const *, HttpReply const *);
-extern void httpReplyHdrCacheInit(HttpReply * rep);
 
 
 /* Sync changes here with HttpReply.cc */
@@ -111,8 +108,12 @@ public:
 
     String protoPrefix;       // e.g., "HTTP/"
 
+public:
+    void httpReplyUpdateOnNotModified(HttpReply const *other);
+
 protected:
     virtual void packFirstLineInto(Packer * p, bool) const;
+    virtual void hdrCacheInit();
 };
 
 MEMPROXY_CLASS_INLINE(HttpReply)
index 02bceb4d7fae33e0418082acc2e621edbab947b1..0ee3dfe7d9093bf47e3e1707aa9fc870082e40ac 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpRequest.cc,v 1.49 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpRequest.cc,v 1.50 2005/09/15 19:22:30 wessels Exp $
  *
  * DEBUG: section 73    HTTP Request
  * AUTHOR: Duane Wessels
@@ -91,8 +91,6 @@ requestCreate(method_t method, protocol_t protocol, const char *aUrlpath)
 
     req->my_addr = no_addr;
 
-    httpRequestHdrCacheInit(req);
-
     return req;
 }
 
@@ -128,8 +126,10 @@ void HttpRequest::clean()
 
     httpHeaderClean(&header);
 
-    if (cache_control)
+    if (cache_control) {
         httpHdrCcDestroy(cache_control);
+        cache_control = NULL;
+    }
 
     if (range)
         delete range;
@@ -188,17 +188,17 @@ requestUnlink(HttpRequest * request)
 }
 
 int
-httpRequestParseHeader(HttpRequest * req, const char *parse_start)
+HttpRequest::parseHeader(const char *parse_start)
 {
     const char *blk_start, *blk_end;
 
     if (!httpMsgIsolateHeaders(&parse_start, &blk_start, &blk_end))
         return 0;
 
-    int result = httpHeaderParse(&req->header, blk_start, blk_end);
+    int result = httpHeaderParse(&header, blk_start, blk_end);
 
     if (result)
-        httpRequestHdrCacheInit(req);
+        hdrCacheInit();
 
     return result;
 }
@@ -268,37 +268,11 @@ httpRequestHdrAllowed(const HttpHeaderEntry * e, String * strConn)
 
 /* sync this routine when you update HttpRequest struct */
 void
-httpRequestHdrCacheInit(HttpRequest * req)
+HttpRequest::hdrCacheInit()
 {
-    const HttpHeader *hdr = &req->header;
-    /*  const char *str; */
-    req->content_length = httpHeaderGetInt(hdr, HDR_CONTENT_LENGTH);
-    /* TODO: canonicalise these into an HttpEntity */
-#if 0
-
-    req->date = httpHeaderGetTime(hdr, HDR_DATE);
-    req->last_modified = httpHeaderGetTime(hdr, HDR_LAST_MODIFIED);
-    str = httpHeaderGetStr(hdr, HDR_CONTENT_TYPE);
-
-    if (str)
-        stringLimitInit(&req->content_type, str, strcspn(str, ";\t "));
-    else
-        req->content_type = String();
-
-#endif
+    HttpMsg::hdrCacheInit();
 
-    req->cache_control = httpHeaderGetCc(hdr);
-
-    req->range = httpHeaderGetRange(hdr);
-
-#if 0
-
-    req->keep_alive = httpMsgIsPersistent(req->http_ver, &req->header);
-
-    /* be sure to set expires after date and cache-control */
-    req->expires = httpReplyHdrExpirationTime(req);
-
-#endif
+    range = httpHeaderGetRange(&header);
 }
 
 /* request_flags */
index 002b42ee478ac5625220f232a9ea779457baf684..9b9a7c313ad09711b262a4a803df3f6fc260b4f9 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpRequest.h,v 1.12 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpRequest.h,v 1.13 2005/09/15 19:22:30 wessels Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -43,14 +43,11 @@ extern HttpRequest *requestCreate(method_t, protocol_t, const char *urlpath);
 extern void requestDestroy(HttpRequest *);
 extern HttpRequest *requestLink(HttpRequest *);
 extern void requestUnlink(HttpRequest *);
-extern int httpRequestParseHeader(HttpRequest * req, const char *parse_start);
 extern void httpRequestSwapOut(const HttpRequest * req, StoreEntry * e);
 extern void httpRequestPack(const HttpRequest * req, Packer * p);
 extern int httpRequestPrefixLen(const HttpRequest * req);
 extern int httpRequestHdrAllowed(const HttpHeaderEntry * e, String * strConnection);
 extern int httpRequestHdrAllowedByName(http_hdr_type id);
-extern void httpRequestHdrCacheInit(HttpRequest * req);
-
 
 class HttpHdrRange;
 
@@ -99,6 +96,7 @@ public:
 
 public:
     bool parseRequestLine(const char *start, const char *end);
+    int parseHeader(const char *parse_start);
 
 private:
     const char *packableURI(bool full_uri) const;
@@ -106,6 +104,7 @@ private:
 protected:
     virtual void packFirstLineInto(Packer * p, bool full_uri) const;
     virtual bool sanityCheckStartLine(MemBuf *buf, http_status *error);
+    virtual void hdrCacheInit();
 
 public: // should be private
     void clean(); // low-level; treat as private
index a9c160d8c7bced870adf6d77fe289e8f4ae2a86a..040303fa3969572b1854cb93ce6ea8723bc94f41 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.695 2005/09/14 21:09:38 wessels Exp $
+ * $Id: client_side.cc,v 1.696 2005/09/15 19:22:30 wessels Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -2205,7 +2205,7 @@ clientProcessRequest(ConnStateData::Pointer &conn, ClientSocketContext *context,
 
     /* compile headers */
     /* we should skip request line! */
-    if (!httpRequestParseHeader(request, prefix + req_line_sz)) {
+    if (!request->parseHeader(prefix + req_line_sz)) {
         clientStreamNode *node = context->getClientReplyContext();
         debug(33, 5) ("Failed to parse request headers:\n%s\n", prefix);
         clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
index 80dcf11011909bfbdcc489520cfb6b4063c15012..00a7ff80e89b5416e6814636e5e23df7c944b325 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_reply.cc,v 1.87 2005/09/14 17:10:38 serassio Exp $
+ * $Id: client_side_reply.cc,v 1.88 2005/09/15 19:22:30 wessels Exp $
  *
  * DEBUG: section 88    Client-side Reply Routines
  * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
@@ -427,7 +427,9 @@ clientReplyContext::handleIMSGiveClientUpdatedOldEntry()
          * www.thegist.com (Netscape/1.13) returns a content-length for
          * 304's which seems to be the length of the 304 HEADERS!!! and
          * not the body they refer to.  */
-        httpReplyUpdateOnNotModified((HttpReply *)old_entry->getReply(), http->storeEntry()->getReply());
+        HttpReply *old_rep = (HttpReply *) old_entry->getReply();
+
+        old_rep->httpReplyUpdateOnNotModified(http->storeEntry()->getReply());
 
         storeTimestampsSet(old_entry);
 
@@ -469,8 +471,8 @@ clientReplyContext::handleIMSGiveClientNewEntry()
         http->logType = LOG_TCP_REFRESH_MISS;
 
         if (HTTP_NOT_MODIFIED == http->storeEntry()->getReply()->sline.status) {
-            httpReplyUpdateOnNotModified((HttpReply *)old_entry->getReply(),
-                                         http->storeEntry()->getReply());
+            HttpReply *old_rep = (HttpReply *) old_entry->getReply();
+            old_rep->httpReplyUpdateOnNotModified(http->storeEntry()->getReply());
             storeTimestampsSet(old_entry);
             http->logType = LOG_TCP_REFRESH_HIT;
         }
index 60dd969b78950c52daad6911989ac4cc33959acd..5d02dbbca38d1a2ac18331a072cea9f401de586b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_request.cc,v 1.46 2005/09/12 22:26:39 wessels Exp $
+ * $Id: client_side_request.cc,v 1.47 2005/09/15 19:22:30 wessels Exp $
  * 
  * DEBUG: section 85    Client-side Request Routines
  * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
@@ -595,8 +595,6 @@ clientInterpretRequestHeaders(ClientHttpRequest * http)
         s.clean();
     }
 
-    request->cache_control = httpHeaderGetCc(req_hdr);
-
     if (request->cache_control)
         if (EBIT_TEST(request->cache_control->mask, CC_NO_CACHE))
             no_cache++;
index 36f3cffecd3c2ce87a49ed5c445d5d7ea92316d0..adaa0e0fb96177a756ff0e8c04f7aec404bce099 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: peer_digest.cc,v 1.103 2005/06/03 15:24:14 serassio Exp $
+ * $Id: peer_digest.cc,v 1.104 2005/09/15 19:22:30 wessels Exp $
  *
  * DEBUG: section 72    Peer Digest Routines
  * AUTHOR: Alex Rousskov
@@ -543,7 +543,9 @@ peerDigestFetchReply(void *data, char *buf, ssize_t size)
 
             assert(fetch->old_entry->mem_obj->request);
 
-            httpReplyUpdateOnNotModified((HttpReply *)fetch->old_entry->getReply(), reply);
+            HttpReply *old_rep = (HttpReply *) fetch->old_entry->getReply();
+
+            old_rep->httpReplyUpdateOnNotModified(reply);
 
             storeTimestampsSet(fetch->old_entry);