Browse Source

namespace cleanup - replace all "using namespace" with namspace aliases (except std in impl files.)

REWORK
heck 5 years ago
parent
commit
0e896bf36c
  1. 8
      src/pEp/_pEp/basic_api.cc
  2. 3
      src/pEp/_pEp/basic_api.hh
  3. 18
      src/pEp/_pEp/identity.cc
  4. 8
      src/pEp/_pEp/identity.hh
  5. 40
      src/pEp/_pEp/message.cc
  6. 50
      src/pEp/_pEp/message.hh
  7. 56
      src/pEp/_pEp/message_api.cc
  8. 8
      src/pEp/_pEp/message_api.hh
  9. 732
      src/pEp/_pEp/pEpmodule.cc
  10. 48
      src/pEp/_pEp/str_attr.cc
  11. 17
      src/pEp/_pEp/str_attr.hh
  12. 12
      src/pEp/_pEp/user_interface.cc
  13. 2
      src/pEp/_pEp/user_interface.hh

8
src/pEp/_pEp/basic_api.cc

@ -21,9 +21,7 @@ void update_identity(Identity &ident) {
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: '" throw runtime_error("update_identity: '" PEP_OWN_USERID "' may only be used for own identities");
PEP_OWN_USERID
"' 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);
@ -104,13 +102,13 @@ void key_reset_trust(Identity ident) {
_throw_status(status); _throw_status(status);
} }
boost::python::list import_key(string key_data) { bp::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) {
_throw_status(status); _throw_status(status);
} }
auto result = boost::python::list(); auto result = bp::list();
for (::identity_list *il = private_keys; il && il->ident; il = il->next) { for (::identity_list *il = private_keys; il && il->ident; il = il->next) {
::pEp_identity *ident = ::identity_dup(il->ident); ::pEp_identity *ident = ::identity_dup(il->ident);
if (!ident) { if (!ident) {

3
src/pEp/_pEp/basic_api.hh

@ -9,6 +9,7 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
namespace bp = boost::python;
void update_identity(Identity &ident); void update_identity(Identity &ident);
@ -24,7 +25,7 @@ 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); bp::list import_key(string key_data);
string export_key(Identity ident); string export_key(Identity ident);

18
src/pEp/_pEp/identity.cc

@ -19,7 +19,7 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
using namespace boost::python; namespace bp = boost::python;
Identity::Identity(string address, string username, string user_id, string fpr, int comm_type, string lang, ::identity_flags_t flags) Identity::Identity(string address, string username, string user_id, string fpr, int comm_type, string lang, ::identity_flags_t flags)
: _ident(::new_identity(address.c_str(), fpr.c_str(), user_id.c_str(), username.c_str()), &::free_identity) { : _ident(::new_identity(address.c_str(), fpr.c_str(), user_id.c_str(), username.c_str()), &::free_identity) {
@ -139,7 +139,7 @@ Identity Identity::copy() {
return Identity(dup); return Identity(dup);
} }
Identity Identity::deepcopy(dict &) { Identity Identity::deepcopy(bp::dict &) {
return copy(); return copy();
} }
@ -205,8 +205,8 @@ Identity identity_attr(::pEp_identity *&ident) {
return _ident; return _ident;
} }
void identity_attr(::pEp_identity *&ident, object value) { void identity_attr(::pEp_identity *&ident, bp::object value) {
Identity &_ident = extract<Identity &>(value); Identity &_ident = bp::extract<Identity &>(value);
::pEp_identity *_dup = ::identity_dup(_ident); ::pEp_identity *_dup = ::identity_dup(_ident);
if (!_dup) { if (!_dup) {
throw bad_alloc(); throw bad_alloc();
@ -217,21 +217,21 @@ void identity_attr(::pEp_identity *&ident, object value) {
ident = _dup; ident = _dup;
} }
boost::python::list identitylist_attr(::identity_list *&il) { bp::list identitylist_attr(::identity_list *&il) {
boost::python::list result; bp::list result;
for (::identity_list *_il = il; _il && _il->ident; _il = _il->next) { for (::identity_list *_il = il; _il && _il->ident; _il = _il->next) {
::pEp_identity *ident = ::identity_dup(_il->ident); ::pEp_identity *ident = ::identity_dup(_il->ident);
if (!ident) { if (!ident) {
throw bad_alloc(); throw bad_alloc();
} }
result.append(object(Identity(ident))); result.append(bp::object(Identity(ident)));
} }
return result; return result;
} }
void identitylist_attr(::identity_list *&il, boost::python::list value) { void identitylist_attr(::identity_list *&il, bp::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();
@ -239,7 +239,7 @@ void identitylist_attr(::identity_list *&il, boost::python::list value) {
::identity_list *_i = _il; ::identity_list *_i = _il;
for (int i = 0; i < len(value); i++) { for (int i = 0; i < len(value); i++) {
extract<Identity &> extract_identity(value[i]); bp::extract<Identity &> extract_identity(value[i]);
if (!extract_identity.check()) { if (!extract_identity.check()) {
::free_identity_list(_il); ::free_identity_list(_il);
} }

8
src/pEp/_pEp/identity.hh

@ -83,7 +83,7 @@ class Identity {
Identity copy(); Identity copy();
Identity deepcopy(dict &memo); Identity deepcopy(bp::dict &memo);
virtual void update(); virtual void update();
@ -107,11 +107,11 @@ class Identity {
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, bp::object value);
boost::python::list identitylist_attr(::identity_list *&il); bp::list identitylist_attr(::identity_list *&il);
void identitylist_attr(::identity_list *&il, boost::python::list value); void identitylist_attr(::identity_list *&il, bp::list value);
} // namespace PythonAdapter } // namespace PythonAdapter
} // namespace pEp } // namespace pEp

40
src/pEp/_pEp/message.cc

@ -21,7 +21,7 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
using namespace boost::python; namespace bp = boost::python;
Message::Blob::Blob(::bloblist_t *bl, bool chained) Message::Blob::Blob(::bloblist_t *bl, bool chained)
: _bl(bl), : _bl(bl),
@ -31,7 +31,7 @@ Message::Blob::Blob(::bloblist_t *bl, bool chained)
} }
} }
Message::Blob::Blob(object data, string mime_type, string filename) Message::Blob::Blob(bp::object data, string mime_type, string filename)
: _bl(::new_bloblist(NULL, 0, NULL, NULL)), : _bl(::new_bloblist(NULL, 0, NULL, NULL)),
part_of_chain(false) { part_of_chain(false) {
if (!_bl) { if (!_bl) {
@ -99,7 +99,7 @@ int Message::Blob::getbuffer(PyObject *self, Py_buffer *view, int flags) {
::bloblist_t *bl = NULL; ::bloblist_t *bl = NULL;
try { try {
Message::Blob &blob = extract<Message::Blob &>(self); Message::Blob &blob = bp::extract<Message::Blob &>(self);
bl = blob._bl; bl = blob._bl;
} catch (exception &e) { } catch (exception &e) {
PyErr_SetString(PyExc_RuntimeError, "extract not possible"); PyErr_SetString(PyExc_RuntimeError, "extract not possible");
@ -130,9 +130,9 @@ string Message::Blob::decode(string encoding) {
} }
} }
object codecs = import("codecs"); bp::object codecs = bp::import("codecs");
object _decode = codecs.attr("decode"); bp::object _decode = codecs.attr("decode");
return call<string>(_decode.ptr(), this, encoding); return bp::call<string>(_decode.ptr(), this, encoding);
} }
PyBufferProcs Message::Blob::bp = {getbuffer, NULL}; PyBufferProcs Message::Blob::bp = {getbuffer, NULL};
@ -246,17 +246,17 @@ string Message::_repr() {
return build.str(); return build.str();
} }
boost::python::tuple Message::attachments() { bp::tuple Message::attachments() {
boost::python::list l; bp::list l;
for (::bloblist_t *bl = _msg->attachments; bl && bl->value; bl = bl->next) { for (::bloblist_t *bl = _msg->attachments; bl && bl->value; bl = bl->next) {
l.append(Blob(bl, true)); l.append(Blob(bl, true));
} }
return boost::python::tuple(l); return bp::tuple(l);
} }
void Message::attachments(boost::python::list value) { void Message::attachments(bp::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();
@ -264,7 +264,7 @@ void Message::attachments(boost::python::list value) {
::bloblist_t *_l = bl; ::bloblist_t *_l = bl;
for (int i = 0; i < len(value); i++) { for (int i = 0; i < len(value); i++) {
Message::Blob &blob = extract<Message::Blob &>(value[i]); Message::Blob &blob = bp::extract<Message::Blob &>(value[i]);
_l = bloblist_add(_l, blob._bl->value, blob._bl->size, blob._bl->mime_type, blob._bl->filename); _l = bloblist_add(_l, blob._bl->value, blob._bl->size, blob._bl->mime_type, blob._bl->filename);
if (!_l) { if (!_l) {
for (_l = bl; _l && _l->value;) { for (_l = bl; _l && _l->value;) {
@ -279,7 +279,7 @@ void Message::attachments(boost::python::list value) {
} }
for (int i = 0; i < len(value); i++) { for (int i = 0; i < len(value); i++) {
Message::Blob &blob = extract<Message::Blob &>(value[i]); Message::Blob &blob = bp::extract<Message::Blob &>(value[i]);
blob._bl->value = NULL; blob._bl->value = NULL;
blob._bl->size = 0; blob._bl->size = 0;
free(blob._bl->mime_type); free(blob._bl->mime_type);
@ -293,18 +293,18 @@ void Message::attachments(boost::python::list value) {
} }
Message Message::encrypt() { Message Message::encrypt() {
boost::python::list extra; bp::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(bp::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);
} }
boost::python::tuple Message::decrypt(int flags) { bp::tuple Message::decrypt(int flags) {
return pEp::PythonAdapter::decrypt_message(*this, flags); return pEp::PythonAdapter::decrypt_message(*this, flags);
} }
@ -346,7 +346,7 @@ Message Message::copy() {
return Message(dup); return Message(dup);
} }
Message Message::deepcopy(dict &) { Message Message::deepcopy(bp::dict &) {
return copy(); return copy();
} }
@ -360,17 +360,17 @@ Message outgoing_message(Identity me) {
return m; return m;
} }
static object update(Identity ident) { static bp::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 bp::object(ident);
} }
static boost::python::list update(boost::python::list il) { static bp::list update(bp::list il) {
for (int i = 0; i < len(il); i++) { for (int i = 0; i < len(il); i++) {
update(extract<Identity>(il[i])); update(bp::extract<Identity>(il[i]));
} }
return il; return il;

50
src/pEp/_pEp/message.hh

@ -7,7 +7,6 @@
// System // System
#include <string> #include <string>
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/lexical_cast.hpp>
// Engine // Engine
#include <pEp/message.h> #include <pEp/message.h>
@ -22,7 +21,6 @@ namespace PythonAdapter {
using std::string; using std::string;
using std::runtime_error; using std::runtime_error;
using std::invalid_argument; using std::invalid_argument;
using boost::lexical_cast;
// Message is owning a message struct // Message is owning a message struct
@ -40,7 +38,7 @@ class Message {
public: public:
Blob(::bloblist_t *bl = ::new_bloblist(NULL, 0, NULL, NULL), bool chained = false); Blob(::bloblist_t *bl = ::new_bloblist(NULL, 0, NULL, NULL), bool chained = false);
Blob(object data, string mime_type = "", string filename = ""); Blob(bp::object data, string mime_type = "", string filename = "");
Blob(const Blob &second); Blob(const Blob &second);
@ -108,9 +106,9 @@ class Message {
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(); bp::tuple attachments();
void attachments(boost::python::list value); void attachments(bp::list value);
time_t sent() { return timestamp_attr(_msg->sent); } time_t sent() { return timestamp_attr(_msg->sent); }
@ -122,47 +120,47 @@ class Message {
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(bp::object value) { identity_attr(_msg->from, value); }
boost::python::list to() { return identitylist_attr(_msg->to); } bp::list to() { return identitylist_attr(_msg->to); }
void to(boost::python::list value) { identitylist_attr(_msg->to, value); } void to(bp::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(bp::object value) { identity_attr(_msg->recv_by, value); }
boost::python::list cc() { return identitylist_attr(_msg->cc); } bp::list cc() { return identitylist_attr(_msg->cc); }
void cc(boost::python::list value) { identitylist_attr(_msg->cc, value); } void cc(bp::list value) { identitylist_attr(_msg->cc, value); }
boost::python::list bcc() { return identitylist_attr(_msg->bcc); } bp::list bcc() { return identitylist_attr(_msg->bcc); }
void bcc(boost::python::list value) { identitylist_attr(_msg->bcc, value); } void bcc(bp::list value) { identitylist_attr(_msg->bcc, value); }
boost::python::list reply_to() { return identitylist_attr(_msg->reply_to); } bp::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(bp::list value) { identitylist_attr(_msg->reply_to, value); }
boost::python::list in_reply_to() { return strlist_attr(_msg->in_reply_to); } bp::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(bp::list value) { strlist_attr(_msg->in_reply_to, value); }
boost::python::list references() { return strlist_attr(_msg->references); } bp::list references() { return strlist_attr(_msg->references); }
void references(boost::python::list value) { strlist_attr(_msg->references, value); } void references(bp::list value) { strlist_attr(_msg->references, value); }
boost::python::list keywords() { return strlist_attr(_msg->keywords); } bp::list keywords() { return strlist_attr(_msg->keywords); }
void keywords(boost::python::list value) { strlist_attr(_msg->keywords, value); } void keywords(bp::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); } bp::dict opt_fields() { return strdict_attr(_msg->opt_fields); }
void opt_fields(dict value) { return strdict_attr(_msg->opt_fields, value); } void opt_fields(bp::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; }
@ -170,15 +168,15 @@ class Message {
Message encrypt(); Message encrypt();
Message _encrypt(boost::python::list extra, int enc_format = 4, int flags = 0); Message _encrypt(bp::list extra, int enc_format = 4, int flags = 0);
boost::python::tuple decrypt(int flags = 0); bp::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(bp::dict &memo);
Message copy(); Message copy();
}; };

56
src/pEp/_pEp/message_api.cc

@ -10,15 +10,13 @@
// local // local
#include "message_api.hh" #include "message_api.hh"
#include "basic_api.hh"
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
using namespace boost::python; namespace bp = boost::python;
// namespace bp = boost::python; Message encrypt_message(Message src, bp::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");
@ -48,7 +46,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) { bp::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;
@ -58,21 +56,21 @@ boost::python::tuple decrypt_message(Message src, int flags) {
::PEP_STATUS status = ::decrypt_message(Adapter::session(), _src, &_dst, &_keylist, &_rating, &_flags); ::PEP_STATUS status = ::decrypt_message(Adapter::session(), _src, &_dst, &_keylist, &_rating, &_flags);
_throw_status(status); _throw_status(status);
boost::python::list keylist; bp::list keylist;
if (_keylist) { if (_keylist) {
keylist = from_stringlist(_keylist); keylist = from_stringlist(_keylist);
::free_stringlist(_keylist); ::free_stringlist(_keylist);
} }
Message dst = _dst ? Message(_dst) : Message(src); Message dst = _dst ? Message(_dst) : Message(src);
return boost::python::make_tuple(dst, keylist, _rating, _flags); return bp::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) { bp::tuple sync_decode(bp::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) {
@ -86,10 +84,10 @@ boost::python::tuple sync_decode(object buffer) {
string _dst(dst); string _dst(dst);
free(dst); free(dst);
return boost::python::make_tuple(_dst, 0); return bp::make_tuple(_dst, 0);
} }
static boost::python::tuple sync_encode(string text) { static bp::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);
@ -101,10 +99,10 @@ static boost::python::tuple sync_encode(string text) {
throw bad_alloc(); throw bad_alloc();
} }
return boost::python::make_tuple(object(handle<>(ba)), 0); return bp::make_tuple(bp::object(bp::handle<>(ba)), 0);
} }
boost::python::tuple Distribution_decode(object buffer) { bp::tuple Distribution_decode(bp::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) {
@ -118,10 +116,10 @@ boost::python::tuple Distribution_decode(object buffer) {
string _dst(dst); string _dst(dst);
free(dst); free(dst);
return boost::python::make_tuple(_dst, 0); return bp::make_tuple(_dst, 0);
} }
static boost::python::tuple Distribution_encode(string text) { static bp::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);
@ -133,34 +131,34 @@ static boost::python::tuple Distribution_encode(string text) {
throw bad_alloc(); throw bad_alloc();
} }
return boost::python::make_tuple(object(handle<>(ba)), 0); return bp::make_tuple(bp::object(bp::handle<>(ba)), 0);
} }
object sync_search(string name) { bp::object sync_search(string name) {
if (name != "pep.sync") { if (name != "pep.sync") {
return object(); return bp::object();
} else { } else {
object codecs = import("codecs"); bp::object codecs = bp::import("codecs");
object CodecInfo = codecs.attr("CodecInfo"); bp::object CodecInfo = codecs.attr("CodecInfo");
object _sync_decode = make_function(sync_decode); bp::object _sync_decode = make_function(sync_decode);
object _sync_encode = make_function(sync_encode); bp::object _sync_encode = make_function(sync_encode);
return call<object>(CodecInfo.ptr(), _sync_encode, _sync_decode); return bp::call<bp::object>(CodecInfo.ptr(), _sync_encode, _sync_decode);
} }
} }
object distribution_search(string name) { bp::object distribution_search(string name) {
if (name != "pep.distribution") { if (name != "pep.distribution") {
return object(); return bp::object();
} else { } else {
object codecs = import("codecs"); bp::object codecs = bp::import("codecs");
object CodecInfo = codecs.attr("CodecInfo"); bp::object CodecInfo = codecs.attr("CodecInfo");
object _distribution_decode = make_function(Distribution_decode); bp::object _distribution_decode = make_function(Distribution_decode);
object _distribution_encode = make_function(Distribution_encode); bp::object _distribution_encode = make_function(Distribution_encode);
return call<object>(CodecInfo.ptr(), _distribution_encode, _distribution_decode); return bp::call<bp::object>(CodecInfo.ptr(), _distribution_encode, _distribution_decode);
} }
} }

8
src/pEp/_pEp/message_api.hh

@ -9,15 +9,15 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
Message encrypt_message(Message src, boost::python::list extra = boost::python::list(), int enc_format = 4, int flags = 0); Message encrypt_message(Message src, bp::list extra = bp::list(), int enc_format = 4, int flags = 0);
boost::python::tuple decrypt_message(Message src, int flags = 0); bp::tuple decrypt_message(Message src, int flags = 0);
::PEP_color _color(int rating); ::PEP_color _color(int rating);
object sync_search(string name); bp::object sync_search(string name);
object distribution_search(string name); bp::object distribution_search(string name);
} /* namespace PythonAdapter */ } /* namespace PythonAdapter */
} /* namespace pEp */ } /* namespace pEp */

732
src/pEp/_pEp/pEpmodule.cc

@ -7,7 +7,6 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <mutex>
// Engine // Engine
#include <pEp/key_reset.h> #include <pEp/key_reset.h>
@ -29,7 +28,8 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
using namespace boost::python; namespace bp = boost::python;
namespace bl = boost::locale;
static const char *version_string = "p≡p Python adapter version 0.3"; static const char *version_string = "p≡p Python adapter version 0.3";
@ -103,9 +103,9 @@ void _throw_status(::PEP_STATUS status) {
try { try {
PyGILState_STATE gil = PyGILState_Ensure(); PyGILState_STATE gil = PyGILState_Ensure();
pEpLog("GIL Aquired"); pEpLog("GIL Aquired");
object modref = import("pEp"); bp::object modref = bp::import("pEp");
object funcref = modref.attr("message_to_send"); bp::object funcref = modref.attr("message_to_send");
call<void>(funcref.ptr(), Message()); bp::call<void>(funcref.ptr(), Message());
PyGILState_Release(gil); PyGILState_Release(gil);
pEpLog("GIL released"); pEpLog("GIL released");
} catch (exception &e) { } catch (exception &e) {
@ -119,9 +119,9 @@ void _throw_status(::PEP_STATUS status) {
try { try {
PyGILState_STATE gil = PyGILState_Ensure(); PyGILState_STATE gil = PyGILState_Ensure();
pEpLog("GIL Aquired"); pEpLog("GIL Aquired");
object modref = import("pEp"); bp::object modref = bp::import("pEp");
object funcref = modref.attr("notify_handshake"); bp::object funcref = modref.attr("notify_handshake");
call<void>(funcref.ptr(), me, partner, signal); bp::call<void>(funcref.ptr(), me, partner, signal);
PyGILState_Release(gil); PyGILState_Release(gil);
pEpLog("GIL released"); pEpLog("GIL released");
} catch (exception &e) { } catch (exception &e) {
@ -154,9 +154,9 @@ void testfunc() {
_messageToSend(NULL); _messageToSend(NULL);
} }
void deliverHandshakeResult(int result, object identities) { void deliverHandshakeResult(int result, bp::object identities) {
identity_list *shared_identities = nullptr; identity_list *shared_identities = nullptr;
if (identities != boost::python::api::object() && boost::python::len(identities)) { if (identities != bp::api::object() && boost::python::len(identities)) {
shared_identities = ::new_identity_list(nullptr); shared_identities = ::new_identity_list(nullptr);
if (!shared_identities) { if (!shared_identities) {
throw bad_alloc(); throw bad_alloc();
@ -164,8 +164,8 @@ void deliverHandshakeResult(int result, object identities) {
try { try {
::identity_list *si = shared_identities; ::identity_list *si = shared_identities;
for (int i = 0; i < boost::python::len(identities); ++i) { for (int i = 0; i < bp::len(identities); ++i) {
Identity ident = extract<Identity>(identities[i]); Identity ident = bp::extract<Identity>(identities[i]);
si = ::identity_list_add(si, ident); si = ::identity_list_add(si, ident);
if (!si) { if (!si) {
throw bad_alloc(); throw bad_alloc();
@ -182,291 +182,481 @@ void deliverHandshakeResult(int result, object identities) {
_throw_status(status); _throw_status(status);
} }
BOOST_PYTHON_MODULE (_pEp) { BOOST_PYTHON_MODULE(_pEp) {
using boost::python::def;
using boost::python::class_;
using boost::python::enum_;
init_before_main_module(); init_before_main_module();
// Module init function called by pEp.init() // Module init function called by pEp.init()
def("_init_after_main_module", _init_after_main_module); def("_init_after_main_module", _init_after_main_module);
def("testfunc", &testfunc); def("testfunc", &testfunc);
docstring_options doc_options(true, false, false); bp::docstring_options doc_options(true, false, false);
boost::locale::generator gen; bl::generator gen;
std::locale::global(gen("")); std::locale::global(gen(""));
scope().attr("about") = about();
scope().attr("per_user_directory") = ::per_user_directory(); bp::scope().attr("about") = about();
scope().attr("per_machine_directory") = ::per_machine_directory(); bp::scope().attr("per_user_directory") = ::per_user_directory();
scope().attr("engine_version") = ::get_engine_version(); bp::scope().attr("per_machine_directory") = ::per_machine_directory();
scope().attr("protocol_version") = ::get_protocol_version(); bp::scope().attr("engine_version") = ::get_engine_version();
bp::scope().attr("protocol_version") = ::get_protocol_version();
def("passive_mode", config_passive_mode, "do not attach pub keys to all messages");
def("passive_mode", config_passive_mode,
def("unencrypted_subject", config_unencrypted_subject, "do not encrypt the subject of messages"); "do not attach pub keys to all messages");
def("key_reset", key_reset_user, "reset the default database status for the user / keypair provided\n" def("unencrypted_subject", config_unencrypted_subject,
"This will effectively perform key_reset on each identity\n" "do not encrypt the subject of messages");
"associated with the key and user_id, if a key is provided, and for\n"
"each key (and all of their identities) if an fpr is not."); def("key_reset", key_reset_user,
"reset the default database status for the user / keypair provided\n"
def("key_reset", key_reset_user2, "reset the default database status for the user / keypair provided\n" "This will effectively perform key_reset on each identity\n"
"This will effectively perform key_reset on each identity\n" "associated with the key and user_id, if a key is provided, and for\n"
"associated with the key and user_id, if a key is provided, and for\n" "each key (and all of their identities) if an fpr is not.");
"each key (and all of their identities) if an fpr is not.");
def("key_reset", key_reset_user2,
def("key_reset_all_own_keys", key_reset_all_own_keys, "revoke and mistrust all own keys, generate new keys for all\n" "reset the default database status for the user / keypair provided\n"
"own identities, and opportunistically communicate key reset\n" "This will effectively perform key_reset on each identity\n"
"information to people we have recently contacted."); "associated with the key and user_id, if a key is provided, and for\n"
"each key (and all of their identities) if an fpr is not.");
auto identity_class = class_<Identity>("Identity", "Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n"
"\n" def("key_reset_all_own_keys", key_reset_all_own_keys,
"represents a p≡p identity\n" "revoke and mistrust all own keys, generate new keys for all\n"
"\n" "own identities, and opportunistically communicate key reset\n"
"an identity is a network address, under which a user is represented in\n" "information to people we have recently contacted.");
"the network\n"
"\n" auto identity_class = class_<Identity>("Identity",
" address network address, either an SMTP address or a URI\n" "Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n"
" username real name or nickname for user\n" "\n"
" user_id ID this user is handled by the application\n" "represents a p≡p identity\n"
" fpr full fingerprint of the key being used as key ID,\n" "\n"
" hex encoded\n" "an identity is a network address, under which a user is represented in\n"
" comm_type first rating level of this communication channel\n" "the network\n"
" lang ISO 639-1 language code for language being preferred\n" "\n"
" on this communication channel\n").def(boost::python::init<string>()).def(boost::python::init<string, string>()).def(boost::python::init<string, string, string>()).def(boost::python::init<string, string, string, string>()) " address network address, either an SMTP address or a URI\n"
.def(boost::python::init<string, string, string, string, int>()).def(boost::python::init<string, string, string, string, int, string>()).def("__repr__", &Identity::_repr).def("__str__", &Identity::_str, "string representation of this identity\n" " username real name or nickname for user\n"
"following the pattern 'username < address >'\n") " user_id ID this user is handled by the application\n"
.def("key_reset", &Identity::key_reset, boost::python::arg("fpr") = object(""), "reset the default database status for the identity / keypair provided. If this\n" " fpr full fingerprint of the key being used as key ID,\n"
"corresponds to the own user and a private key, also revoke the key, generate a\n" " hex encoded\n"
"new one, and communicate the reset to recently contacted pEp partners for this\n" " comm_type first rating level of this communication channel\n"
"identity. If it does not, remove the key from the keyring; the key's status is\n" " lang ISO 639-1 language code for language being preferred\n"
"completely fresh on next contact from the partner.") " on this communication channel\n"
)
.def("key_mistrusted", &Identity::key_mistrusted, boost::python::arg("fpr") = object(""), "If you want updated trust on the identity, you ll have" .def(bp::init<string>())
"to call update_identity or myself respectively after this." .def(bp::init<string, string>())
"N.B. If you are calling this on a key that is the identity or user default," .def(bp::init<string, string, string>())
"it will be removed as the default key for ANY identity and user for which" .def(bp::init<string, string, string, string>())
"it is the default. Please keep in mind that the undo in undo_last_mistrust" .def(bp::init<string, string, string, string, int>())
"will only undo the current identity's / it's user's default, not any" .def(bp::init<string, string, string, string, int, string>())
"other identities which may be impacted (this will not affect most use cases)") .def("__repr__", &Identity::_repr)
.def("__str__", &Identity::_str,
.def("enable_for_sync", &Identity::enable_for_sync, "Enable own identity for p≡p sync.\n\n" "string representation of this identity\n"
"Only use this on own identities, which are used as accounts.\n").def("disable_for_sync", &Identity::disable_for_sync, "Disable own identity for p≡p sync.\n\n" "following the pattern 'username < address >'\n"
"Only use this on own identities, which are used as accounts.\n") )
.def("key_reset", &Identity::key_reset,
.add_property("address", (string(Identity::*)())&Identity::address, (void (Identity::*)(string))&Identity::address, "email address or URI").add_property("fpr", (string(Identity::*)())&Identity::fpr, (void (Identity::*)(string))&Identity::fpr, "key ID (full fingerprint, hex encoded)") bp::arg("fpr")=bp::object(""),
.add_property("user_id", (string(Identity::*)())&Identity::user_id, (void (Identity::*)(string))&Identity::user_id, "ID of person associated or 'pEp_own_userId' if own identity") "reset the default database status for the identity / keypair provided. If this\n"
.add_property("username", (string(Identity::*)())&Identity::username, (void (Identity::*)(string))&Identity::username, "name in full of person associated") "corresponds to the own user and a private key, also revoke the key, generate a\n"
.add_property("comm_type", (int (Identity::*)())(PEP_comm_type(Identity::*)())&Identity::comm_type, (void (Identity::*)(int))(void (Identity::*)(::PEP_comm_type))&Identity::comm_type, "communication type, first rating level (p≡p internal)") "new one, and communicate the reset to recently contacted pEp partners for this\n"
.add_property("lang", (string(Identity::*)())&Identity::lang, (void (Identity::*)(string))&Identity::lang, "ISO 639-1 language code").add_property("flags", (identity_flags_t(Identity::*)())&Identity::flags, (void (Identity::*)(::identity_flags_t))&Identity::flags, "flags (p≡p internal)") "identity. If it does not, remove the key from the keyring; the key's status is\n"
.add_property("rating", &Identity::rating, "rating of Identity").add_property("color", &Identity::color, "color of Identity as PEP_color").add_property("is_pEp_user", &Identity::is_pEp_user, "True if this is an identity of a pEp user").def("__deepcopy__", &Identity::deepcopy) "completely fresh on next contact from the partner.")
.def("update", &Identity::update, "update Identity").def("__copy__", &Identity::copy);
.def("key_mistrusted", &Identity::key_mistrusted,
bp::arg("fpr")=bp::object(""),
"If you want updated trust on the identity, you ll have"
"to call update_identity or myself respectively after this."
"N.B. If you are calling this on a key that is the identity or user default,"
"it will be removed as the default key for ANY identity and user for which"
"it is the default. Please keep in mind that the undo in undo_last_mistrust"
"will only undo the current identity's / it's user's default, not any"
"other identities which may be impacted (this will not affect most use cases)")
.def("enable_for_sync", &Identity::enable_for_sync,
"Enable own identity for p≡p sync.\n\n"
"Only use this on own identities, which are used as accounts.\n")
.def("disable_for_sync", &Identity::disable_for_sync,
"Disable own identity for p≡p sync.\n\n"
"Only use this on own identities, which are used as accounts.\n")
.add_property("address", (string(Identity::*)()) &Identity::address,
(void(Identity::*)(string)) &Identity::address,
"email address or URI")
.add_property("fpr", (string(Identity::*)()) &Identity::fpr,
(void(Identity::*)(string)) &Identity::fpr,
"key ID (full fingerprint, hex encoded)")
.add_property("user_id", (string(Identity::*)()) &Identity::user_id,
(void(Identity::*)(string)) &Identity::user_id,
"ID of person associated or 'pEp_own_userId' if own identity")
.add_property("username", (string(Identity::*)()) &Identity::username,
(void(Identity::*)(string)) &Identity::username,
"name in full of person associated")
.add_property("comm_type", (int(Identity::*)())
(PEP_comm_type(Identity::*)()) &Identity::comm_type,
(void(Identity::*)(int))
(void(Identity::*)(::PEP_comm_type)) &Identity::comm_type,
"communication type, first rating level (p≡p internal)")
.add_property("lang", (string(Identity::*)()) &Identity::lang,
(void(Identity::*)(string)) &Identity::lang,
"ISO 639-1 language code")
.add_property("flags", (identity_flags_t(Identity::*)()) &Identity::flags,
(void(Identity::*)(::identity_flags_t)) &Identity::flags,
"flags (p≡p internal)")
.add_property("rating", &Identity::rating, "rating of Identity")
.add_property("color", &Identity::color, "color of Identity as PEP_color")
.add_property("is_pEp_user", &Identity::is_pEp_user, "True if this is an identity of a pEp user")
.def("__deepcopy__", &Identity::deepcopy)
.def("update", &Identity::update, "update Identity")
.def("__copy__", &Identity::copy);
identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId"; identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId";
auto blob_class = class_<Message::Blob>("Blob", "Blob(data, mime_type='', filename='')\n" auto blob_class = class_<Message::Blob>("Blob",
"\n" "Blob(data, mime_type='', filename='')\n"
"Binary large object\n" "\n"
"\n" "Binary large object\n"
" data bytes-like object\n" "\n"
" mime_type MIME type for the data\n" " data bytes-like object\n"
" filename filename to store the data\n", boost::python::init<object, char const *, char const *>(args("data", "mime_type", "filename"))).def(boost::python::init<object, string>()).def(boost::python::init<object>()) " mime_type MIME type for the data\n"
.def("__repr__", &Message::Blob::_repr).def("__len__", &Message::Blob::size, "size of Blob data in bytes").def("decode", (string(Message::Blob::*)())&Message::Blob::decode).def("decode", (string(Message::Blob::*)(string))&Message::Blob::decode, "text = blob.decode(encoding='')\n" " filename filename to store the data\n",
"\n" bp::init< bp::object, char const*, char const* >(bp::args("data", "mime_type", "filename")))
"decode Blob data into string depending on MIME type if encoding=''\n" .def(bp::init<bp::object, string>())
"\n" .def(bp::init<bp::object>())
" mime_type='application/pEp.sync' decode as 'pEp.sync'\n" .def("__repr__", &Message::Blob::_repr)
" mime_type='application/pEp.keyreset' decode as 'pEp.keyreset'\n" .def("__len__", &Message::Blob::size, "size of Blob data in bytes")
" other mime_type decode as 'ascii' by default\n") .def("decode", (string(Message::Blob::*)()) &Message::Blob::decode)
.add_property("mime_type", (string(Message::Blob::*)())&Message::Blob::mime_type, (void (Message::Blob::*)(string))&Message::Blob::mime_type, "MIME type of object in Blob") .def("decode", (string(Message::Blob::*)(string)) &Message::Blob::decode,
.add_property("filename", (string(Message::Blob::*)())&Message::Blob::filename, (void (Message::Blob::*)(string))&Message::Blob::filename, "filename of object in Blob"); "text = blob.decode(encoding='')\n"
"\n"
"decode Blob data into string depending on MIME type if encoding=''\n"
"\n"
" mime_type='application/pEp.sync' decode as 'pEp.sync'\n"
" mime_type='application/pEp.keyreset' decode as 'pEp.keyreset'\n"
" other mime_type decode as 'ascii' by default\n"
)
.add_property("mime_type", (string(Message::Blob::*)()) &Message::Blob::mime_type,
(void(Message::Blob::*)(string)) &Message::Blob::mime_type,
"MIME type of object in Blob")
.add_property("filename", (string(Message::Blob::*)()) &Message::Blob::filename,
(void(Message::Blob::*)(string)) &Message::Blob::filename,
"filename of object in Blob");
((PyTypeObject *)(void *)blob_class.ptr())->tp_as_buffer = &Message::Blob::bp; ((PyTypeObject *)(void *)blob_class.ptr())->tp_as_buffer = &Message::Blob::bp;
auto message_class = class_<Message>("Message", "Message(dir=1, from=None)\n" auto message_class = class_<Message>("Message",
"\n" "Message(dir=1, from=None)\n"
"new p≡p message\n" "\n"
"\n" "new p≡p message\n"
" dir 1 for outgoing, 2 for incoming\n" "\n"
" from Identity() of sender\n" " dir 1 for outgoing, 2 for incoming\n"
"\n" " from Identity() of sender\n"
"Message(mime_text)\n" "\n"
"\n" "Message(mime_text)\n"
"new incoming p≡p message\n" "\n"
"\n" "new incoming p≡p message\n"
" mime_text text in Multipurpose Internet Mail Extensions format\n").def(boost::python::init<int>()).def(boost::python::init<int, Identity *>()).def(boost::python::init<string>()) "\n"
.def("__str__", &Message::_str, "the string representation of a Message is it's MIME text").def("__repr__", &Message::_repr) " mime_text text in Multipurpose Internet Mail Extensions format\n"
.add_property("dir", (int (Message::*)())(PEP_msg_direction(Message::*)())&Message::dir, (void (Message::*)(int))(void (Message::*)(PEP_msg_direction))&Message::dir, "0: incoming, 1: outgoing message") )
.add_property("id", (string(Message::*)())&Message::id, (void (Message::*)(string))&Message::id, "message ID").add_property("shortmsg", (string(Message::*)())&Message::shortmsg, (void (Message::*)(string))&Message::shortmsg, "subject or short message") .def(bp::init<int>())
.add_property("longmsg", (string(Message::*)())&Message::longmsg, (void (Message::*)(string))&Message::longmsg, "body or long version of message") .def(bp::init<int, Identity *>())
.add_property("longmsg_formatted", (string(Message::*)())&Message::longmsg_formatted, (void (Message::*)(string))&Message::longmsg_formatted, "HTML body or fromatted long version of message") .def(bp::init<string>())
.add_property("attachments", (boost::python::tuple(Message::*)())&Message::attachments, (void (Message::*)(boost::python::list))&Message::attachments, "tuple of Blobs with attachments; setting moves Blobs to attachment tuple") .def("__str__", &Message::_str,
.add_property("sent", (time_t(Message::*)())&Message::sent, (void (Message::*)(time_t))&Message::sent, "time when message was sent in UTC seconds since epoch") "the string representation of a Message is it's MIME text"
.add_property("recv", (time_t(Message::*)())&Message::recv, (void (Message::*)(time_t))&Message::recv, "time when message was received in UTC seconds since epoch") )
.add_property("from_", (Identity(Message::*)())&Message::from, (void (Message::*)(object))&Message::from, "identity where message is from") .def("__repr__", &Message::_repr)
.add_property("to", (boost::python::list(Message::*)())&Message::to, (void (Message::*)(boost::python::list))&Message::to, "list of identities message is going to") .add_property("dir", (int(Message::*)())
.add_property("recv_by", (Identity(Message::*)())&Message::recv_by, (void (Message::*)(object))&Message::recv_by, "identity where message was received by") (PEP_msg_direction(Message::*)()) &Message::dir,
.add_property("cc", (boost::python::list(Message::*)())&Message::cc, (void (Message::*)(boost::python::list))&Message::cc, "list of identities message is going cc") (void(Message::*)(int))
.add_property("bcc", (boost::python::list(Message::*)())&Message::bcc, (void (Message::*)(boost::python::list))&Message::bcc, "list of identities message is going bcc") (void(Message::*)(PEP_msg_direction)) &Message::dir,
.add_property("reply_to", (boost::python::list(Message::*)())&Message::reply_to, (void (Message::*)(boost::python::list))&Message::reply_to, "list of identities where message will be replied to") "0: incoming, 1: outgoing message")
.add_property("in_reply_to", (boost::python::list(Message::*)())&Message::in_reply_to, (void (Message::*)(boost::python::list))&Message::in_reply_to, "in_reply_to list") .add_property("id", (string(Message::*)()) &Message::id,
.add_property("references", (boost::python::list(Message::*)())&Message::references, (void (Message::*)(boost::python::list))&Message::references, "message IDs of messages this one is referring to") (void(Message::*)(string)) &Message::id,
.add_property("keywords", (boost::python::list(Message::*)())&Message::keywords, (void (Message::*)(boost::python::list))&Message::keywords, "keywords this message should be stored under") "message ID")
.add_property("comments", (string(Message::*)())&Message::comments, (void (Message::*)(string))&Message::comments, "comments added to message").add_property("opt_fields", (dict(Message::*)())&Message::opt_fields, (void (Message::*)(dict))&Message::opt_fields, "opt_fields of message") .add_property("shortmsg", (string(Message::*)()) &Message::shortmsg,
.add_property("enc_format", (int (Message::*)())(PEP_enc_format(Message::*)())&Message::enc_format, (void (Message::*)(int))(void (Message::*)(::PEP_enc_format))&Message::enc_format, "0: unencrypted, 1: inline PGP, 2: S/MIME, 3: PGP/MIME, 4: p≡p format") (void(Message::*)(string)) &Message::shortmsg,
.def("encrypt", (Message(Message::*)())&Message::encrypt).def("encrypt", (Message(Message::*)(boost::python::list))&Message::_encrypt).def("encrypt", (Message(Message::*)(boost::python::list, int))&Message::_encrypt) "subject or short message")
.def("encrypt", (Message(Message::*)(boost::python::list, int, int))&Message::_encrypt, "msg2 = msg1.encrypt(extra_keys=[], enc_format='pEp', flags=0)\n" .add_property("longmsg", (string(Message::*)()) &Message::longmsg,
"\n" (void(Message::*)(string)) &Message::longmsg,
"encrypts a p≡p message and returns the encrypted message\n" "body or long version of message")
"\n" .add_property("longmsg_formatted", (string(Message::*)()) &Message::longmsg_formatted,
" extra_keys list of strings with fingerprints for extra keys to use\n" (void(Message::*)(string)) &Message::longmsg_formatted,
" for encryption\n" "HTML body or fromatted long version of message")
" enc_format 0 for none, 1 for partitioned, 2 for S/MIME,\n" .add_property("attachments", (bp::tuple(Message::*)()) &Message::attachments,
" 3 for PGP/MIME, 4 for pEp\n" (void(Message::*)(bp::list)) &Message::attachments,
" flags 1 is force encryption\n").def("decrypt", &Message::decrypt, boost::python::arg("flags") = 0, "msg2, keys, rating, flags = msg1.decrypt()\n" "tuple of Blobs with attachments; setting moves Blobs to attachment tuple")
"\n" .add_property("sent", (time_t(Message::*)()) &Message::sent,
"decrypts a p≡p message and returns a tuple with data\n" (void(Message::*)(time_t)) &Message::sent,
"\n" "time when message was sent in UTC seconds since epoch")
" msg the decrypted p≡p message\n" .add_property("recv", (time_t(Message::*)()) &Message::recv,
" keys a list of keys being used\n" (void(Message::*)(time_t)) &Message::recv,
" rating the rating of the message as integer\n" "time when message was received in UTC seconds since epoch")
" flags flags set while decryption\n") .add_property("from_", (Identity(Message::*)()) &Message::from,
.add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have").add_property("outgoing_color", &Message::outgoing_color, "color outgoing message will have as PEP_color").def("__deepcopy__", &Message::deepcopy).def("__copy__", &Message::copy); (void(Message::*)(bp::object)) &Message::from,
"identity where message is from")
.add_property("to", (bp::list(Message::*)()) &Message::to,
(void(Message::*)(bp::list)) &Message::to,
"list of identities message is going to")
.add_property("recv_by", (Identity(Message::*)()) &Message::recv_by,
(void(Message::*)(bp::object)) &Message::recv_by,
"identity where message was received by")
.add_property("cc", (bp::list(Message::*)()) &Message::cc,
(void(Message::*)(bp::list)) &Message::cc,
"list of identities message is going cc")
.add_property("bcc", (bp::list(Message::*)()) &Message::bcc,
(void(Message::*)(bp::list)) &Message::bcc,
"list of identities message is going bcc")
.add_property("reply_to", (bp::list(Message::*)()) &Message::reply_to,
(void(Message::*)(bp::list)) &Message::reply_to,
"list of identities where message will be replied to")
.add_property("in_reply_to", (bp::list(Message::*)()) &Message::in_reply_to,
(void(Message::*)(bp::list)) &Message::in_reply_to,
"in_reply_to list")
.add_property("references", (bp::list(Message::*)()) &Message::references,
(void(Message::*)(bp::list)) &Message::references,
"message IDs of messages this one is referring to")
.add_property("keywords", (bp::list(Message::*)()) &Message::keywords,
(void(Message::*)(bp::list)) &Message::keywords,
"keywords this message should be stored under")
.add_property("comments", (string(Message::*)()) &Message::comments,
(void(Message::*)(string)) &Message::comments,
"comments added to message")
.add_property("opt_fields", (bp::dict(Message::*)()) &Message::opt_fields,
(void(Message::*)(bp::dict)) &Message::opt_fields,
"opt_fields of message")
.add_property("enc_format", (int(Message::*)())
(PEP_enc_format(Message::*)()) &Message::enc_format,
(void(Message::*)(int))
(void(Message::*)(::PEP_enc_format)) &Message::enc_format,
"0: unencrypted, 1: inline PGP, 2: S/MIME, 3: PGP/MIME, 4: p≡p format")
.def("encrypt", (Message(Message::*)())&Message::encrypt)
.def("encrypt", (Message(Message::*)(bp::list))&Message::_encrypt)
.def("encrypt", (Message(Message::*)(bp::list, int))&Message::_encrypt)
.def("encrypt", (Message(Message::*)(bp::list, int, int))&Message::_encrypt,
"msg2 = msg1.encrypt(extra_keys=[], enc_format='pEp', flags=0)\n"
"\n"
"encrypts a p≡p message and returns the encrypted message\n"
"\n"
" extra_keys list of strings with fingerprints for extra keys to use\n"
" for encryption\n"
" enc_format 0 for none, 1 for partitioned, 2 for S/MIME,\n"
" 3 for PGP/MIME, 4 for pEp\n"
" flags 1 is force encryption\n"
)
.def("decrypt", &Message::decrypt, bp::arg("flags")=0,
"msg2, keys, rating, flags = msg1.decrypt()\n"
"\n"
"decrypts a p≡p message and returns a tuple with data\n"
"\n"
" msg the decrypted p≡p message\n"
" keys a list of keys being used\n"
" rating the rating of the message as integer\n"
" flags flags set while decryption\n"
)
.add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have")
.add_property("outgoing_color", &Message::outgoing_color, "color outgoing message will have as PEP_color")
.def("__deepcopy__", &Message::deepcopy)
.def("__copy__", &Message::copy);
// basic API and key management API // basic API and key management API
def("update_identity", &update_identity, "update_identity(ident)\n" def("update_identity", &update_identity,
"\n" "update_identity(ident)\n"
"update identity information\n" "\n"
"call this to complete identity information when you at least have an address\n"); "update identity information\n"
def("myself", &myself, "myself(ident)\n" "call this to complete identity information when you at least have an address\n"
"\n" );
"ensures that the own identity is being complete\n" def("myself", &myself,
"supply ident.address and ident.username\n"); "myself(ident)\n"
def("trust_personal_key", &trust_personal_key, "trust_personal_key(ident)\n" "\n"
"\n" "ensures that the own identity is being complete\n"
"mark a key as trusted with a person\n"); "supply ident.address and ident.username\n"
);
enum_<::identity_flags>("identity_flags").value("PEP_idf_not_for_sync", ::PEP_idf_not_for_sync).value("PEP_idf_list", ::PEP_idf_list).value("PEP_idf_devicegroup", ::PEP_idf_devicegroup); def("trust_personal_key", &trust_personal_key,
"trust_personal_key(ident)\n"
def("set_identity_flags", &set_identity_flags, "set_identity_flags(ident, flags)\n" "\n"
"\n" "mark a key as trusted with a person\n"
"set identity flags\n"); );
def("unset_identity_flags", &unset_identity_flags, "unset_identity_flags(ident, flags)\n" enum_<::identity_flags>("identity_flags")
"\n" .value("PEP_idf_not_for_sync", ::PEP_idf_not_for_sync)
"unset identity flags\n"); .value("PEP_idf_list", ::PEP_idf_list)
.value("PEP_idf_devicegroup", ::PEP_idf_devicegroup);
def("key_reset_trust", &key_reset_trust, "key_reset_trust(ident)\n"
"\n" def("set_identity_flags", &set_identity_flags,
"reset trust bit or explicitly mistrusted status for an identity and " "set_identity_flags(ident, flags)\n"
"its accompanying key/user_id pair\n"); "\n"
"set identity flags\n"
def("import_key", &import_key, "private_key_list = import_key(key_data)\n" );
"\n"
"import key(s) from key_data\n"); def("unset_identity_flags", &unset_identity_flags,
"unset_identity_flags(ident, flags)\n"
def("export_key", &export_key, "key_data = export_key(identity)\n" "\n"
"\n" "unset identity flags\n"
"export key(s) of identity\n"); );
def("export_secret_key", &export_secret_key, "key_data = export_seret_key(identity)\n" def("key_reset_trust", &key_reset_trust,
"\n" "key_reset_trust(ident)\n"
"export secret key(s) of identity\n"); "\n"
"reset trust bit or explicitly mistrusted status for an identity and "
def("set_own_key", &set_own_key, "set_own_key(me, fpr)\n" "its accompanying key/user_id pair\n"
"\n" );
"mark a key as an own key, and make it the default key\n"
"\n" def("import_key", &import_key,
"me Own identity for which to add the existing key\n" "private_key_list = import_key(key_data)\n"
"fpr The fingerprint of the key to be added\n" "\n"
"\n" "import key(s) from key_data\n"
"me->address, me->user_id and me->username must be set to valid data\n" );
"myself() is called by set_own_key() without key generation\n"
"me->flags are ignored\n" def("export_key", &export_key,
"me->address must not be an alias\n" "key_data = export_key(identity)\n"
"me->fpr will be ignored and replaced by fpr\n"); "\n"
"export key(s) of identity\n"
);
def("export_secret_key", &export_secret_key,
"key_data = export_seret_key(identity)\n"
"\n"
"export secret key(s) of identity\n"
);
def("set_own_key", &set_own_key,
"set_own_key(me, fpr)\n"
"\n"
"mark a key as an own key, and make it the default key\n"
"\n"
"me Own identity for which to add the existing key\n"
"fpr The fingerprint of the key to be added\n"
"\n"
"me->address, me->user_id and me->username must be set to valid data\n"
"myself() is called by set_own_key() without key generation\n"
"me->flags are ignored\n"
"me->address must not be an alias\n"
"me->fpr will be ignored and replaced by fpr\n"
);
// message API // message API
enum_<::PEP_rating>("rating").value("_undefined", ::PEP_rating_undefined).value("cannot_decrypt", ::PEP_rating_cannot_decrypt).value("have_no_key", ::PEP_rating_have_no_key).value("unencrypted", ::PEP_rating_unencrypted).value("unreliable", ::PEP_rating_unreliable) enum_<::PEP_rating>("rating")
.value("reliable", ::PEP_rating_reliable).value("trusted", ::PEP_rating_trusted).value("trusted_and_anonymized", ::PEP_rating_trusted_and_anonymized).value("fully_anonymous", ::PEP_rating_fully_anonymous).value("mistrust", ::PEP_rating_mistrust).value("b0rken", ::PEP_rating_b0rken) .value("_undefined", ::PEP_rating_undefined)
.value("under_attack", ::PEP_rating_under_attack); .value("cannot_decrypt", ::PEP_rating_cannot_decrypt)
.value("have_no_key", ::PEP_rating_have_no_key)
enum_<::PEP_color>("colorvalue").value("no_color", ::PEP_color_no_color).value("yellow", ::PEP_color_yellow).value("green", ::PEP_color_green).value("red", ::PEP_color_red); .value("unencrypted", ::PEP_rating_unencrypted)
.value("unreliable", ::PEP_rating_unreliable)
def("incoming_message", &incoming_message, "msg = incoming_message(mime_text)\n" .value("reliable", ::PEP_rating_reliable)
"\n" .value("trusted", ::PEP_rating_trusted)
"create an incoming message from a MIME text"); .value("trusted_and_anonymized", ::PEP_rating_trusted_and_anonymized)
def("outgoing_message", &outgoing_message, "msg = outgoing_message(ident)\n" .value("fully_anonymous", ::PEP_rating_fully_anonymous)
"\n" .value("mistrust", ::PEP_rating_mistrust)
"create an outgoing message using an own identity"); .value("b0rken", ::PEP_rating_b0rken)
def("color", &_color, "c = color(rating)\n" .value("under_attack", ::PEP_rating_under_attack);
"\n"
"calculate color value out of rating. Returns PEP_color"); enum_<::PEP_color>("colorvalue")
def("trustwords", &_trustwords, "text = trustwords(ident_own, ident_partner)\n" .value("no_color", ::PEP_color_no_color)
"\n" .value("yellow", ::PEP_color_yellow)
"calculate trustwords for two Identities"); .value("green", ::PEP_color_green)
.value("red", ::PEP_color_red);
def("incoming_message", &incoming_message,
"msg = incoming_message(mime_text)\n"
"\n"
"create an incoming message from a MIME text"
);
def("outgoing_message", &outgoing_message,
"msg = outgoing_message(ident)\n"
"\n"
"create an outgoing message using an own identity"
);
def("color", &_color,
"c = color(rating)\n"
"\n"
"calculate color value out of rating. Returns PEP_color"
);
def("trustwords", &_trustwords,
"text = trustwords(ident_own, ident_partner)\n"
"\n"
"calculate trustwords for two Identities");
// Sync API // Sync API
enum_<::sync_handshake_signal>("sync_handshake_signal").value("SYNC_NOTIFY_UNDEFINED", ::SYNC_NOTIFY_UNDEFINED).value("SYNC_NOTIFY_INIT_ADD_OUR_DEVICE", ::SYNC_NOTIFY_INIT_ADD_OUR_DEVICE).value("SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE", ::SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE) enum_<::sync_handshake_signal>("sync_handshake_signal")
.value("SYNC_NOTIFY_INIT_FORM_GROUP", ::SYNC_NOTIFY_INIT_FORM_GROUP).value("SYNC_NOTIFY_TIMEOUT", ::SYNC_NOTIFY_TIMEOUT).value("SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED", ::SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED).value("SYNC_NOTIFY_ACCEPTED_GROUP_CREATED", ::SYNC_NOTIFY_ACCEPTED_GROUP_CREATED) .value("SYNC_NOTIFY_UNDEFINED", ::SYNC_NOTIFY_UNDEFINED)
.value("SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED", ::SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED).value("SYNC_NOTIFY_SOLE", ::SYNC_NOTIFY_SOLE).value("SYNC_NOTIFY_IN_GROUP", ::SYNC_NOTIFY_IN_GROUP); .value("SYNC_NOTIFY_INIT_ADD_OUR_DEVICE", ::SYNC_NOTIFY_INIT_ADD_OUR_DEVICE)
.value("SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE", ::SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE)
// auto user_interface_class = class_<UserInterface, UserInterface_callback, boost::noncopyable>( .value("SYNC_NOTIFY_INIT_FORM_GROUP", ::SYNC_NOTIFY_INIT_FORM_GROUP)
// "UserInterface", .value("SYNC_NOTIFY_TIMEOUT", ::SYNC_NOTIFY_TIMEOUT)
// "class MyUserInterface(UserInterface):\n" .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED", ::SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED)
// " def notifyHandshake(self, me, partner):\n" .value("SYNC_NOTIFY_ACCEPTED_GROUP_CREATED", ::SYNC_NOTIFY_ACCEPTED_GROUP_CREATED)
// " ...\n" .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED", ::SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED)
// "\n" .value("SYNC_NOTIFY_SOLE", ::SYNC_NOTIFY_SOLE)
// "p≡p User Interface class\n" .value("SYNC_NOTIFY_IN_GROUP", ::SYNC_NOTIFY_IN_GROUP);
// "To be used as a mixin\n"
// ) // auto user_interface_class = class_<UserInterface, UserInterface_callback, boost::noncopyable>(
// .def("notifyHandshake", &UserInterface::notifyHandshake, // "UserInterface",
// "notifyHandshake(self, me, partner)\n" // "class MyUserInterface(UserInterface):\n"
// "\n" // " def notifyHandshake(self, me, partner):\n"
// " me own identity\n" // " ...\n"
// " partner identity of communication partner\n" // "\n"
// "\n" // "p≡p User Interface class\n"
// "overwrite this method with an implementation of a handshake dialog") // "To be used as a mixin\n"
// .def("deliverHandshakeResult", &UserInterface::deliverHandshakeResult, // )
// boost::python::arg("identities")=object(), // .def("notifyHandshake", &UserInterface::notifyHandshake,
// "deliverHandshakeResult(self, result, identities=None)\n" // "notifyHandshake(self, me, partner)\n"
// "\n" // "\n"
// " result -1: cancel, 0: accepted, 1: rejected\n" // " me own identity\n"
// " identities list of identities to share or None for all\n" // " partner identity of communication partner\n"
// "\n" // "\n"
// "call to deliver the handshake result of the handshake dialog" // "overwrite this method with an implementation of a handshake dialog")
// ); // .def("deliverHandshakeResult", &UserInterface::deliverHandshakeResult,
// bp::arg("identities")=object(),
def("deliver_handshake_result", &deliverHandshakeResult, 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("start_sync", &start_sync, "start_sync()\n"
"\n" def("deliver_handshake_result", &deliverHandshakeResult, bp::arg("identities")=bp::object(),
"starts the sync thread"); "deliverHandshakeResult(self, result, identities=None)\n"
"\n"
def("shutdown_sync", &shutdown_sync, "shutdown_sync()\n" " result -1: cancel, 0: accepted, 1: rejected\n"
"\n" " identities list of identities to share or None for all\n"
"call this from another thread to shut down the sync thread\n"); "\n"
"call to deliver the handshake result of the handshake dialog"
def("debug_color", &debug_color, "for debug builds set ANSI color value"); );
def("leave_device_group", &leave_device_group, "leave_device_group()\n" def("start_sync", &start_sync,
"\n" "start_sync()\n"
"call this for a grouped device, which should leave\n"); "\n"
"starts the sync thread"
def("is_sync_active", &is_sync_active, "is_sync_active()\n" );
"\n"
"True if sync is active, False otherwise\n"); def("shutdown_sync", &shutdown_sync,
"shutdown_sync()\n"
"\n"
"call this from another thread to shut down the sync thread\n"
);
def("debug_color", &debug_color,
"for debug builds set ANSI color value");
def("leave_device_group", &leave_device_group,
"leave_device_group()\n"
"\n"
"call this for a grouped device, which should leave\n"
);
def("is_sync_active", &is_sync_active,
"is_sync_active()\n"
"\n"
"True if sync is active, False otherwise\n"
);
// codecs // codecs
call<object>(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search)); bp::call< bp::object >(((bp::object)(bp::import("codecs").attr("register"))).ptr(), make_function(sync_search));
call<object>(((object)(import("codecs").attr("register"))).ptr(), make_function(distribution_search)); bp::call< bp::object >(((bp::object)(bp::import("codecs").attr("register"))).ptr(), make_function(distribution_search));
} }
} // namespace PythonAdapter } // namespace PythonAdapter
} // namespace pEp } // namespace pEp

48
src/pEp/_pEp/str_attr.cc

@ -12,17 +12,17 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
using namespace boost::python; namespace bp = boost::python;
using namespace boost::locale; namespace bl = boost::locale;
object repr(object s) { bp::object repr(bp::object s) {
return s.attr("__repr__")(); return s.attr("__repr__")();
} }
string repr(string s) { string repr(string s) {
str _s = s.c_str(); bp::str _s = s.c_str();
object _r = _s.attr("__repr__")(); bp::object _r = _s.attr("__repr__")();
string r = extract<string>(_r); string r = bp::extract<string>(_r);
return r; return r;
} }
@ -34,7 +34,7 @@ string str_attr(char *&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, bl::norm_nfc);
free(str); free(str);
str = strdup(normalized.c_str()); str = strdup(normalized.c_str());
if (!str) { if (!str) {
@ -55,18 +55,18 @@ void timestamp_attr(::timestamp *&ts, time_t value) {
ts = ::new_timestamp(value); ts = ::new_timestamp(value);
} }
boost::python::list strlist_attr(::stringlist_t *&sl) { bp::list strlist_attr(::stringlist_t *&sl) {
boost::python::list result; bp::list result;
for (::stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) { for (::stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) {
string s(_sl->value); string s(_sl->value);
result.append(object(s)); result.append(bp::object(s));
} }
return result; return result;
} }
void strlist_attr(::stringlist_t *&sl, boost::python::list value) { void strlist_attr(::stringlist_t *&sl, bp::list value) {
::stringlist_t *_sl = ::new_stringlist(NULL); ::stringlist_t *_sl = ::new_stringlist(NULL);
if (!_sl) { if (!_sl) {
throw bad_alloc(); throw bad_alloc();
@ -74,12 +74,12 @@ void strlist_attr(::stringlist_t *&sl, boost::python::list value) {
::stringlist_t *_s = _sl; ::stringlist_t *_s = _sl;
for (int i = 0; i < len(value); i++) { for (int i = 0; i < len(value); i++) {
extract<string> extract_string(value[i]); bp::extract<string> extract_string(value[i]);
if (!extract_string.check()) { if (!extract_string.check()) {
free_stringlist(_sl); free_stringlist(_sl);
} }
string s = extract_string(); string s = extract_string();
s = normalize(s, norm_nfc); s = normalize(s, bl::norm_nfc);
_s = stringlist_add(_s, s.c_str()); _s = stringlist_add(_s, s.c_str());
if (!_s) { if (!_s) {
free_stringlist(_sl); free_stringlist(_sl);
@ -91,8 +91,8 @@ void strlist_attr(::stringlist_t *&sl, boost::python::list value) {
sl = _sl; sl = _sl;
} }
dict strdict_attr(::stringpair_list_t *&spl) { bp::dict strdict_attr(::stringpair_list_t *&spl) {
dict result; bp::dict result;
for (::stringpair_list_t *_spl = spl; _spl && _spl->value; _spl = _spl->next) { for (::stringpair_list_t *_spl = spl; _spl && _spl->value; _spl = _spl->next) {
::stringpair_t *p = _spl->value; ::stringpair_t *p = _spl->value;
@ -107,7 +107,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, bp::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();
@ -115,17 +115,17 @@ void strdict_attr(::stringpair_list_t *&spl, dict value) {
::stringpair_list_t *_s = _spl; ::stringpair_list_t *_s = _spl;
for (int i = 0; i < len(value); i++) { for (int i = 0; i < len(value); i++) {
extract<string> extract_key(value.keys()[i]); bp::extract<string> extract_key(value.keys()[i]);
extract<string> extract_value(value.values()[i]); bp::extract<string> extract_value(value.values()[i]);
if (!(extract_key.check() && extract_value.check())) { if (!(extract_key.check() && extract_value.check())) {
free_stringpair_list(_spl); free_stringpair_list(_spl);
} }
string key = extract_key(); string key = extract_key();
key = normalize(key, norm_nfc); key = normalize(key, bl::norm_nfc);
string _value = extract_value(); string _value = extract_value();
_value = normalize(_value, norm_nfc); _value = normalize(_value, bl::norm_nfc);
::stringpair_t *pair = ::new_stringpair(key.c_str(), _value.c_str()); ::stringpair_t *pair = ::new_stringpair(key.c_str(), _value.c_str());
if (!pair) { if (!pair) {
free_stringpair_list(_spl); free_stringpair_list(_spl);
@ -142,7 +142,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(bp::list l) {
::stringlist_t *result = ::new_stringlist(NULL); ::stringlist_t *result = ::new_stringlist(NULL);
if (!result) { if (!result) {
throw bad_alloc(); throw bad_alloc();
@ -150,7 +150,7 @@ void strdict_attr(::stringpair_list_t *&spl, dict value) {
::stringlist_t *_s = result; ::stringlist_t *_s = result;
for (int i = 0; i < len(l); i++) { for (int i = 0; i < len(l); i++) {
extract<string> extract_string(l[i]); bp::extract<string> extract_string(l[i]);
if (!extract_string.check()) { if (!extract_string.check()) {
free_stringlist(result); free_stringlist(result);
} }
@ -165,8 +165,8 @@ void strdict_attr(::stringpair_list_t *&spl, dict value) {
return result; return result;
} }
boost::python::list from_stringlist(const ::stringlist_t *sl) { bp::list from_stringlist(const ::stringlist_t *sl) {
boost::python::list result; bp::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;
result.append(s); result.append(s);

17
src/pEp/_pEp/str_attr.hh

@ -16,10 +16,9 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using std::string; using std::string;
using boost::python::object; namespace bp = boost::python;
using boost::python::dict;
object repr(object s); bp::object repr(bp::object s);
string repr(string s); string repr(string s);
@ -31,17 +30,17 @@ time_t timestamp_attr(::timestamp *&ts);
void timestamp_attr(::timestamp *&ts, time_t value); void timestamp_attr(::timestamp *&ts, time_t value);
boost::python::list strlist_attr(::stringlist_t *&sl); bp::list strlist_attr(::stringlist_t *&sl);
void strlist_attr(::stringlist_t *&sl, boost::python::list value); void strlist_attr(::stringlist_t *&sl, bp::list value);
dict strdict_attr(::stringpair_list_t *&spl); bp::dict strdict_attr(::stringpair_list_t *&spl);
void strdict_attr(::stringpair_list_t *&spl, dict value); void strdict_attr(::stringpair_list_t *&spl, bp::dict value);
::stringlist_t *to_stringlist(boost::python::list l); ::stringlist_t *to_stringlist(bp::list l);
boost::python::list from_stringlist(const ::stringlist_t *sl); bp::list from_stringlist(const ::stringlist_t *sl);
} /* namespace PythonAdapter */ } /* namespace PythonAdapter */
} /* namespace pEp */ } /* namespace pEp */

12
src/pEp/_pEp/user_interface.cc

@ -10,7 +10,7 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
using namespace std; using namespace std;
using namespace boost::python; //namespace bp = boost::python;
UserInterface *UserInterface::_ui = nullptr; UserInterface *UserInterface::_ui = nullptr;
@ -51,9 +51,9 @@ UserInterface_callback::~UserInterface_callback() {
return ::PEP_STATUS_OK; return ::PEP_STATUS_OK;
} }
void UserInterface::deliverHandshakeResult(int result, object identities) { void UserInterface::deliverHandshakeResult(int result, bp::object identities) {
identity_list *shared_identities = nullptr; identity_list *shared_identities = nullptr;
if (identities != boost::python::api::object() && boost::python::len(identities)) { if (identities != bp::api::object() && bp::len(identities)) {
shared_identities = new_identity_list(nullptr); shared_identities = new_identity_list(nullptr);
if (!shared_identities) { if (!shared_identities) {
throw bad_alloc(); throw bad_alloc();
@ -61,8 +61,8 @@ void UserInterface::deliverHandshakeResult(int result, object identities) {
try { try {
identity_list *si = shared_identities; identity_list *si = shared_identities;
for (int i = 0; i < boost::python::len(identities); ++i) { for (int i = 0; i < bp::len(identities); ++i) {
Identity ident = extract<Identity>(identities[i]); Identity ident = bp::extract<Identity>(identities[i]);
si = identity_list_add(si, ident); si = identity_list_add(si, ident);
if (!si) { if (!si) {
throw bad_alloc(); throw bad_alloc();
@ -114,7 +114,7 @@ void UserInterface::deliverHandshakeResult(int result, object identities) {
//} //}
void UserInterface_callback::notifyHandshake(Identity me, Identity partner, sync_handshake_signal signal) { void UserInterface_callback::notifyHandshake(Identity me, Identity partner, sync_handshake_signal signal) {
call_method<void>(_self, "notifyHandshake", me, partner, signal); bp::call_method<void>(_self, "notifyHandshake", me, partner, signal);
} }
} // namespace PythonAdapter } // namespace PythonAdapter

2
src/pEp/_pEp/user_interface.hh

@ -28,7 +28,7 @@ class UserInterface {
throw runtime_error("override this method"); throw runtime_error("override this method");
} }
virtual void deliverHandshakeResult(int result, object identities); virtual void deliverHandshakeResult(int result, bp::object identities);
// PEP_rating get_key_rating_for_user(string user_id, string fpr); // PEP_rating get_key_rating_for_user(string user_id, string fpr);

Loading…
Cancel
Save