diff --git a/src/message_api.cc b/src/message_api.cc index 8693925..07eca57 100644 --- a/src/message_api.cc +++ b/src/message_api.cc @@ -1,6 +1,7 @@ #include "message_api.hh" #include #include +#include namespace pEp { namespace PythonAdapter { @@ -65,6 +66,23 @@ namespace pEp { { ::config_keep_sync_msg(session, enabled); } + + string sync_decode(object buffer) + { + Py_buffer src; + int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO); + if (result) + throw invalid_argument("need a contiguous buffer to read"); + + char *dst = NULL; + PEP_STATUS status = decode_sync_msg((char *) src.buf, src.len, &dst); + PyBuffer_Release(&src); + _throw_status(status); + + string _dst(dst); + free(dst); + return _dst; + } #endif } } diff --git a/src/message_api.hh b/src/message_api.hh index 94fc9c8..fc8fa27 100644 --- a/src/message_api.hh +++ b/src/message_api.hh @@ -10,6 +10,7 @@ namespace pEp { int _color(int rating); #ifndef NDEBUG void _config_keep_sync_msg(bool enabled); + string sync_decode(object buffer); #endif } } diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 66c26e9..d7fe418 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -206,6 +206,7 @@ BOOST_PYTHON_MODULE(pEp) def("trustwords", &_trustwords, "calculate trustwords for two Identities"); #ifndef NDEBUG def("config_keep_sync_msg", &_config_keep_sync_msg, "configure if sync messages are being kept or not"); + def("sync_decode", &sync_decode, "decode sync message to XER/XML"); #endif // key sync API