ENGINE-250: Pretty sure the current bugs are now actual bugs and not sql-related. But will check. insert-or-replace for identity-based set functions is now replaced with a slightly convoluted callback mechanism which does a check for existence and then updates or inserts appropriately, with optional transaction guards (to be set to false if they're called in what's already a transaction, e.g. set_identity) ENGINE-250
authorKrista Bennett <krista@pep-project.org>
Wed, 07 Feb 2018 10:22:23 +0100
branchENGINE-250
changeset 24808799c08f67af
parent 2479 aba55b53cd31
child 2481 dd1eaa8cc1eb
ENGINE-250: Pretty sure the current bugs are now actual bugs and not sql-related. But will check. insert-or-replace for identity-based set functions is now replaced with a slightly convoluted callback mechanism which does a check for existence and then updates or inserts appropriately, with optional transaction guards (to be set to false if they're called in what's already a transaction, e.g. set_identity)
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Wed Feb 07 09:23:51 2018 +0100
     1.2 +++ b/src/pEpEngine.c	Wed Feb 07 10:22:23 2018 +0100
     1.3 @@ -11,6 +11,8 @@
     1.4  #include <stdlib.h>
     1.5  #include <sqlite3.h>
     1.6  
     1.7 +#define _PEP_SQLITE_DEBUG 0
     1.8 +
     1.9  static volatile int init_count = -1;
    1.10  
    1.11  // sql overloaded functions - modified from sqlite3.c
    1.12 @@ -38,6 +40,7 @@
    1.13      }
    1.14  }
    1.15  
    1.16 +#if _PEP_SQLITE_DEBUG
    1.17  int sql_trace_callback (unsigned trace_constant, 
    1.18                          void* context_ptr,
    1.19                          void* P,
    1.20 @@ -63,7 +66,7 @@
    1.21      }
    1.22      return 0;
    1.23  }
    1.24 -
    1.25 +#endif
    1.26  
    1.27  // sql manipulation statements
    1.28  static const char *sql_log = 
    1.29 @@ -195,6 +198,10 @@
    1.30      "insert or ignore into pgp_keypair (fpr) "
    1.31      "values (upper(replace(?1,' ',''))) ;";
    1.32  
    1.33 +static const char* sql_exists_identity_entry = 
    1.34 +    "select count(*) from identity "
    1.35 +    "   where address = ?1 and user_id = ?2;";
    1.36 +
    1.37  static const char *sql_set_identity_entry = 
    1.38      "insert into identity ("
    1.39      "       address, main_key_id, "
    1.40 @@ -242,6 +249,10 @@
    1.41  static const char *sql_update_trust =
    1.42      "update trust set comm_type = ?3 " 
    1.43      "   where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
    1.44 +
    1.45 +static const char* sql_exists_trust_entry = 
    1.46 +    "select count(*) from trust "
    1.47 +    "   where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
    1.48      
    1.49  static const char *sql_update_trust_for_fpr =
    1.50      "update trust "
    1.51 @@ -499,7 +510,9 @@
    1.52          goto pep_error;
    1.53      }
    1.54      
    1.55 +#if _PEP_SQLITE_DEBUG    
    1.56      sqlite3_config(SQLITE_CONFIG_LOG, errorLogCallback, NULL);
    1.57 +#endif
    1.58  
    1.59      int_result = sqlite3_open_v2(
    1.60              LOCAL_DB,
    1.61 @@ -528,10 +541,12 @@
    1.62  
    1.63      sqlite3_busy_timeout(_session->db, BUSY_WAIT_TIME);
    1.64  
    1.65 +#if _PEP_SQLITE_DEBUG
    1.66      sqlite3_trace_v2(_session->db, 
    1.67          SQLITE_TRACE_STMT | SQLITE_TRACE_ROW | SQLITE_TRACE_CLOSE,
    1.68          sql_trace_callback,
    1.69          NULL);
    1.70 +#endif
    1.71  
    1.72      assert(SYSTEM_DB);
    1.73      if (SYSTEM_DB == NULL) {
    1.74 @@ -1018,6 +1033,10 @@
    1.75              (int)strlen(sql_update_person), &_session->update_person, NULL);
    1.76      assert(int_result == SQLITE_OK);
    1.77  
    1.78 +    int_result = sqlite3_prepare_v2(_session->db, sql_exists_person,
    1.79 +            (int)strlen(sql_exists_person), &_session->exists_person, NULL);
    1.80 +    assert(int_result == SQLITE_OK);
    1.81 +
    1.82      int_result = sqlite3_prepare_v2(_session->db, sql_set_as_pep_user,
    1.83              (int)strlen(sql_set_as_pep_user), &_session->set_as_pep_user, NULL);
    1.84      assert(int_result == SQLITE_OK);
    1.85 @@ -1026,10 +1045,6 @@
    1.86              (int)strlen(sql_is_pep_user), &_session->is_pep_user, NULL);
    1.87      assert(int_result == SQLITE_OK);
    1.88  
    1.89 -    int_result = sqlite3_prepare_v2(_session->db, sql_exists_person,
    1.90 -            (int)strlen(sql_exists_person), &_session->exists_person, NULL);
    1.91 -    assert(int_result == SQLITE_OK);
    1.92 -
    1.93      int_result = sqlite3_prepare_v2(_session->db, sql_set_device_group,
    1.94              (int)strlen(sql_set_device_group), &_session->set_device_group, NULL);
    1.95      assert(int_result == SQLITE_OK);
    1.96 @@ -1051,6 +1066,10 @@
    1.97              (int)strlen(sql_update_identity_entry), &_session->update_identity_entry, NULL);
    1.98      assert(int_result == SQLITE_OK);
    1.99  
   1.100 +    int_result = sqlite3_prepare_v2(_session->db, sql_exists_identity_entry,
   1.101 +            (int)strlen(sql_exists_identity_entry), &_session->exists_identity_entry, NULL);
   1.102 +    assert(int_result == SQLITE_OK);
   1.103 +
   1.104      int_result = sqlite3_prepare_v2(_session->db, sql_set_identity_flags,
   1.105              (int)strlen(sql_set_identity_flags), &_session->set_identity_flags,
   1.106              NULL);
   1.107 @@ -1069,6 +1088,10 @@
   1.108              (int)strlen(sql_update_trust), &_session->update_trust, NULL);
   1.109      assert(int_result == SQLITE_OK);
   1.110  
   1.111 +    int_result = sqlite3_prepare_v2(_session->db, sql_exists_trust_entry,
   1.112 +                 (int)strlen(sql_exists_trust_entry), &_session->exists_trust_entry, NULL);
   1.113 +    assert(int_result == SQLITE_OK);
   1.114 +
   1.115      int_result = sqlite3_prepare_v2(_session->db, sql_update_trust_for_fpr,
   1.116              (int)strlen(sql_update_trust_for_fpr), &_session->update_trust_for_fpr, NULL);
   1.117      assert(int_result == SQLITE_OK);
   1.118 @@ -1288,6 +1311,8 @@
   1.119                  sqlite3_finalize(session->get_device_group);
   1.120              if (session->set_pgp_keypair)
   1.121                  sqlite3_finalize(session->set_pgp_keypair);
   1.122 +            if (session->exists_identity_entry)
   1.123 +                sqlite3_finalize(session->exists_identity_entry);                
   1.124              if (session->set_identity_entry)
   1.125                  sqlite3_finalize(session->set_identity_entry);
   1.126              if (session->update_identity_entry)
   1.127 @@ -1296,6 +1321,8 @@
   1.128                  sqlite3_finalize(session->set_identity_flags);
   1.129              if (session->unset_identity_flags)
   1.130                  sqlite3_finalize(session->unset_identity_flags);
   1.131 +            if (session->exists_trust_entry)
   1.132 +                sqlite3_finalize(session->exists_trust_entry);                                
   1.133              if (session->set_trust)
   1.134                  sqlite3_finalize(session->set_trust);
   1.135              if (session->update_trust)
   1.136 @@ -1985,6 +2012,68 @@
   1.137      return PEP_STATUS_OK;
   1.138  }
   1.139  
   1.140 +PEP_STATUS exists_identity_entry(PEP_SESSION session, pEp_identity* identity,
   1.141 +                                 bool* exists) {
   1.142 +    assert(session);
   1.143 +    assert(identity);
   1.144 +    assert(!EMPTYSTR(identity->user_id));        
   1.145 +    assert(!EMPTYSTR(identity->address));
   1.146 +    if (!session || !exists || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->address))
   1.147 +        return PEP_ILLEGAL_VALUE;
   1.148 +    
   1.149 +    *exists = false;
   1.150 +    
   1.151 +    sqlite3_reset(session->exists_identity_entry);
   1.152 +    sqlite3_bind_text(session->exists_identity_entry, 1, identity->address, -1,
   1.153 +                      SQLITE_STATIC);
   1.154 +    sqlite3_bind_text(session->exists_identity_entry, 2, identity->user_id, -1,
   1.155 +                      SQLITE_STATIC);
   1.156 +                  
   1.157 +    int result = sqlite3_step(session->exists_identity_entry);
   1.158 +    switch (result) {
   1.159 +        case SQLITE_ROW: {
   1.160 +            // yeah yeah, I know, we could be lazy here, but it looks bad.
   1.161 +            *exists = (sqlite3_column_int(session->exists_identity_entry, 0) != 0);
   1.162 +            break;
   1.163 +        }
   1.164 +        default:
   1.165 +            return PEP_UNKNOWN_ERROR;
   1.166 +    }
   1.167 +
   1.168 +    return PEP_STATUS_OK;
   1.169 +}
   1.170 +
   1.171 +PEP_STATUS exists_trust_entry(PEP_SESSION session, pEp_identity* identity,
   1.172 +                              bool* exists) {
   1.173 +    assert(session);
   1.174 +    assert(identity);
   1.175 +    assert(!EMPTYSTR(identity->user_id));        
   1.176 +    assert(!EMPTYSTR(identity->fpr));
   1.177 +    if (!session || !exists || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->fpr))
   1.178 +        return PEP_ILLEGAL_VALUE;
   1.179 +    
   1.180 +    *exists = false;
   1.181 +    
   1.182 +    sqlite3_reset(session->exists_trust_entry);
   1.183 +    sqlite3_bind_text(session->exists_trust_entry, 1, identity->user_id, -1,
   1.184 +                      SQLITE_STATIC);
   1.185 +    sqlite3_bind_text(session->exists_trust_entry, 2, identity->fpr, -1,
   1.186 +                      SQLITE_STATIC);
   1.187 +                  
   1.188 +    int result = sqlite3_step(session->exists_trust_entry);
   1.189 +    switch (result) {
   1.190 +        case SQLITE_ROW: {
   1.191 +            // yeah yeah, I know, we could be lazy here, but it looks bad.
   1.192 +            *exists = (sqlite3_column_int(session->exists_trust_entry, 0) != 0);
   1.193 +            break;
   1.194 +        }
   1.195 +        default:
   1.196 +            return PEP_UNKNOWN_ERROR;
   1.197 +    }
   1.198 +
   1.199 +    return PEP_STATUS_OK;
   1.200 +}
   1.201 +
   1.202  // FIXME: We can rollback in set_identity on the return status,
   1.203  // so we should probably do that.
   1.204  PEP_STATUS set_pgp_keypair(PEP_SESSION session, const char* fpr) {
   1.205 @@ -2006,7 +2095,7 @@
   1.206  }
   1.207  
   1.208  static PEP_STATUS _set_or_update_trust(PEP_SESSION session,
   1.209 -                                       const pEp_identity* identity,
   1.210 +                                       pEp_identity* identity,
   1.211                                         sqlite3_stmt* set_or_update) {
   1.212  
   1.213      assert(session);
   1.214 @@ -2035,7 +2124,7 @@
   1.215  }
   1.216  
   1.217  static PEP_STATUS _set_or_update_identity_entry(PEP_SESSION session,
   1.218 -                                                const pEp_identity* identity,
   1.219 +                                                pEp_identity* identity,
   1.220                                                  sqlite3_stmt* set_or_update) {
   1.221      assert(session);
   1.222      assert(identity);
   1.223 @@ -2062,7 +2151,7 @@
   1.224  }
   1.225  
   1.226  static PEP_STATUS _set_or_update_person(PEP_SESSION session, 
   1.227 -                                        const pEp_identity* identity,
   1.228 +                                        pEp_identity* identity,
   1.229                                          sqlite3_stmt* set_or_update) {
   1.230      assert(session);
   1.231      assert(identity);
   1.232 @@ -2093,62 +2182,64 @@
   1.233  }
   1.234  
   1.235  PEP_STATUS set_or_update_with_identity(PEP_SESSION session,
   1.236 -                                       const pEp_identity* identity,
   1.237 -                                       PEP_STATUS (* set_function)(PEP_SESSION, const pEp_identity*, sqlite3_stmt*),
   1.238 +                                       pEp_identity* identity,
   1.239 +                                       PEP_STATUS (* set_function)(PEP_SESSION, pEp_identity*, sqlite3_stmt*),
   1.240 +                                       PEP_STATUS (* exists_function)(PEP_SESSION, pEp_identity*, bool*),                                       
   1.241                                         sqlite3_stmt* update_query,
   1.242                                         sqlite3_stmt* set_query,
   1.243                                         bool guard_transaction) {
   1.244  
   1.245      if (guard_transaction) {
   1.246          sqlite3_exec(session->db, "BEGIN TRANSACTION ;", NULL, NULL, NULL);
   1.247 -    }                      
   1.248 -    PEP_STATUS status = set_function(session, identity, update_query);
   1.249 -    if (status != PEP_STATUS_OK) {
   1.250 -        if (guard_transaction)
   1.251 +    }
   1.252 +    bool exists = false;
   1.253 +    PEP_STATUS status = exists_function(session, identity, &exists);
   1.254 +    
   1.255 +    if (status == PEP_STATUS_OK) {
   1.256 +        if (exists) {
   1.257 +            status = set_function(session, identity, update_query);
   1.258 +        }
   1.259 +        else {
   1.260 +            status = set_function(session, identity, set_query);                                              
   1.261 +        }                    
   1.262 +    }   
   1.263 +    if (guard_transaction) {        
   1.264 +        if (status != PEP_STATUS_OK)
   1.265              sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
   1.266 -        return status;    
   1.267 -    }   
   1.268 -    else {
   1.269 -        if (sqlite3_changes(session->db) == 0) {
   1.270 -            status = set_function(session, identity, set_query);            
   1.271 -            if (status != PEP_STATUS_OK) {
   1.272 -                if (guard_transaction)
   1.273 -                     sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
   1.274 -                return status;    
   1.275 -            }                                  
   1.276 -        }
   1.277 -    }
   1.278 -    if (guard_transaction) {
   1.279 -        sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
   1.280 +        else 
   1.281 +            sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
   1.282      }                      
   1.283      return status;
   1.284  }
   1.285  
   1.286 -PEP_STATUS _set_trust_internal(PEP_SESSION session, const pEp_identity* identity,
   1.287 +PEP_STATUS _set_trust_internal(PEP_SESSION session, pEp_identity* identity,
   1.288                                 bool guard_transaction) {
   1.289      return set_or_update_with_identity(session, identity,
   1.290                                         _set_or_update_trust,
   1.291 +                                       exists_trust_entry,
   1.292                                         session->update_trust,
   1.293                                         session->set_trust,
   1.294                                         guard_transaction);
   1.295  }
   1.296 -PEP_STATUS set_trust(PEP_SESSION session, const pEp_identity* identity) {
   1.297 +PEP_STATUS set_trust(PEP_SESSION session, pEp_identity* identity) {
   1.298      return _set_trust_internal(session, identity, true);
   1.299  }
   1.300  
   1.301 -PEP_STATUS set_person(PEP_SESSION session, const pEp_identity* identity,
   1.302 +PEP_STATUS set_person(PEP_SESSION session, pEp_identity* identity,
   1.303                        bool guard_transaction) {
   1.304      return set_or_update_with_identity(session, identity,
   1.305                                         _set_or_update_person,
   1.306 +                                       exists_person,
   1.307                                         session->update_person,
   1.308                                         session->set_person,
   1.309                                         guard_transaction);
   1.310  }
   1.311  
   1.312 -PEP_STATUS set_identity_entry(PEP_SESSION session, const pEp_identity* identity,
   1.313 +PEP_STATUS set_identity_entry(PEP_SESSION session, pEp_identity* identity,
   1.314                                bool guard_transaction) {
   1.315      return set_or_update_with_identity(session, identity,
   1.316                                         _set_or_update_identity_entry,
   1.317 +                                       exists_identity_entry,
   1.318                                         session->update_identity_entry,
   1.319                                         session->set_identity_entry,
   1.320                                         guard_transaction);
   1.321 @@ -2174,7 +2265,7 @@
   1.322      
   1.323      bool listed;
   1.324  
   1.325 -    bool has_fpr = (identity->fpr && identity->fpr[0] != '\0');
   1.326 +    bool has_fpr = (!EMPTYSTR(identity->fpr));
   1.327      
   1.328      if (has_fpr) {    
   1.329          // blacklist check - FIXME: ENGINE-294 will remove
   1.330 @@ -2207,31 +2298,41 @@
   1.331          }
   1.332      }
   1.333  
   1.334 -    status = set_person(session, identity, false);
   1.335 +    // We do this because there are checks in set_person for
   1.336 +    // aliases, which modify the identity object on return.
   1.337 +    pEp_identity* ident_copy = identity_dup(identity); 
   1.338 +    if (!ident_copy)
   1.339 +        return PEP_OUT_OF_MEMORY;
   1.340 +
   1.341 +    status = set_person(session, ident_copy, false);
   1.342      if (status != PEP_STATUS_OK) {
   1.343          sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
   1.344 -        return status;
   1.345 +        goto pep_free;
   1.346      }
   1.347  
   1.348 -    status = set_identity_entry(session, identity, false);
   1.349 +    status = set_identity_entry(session, ident_copy, false);
   1.350      if (status != PEP_STATUS_OK) {
   1.351          sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
   1.352 -        return status;
   1.353 +        goto pep_free;
   1.354      }
   1.355  
   1.356      if (has_fpr) {
   1.357 -        status = _set_trust_internal(session, identity, false);
   1.358 +        status = _set_trust_internal(session, ident_copy, false);
   1.359          if (status != PEP_STATUS_OK) {
   1.360              sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
   1.361 -            return status;
   1.362 +            goto pep_free;
   1.363          }
   1.364      }
   1.365      
   1.366      result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
   1.367      if (result == SQLITE_OK)
   1.368 -        return PEP_STATUS_OK;
   1.369 +        status = PEP_STATUS_OK;
   1.370      else
   1.371 -        return PEP_COMMIT_FAILED;
   1.372 +        status = PEP_COMMIT_FAILED;
   1.373 +
   1.374 +pep_free:
   1.375 +    free_identity(ident_copy);
   1.376 +    return status;
   1.377  }
   1.378  
   1.379  // This ONLY sets the user flag, and creates a shell identity if necessary.
   1.380 @@ -2241,19 +2342,15 @@
   1.381      assert(user);
   1.382      assert(user->address);
   1.383      assert(!EMPTYSTR(user->user_id));
   1.384 -    
   1.385 -    char* user_id = user->user_id;
   1.386 -    
   1.387 -    if (!session || !user || user->address || EMPTYSTR(user_id))
   1.388 +        
   1.389 +    if (!session || !user || user->address || EMPTYSTR(user->user_id))
   1.390          return PEP_ILLEGAL_VALUE;
   1.391              
   1.392      PEP_STATUS status = PEP_STATUS_OK;
   1.393      
   1.394 -    char* alias_default = NULL;
   1.395 -    
   1.396      bool person_exists = false;
   1.397      
   1.398 -    status = exists_person(session, user_id, &alias_default, &person_exists);
   1.399 +    status = exists_person(session, user, &person_exists);
   1.400      
   1.401      if (status != PEP_STATUS_OK)
   1.402          return status;
   1.403 @@ -2268,12 +2365,11 @@
   1.404          free_identity(tmp_id);
   1.405          if (status != PEP_STATUS_OK)
   1.406              return status;
   1.407 -        alias_default = strdup(user->user_id);
   1.408      }
   1.409          
   1.410      // Ok, let's set it.
   1.411      sqlite3_reset(session->set_as_pep_user);
   1.412 -    sqlite3_bind_text(session->set_as_pep_user, 1, alias_default, -1,
   1.413 +    sqlite3_bind_text(session->set_as_pep_user, 1, user->user_id, -1,
   1.414              SQLITE_STATIC);
   1.415      int result = sqlite3_step(session->set_as_pep_user);
   1.416      sqlite3_reset(session->set_as_pep_user);
   1.417 @@ -2284,24 +2380,27 @@
   1.418      return PEP_STATUS_OK;    
   1.419  }
   1.420  
   1.421 -PEP_STATUS exists_person(PEP_SESSION session, const char* user_id,
   1.422 -                         char** default_id, bool* exists) {
   1.423 +PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity,
   1.424 +                         bool* exists) {            
   1.425 +    
   1.426 +    // const char* user_id,
   1.427 +    //                      char** default_id, bool* exists) {
   1.428      assert(session);
   1.429      assert(exists);
   1.430 -    assert(!EMPTYSTR(user_id));
   1.431 +    assert(identity);
   1.432 +    assert(!EMPTYSTR(identity->user_id));
   1.433          
   1.434 -    if (!session || !exists || EMPTYSTR(user_id))
   1.435 +    if (!session || !exists || !identity || EMPTYSTR(identity->user_id))
   1.436          return PEP_ILLEGAL_VALUE;
   1.437      
   1.438      *exists = false;
   1.439 -    
   1.440 +
   1.441 +    const char* user_id = identity->user_id;
   1.442      char* alias_default = NULL;
   1.443      
   1.444      PEP_STATUS status = get_userid_alias_default(session, user_id, &alias_default);
   1.445      
   1.446      if (status == PEP_CANNOT_FIND_ALIAS || EMPTYSTR(alias_default)) {
   1.447 -        free(alias_default);
   1.448 -        alias_default = NULL;
   1.449          sqlite3_reset(session->exists_person);
   1.450          sqlite3_bind_text(session->exists_person, 1, user_id, -1,
   1.451                  SQLITE_STATIC);
   1.452 @@ -2310,23 +2409,23 @@
   1.453              case SQLITE_ROW: {
   1.454                  // yeah yeah, I know, we could be lazy here, but it looks bad.
   1.455                  *exists = (sqlite3_column_int(session->exists_person, 0) != 0);
   1.456 +                status = PEP_STATUS_OK;
   1.457                  break;
   1.458              }
   1.459              default:
   1.460                  return PEP_UNKNOWN_ERROR;
   1.461          }
   1.462 -        if (*exists)
   1.463 -            alias_default = strdup(user_id);
   1.464 +    }
   1.465 +    else if (status == PEP_STATUS_OK) {
   1.466 +        *exists = true; // thank you, delete on cascade!
   1.467 +        // FIXME: Should we correct the userid default here? I think we should.
   1.468 +        free(identity->user_id);
   1.469 +        identity->user_id = alias_default; // ownership transfer
   1.470      }
   1.471      else
   1.472 -        *exists = true; // thank you, delete on cascade!
   1.473 -
   1.474 -    if (!default_id)
   1.475          free(alias_default);
   1.476 -    else    
   1.477 -        *default_id = alias_default;
   1.478 -    
   1.479 -    return PEP_STATUS_OK;
   1.480 +        
   1.481 +    return status;
   1.482  }
   1.483  
   1.484  PEP_STATUS is_pep_user(PEP_SESSION session, pEp_identity *identity, bool* is_pep)
     2.1 --- a/src/pEpEngine.h	Wed Feb 07 09:23:51 2018 +0100
     2.2 +++ b/src/pEpEngine.h	Wed Feb 07 10:22:23 2018 +0100
     2.3 @@ -934,7 +934,7 @@
     2.4  
     2.5  
     2.6  PEP_STATUS set_trust(PEP_SESSION session, 
     2.7 -                     const pEp_identity* identity);
     2.8 +                     pEp_identity* identity);
     2.9                              
    2.10  PEP_STATUS update_trust_for_fpr(PEP_SESSION session, 
    2.11                                  const char* fpr, 
    2.12 @@ -1232,12 +1232,9 @@
    2.13  // This ONLY sets the *user* flag, and creates a shell identity if necessary.
    2.14  PEP_STATUS set_as_pep_user(PEP_SESSION session, pEp_identity* user);
    2.15  
    2.16 -// returns true (by reference) if a person with this user_id exists; if default_id != NULL,
    2.17 -// function will also return by reference a copy of the default id which
    2.18 -// is this user_id is aliased to (which will usually, but not always, 
    2.19 -// string equivalent to the user_id)
    2.20 -PEP_STATUS exists_person(PEP_SESSION session, const char* user_id,
    2.21 -                         char** default_id, bool* exists);
    2.22 +// returns true (by reference) if a person with this user_id exists; 
    2.23 +// Also replaces aliased user_ids by defaults in identity.
    2.24 +PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity, bool* exists);
    2.25  
    2.26  // returns true if the USER corresponding to this identity has been listed in
    2.27  // the *person* table as a pEp user. This *does not check comm_type*                         
     3.1 --- a/src/pEp_internal.h	Wed Feb 07 09:23:51 2018 +0100
     3.2 +++ b/src/pEp_internal.h	Wed Feb 07 10:22:23 2018 +0100
     3.3 @@ -131,19 +131,21 @@
     3.4      sqlite3_stmt *refresh_userid_default_key;
     3.5      sqlite3_stmt *remove_fpr_as_default;
     3.6      sqlite3_stmt *set_person;
     3.7 -    sqlite3_stmt *update_person;    
     3.8 +    sqlite3_stmt *update_person;
     3.9 +    sqlite3_stmt *exists_person;    
    3.10      sqlite3_stmt *set_as_pep_user;
    3.11      sqlite3_stmt *is_pep_user;
    3.12 -    sqlite3_stmt *exists_person;
    3.13      sqlite3_stmt *set_device_group;
    3.14      sqlite3_stmt *get_device_group;
    3.15      sqlite3_stmt *set_pgp_keypair;
    3.16      sqlite3_stmt *set_identity_entry;
    3.17 -    sqlite3_stmt *update_identity_entry;    
    3.18 +    sqlite3_stmt *update_identity_entry;
    3.19 +    sqlite3_stmt *exists_identity_entry;        
    3.20      sqlite3_stmt *set_identity_flags;
    3.21      sqlite3_stmt *unset_identity_flags;
    3.22      sqlite3_stmt *set_trust;
    3.23      sqlite3_stmt *update_trust;    
    3.24 +    sqlite3_stmt *exists_trust_entry;
    3.25      sqlite3_stmt *update_trust_for_fpr;
    3.26      sqlite3_stmt *get_trust;
    3.27      sqlite3_stmt *least_trust;