]>
Commit | Line | Data |
---|---|---|
67af3857 GB |
1 | #include <string.h> |
2 | #include <stdio.h> | |
3 | #include "../core/hooks.h" | |
4 | #include "../core/schedule.h" | |
5 | #include "../control/control.h" | |
6 | #include "../irc/irc.h" | |
7 | #include "../lib/irc_string.h" | |
8 | #include "../lib/version.h" | |
9 | #include "../core/config.h" | |
10 | #include "rbl.h" | |
11 | ||
12 | MODULE_VERSION(""); | |
13 | ||
14 | rbl_instance *rbl_instances = NULL; | |
15 | ||
16 | int registerrbl(const char *name, const rbl_ops *ops, void *udata) { | |
17 | rbl_instance *instance; | |
18 | ||
19 | instance = malloc(sizeof(*instance)); | |
20 | ||
21 | if (!instance) | |
22 | return -1; | |
23 | ||
24 | instance->name = getsstring(name, 255); | |
25 | instance->ops = ops; | |
26 | instance->udata = udata; | |
27 | ||
28 | instance->next = rbl_instances; | |
29 | rbl_instances = instance; | |
30 | ||
31 | RBL_REFRESH(instance); | |
32 | ||
33 | return 0; | |
34 | } | |
35 | ||
36 | void deregisterrblbyops(const rbl_ops *ops) { | |
37 | rbl_instance **pnext, *rbl; | |
38 | ||
39 | for (pnext = &rbl_instances; *pnext; pnext = &((*pnext)->next)) { | |
40 | rbl = *pnext; | |
41 | ||
42 | if (rbl->ops == ops) { | |
43 | RBL_DTOR(rbl); | |
44 | *pnext = rbl->next; | |
45 | freesstring(rbl->name); | |
46 | free(rbl); | |
47 | ||
48 | if (!*pnext) | |
49 | break; | |
50 | } | |
51 | } | |
52 | } | |
53 | ||
54 | static void rbl_sched_refresh(void *uarg) { | |
55 | rbl_instance *rbl; | |
56 | ||
57 | for (rbl = rbl_instances; rbl; rbl = rbl->next) | |
58 | RBL_REFRESH(rbl); | |
59 | } | |
60 | ||
61 | static void rbl_whois_cb(int hooknum, void *arg) { | |
62 | rbl_instance *rbl; | |
63 | nick *np = (nick *)arg; | |
64 | ||
65 | for (rbl = rbl_instances; rbl; rbl = rbl->next) { | |
66 | char reason[255], message[255]; | |
67 | if (RBL_LOOKUP(rbl, &np->ipaddress, reason, sizeof(reason)) <= 0) | |
68 | continue; | |
69 | ||
70 | snprintf(message, sizeof(message), "RBL : %s (%s)", rbl->name->content, reason); | |
71 | triggerhook(HOOK_CONTROL_WHOISREPLY, message); | |
72 | } | |
73 | } | |
74 | ||
75 | void _init(void) { | |
76 | schedulerecurring(time(NULL)+300, 0, 300, rbl_sched_refresh, NULL); | |
77 | registerhook(HOOK_CONTROL_WHOISREQUEST, &rbl_whois_cb); | |
78 | } | |
79 | ||
80 | void _fini(void) { | |
81 | deleteallschedules(rbl_sched_refresh); | |
82 | deregisterhook(HOOK_CONTROL_WHOISREQUEST, &rbl_whois_cb); | |
83 | } |