From b81c21aae662a0ff1197eb02d94b8566417f9aed Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sat, 6 Aug 2016 22:19:57 +0200 Subject: [PATCH] =?UTF-8?q?init=20and=20release=20p=E2=89=A1p=20session?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pEpmodule.cc | 20 ++++++++++++++++++++ src/pEpmodule.hh | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 8113b9b..9f02676 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -1,6 +1,7 @@ #include "pEpmodule.hh" #include #include +#include #include #include "Identity.hh" #include "Message.hh" @@ -15,6 +16,13 @@ namespace pEp { + PEP_VERSION + "\n"; return version; } + + PEP_SESSION session = NULL; + + static void free_module(void *) + { + release(session); + } } } @@ -139,5 +147,17 @@ BOOST_PYTHON_MODULE(pEp) (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"); + + PyModuleDef * def = PyModule_GetDef(scope().ptr()); + def->m_free = free_module; + + PEP_STATUS status = ::init(&session); + if (status != PEP_STATUS_OK) { + stringstream ss; + ss << "init session failed with error " << status; + string s; + ss >> s; + throw runtime_error(s); + } } diff --git a/src/pEpmodule.hh b/src/pEpmodule.hh index 35a83bd..d7b3c7d 100644 --- a/src/pEpmodule.hh +++ b/src/pEpmodule.hh @@ -1,12 +1,14 @@ #pragma once #include +#include namespace pEp { namespace PythonAdapter { using namespace std; const char *version_string = "p≡p Python adapter version 0.1"; + extern PEP_SESSION session; } }