Merge branch 'ENGINE-878' into ENGINE-633 - merge in prep for user pseudonymity fixes (identity-specific usernames)

doxygen_doc
Krista Bennett 2 years ago
commit 5249038439

@ -703,6 +703,7 @@ static PEP_STATUS _create_core_tables(PEP_SESSION session) {
" main_key_id text\n"
" references pgp_keypair (fpr)\n"
" on delete set null,\n"
" username text,\n"
" comment text,\n"
" flags integer default 0,\n"
" is_own integer default 0,\n"
@ -928,33 +929,48 @@ PEP_STATUS get_db_user_version(PEP_SESSION session, int* version) {
return PEP_STATUS_OK;
}
// Only called if input version is 1
static PEP_STATUS _verify_version(PEP_SESSION session, int* version) {
// Sometimes the user_version wasn't set correctly.
bool version_changed = true;
int int_result;
if (table_contains_column(session, "groups", "group_identity")) {
if (table_contains_column(session, "identity", "username")) {
*version = 17;
}
else if (table_contains_column(session, "trust", "sticky")) {
*version = 16;
}
else if (table_contains_column(session, "groups", "group_identity")) {
*version = 15;
}
else if (table_contains_column(session, "identity", "enc_format")) {
*version = 14;
} else if (table_contains_column(session, "revocation_contact_list", "own_address")) {
}
else if (table_contains_column(session, "revocation_contact_list", "own_address")) {
*version = 13;
} else if (table_contains_column(session, "identity", "pEp_version_major")) {
}
else if (table_contains_column(session, "identity", "pEp_version_major")) {
*version = 12;
} else if (db_contains_table(session, "social_graph") > 0) {
}
else if (db_contains_table(session, "social_graph") > 0) {
if (!table_contains_column(session, "person", "device_group"))
*version = 10;
else
*version = 9;
} else if (table_contains_column(session, "identity", "timestamp") > 0) {
}
else if (table_contains_column(session, "identity", "timestamp") > 0) {
*version = 8;
} else if (table_contains_column(session, "person", "is_pEp_user") > 0) {
}
else if (table_contains_column(session, "person", "is_pEp_user") > 0) {
*version = 7;
} else if (table_contains_column(session, "identity", "is_own") > 0) {
}
else if (table_contains_column(session, "identity", "is_own") > 0) {
*version = 6;
} else if (table_contains_column(session, "pgp_keypair", "flags") > 0) {
}
else if (table_contains_column(session, "pgp_keypair", "flags") > 0) {
*version = 2;
} else {
}
else {
version_changed = false;
}
@ -1484,6 +1500,24 @@ static PEP_STATUS _upgrade_DB_to_ver_16(PEP_SESSION session) {
return PEP_STATUS_OK;
}
static PEP_STATUS _upgrade_DB_to_ver_17(PEP_SESSION session) {
int int_result = sqlite3_exec(
session->db,
"alter table identity\n"
" add column username;\n",
NULL,
NULL,
NULL
);
assert(int_result == SQLITE_OK);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
return PEP_STATUS_OK;
}
static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version) {
PEP_STATUS status = PEP_STATUS_OK;
@ -1547,6 +1581,10 @@ static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version)
if (status != PEP_STATUS_OK)
return status;
case 16:
status = _upgrade_DB_to_ver_17(session);
if (status != PEP_STATUS_OK)
return status;
case 17:
break;
default:
return PEP_ILLEGAL_VALUE;
@ -1993,6 +2031,12 @@ PEP_STATUS pEp_prepare_sql_stmts(PEP_SESSION session) {
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
int_result = sqlite3_prepare_v2(session->db, sql_force_set_identity_username,
(int)strlen(sql_force_set_identity_username), &session->force_set_identity_username, NULL);
assert(int_result == SQLITE_OK);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
int_result = sqlite3_prepare_v2(session->db, sql_set_identity_flags,
(int)strlen(sql_set_identity_flags), &session->set_identity_flags,
@ -2552,6 +2596,8 @@ PEP_STATUS pEp_finalize_sql_stmts(PEP_SESSION session) {
sqlite3_finalize(session->set_identity_entry);
if (session->update_identity_entry)
sqlite3_finalize(session->update_identity_entry);
if (session->force_set_identity_username)
sqlite3_finalize(session->force_set_identity_username);
if (session->set_identity_flags)
sqlite3_finalize(session->set_identity_flags);
if (session->unset_identity_flags)

@ -3,7 +3,7 @@
#include "pEp_internal.h"
// increment this when patching DDL
#define _DDL_USER_VERSION "16"
#define _DDL_USER_VERSION "17"
PEP_STATUS init_databases(PEP_SESSION session);
PEP_STATUS pEp_sql_init(PEP_SESSION session);
@ -25,8 +25,10 @@ static const char *sql_trustword =
// Also: we've never used pgp_keypair.flags before now, but it seems to me that
// having combination of those flags is a road to ruin. Changing this for now.
static const char *sql_get_identity =
"select identity.main_key_id, username, comm_type, lang,"
" identity.flags,"
"select identity.main_key_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
" comm_type, lang, identity.flags,"
// " identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
@ -44,8 +46,10 @@ static const char *sql_get_identity =
" timestamp desc; ";
static const char *sql_get_identities_by_main_key_id =
"select address, identity.user_id, username, comm_type, lang,"
" identity.flags,"
"select address, identity.user_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
" comm_type, lang, identity.flags,"
// " identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
@ -58,8 +62,10 @@ static const char *sql_get_identities_by_main_key_id =
" timestamp desc; ";
static const char *sql_get_identity_without_trust_check =
"select identity.main_key_id, username, lang,"
" identity.flags, is_own, pEp_version_major, pEp_version_minor, enc_format"
"select identity.main_key_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
" lang, identity.flags, is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" where (case when (address = ?1) then (1)"
@ -72,8 +78,10 @@ static const char *sql_get_identity_without_trust_check =
" timestamp desc; ";
static const char *sql_get_identities_by_address =
"select user_id, identity.main_key_id, username, lang,"
" identity.flags, is_own, pEp_version_major, pEp_version_minor, enc_format"
"select user_id, identity.main_key_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
" lang, identity.flags, is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" where (case when (address = ?1) then (1)"
@ -85,18 +93,20 @@ static const char *sql_get_identities_by_address =
" timestamp desc; ";
static const char *sql_get_identities_by_userid =
"select address, identity.main_key_id, username, comm_type, lang,"
" identity.flags,"
// " identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
" left join trust on id = trust.user_id"
" and pgp_keypair_fpr = identity.main_key_id"
" where identity.user_id = ?1"
" order by is_own desc, "
" timestamp desc; ";
"select address, identity.main_key_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
" comm_type, lang, identity.flags,"
// " identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
" left join trust on id = trust.user_id"
" and pgp_keypair_fpr = identity.main_key_id"
" where identity.user_id = ?1"
" order by is_own desc, "
" timestamp desc; ";
static const char *sql_replace_identities_fpr =
"update identity"
@ -214,7 +224,9 @@ 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,"
" user_id, "
" username, "
" flags, is_own,"
" pEp_version_major, pEp_version_minor"
" ) values ("
" ?1,"
@ -223,16 +235,18 @@ static const char *sql_set_identity_entry =
" ?4,"
" ?5,"
" ?6,"
" ?7"
" ?7,"
" ?8 "
" );";
static const char* sql_update_identity_entry =
"update identity "
" set main_key_id = upper(replace(?2,' ','')), "
" flags = ?4, "
" is_own = ?5, "
" pEp_version_major = ?6, "
" pEp_version_minor = ?7 "
" username = coalesce(username, ?4), "
" flags = ?5, "
" is_own = ?6, "
" pEp_version_major = ?7, "
" pEp_version_minor = ?8 "
" where (case when (address = ?1) then (1)"
" when (lower(address) = lower(?1)) then (1)"
" when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1) "
@ -240,6 +254,17 @@ static const char* sql_update_identity_entry =
" end) = 1 "
" and user_id = ?3 ;";
static const char* sql_force_set_identity_username =
"update identity "
" set username = coalesce(username, ?3) "
" where (case when (address = ?1) then (1)"
" when (lower(address) = lower(?1)) then (1)"
" when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1) "
" else 0 "
" end) = 1 "
" and user_id = ?2 ;";
// " (select"
// " coalesce("
// " (select flags from identity"
@ -416,9 +441,10 @@ static const char *sql_is_own_address =
");";
static const char *sql_own_identities_retrieve =
"select address, identity.main_key_id, identity.user_id, username,"
" lang,"
" identity.flags,"
"select address, identity.main_key_id, identity.user_id,"
" (case when (identity.flags & 1024 = 0) then ifnull(identity.username, person.username) "
" else identity.username end),"
" lang, identity.flags,"
// " identity.flags | pgp_keypair.flags,"
" pEp_version_major, pEp_version_minor"
" from identity"

@ -1162,10 +1162,12 @@ static PEP_STATUS _set_or_update_identity_entry(PEP_SESSION session,
SQLITE_STATIC);
sqlite3_bind_text(set_or_update, 3, identity->user_id, -1,
SQLITE_STATIC);
sqlite3_bind_int(set_or_update, 4, identity->flags);
sqlite3_bind_int(set_or_update, 5, identity->me);
sqlite3_bind_int(set_or_update, 6, identity->major_ver);
sqlite3_bind_int(set_or_update, 7, identity->minor_ver);
sqlite3_bind_text(set_or_update, 4, identity->username, -1,
SQLITE_STATIC);
sqlite3_bind_int(set_or_update, 5, identity->flags);
sqlite3_bind_int(set_or_update, 6, identity->me);
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);
sqlite3_reset(set_or_update);
@ -1317,6 +1319,8 @@ PEP_STATUS set_identity_entry(PEP_SESSION session, pEp_identity* identity,
guard_transaction);
}
// 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
@ -1358,6 +1362,7 @@ DYNAMIC_API PEP_STATUS set_identity(
if (!ident_copy)
return PEP_OUT_OF_MEMORY;
// 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);

@ -218,7 +218,8 @@ struct _pEpSession {
sqlite3_stmt *unset_pgp_keypair_flags;
sqlite3_stmt *set_identity_entry;
sqlite3_stmt *update_identity_entry;
sqlite3_stmt *exists_identity_entry;
sqlite3_stmt *exists_identity_entry;
sqlite3_stmt *force_set_identity_username;
sqlite3_stmt *set_identity_flags;
sqlite3_stmt *unset_identity_flags;
sqlite3_stmt *set_ident_enc_format;

Loading…
Cancel
Save