1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2015 ircd-hybrid development team |
4 |
> |
* Copyright (c) 1997-2016 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
38 |
|
#include "motd.h" |
39 |
|
#include "numeric.h" |
40 |
|
#include "conf.h" |
41 |
+ |
#include "conf_gecos.h" |
42 |
|
#include "log.h" |
43 |
|
#include "server.h" |
44 |
|
#include "send.h" |
49 |
|
#include "misc.h" |
50 |
|
#include "parse.h" |
51 |
|
#include "watch.h" |
52 |
+ |
#include "isupport.h" |
53 |
+ |
#include "tls.h" |
54 |
|
|
55 |
|
static char umode_buffer[IRCD_BUFSIZE]; |
56 |
|
|
54 |
– |
/* Used for building up the isupport string, |
55 |
– |
* used with init_isupport, add_isupport, delete_isupport |
56 |
– |
*/ |
57 |
– |
struct Isupport |
58 |
– |
{ |
59 |
– |
dlink_node node; |
60 |
– |
char *name; |
61 |
– |
char *options; |
62 |
– |
int number; |
63 |
– |
}; |
64 |
– |
|
65 |
– |
static dlink_list support_list; |
66 |
– |
static dlink_list support_list_lines; |
67 |
– |
|
57 |
|
const struct user_modes *umode_map[256]; |
58 |
|
const struct user_modes umode_tab[] = |
59 |
|
{ |
89 |
|
}; |
90 |
|
|
91 |
|
void |
92 |
< |
user_usermodes_init(void) |
92 |
> |
user_modes_init(void) |
93 |
|
{ |
94 |
|
char *umode_buffer_ptr = umode_buffer; |
95 |
|
|
151 |
|
Count.max_loc_con = Count.local + Count.myserver; |
152 |
|
} |
153 |
|
|
165 |
– |
/* show_isupport() |
166 |
– |
* |
167 |
– |
* inputs - pointer to client |
168 |
– |
* output - NONE |
169 |
– |
* side effects - display to client what we support (for them) |
170 |
– |
*/ |
171 |
– |
void |
172 |
– |
show_isupport(struct Client *source_p) |
173 |
– |
{ |
174 |
– |
const dlink_node *node = NULL; |
175 |
– |
|
176 |
– |
DLINK_FOREACH(node, support_list_lines.head) |
177 |
– |
sendto_one_numeric(source_p, &me, RPL_ISUPPORT, node->data); |
178 |
– |
} |
179 |
– |
|
180 |
– |
|
154 |
|
/* report_and_set_user_flags() |
155 |
|
* |
156 |
|
* inputs - pointer to source_p |
164 |
|
{ |
165 |
|
/* If this user is being spoofed, tell them so */ |
166 |
|
if (IsConfDoSpoofIp(conf)) |
167 |
< |
sendto_one_notice(source_p, &me, ":*** Spoofing your IP. Congrats."); |
167 |
> |
sendto_one_notice(source_p, &me, ":*** Spoofing your IP"); |
168 |
|
|
169 |
|
/* If this user is in the exception class, set it "E lined" */ |
170 |
|
if (IsConfExemptKline(conf)) |
171 |
|
{ |
172 |
< |
SetExemptKline(source_p); |
173 |
< |
sendto_one_notice(source_p, &me, ":*** You are exempt from K/D lines. Congrats."); |
172 |
> |
AddFlag(source_p, FLAGS_EXEMPTKLINE); |
173 |
> |
sendto_one_notice(source_p, &me, ":*** You are exempt from K/D lines"); |
174 |
|
} |
175 |
|
|
176 |
|
if (IsConfExemptXline(conf)) |
177 |
|
{ |
178 |
< |
SetExemptXline(source_p); |
179 |
< |
sendto_one_notice(source_p, &me, ":*** You are exempt from X lines. Congrats."); |
178 |
> |
AddFlag(source_p, FLAGS_EXEMPTXLINE); |
179 |
> |
sendto_one_notice(source_p, &me, ":*** You are exempt from X lines"); |
180 |
|
} |
181 |
|
|
182 |
|
if (IsConfExemptResv(conf)) |
183 |
|
{ |
184 |
< |
SetExemptResv(source_p); |
185 |
< |
sendto_one_notice(source_p, &me, ":*** You are exempt from resvs. Congrats."); |
184 |
> |
AddFlag(source_p, FLAGS_EXEMPTRESV); |
185 |
> |
sendto_one_notice(source_p, &me, ":*** You are exempt from resvs"); |
186 |
|
} |
187 |
|
|
188 |
|
/* If this user is exempt from user limits set it "F lined" */ |
189 |
|
if (IsConfExemptLimits(conf)) |
190 |
|
{ |
191 |
< |
SetExemptLimits(source_p); |
192 |
< |
sendto_one_notice(source_p, &me, ":*** You are exempt from user limits. Congrats."); |
191 |
> |
AddFlag(source_p, FLAGS_NOLIMIT); |
192 |
> |
sendto_one_notice(source_p, &me, ":*** You are exempt from user limits"); |
193 |
|
} |
194 |
|
|
195 |
|
if (IsConfCanFlood(conf)) |
196 |
|
{ |
197 |
< |
SetCanFlood(source_p); |
198 |
< |
sendto_one_notice(source_p, &me, ":*** You are exempt from flood " |
226 |
< |
"protection, aren't you fearsome."); |
197 |
> |
AddFlag(source_p, FLAGS_CANFLOOD); |
198 |
> |
sendto_one_notice(source_p, &me, ":*** You are exempt from flood protection"); |
199 |
|
} |
200 |
|
} |
201 |
|
|
213 |
|
dlink_node *node = NULL; |
214 |
|
char ubuf[IRCD_BUFSIZE] = ""; |
215 |
|
|
216 |
< |
if (MyClient(source_p)) |
216 |
> |
if (MyConnect(source_p)) |
217 |
|
send_umode(source_p, source_p, 0, ubuf); |
218 |
|
else |
219 |
|
send_umode(NULL, source_p, 0, ubuf); |
233 |
|
if (server == source_p->from) |
234 |
|
continue; |
235 |
|
|
236 |
< |
if (IsCapable(server, CAP_SVS)) |
237 |
< |
sendto_one(server, ":%s UID %s %u %lu %s %s %s %s %s %s :%s", |
238 |
< |
source_p->servptr->id, |
239 |
< |
source_p->name, source_p->hopcount+1, |
240 |
< |
(unsigned long)source_p->tsinfo, |
241 |
< |
ubuf, source_p->username, source_p->host, |
242 |
< |
source_p->sockhost, source_p->id, |
243 |
< |
source_p->account, |
272 |
< |
source_p->info); |
273 |
< |
else |
274 |
< |
sendto_one(server, ":%s UID %s %u %lu %s %s %s %s %s :%s", |
275 |
< |
source_p->servptr->id, |
276 |
< |
source_p->name, source_p->hopcount+1, |
277 |
< |
(unsigned long)source_p->tsinfo, |
278 |
< |
ubuf, source_p->username, source_p->host, |
279 |
< |
source_p->sockhost, source_p->id, source_p->info); |
236 |
> |
sendto_one(server, ":%s UID %s %u %ju %s %s %s %s %s %s :%s", |
237 |
> |
source_p->servptr->id, |
238 |
> |
source_p->name, source_p->hopcount+1, |
239 |
> |
source_p->tsinfo, |
240 |
> |
ubuf, source_p->username, source_p->host, |
241 |
> |
source_p->sockhost, source_p->id, |
242 |
> |
source_p->account, |
243 |
> |
source_p->info); |
244 |
|
|
245 |
|
if (!EmptyString(source_p->certfp)) |
246 |
|
sendto_one(server, ":%s CERTFP %s", source_p->id, source_p->certfp); |
256 |
|
static void |
257 |
|
user_welcome(struct Client *source_p) |
258 |
|
{ |
295 |
– |
#if defined(__TIME__) && defined(__DATE__) |
259 |
|
static const char built_date[] = __DATE__ " at " __TIME__; |
297 |
– |
#else |
298 |
– |
static const char built_date[] = "unknown"; |
299 |
– |
#endif |
260 |
|
|
301 |
– |
#ifdef HAVE_LIBCRYPTO |
261 |
|
if (HasFlag(source_p, FLAGS_SSL)) |
262 |
|
{ |
263 |
|
AddUMode(source_p, UMODE_SSL); |
264 |
|
sendto_one_notice(source_p, &me, ":*** Connected securely via %s", |
265 |
< |
ssl_get_cipher(source_p->connection->fd.ssl)); |
265 |
> |
tls_get_cipher(&source_p->connection->fd.ssl)); |
266 |
|
} |
308 |
– |
#endif |
267 |
|
|
268 |
|
sendto_one_numeric(source_p, &me, RPL_WELCOME, ConfigServerInfo.network_name, |
269 |
|
source_p->name); |
270 |
|
sendto_one_numeric(source_p, &me, RPL_YOURHOST, |
271 |
< |
get_listener_name(source_p->connection->listener), ircd_version); |
271 |
> |
listener_get_name(source_p->connection->listener), ircd_version); |
272 |
|
sendto_one_numeric(source_p, &me, RPL_CREATED, built_date); |
273 |
|
sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer); |
316 |
– |
show_isupport(source_p); |
317 |
– |
sendto_one_numeric(source_p, &me, RPL_YOURID, source_p->id); |
274 |
|
|
275 |
+ |
isupport_show(source_p); |
276 |
|
show_lusers(source_p); |
277 |
|
motd_signon(source_p); |
278 |
|
} |
286 |
|
static int |
287 |
|
check_xline(struct Client *source_p) |
288 |
|
{ |
289 |
< |
struct MaskItem *conf = NULL; |
289 |
> |
const struct GecosItem *gecos = NULL; |
290 |
|
|
291 |
< |
if (IsExemptXline(source_p)) |
291 |
> |
if (HasFlag(source_p, FLAGS_EXEMPTXLINE)) |
292 |
|
return 0; |
293 |
|
|
294 |
< |
if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0))) |
294 |
> |
if ((gecos = gecos_find(source_p->info, match))) |
295 |
|
{ |
339 |
– |
++conf->count; |
296 |
|
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
297 |
|
"X-line Rejecting [%s] [%s], user %s [%s]", |
298 |
< |
source_p->info, conf->reason, |
298 |
> |
source_p->info, gecos->reason, |
299 |
|
get_client_name(source_p, HIDE_IP), |
300 |
|
source_p->sockhost); |
301 |
|
|
315 |
|
void |
316 |
|
register_local_user(struct Client *source_p) |
317 |
|
{ |
362 |
– |
const char *id = NULL; |
318 |
|
const struct MaskItem *conf = NULL; |
319 |
|
|
320 |
|
assert(source_p == source_p->from); |
324 |
|
|
325 |
|
if (ConfigGeneral.ping_cookie) |
326 |
|
{ |
327 |
< |
if (!IsPingSent(source_p) && !source_p->connection->random_ping) |
327 |
> |
if (!HasFlag(source_p, FLAGS_PINGSENT) && !source_p->connection->random_ping) |
328 |
|
{ |
329 |
|
do |
330 |
|
source_p->connection->random_ping = genrand_int32(); |
331 |
|
while (!source_p->connection->random_ping); |
332 |
|
|
333 |
|
sendto_one(source_p, "PING :%u", source_p->connection->random_ping); |
334 |
< |
SetPingSent(source_p); |
334 |
> |
AddFlag(source_p, FLAGS_PINGSENT); |
335 |
|
return; |
336 |
|
} |
337 |
|
|
338 |
< |
if (!HasPingCookie(source_p)) |
338 |
> |
if (!HasFlag(source_p, FLAGS_PING_COOKIE)) |
339 |
|
return; |
340 |
|
} |
341 |
|
|
355 |
|
|
356 |
|
conf = source_p->connection->confs.head->data; |
357 |
|
|
358 |
< |
if (!IsGotId(source_p)) |
358 |
> |
if (!HasFlag(source_p, FLAGS_GOTID)) |
359 |
|
{ |
360 |
|
char username[USERLEN + 1] = ""; |
406 |
– |
const char *p = username; |
361 |
|
unsigned int i = 0; |
362 |
|
|
363 |
|
if (IsNeedIdentd(conf)) |
374 |
|
if (!IsNoTilde(conf)) |
375 |
|
source_p->username[i++] = '~'; |
376 |
|
|
377 |
< |
for (; *p && i < USERLEN; ++p) |
377 |
> |
for (const char *p = username; *p && i < USERLEN; ++p) |
378 |
|
source_p->username[i++] = *p; |
379 |
|
|
380 |
|
source_p->username[i] = '\0'; |
416 |
|
* -Taner |
417 |
|
*/ |
418 |
|
if ((Count.local >= GlobalSetOptions.maxclients + MAX_BUFFER) || |
419 |
< |
(Count.local >= GlobalSetOptions.maxclients && !IsExemptLimits(source_p))) |
419 |
> |
(Count.local >= GlobalSetOptions.maxclients && !HasFlag(source_p, FLAGS_NOLIMIT))) |
420 |
|
{ |
421 |
|
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
422 |
|
"Too many clients, rejecting %s[%s].", |
442 |
|
if (check_xline(source_p)) |
443 |
|
return; |
444 |
|
|
445 |
+ |
const char *id; |
446 |
|
while (hash_find_id((id = uid_get()))) |
447 |
|
; |
448 |
|
|
467 |
|
Count.max_loc = Count.local; |
468 |
|
|
469 |
|
if (!(Count.max_loc % 10)) |
470 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
470 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
471 |
|
"New maximum local client connections: %u", |
472 |
|
Count.max_loc); |
473 |
|
} |
487 |
|
&unknown_list, &local_client_list); |
488 |
|
|
489 |
|
user_welcome(source_p); |
490 |
< |
add_user_host(source_p->username, source_p->host, 0); |
491 |
< |
SetUserHost(source_p); |
490 |
> |
userhost_add(source_p->username, source_p->host, 0); |
491 |
> |
AddFlag(source_p, FLAGS_USERHOST); |
492 |
|
|
493 |
|
introduce_client(source_p); |
494 |
|
} |
538 |
|
SetClient(source_p); |
539 |
|
dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list); |
540 |
|
dlinkAdd(source_p, &source_p->node, &global_client_list); |
541 |
< |
add_user_host(source_p->username, source_p->host, 1); |
542 |
< |
SetUserHost(source_p); |
541 |
> |
userhost_add(source_p->username, source_p->host, 1); |
542 |
> |
AddFlag(source_p, FLAGS_USERHOST); |
543 |
|
|
544 |
|
if (HasFlag(source_p->servptr, FLAGS_EOB)) |
545 |
|
sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE, |
591 |
|
int |
592 |
|
valid_username(const char *username, const int local) |
593 |
|
{ |
639 |
– |
unsigned int dots = 0; |
594 |
|
const char *p = username; |
595 |
|
|
596 |
|
assert(p); |
608 |
|
|
609 |
|
if (local) |
610 |
|
{ |
611 |
+ |
unsigned int dots = 0; |
612 |
+ |
|
613 |
|
while (*++p) |
614 |
|
{ |
615 |
|
if (*p == '.' && ConfigGeneral.dots_in_ident) |
667 |
|
* inputs - client_p |
668 |
|
* - source_p |
669 |
|
* - int old |
714 |
– |
* - sendmask mask of modes to send |
670 |
|
* - suplied umode_buf |
671 |
|
* output - NONE |
672 |
|
*/ |
753 |
|
} |
754 |
|
|
755 |
|
if (ConfigGeneral.cycle_on_host_change) |
756 |
< |
sendto_common_channels_local(target_p, 0, 0, ":%s!%s@%s QUIT :Changing hostname", |
756 |
> |
sendto_common_channels_local(target_p, 0, 0, CAP_CHGHOST, ":%s!%s@%s QUIT :Changing hostname", |
757 |
|
target_p->name, target_p->username, target_p->host); |
758 |
|
|
759 |
< |
if (IsUserHostIp(target_p)) |
760 |
< |
delete_user_host(target_p->username, target_p->host, !MyConnect(target_p)); |
759 |
> |
sendto_common_channels_local(target_p, 0, CAP_CHGHOST, 0, ":%s!%s@%s CHGHOST %s %s", |
760 |
> |
target_p->name, target_p->username, |
761 |
> |
target_p->host, target_p->username, hostname); |
762 |
> |
|
763 |
> |
if (HasFlag(target_p, FLAGS_USERHOST)) |
764 |
> |
userhost_del(target_p->username, target_p->host, !MyConnect(target_p)); |
765 |
|
|
766 |
|
strlcpy(target_p->host, hostname, sizeof(target_p->host)); |
767 |
|
|
768 |
< |
add_user_host(target_p->username, target_p->host, !MyConnect(target_p)); |
769 |
< |
SetUserHost(target_p); |
768 |
> |
userhost_add(target_p->username, target_p->host, !MyConnect(target_p)); |
769 |
> |
AddFlag(target_p, FLAGS_USERHOST); |
770 |
|
|
771 |
< |
if (MyClient(target_p)) |
771 |
> |
if (MyConnect(target_p)) |
772 |
|
{ |
773 |
|
sendto_one_numeric(target_p, &me, RPL_VISIBLEHOST, target_p->host); |
774 |
|
clear_ban_cache_client(target_p); |
779 |
|
|
780 |
|
DLINK_FOREACH(node, target_p->channel.head) |
781 |
|
{ |
782 |
< |
char modebuf[4], nickbuf[NICKLEN * 3 + 3] = ""; |
782 |
> |
char modebuf[CMEMBER_STATUS_FLAGS_LEN + 1]; |
783 |
> |
char nickbuf[CMEMBER_STATUS_FLAGS_LEN * NICKLEN + CMEMBER_STATUS_FLAGS_LEN] = ""; |
784 |
|
char *p = modebuf; |
785 |
|
int len = 0; |
786 |
|
const struct Membership *member = node->data; |
805 |
|
|
806 |
|
*p = '\0'; |
807 |
|
|
808 |
< |
|
809 |
< |
sendto_channel_local_butone(target_p, CAP_EXTENDED_JOIN, 0, member->chptr, ":%s!%s@%s JOIN %s %s :%s", |
810 |
< |
target_p->name, target_p->username, |
811 |
< |
target_p->host, member->chptr->name, |
812 |
< |
(!IsDigit(target_p->account[0]) && target_p->account[0] != '*') ? target_p->account : "*", |
813 |
< |
target_p->info); |
814 |
< |
sendto_channel_local_butone(target_p, 0, CAP_EXTENDED_JOIN, member->chptr, ":%s!%s@%s JOIN :%s", |
855 |
< |
target_p->name, target_p->username, |
856 |
< |
target_p->host, member->chptr->name); |
808 |
> |
sendto_channel_local(target_p, member->chptr, 0, CAP_EXTENDED_JOIN, CAP_CHGHOST, ":%s!%s@%s JOIN %s %s :%s", |
809 |
> |
target_p->name, target_p->username, |
810 |
> |
target_p->host, member->chptr->name, |
811 |
> |
target_p->account, target_p->info); |
812 |
> |
sendto_channel_local(target_p, member->chptr, 0, 0, CAP_EXTENDED_JOIN | CAP_CHGHOST, ":%s!%s@%s JOIN :%s", |
813 |
> |
target_p->name, target_p->username, |
814 |
> |
target_p->host, member->chptr->name); |
815 |
|
|
816 |
|
if (nickbuf[0]) |
817 |
< |
sendto_channel_local_butone(target_p, 0, 0, member->chptr, ":%s MODE %s +%s %s", |
818 |
< |
target_p->servptr->name, member->chptr->name, |
819 |
< |
modebuf, nickbuf); |
862 |
< |
|
817 |
> |
sendto_channel_local(target_p, member->chptr, 0, 0, CAP_CHGHOST, ":%s MODE %s +%s %s", |
818 |
> |
target_p->servptr->name, member->chptr->name, |
819 |
> |
modebuf, nickbuf); |
820 |
|
} |
821 |
|
|
822 |
|
if (target_p->away[0]) |
823 |
< |
sendto_common_channels_local(target_p, 0, CAP_AWAY_NOTIFY, |
823 |
> |
sendto_common_channels_local(target_p, 0, CAP_AWAY_NOTIFY, CAP_CHGHOST, |
824 |
|
":%s!%s@%s AWAY :%s", |
825 |
|
target_p->name, target_p->username, |
826 |
|
target_p->host, target_p->away); |
827 |
|
} |
871 |
– |
|
872 |
– |
/*! \brief Blindly opers up given source_p, using conf info. |
873 |
– |
* All checks on passwords have already been done. |
874 |
– |
* \param source_p Pointer to given client to oper |
875 |
– |
*/ |
876 |
– |
void |
877 |
– |
oper_up(struct Client *source_p) |
878 |
– |
{ |
879 |
– |
const unsigned int old = source_p->umodes; |
880 |
– |
const struct MaskItem *const conf = source_p->connection->confs.head->data; |
881 |
– |
|
882 |
– |
assert(source_p->connection->confs.head); |
883 |
– |
|
884 |
– |
++Count.oper; |
885 |
– |
SetOper(source_p); |
886 |
– |
|
887 |
– |
if (conf->modes) |
888 |
– |
AddUMode(source_p, conf->modes); |
889 |
– |
else if (ConfigGeneral.oper_umodes) |
890 |
– |
AddUMode(source_p, ConfigGeneral.oper_umodes); |
891 |
– |
|
892 |
– |
if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE)) |
893 |
– |
++Count.invisi; |
894 |
– |
if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE)) |
895 |
– |
--Count.invisi; |
896 |
– |
|
897 |
– |
assert(dlinkFind(&oper_list, source_p) == NULL); |
898 |
– |
dlinkAdd(source_p, make_dlink_node(), &oper_list); |
899 |
– |
|
900 |
– |
AddOFlag(source_p, conf->port); |
901 |
– |
|
902 |
– |
if (HasOFlag(source_p, OPER_FLAG_ADMIN)) |
903 |
– |
AddUMode(source_p, UMODE_ADMIN); |
904 |
– |
|
905 |
– |
if (!EmptyString(conf->whois)) |
906 |
– |
{ |
907 |
– |
client_attach_svstag(source_p, RPL_WHOISOPERATOR, "+", conf->whois); |
908 |
– |
sendto_server(source_p, 0, 0, ":%s SVSTAG %s %lu %u + :%s", |
909 |
– |
me.id, source_p->id, (unsigned long)source_p->tsinfo, |
910 |
– |
RPL_WHOISOPERATOR, conf->whois); |
911 |
– |
} |
912 |
– |
|
913 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s is now an operator", |
914 |
– |
get_oper_name(source_p)); |
915 |
– |
sendto_server(NULL, 0, 0, ":%s GLOBOPS :%s is now an operator", |
916 |
– |
me.id, get_oper_name(source_p)); |
917 |
– |
send_umode_out(source_p, old); |
918 |
– |
sendto_one_numeric(source_p, &me, RPL_YOUREOPER); |
919 |
– |
} |
920 |
– |
|
921 |
– |
/* |
922 |
– |
* init_isupport() |
923 |
– |
* |
924 |
– |
* input - NONE |
925 |
– |
* output - NONE |
926 |
– |
* side effects - Must be called before isupport is enabled |
927 |
– |
*/ |
928 |
– |
void |
929 |
– |
init_isupport(void) |
930 |
– |
{ |
931 |
– |
add_isupport("CALLERID", NULL, -1); |
932 |
– |
add_isupport("CASEMAPPING", "rfc1459", -1); |
933 |
– |
add_isupport("DEAF", "D", -1); |
934 |
– |
add_isupport("KICKLEN", NULL, KICKLEN); |
935 |
– |
add_isupport("MODES", NULL, MAXMODEPARAMS); |
936 |
– |
add_isupport("PREFIX", "(ohv)@%+", -1); |
937 |
– |
add_isupport("STATUSMSG", "@%+", -1); |
938 |
– |
add_isupport("EXCEPTS", NULL, -1); |
939 |
– |
add_isupport("INVEX", NULL, -1); |
940 |
– |
} |
941 |
– |
|
942 |
– |
/* |
943 |
– |
* add_isupport() |
944 |
– |
* |
945 |
– |
* input - name of supported function |
946 |
– |
* - options if any |
947 |
– |
* - number if any |
948 |
– |
* output - NONE |
949 |
– |
* side effects - Each supported item must call this when activated |
950 |
– |
*/ |
951 |
– |
void |
952 |
– |
add_isupport(const char *name, const char *options, int n) |
953 |
– |
{ |
954 |
– |
dlink_node *node = NULL; |
955 |
– |
struct Isupport *support = NULL; |
956 |
– |
|
957 |
– |
DLINK_FOREACH(node, support_list.head) |
958 |
– |
{ |
959 |
– |
support = node->data; |
960 |
– |
if (irccmp(support->name, name) == 0) |
961 |
– |
{ |
962 |
– |
MyFree(support->name); |
963 |
– |
MyFree(support->options); |
964 |
– |
break; |
965 |
– |
} |
966 |
– |
} |
967 |
– |
|
968 |
– |
if (node == NULL) |
969 |
– |
{ |
970 |
– |
support = MyCalloc(sizeof(*support)); |
971 |
– |
dlinkAddTail(support, &support->node, &support_list); |
972 |
– |
} |
973 |
– |
|
974 |
– |
support->name = xstrdup(name); |
975 |
– |
if (options) |
976 |
– |
support->options = xstrdup(options); |
977 |
– |
support->number = n; |
978 |
– |
|
979 |
– |
rebuild_isupport_message_line(); |
980 |
– |
} |
981 |
– |
|
982 |
– |
/* |
983 |
– |
* delete_isupport() |
984 |
– |
* |
985 |
– |
* input - name of supported function |
986 |
– |
* output - NONE |
987 |
– |
* side effects - Each supported item must call this when deactivated |
988 |
– |
*/ |
989 |
– |
void |
990 |
– |
delete_isupport(const char *name) |
991 |
– |
{ |
992 |
– |
dlink_node *node = NULL; |
993 |
– |
|
994 |
– |
DLINK_FOREACH(node, support_list.head) |
995 |
– |
{ |
996 |
– |
struct Isupport *support = node->data; |
997 |
– |
|
998 |
– |
if (irccmp(support->name, name) == 0) |
999 |
– |
{ |
1000 |
– |
dlinkDelete(node, &support_list); |
1001 |
– |
MyFree(support->name); |
1002 |
– |
MyFree(support->options); |
1003 |
– |
MyFree(support); |
1004 |
– |
break; |
1005 |
– |
} |
1006 |
– |
} |
1007 |
– |
|
1008 |
– |
rebuild_isupport_message_line(); |
1009 |
– |
} |
1010 |
– |
|
1011 |
– |
/* |
1012 |
– |
* rebuild_isupport_message_line |
1013 |
– |
* |
1014 |
– |
* input - NONE |
1015 |
– |
* output - NONE |
1016 |
– |
* side effects - Destroy the isupport MessageFile lines, and rebuild. |
1017 |
– |
*/ |
1018 |
– |
void |
1019 |
– |
rebuild_isupport_message_line(void) |
1020 |
– |
{ |
1021 |
– |
char isupportbuffer[IRCD_BUFSIZE]; |
1022 |
– |
char *p = isupportbuffer; |
1023 |
– |
dlink_node *node = NULL, *node_next = NULL; |
1024 |
– |
int n = 0; |
1025 |
– |
int tokens = 0; |
1026 |
– |
size_t len = 0; |
1027 |
– |
size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT)); |
1028 |
– |
|
1029 |
– |
DLINK_FOREACH_SAFE(node, node_next, support_list_lines.head) |
1030 |
– |
{ |
1031 |
– |
dlinkDelete(node, &support_list_lines); |
1032 |
– |
MyFree(node->data); |
1033 |
– |
free_dlink_node(node); |
1034 |
– |
} |
1035 |
– |
|
1036 |
– |
DLINK_FOREACH(node, support_list.head) |
1037 |
– |
{ |
1038 |
– |
struct Isupport *support = node->data; |
1039 |
– |
|
1040 |
– |
p += (n = sprintf(p, "%s", support->name)); |
1041 |
– |
len += n; |
1042 |
– |
|
1043 |
– |
if (support->options) |
1044 |
– |
{ |
1045 |
– |
p += (n = sprintf(p, "=%s", support->options)); |
1046 |
– |
len += n; |
1047 |
– |
} |
1048 |
– |
|
1049 |
– |
if (support->number > 0) |
1050 |
– |
{ |
1051 |
– |
p += (n = sprintf(p, "=%d", support->number)); |
1052 |
– |
len += n; |
1053 |
– |
} |
1054 |
– |
|
1055 |
– |
*p++ = ' '; |
1056 |
– |
len++; |
1057 |
– |
*p = '\0'; |
1058 |
– |
|
1059 |
– |
if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve)) |
1060 |
– |
{ /* arbritrary for now */ |
1061 |
– |
if (*--p == ' ') |
1062 |
– |
*p = '\0'; |
1063 |
– |
|
1064 |
– |
dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines); |
1065 |
– |
p = isupportbuffer; |
1066 |
– |
len = 0; |
1067 |
– |
n = tokens = 0; |
1068 |
– |
} |
1069 |
– |
} |
1070 |
– |
|
1071 |
– |
if (len) |
1072 |
– |
{ |
1073 |
– |
if (*--p == ' ') |
1074 |
– |
*p = '\0'; |
1075 |
– |
dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines); |
1076 |
– |
} |
1077 |
– |
} |