]>
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 | ||
32 | /* From the old supported.h which is | |
33 | * Copyright (C) 1996-2002 Hybrid Development Team | |
34 | * Copyright (C) 2002-2004 ircd-ratbox development team | |
35 | */ | |
36 | /* | |
37 | * - from mirc's versions.txt | |
38 | * | |
39 | * mIRC now supports the numeric 005 tokens: CHANTYPES=# and | |
40 | * PREFIX=(ohv)@%+ and can handle a dynamic set of channel and | |
41 | * nick prefixes. | |
42 | * | |
43 | * mIRC assumes that @ is supported on all networks, any mode | |
44 | * left of @ is assumed to have at least equal power to @, and | |
45 | * any mode right of @ has less power. | |
46 | * | |
47 | * mIRC has internal support for @%+ modes. | |
48 | * | |
49 | * $nick() can now handle all mode letters listed in PREFIX. | |
50 | * | |
51 | * Also added support for CHANMODES=A,B,C,D token (not currently | |
52 | * supported by any servers), which lists all modes supported | |
53 | * by a channel, where: | |
54 | * | |
55 | * A = modes that take a parameter, and add or remove nicks | |
56 | * or addresses to a list, such as +bIe for the ban, | |
57 | * invite, and exception lists. | |
58 | * | |
59 | * B = modes that change channel settings, but which take | |
60 | * a parameter when they are set and unset, such as | |
61 | * +k key, and -k key. | |
62 | * | |
63 | * C = modes that change channel settings, but which take | |
64 | * a parameter only when they are set, such as +l N, | |
65 | * and -l. | |
66 | * | |
67 | * D = modes that change channel settings, such as +imnpst | |
68 | * and take no parameters. | |
69 | * | |
70 | * All unknown/unlisted modes are treated as type D. | |
71 | */ | |
72 | ||
73 | #include "stdinc.h" | |
74 | #include "client.h" | |
75 | #include "numeric.h" | |
76 | #include "ircd.h" | |
77 | #include "s_conf.h" | |
78 | #include "s_user.h" | |
79 | #include "supported.h" | |
80 | #include "chmode.h" | |
81 | #include "send.h" | |
82 | ||
83 | rb_dlink_list isupportlist; | |
84 | ||
85 | struct isupportitem | |
86 | { | |
87 | const char *name; | |
88 | const char *(*func)(const void *); | |
89 | const void *param; | |
90 | rb_dlink_node node; | |
91 | }; | |
92 | ||
93 | void | |
94 | add_isupport(const char *name, const char *(*func)(const void *), const void *param) | |
95 | { | |
96 | struct isupportitem *item; | |
97 | ||
98 | item = rb_malloc(sizeof(struct isupportitem)); | |
99 | item->name = name; | |
100 | item->func = func; | |
101 | item->param = param; | |
102 | rb_dlinkAddTail(item, &item->node, &isupportlist); | |
103 | } | |
104 | ||
105 | const void * | |
106 | change_isupport(const char *name, const char *(*func)(const void *), const void *param) | |
107 | { | |
108 | rb_dlink_node *ptr; | |
109 | struct isupportitem *item; | |
110 | const void *oldvalue = NULL; | |
111 | ||
112 | RB_DLINK_FOREACH(ptr, isupportlist.head) | |
113 | { | |
114 | item = ptr->data; | |
115 | ||
116 | if (!strcmp(item->name, name)) | |
117 | { | |
118 | oldvalue = item->param; | |
119 | ||
120 | // item->name = name; | |
121 | item->func = func; | |
122 | item->param = param; | |
123 | ||
124 | break; | |
125 | } | |
126 | } | |
127 | ||
128 | return oldvalue; | |
129 | } | |
130 | ||
131 | void | |
132 | delete_isupport(const char *name) | |
133 | { | |
134 | rb_dlink_node *ptr, *next_ptr; | |
135 | struct isupportitem *item; | |
136 | ||
137 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head) | |
138 | { | |
139 | item = ptr->data; | |
140 | ||
141 | if (!strcmp(item->name, name)) | |
142 | { | |
143 | rb_dlinkDelete(ptr, &isupportlist); | |
144 | rb_free(item); | |
145 | } | |
146 | } | |
147 | } | |
148 | ||
149 | /* XXX caching? */ | |
150 | void | |
151 | show_isupport(struct Client *client_p) | |
152 | { | |
153 | rb_dlink_node *ptr; | |
154 | struct isupportitem *item; | |
155 | const char *value; | |
156 | char buf[512]; | |
157 | int extra_space; | |
158 | unsigned int nchars, nparams; | |
159 | int l; | |
160 | ||
161 | extra_space = strlen(client_p->name); | |
162 | /* UID */ | |
163 | if (!MyClient(client_p) && extra_space < 9) | |
164 | extra_space = 9; | |
165 | /* :<me.name> 005 <nick> <params> :are supported by this server */ | |
166 | /* form_str(RPL_ISUPPORT) is %s :are supported by this server */ | |
167 | extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT)); | |
168 | ||
169 | nchars = extra_space, nparams = 0, buf[0] = '\0'; | |
170 | RB_DLINK_FOREACH(ptr, isupportlist.head) | |
171 | { | |
172 | item = ptr->data; | |
173 | value = (*item->func)(item->param); | |
174 | if (value == NULL) | |
175 | continue; | |
176 | l = strlen(item->name) + (EmptyString(value) ? 0 : 1 + strlen(value)); | |
177 | if (nchars + l + (nparams > 0) >= sizeof buf || nparams + 1 > 12) | |
178 | { | |
179 | sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); | |
180 | nchars = extra_space, nparams = 0, buf[0] = '\0'; | |
181 | } | |
182 | if (nparams > 0) | |
183 | rb_strlcat(buf, " ", sizeof buf), nchars++; | |
184 | rb_strlcat(buf, item->name, sizeof buf); | |
185 | if (!EmptyString(value)) | |
186 | { | |
187 | rb_strlcat(buf, "=", sizeof buf); | |
188 | rb_strlcat(buf, value, sizeof buf); | |
189 | } | |
190 | nchars += l; | |
191 | nparams++; | |
192 | } | |
193 | if (nparams > 0) | |
194 | sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf); | |
195 | } | |
196 | ||
197 | const char * | |
198 | isupport_intptr(const void *ptr) | |
199 | { | |
200 | static char buf[15]; | |
201 | snprintf(buf, sizeof buf, "%d", *(const int *)ptr); | |
202 | return buf; | |
203 | } | |
204 | ||
205 | const char * | |
206 | isupport_boolean(const void *ptr) | |
207 | { | |
208 | ||
209 | return *(const int *)ptr ? "" : NULL; | |
210 | } | |
211 | ||
212 | const char * | |
213 | isupport_string(const void *ptr) | |
214 | { | |
215 | ||
216 | return (const char *)ptr; | |
217 | } | |
218 | ||
219 | const char * | |
220 | isupport_stringptr(const void *ptr) | |
221 | { | |
222 | return *(char * const *)ptr; | |
223 | } | |
224 | ||
225 | static const char * | |
226 | isupport_umode(const void *ptr) | |
227 | { | |
228 | const char *str; | |
229 | ||
230 | str = ptr; | |
231 | return ConfigFileEntry.oper_only_umodes & | |
232 | user_modes[(unsigned char)*str] ? NULL : str; | |
233 | } | |
234 | ||
235 | static const char * | |
236 | isupport_chanmodes(const void *ptr) | |
237 | { | |
238 | static char result[80]; | |
239 | ||
240 | snprintf(result, sizeof result, "%s%sbq,k,%slj,%s", | |
241 | ConfigChannel.use_except ? "e" : "", | |
242 | ConfigChannel.use_invex ? "I" : "", | |
243 | ConfigChannel.use_forward ? "f" : "", | |
244 | cflagsbuf); | |
245 | return result; | |
246 | } | |
247 | ||
248 | static const char * | |
249 | isupport_chantypes(const void *ptr) | |
250 | { | |
251 | return ConfigChannel.disable_local_channels ? "#" : "&#"; | |
252 | } | |
253 | ||
254 | static const char * | |
255 | isupport_chanlimit(const void *ptr) | |
256 | { | |
257 | static char result[30]; | |
258 | ||
259 | snprintf(result, sizeof result, "%s:%i", | |
260 | ConfigChannel.disable_local_channels ? "#" : "&#", ConfigChannel.max_chans_per_user); | |
261 | return result; | |
262 | } | |
263 | ||
264 | static const char * | |
265 | isupport_maxlist(const void *ptr) | |
266 | { | |
267 | static char result[30]; | |
268 | ||
269 | snprintf(result, sizeof result, "bq%s%s:%i", | |
270 | ConfigChannel.use_except ? "e" : "", | |
271 | ConfigChannel.use_invex ? "I" : "", | |
272 | ConfigChannel.max_bans); | |
273 | return result; | |
274 | } | |
275 | ||
276 | static const char * | |
277 | isupport_targmax(const void *ptr) | |
278 | { | |
279 | static char result[200]; | |
280 | ||
281 | snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:", | |
282 | ConfigFileEntry.max_targets, | |
283 | ConfigFileEntry.max_targets); | |
284 | return result; | |
285 | } | |
286 | ||
287 | static const char * | |
288 | isupport_extban(const void *ptr) | |
289 | { | |
290 | const char *p; | |
291 | static char result[200]; | |
292 | ||
293 | p = get_extban_string(); | |
294 | if (EmptyString(p)) | |
295 | return NULL; | |
296 | snprintf(result, sizeof result, "$,%s", p); | |
297 | return result; | |
298 | } | |
299 | ||
300 | static const char * | |
301 | isupport_nicklen(const void *ptr) | |
302 | { | |
303 | static char result[200]; | |
304 | ||
305 | snprintf(result, sizeof result, "%u", ConfigFileEntry.nicklen - 1); | |
306 | return result; | |
307 | } | |
308 | ||
309 | void | |
310 | init_isupport(void) | |
311 | { | |
312 | static int maxmodes = MAXMODEPARAMS; | |
313 | static int channellen = LOC_CHANNELLEN; | |
314 | static int topiclen = TOPICLEN; | |
315 | static int maxnicklen = NICKLEN - 1; | |
316 | ||
317 | add_isupport("CHANTYPES", isupport_chantypes, NULL); | |
318 | add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except); | |
319 | add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex); | |
320 | add_isupport("CHANMODES", isupport_chanmodes, NULL); | |
321 | add_isupport("CHANLIMIT", isupport_chanlimit, NULL); | |
322 | add_isupport("PREFIX", isupport_string, "(ov)@+"); | |
323 | add_isupport("MAXLIST", isupport_maxlist, NULL); | |
324 | add_isupport("MODES", isupport_intptr, &maxmodes); | |
325 | add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name); | |
326 | add_isupport("STATUSMSG", isupport_string, "@+"); | |
327 | add_isupport("CALLERID", isupport_umode, "g"); | |
328 | add_isupport("CASEMAPPING", isupport_string, "rfc1459"); | |
329 | add_isupport("NICKLEN", isupport_nicklen, NULL); | |
330 | add_isupport("MAXNICKLEN", isupport_intptr, &maxnicklen); | |
331 | add_isupport("CHANNELLEN", isupport_intptr, &channellen); | |
332 | add_isupport("TOPICLEN", isupport_intptr, &topiclen); | |
333 | add_isupport("DEAF", isupport_umode, "D"); | |
334 | add_isupport("TARGMAX", isupport_targmax, NULL); | |
335 | add_isupport("EXTBAN", isupport_extban, NULL); | |
336 | add_isupport("CLIENTVER", isupport_string, "3.0"); | |
337 | } |