summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-07-23 13:58:45 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-07-23 13:58:45 +0200
commita58d3fac4cb5475aea804bd7894979508f2cbbba (patch)
treee76b6914da2919f851aa6da48463fe54ba4fe773 /src/plugins
parentda64da74193a47b0f9de53bcb783124e0fc04c04 (diff)
downloadweechat-a58d3fac4cb5475aea804bd7894979508f2cbbba.zip
relay: fix parsing of CAP command without arguments in irc protocol, send ACK only if all capabilities received are OK and NAK otherwise (closes #1040)
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/relay/irc/relay-irc.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/plugins/relay/irc/relay-irc.c b/src/plugins/relay/irc/relay-irc.c
index 99fb0f32b..78e02e751 100644
--- a/src/plugins/relay/irc/relay-irc.c
+++ b/src/plugins/relay/irc/relay-irc.c
@@ -1225,10 +1225,10 @@ relay_irc_hook_signals (struct t_relay_client *client)
void
relay_irc_recv_command_capab (struct t_relay_client *client,
- int argc, char **argv)
+ int argc, char **argv, char **argv_eol)
{
char str_capab[1024];
- int i, capability;
+ int i, capability, server_caps, caps_ok;
if (weechat_strcasecmp (argv[0], "ls") == 0)
{
@@ -1251,32 +1251,32 @@ relay_irc_recv_command_capab (struct t_relay_client *client,
else if (weechat_strcasecmp (argv[0], "req") == 0)
{
/* client is asking for one or more server capabilities */
- str_capab[0] = '\0';
+ caps_ok = 0;
+ server_caps = RELAY_IRC_DATA(client, server_capabilities);
for (i = 1; i < argc; i++)
{
capability = relay_irc_search_server_capability (
(argv[i][0] == ':') ? argv[i] + 1 : argv[i]);
if (capability >= 0)
{
- if (str_capab[0])
- strcat (str_capab, " ");
- strcat (str_capab,
- relay_irc_server_capabilities[capability]);
- RELAY_IRC_DATA(client, server_capabilities) |= 1 << capability;
+ caps_ok = 1;
+ server_caps |= 1 << capability;
+ }
+ else
+ {
+ caps_ok = 0;
+ break;
}
}
- /*
- * if at least one supported capability was enabled, send ACK to
- * client
- */
- if (str_capab[0])
- {
- relay_irc_sendf (client,
- ":%s CAP %s ACK :%s",
- RELAY_IRC_DATA(client, address),
- (RELAY_IRC_DATA(client, nick)) ? RELAY_IRC_DATA(client, nick) : "nick",
- str_capab);
- }
+ if (caps_ok)
+ RELAY_IRC_DATA(client, server_capabilities) = server_caps;
+ relay_irc_sendf (
+ client,
+ ":%s CAP %s %s :%s",
+ RELAY_IRC_DATA(client, address),
+ (RELAY_IRC_DATA(client, nick)) ? RELAY_IRC_DATA(client, nick) : "nick",
+ (caps_ok) ? "ACK" : "NAK",
+ (argc >= 2) ? ((argv_eol[1][0] == ':') ? argv_eol[1] + 1 : argv_eol[1]) : "");
}
else if (weechat_strcasecmp (argv[0], "end") == 0)
{
@@ -1293,7 +1293,7 @@ void
relay_irc_recv (struct t_relay_client *client, const char *data)
{
char str_time[128], str_signal[128], str_server_channel[256];
- char str_command[128], *target, **irc_argv, *pos, *password;
+ char str_command[128], *target, **irc_argv, **irc_argv_eol, *pos, *password;
const char *irc_command, *irc_channel, *irc_args, *irc_args2;
int irc_argc, redirect_msg;
const char *nick, *irc_is_channel, *isupport, *info, *pos_password;
@@ -1323,7 +1323,10 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
irc_channel = weechat_hashtable_get (hash_parsed, "channel");
irc_args = weechat_hashtable_get (hash_parsed, "arguments");
if (irc_args)
+ {
irc_argv = weechat_string_split (irc_args, " ", 0, 0, &irc_argc);
+ irc_argv_eol = weechat_string_split (irc_args, " ", 1, 0, NULL);
+ }
/*
* first process the "nick" command (it will be processed again in this
@@ -1342,7 +1345,10 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
if (irc_command && (weechat_strcasecmp (irc_command, "cap") == 0))
{
if ((irc_argc > 0) && irc_argv)
- relay_irc_recv_command_capab (client, irc_argc, irc_argv);
+ {
+ relay_irc_recv_command_capab (client,
+ irc_argc, irc_argv, irc_argv_eol);
+ }
}
/* if client is not yet "connected" */
if (!RELAY_IRC_DATA(client, connected))