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