From d8f0bcef9407f45161e124aa4703d0f0485fb2db Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Tue, 19 Mar 2019 18:40:24 +0140 Subject: [PATCH] Add publish option to OMEMO device list and bundle --- src/xmpp/omemo.c | 14 ++++++++++++++ src/xmpp/stanza.c | 39 +++++++++++++++++++++++++++++++++++++++ src/xmpp/stanza.h | 2 ++ src/xmpp/xmpp.h | 2 ++ 4 files changed, 57 insertions(+) diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index 16610cb5..1a10e374 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -22,6 +22,13 @@ omemo_devicelist_publish(GList *device_list) { xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_stanza_t *iq = stanza_create_omemo_devicelist_publish(ctx, device_list); + + Jid *jid = jid_create(connection_get_fulljid()); + if (caps_jid_has_feature(jid->barejid, XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) { + stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open"); + } + jid_destroy(jid); + iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -62,6 +69,13 @@ omemo_bundle_publish(void) identity_key, identity_key_length, signed_prekey, signed_prekey_length, signed_prekey_signature, signed_prekey_signature_length, prekeys, ids, lengths); + + Jid *jid = jid_create(connection_get_fulljid()); + if (caps_jid_has_feature(jid->barejid, XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) { + stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open"); + } + jid_destroy(jid); + iq_send_stanza(iq); xmpp_stanza_release(iq); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 2b2ec0d8..65a6e02b 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -1832,6 +1832,45 @@ stanza_get_error_message(xmpp_stanza_t *stanza) return strdup("unknown"); } +void +stanza_attach_publish_options(xmpp_ctx_t *const ctx, xmpp_stanza_t *const iq, const char *const option, const char *const value) +{ + xmpp_stanza_t *publish_options = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(publish_options, STANZA_NAME_PUBLISH_OPTIONS); + + xmpp_stanza_t *x = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(x, STANZA_NAME_X); + xmpp_stanza_set_ns(x, STANZA_NS_DATA); + xmpp_stanza_set_type(x, "submit"); + xmpp_stanza_add_child(publish_options, x); + + xmpp_stanza_t *form_type = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(form_type, STANZA_NAME_FIELD); + xmpp_stanza_set_attribute(form_type, STANZA_ATTR_VAR, "FORM_TYPE"); + xmpp_stanza_set_type(form_type, "hidden"); + xmpp_stanza_t *form_type_value = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(form_type_value, STANZA_NAME_VALUE); + xmpp_stanza_t *form_type_value_text = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(form_type_value_text, XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS); + xmpp_stanza_add_child(form_type_value, form_type_value_text); + xmpp_stanza_add_child(form_type, form_type_value); + xmpp_stanza_add_child(x, form_type); + + xmpp_stanza_t *access_model = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(access_model, STANZA_NAME_FIELD); + xmpp_stanza_set_attribute(access_model, STANZA_ATTR_VAR, option); + xmpp_stanza_t *access_model_value = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(access_model_value, STANZA_NAME_VALUE); + xmpp_stanza_t *access_model_value_text = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(access_model_value_text, value); + xmpp_stanza_add_child(access_model_value, access_model_value_text); + xmpp_stanza_add_child(access_model, access_model_value); + xmpp_stanza_add_child(x, access_model); + + xmpp_stanza_t *pubsub = xmpp_stanza_get_child_by_ns(iq, STANZA_NS_PUBSUB); + xmpp_stanza_add_child(pubsub, publish_options); +} + void stanza_attach_priority(xmpp_ctx_t *const ctx, xmpp_stanza_t *const presence, const int pri) { diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index f392eeff..2efb4cff 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -290,6 +290,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); +void stanza_attach_publish_options(xmpp_ctx_t *const ctx, xmpp_stanza_t *const publish, const char *const option, const char *const value); + xmpp_stanza_t* stanza_create_omemo_devicelist_request(xmpp_ctx_t *ctx, const char *const id, const char *const jid); xmpp_stanza_t* stanza_create_omemo_devicelist_subscribe(xmpp_ctx_t *ctx, const char *const jid); xmpp_stanza_t* stanza_create_omemo_devicelist_publish(xmpp_ctx_t *ctx, GList *const ids); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 763c8a91..67cc722c 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -63,6 +63,8 @@ #define XMPP_FEATURE_MUC_NONANONYMOUS "http://jabber.org/protocol/muc#muc_nonanonymous" #define XMPP_FEATURE_COMMANDS "http://jabber.org/protocol/commands" #define XMPP_FEATURE_OMEMO_DEVICELIST_NOTIFY "eu.siacs.conversations.axolotl.devicelist+notify" +#define XMPP_FEATURE_PUBSUB "http://jabber.org/protocol/pubsub" +#define XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS "http://jabber.org/protocol/pubsub#publish-options" typedef enum { JABBER_CONNECTING,