about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/omemo.c115
-rw-r--r--src/xmpp/omemo.h1
2 files changed, 93 insertions, 23 deletions
diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c
index 54cd12ad..20bf251a 100644
--- a/src/xmpp/omemo.c
+++ b/src/xmpp/omemo.c
@@ -47,12 +47,13 @@
 #include "omemo/omemo.h"
 
 static int _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata);
+static int _omemo_devicelist_publish_result(xmpp_stanza_t* const stanza, void* const userdata);
+static int _omemo_devicelist_configure(xmpp_stanza_t* const stanza, void* const userdata);
+static int _omemo_devicelist_configure_result(xmpp_stanza_t* const stanza, void* const userdata);
 static int _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata);
 static int _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdata);
 static int _omemo_bundle_publish_configure_result(xmpp_stanza_t* const stanza, void* const userdata);
 
-static int _omemo_device_list_publish_result(xmpp_stanza_t* const stanza, void* const userdata);
-
 void
 omemo_devicelist_subscribe(void)
 {
@@ -69,14 +70,28 @@ omemo_devicelist_publish(GList* device_list)
 
     log_debug("[OMEMO] publish device list");
 
-    if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) {
-        stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open");
-    }
+    iq_id_handler_add(xmpp_stanza_get_id(iq), _omemo_devicelist_publish_result, NULL, NULL);
+
+    iq_send_stanza(iq);
+    xmpp_stanza_release(iq);
+}
 
-    iq_id_handler_add(xmpp_stanza_get_id(iq), _omemo_device_list_publish_result, NULL, NULL);
+void
+omemo_devicelist_configure_and_request(void)
+{
+    xmpp_ctx_t* const ctx = connection_get_ctx();
+    char* id = connection_create_stanza_id();
+    Jid* jid = jid_create(connection_get_fulljid());
+
+    xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, jid->barejid, STANZA_NS_OMEMO_DEVICELIST);
+
+    iq_id_handler_add(id, _omemo_devicelist_configure, NULL, NULL);
 
     iq_send_stanza(iq);
+
     xmpp_stanza_release(iq);
+    free(id);
+    jid_destroy(jid);
 }
 
 void
@@ -512,6 +527,76 @@ _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata)
     return 1;
 }
 
+static int
+_omemo_devicelist_publish_result(xmpp_stanza_t* const stanza, void* const userdata)
+{
+    const char* type = xmpp_stanza_get_type(stanza);
+    if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
+        cons_show_error("Unable to publish own OMEMO device list");
+        log_error("[OMEMO] Publishing device list failed");
+        return 0;
+    }
+    return 0;
+}
+
+static int
+_omemo_devicelist_configure(xmpp_stanza_t* const stanza, void* const userdata)
+{
+    log_debug("[OMEMO] _omemo_devicelist_configure()");
+
+    xmpp_stanza_t* pubsub = xmpp_stanza_get_child_by_name(stanza, "pubsub");
+    if (!pubsub) {
+        log_error("[OMEMO] The stanza doesn't contain a 'pubsub' child");
+        return 0;
+    }
+    xmpp_stanza_t* configure = xmpp_stanza_get_child_by_name(pubsub, STANZA_NAME_CONFIGURE);
+    if (!configure) {
+        log_error("[OMEMO] The stanza doesn't contain a 'configure' child");
+        return 0;
+    }
+    xmpp_stanza_t* x = xmpp_stanza_get_child_by_name(configure, "x");
+    if (!x) {
+        log_error("[OMEMO] The stanza doesn't contain an 'x' child");
+        return 0;
+    }
+
+    DataForm* form = form_create(x);
+    form_set_value(form,  "pubsub#access_model", "open");
+
+    xmpp_ctx_t* const ctx = connection_get_ctx();
+    Jid* jid = jid_create(connection_get_fulljid());
+    char* id = connection_create_stanza_id();
+    xmpp_stanza_t* iq = stanza_create_pubsub_configure_submit(ctx, id, jid->barejid, STANZA_NS_OMEMO_DEVICELIST, form);
+
+    iq_id_handler_add(id, _omemo_devicelist_configure_result, NULL, NULL);
+
+    iq_send_stanza(iq);
+
+    xmpp_stanza_release(iq);
+    free(id);
+    jid_destroy(jid);
+    return 0;
+}
+
+static int
+_omemo_devicelist_configure_result(xmpp_stanza_t* const stanza, void* const userdata)
+{
+    const char* type = xmpp_stanza_get_type(stanza);
+
+    if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
+        log_error("[OMEMO] cannot configure device list to an open access model: Result error");
+        return 0;
+    }
+
+    log_debug("[OMEMO] node configured");
+
+    // Try to publish
+    char* barejid = connection_get_barejid();
+    omemo_devicelist_request(barejid);
+
+    return 0;
+}
+
 
 static int
 _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata)
@@ -572,11 +657,7 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat
     }
 
     DataForm* form = form_create(x);
-    char* tag = g_hash_table_lookup(form->var_to_tag, "pubsub#access_model");
-    if (!tag) {
-        log_error("[OMEMO] cannot configure bundle to an open access model");
-        return 0;
-    }
+    form_set_value(form,  "pubsub#access_model", "open");
 
     xmpp_ctx_t* const ctx = connection_get_ctx();
     Jid* jid = jid_create(connection_get_fulljid());
@@ -612,15 +693,3 @@ _omemo_bundle_publish_configure_result(xmpp_stanza_t* const stanza, void* const
 
     return 0;
 }
-
-static int
-_omemo_device_list_publish_result(xmpp_stanza_t* const stanza, void* const userdata)
-{
-    const char* type = xmpp_stanza_get_type(stanza);
-    if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
-        cons_show_error("Unable to publish own OMEMO device list");
-        log_error("[OMEMO] Publishing device list failed");
-        return 0;
-    }
-    return 0;
-}
diff --git a/src/xmpp/omemo.h b/src/xmpp/omemo.h
index 31021ab4..9f29cb96 100644
--- a/src/xmpp/omemo.h
+++ b/src/xmpp/omemo.h
@@ -38,6 +38,7 @@
 #include "xmpp/iq.h"
 
 void omemo_devicelist_subscribe(void);
+void omemo_devicelist_configure_and_request(void);
 void omemo_devicelist_publish(GList* device_list);
 void omemo_devicelist_request(const char* const jid);
 void omemo_bundle_publish(gboolean first);