]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_key_md5.cc
5 * DEBUG: section 20 Storage Manager MD5 Cache Keys
6 * AUTHOR: Duane Wessels
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
37 #include "HttpRequest.h"
40 #include "store_key_md5.h"
43 static cache_key null_key
[SQUID_MD5_DIGEST_LENGTH
];
46 storeKeyText(const cache_key
*key
)
48 static char buf
[SQUID_MD5_DIGEST_LENGTH
* 2+1];
51 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
)
52 snprintf(&buf
[i
*2],sizeof(buf
) - i
*2, "%02X", *(key
+ i
));
58 storeKeyScan(const char *buf
)
60 static unsigned char digest
[SQUID_MD5_DIGEST_LENGTH
];
65 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
) {
66 t
[0] = *(buf
+ (j
++));
67 t
[1] = *(buf
+ (j
++));
69 *(digest
+ i
) = (unsigned char) strtol(t
, NULL
, 16);
76 storeKeyHashCmp(const void *a
, const void *b
)
78 const unsigned char *A
= (const unsigned char *)a
;
79 const unsigned char *B
= (const unsigned char *)b
;
82 for (i
= 0; i
< SQUID_MD5_DIGEST_LENGTH
; ++i
) {
94 storeKeyHashHash(const void *key
, unsigned int n
)
96 /* note, n must be a power of 2! */
97 const unsigned char *digest
= (const unsigned char *)key
;
98 unsigned int i
= digest
[0]
106 storeKeyPrivate(const char *url
, const HttpRequestMethod
& method
, int id
)
108 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
111 debugs(20, 3, "storeKeyPrivate: " << RequestMethodStr(method
) << " " << url
);
113 SquidMD5Update(&M
, (unsigned char *) &id
, sizeof(id
));
114 SquidMD5Update(&M
, (unsigned char *) &method
, sizeof(method
));
115 SquidMD5Update(&M
, (unsigned char *) url
, strlen(url
));
116 SquidMD5Final(digest
, &M
);
121 storeKeyPublic(const char *url
, const HttpRequestMethod
& method
)
123 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
124 unsigned char m
= (unsigned char) method
.id();
127 SquidMD5Update(&M
, &m
, sizeof(m
));
128 SquidMD5Update(&M
, (unsigned char *) url
, strlen(url
));
129 SquidMD5Final(digest
, &M
);
134 storeKeyPublicByRequest(HttpRequest
* request
)
136 return storeKeyPublicByRequestMethod(request
, request
->method
);
140 storeKeyPublicByRequestMethod(HttpRequest
* request
, const HttpRequestMethod
& method
)
142 static cache_key digest
[SQUID_MD5_DIGEST_LENGTH
];
143 unsigned char m
= (unsigned char) method
.id();
144 const char *url
= urlCanonical(request
);
147 SquidMD5Update(&M
, &m
, sizeof(m
));
148 SquidMD5Update(&M
, (unsigned char *) url
, strlen(url
));
150 if (request
->vary_headers
)
151 SquidMD5Update(&M
, (unsigned char *) request
->vary_headers
, strlen(request
->vary_headers
));
153 SquidMD5Final(digest
, &M
);
159 storeKeyDup(const cache_key
* key
)
161 cache_key
*dup
= (cache_key
*)memAllocate(MEM_MD5_DIGEST
);
162 memcpy(dup
, key
, SQUID_MD5_DIGEST_LENGTH
);
167 storeKeyCopy(cache_key
* dst
, const cache_key
* src
)
169 memcpy(dst
, src
, SQUID_MD5_DIGEST_LENGTH
);
174 storeKeyFree(const cache_key
* key
)
176 memFree((void *) key
, MEM_MD5_DIGEST
);
180 storeKeyHashBuckets(int nbuckets
)
191 storeKeyNull(const cache_key
* key
)
193 if (memcmp(key
, null_key
, SQUID_MD5_DIGEST_LENGTH
) == 0)
202 memset(null_key
, '\0', SQUID_MD5_DIGEST_LENGTH
);