Browse Source

Formatting only - K&R 1TBS is the standard here

PYADPT-96_init_version
heck 5 years ago
parent
commit
f40ca8d8e6
  1. 3
      setup.py
  2. 2
      src/pEp/__init__.py
  3. 39
      src/pEp/native_pEp/basic_api.cc
  4. 7
      src/pEp/native_pEp/basic_api.hh
  5. 84
      src/pEp/native_pEp/identity.cc
  6. 23
      src/pEp/native_pEp/identity.hh
  7. 86
      src/pEp/native_pEp/message.cc
  8. 40
      src/pEp/native_pEp/message.hh
  9. 33
      src/pEp/native_pEp/message_api.cc
  10. 3
      src/pEp/native_pEp/message_api.hh
  11. 51
      src/pEp/native_pEp/pEpmodule.cc
  12. 7
      src/pEp/native_pEp/pEpmodule.hh
  13. 36
      src/pEp/native_pEp/str_attr.cc
  14. 21
      src/pEp/native_pEp/user_interface.cc
  15. 5
      src/pEp/native_pEp/user_interface.hh

3
setup.py

@ -29,8 +29,8 @@ def pEpLog(*msg):
func = inspect.currentframe().f_back.f_code func = inspect.currentframe().f_back.f_code
print(func.co_filename + " : " + func.co_name + " : " + msgstr) print(func.co_filename + " : " + func.co_name + " : " + msgstr)
class BuildExtCommand(build_ext):
class BuildExtCommand(build_ext):
user_options = build_ext.user_options + [ user_options = build_ext.user_options + [
('local', None, 'Use local pEp install in HOME/USERPROFILE for libs/includes'), ('local', None, 'Use local pEp install in HOME/USERPROFILE for libs/includes'),
('prefix=', None, 'Use local pEp install in prefix for libs/includes'), ('prefix=', None, 'Use local pEp install in prefix for libs/includes'),
@ -202,7 +202,6 @@ if sys.platform == 'winnt':
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
FileNotFoundError = EnvironmentError FileNotFoundError = EnvironmentError
module_pEp = Extension( module_pEp = Extension(
'native_pEp', 'native_pEp',
sources=[ sources=[

2
src/pEp/__init__.py

@ -11,6 +11,7 @@ from native_pEp import *
# import the module # import the module
import native_pEp import native_pEp
# Executed on module import # Executed on module import
def init(): def init():
print(init, "called") print(init, "called")
@ -45,6 +46,7 @@ def notify_handshake(me, partner, signal):
def main(): def main():
print("I am being run as a script") print("I am being run as a script")
# MAIN # MAIN
if __name__ == "__main__": if __name__ == "__main__":
main() main()

39
src/pEp/native_pEp/basic_api.cc

@ -16,20 +16,19 @@ namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
void update_identity(Identity& ident) void update_identity(Identity &ident) {
{
if (ident.address() == "") if (ident.address() == "")
throw invalid_argument("address needed"); throw invalid_argument("address needed");
if (ident.user_id() == PEP_OWN_USERID) if (ident.user_id() == PEP_OWN_USERID)
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(Adapter::session(), ident);
_throw_status(status); _throw_status(status);
} }
void myself(Identity& ident) void myself(Identity &ident) {
{
if (ident.address() == "") if (ident.address() == "")
throw invalid_argument("address needed"); throw invalid_argument("address needed");
if (ident.username() == "") if (ident.username() == "")
@ -42,8 +41,7 @@ void myself(Identity& ident)
_throw_status(status); _throw_status(status);
} }
string _trustwords(Identity me, Identity partner, string lang, bool full) string _trustwords(Identity me, Identity partner, string lang, bool full) {
{
if (me.fpr() == "" || partner.fpr() == "") if (me.fpr() == "" || partner.fpr() == "")
throw invalid_argument("fingerprint needed in Identities"); throw invalid_argument("fingerprint needed in Identities");
@ -58,8 +56,7 @@ string _trustwords(Identity me, Identity partner, string lang, bool full)
return words; return words;
} }
void trust_personal_key(Identity ident) void trust_personal_key(Identity ident) {
{
if (ident.fpr() == "") if (ident.fpr() == "")
throw invalid_argument("fingerprint needed in Identities"); throw invalid_argument("fingerprint needed in Identities");
if (ident.user_id() == "") if (ident.user_id() == "")
@ -69,8 +66,7 @@ void trust_personal_key(Identity ident)
_throw_status(status); _throw_status(status);
} }
void set_identity_flags(Identity ident, identity_flags_t flags) void set_identity_flags(Identity ident, identity_flags_t flags) {
{
if (ident.address() == "") if (ident.address() == "")
throw invalid_argument("address needed"); throw invalid_argument("address needed");
if (ident.user_id() == "") if (ident.user_id() == "")
@ -80,8 +76,7 @@ void set_identity_flags(Identity ident, identity_flags_t flags)
_throw_status(status); _throw_status(status);
} }
void unset_identity_flags(Identity ident, identity_flags_t flags) void unset_identity_flags(Identity ident, identity_flags_t flags) {
{
if (ident.address() == "") if (ident.address() == "")
throw invalid_argument("address needed"); throw invalid_argument("address needed");
if (ident.user_id() == "") if (ident.user_id() == "")
@ -91,8 +86,7 @@ void unset_identity_flags(Identity ident, identity_flags_t flags)
_throw_status(status); _throw_status(status);
} }
void key_reset_trust(Identity ident) void key_reset_trust(Identity ident) {
{
if (ident.fpr() == "") if (ident.fpr() == "")
throw invalid_argument("fpr needed"); throw invalid_argument("fpr needed");
if (ident.address() == "") if (ident.address() == "")
@ -105,9 +99,7 @@ void key_reset_trust(Identity ident)
} }
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(Adapter::session(), key_data.c_str(), key_data.size(), &private_keys);
if (status && status != PEP_KEY_IMPORTED) if (status && status != PEP_KEY_IMPORTED)
@ -127,8 +119,7 @@ boost::python::list import_key(string key_data)
return result; return result;
} }
string export_key(Identity ident) string export_key(Identity ident) {
{
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;
@ -138,8 +129,7 @@ string export_key(Identity ident)
return key_data; return key_data;
} }
string export_secret_key(Identity ident) string export_secret_key(Identity ident) {
{
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;
@ -149,8 +139,7 @@ string export_secret_key(Identity ident)
return key_data; return key_data;
} }
void set_own_key(Identity& ident, string fpr) void set_own_key(Identity &ident, string fpr) {
{
if (ident.address() == "") if (ident.address() == "")
throw invalid_argument("address needed"); throw invalid_argument("address needed");
if (ident.username() == "") if (ident.username() == "")
@ -167,6 +156,6 @@ void set_own_key(Identity& ident, string fpr)
} }
} // namespace PythonAdapter } // namespace PythonAdapter
} // namespace pEp { } // namespace pEp

7
src/pEp/native_pEp/basic_api.hh

@ -10,18 +10,25 @@ namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
void update_identity(Identity &ident); void update_identity(Identity &ident);
void myself(Identity &ident); void myself(Identity &ident);
string _trustwords(Identity me, Identity partner, string lang, bool full); string _trustwords(Identity me, Identity partner, string lang, bool full);
void trust_personal_key(Identity ident); void trust_personal_key(Identity ident);
void set_identity_flags(Identity ident, identity_flags_t flags); void set_identity_flags(Identity ident, identity_flags_t flags);
void unset_identity_flags(Identity ident, identity_flags_t flags); void unset_identity_flags(Identity ident, identity_flags_t flags);
void key_reset_trust(Identity ident); void key_reset_trust(Identity ident);
boost::python::list import_key(string key_data); boost::python::list import_key(string key_data);
string export_key(Identity ident); string export_key(Identity ident);
string export_secret_key(Identity ident); string export_secret_key(Identity ident);
void set_own_key(Identity &ident, string fpr); void set_own_key(Identity &ident, string fpr);
} /* namespace PythonAdapter */ } /* namespace PythonAdapter */

