Browse Source

remove usage of local adapter.hh/locked_queue.hh / use session() from libpEpAdapter

PYADPT-81
heck 5 years ago
parent
commit
7ee3d324ee
  1. 16
      setup.py
  2. 40
      src/adapter.cc
  3. 2
      src/adapter.hh
  4. 27
      src/basic_api.cc
  5. 27
      src/identity.cc
  6. 7
      src/identity.hh
  7. 18
      src/message.cc
  8. 4
      src/message.hh
  9. 9
      src/message_api.cc
  10. 129
      src/pEpmodule.cc
  11. 10
      src/pEpmodule.hh
  12. 3
      src/str_attr.cc
  13. 1
      src/str_attr.hh
  14. 59
      src/user_interface.cc
  15. 7
      src/user_interface.hh

16
setup.py

@ -90,6 +90,7 @@ class BuildExtCommand(build_ext):
] ]
libs = [ libs = [
'pEpEngine', 'pEpEngine',
'pEpAdapter',
'boost_python37-mt', 'boost_python37-mt',
'boost_locale-mt' 'boost_locale-mt'
] ]
@ -111,6 +112,7 @@ class BuildExtCommand(build_ext):
] ]
libs = [ libs = [
'pEpEngine', 'pEpEngine',
'pEpAdapter',
'boost_python37-mt', 'boost_python37-mt',
'boost_locale-mt' 'boost_locale-mt'
] ]
@ -129,6 +131,7 @@ class BuildExtCommand(build_ext):
] ]
libs = [ libs = [
'pEpEngine', 'pEpEngine',
'pEpAdapter',
'boost_python3', 'boost_python3',
'boost_locale' 'boost_locale'
] ]
@ -185,7 +188,7 @@ class BuildExtCommand(build_ext):
libdirs += sys_libdirs libdirs += sys_libdirs
# Compile flags # Compile flags
compile_flags = ['-std=c++14'] compile_flags = ['-std=c++14', '-fpermissive']
if self.debug: if self.debug:
pEpLog("debug mode") pEpLog("debug mode")
compile_flags += ['-O0', '-g', '-UNDEBUG'] compile_flags += ['-O0', '-g', '-UNDEBUG']
@ -218,7 +221,16 @@ if sys.version_info[0] < 3:
module_pEp = Extension( module_pEp = Extension(
'pEp', 'pEp',
sources = glob('src/*.cc'), sources = [
'src/pEpmodule.cc',
'src/basic_api.cc',
'src/identity.cc',
'src/message.cc',
'src/message_api.cc',
'src/str_attr.cc',
# 'src/user_interface.cc',
# 'src/adapter.cc'
],
) )
# "MAIN" Function # "MAIN" Function

40
src/adapter.cc

@ -3,6 +3,7 @@
#include "user_interface.hh" #include "user_interface.hh"
#include <assert.h> #include <assert.h>
#include "adapter.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
@ -42,7 +43,8 @@ namespace pEp {
case init: case init:
++booked; ++booked;
if (!_session) if (!_session)
status = ::init(&_session, _messageToSend, _inject_sync_event); status = ::init(&_session, _messageToSend, _inject_sync_event, _ensure_passphrase);
// status = ::init(&_session, _messageToSend, _inject_sync_event);
break; break;
default: default:
@ -74,24 +76,24 @@ namespace pEp {
return obj; return obj;
} }
int Adapter::_inject_sync_event(SYNC_EVENT ev, void *management) // int Adapter::_inject_sync_event(SYNC_EVENT ev, void *management)
{ // {
if (!flag_sync_enabled) // if (!flag_sync_enabled)
return 1; // return 1;
//
if (is_sync_thread(adapter.session())) { // if (is_sync_thread(adapter.session())) {
PEP_STATUS status = do_sync_protocol_step(adapter.session(), adapter.ui_object(), ev); // PEP_STATUS status = do_sync_protocol_step(adapter.session(), adapter.ui_object(), ev);
return status == PEP_STATUS_OK ? 0 : 1; // return status == PEP_STATUS_OK ? 0 : 1;
} // }
//
try { // try {
queue().push_back(ev); // queue().push_back(ev);
} // }
catch (exception&) { // catch (exception&) {
return 1; // return 1;
} // }
return 0; // return 0;
} // }
} }
} }

