ENGINE-289: added user_id alias queries ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Wed, 17 Jan 2018 00:25:36 +0100
branchENGINE-289
changeset 2397ee6f72ef704b
parent 2396 f9015ee2527c
child 2398 2365cdba8783
ENGINE-289: added user_id alias queries
src/pEpEngine.c
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Wed Jan 17 00:09:58 2018 +0100
     1.2 +++ b/src/pEpEngine.c	Wed Jan 17 00:25:36 2018 +0100
     1.3 @@ -269,6 +269,14 @@
     1.4      "select revoked_fpr, revocation_date from revoked_keys"
     1.5      "    where replacement_fpr = upper(replace(?1,' ','')) ;";
     1.6  
     1.7 +static const char *sql_get_userid_alias_default =
     1.8 +    "select default_id from alternate_user_id "
     1.9 +    "   where alternate_id = ?1 ; ";
    1.10 +
    1.11 +static const char *sql_add_userid_alias =
    1.12 +    "insert or replace into alternate_user_id (default_id, alternate_id) "
    1.13 +    "values (?1, ?2) ;";
    1.14 +    
    1.15  static int user_version(void *_version, int count, char **text, char **name)
    1.16  {
    1.17      assert(_version);
    1.18 @@ -802,6 +810,14 @@
    1.19      int_result = sqlite3_prepare_v2(_session->db, sql_get_default_own_userid,
    1.20              (int)strlen(sql_get_default_own_userid), &_session->get_default_own_userid, NULL);
    1.21      assert(int_result == SQLITE_OK);
    1.22 +    
    1.23 +    int_result = sqlite3_prepare_v2(_session->db, sql_get_userid_alias_default,
    1.24 +            (int)strlen(sql_get_userid_alias_default), &_session->get_userid_alias_default, NULL);
    1.25 +    assert(int_result == SQLITE_OK);
    1.26 +
    1.27 +    int_result = sqlite3_prepare_v2(_session->db, sql_add_userid_alias,
    1.28 +            (int)strlen(sql_add_userid_alias), &_session->add_userid_alias, NULL);
    1.29 +    assert(int_result == SQLITE_OK);
    1.30  
    1.31      int_result = sqlite3_prepare_v2(_session->db, sql_replace_userid,
    1.32              (int)strlen(sql_replace_userid), &_session->replace_userid, NULL);
    1.33 @@ -1061,6 +1077,10 @@
    1.34                  sqlite3_finalize(session->get_user_default_key);    
    1.35              if (session->get_default_own_userid)
    1.36                  sqlite3_finalize(session->get_default_own_userid);
    1.37 +            if (session->get_userid_alias_default)
    1.38 +                sqlite3_finalize(session->get_userid_alias_default);
    1.39 +            if (session->add_userid_alias)
    1.40 +                sqlite3_finalize(session->add_userid_alias);
    1.41              if (session->replace_identities_fpr)
    1.42                  sqlite3_finalize(session->replace_identities_fpr);        
    1.43              if (session->remove_fpr_as_default)
     2.1 --- a/src/pEp_internal.h	Wed Jan 17 00:09:58 2018 +0100
     2.2 +++ b/src/pEp_internal.h	Wed Jan 17 00:25:36 2018 +0100
     2.3 @@ -170,6 +170,11 @@
     2.4      sqlite3_stmt *set_revoked;
     2.5      sqlite3_stmt *get_revoked;
     2.6  
     2.7 +    // aliases
     2.8 +    sqlite3_stmt *get_userid_alias_default;
     2.9 +    sqlite3_stmt *add_userid_alias;
    2.10 +
    2.11 +
    2.12      // callbacks
    2.13      examine_identity_t examine_identity;
    2.14      void *examine_management;