diff options
author | Paul Fariello <paul@fariello.eu> | 2021-08-18 12:07:09 +0200 |
---|---|---|
committer | Paul Fariello <paul@fariello.eu> | 2021-08-19 10:02:07 +0200 |
commit | 0b6cf20183b07b8d3a9c09356e2365d4a21803f7 (patch) | |
tree | ca3b9943215bbabb5ea221d70dc14253a5e5615f /src | |
parent | 46fe69de9b4049c5c4bf6fddb3dfba4480b13caa (diff) | |
download | profani-tty-0b6cf20183b07b8d3a9c09356e2365d4a21803f7.tar.gz |
OMEMO: try device list creation and reconfigure on precondition-not-met
Diffstat (limited to 'src')
-rw-r--r-- | src/omemo/omemo.c | 3 | ||||
-rw-r--r-- | src/xmpp/omemo.c | 30 | ||||
-rw-r--r-- | src/xmpp/stanza.h | 1 |
3 files changed, 26 insertions, 8 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 05f543f6..b5213d6a 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -386,12 +386,11 @@ omemo_publish_crypto_materials(void) char* barejid = connection_get_barejid(); - /* Ensure device list is properly configured */ - omemo_devicelist_configure_and_request(); /* Ensure we get our current device list, and it gets updated with our * device_id */ g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_own_device_list); + omemo_devicelist_request(barejid); omemo_bundle_publish(true); diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index 20bf251a..e0f79c9e 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -48,7 +48,7 @@ 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_submit(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); @@ -70,6 +70,10 @@ 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); @@ -77,7 +81,7 @@ omemo_devicelist_publish(GList* device_list) } void -omemo_devicelist_configure_and_request(void) +omemo_devicelist_configure(void) { xmpp_ctx_t* const ctx = connection_get_ctx(); char* id = connection_create_stanza_id(); @@ -85,7 +89,7 @@ omemo_devicelist_configure_and_request(void) 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_id_handler_add(id, _omemo_devicelist_configure_submit, NULL, NULL); iq_send_stanza(iq); @@ -534,15 +538,29 @@ _omemo_devicelist_publish_result(xmpp_stanza_t* const stanza, void* const userda 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; + + xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error"); + if (!error) { + log_error("[OMEMO] Missing error element in device list publication result"); + return 0; + } + + xmpp_stanza_t *pubsub_error = xmpp_stanza_get_child_by_ns(error, STANZA_NS_PUBSUB_ERROR); + if (!pubsub_error) { + return 0; + } + + if (g_strcmp0(xmpp_stanza_get_name(pubsub_error), "precondition-not-met") == 0) { + omemo_devicelist_configure(); + } } return 0; } static int -_omemo_devicelist_configure(xmpp_stanza_t* const stanza, void* const userdata) +_omemo_devicelist_configure_submit(xmpp_stanza_t* const stanza, void* const userdata) { - log_debug("[OMEMO] _omemo_devicelist_configure()"); + log_debug("[OMEMO] _omemo_devicelist_configure_submit()"); xmpp_stanza_t* pubsub = xmpp_stanza_get_child_by_name(stanza, "pubsub"); if (!pubsub) { diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 52008b1c..7a95629e 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -216,6 +216,7 @@ #define STANZA_NS_PUBSUB "http://jabber.org/protocol/pubsub" #define STANZA_NS_PUBSUB_OWNER "http://jabber.org/protocol/pubsub#owner" #define STANZA_NS_PUBSUB_EVENT "http://jabber.org/protocol/pubsub#event" +#define STANZA_NS_PUBSUB_ERROR "http://jabber.org/protocol/pubsub#error" #define STANZA_NS_CARBONS "urn:xmpp:carbons:2" #define STANZA_NS_HINTS "urn:xmpp:hints" #define STANZA_NS_FORWARD "urn:xmpp:forward:0" |