From 99b461bb2f93ac09cb882652cc80eebf788d61d1 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 9 Jan 2016 01:22:11 -0600 Subject: [PATCH] ircd: ensure irc_dictionary users have names, for stats tracking. --- include/irc_dictionary.h | 9 +------- ircd/cache.c | 4 ++-- ircd/capability.c | 2 +- ircd/client.c | 2 +- ircd/irc_dictionary.c | 47 ++++++---------------------------------- ircd/parse.c | 2 +- ircd/s_conf.c | 2 +- modules/m_stats.c | 1 + 8 files changed, 15 insertions(+), 54 deletions(-) diff --git a/include/irc_dictionary.h b/include/irc_dictionary.h index 69f3babc6..e5dd6a744 100644 --- a/include/irc_dictionary.h +++ b/include/irc_dictionary.h @@ -47,18 +47,11 @@ struct DictionaryIter */ #define DICTIONARY_FOREACH(element, state, dict) for (irc_dictionary_foreach_start((dict), (state)); (element = irc_dictionary_foreach_cur((dict), (state))); irc_dictionary_foreach_next((dict), (state))) -/* - * irc_dictionary_create() creates a new dictionary tree. - * compare_cb is the comparison function, typically strcmp, strcasecmp or - * irccasecmp. - */ -extern struct Dictionary *irc_dictionary_create(DCF compare_cb); - /* * irc_dictionary_create_named() creates a new dictionary tree which has a name. * name is the name, compare_cb is the comparator. */ -extern struct Dictionary *irc_dictionary_create_named(const char *name, DCF compare_cb); +extern struct Dictionary *irc_dictionary_create(const char *name, DCF compare_cb); /* * irc_dictionary_set_comparator_func() resets the comparator used for lookups and diff --git a/ircd/cache.c b/ircd/cache.c index 88dab60d6..08e58b4ae 100644 --- a/ircd/cache.c +++ b/ircd/cache.c @@ -71,8 +71,8 @@ init_cache(void) oper_motd = cache_file(OPATH, "opers.motd", 0); memset(&links_cache_list, 0, sizeof(links_cache_list)); - help_dict_oper = irc_dictionary_create(strcasecmp); - help_dict_user = irc_dictionary_create(strcasecmp); + help_dict_oper = irc_dictionary_create("oper help", strcasecmp); + help_dict_user = irc_dictionary_create("user help", strcasecmp); } /* diff --git a/ircd/capability.c b/ircd/capability.c index daf72657b..075c0d411 100644 --- a/ircd/capability.c +++ b/ircd/capability.c @@ -143,7 +143,7 @@ capability_index_create(const char *name) idx = rb_malloc(sizeof(struct CapabilityIndex)); idx->name = rb_strdup(name); - idx->cap_dict = irc_dictionary_create(strcasecmp); + idx->cap_dict = irc_dictionary_create(name, strcasecmp); idx->highest_bit = 1; rb_dlinkAdd(idx, &idx->node, &capability_indexes); diff --git a/ircd/client.c b/ircd/client.c index 39d4ea4d8..2fc1f2260 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -129,7 +129,7 @@ init_client(void) rb_event_addish("exit_aborted_clients", exit_aborted_clients, NULL, 1); rb_event_add("flood_recalc", flood_recalc, NULL, 1); - nd_dict = irc_dictionary_create(irccmp); + nd_dict = irc_dictionary_create("nickdelay", irccmp); } diff --git a/ircd/irc_dictionary.c b/ircd/irc_dictionary.c index 36a690549..8bfd4ad88 100644 --- a/ircd/irc_dictionary.c +++ b/ircd/irc_dictionary.c @@ -30,8 +30,6 @@ #include "s_assert.h" #include "logger.h" -static rb_bh *elem_heap = NULL; - struct Dictionary { DCF compare_cb; @@ -42,35 +40,7 @@ struct Dictionary }; /* - * irc_dictionary_create(DCF compare_cb) - * - * Dictionary object factory. - * - * Inputs: - * - function to use for comparing two entries in the dtree - * - * Outputs: - * - on success, a new dictionary object. - * - * Side Effects: - * - if services runs out of memory and cannot allocate the object, - * the program will abort. - */ -struct Dictionary *irc_dictionary_create(DCF compare_cb) -{ - struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); - - dtree->compare_cb = compare_cb; - - if (!elem_heap) - elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap"); - - return dtree; -} - -/* - * irc_dictionary_create_named(const char *name, - * DCF compare_cb) + * irc_dictionary_create(const char *name, DCF compare_cb) * * Dictionary object factory. * @@ -85,7 +55,7 @@ struct Dictionary *irc_dictionary_create(DCF compare_cb) * - if services runs out of memory and cannot allocate the object, * the program will abort. */ -struct Dictionary *irc_dictionary_create_named(const char *name, +struct Dictionary *irc_dictionary_create(const char *name, DCF compare_cb) { struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); @@ -93,9 +63,6 @@ struct Dictionary *irc_dictionary_create_named(const char *name, dtree->compare_cb = compare_cb; dtree->id = rb_strdup(name); - if (!elem_heap) - elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap"); - return dtree; } @@ -365,7 +332,7 @@ irc_dictionary_link(struct Dictionary *dict, dict->root->data = delem->data; dict->count--; - rb_bh_free(elem_heap, delem); + rb_free(delem); } } } @@ -474,7 +441,7 @@ void irc_dictionary_destroy(struct Dictionary *dtree, if (destroy_cb != NULL) (*destroy_cb)(n, privdata); - rb_bh_free(elem_heap, n); + rb_free(n); } rb_free(dtree); @@ -714,14 +681,14 @@ struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const char s_assert(data != NULL); s_assert(irc_dictionary_find(dict, key) == NULL); - delem = rb_bh_alloc(elem_heap); + delem = rb_malloc(sizeof(*delem)); delem->key = key; delem->data = data; /* TBD: is this needed? --nenolod */ if (delem->key == NULL) { - rb_bh_free(elem_heap, delem); + rb_free(delem); return NULL; } @@ -760,7 +727,7 @@ void *irc_dictionary_delete(struct Dictionary *dtree, const char *key) data = delem->data; irc_dictionary_unlink_root(dtree); - rb_bh_free(elem_heap, delem); + rb_free(delem); return data; } diff --git a/ircd/parse.c b/ircd/parse.c index 190c9f08a..84132c82d 100644 --- a/ircd/parse.c +++ b/ircd/parse.c @@ -407,7 +407,7 @@ handle_encap(struct Client *client_p, struct Client *source_p, void clear_hash_parse() { - cmd_dict = irc_dictionary_create(strcasecmp); + cmd_dict = irc_dictionary_create("command", strcasecmp); } /* mod_add_cmd diff --git a/ircd/s_conf.c b/ircd/s_conf.c index 0587f3289..ebd6919bb 100644 --- a/ircd/s_conf.c +++ b/ircd/s_conf.c @@ -826,7 +826,7 @@ set_default_conf(void) ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SHA1; if (!alias_dict) - alias_dict = irc_dictionary_create(strcasecmp); + alias_dict = irc_dictionary_create("alias", strcasecmp); } #undef YES diff --git a/modules/m_stats.c b/modules/m_stats.c index ed8d0077f..c37bd6b33 100644 --- a/modules/m_stats.c +++ b/modules/m_stats.c @@ -48,6 +48,7 @@ #include "hash.h" #include "reject.h" #include "whowas.h" +#include "irc_radixtree.h" static int m_stats (struct Client *, struct Client *, int, const char **);