adding implementation of get_key_rating_for_user() sync
authorVolker Birk <vb@pep-project.org>
Mon, 28 Jan 2019 12:21:06 +0100
branchsync
changeset 324309257addf431
parent 3242 a878c9a02139
child 3247 7019b507538c
adding implementation of get_key_rating_for_user()
src/message_api.c
src/message_api.h
     1.1 --- a/src/message_api.c	Mon Jan 28 11:53:20 2019 +0100
     1.2 +++ b/src/message_api.c	Mon Jan 28 12:21:06 2019 +0100
     1.3 @@ -1101,7 +1101,7 @@
     1.4  }
     1.5  
     1.6  
     1.7 -static PEP_rating _rating(PEP_comm_type ct, PEP_rating rating)
     1.8 +static PEP_rating _rating(PEP_comm_type ct)
     1.9  {
    1.10      if (ct == PEP_ct_unknown)
    1.11          return PEP_rating_undefined;
    1.12 @@ -1115,19 +1115,9 @@
    1.13      else if (ct == PEP_ct_mistrusted)
    1.14          return PEP_rating_mistrust;
    1.15  
    1.16 -    if (rating == PEP_rating_unencrypted_for_some)
    1.17 -        return PEP_rating_unencrypted_for_some;
    1.18 -
    1.19      if (ct == PEP_ct_no_encryption || ct == PEP_ct_no_encrypted_channel ||
    1.20 -            ct == PEP_ct_my_key_not_included) {
    1.21 -        if (rating > PEP_rating_unencrypted_for_some)
    1.22 -            return PEP_rating_unencrypted_for_some;
    1.23 -        else
    1.24 +            ct == PEP_ct_my_key_not_included)
    1.25              return PEP_rating_unencrypted;
    1.26 -    }
    1.27 -
    1.28 -    if (rating == PEP_rating_unencrypted)
    1.29 -        return PEP_rating_unencrypted_for_some;
    1.30  
    1.31      if (ct >= PEP_ct_confirmed_enc_anon)
    1.32          return PEP_rating_trusted_and_anonymized;
    1.33 @@ -1262,7 +1252,7 @@
    1.34      } else {
    1.35          resulting_comm_type = least_comm_type;
    1.36      }
    1.37 -    return _rating(resulting_comm_type, PEP_rating_undefined);
    1.38 +    return _rating(resulting_comm_type);
    1.39  }
    1.40  
    1.41  static PEP_rating worst_rating(PEP_rating rating1, PEP_rating rating2) {
    1.42 @@ -1851,8 +1841,7 @@
    1.43          
    1.44      if (enc_format == PEP_enc_none || !dest_keys_found ||
    1.45          stringlist_length(keys)  == 0 ||
    1.46 -        _rating(max_comm_type,
    1.47 -                PEP_rating_undefined) < PEP_rating_reliable)
    1.48 +        _rating(max_comm_type) < PEP_rating_reliable)
    1.49      {
    1.50          free_stringlist(keys);
    1.51          if ((has_pEp_user || !session->passive_mode) && 
    1.52 @@ -2508,8 +2497,7 @@
    1.53              }
    1.54              if (_sender->comm_type != PEP_ct_unknown) {
    1.55                  *rating = keylist_rating(session, recipients, 
    1.56 -                            fpr, _rating(_sender->comm_type, 
    1.57 -                                          PEP_rating_undefined));
    1.58 +                            fpr, _rating(_sender->comm_type));
    1.59              }
    1.60              
    1.61              free_identity(_sender);
    1.62 @@ -3922,8 +3910,7 @@
    1.63          *rating = PEP_rating_undefined;
    1.64      }
    1.65      else
    1.66 -        *rating = MAX(_rating(max_comm_type, PEP_rating_undefined),
    1.67 -                               PEP_rating_unencrypted);
    1.68 +        *rating = MAX(_rating(max_comm_type), PEP_rating_unencrypted);
    1.69  
    1.70      return PEP_STATUS_OK;
    1.71  }
    1.72 @@ -3958,8 +3945,7 @@
    1.73      _max_comm_type_from_identity_list_preview(msg->bcc, session,
    1.74              &max_comm_type);
    1.75  
    1.76 -    *rating = _MAX(_rating(max_comm_type, PEP_rating_undefined),
    1.77 -            PEP_rating_unencrypted);
    1.78 +    *rating = _MAX(_rating(max_comm_type), PEP_rating_unencrypted);
    1.79  
    1.80      return PEP_STATUS_OK;
    1.81  }
    1.82 @@ -4005,7 +3991,7 @@
    1.83      }
    1.84  
    1.85      if (status == PEP_STATUS_OK)
    1.86 -        *rating = _rating(ident->comm_type, PEP_rating_undefined);
    1.87 +        *rating = _rating(ident->comm_type);
    1.88  
    1.89      return status;
    1.90  }
    1.91 @@ -4727,3 +4713,37 @@
    1.92  
    1.93      return status;
    1.94  }
    1.95 +
    1.96 +DYNAMIC_API PEP_STATUS get_key_rating_for_user(
    1.97 +        PEP_SESSION session,
    1.98 +        char *user_id,
    1.99 +        char *fpr,
   1.100 +        PEP_rating *rating
   1.101 +    )
   1.102 +{
   1.103 +    assert(session && user_id && user_id[0] && fpr && fpr[0] && rating);
   1.104 +    if (!(session && user_id && user_id[0] && fpr && fpr[0] && rating))
   1.105 +        return PEP_ILLEGAL_VALUE;
   1.106 +
   1.107 +    *rating = PEP_rating_undefined;
   1.108 +
   1.109 +    pEp_identity *ident = new_identity(NULL, fpr, user_id, NULL);
   1.110 +    if (!ident)
   1.111 +        return PEP_OUT_OF_MEMORY;
   1.112 +
   1.113 +    PEP_STATUS status = get_trust(session, ident);
   1.114 +    if (status)
   1.115 +        goto the_end;
   1.116 +
   1.117 +    if (!ident->comm_type) {
   1.118 +        status = PEP_RECORD_NOT_FOUND;
   1.119 +        goto the_end;
   1.120 +    }
   1.121 +
   1.122 +    *rating = _rating(ident->comm_type);
   1.123 +
   1.124 +the_end:
   1.125 +    free_identity(ident);
   1.126 +    return status;
   1.127 +}
   1.128 +
     2.1 --- a/src/message_api.h	Mon Jan 28 11:53:20 2019 +0100
     2.2 +++ b/src/message_api.h	Mon Jan 28 12:21:06 2019 +0100
     2.3 @@ -588,7 +588,17 @@
     2.4      PEP_rating *rating
     2.5  );
     2.6  
     2.7 -// TODO: Implement this - and don't even try to use your light saber
     2.8 +// get_key_rating_for_user() - get the rating of a certain key for a certain user
     2.9 +//
    2.10 +//  parameters:
    2.11 +//
    2.12 +//      session (in)            session handle
    2.13 +//      user_id (in)            string with user ID
    2.14 +//      fpr (in)                string with fingerprint
    2.15 +//      rating (out)            rating of key for this user
    2.16 +//
    2.17 +//  returns:
    2.18 +//      PEP_RECORD_NOT_FOUND if no trust record for user_id and fpr can be found
    2.19  
    2.20  DYNAMIC_API PEP_STATUS get_key_rating_for_user(
    2.21          PEP_SESSION session,