mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Wait for discovery end to publish omemo devicelist and bundle
Add sv_ev_connection_features_received for that purpose
This commit is contained in:
parent
edbc15fa2b
commit
4ad6904216
@ -176,6 +176,14 @@ sv_ev_roster_received(void)
|
||||
plugins_on_connect(account_name, fulljid);
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_connection_features_received(void)
|
||||
{
|
||||
#ifdef HAVE_OMEMO
|
||||
omemo_publish_crypto_materials();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_lost_connection(void)
|
||||
{
|
||||
|
@ -85,6 +85,7 @@ void sv_ev_muc_occupant_online(const char *const room, const char *const nick, c
|
||||
void sv_ev_roster_update(const char *const barejid, const char *const name,
|
||||
GSList *groups, const char *const subscription, gboolean pending_out);
|
||||
void sv_ev_roster_received(void);
|
||||
void sv_ev_connection_features_received(void);
|
||||
int sv_ev_certfail(const char *const errormsg, TLSCertificate *cert);
|
||||
void sv_ev_lastactivity_response(const char *const from, const int seconds, const char *const msg);
|
||||
void sv_ev_bookmark_autojoin(Bookmark *bookmark);
|
||||
|
@ -27,7 +27,6 @@
|
||||
|
||||
static gboolean loaded;
|
||||
|
||||
static void _omemo_publish_crypto_materials(ProfAccount *account);
|
||||
static void _generate_pre_keys(int count);
|
||||
static void _generate_signed_pre_key(void);
|
||||
static void _load_identity(void);
|
||||
@ -212,7 +211,6 @@ omemo_on_connect(ProfAccount *account)
|
||||
|
||||
if (g_key_file_load_from_file(omemo_ctx.identity_keyfile, omemo_ctx.identity_filename->str, G_KEY_FILE_KEEP_COMMENTS, &error)) {
|
||||
_load_identity();
|
||||
_omemo_publish_crypto_materials(account);
|
||||
} else if (error->code != G_FILE_ERROR_NOENT) {
|
||||
log_warning("OMEMO: error loading identity from: %s, %s", omemo_ctx.identity_filename->str, error->message);
|
||||
return;
|
||||
@ -291,18 +289,27 @@ omemo_generate_crypto_materials(ProfAccount *account)
|
||||
|
||||
loaded = TRUE;
|
||||
|
||||
_omemo_publish_crypto_materials(account);
|
||||
omemo_publish_crypto_materials();
|
||||
}
|
||||
|
||||
static void
|
||||
_omemo_publish_crypto_materials(ProfAccount *account)
|
||||
void
|
||||
omemo_publish_crypto_materials(void)
|
||||
{
|
||||
if (loaded != TRUE) {
|
||||
log_error("OMEMO: cannot publish crypto materials before they are generated");
|
||||
return;
|
||||
}
|
||||
|
||||
Jid *jid = jid_create(connection_get_fulljid());
|
||||
|
||||
/* 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(account->jid), _handle_own_device_list);
|
||||
omemo_devicelist_request(account->jid);
|
||||
g_hash_table_insert(omemo_ctx.device_list_handler, strdup(jid->barejid), _handle_own_device_list);
|
||||
omemo_devicelist_request(jid->barejid);
|
||||
|
||||
omemo_bundle_publish(true);
|
||||
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -21,6 +21,7 @@ void omemo_on_connect(ProfAccount *account);
|
||||
void omemo_on_disconnect(void);
|
||||
void omemo_generate_crypto_materials(ProfAccount *account);
|
||||
void omemo_key_free(omemo_key_t *key);
|
||||
void omemo_publish_crypto_materials(void);
|
||||
|
||||
uint32_t omemo_device_id(void);
|
||||
void omemo_identity_key(unsigned char **output, size_t *length);
|
||||
|
@ -63,6 +63,7 @@ typedef struct prof_conn_t {
|
||||
char *domain;
|
||||
GHashTable *available_resources;
|
||||
GHashTable *features_by_jid;
|
||||
GHashTable *requested_features;
|
||||
} ProfConnection;
|
||||
|
||||
static ProfConnection conn;
|
||||
@ -89,6 +90,7 @@ connection_init(void)
|
||||
conn.domain = NULL;
|
||||
conn.features_by_jid = NULL;
|
||||
conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
|
||||
conn.requested_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@ -231,6 +233,10 @@ connection_clear_data(void)
|
||||
if (conn.available_resources) {
|
||||
g_hash_table_remove_all(conn.available_resources);
|
||||
}
|
||||
|
||||
if (conn.requested_features) {
|
||||
g_hash_table_remove_all(conn.requested_features);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBMESODE
|
||||
@ -313,12 +319,21 @@ connection_jid_for_feature(const char *const feature)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
connection_request_features(void)
|
||||
{
|
||||
/* We don't record it as a requested feature to avoid triggering th
|
||||
* sv_ev_connection_features_received too soon */
|
||||
iq_disco_info_request_onconnect(conn.domain);
|
||||
}
|
||||
|
||||
void
|
||||
connection_set_disco_items(GSList *items)
|
||||
{
|
||||
GSList *curr = items;
|
||||
while (curr) {
|
||||
DiscoItem *item = curr->data;
|
||||
g_hash_table_insert(conn.requested_features, strdup(item->jid), NULL);
|
||||
g_hash_table_insert(conn.features_by_jid, strdup(item->jid),
|
||||
g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL));
|
||||
|
||||
@ -357,6 +372,14 @@ connection_get_fulljid(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
connection_features_received(const char *const jid)
|
||||
{
|
||||
if (g_hash_table_remove(conn.requested_features, jid) && g_hash_table_size(conn.requested_features) == 0) {
|
||||
sv_ev_connection_features_received();
|
||||
}
|
||||
}
|
||||
|
||||
GHashTable*
|
||||
connection_get_features(const char *const jid)
|
||||
{
|
||||
|
@ -53,6 +53,8 @@ void connection_set_disco_items(GSList *items);
|
||||
xmpp_conn_t* connection_get_conn(void);
|
||||
xmpp_ctx_t* connection_get_ctx(void);
|
||||
char *connection_get_domain(void);
|
||||
void connection_request_features(void);
|
||||
void connection_features_received(const char *const jid);
|
||||
GHashTable* connection_get_features(const char *const jid);
|
||||
|
||||
void connection_clear_data(void);
|
||||
|
@ -2291,6 +2291,8 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *con
|
||||
}
|
||||
}
|
||||
|
||||
connection_features_received(from);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,9 @@ 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);
|
||||
|
||||
stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open");
|
||||
if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) {
|
||||
stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open");
|
||||
}
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
@ -76,7 +78,9 @@ omemo_bundle_publish(gboolean first)
|
||||
g_list_free(lengths);
|
||||
g_list_free(ids);
|
||||
|
||||
stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open");
|
||||
if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) {
|
||||
stanza_attach_publish_options(ctx, iq, "pubsub#access_model", "open");
|
||||
}
|
||||
|
||||
iq_id_handler_add(id, _omemo_bundle_publish_result, NULL, GINT_TO_POINTER(first));
|
||||
|
||||
|
@ -320,8 +320,8 @@ session_login_success(gboolean secured)
|
||||
blocking_request();
|
||||
|
||||
// items discovery
|
||||
connection_request_features();
|
||||
char *domain = connection_get_domain();
|
||||
iq_disco_info_request_onconnect(domain);
|
||||
iq_disco_items_request_onconnect(domain);
|
||||
|
||||
if (prefs_get_boolean(PREF_CARBONS)){
|
||||
|
@ -59,3 +59,4 @@ void omemo_start_session(const char *const barejid) {}
|
||||
void omemo_trust(const char *const jid, const char *const fingerprint_formatted) {}
|
||||
void omemo_untrust(const char *const jid, const char *const fingerprint_formatted) {}
|
||||
void omemo_devicelist_publish(GList *device_list) {}
|
||||
void omemo_publish_crypto_materials(void) {}
|
||||
|
Loading…
Reference in New Issue
Block a user