2
src/adapter.hh

@ -4,7 +4,7 @@
#pragma once #pragma once
#include "pEpmodule.hh" #include "pEpmodule.hh"
#include "locked_queue.hh" #include "pEp/locked_queue.hh"
#include "user_interface.hh" #include "user_interface.hh"
#include <pEp/sync_api.h> #include <pEp/sync_api.h>

27
src/basic_api.cc

@ -1,10 +1,13 @@
// This file is under GNU Affero General Public License 3.0 // This file is under GNU Affero General Public License 3.0
// see LICENSE.txt // see LICENSE.txt
#include "basic_api.hh"
#include <sstream> #include <sstream>
#include <pEp/keymanagement.h> #include <pEp/keymanagement.h>
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/Adapter.hh>
#include "basic_api.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
@ -16,7 +19,7 @@ namespace pEp {
throw runtime_error("update_identity: '" PEP_OWN_USERID throw runtime_error("update_identity: '" PEP_OWN_USERID
"' may only be used for own identities"); "' may only be used for own identities");
PEP_STATUS status = update_identity(adapter.session(), ident); PEP_STATUS status = update_identity(pEp::Adapter::session(), ident);
_throw_status(status); _throw_status(status);
} }
@ -30,7 +33,7 @@ namespace pEp {
if (ident.user_id() == "") if (ident.user_id() == "")
ident.user_id(ident.address()); ident.user_id(ident.address());
PEP_STATUS status = myself(adapter.session(), ident); PEP_STATUS status = myself(pEp::Adapter::session(), ident);
_throw_status(status); _throw_status(status);
} }
@ -44,7 +47,7 @@ namespace pEp {
char *words = NULL; char *words = NULL;
size_t size = 0; size_t size = 0;
PEP_STATUS status = get_trustwords(adapter.session(), me, partner, PEP_STATUS status = get_trustwords(pEp::Adapter::session(), me, partner,
lang.c_str(),&words, &size, full); lang.c_str(),&words, &size, full);
_throw_status(status); _throw_status(status);
return words; return words;
@ -57,7 +60,7 @@ namespace pEp {
if (ident.user_id() == "") if (ident.user_id() == "")
throw invalid_argument("user_id must be provided"); throw invalid_argument("user_id must be provided");
PEP_STATUS status = trust_personal_key(adapter.session(), ident); PEP_STATUS status = trust_personal_key(pEp::Adapter::session(), ident);
_throw_status(status); _throw_status(status);
} }
@ -68,7 +71,7 @@ namespace pEp {
if (ident.user_id() == "") if (ident.user_id() == "")
throw invalid_argument("user_id needed"); throw invalid_argument("user_id needed");
PEP_STATUS status = set_identity_flags(adapter.session(), ident, flags); PEP_STATUS status = set_identity_flags(pEp::Adapter::session(), ident, flags);
_throw_status(status); _throw_status(status);
} }
@ -79,7 +82,7 @@ namespace pEp {
if (ident.user_id() == "") if (ident.user_id() == "")
throw invalid_argument("user_id needed"); throw invalid_argument("user_id needed");
PEP_STATUS status = unset_identity_flags(adapter.session(), ident, flags); PEP_STATUS status = unset_identity_flags(pEp::Adapter::session(), ident, flags);
_throw_status(status); _throw_status(status);
} }
@ -92,7 +95,7 @@ namespace pEp {
if (ident.user_id() == "") if (ident.user_id() == "")
throw invalid_argument("user_id needed"); throw invalid_argument("user_id needed");
PEP_STATUS status = key_reset_trust(adapter.session(), ident); PEP_STATUS status = key_reset_trust(pEp::Adapter::session(), ident);
_throw_status(status); _throw_status(status);
} }
@ -101,7 +104,7 @@ namespace pEp {
boost::python::list import_key(string key_data) boost::python::list import_key(string key_data)
{ {
::identity_list *private_keys = NULL; ::identity_list *private_keys = NULL;
PEP_STATUS status = ::import_key(adapter.session(), key_data.c_str(), key_data.size(), &private_keys); PEP_STATUS status = ::import_key(pEp::Adapter::session(), key_data.c_str(), key_data.size(), &private_keys);
if (status && status != PEP_KEY_IMPORTED) if (status && status != PEP_KEY_IMPORTED)
_throw_status(status); _throw_status(status);
@ -124,7 +127,7 @@ namespace pEp {
PEP_STATUS status = PEP_STATUS_OK; PEP_STATUS status = PEP_STATUS_OK;
char* key_data = NULL; char* key_data = NULL;
size_t size; size_t size;
status = ::export_key(adapter.session(), ident.fpr().c_str(), &key_data, &size); status = ::export_key(pEp::Adapter::session(), ident.fpr().c_str(), &key_data, &size);
_throw_status(status); _throw_status(status);
return key_data; return key_data;
@ -135,7 +138,7 @@ namespace pEp {
PEP_STATUS status = PEP_STATUS_OK; PEP_STATUS status = PEP_STATUS_OK;
char* key_data = NULL; char* key_data = NULL;
size_t size; size_t size;
status = ::export_secret_key(adapter.session(), ident.fpr().c_str(), &key_data, &size); status = ::export_secret_key(pEp::Adapter::session(), ident.fpr().c_str(), &key_data, &size);
_throw_status(status); _throw_status(status);
return key_data; return key_data;
@ -154,7 +157,7 @@ namespace pEp {
const char* fpr_c = fpr.c_str(); const char* fpr_c = fpr.c_str();
PEP_STATUS status = set_own_key(adapter.session(), ident, fpr_c); PEP_STATUS status = set_own_key(pEp::Adapter::session(), ident, fpr_c);
_throw_status(status); _throw_status(status);
} }
} }

27
src/identity.cc

@ -1,16 +1,17 @@
// This file is under GNU Affero General Public License 3.0 // This file is under GNU Affero General Public License 3.0
// see LICENSE.txt // see LICENSE.txt
#include "identity.hh"
#include "pEpmodule.hh"
#include "basic_api.hh"
#include "message_api.hh"
#include <typeinfo> #include <typeinfo>
#include <sstream> #include <sstream>
#include <pEp/identity_list.h> #include <pEp/identity_list.h>
#include <pEp/keymanagement.h> #include <pEp/keymanagement.h>
#include <pEp/key_reset.h> #include <pEp/key_reset.h>
#include <pEp/message_api.h>
#include "identity.hh"
#include "pEpmodule.hh"
#include "basic_api.hh"
#include "message_api.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
@ -118,7 +119,7 @@ namespace pEp {
throw invalid_argument("address must be given"); throw invalid_argument("address must be given");
PEP_rating rating = PEP_rating_undefined; PEP_rating rating = PEP_rating_undefined;
PEP_STATUS status = ::identity_rating(adapter.session(), _ident.get(), &rating); PEP_STATUS status = ::identity_rating(pEp::Adapter::session(), _ident.get(), &rating);
_throw_status(status); _throw_status(status);
return (int) rating; return (int) rating;
@ -150,34 +151,34 @@ namespace pEp {
void Identity::key_reset(string fpr) void Identity::key_reset(string fpr)
{ {
PEP_STATUS status = ::key_reset_identity(adapter.session(), *this, PEP_STATUS status = ::key_reset_identity(pEp::Adapter::session(), *this,
fpr != "" ? fpr.c_str() : nullptr); fpr != "" ? fpr.c_str() : nullptr);
_throw_status(status); _throw_status(status);
} }
void Identity::key_mistrusted() void Identity::key_mistrusted()
{ {
PEP_STATUS status = ::key_mistrusted(adapter.session(), *this); PEP_STATUS status = ::key_mistrusted(pEp::Adapter::session(), *this);
_throw_status(status); _throw_status(status);
} }
bool Identity::is_pEp_user() bool Identity::is_pEp_user()
{ {
bool result; bool result;
PEP_STATUS status = ::is_pEp_user(adapter.session(), *this, &result); PEP_STATUS status = ::is_pEp_user(pEp::Adapter::session(), *this, &result);
_throw_status(status); _throw_status(status);
return result; return result;
} }
void Identity::enable_for_sync() void Identity::enable_for_sync()
{ {
PEP_STATUS status = ::enable_identity_for_sync(adapter.session(), *this); PEP_STATUS status = ::enable_identity_for_sync(pEp::Adapter::session(), *this);
_throw_status(status); _throw_status(status);
} }
void Identity::disable_for_sync() void Identity::disable_for_sync()
{ {
PEP_STATUS status = ::disable_identity_for_sync(adapter.session(), *this); PEP_STATUS status = ::disable_identity_for_sync(pEp::Adapter::session(), *this);
_throw_status(status); _throw_status(status);
} }
@ -220,7 +221,7 @@ namespace pEp {
pEp_identity *_dup = ::identity_dup(_ident); pEp_identity *_dup = ::identity_dup(_ident);
if (!_dup) if (!_dup)
throw bad_alloc(); throw bad_alloc();
PEP_STATUS status = update_identity(adapter.session(), _dup); PEP_STATUS status = update_identity(pEp::Adapter::session(), _dup);
_throw_status(status); _throw_status(status);
free_identity(ident); free_identity(ident);
ident = _dup; ident = _dup;
@ -258,7 +259,7 @@ namespace pEp {
free_identity_list(_il); free_identity_list(_il);
throw bad_alloc(); throw bad_alloc();
} }
PEP_STATUS status = update_identity(adapter.session(), _dup); PEP_STATUS status = update_identity(pEp::Adapter::session(), _dup);
if (status != PEP_STATUS_OK) { if (status != PEP_STATUS_OK) {
free_identity_list(_il); free_identity_list(_il);
_throw_status(status); _throw_status(status);

7
src/identity.hh

@ -4,11 +4,14 @@
#pragma once #pragma once
#include <boost/python.hpp> #include <boost/python.hpp>
#include <pEp/pEpEngine.h>
#include <pEp/message_api.h>
#include <string> #include <string>
#include <memory> #include <memory>
#include <cstddef> #include <cstddef>
#include <pEp/pEpEngine.h>
#include <pEp/message_api.h>
#include "pEp/Adapter.hh"
#include "str_attr.hh" #include "str_attr.hh"
namespace pEp { namespace pEp {

18
src/message.cc

@ -2,17 +2,19 @@
// see LICENSE.txt // see LICENSE.txt
#include <Python.h> #include <Python.h>
#include "message.hh" #include <cstdlib>
#include "message_api.hh" #include <cstring>
#include <stdlib.h>
#include <string.h>
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <pEp/mime.h> #include <pEp/mime.h>
#include <pEp/keymanagement.h> #include <pEp/keymanagement.h>
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include "message.hh"
#include "message_api.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
@ -326,11 +328,11 @@ namespace pEp {
if (len(to()) + len(cc()) == 0) if (len(to()) + len(cc()) == 0)
throw invalid_argument("either to or cc needed"); throw invalid_argument("either to or cc needed");
PEP_STATUS status = myself(adapter.session(), _msg->from); PEP_STATUS status = myself(pEp::Adapter::session(), _msg->from);
_throw_status(status); _throw_status(status);
PEP_rating rating = PEP_rating_undefined; PEP_rating rating = PEP_rating_undefined;
status = outgoing_message_rating(adapter.session(), *this, &rating); status = outgoing_message_rating(pEp::Adapter::session(), *this, &rating);
_throw_status(status); _throw_status(status);
return rating; return rating;
@ -359,7 +361,7 @@ namespace pEp {
if (me.address().empty() || me.user_id().empty()) if (me.address().empty() || me.user_id().empty())
throw runtime_error("at least address and user_id of own user needed"); throw runtime_error("at least address and user_id of own user needed");
::myself(adapter.session(), me); ::myself(pEp::Adapter::session(), me);
auto m = Message(PEP_dir_outgoing, &me); auto m = Message(PEP_dir_outgoing, &me);
return m; return m;
} }
@ -368,7 +370,7 @@ namespace pEp {
{ {
if (ident.address().empty()) if (ident.address().empty())
throw runtime_error("at least address needed"); throw runtime_error("at least address needed");
update_identity(adapter.session(), ident); update_identity(pEp::Adapter::session(), ident);
return object(ident); return object(ident);
} }

4
src/message.hh

@ -5,9 +5,11 @@
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <string>
#include <pEp/message.h> #include <pEp/message.h>
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <string>
#include "str_attr.hh" #include "str_attr.hh"
#include "identity.hh" #include "identity.hh"

9
src/message_api.cc

@ -1,14 +1,15 @@
// This file is under GNU Affero General Public License 3.0 // This file is under GNU Affero General Public License 3.0
// see LICENSE.txt // see LICENSE.txt
#include "message_api.hh"
#include "basic_api.hh"
#include <pEp/pEpEngine.h> #include <pEp/pEpEngine.h>
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
#include <pEp/sync_codec.h> #include <pEp/sync_codec.h>
#include <pEp/distribution_codec.h> #include <pEp/distribution_codec.h>
#include "message_api.hh"
#include "basic_api.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
Message encrypt_message(Message src, boost::python::list extra, int enc_format, Message encrypt_message(Message src, boost::python::list extra, int enc_format,
@ -29,7 +30,7 @@ namespace pEp {
message *_dst = NULL; message *_dst = NULL;
message *_src = src; message *_src = src;
PEP_STATUS status = encrypt_message(adapter.session(), _src, _extra, &_dst, PEP_STATUS status = encrypt_message(pEp::Adapter::session(), _src, _extra, &_dst,
_enc_format, _flags); _enc_format, _flags);
free_stringlist(_extra); free_stringlist(_extra);
_throw_status(status); _throw_status(status);
@ -48,7 +49,7 @@ namespace pEp {
PEP_decrypt_flags_t _flags = (PEP_decrypt_flags_t) flags; PEP_decrypt_flags_t _flags = (PEP_decrypt_flags_t) flags;
message *_src = src; message *_src = src;
PEP_STATUS status = ::decrypt_message(adapter.session(), _src, &_dst, &_keylist, PEP_STATUS status = ::decrypt_message(pEp::Adapter::session(), _src, &_dst, &_keylist,
&_rating, &_flags); &_rating, &_flags);
_throw_status(status); _throw_status(status);

129
src/pEpmodule.cc

@ -1,37 +1,39 @@
// This file is under GNU Affero General Public License 3.0 // This file is under GNU Affero General Public License 3.0
// see LICENSE.txt // see LICENSE.txt
#include "pEpmodule.hh" #include <boost/python.hpp>
#include <boost/locale.hpp> #include <boost/locale.hpp>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include "basic_api.hh"
#include "message_api.hh"
#include "user_interface.hh"
#include "adapter.hh"
#include <mutex> #include <mutex>
#include <pEp/Adapter.hh>
#include <pEp/key_reset.h> #include <pEp/key_reset.h>
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
#include <pEp/status_to_string.h> #include <pEp/status_to_string.h>
#include "pEpmodule.hh"
#include "basic_api.hh"
#include "message_api.hh"
#include "user_interface.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
Adapter adapter(true); // Adapter adapter(true);
void config_passive_mode(bool enable) void config_passive_mode(bool enable)
{ {
::config_passive_mode(adapter.session(), enable); ::config_passive_mode(pEp::Adapter::session(), enable);
} }
void config_unencrypted_subject(bool enable) void config_unencrypted_subject(bool enable)
{ {
::config_unencrypted_subject(adapter.session(), enable); ::config_unencrypted_subject(pEp::Adapter::session(), enable);
} }
void key_reset_user(string user_id, string fpr) void key_reset_user(string user_id, string fpr)
@ -39,7 +41,7 @@ namespace pEp {
if (user_id == "") if (user_id == "")
throw invalid_argument("user_id required"); throw invalid_argument("user_id required");
PEP_STATUS status = ::key_reset_user(adapter.session(), PEP_STATUS status = ::key_reset_user(pEp::Adapter::session(),
user_id.c_str(), fpr != "" ? fpr.c_str() : nullptr); user_id.c_str(), fpr != "" ? fpr.c_str() : nullptr);
_throw_status(status); _throw_status(status);
} }
@ -51,7 +53,7 @@ namespace pEp {
void key_reset_all_own_keys() void key_reset_all_own_keys()
{ {
PEP_STATUS status = ::key_reset_all_own_keys(adapter.session()); PEP_STATUS status = ::key_reset_all_own_keys(pEp::Adapter::session());
_throw_status(status); _throw_status(status);
} }
@ -86,6 +88,11 @@ namespace pEp {
} }
} }
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) if (!_scope)
@ -104,31 +111,31 @@ namespace pEp {
throw runtime_error("implement pEp.messageToSend(msg)"); throw runtime_error("implement pEp.messageToSend(msg)");
} }
void do_sync_protocol() // void do_sync_protocol()
{ // {
::do_sync_protocol(adapter.session(), nullptr); // ::do_sync_protocol(pEp::Adapter::session(), nullptr);
} // }
void shutdown_sync() void shutdown_sync()
{ {
adapter.shutdown_sync(); pEp::Adapter::shutdown();
} }
void debug_color(int ansi_color) void debug_color(int ansi_color)
{ {
::set_debug_color(adapter.session(), ansi_color); ::set_debug_color(pEp::Adapter::session(), ansi_color);
} }
void leave_device_group() { void leave_device_group() {
::leave_device_group(adapter.session()); ::leave_device_group(pEp::Adapter::session());
} }
void script_is_implementing_sync() { // void script_is_implementing_sync() {
adapter.script_is_implementing_sync(); // adapter.script_is_implementing_sync();
} // }
bool is_sync_active() { bool is_sync_active() {
return adapter.is_sync_active(); return pEp::Adapter::is_sync_running();
} }
} }
} }
@ -547,38 +554,40 @@ BOOST_PYTHON_MODULE(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" // "\n"
"overwrite this method with an implementation of a handshake dialog") // "overwrite this method with an implementation of a handshake dialog")
.def("deliverHandshakeResult", &UserInterface::deliverHandshakeResult, // .def("deliverHandshakeResult", &UserInterface::deliverHandshakeResult,
boost::python::arg("identities")=object(), // boost::python::arg("identities")=object(),
"deliverHandshakeResult(self, result, identities=None)\n" // "deliverHandshakeResult(self, result, identities=None)\n"
"\n" // "\n"
" result -1: cancel, 0: accepted, 1: rejected\n" // " result -1: cancel, 0: accepted, 1: rejected\n"
" identities list of identities to share or None for all\n" // " identities list of identities to share or None for all\n"
"\n" // "\n"
"call to deliver the handshake result of the handshake dialog") // "call to deliver the handshake result of the handshake dialog")
; // ;
def("do_sync_protocol", &pEp::PythonAdapter::do_sync_protocol,
"do_sync_protocol()\n" // TODO: Replace with start_sync()
"\n" // def("do_sync_protocol", &pEp::PythonAdapter::do_sync_protocol,
"in case of an explicit sync thread instead of a single threaded\n" // "do_sync_protocol()\n"
"implementation call this function in your sync thread\n" // "\n"
); // "in case of an explicit sync thread instead of a single threaded\n"
// "implementation call this function in your sync thread\n"
// );
def("shutdown_sync", &pEp::PythonAdapter::shutdown_sync, def("shutdown_sync", &pEp::PythonAdapter::shutdown_sync,
"shutdown_sync()\n" "shutdown_sync()\n"
@ -595,12 +604,12 @@ BOOST_PYTHON_MODULE(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", &pEp::PythonAdapter::script_is_implementing_sync, // def("script_is_implementing_sync", &pEp::PythonAdapter::script_is_implementing_sync,
"script_is_implementing_sync()\n" // "script_is_implementing_sync()\n"
"\n" // "\n"
"call this in case the Python script is implementing sync to make\n" // "call this in case the Python script is implementing sync to make\n"
"is_sync_active() working\n" // "is_sync_active() working\n"
); // );
def("is_sync_active", &pEp::PythonAdapter::is_sync_active, def("is_sync_active", &pEp::PythonAdapter::is_sync_active,
"is_sync_active()\n" "is_sync_active()\n"

10
src/pEpmodule.hh

@ -1,10 +1,7 @@
#pragma once #pragma once
#include <boost/python.hpp>
#include "identity.hh"
#include "message.hh"
#include "adapter.hh"
#include <pEp/pEpEngine.h> #include <pEp/pEpEngine.h>
#include "message.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
@ -16,8 +13,9 @@ namespace pEp {
void _throw_status(PEP_STATUS status); void _throw_status(PEP_STATUS status);
void messageToSend(Message msg); void messageToSend(Message msg);
PEP_STATUS _messageToSend(::message *msg); PEP_STATUS _messageToSend(::message *msg);
void do_sync_protocol(); PEP_STATUS _ensure_passphrase(PEP_SESSION session, const char *fpr);
extern Adapter adapter; // void do_sync_protocol();
// extern Adapter adapter;
} }
} }

3
src/str_attr.cc

@ -3,8 +3,9 @@
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/locale.hpp> #include <boost/locale.hpp>
#include <cstdlib>
#include "str_attr.hh" #include "str_attr.hh"
#include <stdlib.h>
namespace pEp { namespace pEp {
namespace utility { namespace utility {

1
src/str_attr.hh

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <pEp/pEpEngine.h> #include <pEp/pEpEngine.h>
#include <pEp/timestamp.h> #include <pEp/timestamp.h>
#include <pEp/stringlist.h> #include <pEp/stringlist.h>

59
src/user_interface.cc

@ -1,9 +1,8 @@
// This file is under GNU Affero General Public License 3.0 // This file is under GNU Affero General Public License 3.0
// see LICENSE.txt // see LICENSE.txt
#include <cassert>
#include "user_interface.hh" #include "user_interface.hh"
#include <assert.h>
#include <time.h>
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
@ -24,8 +23,8 @@ namespace pEp {
UserInterface_callback::UserInterface_callback(PyObject *self) : UserInterface_callback::UserInterface_callback(PyObject *self) :
UserInterface(), _self(self) UserInterface(), _self(self)
{ {
adapter.ui_object(self); // adapter.ui_object(self);
PEP_STATUS status = ::register_sync_callbacks(adapter.session(), PEP_STATUS status = ::register_sync_callbacks(pEp::Adapter::session(),
(void *) this, _notifyHandshake, retrieve_next_sync_event); (void *) this, _notifyHandshake, retrieve_next_sync_event);
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
if (status) if (status)
@ -34,7 +33,7 @@ namespace pEp {
UserInterface_callback::~UserInterface_callback() UserInterface_callback::~UserInterface_callback()
{ {
::unregister_sync_callbacks(adapter.session()); ::unregister_sync_callbacks(pEp::Adapter::session());
} }
PEP_STATUS UserInterface::_notifyHandshake( PEP_STATUS UserInterface::_notifyHandshake(
@ -75,7 +74,7 @@ namespace pEp {
} }
} }
PEP_STATUS status = ::deliverHandshakeResult(adapter.session(), PEP_STATUS status = ::deliverHandshakeResult(pEp::Adapter::session(),
(sync_handshake_result) result, shared_identities); (sync_handshake_result) result, shared_identities);
free_identity_list(shared_identities); free_identity_list(shared_identities);
_throw_status(status); _throw_status(status);
@ -85,35 +84,35 @@ namespace pEp {
{ {
PEP_rating result; PEP_rating result;
PEP_STATUS status = PEP_STATUS status =
::get_key_rating_for_user(adapter.session(), ::get_key_rating_for_user(pEp::Adapter::session(),
user_id.c_str(), fpr.c_str(), &result); user_id.c_str(), fpr.c_str(), &result);
_throw_status(status); _throw_status(status);
return result; return result;
} }
SYNC_EVENT UserInterface::retrieve_next_sync_event(void *management, unsigned threshold) // SYNC_EVENT UserInterface::retrieve_next_sync_event(void *management, unsigned threshold)
{ // {
time_t started = time(nullptr); // time_t started = time(nullptr);
bool timeout = false; // bool timeout = false;
//
while (adapter.queue().empty()) { // while (adapter.queue().empty()) {
int i = 0; // int i = 0;
++i; // ++i;
if (i > 10) { // if (i > 10) {
if (time(nullptr) > started + threshold) { // if (time(nullptr) > started + threshold) {
timeout = true; // timeout = true;
break; // break;
} // }
i = 0; // i = 0;
} // }
nanosleep((const struct timespec[]){{0, 100000000L}}, NULL); // nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
} // }
//
if (timeout) // if (timeout)
return new_sync_timeout_event(); // return new_sync_timeout_event();
//
return adapter.queue().pop_front(); // return adapter.queue().pop_front();
} // }
void UserInterface_callback::notifyHandshake( void UserInterface_callback::notifyHandshake(
Identity me, Identity partner, sync_handshake_signal signal) Identity me, Identity partner, sync_handshake_signal signal)

7
src/user_interface.hh

@ -3,11 +3,14 @@
#pragma once #pragma once
#include "pEpmodule.hh" #include <csetjmp>
#include <setjmp.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include "pEpmodule.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
class UserInterface { class UserInterface {

Loading…
Cancel
Save