summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/LibXMLParser.cpp8
-rw-r--r--Swiften/Parser/LibXMLParser.h5
2 files changed, 12 insertions, 1 deletions
diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp
index ae87f38..1590262 100644
--- a/Swiften/Parser/LibXMLParser.cpp
+++ b/Swiften/Parser/LibXMLParser.cpp
@@ -51,9 +51,15 @@ static void handleError(void*, const char* /*m*/, ... ) {
static void handleWarning(void*, const char*, ... ) {
}
-
+bool LibXMLParser::initialized = false;
LibXMLParser::LibXMLParser(XMLParserClient* client) : XMLParser(client) {
+ // Initialize libXML for multithreaded applications
+ if (!initialized) {
+ xmlInitParser();
+ initialized = true;
+ }
+
memset(&handler_, 0, sizeof(handler_) );
handler_.initialized = XML_SAX2_MAGIC;
handler_.startElementNs = &handleStartElement;
diff --git a/Swiften/Parser/LibXMLParser.h b/Swiften/Parser/LibXMLParser.h
index ba61ad9..cd73637 100644
--- a/Swiften/Parser/LibXMLParser.h
+++ b/Swiften/Parser/LibXMLParser.h
@@ -12,6 +12,10 @@
#include <Swiften/Parser/XMLParser.h>
namespace Swift {
+ /**
+ * Warning: This constructor is not thread-safe, because it depends on global state to
+ * check whether it is initialized.
+ */
class LibXMLParser : public XMLParser, public boost::noncopyable {
public:
LibXMLParser(XMLParserClient* client);
@@ -20,6 +24,7 @@ namespace Swift {
bool parse(const std::string& data);
private:
+ static bool initialized;
xmlSAXHandler handler_;
xmlParserCtxtPtr context_;
};