]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * charybdis: A slightly useful ircd. | |
3 | * supported.c: isupport (005) numeric | |
4 | * | |
5 | * Copyright (C) 2006 Jilles Tjoelker | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions are | |
9 | * met: | |
10 | * | |
11 | * 1.Redistributions of source code must retain the above copyright notice, | |
12 | * this list of conditions and the following disclaimer. | |
13 | * 2.Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3.The name of the author may not be used to endorse or promote products | |
17 | * derived from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
22 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
23 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
27 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
28 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | * | |
c614f4a9 | 31 | * $Id: supported.c 3568 2007-09-09 18:59:08Z jilles $ |
212380e3 AC |
32 | */ |
33 | ||
34 | /* From the old supported.h which is | |
35 | * Copyright (C) 1996-2002 Hybrid Development Team | |
36 | * Copyright (C) 2002-2004 ircd-ratbox development team | |
37 | */ | |
38 | /* | |
39 | * - from mirc's versions.txt | |
40 | * | |
41 | * mIRC now supports the numeric 005 tokens: CHANTYPES=# and | |
42 | * PREFIX=(ohv)@%+ and can handle a dynamic set of channel and | |
43 | * nick prefixes. | |
44 | * | |
45 | * mIRC assumes that @ is supported on all networks, any mode | |
46 | * left of @ is assumed to have at least equal power to @, and | |
47 | * any mode right of @ has less power. | |
48 | * | |
49 | * mIRC has internal support for @%+ modes. | |
50 | * | |
51 | * $nick() can now handle all mode letters listed in PREFIX. | |
52 | * | |
53 | * Also added support for CHANMODES=A,B,C,D token (not currently | |
54 | * supported by any servers), which lists all modes supported | |
55 | * by a channel, where: | |
56 | * | |
57 | * A = modes that take a parameter, and add or remove nicks | |
58 | * or addresses to a list, such as +bIe for the ban, | |
59 | * invite, and exception lists. | |
60 | * | |
61 | * B = modes that change channel settings, but which take | |
62 | * a parameter when they are set and unset, such as | |
63 | * +k key, and -k key. | |
64 | * | |
65 | * C = modes that change channel settings, but which take | |
66 | * a parameter only when they are set, such as +l N, | |
67 | * and -l. | |
68 | * | |
69 | * D = modes that change channel settings, such as +imnpst | |
70 | * and take no parameters. | |
71 | * | |
72 | * All unknown/unlisted modes are treated as type D. | |
73 | */ | |
74 | /* ELIST=[tokens]: | |
75 | * | |
76 | * M = mask search | |
77 | * N = !mask search | |
78 | * U = user count search (< >) | |
79 | * C = creation time search (C> C<) | |
80 | * T = topic search (T> T<) | |
81 | */ | |
82 | ||
83 | #include "stdinc.h" | |
212380e3 AC |
84 | #include "client.h" |
85 | #include "common.h" | |
86 | #include "numeric.h" | |
87 | #include "ircd.h" | |
88 | #include "s_conf.h" | |
48a266e5 | 89 | #include "supported.h" |
c18cb68b | 90 | #include "chmode.h" |
212380e3 | 91 | |
330fc5c1 | 92 | rb_dlink_list isupportlist; |
212380e3 AC |
93 | |
94 | struct isupportitem | |
95 | { | |
96 | const char *name; | |
48a266e5 JT |
97 | const char *(*func)(const void *); |
98 | const void *param; | |
330fc5c1 | 99 | rb_dlink_node node; |
212380e3 AC |
100 | }; |
101 | ||
102 | void | |
48a266e5 | 103 | add_isupport(const char *name, const char *(*func)(const void *), const void *param) |
212380e3 AC |
104 | { |
105 | struct isupportitem *item; | |
106 | ||
eddc2ab6 | 107 | item = rb_malloc(sizeof(struct isupportitem)); |
212380e3 AC |
108 | item->name = name; |
109 | item->func = func; | |
110 | item->param = param; | |
330fc5c1 | 111 | rb_dlinkAddTail(item, &item->node, &isupportlist); |
212380e3 AC |
112 | } |
113 | ||
5d47bdca | 114 | const void * |
474b0d35 AC |
115 | change_isupport(const char *name, const char *(*func)(const void *), const void *param) |
116 | { | |
117 | rb_dlink_node *ptr; | |
118 | struct isupportitem *item; | |
5d47bdca | 119 | void *oldvalue; |
474b0d35 AC |
120 | |
121 | RB_DLINK_FOREACH(ptr, isupportlist.head) | |
122 | { | |
123 | item = ptr->data; | |
124 | ||
125 | if (!strcmp(item->name, name)) | |
126 | { | |
5d47bdca AC |
127 | oldvalue = item->param; |
128 | ||
41d8802e | 129 | // item->name = name; |
474b0d35 AC |
130 | item->func = func; |
131 | item->param = param; | |
132 | ||
133 | break; | |
134 | } | |
135 | } | |
5d47bdca AC |
136 | |
137 | return oldvalue; | |
474b0d35 AC |
138 | } |
139 | ||
212380e3 AC |
140 | void |
141 | delete_isupport(const char *name) | |
142 | { | |
637c4932 | 143 | rb_dlink_node *ptr, *next_ptr; |
212380e3 AC |
144 | struct isupportitem *item; |
145 | ||
637c4932 | 146 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head) |
212380e3 AC |
147 | { |
148 | item = ptr->data; | |
149 | ||
150 | if (!strcmp(item->name, name)) | |
151 | { | |
330fc5c1 | 152 | rb_dlinkDelete(ptr, &isupportlist); |
637c4932 | 153 | rb_free(item); |
212380e3 AC |
154 | } |
155 | } | |
156 | } | |
157 | ||
158 | /* XXX caching? */ | |
159 | void | |
160 | show_isupport(struct Client *client_p) | |
161 | { | |
330fc5c1 | 162 | rb_dlink_node *ptr; |
212380e3 AC |
163 | struct isupportitem *item; |
164 | const char *value; | |
165 | char buf[512]; | |
166 | int extra_space; | |
48a266e5 | 167 | unsigned int nchars, nparams; |
212380e3 AC |
168 | int l; |
169 | ||
170 | extra_space = strlen(client_p->name); | |
171 | /* UID */ | |
172 | if (!MyClient(client_p) && extra_space < 9) | |
173 | extra_space = 9; | |
174 | /* :<me.name> 005 <nick> <params> :are supported by this server */ | |
175 | /* form_str(RPL_ISUPPORT) is %s :are supported by this server */ | |
176 | extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT)); | |
177 | ||
178 | nchars = extra_space, nparams = 0, buf[0] = '\0'; | |
5cefa1d6 | 179 | RB_DLINK_FOREACH(ptr, isupportlist.head) |
212380e3 AC |
180 | { |
181 | item = ptr->data; | |
182 | value = (*item->func)(item->param); | |
183 | if (value == NULL) | |
184 | continue; | |
185 | l = strlen(item->name) + (EmptyString(value) ? 0 : 1 + strlen(value)); | |
186 | if (nchars + l + (nparams > 0) >= sizeof buf || nparams + 1 > 12) | |
187 | { | |
188 | sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); | |
189 | nchars = extra_space, nparams = 0, buf[0] = '\0'; | |
190 | } | |
191 | if (nparams > 0) | |
1f9de103 VY |
192 | rb_strlcat(buf, " ", sizeof buf), nchars++; |
193 | rb_strlcat(buf, item->name, sizeof buf); | |
212380e3 AC |
194 | if (!EmptyString(value)) |
195 | { | |
1f9de103 VY |
196 | rb_strlcat(buf, "=", sizeof buf); |
197 | rb_strlcat(buf, value, sizeof buf); | |
212380e3 AC |
198 | } |
199 | nchars += l; | |
200 | nparams++; | |
201 | } | |
202 | if (nparams > 0) | |
203 | sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); | |
204 | } | |
205 | ||
206 | const char * | |
48a266e5 | 207 | isupport_intptr(const void *ptr) |
212380e3 AC |
208 | { |
209 | static char buf[15]; | |
b2f0da88 | 210 | rb_snprintf(buf, sizeof buf, "%d", *(const int *)ptr); |
212380e3 AC |
211 | return buf; |
212 | } | |
213 | ||
214 | const char * | |
48a266e5 | 215 | isupport_boolean(const void *ptr) |
212380e3 AC |
216 | { |
217 | ||
48a266e5 | 218 | return *(const int *)ptr ? "" : NULL; |
212380e3 AC |
219 | } |
220 | ||
221 | const char * | |
48a266e5 | 222 | isupport_string(const void *ptr) |
212380e3 AC |
223 | { |
224 | ||
225 | return (const char *)ptr; | |
226 | } | |
227 | ||
228 | const char * | |
48a266e5 | 229 | isupport_stringptr(const void *ptr) |
212380e3 | 230 | { |
48a266e5 | 231 | return *(char * const *)ptr; |
212380e3 AC |
232 | } |
233 | ||
48a266e5 JT |
234 | static const char * |
235 | isupport_chanmodes(const void *ptr) | |
212380e3 AC |
236 | { |
237 | static char result[80]; | |
238 | ||
c18cb68b | 239 | rb_snprintf(result, sizeof result, "%s%sbq,k,%slj,%s", |
212380e3 AC |
240 | ConfigChannel.use_except ? "e" : "", |
241 | ConfigChannel.use_invex ? "I" : "", | |
242 | ConfigChannel.use_forward ? "f" : "", | |
c18cb68b | 243 | cflagsbuf); |
212380e3 AC |
244 | return result; |
245 | } | |
246 | ||
48a266e5 JT |
247 | static const char * |
248 | isupport_chanlimit(const void *ptr) | |
212380e3 AC |
249 | { |
250 | static char result[30]; | |
251 | ||
b2f0da88 | 252 | rb_snprintf(result, sizeof result, "&#:%i", ConfigChannel.max_chans_per_user); |
212380e3 AC |
253 | return result; |
254 | } | |
255 | ||
48a266e5 JT |
256 | static const char * |
257 | isupport_maxlist(const void *ptr) | |
212380e3 AC |
258 | { |
259 | static char result[30]; | |
260 | ||
b2f0da88 | 261 | rb_snprintf(result, sizeof result, "bq%s%s:%i", |
212380e3 AC |
262 | ConfigChannel.use_except ? "e" : "", |
263 | ConfigChannel.use_invex ? "I" : "", | |
264 | ConfigChannel.max_bans); | |
265 | return result; | |
266 | } | |
267 | ||
48a266e5 JT |
268 | static const char * |
269 | isupport_targmax(const void *ptr) | |
212380e3 AC |
270 | { |
271 | static char result[200]; | |
272 | ||
b2f0da88 | 273 | rb_snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:", |
212380e3 AC |
274 | ConfigFileEntry.max_targets, |
275 | ConfigFileEntry.max_targets); | |
276 | return result; | |
277 | } | |
278 | ||
48a266e5 JT |
279 | static const char * |
280 | isupport_extban(const void *ptr) | |
212380e3 AC |
281 | { |
282 | const char *p; | |
283 | static char result[200]; | |
284 | ||
285 | p = get_extban_string(); | |
286 | if (EmptyString(p)) | |
287 | return NULL; | |
b2f0da88 | 288 | rb_snprintf(result, sizeof result, "$,%s", p); |
212380e3 AC |
289 | return result; |
290 | } | |
291 | ||
292 | void | |
293 | init_isupport(void) | |
294 | { | |
295 | static int maxmodes = MAXMODEPARAMS; | |
296 | static int nicklen = NICKLEN-1; | |
297 | static int channellen = LOC_CHANNELLEN; | |
298 | static int topiclen = TOPICLEN; | |
299 | ||
300 | add_isupport("CHANTYPES", isupport_string, "&#"); | |
301 | add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except); | |
302 | add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex); | |
303 | add_isupport("CHANMODES", isupport_chanmodes, NULL); | |
304 | add_isupport("CHANLIMIT", isupport_chanlimit, NULL); | |
305 | add_isupport("PREFIX", isupport_string, "(ov)@+"); | |
306 | add_isupport("MAXLIST", isupport_maxlist, NULL); | |
307 | add_isupport("MODES", isupport_intptr, &maxmodes); | |
308 | add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name); | |
309 | add_isupport("KNOCK", isupport_boolean, &ConfigChannel.use_knock); | |
310 | add_isupport("STATUSMSG", isupport_string, "@+"); | |
311 | add_isupport("CALLERID", isupport_string, "g"); | |
312 | add_isupport("SAFELIST", isupport_string, ""); | |
313 | add_isupport("ELIST", isupport_string, "U"); | |
314 | add_isupport("CASEMAPPING", isupport_string, "rfc1459"); | |
315 | add_isupport("CHARSET", isupport_string, "ascii"); | |
316 | add_isupport("NICKLEN", isupport_intptr, &nicklen); | |
317 | add_isupport("CHANNELLEN", isupport_intptr, &channellen); | |
318 | add_isupport("TOPICLEN", isupport_intptr, &topiclen); | |
319 | add_isupport("ETRACE", isupport_string, ""); | |
320 | add_isupport("CPRIVMSG", isupport_string, ""); | |
321 | add_isupport("CNOTICE", isupport_string, ""); | |
322 | add_isupport("DEAF", isupport_string, "D"); | |
323 | add_isupport("MONITOR", isupport_intptr, &ConfigFileEntry.max_monitor); | |
324 | add_isupport("FNC", isupport_string, ""); | |
325 | add_isupport("TARGMAX", isupport_targmax, NULL); | |
326 | add_isupport("EXTBAN", isupport_extban, NULL); | |
ffe4e4ae | 327 | add_isupport("WHOX", isupport_string, ""); |
212380e3 | 328 | } |