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; } }