|
@ -31,15 +31,20 @@ namespace PythonAdapter { |
|
|
using namespace std; |
|
|
using namespace std; |
|
|
using namespace boost::python; |
|
|
using namespace boost::python; |
|
|
|
|
|
|
|
|
scope *_scope = NULL; |
|
|
|
|
|
static const char *version_string = "p≡p Python adapter version 0.3"; |
|
|
static const char *version_string = "p≡p Python adapter version 0.3"; |
|
|
|
|
|
|
|
|
void _init() { |
|
|
void init_before_main_module() { |
|
|
pEpLog("called"); |
|
|
pEpLog("called"); |
|
|
callback_dispatcher.add(_messageToSend, nullptr, nullptr, nullptr); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// hidden init function, wrapped by hello_world.init()
|
|
|
|
|
|
void _init_after_main_module() { |
|
|
|
|
|
pEpLog("called"); |
|
|
|
|
|
callback_dispatcher.add(_messageToSend, notifyHandshake, nullptr, nullptr); |
|
|
Adapter::_messageToSend = CallbackDispatcher::messageToSend; |
|
|
Adapter::_messageToSend = CallbackDispatcher::messageToSend; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void config_passive_mode(bool enable) |
|
|
void config_passive_mode(bool enable) |
|
|
{ |
|
|
{ |
|
|
::config_passive_mode(Adapter::session(), enable); |
|
|
::config_passive_mode(Adapter::session(), enable); |
|
@ -99,37 +104,33 @@ void _throw_status(PEP_STATUS status) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
PEP_STATUS _ensure_passphrase(PEP_SESSION session, const char *fpr) |
|
|
|
|
|
{ |
|
|
|
|
|
return PEP_STATUS_OK; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PEP_STATUS _messageToSend(::message *msg) |
|
|
PEP_STATUS _messageToSend(::message *msg) |
|
|
{ |
|
|
{ |
|
|
if (!_scope) |
|
|
pEpLog("called"); |
|
|
return PEP_SEND_FUNCTION_NOT_REGISTERED; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
object m = _scope->attr("messageToSend"); |
|
|
object modref = import("pEp"); |
|
|
call< void >(m.ptr(), Message(msg)); |
|
|
object funcref = modref.attr("message_to_send"); |
|
|
} |
|
|
call<void>(funcref.ptr(), Message(msg)); |
|
|
catch (exception& e) { } |
|
|
} catch (exception& e) { } |
|
|
|
|
|
|
|
|
return PEP_STATUS_OK; |
|
|
return PEP_STATUS_OK; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void messageToSend(Message msg) { |
|
|
PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) |
|
|
throw runtime_error("implement pEp.messageToSend(msg)"); |
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
|
|
|
return PEP_STATUS_OK; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// void do_sync_protocol()
|
|
|
|
|
|
// {
|
|
|
void start_sync() |
|
|
// ::do_sync_protocol(Adapter::session(), nullptr);
|
|
|
{ |
|
|
// }
|
|
|
CallbackDispatcher::start_sync(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void shutdown_sync() |
|
|
void shutdown_sync() |
|
|
{ |
|
|
{ |
|
|
Adapter::shutdown(); |
|
|
CallbackDispatcher::stop_sync(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void debug_color(int ansi_color) |
|
|
void debug_color(int ansi_color) |
|
@ -142,28 +143,28 @@ void leave_device_group() |
|
|
::leave_device_group(Adapter::session()); |
|
|
::leave_device_group(Adapter::session()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// void script_is_implementing_sync() {
|
|
|
|
|
|
// adapter.script_is_implementing_sync();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
bool is_sync_active() |
|
|
bool is_sync_active() |
|
|
{ |
|
|
{ |
|
|
return Adapter::is_sync_running(); |
|
|
return Adapter::is_sync_running(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void testfunc() { |
|
|
|
|
|
_messageToSend(NULL); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
BOOST_PYTHON_MODULE(native_pEp) |
|
|
BOOST_PYTHON_MODULE(native_pEp) |
|
|
{ |
|
|
{ |
|
|
|
|
|
init_before_main_module(); |
|
|
|
|
|
|
|
|
docstring_options doc_options(true, false, false); |
|
|
// Module init function called by pEp.init()
|
|
|
|
|
|
def("_init_after_main_module", _init_after_main_module); |
|
|
|
|
|
def("testfunc", &testfunc); |
|
|
|
|
|
|
|
|
|
|
|
docstring_options doc_options(true, false, false); |
|
|
boost::locale::generator gen; |
|
|
boost::locale::generator gen; |
|
|
std::locale::global(gen("")); |
|
|
std::locale::global(gen("")); |
|
|
|
|
|
|
|
|
// Module init function called by pEp.init()
|
|
|
// _scope = new scope();
|
|
|
def("_init", _init); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_scope = new scope(); |
|
|
|
|
|
scope().attr("about") = about(); |
|
|
scope().attr("about") = about(); |
|
|
scope().attr("per_user_directory") = per_user_directory(); |
|
|
scope().attr("per_user_directory") = per_user_directory(); |
|
|
scope().attr("per_machine_directory") = per_machine_directory(); |
|
|
scope().attr("per_machine_directory") = per_machine_directory(); |
|
@ -544,14 +545,6 @@ BOOST_PYTHON_MODULE(native_pEp) |
|
|
"\n" |
|
|
"\n" |
|
|
"calculate trustwords for two Identities"); |
|
|
"calculate trustwords for two Identities"); |
|
|
|
|
|
|
|
|
// messageToSend()
|
|
|
|
|
|
|
|
|
|
|
|
def("messageToSend", &messageToSend, |
|
|
|
|
|
"messageToSend(msg)\n" |
|
|
|
|
|
"\n" |
|
|
|
|
|
"override pEp.messageToSend(msg) with your own implementation\n" |
|
|
|
|
|
"this callback is being called when a p≡p management message needs to be sent"); |
|
|
|
|
|
|
|
|
|
|
|
// Sync API
|
|
|
// Sync API
|
|
|
|
|
|
|
|
|
enum_<sync_handshake_signal>("sync_handshake_signal") |
|
|
enum_<sync_handshake_signal>("sync_handshake_signal") |
|
@ -566,40 +559,39 @@ BOOST_PYTHON_MODULE(native_pEp) |
|
|
.value("SYNC_NOTIFY_SOLE" , SYNC_NOTIFY_SOLE) |
|
|
.value("SYNC_NOTIFY_SOLE" , SYNC_NOTIFY_SOLE) |
|
|
.value("SYNC_NOTIFY_IN_GROUP" , SYNC_NOTIFY_IN_GROUP); |
|
|
.value("SYNC_NOTIFY_IN_GROUP" , SYNC_NOTIFY_IN_GROUP); |
|
|
|
|
|
|
|
|
auto user_interface_class = class_<UserInterface, UserInterface_callback, boost::noncopyable>( |
|
|
// auto user_interface_class = class_<UserInterface, UserInterface_callback, boost::noncopyable>(
|
|
|
"UserInterface", |
|
|
// "UserInterface",
|
|
|
"class MyUserInterface(UserInterface):\n" |
|
|
// "class MyUserInterface(UserInterface):\n"
|
|
|
" def notifyHandshake(self, me, partner):\n" |
|
|
// " def notifyHandshake(self, me, partner):\n"
|
|
|
" ...\n" |
|
|
// " ...\n"
|
|
|
"\n" |
|
|
// "\n"
|
|
|
"p≡p User Interface class\n" |
|
|
// "p≡p User Interface class\n"
|
|
|
"To be used as a mixin\n" |
|
|
// "To be used as a mixin\n"
|
|
|
) |
|
|
// )
|
|
|
.def("notifyHandshake", &UserInterface::notifyHandshake, |
|
|
// .def("notifyHandshake", &UserInterface::notifyHandshake,
|
|
|
"notifyHandshake(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"
|
|
|
"\n" |
|
|
|
|
|
"overwrite this method with an implementation of a handshake dialog") |
|
|
|
|
|
.def("deliverHandshakeResult", &UserInterface::deliverHandshakeResult, |
|
|
|
|
|
boost::python::arg("identities")=object(), |
|
|
|
|
|
"deliverHandshakeResult(self, result, identities=None)\n" |
|
|
|
|
|
"\n" |
|
|
|
|
|
" result -1: cancel, 0: accepted, 1: rejected\n" |
|
|
|
|
|
" identities list of identities to share or None for all\n" |
|
|
|
|
|
"\n" |
|
|
|
|
|
"call to deliver the handshake result of the handshake dialog"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Replace with start_sync()
|
|
|
|
|
|
// def("do_sync_protocol", &do_sync_protocol,
|
|
|
|
|
|
// "do_sync_protocol()\n"
|
|
|
|
|
|
// "\n"
|
|
|
// "\n"
|
|
|
// "in case of an explicit sync thread instead of a single threaded\n"
|
|
|
// "overwrite this method with an implementation of a handshake dialog")
|
|
|
// "implementation call this function in your sync thread\n"
|
|
|
// .def("deliverHandshakeResult", &UserInterface::deliverHandshakeResult,
|
|
|
|
|
|
// boost::python::arg("identities")=object(),
|
|
|
|
|
|
// "deliverHandshakeResult(self, result, identities=None)\n"
|
|
|
|
|
|
// "\n"
|
|
|
|
|
|
// " result -1: cancel, 0: accepted, 1: rejected\n"
|
|
|
|
|
|
// " identities list of identities to share or None for all\n"
|
|
|
|
|
|
// "\n"
|
|
|
|
|
|
// "call to deliver the handshake result of the handshake dialog"
|
|
|
// );
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def("start_sync", &start_sync, |
|
|
|
|
|
"start_sync()\n" |
|
|
|
|
|
"\n" |
|
|
|
|
|
"starts the sync thread" |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
def("shutdown_sync", &shutdown_sync, |
|
|
def("shutdown_sync", &shutdown_sync, |
|
|
"shutdown_sync()\n" |
|
|
"shutdown_sync()\n" |
|
|
"\n" |
|
|
"\n" |
|
@ -615,13 +607,6 @@ BOOST_PYTHON_MODULE(native_pEp) |
|
|
"call this for a grouped device, which should leave\n" |
|
|
"call this for a grouped device, which should leave\n" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// def("script_is_implementing_sync", &script_is_implementing_sync,
|
|
|
|
|
|
// "script_is_implementing_sync()\n"
|
|
|
|
|
|
// "\n"
|
|
|
|
|
|
// "call this in case the Python script is implementing sync to make\n"
|
|
|
|
|
|
// "is_sync_active() working\n"
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
def("is_sync_active", &is_sync_active, |
|
|
def("is_sync_active", &is_sync_active, |
|
|
"is_sync_active()\n" |
|
|
"is_sync_active()\n" |
|
|
"\n" |
|
|
"\n" |
|
|