diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2017-06-15 11:04:26 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2017-06-26 13:06:37 (GMT) |
commit | e142d11c3fa6ae2bdfc95ee9cea54bb0000917c9 (patch) | |
tree | 591fce5f344a983a2c0dfd6b3affd08c68b02fc9 /Swiften/Parser/PayloadParsers/MIXJoinParser.cpp | |
parent | cfd0f09744c543efb52dcfeaef8a760a766a4d71 (diff) | |
download | swift-e142d11c3fa6ae2bdfc95ee9cea54bb0000917c9.zip swift-e142d11c3fa6ae2bdfc95ee9cea54bb0000917c9.tar.bz2 |
Adds MIX Join Element, its Parser and Serializer.
Add MIXDestroySerializer to FullPayloadSerializerCollection.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Added tests for MIX Join Parser and Serializer based on examples in XEP 0369, which passes.
Tested on Ubuntu 16.04 LTS.
Change-Id: Ibf7446dd65714dccdd39c485549fd9fb9faba40c
Diffstat (limited to 'Swiften/Parser/PayloadParsers/MIXJoinParser.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParsers/MIXJoinParser.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/MIXJoinParser.cpp b/Swiften/Parser/PayloadParsers/MIXJoinParser.cpp new file mode 100644 index 0000000..2509667 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXJoinParser.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXJoinParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXSubscribeParser.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +MIXJoinParser::MIXJoinParser() : level_(0) { +} + +MIXJoinParser::~MIXJoinParser() { +} + +void MIXJoinParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("channel")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setChannel(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + } + + if (level_ == 1) { + if (element == "subscribe" && ns == "urn:xmpp:mix:1") { + currentPayloadParser_ = std::make_shared<MIXSubscribeParser>(); + } + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser_ = std::make_shared<FormParser>(); + } + } + + if (level_ >= 1 && currentPayloadParser_) { + currentPayloadParser_->handleStartElement(element, ns, attributes); + } + ++level_; +} + +void MIXJoinParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (currentPayloadParser_) { + if (level_ >= 1) { + currentPayloadParser_->handleEndElement(element, ns); + } + + if (level_ == 1) { + if (element == "subscribe" && ns == "urn:xmpp:mix:1") { + getPayloadInternal()->addSubscription(std::dynamic_pointer_cast<MIXSubscribe>(currentPayloadParser_->getPayload())); + } + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setForm(std::dynamic_pointer_cast<Form>(currentPayloadParser_->getPayload())); + } + currentPayloadParser_.reset(); + } + } +} + +void MIXJoinParser::handleCharacterData(const std::string& data) { + if (level_ > 1 && currentPayloadParser_) { + currentPayloadParser_->handleCharacterData(data); + } +} |