src/pEpEngine.c
branchENGINE-654
changeset 4121 0e3f9c6ce8a9
parent 3982 c4162e447585
child 4127 2fb3ecbf7c42
child 4128 4501cadac721
     1.1 --- a/src/pEpEngine.c	Wed Oct 16 17:39:51 2019 +0200
     1.2 +++ b/src/pEpEngine.c	Wed Oct 16 18:10:28 2019 +0200
     1.3 @@ -336,6 +336,10 @@
     1.4      "update trust set comm_type = ?3 " 
     1.5      "   where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
     1.6  
     1.7 +static const char *sql_clear_trust_info =
     1.8 +    "delete from trust "
     1.9 +    "   where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
    1.10 +
    1.11  static const char *sql_update_trust_to_pEp =
    1.12      "update trust set comm_type = comm_type + 71 "
    1.13      "   where (user_id = ?1 "
    1.14 @@ -1760,6 +1764,10 @@
    1.15              NULL);
    1.16      assert(int_result == SQLITE_OK);
    1.17  
    1.18 +    int_result = sqlite3_prepare_v2(_session->db, sql_clear_trust_info,
    1.19 +            (int)strlen(sql_clear_trust_info), &_session->clear_trust_info, NULL);
    1.20 +    assert(int_result == SQLITE_OK);
    1.21 +
    1.22      int_result = sqlite3_prepare_v2(_session->db, sql_set_trust,
    1.23              (int)strlen(sql_set_trust), &_session->set_trust, NULL);
    1.24      assert(int_result == SQLITE_OK);
    1.25 @@ -2034,6 +2042,8 @@
    1.26                  sqlite3_finalize(session->set_pEp_version);                
    1.27              if (session->exists_trust_entry)
    1.28                  sqlite3_finalize(session->exists_trust_entry);                                
    1.29 +            if (session->clear_trust_info)
    1.30 +                sqlite3_finalize(session->clear_trust_info);                
    1.31              if (session->set_trust)
    1.32                  sqlite3_finalize(session->set_trust);
    1.33              if (session->update_trust)
    1.34 @@ -2998,6 +3008,28 @@
    1.35      return PEP_STATUS_OK;
    1.36  }
    1.37  
    1.38 +PEP_STATUS clear_trust_info(PEP_SESSION session,
    1.39 +                            const char* user_id,
    1.40 +                            const char* fpr) {
    1.41 +    if (!session || EMPTYSTR(fpr) || EMPTYSTR(user_id))
    1.42 +        return PEP_ILLEGAL_VALUE;
    1.43 +        
    1.44 +    int result;
    1.45 +    
    1.46 +    sqlite3_reset(session->clear_trust_info);
    1.47 +    sqlite3_bind_text(session->clear_trust_info, 1, user_id, -1,
    1.48 +            SQLITE_STATIC);    
    1.49 +    sqlite3_bind_text(session->clear_trust_info, 2, fpr, -1,
    1.50 +            SQLITE_STATIC);
    1.51 +    result = Sqlite3_step(session->clear_trust_info);
    1.52 +    sqlite3_reset(session->clear_trust_info);
    1.53 +    if (result != SQLITE_DONE) {
    1.54 +        return PEP_UNKNOWN_ERROR;
    1.55 +    }
    1.56 +    
    1.57 +    return PEP_STATUS_OK;
    1.58 +}
    1.59 +
    1.60  static PEP_STATUS _set_or_update_trust(PEP_SESSION session,
    1.61                                         pEp_identity* identity,
    1.62                                         sqlite3_stmt* set_or_update) {