]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_key_md5.cc
3 * $Id: store_key_md5.cc,v 1.30 2003/07/11 01:40:37 robertc Exp $
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"
39 static cache_key null_key
[MD5_DIGEST_CHARS
];
42 storeKeyText(const unsigned char *key
)
44 static char buf
[MD5_DIGEST_CHARS
* 2+1];
47 for (i
= 0; i
< MD5_DIGEST_CHARS
; i
++)
48 snprintf(&buf
[i
*2],sizeof(buf
) - i
*2, "%02X", *(key
+ i
));
54 storeKeyScan(const char *buf
)
56 static unsigned char digest
[MD5_DIGEST_CHARS
];
61 for (i
= 0; i
< MD5_DIGEST_CHARS
; i
++) {
62 t
[0] = *(buf
+ (j
++));
63 t
[1] = *(buf
+ (j
++));
65 *(digest
+ i
) = (unsigned char) strtol(t
, NULL
, 16);
72 storeKeyHashCmp(const void *a
, const void *b
)
74 const unsigned char *A
= (const unsigned char *)a
;
75 const unsigned char *B
= (const unsigned char *)b
;
78 for (i
= 0; i
< MD5_DIGEST_CHARS
; i
++) {
90 storeKeyHashHash(const void *key
, unsigned int n
)
92 /* note, n must be a power of 2! */
93 const unsigned char *digest
= (const unsigned char *)key
;
94 unsigned int i
= digest
[0]
102 storeKeyPrivate(const char *url
, method_t method
, int id
)
104 static cache_key digest
[MD5_DIGEST_CHARS
];
107 debug(20, 3) ("storeKeyPrivate: %s %s\n",
108 RequestMethodStr
[method
], url
);
110 MD5Update(&M
, (unsigned char *) &id
, sizeof(id
));
111 MD5Update(&M
, (unsigned char *) &method
, sizeof(method
));
112 MD5Update(&M
, (unsigned char *) url
, strlen(url
));
113 MD5Final(digest
, &M
);
118 storeKeyPublic(const char *url
, const method_t method
)
120 static cache_key digest
[MD5_DIGEST_CHARS
];
121 unsigned char m
= (unsigned char) method
;
124 MD5Update(&M
, &m
, sizeof(m
));
125 MD5Update(&M
, (unsigned char *) url
, strlen(url
));
126 MD5Final(digest
, &M
);
131 storeKeyPublicByRequest(request_t
* request
)
133 return storeKeyPublicByRequestMethod(request
, request
->method
);
137 storeKeyPublicByRequestMethod(request_t
* request
, const method_t method
)
139 static cache_key digest
[MD5_DIGEST_CHARS
];
140 unsigned char m
= (unsigned char) method
;
141 const char *url
= urlCanonical(request
);
144 MD5Update(&M
, &m
, sizeof(m
));
145 MD5Update(&M
, (unsigned char *) url
, strlen(url
));
147 if (request
->vary_headers
)
148 MD5Update(&M
, (unsigned char *) request
->vary_headers
, strlen(request
->vary_headers
));
150 MD5Final(digest
, &M
);
156 storeKeyDup(const cache_key
* key
)
158 cache_key
*dup
= (cache_key
*)memAllocate(MEM_MD5_DIGEST
);
159 xmemcpy(dup
, key
, MD5_DIGEST_CHARS
);
164 storeKeyCopy(cache_key
* dst
, const cache_key
* src
)
166 xmemcpy(dst
, src
, MD5_DIGEST_CHARS
);
171 storeKeyFree(const cache_key
* key
)
173 memFree((void *) key
, MEM_MD5_DIGEST
);
177 storeKeyHashBuckets(int nbuckets
)
188 storeKeyNull(const cache_key
* key
)
190 if (memcmp(key
, null_key
, MD5_DIGEST_CHARS
) == 0)
199 memset(null_key
, '\0', MD5_DIGEST_CHARS
);