Debian Codegraph @

modules/exttarget/main.c

raw
1 /*
2 * Copyright (c) 2011 William Pitcock <[email protected]>
3 *
4 * Rights to this code are as documented in doc/LICENSE.
5 */
6
7 #include "atheme.h"
8 #include "exttarget.h"
9
10 DECLARE_MODULE_V1
11 (
12 "exttarget/main", false, _modinit, _moddeinit,
13 PACKAGE_STRING,
14 VENDOR_STRING
15 );
16
17 mowgli_patricia_t *exttarget_tree = NULL;
18
19 static void exttarget_find(hook_myentity_req_t *req)
20 {
21 char buf[BUFSIZE];
22 char *i, *j;
23 entity_validate_f val;
24
25 return_if_fail(req != NULL);
26
27 if (req->name == NULL || *req->name != '$')
28 return;
29
30 mowgli_strlcpy(buf, req->name, BUFSIZE);
31
32 i = (buf + 1);
33 if ((j = strchr(buf, ':')) != NULL)
34 *j++ = '\0';
35
36 /* i is now the name of the exttarget. j is the parameter. */
37 val = mowgli_patricia_retrieve(exttarget_tree, i);
38 if (val != NULL)
39 req->entity = val(j);
40 }
41
42 void _modinit(module_t *m)
43 {
44 exttarget_tree = mowgli_patricia_create(strcasecanon);
45
46 hook_add_event("myentity_find");
47 hook_add_myentity_find(exttarget_find);
48 }
49
50 void _moddeinit(module_unload_intent_t intent)
51 {
52 hook_del_myentity_find(exttarget_find);
53
54 mowgli_patricia_destroy(exttarget_tree, NULL, NULL);
55 }