]> jfr.im git - irc/rqf/shadowircd.git/blame - src/supported.c
'rb_dlink_list global_channel_list' declaration moved to channel.c
[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 *
c614f4a9 31 * $Id: supported.c 3568 2007-09-09 18:59:08Z jilles $
212380e3 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 84#include "client.h"
85#include "common.h"
86#include "numeric.h"
87#include "ircd.h"
88#include "s_conf.h"
58067bff 89#include "supported.h"
2392eb24 90#include "chmode.h"
212380e3 91
af81d5a0 92rb_dlink_list isupportlist;
212380e3 93
94struct isupportitem
95{
96 const char *name;
58067bff
JT
97 const char *(*func)(const void *);
98 const void *param;
af81d5a0 99 rb_dlink_node node;
212380e3 100};
101
102void
58067bff 103add_isupport(const char *name, const char *(*func)(const void *), const void *param)
212380e3 104{
105 struct isupportitem *item;
106
8e43b0b4 107 item = rb_malloc(sizeof(struct isupportitem));
212380e3 108 item->name = name;
109 item->func = func;
110 item->param = param;
af81d5a0 111 rb_dlinkAddTail(item, &item->node, &isupportlist);
212380e3 112}
113
114void
115delete_isupport(const char *name)
116{
90a3c35b 117 rb_dlink_node *ptr, *next_ptr;
212380e3 118 struct isupportitem *item;
119
90a3c35b 120 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, isupportlist.head)
212380e3 121 {
122 item = ptr->data;
123
124 if (!strcmp(item->name, name))
125 {
af81d5a0 126 rb_dlinkDelete(ptr, &isupportlist);
90a3c35b 127 rb_free(item);
212380e3 128 }
129 }
130}
131
132/* XXX caching? */
133void
134show_isupport(struct Client *client_p)
135{
af81d5a0 136 rb_dlink_node *ptr;
212380e3 137 struct isupportitem *item;
138 const char *value;
139 char buf[512];
140 int extra_space;
58067bff 141 unsigned int nchars, nparams;
212380e3 142 int l;
143
144 extra_space = strlen(client_p->name);
145 /* UID */
146 if (!MyClient(client_p) && extra_space < 9)
147 extra_space = 9;
148 /* :<me.name> 005 <nick> <params> :are supported by this server */
149 /* form_str(RPL_ISUPPORT) is %s :are supported by this server */
150 extra_space += strlen(me.name) + 1 + strlen(form_str(RPL_ISUPPORT));
151
152 nchars = extra_space, nparams = 0, buf[0] = '\0';
8e69bb4e 153 RB_DLINK_FOREACH(ptr, isupportlist.head)
212380e3 154 {
155 item = ptr->data;
156 value = (*item->func)(item->param);
157 if (value == NULL)
158 continue;
159 l = strlen(item->name) + (EmptyString(value) ? 0 : 1 + strlen(value));
160 if (nchars + l + (nparams > 0) >= sizeof buf || nparams + 1 > 12)
161 {
162 sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf);
163 nchars = extra_space, nparams = 0, buf[0] = '\0';
164 }
165 if (nparams > 0)
a64c5173
VY
166 rb_strlcat(buf, " ", sizeof buf), nchars++;
167 rb_strlcat(buf, item->name, sizeof buf);
212380e3 168 if (!EmptyString(value))
169 {
a64c5173
VY
170 rb_strlcat(buf, "=", sizeof buf);
171 rb_strlcat(buf, value, sizeof buf);
212380e3 172 }
173 nchars += l;
174 nparams++;
175 }
176 if (nparams > 0)
177 sendto_one_numeric(client_p, RPL_ISUPPORT, form_str(RPL_ISUPPORT), buf);
178}
179
180const char *
58067bff 181isupport_intptr(const void *ptr)
212380e3 182{
183 static char buf[15];
38e6acdd 184 rb_snprintf(buf, sizeof buf, "%d", *(const int *)ptr);
212380e3 185 return buf;
186}
187
188const char *
58067bff 189isupport_boolean(const void *ptr)
212380e3 190{
191
58067bff 192 return *(const int *)ptr ? "" : NULL;
212380e3 193}
194
195const char *
58067bff 196isupport_string(const void *ptr)
212380e3 197{
198
199 return (const char *)ptr;
200}
201
202const char *
58067bff 203isupport_stringptr(const void *ptr)
212380e3 204{
58067bff 205 return *(char * const *)ptr;
212380e3 206}
207
58067bff
JT
208static const char *
209isupport_chanmodes(const void *ptr)
212380e3 210{
211 static char result[80];
212
2392eb24 213 rb_snprintf(result, sizeof result, "%s%sbq,k,%slj,%s",
212380e3 214 ConfigChannel.use_except ? "e" : "",
215 ConfigChannel.use_invex ? "I" : "",
216 ConfigChannel.use_forward ? "f" : "",
2392eb24 217 cflagsbuf);
212380e3 218 return result;
219}
220
58067bff
JT
221static const char *
222isupport_chanlimit(const void *ptr)
212380e3 223{
224 static char result[30];
225
38e6acdd 226 rb_snprintf(result, sizeof result, "&#:%i", ConfigChannel.max_chans_per_user);
212380e3 227 return result;
228}
229
58067bff
JT
230static const char *
231isupport_maxlist(const void *ptr)
212380e3 232{
233 static char result[30];
234
38e6acdd 235 rb_snprintf(result, sizeof result, "bq%s%s:%i",
212380e3 236 ConfigChannel.use_except ? "e" : "",
237 ConfigChannel.use_invex ? "I" : "",
238 ConfigChannel.max_bans);
239 return result;
240}
241
58067bff
JT
242static const char *
243isupport_targmax(const void *ptr)
212380e3 244{
245 static char result[200];
246
38e6acdd 247 rb_snprintf(result, sizeof result, "NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%d,NOTICE:%d,ACCEPT:,MONITOR:",
212380e3 248 ConfigFileEntry.max_targets,
249 ConfigFileEntry.max_targets);
250 return result;
251}
252
58067bff
JT
253static const char *
254isupport_extban(const void *ptr)
212380e3 255{
256 const char *p;
257 static char result[200];
258
259 p = get_extban_string();
260 if (EmptyString(p))
261 return NULL;
38e6acdd 262 rb_snprintf(result, sizeof result, "$,%s", p);
212380e3 263 return result;
264}
265
266void
267init_isupport(void)
268{
269 static int maxmodes = MAXMODEPARAMS;
270 static int nicklen = NICKLEN-1;
271 static int channellen = LOC_CHANNELLEN;
272 static int topiclen = TOPICLEN;
273
274 add_isupport("CHANTYPES", isupport_string, "&#");
275 add_isupport("EXCEPTS", isupport_boolean, &ConfigChannel.use_except);
276 add_isupport("INVEX", isupport_boolean, &ConfigChannel.use_invex);
277 add_isupport("CHANMODES", isupport_chanmodes, NULL);
278 add_isupport("CHANLIMIT", isupport_chanlimit, NULL);
279 add_isupport("PREFIX", isupport_string, "(ov)@+");
280 add_isupport("MAXLIST", isupport_maxlist, NULL);
281 add_isupport("MODES", isupport_intptr, &maxmodes);
282 add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name);
283 add_isupport("KNOCK", isupport_boolean, &ConfigChannel.use_knock);
284 add_isupport("STATUSMSG", isupport_string, "@+");
285 add_isupport("CALLERID", isupport_string, "g");
286 add_isupport("SAFELIST", isupport_string, "");
287 add_isupport("ELIST", isupport_string, "U");
288 add_isupport("CASEMAPPING", isupport_string, "rfc1459");
289 add_isupport("CHARSET", isupport_string, "ascii");
290 add_isupport("NICKLEN", isupport_intptr, &nicklen);
291 add_isupport("CHANNELLEN", isupport_intptr, &channellen);
292 add_isupport("TOPICLEN", isupport_intptr, &topiclen);
293 add_isupport("ETRACE", isupport_string, "");
294 add_isupport("CPRIVMSG", isupport_string, "");
295 add_isupport("CNOTICE", isupport_string, "");
296 add_isupport("DEAF", isupport_string, "D");
297 add_isupport("MONITOR", isupport_intptr, &ConfigFileEntry.max_monitor);
298 add_isupport("FNC", isupport_string, "");
299 add_isupport("TARGMAX", isupport_targmax, NULL);
300 add_isupport("EXTBAN", isupport_extban, NULL);
301}