ircd: ensure irc_dictionary users have names, for stats tracking.

This commit is contained in:
William Pitcock 2016-01-09 01:22:11 -06:00
parent b02a913bc8
commit 99b461bb2f
8 changed files with 15 additions and 54 deletions

View file

@ -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))) #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. * irc_dictionary_create_named() creates a new dictionary tree which has a name.
* name is the name, compare_cb is the comparator. * 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 * irc_dictionary_set_comparator_func() resets the comparator used for lookups and

View file

@ -71,8 +71,8 @@ init_cache(void)
oper_motd = cache_file(OPATH, "opers.motd", 0); oper_motd = cache_file(OPATH, "opers.motd", 0);
memset(&links_cache_list, 0, sizeof(links_cache_list)); memset(&links_cache_list, 0, sizeof(links_cache_list));
help_dict_oper = irc_dictionary_create(strcasecmp); help_dict_oper = irc_dictionary_create("oper help", strcasecmp);
help_dict_user = irc_dictionary_create(strcasecmp); help_dict_user = irc_dictionary_create("user help", strcasecmp);
} }
/* /*

View file

@ -143,7 +143,7 @@ capability_index_create(const char *name)
idx = rb_malloc(sizeof(struct CapabilityIndex)); idx = rb_malloc(sizeof(struct CapabilityIndex));
idx->name = rb_strdup(name); idx->name = rb_strdup(name);
idx->cap_dict = irc_dictionary_create(strcasecmp); idx->cap_dict = irc_dictionary_create(name, strcasecmp);
idx->highest_bit = 1; idx->highest_bit = 1;
rb_dlinkAdd(idx, &idx->node, &capability_indexes); rb_dlinkAdd(idx, &idx->node, &capability_indexes);

View file

@ -129,7 +129,7 @@ init_client(void)
rb_event_addish("exit_aborted_clients", exit_aborted_clients, NULL, 1); rb_event_addish("exit_aborted_clients", exit_aborted_clients, NULL, 1);
rb_event_add("flood_recalc", flood_recalc, NULL, 1); rb_event_add("flood_recalc", flood_recalc, NULL, 1);
nd_dict = irc_dictionary_create(irccmp); nd_dict = irc_dictionary_create("nickdelay", irccmp);
} }

View file

@ -30,8 +30,6 @@
#include "s_assert.h" #include "s_assert.h"
#include "logger.h" #include "logger.h"
static rb_bh *elem_heap = NULL;
struct Dictionary struct Dictionary
{ {
DCF compare_cb; DCF compare_cb;
@ -42,35 +40,7 @@ struct Dictionary
}; };
/* /*
* irc_dictionary_create(DCF compare_cb) * irc_dictionary_create(const char *name, 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)
* *
* Dictionary object factory. * 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, * - if services runs out of memory and cannot allocate the object,
* the program will abort. * the program will abort.
*/ */
struct Dictionary *irc_dictionary_create_named(const char *name, struct Dictionary *irc_dictionary_create(const char *name,
DCF compare_cb) DCF compare_cb)
{ {
struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); 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->compare_cb = compare_cb;
dtree->id = rb_strdup(name); dtree->id = rb_strdup(name);
if (!elem_heap)
elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap");
return dtree; return dtree;
} }
@ -365,7 +332,7 @@ irc_dictionary_link(struct Dictionary *dict,
dict->root->data = delem->data; dict->root->data = delem->data;
dict->count--; 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) if (destroy_cb != NULL)
(*destroy_cb)(n, privdata); (*destroy_cb)(n, privdata);
rb_bh_free(elem_heap, n); rb_free(n);
} }
rb_free(dtree); rb_free(dtree);
@ -714,14 +681,14 @@ struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const char
s_assert(data != NULL); s_assert(data != NULL);
s_assert(irc_dictionary_find(dict, key) == NULL); s_assert(irc_dictionary_find(dict, key) == NULL);
delem = rb_bh_alloc(elem_heap); delem = rb_malloc(sizeof(*delem));
delem->key = key; delem->key = key;
delem->data = data; delem->data = data;
/* TBD: is this needed? --nenolod */ /* TBD: is this needed? --nenolod */
if (delem->key == NULL) if (delem->key == NULL)
{ {
rb_bh_free(elem_heap, delem); rb_free(delem);
return NULL; return NULL;
} }
@ -760,7 +727,7 @@ void *irc_dictionary_delete(struct Dictionary *dtree, const char *key)
data = delem->data; data = delem->data;
irc_dictionary_unlink_root(dtree); irc_dictionary_unlink_root(dtree);
rb_bh_free(elem_heap, delem); rb_free(delem);
return data; return data;
} }

View file

@ -407,7 +407,7 @@ handle_encap(struct Client *client_p, struct Client *source_p,
void void
clear_hash_parse() clear_hash_parse()
{ {
cmd_dict = irc_dictionary_create(strcasecmp); cmd_dict = irc_dictionary_create("command", strcasecmp);
} }
/* mod_add_cmd /* mod_add_cmd

View file

@ -826,7 +826,7 @@ set_default_conf(void)
ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SHA1; ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SHA1;
if (!alias_dict) if (!alias_dict)
alias_dict = irc_dictionary_create(strcasecmp); alias_dict = irc_dictionary_create("alias", strcasecmp);
} }
#undef YES #undef YES

View file

@ -48,6 +48,7 @@
#include "hash.h" #include "hash.h"
#include "reject.h" #include "reject.h"
#include "whowas.h" #include "whowas.h"
#include "irc_radixtree.h"
static int m_stats (struct Client *, struct Client *, int, const char **); static int m_stats (struct Client *, struct Client *, int, const char **);