--------------------- PatchSet 1026 Date: 2004/06/07 00:35:41 Author: mmatusiak Branch: varyetag Tag: (none) Log: stale variant validation bug fix Members: src/Packer.cc:1.2.4.1->1.2.4.2 src/client_side_reply.cc:1.48.2.2->1.48.2.3 src/protos.h:1.41.2.1->1.41.2.2 Index: squid3/src/Packer.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Packer.cc,v retrieving revision 1.2.4.1 retrieving revision 1.2.4.2 diff -u -r1.2.4.1 -r1.2.4.2 --- squid3/src/Packer.cc 3 Jun 2004 22:50:06 -0000 1.2.4.1 +++ squid3/src/Packer.cc 7 Jun 2004 00:35:41 -0000 1.2.4.2 @@ -1,6 +1,6 @@ /* - * $Id: Packer.cc,v 1.2.4.1 2004/06/03 22:50:06 ahouhpuc Exp $ + * $Id: Packer.cc,v 1.2.4.2 2004/06/07 00:35:41 mmatusiak Exp $ * * DEBUG: section 60 Packer: A uniform interface to store-like modules * AUTHOR: Alex Rousskov @@ -92,49 +92,13 @@ * warning (e.g., "warning: assignment from incompatible pointer type"). */ -/* - * Appends buf directly to result, increases result->length - */ -static void -storeIOBufferAppend(StoreIOBuffer *result, const char *buf, int sz) { - debug(93, 9) ("storeIOBufferAppend: buf: %s\n", buf); - - assert(result && buf && sz >= 0 && result->data); - - if (sz == 0) - return; - - xmemcpy(result->data + result->length, buf, sz); - result->length += sz; - result->data[result->length] = '\0'; - -} - -/* - * to be used with short 304 replies only (short replies) - * XXX deal with replies larger than 4096B - */ -static void -storeIOBufferAppendVPrintf(StoreIOBuffer *result, const char *fmt, va_list vargs) { - debug(93, 9) ("storeIOBufferAppend: fmt: %s\n", fmt); - - assert(result && fmt && result->data); - LOCAL_ARRAY(char, buf, 4096); - buf[0] = '\0'; - vsnprintf(buf, 4096, fmt, vargs); - storeIOBufferAppend(result, buf, strlen(buf)); - -} - /* append()'s */ static void (*const store_append) (StoreEntry *, const char *, int) = &storeAppend; static void (*const memBuf_append) (MemBuf *, const char *, mb_size_t) = &memBufAppend; -static void (*const sIOBuf_append) (StoreIOBuffer *, const char *, int) = &storeIOBufferAppend; /* vprintf()'s */ static void (*const store_vprintf) (StoreEntry *, const char *, va_list ap) = &storeAppendVPrintf; static void (*const memBuf_vprintf) (MemBuf *, const char *, va_list ap) = &memBufVPrintf; -static void (*const sIOBuf_vprintf) (StoreIOBuffer *, const char *, va_list ap) = &storeIOBufferAppendVPrintf; /* init/clean */ @@ -159,23 +123,6 @@ p->real_handler = mb; } -/* init with this to accumulate data in StoreIOBuffer */ -void -packerToStoreIOBufferInit(Packer *p, StoreIOBuffer *result) { - - debug(93, 9) ("packerToStoreIOBufferInit: p: %p, result: %p\n", p, result); - - assert(p && result); - assert(result->data); - - p->append = (append_f) sIOBuf_append; - p->vprintf = (vprintf_f) sIOBuf_vprintf; - p->real_handler = result; - - result->length = 0; - result->offset = 0; -} - /* call this when you are done */ void packerClean(Packer * p) Index: squid3/src/client_side_reply.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/client_side_reply.cc,v retrieving revision 1.48.2.2 retrieving revision 1.48.2.3 diff -u -r1.48.2.2 -r1.48.2.3 --- squid3/src/client_side_reply.cc 6 Jun 2004 01:18:52 -0000 1.48.2.2 +++ squid3/src/client_side_reply.cc 7 Jun 2004 00:35:41 -0000 1.48.2.3 @@ -1,6 +1,6 @@ /* - * $Id: client_side_reply.cc,v 1.48.2.2 2004/06/06 01:18:52 mmatusiak Exp $ + * $Id: client_side_reply.cc,v 1.48.2.3 2004/06/07 00:35:41 mmatusiak Exp $ * * DEBUG: section 88 Client-side Reply Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -223,7 +223,8 @@ * copy of triggerInitialStoreRead but takes also a callback to call back at the end */ void -clientReplyContext::triggerInitialStoreReadClone(STCB * callback) { +clientReplyContext::triggerInitialStoreReadClone(STCB * callback) +{ StoreIOBuffer otherTempBuffer; /* when confident, 0 becomes reqofs, and then this factors into @@ -661,8 +662,7 @@ // - tempBufferVary - result saved in handleIMSReply // - vary_entry - base vary object // - vary_sc - // - after saveState() - // - old_entry - new 304 response from server (saved) + // - old_entry is stale entry or save new entry for update // 304's headers const HttpHeader *hdr = &old_entry->getReply()->header; @@ -672,7 +672,9 @@ assert(vary_entry->mem_obj); // vary_headers of the variant pointed to by etag_str - const char *vary_headers = vary_entry->mem_obj->etag_mapping->get((char*)etag_str); + + const char *vary_headers = vary_entry->mem_obj->etag_mapping->get + ((char*)etag_str); if (vary_headers) { // we have such a variant @@ -704,10 +706,11 @@ tempBuffer.offset = reqofs; tempBuffer.length = next()->readBuffer.length; tempBuffer.data = next()->readBuffer.data; + // XXX: we should update first storeClientCopy(sc, http->storeEntry(), tempBuffer, SendMoreData, this); } else { - + // here we didn't find variant, we send server response or stale entry debug(93, 9) ("fakeEntryToVariant: sending supposed garbage - no variant found\n"); restoreState(); sendMoreData(tempBufferVary); @@ -715,8 +718,8 @@ } } else { - //we haven't found correct etag->vary_headers mapping, so we must send client - //server response (probably garbage) + // we haven't found correct etag->vary_headers mapping, so we must send client + // server response (probably garbage) or stale entry debug(93, 9) ("fakeEntryToVariant: sending supposed garbage - no mapping\n"); restoreState(); sendMoreData(tempBufferVary); @@ -748,20 +751,28 @@ if (flags.varyvalidation) { debug(88, 9) ("handleIMSReply: variant handling\n"); + // we don't need old_entry anymore + if (old_entry) { + storeUnregister(old_sc, old_entry, this); + + // how to drop it? + storeUnlockObject(old_entry); + old_entry = NULL; + old_sc = NULL; + } + // XXX: it's not sufficient (but for now, we can leave this) // mmatusiak - // if other than HTTP_NOT_MODIFIED send response to client if (status != HTTP_NOT_MODIFIED) { debug(88, 9) ("handleIMSReply: new variant, proceed to sendMoreData()\n"); - if (old_entry) - storeUnregister(old_sc, old_entry, this); + sendMoreData(result); + return; } // XXX: what if entry got aborted? - // we have no existing entry and we don't know what to send to the client // mmatusiak StoreEntry *entry = http->storeEntry(); @@ -2363,7 +2374,8 @@ * see handleConditionalMiss */ void -clientReplyContext::HandleConditionalMiss(void *data, StoreIOBuffer result) { +clientReplyContext::HandleConditionalMiss(void *data, StoreIOBuffer result) +{ clientReplyContext *context = static_cast(data); context->handleConditionalMiss(result); } @@ -2375,7 +2387,8 @@ * in case the request isnot conditional passes to sendMoreData */ void -clientReplyContext::handleConditionalMiss(StoreIOBuffer result) { +clientReplyContext::handleConditionalMiss(StoreIOBuffer result) +{ HttpRequest *r = http->request; @@ -2492,13 +2505,19 @@ // tells if the code below changes the mappings int changed = 1; - if (!vhm->get((char*)vary_headers)) { + if (!vhm->get + ((char*)vary_headers)) { if (etag.str) { // there is ETag - if (em->get((char*)etag.str)) { - vhm->put((char*)vary_headers, (char*)em->get((char*)etag.str)); - } else { + + if (em->get + ((char*)etag.str)) { + + vhm->put((char*)vary_headers, (char*)em->get + ((char*)etag.str)); + } + else { vhm->put((char*)vary_headers, (char*)vary_headers); em->put((char*)etag.str, (char*)vary_headers); } @@ -2507,19 +2526,34 @@ vhm->put((char*)vary_headers, (char*)vary_headers); } - } else { + } + else { if (etag.str) { // there is ETag - if (em->get((char*)etag.str)) { - if (strcmp(vhm->get((char*)vary_headers), em->get((char*)etag.str))) { - vhm->remove((char*)vary_headers); - vhm->put((char*)vary_headers, em->get((char*)etag.str)); - } else + + if (em->get + ((char*)etag.str)) { + if (strcmp(vhm->get + ((char*)vary_headers), em->get + ((char*)etag.str))) { + + vhm->remove + ((char*)vary_headers); + + vhm->put((char*)vary_headers, em->get + ((char*)etag.str)); + } + else changed = 0; - } else { - vhm->remove((char*)vary_headers); + } + else { + + vhm->remove + ((char*)vary_headers); + vhm->put((char*)vary_headers, (char*)vary_headers); + em->put((char*)etag.str, (char*)vary_headers); } } else @@ -2584,7 +2618,8 @@ } else { flags.varycomplete = 2; - debug(93, 9) ("sendMoreData: no base vary entry found!\n");; + debug(93, 9) ("sendMoreData: no base vary entry found!\n"); + ; } Index: squid3/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/protos.h,v retrieving revision 1.41.2.1 retrieving revision 1.41.2.2 diff -u -r1.41.2.1 -r1.41.2.2 --- squid3/src/protos.h 3 Jun 2004 22:50:07 -0000 1.41.2.1 +++ squid3/src/protos.h 7 Jun 2004 00:35:41 -0000 1.41.2.2 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.41.2.1 2004/06/03 22:50:07 ahouhpuc Exp $ + * $Id: protos.h,v 1.41.2.2 2004/06/07 00:35:41 mmatusiak Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -164,8 +164,6 @@ SQUIDCEXTERN void packerToStoreInit(Packer * p, StoreEntry * e); SQUIDCEXTERN void packerToMemInit(Packer * p, MemBuf * mb); -class StoreIOBuffer; -SQUIDCEXTERN void packerToStoreIOBufferInit(Packer * p, StoreIOBuffer * res); SQUIDCEXTERN void packerClean(Packer * p); SQUIDCEXTERN void packerAppend(Packer * p, const char *buf, int size); #if STDC_HEADERS