/*
- * $Id: hash.h,v 1.6 2002/10/13 20:34:51 robertc Exp $
+ * $Id: hash.h,v 1.7 2002/10/15 09:25:32 robertc Exp $
*/
#ifndef SQUID_HASH_H
SQUIDCEXTERN void hash_join(hash_table *, hash_link *);
SQUIDCEXTERN void hash_remove_link(hash_table *, hash_link *);
SQUIDCEXTERN int hashPrime(int n);
-SQUIDCEXTERN void *hash_lookup(hash_table *, const void *);
+SQUIDCEXTERN hash_link *hash_lookup(hash_table *, const void *);
SQUIDCEXTERN void hash_first(hash_table *);
-SQUIDCEXTERN void *hash_next(hash_table *);
+SQUIDCEXTERN hash_link *hash_next(hash_table *);
SQUIDCEXTERN void hash_last(hash_table *);
SQUIDCEXTERN hash_link *hash_get_bucket(hash_table *, unsigned int);
SQUIDCEXTERN void hashFreeMemory(hash_table *);
/*
- * $Id: hash.c,v 1.13 2002/10/02 11:06:30 robertc Exp $
+ * $Id: hash.c,v 1.14 2002/10/15 09:25:32 robertc Exp $
*
* DEBUG: section 0 Hash Tables
* AUTHOR: Harvest Derived
* 'hid'. Returns a pointer to the hash bucket on success; otherwise
* returns NULL.
*/
-void *
+hash_link *
hash_lookup(hash_table * hid, const void *k)
{
hash_link *walker;
*
* MUST call hash_first() before hash_next().
*/
-void *
+hash_link *
hash_next(hash_table * hid)
{
hash_link *this = hid->next;
/*
- * $Id: auth_basic.cc,v 1.19 2002/10/13 20:35:17 robertc Exp $
+ * $Id: auth_basic.cc,v 1.20 2002/10/15 09:25:34 robertc Exp $
*
* DEBUG: section 29 Authenticator
* AUTHOR: Duane Wessels
if (username && (usernamehash = static_cast<AuthUserHashPointer *>(hash_lookup(proxy_auth_username_cache, username)))) {
while (usernamehash) {
if ((authUserHashPointerUser(usernamehash)->auth_type == AUTH_BASIC) &&
- !strcmp(username, usernamehash->key))
+ !strcmp(username, (char const *)usernamehash->key))
return authUserHashPointerUser(usernamehash);
- usernamehash = usernamehash->next;
+ usernamehash = static_cast<AuthUserHashPointer *>(usernamehash->next);
}
}
return NULL;
/*
- * $Id: auth_digest.cc,v 1.16 2002/10/13 20:35:20 robertc Exp $
+ * $Id: auth_digest.cc,v 1.17 2002/10/15 09:25:34 robertc Exp $
*
* DEBUG: section 29 Authenticator
* AUTHOR: Robert Collins
{
if (!nonce)
return;
- if (nonce->hash.key)
- xfree(nonce->hash.key);
- nonce->hash.key = xstrdup(base64_encode_bin((char *) &(nonce->noncedata), sizeof(digest_nonce_data)));
+ if (nonce->key)
+ xfree(nonce->key);
+ nonce->key = xstrdup(base64_encode_bin((char *) &(nonce->noncedata), sizeof(digest_nonce_data)));
}
static digest_nonce_h *
* loop until we get a unique nonce. The nonce creation must
* have a random factor
*/
- while ((temp = authenticateDigestNonceFindNonce((char const *)(newnonce->hash.key)))) {
+ while ((temp = authenticateDigestNonceFindNonce((char const *)(newnonce->key)))) {
/* create a new nonce */
newnonce->noncedata.randomdata = squid_random();
authDigestNonceEncode(newnonce);
}
- hash_join(digest_nonce_cache, &newnonce->hash);
+ hash_join(digest_nonce_cache, newnonce);
/* the cache's link */
authDigestNonceLink(newnonce);
newnonce->flags.incache = 1;
assert(nonce->references == 0);
#if UNREACHABLECODE
if (nonce->flags.incache)
- hash_remove_link(digest_nonce_cache, &nonce->hash);
+ hash_remove_link(digest_nonce_cache, nonce);
#endif
assert(nonce->flags.incache == 0);
- safe_free(nonce->hash.key);
+ safe_free(nonce->key);
memPoolFree(digest_nonce_pool, nonce);
}
}
(long int)current_time.tv_sec);
hash_first(digest_nonce_cache);
while ((nonce = ((digest_nonce_h *) hash_next(digest_nonce_cache)))) {
- debug(29, 3) ("authenticateDigestNonceCacheCleanup: nonce entry : %p '%s'\n", nonce, (char *)nonce->hash.key);
+ debug(29, 3) ("authenticateDigestNonceCacheCleanup: nonce entry : %p '%s'\n", nonce, (char *)nonce->key);
debug(29, 4) ("authenticateDigestNonceCacheCleanup: Creation time: %ld\n", (long int)nonce->noncedata.creationtime);
if (authDigestNonceIsStale(nonce)) {
- debug(29, 4) ("authenticateDigestNonceCacheCleanup: Removing nonce %s from cache due to timeout.\n", (char *)nonce->hash.key);
+ debug(29, 4) ("authenticateDigestNonceCacheCleanup: Removing nonce %s from cache due to timeout.\n", (char *)nonce->key);
assert(nonce->flags.incache);
/* invalidate nonce so future requests fail */
nonce->flags.valid = 0;
{
if (!nonce)
return NULL;
- return (char const *)nonce->hash.key;
+ return (char const *)nonce->key;
}
static digest_nonce_h *
return;
if (!nonce->flags.incache)
return;
- hash_remove_link(digest_nonce_cache, &nonce->hash);
+ hash_remove_link(digest_nonce_cache, nonce);
nonce->flags.incache = 0;
/* the cache's link */
authDigestNonceUnlink(nonce);
if (username && (usernamehash = static_cast<auth_user_hash_pointer *>(hash_lookup(proxy_auth_username_cache, username)))) {
while ((authUserHashPointerUser(usernamehash)->auth_type != AUTH_DIGEST) &&
(usernamehash->next))
- usernamehash = usernamehash->next;
+ usernamehash = static_cast<auth_user_hash_pointer *>(usernamehash->next);
auth_user = NULL;
if (authUserHashPointerUser(usernamehash)->auth_type == AUTH_DIGEST) {
auth_user = authUserHashPointerUser(usernamehash);
};
/* the nonce structure we'll pass around */
-struct _digest_nonce_h {
- hash_link hash; /* must be first */
+struct _digest_nonce_h : public hash_link {
digest_nonce_data noncedata;
/* number of uses we've seen of this nonce */
unsigned long nc;
/*
- * $Id: auth_ntlm.cc,v 1.23 2002/10/13 20:35:23 robertc Exp $
+ * $Id: auth_ntlm.cc,v 1.24 2002/10/15 09:25:35 robertc Exp $
*
* DEBUG: section 29 NTLM Authenticator
* AUTHOR: Robert Collins
node = ntlm_user->proxy_auth_list.head;
/* prevent duplicates */
while (node) {
- if (!strcmp(key, ((struct ProxyAuthCachePointer *) node->data)->key))
+ if (!strcmp(key, (char const *)((struct ProxyAuthCachePointer *) node->data)->key))
return;
node = node->next;
}
* string */
if ((usernamehash = static_cast<AuthUserHashPointer *>(hash_lookup(proxy_auth_username_cache, ntlm_user->username)))) {
while ((authUserHashPointerUser(usernamehash)->auth_type != auth_user->auth_type) && (usernamehash->next) && !authenticateNTLMcmpUsername(static_cast<ntlm_user_t *>(authUserHashPointerUser(usernamehash)->scheme_data), ntlm_user))
- usernamehash = usernamehash->next;
+ usernamehash = static_cast<AuthUserHashPointer*>(usernamehash->next);
if (authUserHashPointerUser(usernamehash)->auth_type == auth_user->auth_type) {
/*
* add another link from the new proxy_auth to the
time_t challengelifetime;
};
-struct ProxyAuthCachePointer {
- /* first two items must be same as hash_link */
- char *key;
- auth_user_hash_pointer *next;dlink_node link;
+struct ProxyAuthCachePointer : public hash_link {
+ dlink_node link;
/* other hash entries that point to the same auth_user */
auth_user_t *auth_user;
};
/*
- * $Id: authenticate.cc,v 1.45 2002/10/14 10:47:51 adrian Exp $
+ * $Id: authenticate.cc,v 1.46 2002/10/15 09:25:33 robertc Exp $
*
* DEBUG: section 29 Authenticator
* AUTHOR: Robert Collins
}
AuthUserHashPointer::AuthUserHashPointer (auth_user_t * anAuth_user):
-key (anAuth_user->username()), next (NULL), auth_user (anAuth_user)
+auth_user (anAuth_user)
{
+ key = (void *)anAuth_user->username();
+ next = NULL;
hash_join(proxy_auth_username_cache, (hash_link *) this);
/* lock for presence in the cache */
authenticateAuthUserLock(auth_user);
/*
- * $Id: authenticate.h,v 1.2 2002/10/14 06:19:49 adrian Exp $
+ * $Id: authenticate.h,v 1.3 2002/10/15 09:25:33 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
class AuthUser;
#endif
-struct AuthUserHashPointer {
+struct AuthUserHashPointer : public hash_link {
/* first two items must be same as hash_link */
- char const *key;
- auth_user_hash_pointer *next;
#ifdef __cplusplus
public:
static void removeFromCache (void *anAuthUserHashPointer);
/*
- * $Id: external_acl.cc,v 1.15 2002/10/13 20:35:01 robertc Exp $
+ * $Id: external_acl.cc,v 1.16 2002/10/15 09:25:33 robertc Exp $
*
* DEBUG: section 82 External ACL
* AUTHOR: Henrik Nordstrom, MARA Systems AB
* external_acl cache entry
* Used opaqueue in the interface
*/
-struct _external_acl_entry {
- hash_link hash;
+struct _external_acl_entry: public hash_link {
dlink_node lru;
int result;
time_t date;
entry = ch->extacl_entry;
if (entry) {
if (cbdataReferenceValid(entry) && entry->def == acl->def &&
- strcmp((char *)entry->hash.key, key) == 0) {
+ strcmp((char *)entry->key, key) == 0) {
/* Ours, use it.. */
} else {
/* Not valid, or not ours.. get rid of it */
free_external_acl_entry(void *data)
{
external_acl_entry *entry = static_cast<external_acl_entry *>(data);
- safe_free(entry->hash.key);
+ safe_free(entry->key);
safe_free(entry->user);
safe_free(entry->error);
}
if (def->cache_size && def->cache_entries >= def->cache_size)
external_acl_cache_delete(def, static_cast<external_acl_entry *>(def->lru_list.tail->data));
entry = cbdataAlloc(external_acl_entry);
- entry->hash.key = xstrdup(key);
+ entry->key = xstrdup(key);
entry->date = squid_curtime;
entry->result = result;
if (user)
if (error)
entry->error = xstrdup(error);
entry->def = def;
- hash_join(def->cache, &entry->hash);
+ hash_join(def->cache, entry);
dlinkAdd(entry, &entry->lru, &def->lru_list);
def->cache_entries += 1;
return entry;
static void
external_acl_cache_delete(external_acl * def, external_acl_entry * entry)
{
- hash_remove_link(def->cache, &entry->hash);
+ hash_remove_link(def->cache, entry);
dlinkDelete(&entry->lru, &def->lru_list);
def->cache_entries -= 1;
cbdataFree(entry);
/*
- * $Id: store.cc,v 1.550 2002/10/15 08:03:30 robertc Exp $
+ * $Id: store.cc,v 1.551 2002/10/15 09:25:33 robertc Exp $
*
* DEBUG: section 20 Storage Manager
* AUTHOR: Harvest Derived
StoreEntry *
storeGet(const cache_key * key)
{
- void *p;
PROF_start(storeGet);
debug(20, 3) ("storeGet: looking up %s\n", storeKeyText(key));
- p = hash_lookup(store_table, key);
+ StoreEntry *p = static_cast<StoreEntry *>(hash_lookup(store_table, key));
PROF_stop(storeGet);
- return (StoreEntry *) p;
+ return p;
}
void