1 /*******************WARNING*********************
2
3 This is a *MODIFIED* version of Geoff Coller's proof-of-concept NOV
4 implementation.
5
6 It has been modified to support threading directly from a file handle
7 to a NNTP server without a temporary file.
8
9 This is not a complete distribution. We have only distributed enough
10 to support NN's needs.
11
12 The original version came from world.std.com:/src/news/nov.dist.tar.Z
13 and was dated 11 Aug 1993.
14
15 In any case, bugs you find here are probably my fault, as I've trimmed
16 a fair bit of unused code.
17
18 -Peter Wemm <peter@DIALix.oz.au>
19 */
20
21 /*
22 * Copyright (c) Geoffrey Collyer 1992, 1993.
23 * All rights reserved.
24 * Written by Geoffrey Collyer.
25 * Thanks to UUNET Communications Services Inc for financial support.
26 *
27 * This software is not subject to any license of the American Telephone
28 * and Telegraph Company, the Regents of the University of California, or
29 * the Free Software Foundation.
30 *
31 * Permission is granted to anyone to use this software for any purpose on
32 * any computer system, and to alter it and redistribute it freely, subject
33 * to the following restrictions:
34 *
35 * 1. The authors are not responsible for the consequences of use of this
36 * software, no matter how awful, even if they arise from flaws in it.
37 *
38 * 2. The origin of this software must not be misrepresented, either by
39 * explicit claim or by omission. Since few users ever read sources,
40 * credits must appear in the documentation.
41 *
42 * 3. Altered versions must be plainly marked as such, and must not be
43 * misrepresented as being the original software. Since few users
44 * ever read sources, credits must appear in the documentation.
45 *
46 * 4. This notice may not be removed or altered.
47 */
48
49
50 /*
51 * general-purpose in-core hashing, normal interface (wrapper)
52 */
53
54 #include <string.h>
55 #include "config.h"
56 #include "hash.h"
57 #include "hdbm.h"
58
59 #ifdef notdef
60 static unsigned /* not yet taken modulus table size */
hashdef(register HASHDATUM key)61 hashdef(register HASHDATUM key)
62 {
63 register unsigned hash = 0;
64 register char c;
65
66 while ((c = *key++) != '\0')
67 hash += c;
68 return hash;
69 }
70
71 #endif
72
73 HASHTABLE *
hashcreate(unsigned size,unsigned (* hashfunc)())74 hashcreate(unsigned size, unsigned (*hashfunc) ())
75 /* size a crude guide to size */
76 {
77 return hdbmcreate(size, hashfunc);
78 }
79
80 void
hashdestroy(register HASHTABLE * tbl)81 hashdestroy(register HASHTABLE * tbl)
82 {
83 hdbmdestroy(tbl);
84 }
85
86 int
hashstore(HASHTABLE * tbl,register HASHDATUM key,register HASHDATUM data)87 hashstore(HASHTABLE * tbl, register HASHDATUM key, register HASHDATUM data)
88 {
89 register HDBMDATUM hdbmkey, hdbmdata;
90
91 hdbmkey.dat_ptr = key; /* actually a string */
92 hdbmkey.dat_len = strlen(key);
93 hdbmdata.dat_ptr = data; /* just an address */
94 hdbmdata.dat_len = 0; /* no promises */
95 return hdbmstore(tbl, hdbmkey, hdbmdata);
96 }
97
98 #if 0
99 static HASHDATUM(*hashalloc) ();
100
101 static HDBMDATUM
102 hdbmalloc(HDBMDATUM key)
103 { /* hdbm->hash->hdbm allocator translator */
104 register HDBMDATUM hdbmdata;
105
106 hdbmdata.dat_ptr = (*hashalloc) (key.dat_ptr);
107 hdbmdata.dat_len = 0; /* just a string */
108 return hdbmdata;
109 }
110
111 /* return any existing entry for key; otherwise call allocator to make one */
112 static HASHDATUM
113 hashentry(register HASHTABLE * tbl, HASHDATUM key, HASHDATUM(*allocator) ())
114 {
115 register HDBMDATUM hdbmkey, hdbmdata;
116
117 hdbmkey.dat_ptr = key; /* just a string */
118 hdbmkey.dat_len = strlen(key);
119 hashalloc = allocator;
120 hdbmdata = hdbmentry(tbl, hdbmkey, hdbmalloc);
121 return hdbmdata.dat_ptr;
122 }
123
124 #endif
125
126 HASHDATUM /* data corresponding to key */
hashfetch(HASHTABLE * tbl,register HASHDATUM key)127 hashfetch(HASHTABLE * tbl, register HASHDATUM key)
128 {
129 register HDBMDATUM hdbmkey, hdbmdata;
130
131 hdbmkey.dat_ptr = key; /* actually a string */
132 hdbmkey.dat_len = strlen(key);
133 hdbmdata = hdbmfetch(tbl, hdbmkey);
134 return hdbmdata.dat_ptr; /* just an address */
135 }
136
137 int
hashdelete(HASHTABLE * tbl,register HASHDATUM key)138 hashdelete(HASHTABLE * tbl, register HASHDATUM key)
139 {
140 register HDBMDATUM hdbmkey;
141
142 hdbmkey.dat_ptr = key; /* actually a string */
143 hdbmkey.dat_len = strlen(key);
144 return hdbmdelete(tbl, hdbmkey);
145 }
146
147 struct translate {
148 char *realhook;
149 int (*func) ();
150 };
151
152 static int
hdbmtohash(HDBMDATUM key,HDBMDATUM data,char * hook)153 hdbmtohash(HDBMDATUM key, HDBMDATUM data, char *hook)
154 {
155 register struct translate *thp = (struct translate *) hook;
156
157 (*thp->func) (key.dat_ptr, data.dat_ptr, thp->realhook);
158 }
159
160 /*
161 * arrange that at each node, hdbmtohash gets called to map the
162 * HDBMDATUM arguments to HASHDATUM arguments. this also demonstrates
163 * how to use the hook argument.
164 */
165 void
hashwalk(HASHTABLE * tbl,int (* nodefunc)(),char * hook)166 hashwalk(HASHTABLE * tbl, int (*nodefunc) (), char *hook)
167 /* hook (void *) really */
168 {
169 struct translate transhook;
170 register struct translate *tp = &transhook;
171
172 tp->realhook = hook;
173 tp->func = nodefunc;
174 hdbmwalk(tbl, hdbmtohash, (char *) tp);
175 }
176