summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Parser/ExpatParser.cpp6
-rw-r--r--Swiften/Parser/ExpatParser.h4
-rw-r--r--Swiften/Parser/LibXMLParser.cpp6
-rw-r--r--Swiften/Parser/LibXMLParser.h4
-rw-r--r--Swiften/Parser/UnitTest/XMLParserTest.cpp9
-rw-r--r--Swiften/Parser/XMLParser.h4
6 files changed, 21 insertions, 12 deletions
diff --git a/Swiften/Parser/ExpatParser.cpp b/Swiften/Parser/ExpatParser.cpp
index 8415c42..e4e66f2 100644
--- a/Swiften/Parser/ExpatParser.cpp
+++ b/Swiften/Parser/ExpatParser.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -82,11 +82,11 @@ ExpatParser::~ExpatParser() {
XML_ParserFree(p->parser_);
}
-bool ExpatParser::parse(const std::string& data) {
+bool ExpatParser::parse(const std::string& data, bool finalData) {
if (data.size() > std::numeric_limits<int>::max()) {
return false;
}
- bool success = XML_Parse(p->parser_, data.c_str(), static_cast<int>(data.size()), false) == XML_STATUS_OK;
+ bool success = XML_Parse(p->parser_, data.c_str(), static_cast<int>(data.size()), finalData) == XML_STATUS_OK;
/*if (!success) {
std::cout << "ERROR: " << XML_ErrorString(XML_GetErrorCode(p->parser_)) << " while parsing " << data << std::endl;
}*/
diff --git a/Swiften/Parser/ExpatParser.h b/Swiften/Parser/ExpatParser.h
index 12df463..7583339 100644
--- a/Swiften/Parser/ExpatParser.h
+++ b/Swiften/Parser/ExpatParser.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -19,7 +19,7 @@ namespace Swift {
ExpatParser(XMLParserClient* client);
~ExpatParser();
- bool parse(const std::string& data);
+ bool parse(const std::string& data, bool finalData = false);
void stopParser();
diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp
index 5bd3737..c9f3a07 100644
--- a/Swiften/Parser/LibXMLParser.cpp
+++ b/Swiften/Parser/LibXMLParser.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2018 Isode Limited.
+ * Copyright (c) 2010-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -94,11 +94,11 @@ LibXMLParser::~LibXMLParser() {
}
}
-bool LibXMLParser::parse(const std::string& data) {
+bool LibXMLParser::parse(const std::string& data, bool finalData) {
if (data.size() > std::numeric_limits<int>::max()) {
return false;
}
- if (xmlParseChunk(p->context_, data.c_str(), static_cast<int>(data.size()), false) == XML_ERR_OK) {
+ if (xmlParseChunk(p->context_, data.c_str(), static_cast<int>(data.size()), finalData) == XML_ERR_OK) {
return true;
}
xmlError* error = xmlCtxtGetLastError(p->context_);
diff --git a/Swiften/Parser/LibXMLParser.h b/Swiften/Parser/LibXMLParser.h
index 9f752ce..a863867 100644
--- a/Swiften/Parser/LibXMLParser.h
+++ b/Swiften/Parser/LibXMLParser.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -22,7 +22,7 @@ namespace Swift {
LibXMLParser(XMLParserClient* client);
virtual ~LibXMLParser();
- bool parse(const std::string& data);
+ bool parse(const std::string& data, bool finalData = false);
private:
static bool initialized;
diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp
index b593aa7..9e9012b 100644
--- a/Swiften/Parser/UnitTest/XMLParserTest.cpp
+++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp
@@ -217,6 +217,15 @@ class XMLParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data);
}
+ void testParse_CompleteDocument() {
+ ParserType testling(&client_);
+
+ CPPUNIT_ASSERT(!testling.parse("<iq", true));
+ CPPUNIT_ASSERT(!testling.parse("<iq>", true));
+ CPPUNIT_ASSERT(!testling.parse("<iq><child>foo</child>", true));
+ CPPUNIT_ASSERT(testling.parse("<iq><child>foo</child></iq>", true));
+ }
+
void testParse_WhitespaceInAttribute() {
ParserType testling(&client_);
diff --git a/Swiften/Parser/XMLParser.h b/Swiften/Parser/XMLParser.h
index 8a73c3f..ad79b2d 100644
--- a/Swiften/Parser/XMLParser.h
+++ b/Swiften/Parser/XMLParser.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -18,7 +18,7 @@ namespace Swift {
XMLParser(XMLParserClient* client);
virtual ~XMLParser();
- virtual bool parse(const std::string& data) = 0;
+ virtual bool parse(const std::string& data, bool finalData = false) = 0;
XMLParserClient* getClient() const {
return client_;