From 671339904799777fc92085c30d54ea6ebb109062 Mon Sep 17 00:00:00 2001 From: Edouard Tisserant Date: Fri, 2 Dec 2016 01:31:36 +0100 Subject: [PATCH] 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 --- src/pEpmodule.cc | 77 ++++++++++++++++++++++++++++------------------- src/sync_mixin.cc | 13 ++++---- src/sync_mixin.hh | 24 +++++++++++---- test/multipEp.py | 32 ++++++++++++-------- 4 files changed, 90 insertions(+), 56 deletions(-) diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index aaf61de..7bb7daf 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -8,6 +8,7 @@ #include "sync_mixin.hh" #include +#include namespace pEp { namespace PythonAdapter { @@ -59,7 +60,7 @@ BOOST_PYTHON_MODULE(pEp) scope().attr("about") = about(); - auto identity_class = class_("Identity", + auto identity_class = class_("Identity", "Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n" "\n" "represents a p≡p identity\n" @@ -82,41 +83,41 @@ BOOST_PYTHON_MODULE(pEp) .def(boost::python::init()) .def(boost::python::init()) .def(boost::python::init()) - .def("__repr__", &Identity::_repr) - .def("__str__", &Identity::_str, + .def("__repr__", &pEp::PythonAdapter::Identity::_repr) + .def("__str__", &pEp::PythonAdapter::Identity::_str, "string representation of this identity\n" "following the pattern 'username < address >'\n" ) - .add_property("address", (string(Identity::*)()) &Identity::address, - (void(Identity::*)(string)) &Identity::address, + .add_property("address", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::address, + (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::address, "email address or URI") - .add_property("fpr", (string(Identity::*)()) &Identity::fpr, - (void(Identity::*)(string)) &Identity::fpr, + .add_property("fpr", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::fpr, + (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::fpr, "key ID (full fingerprint, hex encoded)") - .add_property("user_id", (string(Identity::*)()) &Identity::user_id, - (void(Identity::*)(string)) &Identity::user_id, + .add_property("user_id", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::user_id, + (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::user_id, "ID of person associated or 'pEp_own_userId' if own identity") - .add_property("username", (string(Identity::*)()) &Identity::username, - (void(Identity::*)(string)) &Identity::username, + .add_property("username", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::username, + (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::username, "name in full of person associated") - .add_property("comm_type", (int(Identity::*)()) - (PEP_comm_type(Identity::*)()) &Identity::comm_type, - (void(Identity::*)(int)) - (void(Identity::*)(PEP_comm_type)) &Identity::comm_type, + .add_property("comm_type", (int(pEp::PythonAdapter::Identity::*)()) + (PEP_comm_type(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::comm_type, + (void(pEp::PythonAdapter::Identity::*)(int)) + (void(pEp::PythonAdapter::Identity::*)(PEP_comm_type)) &pEp::PythonAdapter::Identity::comm_type, "communication type, first rating level (p≡p internal)") - .add_property("lang", (string(Identity::*)()) &Identity::lang, - (void(Identity::*)(string)) &Identity::lang, + .add_property("lang", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::lang, + (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::lang, "ISO 639-1 language code") - .add_property("me", (bool(Identity::*)()) &Identity::me, - (void(Identity::*)(bool)) &Identity::me, + .add_property("me", (bool(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::me, + (void(pEp::PythonAdapter::Identity::*)(bool)) &pEp::PythonAdapter::Identity::me, "true if own identity, false otherwise") - .add_property("flags", (identity_flags_t(Identity::*)()) &Identity::flags, - (void(Identity::*)(identity_flags_t)) &Identity::flags, + .add_property("flags", (identity_flags_t(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::flags, + (void(pEp::PythonAdapter::Identity::*)(identity_flags_t)) &pEp::PythonAdapter::Identity::flags, "flags (p≡p internal)") - .add_property("rating", &Identity::rating, "rating of Identity") - .add_property("color", &Identity::color, "color of Identity") - .def("__deepcopy__", &Identity::deepcopy) - .def("__copy__", &Identity::copy); + .add_property("rating", &pEp::PythonAdapter::Identity::rating, "rating of Identity") + .add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity") + .def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy) + .def("__copy__", &pEp::PythonAdapter::Identity::copy); 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" ) .def(boost::python::init()) - .def(boost::python::init()) + .def(boost::python::init()) .def(boost::python::init()) .def("__str__", &Message::_str, "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, (void(Message::*)(time_t)) &Message::recv, "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, "identity where message is from") .add_property("to", (list(Message::*)()) &Message::to, (void(Message::*)(list)) &Message::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, "identity where message was received by") .add_property("cc", (list(Message::*)()) &Message::cc, @@ -346,13 +347,27 @@ BOOST_PYTHON_MODULE(pEp) // key sync API + enum_("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", "class MySyncHandler(SyncMixIn):\n" " def messageToSend(self, msg):\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" "p≡p Sync MixIn\n" @@ -364,8 +379,8 @@ BOOST_PYTHON_MODULE(pEp) " msg p≡p message to send\n" "\n" "overwrite this method with code actually sending msg") - .def("showHandshake", &SyncMixIn::showHandshake, - "showHandshake(self, me, partner)\n" + .def("notifyHandshake", &SyncMixIn::notifyHandshake, + "notifyHandshake(self, me, partner)\n" "\n" " me own identity\n" " partner identity of communication partner\n" diff --git a/src/sync_mixin.cc b/src/sync_mixin.cc index 967fdbe..b0315b1 100644 --- a/src/sync_mixin.cc +++ b/src/sync_mixin.cc @@ -10,7 +10,7 @@ namespace pEp { SyncMixIn_callback::SyncMixIn_callback(PyObject *self) : _self(self) { PEP_STATUS status = register_sync_callbacks(session, (void *) this, - _messageToSend, _showHandshake, inject_sync_msg, + _messageToSend, _notifyHandshake, inject_sync_msg, retrieve_next_sync_msg); assert(status == PEP_STATUS_OK); } @@ -35,8 +35,8 @@ namespace pEp { return PEP_STATUS_OK; } - PEP_STATUS SyncMixIn::_showHandshake(void *obj, - pEp_identity *me, pEp_identity *partner) + PEP_STATUS SyncMixIn::_notifyHandshake(void *obj, + pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) { if (!obj) return PEP_SEND_FUNCTION_NOT_REGISTERED; @@ -46,7 +46,7 @@ namespace pEp { auto that = dynamic_cast< SyncMixIn_callback * >( static_cast< SyncMixIn * > (obj)); - that->showHandshake(Identity(me), Identity(partner)); + that->notifyHandshake(Identity(me), Identity(partner), signal); return PEP_STATUS_OK; } @@ -128,9 +128,10 @@ namespace pEp { 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) diff --git a/src/sync_mixin.hh b/src/sync_mixin.hh index 73b30b6..6a62e96 100644 --- a/src/sync_mixin.hh +++ b/src/sync_mixin.hh @@ -2,6 +2,7 @@ #include "pEpmodule.hh" #include +#include namespace pEp { namespace PythonAdapter { @@ -14,13 +15,20 @@ namespace pEp { 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"); } - virtual void deliverHandshakeResult(Identity partner, int result); + virtual void deliverHandshakeResult( + pEp::PythonAdapter::Identity partner, int result); #ifndef NDEBUG - virtual void _inject(int event, Identity partner, object extra); + virtual void _inject( + int event, + pEp::PythonAdapter::Identity partner, object extra); #endif virtual void setTimeout(time_t timeout){ throw runtime_error("override this method"); @@ -34,8 +42,8 @@ namespace pEp { protected: static PEP_STATUS _messageToSend(void *obj, message *msg); - static PEP_STATUS _showHandshake(void *obj, - pEp_identity *me, pEp_identity *partner); + static PEP_STATUS _notifyHandshake(void *obj, + pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal); static jmp_buf env; static bool running_timeout; @@ -53,7 +61,11 @@ namespace pEp { ~SyncMixIn_callback(); 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 cancelTimeout(); }; diff --git a/test/multipEp.py b/test/multipEp.py index d4f493e..7c0908c 100644 --- a/test/multipEp.py +++ b/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: _send_message(rcpt.address, msg) - def showHandshake(self, me, partner): - printheader("show HANDSHAKE dialog") - printi("handshake needed between " + repr(me) + " and " + repr(partner)) - tw = pEp.trustwords(me, partner, 'en') - printi(tw) - if tw in handshakes_seen : - handshakes_seen.remove(tw) - handshakes_to_accept.append((tw,partner)) - printi("--> TO ACCEPT (already seen)") - else: - handshakes_pending.append((tw,partner)) - handshakes_seen.append(tw) - printheader() + def notifyHandshake(self, me, partner, signal): + if signal == pEp.sync_handshake_signal.SYNC_HANDSHAKE_SHOW_DIALOG: + printheader("show HANDSHAKE dialog") + printi("handshake needed between " + repr(me) + " and " + repr(partner)) + tw = pEp.trustwords(me, partner, 'en') + printi(tw) + if tw in handshakes_seen : + handshakes_seen.remove(tw) + handshakes_to_accept.append((tw,partner)) + printi("--> TO ACCEPT (already seen)") + else: + handshakes_pending.append((tw,partner)) + handshakes_seen.append(tw) + printheader() + else : + printheader("other notification HANDSHAKE dialog") + printi(signal) + #TODO + printheader() def setTimeout(self, timeout): printi("SET TIMEOUT :", timeout)