src/pgp_netpgp.c
branchENGINE-73
changeset 1031 ed718acfd6fe
parent 1030 4354451338cd
child 1033 67e21fb43c77
     1.1 --- a/src/pgp_netpgp.c	Thu Aug 18 13:23:15 2016 +0200
     1.2 +++ b/src/pgp_netpgp.c	Thu Aug 18 14:20:25 2016 +0200
     1.3 @@ -1178,6 +1178,27 @@
     1.4      return PEP_STATUS_OK;
     1.5  }
     1.6  
     1.7 +static PEP_STATUS add_keyinfo_to_stringpair_list(void* arg, pgp_key_t *key) {
     1.8 +    stringpair_list_t** keyinfo_list = (stringpair_list_t**)arg;
     1.9 +    stringpair_t pair = NULL;
    1.10 +    char* id_fpr = NULL;
    1.11 +    char* primary_userid = (char*)pgp_key_get_primary_userid(key);
    1.12 +     
    1.13 +    fpr_to_str(&id_fpr, key->pubkeyfpr.fingerprint,
    1.14 +                key->pubkeyfpr.length);
    1.15 +
    1.16 +    pair = new_stringpair(id_fpr, primary_userid);
    1.17 +    
    1.18 +    if (pair == NULL)
    1.19 +        return PEP_OUT_OF_MEMORY;
    1.20 +    
    1.21 +    *keyinfo_list = stringpair_list_add(*keyinfo_list, pair);
    1.22 +    free(id_fpr);
    1.23 +    if (*keyinfo_list == NULL)
    1.24 +        return PEP_OUT_OF_MEMORY;
    1.25 +    return PEP_STATUS_OK;
    1.26 +}
    1.27 +
    1.28  PEP_STATUS pgp_find_keys(
    1.29      PEP_SESSION session, const char *pattern, stringlist_t **keylist
    1.30      )
    1.31 @@ -1727,37 +1748,11 @@
    1.32      pgp_key_t *key;
    1.33  
    1.34      PEP_STATUS result;
    1.35 -
    1.36 -    result = PEP_KEY_NOT_FOUND;
    1.37      
    1.38 -    // get all available keys
    1.39 -    unsigned n = 0;
    1.40 +    result = find_keys_do(pattern, &add_keyinfo_to_stringpair_list, (void*)keyinfo_list);
    1.41      
    1.42 -    pgp_keyring_t* pubkeys = (pgp_keyring_t *)netpgp.pubring; 
    1.43 -    int keyring_end = pubkeys->keyc;
    1.44 -    
    1.45 -    if (keyring_end < 1)
    1.46 -        return result;
    1.47 -    
    1.48 -    stringpair_list_t* _retval = new_stringpair_list(NULL);
    1.49 -    
    1.50 -    for (key = pubkeys->keys; n < keyring_end; ++n, ++key) {
    1.51 -        assert(key);
    1.52 -        if (!key)
    1.53 -            continue;
    1.54 -        char* primary_userid = (char*)pgp_key_get_primary_userid(key);
    1.55 -//        parse_netpgp_uid_str(primary_userid, &username, &usermail);
    1.56 -     
    1.57 -        char* id_fpr = NULL;
    1.58 -        
    1.59 -        fpr_to_str(&id_fpr, key->pubkeyfpr.fingerprint,
    1.60 -                   key->pubkeyfpr.length);
    1.61 -
    1.62 -        stringlist_add(_retval, new_stringpair(id_fpr, primary_userid));
    1.63 -        free(id_fpr);
    1.64 -        result = PEP_STATUS_OK;
    1.65 -    }
    1.66 -    *id_list = _retval;
    1.67 +    if (!keyinfo_list)
    1.68 +        result = PEP_KEY_NOT_FOUND;
    1.69      
    1.70  unlock_netpgp:
    1.71      pthread_mutex_unlock(&netpgp_mutex);