ENGINE-559: updated current getter and setter functions involving identity struct ENGINE-559
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 17 May 2019 17:44:19 +0200
branchENGINE-559
changeset 37283e8c536a1634
parent 3727 d926613299bf
child 3729 1c6553767712
ENGINE-559: updated current getter and setter functions involving identity struct
src/keymanagement.c
src/pEpEngine.c
src/pEpEngine.h
     1.1 --- a/src/keymanagement.c	Fri May 17 17:05:47 2019 +0200
     1.2 +++ b/src/keymanagement.c	Fri May 17 17:44:19 2019 +0200
     1.3 @@ -1692,6 +1692,8 @@
     1.4                  }
     1.5                  ident->me = true;
     1.6                  ident->flags = flags;
     1.7 +                ident->pEp_version = (float)
     1.8 +                    sqlite3_column_double(session->own_identities_retrieve, 6);
     1.9  
    1.10                  _bl = identity_list_add(_bl, ident);
    1.11                  if (_bl == NULL) {
     2.1 --- a/src/pEpEngine.c	Fri May 17 17:05:47 2019 +0200
     2.2 +++ b/src/pEpEngine.c	Fri May 17 17:44:19 2019 +0200
     2.3 @@ -83,7 +83,7 @@
     2.4  static const char *sql_get_identity =  
     2.5      "select fpr, username, comm_type, lang,"
     2.6      "   identity.flags | pgp_keypair.flags,"
     2.7 -    "   is_own"
     2.8 +    "   is_own, pEp_version"
     2.9      "   from identity"
    2.10      "   join person on id = identity.user_id"
    2.11      "   join pgp_keypair on fpr = identity.main_key_id"
    2.12 @@ -101,7 +101,7 @@
    2.13  static const char *sql_get_identities_by_main_key_id =  
    2.14      "select address, identity.user_id, username, comm_type, lang,"
    2.15      "   identity.flags | pgp_keypair.flags,"
    2.16 -    "   is_own"
    2.17 +    "   is_own, pEp_version"
    2.18      "   from identity"
    2.19      "   join person on id = identity.user_id"
    2.20      "   join pgp_keypair on fpr = identity.main_key_id"
    2.21 @@ -113,7 +113,7 @@
    2.22  
    2.23  static const char *sql_get_identity_without_trust_check =  
    2.24      "select identity.main_key_id, username, lang,"
    2.25 -    "   identity.flags, is_own"
    2.26 +    "   identity.flags, is_own, pEp_version"
    2.27      "   from identity"
    2.28      "   join person on id = identity.user_id"
    2.29      "   where (case when (address = ?1) then (1)"
    2.30 @@ -127,7 +127,7 @@
    2.31  
    2.32  static const char *sql_get_identities_by_address =  
    2.33      "select user_id, identity.main_key_id, username, lang,"
    2.34 -    "   identity.flags, is_own"
    2.35 +    "   identity.flags, is_own, pEp_version"
    2.36      "   from identity"
    2.37      "   join person on id = identity.user_id"
    2.38      "   where (case when (address = ?1) then (1)"
    2.39 @@ -141,7 +141,7 @@
    2.40  static const char *sql_get_identities_by_userid =  
    2.41      "select address, fpr, username, comm_type, lang,"
    2.42      "   identity.flags | pgp_keypair.flags,"
    2.43 -    "   is_own"
    2.44 +    "   is_own, pEp_version"
    2.45      "   from identity"
    2.46      "   join person on id = identity.user_id"
    2.47      "   join pgp_keypair on fpr = identity.main_key_id"
    2.48 @@ -239,20 +239,22 @@
    2.49  static const char *sql_set_identity_entry = 
    2.50      "insert into identity ("
    2.51      "       address, main_key_id, "
    2.52 -    "       user_id, flags, is_own"
    2.53 +    "       user_id, flags, is_own, pEp_version"
    2.54      "   ) values ("
    2.55      "       ?1,"
    2.56      "       upper(replace(?2,' ','')),"
    2.57      "       ?3,"
    2.58      "       ?4,"
    2.59 -    "       ?5"
    2.60 +    "       ?5,"
    2.61 +    "       ?6"
    2.62      "   );";
    2.63      
    2.64  static const char* sql_update_identity_entry =    
    2.65      "update identity "
    2.66      "   set main_key_id = upper(replace(?2,' ','')), "
    2.67      "       flags = ?4, " 
    2.68 -    "       is_own = ?5 "
    2.69 +    "       is_own = ?5, "
    2.70 +    "       pEp_version = ?6 "
    2.71      "   where (case when (address = ?1) then (1)"
    2.72      "               when (lower(address) = lower(?1)) then (1)"
    2.73      "               when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1) "
    2.74 @@ -393,7 +395,7 @@
    2.75  
    2.76  static const char *sql_own_identities_retrieve =  
    2.77      "select address, fpr, identity.user_id, username,"
    2.78 -    "   lang, identity.flags | pgp_keypair.flags"
    2.79 +    "   lang, identity.flags | pgp_keypair.flags, pEp_version"
    2.80      "   from identity"
    2.81      "   join person on id = identity.user_id"
    2.82      "   join pgp_keypair on fpr = identity.main_key_id"
    2.83 @@ -965,7 +967,7 @@
    2.84                  "   comment text,\n"
    2.85                  "   flags integer default 0,\n"
    2.86                  "   is_own integer default 0,\n"
    2.87 -                "   pep_version real default 0,\n"                
    2.88 +                "   pEp_version real default 0.0,\n"                
    2.89                  "   timestamp integer default (datetime('now')),\n"
    2.90                  "   primary key (address, user_id)\n"
    2.91                  ");\n"
    2.92 @@ -1071,7 +1073,7 @@
    2.93          // Sometimes the user_version wasn't set correctly. 
    2.94          if (version == 1) {
    2.95              bool version_changed = true;
    2.96 -            if (table_contains_column(_session, "identity", "pep_version") > 0) {
    2.97 +            if (table_contains_column(_session, "identity", "pEp_version") > 0) {
    2.98                  version = 12;
    2.99              } // N.B. Version 11 was a DB internal fix; there's no identifying information, but this is only one extra exec.
   2.100              else if (db_contains_table(_session, "social_graph") > 0) {
   2.101 @@ -1431,7 +1433,7 @@
   2.102                  int_result = sqlite3_exec(
   2.103                      _session->db,
   2.104                      "alter table identity\n"
   2.105 -                    "   add column pep_version real default 0;\n",
   2.106 +                    "   add column pEp_version real default 0.0;\n",
   2.107                      NULL,
   2.108                      NULL,
   2.109                      NULL
   2.110 @@ -2466,6 +2468,8 @@
   2.111              sqlite3_column_int(session->get_identity, 4);
   2.112          _identity->me = (unsigned int)
   2.113              sqlite3_column_int(session->get_identity, 5);
   2.114 +        _identity->pEp_version = (float)
   2.115 +            sqlite3_column_double(session->get_identity, 6);
   2.116      
   2.117          *identity = _identity;
   2.118          break;
   2.119 @@ -2540,6 +2544,8 @@
   2.120              sqlite3_column_int(session->get_identities_by_userid, 5);
   2.121          ident->me = (unsigned int)
   2.122              sqlite3_column_int(session->get_identities_by_userid, 6);
   2.123 +        ident->pEp_version = (float)
   2.124 +            sqlite3_column_double(session->get_identities_by_userid, 7);
   2.125      
   2.126          identity_list_add(*identities, ident);
   2.127          ident = NULL;
   2.128 @@ -2606,6 +2612,8 @@
   2.129              sqlite3_column_int(session->get_identities_by_main_key_id, 5);
   2.130          ident->me = (unsigned int)
   2.131              sqlite3_column_int(session->get_identities_by_main_key_id, 6);
   2.132 +        ident->pEp_version = (float)
   2.133 +            sqlite3_column_double(session->get_identities_by_main_key_id, 7);
   2.134      
   2.135          identity_list_add(*identities, ident);
   2.136          ident = NULL;
   2.137 @@ -2676,6 +2684,8 @@
   2.138              sqlite3_column_int(session->get_identity_without_trust_check, 3);
   2.139          _identity->me = (unsigned int)
   2.140              sqlite3_column_int(session->get_identity_without_trust_check, 4);
   2.141 +        _identity->pEp_version = (float)
   2.142 +            sqlite3_column_double(session->get_identity_without_trust_check, 5);
   2.143      
   2.144          *identity = _identity;
   2.145          break;
   2.146 @@ -2741,6 +2751,8 @@
   2.147              sqlite3_column_int(session->get_identities_by_address, 4);
   2.148          ident->me = (unsigned int)
   2.149              sqlite3_column_int(session->get_identities_by_address, 5);
   2.150 +        ident->pEp_version = (float)
   2.151 +            sqlite3_column_double(session->get_identities_by_address, 6);
   2.152      
   2.153          if (ident_list)
   2.154              identity_list_add(ident_list, ident);
   2.155 @@ -2897,6 +2909,7 @@
   2.156              SQLITE_STATIC);
   2.157      sqlite3_bind_int(set_or_update, 4, identity->flags);
   2.158      sqlite3_bind_int(set_or_update, 5, identity->me);
   2.159 +    sqlite3_bind_double(set_or_update, 6, identity->pEp_version);
   2.160      int result = sqlite3_step(set_or_update);
   2.161      sqlite3_reset(set_or_update);
   2.162      if (result != SQLITE_DONE)
     3.1 --- a/src/pEpEngine.h	Fri May 17 17:05:47 2019 +0200
     3.2 +++ b/src/pEpEngine.h	Fri May 17 17:44:19 2019 +0200
     3.3 @@ -630,7 +630,7 @@
     3.4      PEP_comm_type comm_type;    // type of communication with this ID
     3.5      char lang[3];               // language of conversation
     3.6                                  // ISO 639-1 ALPHA-2, last byte is 0
     3.7 -    float latest_pEp_version;   // Used to determine highest seenencryption format.
     3.8 +    float pEp_version;          // Used to determine highest seenencryption format.
     3.9                                  // default is 2.0 for pEp users                            
    3.10      bool me;                    // if this is the local user herself/himself
    3.11      identity_flags_t flags;     // identity_flag1 | identity_flag2 | ...