mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-08-02 10:56:22 +00:00
XEP-0157: Print all available addresses
This commit is contained in:
@@ -837,9 +837,14 @@ cons_show_disco_items(GSList* items, const char* const jid)
|
|||||||
cons_alert(NULL);
|
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
|
void
|
||||||
@@ -848,7 +853,7 @@ cons_show_disco_contact_information(GHashTable* addresses)
|
|||||||
cons_show("");
|
cons_show("");
|
||||||
cons_show("Server contact information:");
|
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
|
void
|
||||||
|
|||||||
@@ -2839,10 +2839,18 @@ stanza_create_muc_register_nick(xmpp_ctx_t* ctx, const char* const id, const cha
|
|||||||
return iq;
|
return iq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_contact_addresses_list_free(GSList* list)
|
||||||
|
{
|
||||||
|
if (list) {
|
||||||
|
g_slist_free_full(list, g_free);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GHashTable*
|
GHashTable*
|
||||||
stanza_get_service_contact_addresses(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza)
|
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);
|
xmpp_stanza_t* fields = xmpp_stanza_get_children(stanza);
|
||||||
while (fields) {
|
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);
|
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) {
|
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 );
|
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);
|
xmpp_stanza_t* values = xmpp_stanza_get_children(fields);
|
||||||
|
GSList* val_list = NULL;
|
||||||
while (values) {
|
while (values) {
|
||||||
const char* value_name = xmpp_stanza_get_name(values);
|
const char* value_name = xmpp_stanza_get_name(values);
|
||||||
if (value_name && (g_strcmp0(value_name, STANZA_NAME_VALUE) == 0)) {
|
if (value_name && (g_strcmp0(value_name, STANZA_NAME_VALUE) == 0)) {
|
||||||
char* value_text = xmpp_stanza_get_text(values);
|
char* value_text = xmpp_stanza_get_text(values);
|
||||||
if (value_text) {
|
if (value_text) {
|
||||||
//add to list
|
val_list = g_slist_append(val_list, g_strdup(value_text));
|
||||||
g_hash_table_insert(addresses, g_strdup(var), g_strdup(value_text));
|
|
||||||
|
|
||||||
xmpp_free(ctx, 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);
|
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);
|
fields = xmpp_stanza_get_next(fields);
|
||||||
|
|||||||
Reference in New Issue
Block a user