]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_key_md5.cc
2 * Copyright (C) 1996-2023 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"
17 storeKeyText(const cache_key
*key
)
20 return "[null_store_key]";
22 static char buf
[SQUID_MD5_DIGEST_LENGTH
* 2+1];
25 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
)
26 snprintf(&buf
[i
*2],sizeof(buf
) - i
*2, "%02X", *(key
+ i
));
32 storeKeyScan(const char *buf
)
34 static unsigned char digest
[SQUID_MD5_DIGEST_LENGTH
];
39 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
) {
40 t
[0] = *(buf
+ (j
++));
41 t
[1] = *(buf
+ (j
++));
43 *(digest
+ i
) = (unsigned char) strtol(t
, nullptr, 16);
50 storeKeyHashCmp(const void *a
, const void *b
)
52 const unsigned char *A
= (const unsigned char *)a
;
53 const unsigned char *B
= (const unsigned char *)b
;
56 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
) {
68 storeKeyHashHash(const void *key
, unsigned int n
)
70 /* note, n must be a power of 2! */
71 const unsigned char *digest
= (const unsigned char *)key
;
72 unsigned int i
= digest
[0]
82 // only the count field is required
83 // others just simplify searching for keys in a multi-process cache.log
88 } key
= { 0, getpid(), KidIdentifier
};
89 assert(sizeof(key
) == SQUID_MD5_DIGEST_LENGTH
);
91 return reinterpret_cast<cache_key
*>(&key
);
95 storeKeyPublic(const char *url
, const HttpRequestMethod
& method
, const KeyScope keyScope
)
97 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
98 unsigned char m
= (unsigned char) method
.id();
101 SquidMD5Update(&M
, &m
, sizeof(m
));
102 SquidMD5Update(&M
, (unsigned char *) url
, strlen(url
));
104 SquidMD5Update(&M
, &keyScope
, sizeof(keyScope
));
105 SquidMD5Final(digest
, &M
);
110 storeKeyPublicByRequest(HttpRequest
* request
, const KeyScope keyScope
)
112 return storeKeyPublicByRequestMethod(request
, request
->method
, keyScope
);
116 storeKeyPublicByRequestMethod(HttpRequest
* request
, const HttpRequestMethod
& method
, const KeyScope keyScope
)
118 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
119 unsigned char m
= (unsigned char) method
.id();
120 const SBuf url
= request
->storeId(); /* returns the right storeID\URL for the MD5 calc */
123 SquidMD5Update(&M
, &m
, sizeof(m
));
124 SquidMD5Update(&M
, (unsigned char *) url
.rawContent(), url
.length());
126 SquidMD5Update(&M
, &keyScope
, sizeof(keyScope
));
128 if (!request
->vary_headers
.isEmpty()) {
129 SquidMD5Update(&M
, request
->vary_headers
.rawContent(), request
->vary_headers
.length());
130 debugs(20, 3, "updating public key by vary headers: " << request
->vary_headers
<< " for: " << url
);
133 SquidMD5Final(digest
, &M
);
139 storeKeyDup(const cache_key
* key
)
141 cache_key
*dup
= (cache_key
*)memAllocate(MEM_MD5_DIGEST
);
142 memcpy(dup
, key
, SQUID_MD5_DIGEST_LENGTH
);
147 storeKeyCopy(cache_key
* dst
, const cache_key
* src
)
149 memcpy(dst
, src
, SQUID_MD5_DIGEST_LENGTH
);
154 storeKeyFree(const cache_key
* key
)
156 memFree((void *) key
, MEM_MD5_DIGEST
);
160 storeKeyHashBuckets(int nbuckets
)