]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_key_md5.cc
2 * Copyright (C) 1996-2015 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 static cache_key null_key
[SQUID_MD5_DIGEST_LENGTH
];
20 storeKeyText(const cache_key
*key
)
23 return "[null_store_key]";
25 static char buf
[SQUID_MD5_DIGEST_LENGTH
* 2+1];
28 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
)
29 snprintf(&buf
[i
*2],sizeof(buf
) - i
*2, "%02X", *(key
+ i
));
35 storeKeyScan(const char *buf
)
37 static unsigned char digest
[SQUID_MD5_DIGEST_LENGTH
];
42 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
) {
43 t
[0] = *(buf
+ (j
++));
44 t
[1] = *(buf
+ (j
++));
46 *(digest
+ i
) = (unsigned char) strtol(t
, NULL
, 16);
53 storeKeyHashCmp(const void *a
, const void *b
)
55 const unsigned char *A
= (const unsigned char *)a
;
56 const unsigned char *B
= (const unsigned char *)b
;
59 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
) {
71 storeKeyHashHash(const void *key
, unsigned int n
)
73 /* note, n must be a power of 2! */
74 const unsigned char *digest
= (const unsigned char *)key
;
75 unsigned int i
= digest
[0]
83 storeKeyPrivate(const char *url
, const HttpRequestMethod
& method
, int id
)
85 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
88 debugs(20, 3, "storeKeyPrivate: " << method
<< " " << url
);
90 SquidMD5Update(&M
, (unsigned char *) &id
, sizeof(id
));
91 SquidMD5Update(&M
, (unsigned char *) &method
, sizeof(method
));
92 SquidMD5Update(&M
, (unsigned char *) url
, strlen(url
));
93 SquidMD5Final(digest
, &M
);
98 storeKeyPublic(const char *url
, const HttpRequestMethod
& method
)
100 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
101 unsigned char m
= (unsigned char) method
.id();
104 SquidMD5Update(&M
, &m
, sizeof(m
));
105 SquidMD5Update(&M
, (unsigned char *) url
, strlen(url
));
106 SquidMD5Final(digest
, &M
);
111 storeKeyPublicByRequest(HttpRequest
* request
)
113 return storeKeyPublicByRequestMethod(request
, request
->method
);
117 storeKeyPublicByRequestMethod(HttpRequest
* request
, const HttpRequestMethod
& method
)
119 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
120 unsigned char m
= (unsigned char) method
.id();
121 const char *url
= request
->storeId(); /* storeId returns the right storeID\canonical URL for the md5 calc */
124 SquidMD5Update(&M
, &m
, sizeof(m
));
125 SquidMD5Update(&M
, (unsigned char *) url
, strlen(url
));
127 if (request
->vary_headers
) {
128 SquidMD5Update(&M
, (unsigned char *) request
->vary_headers
, strlen(request
->vary_headers
));
129 debugs(20, 3, "updating public key by vary headers: " << request
->vary_headers
<< " for: " << url
);
132 SquidMD5Final(digest
, &M
);
138 storeKeyDup(const cache_key
* key
)
140 cache_key
*dup
= (cache_key
*)memAllocate(MEM_MD5_DIGEST
);
141 memcpy(dup
, key
, SQUID_MD5_DIGEST_LENGTH
);
146 storeKeyCopy(cache_key
* dst
, const cache_key
* src
)
148 memcpy(dst
, src
, SQUID_MD5_DIGEST_LENGTH
);
153 storeKeyFree(const cache_key
* key
)
155 memFree((void *) key
, MEM_MD5_DIGEST
);
159 storeKeyHashBuckets(int nbuckets
)
170 storeKeyNull(const cache_key
* key
)
172 if (memcmp(key
, null_key
, SQUID_MD5_DIGEST_LENGTH
) == 0)
181 memset(null_key
, '\0', SQUID_MD5_DIGEST_LENGTH
);