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