/* * ircd-ratbox: A slightly useful ircd. * hash.c: Maintains hashtables. * * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center * Copyright (C) 1996-2002 Hybrid Development Team * Copyright (C) 2002-2005 ircd-ratbox development team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ namespace ircd { rb_dictionary *client_connid_tree = NULL; rb_radixtree *client_id_tree = NULL; rb_radixtree *client_name_tree = NULL; rb_radixtree *resv_tree = NULL; rb_radixtree *hostname_tree = NULL; /* * look in whowas.c for the missing ...[WW_MAX]; entry */ /* init_hash() * * clears the various hashtables */ void init_hash(void) { client_connid_tree = rb_dictionary_create("client connid", rb_uint32cmp); client_id_tree = rb_radixtree_create("client id", NULL); client_name_tree = rb_radixtree_create("client name", irccasecanon); resv_tree = rb_radixtree_create("resv", irccasecanon); hostname_tree = rb_radixtree_create("hostname", irccasecanon); } uint32_t fnv_hash_upper(const unsigned char *s, int bits) { uint32_t h = FNV1_32_INIT; while (*s) { h ^= rfc1459::toupper(*s++); h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24); } if (bits < 32) h = ((h >> bits) ^ h) & ((1<> bits) ^ h) & ((1<> bits) ^ h) & ((1<> bits) ^ h) & ((1<head; } /* hash_find_resv() * * hunts for a resv entry in the resv hash table */ struct ConfItem * hash_find_resv(const char *name) { struct ConfItem *aconf; s_assert(name != NULL); if(EmptyString(name)) return NULL; aconf = (ConfItem *)rb_radixtree_retrieve(resv_tree, name); if (aconf != NULL) { aconf->port++; return aconf; } return NULL; } void clear_resv_hash(void) { struct ConfItem *aconf; rb_radixtree_iteration_state iter; void *elem; RB_RADIXTREE_FOREACH(elem, &iter, resv_tree) { aconf = (ConfItem *)elem; /* skip temp resvs */ if(aconf->hold) continue; rb_radixtree_delete(resv_tree, aconf->host); free_conf(aconf); } } void add_to_cli_connid_hash(client::client *client_p, uint32_t id) { rb_dictionary_add(client_connid_tree, RB_UINT_TO_POINTER(id), client_p); } void del_from_cli_connid_hash(uint32_t id) { rb_dictionary_delete(client_connid_tree, RB_UINT_TO_POINTER(id)); } client::client * find_cli_connid_hash(uint32_t connid) { return (client::client *)rb_dictionary_retrieve(client_connid_tree, RB_UINT_TO_POINTER(connid)); } } // namespace ircd