diff options
author | Michael Vetter <jubalh@iodoru.org> | 2021-06-30 11:07:02 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2021-06-30 11:23:22 +0200 |
commit | 817a6bff54217e12444cb2d6dba1c0741918e578 (patch) | |
tree | ff6a5f77cfa0baec6f57953f76534e4a453281d4 | |
parent | ef96bea82e945d2c00426cac21b6578fdce62eb2 (diff) | |
download | profani-tty-817a6bff54217e12444cb2d6dba1c0741918e578.tar.gz |
XEP-0157: Print all available addresses
-rw-r--r-- | src/ui/console.c | 11 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 23 |
2 files changed, 26 insertions, 8 deletions
diff --git a/src/ui/console.c b/src/ui/console.c index f3993424..59e24891 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -837,9 +837,14 @@ cons_show_disco_items(GSList* items, const char* const jid) cons_alert(NULL); } -static void _cons_print_contact_information_item(gpointer key, gpointer value, gpointer userdata) +static void _cons_print_contact_information_item(gpointer data, gpointer user_data) { - cons_show("%s: %s", (char*)key, (char*)value); + cons_show("%s: %s", (char*)user_data, (char*)data); +} + +static void _cons_print_contact_information_hashlist_item(gpointer key, gpointer value, gpointer userdata) +{ + g_slist_foreach((GSList*)value, _cons_print_contact_information_item, key); } void @@ -848,7 +853,7 @@ cons_show_disco_contact_information(GHashTable* addresses) cons_show(""); cons_show("Server contact information:"); - g_hash_table_foreach(addresses, _cons_print_contact_information_item, NULL); + g_hash_table_foreach(addresses, _cons_print_contact_information_hashlist_item, NULL); } void diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 27e6d647..604d4003 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -2839,10 +2839,18 @@ stanza_create_muc_register_nick(xmpp_ctx_t* ctx, const char* const id, const cha return iq; } +static void +_contact_addresses_list_free(GSList* list) +{ + if (list) { + g_slist_free_full(list, g_free); + } +} + GHashTable* stanza_get_service_contact_addresses(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza) { - GHashTable* addresses = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + GHashTable* addresses = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_contact_addresses_list_free); xmpp_stanza_t* fields = xmpp_stanza_get_children(stanza); while (fields) { @@ -2850,18 +2858,18 @@ stanza_get_service_contact_addresses(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza) const char* child_type = xmpp_stanza_get_type(fields); if (g_strcmp0(child_name, STANZA_NAME_FIELD) == 0 && g_strcmp0(child_type, STANZA_TYPE_LIST_MULTI) == 0) { - // key + // extract key (eg 'admin-addresses') const char* var = xmpp_stanza_get_attribute(fields, STANZA_ATTR_VAR ); - // values + // extract values (a list of contact addresses eg mailto:xmpp@shakespeare.lit, xmpp:admins@shakespeare.lit) xmpp_stanza_t* values = xmpp_stanza_get_children(fields); + GSList* val_list = NULL; while (values) { const char* value_name = xmpp_stanza_get_name(values); if (value_name && (g_strcmp0(value_name, STANZA_NAME_VALUE) == 0)) { char* value_text = xmpp_stanza_get_text(values); if (value_text) { - //add to list - g_hash_table_insert(addresses, g_strdup(var), g_strdup(value_text)); + val_list = g_slist_append(val_list, g_strdup(value_text)); xmpp_free(ctx, value_text); } @@ -2869,6 +2877,11 @@ stanza_get_service_contact_addresses(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza) values = xmpp_stanza_get_next(values); } + + // add to list + if (g_slist_length(val_list) > 0) { + g_hash_table_insert(addresses, g_strdup(var), val_list); + } } fields = xmpp_stanza_get_next(fields); |