Move irc_* data structures to librb.

This makes the base ircd less cluttered up with data structures that can
go elsewhere.
This commit is contained in:
Elizabeth Myers 2016-03-06 14:17:19 -06:00
parent eddf454cd3
commit a4bf26dd34
31 changed files with 809 additions and 786 deletions

View file

@ -43,7 +43,7 @@
#include "hash.h"
#include "modules.h"
#include "messages.h"
#include "irc_radixtree.h"
#include "rb_radixtree.h"
static int mo_sendbans(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
@ -90,7 +90,7 @@ static int mo_sendbans(struct MsgBuf *msgbuf_p, struct Client *client_p, struct
int i, count;
const char *target, *mask2;
struct Client *server_p;
struct irc_radixtree_iteration_state state;
struct rb_radixtree_iteration_state state;
if (!IsOperRemoteBan(source_p))
{
@ -144,7 +144,7 @@ static int mo_sendbans(struct MsgBuf *msgbuf_p, struct Client *client_p, struct
target, aconf->host, aconf->passwd);
}
IRC_RADIXTREE_FOREACH(aconf, &state, resv_tree)
RB_RADIXTREE_FOREACH(aconf, &state, resv_tree)
{
if (aconf->hold)
continue;

View file

@ -26,11 +26,11 @@
#define INCLUDED_hash_h
struct Dictionary;
struct irc_radixtree;
struct rb_radixtree;
extern struct Dictionary *nd_dict;
extern struct irc_radixtree *resv_tree;
extern struct irc_radixtree *channel_tree;
extern struct rb_radixtree *resv_tree;
extern struct rb_radixtree *channel_tree;
/* Magic value for FNV hash functions */
#define FNV1_32_INIT 0x811c9dc5UL

View file

@ -1,170 +0,0 @@
/*
* charybdis: an advanced ircd.
* irc_dictionary.h: Dictionary-based storage.
*
* Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk>
* Copyright (c) 2007 Jilles Tjoelker <jilles -at- stack.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __IRC_DICTIONARY_H__
#define __IRC_DICTIONARY_H__
struct Dictionary; /* defined in src/dictionary.c */
typedef int (*DCF)(/* const void *a, const void *b */);
struct DictionaryElement
{
struct DictionaryElement *left, *right, *prev, *next;
void *data;
const void *key;
int position;
};
struct DictionaryIter
{
struct DictionaryElement *cur, *next;
};
/*
* this is a convenience macro for inlining iteration of dictionaries.
*/
#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_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(const char *name, DCF compare_cb);
/*
* irc_dictionary_set_comparator_func() resets the comparator used for lookups and
* insertions in the DTree structure.
*/
extern void irc_dictionary_set_comparator_func(struct Dictionary *dict,
DCF compare_cb);
/*
* irc_dictionary_get_comparator_func() returns the comparator used for lookups and
* insertions in the DTree structure.
*/
extern DCF irc_dictionary_get_comparator_func(struct Dictionary *dict);
/*
* irc_dictionary_get_linear_index() returns the linear index of an object in the
* DTree structure.
*/
extern int irc_dictionary_get_linear_index(struct Dictionary *dict, const void *key);
/*
* irc_dictionary_destroy() destroys all entries in a dtree, and also optionally calls
* a defined callback function to destroy any data attached to it.
*/
extern void irc_dictionary_destroy(struct Dictionary *dtree,
void (*destroy_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata);
/*
* irc_dictionary_foreach() iterates all entries in a dtree, and also optionally calls
* a defined callback function to use any data attached to it.
*
* To shortcircuit iteration, return non-zero from the callback function.
*/
extern void irc_dictionary_foreach(struct Dictionary *dtree,
int (*foreach_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata);
/*
* irc_dictionary_search() iterates all entries in a dtree, and also optionally calls
* a defined callback function to use any data attached to it.
*
* When the object is found, a non-NULL is returned from the callback, which results
* in that object being returned to the user.
*/
extern void *irc_dictionary_search(struct Dictionary *dtree,
void *(*foreach_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata);
/*
* irc_dictionary_foreach_start() begins an iteration over all items
* keeping state in the given struct. If there is only one iteration
* in progress at a time, it is permitted to remove the current element
* of the iteration (but not any other element).
*/
extern void irc_dictionary_foreach_start(struct Dictionary *dtree,
struct DictionaryIter *state);
/*
* irc_dictionary_foreach_cur() returns the current element of the iteration,
* or NULL if there are no more elements.
*/
extern void *irc_dictionary_foreach_cur(struct Dictionary *dtree,
struct DictionaryIter *state);
/*
* irc_dictionary_foreach_next() moves to the next element.
*/
extern void irc_dictionary_foreach_next(struct Dictionary *dtree,
struct DictionaryIter *state);
/*
* irc_dictionary_add() adds a key->value entry to the dictionary tree.
*/
extern struct DictionaryElement *irc_dictionary_add(struct Dictionary *dtree, const void *key, void *data);
/*
* irc_dictionary_find() returns a struct DictionaryElement container from a dtree for key 'key'.
*/
extern struct DictionaryElement *irc_dictionary_find(struct Dictionary *dtree, const void *key);
/*
* irc_dictionary_find() returns data from a dtree for key 'key'.
*/
extern void *irc_dictionary_retrieve(struct Dictionary *dtree, const void *key);
/*
* irc_dictionary_delete() deletes a key->value entry from the dictionary tree.
*/
extern void *irc_dictionary_delete(struct Dictionary *dtree, const void *key);
/*
* irc_dictionary_size() returns the number of elements in a dictionary tree.
*/
extern unsigned int irc_dictionary_size(struct Dictionary *dtree);
void irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata);
void irc_dictionary_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata);
#define IRC_POINTER_TO_INT(x) ((int32_t) (long) (x))
#define IRC_INT_TO_POINTER(x) ((void *) (long) (int32_t) (x))
#define IRC_POINTER_TO_UINT(x) ((uint32_t) (unsigned long) (x))
#define IRC_UINT_TO_POINTER(x) ((void *) (unsigned long) (uint32_t) (x))
static inline int irc_int32cmp(const void *a, const void *b)
{
return IRC_POINTER_TO_INT(b) - IRC_POINTER_TO_INT(a);
}
static inline int irc_uint32cmp(const void *a, const void *b)
{
return IRC_POINTER_TO_UINT(b) - IRC_POINTER_TO_UINT(a);
}
#endif

View file

@ -1,156 +0,0 @@
/*
* charybdis: an advanced ircd.
* irc_radixtree.h: Dictionary-based storage.
*
* Copyright (c) 2007-2016 William Pitcock <nenolod -at- dereferenced.org>
* Copyright (c) 2007-2016 Jilles Tjoelker <jilles -at- stack.nl>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __irc_radixtree_H__
#define __irc_radixtree_H__
struct irc_radixtree;/* defined in ircd/irc_radixtree.c */
struct irc_radixtree_leaf; /* defined in ircd/irc_radixtree.c */
/*
* struct irc_radixtree_iteration_state, private.
*/
struct irc_radixtree_iteration_state
{
struct irc_radixtree_leaf *cur, *next;
void *pspare[4];
int ispare[4];
};
/*
* this is a convenience macro for inlining iteration of dictionaries.
*/
#define IRC_RADIXTREE_FOREACH(element, state, dict) \
for (irc_radixtree_foreach_start((dict), (state)); (element = irc_radixtree_foreach_cur((dict), (state))); irc_radixtree_foreach_next((dict), (state)))
#define IRC_RADIXTREE_FOREACH_FROM(element, state, dict, key) \
for (irc_radixtree_foreach_start_from((dict), (state), (key)); (element = irc_radixtree_foreach_cur((dict), (state))); irc_radixtree_foreach_next((dict), (state)))
/*
* irc_radixtree_create() creates a new patricia tree of the defined resolution.
* compare_cb is the canonizing function.
*/
extern struct irc_radixtree *irc_radixtree_create(const char *name, void (*canonize_cb)(char *key));
/*
* irc_radixtree_shutdown() deallocates all heaps used in patricia trees. This is
* useful on embedded devices with little memory, and/or when you know you won't need
* any more patricia trees.
*/
extern void irc_radixtree_shutdown(void);
/*
* irc_radixtree_destroy() destroys all entries in a dtree, and also optionally calls
* a defined callback function to destroy any data attached to it.
*/
extern void irc_radixtree_destroy(struct irc_radixtree *dtree, void (*destroy_cb)(const char *key, void *data, void *privdata), void *privdata);
/*
* irc_radixtree_foreach() iterates all entries in a dtree, and also optionally calls
* a defined callback function to use any data attached to it.
*
* To shortcircuit iteration, return non-zero from the callback function.
*/
extern void irc_radixtree_foreach(struct irc_radixtree *dtree, int (*foreach_cb)(const char *key, void *data, void *privdata), void *privdata);
/*
* irc_radixtree_search() iterates all entries in a dtree, and also optionally calls
* a defined callback function to use any data attached to it.
*
* When the object is found, a non-NULL is returned from the callback, which results
* in that object being returned to the user.
*/
extern void *irc_radixtree_search(struct irc_radixtree *dtree, void *(*foreach_cb)(const char *key, void *data, void *privdata), void *privdata);
/*
* irc_radixtree_foreach_start() begins an iteration over all items
* keeping state in the given struct. If there is only one iteration
* in progress at a time, it is permitted to remove the current element
* of the iteration (but not any other element).
*/
extern void irc_radixtree_foreach_start(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state);
/*
* irc_radixtree_foreach_start_from() begins an iteration over all items,
* starting with the item specified by `key`. If there is only one iteration
* in progress at a time, it is permitted to remove the current element
* of the iteration (but not any other element).
* Use NULL as a key to have it start at the beginning.
*/
extern void irc_radixtree_foreach_start_from(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state, const char *key);
/*
* irc_radixtree_foreach_cur() returns the current element of the iteration,
* or NULL if there are no more elements.
*/
extern void *irc_radixtree_foreach_cur(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state);
/*
* irc_radixtree_foreach_next() moves to the next element.
*/
extern void irc_radixtree_foreach_next(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state);
/*
* irc_radixtree_add() adds a key->value entry to the patricia tree.
*/
extern int irc_radixtree_add(struct irc_radixtree *dtree, const char *key, void *data);
/*
* irc_radixtree_find() returns data from a dtree for key 'key'.
*/
extern void *irc_radixtree_retrieve(struct irc_radixtree *dtree, const char *key);
/*
* irc_radixtree_delete() deletes a key->value entry from the patricia tree.
*/
extern void *irc_radixtree_delete(struct irc_radixtree *dtree, const char *key);
/* Low-level functions */
struct irc_radixtree_leaf *irc_radixtree_elem_add(struct irc_radixtree *dtree, const char *key, void *data);
struct irc_radixtree_leaf *irc_radixtree_elem_find(struct irc_radixtree *dtree, const char *key, int fuzzy);
void irc_radixtree_elem_delete(struct irc_radixtree *dtree, struct irc_radixtree_leaf *elem);
const char *irc_radixtree_elem_get_key(struct irc_radixtree_leaf *elem);
void irc_radixtree_elem_set_data(struct irc_radixtree_leaf *elem, void *data);
void *irc_radixtree_elem_get_data(struct irc_radixtree_leaf *elem);
unsigned int irc_radixtree_size(struct irc_radixtree *dict);
void irc_radixtree_stats(struct irc_radixtree *dict, void (*cb)(const char *line, void *privdata), void *privdata);
void irc_radixtree_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata);
void irc_radixtree_strcasecanon(char *key);
void irc_radixtree_irccasecanon(char *key);
#endif

View file

@ -1,6 +1,6 @@
/*
* ircd-ratbox: A slightly useful ircd.
* irc_string.h: A header for the ircd string functions.
* match.h: A header for the ircd string functions.
*
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
* Copyright (C) 1996-2002 Hybrid Development Team
@ -137,4 +137,26 @@ extern const unsigned int CharAttrs[];
#define IsNonEOS(c) (CharAttrs[(unsigned char)(c)] & NONEOS_C)
#define IsEol(c) (CharAttrs[(unsigned char)(c)] & EOL_C)
/* Below are used for radix trees and the like */
static inline void irccasecanon(char *str)
{
while (*str)
{
*str = ToUpper(*str);
str++;
}
return;
}
static inline void strcasecanon(char *str)
{
while (*str)
{
*str = toupper((unsigned char)*str);
str++;
}
return;
}
#endif /* INCLUDED_match_h */

View file

@ -25,7 +25,7 @@
#ifndef INCLUDED_parse_h_h
#define INCLUDED_parse_h_h
#include "irc_dictionary.h"
#include "rb_dictionary.h"
struct Message;
struct Client;

View file

@ -31,8 +31,6 @@ libircd_la_SOURCES = \
hook.c \
hostmask.c \
ipv4_from_ipv6.c \
irc_radixtree.c \
irc_dictionary.c \
ircd.c \
ircd_parser.y \
ircd_lexer.l \

View file

@ -37,7 +37,7 @@
#include "client.h"
#include "hash.h"
#include "cache.h"
#include "irc_dictionary.h"
#include "rb_dictionary.h"
#include "numeric.h"
#include "send.h"
@ -69,8 +69,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("oper help", strcasecmp);
help_dict_user = irc_dictionary_create("user help", strcasecmp);
help_dict_oper = rb_dictionary_create("oper help", strcasecmp);
help_dict_user = rb_dictionary_create("user help", strcasecmp);
}
/*
@ -245,12 +245,12 @@ load_help(void)
DICTIONARY_FOREACH(cacheptr, &iter, help_dict_oper)
{
irc_dictionary_delete(help_dict_oper, cacheptr->name);
rb_dictionary_delete(help_dict_oper, cacheptr->name);
free_cachefile(cacheptr);
}
DICTIONARY_FOREACH(cacheptr, &iter, help_dict_user)
{
irc_dictionary_delete(help_dict_user, cacheptr->name);
rb_dictionary_delete(help_dict_user, cacheptr->name);
free_cachefile(cacheptr);
}
@ -265,7 +265,7 @@ load_help(void)
continue;
snprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name);
cacheptr = cache_file(filename, ldirent->d_name, HELP_OPER);
irc_dictionary_add(help_dict_oper, cacheptr->name, cacheptr);
rb_dictionary_add(help_dict_oper, cacheptr->name, cacheptr);
}
closedir(helpfile_dir);
@ -289,7 +289,7 @@ load_help(void)
*/
if(S_ISLNK(sb.st_mode))
{
cacheptr = irc_dictionary_retrieve(help_dict_oper, ldirent->d_name);
cacheptr = rb_dictionary_retrieve(help_dict_oper, ldirent->d_name);
if(cacheptr != NULL)
{
@ -300,7 +300,7 @@ load_help(void)
#endif
cacheptr = cache_file(filename, ldirent->d_name, HELP_USER);
irc_dictionary_add(help_dict_user, cacheptr->name, cacheptr);
rb_dictionary_add(help_dict_user, cacheptr->name, cacheptr);
}
closedir(helpfile_dir);

View file

@ -20,7 +20,7 @@
#include "stdinc.h"
#include "capability.h"
#include "irc_dictionary.h"
#include "rb_dictionary.h"
#include "s_assert.h"
static rb_dlink_list capability_indexes = { NULL, NULL, 0 };
@ -32,7 +32,7 @@ capability_find(struct CapabilityIndex *idx, const char *cap)
if (cap == NULL)
return NULL;
return irc_dictionary_retrieve(idx->cap_dict, cap);
return rb_dictionary_retrieve(idx->cap_dict, cap);
}
unsigned int
@ -44,7 +44,7 @@ capability_get(struct CapabilityIndex *idx, const char *cap, void **ownerdata)
if (cap == NULL)
return 0;
entry = irc_dictionary_retrieve(idx->cap_dict, cap);
entry = rb_dictionary_retrieve(idx->cap_dict, cap);
if (entry != NULL && !(entry->flags & CAP_ORPHANED))
{
if (ownerdata != NULL)
@ -64,7 +64,7 @@ capability_put(struct CapabilityIndex *idx, const char *cap, void *ownerdata)
if (!idx->highest_bit)
return 0xFFFFFFFF;
if ((entry = irc_dictionary_retrieve(idx->cap_dict, cap)) != NULL)
if ((entry = rb_dictionary_retrieve(idx->cap_dict, cap)) != NULL)
{
entry->flags &= ~CAP_ORPHANED;
return (1 << entry->value);
@ -76,7 +76,7 @@ capability_put(struct CapabilityIndex *idx, const char *cap, void *ownerdata)
entry->value = idx->highest_bit;
entry->ownerdata = ownerdata;
irc_dictionary_add(idx->cap_dict, entry->cap, entry);
rb_dictionary_add(idx->cap_dict, entry->cap, entry);
idx->highest_bit++;
if (idx->highest_bit % (sizeof(unsigned int) * 8) == 0)
@ -107,7 +107,7 @@ capability_orphan(struct CapabilityIndex *idx, const char *cap)
s_assert(idx != NULL);
entry = irc_dictionary_retrieve(idx->cap_dict, cap);
entry = rb_dictionary_retrieve(idx->cap_dict, cap);
if (entry != NULL)
{
entry->flags &= ~CAP_REQUIRED;
@ -123,7 +123,7 @@ capability_require(struct CapabilityIndex *idx, const char *cap)
s_assert(idx != NULL);
entry = irc_dictionary_retrieve(idx->cap_dict, cap);
entry = rb_dictionary_retrieve(idx->cap_dict, cap);
if (entry != NULL)
entry->flags |= CAP_REQUIRED;
}
@ -143,7 +143,7 @@ capability_index_create(const char *name)
idx = rb_malloc(sizeof(struct CapabilityIndex));
idx->name = name;
idx->cap_dict = irc_dictionary_create(name, strcasecmp);
idx->cap_dict = rb_dictionary_create(name, strcasecmp);
idx->highest_bit = 1;
rb_dlinkAdd(idx, &idx->node, &capability_indexes);
@ -158,7 +158,7 @@ capability_index_destroy(struct CapabilityIndex *idx)
rb_dlinkDelete(&idx->node, &capability_indexes);
irc_dictionary_destroy(idx->cap_dict, capability_destroy, NULL);
rb_dictionary_destroy(idx->cap_dict, capability_destroy, NULL);
rb_free(idx);
}

View file

@ -51,7 +51,7 @@
#include "blacklist.h"
#include "reject.h"
#include "scache.h"
#include "irc_dictionary.h"
#include "rb_dictionary.h"
#include "sslproc.h"
#include "s_assert.h"
@ -127,7 +127,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("nickdelay", irccmp);
nd_dict = rb_dictionary_create("nickdelay", irccmp);
}

View file

@ -37,17 +37,17 @@
#include "cache.h"
#include "s_newconf.h"
#include "s_assert.h"
#include "irc_dictionary.h"
#include "irc_radixtree.h"
#include "rb_dictionary.h"
#include "rb_radixtree.h"
struct Dictionary *client_connid_tree = NULL;
struct Dictionary *client_zconnid_tree = NULL;
struct irc_radixtree *client_id_tree = NULL;
struct irc_radixtree *client_name_tree = NULL;
struct rb_radixtree *client_id_tree = NULL;
struct rb_radixtree *client_name_tree = NULL;
struct irc_radixtree *channel_tree = NULL;
struct irc_radixtree *resv_tree = NULL;
struct irc_radixtree *hostname_tree = NULL;
struct rb_radixtree *channel_tree = NULL;
struct rb_radixtree *resv_tree = NULL;
struct rb_radixtree *hostname_tree = NULL;
/*
* look in whowas.c for the missing ...[WW_MAX]; entry
@ -60,15 +60,15 @@ struct irc_radixtree *hostname_tree = NULL;
void
init_hash(void)
{
client_connid_tree = irc_dictionary_create("client connid", irc_uint32cmp);
client_zconnid_tree = irc_dictionary_create("client zconnid", irc_uint32cmp);
client_id_tree = irc_radixtree_create("client id", NULL);
client_name_tree = irc_radixtree_create("client name", irc_radixtree_irccasecanon);
client_connid_tree = rb_dictionary_create("client connid", rb_uint32cmp);
client_zconnid_tree = rb_dictionary_create("client zconnid", rb_uint32cmp);
client_id_tree = rb_radixtree_create("client id", NULL);
client_name_tree = rb_radixtree_create("client name", irccasecanon);
channel_tree = irc_radixtree_create("channel", irc_radixtree_irccasecanon);
resv_tree = irc_radixtree_create("resv", irc_radixtree_irccasecanon);
channel_tree = rb_radixtree_create("channel", irccasecanon);
resv_tree = rb_radixtree_create("resv", irccasecanon);
hostname_tree = irc_radixtree_create("hostname", irc_radixtree_irccasecanon);
hostname_tree = rb_radixtree_create("hostname", irccasecanon);
}
u_int32_t
@ -141,7 +141,7 @@ add_to_id_hash(const char *name, struct Client *client_p)
if(EmptyString(name) || (client_p == NULL))
return;
irc_radixtree_add(client_id_tree, name, client_p);
rb_radixtree_add(client_id_tree, name, client_p);
}
/* add_to_client_hash()
@ -156,7 +156,7 @@ add_to_client_hash(const char *name, struct Client *client_p)
if(EmptyString(name) || (client_p == NULL))
return;
irc_radixtree_add(client_name_tree, name, client_p);
rb_radixtree_add(client_name_tree, name, client_p);
}
/* add_to_hostname_hash()
@ -173,7 +173,7 @@ add_to_hostname_hash(const char *hostname, struct Client *client_p)
if(EmptyString(hostname) || (client_p == NULL))
return;
list = irc_radixtree_retrieve(hostname_tree, hostname);
list = rb_radixtree_retrieve(hostname_tree, hostname);
if (list != NULL)
{
rb_dlinkAddAlloc(client_p, list);
@ -181,7 +181,7 @@ add_to_hostname_hash(const char *hostname, struct Client *client_p)
}
list = rb_malloc(sizeof(*list));
irc_radixtree_add(hostname_tree, hostname, list);
rb_radixtree_add(hostname_tree, hostname, list);
rb_dlinkAddAlloc(client_p, list);
}
@ -197,7 +197,7 @@ add_to_resv_hash(const char *name, struct ConfItem *aconf)
if(EmptyString(name) || aconf == NULL)
return;
irc_radixtree_add(resv_tree, name, aconf);
rb_radixtree_add(resv_tree, name, aconf);
}
/* del_from_id_hash()
@ -212,7 +212,7 @@ del_from_id_hash(const char *id, struct Client *client_p)
if(EmptyString(id) || client_p == NULL)
return;
irc_radixtree_delete(client_id_tree, id);
rb_radixtree_delete(client_id_tree, id);
}
/* del_from_client_hash()
@ -228,7 +228,7 @@ del_from_client_hash(const char *name, struct Client *client_p)
if(EmptyString(name) || client_p == NULL)
return;
irc_radixtree_delete(client_name_tree, name);
rb_radixtree_delete(client_name_tree, name);
}
/* del_from_channel_hash()
@ -244,7 +244,7 @@ del_from_channel_hash(const char *name, struct Channel *chptr)
if(EmptyString(name) || chptr == NULL)
return;
irc_radixtree_delete(channel_tree, name);
rb_radixtree_delete(channel_tree, name);
}
/* del_from_hostname_hash()
@ -259,7 +259,7 @@ del_from_hostname_hash(const char *hostname, struct Client *client_p)
if(hostname == NULL || client_p == NULL)
return;
list = irc_radixtree_retrieve(hostname_tree, hostname);
list = rb_radixtree_retrieve(hostname_tree, hostname);
if (list == NULL)
return;
@ -267,7 +267,7 @@ del_from_hostname_hash(const char *hostname, struct Client *client_p)
if (rb_dlink_list_length(list) == 0)
{
irc_radixtree_delete(hostname_tree, hostname);
rb_radixtree_delete(hostname_tree, hostname);
rb_free(list);
}
}
@ -284,7 +284,7 @@ del_from_resv_hash(const char *name, struct ConfItem *aconf)
if(EmptyString(name) || aconf == NULL)
return;
irc_radixtree_delete(resv_tree, name);
rb_radixtree_delete(resv_tree, name);
}
/* find_id()
@ -297,7 +297,7 @@ find_id(const char *name)
if(EmptyString(name))
return NULL;
return irc_radixtree_retrieve(client_id_tree, name);
return rb_radixtree_retrieve(client_id_tree, name);
}
/* find_client()
@ -315,7 +315,7 @@ find_client(const char *name)
if(IsDigit(*name))
return (find_id(name));
return irc_radixtree_retrieve(client_name_tree, name);
return rb_radixtree_retrieve(client_name_tree, name);
}
/* find_named_client()
@ -329,7 +329,7 @@ find_named_client(const char *name)
if(EmptyString(name))
return NULL;
return irc_radixtree_retrieve(client_name_tree, name);
return rb_radixtree_retrieve(client_name_tree, name);
}
/* find_server()
@ -351,7 +351,7 @@ find_server(struct Client *source_p, const char *name)
return(target_p);
}
target_p = irc_radixtree_retrieve(client_name_tree, name);
target_p = rb_radixtree_retrieve(client_name_tree, name);
if (target_p != NULL)
{
if(IsServer(target_p) || IsMe(target_p))
@ -375,7 +375,7 @@ find_hostname(const char *hostname)
if(EmptyString(hostname))
return NULL;
hlist = irc_radixtree_retrieve(hostname_tree, hostname);
hlist = rb_radixtree_retrieve(hostname_tree, hostname);
if (hlist == NULL)
return NULL;
@ -393,7 +393,7 @@ find_channel(const char *name)
if(EmptyString(name))
return NULL;
return irc_radixtree_retrieve(channel_tree, name);
return rb_radixtree_retrieve(channel_tree, name);
}
/*
@ -433,7 +433,7 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
s = t;
}
chptr = irc_radixtree_retrieve(channel_tree, s);
chptr = rb_radixtree_retrieve(channel_tree, s);
if (chptr != NULL)
{
if (isnew != NULL)
@ -448,7 +448,7 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */
rb_dlinkAdd(chptr, &chptr->node, &global_channel_list);
irc_radixtree_add(channel_tree, chptr->chname, chptr);
rb_radixtree_add(channel_tree, chptr->chname, chptr);
return chptr;
}
@ -466,7 +466,7 @@ hash_find_resv(const char *name)
if(EmptyString(name))
return NULL;
aconf = irc_radixtree_retrieve(resv_tree, name);
aconf = rb_radixtree_retrieve(resv_tree, name);
if (aconf != NULL)
{
aconf->port++;
@ -480,15 +480,15 @@ void
clear_resv_hash(void)
{
struct ConfItem *aconf;
struct irc_radixtree_iteration_state iter;
struct rb_radixtree_iteration_state iter;
IRC_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
RB_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
{
/* skip temp resvs */
if(aconf->hold)
continue;
irc_radixtree_delete(resv_tree, aconf->host);
rb_radixtree_delete(resv_tree, aconf->host);
free_conf(aconf);
}
}
@ -496,25 +496,25 @@ clear_resv_hash(void)
void
add_to_zconnid_hash(struct Client *client_p)
{
irc_dictionary_add(client_zconnid_tree, IRC_UINT_TO_POINTER(client_p->localClient->zconnid), client_p);
rb_dictionary_add(client_zconnid_tree, RB_UINT_TO_POINTER(client_p->localClient->zconnid), client_p);
}
void
del_from_zconnid_hash(struct Client *client_p)
{
irc_dictionary_delete(client_zconnid_tree, IRC_UINT_TO_POINTER(client_p->localClient->zconnid));
rb_dictionary_delete(client_zconnid_tree, RB_UINT_TO_POINTER(client_p->localClient->zconnid));
}
void
add_to_cli_connid_hash(struct Client *client_p)
{
irc_dictionary_add(client_connid_tree, IRC_UINT_TO_POINTER(client_p->localClient->connid), client_p);
rb_dictionary_add(client_connid_tree, RB_UINT_TO_POINTER(client_p->localClient->connid), client_p);
}
void
del_from_cli_connid_hash(struct Client *client_p)
{
irc_dictionary_delete(client_connid_tree, IRC_UINT_TO_POINTER(client_p->localClient->connid));
rb_dictionary_delete(client_connid_tree, RB_UINT_TO_POINTER(client_p->localClient->connid));
}
struct Client *
@ -522,11 +522,11 @@ find_cli_connid_hash(uint32_t connid)
{
struct Client *target_p;
target_p = irc_dictionary_retrieve(client_connid_tree, IRC_UINT_TO_POINTER(connid));
target_p = rb_dictionary_retrieve(client_connid_tree, RB_UINT_TO_POINTER(connid));
if (target_p != NULL)
return target_p;
target_p = irc_dictionary_retrieve(client_zconnid_tree, IRC_UINT_TO_POINTER(connid));
target_p = rb_dictionary_retrieve(client_zconnid_tree, RB_UINT_TO_POINTER(connid));
if (target_p != NULL)
return target_p;

View file

@ -35,14 +35,14 @@
#include "hash.h"
#include "numeric.h"
#include "send.h"
#include "irc_radixtree.h"
#include "rb_radixtree.h"
static struct irc_radixtree *monitor_tree;
static struct rb_radixtree *monitor_tree;
void
init_monitor(void)
{
monitor_tree = irc_radixtree_create("monitor lists", irc_radixtree_irccasecanon);
monitor_tree = rb_radixtree_create("monitor lists", irccasecanon);
}
struct monitor *
@ -50,7 +50,7 @@ find_monitor(const char *name, int add)
{
struct monitor *monptr;
monptr = irc_radixtree_retrieve(monitor_tree, name);
monptr = rb_radixtree_retrieve(monitor_tree, name);
if (monptr != NULL)
return monptr;
@ -58,7 +58,7 @@ find_monitor(const char *name, int add)
{
monptr = rb_malloc(sizeof(*monptr));
rb_strlcpy(monptr->name, name, sizeof(monptr->name));
irc_radixtree_add(monitor_tree, monptr->name, monptr);
rb_radixtree_add(monitor_tree, monptr->name, monptr);
return monptr;
}
@ -72,7 +72,7 @@ free_monitor(struct monitor *monptr)
if (rb_dlink_list_length(&monptr->users) > 0)
return;
irc_radixtree_delete(monitor_tree, monptr->name);
rb_radixtree_delete(monitor_tree, monptr->name);
rb_free(monptr);
}

View file

@ -1780,7 +1780,7 @@ conf_end_alias(struct TopConf *tc)
return -1;
}
irc_dictionary_add(alias_dict, yy_alias->name, yy_alias);
rb_dictionary_add(alias_dict, yy_alias->name, yy_alias);
return 0;
}

View file

@ -35,9 +35,9 @@
#include "match.h"
#include "hash.h"
#include "operhash.h"
#include "irc_radixtree.h"
#include "rb_radixtree.h"
static struct irc_radixtree *operhash_tree = NULL;
static struct rb_radixtree *operhash_tree = NULL;
struct operhash_entry
{
@ -48,7 +48,7 @@ struct operhash_entry
void
init_operhash(void)
{
operhash_tree = irc_radixtree_create("operhash", NULL);
operhash_tree = rb_radixtree_create("operhash", NULL);
}
const char *
@ -60,7 +60,7 @@ operhash_add(const char *name)
if(EmptyString(name))
return NULL;
if((ohash = (struct operhash_entry *) irc_radixtree_retrieve(operhash_tree, name)) != NULL)
if((ohash = (struct operhash_entry *) rb_radixtree_retrieve(operhash_tree, name)) != NULL)
{
ohash->refcount++;
return ohash->name;
@ -70,20 +70,20 @@ operhash_add(const char *name)
ohash = rb_malloc(sizeof(struct operhash_entry) + len);
ohash->refcount = 1;
memcpy(ohash->name, name, len);
irc_radixtree_add(operhash_tree, ohash->name, ohash);
rb_radixtree_add(operhash_tree, ohash->name, ohash);
return ohash->name;
}
const char *
operhash_find(const char *name)
{
return irc_radixtree_retrieve(operhash_tree, name);
return rb_radixtree_retrieve(operhash_tree, name);
}
void
operhash_delete(const char *name)
{
struct operhash_entry *ohash = irc_radixtree_retrieve(operhash_tree, name);
struct operhash_entry *ohash = rb_radixtree_retrieve(operhash_tree, name);
if (ohash != NULL)
rb_free(ohash);

View file

@ -136,14 +136,14 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
}
else
{
mptr = irc_dictionary_retrieve(cmd_dict, msgbuf.cmd);
mptr = rb_dictionary_retrieve(cmd_dict, msgbuf.cmd);
/* no command or its encap only, error */
if(!mptr || !mptr->cmd)
{
if (IsPerson(client_p))
{
struct alias_entry *aptr = irc_dictionary_retrieve(alias_dict, msgbuf.cmd);
struct alias_entry *aptr = rb_dictionary_retrieve(alias_dict, msgbuf.cmd);
if (aptr != NULL)
{
do_alias(aptr, client_p, reconstruct_parv(msgbuf.n_para - 1, msgbuf.para + 1));
@ -264,7 +264,7 @@ handle_encap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *so
struct MessageEntry ehandler;
MessageHandler handler = 0;
mptr = irc_dictionary_retrieve(cmd_dict, command);
mptr = rb_dictionary_retrieve(cmd_dict, command);
if(mptr == NULL || mptr->cmd == NULL)
return;
@ -290,7 +290,7 @@ handle_encap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *so
void
clear_hash_parse()
{
cmd_dict = irc_dictionary_create("command", strcasecmp);
cmd_dict = rb_dictionary_create("command", strcasecmp);
}
/* mod_add_cmd
@ -309,14 +309,14 @@ mod_add_cmd(struct Message *msg)
if(msg == NULL)
return;
if (irc_dictionary_find(cmd_dict, msg->cmd) != NULL)
if (rb_dictionary_find(cmd_dict, msg->cmd) != NULL)
return;
msg->count = 0;
msg->rcount = 0;
msg->bytes = 0;
irc_dictionary_add(cmd_dict, msg->cmd, msg);
rb_dictionary_add(cmd_dict, msg->cmd, msg);
}
/* mod_del_cmd
@ -332,7 +332,7 @@ mod_del_cmd(struct Message *msg)
if(msg == NULL)
return;
irc_dictionary_delete(cmd_dict, msg->cmd);
rb_dictionary_delete(cmd_dict, msg->cmd);
}
/* cancel_clients()

View file

@ -826,7 +826,7 @@ set_default_conf(void)
ConfigFileEntry.hide_opers_in_whois = 0;
if (!alias_dict)
alias_dict = irc_dictionary_create("alias", strcasecmp);
alias_dict = rb_dictionary_create("alias", strcasecmp);
}
#undef YES
@ -1532,7 +1532,7 @@ clear_out_old_conf(void)
/* remove any aliases... -- nenolod */
if (alias_dict != NULL)
{
irc_dictionary_destroy(alias_dict, free_alias_cb, NULL);
rb_dictionary_destroy(alias_dict, free_alias_cb, NULL);
alias_dict = NULL;
}

View file

@ -41,8 +41,8 @@
#include "hostmask.h"
#include "newconf.h"
#include "hash.h"
#include "irc_dictionary.h"
#include "irc_radixtree.h"
#include "rb_dictionary.h"
#include "rb_radixtree.h"
#include "s_assert.h"
#include "logger.h"
#include "dns.h"
@ -686,9 +686,9 @@ expire_temp_rxlines(void *unused)
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
int i;
struct irc_radixtree_iteration_state state;
struct rb_radixtree_iteration_state state;
IRC_RADIXTREE_FOREACH(aconf, &state, resv_tree)
RB_RADIXTREE_FOREACH(aconf, &state, resv_tree)
{
if(aconf->lifetime != 0)
continue;
@ -699,7 +699,7 @@ expire_temp_rxlines(void *unused)
"Temporary RESV for [%s] expired",
aconf->host);
irc_radixtree_delete(resv_tree, aconf->host);
rb_radixtree_delete(resv_tree, aconf->host);
free_conf(aconf);
}
}
@ -750,7 +750,7 @@ add_nd_entry(const char *name)
{
struct nd_entry *nd;
if(irc_dictionary_find(nd_dict, name) != NULL)
if(rb_dictionary_find(nd_dict, name) != NULL)
return;
nd = rb_bh_alloc(nd_heap);
@ -761,13 +761,13 @@ add_nd_entry(const char *name)
/* this list is ordered */
rb_dlinkAddTail(nd, &nd->lnode, &nd_list);
irc_dictionary_add(nd_dict, nd->name, nd);
rb_dictionary_add(nd_dict, nd->name, nd);
}
void
free_nd_entry(struct nd_entry *nd)
{
irc_dictionary_delete(nd_dict, nd->name);
rb_dictionary_delete(nd_dict, nd->name);
rb_dlinkDelete(&nd->lnode, &nd_list);
rb_bh_free(nd_heap, nd);

View file

@ -32,7 +32,7 @@
#include "scache.h"
#include "s_conf.h"
#include "s_assert.h"
#include "irc_radixtree.h"
#include "rb_radixtree.h"
/*
* ircd used to store full servernames in anUser as well as in the
@ -45,7 +45,7 @@
* reworked to serve for flattening/delaying /links also
* -- jilles
*
* reworked to make use of irc_radixtree.
* reworked to make use of rb_radixtree.
* -- kaniini
*/
@ -62,12 +62,12 @@ struct scache_entry
time_t last_split;
};
static struct irc_radixtree *scache_tree = NULL;
static struct rb_radixtree *scache_tree = NULL;
void
clear_scache_hash_table(void)
{
scache_tree = irc_radixtree_create("server names cache", irc_radixtree_irccasecanon);
scache_tree = rb_radixtree_create("server names cache", irccasecanon);
}
static struct scache_entry *
@ -75,7 +75,7 @@ find_or_add(const char *name)
{
struct scache_entry *ptr;
ptr = irc_radixtree_retrieve(scache_tree, name);
ptr = rb_radixtree_retrieve(scache_tree, name);
if (ptr != NULL)
return ptr;
@ -89,7 +89,7 @@ find_or_add(const char *name)
ptr->last_connect = 0;
ptr->last_split = 0;
irc_radixtree_add(scache_tree, ptr->name, ptr);
rb_radixtree_add(scache_tree, ptr->name, ptr);
return ptr;
}
@ -134,10 +134,10 @@ void
scache_send_flattened_links(struct Client *source_p)
{
struct scache_entry *scache_ptr;
struct irc_radixtree_iteration_state iter;
struct rb_radixtree_iteration_state iter;
int show;
IRC_RADIXTREE_FOREACH(scache_ptr, &iter, scache_tree)
RB_RADIXTREE_FOREACH(scache_ptr, &iter, scache_tree)
{
if (!irccmp(scache_ptr->name, me.name))
show = FALSE;
@ -170,9 +170,9 @@ void
scache_send_missing(struct Client *source_p)
{
struct scache_entry *scache_ptr;
struct irc_radixtree_iteration_state iter;
struct rb_radixtree_iteration_state iter;
IRC_RADIXTREE_FOREACH(scache_ptr, &iter, scache_tree)
RB_RADIXTREE_FOREACH(scache_ptr, &iter, scache_tree)
{
if (!(scache_ptr->flags & SC_ONLINE) && scache_ptr->last_split > rb_current_time() - MISSING_TIMEOUT)
sendto_one_numeric(source_p, RPL_MAP, "** %s (recently split)",
@ -191,12 +191,12 @@ void
count_scache(size_t * number_servers_cached, size_t * mem_servers_cached)
{
struct scache_entry *scache_ptr;
struct irc_radixtree_iteration_state iter;
struct rb_radixtree_iteration_state iter;
*number_servers_cached = 0;
*mem_servers_cached = 0;
IRC_RADIXTREE_FOREACH(scache_ptr, &iter, scache_tree)
RB_RADIXTREE_FOREACH(scache_ptr, &iter, scache_tree)
{
*number_servers_cached = *number_servers_cached + 1;
*mem_servers_cached = *mem_servers_cached +

View file

@ -38,7 +38,7 @@
#include "send.h"
#include "logger.h"
#include "scache.h"
#include "irc_radixtree.h"
#include "rb_radixtree.h"
struct whowas_top
{
@ -46,7 +46,7 @@ struct whowas_top
rb_dlink_list wwlist;
};
static struct irc_radixtree *whowas_tree = NULL;
static struct rb_radixtree *whowas_tree = NULL;
static rb_dlink_list whowas_list = {NULL, NULL, 0};
static unsigned int whowas_list_length = NICKNAMEHISTORYLENGTH;
static void whowas_trim(void *unused);
@ -56,7 +56,7 @@ whowas_free_wtop(struct whowas_top *wtop)
{
if(rb_dlink_list_length(&wtop->wwlist) == 0)
{
irc_radixtree_delete(whowas_tree, wtop->name);
rb_radixtree_delete(whowas_tree, wtop->name);
rb_free(wtop->name);
rb_free(wtop);
}
@ -67,13 +67,13 @@ whowas_get_top(const char *name)
{
struct whowas_top *wtop;
wtop = irc_radixtree_retrieve(whowas_tree, name);
wtop = rb_radixtree_retrieve(whowas_tree, name);
if (wtop != NULL)
return wtop;
wtop = rb_malloc(sizeof(struct whowas_top));
wtop->name = rb_strdup(name);
irc_radixtree_add(whowas_tree, wtop->name, wtop);
rb_radixtree_add(whowas_tree, wtop->name, wtop);
return wtop;
}
@ -82,7 +82,7 @@ rb_dlink_list *
whowas_get_list(const char *name)
{
struct whowas_top *wtop;
wtop = irc_radixtree_retrieve(whowas_tree, name);
wtop = rb_radixtree_retrieve(whowas_tree, name);
if(wtop == NULL)
return NULL;
return &wtop->wwlist;
@ -151,7 +151,7 @@ whowas_get_history(const char *nick, time_t timelimit)
struct whowas_top *wtop;
rb_dlink_node *ptr;
wtop = irc_radixtree_retrieve(whowas_tree, nick);
wtop = rb_radixtree_retrieve(whowas_tree, nick);
if(wtop == NULL)
return NULL;
@ -197,7 +197,7 @@ whowas_trim(void *unused)
void
whowas_init(void)
{
whowas_tree = irc_radixtree_create("whowas", irc_radixtree_irccasecanon);
whowas_tree = rb_radixtree_create("whowas", irccasecanon);
if(whowas_list_length == 0)
{
whowas_list_length = NICKNAMEHISTORYLENGTH;
@ -217,5 +217,5 @@ whowas_memory_usage(size_t * count, size_t * memused)
{
*count = rb_dlink_list_length(&whowas_list);
*memused += *count * sizeof(struct Whowas);
*memused += sizeof(struct whowas_top) * irc_radixtree_size(whowas_tree);
*memused += sizeof(struct whowas_top) * rb_radixtree_size(whowas_tree);
}

View file

@ -0,0 +1,170 @@
/*
* charybdis: an advanced ircd.
* rb_dictionary.h: Dictionary-based storage.
*
* Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk>
* Copyright (c) 2007 Jilles Tjoelker <jilles -at- stack.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __RB_DICTIONARY_H__
#define __RB_DICTIONARY_H__
struct Dictionary; /* defined in src/dictionary.c */
typedef int (*DCF)(/* const void *a, const void *b */);
struct DictionaryElement
{
struct DictionaryElement *left, *right, *prev, *next;
void *data;
const void *key;
int position;
};
struct DictionaryIter
{
struct DictionaryElement *cur, *next;
};
/*
* this is a convenience macro for inlining iteration of dictionaries.
*/
#define DICTIONARY_FOREACH(element, state, dict) for (rb_dictionary_foreach_start((dict), (state)); (element = rb_dictionary_foreach_cur((dict), (state))); rb_dictionary_foreach_next((dict), (state)))
/*
* rb_dictionary_create_named() creates a new dictionary tree which has a name.
* name is the name, compare_cb is the comparator.
*/
extern struct Dictionary *rb_dictionary_create(const char *name, DCF compare_cb);
/*
* rb_dictionary_set_comparator_func() resets the comparator used for lookups and
* insertions in the DTree structure.
*/
extern void rb_dictionary_set_comparator_func(struct Dictionary *dict,
DCF compare_cb);
/*
* rb_dictionary_get_comparator_func() returns the comparator used for lookups and
* insertions in the DTree structure.
*/
extern DCF rb_dictionary_get_comparator_func(struct Dictionary *dict);
/*
* rb_dictionary_get_linear_index() returns the linear index of an object in the
* DTree structure.
*/
extern int rb_dictionary_get_linear_index(struct Dictionary *dict, const void *key);
/*
* rb_dictionary_destroy() destroys all entries in a dtree, and also optionally calls
* a defined callback function to destroy any data attached to it.
*/
extern void rb_dictionary_destroy(struct Dictionary *dtree,
void (*destroy_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata);
/*
* rb_dictionary_foreach() iterates all entries in a dtree, and also optionally calls
* a defined callback function to use any data attached to it.
*
* To shortcircuit iteration, return non-zero from the callback function.
*/
extern void rb_dictionary_foreach(struct Dictionary *dtree,
int (*foreach_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata);
/*
* rb_dictionary_search() iterates all entries in a dtree, and also optionally calls
* a defined callback function to use any data attached to it.
*
* When the object is found, a non-NULL is returned from the callback, which results
* in that object being returned to the user.
*/
extern void *rb_dictionary_search(struct Dictionary *dtree,
void *(*foreach_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata);
/*
* rb_dictionary_foreach_start() begins an iteration over all items
* keeping state in the given struct. If there is only one iteration
* in progress at a time, it is permitted to remove the current element
* of the iteration (but not any other element).
*/
extern void rb_dictionary_foreach_start(struct Dictionary *dtree,
struct DictionaryIter *state);
/*
* rb_dictionary_foreach_cur() returns the current element of the iteration,
* or NULL if there are no more elements.
*/
extern void *rb_dictionary_foreach_cur(struct Dictionary *dtree,
struct DictionaryIter *state);
/*
* rb_dictionary_foreach_next() moves to the next element.
*/
extern void rb_dictionary_foreach_next(struct Dictionary *dtree,
struct DictionaryIter *state);
/*
* rb_dictionary_add() adds a key->value entry to the dictionary tree.
*/
extern struct DictionaryElement *rb_dictionary_add(struct Dictionary *dtree, const void *key, void *data);
/*
* rb_dictionary_find() returns a struct DictionaryElement container from a dtree for key 'key'.
*/
extern struct DictionaryElement *rb_dictionary_find(struct Dictionary *dtree, const void *key);
/*
* rb_dictionary_find() returns data from a dtree for key 'key'.
*/
extern void *rb_dictionary_retrieve(struct Dictionary *dtree, const void *key);
/*
* rb_dictionary_delete() deletes a key->value entry from the dictionary tree.
*/
extern void *rb_dictionary_delete(struct Dictionary *dtree, const void *key);
/*
* rb_dictionary_size() returns the number of elements in a dictionary tree.
*/
extern unsigned int rb_dictionary_size(struct Dictionary *dtree);
void rb_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata);
void rb_dictionary_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata);
#define RB_POINTER_TO_INT(x) ((int32_t) (long) (x))
#define RB_INT_TO_POINTER(x) ((void *) (long) (int32_t) (x))
#define RB_POINTER_TO_UINT(x) ((uint32_t) (unsigned long) (x))
#define RB_UINT_TO_POINTER(x) ((void *) (unsigned long) (uint32_t) (x))
static inline int rb_int32cmp(const void *a, const void *b)
{
return RB_POINTER_TO_INT(b) - RB_POINTER_TO_INT(a);
}
static inline int rb_uint32cmp(const void *a, const void *b)
{
return RB_POINTER_TO_UINT(b) - RB_POINTER_TO_UINT(a);
}
#endif

View file

@ -0,0 +1,153 @@
/*
* charybdis: an advanced ircd.
* rb_radixtree.h: Dictionary-based storage.
*
* Copyright (c) 2007-2016 William Pitcock <nenolod -at- dereferenced.org>
* Copyright (c) 2007-2016 Jilles Tjoelker <jilles -at- stack.nl>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __rb_radixtree_H__
#define __rb_radixtree_H__
struct rb_radixtree; /* defined in src/rb_radixtree.c */
struct rb_radixtree_leaf; /* defined in src/rb_radixtree.c */
/*
* struct rb_radixtree_iteration_state, private.
*/
struct rb_radixtree_iteration_state
{
struct rb_radixtree_leaf *cur, *next;
void *pspare[4];
int ispare[4];
};
/*
* this is a convenience macro for inlining iteration of dictionaries.
*/
#define RB_RADIXTREE_FOREACH(element, state, dict) \
for (rb_radixtree_foreach_start((dict), (state)); (element = rb_radixtree_foreach_cur((dict), (state))); rb_radixtree_foreach_next((dict), (state)))
#define RB_RADIXTREE_FOREACH_FROM(element, state, dict, key) \
for (rb_radixtree_foreach_start_from((dict), (state), (key)); (element = rb_radixtree_foreach_cur((dict), (state))); rb_radixtree_foreach_next((dict), (state)))
/*
* rb_radixtree_create() creates a new patricia tree of the defined resolution.
* compare_cb is the canonizing function.
*/
extern struct rb_radixtree *rb_radixtree_create(const char *name, void (*canonize_cb)(char *key));
/*
* rb_radixtree_shutdown() deallocates all heaps used in patricia trees. This is
* useful on embedded devices with little memory, and/or when you know you won't need
* any more patricia trees.
*/
extern void rb_radixtree_shutdown(void);
/*
* rb_radixtree_destroy() destroys all entries in a dtree, and also optionally calls
* a defined callback function to destroy any data attached to it.
*/
extern void rb_radixtree_destroy(struct rb_radixtree *dtree, void (*destroy_cb)(const char *key, void *data, void *privdata), void *privdata);
/*
* rb_radixtree_foreach() iterates all entries in a dtree, and also optionally calls
* a defined callback function to use any data attached to it.
*
* To shortcircuit iteration, return non-zero from the callback function.
*/
extern void rb_radixtree_foreach(struct rb_radixtree *dtree, int (*foreach_cb)(const char *key, void *data, void *privdata), void *privdata);
/*
* rb_radixtree_search() iterates all entries in a dtree, and also optionally calls
* a defined callback function to use any data attached to it.
*
* When the object is found, a non-NULL is returned from the callback, which results
* in that object being returned to the user.
*/
extern void *rb_radixtree_search(struct rb_radixtree *dtree, void *(*foreach_cb)(const char *key, void *data, void *privdata), void *privdata);
/*
* rb_radixtree_foreach_start() begins an iteration over all items
* keeping state in the given struct. If there is only one iteration
* in progress at a time, it is permitted to remove the current element
* of the iteration (but not any other element).
*/
extern void rb_radixtree_foreach_start(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state);
/*
* rb_radixtree_foreach_start_from() begins an iteration over all items,
* starting with the item specified by `key`. If there is only one iteration
* in progress at a time, it is permitted to remove the current element
* of the iteration (but not any other element).
* Use NULL as a key to have it start at the beginning.
*/
extern void rb_radixtree_foreach_start_from(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state, const char *key);
/*
* rb_radixtree_foreach_cur() returns the current element of the iteration,
* or NULL if there are no more elements.
*/
extern void *rb_radixtree_foreach_cur(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state);
/*
* rb_radixtree_foreach_next() moves to the next element.
*/
extern void rb_radixtree_foreach_next(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state);
/*
* rb_radixtree_add() adds a key->value entry to the patricia tree.
*/
extern int rb_radixtree_add(struct rb_radixtree *dtree, const char *key, void *data);
/*
* rb_radixtree_find() returns data from a dtree for key 'key'.
*/
extern void *rb_radixtree_retrieve(struct rb_radixtree *dtree, const char *key);
/*
* rb_radixtree_delete() deletes a key->value entry from the patricia tree.
*/
extern void *rb_radixtree_delete(struct rb_radixtree *dtree, const char *key);
/* Low-level functions */
struct rb_radixtree_leaf *rb_radixtree_elem_add(struct rb_radixtree *dtree, const char *key, void *data);
struct rb_radixtree_leaf *rb_radixtree_elem_find(struct rb_radixtree *dtree, const char *key, int fuzzy);
void rb_radixtree_elem_delete(struct rb_radixtree *dtree, struct rb_radixtree_leaf *elem);
const char *rb_radixtree_elem_get_key(struct rb_radixtree_leaf *elem);
void rb_radixtree_elem_set_data(struct rb_radixtree_leaf *elem, void *data);
void *rb_radixtree_elem_get_data(struct rb_radixtree_leaf *elem);
unsigned int rb_radixtree_size(struct rb_radixtree *dict);
void rb_radixtree_stats(struct rb_radixtree *dict, void (*cb)(const char *line, void *privdata), void *privdata);
void rb_radixtree_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata);
#endif

View file

@ -38,6 +38,8 @@ librb_la_SOURCES = \
kqueue.c \
rawbuf.c \
patricia.c \
dictionary.c \
radixtree.c \
arc4random.c \
version.c

View file

@ -1,6 +1,6 @@
/*
* charybdis: an advanced ircd
* irc_dictionary.c: Dictionary-based information storage.
* rb_dictionary.c: Dictionary-based information storage.
*
* Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk>
* Copyright (c) 2007 Jilles Tjoelker <jilles -at- stack.nl>
@ -22,13 +22,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdinc.h"
#include "match.h"
#include "client.h"
#include "setup.h"
#include "irc_dictionary.h"
#include "s_assert.h"
#include "logger.h"
#include <librb_config.h>
#include <rb_lib.h>
#include <rb_dictionary.h>
struct Dictionary
{
@ -44,7 +40,7 @@ struct Dictionary
static rb_dlink_list dictionary_list = {NULL, NULL, 0};
/*
* irc_dictionary_create(const char *name, DCF compare_cb)
* rb_dictionary_create(const char *name, DCF compare_cb)
*
* Dictionary object factory.
*
@ -59,7 +55,7 @@ static rb_dlink_list dictionary_list = {NULL, NULL, 0};
* - if services runs out of memory and cannot allocate the object,
* the program will abort.
*/
struct Dictionary *irc_dictionary_create(const char *name,
struct Dictionary *rb_dictionary_create(const char *name,
DCF compare_cb)
{
struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary));
@ -73,7 +69,7 @@ struct Dictionary *irc_dictionary_create(const char *name,
}
/*
* irc_dictionary_set_comparator_func(struct Dictionary *dict,
* rb_dictionary_set_comparator_func(struct Dictionary *dict,
* DCF compare_cb)
*
* Resets the comparator function used by the dictionary code for
@ -89,17 +85,17 @@ struct Dictionary *irc_dictionary_create(const char *name,
* Side Effects:
* - the dictionary comparator function is reset.
*/
void irc_dictionary_set_comparator_func(struct Dictionary *dict,
void rb_dictionary_set_comparator_func(struct Dictionary *dict,
DCF compare_cb)
{
s_assert(dict != NULL);
s_assert(compare_cb != NULL);
lrb_assert(dict != NULL);
lrb_assert(compare_cb != NULL);
dict->compare_cb = compare_cb;
}
/*
* irc_dictionary_get_comparator_func(struct Dictionary *dict)
* rb_dictionary_get_comparator_func(struct Dictionary *dict)
*
* Returns the current comparator function used by the dictionary.
*
@ -113,15 +109,15 @@ void irc_dictionary_set_comparator_func(struct Dictionary *dict,
* - none
*/
DCF
irc_dictionary_get_comparator_func(struct Dictionary *dict)
rb_dictionary_get_comparator_func(struct Dictionary *dict)
{
s_assert(dict != NULL);
lrb_assert(dict != NULL);
return dict->compare_cb;
}
/*
* irc_dictionary_get_linear_index(struct Dictionary *dict,
* rb_dictionary_get_linear_index(struct Dictionary *dict,
* const void *key)
*
* Gets a linear index number for key.
@ -137,14 +133,14 @@ irc_dictionary_get_comparator_func(struct Dictionary *dict)
* - rebuilds the linear index if the tree is marked as dirty.
*/
int
irc_dictionary_get_linear_index(struct Dictionary *dict, const void *key)
rb_dictionary_get_linear_index(struct Dictionary *dict, const void *key)
{
struct DictionaryElement *elem;
s_assert(dict != NULL);
s_assert(key != NULL);
lrb_assert(dict != NULL);
lrb_assert(key != NULL);
elem = irc_dictionary_find(dict, key);
elem = rb_dictionary_find(dict, key);
if (elem == NULL)
return -1;
@ -165,7 +161,7 @@ irc_dictionary_get_linear_index(struct Dictionary *dict, const void *key)
}
/*
* irc_dictionary_retune(struct Dictionary *dict, const void *key)
* rb_dictionary_retune(struct Dictionary *dict, const void *key)
*
* Retunes the tree, self-optimizing for the element which belongs to key.
*
@ -179,12 +175,12 @@ irc_dictionary_get_linear_index(struct Dictionary *dict, const void *key)
* - a new root node is nominated.
*/
static void
irc_dictionary_retune(struct Dictionary *dict, const void *key)
rb_dictionary_retune(struct Dictionary *dict, const void *key)
{
struct DictionaryElement n, *tn, *left, *right, *node;
int ret;
s_assert(dict != NULL);
lrb_assert(dict != NULL);
if (dict->root == NULL)
return;
@ -257,7 +253,7 @@ irc_dictionary_retune(struct Dictionary *dict, const void *key)
}
/*
* irc_dictionary_link(struct Dictionary *dict,
* rb_dictionary_link(struct Dictionary *dict,
* struct DictionaryElement *delem)
*
* Links a dictionary tree element to the dictionary.
@ -278,11 +274,11 @@ irc_dictionary_retune(struct Dictionary *dict, const void *key)
* - a node is linked to the dictionary tree
*/
static void
irc_dictionary_link(struct Dictionary *dict,
rb_dictionary_link(struct Dictionary *dict,
struct DictionaryElement *delem)
{
s_assert(dict != NULL);
s_assert(delem != NULL);
lrb_assert(dict != NULL);
lrb_assert(delem != NULL);
dict->dirty = TRUE;
@ -298,7 +294,7 @@ irc_dictionary_link(struct Dictionary *dict,
{
int ret;
irc_dictionary_retune(dict, delem->key);
rb_dictionary_retune(dict, delem->key);
if ((ret = dict->compare_cb(delem->key, dict->root->key)) < 0)
{
@ -344,7 +340,7 @@ irc_dictionary_link(struct Dictionary *dict,
}
/*
* irc_dictionary_unlink_root(struct Dictionary *dict)
* rb_dictionary_unlink_root(struct Dictionary *dict)
*
* Unlinks the root dictionary tree element from the dictionary.
*
@ -358,7 +354,7 @@ irc_dictionary_link(struct Dictionary *dict,
* - the root node is unlinked from the dictionary tree
*/
static void
irc_dictionary_unlink_root(struct Dictionary *dict)
rb_dictionary_unlink_root(struct Dictionary *dict)
{
struct DictionaryElement *delem, *nextnode, *parentofnext;
@ -377,7 +373,7 @@ irc_dictionary_unlink_root(struct Dictionary *dict)
/* Make the node with the next highest key the new root.
* This node has a NULL left pointer. */
nextnode = delem->next;
s_assert(nextnode->left == NULL);
lrb_assert(nextnode->left == NULL);
if (nextnode == delem->right)
{
dict->root = nextnode;
@ -388,7 +384,7 @@ irc_dictionary_unlink_root(struct Dictionary *dict)
parentofnext = delem->right;
while (parentofnext->left != NULL && parentofnext->left != nextnode)
parentofnext = parentofnext->left;
s_assert(parentofnext->left == nextnode);
lrb_assert(parentofnext->left == nextnode);
parentofnext->left = nextnode->right;
dict->root = nextnode;
dict->root->left = delem->left;
@ -413,7 +409,7 @@ irc_dictionary_unlink_root(struct Dictionary *dict)
}
/*
* irc_dictionary_destroy(struct Dictionary *dtree,
* rb_dictionary_destroy(struct Dictionary *dtree,
* void (*destroy_cb)(dictionary_elem_t *delem, void *privdata),
* void *privdata);
*
@ -434,13 +430,13 @@ irc_dictionary_unlink_root(struct Dictionary *dict)
* - if this is called without a callback, the objects bound to the
* DTree will not be destroyed.
*/
void irc_dictionary_destroy(struct Dictionary *dtree,
void rb_dictionary_destroy(struct Dictionary *dtree,
void (*destroy_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata)
{
struct DictionaryElement *n, *tn;
s_assert(dtree != NULL);
lrb_assert(dtree != NULL);
RB_DLINK_FOREACH_SAFE(n, tn, dtree->head)
{
@ -456,7 +452,7 @@ void irc_dictionary_destroy(struct Dictionary *dtree,
}
/*
* irc_dictionary_foreach(struct Dictionary *dtree,
* rb_dictionary_foreach(struct Dictionary *dtree,
* void (*destroy_cb)(dictionary_elem_t *delem, void *privdata),
* void *privdata);
*
@ -473,13 +469,13 @@ void irc_dictionary_destroy(struct Dictionary *dtree,
* Side Effects:
* - on success, a dtree is iterated
*/
void irc_dictionary_foreach(struct Dictionary *dtree,
void rb_dictionary_foreach(struct Dictionary *dtree,
int (*foreach_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata)
{
struct DictionaryElement *n, *tn;
s_assert(dtree != NULL);
lrb_assert(dtree != NULL);
RB_DLINK_FOREACH_SAFE(n, tn, dtree->head)
{
@ -492,7 +488,7 @@ void irc_dictionary_foreach(struct Dictionary *dtree,
}
/*
* irc_dictionary_search(struct Dictionary *dtree,
* rb_dictionary_search(struct Dictionary *dtree,
* void (*destroy_cb)(struct DictionaryElement *delem, void *privdata),
* void *privdata);
*
@ -510,14 +506,14 @@ void irc_dictionary_foreach(struct Dictionary *dtree,
* Side Effects:
* - a dtree is iterated until the requested conditions are met
*/
void *irc_dictionary_search(struct Dictionary *dtree,
void *rb_dictionary_search(struct Dictionary *dtree,
void *(*foreach_cb)(struct DictionaryElement *delem, void *privdata),
void *privdata)
{
struct DictionaryElement *n, *tn;
void *ret = NULL;
s_assert(dtree != NULL);
lrb_assert(dtree != NULL);
RB_DLINK_FOREACH_SAFE(n, tn, dtree->head)
{
@ -535,7 +531,7 @@ void *irc_dictionary_search(struct Dictionary *dtree,
}
/*
* irc_dictionary_foreach_start(struct Dictionary *dtree,
* rb_dictionary_foreach_start(struct Dictionary *dtree,
* struct DictionaryIter *state);
*
* Initializes a static DTree iterator.
@ -550,11 +546,11 @@ void *irc_dictionary_search(struct Dictionary *dtree,
* Side Effects:
* - the static iterator, &state, is initialized.
*/
void irc_dictionary_foreach_start(struct Dictionary *dtree,
void rb_dictionary_foreach_start(struct Dictionary *dtree,
struct DictionaryIter *state)
{
s_assert(dtree != NULL);
s_assert(state != NULL);
lrb_assert(dtree != NULL);
lrb_assert(state != NULL);
state->cur = NULL;
state->next = NULL;
@ -568,11 +564,11 @@ void irc_dictionary_foreach_start(struct Dictionary *dtree,
/* make state->cur point to first item and state->next point to
* second item */
state->next = state->cur;
irc_dictionary_foreach_next(dtree, state);
rb_dictionary_foreach_next(dtree, state);
}
/*
* irc_dictionary_foreach_cur(struct Dictionary *dtree,
* rb_dictionary_foreach_cur(struct Dictionary *dtree,
* struct DictionaryIter *state);
*
* Returns the data from the current node being iterated by the
@ -588,17 +584,17 @@ void irc_dictionary_foreach_start(struct Dictionary *dtree,
* Side Effects:
* - none
*/
void *irc_dictionary_foreach_cur(struct Dictionary *dtree,
void *rb_dictionary_foreach_cur(struct Dictionary *dtree,
struct DictionaryIter *state)
{
s_assert(dtree != NULL);
s_assert(state != NULL);
lrb_assert(dtree != NULL);
lrb_assert(state != NULL);
return state->cur != NULL ? state->cur->data : NULL;
}
/*
* irc_dictionary_foreach_next(struct Dictionary *dtree,
* rb_dictionary_foreach_next(struct Dictionary *dtree,
* struct DictionaryIter *state);
*
* Advances a static DTree iterator.
@ -613,15 +609,15 @@ void *irc_dictionary_foreach_cur(struct Dictionary *dtree,
* Side Effects:
* - the static iterator, &state, is advanced to a new DTree node.
*/
void irc_dictionary_foreach_next(struct Dictionary *dtree,
void rb_dictionary_foreach_next(struct Dictionary *dtree,
struct DictionaryIter *state)
{
s_assert(dtree != NULL);
s_assert(state != NULL);
lrb_assert(dtree != NULL);
lrb_assert(state != NULL);
if (state->cur == NULL)
{
ilog(L_MAIN, "irc_dictionary_foreach_next(): called again after iteration finished on dtree<%p>", (void *)dtree);
rb_lib_log("rb_dictionary_foreach_next(): called again after iteration finished on dtree<%p>", (void *)dtree);
return;
}
@ -634,7 +630,7 @@ void irc_dictionary_foreach_next(struct Dictionary *dtree,
}
/*
* irc_dictionary_find(struct Dictionary *dtree, const void *key)
* rb_dictionary_find(struct Dictionary *dtree, const void *key)
*
* Looks up a DTree node by name.
*
@ -649,13 +645,13 @@ void irc_dictionary_foreach_next(struct Dictionary *dtree,
* Side Effects:
* - none
*/
struct DictionaryElement *irc_dictionary_find(struct Dictionary *dict, const void *key)
struct DictionaryElement *rb_dictionary_find(struct Dictionary *dict, const void *key)
{
s_assert(dict != NULL);
s_assert(key != NULL);
lrb_assert(dict != NULL);
lrb_assert(key != NULL);
/* retune for key, key will be the tree's root if it's available */
irc_dictionary_retune(dict, key);
rb_dictionary_retune(dict, key);
if (dict->root && !dict->compare_cb(key, dict->root->key))
return dict->root;
@ -664,7 +660,7 @@ struct DictionaryElement *irc_dictionary_find(struct Dictionary *dict, const voi
}
/*
* irc_dictionary_add(struct Dictionary *dtree, const void *key, void *data)
* rb_dictionary_add(struct Dictionary *dtree, const void *key, void *data)
*
* Creates a new DTree node and binds data to it.
*
@ -680,26 +676,26 @@ struct DictionaryElement *irc_dictionary_find(struct Dictionary *dict, const voi
* Side Effects:
* - data is inserted into the DTree.
*/
struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const void *key, void *data)
struct DictionaryElement *rb_dictionary_add(struct Dictionary *dict, const void *key, void *data)
{
struct DictionaryElement *delem;
s_assert(dict != NULL);
s_assert(key != NULL);
s_assert(data != NULL);
s_assert(irc_dictionary_find(dict, key) == NULL);
lrb_assert(dict != NULL);
lrb_assert(key != NULL);
lrb_assert(data != NULL);
lrb_assert(rb_dictionary_find(dict, key) == NULL);
delem = rb_malloc(sizeof(*delem));
delem->key = key;
delem->data = data;
irc_dictionary_link(dict, delem);
rb_dictionary_link(dict, delem);
return delem;
}
/*
* irc_dictionary_delete(struct Dictionary *dtree, const void *key)
* rb_dictionary_delete(struct Dictionary *dtree, const void *key)
*
* Deletes data from a dictionary tree.
*
@ -717,9 +713,9 @@ struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const void
* Notes:
* - the returned data needs to be mowgli_freed/released manually!
*/
void *irc_dictionary_delete(struct Dictionary *dtree, const void *key)
void *rb_dictionary_delete(struct Dictionary *dtree, const void *key)
{
struct DictionaryElement *delem = irc_dictionary_find(dtree, key);
struct DictionaryElement *delem = rb_dictionary_find(dtree, key);
void *data;
if (delem == NULL)
@ -727,14 +723,14 @@ void *irc_dictionary_delete(struct Dictionary *dtree, const void *key)
data = delem->data;
irc_dictionary_unlink_root(dtree);
rb_dictionary_unlink_root(dtree);
rb_free(delem);
return data;
}
/*
* irc_dictionary_retrieve(struct Dictionary *dtree, const void *key)
* rb_dictionary_retrieve(struct Dictionary *dtree, const void *key)
*
* Retrieves data from a dictionary.
*
@ -749,9 +745,9 @@ void *irc_dictionary_delete(struct Dictionary *dtree, const void *key)
* Side Effects:
* - none
*/
void *irc_dictionary_retrieve(struct Dictionary *dtree, const void *key)
void *rb_dictionary_retrieve(struct Dictionary *dtree, const void *key)
{
struct DictionaryElement *delem = irc_dictionary_find(dtree, key);
struct DictionaryElement *delem = rb_dictionary_find(dtree, key);
if (delem != NULL)
return delem->data;
@ -760,7 +756,7 @@ void *irc_dictionary_retrieve(struct Dictionary *dtree, const void *key)
}
/*
* irc_dictionary_size(struct Dictionary *dict)
* rb_dictionary_size(struct Dictionary *dict)
*
* Returns the size of a dictionary.
*
@ -773,9 +769,9 @@ void *irc_dictionary_retrieve(struct Dictionary *dtree, const void *key)
* Side Effects:
* - none
*/
unsigned int irc_dictionary_size(struct Dictionary *dict)
unsigned int rb_dictionary_size(struct Dictionary *dict)
{
s_assert(dict != NULL);
lrb_assert(dict != NULL);
return dict->count;
}
@ -797,7 +793,7 @@ stats_recurse(struct DictionaryElement *delem, int depth, int *pmaxdepth)
}
/*
* irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata)
* rb_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata)
*
* Returns the size of a dictionary.
*
@ -812,12 +808,12 @@ stats_recurse(struct DictionaryElement *delem, int depth, int *pmaxdepth)
* Side Effects:
* - callback called with stats text
*/
void irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata)
void rb_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata)
{
char str[256];
int sum, maxdepth;
s_assert(dict != NULL);
lrb_assert(dict != NULL);
if (dict->count)
{
@ -833,12 +829,12 @@ void irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line,
cb(str, privdata);
}
void irc_dictionary_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata)
void rb_dictionary_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata)
{
rb_dlink_node *ptr;
RB_DLINK_FOREACH(ptr, dictionary_list.head)
{
irc_dictionary_stats(ptr->data, cb, privdata);
rb_dictionary_stats(ptr->data, cb, privdata);
}
}

View file

@ -1,3 +1,9 @@
make_and_lookup
make_and_lookup_ip
rb_accept_tcp
rb_base64_decode
rb_base64_encode
rb_basename
rb_bh_alloc
rb_bh_create
rb_bh_destroy
@ -5,57 +11,35 @@ rb_bh_free
rb_bh_total_usage
rb_bh_usage
rb_bh_usage_all
rb_init_bh
rb_accept_tcp
rb_checktimeouts
rb_clear_patricia
rb_close
rb_connect_sockaddr
rb_connect_tcp
rb_connect_tcp_ssl
rb_count_rb_linebuf_memory
rb_crypt
rb_ctime
rb_current_time
rb_current_time_tv
rb_date
rb_destroy_patricia
rb_dictionary_add
rb_dictionary_create
rb_dictionary_delete
rb_dictionary_destroy
rb_dictionary_find
rb_dictionary_foreach_cur
rb_dictionary_foreach_next
rb_dictionary_foreach_start
rb_dictionary_retrieve
rb_dictionary_size
rb_dictionary_stats
rb_dictionary_stats_walk
rb_dirname
rb_dump_events
rb_dump_fd
rb_errstr
rb_fd_ssl
rb_fdlist_init
rb_get_fd
rb_get_fde
rb_get_iotype
rb_get_random
rb_get_sockerr
rb_get_ssl_certfp
rb_get_ssl_strerror
rb_get_type
rb_getmaxconnect
rb_ignore_errno
rb_inet_ntop
rb_inet_ntop_sock
rb_inet_pton
rb_inet_pton_sock
rb_init_netio
rb_init_prng
rb_listen
rb_note
rb_open
rb_pipe
rb_read
rb_recv_fd_buf
rb_select
rb_send_fd_buf
rb_set_buffers
rb_set_nb
rb_set_type
rb_setselect
rb_settimeout
rb_setup_fd
rb_setup_ssl_server
rb_socket
rb_socketpair
rb_ssl_listen
rb_ssl_start_accepted
rb_ssl_start_connected
rb_write
rb_writev
rb_crypt
rb_dump_events
rb_event_add
rb_event_addish
rb_event_addonce
@ -65,7 +49,21 @@ rb_event_init
rb_event_next
rb_event_run
rb_event_update
rb_run_event
rb_fdlist_init
rb_fd_ssl
rb_free_rawbuffer
rb_free_rb_dlink_node
rb_get_fd
rb_get_fde
rb_get_iotype
rb_getmaxconnect
rb_getpid
rb_get_random
rb_get_sockerr
rb_get_ssl_certfp
rb_get_ssl_strerror
rb_gettimeofday
rb_get_type
rb_helper_child
rb_helper_close
rb_helper_loop
@ -75,7 +73,24 @@ rb_helper_run
rb_helper_start
rb_helper_write
rb_helper_write_queue
rb_count_rb_linebuf_memory
rb_ignore_errno
rb_inet_ntop
rb_inet_ntop_sock
rb_inet_pton
rb_inet_pton_sock
rb_init_bh
rb_init_netio
rb_init_patricia
rb_init_prng
rb_init_rawbuffers
rb_init_rb_dlink_nodes
rb_kill
rb_lib_die
rb_lib_init
rb_lib_log
rb_lib_loop
rb_lib_restart
rb_lib_version
rb_linebuf_attach
rb_linebuf_donebuf
rb_linebuf_flush
@ -87,66 +102,80 @@ rb_linebuf_put
rb_linebuf_putbuf
rb_linebuf_putmsg
rb_linebuf_putprefix
make_and_lookup
make_and_lookup_ip
rb_clear_patricia
rb_destroy_patricia
rb_init_patricia
rb_listen
rb_make_rb_dlink_node
rb_match_exact_string
rb_match_ip
rb_match_ip_exact
rb_match_string
rb_new_patricia
rb_new_rawbuffer
rb_note
rb_open
rb_outofmemory
rb_patricia_lookup
rb_patricia_process
rb_patricia_remove
rb_patricia_search_best
rb_patricia_search_best2
rb_patricia_search_exact
rb_base64_decode
rb_base64_encode
rb_ctime
rb_current_time
rb_current_time_tv
rb_date
rb_lib_die
rb_lib_init
rb_lib_log
rb_lib_loop
rb_lib_restart
rb_lib_version
rb_set_time
rb_strtok_r
rb_free_rawbuffer
rb_init_rawbuffers
rb_new_rawbuffer
rb_pipe
rb_radixtree_add
rb_radixtree_create
rb_radixtree_delete
rb_radixtree_elem_add
rb_radixtree_elem_delete
rb_radixtree_elem_find
rb_radixtree_elem_get_data
rb_radixtree_elem_get_key
rb_radixtree_elem_set_data
rb_radixtree_foreach_cur
rb_radixtree_foreach_next
rb_radixtree_foreach_start
rb_radixtree_foreach_start_from
rb_radixtree_retrieve
rb_radixtree_size
rb_radixtree_stats
rb_radixtree_stats_walk
rb_rawbuf_append
rb_rawbuf_flush
rb_rawbuf_get
rb_rawbuf_length
rb_outofmemory
rb_read
rb_recv_fd_buf
rb_run_event
rb_select
rb_send_fd_buf
rb_set_buffers
rb_setenv
rb_set_nb
rb_setselect
rb_set_time
rb_settimeout
rb_set_type
rb_setup_fd
rb_setup_ssl_server
rb_sleep
rb_snprintf_append
rb_free_rb_dlink_node
rb_init_rb_dlink_nodes
rb_make_rb_dlink_node
rb_socket
rb_socketpair
rb_spawn_process
rb_ssl_clear_handshake_count
rb_ssl_get_cipher
rb_ssl_handshake_count
rb_ssl_listen
rb_ssl_start_accepted
rb_ssl_start_connected
rb_strerror
rb_string_to_array
rb_strlcat
rb_strlcpy
rb_strnlen
rb_gettimeofday
rb_sleep
rb_spawn_process
rb_strtok_r
rb_supports_ssl
rb_ssl_handshake_count
rb_ssl_clear_handshake_count
rb_strerror
rb_kill
rb_setenv
rb_getpid
rb_waitpid
rb_basename
rb_dirname
rb_ssl_get_cipher
rb_write
rb_writev
rb_zstring_alloc
rb_zstring_append_from_c
rb_zstring_append_from_zstring

View file

@ -1,6 +1,6 @@
/*
* charybdis: an advanced ircd.
* irc_radixtree.c: Dictionary-based information storage.
* rb_radixtree.c: Dictionary-based information storage.
*
* Copyright (c) 2007-2016 William Pitcock <nenolod -at- dereferenced.org>
* Copyright (c) 2007-2016 Jilles Tjoelker <jilles -at- stack.nl>
@ -32,10 +32,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdinc.h"
#include "s_assert.h"
#include "match.h"
#include "irc_radixtree.h"
#include <librb_config.h>
#include <rb_lib.h>
#include <rb_radixtree.h>
rb_dlink_list radixtree_list = {NULL, NULL, 0};
@ -53,12 +52,12 @@ rb_dlink_list radixtree_list = {NULL, NULL, 0};
* -- jilles
*/
union irc_radixtree_elem;
union rb_radixtree_elem;
struct irc_radixtree
struct rb_radixtree
{
void (*canonize_cb)(char *key);
union irc_radixtree_elem *root;
union rb_radixtree_elem *root;
unsigned int count;
char *id;
@ -69,19 +68,19 @@ struct irc_radixtree
#define POINTERS_PER_NODE 16
#define NIBBLE_VAL(key, nibnum) (((key)[(nibnum) / 2] >> ((nibnum) & 1 ? 0 : 4)) & 0xF)
struct irc_radixtree_node
struct rb_radixtree_node
{
/* nibble to test (nibble NUM%2 of byte NUM/2) */
int nibnum;
/* branches of the tree */
union irc_radixtree_elem *down[POINTERS_PER_NODE];
union irc_radixtree_elem *parent;
union rb_radixtree_elem *down[POINTERS_PER_NODE];
union rb_radixtree_elem *parent;
char parent_val;
};
struct irc_radixtree_leaf
struct rb_radixtree_leaf
{
/* -1 to indicate this is a leaf, not a node */
int nibnum;
@ -91,17 +90,17 @@ struct irc_radixtree_leaf
/* key (canonized copy) */
char *key;
union irc_radixtree_elem *parent;
union rb_radixtree_elem *parent;
char parent_val;
};
union irc_radixtree_elem
union rb_radixtree_elem
{
int nibnum;
struct irc_radixtree_node node;
struct rb_radixtree_node node;
struct irc_radixtree_leaf leaf;
struct rb_radixtree_leaf leaf;
};
#define IS_LEAF(elem) ((elem)->nibnum == -1)
@ -124,8 +123,8 @@ union irc_radixtree_elem
* Side Effects:
* - none
*/
static union irc_radixtree_elem *
first_leaf(union irc_radixtree_elem *delem)
static union rb_radixtree_elem *
first_leaf(union rb_radixtree_elem *delem)
{
int val;
@ -143,7 +142,7 @@ first_leaf(union irc_radixtree_elem *delem)
}
/*
* irc_radixtree_create_named(const char *name,
* rb_radixtree_create_named(const char *name,
* void (*canonize_cb)(char *key))
*
* Dictionary object factory.
@ -161,10 +160,10 @@ first_leaf(union irc_radixtree_elem *delem)
* - if services runs out of memory and cannot allocate the object,
* the program will abort.
*/
struct irc_radixtree *
irc_radixtree_create(const char *name, void (*canonize_cb)(char *key))
struct rb_radixtree *
rb_radixtree_create(const char *name, void (*canonize_cb)(char *key))
{
struct irc_radixtree *dtree = (struct irc_radixtree *) rb_malloc(sizeof(struct irc_radixtree));
struct rb_radixtree *dtree = (struct rb_radixtree *) rb_malloc(sizeof(struct rb_radixtree));
dtree->canonize_cb = canonize_cb;
dtree->id = rb_strdup(name);
@ -176,7 +175,7 @@ irc_radixtree_create(const char *name, void (*canonize_cb)(char *key))
}
/*
* irc_radixtree_destroy(struct irc_radixtree *dtree,
* rb_radixtree_destroy(struct rb_radixtree *dtree,
* void (*destroy_cb)(const char *key, void *data, void *privdata),
* void *privdata);
*
@ -198,16 +197,16 @@ irc_radixtree_create(const char *name, void (*canonize_cb)(char *key))
* DTree will not be destroyed.
*/
void
irc_radixtree_destroy(struct irc_radixtree *dtree, void (*destroy_cb)(const char *key, void *data, void *privdata), void *privdata)
rb_radixtree_destroy(struct rb_radixtree *dtree, void (*destroy_cb)(const char *key, void *data, void *privdata), void *privdata)
{
struct irc_radixtree_iteration_state state;
union irc_radixtree_elem *delem;
struct rb_radixtree_iteration_state state;
union rb_radixtree_elem *delem;
void *entry;
s_assert(dtree != NULL);
lrb_assert(dtree != NULL);
IRC_RADIXTREE_FOREACH(entry, &state, dtree)
RB_RADIXTREE_FOREACH(entry, &state, dtree)
{
delem = STATE_CUR(&state);
@ -215,7 +214,7 @@ irc_radixtree_destroy(struct irc_radixtree *dtree, void (*destroy_cb)(const char
(*destroy_cb)(delem->leaf.key, delem->leaf.data,
privdata);
irc_radixtree_delete(dtree, delem->leaf.key);
rb_radixtree_delete(dtree, delem->leaf.key);
}
rb_dlinkDelete(&dtree->node, &radixtree_list);
@ -224,7 +223,7 @@ irc_radixtree_destroy(struct irc_radixtree *dtree, void (*destroy_cb)(const char
}
/*
* irc_radixtree_foreach(struct irc_radixtree *dtree,
* rb_radixtree_foreach(struct rb_radixtree *dtree,
* int (*foreach_cb)(const char *key, void *data, void *privdata),
* void *privdata);
*
@ -242,13 +241,13 @@ irc_radixtree_destroy(struct irc_radixtree *dtree, void (*destroy_cb)(const char
* - on success, a dtree is iterated
*/
void
irc_radixtree_foreach(struct irc_radixtree *dtree, int (*foreach_cb)(const char *key, void *data, void *privdata), void *privdata)
rb_radixtree_foreach(struct rb_radixtree *dtree, int (*foreach_cb)(const char *key, void *data, void *privdata), void *privdata)
{
union irc_radixtree_elem *delem, *next;
union rb_radixtree_elem *delem, *next;
int val;
s_assert(dtree != NULL);
lrb_assert(dtree != NULL);
delem = dtree->root;
@ -300,7 +299,7 @@ irc_radixtree_foreach(struct irc_radixtree *dtree, int (*foreach_cb)(const char
}
/*
* irc_radixtree_search(struct irc_radixtree *dtree,
* rb_radixtree_search(struct rb_radixtree *dtree,
* void *(*foreach_cb)(const char *key, void *data, void *privdata),
* void *privdata);
*
@ -319,14 +318,14 @@ irc_radixtree_foreach(struct irc_radixtree *dtree, int (*foreach_cb)(const char
* - a dtree is iterated until the requested conditions are met
*/
void *
irc_radixtree_search(struct irc_radixtree *dtree, void *(*foreach_cb)(const char *key, void *data, void *privdata), void *privdata)
rb_radixtree_search(struct rb_radixtree *dtree, void *(*foreach_cb)(const char *key, void *data, void *privdata), void *privdata)
{
union irc_radixtree_elem *delem, *next;
union rb_radixtree_elem *delem, *next;
int val;
void *ret = NULL;
s_assert(dtree != NULL);
lrb_assert(dtree != NULL);
delem = dtree->root;
@ -383,8 +382,8 @@ irc_radixtree_search(struct irc_radixtree *dtree, void *(*foreach_cb)(const char
}
/*
* irc_radixtree_foreach_start(struct irc_radixtree *dtree,
* struct irc_radixtree_iteration_state *state);
* rb_radixtree_foreach_start(struct rb_radixtree *dtree,
* struct rb_radixtree_iteration_state *state);
*
* Initializes a static DTree iterator.
*
@ -399,12 +398,12 @@ irc_radixtree_search(struct irc_radixtree *dtree, void *(*foreach_cb)(const char
* - the static iterator, &state, is initialized.
*/
void
irc_radixtree_foreach_start(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state)
rb_radixtree_foreach_start(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state)
{
if (dtree == NULL)
return;
s_assert(state != NULL);
lrb_assert(state != NULL);
if (dtree->root != NULL)
STATE_NEXT(state) = first_leaf(dtree->root);
@ -418,12 +417,12 @@ irc_radixtree_foreach_start(struct irc_radixtree *dtree, struct irc_radixtree_it
/* make STATE_CUR point to first item and STATE_NEXT point to
* second item */
irc_radixtree_foreach_next(dtree, state);
rb_radixtree_foreach_next(dtree, state);
}
/*
* irc_radixtree_foreach_cur(struct irc_radixtree *dtree,
* struct irc_radixtree_iteration_state *state);
* rb_radixtree_foreach_cur(struct rb_radixtree *dtree,
* struct rb_radixtree_iteration_state *state);
*
* Returns the data from the current node being iterated by the
* static iterator.
@ -439,20 +438,20 @@ irc_radixtree_foreach_start(struct irc_radixtree *dtree, struct irc_radixtree_it
* - none
*/
void *
irc_radixtree_foreach_cur(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state)
rb_radixtree_foreach_cur(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state)
{
if (dtree == NULL)
return NULL;
s_assert(state != NULL);
lrb_assert(state != NULL);
return STATE_CUR(state) != NULL ?
((struct irc_radixtree_leaf *) STATE_CUR(state))->data : NULL;
((struct rb_radixtree_leaf *) STATE_CUR(state))->data : NULL;
}
/*
* irc_radixtree_foreach_next(struct irc_radixtree *dtree,
* struct irc_radixtree_iteration_state *state);
* rb_radixtree_foreach_next(struct rb_radixtree *dtree,
* struct rb_radixtree_iteration_state *state);
*
* Advances a static DTree iterator.
*
@ -467,18 +466,18 @@ irc_radixtree_foreach_cur(struct irc_radixtree *dtree, struct irc_radixtree_iter
* - the static iterator, &state, is advanced to a new DTree node.
*/
void
irc_radixtree_foreach_next(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state)
rb_radixtree_foreach_next(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state)
{
struct irc_radixtree_leaf *leaf;
struct rb_radixtree_leaf *leaf;
union irc_radixtree_elem *delem, *next;
union rb_radixtree_elem *delem, *next;
int val;
if (dtree == NULL)
return;
s_assert(state != NULL);
lrb_assert(state != NULL);
if (STATE_CUR(state) == NULL)
return;
@ -538,7 +537,7 @@ irc_radixtree_foreach_next(struct irc_radixtree *dtree, struct irc_radixtree_ite
}
/*
* irc_radixtree_elem_find(struct irc_radixtree *dtree, const char *key)
* rb_radixtree_elem_find(struct rb_radixtree *dtree, const char *key)
*
* Looks up a DTree node by name.
*
@ -554,19 +553,19 @@ irc_radixtree_foreach_next(struct irc_radixtree *dtree, struct irc_radixtree_ite
* Side Effects:
* - none
*/
struct irc_radixtree_leaf *
irc_radixtree_elem_find(struct irc_radixtree *dict, const char *key, int fuzzy)
struct rb_radixtree_leaf *
rb_radixtree_elem_find(struct rb_radixtree *dict, const char *key, int fuzzy)
{
char ckey_store[256];
char *ckey_buf = NULL;
const char *ckey;
union irc_radixtree_elem *delem;
union rb_radixtree_elem *delem;
int val, keylen;
s_assert(dict != NULL);
s_assert(key != NULL);
lrb_assert(dict != NULL);
lrb_assert(key != NULL);
keylen = strlen(key);
@ -613,9 +612,9 @@ irc_radixtree_elem_find(struct irc_radixtree *dict, const char *key, int fuzzy)
}
/*
* irc_radixtree_foreach_start_from(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state, const char *key)
* rb_radixtree_foreach_start_from(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state, const char *key)
*
* Starts iteration from a specified key, by wrapping irc_radixtree_elem_find().
* Starts iteration from a specified key, by wrapping rb_radixtree_elem_find().
*
* Inputs:
* - patricia tree object
@ -629,26 +628,26 @@ irc_radixtree_elem_find(struct irc_radixtree *dict, const char *key, int fuzzy)
* - the iterator's state is initialized at a specific point
*/
void
irc_radixtree_foreach_start_from(struct irc_radixtree *dtree, struct irc_radixtree_iteration_state *state, const char *key)
rb_radixtree_foreach_start_from(struct rb_radixtree *dtree, struct rb_radixtree_iteration_state *state, const char *key)
{
s_assert(dtree != NULL);
s_assert(state != NULL);
lrb_assert(dtree != NULL);
lrb_assert(state != NULL);
if (key != NULL)
{
STATE_CUR(state) = NULL;
STATE_NEXT(state) = irc_radixtree_elem_find(dtree, key, 1);
STATE_NEXT(state) = rb_radixtree_elem_find(dtree, key, 1);
/* make STATE_CUR point to selected item and STATE_NEXT point to
* next item in the tree */
irc_radixtree_foreach_next(dtree, state);
rb_radixtree_foreach_next(dtree, state);
}
else
irc_radixtree_foreach_start(dtree, state);
rb_radixtree_foreach_start(dtree, state);
}
/*
* irc_radixtree_add(struct irc_radixtree *dtree, const char *key, void *data)
* rb_radixtree_add(struct rb_radixtree *dtree, const char *key, void *data)
*
* Creates a new DTree node and binds data to it.
*
@ -664,21 +663,21 @@ irc_radixtree_foreach_start_from(struct irc_radixtree *dtree, struct irc_radixtr
* Side Effects:
* - data is inserted into the DTree.
*/
struct irc_radixtree_leaf *
irc_radixtree_elem_add(struct irc_radixtree *dict, const char *key, void *data)
struct rb_radixtree_leaf *
rb_radixtree_elem_add(struct rb_radixtree *dict, const char *key, void *data)
{
char *ckey;
union irc_radixtree_elem *delem, *prev, *newnode;
union rb_radixtree_elem *delem, *prev, *newnode;
union irc_radixtree_elem **place1;
union rb_radixtree_elem **place1;
int val, keylen;
int i, j;
s_assert(dict != NULL);
s_assert(key != NULL);
s_assert(data != NULL);
lrb_assert(dict != NULL);
lrb_assert(key != NULL);
lrb_assert(data != NULL);
keylen = strlen(key);
ckey = rb_strdup(key);
@ -718,11 +717,11 @@ irc_radixtree_elem_add(struct irc_radixtree *dict, const char *key, void *data)
if (delem == NULL)
{
s_assert(prev == NULL);
s_assert(dict->count == 0);
lrb_assert(prev == NULL);
lrb_assert(dict->count == 0);
place1 = &dict->root;
*place1 = rb_malloc(sizeof(struct irc_radixtree_leaf));
s_assert(*place1 != NULL);
*place1 = rb_malloc(sizeof(struct rb_radixtree_leaf));
lrb_assert(*place1 != NULL);
(*place1)->nibnum = -1;
(*place1)->leaf.data = data;
(*place1)->leaf.key = ckey;
@ -746,8 +745,8 @@ irc_radixtree_elem_add(struct irc_radixtree *dict, const char *key, void *data)
if ((prev == NULL) || (prev->nibnum < i))
{
/* Insert new node below prev */
newnode = rb_malloc(sizeof(struct irc_radixtree_node));
s_assert(newnode != NULL);
newnode = rb_malloc(sizeof(struct rb_radixtree_node));
lrb_assert(newnode != NULL);
newnode->nibnum = i;
newnode->node.parent = prev;
newnode->node.parent_val = val;
@ -766,7 +765,7 @@ irc_radixtree_elem_add(struct irc_radixtree *dict, const char *key, void *data)
}
else
{
s_assert(dict->root->nibnum > i);
lrb_assert(dict->root->nibnum > i);
dict->root->node.parent = newnode;
dict->root->node.parent_val = NIBBLE_VAL(delem->leaf.key, i);
}
@ -794,15 +793,15 @@ irc_radixtree_elem_add(struct irc_radixtree *dict, const char *key, void *data)
else
{
/* This nibble is already checked. */
s_assert(prev->nibnum == i);
lrb_assert(prev->nibnum == i);
newnode = prev;
}
val = NIBBLE_VAL(ckey, i);
place1 = &newnode->node.down[val];
s_assert(*place1 == NULL);
*place1 = rb_malloc(sizeof(struct irc_radixtree_leaf));
s_assert(*place1 != NULL);
lrb_assert(*place1 == NULL);
*place1 = rb_malloc(sizeof(struct rb_radixtree_leaf));
lrb_assert(*place1 != NULL);
(*place1)->nibnum = -1;
(*place1)->leaf.data = data;
(*place1)->leaf.key = ckey;
@ -813,13 +812,13 @@ irc_radixtree_elem_add(struct irc_radixtree *dict, const char *key, void *data)
}
int
irc_radixtree_add(struct irc_radixtree *dict, const char *key, void *data)
rb_radixtree_add(struct rb_radixtree *dict, const char *key, void *data)
{
return (irc_radixtree_elem_add(dict, key, data) != NULL);
return (rb_radixtree_elem_add(dict, key, data) != NULL);
}
/*
* irc_radixtree_delete(struct irc_radixtree *dtree, const char *key)
* rb_radixtree_delete(struct rb_radixtree *dtree, const char *key)
*
* Deletes data from a patricia tree.
*
@ -838,32 +837,32 @@ irc_radixtree_add(struct irc_radixtree *dict, const char *key, void *data)
* - the returned data needs to be rb_freed/released manually!
*/
void *
irc_radixtree_delete(struct irc_radixtree *dict, const char *key)
rb_radixtree_delete(struct rb_radixtree *dict, const char *key)
{
void *data;
struct irc_radixtree_leaf *leaf;
struct rb_radixtree_leaf *leaf;
leaf = irc_radixtree_elem_find(dict, key, 0);
leaf = rb_radixtree_elem_find(dict, key, 0);
if (leaf == NULL)
return NULL;
data = leaf->data;
irc_radixtree_elem_delete(dict, leaf);
rb_radixtree_elem_delete(dict, leaf);
return data;
}
void
irc_radixtree_elem_delete(struct irc_radixtree *dict, struct irc_radixtree_leaf *leaf)
rb_radixtree_elem_delete(struct rb_radixtree *dict, struct rb_radixtree_leaf *leaf)
{
union irc_radixtree_elem *delem, *prev, *next;
union rb_radixtree_elem *delem, *prev, *next;
int val, i, used;
s_assert(dict != NULL);
s_assert(leaf != NULL);
lrb_assert(dict != NULL);
lrb_assert(leaf != NULL);
delem = (union irc_radixtree_elem *) leaf;
delem = (union rb_radixtree_elem *) leaf;
val = delem->leaf.parent_val;
prev = delem->leaf.parent;
@ -884,7 +883,7 @@ irc_radixtree_elem_delete(struct irc_radixtree *dict, struct irc_radixtree_leaf
if (delem->node.down[i] != NULL)
used = used == -1 ? i : -2;
s_assert(used == -2 || used >= 0);
lrb_assert(used == -2 || used >= 0);
if (used >= 0)
{
@ -919,13 +918,13 @@ irc_radixtree_elem_delete(struct irc_radixtree *dict, struct irc_radixtree_leaf
if (dict->count == 0)
{
s_assert(dict->root == NULL);
lrb_assert(dict->root == NULL);
dict->root = NULL;
}
}
/*
* irc_radixtree_retrieve(struct irc_radixtree *dtree, const char *key)
* rb_radixtree_retrieve(struct rb_radixtree *dtree, const char *key)
*
* Retrieves data from a patricia.
*
@ -941,9 +940,9 @@ irc_radixtree_elem_delete(struct irc_radixtree *dict, struct irc_radixtree_leaf
* - none
*/
void *
irc_radixtree_retrieve(struct irc_radixtree *dtree, const char *key)
rb_radixtree_retrieve(struct rb_radixtree *dtree, const char *key)
{
struct irc_radixtree_leaf *delem = irc_radixtree_elem_find(dtree, key, 0);
struct rb_radixtree_leaf *delem = rb_radixtree_elem_find(dtree, key, 0);
if (delem != NULL)
return delem->data;
@ -952,31 +951,31 @@ irc_radixtree_retrieve(struct irc_radixtree *dtree, const char *key)
}
const char *
irc_radixtree_elem_get_key(struct irc_radixtree_leaf *leaf)
rb_radixtree_elem_get_key(struct rb_radixtree_leaf *leaf)
{
s_assert(leaf != NULL);
lrb_assert(leaf != NULL);
return leaf->key;
}
void
irc_radixtree_elem_set_data(struct irc_radixtree_leaf *leaf, void *data)
rb_radixtree_elem_set_data(struct rb_radixtree_leaf *leaf, void *data)
{
s_assert(leaf != NULL);
lrb_assert(leaf != NULL);
leaf->data = data;
}
void *
irc_radixtree_elem_get_data(struct irc_radixtree_leaf *leaf)
rb_radixtree_elem_get_data(struct rb_radixtree_leaf *leaf)
{
s_assert(leaf != NULL);
lrb_assert(leaf != NULL);
return leaf->data;
}
/*
* irc_radixtree_size(struct irc_radixtree *dict)
* rb_radixtree_size(struct rb_radixtree *dict)
*
* Returns the size of a patricia.
*
@ -990,9 +989,9 @@ irc_radixtree_elem_get_data(struct irc_radixtree_leaf *leaf)
* - none
*/
unsigned int
irc_radixtree_size(struct irc_radixtree *dict)
rb_radixtree_size(struct rb_radixtree *dict)
{
s_assert(dict != NULL);
lrb_assert(dict != NULL);
return dict->count;
}
@ -1000,11 +999,11 @@ irc_radixtree_size(struct irc_radixtree *dict)
/* returns the sum of the depths of the subtree rooted in delem at depth depth */
/* there is no need for this to be recursive, but it is easier... */
static int
stats_recurse(union irc_radixtree_elem *delem, int depth, int *pmaxdepth)
stats_recurse(union rb_radixtree_elem *delem, int depth, int *pmaxdepth)
{
int result = 0;
int val;
union irc_radixtree_elem *next;
union rb_radixtree_elem *next;
if (depth > *pmaxdepth)
*pmaxdepth = depth;
@ -1012,10 +1011,10 @@ stats_recurse(union irc_radixtree_elem *delem, int depth, int *pmaxdepth)
if (depth == 0)
{
if (IS_LEAF(delem))
s_assert(delem->leaf.parent == NULL);
lrb_assert(delem->leaf.parent == NULL);
else
s_assert(delem->node.parent == NULL);
lrb_assert(delem->node.parent == NULL);
}
if (IS_LEAF(delem))
@ -1032,14 +1031,14 @@ stats_recurse(union irc_radixtree_elem *delem, int depth, int *pmaxdepth)
if (IS_LEAF(next))
{
s_assert(next->leaf.parent == delem);
s_assert(next->leaf.parent_val == val);
lrb_assert(next->leaf.parent == delem);
lrb_assert(next->leaf.parent_val == val);
}
else
{
s_assert(next->node.parent == delem);
s_assert(next->node.parent_val == val);
s_assert(next->node.nibnum > delem->node.nibnum);
lrb_assert(next->node.parent == delem);
lrb_assert(next->node.parent_val == val);
lrb_assert(next->node.nibnum > delem->node.nibnum);
}
}
@ -1047,7 +1046,7 @@ stats_recurse(union irc_radixtree_elem *delem, int depth, int *pmaxdepth)
}
/*
* irc_radixtree_stats(struct irc_radixtree *dict, void (*cb)(const char *line, void *privdata), void *privdata)
* rb_radixtree_stats(struct rb_radixtree *dict, void (*cb)(const char *line, void *privdata), void *privdata)
*
* Returns the size of a patricia.
*
@ -1063,12 +1062,12 @@ stats_recurse(union irc_radixtree_elem *delem, int depth, int *pmaxdepth)
* - callback called with stats text
*/
void
irc_radixtree_stats(struct irc_radixtree *dict, void (*cb)(const char *line, void *privdata), void *privdata)
rb_radixtree_stats(struct rb_radixtree *dict, void (*cb)(const char *line, void *privdata), void *privdata)
{
char str[256];
int sum, maxdepth;
s_assert(dict != NULL);
lrb_assert(dict != NULL);
maxdepth = 0;
if (dict->count > 0)
@ -1086,33 +1085,13 @@ irc_radixtree_stats(struct irc_radixtree *dict, void (*cb)(const char *line, voi
}
void
irc_radixtree_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata)
rb_radixtree_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata)
{
rb_dlink_node *ptr;
RB_DLINK_FOREACH(ptr, radixtree_list.head)
{
irc_radixtree_stats(ptr->data, cb, privdata);
rb_radixtree_stats(ptr->data, cb, privdata);
}
}
void irc_radixtree_irccasecanon(char *str)
{
while (*str)
{
*str = ToUpper(*str);
str++;
}
return;
}
void irc_radixtree_strcasecanon(char *str)
{
while (*str)
{
*str = toupper((unsigned char)*str);
str++;
}
return;
}

View file

@ -146,7 +146,7 @@ mr_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
return 0;
}
if(irc_dictionary_find(nd_dict, nick))
if(rb_dictionary_find(nd_dict, nick))
{
sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick);
@ -198,7 +198,7 @@ m_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
return 0;
}
if(irc_dictionary_find(nd_dict, nick))
if(rb_dictionary_find(nd_dict, nick))
{
sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick);
@ -754,7 +754,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 = irc_dictionary_retrieve(nd_dict, nick)))
if((nd = rb_dictionary_retrieve(nd_dict, nick)))
free_nd_entry(nd);
strcpy(source_p->name, nick);
@ -1076,7 +1076,7 @@ register_client(struct Client *client_p, struct Client *server,
}
/* remove any nd entries for this nick */
if((nd = irc_dictionary_retrieve(nd_dict, nick)))
if((nd = rb_dictionary_retrieve(nd_dict, nick)))
free_nd_entry(nd);
add_to_client_hash(nick, source_p);

View file

@ -34,7 +34,7 @@
#include "modules.h"
#include "hash.h"
#include "cache.h"
#include "irc_dictionary.h"
#include "rb_dictionary.h"
static int m_help(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
static int mo_help(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
@ -97,7 +97,7 @@ dohelp(struct Client *source_p, int flags, const char *topic)
if(EmptyString(topic))
topic = ntopic;
hptr = irc_dictionary_retrieve(flags & HELP_OPER ? help_dict_oper : help_dict_user, topic);
hptr = rb_dictionary_retrieve(flags & HELP_OPER ? help_dict_oper : help_dict_user, topic);
if(hptr == NULL || !(hptr->flags & flags))
{

View file

@ -49,7 +49,7 @@
#include "inline/stringops.h"
#include "s_assert.h"
#include "logger.h"
#include "irc_radixtree.h"
#include "rb_radixtree.h"
static rb_dlink_list safelisting_clients = { NULL, NULL, 0 };
@ -472,9 +472,9 @@ static void safelist_one_channel(struct Client *source_p, struct Channel *chptr,
static void safelist_iterate_client(struct Client *source_p)
{
struct Channel *chptr;
struct irc_radixtree_iteration_state iter;
struct rb_radixtree_iteration_state iter;
IRC_RADIXTREE_FOREACH_FROM(chptr, &iter, channel_tree, source_p->localClient->safelist_data->chname)
RB_RADIXTREE_FOREACH_FROM(chptr, &iter, channel_tree, source_p->localClient->safelist_data->chname)
{
if (safelist_sendq_exceeded(source_p->from) == YES)
{

View file

@ -41,7 +41,7 @@
#include "reject.h"
#include "hash.h"
#include "cache.h"
#include "irc_radixtree.h"
#include "rb_radixtree.h"
#include "sslproc.h"
static int mo_rehash(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
@ -194,7 +194,7 @@ static void
rehash_tresvs(struct Client *source_p)
{
struct ConfItem *aconf;
struct irc_radixtree_iteration_state iter;
struct rb_radixtree_iteration_state iter;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
int i;
@ -204,12 +204,12 @@ rehash_tresvs(struct Client *source_p)
if (!MyConnect(source_p))
remote_rehash_oper_p = source_p;
IRC_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
RB_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
{
if(!aconf->hold || aconf->lifetime)
continue;
irc_radixtree_delete(resv_tree, aconf->host);
rb_radixtree_delete(resv_tree, aconf->host);
free_conf(aconf);
}

View file

@ -280,7 +280,7 @@ me_nickdelay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *so
duration = atoi(parv[1]);
if (duration <= 0)
{
nd = irc_dictionary_retrieve(nd_dict, parv[2]);
nd = rb_dictionary_retrieve(nd_dict, parv[2]);
if (nd != NULL)
free_nd_entry(nd);
}
@ -289,7 +289,7 @@ me_nickdelay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *so
if (duration > 86400)
duration = 86400;
add_nd_entry(parv[2]);
nd = irc_dictionary_retrieve(nd_dict, parv[2]);
nd = rb_dictionary_retrieve(nd_dict, parv[2]);
if (nd != NULL)
nd->expire = rb_current_time() + duration;
}

View file

@ -46,7 +46,7 @@
#include "hash.h"
#include "reject.h"
#include "whowas.h"
#include "irc_radixtree.h"
#include "rb_radixtree.h"
#include "sslproc.h"
static int m_stats (struct MsgBuf *, struct Client *, struct Client *, int, const char **);
@ -292,8 +292,8 @@ stats_hash(struct Client *source_p)
sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
"NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
irc_dictionary_stats_walk(stats_hash_cb, source_p);
irc_radixtree_stats_walk(stats_hash_cb, source_p);
rb_dictionary_stats_walk(stats_hash_cb, source_p);
rb_radixtree_stats_walk(stats_hash_cb, source_p);
}
static void
@ -856,7 +856,7 @@ static void
stats_tresv(struct Client *source_p)
{
struct ConfItem *aconf;
struct irc_radixtree_iteration_state state;
struct rb_radixtree_iteration_state state;
rb_dlink_node *ptr;
int i;
@ -869,7 +869,7 @@ stats_tresv(struct Client *source_p)
'q', aconf->port, aconf->host, aconf->passwd);
}
IRC_RADIXTREE_FOREACH(aconf, &state, resv_tree)
RB_RADIXTREE_FOREACH(aconf, &state, resv_tree)
{
if(aconf->hold)
sendto_one_numeric(source_p, RPL_STATSQLINE,
@ -883,7 +883,7 @@ static void
stats_resv(struct Client *source_p)
{
struct ConfItem *aconf;
struct irc_radixtree_iteration_state state;
struct rb_radixtree_iteration_state state;
rb_dlink_node *ptr;
int i;
@ -896,7 +896,7 @@ stats_resv(struct Client *source_p)
'Q', aconf->port, aconf->host, aconf->passwd);
}
IRC_RADIXTREE_FOREACH(aconf, &state, resv_tree)
RB_RADIXTREE_FOREACH(aconf, &state, resv_tree)
{
if(!aconf->hold)
sendto_one_numeric(source_p, RPL_STATSQLINE,