From 961b0bd396d4b169915c5843f76aa6d325f0e8ae Mon Sep 17 00:00:00 2001 From: Bulat Gaifullin Date: Fri, 10 Mar 2017 20:41:50 +0300 Subject: [PATCH] fixed loading crypto library for xmlsec >1.2.21 #50 --- setup.py | 21 +++++++++++++++++---- src/main.c | 10 ++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index d783d227..0e8c6c73 100644 --- a/setup.py +++ b/setup.py @@ -21,18 +21,29 @@ def is_debug(): if is_debug(): - macroses.append(("PYXMLSEC_ENABLE_DEBUG", 1)) + macroses.append(("PYXMLSEC_ENABLE_DEBUG", "1")) cflags.extend(["-Wall", "-O0"]) else: cflags.extend(["-Os"]) -def add_to_list(target, up): +# values which requires escaping +require_escape = {"XMLSEC_CRYPTO"} + + +def add_to_list(target, up, need_to_escape=None): if up is None: return target value = set(target) - value.update(up) + if need_to_escape: + for x in up: + if x[0] in need_to_escape: + value.add((x[0], '"{0}"'.format(x[1]))) + else: + value.add(x) + else: + value.update(up) target[:] = list(value) @@ -61,10 +72,12 @@ def patch_xmlsec(self): ext = self.ext_map[__name__] config = pkgconfig.parse("xmlsec1") + # need to escape XMLSEC_CRYPTO # added build flags from pkg-config - for item in ('define_macros', 'libraries', 'library_dirs', 'include_dirs'): + for item in ('libraries', 'library_dirs', 'include_dirs'): add_to_list(getattr(ext, item), config.get(item)) + add_to_list(ext.define_macros, config.get('define_macros'), {"XMLSEC_CRYPTO"}) add_to_list(ext.include_dirs, lxml.get_include()) diff --git a/src/main.c b/src/main.c index a05700a7..26842c26 100644 --- a/src/main.c +++ b/src/main.c @@ -46,7 +46,14 @@ static int PyXmlSec_Init(void) { } #ifndef XMLSEC_NO_CRYPTO_DYNAMIC_LOADING - if (xmlSecCryptoDLLoadLibrary((const xmlChar*) STRINGIFY(XMLSEC_CRYPTO)) < 0) { +#if XMLSEC_VERSION_HEX > 308 + // xmlSecGetDefaultCrypto was introduced in version 1.2.21 + const xmlChar* cryptoLib = xmlSecGetDefaultCrypto(); +#else + const xmlChar* cryptoLib = (const xmlChar*) XMLSEC_CRYPTO; +#endif + PYXMLSEC_DEBUGF("dynamic crypto library: %s", cryptoLib); + if (xmlSecCryptoDLLoadLibrary(cryptoLib) < 0) { PyXmlSec_SetLastError("cannot load crypto library for xmlsec."); PyXmlSec_Free(_FREE_XMLSEC); return -1; @@ -240,6 +247,5 @@ PYENTRY_FUNC_NAME(void) PY_MOD_RETURN(module); ON_FAIL: - Py_DECREF(module); PY_MOD_RETURN(NULL); }