From b882fd495a5488a136b7e2d39bc09583658d9e77 Mon Sep 17 00:00:00 2001 From: DebXWoody Date: Sat, 23 May 2020 07:41:06 +0200 Subject: OMEMO - Request only "current" item MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NOTE: as per XEP-0060 ยง12.20, it is RECOMMENDED for the publisher to specify an ItemID of "current" to ensure that the publication of a new item will overwrite the existing item. https://xmpp.org/extensions/xep-0384.html#devices Issue: 1329 --- src/xmpp/omemo.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index 780cfe17..3be4dad5 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -442,7 +442,7 @@ _omemo_receive_devicelist(xmpp_stanza_t *const stanza, void *const userdata) } xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(items, "item"); - if (item) { + if (item && 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; @@ -462,6 +462,10 @@ _omemo_receive_devicelist(xmpp_stanza_t *const stanza, void *const userdata) } } } + if (item && g_strcmp0(xmpp_stanza_get_id(item), "current") != 0 ) { + log_warning("OMEMO: User %s has a non 'current' device item list: %s.", from, xmpp_stanza_get_id(item)); + } + omemo_set_device_list(from, device_list); return 1; -- cgit 1.4.1-2-gfad0 From 24e8243a9860c15227c756c5050ea3a5d25d5134 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 29 May 2020 10:28:41 +0200 Subject: _omemo_receive_devicelist() use if/else --- src/xmpp/omemo.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index 3be4dad5..eb4f0fbc 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -442,29 +442,30 @@ _omemo_receive_devicelist(xmpp_stanza_t *const stanza, void *const userdata) } xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(items, "item"); - if (item && 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; + 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; } - 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"); + 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"); + } } + } else { + log_warning("OMEMO: User %s has a non 'current' device item list: %s.", from, xmpp_stanza_get_id(item)); } } - if (item && g_strcmp0(xmpp_stanza_get_id(item), "current") != 0 ) { - log_warning("OMEMO: User %s has a non 'current' device item list: %s.", from, xmpp_stanza_get_id(item)); - } omemo_set_device_list(from, device_list); -- cgit 1.4.1-2-gfad0