84
src/pEp/native_pEp/identity.cc

@ -24,8 +24,7 @@ using namespace boost::python;
Identity::Identity(string address, string username, string user_id, Identity::Identity(string address, string username, string user_id,
string fpr, int comm_type, string lang, identity_flags_t flags) string fpr, int comm_type, string lang, identity_flags_t flags)
: _ident(new_identity(address.c_str(), fpr.c_str(), user_id.c_str(), : _ident(new_identity(address.c_str(), fpr.c_str(), user_id.c_str(),
username.c_str()), &::free_identity) username.c_str()), &::free_identity) {
{
if (!_ident) if (!_ident)
throw bad_alloc(); throw bad_alloc();
_ident->comm_type = (PEP_comm_type) comm_type; _ident->comm_type = (PEP_comm_type) comm_type;
@ -34,34 +33,28 @@ Identity::Identity(string address, string username, string user_id,
} }
Identity::Identity(const Identity &second) Identity::Identity(const Identity &second)
: _ident(second._ident) : _ident(second._ident) {
{
} }
Identity::Identity(pEp_identity *ident) Identity::Identity(pEp_identity *ident)
: _ident(ident, &::free_identity) : _ident(ident, &::free_identity) {
{
} }
Identity::~Identity() Identity::~Identity() {
{
} }
Identity::operator pEp_identity *() Identity::operator pEp_identity *() {
{
return _ident.get(); return _ident.get();
} }
Identity::operator const pEp_identity *() const Identity::operator const pEp_identity *() const {
{
return _ident.get(); return _ident.get();
} }
string Identity::_repr() string Identity::_repr() {
{
stringstream build; stringstream build;
build << "Identity("; build << "Identity(";
string address; string address;
@ -86,8 +79,7 @@ string Identity::_repr()
return build.str(); return build.str();
} }
string Identity::_str() string Identity::_str() {
{
if (!(_ident->address && _ident->address[0])) if (!(_ident->address && _ident->address[0]))
return ""; return "";
if (!(_ident->username && _ident->username[0])) if (!(_ident->username && _ident->username[0]))
@ -95,16 +87,14 @@ string Identity::_str()
return string(_ident->username) + " <" + _ident->address + ">"; return string(_ident->username) + " <" + _ident->address + ">";
} }
void Identity::username(string value) void Identity::username(string value) {
{
if (value.length() && value.length() < 5) if (value.length() && value.length() < 5)
throw length_error("username must be at least 5 characters"); throw length_error("username must be at least 5 characters");
str_attr(_ident->username, value); str_attr(_ident->username, value);
} }
void Identity::lang(string value) void Identity::lang(string value) {
{
if (value == "") if (value == "")
memset(_ident->lang, 0, 3); memset(_ident->lang, 0, 3);
else if (value.length() != 2) else if (value.length() != 2)
@ -113,13 +103,11 @@ void Identity::lang(string value)
memcpy(_ident->lang, value.c_str(), 3); memcpy(_ident->lang, value.c_str(), 3);
} }
string Identity::lang() string Identity::lang() {
{
return _ident->lang; return _ident->lang;
} }
int Identity::rating() int Identity::rating() {
{
if (!(_ident->address)) if (!(_ident->address))
throw invalid_argument("address must be given"); throw invalid_argument("address must be given");
@ -130,13 +118,11 @@ int Identity::rating()
return (int) rating; return (int) rating;
} }
PEP_color Identity::color() PEP_color Identity::color() {
{
return _color(rating()); return _color(rating());
} }
Identity Identity::copy() Identity Identity::copy() {
{
pEp_identity *dup = ::identity_dup(*this); pEp_identity *dup = ::identity_dup(*this);
if (!dup) if (!dup)
throw bad_alloc(); throw bad_alloc();
@ -144,53 +130,44 @@ Identity Identity::copy()
return Identity(dup); return Identity(dup);
} }
Identity Identity::deepcopy(dict&) Identity Identity::deepcopy(dict &) {
{
return copy(); return copy();
} }
void Identity::update() void Identity::update() {
{
update_identity(*this); update_identity(*this);
} }
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(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(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(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(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(Adapter::session(), *this);
_throw_status(status); _throw_status(status);
} }
Myself::Myself(string address, string username, string user_id, string lang) Myself::Myself(string address, string username, string user_id, string lang)
: Identity(address, username, user_id, "", 0, lang) : Identity(address, username, user_id, "", 0, lang) {
{
if (!(address.length() && username.length())) if (!(address.length() && username.length()))
throw invalid_argument("address and username must be set"); throw invalid_argument("address and username must be set");
if (lang.length() && lang.length() != 2) if (lang.length() && lang.length() != 2)
@ -202,13 +179,11 @@ Myself::Myself(string address, string username, string user_id, string lang)
throw runtime_error("user_id feature not yet implemented for Myself"); throw runtime_error("user_id feature not yet implemented for Myself");
} }
void Myself::update() void Myself::update() {
{
pEp::PythonAdapter::myself(*this); pEp::PythonAdapter::myself(*this);
} }
Identity identity_attr(pEp_identity *&ident) Identity identity_attr(pEp_identity *&ident) {
{
if (!ident) if (!ident)
throw out_of_range("no identity assigned"); throw out_of_range("no identity assigned");
@ -220,8 +195,7 @@ Identity identity_attr(pEp_identity *&ident)
return _ident; return _ident;
} }
void identity_attr(pEp_identity *&ident, object value) void identity_attr(pEp_identity *&ident, object value) {
{
Identity &_ident = extract<Identity &>(value); Identity &_ident = extract<Identity &>(value);
pEp_identity *_dup = ::identity_dup(_ident); pEp_identity *_dup = ::identity_dup(_ident);
if (!_dup) if (!_dup)
@ -232,8 +206,7 @@ void identity_attr(pEp_identity *&ident, object value)
ident = _dup; ident = _dup;
} }
boost::python::list identitylist_attr(identity_list *&il) boost::python::list identitylist_attr(identity_list *&il) {
{
boost::python::list result; boost::python::list result;
for (identity_list *_il = il; _il && _il->ident; _il = _il->next) { for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
@ -246,8 +219,7 @@ boost::python::list identitylist_attr(identity_list *&il)
return result; return result;
} }
void identitylist_attr(identity_list *&il, boost::python::list value) void identitylist_attr(identity_list *&il, boost::python::list value) {
{
identity_list *_il = new_identity_list(NULL); identity_list *_il = new_identity_list(NULL);
if (!_il) if (!_il)
throw bad_alloc(); throw bad_alloc();
@ -281,5 +253,5 @@ void identitylist_attr(identity_list *&il, boost::python::list value)
} }
} // namespace PythonAdapter } // namespace PythonAdapter
} // namespace pEp { } // namespace pEp

23
src/pEp/native_pEp/identity.hh

@ -38,65 +38,84 @@ public:
string lang = "", identity_flags_t flags = 0); string lang = "", identity_flags_t flags = 0);
Identity(const Identity &second); Identity(const Identity &second);
Identity(pEp_identity *ident); Identity(pEp_identity *ident);
virtual ~Identity(); virtual ~Identity();
operator pEp_identity *(); operator pEp_identity *();
operator const pEp_identity *() const; operator const pEp_identity *() const;
string _repr(); string _repr();
string _str(); string _str();
string address() { return str_attr(_ident->address); } string address() { return str_attr(_ident->address); }
void address(string value) { str_attr(_ident->address, value); } void address(string value) { str_attr(_ident->address, value); }
string fpr() { return str_attr(_ident->fpr); } string fpr() { return str_attr(_ident->fpr); }
void fpr(string value) { str_attr(_ident->fpr, value); } void fpr(string value) { str_attr(_ident->fpr, value); }
string user_id() { return str_attr(_ident->user_id); } string user_id() { return str_attr(_ident->user_id); }
void user_id(string value) { str_attr(_ident->user_id, value); } void user_id(string value) { str_attr(_ident->user_id, value); }
string username() { return str_attr(_ident->username); } string username() { return str_attr(_ident->username); }
void username(string value); void username(string value);
PEP_comm_type comm_type() { return _ident->comm_type; } PEP_comm_type comm_type() { return _ident->comm_type; }
void comm_type(PEP_comm_type value) { _ident->comm_type = value; }; void comm_type(PEP_comm_type value) { _ident->comm_type = value; };
std::string lang(); std::string lang();
void lang(std::string value); void lang(std::string value);
identity_flags_t flags() { return _ident->flags; } identity_flags_t flags() { return _ident->flags; }
void flags(identity_flags_t flags) { _ident->flags = flags; } void flags(identity_flags_t flags) { _ident->flags = flags; }
int rating(); int rating();
PEP_color color(); PEP_color color();
Identity copy(); Identity copy();
Identity deepcopy(dict &memo); Identity deepcopy(dict &memo);
virtual void update(); virtual void update();
void key_reset(string fpr = ""); void key_reset(string fpr = "");
void key_mistrusted(); void key_mistrusted();
bool is_pEp_user(); bool is_pEp_user();
void enable_for_sync(); void enable_for_sync();
void disable_for_sync(); void disable_for_sync();
}; };
class Myself : public Identity { class Myself : public Identity {
public: public:
Myself(string address, string username, string user_id = "", string lang = ""); Myself(string address, string username, string user_id = "", string lang = "");
virtual void update(); virtual void update();
}; };
Identity identity_attr(pEp_identity *&ident); Identity identity_attr(pEp_identity *&ident);
void identity_attr(pEp_identity *&ident, object value); void identity_attr(pEp_identity *&ident, object value);
boost::python::list identitylist_attr(identity_list *&il); boost::python::list identitylist_attr(identity_list *&il);
void identitylist_attr(identity_list *&il, boost::python::list value); void identitylist_attr(identity_list *&il, boost::python::list value);
} /* namespace PythonAdapter */ } // namespace PythonAdapter
} /* namespace pEp */ } // namespace pEp
#endif /* IDENTITY_HH */ #endif /* IDENTITY_HH */

