use the functionality from sql_reliability.h in existing Engine code

gitea-90
positron 2 weeks ago
parent 635016834b
commit 613b62fa65

@ -29,7 +29,7 @@ function "exec_sql_int" {
call "init_sql" with "sql", "$sql";
||
int _result = 0;
int_result = sqlite3_step(_sql);
int_result = pEp_sqlite3_step_nonbusy(session, _sql);
PEP_ASSERT(int_result == SQLITE_ROW);
if (int_result == SQLITE_ROW)
_result = sqlite3_column_int(_sql, 0);

@ -297,7 +297,9 @@ static PEP_STATUS echo_get_below_rate_limit(PEP_SESSION session,
ON_SQL_ERROR_SET_STATUS_AND_GOTO;
/* Execute it. The result must be one row with one column. */
sql_status = sqlite3_step(session->echo_get_echo_below_rate_limit);
sql_status
= pEp_sqlite3_step_nonbusy(session,
session->echo_get_echo_below_rate_limit);
ON_SQL_ERROR_SET_STATUS_AND_GOTO;
PEP_ASSERT(sql_status == SQLITE_ROW);
PEP_ASSERT(sqlite3_column_count(session->echo_get_echo_below_rate_limit)
@ -349,7 +351,7 @@ static PEP_STATUS echo_set_last_echo_timestap(PEP_SESSION session,
ON_SQL_ERROR_SET_STATUS_AND_GOTO;
/* Execute it. */
sql_status = sqlite3_step(session->echo_set_timestamp);
sql_status = pEp_sqlite3_step_nonbusy(session, session->echo_set_timestamp);
ON_SQL_ERROR_SET_STATUS_AND_GOTO;
PEP_ASSERT(sql_status == SQLITE_DONE);
@ -411,7 +413,7 @@ static PEP_STATUS echo_challenge_for_identity(PEP_SESSION session,
sql_status = sqlite3_bind_text(session->echo_get_challenge,
2, identity->user_id, -1, SQLITE_STATIC);
ON_SQL_ERROR_SET_STATUS_AND_GOTO;
sql_status = sqlite3_step(session->echo_get_challenge);
sql_status = pEp_sqlite3_step_nonbusy(session, session->echo_get_challenge);
ON_SQL_ERROR_SET_STATUS_AND_GOTO;
if (sql_status != SQLITE_ROW)
LOG_ERROR("foo!");
@ -449,7 +451,7 @@ static PEP_STATUS echo_challenge_for_identity(PEP_SESSION session,
= sqlite3_bind_text(session->echo_set_challenge, 3, identity->user_id,
-1, SQLITE_STATIC);
ON_SQL_ERROR_SET_STATUS_AND_GOTO;
sql_status = sqlite3_step(session->echo_set_challenge);
sql_status = pEp_sqlite3_step_nonbusy(session, session->echo_set_challenge);
ON_SQL_ERROR_SET_STATUS_AND_GOTO;
/* If we arrived here then the SQL UPDATE statement succeeded. */

@ -145,7 +145,7 @@ static int db_contains_table(PEP_SESSION session, const char* table_name) {
int retval = 0;
int rc = sqlite3_step(stmt);
int rc = pEp_sqlite3_step_nonbusy(session, stmt);
if (rc == SQLITE_DONE || rc == SQLITE_OK || rc == SQLITE_ROW) {
retval = 1;
}
@ -208,7 +208,7 @@ static int table_contains_column(PEP_SESSION session, const char* table_name,
int retval = 0;
int rc = sqlite3_step(stmt);
int rc = pEp_sqlite3_step_nonbusy(session, stmt);
if (rc == SQLITE_DONE || rc == SQLITE_OK || rc == SQLITE_ROW) {
retval = 1;
}
@ -239,7 +239,7 @@ PEP_STATUS repair_altered_tables(PEP_SESSION session) {
sqlite3_prepare_v2(session->db, sql_query, -1, &stmt, NULL);
int i = 0;
int int_result = 0;
while ((int_result = sqlite3_step(stmt)) == SQLITE_ROW && i < _PEP_MAX_AFFECTED) {
while ((int_result = pEp_sqlite3_step_nonbusy(session, stmt)) == SQLITE_ROW && i < _PEP_MAX_AFFECTED) {
table_names[i++] = strdup((const char*)(sqlite3_column_text(stmt, 0)));
}
@ -492,7 +492,7 @@ static PEP_STATUS upgrade_revoc_contact_to_13(PEP_SESSION session) {
sqlite3_bind_text(update_revoked_w_addr_stmt, 2, curr_key->value, -1,
SQLITE_STATIC);
int_result = sqlite3_step(update_revoked_w_addr_stmt);
int_result = pEp_sqlite3_step_nonbusy(session, update_revoked_w_addr_stmt);
PEP_ASSERT(int_result == SQLITE_DONE);
sql_reset_and_clear_bindings(update_revoked_w_addr_stmt);

@ -306,7 +306,7 @@ static PEP_STATUS _set_own_status_joined(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->group_join, 4, as_member->address, -1,
SQLITE_STATIC);
result = sqlite3_step(session->group_join);
result = pEp_sqlite3_step_nonbusy(session, session->group_join);
sql_reset_and_clear_bindings(session->group_join);
@ -338,7 +338,7 @@ static PEP_STATUS _remove_member_from_group(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->group_delete_member, 4, member->address, -1,
SQLITE_STATIC);
result = sqlite3_step(session->group_delete_member);
result = pEp_sqlite3_step_nonbusy(session, session->group_delete_member);
sql_reset_and_clear_bindings(session->group_delete_member);
@ -369,7 +369,7 @@ static PEP_STATUS _set_leave_group_status(PEP_SESSION session, pEp_identity* gro
sqlite3_bind_text(session->leave_group, 4, leaver->address, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->leave_group);
int result = pEp_sqlite3_step_nonbusy(session, session->leave_group);
sql_reset_and_clear_bindings(session->leave_group);
@ -394,7 +394,7 @@ static PEP_STATUS _set_group_as_disabled(PEP_SESSION session, pEp_identity* grou
SQLITE_STATIC);
sqlite3_bind_text(session->disable_group, 2, group_identity->address, -1,
SQLITE_STATIC);
result = sqlite3_step(session->disable_group);
result = pEp_sqlite3_step_nonbusy(session, session->disable_group);
sql_reset_and_clear_bindings(session->disable_group);
@ -430,7 +430,7 @@ static PEP_STATUS _retrieve_own_membership_info_for_group(PEP_SESSION session, p
sqlite3_bind_text(session->retrieve_own_membership_info_for_group, 2, group_identity->address, -1,
SQLITE_STATIC);
while ((result = sqlite3_step(session->retrieve_own_membership_info_for_group)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->retrieve_own_membership_info_for_group)) == SQLITE_ROW) {
ident = new_identity((const char *) sqlite3_column_text(session->retrieve_own_membership_info_for_group, 1),
NULL,(const char *) sqlite3_column_text(session->retrieve_own_membership_info_for_group, 0),
NULL);
@ -504,6 +504,8 @@ static PEP_STATUS is_invited_group_member(PEP_SESSION session, pEp_identity* gro
if (!member || EMPTYSTR(member->user_id) || EMPTYSTR(member->address))
return PEP_ILLEGAL_VALUE;
sql_reset_and_clear_bindings(session->is_invited_group_member);
sqlite3_bind_text(session->is_invited_group_member, 1, group_identity->user_id, -1,
SQLITE_STATIC);
sqlite3_bind_text(session->is_invited_group_member, 2, group_identity->address, -1,
@ -513,7 +515,7 @@ static PEP_STATUS is_invited_group_member(PEP_SESSION session, pEp_identity* gro
sqlite3_bind_text(session->is_invited_group_member, 4, member->address, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->is_invited_group_member);
int result = pEp_sqlite3_step_nonbusy(session, session->is_invited_group_member);
if (result != SQLITE_ROW)
status = PEP_UNKNOWN_DB_ERROR;
@ -599,7 +601,7 @@ PEP_STATUS set_membership_status(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->set_group_member_status, 5, as_member->address, -1,
SQLITE_STATIC);
result = sqlite3_step(session->set_group_member_status);
result = pEp_sqlite3_step_nonbusy(session, session->set_group_member_status);
sql_reset_and_clear_bindings(session->set_group_member_status);
@ -628,7 +630,7 @@ PEP_STATUS get_group_manager(PEP_SESSION session,
*manager = NULL;
int result = sqlite3_step(session->get_group_manager);
int result = pEp_sqlite3_step_nonbusy(session, session->get_group_manager);
if (result != SQLITE_ROW)
status = PEP_GROUP_NOT_FOUND;
@ -656,7 +658,7 @@ PEP_STATUS is_group_active(PEP_SESSION session, pEp_identity* group_identity, bo
sqlite3_bind_text(session->is_group_active, 2, group_identity->address, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->is_group_active);
int result = pEp_sqlite3_step_nonbusy(session, session->is_group_active);
switch (result) {
case SQLITE_ROW:
@ -713,7 +715,7 @@ PEP_STATUS create_group_entry(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->create_group, 4, manager->address, -1,
SQLITE_STATIC);
result = sqlite3_step(session->create_group);
result = pEp_sqlite3_step_nonbusy(session, session->create_group);
sql_reset_and_clear_bindings(session->create_group);
@ -740,6 +742,8 @@ PEP_STATUS add_own_membership_entry(PEP_SESSION session,
if (EMPTYSTR(own_identity_recip->user_id) || EMPTYSTR(own_identity_recip->address))
return PEP_ILLEGAL_VALUE;
sql_reset_and_clear_bindings(session->add_own_membership_entry);
int result = 0;
sqlite3_bind_text(session->add_own_membership_entry, 1, group_identity->user_id, -1,
@ -750,7 +754,7 @@ PEP_STATUS add_own_membership_entry(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->add_own_membership_entry, 4, own_identity_recip->address, -1,
SQLITE_STATIC);
result = sqlite3_step(session->add_own_membership_entry);
result = pEp_sqlite3_step_nonbusy(session, session->add_own_membership_entry);
sql_reset_and_clear_bindings(session->add_own_membership_entry);
@ -776,7 +780,7 @@ PEP_STATUS get_own_membership_status(PEP_SESSION session,
sqlite3_bind_text(session->get_own_membership_status, 4, own_identity->address, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->get_own_membership_status);
int result = pEp_sqlite3_step_nonbusy(session, session->get_own_membership_status);
switch (result) {
case SQLITE_ROW:
@ -822,7 +826,7 @@ PEP_STATUS retrieve_own_membership_info_for_group_and_identity(PEP_SESSION sessi
sqlite3_bind_text(session->retrieve_own_membership_info_for_group_and_ident, 4, own_identity->address, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->retrieve_own_membership_info_for_group_and_ident);
int result = pEp_sqlite3_step_nonbusy(session, session->retrieve_own_membership_info_for_group_and_ident);
switch (result) {
@ -906,7 +910,7 @@ PEP_STATUS leave_group(
SQLITE_STATIC);
sqlite3_bind_text(session->leave_group, 4, member_identity->address, -1,
SQLITE_STATIC);
result = sqlite3_step(session->leave_group);
result = pEp_sqlite3_step_nonbusy(session, session->leave_group);
sql_reset_and_clear_bindings(session->leave_group);
@ -936,7 +940,7 @@ PEP_STATUS group_enable(
SQLITE_STATIC);
sqlite3_bind_text(session->enable_group, 2, group_identity->address, -1,
SQLITE_STATIC);
result = sqlite3_step(session->enable_group);
result = pEp_sqlite3_step_nonbusy(session, session->enable_group);
sql_reset_and_clear_bindings(session->enable_group);
@ -960,7 +964,7 @@ PEP_STATUS exists_group(
sqlite3_bind_text(session->exists_group_entry, 2, group_identity->address, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->exists_group_entry);
int result = pEp_sqlite3_step_nonbusy(session, session->exists_group_entry);
switch (result) {
case SQLITE_ROW: {
@ -1005,7 +1009,7 @@ PEP_STATUS group_add_member(
SQLITE_STATIC);
result = sqlite3_step(session->group_add_member);
result = pEp_sqlite3_step_nonbusy(session, session->group_add_member);
sql_reset_and_clear_bindings(session->group_add_member);
@ -1039,7 +1043,7 @@ PEP_STATUS retrieve_full_group_membership(
member_list* retval = NULL;
member_list** member_list_next = &retval;
while ((result = sqlite3_step(session->get_all_members)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_all_members)) == SQLITE_ROW) {
pEp_identity *ident = new_identity((const char *) sqlite3_column_text(session->get_all_members, 1),
NULL,(const char *) sqlite3_column_text(session->get_all_members, 0),
NULL);
@ -1100,7 +1104,7 @@ PEP_STATUS retrieve_active_member_list(
member_list* retval = NULL;
member_list** mbr_list_next = &retval;
while ((result = sqlite3_step(session->get_active_members)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_active_members)) == SQLITE_ROW) {
pEp_identity *ident = new_identity((const char *) sqlite3_column_text(session->get_active_members, 1),
NULL,(const char *) sqlite3_column_text(session->get_active_members, 0),
NULL);
@ -2427,7 +2431,7 @@ PEP_STATUS is_active_group_member(PEP_SESSION session, pEp_identity* group_ident
sqlite3_bind_text(session->is_active_group_member, 4, member->address, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->is_active_group_member);
int result = pEp_sqlite3_step_nonbusy(session, session->is_active_group_member);
if (result == SQLITE_ROW)
*is_active = sqlite3_column_int(session->is_active_group_member, 0);

@ -405,7 +405,7 @@ PEP_STATUS has_key_reset_been_sent(
SQLITE_STATIC);
sqlite3_bind_text(session->was_id_for_revoke_contacted, 3, user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->was_id_for_revoke_contacted);
int result = pEp_sqlite3_step_nonbusy(session, session->was_id_for_revoke_contacted);
switch (result) {
case SQLITE_ROW: {
*contacted = (sqlite3_column_int(session->was_id_for_revoke_contacted, 0) != 0);
@ -417,6 +417,8 @@ PEP_STATUS has_key_reset_been_sent(
return PEP_UNKNOWN_DB_ERROR;
}
// positron: is alias_default leaked when we arrive here? I strongly suspect it is.
sql_reset_and_clear_bindings(session->was_id_for_revoke_contacted);
return PEP_STATUS_OK;
}
@ -442,7 +444,7 @@ PEP_STATUS set_reset_contact_notified(
int result;
result = sqlite3_step(session->set_revoke_contact_as_notified);
result = pEp_sqlite3_step_nonbusy(session, session->set_revoke_contact_as_notified);
switch (result) {
case SQLITE_DONE:
status = PEP_STATUS_OK;

@ -230,7 +230,7 @@ PEP_STATUS get_all_keys_for_user(PEP_SESSION session,
int result = -1;
while ((result = sqlite3_step(session->get_all_keys_for_user)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_all_keys_for_user)) == SQLITE_ROW) {
const char* keyres = (const char *) sqlite3_column_text(session->get_all_keys_for_user, 0);
if (keyres) {
if (_kl)
@ -267,7 +267,7 @@ PEP_STATUS get_all_keys_for_identity(PEP_SESSION session,
int result = -1;
while ((result = sqlite3_step(session->get_all_keys_for_identity)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_all_keys_for_identity)) == SQLITE_ROW) {
const char* keyres = (const char *) sqlite3_column_text(session->get_all_keys_for_identity, 0);
if (keyres) {
if (_kl)
@ -298,7 +298,7 @@ PEP_STATUS get_user_default_key(PEP_SESSION session, const char* user_id,
sqlite3_bind_text(session->get_user_default_key, 1, user_id,
-1, SQLITE_STATIC);
const int result = sqlite3_step(session->get_user_default_key);
const int result = pEp_sqlite3_step_nonbusy(session, session->get_user_default_key);
char* user_fpr = NULL;
if (result == SQLITE_ROW) {
const char* u_fpr =
@ -1590,7 +1590,7 @@ DYNAMIC_API PEP_STATUS own_key_is_listed(
int result;
result = sqlite3_step(session->own_key_is_listed);
result = pEp_sqlite3_step_nonbusy(session, session->own_key_is_listed);
switch (result) {
case SQLITE_ROW:
count = sqlite3_column_int(session->own_key_is_listed, 0);
@ -1637,7 +1637,7 @@ PEP_STATUS _own_identities_retrieve(
sqlite3_bind_int(session->own_identities_retrieve, 1, excluded_flags);
do {
result = sqlite3_step(session->own_identities_retrieve);
result = pEp_sqlite3_step_nonbusy(session, session->own_identities_retrieve);
switch (result) {
case SQLITE_ROW:
address = (const char *)
@ -1728,7 +1728,7 @@ PEP_STATUS _own_keys_retrieve(
sqlite3_bind_int(session->own_keys_retrieve, 1, excluded_flags);
do {
result = sqlite3_step(session->own_keys_retrieve);
result = pEp_sqlite3_step_nonbusy(session, session->own_keys_retrieve);
switch (result) {
case SQLITE_ROW:
_bl = stringlist_add(_bl, (const char *)
@ -1808,7 +1808,7 @@ PEP_STATUS update_key_sticky_bit_for_user(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->update_key_sticky_bit_for_user, 3, fpr, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->update_key_sticky_bit_for_user);
int result = pEp_sqlite3_step_nonbusy(session, session->update_key_sticky_bit_for_user);
sql_reset_and_clear_bindings(session->update_key_sticky_bit_for_user);
if (result != SQLITE_DONE) {
return PEP_CANNOT_SET_TRUST;
@ -1833,7 +1833,7 @@ PEP_STATUS get_key_sticky_bit_for_user(PEP_SESSION session,
sqlite3_bind_text(session->is_key_sticky_for_user, 2, fpr, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->is_key_sticky_for_user);
int result = pEp_sqlite3_step_nonbusy(session, session->is_key_sticky_for_user);
switch (result) {
case SQLITE_ROW: {
*is_sticky = sqlite3_column_int(session->is_key_sticky_for_user, 0);
@ -1958,7 +1958,7 @@ PEP_STATUS add_mistrusted_key(PEP_SESSION session, const char* fpr)
sqlite3_bind_text(session->add_mistrusted_key, 1, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->add_mistrusted_key);
result = pEp_sqlite3_step_nonbusy(session, session->add_mistrusted_key);
sql_reset_and_clear_bindings(session->add_mistrusted_key);
if (result != SQLITE_DONE)
@ -1976,7 +1976,7 @@ PEP_STATUS delete_mistrusted_key(PEP_SESSION session, const char* fpr)
sqlite3_bind_text(session->delete_mistrusted_key, 1, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->delete_mistrusted_key);
result = pEp_sqlite3_step_nonbusy(session, session->delete_mistrusted_key);
sql_reset_and_clear_bindings(session->delete_mistrusted_key);
if (result != SQLITE_DONE)
@ -1998,7 +1998,7 @@ PEP_STATUS is_mistrusted_key(PEP_SESSION session, const char* fpr,
int result;
result = sqlite3_step(session->is_mistrusted_key);
result = pEp_sqlite3_step_nonbusy(session, session->is_mistrusted_key);
switch (result) {
case SQLITE_ROW:
*mistrusted = sqlite3_column_int(session->is_mistrusted_key, 0);

@ -341,7 +341,7 @@ DYNAMIC_API PEP_STATUS trustword(
sqlite3_bind_text(session->trustword, 1, lang, -1, SQLITE_STATIC);
sqlite3_bind_int(session->trustword, 2, value);
const int result = sqlite3_step(session->trustword);
const int result = pEp_sqlite3_step_nonbusy(session, session->trustword);
if (result == SQLITE_ROW) {
*word = strdup((const char *) sqlite3_column_text(session->trustword,
1));
@ -527,7 +527,7 @@ DYNAMIC_API PEP_STATUS get_default_own_userid(
sql_reset_and_clear_bindings(session->get_default_own_userid);
const int result = sqlite3_step(session->get_default_own_userid);
const int result = pEp_sqlite3_step_nonbusy(session, session->get_default_own_userid);
const char* id;
switch (result) {
@ -569,7 +569,7 @@ DYNAMIC_API PEP_STATUS get_userid_alias_default(
const char* tempid;
const int result = sqlite3_step(session->get_userid_alias_default);
const int result = pEp_sqlite3_step_nonbusy(session, session->get_userid_alias_default);
switch (result) {
case SQLITE_ROW:
tempid = (const char *) sqlite3_column_text(session->get_userid_alias_default, 0);
@ -597,7 +597,7 @@ DYNAMIC_API PEP_STATUS set_userid_alias (
int result;
sqlite3_exec(session->db, "BEGIN TRANSACTION ;", NULL, NULL, NULL);
PEP_SQL_BEGIN_EXCLUSIVE_TRANSACTION();
sql_reset_and_clear_bindings(session->add_userid_alias);
sqlite3_bind_text(session->add_userid_alias, 1, default_id, -1,
@ -606,13 +606,14 @@ DYNAMIC_API PEP_STATUS set_userid_alias (
SQLITE_STATIC);
result = sqlite3_step(session->add_userid_alias);
PEP_ASSERT(result != SQLITE_BUSY && result != SQLITE_LOCKED); // we are inside an EXCLUSIVE transaction
sql_reset_and_clear_bindings(session->add_userid_alias);
if (result != SQLITE_DONE) {
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
PEP_SQL_ROLLBACK_TRANSACTION();
return PEP_CANNOT_SET_ALIAS;
}
sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
PEP_SQL_COMMIT_TRANSACTION();
return PEP_STATUS_OK;
@ -635,7 +636,7 @@ DYNAMIC_API PEP_STATUS get_identity(
sqlite3_bind_text(session->get_identity, 1, address, -1, SQLITE_STATIC);
sqlite3_bind_text(session->get_identity, 2, user_id, -1, SQLITE_STATIC);
const int result = sqlite3_step(session->get_identity);
const int result = pEp_sqlite3_step_nonbusy(session, session->get_identity);
switch (result) {
case SQLITE_ROW:
_identity = new_identity(
@ -701,7 +702,7 @@ PEP_STATUS get_identities_by_userid(
sqlite3_bind_text(session->get_identities_by_userid, 1, user_id, -1, SQLITE_STATIC);
int result = -1;
while ((result = sqlite3_step(session->get_identities_by_userid)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_identities_by_userid)) == SQLITE_ROW) {
// "select address, identity.main_key_id, username, comm_type, lang,"
// " identity.flags | pgp_keypair.flags,"
// " is_own"
@ -784,7 +785,7 @@ PEP_STATUS get_identities_by_main_key_id(
int result = -1;
while ((result = sqlite3_step(session->get_identities_by_main_key_id)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_identities_by_main_key_id)) == SQLITE_ROW) {
ident = new_identity(
(const char *) sqlite3_column_text(session->get_identities_by_main_key_id, 0),
fpr,
@ -853,7 +854,7 @@ PEP_STATUS get_identity_without_trust_check(
sqlite3_bind_text(session->get_identity_without_trust_check, 1, address, -1, SQLITE_STATIC);
sqlite3_bind_text(session->get_identity_without_trust_check, 2, user_id, -1, SQLITE_STATIC);
const int result = sqlite3_step(session->get_identity_without_trust_check);
const int result = pEp_sqlite3_step_nonbusy(session, session->get_identity_without_trust_check);
switch (result) {
case SQLITE_ROW:
_identity = new_identity(
@ -916,7 +917,7 @@ PEP_STATUS get_identities_by_address(
sqlite3_bind_text(session->get_identities_by_address, 1, address, -1, SQLITE_STATIC);
int result;
while ((result = sqlite3_step(session->get_identities_by_address)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_identities_by_address)) == SQLITE_ROW) {
//"select user_id, main_key_id, username, comm_type, lang,"
//" identity.flags, is_own"
pEp_identity *ident = new_identity(
@ -1000,7 +1001,7 @@ PEP_STATUS exists_identity_entry(PEP_SESSION session, pEp_identity* identity,
sqlite3_bind_text(session->exists_identity_entry, 2, identity->user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->exists_identity_entry);
int result = pEp_sqlite3_step_nonbusy(session, session->exists_identity_entry);
switch (result) {
case SQLITE_ROW: {
@ -1031,7 +1032,7 @@ PEP_STATUS exists_trust_entry(PEP_SESSION session, pEp_identity* identity,
sqlite3_bind_text(session->exists_trust_entry, 2, identity->fpr, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->exists_trust_entry);
int result = pEp_sqlite3_step_nonbusy(session, session->exists_trust_entry);
switch (result) {
case SQLITE_ROW: {
// yeah yeah, I know, we could be lazy here, but it looks bad.
@ -1054,7 +1055,7 @@ PEP_STATUS set_pgp_keypair(PEP_SESSION session, const char* fpr) {
sql_reset_and_clear_bindings(session->set_pgp_keypair);
sqlite3_bind_text(session->set_pgp_keypair, 1, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->set_pgp_keypair);
result = pEp_sqlite3_step_nonbusy(session, session->set_pgp_keypair);
sql_reset_and_clear_bindings(session->set_pgp_keypair);
if (result != SQLITE_DONE) {
return PEP_CANNOT_SET_PGP_KEYPAIR;
@ -1075,7 +1076,7 @@ PEP_STATUS clear_trust_info(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->clear_trust_info, 2, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->clear_trust_info);
result = pEp_sqlite3_step_nonbusy(session, session->clear_trust_info);
sql_reset_and_clear_bindings(session->clear_trust_info);
if (result != SQLITE_DONE) {
return PEP_UNKNOWN_ERROR;
@ -1118,7 +1119,7 @@ static PEP_STATUS _set_or_update_trust(PEP_SESSION session,
sqlite3_bind_text(set_or_update, 2, identity->fpr, -1,
SQLITE_STATIC);
sqlite3_bind_int(set_or_update, 3, identity->comm_type);
result = sqlite3_step(set_or_update);
result = pEp_sqlite3_step_nonbusy(session, set_or_update);
sql_reset_and_clear_bindings(set_or_update);
PEP_WEAK_ASSERT_ORELSE_RETURN(result == SQLITE_DONE, PEP_CANNOT_SET_TRUST);
@ -1161,7 +1162,7 @@ static PEP_STATUS _set_or_update_identity_entry(PEP_SESSION session,
sqlite3_bind_int(set_or_update, 7, identity->major_ver);
sqlite3_bind_int(set_or_update, 8, identity->minor_ver);
int result = sqlite3_step(set_or_update);
int result = pEp_sqlite3_step_nonbusy(session, set_or_update);
sql_reset_and_clear_bindings(set_or_update);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_IDENTITY;
@ -1203,7 +1204,7 @@ static PEP_STATUS _set_or_update_person(PEP_SESSION session,
sqlite3_bind_null(set_or_update, 3);
sqlite3_bind_text(set_or_update, 4, EMPTYSTR(identity->fpr) ? NULL : identity->fpr, -1,
SQLITE_STATIC);
int result = sqlite3_step(set_or_update);
int result = pEp_sqlite3_step_nonbusy(session, set_or_update);
sql_reset_and_clear_bindings(set_or_update);
if (result != SQLITE_DONE)
@ -1221,9 +1222,8 @@ PEP_STATUS set_or_update_with_identity(PEP_SESSION session,
bool guard_transaction) {
PEP_REQUIRE(session && identity && set_function && exists_function);
if (guard_transaction) {
sqlite3_exec(session->db, "BEGIN TRANSACTION ;", NULL, NULL, NULL);
}
if (guard_transaction)
PEP_SQL_BEGIN_EXCLUSIVE_TRANSACTION();
bool exists = false;
PEP_STATUS status = exists_function(session, identity, &exists);
@ -1237,9 +1237,9 @@ PEP_STATUS set_or_update_with_identity(PEP_SESSION session,
}
if (guard_transaction) {
if (status != PEP_STATUS_OK)
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
else
sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
PEP_SQL_ROLLBACK_TRANSACTION();
else
PEP_SQL_COMMIT_TRANSACTION();
}
return status;
}
@ -1333,7 +1333,7 @@ DYNAMIC_API PEP_STATUS set_identity(
bool has_fpr = (!EMPTYSTR(identity->fpr));
sqlite3_exec(session->db, "BEGIN TRANSACTION ;", NULL, NULL, NULL);
PEP_SQL_BEGIN_EXCLUSIVE_TRANSACTION();
if (identity->lang[0]) {
PEP_ASSERT(identity->lang[0] >= 'a' && identity->lang[0] <= 'z');
@ -1346,9 +1346,10 @@ DYNAMIC_API PEP_STATUS set_identity(
sqlite3_bind_text(session->set_pgp_keypair, 1, identity->fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->set_pgp_keypair);
PEP_ASSERT(result != SQLITE_BUSY && result != SQLITE_LOCKED); // we are inside an EXCLUSIVE transaction
sql_reset_and_clear_bindings(session->set_pgp_keypair);
if (result != SQLITE_DONE) {
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
PEP_SQL_ROLLBACK_TRANSACTION();
return PEP_CANNOT_SET_PGP_KEYPAIR;
}
}
@ -1362,35 +1363,32 @@ DYNAMIC_API PEP_STATUS set_identity(
// For now, we ALWAYS set the person.username.
status = set_person(session, ident_copy, false);
if (status != PEP_STATUS_OK) {
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
PEP_SQL_ROLLBACK_TRANSACTION();
goto pEp_free;
}
status = set_identity_entry(session, ident_copy, false);
if (status != PEP_STATUS_OK) {
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
PEP_SQL_ROLLBACK_TRANSACTION();
goto pEp_free;
}
if (has_fpr) {
status = _set_trust_internal(session, ident_copy, false);
if (status != PEP_STATUS_OK) {
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
PEP_SQL_ROLLBACK_TRANSACTION();
goto pEp_free;
}
}
status = set_protocol_version(session, ident_copy, ident_copy->major_ver, ident_copy->minor_ver);
if (status != PEP_STATUS_OK) {
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
PEP_SQL_ROLLBACK_TRANSACTION();
goto pEp_free;
}
result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
if (result == SQLITE_OK)
status = PEP_STATUS_OK;
else
status = PEP_COMMIT_FAILED;
PEP_SQL_COMMIT_TRANSACTION();
status = PEP_STATUS_OK;
pEp_free:
free_identity(ident_copy);
@ -1424,7 +1422,7 @@ PEP_STATUS force_set_identity_username(PEP_SESSION session, pEp_identity* ident,
SQLITE_STATIC);
sqlite3_bind_text(session->force_set_identity_username, 3, username, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->force_set_identity_username);
int result = pEp_sqlite3_step_nonbusy(session, session->force_set_identity_username);
sql_reset_and_clear_bindings(session->force_set_identity_username);
@ -1455,7 +1453,7 @@ PEP_STATUS update_pEp_user_trust_vals(PEP_SESSION session,
sql_reset_and_clear_bindings(session->update_trust_to_pEp);
sqlite3_bind_text(session->update_trust_to_pEp, 1, user->user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->update_trust_to_pEp);
int result = pEp_sqlite3_step_nonbusy(session, session->update_trust_to_pEp);
sql_reset_and_clear_bindings(session->update_trust_to_pEp);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_TRUST;
@ -1488,7 +1486,7 @@ DYNAMIC_API PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user)
sql_reset_and_clear_bindings(session->set_as_pEp_user);
sqlite3_bind_text(session->set_as_pEp_user, 1, user->user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->set_as_pEp_user);
int result = pEp_sqlite3_step_nonbusy(session, session->set_as_pEp_user);
sql_reset_and_clear_bindings(session->set_as_pEp_user);
if (result != SQLITE_DONE)
@ -1512,7 +1510,7 @@ PEP_STATUS set_protocol_version(PEP_SESSION session, pEp_identity* ident, unsign
sqlite3_bind_text(session->set_protocol_version, 4, ident->user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->set_protocol_version);
int result = pEp_sqlite3_step_nonbusy(session, session->set_protocol_version);
sql_reset_and_clear_bindings(session->set_protocol_version);
if (result != SQLITE_DONE)
@ -1536,7 +1534,7 @@ PEP_STATUS upgrade_protocol_version_by_user_id(PEP_SESSION session,
sqlite3_bind_text(session->upgrade_protocol_version_by_user_id, 3, ident->user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->upgrade_protocol_version_by_user_id);
int result = pEp_sqlite3_step_nonbusy(session, session->upgrade_protocol_version_by_user_id);
sql_reset_and_clear_bindings(session->upgrade_protocol_version_by_user_id);
if (result != SQLITE_DONE)
@ -1560,7 +1558,7 @@ PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity,
sql_reset_and_clear_bindings(session->exists_person);
sqlite3_bind_text(session->exists_person, 1, user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->exists_person);
int result = pEp_sqlite3_step_nonbusy(session, session->exists_person);
switch (result) {
case SQLITE_ROW: {
// yeah yeah, I know, we could be lazy here, but it looks bad.
@ -1609,7 +1607,7 @@ PEP_STATUS delete_person(PEP_SESSION session, const char* user_id) {
sqlite3_bind_text(session->delete_person, 1, user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->delete_person);
int result = pEp_sqlite3_step_nonbusy(session, session->delete_person);
if (result != SQLITE_DONE)
status = PEP_UNKNOWN_ERROR;
@ -1638,7 +1636,7 @@ DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session, pEp_identity *identity,
sql_reset_and_clear_bindings(session->is_pEp_user);
sqlite3_bind_text(session->is_pEp_user, 1, user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->is_pEp_user);
int result = pEp_sqlite3_step_nonbusy(session, session->is_pEp_user);
switch (result) {
case SQLITE_ROW: {
// yeah yeah, I know, we could be lazy here, but it looks bad.
@ -1666,7 +1664,7 @@ PEP_STATUS is_own_address(PEP_SESSION session, const char* address, bool* is_own
sql_reset_and_clear_bindings(session->is_own_address);
sqlite3_bind_text(session->is_own_address, 1, address, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->is_own_address);
int result = pEp_sqlite3_step_nonbusy(session, session->is_own_address);
switch (result) {
case SQLITE_ROW: {
// yeah yeah, I know, we could be lazy here, but it looks bad.
@ -1699,7 +1697,7 @@ PEP_STATUS bind_own_ident_with_contact_ident(PEP_SESSION session,
sqlite3_bind_text(session->add_into_social_graph, 3, contact_ident->user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->add_into_social_graph);
int result = pEp_sqlite3_step_nonbusy(session, session->add_into_social_graph);
sql_reset_and_clear_bindings(session->add_into_social_graph);
if (result != SQLITE_DONE)
@ -1724,7 +1722,7 @@ PEP_STATUS has_partner_contacted_address(PEP_SESSION session, const char* partne
sqlite3_bind_text(session->has_id_contacted_address, 2, partner_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->has_id_contacted_address);
int result = pEp_sqlite3_step_nonbusy(session, session->has_id_contacted_address);
switch (result) {
case SQLITE_ROW: {
// yeah yeah, I know, we could be lazy here, but it looks bad.
@ -1760,7 +1758,7 @@ PEP_STATUS get_own_ident_for_contact_id(PEP_SESSION session,
sqlite3_bind_text(session->get_own_address_binding_from_contact, 2, contact->user_id, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->get_own_address_binding_from_contact);
int result = pEp_sqlite3_step_nonbusy(session, session->get_own_address_binding_from_contact);
const char* own_address = NULL;
@ -1779,6 +1777,7 @@ PEP_STATUS get_own_ident_for_contact_id(PEP_SESSION session,
default:
status = PEP_CANNOT_FIND_IDENTITY;
}
sql_reset_and_clear_bindings(session->get_own_address_binding_from_contact);
free(own_user_id);
return status;
@ -1793,7 +1792,7 @@ PEP_STATUS remove_fpr_as_default(PEP_SESSION session,
sqlite3_bind_text(session->remove_fpr_as_identity_default, 1, fpr, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->remove_fpr_as_identity_default);
int result = pEp_sqlite3_step_nonbusy(session, session->remove_fpr_as_identity_default);
sql_reset_and_clear_bindings(session->remove_fpr_as_identity_default);
if (result != SQLITE_DONE)
@ -1803,7 +1802,7 @@ PEP_STATUS remove_fpr_as_default(PEP_SESSION session,
sqlite3_bind_text(session->remove_fpr_as_user_default, 1, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->remove_fpr_as_user_default);
result = pEp_sqlite3_step_nonbusy(session, session->remove_fpr_as_user_default);
sql_reset_and_clear_bindings(session->remove_fpr_as_user_default);
if (result != SQLITE_DONE)
@ -1825,7 +1824,7 @@ PEP_STATUS replace_identities_fpr(PEP_SESSION session,
sqlite3_bind_text(session->replace_identities_fpr, 2, old_fpr, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->replace_identities_fpr);
int result = pEp_sqlite3_step_nonbusy(session, session->replace_identities_fpr);
sql_reset_and_clear_bindings(session->replace_identities_fpr);
if (result != SQLITE_DONE)
@ -1844,7 +1843,7 @@ PEP_STATUS update_trust_for_fpr(PEP_SESSION session,
sqlite3_bind_int(session->update_trust_for_fpr, 1, comm_type);
sqlite3_bind_text(session->update_trust_for_fpr, 2, fpr, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->update_trust_for_fpr);
int result = pEp_sqlite3_step_nonbusy(session, session->update_trust_for_fpr);
sql_reset_and_clear_bindings(session->update_trust_for_fpr);
if (result != SQLITE_DONE) {
return PEP_CANNOT_SET_TRUST;
@ -1871,7 +1870,7 @@ DYNAMIC_API PEP_STATUS set_identity_flags(
sqlite3_bind_text(session->set_identity_flags, 3, identity->user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->set_identity_flags);
result = pEp_sqlite3_step_nonbusy(session, session->set_identity_flags);
sql_reset_and_clear_bindings(session->set_identity_flags);
if (result != SQLITE_DONE)
@ -1897,7 +1896,7 @@ DYNAMIC_API PEP_STATUS unset_identity_flags(
SQLITE_STATIC);
sqlite3_bind_text(session->unset_identity_flags, 3, identity->user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->unset_identity_flags);
result = pEp_sqlite3_step_nonbusy(session, session->unset_identity_flags);
sql_reset_and_clear_bindings(session->unset_identity_flags);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_IDENTITY;
@ -1924,7 +1923,7 @@ DYNAMIC_API PEP_STATUS set_ident_enc_format(
sqlite3_bind_text(session->set_ident_enc_format, 3, identity->user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->set_ident_enc_format);
result = pEp_sqlite3_step_nonbusy(session, session->set_ident_enc_format);
sql_reset_and_clear_bindings(session->set_ident_enc_format);
if (result != SQLITE_DONE)
@ -1960,7 +1959,7 @@ PEP_STATUS get_trust_by_userid(PEP_SESSION session, const char* user_id,
sql_reset_and_clear_bindings(session->get_trust_by_userid);
sqlite3_bind_text(session->get_trust_by_userid, 1, user_id, -1, SQLITE_STATIC);
while ((result = sqlite3_step(session->get_trust_by_userid)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_trust_by_userid)) == SQLITE_ROW) {
if (!t_list)
t_list = new_labeled_int_list(sqlite3_column_int(session->get_trust_by_userid, 1),
(const char *) sqlite3_column_text(session->get_trust_by_userid, 0));
@ -2372,7 +2371,7 @@ PEP_STATUS replace_userid(PEP_SESSION session, const char* old_uid,
SQLITE_STATIC);
sqlite3_bind_text(session->replace_userid, 2, old_uid, -1,
SQLITE_STATIC);
result = sqlite3_step(session->replace_userid);
result = pEp_sqlite3_step_nonbusy(session, session->replace_userid);
if (result != SQLITE_DONE) {
const char *errmsg = sqlite3_errmsg(session->db);
LOG_ERROR("SQLite3 error: replace_userid failed: %s", errmsg);
@ -2391,7 +2390,7 @@ PEP_STATUS remove_key(PEP_SESSION session, const char* fpr) {
sql_reset_and_clear_bindings(session->delete_key);
sqlite3_bind_text(session->delete_key, 1, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->delete_key);
result = pEp_sqlite3_step_nonbusy(session, session->delete_key);
sql_reset_and_clear_bindings(session->delete_key);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PGP_KEYPAIR;
@ -2407,7 +2406,7 @@ PEP_STATUS refresh_userid_default_key(PEP_SESSION session, const char* user_id)
sql_reset_and_clear_bindings(session->refresh_userid_default_key);
sqlite3_bind_text(session->refresh_userid_default_key, 1, user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->refresh_userid_default_key);
result = pEp_sqlite3_step_nonbusy(session, session->refresh_userid_default_key);
sql_reset_and_clear_bindings(session->refresh_userid_default_key);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PERSON;
@ -2425,7 +2424,7 @@ PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
SQLITE_STATIC);
sqlite3_bind_text(session->replace_main_user_fpr, 2, user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->replace_main_user_fpr);
result = pEp_sqlite3_step_nonbusy(session, session->replace_main_user_fpr);
sql_reset_and_clear_bindings(session->replace_main_user_fpr);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PERSON;
@ -2453,7 +2452,7 @@ PEP_STATUS replace_main_user_fpr_if_equal(PEP_SESSION session, const char* user_
SQLITE_STATIC);
sqlite3_bind_text(session->replace_main_user_fpr_if_equal, 3, compare_fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->replace_main_user_fpr_if_equal);
result = pEp_sqlite3_step_nonbusy(session, session->replace_main_user_fpr_if_equal);
sql_reset_and_clear_bindings(session->replace_main_user_fpr_if_equal);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PERSON;
@ -2474,7 +2473,7 @@ PEP_STATUS get_main_user_fpr(PEP_SESSION session,
sql_reset_and_clear_bindings(session->get_main_user_fpr);
sqlite3_bind_text(session->get_main_user_fpr, 1, user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->get_main_user_fpr);
result = pEp_sqlite3_step_nonbusy(session, session->get_main_user_fpr);
switch (result) {
case SQLITE_ROW: {
const char* _fpr =
@ -2519,7 +2518,7 @@ PEP_STATUS set_default_identity_fpr(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->set_default_identity_fpr, 3, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->set_default_identity_fpr);
result = pEp_sqlite3_step_nonbusy(session, session->set_default_identity_fpr);
sql_reset_and_clear_bindings(session->set_default_identity_fpr);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PGP_KEYPAIR;
@ -2546,7 +2545,7 @@ PEP_STATUS get_default_identity_fpr(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(session->get_default_identity_fpr, 2, user_id, -1,
SQLITE_STATIC);
result = sqlite3_step(session->get_default_identity_fpr);
result = pEp_sqlite3_step_nonbusy(session, session->get_default_identity_fpr);
switch (result) {
case SQLITE_ROW: {
const char* _fpr =
@ -2593,7 +2592,7 @@ DYNAMIC_API PEP_STATUS mark_as_compromised(
sql_reset_and_clear_bindings(session->mark_compromised);
sqlite3_bind_text(session->mark_compromised, 1, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->mark_compromised);
result = pEp_sqlite3_step_nonbusy(session, session->mark_compromised);
sql_reset_and_clear_bindings(session->mark_compromised);
if (result != SQLITE_DONE)
@ -2626,7 +2625,7 @@ DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity)
SQLITE_STATIC);
sqlite3_bind_text(session->get_trust, 2, identity->fpr, -1, SQLITE_STATIC);
result = sqlite3_step(session->get_trust);
result = pEp_sqlite3_step_nonbusy(session, session->get_trust);
switch (result) {
case SQLITE_ROW: {
int comm_type = (PEP_comm_type) sqlite3_column_int(session->get_trust,
@ -2660,7 +2659,7 @@ DYNAMIC_API PEP_STATUS least_trust(
sql_reset_and_clear_bindings(session->least_trust);
sqlite3_bind_text(session->least_trust, 1, fpr, -1, SQLITE_STATIC);
result = sqlite3_step(session->least_trust);
result = pEp_sqlite3_step_nonbusy(session, session->least_trust);
switch (result) {
case SQLITE_ROW: {
int _comm_type = sqlite3_column_int(session->least_trust, 0);
@ -3132,7 +3131,7 @@ DYNAMIC_API PEP_STATUS get_crashdump_log(
int result;
do {
result = sqlite3_step(session->crashdump);
result = pEp_sqlite3_step_nonbusy(session, session->crashdump);
switch (result) {
case SQLITE_ROW:
timestamp = (const char *) sqlite3_column_text(session->crashdump,
@ -3219,7 +3218,7 @@ DYNAMIC_API PEP_STATUS get_languagelist(
int result;
do {
result = sqlite3_step(session->languagelist);
result = pEp_sqlite3_step_nonbusy(session, session->languagelist);
switch (result) {
case SQLITE_ROW:
lang = (const char *) sqlite3_column_text(session->languagelist,
@ -3287,7 +3286,7 @@ DYNAMIC_API PEP_STATUS get_phrase(
const char *_phrase = NULL;
int result;
result = sqlite3_step(session->i18n_token);
result = pEp_sqlite3_step_nonbusy(session, session->i18n_token);
switch (result) {
case SQLITE_ROW:
_phrase = (const char *) sqlite3_column_text(session->i18n_token, 0);
@ -3342,7 +3341,7 @@ static PEP_STATUS _get_sequence_value(PEP_SESSION session, const char *name,
sql_reset_and_clear_bindings(session->sequence_value2);
sqlite3_bind_text(session->sequence_value2, 1, name, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->sequence_value2);
int result = pEp_sqlite3_step_nonbusy(session, session->sequence_value2);
switch (result) {
case SQLITE_ROW: {
int32_t _value = (int32_t)
@ -3383,7 +3382,7 @@ static PEP_STATUS _increment_sequence_value(PEP_SESSION session,
sql_reset_and_clear_bindings(session->sequence_value1);
sqlite3_bind_text(session->sequence_value1, 1, name, -1, SQLITE_STATIC);
int result = sqlite3_step(session->sequence_value1);
int result = pEp_sqlite3_step_nonbusy(session, session->sequence_value1);
sql_reset_and_clear_bindings(session->sequence_value1);
PEP_WEAK_ASSERT_ORELSE_RETURN(result == SQLITE_DONE,
PEP_CANNOT_INCREASE_SEQUENCE);
@ -3400,24 +3399,20 @@ DYNAMIC_API PEP_STATUS sequence_value(
PEP_STATUS status = PEP_STATUS_OK;
*value = 0;
sqlite3_exec(session->db, "BEGIN TRANSACTION ;", NULL, NULL, NULL);
PEP_SQL_BEGIN_EXCLUSIVE_TRANSACTION();
status = _increment_sequence_value(session, name);
if (status == PEP_STATUS_OK)
status = _get_sequence_value(session, name, value);
if (status == PEP_STATUS_OK) {
int result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
if (result == SQLITE_OK){
assert(*value < INT32_MAX);
if (*value == INT32_MAX){
return PEP_CANNOT_INCREASE_SEQUENCE;
}
return status;
} else {
return PEP_COMMIT_FAILED;
PEP_SQL_COMMIT_TRANSACTION();
PEP_ASSERT(*value < INT32_MAX);
if (*value == INT32_MAX){
return PEP_CANNOT_INCREASE_SEQUENCE;
}
return status;
} else {
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
PEP_SQL_ROLLBACK_TRANSACTION();
return status;
}
@ -3482,7 +3477,7 @@ DYNAMIC_API PEP_STATUS set_revoked(
int result;
result = sqlite3_step(session->set_revoked);
result = pEp_sqlite3_step_nonbusy(session, session->set_revoked);
switch (result) {
case SQLITE_DONE:
status = PEP_STATUS_OK;
@ -3514,7 +3509,7 @@ DYNAMIC_API PEP_STATUS get_revoked(
int result;
result = sqlite3_step(session->get_revoked);
result = pEp_sqlite3_step_nonbusy(session, session->get_revoked);
switch (result) {
case SQLITE_ROW: {
*revoked_fpr = strdup((const char *)
@ -3556,7 +3551,7 @@ DYNAMIC_API PEP_STATUS get_replacement_fpr(
int result;
result = sqlite3_step(session->get_replacement_fpr);
result = pEp_sqlite3_step_nonbusy(session, session->get_replacement_fpr);
switch (result) {
case SQLITE_ROW: {
*revoked_fpr = strdup((const char *)
@ -3591,7 +3586,7 @@ PEP_STATUS get_last_contacted(
sql_reset_and_clear_bindings(session->get_last_contacted);
int result;
while ((result = sqlite3_step(session->get_last_contacted)) == SQLITE_ROW) {
while ((result = pEp_sqlite3_step_nonbusy(session, session->get_last_contacted)) == SQLITE_ROW) {
pEp_identity *ident = new_identity(
(const char *) sqlite3_column_text(session->get_last_contacted, 1),
NULL,

@ -280,13 +280,13 @@ local_wait_time += _pEp_sql_backoff_state.total_time_slept_in_ms;*/ \
PEP_ASSERT(_pEp_sql_sqlite_status != SQLITE_LOCKED); \
if (_pEp_sql_sqlite_status != SQLITE_DONE) \
LOG_ERROR("UNEXPECTED error on BEGIN EXCLUSIVE TRANSACTION: %i %s", \
_pEp_sql_sqlite_status, sqlite3_errmsg(db)); \
_pEp_sql_sqlite_status, sqlite3_errmsg(session->db)); \
PEP_ASSERT(_pEp_sql_sqlite_status == SQLITE_DONE); \
} while (false)
/* This macro factors the common logic of PEP_SQL_COMMIT_EXCLUSIVE_TRANSACTION
and PEP_SQL_ROLLBACK_EXCLUSIVE_TRANSACTION . */
#define PEP_SQL_COMMIT_OR_ROLLBACK_EXCLUSIVE_TRANSACTION(commit) \
/* This macro factors the common logic of PEP_SQL_COMMIT_TRANSACTION and
PEP_SQL_ROLLBACK_TRANSACTION . */
#define PEP_SQL_COMMIT_OR_ROLLBACK_TRANSACTION(commit) \
do { \
/* Here thre is no need to loop using PEP_SQL_BEGIN_LOOP and \
PEP_SQL_END_LOOP: if we first began the transaction with \
@ -311,25 +311,25 @@ local_wait_time += _pEp_sql_backoff_state.total_time_slept_in_ms;*/ \
if (_pEp_sql_sqlite_status != SQLITE_DONE) \
LOG_ERROR("UNEXPECTED error on %s: %i %s", \
(_pEp_bool_commit ? "COMMIT" : "ROLLBACK"), \
_pEp_sql_sqlite_status, sqlite3_errmsg(db)); \
_pEp_sql_sqlite_status, sqlite3_errmsg(session->db)); \
PEP_ASSERT(_pEp_sql_sqlite_status == SQLITE_DONE); \
} while (false)
/**
* @internal
* <!-- PEP_SQL_COMMIT_EXCLUSIVE_TRANSACTION() -->
* <!-- PEP_SQL_COMMIT_TRANSACTION() -->
*
* @brief Commit the current exclusive transaction. */
#define PEP_SQL_COMMIT_EXCLUSIVE_TRANSACTION() \
PEP_SQL_COMMIT_OR_ROLLBACK_EXCLUSIVE_TRANSACTION(true)
#define PEP_SQL_COMMIT_TRANSACTION() \
PEP_SQL_COMMIT_OR_ROLLBACK_TRANSACTION(true)
/**
* @internal
* <!-- PEP_SQL_ROLLBACK_EXCLUSIVE_TRANSACTION() -->
* <!-- PEP_SQL_ROLLBACK_TRANSACTION() -->
*
* @brief Rollback the current exclusive transaction. */
#define PEP_SQL_ROLLBACK_EXCLUSIVE_TRANSACTION() \
PEP_SQL_COMMIT_OR_ROLLBACK_EXCLUSIVE_TRANSACTION(false)
#define PEP_SQL_ROLLBACK_TRANSACTION()