Skip to content

Commit 0bad2e4

Browse files
committed
Add ability to query libxml version number
1 parent 802dff2 commit 0bad2e4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: src/main.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,18 @@ static PyObject* PyXmlSec_PyShutdown(PyObject* self) {
121121

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

129+
static char PyXmlSec_GetLibXmlVersion__doc__[] = \
130+
"get_libxml_version() -> tuple\n"
131+
"Returns Version tuple of wrapped libxml library.";
132+
static PyObject* PyXmlSec_GetLibXmlVersion() {
133+
return Py_BuildValue("(iii)", XMLSEC_LIBXML_VERSION_MAJOR, XMLSEC_LIBXML_VERSION_MINOR, XMLSEC_LIBXML_VERSION_PATCH);
134+
}
135+
129136
static char PyXmlSec_PyEnableDebugOutput__doc__[] = \
130137
"enable_debug_trace(enabled) -> None\n"
131138
"Enables or disables calling LibXML2 callback from the default errors callback.\n\n"
@@ -399,6 +406,12 @@ static PyMethodDef PyXmlSec_MainMethods[] = {
399406
METH_NOARGS,
400407
PyXmlSec_GetLibXmlSecVersion__doc__
401408
},
409+
{
410+
"get_libxml_version",
411+
(PyCFunction)PyXmlSec_GetLibXmlVersion,
412+
METH_NOARGS,
413+
PyXmlSec_GetLibXmlVersion__doc__
414+
},
402415
{
403416
"enable_debug_trace",
404417
(PyCFunction)PyXmlSec_PyEnableDebugOutput,

Diff for: src/platform.h

+7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212

1313
#define PY_SSIZE_T_CLEAN 1
1414

15+
#include <libxml/xmlversion.h>
1516
#include <xmlsec/version.h>
1617
#include <Python.h>
1718

1819
#ifdef MS_WIN32
1920
#include <windows.h>
2021
#endif /* MS_WIN32 */
2122

23+
#define XMLSEC_EXTRACT_VERSION(x, y) ((x / (y)) % 100)
24+
25+
#define XMLSEC_LIBXML_VERSION_MAJOR XMLSEC_EXTRACT_VERSION(LIBXML_VERSION, 100 * 100)
26+
#define XMLSEC_LIBXML_VERSION_MINOR XMLSEC_EXTRACT_VERSION(LIBXML_VERSION, 100)
27+
#define XMLSEC_LIBXML_VERSION_PATCH XMLSEC_EXTRACT_VERSION(LIBXML_VERSION, 1)
28+
2229
#define XMLSEC_VERSION_HEX ((XMLSEC_VERSION_MAJOR << 16) | (XMLSEC_VERSION_MINOR << 8) | (XMLSEC_VERSION_SUBMINOR))
2330

2431
// XKMS support was removed in version 1.2.21

0 commit comments

Comments
 (0)