summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-06-24 17:07:44 (GMT)
committerTobias Markmann <tm@ayena.de>2017-06-25 09:01:13 (GMT)
commit02763529a75970a1d57d9abf3448848f728c4101 (patch)
tree8eb5ee15eb01ed0c9c2a0924eb20a3556450aeac /Swiften/Parser
parentd46e946db8b25ddc34715e2e86c1e561f8381810 (diff)
downloadswift-02763529a75970a1d57d9abf3448848f728c4101.zip
swift-02763529a75970a1d57d9abf3448848f728c4101.tar.bz2
Adds MIX Destroy Element, its Parser and Serializer.
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Added tests for MIX Destroy Parser and Serializer based on examples in XEP 0369, which passes. Change-Id: I56810eb2fc26cc6aeb5e1cfb2a32e312f0607ba9
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp36
-rw-r--r--Swiften/Parser/PayloadParsers/MIXDestroyParser.h31
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp25
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp24
-rw-r--r--Swiften/Parser/SConscript1
6 files changed, 119 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index f657e11..dbfcb6b 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -52,6 +52,7 @@
#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h>
#include <Swiften/Parser/PayloadParsers/MAMResultParser.h>
#include <Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h>
#include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h>
@@ -131,6 +132,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(std::make_shared<ChatStateParserFactory>());
factories_.push_back(std::make_shared<ClientStateParserFactory>());
factories_.push_back(std::make_shared<MIXParticipantParserFactory>());
+ factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXDestroyParser> >("destroy", "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/MIXDestroyParser.cpp b/Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp
new file mode 100644
index 0000000..0437b48
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h>
+
+#include <boost/optional.hpp>
+
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/FormParser.h>
+
+using namespace Swift;
+
+MIXDestroyParser::MIXDestroyParser() : level_(0) {
+}
+
+MIXDestroyParser::~MIXDestroyParser() {
+}
+
+void MIXDestroyParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) {
+ if (level_ == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("channel")) {
+ getPayloadInternal()->setChannel(*attributeValue);
+ }
+ }
+ ++level_;
+}
+
+void MIXDestroyParser::handleEndElement(const std::string&, const std::string&) {
+ --level_;
+}
+
+void MIXDestroyParser::handleCharacterData(const std::string&) {
+}
diff --git a/Swiften/Parser/PayloadParsers/MIXDestroyParser.h b/Swiften/Parser/PayloadParsers/MIXDestroyParser.h
new file mode 100644
index 0000000..3a925de
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXDestroyParser.h
@@ -0,0 +1,31 @@
+/*
+ * 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/MIXDestroy.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParser;
+
+ class SWIFTEN_API MIXDestroyParser : public GenericPayloadParser<MIXDestroy> {
+ public:
+ MIXDestroyParser();
+ virtual ~MIXDestroyParser();
+
+ 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/MIXDestroyParser.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp
new file mode 100644
index 0000000..fc2588a
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp
@@ -0,0 +1,25 @@
+/*
+ * 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/MIXDestroy.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+TEST(MIXDestroyParserTest, XEP0369_Example70) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<destroy channel=\"coven\" xmlns=\"urn:xmpp:mix:1\"/>"
+ ));
+
+ auto payload = parser.getPayload<MIXDestroy>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_TRUE(payload->getChannel());
+ ASSERT_EQ(std::string("coven"), *payload->getChannel());
+}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp
new file mode 100644
index 0000000..8e4dff2
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp
@@ -0,0 +1,24 @@
+/*
+ * 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/MIXDestroy.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+TEST(MIXDestroyParserTest, XEP0369_Example70) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<destroy channel=\"coven\" xmlns=\"urn:xmpp:mix:1\"/>"
+ ));
+
+ auto payload = parser.getPayload<MIXDestroy>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_EQ(std::string("coven"), payload->getChannel());
+}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 3ef6237..a01c1e1 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -68,6 +68,7 @@ sources = [
"PayloadParsers/VCardUpdateParser.cpp",
"PayloadParsers/DelayParser.cpp",
"PayloadParsers/MIXParticipantParser.cpp",
+ "PayloadParsers/MIXDestroyParser.cpp",
"PayloadParsers/MUCUserPayloadParser.cpp",
"PayloadParsers/MUCAdminPayloadParser.cpp",
"PayloadParsers/MUCOwnerPayloadParser.cpp",