Browse Source

ENGINE-878: setting now in on the sql side, but needs to be coordinated with https://dev.pep.foundation/Engine/UserPseudonymity in the identity management functions.

ENGINE-878
Krista Bennett 1 year ago
parent
commit
2ed07d4364
4 changed files with 40 additions and 11 deletions
  1. +8
    -0
      src/engine_sql.c
  2. +21
    -6
      src/engine_sql.h
  3. +9
    -4
      src/pEpEngine.c
  4. +2
    -1
      src/pEp_internal.h

+ 8
- 0
src/engine_sql.c View File

@ -2025,6 +2025,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,
@ -2582,6 +2588,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)


+ 21
- 6
src/engine_sql.h View File

@ -215,7 +215,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,"
@ -224,16 +226,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) "
@ -241,6 +245,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"


+ 9
- 4
src/pEpEngine.c View File

@ -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);


+ 2
- 1
src/pEp_internal.h View File

@ -208,7 +208,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