]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * charybdis: A slightly useful ircd. | |
3 | * extban.c: extended ban types ($type:data) | |
4 | * | |
5 | * Copyright (C) 2006 charybdis development team | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
20 | * USA | |
212380e3 AC |
21 | */ |
22 | ||
23 | #include "stdinc.h" | |
212380e3 AC |
24 | #include "channel.h" |
25 | #include "client.h" | |
26 | #include "common.h" | |
27 | ||
28 | ExtbanFunc extban_table[256] = { NULL }; | |
29 | ||
30 | int | |
31 | match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) | |
32 | { | |
33 | const char *p; | |
34 | int invert = 0, result = EXTBAN_INVALID; | |
35 | ExtbanFunc f; | |
36 | ||
37 | if (*banstr != '$') | |
38 | return 0; | |
39 | p = banstr + 1; | |
40 | if (*p == '~') | |
41 | { | |
42 | invert = 1; | |
43 | p++; | |
44 | } | |
45 | f = extban_table[(unsigned char) ToLower(*p)]; | |
46 | if (*p != '\0') | |
47 | { | |
48 | p++; | |
49 | if (*p == ':') | |
50 | p++; | |
51 | else | |
52 | p = NULL; | |
53 | } | |
54 | if (f != NULL) | |
55 | result = f(p, client_p, chptr, mode_type); | |
56 | else | |
57 | result = EXTBAN_INVALID; | |
58 | ||
59 | if (invert) | |
60 | return result == EXTBAN_NOMATCH; | |
61 | else | |
62 | return result == EXTBAN_MATCH; | |
63 | } | |
64 | ||
65 | int | |
66 | valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) | |
67 | { | |
68 | const char *p; | |
d7dc7ae6 | 69 | int result = EXTBAN_INVALID; |
212380e3 AC |
70 | ExtbanFunc f; |
71 | ||
72 | if (*banstr != '$') | |
73 | return 0; | |
74 | p = banstr + 1; | |
75 | if (*p == '~') | |
212380e3 | 76 | p++; |
212380e3 AC |
77 | f = extban_table[(unsigned char) ToLower(*p)]; |
78 | if (*p != '\0') | |
79 | { | |
80 | p++; | |
81 | if (*p == ':') | |
82 | p++; | |
83 | else | |
84 | p = NULL; | |
85 | } | |
86 | if (f != NULL) | |
87 | result = f(p, client_p, chptr, mode_type); | |
88 | else | |
89 | result = EXTBAN_INVALID; | |
90 | ||
91 | return result != EXTBAN_INVALID; | |
92 | } | |
93 | ||
94 | const char * | |
95 | get_extban_string(void) | |
96 | { | |
97 | static char e[256]; | |
98 | int i, j; | |
99 | ||
100 | j = 0; | |
101 | for (i = 1; i < 256; i++) | |
102 | if (i == ToLower(i) && extban_table[i]) | |
103 | e[j++] = i; | |
104 | e[j] = 0; | |
105 | return e; | |
106 | } |