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

PYADPT-81
heck 3 years ago
parent 60715b61d4
commit 7ee3d324ee

@ -90,6 +90,7 @@ class BuildExtCommand(build_ext):
]
libs = [
'pEpEngine',
'pEpAdapter',
'boost_python37-mt',
'boost_locale-mt'
]
@ -111,6 +112,7 @@ class BuildExtCommand(build_ext):
]
libs = [
'pEpEngine',
'pEpAdapter',
'boost_python37-mt',
'boost_locale-mt'
]
@ -129,6 +131,7 @@ class BuildExtCommand(build_ext):
]
libs = [
'pEpEngine',
'pEpAdapter',
'boost_python3',
'boost_locale'
]
@ -185,7 +188,7 @@ class BuildExtCommand(build_ext):
libdirs += sys_libdirs
# Compile flags
compile_flags = ['-std=c++14']
compile_flags = ['-std=c++14', '-fpermissive']
if self.debug:
pEpLog("debug mode")
compile_flags += ['-O0', '-g', '-UNDEBUG']
@ -218,7 +221,16 @@ if sys.version_info[0] < 3:
module_pEp = Extension(
'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

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

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

@ -1,10 +1,13 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include "basic_api.hh"
#include <sstream>
#include <pEp/keymanagement.h>
#include <pEp/message_api.h>
#include <pEp/Adapter.hh>
#include "basic_api.hh"
namespace pEp {
namespace PythonAdapter {
@ -16,7 +19,7 @@ namespace pEp {
throw runtime_error("update_identity: '" PEP_OWN_USERID
"' 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);
}
@ -30,7 +33,7 @@ namespace pEp {
if (ident.user_id() == "")
ident.user_id(ident.address());
PEP_STATUS status = myself(adapter.session(), ident);
PEP_STATUS status = myself(pEp::Adapter::session(), ident);
_throw_status(status);
}
@ -44,7 +47,7 @@ namespace pEp {
char *words = NULL;
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);
_throw_status(status);
return words;
@ -57,7 +60,7 @@ namespace pEp {
if (ident.user_id() == "")
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);
}
@ -68,7 +71,7 @@ namespace pEp {
if (ident.user_id() == "")
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);
}
@ -79,7 +82,7 @@ namespace pEp {
if (ident.user_id() == "")
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);
}
@ -92,7 +95,7 @@ namespace pEp {
if (ident.user_id() == "")
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);
}
@ -101,7 +104,7 @@ namespace pEp {
boost::python::list import_key(string key_data)
{
::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)
_throw_status(status);
@ -124,7 +127,7 @@ namespace pEp {
PEP_STATUS status = PEP_STATUS_OK;
char* key_data = NULL;
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);
return key_data;
@ -135,7 +138,7 @@ namespace pEp {
PEP_STATUS status = PEP_STATUS_OK;
char* key_data = NULL;
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);
return key_data;
@ -154,7 +157,7 @@ namespace pEp {
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);
}
}

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

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

@ -2,17 +2,19 @@
// see LICENSE.txt
#include <Python.h>
#include "message.hh"
#include "message_api.hh"
#include <stdlib.h>
#include <string.h>
#include <cstdlib>
#include <cstring>
#include <stdexcept>
#include <sstream>
#include <vector>
#include <pEp/mime.h>
#include <pEp/keymanagement.h>
#include <pEp/message_api.h>
#include "message.hh"
#include "message_api.hh"
namespace pEp {
namespace PythonAdapter {
using namespace std;
@ -326,11 +328,11 @@ namespace pEp {
if (len(to()) + len(cc()) == 0)
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);
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);
return rating;
@ -359,7 +361,7 @@ namespace pEp {
if (me.address().empty() || me.user_id().empty())
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);
return m;
}
@ -368,7 +370,7 @@ namespace pEp {
{
if (ident.address().empty())
throw runtime_error("at least address needed");
update_identity(adapter.session(), ident);
update_identity(pEp::Adapter::session(), ident);
return object(ident);
}

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

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

@ -1,37 +1,39 @@
// This file is under GNU Affero General Public License 3.0
// see LICENSE.txt
#include "pEpmodule.hh"
#include <boost/python.hpp>
#include <boost/locale.hpp>
#include <string>
#include <sstream>
#include <iomanip>
#include "basic_api.hh"
#include "message_api.hh"
#include "user_interface.hh"
#include "adapter.hh"
#include <mutex>
#include <pEp/Adapter.hh>
#include <pEp/key_reset.h>
#include <pEp/message_api.h>
#include <pEp/sync_api.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 PythonAdapter {
using namespace std;
Adapter adapter(true);
// Adapter adapter(true);
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)
{
::config_unencrypted_subject(adapter.session(), enable);
::config_unencrypted_subject(pEp::Adapter::session(), enable);
}
void key_reset_user(string user_id, string fpr)
@ -39,7 +41,7 @@ namespace pEp {
if (user_id == "")
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);
_throw_status(status);
}
@ -51,7 +53,7 @@ namespace pEp {
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);
}
@ -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)
{
if (!_scope)
@ -104,31 +111,31 @@ namespace pEp {
throw runtime_error("implement pEp.messageToSend(msg)");
}
void do_sync_protocol()
{
::do_sync_protocol(adapter.session(), nullptr);
}
// void do_sync_protocol()
// {
// ::do_sync_protocol(pEp::Adapter::session(), nullptr);
// }
void shutdown_sync()
{
adapter.shutdown_sync();
pEp::Adapter::shutdown();
}
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() {
::leave_device_group(adapter.session());
::leave_device_group(pEp::Adapter::session());
}
void script_is_implementing_sync() {
adapter.script_is_implementing_sync();
}
// void script_is_implementing_sync() {
// adapter.script_is_implementing_sync();
// }
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_IN_GROUP" , SYNC_NOTIFY_IN_GROUP);
auto user_interface_class = class_<UserInterface, UserInterface_callback, boost::noncopyable>(
"UserInterface",
"class MyUserInterface(UserInterface):\n"
" def notifyHandshake(self, me, partner):\n"
" ...\n"
"\n"
"p≡p User Interface class\n"
"To be used as a mixin\n"
)
.def("notifyHandshake", &UserInterface::notifyHandshake,
"notifyHandshake(self, me, partner)\n"
"\n"
" me own identity\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")
;
def("do_sync_protocol", &pEp::PythonAdapter::do_sync_protocol,
"do_sync_protocol()\n"
"\n"
"in case of an explicit sync thread instead of a single threaded\n"
"implementation call this function in your sync thread\n"
);
// auto user_interface_class = class_<UserInterface, UserInterface_callback, boost::noncopyable>(
// "UserInterface",
// "class MyUserInterface(UserInterface):\n"
// " def notifyHandshake(self, me, partner):\n"
// " ...\n"
// "\n"
// "p≡p User Interface class\n"
// "To be used as a mixin\n"
// )
// .def("notifyHandshake", &UserInterface::notifyHandshake,
// "notifyHandshake(self, me, partner)\n"
// "\n"
// " me own identity\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", &pEp::PythonAdapter::do_sync_protocol,
// "do_sync_protocol()\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,
"shutdown_sync()\n"
@ -595,12 +604,12 @@ BOOST_PYTHON_MODULE(pEp)
"call this for a grouped device, which should leave\n"
);
def("script_is_implementing_sync", &pEp::PythonAdapter::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("script_is_implementing_sync", &pEp::PythonAdapter::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", &pEp::PythonAdapter::is_sync_active,
"is_sync_active()\n"

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

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

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

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

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

Loading…
Cancel
Save