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