mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Parse the K/V form in CAP LS
This is a prerequisite for the IRC v3.2 compliance.
This commit is contained in:
parent
d85f867261
commit
98836f8b7e
@ -45,7 +45,7 @@ int cap_toggle (IRC_SERVER_REC *server, char *cap, int enable)
|
|||||||
|
|
||||||
if (enable && !gslist_find_string(server->cap_active, cap)) {
|
if (enable && !gslist_find_string(server->cap_active, cap)) {
|
||||||
/* Make sure the required cap is supported by the server */
|
/* Make sure the required cap is supported by the server */
|
||||||
if (!gslist_find_string(server->cap_supported, cap))
|
if (!g_hash_table_lookup_extended(server->cap_supported, cap, NULL, NULL))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
irc_send_cmdv(server, "CAP REQ %s", cap);
|
irc_send_cmdv(server, "CAP REQ %s", cap);
|
||||||
@ -96,9 +96,44 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
|
|||||||
caps_length = g_strv_length(caps);
|
caps_length = g_strv_length(caps);
|
||||||
|
|
||||||
if (!g_strcmp0(evt, "LS")) {
|
if (!g_strcmp0(evt, "LS")) {
|
||||||
|
if (server->cap_supported) {
|
||||||
|
g_hash_table_destroy(server->cap_supported);
|
||||||
|
}
|
||||||
|
/* Start with a fresh table */
|
||||||
|
server->cap_supported = g_hash_table_new_full(g_str_hash,
|
||||||
|
g_str_equal,
|
||||||
|
g_free, g_free);
|
||||||
|
|
||||||
/* Create a list of the supported caps */
|
/* Create a list of the supported caps */
|
||||||
for (i = 0; i < caps_length; i++)
|
for (i = 0; i < caps_length; i++) {
|
||||||
server->cap_supported = g_slist_prepend(server->cap_supported, g_strdup(caps[i]));
|
const char *name = caps[i];
|
||||||
|
const char *eq = strchr(name, '=');
|
||||||
|
int fresh = TRUE;
|
||||||
|
|
||||||
|
if (!eq) {
|
||||||
|
fresh = g_hash_table_insert(server->cap_supported,
|
||||||
|
g_strdup(name),
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
/* Some values are in a KEY=VALUE form, parse them */
|
||||||
|
else if (eq[1] != '\0') {
|
||||||
|
char *key = g_strndup(name, (int)(eq - name));
|
||||||
|
char *val = g_strdup(eq + 1);
|
||||||
|
fresh = g_hash_table_insert(server->cap_supported,
|
||||||
|
key, val);
|
||||||
|
}
|
||||||
|
/* If the string ends after the '=' consider the value
|
||||||
|
* as invalid */
|
||||||
|
else {
|
||||||
|
g_warning("Invalid CAP key/value pair");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The specification doesn't say anything about
|
||||||
|
* duplicated values, let's just warn the user */
|
||||||
|
if (fresh == FALSE) {
|
||||||
|
g_warning("Duplicate value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Request the required caps, if any */
|
/* Request the required caps, if any */
|
||||||
if (server->cap_queue == NULL) {
|
if (server->cap_queue == NULL) {
|
||||||
@ -111,7 +146,7 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
|
|||||||
|
|
||||||
/* Check whether the cap is supported by the server */
|
/* Check whether the cap is supported by the server */
|
||||||
for (tmp = server->cap_queue; tmp != NULL; tmp = tmp->next) {
|
for (tmp = server->cap_queue; tmp != NULL; tmp = tmp->next) {
|
||||||
if (gslist_find_string(server->cap_supported, tmp->data)) {
|
if (g_hash_table_lookup_extended(server->cap_supported, tmp->data, NULL, NULL)) {
|
||||||
if (avail_caps > 0)
|
if (avail_caps > 0)
|
||||||
g_string_append_c(cmd, ' ');
|
g_string_append_c(cmd, ' ');
|
||||||
g_string_append(cmd, tmp->data);
|
g_string_append(cmd, tmp->data);
|
||||||
|
@ -443,7 +443,7 @@ static void sig_disconnected(IRC_SERVER_REC *server)
|
|||||||
gslist_free_full(server->cap_active, (GDestroyNotify) g_free);
|
gslist_free_full(server->cap_active, (GDestroyNotify) g_free);
|
||||||
server->cap_active = NULL;
|
server->cap_active = NULL;
|
||||||
|
|
||||||
gslist_free_full(server->cap_supported, (GDestroyNotify) g_free);
|
g_hash_table_destroy(server->cap_supported);
|
||||||
server->cap_supported = NULL;
|
server->cap_supported = NULL;
|
||||||
|
|
||||||
gslist_free_full(server->cap_queue, (GDestroyNotify) g_free);
|
gslist_free_full(server->cap_queue, (GDestroyNotify) g_free);
|
||||||
|
@ -75,7 +75,7 @@ struct _IRC_SERVER_REC {
|
|||||||
int max_whois_in_cmd; /* max. number of nicks in one /WHOIS command */
|
int max_whois_in_cmd; /* max. number of nicks in one /WHOIS command */
|
||||||
int max_msgs_in_cmd; /* max. number of targets in one /MSG */
|
int max_msgs_in_cmd; /* max. number of targets in one /MSG */
|
||||||
|
|
||||||
GSList *cap_supported; /* A list of caps supported by the server */
|
GHashTable *cap_supported; /* A list of caps supported by the server */
|
||||||
GSList *cap_active; /* A list of caps active for this session */
|
GSList *cap_active; /* A list of caps active for this session */
|
||||||
GSList *cap_queue; /* A list of caps to request on connection */
|
GSList *cap_queue; /* A list of caps to request on connection */
|
||||||
|
|
||||||
|
@ -12,7 +12,10 @@ static void perl_irc_connect_fill_hash(HV *hv, IRC_SERVER_CONNECT_REC *conn)
|
|||||||
static void perl_irc_server_fill_hash(HV *hv, IRC_SERVER_REC *server)
|
static void perl_irc_server_fill_hash(HV *hv, IRC_SERVER_REC *server)
|
||||||
{
|
{
|
||||||
AV *av;
|
AV *av;
|
||||||
|
HV *hv_;
|
||||||
GSList *tmp;
|
GSList *tmp;
|
||||||
|
GHashTableIter iter;
|
||||||
|
gpointer key_, val_;
|
||||||
|
|
||||||
perl_irc_connect_fill_hash(hv, server->connrec);
|
perl_irc_connect_fill_hash(hv, server->connrec);
|
||||||
perl_server_fill_hash(hv, (SERVER_REC *) server);
|
perl_server_fill_hash(hv, (SERVER_REC *) server);
|
||||||
@ -34,10 +37,14 @@ static void perl_irc_server_fill_hash(HV *hv, IRC_SERVER_REC *server)
|
|||||||
(void) hv_store(hv, "cap_complete", 12, newSViv(server->cap_complete), 0);
|
(void) hv_store(hv, "cap_complete", 12, newSViv(server->cap_complete), 0);
|
||||||
(void) hv_store(hv, "sasl_success", 12, newSViv(server->sasl_success), 0);
|
(void) hv_store(hv, "sasl_success", 12, newSViv(server->sasl_success), 0);
|
||||||
|
|
||||||
av = newAV();
|
hv_ = newHV();
|
||||||
for (tmp = server->cap_supported; tmp != NULL; tmp = tmp->next)
|
g_hash_table_iter_init(&iter, server->cap_supported);
|
||||||
av_push(av, new_pv(tmp->data));
|
while (g_hash_table_iter_next(&iter, &key_, &val_)) {
|
||||||
(void) hv_store(hv, "cap_supported", 13, newRV_noinc((SV*)av), 0);
|
char *key = (char *)key_;
|
||||||
|
char *val = (char *)val_;
|
||||||
|
hv_store(hv_, key, strlen(key), new_pv(val), 0);
|
||||||
|
}
|
||||||
|
(void) hv_store(hv, "cap_supported", 13, newRV_noinc((SV*)hv_), 0);
|
||||||
|
|
||||||
av = newAV();
|
av = newAV();
|
||||||
for (tmp = server->cap_active; tmp != NULL; tmp = tmp->next)
|
for (tmp = server->cap_active; tmp != NULL; tmp = tmp->next)
|
||||||
|
Loading…
Reference in New Issue
Block a user