]>
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 | */ | |
212380e3 AC |
74 | |
75 | #include "stdinc.h" | |
212380e3 AC |
76 | #include "client.h" |
77 | #include "common.h" | |
78 | #include "numeric.h" | |
79 | #include "ircd.h" | |
80 | #include "s_conf.h" | |
294d32bf | 81 | #include "s_user.h" |
48a266e5 | 82 | #include "supported.h" |
c18cb68b | 83 | #include "chmode.h" |
212380e3 | 84 | |
330fc5c1 | 85 | rb_dlink_list isupportlist; |
212380e3 AC |
86 | |
87 | struct isupportitem | |
88 | { | |
89 | const char *name; | |
48a266e5 JT |
90 | const char *(*func)(const void *); |
91 | const void *param; | |
330fc5c1 | 92 | rb_dlink_node node; |
212380e3 AC |
93 | }; |
94 | ||
95 | void | |
48a266e5 | 96 | add_isupport(const char *name, const char *(*func)(const void *), const void *param) |
212380e3 AC |
97 | { |
98 | struct isupportitem *item; | |
99 | ||
eddc2ab6 | 100 | item = rb_malloc(sizeof(struct isupportitem)); |
212380e3 AC |
101 | item->name = name; |
102 | item->func = func; | |
103 | item->param = param; | |
330fc5c1 | 104 | rb_dlinkAddTail(item, &item->node, &isupportlist); |
212380e3 AC |
105 | } |
106 | ||
5d47bdca | 107 | const void * |
474b0d35 AC |
108 | change_isupport(const char *name, const char *(*func)(const void *), const void *param) |
109 | { | |
110 | rb_dlink_node *ptr; | |
111 | struct isupportitem *item; | |
eac04554 | 112 | const void *oldvalue = NULL; |
474b0d35 AC |
113 | |
114 | RB_DLINK_FOREACH(ptr, isupportlist.head) | |
115 | { | |
116 | item = ptr->data; | |
117 | ||
118 | if (!strcmp(item->name, name)) | |
119 | { | |
5d47bdca AC |
120 | oldvalue = item->param; |
121 | ||
41d8802e | 122 | // item->name = name; |
474b0d35 AC |
123 | item->func = func; |
124 | item->param = param; | |
125 | ||
126 | break; | |
127 | } | |
128 | } | |
5d47bdca AC |
129 | |
130 | return oldvalue; | |
474b0d35 AC |
131 | } |
132 | ||
212380e3 AC |
133 | void |
134 | delete_isupport(const char *name) | |
135 | { | |
637c4932 | 136 | rb_dlink_node *ptr, *next_ptr; |
212380e3 AC |
137 | struct isupportitem *item; |
138 | ||
637c4932 | 139 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head) |
212380e3 AC |
140 | { |
141 | item = ptr->data; | |
142 | ||
143 | if (!strcmp(item->name, name)) | |
144 | { | |
330fc5c1 | 145 | rb_dlinkDelete(ptr, &isupportlist); |
637c4932 | 146 | rb_free(item); |
212380e3 AC |
147 | } |
148 | } | |
149 | } | |
150 | ||
151 | /* XXX caching? */ | |
152 | void | |
153 | show_isupport(struct Client *client_p) | |
154 | { | |
330fc5c1 | 155 | rb_dlink_node *ptr; |
212380e3 AC |
156 | struct isupportitem *item; |
157 | const char *value; | |
158 | char buf[512]; | |
159 | int extra_space; | |
48a266e5 | 160 | unsigned int nchars, nparams; |
212380e3 AC |
161 | int l; |
162 | ||
163 | extra_space = strlen(client_p->name); | |
164 | /* UID */ | |
165 | if (!MyClient(client_p) && extra_space < 9) | |
166 | extra_space = 9; | |
167 | /* :<me.name> 005 <nick> <params> :are supported by this server */ | |
168 | /* form_str(RPL_ISUPPORT) is %s :are supported by this server */ | |
169 | extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT)); | |
170 | ||
171 | nchars = extra_space, nparams = 0, buf[0] = '\0'; | |
5cefa1d6 | 172 | RB_DLINK_FOREACH(ptr, isupportlist.head) |
212380e3 AC |
173 | { |
174 | item = ptr->data; | |
175 | value = (*item->func)(item->param); | |
176 | if (value == NULL) | |
177 | continue; | |
178 | l = strlen(item->name) + (EmptyString(value) ? 0 : 1 + strlen(value)); | |
179 | if (nchars + l + (nparams > 0) >= sizeof buf || nparams + 1 > 12) | |
180 | { | |
181 | sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); | |
182 | nchars = extra_space, nparams = 0, buf[0] = '\0'; | |
183 | } | |
184 | if (nparams > 0) | |
1f9de103 VY |
185 | rb_strlcat(buf, " ", sizeof buf), nchars++; |
186 | rb_strlcat(buf, item->name, sizeof buf); | |
212380e3 AC |
187 | if (!EmptyString(value)) |
188 | { | |
1f9de103 VY |
189 | rb_strlcat(buf, "=", sizeof buf); |
190 | rb_strlcat(buf, value, sizeof buf); | |
212380e3 AC |
191 | } |
192 | nchars += l; | |
193 | nparams++; | |
194 | } | |
195 | if (nparams > 0) | |
196 | sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); | |
197 | } | |
198 | ||
199 | const char * | |
48a266e5 | 200 | isupport_intptr(const void *ptr) |
212380e3 AC |
201 | { |
202 | static char buf[15]; | |
b2f0da88 | 203 | rb_snprintf(buf, sizeof buf, "%d", *(const int *)ptr); |
212380e3 AC |
204 | return buf; |
205 | } | |
206 | ||
207 | const char * | |
48a266e5 | 208 | isupport_boolean(const void *ptr) |
212380e3 AC |
209 | { |
210 | ||
48a266e5 | 211 | return *(const int *)ptr ? "" : NULL; |
212380e3 AC |
212 | } |
213 | ||
214 | const char * | |
48a266e5 | 215 | isupport_string(const void *ptr) |
212380e3 AC |
216 | { |
217 | ||
218 | return (const char *)ptr; | |
219 | } | |
220 | ||
221 | const char * | |
48a266e5 | 222 | isupport_stringptr(const void *ptr) |
212380e3 | 223 | { |
48a266e5 | 224 | return *(char * const *)ptr; |
212380e3 AC |
225 | } |
226 | ||
294d32bf JT |
227 | static const char * |
228 | isupport_umode(const void *ptr) | |
229 | { | |
230 | const char *str; | |
231 | ||
232 | str = ptr; | |
7ddd614c JT |
233 | return ConfigFileEntry.oper_only_umodes & |
234 | user_modes[(unsigned char)*str] ? NULL : str; | |
294d32bf JT |
235 | } |
236 | ||
48a266e5 JT |
237 | static const char * |
238 | isupport_chanmodes(const void *ptr) | |
212380e3 AC |
239 | { |
240 | static char result[80]; | |
241 | ||
2da6f6eb | 242 | rb_snprintf(result, sizeof result, "%s%sbq,k,%slj,%s", |
212380e3 AC |
243 | ConfigChannel.use_except ? "e" : "", |
244 | ConfigChannel.use_invex ? "I" : "", | |
2da6f6eb | 245 | ConfigChannel.use_forward ? "f" : "", |
c18cb68b | 246 | cflagsbuf); |
212380e3 AC |
247 | return result; |
248 | } | |
249 | ||
341f971e SB |
250 | static const char * |
251 | isupport_chantypes(const void *ptr) | |
252 | { | |
253 | return ConfigChannel.disable_local_channels ? "#" : "&#"; | |
254 | } | |
255 | ||
48a266e5 JT |
256 | static const char * |
257 | isupport_chanlimit(const void *ptr) | |
212380e3 AC |
258 | { |
259 | static char result[30]; | |
260 | ||
341f971e SB |
261 | rb_snprintf(result, sizeof result, "%s:%i", |
262 | ConfigChannel.disable_local_channels ? "#" : "&#", ConfigChannel.max_chans_per_user); | |
212380e3 AC |
263 | return result; |
264 | } | |
265 | ||
48a266e5 JT |
266 | static const char * |
267 | isupport_maxlist(const void *ptr) | |
212380e3 AC |
268 | { |
269 | static char result[30]; | |
270 | ||
b2f0da88 | 271 | rb_snprintf(result, sizeof result, "bq%s%s:%i", |
212380e3 AC |
272 | ConfigChannel.use_except ? "e" : "", |
273 | ConfigChannel.use_invex ? "I" : "", | |
274 | ConfigChannel.max_bans); | |
275 | return result; | |
276 | } | |
277 | ||
48a266e5 JT |
278 | static const char * |
279 | isupport_targmax(const void *ptr) | |
212380e3 AC |
280 | { |
281 | static char result[200]; | |
282 | ||
b2f0da88 | 283 | rb_snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:", |
212380e3 AC |
284 | ConfigFileEntry.max_targets, |
285 | ConfigFileEntry.max_targets); | |
286 | return result; | |
287 | } | |
288 | ||
48a266e5 JT |
289 | static const char * |
290 | isupport_extban(const void *ptr) | |
212380e3 AC |
291 | { |
292 | const char *p; | |
293 | static char result[200]; | |
294 | ||
295 | p = get_extban_string(); | |
296 | if (EmptyString(p)) | |
297 | return NULL; | |
b2f0da88 | 298 | rb_snprintf(result, sizeof result, "$,%s", p); |
212380e3 AC |
299 | return result; |
300 | } | |
301 | ||
c68d30f7 AC |
302 | static const char * |
303 | isupport_nicklen(const void *ptr) | |
304 | { | |
305 | static char result[200]; | |
306 | ||
307 | rb_snprintf(result, sizeof result, "%u", ConfigFileEntry.nicklen - 1); | |
308 | return result; | |
309 | } | |
310 | ||
212380e3 AC |
311 | void |
312 | init_isupport(void) | |
313 | { | |
314 | static int maxmodes = MAXMODEPARAMS; | |
212380e3 AC |
315 | static int channellen = LOC_CHANNELLEN; |
316 | static int topiclen = TOPICLEN; | |
c68d30f7 | 317 | static int maxnicklen = NICKLEN - 1; |
212380e3 | 318 | |
341f971e | 319 | add_isupport("CHANTYPES", isupport_chantypes, NULL); |
212380e3 AC |
320 | add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except); |
321 | add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex); | |
322 | add_isupport("CHANMODES", isupport_chanmodes, NULL); | |
323 | add_isupport("CHANLIMIT", isupport_chanlimit, NULL); | |
324 | add_isupport("PREFIX", isupport_string, "(ov)@+"); | |
325 | add_isupport("MAXLIST", isupport_maxlist, NULL); | |
326 | add_isupport("MODES", isupport_intptr, &maxmodes); | |
327 | add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name); | |
328 | add_isupport("KNOCK", isupport_boolean, &ConfigChannel.use_knock); | |
329 | add_isupport("STATUSMSG", isupport_string, "@+"); | |
294d32bf | 330 | add_isupport("CALLERID", isupport_umode, "g"); |
212380e3 AC |
331 | add_isupport("CASEMAPPING", isupport_string, "rfc1459"); |
332 | add_isupport("CHARSET", isupport_string, "ascii"); | |
c68d30f7 AC |
333 | add_isupport("NICKLEN", isupport_nicklen, NULL); |
334 | add_isupport("MAXNICKLEN", isupport_intptr, &maxnicklen); | |
212380e3 AC |
335 | add_isupport("CHANNELLEN", isupport_intptr, &channellen); |
336 | add_isupport("TOPICLEN", isupport_intptr, &topiclen); | |
337 | add_isupport("ETRACE", isupport_string, ""); | |
338 | add_isupport("CPRIVMSG", isupport_string, ""); | |
339 | add_isupport("CNOTICE", isupport_string, ""); | |
294d32bf | 340 | add_isupport("DEAF", isupport_umode, "D"); |
212380e3 AC |
341 | add_isupport("MONITOR", isupport_intptr, &ConfigFileEntry.max_monitor); |
342 | add_isupport("FNC", isupport_string, ""); | |
343 | add_isupport("TARGMAX", isupport_targmax, NULL); | |
344 | add_isupport("EXTBAN", isupport_extban, NULL); | |
ffe4e4ae | 345 | add_isupport("WHOX", isupport_string, ""); |
bde6442c | 346 | add_isupport("CLIENTVER", isupport_string, "3.0"); |
212380e3 | 347 | } |