diff options
author | Joanna Hulboj <joanna.hulboj@isode.com> | 2017-03-18 18:52:56 (GMT) |
---|---|---|
committer | Joanna Hulboj <joanna.hulboj@isode.com> | 2017-03-28 14:19:18 (GMT) |
commit | 0e503ccd97ca5287a14d3147b0deaa99892ccd6f (patch) | |
tree | 5500f9f6376f8fa6544fc281ed40ea8b18d7129b /Swiften/Parser | |
parent | cc873b3f00db4cd0a778bc2ec04f8748d70a92f9 (diff) | |
download | swift-0e503ccd97ca5287a14d3147b0deaa99892ccd6f.zip swift-0e503ccd97ca5287a14d3147b0deaa99892ccd6f.tar.bz2 |
Modified XMLBeautifier to handle split payloads
When receiving network data we were processing it in chunks. Sometimes
one XML message got split across multiple chunks. XMLBeautifier was
stateless and would create a new parser for every single chunk. This was
causing multi-chunk messages to be truncated in the beautified output.
The change I made in XMLBeautifier allows it to maintain the state.
Test-Information:
Tested unger Windows 10 and CentOS.
Unit tests pass OK.
Change-Id: Idad2a8e0248ed3cbe2b47a12718b909e56ac1279
Diffstat (limited to 'Swiften/Parser')
-rw-r--r-- | Swiften/Parser/BOSHBodyExtractor.cpp | 2 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h | 6 | ||||
-rw-r--r-- | Swiften/Parser/PlatformXMLParserFactory.cpp | 6 | ||||
-rw-r--r-- | Swiften/Parser/PlatformXMLParserFactory.h | 2 | ||||
-rw-r--r-- | Swiften/Parser/UnitTest/ParserTester.h | 9 | ||||
-rw-r--r-- | Swiften/Parser/XMLParserFactory.h | 4 | ||||
-rw-r--r-- | Swiften/Parser/XMPPParser.cpp | 1 | ||||
-rw-r--r-- | Swiften/Parser/XMPPParser.h | 2 |
8 files changed, 12 insertions, 20 deletions
diff --git a/Swiften/Parser/BOSHBodyExtractor.cpp b/Swiften/Parser/BOSHBodyExtractor.cpp index c45d338..803f16a 100644 --- a/Swiften/Parser/BOSHBodyExtractor.cpp +++ b/Swiften/Parser/BOSHBodyExtractor.cpp @@ -126,7 +126,7 @@ BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const Byte // Parse the body element BOSHBodyParserClient parserClient(this); - std::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient)); + std::shared_ptr<XMLParser> parser(std::move(parserFactory->createXMLParser(&parserClient))); if (!parser->parse(std::string( reinterpret_cast<const char*>(vecptr(data)), boost::numeric_cast<size_t>(std::distance(data.begin(), i))))) { diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h index 2c1ff8e..dcdbffa 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h @@ -22,10 +22,6 @@ namespace Swift { xmlParser = PlatformXMLParserFactory().createXMLParser(this); } - ~PayloadsParserTester() { - delete xmlParser; - } - bool parse(const std::string& data) { return xmlParser->parse(data); } @@ -60,7 +56,7 @@ namespace Swift { } private: - XMLParser* xmlParser; + std::unique_ptr<XMLParser> xmlParser; FullPayloadParserFactoryCollection factories; std::shared_ptr<PayloadParser> payloadParser; int level; diff --git a/Swiften/Parser/PlatformXMLParserFactory.cpp b/Swiften/Parser/PlatformXMLParserFactory.cpp index 87f70d1..97e1c9e 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.cpp +++ b/Swiften/Parser/PlatformXMLParserFactory.cpp @@ -20,11 +20,11 @@ namespace Swift { PlatformXMLParserFactory::PlatformXMLParserFactory() { } -XMLParser* PlatformXMLParserFactory::createXMLParser(XMLParserClient* client) { +std::unique_ptr<XMLParser> PlatformXMLParserFactory::createXMLParser(XMLParserClient* client) { #ifdef HAVE_LIBXML - return new LibXMLParser(client); + return std::unique_ptr<XMLParser>(new LibXMLParser(client)); #else - return new ExpatParser(client); + return std::unique_ptr<XMLParser>(new ExpatParser(client)); #endif } diff --git a/Swiften/Parser/PlatformXMLParserFactory.h b/Swiften/Parser/PlatformXMLParserFactory.h index 82b8573..fa3ca19 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.h +++ b/Swiften/Parser/PlatformXMLParserFactory.h @@ -14,6 +14,6 @@ namespace Swift { public: PlatformXMLParserFactory(); - virtual XMLParser* createXMLParser(XMLParserClient*); + virtual std::unique_ptr<XMLParser> createXMLParser(XMLParserClient*); }; } diff --git a/Swiften/Parser/UnitTest/ParserTester.h b/Swiften/Parser/UnitTest/ParserTester.h index a98eb51..aa01d40 100644 --- a/Swiften/Parser/UnitTest/ParserTester.h +++ b/Swiften/Parser/UnitTest/ParserTester.h @@ -16,12 +16,7 @@ namespace Swift { template<typename ParserType> class ParserTester : public XMLParserClient { public: - ParserTester(ParserType* parser) : parser_(parser) { - xmlParser_ = PlatformXMLParserFactory().createXMLParser(this); - } - - ~ParserTester() { - delete xmlParser_; + ParserTester(ParserType* parser) : xmlParser_(PlatformXMLParserFactory().createXMLParser(this)), parser_(parser) { } bool parse(const std::string& data) { @@ -41,7 +36,7 @@ namespace Swift { } private: - XMLParser* xmlParser_; + std::unique_ptr<XMLParser> xmlParser_; ParserType* parser_; }; } diff --git a/Swiften/Parser/XMLParserFactory.h b/Swiften/Parser/XMLParserFactory.h index 091f45b..595512b 100644 --- a/Swiften/Parser/XMLParserFactory.h +++ b/Swiften/Parser/XMLParserFactory.h @@ -6,6 +6,8 @@ #pragma once +#include <memory> + #include <Swiften/Base/API.h> namespace Swift { @@ -16,6 +18,6 @@ namespace Swift { public: virtual ~XMLParserFactory(); - virtual XMLParser* createXMLParser(XMLParserClient*) = 0; + virtual std::unique_ptr<XMLParser> createXMLParser(XMLParserClient*) = 0; }; } diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp index 2b45a12..d2a5a98 100644 --- a/Swiften/Parser/XMPPParser.cpp +++ b/Swiften/Parser/XMPPParser.cpp @@ -60,7 +60,6 @@ XMPPParser::XMPPParser( XMPPParser::~XMPPParser() { delete currentElementParser_; - delete xmlParser_; } bool XMPPParser::parse(const std::string& data) { diff --git a/Swiften/Parser/XMPPParser.h b/Swiften/Parser/XMPPParser.h index 09fae38..6595b94 100644 --- a/Swiften/Parser/XMPPParser.h +++ b/Swiften/Parser/XMPPParser.h @@ -42,7 +42,7 @@ namespace Swift { ElementParser* createElementParser(const std::string& element, const std::string& xmlns); private: - XMLParser* xmlParser_; + std::unique_ptr<XMLParser> xmlParser_; XMPPParserClient* client_; PayloadParserFactoryCollection* payloadParserFactories_; enum Level { |