]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/store_key_md5.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / store_key_md5.cc
index 6487980deacc7b6d69e915ea43f9df6fd9701687..4d306e489732eb6625d624e75a4cb4d644fdb611 100644 (file)
@@ -1,50 +1,31 @@
-
 /*
- * $Id: store_key_md5.cc,v 1.35 2007/11/15 09:18:12 amosjeffries Exp $
- *
- * DEBUG: section 20    Storage Manager MD5 Cache Keys
- * AUTHOR: Duane Wessels
- *
- * 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) 1996-2015 The Squid Software Foundation and contributors
  *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 20    Storage Manager MD5 Cache Keys */
+
 #include "squid.h"
 #include "HttpRequest.h"
+#include "md5.h"
+#include "store_key_md5.h"
+#include "URL.h"
 
-static cache_key null_key[MD5_DIGEST_CHARS];
+static cache_key null_key[SQUID_MD5_DIGEST_LENGTH];
 
 const char *
 storeKeyText(const cache_key *key)
 {
-    static char buf[MD5_DIGEST_CHARS * 2+1];
+    if (!key)
+        return "[null_store_key]";
+
+    static char buf[SQUID_MD5_DIGEST_LENGTH * 2+1];
     int i;
 
-    for (i = 0; i < MD5_DIGEST_CHARS; i++)
+    for (i = 0; i < SQUID_MD5_DIGEST_LENGTH; ++i)
         snprintf(&buf[i*2],sizeof(buf) - i*2, "%02X", *(key + i));
 
     return buf;
@@ -53,12 +34,12 @@ storeKeyText(const cache_key *key)
 const cache_key *
 storeKeyScan(const char *buf)
 {
-    static unsigned char digest[MD5_DIGEST_CHARS];
+    static unsigned char digest[SQUID_MD5_DIGEST_LENGTH];
     int i;
     int j = 0;
     char t[3];
 
-    for (i = 0; i < MD5_DIGEST_CHARS; i++) {
+    for (i = 0; i < SQUID_MD5_DIGEST_LENGTH; ++i) {
         t[0] = *(buf + (j++));
         t[1] = *(buf + (j++));
         t[2] = '\0';
@@ -75,7 +56,7 @@ storeKeyHashCmp(const void *a, const void *b)
     const unsigned char *B = (const unsigned char *)b;
     int i;
 
-    for (i = 0; i < MD5_DIGEST_CHARS; i++) {
+    for (i = 0; i < SQUID_MD5_DIGEST_LENGTH; ++i) {
         if (A[i] < B[i])
             return -1;
 
@@ -99,30 +80,30 @@ storeKeyHashHash(const void *key, unsigned int n)
 }
 
 const cache_key *
-storeKeyPrivate(const char *url, method_t method, int id)
+storeKeyPrivate(const char *url, const HttpRequestMethod& method, int id)
 {
-    static cache_key digest[MD5_DIGEST_CHARS];
-    MD5_CTX M;
+    static cache_key digest[SQUID_MD5_DIGEST_LENGTH];
+    SquidMD5_CTX M;
     assert(id > 0);
-    debugs(20, 3, "storeKeyPrivate: " << RequestMethodStr[method] << " " << url);
-    xMD5Init(&M);
-    xMD5Update(&M, (unsigned char *) &id, sizeof(id));
-    xMD5Update(&M, (unsigned char *) &method, sizeof(method));
-    xMD5Update(&M, (unsigned char *) url, strlen(url));
-    xMD5Final(digest, &M);
+    debugs(20, 3, "storeKeyPrivate: " << method << " " << url);
+    SquidMD5Init(&M);
+    SquidMD5Update(&M, (unsigned char *) &id, sizeof(id));
+    SquidMD5Update(&M, (unsigned char *) &method, sizeof(method));
+    SquidMD5Update(&M, (unsigned char *) url, strlen(url));
+    SquidMD5Final(digest, &M);
     return digest;
 }
 
 const cache_key *
-storeKeyPublic(const char *url, const method_t method)
+storeKeyPublic(const char *url, const HttpRequestMethod& method)
 {
-    static cache_key digest[MD5_DIGEST_CHARS];
-    unsigned char m = (unsigned char) method;
-    MD5_CTX M;
-    xMD5Init(&M);
-    xMD5Update(&M, &m, sizeof(m));
-    xMD5Update(&M, (unsigned char *) url, strlen(url));
-    xMD5Final(digest, &M);
+    static cache_key digest[SQUID_MD5_DIGEST_LENGTH];
+    unsigned char m = (unsigned char) method.id();
+    SquidMD5_CTX M;
+    SquidMD5Init(&M);
+    SquidMD5Update(&M, &m, sizeof(m));
+    SquidMD5Update(&M, (unsigned char *) url, strlen(url));
+    SquidMD5Final(digest, &M);
     return digest;
 }
 
@@ -133,20 +114,22 @@ storeKeyPublicByRequest(HttpRequest * request)
 }
 
 const cache_key *
-storeKeyPublicByRequestMethod(HttpRequest * request, const method_t method)
+storeKeyPublicByRequestMethod(HttpRequest * request, const HttpRequestMethod& method)
 {
-    static cache_key digest[MD5_DIGEST_CHARS];
-    unsigned char m = (unsigned char) method;
-    const char *url = urlCanonical(request);
-    MD5_CTX M;
-    xMD5Init(&M);
-    xMD5Update(&M, &m, sizeof(m));
-    xMD5Update(&M, (unsigned char *) url, strlen(url));
-
-    if (request->vary_headers)
-        xMD5Update(&M, (unsigned char *) request->vary_headers, strlen(request->vary_headers));
+    static cache_key digest[SQUID_MD5_DIGEST_LENGTH];
+    unsigned char m = (unsigned char) method.id();
+    const char *url = request->storeId(); /* storeId returns the right storeID\canonical URL for the md5 calc */
+    SquidMD5_CTX M;
+    SquidMD5Init(&M);
+    SquidMD5Update(&M, &m, sizeof(m));
+    SquidMD5Update(&M, (unsigned char *) url, strlen(url));
+
+    if (request->vary_headers) {
+        SquidMD5Update(&M, (unsigned char *) request->vary_headers, strlen(request->vary_headers));
+        debugs(20, 3, "updating public key by vary headers: " << request->vary_headers << " for: " << url);
+    }
 
-    xMD5Final(digest, &M);
+    SquidMD5Final(digest, &M);
 
     return digest;
 }
@@ -155,14 +138,14 @@ cache_key *
 storeKeyDup(const cache_key * key)
 {
     cache_key *dup = (cache_key *)memAllocate(MEM_MD5_DIGEST);
-    xmemcpy(dup, key, MD5_DIGEST_CHARS);
+    memcpy(dup, key, SQUID_MD5_DIGEST_LENGTH);
     return dup;
 }
 
 cache_key *
 storeKeyCopy(cache_key * dst, const cache_key * src)
 {
-    xmemcpy(dst, src, MD5_DIGEST_CHARS);
+    memcpy(dst, src, SQUID_MD5_DIGEST_LENGTH);
     return dst;
 }
 
@@ -186,7 +169,7 @@ storeKeyHashBuckets(int nbuckets)
 int
 storeKeyNull(const cache_key * key)
 {
-    if (memcmp(key, null_key, MD5_DIGEST_CHARS) == 0)
+    if (memcmp(key, null_key, SQUID_MD5_DIGEST_LENGTH) == 0)
         return 1;
     else
         return 0;
@@ -195,5 +178,6 @@ storeKeyNull(const cache_key * key)
 void
 storeKeyInit(void)
 {
-    memset(null_key, '\0', MD5_DIGEST_CHARS);
+    memset(null_key, '\0', SQUID_MD5_DIGEST_LENGTH);
 }
+