1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-29 04:45:57 -04:00

Handle CAP {ADD,DEL} from cap-notify

This is the last piece of the puzzle.
This commit is contained in:
LemonBoy 2017-10-21 17:11:43 +02:00
parent 8c87766132
commit f4d811ddf5

View File

@ -135,6 +135,8 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
return;
}
g_warning("%s -> %s", evt, list);
/* Strip the trailing whitespaces before splitting the string, some servers send responses with
* superfluous whitespaces that g_strsplit the interprets as tokens */
caps = g_strsplit(g_strchomp(list), " ", -1);
@ -158,11 +160,11 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
key, val)) {
/* The specification doesn't say anything about
* duplicated values, let's just warn the user */
g_warning("Duplicate value");
g_warning("Duplicate value %s", key);
}
}
else {
g_warning("Invalid CAP key/value pair");
g_warning("Invalid CAP %s key/value pair", evt);
}
}
@ -236,6 +238,36 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
for (i = 0; i < caps_length; i++)
cap_emit_signal(server, "nak", caps[i]);
}
else if (!strcmp(evt, "NEW")) {
for (i = 0; i < caps_length; i++) {
char *key, *val;
if (parse_cap_name(caps[i], &key, &val)) {
g_hash_table_insert(server->cap_supported,
key, val);
}
else {
g_warning("Invalid CAP %s key/value pair", evt);
}
cap_emit_signal(server, "new", key);
}
}
else if (!strcmp(evt, "DEL")) {
for (i = 0; i < caps_length; i++) {
char *key, *val;
if (parse_cap_name(caps[i], &key, &val)) {
g_hash_table_remove(server->cap_supported, key);
}
else {
g_warning("Invalid CAP %s key/value pair", evt);
}
cap_emit_signal(server, "delete", key);
/* The server removed this CAP, remove it from the list
* of the active ones if we had requested it */
server->cap_active = gslist_remove_string(server->cap_active, key);
}
}
else {
g_warning("Unhandled CAP subcommand %s", evt);
}