]>
Commit | Line | Data |
---|---|---|
212380e3 | 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 | |
21 | * | |
212380e3 | 22 | */ |
23 | ||
24 | #include "stdinc.h" | |
212380e3 | 25 | #include "channel.h" |
26 | #include "client.h" | |
27 | #include "common.h" | |
28 | ||
29 | ExtbanFunc extban_table[256] = { NULL }; | |
30 | ||
31 | int | |
32 | match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) | |
33 | { | |
34 | const char *p; | |
35 | int invert = 0, result = EXTBAN_INVALID; | |
36 | ExtbanFunc f; | |
37 | ||
38 | if (*banstr != '$') | |
39 | return 0; | |
40 | p = banstr + 1; | |
41 | if (*p == '~') | |
42 | { | |
43 | invert = 1; | |
44 | p++; | |
45 | } | |
46 | f = extban_table[(unsigned char) ToLower(*p)]; | |
47 | if (*p != '\0') | |
48 | { | |
49 | p++; | |
50 | if (*p == ':') | |
51 | p++; | |
52 | else | |
53 | p = NULL; | |
54 | } | |
55 | if (f != NULL) | |
56 | result = f(p, client_p, chptr, mode_type); | |
57 | else | |
58 | result = EXTBAN_INVALID; | |
59 | ||
60 | if (invert) | |
61 | return result == EXTBAN_NOMATCH; | |
62 | else | |
63 | return result == EXTBAN_MATCH; | |
64 | } | |
65 | ||
66 | int | |
67 | valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) | |
68 | { | |
69 | const char *p; | |
628eee00 | 70 | int result = EXTBAN_INVALID; |
212380e3 | 71 | ExtbanFunc f; |
72 | ||
73 | if (*banstr != '$') | |
74 | return 0; | |
75 | p = banstr + 1; | |
76 | if (*p == '~') | |
212380e3 | 77 | p++; |
212380e3 | 78 | f = extban_table[(unsigned char) ToLower(*p)]; |
79 | if (*p != '\0') | |
80 | { | |
81 | p++; | |
82 | if (*p == ':') | |
83 | p++; | |
84 | else | |
85 | p = NULL; | |
86 | } | |
87 | if (f != NULL) | |
88 | result = f(p, client_p, chptr, mode_type); | |
89 | else | |
90 | result = EXTBAN_INVALID; | |
91 | ||
92 | return result != EXTBAN_INVALID; | |
93 | } | |
94 | ||
95 | const char * | |
96 | get_extban_string(void) | |
97 | { | |
98 | static char e[256]; | |
99 | int i, j; | |
100 | ||
101 | j = 0; | |
102 | for (i = 1; i < 256; i++) | |
103 | if (i == ToLower(i) && extban_table[i]) | |
104 | e[j++] = i; | |
105 | e[j] = 0; | |
106 | return e; | |
107 | } |