86
src/pEp/native_pEp/message.cc

@ -24,15 +24,13 @@ using namespace std;
using namespace boost::python; using namespace boost::python;
Message::Blob::Blob(bloblist_t *bl, bool chained) : Message::Blob::Blob(bloblist_t *bl, bool chained) :
_bl(bl), part_of_chain(chained) _bl(bl), part_of_chain(chained) {
{
if (!_bl) if (!_bl)
throw bad_alloc(); throw bad_alloc();
} }
Message::Blob::Blob(object data, string mime_type, string filename) : Message::Blob::Blob(object data, string mime_type, string filename) :
_bl(new_bloblist(NULL, 0, NULL, NULL)), part_of_chain(false) _bl(new_bloblist(NULL, 0, NULL, NULL)), part_of_chain(false) {
{
if (!_bl) if (!_bl)
throw bad_alloc(); throw bad_alloc();
@ -59,27 +57,23 @@ Message::Blob::Blob(object data, string mime_type, string filename) :
} }
Message::Blob::Blob(const Message::Blob &second) : Message::Blob::Blob(const Message::Blob &second) :
_bl(second._bl), part_of_chain(true) _bl(second._bl), part_of_chain(true) {
{
} }
Message::Blob::~Blob() Message::Blob::~Blob() {
{
if (!part_of_chain) { if (!part_of_chain) {
free(_bl->value); free(_bl->value);
free(_bl); free(_bl);
} }
} }
string Message::Blob::_repr() string Message::Blob::_repr() {
{
stringstream build; stringstream build;
build << "Blob("; build << "Blob(";
if (!_bl) { if (!_bl) {
build << "b'', '', ''"; build << "b'', '', ''";
} } else {
else {
build << "bytes(" << _bl->size << "), "; build << "bytes(" << _bl->size << "), ";
string mime_type; string mime_type;
if (_bl->mime_type) if (_bl->mime_type)
@ -116,8 +110,7 @@ int Message::Blob::getbuffer(PyObject *self, Py_buffer *view, int flags) {
return PyBuffer_FillInfo(view, self, bl->value, bl->size, 0, flags); return PyBuffer_FillInfo(view, self, bl->value, bl->size, 0, flags);
} }
string Message::Blob::decode(string encoding) string Message::Blob::decode(string encoding) {
{
if (encoding == "") { if (encoding == "") {
string _mime_type = _bl->mime_type ? _bl->mime_type : ""; string _mime_type = _bl->mime_type ? _bl->mime_type : "";
encoding = "ascii"; encoding = "ascii";
@ -137,8 +130,7 @@ string Message::Blob::decode(string encoding)
PyBufferProcs Message::Blob::bp = {getbuffer, NULL}; PyBufferProcs Message::Blob::bp = {getbuffer, NULL};
Message::Message(int dir, Identity *from) Message::Message(int dir, Identity *from)
: _msg(new_message((PEP_msg_direction) dir), &free_message) : _msg(new_message((PEP_msg_direction) dir), &free_message) {
{
if (!_msg) if (!_msg)
throw bad_alloc(); throw bad_alloc();
@ -151,8 +143,7 @@ Message::Message(int dir, Identity *from)
} }
Message::Message(string mimetext) Message::Message(string mimetext)
: _msg(NULL, &free_message) : _msg(NULL, &free_message) {
{
message *_cpy; message *_cpy;
PEP_STATUS status = mime_decode_message(mimetext.c_str(), PEP_STATUS status = mime_decode_message(mimetext.c_str(),
mimetext.size(), &_cpy, NULL); mimetext.size(), &_cpy, NULL);
@ -186,35 +177,29 @@ Message::Message(string mimetext)
} }
Message::Message(const Message &second) Message::Message(const Message &second)
: _msg(second._msg) : _msg(second._msg) {
{
if (!_msg.get()) if (!_msg.get())
throw bad_alloc(); throw bad_alloc();
} }
Message::Message(message *msg) Message::Message(message *msg)
: _msg(::message_dup(msg), &free_message) : _msg(::message_dup(msg), &free_message) {
{
} }
Message::~Message() Message::~Message() {
{
} }
Message::operator message *() Message::operator message *() {
{
return _msg.get(); return _msg.get();
} }
Message::operator const message *() const Message::operator const message *() const {
{
return _msg.get(); return _msg.get();
} }
string Message::_str() string Message::_str() {
{
if (!(_msg->from && _msg->from->address && _msg->from->address[0])) if (!(_msg->from && _msg->from->address && _msg->from->address[0]))
throw out_of_range(".from_.address missing"); throw out_of_range(".from_.address missing");
@ -246,15 +231,13 @@ string Message::_str()
return result; return result;
} }
string Message::_repr() string Message::_repr() {
{
stringstream build; stringstream build;
build << "Message(" << repr(_str()) << ")"; build << "Message(" << repr(_str()) << ")";
return build.str(); return build.str();
} }
boost::python::tuple Message::attachments() boost::python::tuple Message::attachments() {
{
boost::python::list l; boost::python::list l;
for (bloblist_t *bl = _msg->attachments; bl && bl->value; bl = for (bloblist_t *bl = _msg->attachments; bl && bl->value; bl =
@ -265,8 +248,7 @@ boost::python::tuple Message::attachments()
return boost::python::tuple(l); return boost::python::tuple(l);
} }
void Message::attachments(boost::python::list value) void Message::attachments(boost::python::list value) {
{
bloblist_t *bl = new_bloblist(NULL, 0, NULL, NULL); bloblist_t *bl = new_bloblist(NULL, 0, NULL, NULL);
if (!bl) if (!bl)
throw bad_alloc(); throw bad_alloc();
@ -302,14 +284,12 @@ void Message::attachments(boost::python::list value)
_msg->attachments = bl; _msg->attachments = bl;
} }
Message Message::encrypt() Message Message::encrypt() {
{
boost::python::list extra; boost::python::list extra;
return encrypt_message(*this, extra, PEP_enc_PGP_MIME, 0); return encrypt_message(*this, extra, PEP_enc_PGP_MIME, 0);
} }
Message Message::_encrypt(boost::python::list extra, int enc_format, int flags) Message Message::_encrypt(boost::python::list extra, int enc_format, int flags) {
{
if (!enc_format) if (!enc_format)
enc_format = PEP_enc_PGP_MIME; enc_format = PEP_enc_PGP_MIME;
return encrypt_message(*this, extra, enc_format, flags); return encrypt_message(*this, extra, enc_format, flags);
@ -319,8 +299,7 @@ boost::python::tuple Message::decrypt(int flags) {
return pEp::PythonAdapter::decrypt_message(*this, flags); return pEp::PythonAdapter::decrypt_message(*this, flags);
} }
PEP_rating Message::outgoing_rating() PEP_rating Message::outgoing_rating() {
{
if (_msg->dir != PEP_dir_outgoing) if (_msg->dir != PEP_dir_outgoing)
throw invalid_argument("Message.dir must be outgoing"); throw invalid_argument("Message.dir must be outgoing");
@ -342,26 +321,22 @@ PEP_rating Message::outgoing_rating()
return rating; return rating;
} }
PEP_color Message::outgoing_color() PEP_color Message::outgoing_color() {
{
return _color(outgoing_rating()); return _color(outgoing_rating());
} }
Message Message::copy() Message Message::copy() {
{
message *dup = message_dup(*this); message *dup = message_dup(*this);
if (!dup) if (!dup)
throw bad_alloc(); throw bad_alloc();
return Message(dup); return Message(dup);
} }
Message Message::deepcopy(dict&) Message Message::deepcopy(dict &) {
{
return copy(); return copy();
} }
Message outgoing_message(Identity me) Message outgoing_message(Identity me) {
{
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");
@ -370,16 +345,14 @@ Message outgoing_message(Identity me)
return m; return m;
} }
static object update(Identity ident) static object update(Identity ident) {
{
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(Adapter::session(), ident);
return object(ident); return object(ident);
} }
static boost::python::list update(boost::python::list il) static boost::python::list update(boost::python::list il) {
{
for (int i = 0; i < len(il); i++) { for (int i = 0; i < len(il); i++) {
update(extract<Identity>(il[i])); update(extract<Identity>(il[i]));
} }
@ -387,8 +360,7 @@ static boost::python::list update(boost::python::list il)
return il; return il;
} }
Message incoming_message(string mime_text) Message incoming_message(string mime_text) {
{
auto m = Message(mime_text); auto m = Message(mime_text);
m.dir(PEP_dir_incoming); m.dir(PEP_dir_incoming);
@ -410,4 +382,4 @@ Message incoming_message(string mime_text)
} }
} // namespace PythonAdapter } // namespace PythonAdapter
} // namespace pEp { } // namespace pEp

40
src/pEp/native_pEp/message.hh

@ -40,20 +40,27 @@ public:
public: public:
Blob(bloblist_t *bl = new_bloblist(NULL, 0, NULL, NULL), Blob(bloblist_t *bl = new_bloblist(NULL, 0, NULL, NULL),
bool chained = false); bool chained = false);
Blob(object data, string mime_type = "", string filename = ""); Blob(object data, string mime_type = "", string filename = "");
Blob(const Blob &second); Blob(const Blob &second);
~Blob(); ~Blob();
string _repr(); string _repr();
string mime_type() { return _bl ? str_attr(_bl->mime_type) : ""; } string mime_type() { return _bl ? str_attr(_bl->mime_type) : ""; }
void mime_type(string value) { str_attr(_bl->mime_type, value); } void mime_type(string value) { str_attr(_bl->mime_type, value); }
string filename() { return str_attr(_bl->filename); } string filename() { return str_attr(_bl->filename); }
void filename(string value) { str_attr(_bl->filename, value); } void filename(string value) { str_attr(_bl->filename, value); }
size_t size() { return _bl->size; } size_t size() { return _bl->size; }
string decode(string encoding); string decode(string encoding);
string decode() { return decode(""); } string decode() { return decode(""); }
static PyBufferProcs bp; static PyBufferProcs bp;
@ -65,87 +72,120 @@ public:
}; };
Message(int dir = PEP_dir_outgoing, Identity *from = NULL); Message(int dir = PEP_dir_outgoing, Identity *from = NULL);
Message(string mimetext); Message(string mimetext);
Message(const Message &second); Message(const Message &second);
Message(message *msg); Message(message *msg);
~Message(); ~Message();
operator message *(); operator message *();
operator const message *() const; operator const message *() const;
string _str(); string _str();
string _repr(); string _repr();
PEP_msg_direction dir() { return _msg->dir; } PEP_msg_direction dir() { return _msg->dir; }
void dir(PEP_msg_direction value) { _msg->dir = value; } void dir(PEP_msg_direction value) { _msg->dir = value; }
string id() { return str_attr(_msg->id); } string id() { return str_attr(_msg->id); }
void id(string value) { str_attr(_msg->id, value); } void id(string value) { str_attr(_msg->id, value); }
string shortmsg() { return str_attr(_msg->shortmsg); } string shortmsg() { return str_attr(_msg->shortmsg); }
void shortmsg(string value) { str_attr(_msg->shortmsg, value); } void shortmsg(string value) { str_attr(_msg->shortmsg, value); }
string longmsg() { return str_attr(_msg->longmsg); } string longmsg() { return str_attr(_msg->longmsg); }
void longmsg(string value) { str_attr(_msg->longmsg, value); } void longmsg(string value) { str_attr(_msg->longmsg, value); }
string longmsg_formatted() { return str_attr(_msg->longmsg_formatted); } string longmsg_formatted() { return str_attr(_msg->longmsg_formatted); }
void longmsg_formatted(string value) { str_attr(_msg->longmsg_formatted, value); } void longmsg_formatted(string value) { str_attr(_msg->longmsg_formatted, value); }
boost::python::tuple attachments(); boost::python::tuple attachments();
void attachments(boost::python::list value); void attachments(boost::python::list value);
time_t sent() { return timestamp_attr(_msg->sent); } time_t sent() { return timestamp_attr(_msg->sent); }
void sent(time_t value) { timestamp_attr(_msg->sent, value); } void sent(time_t value) { timestamp_attr(_msg->sent, value); }
time_t recv() { return timestamp_attr(_msg->recv); } time_t recv() { return timestamp_attr(_msg->recv); }
void recv(time_t value) { timestamp_attr(_msg->recv, value); } void recv(time_t value) { timestamp_attr(_msg->recv, value); }
Identity from() { return identity_attr(_msg->from); } Identity from() { return identity_attr(_msg->from); }
void from(object value) { identity_attr(_msg->from, value); } void from(object value) { identity_attr(_msg->from, value); }
boost::python::list to() { return identitylist_attr(_msg->to); } boost::python::list to() { return identitylist_attr(_msg->to); }
void to(boost::python::list value) { identitylist_attr(_msg->to, value); } void to(boost::python::list value) { identitylist_attr(_msg->to, value); }
Identity recv_by() { return identity_attr(_msg->recv_by); } Identity recv_by() { return identity_attr(_msg->recv_by); }
void recv_by(object value) { identity_attr(_msg->recv_by, value); } void recv_by(object value) { identity_attr(_msg->recv_by, value); }
boost::python::list cc() { return identitylist_attr(_msg->cc); } boost::python::list cc() { return identitylist_attr(_msg->cc); }
void cc(boost::python::list value) { identitylist_attr(_msg->cc, value); } void cc(boost::python::list value) { identitylist_attr(_msg->cc, value); }
boost::python::list bcc() { return identitylist_attr(_msg->bcc); } boost::python::list bcc() { return identitylist_attr(_msg->bcc); }
void bcc(boost::python::list value) { identitylist_attr(_msg->bcc, value); } void bcc(boost::python::list value) { identitylist_attr(_msg->bcc, value); }
boost::python::list reply_to() { return identitylist_attr(_msg->reply_to); } boost::python::list reply_to() { return identitylist_attr(_msg->reply_to); }
void reply_to(boost::python::list value) { identitylist_attr(_msg->reply_to, value); } void reply_to(boost::python::list value) { identitylist_attr(_msg->reply_to, value); }
boost::python::list in_reply_to() { return strlist_attr(_msg->in_reply_to); } boost::python::list in_reply_to() { return strlist_attr(_msg->in_reply_to); }
void in_reply_to(boost::python::list value) { strlist_attr(_msg->in_reply_to, value); } void in_reply_to(boost::python::list value) { strlist_attr(_msg->in_reply_to, value); }
boost::python::list references() { return strlist_attr(_msg->references); } boost::python::list references() { return strlist_attr(_msg->references); }
void references(boost::python::list value) { strlist_attr(_msg->references, value); } void references(boost::python::list value) { strlist_attr(_msg->references, value); }
boost::python::list keywords() { return strlist_attr(_msg->keywords); } boost::python::list keywords() { return strlist_attr(_msg->keywords); }
void keywords(boost::python::list value) { strlist_attr(_msg->keywords, value); } void keywords(boost::python::list value) { strlist_attr(_msg->keywords, value); }
string comments() { return str_attr(_msg->comments); } string comments() { return str_attr(_msg->comments); }
void comments(string value) { str_attr(_msg->comments, value); } void comments(string value) { str_attr(_msg->comments, value); }
dict opt_fields() { return strdict_attr(_msg->opt_fields); } dict opt_fields() { return strdict_attr(_msg->opt_fields); }
void opt_fields(dict value) { return strdict_attr(_msg->opt_fields, value); } void opt_fields(dict value) { return strdict_attr(_msg->opt_fields, value); }
PEP_enc_format enc_format() { return _msg->enc_format; } PEP_enc_format enc_format() { return _msg->enc_format; }
void enc_format(PEP_enc_format value) { _msg->enc_format = value; } void enc_format(PEP_enc_format value) { _msg->enc_format = value; }
Message encrypt(); Message encrypt();
Message _encrypt(boost::python::list extra, int enc_format = 4, int flags = 0); Message _encrypt(boost::python::list extra, int enc_format = 4, int flags = 0);
boost::python::tuple decrypt(int flags = 0); boost::python::tuple decrypt(int flags = 0);
PEP_rating outgoing_rating(); PEP_rating outgoing_rating();
PEP_color outgoing_color(); PEP_color outgoing_color();
Message deepcopy(dict &memo); Message deepcopy(dict &memo);
Message copy(); Message copy();
}; };
Message outgoing_message(Identity me); Message outgoing_message(Identity me);
Message incoming_message(string mime_text); Message incoming_message(string mime_text);
} /* namespace PythonAdapter */ } /* namespace PythonAdapter */

33
src/pEp/native_pEp/message_api.cc

@ -17,8 +17,7 @@ namespace PythonAdapter {
using namespace std; using namespace std;
using namespace boost::python; using namespace boost::python;
Message encrypt_message(Message src, boost::python::list extra, int enc_format, int flags) Message encrypt_message(Message src, boost::python::list extra, int enc_format, int flags) {
{
Identity _from = src.from(); Identity _from = src.from();
if (_from.address() == "") if (_from.address() == "")
throw invalid_argument("encrypt_message: src.from_.address empty"); throw invalid_argument("encrypt_message: src.from_.address empty");
@ -45,8 +44,7 @@ Message encrypt_message(Message src, boost::python::list extra, int enc_format,
return Message(_dst); return Message(_dst);
} }
boost::python::tuple decrypt_message(Message src, int flags) boost::python::tuple decrypt_message(Message src, int flags) {
{
message *_dst = NULL; message *_dst = NULL;
stringlist_t *_keylist = NULL; stringlist_t *_keylist = NULL;
PEP_rating _rating = PEP_rating_undefined; PEP_rating _rating = PEP_rating_undefined;
@ -67,13 +65,11 @@ boost::python::tuple decrypt_message(Message src, int flags)
return boost::python::make_tuple(dst, keylist, _rating, _flags); return boost::python::make_tuple(dst, keylist, _rating, _flags);
} }
PEP_color _color(int rating) PEP_color _color(int rating) {
{
return ::color_from_rating((PEP_rating) rating); return ::color_from_rating((PEP_rating) rating);
} }
boost::python::tuple sync_decode(object buffer) boost::python::tuple sync_decode(object buffer) {
{
Py_buffer src; Py_buffer src;
int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO); int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO);
if (result) if (result)
@ -89,8 +85,7 @@ boost::python::tuple sync_decode(object buffer)
return boost::python::make_tuple(_dst, 0); return boost::python::make_tuple(_dst, 0);
} }
static boost::python::tuple sync_encode(string text) static boost::python::tuple sync_encode(string text) {
{
char *data = NULL; char *data = NULL;
size_t size = 0; size_t size = 0;
PEP_STATUS status = XER_to_PER_Sync_msg(text.c_str(), &data, &size); PEP_STATUS status = XER_to_PER_Sync_msg(text.c_str(), &data, &size);
@ -104,8 +99,7 @@ static boost::python::tuple sync_encode(string text)
return boost::python::make_tuple(object(handle<>(ba)), 0); return boost::python::make_tuple(object(handle<>(ba)), 0);
} }
boost::python::tuple Distribution_decode(object buffer) boost::python::tuple Distribution_decode(object buffer) {
{
Py_buffer src; Py_buffer src;
int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO); int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO);
if (result) if (result)
@ -121,8 +115,7 @@ boost::python::tuple Distribution_decode(object buffer)
return boost::python::make_tuple(_dst, 0); return boost::python::make_tuple(_dst, 0);
} }
static boost::python::tuple Distribution_encode(string text) static boost::python::tuple Distribution_encode(string text) {
{
char *data = NULL; char *data = NULL;
size_t size = 0; size_t size = 0;
PEP_STATUS status = XER_to_PER_Distribution_msg(text.c_str(), &data, &size); PEP_STATUS status = XER_to_PER_Distribution_msg(text.c_str(), &data, &size);
@ -136,12 +129,10 @@ static boost::python::tuple Distribution_encode(string text)
return boost::python::make_tuple(object(handle<>(ba)), 0); return boost::python::make_tuple(object(handle<>(ba)), 0);
} }
object sync_search(string name) object sync_search(string name) {
{
if (name != "pep.sync") { if (name != "pep.sync") {
return object(); return object();
} } else {
else {
object codecs = import("codecs"); object codecs = import("codecs");
object CodecInfo = codecs.attr("CodecInfo"); object CodecInfo = codecs.attr("CodecInfo");
@ -152,12 +143,10 @@ object sync_search(string name)
} }
} }
object distribution_search(string name) object distribution_search(string name) {
{
if (name != "pep.distribution") { if (name != "pep.distribution") {
return object(); return object();
} } else {
else {
object codecs = import("codecs"); object codecs = import("codecs");
object CodecInfo = codecs.attr("CodecInfo"); object CodecInfo = codecs.attr("CodecInfo");

3
src/pEp/native_pEp/message_api.hh

@ -17,8 +17,11 @@ Message encrypt_message(
); );
boost::python::tuple decrypt_message(Message src, int flags = 0); boost::python::tuple decrypt_message(Message src, int flags = 0);
PEP_color _color(int rating); PEP_color _color(int rating);
object sync_search(string name); object sync_search(string name);
object distribution_search(string name); object distribution_search(string name);
} /* namespace PythonAdapter */ } /* namespace PythonAdapter */

51
src/pEp/native_pEp/pEpmodule.cc

@ -45,18 +45,15 @@ void _init_after_main_module() {
} }
void config_passive_mode(bool enable) void config_passive_mode(bool enable) {
{
::config_passive_mode(Adapter::session(), enable); ::config_passive_mode(Adapter::session(), enable);
} }
void config_unencrypted_subject(bool enable) void config_unencrypted_subject(bool enable) {
{
::config_unencrypted_subject(Adapter::session(), enable); ::config_unencrypted_subject(Adapter::session(), enable);
} }
void key_reset_user(string user_id, string fpr) void key_reset_user(string user_id, string fpr) {
{
if (user_id == "") if (user_id == "")
throw invalid_argument("user_id required"); throw invalid_argument("user_id required");
@ -65,26 +62,22 @@ void key_reset_user(string user_id, string fpr)
_throw_status(status); _throw_status(status);
} }
void key_reset_user2(string user_id) void key_reset_user2(string user_id) {
{
key_reset_user(user_id, ""); key_reset_user(user_id, "");
} }
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(Adapter::session());
_throw_status(status); _throw_status(status);
} }
static string about() static string about() {
{
string version = string(version_string) + "\np≡p version " string version = string(version_string) + "\np≡p version "
+ PEP_VERSION + "\n"; + PEP_VERSION + "\n";
return version; return version;
} }
void _throw_status(PEP_STATUS status) void _throw_status(PEP_STATUS status) {
{
if (status == PEP_STATUS_OK) if (status == PEP_STATUS_OK)
return; return;
if (status >= 0x400 && status <= 0x4ff) if (status >= 0x400 && status <= 0x4ff)
@ -98,14 +91,12 @@ void _throw_status(PEP_STATUS status)
stringstream build; stringstream build;
build << setfill('0') << "p≡p 0x" << setw(4) << hex << status; build << setfill('0') << "p≡p 0x" << setw(4) << hex << status;
throw runtime_error(build.str()); throw runtime_error(build.str());
} } else {
else {
throw runtime_error(pEp_status_to_string(status)); throw runtime_error(pEp_status_to_string(status));
} }
} }
PEP_STATUS _messageToSend(::message *msg) PEP_STATUS _messageToSend(::message *msg) {
{
pEpLog("called"); pEpLog("called");
try { try {
PyGILState_STATE gil = PyGILState_Ensure(); PyGILState_STATE gil = PyGILState_Ensure();
@ -120,8 +111,7 @@ PEP_STATUS _messageToSend(::message *msg)
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal) {
{
pEpLog("called"); pEpLog("called");
try { try {
PyGILState_STATE gil = PyGILState_Ensure(); PyGILState_STATE gil = PyGILState_Ensure();
@ -137,28 +127,23 @@ PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handsha
} }
void start_sync() void start_sync() {
{
CallbackDispatcher::start_sync(); CallbackDispatcher::start_sync();
} }
void shutdown_sync() void shutdown_sync() {
{
CallbackDispatcher::stop_sync(); CallbackDispatcher::stop_sync();
} }
void debug_color(int ansi_color) void debug_color(int ansi_color) {
{
::set_debug_color(Adapter::session(), ansi_color); ::set_debug_color(Adapter::session(), ansi_color);
} }
void leave_device_group() void leave_device_group() {
{
::leave_device_group(Adapter::session()); ::leave_device_group(Adapter::session());
} }
bool is_sync_active() bool is_sync_active() {
{
return Adapter::is_sync_running(); return Adapter::is_sync_running();
} }
@ -166,8 +151,7 @@ void testfunc() {
_messageToSend(NULL); _messageToSend(NULL);
} }
void deliverHandshakeResult(int result, object identities) void deliverHandshakeResult(int result, object identities) {
{
identity_list *shared_identities = nullptr; identity_list *shared_identities = nullptr;
if (identities != boost::python::api::object() && boost::python::len(identities)) { if (identities != boost::python::api::object() && boost::python::len(identities)) {
shared_identities = new_identity_list(nullptr); shared_identities = new_identity_list(nullptr);
@ -194,8 +178,7 @@ void deliverHandshakeResult(int result, object identities)
_throw_status(status); _throw_status(status);
} }
BOOST_PYTHON_MODULE(native_pEp) BOOST_PYTHON_MODULE(native_pEp) {
{
init_before_main_module(); init_before_main_module();
// Module init function called by pEp.init() // Module init function called by pEp.init()

7
src/pEp/native_pEp/pEpmodule.hh

@ -14,12 +14,19 @@ namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
extern string device_name; extern string device_name;
void config_passive_mode(bool enable); void config_passive_mode(bool enable);
void config_unencrypted_subject(bool enable); void config_unencrypted_subject(bool enable);
void key_reset_user(string user_id, string fpr); void key_reset_user(string user_id, string fpr);
void key_reset_all_own_keys(); void key_reset_all_own_keys();
void _throw_status(PEP_STATUS status); void _throw_status(PEP_STATUS status);
PEP_STATUS _messageToSend(::message *msg); PEP_STATUS _messageToSend(::message *msg);
PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal); PEP_STATUS notifyHandshake(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal);
} /* namespace PythonAdapter */ } /* namespace PythonAdapter */

36
src/pEp/native_pEp/str_attr.cc

@ -15,28 +15,24 @@ using namespace std;
using namespace boost::python; using namespace boost::python;
using namespace boost::locale; using namespace boost::locale;
object repr(object s) object repr(object s) {
{
return s.attr("__repr__")(); return s.attr("__repr__")();
} }
string repr(string s) string repr(string s) {
{
str _s = s.c_str(); str _s = s.c_str();
object _r = _s.attr("__repr__")(); object _r = _s.attr("__repr__")();
string r = extract<string>(_r); string r = extract<string>(_r);
return r; return r;
} }
string str_attr(char *&str) string str_attr(char *&str) {
{
if (!str) if (!str)
return string(""); return string("");
return string(str); return string(str);
} }
void str_attr(char *&str, string value) void str_attr(char *&str, string value) {
{
string normalized = normalize(value, norm_nfc); string normalized = normalize(value, norm_nfc);
free(str); free(str);
str = strdup(normalized.c_str()); str = strdup(normalized.c_str());
@ -44,22 +40,19 @@ void str_attr(char *&str, string value)
throw bad_alloc(); throw bad_alloc();
} }
time_t timestamp_attr(timestamp *&ts) time_t timestamp_attr(timestamp *&ts) {
{
if (!ts) if (!ts)
return 0; return 0;
return timegm(ts); return timegm(ts);
} }
void timestamp_attr(timestamp *&ts, time_t value) void timestamp_attr(timestamp *&ts, time_t value) {
{
free_timestamp(ts); free_timestamp(ts);
ts = new_timestamp(value); ts = new_timestamp(value);
} }
boost::python::list strlist_attr(stringlist_t *&sl) boost::python::list strlist_attr(stringlist_t *&sl) {
{
boost::python::list result; boost::python::list result;
for (stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) { for (stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) {
@ -70,8 +63,7 @@ boost::python::list strlist_attr(stringlist_t *&sl)
return result; return result;
} }
void strlist_attr(stringlist_t *&sl, boost::python::list value) void strlist_attr(stringlist_t *&sl, boost::python::list value) {
{
stringlist_t *_sl = new_stringlist(NULL); stringlist_t *_sl = new_stringlist(NULL);
if (!_sl) if (!_sl)
throw bad_alloc(); throw bad_alloc();
@ -95,8 +87,7 @@ void strlist_attr(stringlist_t *&sl, boost::python::list value)
sl = _sl; sl = _sl;
} }
dict strdict_attr(stringpair_list_t *&spl) dict strdict_attr(stringpair_list_t *&spl) {
{
dict result; dict result;
for (stringpair_list_t *_spl = spl; _spl && _spl->value; _spl = for (stringpair_list_t *_spl = spl; _spl && _spl->value; _spl =
@ -113,8 +104,7 @@ dict strdict_attr(stringpair_list_t *&spl)
return result; return result;
} }
void strdict_attr(stringpair_list_t *&spl, dict value) void strdict_attr(stringpair_list_t *&spl, dict value) {
{
stringpair_list_t *_spl = new_stringpair_list(NULL); stringpair_list_t *_spl = new_stringpair_list(NULL);
if (!_spl) if (!_spl)
throw bad_alloc(); throw bad_alloc();
@ -147,8 +137,7 @@ void strdict_attr(stringpair_list_t *&spl, dict value)
spl = _spl; spl = _spl;
} }
stringlist_t *to_stringlist(boost::python::list l) stringlist_t *to_stringlist(boost::python::list l) {
{
stringlist_t *result = new_stringlist(NULL); stringlist_t *result = new_stringlist(NULL);
if (!result) if (!result)
throw bad_alloc(); throw bad_alloc();
@ -169,8 +158,7 @@ stringlist_t *to_stringlist(boost::python::list l)
return result; return result;
} }
boost::python::list from_stringlist(const stringlist_t *sl) boost::python::list from_stringlist(const stringlist_t *sl) {
{
boost::python::list result; boost::python::list result;
for (const stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) { for (const stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) {
string s = _sl->value; string s = _sl->value;

21
src/pEp/native_pEp/user_interface.cc

@ -14,21 +14,18 @@ using namespace boost::python;
UserInterface *UserInterface::_ui = nullptr; UserInterface *UserInterface::_ui = nullptr;
UserInterface::UserInterface() UserInterface::UserInterface() {
{
if (_ui) if (_ui)
throw runtime_error("only one UserInterface thread allowed"); throw runtime_error("only one UserInterface thread allowed");
_ui = this; _ui = this;
} }
UserInterface::~UserInterface() UserInterface::~UserInterface() {
{
_ui = nullptr; _ui = nullptr;
} }
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(Adapter::session(),
// (void *) this, _notifyHandshake, retrieve_next_sync_event); // (void *) this, _notifyHandshake, retrieve_next_sync_event);
@ -37,16 +34,14 @@ UserInterface_callback::UserInterface_callback(PyObject *self) :
// _throw_status(status); // _throw_status(status);
} }
UserInterface_callback::~UserInterface_callback() UserInterface_callback::~UserInterface_callback() {
{
// ::unregister_sync_callbacks(Adapter::session()); // ::unregister_sync_callbacks(Adapter::session());
} }
PEP_STATUS UserInterface::_notifyHandshake( PEP_STATUS UserInterface::_notifyHandshake(
pEp_identity *me, pEp_identity *partner, pEp_identity *me, pEp_identity *partner,
sync_handshake_signal signal sync_handshake_signal signal
) ) {
{
if (!(me && partner)) if (!(me && partner))
return PEP_ILLEGAL_VALUE; return PEP_ILLEGAL_VALUE;
@ -56,8 +51,7 @@ PEP_STATUS UserInterface::_notifyHandshake(
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
void UserInterface::deliverHandshakeResult(int result, object identities) void UserInterface::deliverHandshakeResult(int result, object identities) {
{
identity_list *shared_identities = nullptr; identity_list *shared_identities = nullptr;
if (identities != boost::python::api::object() && boost::python::len(identities)) { if (identities != boost::python::api::object() && boost::python::len(identities)) {
shared_identities = new_identity_list(nullptr); shared_identities = new_identity_list(nullptr);
@ -120,8 +114,7 @@ void UserInterface::deliverHandshakeResult(int result, object identities)
//} //}
void UserInterface_callback::notifyHandshake( void UserInterface_callback::notifyHandshake(
Identity me, Identity partner, sync_handshake_signal signal) Identity me, Identity partner, sync_handshake_signal signal) {
{
call_method<void>(_self, "notifyHandshake", me, partner, signal); call_method<void>(_self, "notifyHandshake", me, partner, signal);
} }

5
src/pEp/native_pEp/user_interface.hh

@ -22,13 +22,13 @@ class UserInterface {
static UserInterface *_ui; static UserInterface *_ui;
public: public:
UserInterface(); UserInterface();
virtual ~UserInterface(); virtual ~UserInterface();
virtual void notifyHandshake( virtual void notifyHandshake(
Identity me, Identity me,
Identity partner, Identity partner,
sync_handshake_signal signal) sync_handshake_signal signal) {
{
throw runtime_error("override this method"); throw runtime_error("override this method");
} }
@ -44,6 +44,7 @@ class UserInterface_callback : public UserInterface {
PyObject *_self; PyObject *_self;
public: public:
UserInterface_callback(PyObject *self); UserInterface_callback(PyObject *self);
~UserInterface_callback(); ~UserInterface_callback();
void notifyHandshake( void notifyHandshake(

Loading…
Cancel
Save