1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

XEP-0157: Print all available addresses

This commit is contained in:
Michael Vetter 2021-06-30 11:07:02 +02:00
parent ef96bea82e
commit 817a6bff54
2 changed files with 26 additions and 8 deletions

View File

@ -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

View File

@ -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);