Skip to content

Commit 74331b1

Browse files
committed
Fix debug trace
1 parent 2276d51 commit 74331b1

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/exception.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616

1717
#include <pythread.h>
1818

19+
#include <stdio.h>
20+
1921
// default error class
2022
PyObject* PyXmlSec_Error;
2123
PyObject* PyXmlSec_InternalError;
2224
PyObject* PyXmlSec_VerificationError;
2325

2426
static int PyXmlSec_LastErrorKey = 0;
2527

28+
static int PyXmlSec_PrintErrorMessage = 0;
29+
2630
typedef struct {
2731
const xmlChar* file;
2832
const xmlChar* func;
@@ -83,8 +87,27 @@ static void PyXmlSec_ErrorCallback(const char* file, int line, const char* func,
8387
// TODO do not allocate error object each time.
8488
PyXmlSec_ErrorHolderFree(PyXmlSec_ExchangeLastError(PyXmlSec_ErrorHolderCreate(file, line, func, object, subject, reason, msg)));
8589

86-
// also call default callback
87-
xmlSecErrorsDefaultCallback(file, line, func, object, subject, reason, msg);
90+
if (PyXmlSec_PrintErrorMessage) {
91+
const char* error_msg = NULL;
92+
xmlSecSize i;
93+
for (i = 0; (i < XMLSEC_ERRORS_MAX_NUMBER) && (xmlSecErrorsGetMsg(i) != NULL); ++i) {
94+
if(xmlSecErrorsGetCode(i) == reason) {
95+
error_msg = xmlSecErrorsGetMsg(i);
96+
break;
97+
}
98+
}
99+
100+
fprintf(stderr,
101+
"func=%s:file=%s:line=%d:obj=%s:subj=%s:error=%d:%s:%s\n",
102+
(func != NULL) ? func : "unknown",
103+
(file != NULL) ? file : "unknown",
104+
line,
105+
(object != NULL) ? object : "unknown",
106+
(subject != NULL) ? subject : "unknown",
107+
reason,
108+
(error_msg != NULL) ? error_msg : "",
109+
(msg != NULL) ? msg : "");
110+
}
88111
}
89112

90113
// pops the last error which was occurred in current thread
@@ -133,6 +156,10 @@ void PyXmlSec_ClearError(void) {
133156
PyXmlSec_ErrorHolderFree(PyXmlSec_ExchangeLastError(NULL));
134157
}
135158

159+
void PyXmlSecEnableDebugTrace(int v) {
160+
PyXmlSec_PrintErrorMessage = v;
161+
}
162+
136163
// initializes errors module
137164
int PyXmlSec_ExceptionsModule_Init(PyObject* package) {
138165
PyXmlSec_Error = NULL;

src/exception.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ void PyXmlSec_SetLastError2(PyObject* type, const char* msg);
2222

2323
void PyXmlSec_ClearError(void);
2424

25+
void PyXmlSecEnableDebugTrace(int);
26+
2527
#endif //__PYXMLSEC_EXCEPTIONS_H__

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static PyObject* PyXmlSec_PyEnableDebugOutput(PyObject *self, PyObject* args, Py
106106
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O:enable_debug_trace", kwlist, &enabled)) {
107107
return NULL;
108108
}
109-
xmlSecErrorsDefaultCallbackEnableOutput(PyObject_IsTrue(enabled));
109+
PyXmlSecEnableDebugTrace(PyObject_IsTrue(enabled));
110110
Py_RETURN_NONE;
111111
}
112112

0 commit comments

Comments
 (0)