Browse Source

adding message API

PYADPT-55
Volker Birk 9 years ago
parent
commit
20fc370e76
  1. 15
      src/basic_api.cc
  2. 2
      src/basic_api.hh
  3. 6
      src/identity.cc
  4. 2
      src/identity.hh
  5. 6
      src/message.cc
  6. 6
      src/message.hh
  7. 35
      src/message_api.cc
  8. 11
      src/message_api.hh
  9. 29
      src/pEpmodule.cc
  10. 1
      src/pEpmodule.hh
  11. 4
      src/str_attr.cc
  12. 2
      src/str_attr.hh

15
src/basic_api.cc

@ -4,21 +4,6 @@
namespace pEp {
namespace PythonAdapter {
void _throw_status(PEP_STATUS status)
{
if (status == PEP_STATUS_OK)
return;
if (status >= 0x400 && status <= 0x4ff)
return;
if (status == PEP_OUT_OF_MEMORY)
throw bad_alloc();
stringstream build;
build << "p≡p error: " << status;
throw runtime_error(build.str());
}
void update_identity(Identity& ident)
{
if (ident.me())

2
src/basic_api.hh

@ -4,8 +4,6 @@
namespace pEp {
namespace PythonAdapter {
void _throw_status(PEP_STATUS status);
void update_identity(Identity& ident);
void myself(Identity& ident);
}

6
src/Identity.cc → src/identity.cc

@ -102,7 +102,7 @@ namespace pEp {
return _ident->lang;
}
object identity_attr(pEp_identity *&ident)
Identity identity_attr(pEp_identity *&ident)
{
pEp_identity *_dup;
@ -113,8 +113,8 @@ namespace pEp {
if (!_dup)
throw bad_alloc();
Identity *_ident = new Identity(_dup);
return object(_ident);
Identity _ident(_dup);
return _ident;
}
void identity_attr(pEp_identity *&ident, object value)

2
src/Identity.hh → src/identity.hh

@ -52,7 +52,7 @@ namespace pEp {
void flags(identity_flags_t flags) { _ident->flags = flags; }
};
object identity_attr(pEp_identity *&ident);
Identity identity_attr(pEp_identity *&ident);
void identity_attr(pEp_identity *&ident, object value);
list identitylist_attr(identity_list *&il);

6
src/message.cc

@ -120,9 +120,11 @@ namespace pEp {
mimetext.size(), &_msg);
switch (status) {
case PEP_STATUS_OK:
if (_msg)
if (_msg) {
_msg->dir = PEP_dir_outgoing;
return;
_msg = new_message(PEP_dir_incoming);
}
_msg = new_message(PEP_dir_outgoing);
break;
case PEP_BUFFER_TOO_SMALL:

6
src/message.hh

@ -54,7 +54,7 @@ namespace pEp {
Message(PEP_msg_direction dir = PEP_dir_outgoing);
Message(string mimetext);
Message(const Message& second);
Message(message *ident);
Message(message *msg);
~Message();
operator message *();
void attach(message *ident);
@ -86,13 +86,13 @@ namespace pEp {
time_t recv() { return timestamp_attr(_msg->recv); }
void recv(time_t value) { timestamp_attr(_msg->recv, value); }
object from() { return identity_attr(_msg->from); }
Identity from() { return identity_attr(_msg->from); }
void from(object value) { identity_attr(_msg->from, value); }
list to() { return identitylist_attr(_msg->to); }
void to(list value) { identitylist_attr(_msg->to, value); }
object 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); }
list cc() { return identitylist_attr(_msg->cc); }

35
src/message_api.cc

@ -0,0 +1,35 @@
#include "message_api.hh"
#include <pEp/message_api.h>
namespace pEp {
namespace PythonAdapter {
Message encrypt_message(Message& src, list extra, int enc_format,
int flags)
{
Identity _from = src.from();
if (_from.address() == "")
throw invalid_argument("encrypt_message: src.from_.address empty");
if (_from.username() == "")
throw invalid_argument("encrypt_message: src.from_.username empty");
stringlist_t *_extra = to_stringlist(extra);
PEP_enc_format _enc_format = (PEP_enc_format) enc_format;
PEP_encrypt_flags_t _flags = (PEP_encrypt_flags_t) flags;
message *_dst = NULL;
PEP_STATUS status = encrypt_message(session, src, _extra, &_dst,
_enc_format, _flags);
free_stringlist(_extra);
_throw_status(status);
if (!_dst || _dst == src) {
Message dst(src);
return dst;
}
Message dst(_dst);
return dst;
}
}
}

11
src/message_api.hh

@ -0,0 +1,11 @@
#pragma once
#include "pEpmodule.hh"
namespace pEp {
namespace PythonAdapter {
Message encrypt_message(Message& src, list extra, int enc_format,
int flags);
}
}

29
src/pEpmodule.cc

@ -3,6 +3,7 @@
#include <string>
#include <sstream>
#include "basic_api.hh"
#include "message_api.hh"
namespace pEp {
namespace PythonAdapter {
@ -22,6 +23,22 @@ namespace pEp {
{
release(session);
}
void _throw_status(PEP_STATUS status)
{
if (status == PEP_STATUS_OK)
return;
if (status >= 0x400 && status <= 0x4ff)
return;
if (status == PEP_OUT_OF_MEMORY)
throw bad_alloc();
if (status == PEP_ILLEGAL_VALUE)
throw invalid_argument("illegal value");
stringstream build;
build << "p≡p error: " << status;
throw runtime_error(build.str());
}
}
}
@ -120,13 +137,13 @@ BOOST_PYTHON_MODULE(pEp)
.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_", (object(Message::*)()) &Message::from,
.add_property("from_", (Identity(Message::*)()) &Message::from,
(void(Message::*)(object)) &Message::from,
"identity where message is from")
.add_property("to", (list(Message::*)()) &Message::to,
(void(Message::*)(list)) &Message::to,
"list of identities message is going to")
.add_property("recv_by", (object(Message::*)()) &Message::recv_by,
.add_property("recv_by", (Identity(Message::*)()) &Message::recv_by,
(void(Message::*)(object)) &Message::recv_by,
"identity where message was received by")
.add_property("cc", (list(Message::*)()) &Message::cc,
@ -159,9 +176,17 @@ BOOST_PYTHON_MODULE(pEp)
(void(Message::*)(PEP_enc_format)) &Message::enc_format,
"0: unencrypted, 1: inline PGP, 2: S/MIME, 3: PGP/MIME, 4: p≡p format");
// basic API
def("update_identity", &update_identity, "update identity information");
def("myself", &myself, "ensures that the own identity is being complete");
// message API
def("encrypt_message", &encrypt_message, "encrypt message in memory");
// init() and release()
PyModuleDef * _def = PyModule_GetDef(scope().ptr());
_def->m_free = free_module;

1
src/pEpmodule.hh

@ -8,6 +8,7 @@
namespace pEp {
namespace PythonAdapter {
extern PEP_SESSION session;
void _throw_status(PEP_STATUS status);
}
}

4
src/str_attr.cc

@ -162,10 +162,10 @@ namespace pEp {
return result;
}
list from_stringlist(stringlist_t *sl)
list from_stringlist(const stringlist_t *sl)
{
list result;
for (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;
result.append(s);
}

2
src/str_attr.hh

@ -27,7 +27,7 @@ namespace pEp {
void strdict_attr(stringpair_list_t *&spl, dict value);
stringlist_t *to_stringlist(list l);
list from_stringlist(stringlist_t *sl);
list from_stringlist(const stringlist_t *sl);
}
}

Loading…
Cancel
Save