Skip to content

Add ability to query libxml version number #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,18 @@ static PyObject* PyXmlSec_PyShutdown(PyObject* self) {

static char PyXmlSec_GetLibXmlSecVersion__doc__[] = \
"get_libxmlsec_version() -> tuple\n"
"Returns Version tuple of wrapped libxml library.";
"Returns Version tuple of wrapped libxmlsec library.";
static PyObject* PyXmlSec_GetLibXmlSecVersion() {
return Py_BuildValue("(iii)", XMLSEC_VERSION_MAJOR, XMLSEC_VERSION_MINOR, XMLSEC_VERSION_SUBMINOR);
}

static char PyXmlSec_GetLibXmlVersion__doc__[] = \
"get_libxml_version() -> tuple\n"
"Returns Version tuple of wrapped libxml library.";
static PyObject* PyXmlSec_GetLibXmlVersion() {
return Py_BuildValue("(iii)", XMLSEC_LIBXML_VERSION_MAJOR, XMLSEC_LIBXML_VERSION_MINOR, XMLSEC_LIBXML_VERSION_PATCH);
}

static char PyXmlSec_PyEnableDebugOutput__doc__[] = \
"enable_debug_trace(enabled) -> None\n"
"Enables or disables calling LibXML2 callback from the default errors callback.\n\n"
Expand Down Expand Up @@ -399,6 +406,12 @@ static PyMethodDef PyXmlSec_MainMethods[] = {
METH_NOARGS,
PyXmlSec_GetLibXmlSecVersion__doc__
},
{
"get_libxml_version",
(PyCFunction)PyXmlSec_GetLibXmlVersion,
METH_NOARGS,
PyXmlSec_GetLibXmlVersion__doc__
},
{
"enable_debug_trace",
(PyCFunction)PyXmlSec_PyEnableDebugOutput,
Expand Down
7 changes: 7 additions & 0 deletions src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@

#define PY_SSIZE_T_CLEAN 1

#include <libxml/xmlversion.h>
#include <xmlsec/version.h>
#include <Python.h>

#ifdef MS_WIN32
#include <windows.h>
#endif /* MS_WIN32 */

#define XMLSEC_EXTRACT_VERSION(x, y) ((x / (y)) % 100)

#define XMLSEC_LIBXML_VERSION_MAJOR XMLSEC_EXTRACT_VERSION(LIBXML_VERSION, 100 * 100)
#define XMLSEC_LIBXML_VERSION_MINOR XMLSEC_EXTRACT_VERSION(LIBXML_VERSION, 100)
#define XMLSEC_LIBXML_VERSION_PATCH XMLSEC_EXTRACT_VERSION(LIBXML_VERSION, 1)

#define XMLSEC_VERSION_HEX ((XMLSEC_VERSION_MAJOR << 16) | (XMLSEC_VERSION_MINOR << 8) | (XMLSEC_VERSION_SUBMINOR))

// XKMS support was removed in version 1.2.21
Expand Down
Loading