From: robertc <> Date: Fri, 20 Jun 2003 07:00:57 +0000 (+0000) Subject: Summary: Encapsulate ClientHttpRequest::entry. X-Git-Tag: SQUID_3_0_PRE1~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86a2f789346153337437cbb1dd77210f98eecca0;p=thirdparty%2Fsquid.git Summary: Encapsulate ClientHttpRequest::entry. Keywords: * Add accessor and mutator methods storeEntry(). * Find all mutations, and convert to using the mutator. * Bugfix libTrie for --disable-inline builds. * Make ClientHttpRequest::memObject() const inline. * Introduce removeClientStoreReference to clientReplyContext to manage the encapsulation. * Add needed MemObject.h header includes to gopher, ftp and wais.cc. --- diff --git a/lib/libTrie/src/Trie.cc b/lib/libTrie/src/Trie.cc index 5964f778a7..3226e9be56 100644 --- a/lib/libTrie/src/Trie.cc +++ b/lib/libTrie/src/Trie.cc @@ -74,3 +74,7 @@ extern "C" int TrieAdd (void *aTrie, char const *aString, size_t theLength, void return ((Trie *)aTrie)->add (aString, theLength, privatedata); } + +#ifndef _USE_INLINE_ +#include "Trie.cci" +#endif diff --git a/lib/libTrie/src/TrieNode.cc b/lib/libTrie/src/TrieNode.cc index 8a677c54fd..a7f4786428 100644 --- a/lib/libTrie/src/TrieNode.cc +++ b/lib/libTrie/src/TrieNode.cc @@ -69,3 +69,7 @@ TrieNode::add } } +#ifndef _USE_INLINE_ +#include "TrieNode.cci" +#endif + diff --git a/src/Makefile.am b/src/Makefile.am index 96b926bfec..5ab9603ded 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.78 2003/05/21 02:58:10 robertc Exp $ +# $Id: Makefile.am,v 1.79 2003/06/20 01:00:57 robertc Exp $ # # Uncomment and customize the following to suit your needs: # @@ -431,6 +431,7 @@ squid_SOURCES = \ $(WIN32SOURCE) noinst_HEADERS = ACLChecklist.cci \ + client_side_request.cci \ MemBuf.cci \ MemBuf.h \ Store.cci \ diff --git a/src/client_side.cc b/src/client_side.cc index 7ac80e0b4f..d6dfdeedb2 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.640 2003/06/19 18:56:59 hno Exp $ + * $Id: client_side.cc,v 1.641 2003/06/20 01:01:00 robertc Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -462,15 +462,6 @@ ClientHttpRequest::updateCounters() clientUpdateHierCounters(&request->hier); } -MemObject * -ClientHttpRequest::memObject() const -{ - if (entry) - return entry->mem_obj; - - return NULL; -} - void clientPrepareLogWithRequestDetails(request_t * request, AccessLogEntry * aLogEntry) { @@ -873,9 +864,9 @@ ClientSocketContext::packRange(const char **buf, */ if (http->multipartRangeRequest() && i->debt() == i->currentSpec()->length) { - assert(http->entry->mem_obj); + assert(http->memObject()); clientPackRangeHdr( - http->entry->mem_obj->getReply(), /* original reply */ + http->memObject()->getReply(), /* original reply */ i->currentSpec(), /* current range */ i->boundary, /* boundary, the same for all */ mb); @@ -939,7 +930,7 @@ ClientHttpRequest::mRangeCLen() int clen = 0; MemBuf mb; - assert(entry->mem_obj); + assert(memObject()); memBufDefInit(&mb); HttpHdrRange::iterator pos = request->range->begin(); @@ -947,7 +938,7 @@ ClientHttpRequest::mRangeCLen() while (pos != request->range->end()) { /* account for headers for this range */ memBufReset(&mb); - clientPackRangeHdr(entry->mem_obj->getReply(), + clientPackRangeHdr(memObject()->getReply(), *pos, range_iter.boundary, &mb); clen += mb.size; @@ -1003,7 +994,7 @@ clientIfRangeMatch(clientHttpRequest * http, HttpReply * rep) /* got modification time? */ if (spec.time >= 0) { - return http->entry->lastmod <= spec.time; + return http->storeEntry()->lastmod <= spec.time; } assert(0); /* should not happen */ @@ -1019,7 +1010,7 @@ ClientHttpRequest::rangeBoundaryStr() const const char *key; String b (full_appname_string); b.append (":",1); - key = entry->getMD5Text(); + key = storeEntry()->getMD5Text(); b.append(key, strlen(key)); return b; } @@ -1048,7 +1039,7 @@ ClientSocketContext::buildRangeHeader(HttpReply * rep) else if (rep->content_length < 0) range_err = "unknown length"; - else if (rep->content_length != http->entry->mem_obj->getReply()->content_length) + else if (rep->content_length != http->memObject()->getReply()->content_length) range_err = "INCONSISTENT length"; /* a bug? */ else if (httpHeaderHas(&http->request->header, HDR_IF_RANGE) && !clientIfRangeMatch(http, rep)) range_err = "If-Range match failed"; @@ -1439,7 +1430,7 @@ clientWriteComplete(int fd, char *bufnotused, size_t size, comm_err_t errflag, v void ClientSocketContext::writeComplete(int fd, char *bufnotused, size_t size, comm_err_t errflag) { - StoreEntry *entry = http->entry; + StoreEntry *entry = http->storeEntry(); http->out.size += size; assert(fd > -1); debug(33, 5) ("clientWriteComplete: FD %d, sz %ld, err %d, off %ld, len %d\n", diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 285d7e6461..2b56168bf2 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side_reply.cc,v 1.53 2003/05/25 20:29:24 hno Exp $ + * $Id: client_side_reply.cc,v 1.54 2003/06/20 01:01:00 robertc Exp $ * * DEBUG: section 88 Client-side Reply Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -69,7 +69,7 @@ clientReplyContext::~clientReplyContext() /* This may trigger a callback back into SendMoreData as the cbdata * is still valid */ - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); /* old_entry might still be set if we didn't yet get the reply * code in HandleIMSReply() */ removeStoreReference(&old_sc, &old_entry); @@ -112,7 +112,7 @@ clientReplyContext::setReplyToError( } assert(errstate->callback_data == NULL); - errorAppendEntry(http->entry, errstate); + errorAppendEntry(http->storeEntry(), errstate); /* Now the caller reads to get this */ } @@ -131,6 +131,14 @@ clientReplyContext::removeStoreReference(store_client ** scp, } } +void +clientReplyContext::removeClientStoreReference(store_client **scp, ClientHttpRequest *http) +{ + StoreEntry *reference = http->storeEntry(); + removeStoreReference(scp, &reference); + http->storeEntry(reference); +} + void * clientReplyContext::operator new (size_t byteCount) { @@ -158,12 +166,12 @@ clientReplyContext::saveState() { assert(old_sc == NULL); debug(88, 3)("clientReplyContext::saveState: saving store context\n"); - old_entry = http->entry; + old_entry = http->storeEntry(); old_sc = sc; old_reqsize = reqsize; tempBuffer.offset = reqofs; /* Prevent accessing the now saved entries */ - http->entry = NULL; + http->storeEntry(NULL); sc = NULL; reqsize = 0; reqofs = 0; @@ -174,8 +182,8 @@ clientReplyContext::restoreState() { assert(old_sc != NULL); debug(88, 3)("clientReplyContext::restoreState: Restoring store context\n"); - removeStoreReference(&sc, &http->entry); - http->entry = old_entry; + removeClientStoreReference(&sc, http); + http->storeEntry(old_entry); sc = old_sc; reqsize = old_reqsize; reqofs = tempBuffer.offset; @@ -191,7 +199,7 @@ clientReplyContext::startError(ErrorState * err) { createStoreEntry(http->request->method, request_flags()); triggerInitialStoreRead(); - errorAppendEntry(http->entry, err); + errorAppendEntry(http->storeEntry(), err); } clientStreamNode * @@ -214,7 +222,7 @@ clientReplyContext::triggerInitialStoreRead() tempBuffer.offset = 0; tempBuffer.length = next()->readBuffer.length; tempBuffer.data = next()->readBuffer.data; - storeClientCopy(sc, http->entry, tempBuffer, SendMoreData, this); + storeClientCopy(sc, http->storeEntry(), tempBuffer, SendMoreData, this); } /* there is an expired entry in the store. @@ -226,7 +234,7 @@ clientReplyContext::processExpired() char *url = http->uri; StoreEntry *entry = NULL; debug(88, 3)("clientReplyContext::processExpired: '%s'", http->uri); - assert(http->entry->lastmod >= 0); + assert(http->storeEntry()->lastmod >= 0); /* * check if we are allowed to contact other servers * @?@: Instead of a 504 (Gateway Timeout) reply, we may want to return @@ -258,9 +266,9 @@ clientReplyContext::processExpired() http->request->lastmod = old_entry->lastmod; debug(88, 5)("clientReplyContext::processExpired : lastmod %ld", (long int) entry->lastmod); - http->entry = entry; + http->storeEntry(entry); assert(http->out.offset == 0); - fwdStart(http->conn ? http->conn->fd : -1, http->entry, http->request); + fwdStart(http->conn ? http->conn->fd : -1, http->storeEntry(), http->request); /* Register with storage manager to receive updates when data comes in. */ if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) @@ -276,7 +284,7 @@ clientReplyContext::processExpired() bool clientReplyContext::clientGetsOldEntry()const { - const http_status status = http->entry->getReply()->sline.status; + const http_status status = http->storeEntry()->getReply()->sline.status; if (0 == status) { debug(88, 5) ("clientGetsOldEntry: YES, broken HTTP reply\n"); @@ -313,7 +321,7 @@ clientReplyContext::clientGetsOldEntry()const /* This is a duplicate call through the HandleIMS code path. * Can we guarantee we don't need it elsewhere? */ - if (!httpReplyValidatorsMatch(http->entry->getReply(), + if (!httpReplyValidatorsMatch(http->storeEntry()->getReply(), old_entry->getReply())) { debug(88, 5) ("clientGetsOldEntry: NO, Old object has been invalidated" "by the new one\n"); @@ -344,7 +352,7 @@ clientReplyContext::sendClientUpstreamResponse() /* sendMoreData tracks the offset as well. * Force it back to zero */ reqofs = 0; - assert(!EBIT_TEST(http->entry->flags, ENTRY_ABORTED)); + assert(!EBIT_TEST(http->storeEntry()->flags, ENTRY_ABORTED)); /* TODO: provide sendMoreData with the ready parsed reply */ tempresult.length = reqsize; tempresult.data = tempbuf; @@ -364,7 +372,7 @@ clientReplyContext::sendClientOldEntry() /* Get the old request back */ restoreState(); /* here the data to send is in the next nodes buffers already */ - assert(!EBIT_TEST(http->entry->flags, ENTRY_ABORTED)); + assert(!EBIT_TEST(http->storeEntry()->flags, ENTRY_ABORTED)); /* sendMoreData tracks the offset as well. * Force it back to zero */ reqofs = 0; @@ -375,7 +383,7 @@ clientReplyContext::sendClientOldEntry() void clientReplyContext::cleanUpAfterIMSCheck() { - debug(88, 3) ("clientHandleIMSReply: ABORTED '%s'\n", storeUrl(http->entry)); + debug(88, 3) ("clientHandleIMSReply: ABORTED '%s'\n", storeUrl(http->storeEntry())); /* We have an existing entry, but failed to validate it */ /* Its okay to send the old one anyway */ http->logType = LOG_TCP_REFRESH_FAIL_HIT; @@ -387,13 +395,13 @@ clientReplyContext::handlePartialIMSHeaders() { /* more headers needed to decide */ debug(88, 3) ("clientHandleIMSReply: Incomplete headers for '%s'\n", - storeUrl(http->entry)); + storeUrl(http->storeEntry())); if (reqsize >= HTTP_REQBUF_SZ) { /* will not get any bigger than that */ debug(88, 3) ("clientHandleIMSReply: Reply is too large '%s', using old entry\n", - storeUrl(http->entry)); + storeUrl(http->storeEntry())); /* use old entry, this repeats the code above */ http->logType = LOG_TCP_REFRESH_FAIL_HIT; sendClientOldEntry(); @@ -412,12 +420,12 @@ clientReplyContext::handleIMSGiveClientUpdatedOldEntry() * headers have been loaded from disk. */ http->logType = LOG_TCP_REFRESH_HIT; - if (httpReplyValidatorsMatch(http->entry->getReply(), + if (httpReplyValidatorsMatch(http->storeEntry()->getReply(), old_entry->getReply())) { int unlink_request = 0; if (old_entry->mem_obj->request == NULL) { - old_entry->mem_obj->request = requestLink(http->entry->mem_obj->request); + old_entry->mem_obj->request = requestLink(http->memObject()->request); unlink_request = 1; } @@ -425,7 +433,7 @@ 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->entry->getReply()); + httpReplyUpdateOnNotModified((HttpReply *)old_entry->getReply(), http->storeEntry()->getReply()); storeTimestampsSet(old_entry); @@ -457,7 +465,7 @@ clientReplyContext::handleIMSGiveClientNewEntry() * Send the IMS reply to the client. */ sendClientUpstreamResponse(); - } else if (httpReplyValidatorsMatch (http->entry->getReply(), + } else if (httpReplyValidatorsMatch (http->storeEntry()->getReply(), old_entry->getReply())) { /* Our object is usable once updated */ /* the client did not ask for IMS, send the whole object @@ -466,9 +474,9 @@ clientReplyContext::handleIMSGiveClientNewEntry() StoreIOBuffer tempresult; http->logType = LOG_TCP_REFRESH_MISS; - if (HTTP_NOT_MODIFIED == http->entry->getReply()->sline.status) { + if (HTTP_NOT_MODIFIED == http->storeEntry()->getReply()->sline.status) { httpReplyUpdateOnNotModified((HttpReply *)old_entry->getReply(), - http->entry->getReply()); + http->storeEntry()->getReply()); storeTimestampsSet(old_entry); http->logType = LOG_TCP_REFRESH_HIT; } @@ -480,7 +488,7 @@ clientReplyContext::handleIMSGiveClientNewEntry() /* clientSendMoreData tracks the offset as well. * Force it back to zero */ reqofs = 0; - assert(!EBIT_TEST(http->entry->flags, ENTRY_ABORTED)); + assert(!EBIT_TEST(http->storeEntry()->flags, ENTRY_ABORTED)); /* TODO: provide SendMoreData with the ready parsed reply */ tempresult.length = reqsize; tempresult.data = tempbuf; @@ -507,23 +515,23 @@ void clientReplyContext::handleIMSReply(StoreIOBuffer result) { debug(88, 3) ("clientHandleIMSReply: %s, %lu bytes\n", - storeUrl(http->entry), + storeUrl(http->storeEntry()), (long unsigned) result.length); - if (http->entry == NULL) + if (http->storeEntry() == NULL) return; - if (result.flags.error && !EBIT_TEST(http->entry->flags, ENTRY_ABORTED)) + if (result.flags.error && !EBIT_TEST(http->storeEntry()->flags, ENTRY_ABORTED)) return; /* update size of the request */ reqsize = result.length + reqofs; - http_status status = http->entry->getReply()->sline.status; + http_status status = http->storeEntry()->getReply()->sline.status; - if (EBIT_TEST(http->entry->flags, ENTRY_ABORTED)) + if (EBIT_TEST(http->storeEntry()->flags, ENTRY_ABORTED)) cleanUpAfterIMSCheck(); - else if (STORE_PENDING == http->entry->store_status && 0 == status) + else if (STORE_PENDING == http->storeEntry()->store_status && 0 == status) handlePartialIMSHeaders(); else if (clientGetsOldEntry()) handleIMSGiveClientUpdatedOldEntry(); @@ -551,18 +559,18 @@ clientReplyContext::CacheHit(void *data, StoreIOBuffer result) void clientReplyContext::cacheHit(StoreIOBuffer result) { - StoreEntry *e = http->entry; + StoreEntry *e = http->storeEntry(); request_t *r = http->request; debug(88, 3) ("clientCacheHit: %s, %ud bytes\n", http->uri, (unsigned int)result.length); - if (http->entry == NULL) { + if (http->storeEntry() == NULL) { debug(88, 3) ("clientCacheHit: request aborted\n"); return; } else if (result.flags.error) { /* swap in failure */ debug(88, 3) ("clientCacheHit: swapin failure for %s\n", http->uri); http->logType = LOG_TCP_SWAPFAIL_MISS; - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); processMiss(); return; } @@ -628,7 +636,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result) /* This is not the correct entity for this request. We need * to requery the cache. */ - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); e = NULL; /* Note: varyEvalyateMatch updates the request with vary information * so we only get here once. (it also takes care of cancelling loops) @@ -645,7 +653,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result) } if (r->method == METHOD_PURGE) { - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); e = NULL; purgeRequest(); return; @@ -714,10 +722,10 @@ clientReplyContext::cacheHit(StoreIOBuffer result) time_t const timestamp = e->timestamp; HttpReply *temprep = httpReplyMake304 (e->getReply()); http->logType = LOG_TCP_IMS_HIT; - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); createStoreEntry(http->request->method, request_flags()); - e = http->entry; + e = http->storeEntry(); /* * Copy timestamp from the original entry so the 304 * reply has a meaningful Age: header. @@ -761,15 +769,15 @@ clientReplyContext::processMiss() * or IMS request. */ - if (http->entry) { - if (EBIT_TEST(http->entry->flags, ENTRY_SPECIAL)) { + if (http->storeEntry()) { + if (EBIT_TEST(http->storeEntry()->flags, ENTRY_SPECIAL)) { debug(88, 0) ("clientProcessMiss: miss on a special object (%s).\n", url); debug(88, 0) ("\tlog_type = %s\n", log_tags[http->logType]); - storeEntryDump(http->entry, 1); + storeEntryDump(http->storeEntry(), 1); } - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); } if (r->method == METHOD_PURGE) { @@ -791,7 +799,7 @@ clientReplyContext::processMiss() clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, &http->conn->peer.sin_addr, http->request); createStoreEntry(r->method, request_flags()); - errorAppendEntry(http->entry, err); + errorAppendEntry(http->storeEntry(), err); triggerInitialStoreRead(); return; } else { @@ -806,18 +814,18 @@ clientReplyContext::processMiss() http->logType = LOG_TCP_REDIRECT; #endif - storeReleaseRequest(http->entry); + storeReleaseRequest(http->storeEntry()); httpRedirectReply(rep, http->redirect.status, http->redirect.location); - httpReplySwapOut(rep, http->entry); - http->entry->complete(); + httpReplySwapOut(rep, http->storeEntry()); + http->storeEntry()->complete(); return; } if (http->flags.internal) r->protocol = PROTO_INTERNAL; - fwdStart(http->conn ? http->conn->fd : -1, http->entry, r); + fwdStart(http->conn ? http->conn->fd : -1, http->storeEntry(), r); } } @@ -836,7 +844,7 @@ clientReplyContext::processOnlyIfCachedMiss() http->al.http.code = HTTP_GATEWAY_TIMEOUT; err = clientBuildError(ERR_ONLY_IF_CACHED_MISS, HTTP_GATEWAY_TIMEOUT, NULL, &http->conn->peer.sin_addr, http->request); - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); startError(err); } @@ -889,17 +897,17 @@ clientReplyContext::purgeFoundObject(StoreEntry *entry) assert (entry && !entry->isNull()); StoreIOBuffer tempBuffer; /* Swap in the metadata */ - http->entry = entry; - storeLockObject(http->entry); - storeCreateMemObject(http->entry, http->uri, http->log_uri); - http->entry->mem_obj->method = http->request->method; - sc = storeClientListAdd(http->entry, this); + http->storeEntry(entry); + storeLockObject(http->storeEntry()); + storeCreateMemObject(http->storeEntry(), http->uri, http->log_uri); + http->storeEntry()->mem_obj->method = http->request->method; + sc = storeClientListAdd(http->storeEntry(), this); http->logType = LOG_TCP_HIT; reqofs = 0; tempBuffer.offset = http->out.offset; tempBuffer.length = next()->readBuffer.length; tempBuffer.data = next()->readBuffer.data; - storeClientCopy(sc, http->entry, + storeClientCopy(sc, http->storeEntry(), tempBuffer, CacheHit, this); } @@ -1005,9 +1013,9 @@ clientReplyContext::purgeDoPurgeHead(StoreEntry *newEntry) httpReplySetHeaders(r, version, purgeStatus, NULL, NULL, 0, 0, -1); - httpReplySwapOut(r, http->entry); + httpReplySwapOut(r, http->storeEntry()); - http->entry->complete(); + http->storeEntry()->complete(); } void @@ -1022,17 +1030,17 @@ clientReplyContext::traceReply(clientStreamNode * node) tempBuffer.offset = next->readBuffer.offset + headers_sz; tempBuffer.length = next->readBuffer.length; tempBuffer.data = next->readBuffer.data; - storeClientCopy(sc, http->entry, + storeClientCopy(sc, http->storeEntry(), tempBuffer, SendMoreData, this); - storeReleaseRequest(http->entry); - storeBuffer(http->entry); + storeReleaseRequest(http->storeEntry()); + storeBuffer(http->storeEntry()); rep = httpReplyCreate(); httpBuildVersion(&version, 1, 0); httpReplySetHeaders(rep, version, HTTP_OK, NULL, "text/plain", httpRequestPrefixLen(http->request), 0, squid_curtime); - httpReplySwapOut(rep, http->entry); - httpRequestSwapOut(http->request, http->entry); - http->entry->complete(); + httpReplySwapOut(rep, http->storeEntry()); + httpRequestSwapOut(http->request, http->storeEntry()); + http->storeEntry()->complete(); } #define SENDING_BODY 0 @@ -1040,7 +1048,7 @@ clientReplyContext::traceReply(clientStreamNode * node) int clientReplyContext::checkTransferDone() { - StoreEntry *entry = http->entry; + StoreEntry *entry = http->storeEntry(); if (entry == NULL) return 0; @@ -1068,7 +1076,7 @@ clientReplyContext::checkTransferDone() int clientReplyContext::storeOKTransferDone() const { - if (http->out.offset >= objectLen(http->entry) - headers_sz) + if (http->out.offset >= objectLen(http->storeEntry()) - headers_sz) return 1; return 0; @@ -1080,7 +1088,7 @@ clientReplyContext::storeNotOKTransferDone() const /* * Now, handle STORE_PENDING objects */ - MemObject *mem = http->entry->mem_obj; + MemObject *mem = http->storeEntry()->mem_obj; assert(mem != NULL); assert(http->request != NULL); /* mem->reply was wrong because it uses the UPSTREAM header length!!! */ @@ -1177,10 +1185,10 @@ clientReplyContext::replyStatus() int done; /* Here because lower nodes don't need it */ - if (http->entry == NULL) + if (http->storeEntry() == NULL) return STREAM_FAILED; /* yuck, but what can we do? */ - if (EBIT_TEST(http->entry->flags, ENTRY_ABORTED)) + if (EBIT_TEST(http->storeEntry()->flags, ENTRY_ABORTED)) /* TODO: Could upstream read errors (result.flags.error) be * lost, and result in undersize requests being considered * complete. Should we tcp reset such connections ? @@ -1192,7 +1200,7 @@ clientReplyContext::replyStatus() /* Ok we're finished, but how? */ if (httpReplyBodySize(http->request->method, - http->entry->getReply()) < 0) { + http->storeEntry()->getReply()) < 0) { debug(88, 5) ("clientReplyStatus: closing, content_length < 0\n"); return STREAM_FAILED; } @@ -1337,13 +1345,13 @@ clientReplyContext::buildReplyHeader() * information to the reply in any case. */ - if (NULL == http->entry) + if (NULL == http->storeEntry()) (void) 0; - else if (http->entry->timestamp < 0) + else if (http->storeEntry()->timestamp < 0) (void) 0; - else if (http->entry->timestamp < squid_curtime) { + else if (http->storeEntry()->timestamp < squid_curtime) { httpHeaderPutInt(hdr, HDR_AGE, - squid_curtime - http->entry->timestamp); + squid_curtime - http->storeEntry()->timestamp); /* Signal old objects. NB: rfc 2616 is not clear, * by implication, on whether we should do this to all * responses, or only cache hits. @@ -1353,7 +1361,7 @@ clientReplyContext::buildReplyHeader() */ /* TODO: if maxage or s-maxage is present, don't do this */ - if (squid_curtime - http->entry->timestamp >= 86400) { + if (squid_curtime - http->storeEntry()->timestamp >= 86400) { char tempbuf[512]; snprintf (tempbuf, sizeof(tempbuf), "%s %s %s", "113", ThisCache, @@ -1434,7 +1442,7 @@ clientReplyContext::buildReplyHeader() * debugger [hdr->entries.count-1]. */ httpHeaderPutStr(hdr, HDR_X_REQUEST_URI, - http->entry->mem_obj->url ? http->entry->mem_obj->url : http->uri); + http->memOjbect()->url ? http->memObject()->url : http->uri); #endif @@ -1493,12 +1501,12 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry) request_t *r = http->request; if (e->isNull()) { - http->entry = NULL; + http->storeEntry(NULL); } else { - http->entry = e; + http->storeEntry(e); } - e = http->entry; + e = http->storeEntry(); /* Release negatively cached IP-cache entries on reload */ if (r->flags.nocache) @@ -1512,11 +1520,11 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry) #endif #if USE_CACHE_DIGESTS - lookup_type = http->entry ? "HIT" : "MISS"; + lookup_type = http->storeEntry() ? "HIT" : "MISS"; #endif - if (NULL == http->entry) { + if (NULL == http->storeEntry()) { /* this object isn't in the cache */ debug(85, 3) ("clientProcessRequest2: storeGet() MISS\n"); http->logType = LOG_TCP_MISS; @@ -1533,7 +1541,7 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry) if (http->redirect.status) { /* force this to be a miss */ - http->entry = NULL; + http->storeEntry(NULL); http->logType = LOG_TCP_MISS; doGetMoreData(); return; @@ -1541,7 +1549,7 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry) if (!storeEntryValidToSend(e)) { debug(85, 3) ("clientProcessRequest2: !storeEntryValidToSend MISS\n"); - http->entry = NULL; + http->storeEntry(NULL); http->logType = LOG_TCP_MISS; doGetMoreData(); return; @@ -1556,10 +1564,10 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry) } #if HTTP_VIOLATIONS - if (http->entry->store_status == STORE_PENDING) { + if (http->storeEntry()->store_status == STORE_PENDING) { if (r->flags.nocache || r->flags.nocache_hack) { debug(85, 3) ("Clearing no-cache for STORE_PENDING request\n\t%s\n", - storeUrl(http->entry)); + storeUrl(http->storeEntry())); r->flags.nocache = 0; r->flags.nocache_hack = 0; } @@ -1568,7 +1576,7 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry) #endif if (r->flags.nocache) { debug(85, 3) ("clientProcessRequest2: no-cache REFRESH MISS\n"); - http->entry = NULL; + http->storeEntry(NULL); http->logType = LOG_TCP_CLIENT_REFRESH_MISS; doGetMoreData(); return; @@ -1582,7 +1590,7 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry) if (r->flags.range) { /* XXX: test to see if we can satisfy the range with the cached object */ debug(85, 3) ("clientProcessRequest2: force MISS due to range presence\n"); - http->entry = NULL; + http->storeEntry(NULL); http->logType = LOG_TCP_MISS; doGetMoreData(); return; @@ -1625,7 +1633,7 @@ clientGetMoreData(clientStreamNode * aNode, clientHttpRequest * http) tempBuffer.length = next->readBuffer.length; tempBuffer.data = next->readBuffer.data; - storeClientCopy(context->sc, http->entry, + storeClientCopy(context->sc, http->storeEntry(), tempBuffer, clientReplyContext::SendMoreData, context); return; } @@ -1654,12 +1662,12 @@ clientReplyContext::doGetMoreData() { /* We still have to do store logic processing - vary, cache hit etc */ - if (http->entry != NULL) { + if (http->storeEntry() != NULL) { /* someone found the object in the cache for us */ StoreIOBuffer tempBuffer; - storeLockObject(http->entry); + storeLockObject(http->storeEntry()); - if (http->entry->mem_obj == NULL) { + if (http->storeEntry()->mem_obj == NULL) { /* * This if-block exists because we don't want to clobber * a preexiting mem_obj->method value if the mem_obj @@ -1667,13 +1675,13 @@ clientReplyContext::doGetMoreData() * is a cache hit for a GET response, we want to keep * the method as GET. */ - storeCreateMemObject(http->entry, http->uri, + storeCreateMemObject(http->storeEntry(), http->uri, http->log_uri); - http->entry->mem_obj->method = + http->storeEntry()->mem_obj->method = http->request->method; } - sc = storeClientListAdd(http->entry, this); + sc = storeClientListAdd(http->storeEntry(), this); #if DELAY_POOLS sc->setDelayId(DelayId::DelayClient(http)); @@ -1687,7 +1695,7 @@ clientReplyContext::doGetMoreData() tempBuffer.offset = reqofs; tempBuffer.length = getNextNode()->readBuffer.length; tempBuffer.data = getNextNode()->readBuffer.data; - storeClientCopy(sc, http->entry, + storeClientCopy(sc, http->storeEntry(), tempBuffer, CacheHit, this); } else { /* MISS CASE, http->logType is already set! */ @@ -1726,7 +1734,7 @@ bool clientReplyContext::errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const { return /* aborted request */ - (http->entry && EBIT_TEST(http->entry->flags, ENTRY_ABORTED)) || + (http->storeEntry() && EBIT_TEST(http->storeEntry()->flags, ENTRY_ABORTED)) || /* Upstream read error */ (result.flags.error) || /* Upstream EOF */ (sizeToProcess == 0); } @@ -1796,7 +1804,7 @@ clientReplyContext::startSendProcess() tempBuffer.offset = reqofs; tempBuffer.length = next()->readBuffer.length - reqofs; tempBuffer.data = next()->readBuffer.data + reqofs; - storeClientCopy(sc, http->entry, + storeClientCopy(sc, http->storeEntry(), tempBuffer, SendMoreData, this); } @@ -1847,7 +1855,7 @@ clientReplyContext::processReplyAccess () clientBuildError(ERR_TOO_BIG, HTTP_FORBIDDEN, NULL, http->conn ? &http->conn->peer.sin_addr : &no_addr, http->request); - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); startError(err); httpReplyDestroy(rep); return; @@ -1888,7 +1896,7 @@ clientReplyContext::processReplyAccessResult(bool accessAllowed) clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, http->conn ? &http->conn->peer.sin_addr : &no_addr, http->request); - removeStoreReference(&sc, &http->entry); + removeClientStoreReference(&sc, http); startError(err); httpReplyDestroy(rep); return; @@ -1951,7 +1959,7 @@ clientReplyContext::sendMoreData (StoreIOBuffer result) if (deleting) return; - StoreEntry *entry = http->entry; + StoreEntry *entry = http->storeEntry(); ConnStateData *conn = http->conn; @@ -2129,7 +2137,7 @@ clientReplyContext::createStoreEntry(method_t m, request_flags flags) /* NOTE: after ANY data flows down the pipe, even one step, * this function CAN NOT be used to manage errors */ - http->entry = e; + http->storeEntry(e); } ErrorState * diff --git a/src/client_side_reply.h b/src/client_side_reply.h index bc551fca48..5c8a5237b3 100644 --- a/src/client_side_reply.h +++ b/src/client_side_reply.h @@ -1,6 +1,6 @@ /* - * $Id: client_side_reply.h,v 1.3 2003/05/11 13:53:03 hno Exp $ + * $Id: client_side_reply.h,v 1.4 2003/06/20 01:01:00 robertc Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -77,6 +77,7 @@ public: void setReplyToError(err_type, http_status, method_t, char const *, struct in_addr *, request_t *, char *, auth_user_request_t *); void createStoreEntry(method_t m, request_flags flags); void removeStoreReference(store_client ** scp, StoreEntry ** ep); + void removeClientStoreReference(store_client **scp, ClientHttpRequest *http); void startError(ErrorState * err); bool clientGetsOldEntry() const; void processExpired(); diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 16ee27747f..97cec62b4e 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side_request.cc,v 1.22 2003/05/18 00:04:07 robertc Exp $ + * $Id: client_side_request.cc,v 1.23 2003/06/20 01:01:00 robertc Exp $ * * DEBUG: section 85 Client-side Request Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -52,6 +52,7 @@ #include "client_side_reply.h" #include "Store.h" #include "HttpReply.h" +#include "MemObject.h" #if LINGERING_CLOSE #define comm_close comm_lingering_close @@ -867,8 +868,9 @@ ClientHttpRequest::httpStart() bool ClientHttpRequest::gotEnough() const { + /** TODO: should be querying the stream. */ int contentLength = - httpReplyBodySize(request->method, entry->mem_obj->getReply()); + httpReplyBodySize(request->method, memObject()->getReply()); assert(contentLength >= 0); if (out.offset < contentLength) @@ -900,3 +902,14 @@ ClientHttpRequest::isReplyBodyTooLarge(ssize_t clen) const return clen > maxReplyBodySize(); } + +void +ClientHttpRequest::storeEntry(StoreEntry *newEntry) +{ + entry_ = newEntry; +} + + +#ifndef _USE_INLINE_ +#include "client_side_request.cci" +#endif diff --git a/src/client_side_request.cci b/src/client_side_request.cci new file mode 100644 index 0000000000..2e622f655e --- /dev/null +++ b/src/client_side_request.cci @@ -0,0 +1,51 @@ + +/* + * $Id: client_side_request.cci,v 1.1 2003/06/20 01:01:05 robertc Exp $ + * + * DEBUG: section 85 Client-side Request Routines + * AUTHOR: Robert Collins + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + * Copyright (c) 2003, Robert Collins + */ + +StoreEntry * +ClientHttpRequest::storeEntry() const +{ + return entry_; +} + +MemObject * +ClientHttpRequest::memObject() const +{ + if (storeEntry()) + return storeEntry()->mem_obj; + + return NULL; +} + diff --git a/src/client_side_request.h b/src/client_side_request.h index 6621aef671..7b7e1fb314 100644 --- a/src/client_side_request.h +++ b/src/client_side_request.h @@ -1,6 +1,6 @@ /* - * $Id: client_side_request.h,v 1.10 2003/05/11 13:53:03 hno Exp $ + * $Id: client_side_request.h,v 1.11 2003/06/20 01:01:00 robertc Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -62,12 +62,14 @@ public: void freeResources(); void updateCounters(); void logRequest(); - MemObject * memObject() const; + _SQUID_INLINE_ MemObject * memObject() const; bool multipartRangeRequest() const; void processRequest(); void httpStart(); bool onlyIfCached()const; bool gotEnough() const; + _SQUID_INLINE_ StoreEntry *storeEntry() const; + void storeEntry(StoreEntry *); ConnStateData *conn; request_t *request; /* Parsed URL ... */ @@ -84,7 +86,6 @@ public: out; HttpHdrRangeIter range_iter; /* data for iterating thru range specs */ size_t req_sz; /* raw request size on input, not current request size */ - StoreEntry *entry; log_type logType; struct timeval start; @@ -128,8 +129,9 @@ unsigned int purging: bool isReplyBodyTooLarge(ssize_t len) const; private: - ssize_t maxReplyBodySize_; CBDATA_CLASS(ClientHttpRequest); + ssize_t maxReplyBodySize_; + StoreEntry *entry_; }; /* client http based routines */ @@ -143,4 +145,8 @@ SQUIDCEXTERN void redirectStart(clientHttpRequest *, RH *, void *); SQUIDCEXTERN void sslStart(clientHttpRequest *, size_t *, int *); +#ifdef _USE_INLINE_ +#include "client_side_request.cci" +#endif + #endif /* SQUID_CLIENTSIDEREQUEST_H */ diff --git a/src/ftp.cc b/src/ftp.cc index a5b5aefb58..fd5f8ac15a 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.349 2003/06/09 04:51:10 robertc Exp $ + * $Id: ftp.cc,v 1.350 2003/06/20 01:01:00 robertc Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -44,6 +44,7 @@ #include "HttpHeader.h" #if DELAY_POOLS #include "DelayPools.h" +#include "MemObject.h" #endif #include "ConnectionDetail.h" diff --git a/src/gopher.cc b/src/gopher.cc index e2a8859f95..f7dbbf2cf6 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,6 +1,6 @@ /* - * $Id: gopher.cc,v 1.182 2003/03/06 06:21:38 robertc Exp $ + * $Id: gopher.cc,v 1.183 2003/06/20 01:01:00 robertc Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -39,6 +39,7 @@ #include "comm.h" #if DELAY_POOLS #include "DelayPools.h" +#include "MemObject.h" #endif /* gopher type code from rfc. Anawat. */ diff --git a/src/stat.cc b/src/stat.cc index 3fb08e74bf..31061bf3ad 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.374 2003/04/24 06:35:09 hno Exp $ + * $Id: stat.cc,v 1.375 2003/06/20 01:01:01 robertc Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -1604,7 +1604,7 @@ statClientRequests(StoreEntry * s) storeAppendPrintf(s, "out.offset %ld, out.size %lu\n", (long int) http->out.offset, (unsigned long int) http->out.size); storeAppendPrintf(s, "req_sz %ld\n", (long int) http->req_sz); - e = http->entry; + e = http->storeEntry(); storeAppendPrintf(s, "entry %p/%s\n", e, e ? e->getMD5Text() : "N/A"); #if 0 /* Not a member anymore */ diff --git a/src/wais.cc b/src/wais.cc index d64b2cac00..e843abb68e 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,6 +1,6 @@ /* - * $Id: wais.cc,v 1.148 2003/03/04 01:40:31 robertc Exp $ + * $Id: wais.cc,v 1.149 2003/06/20 01:01:01 robertc Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -38,6 +38,7 @@ #include "HttpRequest.h" #if DELAY_POOLS #include "DelayPools.h" +#include "MemObject.h" #endif #include "comm.h"