src/pEpEngine.c
changeset 932 d35b292fe141
parent 930 c201a657e628
child 934 6ec71cdedec1
     1.1 --- a/src/pEpEngine.c	Wed Jul 27 14:46:41 2016 +0200
     1.2 +++ b/src/pEpEngine.c	Wed Jul 27 15:34:44 2016 +0200
     1.3 @@ -29,6 +29,7 @@
     1.4      static const char *sql_set_person;
     1.5      static const char *sql_set_pgp_keypair;
     1.6      static const char *sql_set_identity;
     1.7 +    static const char *sql_set_identity_flags;
     1.8      static const char *sql_set_trust;
     1.9      static const char *sql_get_trust;
    1.10      static const char *sql_least_trust;
    1.11 @@ -295,6 +296,9 @@
    1.12                             "user_id, flags) values (?1, upper(replace(?2,' ','')),"
    1.13                             "?3, ?4) ;";
    1.14  
    1.15 +        sql_set_identity_flags = "update identity set flags = ?1 "
    1.16 +                                 "where address = ?2 and user_id = ?3 ;";
    1.17 +
    1.18          sql_set_trust = "insert or replace into trust (user_id, pgp_keypair_fpr, comm_type) "
    1.19                          "values (?1, upper(replace(?2,' ','')), ?3) ;";
    1.20  
    1.21 @@ -385,6 +389,10 @@
    1.22              (int)strlen(sql_set_identity), &_session->set_identity, NULL);
    1.23      assert(int_result == SQLITE_OK);
    1.24  
    1.25 +    int_result = sqlite3_prepare_v2(_session->db, sql_set_identity_flags,
    1.26 +            (int)strlen(sql_set_identity_flags), &_session->set_identity_flags, NULL);
    1.27 +    assert(int_result == SQLITE_OK);
    1.28 +
    1.29      int_result = sqlite3_prepare_v2(_session->db, sql_set_trust,
    1.30              (int)strlen(sql_set_trust), &_session->set_trust, NULL);
    1.31      assert(int_result == SQLITE_OK);
    1.32 @@ -527,6 +535,8 @@
    1.33                  sqlite3_finalize(session->set_pgp_keypair);
    1.34              if (session->set_identity)
    1.35                  sqlite3_finalize(session->set_identity);
    1.36 +            if (session->set_identity_flags)
    1.37 +                sqlite3_finalize(session->set_identity_flags);
    1.38              if (session->set_trust)
    1.39                  sqlite3_finalize(session->set_trust);
    1.40              if (session->get_trust)
    1.41 @@ -955,7 +965,7 @@
    1.42              SQLITE_STATIC);
    1.43      sqlite3_bind_text(session->set_identity, 3, identity->user_id, -1,
    1.44              SQLITE_STATIC);
    1.45 -    sqlite3_bind_int(session->set_trust, 4, identity->flags);
    1.46 +    sqlite3_bind_int(session->set_identity, 4, identity->flags);
    1.47      result = sqlite3_step(session->set_identity);
    1.48      sqlite3_reset(session->set_identity);
    1.49      if (result != SQLITE_DONE) {
    1.50 @@ -983,6 +993,34 @@
    1.51          return PEP_COMMIT_FAILED;
    1.52  }
    1.53  
    1.54 +DYNAMIC_API PEP_STATUS set_identity_flags(
    1.55 +        PEP_SESSION session, const pEp_identity *identity
    1.56 +    )
    1.57 +{
    1.58 +    int result;
    1.59 +
    1.60 +    assert(session);
    1.61 +    assert(identity);
    1.62 +    assert(identity->address);
    1.63 +    assert(identity->user_id);
    1.64 +
    1.65 +    if (!(session && identity && identity->address && identity->user_id))
    1.66 +        return PEP_ILLEGAL_VALUE;
    1.67 +
    1.68 +    sqlite3_reset(session->set_identity_flags);
    1.69 +    sqlite3_bind_int(session->set_identity_flags, 1, identity->flags);
    1.70 +    sqlite3_bind_text(session->set_identity_flags, 2, identity->address, -1,
    1.71 +            SQLITE_STATIC);
    1.72 +    sqlite3_bind_text(session->set_identity_flags, 3, identity->user_id, -1,
    1.73 +            SQLITE_STATIC);
    1.74 +    result = sqlite3_step(session->set_identity_flags);
    1.75 +    sqlite3_reset(session->set_identity_flags);
    1.76 +    if (result != SQLITE_DONE)
    1.77 +        return PEP_CANNOT_SET_IDENTITY;
    1.78 +
    1.79 +    return PEP_STATUS_OK;
    1.80 +}
    1.81 +
    1.82  DYNAMIC_API PEP_STATUS mark_as_compromized(
    1.83          PEP_SESSION session,
    1.84          const char *fpr