fix(omemo): bootstrap device list on prosody servers (#169) #171

Open
jabber.developer2 wants to merge 1 commits from fix/omemo-prosody-bootstrap into master
2 changed files with 14 additions and 2 deletions

View File

@@ -658,6 +658,15 @@ 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);
const char* barejid = connection_get_barejid();
if (barejid && g_strcmp0(barejid, conn.domain) != 0) {
if (!g_hash_table_contains(conn.features_by_jid, barejid)) {
g_hash_table_insert(conn.features_by_jid, strdup(barejid),
g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL));
}
iq_disco_info_request_onconnect(barejid); // XEP-0163: PEP services announce features on the account's bare JID
Review

so we overwrite the features received from to=server by features from to=barejid here:

// iq.c
void
iq_disco_info_request_onconnect(const char* jid)
{
// ...
    iq_id_handler_add(id, _disco_info_response_id_handler_onconnect, NULL, NULL);
// ...
}

// ...
static int
_disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* const userdata)
{
// ...
    connection_features_received(from);

    return 0;
}

// connection.c
void
connection_features_received(const char* const jid)
{
    const char* key = _get_from_via_jid(jid);
    if (!key) {
        return;
    }
    log_info("[CONNECTION] connection_features_received %s", key);
    if (g_hash_table_remove(conn.requested_features, key) && g_hash_table_size(conn.requested_features) == 0) { // <--- here
        sv_ev_connection_features_received();
    }
}
so we overwrite the features received from `to=server` by features from `to=barejid` here: ```c // iq.c void iq_disco_info_request_onconnect(const char* jid) { // ... iq_id_handler_add(id, _disco_info_response_id_handler_onconnect, NULL, NULL); // ... } // ... static int _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* const userdata) { // ... connection_features_received(from); return 0; } // connection.c void connection_features_received(const char* const jid) { const char* key = _get_from_via_jid(jid); if (!key) { return; } log_info("[CONNECTION] connection_features_received %s", key); if (g_hash_table_remove(conn.requested_features, key) && g_hash_table_size(conn.requested_features) == 0) { // <--- here sv_ev_connection_features_received(); } } ```
}
}
void

View File

@@ -446,18 +446,21 @@ _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata)
GList* device_list = NULL;
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
log_error("[OMEMO] can't get OMEMO device list");
xmpp_stanza_t* error = xmpp_stanza_get_child_by_name(stanza, "error");
if (!error) {
log_error("[OMEMO] missing error element in device list response");
return 1;
}
// a missing node is signalled via legacy code='404' or the RFC 6120 <item-not-found/> condition
const char* code = xmpp_stanza_get_attribute(error, "code");
if (g_strcmp0(code, "404") == 0) {
if (g_strcmp0(code, "404") == 0
|| xmpp_stanza_get_child_by_name_and_ns(error, STANZA_NAME_ITEM_NOT_FOUND, STANZA_NS_STANZAS)) {
log_debug("[OMEMO] no devicelist node for %s, bootstrapping an empty one", from);
omemo_set_device_list(from, NULL);
return 1;
}
log_error("[OMEMO] can't get OMEMO device list");
}
xmpp_stanza_t* root = NULL;