about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-06-29 22:52:45 +0200
committerMichael Vetter <jubalh@iodoru.org>2021-06-29 22:52:45 +0200
commit2f5aa124cacae454e4b49c2ecbc7ca72bdf63d1c (patch)
tree1ea78bfc99bbc6ff917bd7de78f5ed0d53e2d1da
parent3c648ee2f5715998e440c316ea9eadfd8205463c (diff)
downloadprofani-tty-2f5aa124cacae454e4b49c2ecbc7ca72bdf63d1c.tar.gz
XEP-0157: Parse contact address stanza
-rw-r--r--src/xmpp/iq.c26
-rw-r--r--src/xmpp/stanza.c31
-rw-r--r--src/xmpp/stanza.h3
3 files changed, 56 insertions, 4 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index beecb97e..7af477e6 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -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);
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 235a7dee..96c47dc7 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -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);
+    }
+}
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 5effaf3e..7856a739 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -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);