Handle CAP requests from clients, reply with no capabilities
Some clients require the server to handle CAP requests (IRCv3). This adds basic support for CAP requests during the authentication phase, sending no capabilities on CAP LS or CAP LIST, and CAP NAK with all requested capabilities listed on CAP REQ. This will be a base for adding capabilities later. Signed-off-by: Loïc Gomez <bip@animanova.fr>
This commit is contained in:
parent
f797d25e06
commit
91ece92e4f
27
src/irc.c
27
src/irc.c
@ -1025,6 +1025,31 @@ static int irc_cli_pass(bip_t *bip, struct link_client *ic, struct line *line)
|
|||||||
return OK_FORGET;
|
return OK_FORGET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int irc_cli_cap(bip_t *bip, struct link_client *ic, struct line *line)
|
||||||
|
{
|
||||||
|
if (irc_line_count(line) < 2)
|
||||||
|
return ERR_PROTOCOL;
|
||||||
|
|
||||||
|
/* When we decide to enable actual capabilities, we'll have to handle CAP
|
||||||
|
* version, add a flag cap_started or similar, and handle CAP END.
|
||||||
|
*/
|
||||||
|
if (irc_line_elem_equals(line, 1, "LS")) {
|
||||||
|
WRITE_LINE2(CONN(ic), NULL, "CAP", "*", "LS");
|
||||||
|
} else if (irc_line_elem_equals(line, 1, "LIST")) {
|
||||||
|
WRITE_LINE3(CONN(ic), NULL, "CAP", "*", "LIST", "");
|
||||||
|
} else if (irc_line_elem_equals(line, 1, "REQ")) {
|
||||||
|
char *caps = irc_line_to_string_skip(line, 2);
|
||||||
|
if (caps) {
|
||||||
|
caps++;
|
||||||
|
WRITE_LINE3(CONN(ic), NULL, "CAP", "*", "NAK", caps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ic->state & IRCC_READY) == IRCC_READY)
|
||||||
|
return irc_cli_startup(bip, ic, line);
|
||||||
|
return OK_FORGET;
|
||||||
|
}
|
||||||
|
|
||||||
static int irc_cli_quit(struct link_client *ic, struct line *line)
|
static int irc_cli_quit(struct link_client *ic, struct line *line)
|
||||||
{
|
{
|
||||||
(void)ic;
|
(void)ic;
|
||||||
@ -1403,6 +1428,8 @@ static int irc_dispatch_logging_client(bip_t *bip, struct link_client *ic,
|
|||||||
return irc_cli_user(bip, ic, line);
|
return irc_cli_user(bip, ic, line);
|
||||||
} else if (irc_line_elem_equals(line, 0, "PASS")) {
|
} else if (irc_line_elem_equals(line, 0, "PASS")) {
|
||||||
return irc_cli_pass(bip, ic, line);
|
return irc_cli_pass(bip, ic, line);
|
||||||
|
} else if (irc_line_elem_equals(line, 0, "CAP")) {
|
||||||
|
return irc_cli_cap(bip, ic, line);
|
||||||
}
|
}
|
||||||
return OK_FORGET;
|
return OK_FORGET;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user