Browse Source

adding trustwords

PYADPT-55
Volker Birk 9 years ago
parent
commit
633842ea7b
  1. 39
      src/basic_api.cc
  2. 1
      src/basic_api.hh
  3. 1
      src/pEpmodule.cc

39
src/basic_api.cc

@ -6,6 +6,8 @@ namespace pEp {
namespace PythonAdapter {
void update_identity(Identity& ident)
{
if (ident.address() == "")
throw invalid_argument("address needed");
if (ident.me())
throw runtime_error("update_identity: not for own identities");
if (ident.user_id() == PEP_OWN_USERID)
@ -18,12 +20,49 @@ namespace pEp {
void myself(Identity& ident)
{
if (ident.address() == "")
throw invalid_argument("address needed");
if (ident.username() == "")
throw invalid_argument("username needed");
if (!(ident.user_id() == "" || ident.user_id() == PEP_OWN_USERID))
throw invalid_argument("user_id must be empty or '" PEP_OWN_USERID "'");
ident.me(true);
ident.user_id(PEP_OWN_USERID);
PEP_STATUS status = myself(session, ident);
_throw_status(status);
}
string _trustwords(Identity me, Identity partner, string lang)
{
if (me.fpr() == "" || partner.fpr() == "")
throw invalid_argument("fingerprint needed in Identities");
if (lang == "" && me.lang() == partner.lang())
lang = me.lang();
char *words = NULL;
size_t size = 0;
PEP_STATUS status = trustwords(session, me.fpr().c_str(),
lang.c_str(), &words, &size, 5);
_throw_status(status);
string my_words = words;
free(words);
words = NULL;
size = 0;
status = trustwords(session, partner.fpr().c_str(), lang.c_str(),
&words, &size, 5);
_throw_status(status);
string partner_words = words;
free(words);
if (me.fpr() > partner.fpr())
return partner_words + my_words;
else
return my_words + partner_words;
}
}
}

1
src/basic_api.hh

@ -6,6 +6,7 @@ namespace pEp {
namespace PythonAdapter {
void update_identity(Identity& ident);
void myself(Identity& ident);
string _trustwords(Identity me, Identity partner, string lang);
}
}

1
src/pEpmodule.cc

@ -196,6 +196,7 @@ BOOST_PYTHON_MODULE(pEp)
// message API
def("color", &_color, "calculate color value out of rating");
def("trustwords", &_trustwords, "calculate trustwords for two Identities");
// key sync API

Loading…
Cancel
Save