diff options
Diffstat (limited to 'Swiften')
| -rw-r--r-- | Swiften/Parser/ExpatParser.cpp | 6 | ||||
| -rw-r--r-- | Swiften/Parser/ExpatParser.h | 4 | ||||
| -rw-r--r-- | Swiften/Parser/LibXMLParser.cpp | 6 | ||||
| -rw-r--r-- | Swiften/Parser/LibXMLParser.h | 4 | ||||
| -rw-r--r-- | Swiften/Parser/UnitTest/XMLParserTest.cpp | 9 | ||||
| -rw-r--r-- | Swiften/Parser/XMLParser.h | 4 |
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,7 +1,7 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2019 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/ExpatParser.h> @@ -80,15 +80,15 @@ ExpatParser::ExpatParser(XMLParserClient* client) : XMLParser(client), p(new Pri 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; }*/ return success; } 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,7 +1,7 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2019 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -17,11 +17,11 @@ namespace Swift { class SWIFTEN_API ExpatParser : public XMLParser, public boost::noncopyable { public: ExpatParser(XMLParserClient* client); ~ExpatParser(); - bool parse(const std::string& data); + bool parse(const std::string& data, bool finalData = false); void stopParser(); private: struct Private; 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,7 +1,7 @@ /* - * Copyright (c) 2010-2018 Isode Limited. + * Copyright (c) 2010-2019 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/LibXMLParser.h> @@ -92,15 +92,15 @@ LibXMLParser::~LibXMLParser() { if (p->context_) { xmlFreeParserCtxt(p->context_); } } -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_); if (error->code == XML_WAR_NS_URI || error->code == XML_WAR_NS_URI_RELATIVE) { xmlCtxtResetLastError(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,7 +1,7 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2019 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -20,11 +20,11 @@ namespace Swift { class LibXMLParser : public XMLParser, public boost::noncopyable { public: LibXMLParser(XMLParserClient* client); virtual ~LibXMLParser(); - bool parse(const std::string& data); + bool parse(const std::string& data, bool finalData = false); private: static bool initialized; struct Private; 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 @@ -215,10 +215,19 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); 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_); CPPUNIT_ASSERT(testling.parse( "<query xmlns='http://www.xmpp.org/extensions/xep-0084.html#ns-data '>")); 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,7 +1,7 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2019 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -16,11 +16,11 @@ namespace Swift { class SWIFTEN_API XMLParser { public: 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_; } |
Swift