Browse Source

ENGINE-133 wrapped new notifyHandshake call and enum, added corresponding code to keep tests passing, still didn't add code testing occurence of additional callbacks in timeout or success cases

PYADPT-55
Edouard Tisserant 9 years ago
parent
commit
6713399047
  1. 77
      src/pEpmodule.cc
  2. 13
      src/sync_mixin.cc
  3. 24
      src/sync_mixin.hh
  4. 32
      test/multipEp.py

77
src/pEpmodule.cc

@ -8,6 +8,7 @@
#include "sync_mixin.hh" #include "sync_mixin.hh"
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/sync.h>
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
@ -59,7 +60,7 @@ BOOST_PYTHON_MODULE(pEp)
scope().attr("about") = about(); scope().attr("about") = about();
auto identity_class = class_<Identity>("Identity", auto identity_class = class_<pEp::PythonAdapter::Identity>("Identity",
"Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n" "Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n"
"\n" "\n"
"represents a p≡p identity\n" "represents a p≡p identity\n"
@ -82,41 +83,41 @@ BOOST_PYTHON_MODULE(pEp)
.def(boost::python::init<string, string, string, string>()) .def(boost::python::init<string, string, string, string>())
.def(boost::python::init<string, string, string, string, int>()) .def(boost::python::init<string, string, string, string, int>())
.def(boost::python::init<string, string, string, string, int, string>()) .def(boost::python::init<string, string, string, string, int, string>())
.def("__repr__", &Identity::_repr) .def("__repr__", &pEp::PythonAdapter::Identity::_repr)
.def("__str__", &Identity::_str, .def("__str__", &pEp::PythonAdapter::Identity::_str,
"string representation of this identity\n" "string representation of this identity\n"
"following the pattern 'username < address >'\n" "following the pattern 'username < address >'\n"
) )
.add_property("address", (string(Identity::*)()) &Identity::address, .add_property("address", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::address,
(void(Identity::*)(string)) &Identity::address, (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::address,
"email address or URI") "email address or URI")
.add_property("fpr", (string(Identity::*)()) &Identity::fpr, .add_property("fpr", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::fpr,
(void(Identity::*)(string)) &Identity::fpr, (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::fpr,
"key ID (full fingerprint, hex encoded)") "key ID (full fingerprint, hex encoded)")
.add_property("user_id", (string(Identity::*)()) &Identity::user_id, .add_property("user_id", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::user_id,
(void(Identity::*)(string)) &Identity::user_id, (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::user_id,
"ID of person associated or 'pEp_own_userId' if own identity") "ID of person associated or 'pEp_own_userId' if own identity")
.add_property("username", (string(Identity::*)()) &Identity::username, .add_property("username", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::username,
(void(Identity::*)(string)) &Identity::username, (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::username,
"name in full of person associated") "name in full of person associated")
.add_property("comm_type", (int(Identity::*)()) .add_property("comm_type", (int(pEp::PythonAdapter::Identity::*)())
(PEP_comm_type(Identity::*)()) &Identity::comm_type, (PEP_comm_type(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::comm_type,
(void(Identity::*)(int)) (void(pEp::PythonAdapter::Identity::*)(int))
(void(Identity::*)(PEP_comm_type)) &Identity::comm_type, (void(pEp::PythonAdapter::Identity::*)(PEP_comm_type)) &pEp::PythonAdapter::Identity::comm_type,
"communication type, first rating level (p≡p internal)") "communication type, first rating level (p≡p internal)")
.add_property("lang", (string(Identity::*)()) &Identity::lang, .add_property("lang", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::lang,
(void(Identity::*)(string)) &Identity::lang, (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::lang,
"ISO 639-1 language code") "ISO 639-1 language code")
.add_property("me", (bool(Identity::*)()) &Identity::me, .add_property("me", (bool(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::me,
(void(Identity::*)(bool)) &Identity::me, (void(pEp::PythonAdapter::Identity::*)(bool)) &pEp::PythonAdapter::Identity::me,
"true if own identity, false otherwise") "true if own identity, false otherwise")
.add_property("flags", (identity_flags_t(Identity::*)()) &Identity::flags, .add_property("flags", (identity_flags_t(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::flags,
(void(Identity::*)(identity_flags_t)) &Identity::flags, (void(pEp::PythonAdapter::Identity::*)(identity_flags_t)) &pEp::PythonAdapter::Identity::flags,
"flags (p≡p internal)") "flags (p≡p internal)")
.add_property("rating", &Identity::rating, "rating of Identity") .add_property("rating", &pEp::PythonAdapter::Identity::rating, "rating of Identity")
.add_property("color", &Identity::color, "color of Identity") .add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity")
.def("__deepcopy__", &Identity::deepcopy) .def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy)
.def("__copy__", &Identity::copy); .def("__copy__", &pEp::PythonAdapter::Identity::copy);
identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId"; identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId";
@ -166,7 +167,7 @@ BOOST_PYTHON_MODULE(pEp)
" mime_text text in Multipurpose Internet Mail Extensions format\n" " mime_text text in Multipurpose Internet Mail Extensions format\n"
) )
.def(boost::python::init<int>()) .def(boost::python::init<int>())
.def(boost::python::init<int, Identity *>()) .def(boost::python::init<int, pEp::PythonAdapter::Identity *>())
.def(boost::python::init<string>()) .def(boost::python::init<string>())
.def("__str__", &Message::_str, .def("__str__", &Message::_str,
"the string representation of a Message is it's MIME text" "the string representation of a Message is it's MIME text"
@ -198,13 +199,13 @@ BOOST_PYTHON_MODULE(pEp)
.add_property("recv", (time_t(Message::*)()) &Message::recv, .add_property("recv", (time_t(Message::*)()) &Message::recv,
(void(Message::*)(time_t)) &Message::recv, (void(Message::*)(time_t)) &Message::recv,
"time when message was received in UTC seconds since epoch") "time when message was received in UTC seconds since epoch")
.add_property("from_", (Identity(Message::*)()) &Message::from, .add_property("from_", (pEp::PythonAdapter::Identity(Message::*)()) &Message::from,
(void(Message::*)(object)) &Message::from, (void(Message::*)(object)) &Message::from,
"identity where message is from") "identity where message is from")
.add_property("to", (list(Message::*)()) &Message::to, .add_property("to", (list(Message::*)()) &Message::to,
(void(Message::*)(list)) &Message::to, (void(Message::*)(list)) &Message::to,
"list of identities message is going to") "list of identities message is going to")
.add_property("recv_by", (Identity(Message::*)()) &Message::recv_by, .add_property("recv_by", (pEp::PythonAdapter::Identity(Message::*)()) &Message::recv_by,
(void(Message::*)(object)) &Message::recv_by, (void(Message::*)(object)) &Message::recv_by,
"identity where message was received by") "identity where message was received by")
.add_property("cc", (list(Message::*)()) &Message::cc, .add_property("cc", (list(Message::*)()) &Message::cc,
@ -346,13 +347,27 @@ BOOST_PYTHON_MODULE(pEp)
// key sync API // key sync API
enum_<sync_handshake_signal>("sync_handshake_signal")
.value("SYNC_HANDSHAKE_DISMISS_DIALOG",SYNC_HANDSHAKE_DISMISS_DIALOG)
.value("SYNC_HANDSHAKE_SHOW_DIALOG" ,SYNC_HANDSHAKE_SHOW_DIALOG)
.value("SYNC_HANDSHAKE_SUCCESS" ,SYNC_HANDSHAKE_SUCCESS)
.value("SYNC_HANDSHAKE_FAILURE" ,SYNC_HANDSHAKE_FAILURE)
.value("SYNC_DEVICE_ADDED" ,SYNC_DEVICE_ADDED)
.value("SYNC_GROUP_CREATED" ,SYNC_GROUP_CREATED);
auto sync_mixin_class = class_<SyncMixIn, SyncMixIn_callback, boost::noncopyable>( auto sync_mixin_class = class_<SyncMixIn, SyncMixIn_callback, boost::noncopyable>(
"SyncMixIn", "SyncMixIn",
"class MySyncHandler(SyncMixIn):\n" "class MySyncHandler(SyncMixIn):\n"
" def messageToSend(self, msg):\n" " def messageToSend(self, msg):\n"
" ...\n" " ...\n"
"\n" "\n"
" def showHandshake(self, me, partner):\n" " def notifyHandshake(self, me, partner):\n"
" ...\n"
"\n"
" def setTimeout(self, timeout):\n"
" ...\n"
"\n"
" def cancelTimeout(self):\n"
" ...\n" " ...\n"
"\n" "\n"
"p≡p Sync MixIn\n" "p≡p Sync MixIn\n"
@ -364,8 +379,8 @@ BOOST_PYTHON_MODULE(pEp)
" msg p≡p message to send\n" " msg p≡p message to send\n"
"\n" "\n"
"overwrite this method with code actually sending msg") "overwrite this method with code actually sending msg")
.def("showHandshake", &SyncMixIn::showHandshake, .def("notifyHandshake", &SyncMixIn::notifyHandshake,
"showHandshake(self, me, partner)\n" "notifyHandshake(self, me, partner)\n"
"\n" "\n"
" me own identity\n" " me own identity\n"
" partner identity of communication partner\n" " partner identity of communication partner\n"

13
src/sync_mixin.cc

@ -10,7 +10,7 @@ namespace pEp {
SyncMixIn_callback::SyncMixIn_callback(PyObject *self) : _self(self) SyncMixIn_callback::SyncMixIn_callback(PyObject *self) : _self(self)
{ {
PEP_STATUS status = register_sync_callbacks(session, (void *) this, PEP_STATUS status = register_sync_callbacks(session, (void *) this,
_messageToSend, _showHandshake, inject_sync_msg, _messageToSend, _notifyHandshake, inject_sync_msg,
retrieve_next_sync_msg); retrieve_next_sync_msg);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
} }
@ -35,8 +35,8 @@ namespace pEp {
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
PEP_STATUS SyncMixIn::_showHandshake(void *obj, PEP_STATUS SyncMixIn::_notifyHandshake(void *obj,
pEp_identity *me, pEp_identity *partner) pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
{ {
if (!obj) if (!obj)
return PEP_SEND_FUNCTION_NOT_REGISTERED; return PEP_SEND_FUNCTION_NOT_REGISTERED;
@ -46,7 +46,7 @@ namespace pEp {
auto that = dynamic_cast< SyncMixIn_callback * >( auto that = dynamic_cast< SyncMixIn_callback * >(
static_cast< SyncMixIn * > (obj)); static_cast< SyncMixIn * > (obj));
that->showHandshake(Identity(me), Identity(partner)); that->notifyHandshake(Identity(me), Identity(partner), signal);
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
@ -128,9 +128,10 @@ namespace pEp {
call_method< void >(_self, "messageToSend", msg); call_method< void >(_self, "messageToSend", msg);
} }
void SyncMixIn_callback::showHandshake(Identity me, Identity partner) void SyncMixIn_callback::notifyHandshake(
Identity me, Identity partner, sync_handshake_signal signal)
{ {
call_method< void >(_self, "showHandshake", me, partner); call_method< void >(_self, "notifyHandshake", me, partner, signal);
} }
void SyncMixIn_callback::setTimeout(time_t timeout) void SyncMixIn_callback::setTimeout(time_t timeout)

24
src/sync_mixin.hh

@ -2,6 +2,7 @@
#include "pEpmodule.hh" #include "pEpmodule.hh"
#include <setjmp.h> #include <setjmp.h>
#include <pEp/sync.h>
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
@ -14,13 +15,20 @@ namespace pEp {
throw runtime_error("override this method"); throw runtime_error("override this method");
} }
virtual void showHandshake(Identity me, Identity partner) { virtual void notifyHandshake(
pEp::PythonAdapter::Identity me,
pEp::PythonAdapter::Identity partner,
sync_handshake_signal signal)
{
throw runtime_error("override this method"); throw runtime_error("override this method");
} }
virtual void deliverHandshakeResult(Identity partner, int result); virtual void deliverHandshakeResult(
pEp::PythonAdapter::Identity partner, int result);
#ifndef NDEBUG #ifndef NDEBUG
virtual void _inject(int event, Identity partner, object extra); virtual void _inject(
int event,
pEp::PythonAdapter::Identity partner, object extra);
#endif #endif
virtual void setTimeout(time_t timeout){ virtual void setTimeout(time_t timeout){
throw runtime_error("override this method"); throw runtime_error("override this method");
@ -34,8 +42,8 @@ namespace pEp {
protected: protected:
static PEP_STATUS _messageToSend(void *obj, message *msg); static PEP_STATUS _messageToSend(void *obj, message *msg);
static PEP_STATUS _showHandshake(void *obj, static PEP_STATUS _notifyHandshake(void *obj,
pEp_identity *me, pEp_identity *partner); pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal);
static jmp_buf env; static jmp_buf env;
static bool running_timeout; static bool running_timeout;
@ -53,7 +61,11 @@ namespace pEp {
~SyncMixIn_callback(); ~SyncMixIn_callback();
void messageToSend(Message msg); void messageToSend(Message msg);
void showHandshake(Identity me, Identity partner); void notifyHandshake(
pEp::PythonAdapter::Identity me,
pEp::PythonAdapter::Identity partner,
sync_handshake_signal signal);
void setTimeout(time_t timeout); void setTimeout(time_t timeout);
void cancelTimeout(); void cancelTimeout();
}; };

32
test/multipEp.py

@ -259,19 +259,25 @@ def pEp_instance_run(iname, _own_addresses, conn, _msgs_folders, _handshakes_see
for rcpt in msg.to + msg.cc + msg.bcc: for rcpt in msg.to + msg.cc + msg.bcc:
_send_message(rcpt.address, msg) _send_message(rcpt.address, msg)
def showHandshake(self, me, partner): def notifyHandshake(self, me, partner, signal):
printheader("show HANDSHAKE dialog") if signal == pEp.sync_handshake_signal.SYNC_HANDSHAKE_SHOW_DIALOG:
printi("handshake needed between " + repr(me) + " and " + repr(partner)) printheader("show HANDSHAKE dialog")
tw = pEp.trustwords(me, partner, 'en') printi("handshake needed between " + repr(me) + " and " + repr(partner))
printi(tw) tw = pEp.trustwords(me, partner, 'en')
if tw in handshakes_seen : printi(tw)
handshakes_seen.remove(tw) if tw in handshakes_seen :
handshakes_to_accept.append((tw,partner)) handshakes_seen.remove(tw)
printi("--> TO ACCEPT (already seen)") handshakes_to_accept.append((tw,partner))
else: printi("--> TO ACCEPT (already seen)")
handshakes_pending.append((tw,partner)) else:
handshakes_seen.append(tw) handshakes_pending.append((tw,partner))
printheader() handshakes_seen.append(tw)
printheader()
else :
printheader("other notification HANDSHAKE dialog")
printi(signal)
#TODO
printheader()
def setTimeout(self, timeout): def setTimeout(self, timeout):
printi("SET TIMEOUT :", timeout) printi("SET TIMEOUT :", timeout)

Loading…
Cancel
Save