Wait for discovery end to publish omemo devicelist and bundle

Add sv_ev_connection_features_received for that purpose
This commit is contained in:
Paul Fariello
2019-04-08 20:29:25 +03:20
parent edbc15fa2b
commit 4ad6904216
10 changed files with 59 additions and 10 deletions

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -2291,6 +2291,8 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *con
}
}
connection_features_received(from);
return 0;
}

View File

@@ -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));

View File

@@ -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)){