src/keymanagement.c
branchENGINE-140-reloaded
changeset 1394 8659157b681f
parent 1385 5f54184b1e94
child 1406 8d8ae9657388
     1.1 --- a/src/keymanagement.c	Mon Nov 14 14:09:10 2016 +0100
     1.2 +++ b/src/keymanagement.c	Tue Nov 15 15:56:18 2016 +0100
     1.3 @@ -913,9 +913,8 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 -DYNAMIC_API PEP_STATUS keys_retrieve_by_flag(
     1.8 +DYNAMIC_API PEP_STATUS own_keys_retrieve(
     1.9          PEP_SESSION session,
    1.10 -        keypair_flags_t flags,
    1.11          stringlist_t **keylist
    1.12        )
    1.13  {
    1.14 @@ -928,18 +927,17 @@
    1.15      *keylist = NULL;
    1.16      stringlist_t *_keylist = NULL;
    1.17      
    1.18 -    sqlite3_reset(session->keys_retrieve_by_flag);
    1.19 -    sqlite3_bind_int(session->keys_retrieve_by_flag, 1, flags);
    1.20 +    sqlite3_reset(session->own_keys_retrieve);
    1.21      
    1.22      int result;
    1.23      char *fpr = NULL;
    1.24      
    1.25      stringlist_t *_bl = _keylist;
    1.26      do {
    1.27 -        result = sqlite3_step(session->keys_retrieve_by_flag);
    1.28 +        result = sqlite3_step(session->own_keys_retrieve);
    1.29          switch (result) {
    1.30              case SQLITE_ROW:
    1.31 -                fpr = strdup((const char *) sqlite3_column_text(session->keys_retrieve_by_flag, 0));
    1.32 +                fpr = strdup((const char *) sqlite3_column_text(session->own_keys_retrieve, 0));
    1.33                  if(fpr == NULL)
    1.34                      goto enomem;
    1.35  
    1.36 @@ -962,7 +960,7 @@
    1.37          }
    1.38      } while (result != SQLITE_DONE);
    1.39      
    1.40 -    sqlite3_reset(session->keys_retrieve_by_flag);
    1.41 +    sqlite3_reset(session->own_keys_retrieve);
    1.42      if (status == PEP_STATUS_OK)
    1.43          *keylist = _keylist;
    1.44      else
    1.45 @@ -978,6 +976,45 @@
    1.46      return status;
    1.47  }
    1.48  
    1.49 +// TODO: Unused for now, but should be used when sync receive old keys (ENGINE-145)
    1.50 +DYNAMIC_API PEP_STATUS set_own_key(
    1.51 +       PEP_SESSION session,
    1.52 +       const char *address,
    1.53 +       const char *fpr
    1.54 +    )
    1.55 +{
    1.56 +    PEP_STATUS status = PEP_STATUS_OK;
    1.57 +    
    1.58 +    assert(session &&
    1.59 +           address && address[0] &&
    1.60 +           fpr && fpr[0]
    1.61 +          );
    1.62 +    
    1.63 +    if (!(session &&
    1.64 +          address && address[0] &&
    1.65 +          fpr && fpr[0]
    1.66 +         ))
    1.67 +        return PEP_ILLEGAL_VALUE;
    1.68 +    
    1.69 +    sqlite3_reset(session->set_own_key);
    1.70 +    sqlite3_bind_text(session->set_own_key, 1, address, -1, SQLITE_STATIC);
    1.71 +    sqlite3_bind_text(session->set_own_key, 2, fpr, -1, SQLITE_STATIC);
    1.72 +
    1.73 +    int result;
    1.74 +    
    1.75 +    result = sqlite3_step(session->set_own_key);
    1.76 +    switch (result) {
    1.77 +        case SQLITE_DONE:
    1.78 +            status = PEP_STATUS_OK;
    1.79 +            break;
    1.80 +            
    1.81 +        default:
    1.82 +            status = PEP_UNKNOWN_ERROR;
    1.83 +    }
    1.84 +    
    1.85 +    sqlite3_reset(session->set_own_key);
    1.86 +    return status;
    1.87 +}
    1.88  
    1.89  PEP_STATUS contains_priv_key(PEP_SESSION session, const char *fpr,
    1.90                               bool *has_private) {