From 08e5d64f4c4eb55f9f14f484e7651609dd97a45b Mon Sep 17 00:00:00 2001 From: wessels <> Date: Mon, 21 Sep 1998 12:52:13 +0000 Subject: [PATCH] Added storeGetPublic() mostly so that we can check both old and new style cache keys. It doesn't seem to make things less elegant, so maybe its a good idea anyway. --- src/htcp.cc | 5 ++--- src/http.cc | 9 +++------ src/icp_v2.cc | 5 ++--- src/icp_v3.cc | 5 ++--- src/mime.cc | 6 ++---- src/protos.h | 6 ++++-- src/store.cc | 16 +++++++++++++++- src/store_key_md5.cc | 23 +++++++++++++++++++++-- src/urn.cc | 14 +++----------- 9 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/htcp.cc b/src/htcp.cc index bb96c0e44e..2f3fefd9ee 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -1,6 +1,6 @@ /* - * $Id: htcp.cc,v 1.22 1998/09/04 23:04:48 wessels Exp $ + * $Id: htcp.cc,v 1.23 1998/09/21 06:52:13 wessels Exp $ * * DEBUG: section 31 Hypertext Caching Protocol * AUTHOR: Duane Wesssels @@ -674,8 +674,7 @@ htcpHandleTstRequest(htcpDataHeader * dhdr, char *buf, int sz, struct sockaddr_i s->version); m = urlParseMethod(s->method); debug(31, 1) ("htcpHandleTstRequest: %s\n", s->req_hdrs); - key = storeKeyPublic(s->uri, m); - e = storeGet(key); + e = storeGetPublic(s->uri, m); if (NULL == e) { /* cache miss */ htcpTstReply(dhdr, NULL, NULL, from); diff --git a/src/http.cc b/src/http.cc index 89b85a4657..71f6d660db 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.322 1998/09/19 17:06:05 wessels Exp $ + * $Id: http.cc,v 1.323 1998/09/21 06:52:14 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -132,7 +132,6 @@ static void httpMaybeRemovePublic(StoreEntry * e, http_status status) { int remove = 0; - const cache_key *key; StoreEntry *pe; if (!EBIT_TEST(e->flags, KEY_PRIVATE)) return; @@ -160,15 +159,13 @@ httpMaybeRemovePublic(StoreEntry * e, http_status status) if (!remove) return; assert(e->mem_obj); - key = storeKeyPublic(e->mem_obj->url, e->mem_obj->method); - if ((pe = storeGet(key)) != NULL) { + if ((pe = storeGetPublic(e->mem_obj->url, e->mem_obj->method)) != NULL) { assert(e != pe); storeRelease(pe); } if (e->mem_obj->method == METHOD_GET) { /* A fresh GET should eject old HEAD objects */ - key = storeKeyPublic(e->mem_obj->url, METHOD_HEAD); - if ((pe = storeGet(key)) != NULL) { + if ((pe = storeGetPublic(e->mem_obj->url, METHOD_HEAD)) != NULL) { assert(e != pe); storeRelease(pe); } diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 793d7c3475..5b3f1c65fb 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.cc,v 1.52 1998/09/15 19:37:49 wessels Exp $ + * $Id: icp_v2.cc,v 1.53 1998/09/21 06:52:15 wessels Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -243,8 +243,7 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) flags |= ICP_FLAG_SRC_RTT; } /* The peer is allowed to use this cache */ - key = storeKeyPublic(url, METHOD_GET); - entry = storeGet(key); + entry = storeGetPublic(url, METHOD_GET); debug(12, 5) ("icpHandleIcpV2: OPCODE %s\n", icp_opcode_str[header.opcode]); if (icpCheckUdpHit(entry, icp_request)) { reply = icpCreateMessage(ICP_HIT, flags, url, header.reqnum, src_rtt); diff --git a/src/icp_v3.cc b/src/icp_v3.cc index a0de45cb83..0928741483 100644 --- a/src/icp_v3.cc +++ b/src/icp_v3.cc @@ -1,6 +1,6 @@ /* - * $Id: icp_v3.cc,v 1.25 1998/09/11 17:07:44 wessels Exp $ + * $Id: icp_v3.cc,v 1.26 1998/09/21 06:52:16 wessels Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -90,8 +90,7 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len) break; } /* The peer is allowed to use this cache */ - key = storeKeyPublic(url, METHOD_GET); - entry = storeGet(key); + entry = storeGetPublic(url, METHOD_GET); debug(12, 5) ("icpHandleIcpV3: OPCODE %s\n", icp_opcode_str[header.opcode]); if (icpCheckUdpHit(entry, icp_request)) { diff --git a/src/mime.cc b/src/mime.cc index 9d1e50638a..641aa7d676 100644 --- a/src/mime.cc +++ b/src/mime.cc @@ -1,6 +1,6 @@ /* - * $Id: mime.cc,v 1.80 1998/09/19 17:06:06 wessels Exp $ + * $Id: mime.cc,v 1.81 1998/09/21 06:52:17 wessels Exp $ * * DEBUG: section 25 MIME Parsing * AUTHOR: Harvest Derived @@ -376,14 +376,12 @@ mimeLoadIconFile(const char *icon) LOCAL_ARRAY(char, path, MAXPATHLEN); LOCAL_ARRAY(char, url, MAX_URL); char *buf; - const cache_key *key; const char *type = mimeGetContentType(icon); if (type == NULL) fatal("Unknown icon format while reading mime.conf\n"); buf = internalLocalUri("/squid-internal-static/icons/", icon); xstrncpy(url, buf, MAX_URL); - key = storeKeyPublic(url, METHOD_GET); - if (storeGet(key)) + if (storeGetPublic(url, METHOD_GET)) return; snprintf(path, MAXPATHLEN, "%s/%s", Config.icons.directory, icon); fd = file_open(path, O_RDONLY, NULL, NULL, NULL); diff --git a/src/protos.h b/src/protos.h index 568615d11d..eb5996b237 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.269 1998/09/21 06:42:57 wessels Exp $ + * $Id: protos.h,v 1.270 1998/09/21 06:52:19 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -734,6 +734,7 @@ extern void stmemFreeData(mem_hdr *); */ extern StoreEntry *new_StoreEntry(int, const char *, const char *); extern StoreEntry *storeGet(const cache_key *); +extern StoreEntry *storeGetPublic(const char *uri, const method_t method); extern StoreEntry *storeCreateEntry(const char *, const char *, request_flags, method_t); extern void storeSetPublicKey(StoreEntry *); extern void storeComplete(StoreEntry *); @@ -812,7 +813,8 @@ extern cache_key *storeKeyCopy(cache_key *, const cache_key *); extern void storeKeyFree(const cache_key *); extern const cache_key *storeKeyScan(const char *); extern const char *storeKeyText(const cache_key *); -extern const cache_key *storeKeyPublic(const char *, method_t); +extern const cache_key *storeKeyPublic(const char *, const method_t); +extern const cache_key *storeKeyPublicOld(const char *, method_t); extern const cache_key *storeKeyPrivate(const char *, method_t, int); extern int storeKeyHashBuckets(int); extern int storeKeyNull(const cache_key *); diff --git a/src/store.cc b/src/store.cc index 77d1c5b0c5..046a9da6ee 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.462 1998/09/19 17:06:12 wessels Exp $ + * $Id: store.cc,v 1.463 1998/09/21 06:52:22 wessels Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -279,6 +279,20 @@ storeGet(const cache_key * key) return (StoreEntry *) hash_lookup(store_table, key); } +StoreEntry * +storeGetPublic(const char *uri, const method_t method) +{ + cache_key *key; + StoreEntry *e; + key = storeKeyPublic(uri, method); + e = storeGet(key); + if (e == NULL && squid_curtime < 909000000) { + key = storeKeyPublicOld(uri, method); + e = storeGet(key); + } + return storeGet(key); +} + static int getKeyCounter(void) { diff --git a/src/store_key_md5.cc b/src/store_key_md5.cc index f1e55355ca..6e94797c63 100644 --- a/src/store_key_md5.cc +++ b/src/store_key_md5.cc @@ -1,6 +1,6 @@ /* - * $Id: store_key_md5.cc,v 1.16 1998/09/15 19:38:02 wessels Exp $ + * $Id: store_key_md5.cc,v 1.17 1998/09/21 06:52:23 wessels Exp $ * * DEBUG: section 20 Storage Manager MD5 Cache Keys * AUTHOR: Duane Wessels @@ -108,7 +108,7 @@ storeKeyPrivate(const char *url, method_t method, int id) } const cache_key * -storeKeyPublic(const char *url, method_t method) +storeKeyPublic(const char *url, const method_t method) { static cache_key digest[MD5_DIGEST_CHARS]; MD5_CTX M; @@ -119,6 +119,25 @@ storeKeyPublic(const char *url, method_t method) return digest; } +/* + * Compatibility transition period. Remove this after Oct 21, 1998 + */ +const cache_key * +storeKeyPublicOld(const char *url, method_t method) +{ + static cache_key digest[MD5_DIGEST_CHARS]; + MD5_CTX M; + int n; + char key_buf[MAX_URL + 100]; + n = snprintf(key_buf, sizeof(key_buf), "%s %s", + RequestMethodStr[method], + url); + MD5Init(&M); + MD5Update(&M, (unsigned char *) key_buf, n); + MD5Final(digest, &M); + return digest; +} + const cache_key * storeKeyDup(const cache_key * key) { diff --git a/src/urn.cc b/src/urn.cc index d2ee372d76..ee1adbf9df 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -1,7 +1,7 @@ /* * - * $Id: urn.cc,v 1.45 1998/09/14 22:18:04 wessels Exp $ + * $Id: urn.cc,v 1.47 1998/09/21 06:52:23 wessels Exp $ * * DEBUG: section 52 URN Parsing * AUTHOR: Kostas Anagnostakis @@ -36,10 +36,6 @@ #include "squid.h" -enum { - URN_FORCE_MENU -}; - typedef struct { StoreEntry *entry; StoreEntry *urlres_e; @@ -104,7 +100,6 @@ urnStart(request_t * r, StoreEntry * e) { LOCAL_ARRAY(char, urlres, 4096); request_t *urlres_r = NULL; - const cache_key *k; const char *t; char *host; UrnState *urnState; @@ -131,7 +126,6 @@ urnStart(request_t * r, StoreEntry * e) } snprintf(urlres, 4096, "http://%s/uri-res/N2L?urn:%s", host, strBuf(r->urlpath)); safe_free(host); - k = storeKeyPublic(urlres, METHOD_GET); urlres_r = urlParse(METHOD_GET, urlres); if (urlres_r == NULL) { debug(52, 3) ("urnStart: Bad uri-res URL %s\n", urlres); @@ -141,7 +135,7 @@ urnStart(request_t * r, StoreEntry * e) return; } httpHeaderPutStr(&urlres_r->header, HDR_ACCEPT, "text/plain"); - if ((urlres_e = storeGet(k)) == NULL) { + if ((urlres_e = storeGetPublic(urlres, METHOD_GET)) == NULL) { urlres_e = storeCreateEntry(urlres, urlres, null_request_flags, METHOD_GET); storeClientListAdd(urlres_e, urnState); fwdStart(-1, urlres_e, urlres_r, no_addr); @@ -314,7 +308,6 @@ urnParseReply(const char *inbuf, method_t m) char *token; char *url; char *host; - const cache_key *key; int rtt; url_entry *list; url_entry *old; @@ -340,11 +333,10 @@ urnParseReply(const char *inbuf, method_t m) debug(52, 3) ("urnParseReply: Pinging %s\n", host); netdbPingSite(host); } - key = storeKeyPublic(url, m); list[i].url = url; list[i].host = xstrdup(host); list[i].rtt = rtt; - list[i].flags.cached = storeGet(key) ? 1 : 0; + list[i].flags.cached = storeGetPublic(url, m) ? 1 : 0; i++; } debug(0, 0) ("urnParseReply: Found %d URLs\n", i); -- 2.47.3