1 |
/* |
2 |
* pmodule.C: Protocol command management. |
3 |
* Rights to this code are documented in doc/pod/license.pod. |
4 |
* |
5 |
* Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 |
*/ |
7 |
|
8 |
static char const rcsid[] = "$Id"; |
9 |
|
10 |
#include "atheme.h" |
11 |
#include "pmodule.h" |
12 |
|
13 |
dictionary_tree_t *pcommands; |
14 |
BlockHeap *pcommand_heap; |
15 |
BlockHeap *messagetree_heap; |
16 |
cmode_t *mode_list; |
17 |
extmode *ignore_mode_list; |
18 |
cmode_t *status_mode_list; |
19 |
cmode_t *prefix_mode_list; |
20 |
ircd_t *ircd; |
21 |
bool pmodule_loaded = false; |
22 |
bool backend_loaded = false; |
23 |
|
24 |
void |
25 |
pcommand_init (void) |
26 |
{ |
27 |
pcommand_heap = BlockHeapCreate (sizeof (pcommand_t), 64); |
28 |
|
29 |
if (!pcommand_heap) |
30 |
{ |
31 |
slog (LG_INFO, "pcommand_init(): block allocator failed."); |
32 |
exit (EXIT_FAILURE); |
33 |
} |
34 |
|
35 |
pcommands = dictionary_create ("pcommand", HASH_COMMAND, strcmp); |
36 |
} |
37 |
|
38 |
void |
39 |
pcommand_add (char *token, void (*handler) (sourceinfo_t *si, int parc, char *parv[]), int minparc, int sourcetype) |
40 |
{ |
41 |
pcommand_t *pcmd; |
42 |
|
43 |
if ((pcmd = pcommand_find (token))) |
44 |
{ |
45 |
slog (LG_INFO, "pcommand_add(): token %s is already registered", token); |
46 |
return; |
47 |
} |
48 |
|
49 |
pcmd = static_cast<pcommand_t *> (BlockHeapAlloc (pcommand_heap)); |
50 |
pcmd->token = sstrdup (token); |
51 |
pcmd->handler = handler; |
52 |
pcmd->minparc = minparc; |
53 |
pcmd->sourcetype = sourcetype; |
54 |
|
55 |
dictionary_add (pcommands, pcmd->token, pcmd); |
56 |
} |
57 |
|
58 |
void |
59 |
pcommand_delete (char *token) |
60 |
{ |
61 |
pcommand_t *pcmd; |
62 |
|
63 |
if (!(pcmd = pcommand_find (token))) |
64 |
{ |
65 |
slog (LG_INFO, "pcommand_delete(): token %s is not registered", token); |
66 |
return; |
67 |
} |
68 |
|
69 |
dictionary_delete (pcommands, pcmd->token); |
70 |
|
71 |
free (pcmd->token); |
72 |
pcmd->handler = NULL; |
73 |
BlockHeapFree (pcommand_heap, pcmd); |
74 |
} |
75 |
|
76 |
pcommand_t * |
77 |
pcommand_find (char *token) |
78 |
{ |
79 |
return static_cast<pcommand_t *> (dictionary_retrieve (pcommands, token)); |
80 |
} |