--------------------- PatchSet 2396 Date: 2001/05/28 16:07:16 Author: hno Branch: etag Tag: (none) Log: Parse ETag as simple strings Members: src/ETag.c:1.4.46.1->1.4.46.2(DEAD) src/HttpHeader.c:1.6->1.6.18.1 src/client_side.c:1.29->1.29.2.1 src/protos.h:1.29->1.29.2.1 src/store.c:1.12.14.3->1.12.14.4 src/structs.h:1.33->1.33.4.1 --- squid/src/ETag.c Wed Feb 14 00:53:29 2007 +++ /dev/null Wed Feb 14 00:52:54 2007 @@ -1,67 +0,0 @@ - -/* - * $Id: ETag.c,v 1.4.46.1 2001/05/28 11:47:49 hno Exp $ - * - * DEBUG: none ETag parsing support - * AUTHOR: Alex Rousskov - * - * 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. - * - */ - -#include "squid.h" - -/* - * Note: ETag is not an http "field" like, for example HttpHdrRange. ETag is a - * field-value that maybe used in many http fields. - */ - -/* parses a string as weak or strong entity-tag; returns true on success */ -/* note: we do not duplicate "str"! */ -int -etagParseInit(ETag * etag, const char *str) -{ - int len; - assert(etag && str); - etag->str = NULL; - etag->weak = !strncmp(str, "W/", 2); - if (etag->weak) - str += 2; - /* check format (quoted-string) */ - len = strlen(str); - if (len >= 2 && str[0] == '"' && str[len - 1] == '"') - etag->str = str; - return etag->str != NULL; -} - -/* returns true if etags are equal */ -int -etagIsEqual(const ETag * tag1, const ETag * tag2) -{ - assert(tag1 && tag2); - return (tag1->weak == tag2->weak) && !strcmp(tag1->str, tag2->str); -} Index: squid/src/HttpHeader.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpHeader.c,v retrieving revision 1.6 retrieving revision 1.6.18.1 diff -u -r1.6 -r1.6.18.1 --- squid/src/HttpHeader.c 14 Apr 2001 00:31:01 -0000 1.6 +++ squid/src/HttpHeader.c 28 May 2001 16:07:16 -0000 1.6.18.1 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.c,v 1.6 2001/04/14 00:31:01 squidadm Exp $ + * $Id: HttpHeader.c,v 1.6.18.1 2001/05/28 16:07:16 hno Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -86,7 +86,7 @@ {"Content-Type", HDR_CONTENT_TYPE, ftStr}, {"Cookie", HDR_COOKIE, ftStr}, {"Date", HDR_DATE, ftDate_1123}, - {"ETag", HDR_ETAG, ftETag}, + {"ETag", HDR_ETAG, ftStr}, {"Expires", HDR_EXPIRES, ftDate_1123}, {"From", HDR_FROM, ftStr}, {"Host", HDR_HOST, ftStr}, @@ -898,18 +898,6 @@ return base64_decode(field); } -ETag -httpHeaderGetETag(const HttpHeader * hdr, http_hdr_type id) -{ - ETag etag = - {NULL, -1}; - HttpHeaderEntry *e; - assert(Headers[id].type == ftETag); /* must be of an appropriate type */ - if ((e = httpHeaderFindEntry(hdr, id))) - etagParseInit(&etag, strBuf(e->value)); - return etag; -} - TimeOrTag httpHeaderGetTimeOrTag(const HttpHeader * hdr, http_hdr_type id) { @@ -920,17 +908,20 @@ if ((e = httpHeaderFindEntry(hdr, id))) { const char *str = strBuf(e->value); /* try as an ETag */ - if (etagParseInit(&tot.tag, str)) { - tot.valid = tot.tag.str != NULL; + if (*str == '"' || (str[0] == 'W' && str[1] == '/')) { + tot.tag = str; tot.time = -1; + tot.valid = 1; } else { /* or maybe it is time? */ tot.time = parse_rfc1123(str); - tot.valid = tot.time >= 0; - tot.tag.str = NULL; + if (tot.time >= 0) + tot.valid = 1; + tot.tag = NULL; } + } else { + tot.time = -1; } - assert(tot.time < 0 || !tot.tag.str); /* paranoid */ return tot; } Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.29 retrieving revision 1.29.2.1 diff -u -r1.29 -r1.29.2.1 --- squid/src/client_side.c 21 May 2001 18:51:19 -0000 1.29 +++ squid/src/client_side.c 28 May 2001 16:07:16 -0000 1.29.2.1 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.29 2001/05/21 18:51:19 squidadm Exp $ + * $Id: client_side.c,v 1.29.2.1 2001/05/28 16:07:16 hno Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1130,21 +1130,21 @@ if (!spec.valid) return 0; /* got an ETag? */ - if (spec.tag.str) { - ETag rep_tag = httpHeaderGetETag(&rep->header, HDR_ETAG); + if (spec.tag) { + const char *rep_tag = httpHeaderGetStr(&rep->header, HDR_ETAG); debug(33, 3) ("clientIfRangeMatch: ETags: %s and %s\n", - spec.tag.str, rep_tag.str ? rep_tag.str : ""); - if (!rep_tag.str) + spec.tag, rep_tag ? rep_tag : ""); + if (!rep_tag) return 0; /* entity has no etag to compare with! */ - if (spec.tag.weak || rep_tag.weak) { + if (spec.tag[0] == 'W' || rep_tag[0] == 'W') { debug(33, 1) ("clientIfRangeMatch: Weak ETags are not allowed in If-Range: %s ? %s\n", - spec.tag.str, rep_tag.str); + spec.tag, rep_tag); return 0; /* must use strong validator for sub-range requests */ } - return etagIsEqual(&rep_tag, &spec.tag); + return strcmp(rep_tag, spec.tag) == 0; } /* got modification time? */ - if (spec.time >= 0) { + else if (spec.time >= 0) { return http->entry->lastmod <= spec.time; } assert(0); /* should not happen */ Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.29 retrieving revision 1.29.2.1 diff -u -r1.29 -r1.29.2.1 --- squid/src/protos.h 21 May 2001 18:51:19 -0000 1.29 +++ squid/src/protos.h 28 May 2001 16:07:16 -0000 1.29.2.1 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.29 2001/05/21 18:51:19 squidadm Exp $ + * $Id: protos.h,v 1.29.2.1 2001/05/28 16:07:16 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -307,10 +307,6 @@ extern void httpBuildVersion(http_version_t * version, unsigned int major, unsigned int minor); extern const char *httpMakeVaryMark(request_t * request, HttpReply * reply); -/* ETag */ -extern int etagParseInit(ETag * etag, const char *str); -extern int etagIsEqual(const ETag * tag1, const ETag * tag2); - /* Http Status Line */ /* init/clean */ extern void httpStatusLineInit(HttpStatusLine * sline); Index: squid/src/store.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store.c,v retrieving revision 1.12.14.3 retrieving revision 1.12.14.4 diff -u -r1.12.14.3 -r1.12.14.4 --- squid/src/store.c 28 May 2001 15:06:47 -0000 1.12.14.3 +++ squid/src/store.c 28 May 2001 16:07:17 -0000 1.12.14.4 @@ -1,6 +1,6 @@ /* - * $Id: store.c,v 1.12.14.3 2001/05/28 15:06:47 hno Exp $ + * $Id: store.c,v 1.12.14.4 2001/05/28 16:07:17 hno Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -374,42 +374,44 @@ storeHashInsert(e, newkey); } +/* + * Adds/updates a Vary record. + * For updates only one of key or etag needs to be specified + * At leas one of key or etag must be specified, preferably both. + */ static void storeAddVary(const char *url, const char *log_url, const method_t method, const cache_key *key, const char *etag, const char *vary, const char *vary_headers) { StoreEntry *pe; - if (!storeGetPublic(url, method)) { - /* Create "vary" base object */ - http_version_t version; - pe = storeCreateEntry(url, log_url, null_request_flags, method); - httpBuildVersion(&version, 1, 0); - httpReplySetHeaders(pe->mem_obj->reply, version, HTTP_OK, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000); - httpHeaderPutStr(&pe->mem_obj->reply->header, HDR_VARY, vary); - storeSetPublicKey(pe); - httpReplySwapOut(pe->mem_obj->reply, pe); - storeAppendPrintf(pe, "Key: %s\n", storeKeyText(key)); - if (etag) - storeAppendPrintf(pe, "ETag: %s\n", etag); - storeAppendPrintf(pe, "VaryData: %s\n", vary_headers); - /* XXX Here we need to tack on the old etag/vary information, and we should - * merge, clean up etc - * - * Suggestion: - * swap in the old file, looking for ETag, Key and VaryData. If a match is - * found then - * - on ETag, update the key, and expire the old object if different - * - on Key, drop the old data if ETag is different, else nothing - * - on VaryData, remove the line if a different key. If this makes - * the searched key "empty" then expire it and remove it from the - * map - * - VaryData is added last in the Key record it corresponds to (after - * modifications above) - */ - storeBufferFlush(pe); - storeTimestampsSet(pe); - storeComplete(pe); - storeUnlockObject(pe); - } + http_version_t version; + pe = storeCreateEntry(url, log_url, null_request_flags, method); + httpBuildVersion(&version, 1, 0); + httpReplySetHeaders(pe->mem_obj->reply, version, HTTP_OK, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000); + httpHeaderPutStr(&pe->mem_obj->reply->header, HDR_VARY, vary); + storeSetPublicKey(pe); + httpReplySwapOut(pe->mem_obj->reply, pe); + storeAppendPrintf(pe, "Key: %s\n", storeKeyText(key)); + if (etag) + storeAppendPrintf(pe, "ETag: %s\n", etag); + storeAppendPrintf(pe, "VaryData: %s\n", vary_headers); + /* XXX Here we need to tack on the old etag/vary information, and we should + * merge, clean up etc + * + * Suggestion: + * swap in the old file, looking for ETag, Key and VaryData. If a match is + * found then + * - on ETag, update the key, and expire the old object if different + * - on Key, drop the old data if ETag is different, else nothing + * - on VaryData, remove the line if a different key. If this makes + * the searched key "empty" then expire it and remove it from the + * map + * - VaryData is added last in the Key record it corresponds to (after + * modifications above) + */ + storeBufferFlush(pe); + storeTimestampsSet(pe); + storeComplete(pe); + storeUnlockObject(pe); } void Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.33 retrieving revision 1.33.4.1 diff -u -r1.33 -r1.33.4.1 --- squid/src/structs.h 8 May 2001 15:27:00 -0000 1.33 +++ squid/src/structs.h 28 May 2001 16:07:17 -0000 1.33.4.1 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.33 2001/05/08 15:27:00 squidadm Exp $ + * $Id: structs.h,v 1.33.4.1 2001/05/28 16:07:17 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -837,7 +837,7 @@ /* some fields can hold either time or etag specs (e.g. If-Range) */ struct _TimeOrTag { - ETag tag; /* entity tag */ + const char *tag; /* entity tag */ time_t time; int valid; /* true if struct is usable */ };