]> mj.ucw.cz Git - libucw.git/blob - lib/urlkey.c
3e437b61f4e5465d93512c224e6bb6954ea15ec7
[libucw.git] / lib / urlkey.c
1 /*
2  *      Sherlock Library -- URL Keys & URL Fingerprints
3  *
4  *      (c) 2003 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11 #include "lib/conf.h"
12 #include "lib/index.h"
13 #include "lib/url.h"
14
15 #include <string.h>
16
17 static uns urlkey_www_hack;
18
19 static struct cfitem urlkey_config[] = {
20   { "URLKey",           CT_SECTION,     NULL },
21   { "WWWHack",          CT_INT,         &urlkey_www_hack },
22   { NULL,               CT_STOP,        NULL }
23 };
24
25 static void CONSTRUCTOR urlkey_conf_init(void)
26 {
27   cf_register(urlkey_config);
28 }
29
30 byte *
31 url_key(byte *url, byte *buf)
32 {
33   if (urlkey_www_hack && !strncmp(url, "http://www.", 11))
34     {
35       strcpy(buf, "http://");
36       strcpy(buf+7, url+11);
37       return buf;
38     }
39   else
40     return url;
41 }
42
43 void
44 url_fingerprint(byte *url, struct fingerprint *fp)
45 {
46   byte buf[MAX_URL_SIZE];
47   return fingerprint(url_key(url, buf), fp);
48 }