diff --git a/include/cache.h b/include/cache.h index f60b5b9..64fb30c 100644 --- a/include/cache.h +++ b/include/cache.h @@ -43,5 +43,8 @@ extern void load_help(void); extern void send_user_motd(struct Client *); extern void send_oper_motd(struct Client *); +struct Dictionary; +extern struct Dictionary *help_dict; + #endif diff --git a/modules/m_help.c b/modules/m_help.c index 85f9de3..24c562f 100644 --- a/modules/m_help.c +++ b/modules/m_help.c @@ -36,6 +36,7 @@ #include "modules.h" #include "hash.h" #include "cache.h" +#include "irc_dictionary.h" static int m_help(struct Client *, struct Client *, int, const char **); static int mo_help(struct Client *, struct Client *, int, const char **); @@ -61,24 +62,6 @@ DECLARE_MODULE_AV1(help, NULL, NULL, help_clist, NULL, NULL, "$Revision: 254 $") static int m_help(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { - static time_t last_used = 0; - - /* HELP is always local */ - if((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "HELP"); - sendto_one(source_p, form_str(RPL_ENDOFHELP), - me.name, source_p->name, - (parc > 1 && !EmptyString(parv[1])) ? parv[1] : "index"); - return 0; - } - else - { - last_used = CurrentTime; - } - dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); return 0; @@ -119,9 +102,9 @@ dohelp(struct Client *source_p, int flags, const char *topic) if(EmptyString(topic)) topic = ntopic; - hptr = hash_find_help(topic, flags); + hptr = irc_dictionary_retrieve(help_dict, topic); - if(hptr == NULL) + if(hptr == NULL || !(hptr->flags & flags)) { sendto_one(source_p, form_str(ERR_HELPNOTFOUND), me.name, source_p->name, topic); diff --git a/src/cache.c b/src/cache.c index c55364a..3321e64 100644 --- a/src/cache.c +++ b/src/cache.c @@ -44,6 +44,7 @@ #include "hash.h" #include "cache.h" #include "sprintf_irc.h" +#include "irc_dictionary.h" static BlockHeap *cachefile_heap = NULL; static BlockHeap *cacheline_heap = NULL; @@ -52,6 +53,8 @@ struct cachefile *user_motd = NULL; struct cachefile *oper_motd = NULL; char user_motd_changed[MAX_DATE_STRING]; +struct Dictionary *help_dict = NULL; + /* init_cache() * * inputs - @@ -68,6 +71,8 @@ init_cache(void) user_motd = cache_file(MPATH, "ircd.motd", 0); oper_motd = cache_file(OPATH, "opers.motd", 0); + + help_dict = irc_dictionary_create(strcasecmp); } /* cache_file() @@ -180,7 +185,7 @@ load_help(void) { ircsnprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name); cacheptr = cache_file(filename, ldirent->d_name, HELP_OPER); - add_to_help_hash(cacheptr->name, cacheptr); + irc_dictionary_add(help_dict, cacheptr->name, cacheptr); } closedir(helpfile_dir); @@ -202,9 +207,9 @@ load_help(void) */ if(S_ISLNK(sb.st_mode)) { - cacheptr = hash_find_help(ldirent->d_name, HELP_OPER); + cacheptr = irc_dictionary_retrieve(help_dict, ldirent->d_name); - if(cacheptr != NULL) + if(cacheptr != NULL && cacheptr->flags & HELP_OPER) /* is this really needed? --nenolod */ { cacheptr->flags |= HELP_USER; continue; @@ -213,7 +218,7 @@ load_help(void) #endif cacheptr = cache_file(filename, ldirent->d_name, HELP_USER); - add_to_help_hash(cacheptr->name, cacheptr); + irc_dictionary_add(help_dict, cacheptr->name, cacheptr); } closedir(helpfile_dir); diff --git a/src/hash.c b/src/hash.c index f10c5ae..6f2bd65 100644 --- a/src/hash.c +++ b/src/hash.c @@ -46,7 +46,6 @@ dlink_list *channelTable; dlink_list *idTable; dlink_list *resvTable; dlink_list *hostTable; -dlink_list *helpTable; /* * look in whowas.c for the missing ...[WW_MAX]; entry @@ -97,7 +96,6 @@ init_hash(void) channelTable = MyMalloc(sizeof(dlink_list) * CH_MAX); hostTable = MyMalloc(sizeof(dlink_list) * HOST_MAX); resvTable = MyMalloc(sizeof(dlink_list) * R_MAX); - helpTable = MyMalloc(sizeof(dlink_list) * HELP_MAX); } #ifndef RICER_HASHING @@ -209,19 +207,6 @@ hash_resv(const char *name) return fnv_hash_upper_len((const unsigned char *) name, R_MAX_BITS, 30); } -static unsigned int -hash_help(const char *name) -{ - unsigned int h = 0; - - while(*name) - { - h += (unsigned int) (ToLower(*name++) & 0xDF); - } - - return (h % HELP_MAX); -} - /* add_to_id_hash() * * adds an entry to the id hash table @@ -292,18 +277,6 @@ add_to_resv_hash(const char *name, struct ConfItem *aconf) dlinkAddAlloc(aconf, &resvTable[hashv]); } -void -add_to_help_hash(const char *name, struct cachefile *hptr) -{ - unsigned int hashv; - - if(EmptyString(name) || hptr == NULL) - return; - - hashv = hash_help(name); - dlinkAddAlloc(hptr, &helpTable[hashv]); -} - /* del_from_id_hash() * * removes an id from the id hash table @@ -396,21 +369,6 @@ del_from_resv_hash(const char *name, struct ConfItem *aconf) dlinkFindDestroy(aconf, &resvTable[hashv]); } -void -clear_help_hash(void) -{ - dlink_node *ptr; - dlink_node *next_ptr; - int i; - - HASH_WALK_SAFE(i, HELP_MAX, ptr, next_ptr, helpTable) - { - free_cachefile(ptr->data); - dlinkDestroy(ptr, &helpTable[i]); - } - HASH_WALK_END -} - /* find_id() * * finds a client entry from the id hash table @@ -678,30 +636,6 @@ hash_find_resv(const char *name) return NULL; } -struct cachefile * -hash_find_help(const char *name, int flags) -{ - struct cachefile *hptr; - dlink_node *ptr; - unsigned int hashv; - - if(EmptyString(name)) - return NULL; - - hashv = hash_help(name); - - DLINK_FOREACH(ptr, helpTable[hashv].head) - { - hptr = ptr->data; - - if((irccmp(name, hptr->name) == 0) && - (hptr->flags & flags)) - return hptr; - } - - return NULL; -} - void clear_resv_hash(void) {