summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc1
-rw-r--r--src/plugins/relay/irc/relay-irc.c50
2 files changed, 29 insertions, 22 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index d12c678f5..3abab8f85 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -33,6 +33,7 @@ Bug fixes::
* core: call the config hook when options are renamed or removed
* buflist: fix crash in auto-scroll of bar when the buflist item is not the first item in the bar
+ * relay: fix parsing of CAP command without arguments in irc protocol, send ACK only if all capabilities received are OK and NAK otherwise (issue #1040)
[[v1.9]]
== Version 1.9 (2017-06-25)
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))