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

XEP-0157: Parse contact address stanza

This commit is contained in:
Michael Vetter 2021-06-29 22:52:45 +02:00
parent 3c648ee2f5
commit 2f5aa124ca
3 changed files with 56 additions and 4 deletions

View File

@ -2308,6 +2308,8 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat
GSList* features = NULL;
while (child) {
const char* stanza_name = xmpp_stanza_get_name(child);
const char* child_type = xmpp_stanza_get_type(child);
if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
const char* var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR);
if (var) {
@ -2315,10 +2317,9 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat
}
} else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) {
const char* name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
const char* type = xmpp_stanza_get_type(child);
const char* category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY);
if (name || category || type) {
if (name || category || child_type) {
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
if (identity) {
@ -2332,8 +2333,8 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat
} else {
identity->category = NULL;
}
if (type) {
identity->type = strdup(type);
if (child_type) {
identity->type = strdup(child_type);
} else {
identity->type = NULL;
}
@ -2341,6 +2342,23 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat
identities = g_slist_append(identities, identity);
}
}
} else if (g_strcmp0(child_type, STANZA_TYPE_RESULT) == 0) {
/*
DataForm* form = form_create(child);
ProfConfWin* confwin = (ProfConfWin*)wins_new_config(from, form, NULL, NULL, NULL);
confwin_handle_configuration(confwin, form);
*/
/*g_hash_table_new () with field var='security-addresses' as key
* a list of <value>xmpp:security@shakespeare.lit</value> as value
*/
stanza_get_service_contact_addresses(connection_get_ctx(), child);
/*
char* text;
size_t text_size;
xmpp_stanza_to_text(child, &text, &text_size);
cons_show(text);
free(text);
*/
}
child = xmpp_stanza_get_next(child);

View File

@ -2838,3 +2838,34 @@ stanza_create_muc_register_nick(xmpp_ctx_t* ctx, const char* const id, const cha
return iq;
}
void
stanza_get_service_contact_addresses(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza)
{
xmpp_stanza_t* fields = xmpp_stanza_get_children(stanza);
while (fields) {
const char* child_name = xmpp_stanza_get_name(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) {
// key
const char* var = xmpp_stanza_get_attribute(fields, STANZA_ATTR_VAR );
var = var;
// values
xmpp_stanza_t* values = xmpp_stanza_get_children(fields);
if (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
xmpp_free(ctx, value_text);
}
}
}
}
fields = xmpp_stanza_get_next(fields);
}
}

View File

@ -162,6 +162,7 @@
#define STANZA_TYPE_SUBMIT "submit"
#define STANZA_TYPE_CANCEL "cancel"
#define STANZA_TYPE_MODIFY "modify"
#define STANZA_TYPE_LIST_MULTI "list-multi"
#define STANZA_ATTR_TO "to"
#define STANZA_ATTR_FROM "from"
@ -388,6 +389,8 @@ char* stanza_get_muc_destroy_reason(xmpp_stanza_t* stanza);
const char* stanza_get_actor(xmpp_stanza_t* stanza);
char* stanza_get_reason(xmpp_stanza_t* stanza);
void stanza_get_service_contact_addresses(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza);
Resource* stanza_resource_from_presence(XMPPPresence* presence);
XMPPPresence* stanza_parse_presence(xmpp_stanza_t* stanza, int* err);
void stanza_free_presence(XMPPPresence* presence);