summaryrefslogtreecommitdiff
path: root/src/utils/xml.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-11-05 13:42:27 +0300
committerAndrei Karas <akaras@inbox.ru>2013-11-05 13:42:27 +0300
commit9f7b1073ad4e1cc8f17e83fb13b85e4a20d5320e (patch)
tree3320da9c72f65c1459ca59e8c39b90652fb9dde0 /src/utils/xml.cpp
parent4f72bbf3eb55d6fb0fd245b683482efc9b92d42d (diff)
downloadplus-9f7b1073ad4e1cc8f17e83fb13b85e4a20d5320e.tar.gz
plus-9f7b1073ad4e1cc8f17e83fb13b85e4a20d5320e.tar.bz2
plus-9f7b1073ad4e1cc8f17e83fb13b85e4a20d5320e.tar.xz
plus-9f7b1073ad4e1cc8f17e83fb13b85e4a20d5320e.zip
add libxml2 error logging.
Diffstat (limited to 'src/utils/xml.cpp')
-rw-r--r--src/utils/xml.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 5f691fd68..a81e1b4ef 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -34,9 +34,39 @@
#include "debug.h"
-static void xmlNullLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...)
+static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...)
+#ifdef __GNUC__
+#ifdef __OpenBSD__
+ __attribute__((__format__(printf, 2, 3)))
+#else
+ __attribute__((__format__(gnu_printf, 2, 3)))
+#endif
+#endif
+;
+
+static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...)
{
- // Does nothing, that's the whole point of it
+ unsigned size = 1024;
+ const unsigned msgSize = strlen(msg);
+ if (msgSize * 3 > size)
+ size = static_cast<unsigned>(msgSize * 3);
+
+ char* buf = new char[size + 1];
+ va_list ap;
+
+ // Use a temporary buffer to fill in the variables
+ va_start(ap, msg);
+ vsnprintf(buf, size, msg, ap);
+ buf[size] = 0;
+ va_end(ap);
+
+ if (logger)
+ logger->log(buf);
+ else
+ puts(buf);
+
+ // Delete temporary buffer
+ delete [] buf;
}
namespace XML
@@ -213,7 +243,7 @@ namespace XML
LIBXML_TEST_VERSION;
// Suppress libxml2 error messages
- xmlSetGenericErrorFunc(nullptr, &xmlNullLogger);
+ xmlSetGenericErrorFunc(nullptr, &xmlErrorLogger);
}
// Shutdown libxml