From b37021a45e15eef2e937aa11f185b48cf766d772 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 3 Dec 2007 10:59:25 -0600 Subject: [PATCH] nickdelay -> dictionary. --- include/hash.h | 8 ++++---- include/s_newconf.h | 3 --- modules/core/m_nick.c | 8 ++++---- modules/m_services.c | 4 ++-- modules/m_stats.c | 7 ++----- src/client.c | 4 +++- src/hash.c | 34 +--------------------------------- src/s_newconf.c | 13 ++++++++++--- 8 files changed, 26 insertions(+), 55 deletions(-) diff --git a/include/hash.h b/include/hash.h index 84d9f99..38319f0 100644 --- a/include/hash.h +++ b/include/hash.h @@ -29,13 +29,16 @@ #include "tools.h" +struct Dictionary; + extern dlink_list *clientTable; extern dlink_list *channelTable; extern dlink_list *idTable; extern dlink_list *resvTable; extern dlink_list *hostTable; extern dlink_list *helpTable; -extern dlink_list *ndTable; + +extern struct Dictionary *nd_dict; /* Magic value for FNV hash functions */ #define FNV1_32_INIT 0x811c9dc5UL @@ -101,9 +104,6 @@ extern void add_to_help_hash(const char *name, struct cachefile *hptr); extern void clear_help_hash(void); extern struct cachefile *hash_find_help(const char *name, int flags); -extern void add_to_nd_hash(const char *name, struct nd_entry *nd); -extern struct nd_entry *hash_find_nd(const char *name); - extern void hash_stats(struct Client *); #endif /* INCLUDED_hash_h */ diff --git a/include/s_newconf.h b/include/s_newconf.h index ee25ac9..89233aa 100644 --- a/include/s_newconf.h +++ b/include/s_newconf.h @@ -249,9 +249,6 @@ struct nd_entry { char name[NICKLEN+1]; time_t expire; - unsigned int hashv; - - dlink_node hnode; /* node in hash */ dlink_node lnode; /* node in ll */ }; diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index ea91da2..336b852 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -156,7 +156,7 @@ mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char * return 0; } - if(hash_find_nd(nick)) + if(irc_dictionary_find(nd_dict, nick)) { sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); @@ -217,7 +217,7 @@ m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *p return 0; } - if(hash_find_nd(nick)) + if(irc_dictionary_find(nd_dict, nick)) { sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); @@ -890,7 +890,7 @@ change_remote_nick(struct Client *client_p, struct Client *source_p, del_from_client_hash(source_p->name, source_p); /* invalidate nick delay when a remote client uses the nick.. */ - if((nd = hash_find_nd(nick))) + if((nd = irc_dictionary_retrieve(nd_dict, nick))) free_nd_entry(nd); strcpy(source_p->name, nick); @@ -1225,7 +1225,7 @@ register_client(struct Client *client_p, struct Client *server, } /* remove any nd entries for this nick */ - if((nd = hash_find_nd(nick))) + if((nd = irc_dictionary_retrieve(nd_dict, nick))) free_nd_entry(nd); add_to_client_hash(nick, source_p); diff --git a/modules/m_services.c b/modules/m_services.c index f124fc4..5108f58 100644 --- a/modules/m_services.c +++ b/modules/m_services.c @@ -259,7 +259,7 @@ me_nickdelay(struct Client *client_p, struct Client *source_p, int parc, const c duration = atoi(parv[1]); if (duration <= 0) { - nd = hash_find_nd(parv[2]); + nd = irc_dictionary_retrieve(nd_dict, parv[2]); if (nd != NULL) free_nd_entry(nd); } @@ -268,7 +268,7 @@ me_nickdelay(struct Client *client_p, struct Client *source_p, int parc, const c if (duration > 86400) duration = 86400; add_nd_entry(parv[2]); - nd = hash_find_nd(parv[2]); + nd = irc_dictionary_retrieve(nd_dict, parv[2]); if (nd != NULL) nd->expire = CurrentTime + duration; } diff --git a/modules/m_stats.c b/modules/m_stats.c index 14c3bf7..3c52100 100644 --- a/modules/m_stats.c +++ b/modules/m_stats.c @@ -259,16 +259,13 @@ static void stats_delay(struct Client *source_p) { struct nd_entry *nd; - dlink_node *ptr; - int i; + struct DictionaryIter iter; - HASH_WALK(i, U_MAX, ptr, ndTable) + DICTIONARY_FOREACH(nd, &iter, nd_dict) { - nd = ptr->data; sendto_one_notice(source_p, "Delaying: %s for %ld", nd->name, (long) nd->expire); } - HASH_WALK_END } static void diff --git a/src/client.c b/src/client.c index bb0f472..045f857 100644 --- a/src/client.c +++ b/src/client.c @@ -1,10 +1,11 @@ /* - * ircd-ratbox: A slightly useful ircd. + * charybdis: an advanced ircd. * client.c: Controls clients. * * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center * Copyright (C) 1996-2002 Hybrid Development Team * Copyright (C) 2002-2005 ircd-ratbox development team + * Copyright (C) 2007 William Pitcock * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,6 +61,7 @@ #include "blacklist.h" #include "reject.h" #include "scache.h" +#include "irc_dictionary.h" #define DEBUG_EXITED_CLIENTS diff --git a/src/hash.c b/src/hash.c index 95efc55..f10c5ae 100644 --- a/src/hash.c +++ b/src/hash.c @@ -45,9 +45,8 @@ dlink_list *clientTable; dlink_list *channelTable; dlink_list *idTable; dlink_list *resvTable; -dlink_list *hostTable; +dlink_list *hostTable; dlink_list *helpTable; -dlink_list *ndTable; /* * look in whowas.c for the missing ...[WW_MAX]; entry @@ -95,7 +94,6 @@ init_hash(void) { clientTable = MyMalloc(sizeof(dlink_list) * U_MAX); idTable = MyMalloc(sizeof(dlink_list) * U_MAX); - ndTable = MyMalloc(sizeof(dlink_list) * U_MAX); channelTable = MyMalloc(sizeof(dlink_list) * CH_MAX); hostTable = MyMalloc(sizeof(dlink_list) * HOST_MAX); resvTable = MyMalloc(sizeof(dlink_list) * R_MAX); @@ -306,13 +304,6 @@ add_to_help_hash(const char *name, struct cachefile *hptr) dlinkAddAlloc(hptr, &helpTable[hashv]); } -void -add_to_nd_hash(const char *name, struct nd_entry *nd) -{ - nd->hashv = hash_nick(name); - dlinkAdd(nd, &nd->hnode, &ndTable[nd->hashv]); -} - /* del_from_id_hash() * * removes an id from the id hash table @@ -733,29 +724,6 @@ clear_resv_hash(void) HASH_WALK_END } -struct nd_entry * -hash_find_nd(const char *name) -{ - struct nd_entry *nd; - dlink_node *ptr; - unsigned int hashv; - - if(EmptyString(name)) - return NULL; - - hashv = hash_nick(name); - - DLINK_FOREACH(ptr, ndTable[hashv].head) - { - nd = ptr->data; - - if(!irccmp(name, nd->name)) - return nd; - } - - return NULL; -} - static void output_hash(struct Client *source_p, const char *name, int length, int *counts, int deepest) { diff --git a/src/s_newconf.c b/src/s_newconf.c index dc0474d..865b8fb 100644 --- a/src/s_newconf.c +++ b/src/s_newconf.c @@ -48,6 +48,7 @@ #include "balloc.h" #include "event.h" #include "sprintf_irc.h" +#include "irc_dictionary.h" dlink_list shared_conf_list; dlink_list cluster_conf_list; @@ -744,13 +745,17 @@ get_nd_count(void) return(dlink_list_length(&nd_list)); } +struct Dictionary *nd_dict = NULL; void add_nd_entry(const char *name) { struct nd_entry *nd; - if(hash_find_nd(name) != NULL) + if(nd_dict == NULL) + nd_dict = irc_dictionary_create(irccmp); + + if(irc_dictionary_find(nd_dict, name) != NULL) return; nd = BlockHeapAlloc(nd_heap); @@ -760,14 +765,16 @@ add_nd_entry(const char *name) /* this list is ordered */ dlinkAddTail(nd, &nd->lnode, &nd_list); - add_to_nd_hash(name, nd); + + irc_dictionary_add(nd_dict, nd->name, nd); } void free_nd_entry(struct nd_entry *nd) { + irc_dictionary_delete(nd_dict, nd->name); + dlinkDelete(&nd->lnode, &nd_list); - dlinkDelete(&nd->hnode, &ndTable[nd->hashv]); BlockHeapFree(nd_heap, nd); }