mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-05 10:39:27 +02:00
remove unneeded locks II
This commit is contained in:
parent
dd1b98316d
commit
960ee2cb0e
7 changed files with 28 additions and 116 deletions
|
@ -939,7 +939,6 @@ uint32_t dc_get_next_media(dc_context_t* context, uint32_t curr_msg_id, int dir)
|
|||
{
|
||||
uint32_t ret_msg_id = 0;
|
||||
dc_msg_t* msg = dc_msg_new();
|
||||
int locked = 0;
|
||||
dc_array_t* list = NULL;
|
||||
int i, cnt;
|
||||
|
||||
|
@ -947,19 +946,13 @@ uint32_t dc_get_next_media(dc_context_t* context, uint32_t curr_msg_id, int dir)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
if( !dc_msg_load_from_db(msg, context, curr_msg_id) ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( !dc_msg_load_from_db(msg, context, curr_msg_id) ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( (list=dc_get_chat_media(context, msg->m_chat_id, msg->m_type, 0))==NULL ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
if( (list=dc_get_chat_media(context, msg->m_chat_id, msg->m_type, 0))==NULL ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cnt = dc_array_get_cnt(list);
|
||||
for( i = 0; i < cnt; i++ ) {
|
||||
|
@ -983,7 +976,6 @@ uint32_t dc_get_next_media(dc_context_t* context, uint32_t curr_msg_id, int dir)
|
|||
|
||||
|
||||
cleanup:
|
||||
if( locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
dc_array_unref(list);
|
||||
dc_msg_unref(msg);
|
||||
return ret_msg_id;
|
||||
|
@ -2638,7 +2630,7 @@ cleanup:
|
|||
|
||||
int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t contact_id, int flags)
|
||||
{
|
||||
int success = 0, locked = 0;
|
||||
int success = 0;
|
||||
dc_contact_t* contact = dc_get_contact(context, contact_id);
|
||||
dc_apeerstate_t* peerstate = dc_apeerstate_new(context);
|
||||
dc_chat_t* chat = dc_chat_new(context);
|
||||
|
@ -2649,9 +2641,6 @@ int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
|
||||
if( 0==dc_real_group_exists(context, chat_id) /*this also makes sure, not contacts are added to special or normal chats*/
|
||||
|| (0==dc_real_contact_exists(context, contact_id) && contact_id!=DC_CONTACT_ID_SELF)
|
||||
|| 0==dc_chat_load_from_db(chat, chat_id) ) {
|
||||
|
@ -2698,9 +2687,6 @@ int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t
|
|||
}
|
||||
}
|
||||
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
|
||||
/* send a status mail to all group members */
|
||||
if( DO_SEND_STATUS_MAILS )
|
||||
{
|
||||
|
@ -2717,7 +2703,6 @@ int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t
|
|||
success = 1;
|
||||
|
||||
cleanup:
|
||||
if( locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
dc_chat_unref(chat);
|
||||
dc_contact_unref(contact);
|
||||
dc_apeerstate_unref(peerstate);
|
||||
|
@ -3786,25 +3771,19 @@ void dc_update_server_uid(dc_context_t* context, const char* rfc724_mid, const c
|
|||
dc_msg_t* dc_get_msg(dc_context_t* context, uint32_t msg_id)
|
||||
{
|
||||
int success = 0;
|
||||
int db_locked = 0;
|
||||
dc_msg_t* obj = dc_msg_new();
|
||||
|
||||
if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
db_locked = 1;
|
||||
if( !dc_msg_load_from_db(obj, context, msg_id) ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( !dc_msg_load_from_db(obj, context, msg_id) ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
success = 1;
|
||||
success = 1;
|
||||
|
||||
cleanup:
|
||||
if( db_locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
|
||||
if( success ) {
|
||||
return obj;
|
||||
}
|
||||
|
@ -4107,7 +4086,6 @@ void dc_star_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt, i
|
|||
return;
|
||||
}
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
dc_sqlite3_begin_transaction(context->m_sql);
|
||||
|
||||
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->m_sql,
|
||||
|
@ -4122,7 +4100,6 @@ void dc_star_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt, i
|
|||
sqlite3_finalize(stmt);
|
||||
|
||||
dc_sqlite3_commit(context->m_sql);
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -235,8 +235,6 @@ static int load_or_generate_self_public_key__(dc_context_t* context, dc_key_t* p
|
|||
|
||||
dc_log_info(context, 0, "Generating keypair ...");
|
||||
|
||||
dc_sqlite3_unlock(context->m_sql); /* SIC! unlock database during creation - otherwise the GUI may hang */
|
||||
|
||||
/* The public key must contain the following:
|
||||
- a signing-capable primary key Kp
|
||||
- a user id
|
||||
|
@ -246,8 +244,6 @@ static int load_or_generate_self_public_key__(dc_context_t* context, dc_key_t* p
|
|||
(see https://autocrypt.readthedocs.io/en/latest/level0.html#type-p-openpgp-based-key-data )*/
|
||||
key_created = dc_pgp_create_keypair(context, self_addr, public_key, private_key);
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
|
||||
if( !key_created ) {
|
||||
dc_log_warning(context, 0, "Cannot create keypair.");
|
||||
goto cleanup;
|
||||
|
@ -282,7 +278,7 @@ int dc_ensure_secret_key_exists(dc_context_t* context)
|
|||
{
|
||||
/* normally, the key is generated as soon as the first mail is send
|
||||
(this is to gain some extra-random-seed by the message content and the timespan between program start and message sending) */
|
||||
int success = 0, locked = 0;
|
||||
int success = 0;
|
||||
dc_key_t* public_key = dc_key_new();
|
||||
char* self_addr = NULL;
|
||||
|
||||
|
@ -290,9 +286,6 @@ int dc_ensure_secret_key_exists(dc_context_t* context)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
|
||||
if( (self_addr=dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL))==NULL ) {
|
||||
dc_log_warning(context, 0, "Cannot ensure secret key if context is not configured.");
|
||||
goto cleanup;
|
||||
|
@ -305,7 +298,6 @@ int dc_ensure_secret_key_exists(dc_context_t* context)
|
|||
success = 1;
|
||||
|
||||
cleanup:
|
||||
if( locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
dc_key_unref(public_key);
|
||||
free(self_addr);
|
||||
return success;
|
||||
|
@ -341,9 +333,6 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
|
||||
/* init autocrypt header from db */
|
||||
autocryptheader->m_prefer_encrypt = DC_PE_NOPREFERENCE;
|
||||
if( context->m_e2ee_enabled ) {
|
||||
|
@ -399,9 +388,6 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
|
|||
do_encrypt = 0;
|
||||
}
|
||||
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
|
||||
if( (imffields_unprotected=mailmime_find_mailimf_fields(in_out_message))==NULL ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,6 @@
|
|||
*/
|
||||
char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
|
||||
{
|
||||
int locked = 0;
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
char* self_addr = NULL;
|
||||
dc_key_t* curr_private_key = dc_key_new();
|
||||
|
@ -134,9 +133,6 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
|
|||
}
|
||||
|
||||
{
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
|
||||
self_addr = dc_sqlite3_get_config(context->m_sql, "configured_addr", NULL);
|
||||
dc_key_load_self_private(curr_private_key, self_addr, context->m_sql);
|
||||
|
||||
|
@ -145,9 +141,6 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
|
||||
//printf("\n~~~~~~~~~~~~~~~~~~~~SETUP-PAYLOAD~~~~~~~~~~~~~~~~~~~~\n%s~~~~~~~~~~~~~~~~~~~~/SETUP-PAYLOAD~~~~~~~~~~~~~~~~~~~~\n",key_asc); // DEBUG OUTPUT
|
||||
|
||||
|
||||
|
@ -275,7 +268,6 @@ char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
|
|||
|
||||
cleanup:
|
||||
sqlite3_finalize(stmt);
|
||||
if( locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
|
||||
if( payload_output ) { pgp_output_delete(payload_output); }
|
||||
if( payload_mem ) { pgp_memory_free(payload_mem); }
|
||||
|
@ -711,10 +703,6 @@ static int export_self_keys(dc_context_t* context, const char* dir)
|
|||
int id = 0, is_default = 0;
|
||||
dc_key_t* public_key = dc_key_new();
|
||||
dc_key_t* private_key = dc_key_new();
|
||||
int locked = 0;
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
|
||||
if( (stmt=dc_sqlite3_prepare(context->m_sql, "SELECT id, public_key, private_key, is_default FROM keypairs;"))==NULL ) {
|
||||
goto cleanup;
|
||||
|
@ -732,7 +720,6 @@ static int export_self_keys(dc_context_t* context, const char* dir)
|
|||
success = 1;
|
||||
|
||||
cleanup:
|
||||
if( locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
sqlite3_finalize(stmt);
|
||||
dc_key_unref(public_key);
|
||||
dc_key_unref(private_key);
|
||||
|
|
|
@ -305,9 +305,7 @@ static void mark_as_error(dc_context_t* context, dc_msg_t* msg)
|
|||
return;
|
||||
}
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
dc_update_msg_state(context, msg->m_id, DC_STATE_OUT_ERROR);
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
dc_update_msg_state(context, msg->m_id, DC_STATE_OUT_ERROR);
|
||||
context->m_cb(context, DC_EVENT_MSGS_CHANGED, msg->m_chat_id, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ static void load_from__(dc_mimefactory_t* factory)
|
|||
|
||||
int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id)
|
||||
{
|
||||
int success = 0, locked = 0;
|
||||
int success = 0;
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
|
||||
if( factory == NULL || msg_id <= DC_MSG_ID_LAST_SPECIAL
|
||||
|
@ -119,9 +119,6 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id)
|
|||
factory->m_msg = dc_msg_new();
|
||||
factory->m_chat = dc_chat_new(context);
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
|
||||
if( dc_msg_load_from_db(factory->m_msg, context, msg_id)
|
||||
&& dc_chat_load_from_db(factory->m_chat, factory->m_msg->m_chat_id) )
|
||||
{
|
||||
|
@ -238,11 +235,7 @@ int dc_mimefactory_load_msg(dc_mimefactory_t* factory, uint32_t msg_id)
|
|||
factory->m_increation = dc_msg_is_increation(factory->m_msg);
|
||||
}
|
||||
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
|
||||
cleanup:
|
||||
if( locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
}
|
||||
|
@ -250,7 +243,7 @@ cleanup:
|
|||
|
||||
int dc_mimefactory_load_mdn(dc_mimefactory_t* factory, uint32_t msg_id)
|
||||
{
|
||||
int success = 0, locked = 0;
|
||||
int success = 0;
|
||||
dc_contact_t* contact = dc_contact_new(factory->m_context);
|
||||
|
||||
if( factory == NULL ) {
|
||||
|
@ -263,9 +256,6 @@ int dc_mimefactory_load_mdn(dc_mimefactory_t* factory, uint32_t msg_id)
|
|||
factory->m_recipients_addr = clist_new();
|
||||
factory->m_msg = dc_msg_new();
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
|
||||
if( !dc_sqlite3_get_config_int(context->m_sql, "mdns_enabled", DC_MDNS_DEFAULT_ENABLED) ) {
|
||||
goto cleanup; /* MDNs not enabled - check this is late, in the job. the use may have changed its choice while offline ... */
|
||||
}
|
||||
|
@ -292,14 +282,10 @@ int dc_mimefactory_load_mdn(dc_mimefactory_t* factory, uint32_t msg_id)
|
|||
factory->m_timestamp = dc_create_smeared_timestamp__();
|
||||
factory->m_rfc724_mid = dc_create_outgoing_rfc724_mid(NULL, factory->m_from_addr);
|
||||
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
|
||||
success = 1;
|
||||
factory->m_loaded = DC_MF_MDN_LOADED;
|
||||
|
||||
cleanup:
|
||||
if( locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
|
@ -964,7 +964,6 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
time_t sent_timestamp = DC_INVALID_TIMESTAMP;
|
||||
time_t rcvd_timestamp = DC_INVALID_TIMESTAMP;
|
||||
dc_mimeparser_t* mime_parser = dc_mimeparser_new(context->m_blobdir, context);
|
||||
int db_locked = 0;
|
||||
int transaction_pending = 0;
|
||||
const struct mailimf_field* field;
|
||||
|
||||
|
@ -1018,8 +1017,6 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
}
|
||||
}
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
db_locked = 1;
|
||||
dc_sqlite3_begin_transaction(context->m_sql);
|
||||
transaction_pending = 1;
|
||||
|
||||
|
@ -1134,12 +1131,10 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
assert( chat_id == 0 );
|
||||
if( dc_mimeparser_lookup_field(mime_parser, "Secure-Join") ) {
|
||||
dc_sqlite3_commit(context->m_sql);
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
if( dc_handle_securejoin_handshake(context, mime_parser, from_id) == DC_IS_HANDSHAKE_STOP_NORMAL_PROCESSING ) {
|
||||
hidden = 1;
|
||||
state = DC_STATE_IN_SEEN;
|
||||
}
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
dc_sqlite3_begin_transaction(context->m_sql);
|
||||
}
|
||||
|
||||
|
@ -1473,7 +1468,6 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
|
|||
|
||||
cleanup:
|
||||
if( transaction_pending ) { dc_sqlite3_rollback(context->m_sql); }
|
||||
if( db_locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
|
||||
dc_mimeparser_unref(mime_parser);
|
||||
free(rfc724_mid);
|
||||
|
|
|
@ -334,7 +334,6 @@ char* dc_get_securejoin_qr(dc_context_t* context, uint32_t group_chat_id)
|
|||
==== Step 1 in "Setup verified contact" protocol ====
|
||||
========================================================= */
|
||||
|
||||
int locked = 0;
|
||||
char* qr = NULL;
|
||||
char* self_addr = NULL;
|
||||
char* self_addr_urlencoded = NULL;
|
||||
|
@ -353,9 +352,6 @@ char* dc_get_securejoin_qr(dc_context_t* context, uint32_t group_chat_id)
|
|||
|
||||
dc_ensure_secret_key_exists(context);
|
||||
|
||||
dc_sqlite3_lock(context->m_sql);
|
||||
locked = 1;
|
||||
|
||||
// invitenumber will be used to allow starting the handshake, auth will be used to verify the fingerprint
|
||||
invitenumber = dc_token_lookup__(context, DC_TOKEN_INVITENUMBER, group_chat_id);
|
||||
if( invitenumber == NULL ) {
|
||||
|
@ -376,9 +372,6 @@ char* dc_get_securejoin_qr(dc_context_t* context, uint32_t group_chat_id)
|
|||
|
||||
self_name = dc_sqlite3_get_config(context->m_sql, "displayname", "");
|
||||
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
|
||||
if( (fingerprint=get_self_fingerprint(context)) == NULL ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -405,7 +398,6 @@ char* dc_get_securejoin_qr(dc_context_t* context, uint32_t group_chat_id)
|
|||
}
|
||||
|
||||
cleanup:
|
||||
if( locked ) { dc_sqlite3_unlock(context->m_sql); }
|
||||
free(self_addr_urlencoded);
|
||||
free(self_addr);
|
||||
free(self_name);
|
||||
|
@ -586,12 +578,10 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
LOCK
|
||||
if( dc_token_exists__(context, DC_TOKEN_INVITENUMBER, invitenumber) == 0 ) {
|
||||
dc_log_warning(context, 0, "Secure-join denied (bad invitenumber)."); // do not raise an error, this might just be spam or come from an old request
|
||||
goto cleanup;
|
||||
}
|
||||
UNLOCK
|
||||
if( dc_token_exists__(context, DC_TOKEN_INVITENUMBER, invitenumber) == 0 ) {
|
||||
dc_log_warning(context, 0, "Secure-join denied (bad invitenumber)."); // do not raise an error, this might just be spam or come from an old request
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_log_info(context, 0, "Secure-join requested.");
|
||||
|
||||
|
@ -678,23 +668,17 @@ int dc_handle_securejoin_handshake(dc_context_t* context, dc_mimeparser_t* mimep
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
LOCK
|
||||
if( dc_token_exists__(context, DC_TOKEN_AUTH, auth) == 0 ) {
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
could_not_establish_secure_connection(context, contact_chat_id, "Auth invalid.");
|
||||
goto cleanup;
|
||||
}
|
||||
if( dc_token_exists__(context, DC_TOKEN_AUTH, auth) == 0 ) {
|
||||
could_not_establish_secure_connection(context, contact_chat_id, "Auth invalid.");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( !mark_peer_as_verified(context, fingerprint) ) {
|
||||
dc_sqlite3_unlock(context->m_sql);
|
||||
locked = 0;
|
||||
could_not_establish_secure_connection(context, contact_chat_id, "Fingerprint mismatch on inviter-side."); // should not happen, we've compared the fingerprint some lines above
|
||||
goto cleanup;
|
||||
}
|
||||
if( !mark_peer_as_verified(context, fingerprint) ) {
|
||||
could_not_establish_secure_connection(context, contact_chat_id, "Fingerprint mismatch on inviter-side."); // should not happen, we've compared the fingerprint some lines above
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dc_scaleup_contact_origin(context, contact_id, DC_ORIGIN_SECUREJOIN_INVITED);
|
||||
UNLOCK
|
||||
dc_scaleup_contact_origin(context, contact_id, DC_ORIGIN_SECUREJOIN_INVITED);
|
||||
|
||||
dc_log_info(context, 0, "Auth verified.");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue