/*
- * $Id: hash.h,v 1.3 1998/09/23 20:13:46 wessels Exp $
+ * $Id: hash.h,v 1.4 2000/10/31 23:48:08 wessels Exp $
*/
typedef void HASHFREE(void *);
typedef struct _hash_table hash_table;
struct _hash_link {
- char *key;
+ void *key;
hash_link *next;
};
extern void hashFreeItems(hash_table *, HASHFREE *);
extern HASHHASH hash_string;
extern HASHHASH hash4;
+extern const char *hashKeyStr(hash_link *);
/*
* Here are some good prime number choices. It's important not to
* HASH_SIZE 33493 // prime number < 32768
* HASH_SIZE 65357 // prime number < 65536
*/
-#define DEFAULT_HASH_SIZE 7951 /* prime number < 8192 */
+#define DEFAULT_HASH_SIZE 7951 /* prime number < 8192 */
/*
- * $Id: hash.c,v 1.9 2000/03/27 21:56:21 wessels Exp $
+ * $Id: hash.c,v 1.10 2000/10/31 23:48:12 wessels Exp $
*
* DEBUG: section 0 Hash Tables
* AUTHOR: Harvest Derived
return best_prime;
}
+/*
+ * return the key of a hash_link as a const string
+ */
+const char *
+hashKeyStr(hash_link * hl)
+{
+ return (const char *) hl->key;
+}
+
#ifdef USE_HASH_DRIVER
/*
/*
- * $Id: HttpHdrRange.cc,v 1.22 2000/10/04 15:32:13 wessels Exp $
+ * $Id: HttpHdrRange.cc,v 1.23 2000/10/31 23:48:12 wessels Exp $
*
* DEBUG: section 64 HTTP Range Header
* AUTHOR: Alex Rousskov
assert(http);
stringAppend(&b, full_appname_string, strlen(full_appname_string));
stringAppend(&b, ":", 1);
- key = storeKeyText(http->entry->key);
+ key = storeKeyText(http->entry->hash.key);
stringAppend(&b, key, strlen(key));
return b;
}
/*
- * $Id: access_log.cc,v 1.59 2000/10/10 18:15:30 wessels Exp $
+ * $Id: access_log.cc,v 1.60 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 46 Access Log
* AUTHOR: Duane Wessels
fv = hash_lookup(hash, key);
if (NULL == fv) {
fv = xcalloc(1, sizeof(fvdb_entry));
- fv->key = xstrdup(key);
- hash_join(hash, (hash_link *) fv);
+ fv->hash.key = xstrdup(key);
+ hash_join(hash, &fv->hash);
}
fv->n++;
}
hash_first(hash);
while ((h = hash_next(hash))) {
fv = (fvdb_entry *) h;
- storeAppendPrintf(e, "%9d %s\n", fv->n, fv->key);
+ storeAppendPrintf(e, "%9d %s\n", fv->n, hashKeyStr(&fv->hash));
}
}
fvdbFreeEntry(void *data)
{
fvdb_entry *fv = data;
- xfree(fv->key);
+ xfree(fv->hash.key);
xfree(fv);
}
/*
- * $Id: acl.cc,v 1.224 2000/10/04 00:24:16 wessels Exp $
+ * $Id: acl.cc,v 1.225 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 28 Access Control
* AUTHOR: Duane Wessels
auth_user->expiretime = current_time.tv_sec + Config.authenticateTTL;
auth_user->ip_expiretime = squid_curtime + Config.authenticateIpTTL;
auth_user->ipaddr = checklist->src_addr;
- hash_join(proxy_auth_cache, (hash_link *) auth_user);
+ hash_join(proxy_auth_cache, &auth_user->hash);
/* Continue checking below, as normal */
}
}
debug(28, 4) ("aclLookupProxyAuthStart: going to ask authenticator on %s\n", user);
/* we must still check this user's password */
auth_user = memAllocate(MEM_ACL_PROXY_AUTH_USER);
- auth_user->user = xstrdup(user);
+ auth_user->hash.key = xstrdup(user);
auth_user->passwd = xstrdup(password);
auth_user->passwd_ok = -1;
auth_user->expiretime = -1;
aclFreeProxyAuthUser(void *data)
{
acl_proxy_auth_user *u = data;
- xfree(u->user);
+ xfree(u->hash.key);
xfree(u->passwd);
memFree(u, MEM_ACL_PROXY_AUTH_USER);
}
/*
- * $Id: authenticate.cc,v 1.12 2000/03/06 16:23:28 wessels Exp $
+ * $Id: authenticate.cc,v 1.13 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 29 Authenticator
* AUTHOR: Duane Wessels
char buf[8192];
assert(auth_user);
assert(handler);
- debug(29, 5) ("authenticateStart: '%s:%s'\n", auth_user->user,
+ debug(29, 5) ("authenticateStart: '%s:%s'\n", hashKeyStr(&auth_user->hash),
auth_user->passwd);
if (Config.Program.authenticate == NULL) {
handler(data, NULL);
cbdataLock(data);
r->data = data;
r->auth_user = auth_user;
- snprintf(buf, 8192, "%s %s\n", r->auth_user->user, r->auth_user->passwd);
+ snprintf(buf, 8192, "%s %s\n", hashKeyStr(&r->auth_user->hash),
+ r->auth_user->passwd);
helperSubmit(authenticators, buf, authenticateHandleReply, r);
}
/*
- * $Id: cache_diff.cc,v 1.12 2000/06/06 19:34:31 hno Exp $
+ * $Id: cache_diff.cc,v 1.13 2000/10/31 23:48:13 wessels Exp $
*
* AUTHOR: Alex Rousskov
*
idx->bad_add_count++;
} else {
CacheEntry *e = cacheEntryCreate(&s);
- hash_join(idx->hash, (hash_link *) e);
+ hash_join(idx->hash, &e->hash);
idx->count++;
}
} else if (s.op == SWAP_LOG_DEL) {
/*
- * $Id: cbdata.cc,v 1.30 2000/10/17 08:06:02 adrian Exp $
+ * $Id: cbdata.cc,v 1.31 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 45 Callback Data Registry
* AUTHOR: Duane Wessels
static int cbdataCount = 0;
typedef struct _cbdata {
- const void *key;
- struct _cbdata *next;
+ hash_link hash; /* must be first */
int valid;
int locks;
CBDUNL *unlock_func;
assert(htable != NULL);
assert(hash_lookup(htable, p) == NULL);
c = memPoolAlloc(cbdata_pool);
- c->key = p;
+ c->hash.key = (void *) p;
c->valid = 1;
c->unlock_func = unlock_func;
c->id = id;
c->file = file;
c->line = line;
#endif
- hash_join(htable, (hash_link *) c);
+ hash_join(htable, &c->hash);
cbdataCount++;
}
cbdataReallyFree(cbdata * c)
{
CBDUNL *unlock_func = c->unlock_func;
- void *p = (void *) c->key;
+ void *p = c->hash.key;
int id = c->id;
hash_remove_link(htable, (hash_link *) c);
cbdataCount--;
- memPoolFree(cbdata_pool,c);
+ memPoolFree(cbdata_pool, c);
debug(45, 3) ("cbdataReallyFree: Freeing %p\n", p);
if (unlock_func)
unlock_func(p, id);
c = (cbdata *) hptr;
#if CBDATA_DEBUG
storeAppendPrintf(sentry, "%20p %10s %d locks %s:%d\n",
- c->key,
+ c->hash.key,
c->valid ? "VALID" : "NOT VALID",
c->locks,
c->file, c->line);
#else
storeAppendPrintf(sentry, "%20p %10s %d locks\n",
- c->key,
+ c->hash.key,
c->valid ? "VALID" : "NOT VALID",
c->locks);
#endif
/*
- * $Id: client_db.cc,v 1.50 2000/06/27 22:05:58 hno Exp $
+ * $Id: client_db.cc,v 1.51 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 0 Client Database
* AUTHOR: Duane Wessels
{
ClientInfo *c;
c = memAllocate(MEM_CLIENT_INFO);
- c->key = xstrdup(inet_ntoa(addr));
+ c->hash.key = xstrdup(inet_ntoa(addr));
c->addr = addr;
- hash_join(client_table, (hash_link *) c);
+ hash_join(client_table, &c->hash);
statCounter.client_http.clients++;
return c;
}
storeAppendPrintf(sentry, "Cache Clients:\n");
hash_first(client_table);
while ((c = (ClientInfo *) hash_next(client_table))) {
- storeAppendPrintf(sentry, "Address: %s\n", c->key);
+ storeAppendPrintf(sentry, "Address: %s\n", hashKeyStr(&c->hash));
storeAppendPrintf(sentry, "Name: %s\n", fqdnFromAddr(c->addr));
storeAppendPrintf(sentry, "Currently established connections: %d\n",
c->n_established);
clientdbFreeItem(void *data)
{
ClientInfo *c = data;
- safe_free(c->key);
+ safe_free(c->hash.key);
memFree(c, MEM_CLIENT_INFO);
}
key = inet_ntoa(*current);
hash_first(client_table);
while ((c = (ClientInfo *) hash_next(client_table))) {
- if (!strcmp(key, c->key))
+ if (!strcmp(key, hashKeyStr(&c->hash)))
break;
}
c = (ClientInfo *) hash_next(client_table);
/*
- * $Id: fqdncache.cc,v 1.141 2000/10/17 08:06:03 adrian Exp $
+ * $Id: fqdncache.cc,v 1.142 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 35 FQDN Cache
* AUTHOR: Harvest Derived
typedef struct _fqdncache_entry fqdncache_entry;
struct _fqdncache_entry {
- /* first two items must be equivalent to hash_link */
- char *name;
- fqdncache_entry *next;
+ hash_link hash; /* must be first */
time_t lastref;
time_t expires;
unsigned char name_count;
for (k = 0; k < (int) f->name_count; k++)
safe_free(f->names[k]);
debug(35, 5) ("fqdncacheRelease: Released FQDN record for '%s'.\n",
- f->name);
+ hashKeyStr(&f->hash));
dlinkDelete(&f->lru, &lru_list);
- safe_free(f->name);
+ safe_free(f->hash.key);
safe_free(f->error_message);
memFree(f, MEM_FQDNCACHE_ENTRY);
}
{
static fqdncache_entry *f;
f = memAllocate(MEM_FQDNCACHE_ENTRY);
- f->name = xstrdup(name);
+ f->hash.key = xstrdup(name);
f->expires = squid_curtime + Config.negativeDnsTtl;
return f;
}
static void
fqdncacheAddEntry(fqdncache_entry * f)
{
- hash_link *e = hash_lookup(fqdn_table, f->name);
+ hash_link *e = hash_lookup(fqdn_table, f->hash.key);
if (NULL != e) {
/* avoid colission */
fqdncache_entry *q = (fqdncache_entry *) e;
fqdncacheRelease(q);
}
- hash_join(fqdn_table, (hash_link *) f);
+ hash_join(fqdn_table, &f->hash);
dlinkAdd(f, &f->lru, &lru_list);
f->lastref = squid_curtime;
}
c->data = f;
cbdataAdd(c, memFree, MEM_GEN_CBDATA);
#if USE_DNSSERVERS
- dnsSubmit(f->name, fqdncacheHandleReply, c);
+ dnsSubmit(hashKeyStr(&f->hash), fqdncacheHandleReply, c);
#else
idnsPTRLookup(addr, fqdncacheHandleReply, c);
#endif
while ((f = (fqdncache_entry *) hash_next(fqdn_table))) {
ttl = (f->expires - squid_curtime);
storeAppendPrintf(sentry, " %-32.32s %c %6d %d",
- f->name,
+ hashKeyStr(&f->hash),
f->flags.negcached ? 'N' : ' ',
ttl,
(int) f->name_count);
int k;
for (k = 0; k < (int) f->name_count; k++)
safe_free(f->names[k]);
- safe_free(f->name);
+ safe_free(f->hash.key);
safe_free(f->error_message);
memFree(f, MEM_FQDNCACHE_ENTRY);
}
/*
- * $Id: store_dir_aufs.cc,v 1.10 2000/10/17 08:06:07 adrian Exp $
+ * $Id: store_dir_aufs.cc,v 1.11 2000/10/31 23:48:17 wessels Exp $
*
* DEBUG: section 47 Store Directory Routines
* AUTHOR: Duane Wessels
storeAufsDirUnlinkFile(SD, sfileno);
continue;
}
- tmpe.key = key;
+ tmpe.hash.key = key;
/* check sizes */
if (tmpe.swap_file_sz == 0) {
tmpe.swap_file_sz = sb.st_size;
s.swap_file_sz = e->swap_file_sz;
s.refcount = e->refcount;
s.flags = e->flags;
- xmemcpy(&s.key, e->key, MD5_DIGEST_CHARS);
+ xmemcpy(&s.key, e->hash.key, MD5_DIGEST_CHARS);
xmemcpy(state->outbuf + state->outbuf_offset, &s, ss);
state->outbuf_offset += ss;
/* buffered write */
s->swap_file_sz = e->swap_file_sz;
s->refcount = e->refcount;
s->flags = e->flags;
- xmemcpy(s->key, e->key, MD5_DIGEST_CHARS);
+ xmemcpy(s->key, e->hash.key, MD5_DIGEST_CHARS);
file_write(aioinfo->swaplog_fd,
-1,
s,
/*
- * $Id: store_dir_coss.cc,v 1.5 2000/10/18 04:00:23 hno Exp $
+ * $Id: store_dir_coss.cc,v 1.6 2000/10/31 23:48:17 wessels Exp $
*
* DEBUG: section 81 Store COSS Directory Routines
* AUTHOR: Eric Stern
s.swap_file_sz = e->swap_file_sz;
s.refcount = e->refcount;
s.flags = e->flags;
- xmemcpy(&s.key, e->key, MD5_DIGEST_CHARS);
+ xmemcpy(&s.key, e->hash.key, MD5_DIGEST_CHARS);
xmemcpy(state->outbuf + state->outbuf_offset, &s, ss);
state->outbuf_offset += ss;
/* buffered write */
s->swap_file_sz = e->swap_file_sz;
s->refcount = e->refcount;
s->flags = e->flags;
- xmemcpy(s->key, e->key, MD5_DIGEST_CHARS);
+ xmemcpy(s->key, e->hash.key, MD5_DIGEST_CHARS);
file_write(cs->swaplog_fd,
-1,
s,
/*
- * $Id: store_dir_diskd.cc,v 1.21 2000/10/17 08:06:08 adrian Exp $
+ * $Id: store_dir_diskd.cc,v 1.22 2000/10/31 23:48:18 wessels Exp $
*
* DEBUG: section 47 Store Directory Routines
* AUTHOR: Duane Wessels
storeDiskdDirUnlinkFile(SD, sfileno);
continue;
}
- tmpe.key = key;
+ tmpe.hash.key = key;
/* check sizes */
if (tmpe.swap_file_sz == 0) {
tmpe.swap_file_sz = sb.st_size;
s.swap_file_sz = e->swap_file_sz;
s.refcount = e->refcount;
s.flags = e->flags;
- xmemcpy(&s.key, e->key, MD5_DIGEST_CHARS);
+ xmemcpy(&s.key, e->hash.key, MD5_DIGEST_CHARS);
xmemcpy(state->outbuf + state->outbuf_offset, &s, ss);
state->outbuf_offset += ss;
/* buffered write */
s->swap_file_sz = e->swap_file_sz;
s->refcount = e->refcount;
s->flags = e->flags;
- xmemcpy(s->key, e->key, MD5_DIGEST_CHARS);
+ xmemcpy(s->key, e->hash.key, MD5_DIGEST_CHARS);
file_write(diskdinfo->swaplog_fd,
-1,
s,
/*
- * $Id: store_dir_ufs.cc,v 1.10 2000/10/17 08:06:09 adrian Exp $
+ * $Id: store_dir_ufs.cc,v 1.11 2000/10/31 23:48:18 wessels Exp $
*
* DEBUG: section 47 Store Directory Routines
* AUTHOR: Duane Wessels
storeUfsDirUnlinkFile(SD, sfileno);
continue;
}
- tmpe.key = key;
+ tmpe.hash.key = key;
/* check sizes */
if (tmpe.swap_file_sz == 0) {
tmpe.swap_file_sz = sb.st_size;
unlink(state->cln);
state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC);
if (state->fd < 0)
- return -1; /* state not free'd - possible leak */
+ return -1; /* state not free'd - possible leak */
debug(20, 3) ("storeDirWriteCleanLogs: opened %s, FD %d\n",
state->new, state->fd);
#if HAVE_FCHMOD
s.swap_file_sz = e->swap_file_sz;
s.refcount = e->refcount;
s.flags = e->flags;
- xmemcpy(&s.key, e->key, MD5_DIGEST_CHARS);
+ xmemcpy(&s.key, e->hash.key, MD5_DIGEST_CHARS);
xmemcpy(state->outbuf + state->outbuf_offset, &s, ss);
state->outbuf_offset += ss;
/* buffered write */
s->swap_file_sz = e->swap_file_sz;
s->refcount = e->refcount;
s->flags = e->flags;
- xmemcpy(s->key, e->key, MD5_DIGEST_CHARS);
+ xmemcpy(s->key, e->hash.key, MD5_DIGEST_CHARS);
file_write(ufsinfo->swaplog_fd,
-1,
s,
/*
- * $Id: http.cc,v 1.367 2000/10/04 15:32:13 wessels Exp $
+ * $Id: http.cc,v 1.368 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
HttpReply *reply = entry->mem_obj->reply;
Ctx ctx;
debug(11, 3) ("httpProcessReplyHeader: key '%s'\n",
- storeKeyText(entry->key));
+ storeKeyText(entry->hash.key));
if (httpState->reply_hdr == NULL)
httpState->reply_hdr = memAllocate(MEM_8K_BUF);
assert(httpState->reply_hdr_state == 0);
/*
- * $Id: ident.cc,v 1.53 2000/06/27 22:06:02 hno Exp $
+ * $Id: ident.cc,v 1.54 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 30 Ident (RFC 931)
* AUTHOR: Duane Wessels
} IdentClient;
typedef struct _IdentStateData {
- char *key;
- struct _IdentStateData *next;
+ hash_link hash; /* must be first */
int fd; /* IDENT fd */
struct sockaddr_in me;
struct sockaddr_in my_peer;
}
state = xcalloc(1, sizeof(IdentStateData));
cbdataAdd(state, cbdataXfree, 0);
- state->key = xstrdup(key);
+ state->hash.key = xstrdup(key);
state->fd = fd;
state->me = *me;
state->my_peer = *my_peer;
identClientAdd(state, callback, data);
- hash_join(ident_hash, (hash_link *) state);
+ hash_join(ident_hash, &state->hash);
comm_add_close_handler(fd,
identClose,
state);
/*
- * $Id: ipcache.cc,v 1.226 2000/10/17 08:06:03 adrian Exp $
+ * $Id: ipcache.cc,v 1.227 2000/10/31 23:48:13 wessels Exp $
*
* DEBUG: section 14 IP Cache
* AUTHOR: Harvest Derived
typedef struct _ipcache_entry ipcache_entry;
struct _ipcache_entry {
- /* first two items must be equivalent to hash_link */
- char *name;
- ipcache_entry *next;
+ hash_link hash; /* must be first */
time_t lastref;
time_t expires;
ipcache_addrs addrs;
{
static ipcache_entry *i;
i = memAllocate(MEM_IPCACHE_ENTRY);
- i->name = xstrdup(name);
+ i->hash.key = xstrdup(name);
i->expires = squid_curtime + Config.negativeDnsTtl;
return i;
}
static void
ipcacheAddEntry(ipcache_entry * i)
{
- hash_link *e = hash_lookup(ip_table, i->name);
+ hash_link *e = hash_lookup(ip_table, i->hash.key);
if (NULL != e) {
/* avoid colission */
ipcache_entry *q = (ipcache_entry *) e;
ipcacheRelease(q);
}
- hash_join(ip_table, (hash_link *) i);
+ hash_join(ip_table, &i->hash);
dlinkAdd(i, &i->lru, &lru_list);
i->lastref = squid_curtime;
}
c->data = i;
cbdataAdd(c, memFree, MEM_GEN_CBDATA);
#if USE_DNSSERVERS
- dnsSubmit(i->name, ipcacheHandleReply, c);
+ dnsSubmit(hashKeyStr(&i->hash), ipcacheHandleReply, c);
#else
- idnsALookup(i->name, ipcacheHandleReply, c);
+ idnsALookup(hashKeyStr(&i->hash), ipcacheHandleReply, c);
#endif
}
{
int k;
storeAppendPrintf(sentry, " %-32.32s %c %6d %6d %2d(%2d)",
- i->name,
+ hashKeyStr(&i->hash),
i->flags.negcached ? 'N' : ' ',
(int) (squid_curtime - i->lastref),
(int) (i->expires - squid_curtime),
ipcache_entry *i = data;
safe_free(i->addrs.in_addrs);
safe_free(i->addrs.bad_mask);
- safe_free(i->name);
+ safe_free(i->hash.key);
safe_free(i->error_message);
memFree(i, MEM_IPCACHE_ENTRY);
}
/*
- * $Id: leakfinder.cc,v 1.3 2000/03/06 16:23:32 wessels Exp $
+ * $Id: leakfinder.cc,v 1.4 2000/10/31 23:48:14 wessels Exp $
*
* DEBUG: section 45 Callback Data Registry
* AUTHOR: Duane Wessels
static int leakCount = 0;
typedef struct _ptr {
+ hash_link hash; /* must be first */
void *key;
struct _ptr *next;
const char *file;
c->file = file;
c->line = line;
c->when = squid_curtime;
- hash_join(htable, (hash_link *) c);
+ hash_join(htable, &c->hash);
leakCount++;
return p;
}
/*
- * $Id: neighbors.cc,v 1.286 2000/10/10 02:10:42 wessels Exp $
+ * $Id: neighbors.cc,v 1.287 2000/10/31 23:48:14 wessels Exp $
*
* DEBUG: section 15 Neighbor Routines
* AUTHOR: Harvest Derived
mem->start_ping = current_time;
mem->ping_reply_callback = callback;
mem->ircb_data = callback_data;
- reqnum = icpSetCacheKey(entry->key);
+ reqnum = icpSetCacheKey(entry->hash.key);
for (i = 0, p = first_ping; i++ < Config.npeers; p = p->next) {
if (p == NULL)
p = Config.peers;
p->host, url);
if (p->type == PEER_MULTICAST)
mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
- debug(15, 3) ("neighborsUdpPing: key = '%s'\n", storeKeyText(entry->key));
+ debug(15, 3) ("neighborsUdpPing: key = '%s'\n", storeKeyText(entry->hash.key));
debug(15, 3) ("neighborsUdpPing: reqnum = %d\n", reqnum);
#if USE_HTCP
return 0;
/*
* The peer can not be UP if we don't have any IP addresses
- * for it.
+ * for it.
*/
if (0 == p->n_addresses)
return 0;
mem->ircb_data = psstate;
mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
p->mcast.id = mem->id;
- reqnum = icpSetCacheKey(fake->key);
+ reqnum = icpSetCacheKey(fake->hash.key);
query = icpCreateMessage(ICP_QUERY, 0, url, reqnum, 0);
icpUdpSend(theOutIcpConnection,
&p->in_addr,
/*
- * $Id: net_db.cc,v 1.150 2000/10/26 07:09:23 wessels Exp $
+ * $Id: net_db.cc,v 1.151 2000/10/31 23:48:14 wessels Exp $
*
* DEBUG: section 38 Network Measurement Database
* AUTHOR: Duane Wessels
netdbHashInsert(netdbEntry * n, struct in_addr addr)
{
xstrncpy(n->network, inet_ntoa(networkFromInaddr(addr)), 16);
- n->key = n->network;
+ n->hash.key = n->network;
assert(hash_lookup(addr_table, n->network) == NULL);
- hash_join(addr_table, (hash_link *) n);
+ hash_join(addr_table, &n->hash);
}
static void
netdbHostInsert(netdbEntry * n, const char *hostname)
{
net_db_name *x = memAllocate(MEM_NET_DB_NAME);
- x->name = xstrdup(hostname);
+ x->hash.key = xstrdup(hostname);
x->next = n->hosts;
n->hosts = x;
x->net_db_entry = n;
assert(hash_lookup(host_table, hostname) == NULL);
- hash_join(host_table, (hash_link *) x);
+ hash_join(host_table, &x->hash);
n->link_count++;
}
}
}
hash_remove_link(host_table, (hash_link *) x);
- xfree(x->name);
+ xfree(x->hash.key);
memFree((void *) x, MEM_NET_DB_NAME);
}
(int) n->next_ping_time,
(int) n->last_use_time);
for (x = n->hosts; x; x = x->next)
- logfilePrintf(lf, " %s", x->name);
+ logfilePrintf(lf, " %s", hashKeyStr(&x->hash));
logfilePrintf(lf, "\n");
count++;
#undef RBUF_SZ
netdbFreeNameEntry(void *data)
{
net_db_name *x = data;
- xfree(x->name);
+ xfree(x->hash.key);
memFree(x, MEM_NET_DB_NAME);
}
n->rtt,
n->hops);
for (x = n->hosts; x; x = x->next)
- storeAppendPrintf(sentry, " %s", x->name);
+ storeAppendPrintf(sentry, " %s", hashKeyStr(&x->hash));
storeAppendPrintf(sentry, "\n");
p = n->peers;
for (j = 0; j < n->n_peers; j++, p++) {
/*
- * $Id: pconn.cc,v 1.28 2000/10/17 08:06:04 adrian Exp $
+ * $Id: pconn.cc,v 1.29 2000/10/31 23:48:14 wessels Exp $
*
* DEBUG: section 48 Persistent Connections
* AUTHOR: Duane Wessels
#include "squid.h"
struct _pconn {
- char *key;
- struct _pconn *next;
+ hash_link hash; /* must be first */
int *fds;
int nfds_alloc;
int nfds;
};
-#define PCONN_FDS_SZ 8 /* pconn set size, increase for better memcache hit rate */
+#define PCONN_FDS_SZ 8 /* pconn set size, increase for better memcache hit rate */
#define PCONN_HIST_SZ (1<<16)
int client_pconn_hist[PCONN_HIST_SZ];
int server_pconn_hist[PCONN_HIST_SZ];
pconnNew(const char *key)
{
struct _pconn *p = memPoolAlloc(pconn_data_pool);
- p->key = xstrdup(key);
+ p->hash.key = xstrdup(key);
p->nfds_alloc = PCONN_FDS_SZ;
p->fds = memPoolAlloc(pconn_fds_pool);
- debug(48, 3) ("pconnNew: adding %s\n", p->key);
- hash_join(table, (hash_link *) p);
+ debug(48, 3) ("pconnNew: adding %s\n", hashKeyStr(&p->hash));
+ hash_join(table, &p->hash);
return p;
}
static void
pconnDelete(struct _pconn *p)
{
- debug(48, 3) ("pconnDelete: deleting %s\n", p->key);
+ debug(48, 3) ("pconnDelete: deleting %s\n", hashKeyStr(&p->hash));
hash_remove_link(table, (hash_link *) p);
if (p->nfds_alloc == PCONN_FDS_SZ)
- memPoolFree(pconn_fds_pool,p->fds);
+ memPoolFree(pconn_fds_pool, p->fds);
else
xfree(p->fds);
- xfree(p->key);
+ xfree(p->hash.key);
memPoolFree(pconn_data_pool, p);
}
{
struct _pconn *p = data;
assert(table != NULL);
- debug(48, 3) ("pconnTimeout: FD %d %s\n", fd, p->key);
+ debug(48, 3) ("pconnTimeout: FD %d %s\n", fd, hashKeyStr(&p->hash));
pconnRemoveFD(p, fd);
comm_close(fd);
}
assert(table != NULL);
statCounter.syscalls.sock.reads++;
n = read(fd, buf, 256);
- debug(48, 3) ("pconnRead: %d bytes from FD %d, %s\n", n, fd, p->key);
+ debug(48, 3) ("pconnRead: %d bytes from FD %d, %s\n", n, fd,
+ hashKeyStr(&p->hash));
pconnRemoveFD(p, fd);
comm_close(fd);
}
p->fds = xmalloc(p->nfds_alloc * sizeof(int));
xmemcpy(p->fds, old, p->nfds * sizeof(int));
if (p->nfds == PCONN_FDS_SZ)
- memPoolFree(pconn_fds_pool,old);
+ memPoolFree(pconn_fds_pool, old);
else
xfree(old);
}
/*
- * $Id: protos.h,v 1.383 2000/10/17 08:06:04 adrian Exp $
+ * $Id: protos.h,v 1.384 2000/10/31 23:48:14 wessels Exp $
*
*
* SQUID Internet Object Cache http://squid.nlanr.net/Squid/
/*
* store_key_*.c
*/
-extern const cache_key *storeKeyDup(const cache_key *);
+extern cache_key *storeKeyDup(const cache_key *);
extern cache_key *storeKeyCopy(cache_key *, const cache_key *);
extern void storeKeyFree(const cache_key *);
extern const cache_key *storeKeyScan(const char *);
/*
- * $Id: stat.cc,v 1.339 2000/10/17 08:06:04 adrian Exp $
+ * $Id: stat.cc,v 1.340 2000/10/31 23:48:14 wessels Exp $
*
* DEBUG: section 18 Cache Manager Statistics
* AUTHOR: Harvest Derived
int i;
struct _store_client *sc;
dlink_node *node;
- storeAppendPrintf(s, "KEY %s\n", storeKeyText(e->key));
+ storeAppendPrintf(s, "KEY %s\n", storeKeyText(e->hash.key));
if (mem)
storeAppendPrintf(s, "\t%s %s\n",
RequestMethodStr[mem->method], mem->log_url);
{
StoreEntry *sentry = data;
if (number > 0)
- storeAppendPrintf(sentry, "%d\t %d\t %d\t %.1f\n", size, number, number - oldnum , xdiv((number - oldnum),xm_deltat));
+ storeAppendPrintf(sentry, "%d\t %d\t %d\t %.1f\n", size, number, number - oldnum, xdiv((number - oldnum), xm_deltat));
}
#endif
http->out.offset, http->out.size);
storeAppendPrintf(s, "req_sz %d\n", http->req_sz);
e = http->entry;
- storeAppendPrintf(s, "entry %p/%s\n", e, e ? storeKeyText(e->key) : "N/A");
+ storeAppendPrintf(s, "entry %p/%s\n", e, e ? storeKeyText(e->hash.key) : "N/A");
e = http->old_entry;
- storeAppendPrintf(s, "old_entry %p/%s\n", e, e ? storeKeyText(e->key) : "N/A");
+ storeAppendPrintf(s, "old_entry %p/%s\n", e, e ? storeKeyText(e->hash.key) : "N/A");
storeAppendPrintf(s, "start %d.%06d (%f seconds ago)\n", http->start.tv_sec,
http->start.tv_usec,
tvSubDsec(http->start, current_time));
/*
- * $Id: store.cc,v 1.530 2000/07/20 16:10:41 wessels Exp $
+ * $Id: store.cc,v 1.531 2000/10/31 23:48:14 wessels Exp $
*
* DEBUG: section 20 Storage Manager
* AUTHOR: Harvest Derived
if (e->mem_obj)
destroy_MemObject(e);
storeHashDelete(e);
- assert(e->key == NULL);
+ assert(e->hash.key == NULL);
memFree(e, MEM_STOREENTRY);
}
{
debug(20, 3) ("storeHashInsert: Inserting Entry %p key '%s'\n",
e, storeKeyText(key));
- e->key = storeKeyDup(key);
- hash_join(store_table, (hash_link *) e);
+ e->hash.key = storeKeyDup(key);
+ hash_join(store_table, &e->hash);
}
static void
storeHashDelete(StoreEntry * e)
{
- hash_remove_link(store_table, (hash_link *) e);
- storeKeyFree(e->key);
- e->key = NULL;
+ hash_remove_link(store_table, &e->hash);
+ storeKeyFree(e->hash.key);
+ e->hash.key = NULL;
}
/* -------------------------------------------------------------------------- */
if (e->mem_obj == NULL)
return;
debug(20, 3) ("storePurgeMem: Freeing memory-copy of %s\n",
- storeKeyText(e->key));
+ storeKeyText(e->hash.key));
storeSetMemStatus(e, NOT_IN_MEMORY);
destroy_MemObject(e);
if (e->swap_status != SWAPOUT_DONE)
{
e->lock_count++;
debug(20, 3) ("storeLockObject: key '%s' count=%d\n",
- storeKeyText(e->key), (int) e->lock_count);
+ storeKeyText(e->hash.key), (int) e->lock_count);
e->lastref = squid_curtime;
storeEntryReferenced(e);
}
{
if (EBIT_TEST(e->flags, RELEASE_REQUEST))
return;
- debug(20, 3) ("storeReleaseRequest: '%s'\n", storeKeyText(e->key));
+ debug(20, 3) ("storeReleaseRequest: '%s'\n", storeKeyText(e->hash.key));
EBIT_SET(e->flags, RELEASE_REQUEST);
/*
* Clear cachable flag here because we might get called before
{
e->lock_count--;
debug(20, 3) ("storeUnlockObject: key '%s' count=%d\n",
- storeKeyText(e->key), e->lock_count);
+ storeKeyText(e->hash.key), e->lock_count);
if (e->lock_count)
return (int) e->lock_count;
if (e->store_status == STORE_PENDING)
{
const cache_key *newkey;
MemObject *mem = e->mem_obj;
- if (e->key && EBIT_TEST(e->flags, KEY_PRIVATE))
+ if (e->hash.key && EBIT_TEST(e->flags, KEY_PRIVATE))
return; /* is already private */
- if (e->key) {
+ if (e->hash.key) {
if (e->swap_filen > -1)
storeDirSwapLog(e, SWAP_LOG_DEL);
storeHashDelete(e);
StoreEntry *e2 = NULL;
const cache_key *newkey;
MemObject *mem = e->mem_obj;
- if (e->key && !EBIT_TEST(e->flags, KEY_PRIVATE))
+ if (e->hash.key && !EBIT_TEST(e->flags, KEY_PRIVATE))
return; /* is already public */
assert(mem);
/*
#if MORE_DEBUG_OUTPUT
if (EBIT_TEST(e->flags, RELEASE_REQUEST))
debug(20, 1) ("assertion failed: RELEASE key %s, url %s\n",
- e->key, mem->url);
+ e->hash.key, mem->url);
#endif
assert(!EBIT_TEST(e->flags, RELEASE_REQUEST));
newkey = storeKeyPublic(mem->url, mem->method);
storeRelease(e2);
newkey = storeKeyPublic(mem->url, mem->method);
}
- if (e->key)
+ if (e->hash.key)
storeHashDelete(e);
EBIT_CLR(e->flags, KEY_PRIVATE);
storeHashInsert(e, newkey);
void
storeExpireNow(StoreEntry * e)
{
- debug(20, 3) ("storeExpireNow: '%s'\n", storeKeyText(e->key));
+ debug(20, 3) ("storeExpireNow: '%s'\n", storeKeyText(e->hash.key));
e->expires = squid_curtime;
}
if (len) {
debug(20, 5) ("storeAppend: appending %d bytes for '%s'\n",
len,
- storeKeyText(e->key));
+ storeKeyText(e->hash.key));
storeGetMemSpace(len);
stmemAppend(&mem->data_hdr, buf, len);
mem->inmem_hi += len;
void
storeComplete(StoreEntry * e)
{
- debug(20, 3) ("storeComplete: '%s'\n", storeKeyText(e->key));
+ debug(20, 3) ("storeComplete: '%s'\n", storeKeyText(e->hash.key));
if (e->store_status != STORE_PENDING) {
/*
* if we're not STORE_PENDING, then probably we got aborted
MemObject *mem = e->mem_obj;
assert(e->store_status == STORE_PENDING);
assert(mem != NULL);
- debug(20, 6) ("storeAbort: %s\n", storeKeyText(e->key));
+ debug(20, 6) ("storeAbort: %s\n", storeKeyText(e->hash.key));
storeLockObject(e); /* lock while aborting */
storeNegativeCache(e);
storeReleaseRequest(e);
void
storeRelease(StoreEntry * e)
{
- debug(20, 3) ("storeRelease: Releasing: '%s'\n", storeKeyText(e->key));
+ debug(20, 3) ("storeRelease: Releasing: '%s'\n", storeKeyText(e->hash.key));
/* If, for any reason we can't discard this object because of an
* outstanding request, mark it for pending release */
if (storeEntryLocked(e)) {
const HttpReply *reply;
assert(e->mem_obj != NULL);
reply = e->mem_obj->reply;
- debug(20, 3) ("storeEntryValidLength: Checking '%s'\n", storeKeyText(e->key));
+ debug(20, 3) ("storeEntryValidLength: Checking '%s'\n", storeKeyText(e->hash.key));
debug(20, 5) ("storeEntryValidLength: object_len = %d\n",
objectLen(e));
debug(20, 5) ("storeEntryValidLength: hdr_sz = %d\n",
reply->content_length);
if (reply->content_length < 0) {
debug(20, 5) ("storeEntryValidLength: Unspecified content length: %s\n",
- storeKeyText(e->key));
+ storeKeyText(e->hash.key));
return 1;
}
if (reply->hdr_sz == 0) {
debug(20, 5) ("storeEntryValidLength: Zero header size: %s\n",
- storeKeyText(e->key));
+ storeKeyText(e->hash.key));
return 1;
}
if (e->mem_obj->method == METHOD_HEAD) {
debug(20, 5) ("storeEntryValidLength: HEAD request: %s\n",
- storeKeyText(e->key));
+ storeKeyText(e->hash.key));
return 1;
}
if (reply->sline.status == HTTP_NOT_MODIFIED)
debug(20, 3) ("storeEntryValidLength: %d bytes too %s; '%s'\n",
diff < 0 ? -diff : diff,
diff < 0 ? "big" : "small",
- storeKeyText(e->key));
+ storeKeyText(e->hash.key));
return 0;
}
void
storeEntryDump(const StoreEntry * e, int l)
{
- debug(20, l) ("StoreEntry->key: %s\n", storeKeyText(e->key));
- debug(20, l) ("StoreEntry->next: %p\n", e->next);
+ debug(20, l) ("StoreEntry->key: %s\n", storeKeyText(e->hash.key));
+ debug(20, l) ("StoreEntry->next: %p\n", e->hash.next);
debug(20, l) ("StoreEntry->mem_obj: %p\n", e->mem_obj);
debug(20, l) ("StoreEntry->timestamp: %d\n", (int) e->timestamp);
debug(20, l) ("StoreEntry->lastref: %d\n", (int) e->lastref);
if (strcmp(r->typestr, settings->type) == 0)
return r->create(settings->args);
}
- debug(20,1)("Unknown policy %s\n", settings->type);
+ debug(20, 1) ("Unknown policy %s\n", settings->type);
return NULL;
}
/*
- * $Id: store_client.cc,v 1.97 2000/10/10 02:10:43 wessels Exp $
+ * $Id: store_client.cc,v 1.98 2000/10/31 23:48:15 wessels Exp $
*
* DEBUG: section 20 Storage Manager Client-Side Interface
* AUTHOR: Duane Wessels
{
assert(!EBIT_TEST(e->flags, ENTRY_ABORTED));
debug(20, 3) ("storeClientCopy: %s, seen %d, want %d, size %d, cb %p, cbdata %p\n",
- storeKeyText(e->key),
+ storeKeyText(e->hash.key),
(int) seen_offset,
(int) copy_offset,
(int) size,
}
cbdataLock(sc); /* ick, prevent sc from getting freed */
sc->flags.store_copying = 1;
- debug(20, 3) ("storeClientCopy2: %s\n", storeKeyText(e->key));
+ debug(20, 3) ("storeClientCopy2: %s\n", storeKeyText(e->hash.key));
assert(sc->callback != NULL);
/*
* We used to check for ENTRY_ABORTED here. But there were some
case STORE_META_KEY:
assert(t->length == MD5_DIGEST_CHARS);
if (!EBIT_TEST(e->flags, KEY_PRIVATE) &&
- memcmp(t->value, e->key, MD5_DIGEST_CHARS)) {
+ memcmp(t->value, e->hash.key, MD5_DIGEST_CHARS)) {
debug(20, 2) ("storeClientReadHeader: swapin MD5 mismatch\n");
debug(20, 2) ("\t%s\n", storeKeyText(t->value));
- debug(20, 2) ("\t%s\n", storeKeyText(e->key));
+ debug(20, 2) ("\t%s\n", storeKeyText(e->hash.key));
if (isPowTen(++md5_mismatches))
debug(20, 1) ("WARNING: %d swapin MD5 mismatches\n",
md5_mismatches);
#endif
if (mem == NULL)
return 0;
- debug(20, 3) ("storeUnregister: called for '%s'\n", storeKeyText(e->key));
+ debug(20, 3) ("storeUnregister: called for '%s'\n", storeKeyText(e->hash.key));
if (sc == NULL)
return 0;
if (mem->clients.head == NULL)
dlink_node *nx = NULL;
dlink_node *node;
- debug(20, 3) ("InvokeHandlers: %s\n", storeKeyText(e->key));
+ debug(20, 3) ("InvokeHandlers: %s\n", storeKeyText(e->hash.key));
/* walk the entire list looking for valid callbacks */
for (node = mem->clients.head; node; node = nx) {
sc = node->data;
/*
- * $Id: store_dir.cc,v 1.114 2000/07/18 06:16:42 wessels Exp $
+ * $Id: store_dir.cc,v 1.115 2000/10/31 23:48:15 wessels Exp $
*
* DEBUG: section 47 Store Directory Routines
* AUTHOR: Duane Wessels
assert(op > SWAP_LOG_NOP && op < SWAP_LOG_MAX);
debug(20, 3) ("storeDirSwapLog: %s %s %d %08X\n",
swap_log_op_str[op],
- storeKeyText(e->key),
+ storeKeyText(e->hash.key),
e->swap_dirn,
e->swap_filen);
sd = &Config.cacheSwap.swapDirs[e->swap_dirn];
/*
- * $Id: store_key_md5.cc,v 1.23 2000/03/06 16:23:35 wessels Exp $
+ * $Id: store_key_md5.cc,v 1.24 2000/10/31 23:48:15 wessels Exp $
*
* DEBUG: section 20 Storage Manager MD5 Cache Keys
* AUTHOR: Duane Wessels
return digest;
}
-const cache_key *
+cache_key *
storeKeyDup(const cache_key * key)
{
cache_key *dup = memAllocate(MEM_MD5_DIGEST);
/*
- * $Id: store_log.cc,v 1.19 2000/10/10 18:15:30 wessels Exp $
+ * $Id: store_log.cc,v 1.20 2000/10/31 23:48:15 wessels Exp $
*
* DEBUG: section 20 Storage Manager Logging Functions
* AUTHOR: Duane Wessels
storeLogTags[tag],
e->swap_dirn,
e->swap_filen,
- storeKeyText(e->key),
+ storeKeyText(e->hash.key),
reply->sline.status,
(int) reply->date,
(int) reply->last_modified,
storeLogTags[tag],
e->swap_dirn,
e->swap_filen,
- storeKeyText(e->key));
+ storeKeyText(e->hash.key));
}
}
/*
- * $Id: store_swapin.cc,v 1.26 2000/06/27 22:06:05 hno Exp $
+ * $Id: store_swapin.cc,v 1.27 2000/10/31 23:48:15 wessels Exp $
*
* DEBUG: section 20 Storage Manager Swapin Functions
* AUTHOR: Duane Wessels
return;
}
debug(20, 3) ("storeSwapInStart: called for %d %08X %s \n",
- e->swap_dirn, e->swap_filen, storeKeyText(e->key));
+ e->swap_dirn, e->swap_filen, storeKeyText(e->hash.key));
if (e->swap_status != SWAPOUT_WRITING && e->swap_status != SWAPOUT_DONE) {
debug(20, 1) ("storeSwapInStart: bad swap_status (%s)\n",
swapStatusStr[e->swap_status]);
/*
- * $Id: store_swapmeta.cc,v 1.12 2000/10/17 08:06:04 adrian Exp $
+ * $Id: store_swapmeta.cc,v 1.13 2000/10/31 23:48:15 wessels Exp $
*
* DEBUG: section 20 Storage Manager Swapfile Metadata
* AUTHOR: Kostas Anagnostakis
assert(e->swap_status == SWAPOUT_WRITING);
url = storeUrl(e);
debug(20, 3) ("storeSwapMetaBuild: %s\n", url);
- T = storeSwapTLVAdd(STORE_META_KEY, e->key, MD5_DIGEST_CHARS, T);
+ T = storeSwapTLVAdd(STORE_META_KEY, e->hash.key, MD5_DIGEST_CHARS, T);
T = storeSwapTLVAdd(STORE_META_STD, &e->timestamp, STORE_HDR_METASIZE, T);
T = storeSwapTLVAdd(STORE_META_URL, url, strlen(url) + 1, T);
return TLV;
/*
- * $Id: store_swapout.cc,v 1.76 2000/10/17 08:06:04 adrian Exp $
+ * $Id: store_swapout.cc,v 1.77 2000/10/31 23:48:15 wessels Exp $
*
* DEBUG: section 20 Storage Manager Swapout Functions
* AUTHOR: Duane Wessels
{
MemObject *mem = e->mem_obj;
assert(mem != NULL);
- debug(20, 3) ("storeSwapOutFileClose: %s\n", storeKeyText(e->key));
+ debug(20, 3) ("storeSwapOutFileClose: %s\n", storeKeyText(e->hash.key));
debug(20, 3) ("storeSwapOutFileClose: sio = %p\n", mem->swapout.sio);
if (mem->swapout.sio == NULL)
return;
/*
- * $Id: structs.h,v 1.356 2000/10/17 08:06:05 adrian Exp $
+ * $Id: structs.h,v 1.357 2000/10/31 23:48:15 wessels Exp $
*
*
* SQUID Internet Object Cache http://squid.nlanr.net/Squid/
};
struct _acl_proxy_auth_user {
- /* first two items must be same as hash_link */
- char *user;
- acl_proxy_auth_user *next;
+ hash_link hash; /* must be first */
/* extra fields for proxy_auth */
char *passwd;
int passwd_ok; /* 1 = passwd checked OK */
};
struct _net_db_name {
- char *name;
- net_db_name *htbl_next;
+ hash_link hash; /* must be first */
net_db_name *next;
netdbEntry *net_db_entry;
};
};
struct _netdbEntry {
- /* first two items must be equivalent to hash_link */
- char *key;
- netdbEntry *next;
+ hash_link hash; /* must be first */
char network[16];
int pings_sent;
int pings_recv;
};
struct _StoreEntry {
- /* first two items must be same as hash_link */
- const cache_key *key;
- StoreEntry *next;
+ hash_link hash; /* must be first */
MemObject *mem_obj;
time_t timestamp;
time_t lastref;
};
struct _ClientInfo {
- /* first two items must be equivalent to hash_link */
- char *key;
- ClientInfo *next;
+ hash_link hash; /* must be first */
struct in_addr addr;
struct {
int result_hist[LOG_TYPE_MAX];
struct _PumpStateData {
FwdState *fwd;
request_t *req;
- store_client *sc; /* The store client we're using */
- int c_fd; /* client fd */
- int s_fd; /* server end */
- int rcvd; /* bytes received from client */
- int sent; /* bytes sent to server */
- StoreEntry *request_entry; /* the request entry */
- StoreEntry *reply_entry; /* the reply entry */
- CWCB *callback; /* what to do when we finish sending */
- void *cbdata; /* callback data passed to callback func */
- struct {
- int closing:1;
+ store_client *sc; /* The store client we're using */
+ int c_fd; /* client fd */
+ int s_fd; /* server end */
+ int rcvd; /* bytes received from client */
+ int sent; /* bytes sent to server */
+ StoreEntry *request_entry; /* the request entry */
+ StoreEntry *reply_entry; /* the reply entry */
+ CWCB *callback; /* what to do when we finish sending */
+ void *cbdata; /* callback data passed to callback func */
+ struct {
+ int closing:1;
} flags;
struct _PumpStateData *next;
};
/*
- * $Id: test_cache_digest.cc,v 1.25 2000/05/16 07:09:34 wessels Exp $
+ * $Id: test_cache_digest.cc,v 1.26 2000/10/31 23:48:15 wessels Exp $
*
* AUTHOR: Alex Rousskov
*
cache->bad_add_count++;
} else {
CacheEntry *e = cacheEntryCreate(s);
- hash_join(cache->hash, (hash_link *) e);
+ hash_join(cache->hash, &e->hash);
cache->count++;
if (update_digest)
cacheDigestAdd(cache->digest, e->key);