]> jfr.im git - solanum.git/blame - ircd/operhash.c
config.h.dist: forgot one...
[solanum.git] / ircd / operhash.c
CommitLineData
b02a913b 1/* charybdis
27f616dd
JT
2 * operhash.c - Hashes nick!user@host{oper}
3 *
4 * Copyright (C) 2005 Lee Hardy <lee -at- leeh.co.uk>
b02a913b
AC
5 * Copyright (C) 2005-2016 ircd-ratbox development team
6 * Copyright (C) 2016 William Pitcock <nenolod@dereferenced.org>
27f616dd
JT
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * 1.Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * 2.Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3.The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
27f616dd 31 */
b02a913b 32
27f616dd
JT
33#include <ratbox_lib.h>
34#include "stdinc.h"
35#include "match.h"
36#include "hash.h"
37#include "operhash.h"
b02a913b 38#include "irc_radixtree.h"
27f616dd 39
b02a913b 40static struct irc_radixtree *operhash_tree = NULL;
27f616dd 41
b02a913b
AC
42struct operhash_entry
43{
44 unsigned int refcount;
45 char name[];
46};
27f616dd 47
b02a913b
AC
48void
49init_operhash(void)
50{
51 operhash_tree = irc_radixtree_create("operhash", NULL);
52}
27f616dd
JT
53
54const char *
55operhash_add(const char *name)
56{
b02a913b
AC
57 struct operhash_entry *ohash;
58 size_t len;
27f616dd
JT
59
60 if(EmptyString(name))
61 return NULL;
62
b02a913b 63 if((ohash = (struct operhash_entry *) irc_radixtree_retrieve(operhash_tree, name)) != NULL)
27f616dd 64 {
b02a913b
AC
65 ohash->refcount++;
66 return ohash->name;
27f616dd
JT
67 }
68
b02a913b
AC
69 len = strlen(name) + 1;
70 ohash = rb_malloc(sizeof(struct operhash_entry) + len);
71 ohash->refcount = 1;
72 memcpy(ohash->name, name, len);
73 irc_radixtree_add(operhash_tree, ohash->name, ohash);
74 return ohash->name;
27f616dd
JT
75}
76
77const char *
78operhash_find(const char *name)
79{
b02a913b 80 return irc_radixtree_retrieve(operhash_tree, name);
27f616dd
JT
81}
82
83void
84operhash_delete(const char *name)
85{
b02a913b 86 struct operhash_entry *ohash = irc_radixtree_retrieve(operhash_tree, name);
27f616dd 87
b02a913b
AC
88 if (ohash != NULL)
89 rb_free(ohash);
27f616dd 90}