X-Git-Url: https://jfr.im/git/solanum.git/blobdiff_plain/ff12cc94790de2e87e78ee7aa378f21fa415d73c..8a26cd19732a12da153c3d2be626eb0e4c46f67a:/ircd/monitor.c diff --git a/ircd/monitor.c b/ircd/monitor.c index 25df1793..2a9bd3e6 100644 --- a/ircd/monitor.c +++ b/ircd/monitor.c @@ -28,8 +28,6 @@ * 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. - * - * $Id: monitor.c 3520 2007-06-30 22:15:35Z jilles $ */ #include "stdinc.h" #include "client.h" @@ -37,44 +35,31 @@ #include "hash.h" #include "numeric.h" #include "send.h" +#include "rb_radixtree.h" -static rb_dlink_list monitorTable[MONITOR_HASH_SIZE]; -static rb_bh *monitor_heap; +static struct rb_radixtree *monitor_tree; void init_monitor(void) { - monitor_heap = rb_bh_create(sizeof(struct monitor), MONITOR_HEAP_SIZE, "monitor_heap"); -} - -static inline unsigned int -hash_monitor_nick(const char *name) -{ - return fnv_hash_upper((const unsigned char *)name, MONITOR_HASH_BITS); + monitor_tree = rb_radixtree_create("monitor lists", irccasecanon); } struct monitor * find_monitor(const char *name, int add) { struct monitor *monptr; - rb_dlink_node *ptr; - - unsigned int hashv = hash_monitor_nick(name); - RB_DLINK_FOREACH(ptr, monitorTable[hashv].head) - { - monptr = ptr->data; - if(!irccmp(monptr->name, name)) - return monptr; - } + monptr = rb_radixtree_retrieve(monitor_tree, name); + if (monptr != NULL) + return monptr; if(add) { - monptr = rb_bh_alloc(monitor_heap); + monptr = rb_malloc(sizeof(*monptr)); rb_strlcpy(monptr->name, name, sizeof(monptr->name)); - monptr->hashv = hashv; + rb_radixtree_add(monitor_tree, monptr->name, monptr); - rb_dlinkAdd(monptr, &monptr->node, &monitorTable[hashv]); return monptr; } @@ -87,8 +72,8 @@ free_monitor(struct monitor *monptr) if (rb_dlink_list_length(&monptr->users) > 0) return; - rb_dlinkDelete(&monptr->node, &monitorTable[monptr->hashv]); - rb_bh_free(monitor_heap, monptr); + rb_radixtree_delete(monitor_tree, monptr->name); + rb_free(monptr); } /* monitor_signon() @@ -108,7 +93,7 @@ monitor_signon(struct Client *client_p) if(monptr == NULL) return; - rb_snprintf(buf, sizeof(buf), "%s!%s@%s", client_p->name, client_p->username, client_p->host); + snprintf(buf, sizeof(buf), "%s!%s@%s", client_p->name, client_p->username, client_p->host); sendto_monitor(monptr, form_str(RPL_MONONLINE), me.name, "*", buf); }