adding set_identity_flags()
authorVolker Birk <vb@pep-project.org>
Wed, 27 Jul 2016 15:34:44 +0200
changeset 932d35b292fe141
parent 931 02ec6c6296a2
child 933 8fecdff2f957
adding set_identity_flags()
src/keymanagement.c
src/keymanagement.h
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/keymanagement.c	Wed Jul 27 14:46:41 2016 +0200
     1.2 +++ b/src/keymanagement.c	Wed Jul 27 15:34:44 2016 +0200
     1.3 @@ -203,6 +203,8 @@
     1.4              identity->lang[1] = stored_identity->lang[1];
     1.5              identity->lang[2] = 0;
     1.6          }
     1.7 +
     1.8 +        identity->flags = stored_identity->flags;
     1.9      }
    1.10      else /* stored_identity == NULL */ {
    1.11          if (!EMPTYSTR(identity->fpr)) {
    1.12 @@ -390,6 +392,8 @@
    1.13                  return PEP_OUT_OF_MEMORY;
    1.14              }
    1.15          }
    1.16 +
    1.17 +        identity->flags = stored_identity->flags;
    1.18      }
    1.19      else if (!EMPTYSTR(identity->fpr))
    1.20      {
     2.1 --- a/src/keymanagement.h	Wed Jul 27 14:46:41 2016 +0200
     2.2 +++ b/src/keymanagement.h	Wed Jul 27 15:34:44 2016 +0200
     2.3 @@ -18,6 +18,8 @@
     2.4  //      asynchronous management implementation, so retrieve_next_identity()
     2.5  //      will return this identity later
     2.6  //      at least identity->address must be a non-empty UTF-8 string as input
     2.7 +//      update_identity() never writes flags; use set_identity_flags() for
     2.8 +//      writing
     2.9  
    2.10  DYNAMIC_API PEP_STATUS update_identity(
    2.11          PEP_SESSION session, pEp_identity * identity
    2.12 @@ -40,6 +42,7 @@
    2.13  //      it can need a decent amount of time to return
    2.14  //      if you need to do this asynchronous, you need to return an identity
    2.15  //      with retrieve_next_identity() where pEp_identity.me is true
    2.16 +//      myself() never writes flags; use set_identity_flags() for writing
    2.17  
    2.18  DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity);
    2.19  
     3.1 --- a/src/pEpEngine.c	Wed Jul 27 14:46:41 2016 +0200
     3.2 +++ b/src/pEpEngine.c	Wed Jul 27 15:34:44 2016 +0200
     3.3 @@ -29,6 +29,7 @@
     3.4      static const char *sql_set_person;
     3.5      static const char *sql_set_pgp_keypair;
     3.6      static const char *sql_set_identity;
     3.7 +    static const char *sql_set_identity_flags;
     3.8      static const char *sql_set_trust;
     3.9      static const char *sql_get_trust;
    3.10      static const char *sql_least_trust;
    3.11 @@ -295,6 +296,9 @@
    3.12                             "user_id, flags) values (?1, upper(replace(?2,' ','')),"
    3.13                             "?3, ?4) ;";
    3.14  
    3.15 +        sql_set_identity_flags = "update identity set flags = ?1 "
    3.16 +                                 "where address = ?2 and user_id = ?3 ;";
    3.17 +
    3.18          sql_set_trust = "insert or replace into trust (user_id, pgp_keypair_fpr, comm_type) "
    3.19                          "values (?1, upper(replace(?2,' ','')), ?3) ;";
    3.20  
    3.21 @@ -385,6 +389,10 @@
    3.22              (int)strlen(sql_set_identity), &_session->set_identity, NULL);
    3.23      assert(int_result == SQLITE_OK);
    3.24  
    3.25 +    int_result = sqlite3_prepare_v2(_session->db, sql_set_identity_flags,
    3.26 +            (int)strlen(sql_set_identity_flags), &_session->set_identity_flags, NULL);
    3.27 +    assert(int_result == SQLITE_OK);
    3.28 +
    3.29      int_result = sqlite3_prepare_v2(_session->db, sql_set_trust,
    3.30              (int)strlen(sql_set_trust), &_session->set_trust, NULL);
    3.31      assert(int_result == SQLITE_OK);
    3.32 @@ -527,6 +535,8 @@
    3.33                  sqlite3_finalize(session->set_pgp_keypair);
    3.34              if (session->set_identity)
    3.35                  sqlite3_finalize(session->set_identity);
    3.36 +            if (session->set_identity_flags)
    3.37 +                sqlite3_finalize(session->set_identity_flags);
    3.38              if (session->set_trust)
    3.39                  sqlite3_finalize(session->set_trust);
    3.40              if (session->get_trust)
    3.41 @@ -955,7 +965,7 @@
    3.42              SQLITE_STATIC);
    3.43      sqlite3_bind_text(session->set_identity, 3, identity->user_id, -1,
    3.44              SQLITE_STATIC);
    3.45 -    sqlite3_bind_int(session->set_trust, 4, identity->flags);
    3.46 +    sqlite3_bind_int(session->set_identity, 4, identity->flags);
    3.47      result = sqlite3_step(session->set_identity);
    3.48      sqlite3_reset(session->set_identity);
    3.49      if (result != SQLITE_DONE) {
    3.50 @@ -983,6 +993,34 @@
    3.51          return PEP_COMMIT_FAILED;
    3.52  }
    3.53  
    3.54 +DYNAMIC_API PEP_STATUS set_identity_flags(
    3.55 +        PEP_SESSION session, const pEp_identity *identity
    3.56 +    )
    3.57 +{
    3.58 +    int result;
    3.59 +
    3.60 +    assert(session);
    3.61 +    assert(identity);
    3.62 +    assert(identity->address);
    3.63 +    assert(identity->user_id);
    3.64 +
    3.65 +    if (!(session && identity && identity->address && identity->user_id))
    3.66 +        return PEP_ILLEGAL_VALUE;
    3.67 +
    3.68 +    sqlite3_reset(session->set_identity_flags);
    3.69 +    sqlite3_bind_int(session->set_identity_flags, 1, identity->flags);
    3.70 +    sqlite3_bind_text(session->set_identity_flags, 2, identity->address, -1,
    3.71 +            SQLITE_STATIC);
    3.72 +    sqlite3_bind_text(session->set_identity_flags, 3, identity->user_id, -1,
    3.73 +            SQLITE_STATIC);
    3.74 +    result = sqlite3_step(session->set_identity_flags);
    3.75 +    sqlite3_reset(session->set_identity_flags);
    3.76 +    if (result != SQLITE_DONE)
    3.77 +        return PEP_CANNOT_SET_IDENTITY;
    3.78 +
    3.79 +    return PEP_STATUS_OK;
    3.80 +}
    3.81 +
    3.82  DYNAMIC_API PEP_STATUS mark_as_compromized(
    3.83          PEP_SESSION session,
    3.84          const char *fpr
     4.1 --- a/src/pEpEngine.h	Wed Jul 27 14:46:41 2016 +0200
     4.2 +++ b/src/pEpEngine.h	Wed Jul 27 15:34:44 2016 +0200
     4.3 @@ -411,7 +411,7 @@
     4.4  //      username (in)       UTF-8 string or NULL 
     4.5  //
     4.6  //  return value:
     4.7 -//      pEp_identity struct with correct size values or NULL if out of memory
     4.8 +//      pEp_identity struct or NULL if out of memory
     4.9  //
    4.10  //  caveat:
    4.11  //      the strings are copied; the original strings are still being owned by
    4.12 @@ -423,13 +423,13 @@
    4.13      );
    4.14  
    4.15  
    4.16 -// identity_dup() - allocate memory and set the string and size fields
    4.17 +// identity_dup() - allocate memory and duplicate
    4.18  //
    4.19  //  parameters:
    4.20  //      src (in)            identity to duplicate
    4.21  //
    4.22  //  return value:
    4.23 -//      pEp_identity struct with correct size values or NULL if out of memory
    4.24 +//      pEp_identity struct or NULL if out of memory
    4.25  //
    4.26  //  caveat:
    4.27  //      the strings are copied; the original strings are still being owned by
    4.28 @@ -486,18 +486,34 @@
    4.29  //        PEP_CANNOT_SET_PGP_KEYPAIR    writing to table pgp_keypair failed
    4.30  //        PEP_CANNOT_SET_IDENTITY       writing to table identity failed
    4.31  //        PEP_COMMIT_FAILED             SQL commit failed
    4.32 -//      PEP_KEY_BLACKLISTED             Key blacklisted, cannot set identity
    4.33 +//        PEP_KEY_BLACKLISTED           Key blacklisted, cannot set identity
    4.34  //
    4.35  //    caveat:
    4.36 -//        in the identity structure you need to set the const char * fields to
    4.37 -//        UTF-8 C strings
    4.38 -//        the size fields are ignored
    4.39 +//        address, fpr, user_id and username must be given
    4.40  
    4.41  DYNAMIC_API PEP_STATUS set_identity(
    4.42          PEP_SESSION session, const pEp_identity *identity
    4.43      );
    4.44  
    4.45  
    4.46 +// set_identity_flags() - update identity flags on existing identity
    4.47 +//
    4.48 +//    parameters:
    4.49 +//        session (in)        session handle
    4.50 +//        identity (in)       pointer to pEp_identity structure
    4.51 +//
    4.52 +//    return value:
    4.53 +//        PEP_STATUS_OK = 0             encryption and signing succeeded
    4.54 +//        PEP_CANNOT_SET_IDENTITY       update of identity failed
    4.55 +//
    4.56 +//    caveat:
    4.57 +//        address and user_id must be given
    4.58 +
    4.59 +DYNAMIC_API PEP_STATUS set_identity_flags(
    4.60 +        PEP_SESSION session, const pEp_identity *identity
    4.61 +    );
    4.62 +
    4.63 +
    4.64  // mark_as_compromized() - mark key in trust db as compromized
    4.65  //
    4.66  //    parameters:
     5.1 --- a/src/pEp_internal.h	Wed Jul 27 14:46:41 2016 +0200
     5.2 +++ b/src/pEp_internal.h	Wed Jul 27 15:34:44 2016 +0200
     5.3 @@ -97,6 +97,7 @@
     5.4      sqlite3_stmt *set_person;
     5.5      sqlite3_stmt *set_pgp_keypair;
     5.6      sqlite3_stmt *set_identity;
     5.7 +    sqlite3_stmt *set_identity_flags;
     5.8      sqlite3_stmt *set_trust;
     5.9      sqlite3_stmt *get_trust;
    5.10      sqlite3_stmt *least_trust;