diff options
author | Richard Maudsley <richard.maudsley@isode.com> | 2014-02-25 13:19:11 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2014-04-24 13:06:33 (GMT) |
commit | e4704555946626980014d936dcfe6ede2710501b (patch) | |
tree | 59d0db1bad3d4a0f74c89da8834b2002369c3b4b /Swiften/Parser/PayloadParsers/MAMResultParser.cpp | |
parent | 09e9713028b728fad9050c4e20180cc96c4572ce (diff) | |
download | swift-e4704555946626980014d936dcfe6ede2710501b.zip swift-e4704555946626980014d936dcfe6ede2710501b.tar.bz2 |
Added MAM parsers, serializers and tests.
Change-Id: I589a7c65664bfecfd0ac34240600dcccb4cbd40e
Diffstat (limited to 'Swiften/Parser/PayloadParsers/MAMResultParser.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParsers/MAMResultParser.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp new file mode 100644 index 0000000..e4eec3b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> +#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> +#include <Swiften/Parser/PayloadParsers/MAMResultParser.h> + +using namespace Swift; + +MAMResultParser::MAMResultParser(PayloadParserFactoryCollection* factories) : factories_(factories), level_(TopLevel) { +} + +void MAMResultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == TopLevel) { + boost::optional<std::string> attributeValue; + if ((attributeValue = attributes.getAttributeValue("id"))) { + getPayloadInternal()->setID(*attributeValue); + } + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + } else if (level_ == PayloadLevel) { + if (element == "forwarded" && ns == "urn:xmpp:forward:0") { + payloadParser_ = boost::make_shared<ForwardedParser>(factories_); + } + } + + if (payloadParser_) { + /* parsing a nested payload */ + payloadParser_->handleStartElement(element, ns, attributes); + } + + ++level_; +} + +void MAMResultParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (payloadParser_ && level_ >= PayloadLevel) { + payloadParser_->handleEndElement(element, ns); + } + if (payloadParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<Forwarded>(payloadParser_->getPayload())); + payloadParser_.reset(); + } +} + +void MAMResultParser::handleCharacterData(const std::string& data) { + if (payloadParser_) { + payloadParser_->handleCharacterData(data); + } +} |