From: wessels <> Date: Fri, 16 Sep 2005 01:22:30 +0000 (+0000) Subject: Made httpReplyHdrCacheInit() and httpRequestHdrCacheInit() into virtual X-Git-Tag: SQUID_3_0_PRE4~614 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07947ad86cbaef1c6b29d3387e5dd227331ff8fd;p=thirdparty%2Fsquid.git Made httpReplyHdrCacheInit() and httpRequestHdrCacheInit() into virtual 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. --- diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index 48b418ad2a..722ebd0cc2 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -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); +} diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 4b122abb90..5f302a5961 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -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(); }; diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 0b52f9e7e4..9b9844571b 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -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; + } } /* diff --git a/src/HttpReply.h b/src/HttpReply.h index c2bd40b96b..ba23bb5a60 100644 --- a/src/HttpReply.h +++ b/src/HttpReply.h @@ -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) diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 02bceb4d7f..0ee3dfe7d9 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -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 */ diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 002b42ee47..9b9a7c313a 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -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 diff --git a/src/client_side.cc b/src/client_side.cc index a9c160d8c7..040303fa39 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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(node->data.getRaw()); diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 80dcf11011..00a7ff80e8 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -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; } diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 60dd969b78..5d02dbbca3 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -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++; diff --git a/src/peer_digest.cc b/src/peer_digest.cc index 36f3cffecd..adaa0e0fb9 100644 --- a/src/peer_digest.cc +++ b/src/peer_digest.cc @@ -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);