about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/xmpp/omemo.c15
-rw-r--r--src/xmpp/omemo.h1
-rw-r--r--src/xmpp/session.c7
-rw-r--r--src/xmpp/stanza.c25
-rw-r--r--src/xmpp/stanza.h2
5 files changed, 50 insertions, 0 deletions
diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c
new file mode 100644
index 00000000..42b18c6b
--- /dev/null
+++ b/src/xmpp/omemo.c
@@ -0,0 +1,15 @@
+#include "xmpp/connection.h"
+#include "xmpp/iq.h"
+#include "xmpp/stanza.h"
+
+void
+omemo_devicelist_publish(void)
+{
+    xmpp_ctx_t * const ctx = connection_get_ctx();
+    char *barejid = xmpp_jid_bare(ctx, session_get_account_name());
+    xmpp_stanza_t *iq = stanza_create_omemo_devicelist_subscription(ctx, barejid);
+    iq_send_stanza(iq);
+    xmpp_stanza_release(iq);
+
+    free(barejid);
+}
diff --git a/src/xmpp/omemo.h b/src/xmpp/omemo.h
new file mode 100644
index 00000000..413aa563
--- /dev/null
+++ b/src/xmpp/omemo.h
@@ -0,0 +1 @@
+void omemo_devicelist_publish(void);
diff --git a/src/xmpp/session.c b/src/xmpp/session.c
index de7fb7ac..ee836090 100644
--- a/src/xmpp/session.c
+++ b/src/xmpp/session.c
@@ -60,6 +60,10 @@
 #include "xmpp/chat_session.h"
 #include "xmpp/jid.h"
 
+#ifdef HAVE_OMEMO
+#include "xmpp/omemo.h"
+#endif
+
 // for auto reconnect
 static struct {
     char *name;
@@ -313,6 +317,9 @@ session_login_success(gboolean secured)
     roster_request();
     bookmark_request();
     blocking_request();
+#ifdef HAVE_OMEMO
+    omemo_devicelist_publish();
+#endif
 
     // items discovery
     char *domain = connection_get_domain();
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 534ee06b..ffd0c053 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -2092,6 +2092,31 @@ stanza_create_command_config_submit_iq(xmpp_ctx_t *ctx, const char *const room,
     return iq;
 }
 
+xmpp_stanza_t*
+stanza_create_omemo_devicelist_pubsub_subscription(xmpp_ctx_t *ctx, const char *const jid)
+{
+    char *id = connection_create_stanza_id("omemo_devicelist_subscribe");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
+
+    xmpp_stanza_t *pubsub = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
+    xmpp_stanza_set_ns(pubsub, STANZA_NS_PUBSUB);
+
+    xmpp_stanza_t *subscribe = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(subscribe, "subscribe");
+    xmpp_stanza_set_attribute(subscribe, "node", "eu.siacs.conversations.axolotl.devicelist");
+    xmpp_stanza_set_attribute(subscribe, "jid", jid);
+
+    xmpp_stanza_add_child(pubsub, subscribe);
+    xmpp_stanza_add_child(iq, pubsub);
+
+    xmpp_stanza_release(subscribe);
+    xmpp_stanza_release(pubsub);
+
+    return iq;
+}
+
 static void
 _stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix)
 {
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index d3c3c9dc..ce655a93 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -284,6 +284,8 @@ xmpp_stanza_t* stanza_create_room_kick_iq(xmpp_ctx_t *const ctx, const char *con
 xmpp_stanza_t* stanza_create_command_exec_iq(xmpp_ctx_t *ctx, const char *const target, const char *const node);
 xmpp_stanza_t* stanza_create_command_config_submit_iq(xmpp_ctx_t *ctx, const char *const room, const char *const node, const char *const sessionid, DataForm *form);
 
+xmpp_stanza_t* stanza_create_omemo_devicelist_pubsub_subscription(xmpp_ctx_t *ctx, const char *const jid);
+
 int stanza_get_idle_time(xmpp_stanza_t *const stanza);
 
 void stanza_attach_priority(xmpp_ctx_t *const ctx, xmpp_stanza_t *const presence, const int pri);