From 3efe1e07ba2bd0f92dcd1c6d2dd7751cd3bfda96 Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Wed, 14 Oct 2026 02:51:03 +0000 Subject: [PATCH 1/6] Add IRCv3 CAP negotiation skeleton with a static capability registry Implements CAP LS [302], LIST, REQ and END. Capabilities are listed in clientcaps[] in caps.c and checked with HasCap(). Registration is held from the first CAP LS/REQ until CAP END. REQ is applied atomically (ACK or NAK for the whole list, -cap disables). cap-notify is the only built-in capability and is enabled implicitly by CAP LS 302. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- include/caps.h | 49 ++++++++++ include/msg.h | 3 + include/numeric.h | 1 + include/struct.h | 3 + src/Makefile.in | 2 +- src/caps.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++ src/m_nick.c | 3 +- src/s_err.c | 2 +- src/s_user.c | 4 +- 9 files changed, 290 insertions(+), 4 deletions(-) create mode 100644 include/caps.h create mode 100644 src/caps.c diff --git a/include/caps.h b/include/caps.h new file mode 100644 index 00000000..36d7c1aa --- /dev/null +++ b/include/caps.h @@ -0,0 +1,49 @@ +/* + * IRC - Internet Relay Chat, include/caps.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef CAPS_H +#define CAPS_H + +/* + * IRCv3 client capabilities (CAP). + * + * To add a capability: define a new CAP_ bit here, add an entry to + * clientcaps[] in caps.c, and check it with HasCap() where the + * capability changes behavior. + */ + +#define CAP_CAP_NOTIFY 0x00000001 /* cap-notify */ + +#define CAPF_STICKY_302 0x0001 /* cannot be disabled after CAP LS 302 */ + +typedef struct ClientCap aClientCap; + +struct ClientCap +{ + char *name; + unsigned int bit; + char *value; /* advertised as name=value with CAP LS 302 */ + int flags; +}; + +#define HasCap(x, c) (MyConnect(x) && ((x)->caps & (c))) +#define IsCapNegotiating(x) (MyConnect(x) && (x)->cap_negotiating) + +extern int m_cap(aClient *, aClient *, int, char **); + +#endif diff --git a/include/msg.h b/include/msg.h index c155fbae..b8403017 100644 --- a/include/msg.h +++ b/include/msg.h @@ -131,6 +131,7 @@ #define MSG_POST "POST" /* POST */ #define MSG_CHECK "CHECK" /* CHECK */ +#define MSG_CAP "CAP" /* IRCv3 capability negotiation */ #define MSG_WEBIRC "WEBIRC" /* WEBIRC */ #define MAXPARA 15 @@ -233,6 +234,7 @@ extern int m_put(aClient *, aClient *, int, char **); extern int m_post(aClient *, aClient *, int, char **); extern int m_check(aClient *, aClient *, int, char **); extern int m_webirc(aClient *, aClient *, int, char **); +extern int m_cap(aClient *, aClient *, int, char **); extern int m_spamops(aClient *, aClient *, int, char **); extern int m_sf(aClient *, aClient *, int, char **); extern int m_aj(aClient *, aClient *, int, char **); @@ -383,6 +385,7 @@ struct Message msgtab[] = {"AJ", m_aj, MAXPARA, 0, 0}, {"SJR", m_sjr, MAXPARA, MF_ALIAS, AII_NS}, {MSG_WEBIRC, m_webirc, MAXPARA, MF_UNREG, 0}, + {MSG_CAP, m_cap, MAXPARA, MF_UNREG, 0}, { 0 } }; #ifdef __clang__ diff --git a/include/numeric.h b/include/numeric.h index 624cc308..289a3ca4 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -182,6 +182,7 @@ #define ERR_NOTOPLEVEL 413 #define ERR_WILDTOPLEVEL 414 +#define ERR_INVALIDCAPCMD 410 #define ERR_UNKNOWNCOMMAND 421 #define ERR_NOMOTD 422 #define ERR_NOADMININFO 423 diff --git a/include/struct.h b/include/struct.h index 1988200d..fbe26381 100644 --- a/include/struct.h +++ b/include/struct.h @@ -1057,6 +1057,9 @@ struct Client int sockerr; /* what was the last error returned for * this socket? */ int capabilities; /* what this server/client supports */ + unsigned int caps; /* IRCv3 capabilities enabled (CAP_*) */ + int cap_version; /* CAP LS version, e.g. 302 */ + char cap_negotiating; /* registration held until CAP END */ aClass *class; /* our current effective class */ #ifdef MSG_TARGET_LIMIT diff --git a/src/Makefile.in b/src/Makefile.in index 23e159ed..1871d52b 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -24,7 +24,7 @@ SOURCES = blalloc.c bsd.c channel.c clientlist.c clones.c confparse.c \ probability.c res.c s_auth.c s_bsd.c s_conf.c s_debug.c s_err.c \ s_misc.c s_numeric.c s_serv.c s_user.c sbuf.c scache.c send.c \ struct.c support.c throttle.c userban.c whowas.c zlink.c ssl.c \ - bitncmp.c inet_parse_cidr.c m_webirc.c spamfilter.c \ + bitncmp.c inet_parse_cidr.c m_webirc.c spamfilter.c caps.c \ $(ENGINE) $(CRYPTO) $(RES_SRC) OBJECTS = $(SOURCES:.c=.o) version.o diff --git a/src/caps.c b/src/caps.c new file mode 100644 index 00000000..fa291681 --- /dev/null +++ b/src/caps.c @@ -0,0 +1,227 @@ +/* + * IRC - Internet Relay Chat, src/caps.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * IRCv3 client capability negotiation. + * See https://ircv3.net/specs/extensions/capability-negotiation + */ + +#include "struct.h" +#include "common.h" +#include "sys.h" +#include "numeric.h" +#include "h.h" +#include "caps.h" + +extern int register_user(aClient *, aClient *, char *, char *, char *); + +/* leave room for ":server CAP nick LS * :" within the 512 byte limit */ +#define CAP_LINELEN 400 + +static aClientCap clientcaps[] = +{ + { "cap-notify", CAP_CAP_NOTIFY, NULL, CAPF_STICKY_302 }, + { NULL, 0, NULL, 0 } +}; + +static aClientCap * +find_cap(char *name) +{ + aClientCap *cap; + + for (cap = clientcaps; cap->name; cap++) + if (!strcmp(cap->name, name)) + return cap; + return NULL; +} + +static char * +cap_nick(aClient *sptr) +{ + return *sptr->name ? sptr->name : "*"; +} + +/* + * send_caps - send the capabilities in mask as CAP , split over + * several lines if needed. CAP 302 clients get a "*" continuation + * marker on all but the last line and name=value pairs. + */ +static void +send_caps(aClient *sptr, char *subcmd, unsigned int mask) +{ + char buf[BUFSIZE], tok[BUFSIZE]; + aClientCap *cap; + int v302 = (sptr->cap_version >= 302); + int len = 0, n; + + *buf = '\0'; + for (cap = clientcaps; cap->name; cap++) + { + if (!(mask & cap->bit)) + continue; + + if (v302 && cap->value) + ircsnprintf(tok, sizeof(tok), "%s=%s", cap->name, cap->value); + else + strncpyzt(tok, cap->name, sizeof(tok)); + n = strlen(tok); + + if (len && len + 1 + n > CAP_LINELEN) + { + sendto_one(sptr, ":%s CAP %s %s %s:%s", me.name, cap_nick(sptr), + subcmd, v302 ? "* " : "", buf); + len = 0; + *buf = '\0'; + } + + if (len) + buf[len++] = ' '; + strcpy(buf + len, tok); + len += n; + } + + sendto_one(sptr, ":%s CAP %s %s :%s", me.name, cap_nick(sptr), subcmd, + buf); +} + +static int +cap_ls(aClient *sptr, int parc, char *parv[]) +{ + if (!IsRegistered(sptr)) + sptr->cap_negotiating = 1; + + if (parc > 2 && atoi(parv[2]) >= 302 && sptr->cap_version < 302) + { + sptr->cap_version = 302; + sptr->caps |= CAP_CAP_NOTIFY; + } + + send_caps(sptr, "LS", ~0U); + return 0; +} + +static int +cap_list(aClient *sptr) +{ + send_caps(sptr, "LIST", sptr->caps); + return 0; +} + +/* + * cap_req - the request is applied atomically: either every capability + * in it is changed and the whole request is ACKed, or none are and it + * is NAKed. + */ +static int +cap_req(aClient *sptr, int parc, char *parv[]) +{ + char reqbuf[BUFSIZE], *tok, *p = NULL; + unsigned int add = 0, del = 0; + aClientCap *cap; + int neg; + + if (parc < 3 || BadPtr(parv[2])) + { + sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, + cap_nick(sptr), "CAP"); + return 0; + } + + if (!IsRegistered(sptr)) + sptr->cap_negotiating = 1; + + strncpyzt(reqbuf, parv[2], sizeof(reqbuf)); + for (tok = strtoken(&p, reqbuf, " "); tok; tok = strtoken(&p, NULL, " ")) + { + neg = (*tok == '-'); + if (neg) + tok++; + + cap = find_cap(tok); + if (!cap || (neg && (cap->flags & CAPF_STICKY_302) && + sptr->cap_version >= 302)) + { + sendto_one(sptr, ":%s CAP %s NAK :%s", me.name, cap_nick(sptr), + parv[2]); + return 0; + } + + if (neg) + { + del |= cap->bit; + add &= ~cap->bit; + } + else + { + add |= cap->bit; + del &= ~cap->bit; + } + } + + sptr->caps = (sptr->caps | add) & ~del; + sendto_one(sptr, ":%s CAP %s ACK :%s", me.name, cap_nick(sptr), parv[2]); + return 0; +} + +static int +cap_end(aClient *cptr, aClient *sptr) +{ + if (IsRegistered(sptr) || !sptr->cap_negotiating) + return 0; + + sptr->cap_negotiating = 0; + + /* NICK and USER already received, finish registration now */ + if (*sptr->name && sptr->user) + return register_user(cptr, sptr, sptr->name, sptr->user->username, + NULL); + return 0; +} + +/* + * m_cap + * parv[0] = sender prefix + * parv[1] = subcommand (LS, LIST, REQ, END) + * parv[2] = LS version or REQ capability list + */ +int +m_cap(aClient *cptr, aClient *sptr, int parc, char *parv[]) +{ + if (!MyConnect(sptr) || IsServer(sptr)) + return 0; + + if (parc < 2 || BadPtr(parv[1])) + { + sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, + cap_nick(sptr), "CAP"); + return 0; + } + + if (!mycmp(parv[1], "LS")) + return cap_ls(sptr, parc, parv); + if (!mycmp(parv[1], "LIST")) + return cap_list(sptr); + if (!mycmp(parv[1], "REQ")) + return cap_req(sptr, parc, parv); + if (!mycmp(parv[1], "END")) + return cap_end(cptr, sptr); + + sendto_one(sptr, err_str(ERR_INVALIDCAPCMD), me.name, cap_nick(sptr), + parv[1]); + return 0; +} diff --git a/src/m_nick.c b/src/m_nick.c index ca133402..59af423d 100644 --- a/src/m_nick.c +++ b/src/m_nick.c @@ -31,6 +31,7 @@ #include "h.h" #include "userban.h" #include "hooks.h" +#include "caps.h" extern int do_user(char *, aClient *, aClient *, char *, char *, char *, unsigned long, char *, char *); @@ -639,7 +640,7 @@ int m_nick(aClient *cptr, aClient *sptr, int parc, char *parv[]) strcpy(sptr->name, nick); sptr->tsinfo = timeofday; - if (sptr->user) + if (sptr->user && !IsCapNegotiating(sptr)) { /* USER already received, now we have NICK */ diff --git a/src/s_err.c b/src/s_err.c index 9a78a63f..148a2c5a 100644 --- a/src/s_err.c +++ b/src/s_err.c @@ -454,7 +454,7 @@ static char *replies[] = /* 408 ERR_NOCTRLSONCHAN */ ":%s 408 %s %s :You cannot use control codes " "on this channel. Not sent: %s", /* 409 ERR_NOORIGIN */ ":%s 409 %s :No origin specified", - /* 410 */ NULL, + /* 410 ERR_INVALIDCAPCMD */ ":%s 410 %s %s :Invalid CAP subcommand", /* 411 ERR_NORECIPIENT */ ":%s 411 %s :No recipient given (%s)", /* 412 ERR_NOTEXTOSEND */ ":%s 412 %s :No text to send", /* 413 ERR_NOTOPLEVEL */ ":%s 413 %s %s :No toplevel domain specified", diff --git a/src/s_user.c b/src/s_user.c index eb6dce29..95a1a026 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -37,6 +37,7 @@ #endif /* FLUD */ #include "userban.h" #include "hooks.h" +#include "caps.h" #include "memcount.h" #include "inet.h" #include "spamfilter.h" @@ -2418,7 +2419,8 @@ do_user(char *nick, aClient *cptr, aClient *sptr, char *username, char *host, } if(MyConnect(sptr)) sptr->oflag=0; - if (sptr->name[0]) /* NICK already received, now I have USER... */ + if (sptr->name[0] && !IsCapNegotiating(sptr)) + /* NICK already received, now I have USER... */ return register_user(cptr, sptr, sptr->name, username, ip); else strncpyzt(sptr->user->username, username, USERLEN + 1); From c18ac25487bf426117f8dc1c8ee57e246cea5967 Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Wed, 28 Oct 2026 18:33:26 +0000 Subject: [PATCH 2/6] CAP: no values in LIST, reject blank and over-long REQ; declare register_user in h.h Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- include/h.h | 1 + src/caps.c | 33 ++++++++++++++++++++++++++------- src/m_nick.c | 1 - 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/h.h b/include/h.h index 201a9abb..4ff3ae4d 100644 --- a/include/h.h +++ b/include/h.h @@ -252,6 +252,7 @@ extern char *get_client_name(aClient *, int); extern char *my_name_for_link(char *, aConnect *); extern char *myctime(time_t), *date(time_t); extern int exit_client(aClient *, aClient *, aClient *, char *); +extern int register_user(aClient *, aClient *, char *, char *, char *); extern void initstats(void); extern char *make_parv_copy(char *, int, char **); extern int exit_banned_client(aClient *, int, char, char *, int); diff --git a/src/caps.c b/src/caps.c index fa291681..d22dcc5d 100644 --- a/src/caps.c +++ b/src/caps.c @@ -28,8 +28,6 @@ #include "h.h" #include "caps.h" -extern int register_user(aClient *, aClient *, char *, char *, char *); - /* leave room for ":server CAP nick LS * :" within the 512 byte limit */ #define CAP_LINELEN 400 @@ -59,10 +57,11 @@ cap_nick(aClient *sptr) /* * send_caps - send the capabilities in mask as CAP , split over * several lines if needed. CAP 302 clients get a "*" continuation - * marker on all but the last line and name=value pairs. + * marker on all but the last line, and name=value pairs if values is set + * (only allowed for LS and NEW). */ static void -send_caps(aClient *sptr, char *subcmd, unsigned int mask) +send_caps(aClient *sptr, char *subcmd, unsigned int mask, int values) { char buf[BUFSIZE], tok[BUFSIZE]; aClientCap *cap; @@ -75,7 +74,7 @@ send_caps(aClient *sptr, char *subcmd, unsigned int mask) if (!(mask & cap->bit)) continue; - if (v302 && cap->value) + if (v302 && values && cap->value) ircsnprintf(tok, sizeof(tok), "%s=%s", cap->name, cap->value); else strncpyzt(tok, cap->name, sizeof(tok)); @@ -111,14 +110,14 @@ cap_ls(aClient *sptr, int parc, char *parv[]) sptr->caps |= CAP_CAP_NOTIFY; } - send_caps(sptr, "LS", ~0U); + send_caps(sptr, "LS", ~0U, 1); return 0; } static int cap_list(aClient *sptr) { - send_caps(sptr, "LIST", sptr->caps); + send_caps(sptr, "LIST", sptr->caps, 0); return 0; } @@ -142,9 +141,29 @@ cap_req(aClient *sptr, int parc, char *parv[]) return 0; } + for (tok = parv[2]; *tok == ' '; tok++) + ; + if (!*tok) + { + sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, + cap_nick(sptr), "CAP"); + return 0; + } + if (!IsRegistered(sptr)) sptr->cap_negotiating = 1; + /* too long to echo back in a single ACK, reject it unchanged */ + if (strlen(parv[2]) > CAP_LINELEN) + { + strncpyzt(reqbuf, parv[2], CAP_LINELEN + 1); + if ((tok = strrchr(reqbuf, ' '))) + *tok = '\0'; + sendto_one(sptr, ":%s CAP %s NAK :%s", me.name, cap_nick(sptr), + reqbuf); + return 0; + } + strncpyzt(reqbuf, parv[2], sizeof(reqbuf)); for (tok = strtoken(&p, reqbuf, " "); tok; tok = strtoken(&p, NULL, " ")) { diff --git a/src/m_nick.c b/src/m_nick.c index 59af423d..34158aa8 100644 --- a/src/m_nick.c +++ b/src/m_nick.c @@ -36,7 +36,6 @@ extern int do_user(char *, aClient *, aClient *, char *, char *, char *, unsigned long, char *, char *); -extern int register_user(aClient *, aClient *, char *, char *, char *); extern int del_dccallow(aClient *, aClient *, int); extern int is_xflags_exempted(aClient *sptr, aChannel *chptr); From b340f5fe034ab52633df3b9e55c4e0753b5fc4cb Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Wed, 28 Oct 2026 18:34:43 +0000 Subject: [PATCH 3/6] Move register_user prototype away from #268's h.h hunk Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- include/h.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/h.h b/include/h.h index 4ff3ae4d..4305c54c 100644 --- a/include/h.h +++ b/include/h.h @@ -252,7 +252,6 @@ extern char *get_client_name(aClient *, int); extern char *my_name_for_link(char *, aConnect *); extern char *myctime(time_t), *date(time_t); extern int exit_client(aClient *, aClient *, aClient *, char *); -extern int register_user(aClient *, aClient *, char *, char *, char *); extern void initstats(void); extern char *make_parv_copy(char *, int, char **); extern int exit_banned_client(aClient *, int, char, char *, int); @@ -268,6 +267,7 @@ extern void verbose_to_opers(aClient *sptr, aChannel *chptr, char *cmd, char *re extern int m_umode(aClient *, aClient *, int, char **); extern int m_names(aClient *, aClient *, int, char **); +extern int register_user(aClient *, aClient *, char *, char *, char *); extern void send_umode(aClient *, aClient *, long, long, char *, int); extern int del_silence(aClient *, char *); From 3ee039d39c0f51e06ff4bce6acaf39124bbb7cfe Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Wed, 28 Oct 2026 18:43:21 +0000 Subject: [PATCH 4/6] Keep ERR_INVALIDCAPCMD in numeric order; simplify CAP REQ cap update Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- include/numeric.h | 2 +- src/caps.c | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/include/numeric.h b/include/numeric.h index 289a3ca4..855ec60c 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -176,13 +176,13 @@ #define ERR_TOOMANYTARGETS 407 #define ERR_NOCTRLSONCHAN 408 #define ERR_NOORIGIN 409 +#define ERR_INVALIDCAPCMD 410 #define ERR_NORECIPIENT 411 #define ERR_NOTEXTTOSEND 412 #define ERR_NOTOPLEVEL 413 #define ERR_WILDTOPLEVEL 414 -#define ERR_INVALIDCAPCMD 410 #define ERR_UNKNOWNCOMMAND 421 #define ERR_NOMOTD 422 #define ERR_NOADMININFO 423 diff --git a/src/caps.c b/src/caps.c index d22dcc5d..2ffdcde1 100644 --- a/src/caps.c +++ b/src/caps.c @@ -130,7 +130,7 @@ static int cap_req(aClient *sptr, int parc, char *parv[]) { char reqbuf[BUFSIZE], *tok, *p = NULL; - unsigned int add = 0, del = 0; + unsigned int newcaps = sptr->caps; aClientCap *cap; int neg; @@ -181,18 +181,12 @@ cap_req(aClient *sptr, int parc, char *parv[]) } if (neg) - { - del |= cap->bit; - add &= ~cap->bit; - } + newcaps &= ~cap->bit; else - { - add |= cap->bit; - del &= ~cap->bit; - } + newcaps |= cap->bit; } - sptr->caps = (sptr->caps | add) & ~del; + sptr->caps = newcaps; sendto_one(sptr, ":%s CAP %s ACK :%s", me.name, cap_nick(sptr), parv[2]); return 0; } From aaaba927c7f4e9466b0fe01b02fa208147dec0e7 Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Wed, 28 Oct 2026 18:50:30 +0000 Subject: [PATCH 5/6] Make client caps a uint64_t Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- include/caps.h | 4 ++-- include/struct.h | 3 ++- src/caps.c | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/caps.h b/include/caps.h index 36d7c1aa..dc22d9fa 100644 --- a/include/caps.h +++ b/include/caps.h @@ -27,7 +27,7 @@ * capability changes behavior. */ -#define CAP_CAP_NOTIFY 0x00000001 /* cap-notify */ +#define CAP_CAP_NOTIFY (1ULL << 0) /* cap-notify */ #define CAPF_STICKY_302 0x0001 /* cannot be disabled after CAP LS 302 */ @@ -36,7 +36,7 @@ typedef struct ClientCap aClientCap; struct ClientCap { char *name; - unsigned int bit; + uint64_t bit; char *value; /* advertised as name=value with CAP LS 302 */ int flags; }; diff --git a/include/struct.h b/include/struct.h index fbe26381..1ef26781 100644 --- a/include/struct.h +++ b/include/struct.h @@ -37,6 +37,7 @@ #include #if defined( HAVE_STDDEF_H ) #include +#include #endif #ifdef ORATIMING #include @@ -1057,7 +1058,7 @@ struct Client int sockerr; /* what was the last error returned for * this socket? */ int capabilities; /* what this server/client supports */ - unsigned int caps; /* IRCv3 capabilities enabled (CAP_*) */ + uint64_t caps; /* IRCv3 capabilities enabled (CAP_*) */ int cap_version; /* CAP LS version, e.g. 302 */ char cap_negotiating; /* registration held until CAP END */ aClass *class; /* our current effective class */ diff --git a/src/caps.c b/src/caps.c index 2ffdcde1..ce991a15 100644 --- a/src/caps.c +++ b/src/caps.c @@ -61,7 +61,7 @@ cap_nick(aClient *sptr) * (only allowed for LS and NEW). */ static void -send_caps(aClient *sptr, char *subcmd, unsigned int mask, int values) +send_caps(aClient *sptr, char *subcmd, uint64_t mask, int values) { char buf[BUFSIZE], tok[BUFSIZE]; aClientCap *cap; @@ -110,7 +110,7 @@ cap_ls(aClient *sptr, int parc, char *parv[]) sptr->caps |= CAP_CAP_NOTIFY; } - send_caps(sptr, "LS", ~0U, 1); + send_caps(sptr, "LS", ~(uint64_t)0, 1); return 0; } @@ -130,7 +130,7 @@ static int cap_req(aClient *sptr, int parc, char *parv[]) { char reqbuf[BUFSIZE], *tok, *p = NULL; - unsigned int newcaps = sptr->caps; + uint64_t newcaps = sptr->caps; aClientCap *cap; int neg; From 02db0518959b7ad2589601793aa26242a04b85bb Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Wed, 28 Oct 2026 18:55:19 +0000 Subject: [PATCH 6/6] Track CAP registration hold with FLAGS_CAPNEGO instead of a char field Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- include/caps.h | 4 +++- include/struct.h | 2 +- src/caps.c | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/caps.h b/include/caps.h index dc22d9fa..8e9db08f 100644 --- a/include/caps.h +++ b/include/caps.h @@ -42,7 +42,9 @@ struct ClientCap }; #define HasCap(x, c) (MyConnect(x) && ((x)->caps & (c))) -#define IsCapNegotiating(x) (MyConnect(x) && (x)->cap_negotiating) +#define IsCapNegotiating(x) ((x)->flags & FLAGS_CAPNEGO) +#define SetCapNegotiating(x) ((x)->flags |= FLAGS_CAPNEGO) +#define ClearCapNegotiating(x) ((x)->flags &= ~FLAGS_CAPNEGO) extern int m_cap(aClient *, aClient *, int, char **); diff --git a/include/struct.h b/include/struct.h index 1ef26781..25434d56 100644 --- a/include/struct.h +++ b/include/struct.h @@ -230,6 +230,7 @@ typedef struct SServicesTag ServicesTag; #define FLAGS_NONL 0x002000 /* No \n in buffer */ #define FLAGS_NORMALEX 0x004000 /* Client exited normally */ #define FLAGS_SENDQEX 0x008000 /* Sendq exceeded */ +#define FLAGS_CAPNEGO 0x010000 /* registration held until CAP END */ #define FLAGS_ULINE 0x020000 /* client is U-lined */ #define FLAGS_USERBURST 0x040000 /* server in nick/channel netburst */ #define FLAGS_TOPICBURST 0x080000 /* server in topic netburst */ @@ -1060,7 +1061,6 @@ struct Client int capabilities; /* what this server/client supports */ uint64_t caps; /* IRCv3 capabilities enabled (CAP_*) */ int cap_version; /* CAP LS version, e.g. 302 */ - char cap_negotiating; /* registration held until CAP END */ aClass *class; /* our current effective class */ #ifdef MSG_TARGET_LIMIT diff --git a/src/caps.c b/src/caps.c index ce991a15..ee28d32d 100644 --- a/src/caps.c +++ b/src/caps.c @@ -102,7 +102,7 @@ static int cap_ls(aClient *sptr, int parc, char *parv[]) { if (!IsRegistered(sptr)) - sptr->cap_negotiating = 1; + SetCapNegotiating(sptr); if (parc > 2 && atoi(parv[2]) >= 302 && sptr->cap_version < 302) { @@ -151,7 +151,7 @@ cap_req(aClient *sptr, int parc, char *parv[]) } if (!IsRegistered(sptr)) - sptr->cap_negotiating = 1; + SetCapNegotiating(sptr); /* too long to echo back in a single ACK, reject it unchanged */ if (strlen(parv[2]) > CAP_LINELEN) @@ -194,10 +194,10 @@ cap_req(aClient *sptr, int parc, char *parv[]) static int cap_end(aClient *cptr, aClient *sptr) { - if (IsRegistered(sptr) || !sptr->cap_negotiating) + if (IsRegistered(sptr) || !IsCapNegotiating(sptr)) return 0; - sptr->cap_negotiating = 0; + ClearCapNegotiating(sptr); /* NICK and USER already received, finish registration now */ if (*sptr->name && sptr->user)