text stringlengths 0 357 |
|---|
success = 1; |
cleanup: |
sqlite3_finalize(stmt); |
return success; |
} |
int dc_apeerstate_load_by_fingerprint(dc_apeerstate_t* peerstate, dc_sqlite3_t* sql, const char* fingerprint) |
{ |
int success = 0; |
sqlite3_stmt* stmt = NULL; |
if (peerstate==NULL || sql==NULL || fingerprint==NULL) { |
goto cleanup; |
} |
dc_apeerstate_empty(peerstate); |
stmt = dc_sqlite3_prepare(sql, |
"SELECT " PEERSTATE_FIELDS |
" FROM acpeerstates " |
" WHERE public_key_fingerprint=? COLLATE NOCASE " |
" OR gossip_key_fingerprint=? COLLATE NOCASE " |
" ORDER BY public_key_fingerprint=? DESC;"); // if for, any reasons, different peers have the same key, prefer the peer with the correct public key. should not happen, however. |
sqlite3_bind_text(stmt, 1, fingerprint, -1, SQLITE_STATIC); |
sqlite3_bind_text(stmt, 2, fingerprint, -1, SQLITE_STATIC); |
sqlite3_bind_text(stmt, 3, fingerprint, -1, SQLITE_STATIC); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
dc_apeerstate_set_from_stmt(peerstate, stmt); |
success = 1; |
cleanup: |
sqlite3_finalize(stmt); |
return success; |
} |
int dc_apeerstate_save_to_db(const dc_apeerstate_t* peerstate, dc_sqlite3_t* sql, int create) |
{ |
int success = 0; |
sqlite3_stmt* stmt = NULL; |
if (peerstate==NULL || sql==NULL || peerstate->addr==NULL) { |
return 0; |
} |
if (create) { |
stmt = dc_sqlite3_prepare(sql, "INSERT INTO acpeerstates (addr) VALUES(?);"); |
sqlite3_bind_text(stmt, 1, peerstate->addr, -1, SQLITE_STATIC); |
sqlite3_step(stmt); |
sqlite3_finalize(stmt); |
stmt = NULL; |
} |
if ((peerstate->to_save&DC_SAVE_ALL) || create) |
{ |
stmt = dc_sqlite3_prepare(sql, |
"UPDATE acpeerstates " |
" SET last_seen=?, last_seen_autocrypt=?, prefer_encrypted=?, " |
" public_key=?, gossip_timestamp=?, gossip_key=?, public_key_fingerprint=?, gossip_key_fingerprint=?, verified_key=?, verified_key_fingerprint=? " |
" WHERE addr=?;"); |
sqlite3_bind_int64(stmt, 1, peerstate->last_seen); |
sqlite3_bind_int64(stmt, 2, peerstate->last_seen_autocrypt); |
sqlite3_bind_int64(stmt, 3, peerstate->prefer_encrypt); |
sqlite3_bind_blob (stmt, 4, peerstate->public_key? peerstate->public_key->binary : NULL/*results in sqlite3_bind_null()*/, peerstate->public_key? peerstate->public_key->bytes : 0, SQLITE_STATIC); |
sqlite3_bind_int64(stmt, 5, peerstate->gossip_timestamp); |
sqlite3_bind_blob (stmt, 6, peerstate->gossip_key? peerstate->gossip_key->binary : NULL/*results in sqlite3_bind_null()*/, peerstate->gossip_key? peerstate->gossip_key->bytes : 0, SQLITE_STATIC); |
sqlite3_bind_text (stmt, 7, peerstate->public_key_fingerprint, -1, SQLITE_STATIC); |
sqlite3_bind_text (stmt, 8, peerstate->gossip_key_fingerprint, -1, SQLITE_STATIC); |
sqlite3_bind_blob (stmt, 9, peerstate->verified_key? peerstate->verified_key->binary : NULL/*results in sqlite3_bind_null()*/, peerstate->verified_key? peerstate->verified_key->bytes : 0, SQLITE_STATIC); |
sqlite3_bind_text (stmt,10, peerstate->verified_key_fingerprint, -1, SQLITE_STATIC); |
sqlite3_bind_text (stmt,11, peerstate->addr, -1, SQLITE_STATIC); |
if (sqlite3_step(stmt)!=SQLITE_DONE) { |
goto cleanup; |
} |
sqlite3_finalize(stmt); |
stmt = NULL; |
} |
else if (peerstate->to_save&DC_SAVE_TIMESTAMPS) |
{ |
stmt = dc_sqlite3_prepare(sql, |
"UPDATE acpeerstates SET last_seen=?, last_seen_autocrypt=?, gossip_timestamp=? WHERE addr=?;"); |
sqlite3_bind_int64(stmt, 1, peerstate->last_seen); |
sqlite3_bind_int64(stmt, 2, peerstate->last_seen_autocrypt); |
sqlite3_bind_int64(stmt, 3, peerstate->gossip_timestamp); |
sqlite3_bind_text (stmt, 4, peerstate->addr, -1, SQLITE_STATIC); |
if (sqlite3_step(stmt)!=SQLITE_DONE) { |
goto cleanup; |
} |
sqlite3_finalize(stmt); |
stmt = NULL; |
} |
if ((peerstate->to_save&DC_SAVE_ALL) || create) { |
dc_reset_gossiped_timestamp(peerstate->context, 0); |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.