ENGINE-140 clean'up own_identities_retrieve so that available pEpEngine API returns all own identities, not only those that can be synced
authorEdouard Tisserant <edouard@pep-project.org>
Mon, 21 Nov 2016 22:27:25 +0100
changeset 141251341b8d69d0
parent 1411 25a8f419816d
child 1413 41c869ac1c48
child 1417 3507e785e538
ENGINE-140 clean'up own_identities_retrieve so that available pEpEngine API returns all own identities, not only those that can be synced
src/keymanagement.c
src/keymanagement.h
src/pEpEngine.c
src/sync_impl.c
src/sync_send_actions.c
sync/gen_actions_skeleton.ysl2
     1.1 --- a/src/keymanagement.c	Sun Nov 20 21:35:25 2016 +0100
     1.2 +++ b/src/keymanagement.c	Mon Nov 21 22:27:25 2016 +0100
     1.3 @@ -822,9 +822,10 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 -DYNAMIC_API PEP_STATUS own_identities_retrieve(
     1.8 +PEP_STATUS _own_identities_retrieve(
     1.9          PEP_SESSION session,
    1.10 -        identity_list **own_identities
    1.11 +        identity_list **own_identities,
    1.12 +        identity_flags_t excluded_flags
    1.13        )
    1.14  {
    1.15      PEP_STATUS status = PEP_STATUS_OK;
    1.16 @@ -852,6 +853,7 @@
    1.17      
    1.18      identity_list *_bl = _own_identities;
    1.19      do {
    1.20 +        sqlite3_bind_int(session->own_identities_retrieve, 1, excluded_flags);
    1.21          result = sqlite3_step(session->own_identities_retrieve);
    1.22          switch (result) {
    1.23              case SQLITE_ROW:
    1.24 @@ -913,9 +915,18 @@
    1.25      return status;
    1.26  }
    1.27  
    1.28 -DYNAMIC_API PEP_STATUS own_keys_retrieve(
    1.29 +DYNAMIC_API PEP_STATUS own_identities_retrieve(
    1.30          PEP_SESSION session,
    1.31 -        stringlist_t **keylist
    1.32 +        identity_list **own_identities
    1.33 +      )
    1.34 +{
    1.35 +    return _own_identities_retrieve(session, own_identities, 0);
    1.36 +}
    1.37 +
    1.38 +PEP_STATUS _own_keys_retrieve(
    1.39 +        PEP_SESSION session,
    1.40 +        stringlist_t **keylist,
    1.41 +        identity_flags_t excluded_flags
    1.42        )
    1.43  {
    1.44      PEP_STATUS status = PEP_STATUS_OK;
    1.45 @@ -934,6 +945,7 @@
    1.46      
    1.47      stringlist_t *_bl = _keylist;
    1.48      do {
    1.49 +        sqlite3_bind_int(session->own_keys_retrieve, 1, excluded_flags);
    1.50          result = sqlite3_step(session->own_keys_retrieve);
    1.51          switch (result) {
    1.52              case SQLITE_ROW:
    1.53 @@ -976,6 +988,11 @@
    1.54      return status;
    1.55  }
    1.56  
    1.57 +DYNAMIC_API PEP_STATUS own_keys_retrieve(PEP_SESSION session, stringlist_t **keylist)
    1.58 +{
    1.59 +    return _own_keys_retrieve(session, keylist, 0);
    1.60 +}
    1.61 +
    1.62  // TODO: Unused for now, but should be used when sync receive old keys (ENGINE-145)
    1.63  DYNAMIC_API PEP_STATUS set_own_key(
    1.64         PEP_SESSION session,
     2.1 --- a/src/keymanagement.h	Sun Nov 20 21:35:25 2016 +0100
     2.2 +++ b/src/keymanagement.h	Mon Nov 21 22:27:25 2016 +0100
     2.3 @@ -171,6 +171,22 @@
     2.4      );
     2.5  
     2.6  
     2.7 +// _own_identities_retrieve() - retrieve all own identities
     2.8 +//
     2.9 +//  parameters:
    2.10 +//      session (in)            session to use
    2.11 +//      own_identities (out)    list of own identities
    2.12 +//      excluded_flags (int)    flags to exclude from results
    2.13 +//
    2.14 +//  caveat:
    2.15 +//      the ownership of the copy of own_identities goes to the caller
    2.16 +
    2.17 +DYNAMIC_API PEP_STATUS _own_identities_retrieve(
    2.18 +        PEP_SESSION session,
    2.19 +        identity_list **own_identities,
    2.20 +        identity_flags_t excluded_flags
    2.21 +    );
    2.22 +
    2.23  // own_identities_retrieve() - retrieve all own identities
    2.24  //
    2.25  //  parameters:
    2.26 @@ -188,6 +204,21 @@
    2.27  PEP_STATUS contains_priv_key(PEP_SESSION session, const char *fpr,
    2.28                               bool *has_private);
    2.29  
    2.30 +// _own_keys_retrieve() - retrieve all flagged keypair fingerprints 
    2.31 +//
    2.32 +//  parameters:
    2.33 +//      session (in)            session to use
    2.34 +//      keylist (out)           list of fingerprints
    2.35 +//      excluded_flags (int)    flags to exclude from results
    2.36 +//
    2.37 +//  caveat:
    2.38 +//      the ownership of the list goes to the caller
    2.39 +DYNAMIC_API PEP_STATUS _own_keys_retrieve(
    2.40 +        PEP_SESSION session,
    2.41 +        stringlist_t **keylist,
    2.42 +        identity_flags_t excluded_flags
    2.43 +      );
    2.44 +
    2.45  // own_keys_retrieve() - retrieve all flagged keypair fingerprints 
    2.46  //
    2.47  //  parameters:
     3.1 --- a/src/pEpEngine.c	Sun Nov 20 21:35:25 2016 +0100
     3.2 +++ b/src/pEpEngine.c	Mon Nov 21 22:27:25 2016 +0100
     3.3 @@ -411,12 +411,12 @@
     3.4                              "   join trust on id = trust.user_id"
     3.5                              "       and pgp_keypair_fpr = identity.main_key_id"
     3.6                              "   where identity.user_id = '" PEP_OWN_USERID "'"
     3.7 -                            "       and (identity.flags & 1) = 0;";
     3.8 +                            "       and (identity.flags & ?1) = 0;";
     3.9          
    3.10          sql_own_keys_retrieve =  
    3.11                              "select fpr from own_keys"
    3.12                              "   natural join identity"
    3.13 -                            "   where (identity.flags & 1) = 0;"; // PEP_idf_not_for_sync
    3.14 +                            "   where (identity.flags & ?1) = 0;";
    3.15  
    3.16          sql_set_own_key = "insert or replace into own_keys (address, user_id, fpr)"
    3.17                            " values (?1, '" PEP_OWN_USERID "', upper(replace(?2,' ','')));";
     4.1 --- a/src/sync_impl.c	Sun Nov 20 21:35:25 2016 +0100
     4.2 +++ b/src/sync_impl.c	Mon Nov 21 22:27:25 2016 +0100
     4.3 @@ -579,7 +579,7 @@
     4.4              }
     4.5              
     4.6              stringlist_t *keylist = NULL;
     4.7 -            status = own_keys_retrieve(session, &keylist);
     4.8 +            status = _own_keys_retrieve(session, &keylist, PEP_idf_not_for_sync);
     4.9              if (status != PEP_STATUS_OK)
    4.10                  goto error;
    4.11  
    4.12 @@ -641,7 +641,7 @@
    4.13          return PEP_ILLEGAL_VALUE;
    4.14  
    4.15      identity_list *own_identities = NULL;
    4.16 -    status = own_identities_retrieve(session, &own_identities);
    4.17 +    status = _own_identities_retrieve(session, &own_identities, PEP_idf_not_for_sync);
    4.18      if (status != PEP_STATUS_OK)
    4.19          return status;
    4.20  
     5.1 --- a/src/sync_send_actions.c	Sun Nov 20 21:35:25 2016 +0100
     5.2 +++ b/src/sync_send_actions.c	Mon Nov 21 22:27:25 2016 +0100
     5.3 @@ -134,7 +134,7 @@
     5.4      if (!msg)
     5.5          goto enomem;
     5.6  
     5.7 -    status = own_identities_retrieve(session, &kl);
     5.8 +    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
     5.9      if (status != PEP_STATUS_OK)
    5.10          goto error;
    5.11      if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
    5.12 @@ -190,7 +190,7 @@
    5.13      if (!msg)
    5.14          goto enomem;
    5.15  
    5.16 -    status = own_identities_retrieve(session, &kl);
    5.17 +    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
    5.18      if (status != PEP_STATUS_OK)
    5.19          goto error;
    5.20      if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupUpdate.ownIdentities) == NULL)
     6.1 --- a/sync/gen_actions_skeleton.ysl2	Sun Nov 20 21:35:25 2016 +0100
     6.2 +++ b/sync/gen_actions_skeleton.ysl2	Mon Nov 21 22:27:25 2016 +0100
     6.3 @@ -169,7 +169,7 @@
     6.4          choose {
     6.5              when "$name='GroupKeys' or $name='GroupUpdate'" {
     6.6                  |
     6.7 -                |> status = own_identities_retrieve(session, &kl);
     6.8 +                |> status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
     6.9                  |> if (status != PEP_STATUS_OK)
    6.10                  |>> goto error;
    6.11                  |> if (IdentityList_from_identity_list(kl, &msg->payload.choice.«$lname».ownIdentities) == NULL)