Browse Source

add config_unencrypted_subject() and config_passive_mode()

PYADPT-55
Volker Birk 6 years ago
parent
commit
04d5597145
  1. 20
      src/adapter.cc
  2. 5
      src/adapter.hh
  3. 17
      src/pEpmodule.cc
  4. 2
      test/minimail.py
  5. 16
      test/sync_handshake.py

20
src/adapter.cc

@ -7,7 +7,8 @@
namespace pEp {
namespace PythonAdapter {
Adapter::Adapter(bool unregister_this)
: flag_unregister(unregister_this)
: flag_unregister(unregister_this), passive_mode(false),
unencrypted_subject(false)
{
session(init);
}
@ -41,8 +42,13 @@ namespace pEp {
case init:
++booked;
if (!_session)
if (!_session) {
status = ::init(&_session, _messageToSend, _inject_sync_event);
if (!status) {
::config_passive_mode(_session, passive_mode);
::config_unencrypted_subject(_session, unencrypted_subject);
}
}
break;
default:
@ -55,6 +61,16 @@ namespace pEp {
return _session;
}
void Adapter::config_passive_mode(bool enable)
{
::config_passive_mode(session(), enable);
}
void Adapter::config_unencrypted_subject(bool enable)
{
::config_unencrypted_subject(session(), enable);
}
PyObject *Adapter::ui_object(PyObject *value)
{
lock_guard<mutex> lock(mtx());

5
src/adapter.hh

@ -14,6 +14,8 @@ namespace pEp {
class Adapter {
bool flag_unregister;
bool passive_mode;
bool unencrypted_subject;
public:
Adapter(bool unregister_this = false);
@ -32,6 +34,9 @@ namespace pEp {
return q;
}
void config_passive_mode(bool enable);
void config_unencrypted_subject(bool enable);
protected:
static PyObject *ui_object(PyObject *value = nullptr);
static int _inject_sync_event(SYNC_EVENT ev, void *management);

17
src/pEpmodule.cc

@ -21,6 +21,17 @@ namespace pEp {
using namespace std;
Adapter adapter(true);
void config_passive_mode(bool enable)
{
adapter.config_passive_mode(enable);
}
void config_unencrypted_subject(bool enable)
{
adapter.config_unencrypted_subject(enable);
}
scope *_scope = NULL;
static const char *version_string = "p≡p Python adapter version 0.3";
@ -81,6 +92,12 @@ BOOST_PYTHON_MODULE(pEp)
scope().attr("about") = about();
def("config_passive_mode", pEp::PythonAdapter::config_passive_mode,
"do not attach pub keys to all messages");
def("config_unencrypted_subject", pEp::PythonAdapter::config_unencrypted_subject,
"do not encrypt the subject of messages");
auto identity_class = class_<pEp::PythonAdapter::Identity>("Identity",
"Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n"
"\n"

2
test/minimail.py

@ -82,7 +82,7 @@ def recv_all(inbox, marker):
if newer(p, inbox / marker):
with open(p, "rb") as f:
t = f.read(-1)
r.append(t)
r.append((p, t))
(inbox / marker).touch(exist_ok=True)
if not r:
sleep(1)

16
test/sync_handshake.py

@ -44,6 +44,7 @@ output = print
DONT_TRIGGER_SYNC = 0x200
SYNC_HANDSHAKE_ACCEPTED = 0
SYNC_HANDSHAKE_REJECTED = 1
def print_msg(p):
@ -85,7 +86,12 @@ class UserInterface(pEp.UserInterface):
def notifyHandshake(self, me, partner, signal):
output("on " + device_name + " signal " + str(signal) + " for identities " + str(me.fpr) + " " +
str(partner.fpr))
try:
if options.reject:
self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED)
else:
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED)
except NameError:
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED)
@ -105,11 +111,9 @@ def run(name, color=None):
try:
while True:
l = minimail.recv_all(inbox, name)
for m in l:
for n, m in l:
msg = pEp.Message(m)
msg2, keys, rating, flags = msg.decrypt()
#text = "<!-- receiving on " + device_name + " -->\n" + msg2.attachments[0].decode()
#output(text)
except KeyboardInterrupt:
pass
@ -126,6 +130,10 @@ if __name__=="__main__":
"(default: name of actual directory)")
optParser.add_option("--color", action="store", type="string",
dest="color", help="print debug output in this color", default=None)
optParser.add_option("--reject", action="store_true", dest="reject",
help="reject device group")
optParser.add_option("--accept", action="store_false", dest="reject",
help="accept device group (default)")
options, args = optParser.parse_args()
if not options.exec_for:

Loading…
Cancel
Save