about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDebXWoody <stefan@debxwoody.de>2020-07-03 18:30:23 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-07-04 17:38:30 +0200
commit54667c022f17bdb547c3b8b4eec1c2889c9d60f3 (patch)
tree323f42528c21de14ab958fd2d2160b1e10753b34
parent3af5f33489d1e065c9da03b0bb99eddff57816a4 (diff)
downloadprofani-tty-54667c022f17bdb547c3b8b4eec1c2889c9d60f3.tar.gz
Messages are not shown in ChatSecure
In 0.9.x we fixed an issue, because OMEMO devices should be defined in "item"
with id "current". This should work, but it won't work if there is no "current".
If there is no "current" we will just use the first item.

Issue #1384
-rw-r--r--src/omemo/omemo.c1
-rw-r--r--src/xmpp/omemo.c59
2 files changed, 39 insertions, 21 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index 343f2f60..572508ca 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -98,7 +98,6 @@ struct omemo_context_t {
     GHashTable *pre_key_store;
     GHashTable *signed_pre_key_store;
     identity_key_store_t identity_key_store;
-    GHashTable *device_ids;
     GString *identity_filename;
     GKeyFile *identity_keyfile;
     GString *trust_filename;
diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c
index eb4f0fbc..2021816a 100644
--- a/src/xmpp/omemo.c
+++ b/src/xmpp/omemo.c
@@ -441,29 +441,48 @@ _omemo_receive_devicelist(xmpp_stanza_t *const stanza, void *const userdata)
         return 1;
     }
 
-    xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(items, "item");
-    if (item) {
-        if (g_strcmp0(xmpp_stanza_get_id(item), "current") == 0 ) {
-            xmpp_stanza_t *list = xmpp_stanza_get_child_by_ns(item, STANZA_NS_OMEMO);
-            if (!list) {
-                return 1;
-            }
 
-            xmpp_stanza_t *device;
-            for (device = xmpp_stanza_get_children(list); device != NULL; device = xmpp_stanza_get_next(device)) {
-                if (g_strcmp0(xmpp_stanza_get_name(device), "device") != 0) {
-                    continue;
-                }
-
-                const char *id = xmpp_stanza_get_id(device);
-                if (id != NULL) {
-                    device_list = g_list_append(device_list, GINT_TO_POINTER(strtoul(id, NULL, 10)));
-                } else {
-                    log_error("OMEMO: received device without ID");
-                }
+    // Looking for "current" item - if there is no current, take the first item.
+    xmpp_stanza_t* first = NULL;
+    xmpp_stanza_t* current = NULL;
+    
+    xmpp_stanza_t *item = xmpp_stanza_get_children(items);
+    while ( item ) {
+        if (g_strcmp0(xmpp_stanza_get_name(item), "item") == 0) {
+            first = item;
+            if (g_strcmp0(xmpp_stanza_get_id(item), "current") == 0 ) {
+                current = item;
+                break;
             }
+        }
+        item = xmpp_stanza_get_next(item);
+    }
+
+    if(current) {
+        item = current;
+    } else if( first ) {
+        log_warning("OMEMO: User %s has a non 'current' device item list: %s.", from, xmpp_stanza_get_id(first));
+        item = first;
+    } else {
+        return 1;
+    }
+
+    xmpp_stanza_t *list = xmpp_stanza_get_child_by_ns(item, STANZA_NS_OMEMO);
+    if (!list) {
+        return 1;
+    }
+
+    xmpp_stanza_t *device;
+    for (device = xmpp_stanza_get_children(list); device != NULL; device = xmpp_stanza_get_next(device)) {
+        if (g_strcmp0(xmpp_stanza_get_name(device), "device") != 0) {
+            continue;
+        }
+
+        const char *id = xmpp_stanza_get_id(device);
+        if (id != NULL) {
+            device_list = g_list_append(device_list, GINT_TO_POINTER(strtoul(id, NULL, 10)));
         } else {
-            log_warning("OMEMO: User %s has a non 'current' device item list: %s.", from, xmpp_stanza_get_id(item));
+            log_error("OMEMO: received device without ID");
         }
     }