|
|
@ -83,7 +83,7 @@ static const char *sql_trustword = |
|
|
|
static const char *sql_get_identity = |
|
|
|
"select fpr, username, comm_type, lang," |
|
|
|
" identity.flags | pgp_keypair.flags," |
|
|
|
" is_own, pEp_version" |
|
|
|
" is_own" |
|
|
|
" from identity" |
|
|
|
" join person on id = identity.user_id" |
|
|
|
" join pgp_keypair on fpr = identity.main_key_id" |
|
|
@ -101,7 +101,7 @@ static const char *sql_get_identity = |
|
|
|
static const char *sql_get_identities_by_main_key_id = |
|
|
|
"select address, identity.user_id, username, comm_type, lang," |
|
|
|
" identity.flags | pgp_keypair.flags," |
|
|
|
" is_own, pEp_version" |
|
|
|
" is_own" |
|
|
|
" from identity" |
|
|
|
" join person on id = identity.user_id" |
|
|
|
" join pgp_keypair on fpr = identity.main_key_id" |
|
|
@ -113,7 +113,7 @@ static const char *sql_get_identities_by_main_key_id = |
|
|
|
|
|
|
|
static const char *sql_get_identity_without_trust_check = |
|
|
|
"select identity.main_key_id, username, lang," |
|
|
|
" identity.flags, is_own, pEp_version" |
|
|
|
" identity.flags, is_own" |
|
|
|
" from identity" |
|
|
|
" join person on id = identity.user_id" |
|
|
|
" where (case when (address = ?1) then (1)" |
|
|
@ -127,7 +127,7 @@ static const char *sql_get_identity_without_trust_check = |
|
|
|
|
|
|
|
static const char *sql_get_identities_by_address = |
|
|
|
"select user_id, identity.main_key_id, username, lang," |
|
|
|
" identity.flags, is_own, pEp_version" |
|
|
|
" identity.flags, is_own" |
|
|
|
" from identity" |
|
|
|
" join person on id = identity.user_id" |
|
|
|
" where (case when (address = ?1) then (1)" |
|
|
@ -141,7 +141,7 @@ static const char *sql_get_identities_by_address = |
|
|
|
static const char *sql_get_identities_by_userid = |
|
|
|
"select address, fpr, username, comm_type, lang," |
|
|
|
" identity.flags | pgp_keypair.flags," |
|
|
|
" is_own, pEp_version" |
|
|
|
" is_own" |
|
|
|
" from identity" |
|
|
|
" join person on id = identity.user_id" |
|
|
|
" join pgp_keypair on fpr = identity.main_key_id" |
|
|
@ -239,22 +239,20 @@ static const char* sql_exists_identity_entry = |
|
|
|
static const char *sql_set_identity_entry = |
|
|
|
"insert into identity (" |
|
|
|
" address, main_key_id, " |
|
|
|
" user_id, flags, is_own, pEp_version" |
|
|
|
" user_id, flags, is_own" |
|
|
|
" ) values (" |
|
|
|
" ?1," |
|
|
|
" upper(replace(?2,' ',''))," |
|
|
|
" ?3," |
|
|
|
" ?4," |
|
|
|
" ?5," |
|
|
|
" ?6" |
|
|
|
" ?5" |
|
|
|
" );"; |
|
|
|
|
|
|
|
static const char* sql_update_identity_entry = |
|
|
|
"update identity " |
|
|
|
" set main_key_id = upper(replace(?2,' ','')), " |
|
|
|
" flags = ?4, " |
|
|
|
" is_own = ?5, " |
|
|
|
" pEp_version = ?6 " |
|
|
|
" is_own = ?5 " |
|
|
|
" where (case when (address = ?1) then (1)" |
|
|
|
" when (lower(address) = lower(?1)) then (1)" |
|
|
|
" when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1) " |
|
|
@ -303,6 +301,16 @@ static const char *sql_unset_identity_flags = |
|
|
|
" end) = 1" |
|
|
|
" and user_id = ?3 ;"; |
|
|
|
|
|
|
|
static const char *sql_set_pEp_version = |
|
|
|
"update identity " |
|
|
|
" set pEp_version = ?1 " |
|
|
|
" where (case when (address = ?2) then (1)" |
|
|
|
" when (lower(address) = lower(?2)) then (1)" |
|
|
|
" when (replace(lower(address),'.','') = replace(lower(?2),'.','')) then (1) " |
|
|
|
" else 0 " |
|
|
|
" end) = 1 " |
|
|
|
" and user_id = ?3 ;"; |
|
|
|
|
|
|
|
static const char *sql_set_trust = |
|
|
|
"insert into trust (user_id, pgp_keypair_fpr, comm_type) " |
|
|
|
"values (?1, upper(replace(?2,' ','')), ?3) ;"; |
|
|
@ -355,7 +363,7 @@ static const char *sql_languagelist = |
|
|
|
|
|
|
|
static const char *sql_i18n_token = |
|
|
|
"select phrase from i18n_token where lang = lower(?1) and id = ?2 ;"; |
|
|
|
|
|
|
|
|
|
|
|
// blacklist |
|
|
|
static const char *sql_blacklist_add = |
|
|
|
"insert or ignore into blacklist_keys (fpr) values (upper(replace(?1,' ',''))) ;" |
|
|
@ -395,7 +403,7 @@ static const char *sql_is_own_address = |
|
|
|
|
|
|
|
static const char *sql_own_identities_retrieve = |
|
|
|
"select address, fpr, identity.user_id, username," |
|
|
|
" lang, identity.flags | pgp_keypair.flags, pEp_version" |
|
|
|
" lang, identity.flags | pgp_keypair.flags" |
|
|
|
" from identity" |
|
|
|
" join person on id = identity.user_id" |
|
|
|
" join pgp_keypair on fpr = identity.main_key_id" |
|
|
@ -906,7 +914,7 @@ DYNAMIC_API PEP_STATUS init( |
|
|
|
sqlite3_busy_timeout(_session->system_db, 1000); |
|
|
|
|
|
|
|
// increment this when patching DDL |
|
|
|
#define _DDL_USER_VERSION "12" |
|
|
|
#define _DDL_USER_VERSION "11" |
|
|
|
|
|
|
|
if (in_first) { |
|
|
|
|
|
|
@ -967,7 +975,7 @@ DYNAMIC_API PEP_STATUS init( |
|
|
|
" comment text,\n" |
|
|
|
" flags integer default 0,\n" |
|
|
|
" is_own integer default 0,\n" |
|
|
|
" pEp_version real default 0.0,\n" |
|
|
|
" pEp_version real default 0,\n" |
|
|
|
" timestamp integer default (datetime('now')),\n" |
|
|
|
" primary key (address, user_id)\n" |
|
|
|
");\n" |
|
|
@ -1073,9 +1081,9 @@ DYNAMIC_API PEP_STATUS init( |
|
|
|
// Sometimes the user_version wasn't set correctly. |
|
|
|
if (version == 1) { |
|
|
|
bool version_changed = true; |
|
|
|
if (table_contains_column(_session, "identity", "pEp_version") > 0) { |
|
|
|
if (table_contains_column(_session, "identity", "pEp_version")) { |
|
|
|
version = 12; |
|
|
|
} // N.B. Version 11 was a DB internal fix; there's no identifying information, but this is only one extra exec. |
|
|
|
} |
|
|
|
else if (db_contains_table(_session, "social_graph") > 0) { |
|
|
|
if (!table_contains_column(_session, "person", "device_group")) |
|
|
|
version = 10; |
|
|
@ -1433,12 +1441,13 @@ DYNAMIC_API PEP_STATUS init( |
|
|
|
int_result = sqlite3_exec( |
|
|
|
_session->db, |
|
|
|
"alter table identity\n" |
|
|
|
" add column pEp_version real default 0.0;\n", |
|
|
|
" add column pEp_version real default 0\n", |
|
|
|
NULL, |
|
|
|
NULL, |
|
|
|
NULL |
|
|
|
); |
|
|
|
assert(int_result == SQLITE_OK); |
|
|
|
if (status != PEP_STATUS_OK) |
|
|
|
return status; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
@ -1638,6 +1647,11 @@ DYNAMIC_API PEP_STATUS init( |
|
|
|
NULL); |
|
|
|
assert(int_result == SQLITE_OK); |
|
|
|
|
|
|
|
int_result = sqlite3_prepare_v2(_session->db, sql_set_pEp_version, |
|
|
|
(int)strlen(sql_set_pEp_version), &_session->set_pEp_version, |
|
|
|
NULL); |
|
|
|
assert(int_result == SQLITE_OK); |
|
|
|
|
|
|
|
int_result = sqlite3_prepare_v2(_session->db, sql_set_trust, |
|
|
|
(int)strlen(sql_set_trust), &_session->set_trust, NULL); |
|
|
|
assert(int_result == SQLITE_OK); |
|
|
@ -2468,8 +2482,6 @@ DYNAMIC_API PEP_STATUS get_identity( |
|
|
|
sqlite3_column_int(session->get_identity, 4); |
|
|
|
_identity->me = (unsigned int) |
|
|
|
sqlite3_column_int(session->get_identity, 5); |
|
|
|
_identity->pEp_version = (float) |
|
|
|
sqlite3_column_double(session->get_identity, 6); |
|
|
|
|
|
|
|
*identity = _identity; |
|
|
|
break; |
|
|
@ -2544,8 +2556,6 @@ PEP_STATUS get_identities_by_userid( |
|
|
|
sqlite3_column_int(session->get_identities_by_userid, 5); |
|
|
|
ident->me = (unsigned int) |
|
|
|
sqlite3_column_int(session->get_identities_by_userid, 6); |
|
|
|
ident->pEp_version = (float) |
|
|
|
sqlite3_column_double(session->get_identities_by_userid, 7); |
|
|
|
|
|
|
|
identity_list_add(*identities, ident); |
|
|
|
ident = NULL; |
|
|
@ -2612,8 +2622,6 @@ PEP_STATUS get_identities_by_main_key_id( |
|
|
|
sqlite3_column_int(session->get_identities_by_main_key_id, 5); |
|
|
|
ident->me = (unsigned int) |
|
|
|
sqlite3_column_int(session->get_identities_by_main_key_id, 6); |
|
|
|
ident->pEp_version = (float) |
|
|
|
sqlite3_column_double(session->get_identities_by_main_key_id, 7); |
|
|
|
|
|
|
|
identity_list_add(*identities, ident); |
|
|
|
ident = NULL; |
|
|
@ -2684,8 +2692,6 @@ PEP_STATUS get_identity_without_trust_check( |
|
|
|
sqlite3_column_int(session->get_identity_without_trust_check, 3); |
|
|
|
_identity->me = (unsigned int) |
|
|
|
sqlite3_column_int(session->get_identity_without_trust_check, 4); |
|
|
|
_identity->pEp_version = (float) |
|
|
|
sqlite3_column_double(session->get_identity_without_trust_check, 5); |
|
|
|
|
|
|
|
*identity = _identity; |
|
|
|
break; |
|
|
@ -2751,8 +2757,6 @@ PEP_STATUS get_identities_by_address( |
|
|
|
sqlite3_column_int(session->get_identities_by_address, 4); |
|
|
|
ident->me = (unsigned int) |
|
|
|
sqlite3_column_int(session->get_identities_by_address, 5); |
|
|
|
ident->pEp_version = (float) |
|
|
|
sqlite3_column_double(session->get_identities_by_address, 6); |
|
|
|
|
|
|
|
if (ident_list) |
|
|
|
identity_list_add(ident_list, ident); |
|
|
@ -2909,7 +2913,6 @@ static PEP_STATUS _set_or_update_identity_entry(PEP_SESSION session, |
|
|
|
SQLITE_STATIC); |
|
|
|
sqlite3_bind_int(set_or_update, 4, identity->flags); |
|
|
|
sqlite3_bind_int(set_or_update, 5, identity->me); |
|
|
|
sqlite3_bind_double(set_or_update, 6, identity->pEp_version); |
|
|
|
int result = sqlite3_step(set_or_update); |
|
|
|
sqlite3_reset(set_or_update); |
|
|
|
if (result != SQLITE_DONE) |
|
|
@ -3023,7 +3026,7 @@ PEP_STATUS set_identity_entry(PEP_SESSION session, pEp_identity* identity, |
|
|
|
guard_transaction); |
|
|
|
} |
|
|
|
|
|
|
|
// This will NOT call set_as_pEp_user; you have to do that separately. |
|
|
|
// This will NOT call set_as_pEp_user, nor set_pEp_version; you have to do that separately. |
|
|
|
DYNAMIC_API PEP_STATUS set_identity( |
|
|
|
PEP_SESSION session, const pEp_identity *identity |
|
|
|
) |
|
|
@ -3155,6 +3158,29 @@ DYNAMIC_API PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user) |
|
|
|
return status; |
|
|
|
} |
|
|
|
|
|
|
|
// This ONLY sets the version flag. Must be called outside of a transaction. |
|
|
|
PEP_STATUS set_pEp_version(PEP_SESSION session, pEp_identity* ident, float new_pEp_version) { |
|
|
|
assert(session); |
|
|
|
assert(!EMPTYSTR(ident->user_id)); |
|
|
|
assert(!EMPTYSTR(ident->address)); |
|
|
|
|
|
|
|
sqlite3_reset(session->set_pEp_version); |
|
|
|
sqlite3_bind_double(session->set_pEp_version, 1, new_pEp_version); |
|
|
|
sqlite3_bind_text(session->set_pEp_version, 2, ident->address, -1, |
|
|
|
SQLITE_STATIC); |
|
|
|
sqlite3_bind_text(session->set_pEp_version, 3, ident->user_id, -1, |
|
|
|
SQLITE_STATIC); |
|
|
|
|
|
|
|
int result = sqlite3_step(session->set_pEp_version); |
|
|
|
sqlite3_reset(session->set_pEp_version); |
|
|
|
|
|
|
|
if (result != SQLITE_DONE) |
|
|
|
return PEP_CANNOT_SET_PEP_VERSION; |
|
|
|
|
|
|
|
return PEP_STATUS_OK; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity, |
|
|
|
bool* exists) { |
|
|
|
|
|
|
|