degesch: properly unescape RPL_ISUPPORT values

This commit is contained in:
Přemysl Eric Janouch 2015-05-30 22:34:09 +02:00
parent b7b84b489d
commit 3c32558a42

View File

@ -4486,6 +4486,25 @@ irc_handle_isupport_prefix (struct server *s, char *value)
s->irc_channel_prefixes = xstrndup (prefixes, n_prefixes);
}
static void
unescape_isupport_value (const char *value, struct str *output)
{
const char *alphabet = "0123456789abcdef", *a, *b;
for (const char *p = value; *p; p++)
{
if (p[0] == '\\'
&& p[1] == 'x'
&& p[2] && (a = strchr (alphabet, tolower_ascii (p[2])))
&& p[3] && (b = strchr (alphabet, tolower_ascii (p[3]))))
{
str_append_c (output, (a - alphabet) << 4 | (b - alphabet));
p += 3;
}
else
str_append_c (output, *p);
}
}
static void
irc_handle_rpl_isupport (struct server *s, const struct irc_message *msg)
{
@ -4499,8 +4518,14 @@ irc_handle_rpl_isupport (struct server *s, const struct irc_message *msg)
char *value = param + strcspn (param, "=");
if (*value) *value++ = '\0';
struct str value_unescaped;
str_init (&value_unescaped);
unescape_isupport_value (value, &value_unescaped);
if (!strcmp (param, "PREFIX"))
irc_handle_isupport_prefix (s, value);
irc_handle_isupport_prefix (s, value_unescaped.str);
str_free (&value_unescaped);
}
// TODO: initialize key_strxfrm according to server properties;