]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_key_md5.cc
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 20 Storage Manager MD5 Cache Keys */
12 #include "HttpRequest.h"
14 #include "store_key_md5.h"
16 static cache_key null_key
[SQUID_MD5_DIGEST_LENGTH
];
19 storeKeyText(const cache_key
*key
)
22 return "[null_store_key]";
24 static char buf
[SQUID_MD5_DIGEST_LENGTH
* 2+1];
27 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
)
28 snprintf(&buf
[i
*2],sizeof(buf
) - i
*2, "%02X", *(key
+ i
));
34 storeKeyScan(const char *buf
)
36 static unsigned char digest
[SQUID_MD5_DIGEST_LENGTH
];
41 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
) {
42 t
[0] = *(buf
+ (j
++));
43 t
[1] = *(buf
+ (j
++));
45 *(digest
+ i
) = (unsigned char) strtol(t
, NULL
, 16);
52 storeKeyHashCmp(const void *a
, const void *b
)
54 const unsigned char *A
= (const unsigned char *)a
;
55 const unsigned char *B
= (const unsigned char *)b
;
58 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
) {
70 storeKeyHashHash(const void *key
, unsigned int n
)
72 /* note, n must be a power of 2! */
73 const unsigned char *digest
= (const unsigned char *)key
;
74 unsigned int i
= digest
[0]
84 // only the count field is required
85 // others just simplify searching for keys in a multi-process cache.log
90 } key
= { 0, getpid(), KidIdentifier
};
91 assert(sizeof(key
) == SQUID_MD5_DIGEST_LENGTH
);
93 return reinterpret_cast<cache_key
*>(&key
);
97 storeKeyPublic(const char *url
, const HttpRequestMethod
& method
, const KeyScope keyScope
)
99 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
100 unsigned char m
= (unsigned char) method
.id();
103 SquidMD5Update(&M
, &m
, sizeof(m
));
104 SquidMD5Update(&M
, (unsigned char *) url
, strlen(url
));
106 SquidMD5Update(&M
, &keyScope
, sizeof(keyScope
));
107 SquidMD5Final(digest
, &M
);
112 storeKeyPublicByRequest(HttpRequest
* request
, const KeyScope keyScope
)
114 return storeKeyPublicByRequestMethod(request
, request
->method
, keyScope
);
118 storeKeyPublicByRequestMethod(HttpRequest
* request
, const HttpRequestMethod
& method
, const KeyScope keyScope
)
120 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
121 unsigned char m
= (unsigned char) method
.id();
122 const SBuf url
= request
->storeId(); /* returns the right storeID\URL for the MD5 calc */
125 SquidMD5Update(&M
, &m
, sizeof(m
));
126 SquidMD5Update(&M
, (unsigned char *) url
.rawContent(), url
.length());
128 SquidMD5Update(&M
, &keyScope
, sizeof(keyScope
));
130 if (!request
->vary_headers
.isEmpty()) {
131 SquidMD5Update(&M
, request
->vary_headers
.rawContent(), request
->vary_headers
.length());
132 debugs(20, 3, "updating public key by vary headers: " << request
->vary_headers
<< " for: " << url
);
135 SquidMD5Final(digest
, &M
);
141 storeKeyDup(const cache_key
* key
)
143 cache_key
*dup
= (cache_key
*)memAllocate(MEM_MD5_DIGEST
);
144 memcpy(dup
, key
, SQUID_MD5_DIGEST_LENGTH
);
149 storeKeyCopy(cache_key
* dst
, const cache_key
* src
)
151 memcpy(dst
, src
, SQUID_MD5_DIGEST_LENGTH
);
156 storeKeyFree(const cache_key
* key
)
158 memFree((void *) key
, MEM_MD5_DIGEST
);
162 storeKeyHashBuckets(int nbuckets
)
173 storeKeyNull(const cache_key
* key
)
175 if (memcmp(key
, null_key
, SQUID_MD5_DIGEST_LENGTH
) == 0)
184 memset(null_key
, '\0', SQUID_MD5_DIGEST_LENGTH
);