Browse Source

Merge pull request 'add instance method Message.set_recv_by' (#19) from positron-set-recv-by into master

Reviewed-on: https://gitea.pep.foundation/pEp.foundation/pEpPythonAdapter/pulls/19
positron-misleading-help-string
heck 2 years ago
parent
commit
f38f65e1fb
  1. 30
      src/pEp/_pEp/message.cc
  2. 2
      src/pEp/_pEp/message.hh
  3. 7
      src/pEp/_pEp/pEpmodule.cc

30
src/pEp/_pEp/message.cc

@ -314,6 +314,36 @@ namespace pEp {
_throw_status(status); _throw_status(status);
} }
void Message::set_recv_by(Identity &new_recv_by)
{
// Validate self and the new Recv-By identity.
::message *msg_c = _msg.get();
if (msg_c->dir != ::PEP_dir_incoming) {
throw invalid_argument("message not incoming");
}
if (new_recv_by.address().empty() || new_recv_by.user_id().empty()) {
throw invalid_argument("identity incomplete");
}
if (new_recv_by.user_id() != PEP_OWN_USERID) {
throw invalid_argument("identity non-own");
}
// Make a a copy of the given identity.
::pEp_identity *new_recv_by_c = new_recv_by;
::pEp_identity *new_recv_by_copy_c = ::identity_dup(new_recv_by_c);
if (new_recv_by_copy_c == NULL) {
throw std::bad_alloc();
}
// If we have not failed yet this will succeed.
// Destroy the old Recv-By.
::free_identity(msg_c->recv_by);
msg_c->recv_by = NULL;
// Use the copy as the new Recv-By.
msg_c->recv_by = new_recv_by_copy_c;
}
Message Message::encrypt() Message Message::encrypt()
{ {
boost::python::list extra; boost::python::list extra;

2
src/pEp/_pEp/message.hh

@ -303,6 +303,8 @@ namespace pEp {
void remove_opt_field(string name); void remove_opt_field(string name);
void set_opt_field(string name, string value); void set_opt_field(string name, string value);
void set_recv_by(Identity &new_recv_by);
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);

7
src/pEp/_pEp/pEpmodule.cc

@ -551,6 +551,13 @@ namespace pEp {
" msg a message\n" " msg a message\n"
" name the field name as a string\n" " name the field name as a string\n"
" value the new field value as a string\n") " value the new field value as a string\n")
.def("set_recv_by", &Message::set_recv_by,
"msg.set_recv_by(identity)\n"
"\n"
"Alters the given incoming message setting or replacing the Recv-By\n"
"field with the given own identity.\n"
"\n"
" identity an own identity, on which myself has been called already\n")
.def("encrypt", (Message(Message::*)()) & Message::encrypt) .def("encrypt", (Message(Message::*)()) & Message::encrypt)
.def( .def(
"encrypt", "encrypt",

Loading…
Cancel
Save