diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
4 files changed, 101 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index ea7bdbf..4729fdb 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -56,6 +56,7 @@ #include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h> #include <Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h> #include <Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.h> +#include <Swiften/Parser/PayloadParsers/MIXLeaveParser.h> #include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h> @@ -138,6 +139,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXDestroyParser> >("destroy", "urn:xmpp:mix:1")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXCreateParser> >("create", "urn:xmpp:mix:1")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXUserPreferenceParser> >("user-preference", "urn:xmpp:mix:1")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXLeaveParser> >("leave", "urn:xmpp:mix:1")); factories_.push_back(std::make_shared<MUCUserPayloadParserFactory>(this)); factories_.push_back(std::make_shared<MUCOwnerPayloadParserFactory>(this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory<MUCInvitationPayloadParser> >("x", "jabber:x:conference")); diff --git a/Swiften/Parser/PayloadParsers/MIXLeaveParser.cpp b/Swiften/Parser/PayloadParsers/MIXLeaveParser.cpp new file mode 100644 index 0000000..6330925 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXLeaveParser.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXLeaveParser.h> + +#include <boost/optional.hpp> + +namespace Swift { + +MIXLeaveParser::MIXLeaveParser() : level_(0) { +} + +MIXLeaveParser::~MIXLeaveParser() { +} + +void MIXLeaveParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + if (auto attributeValue = attributes.getAttributeValue("channel")) { + if (auto jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setChannel(*jid); + } + } + } + ++level_; +} + +void MIXLeaveParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void MIXLeaveParser::handleCharacterData(const std::string&) { + +} +} diff --git a/Swiften/Parser/PayloadParsers/MIXLeaveParser.h b/Swiften/Parser/PayloadParsers/MIXLeaveParser.h new file mode 100644 index 0000000..3d35c1b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXLeaveParser.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> +#include <Swiften/Elements/MIXLeave.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + + class SWIFTEN_API MIXLeaveParser : public GenericPayloadParser<MIXLeave> { + public: + MIXLeaveParser(); + virtual ~MIXLeaveParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXLeaveParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXLeaveParserTest.cpp new file mode 100644 index 0000000..dab3ea4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXLeaveParserTest.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXLeave.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXLeaveParserTest, XEP0369_Example33) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse("<leave xmlns=\"urn:xmpp:mix:1\" channel=\"coven@mix.shakespeare.example\"/>")); + + auto payload = parser.getPayload<MIXLeave>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(JID("coven@mix.shakespeare.example"), *payload->getChannel()); +} + +TEST(MIXLeaveParserTest, XEP0369_Example34) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse("<leave xmlns=\"urn:xmpp:mix:1\"/>")); + + auto payload = parser.getPayload<MIXLeave>(); + ASSERT_TRUE(payload); + ASSERT_FALSE(payload->getChannel()); +} |