summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-06-19 11:28:01 (GMT)
committerTobias Markmann <tm@ayena.de>2017-07-06 11:53:33 (GMT)
commit610a2169757b578c6246c0d277f95a79695652ba (patch)
tree98cc8e92a786d4a06e7aa29ab3c52d73c22e4908
parentba67437900cfabb1ce9e115c0ec5029c76696b8b (diff)
downloadswift-aa0e8458595ef17650830120e9796f207c9df793.zip
swift-aa0e8458595ef17650830120e9796f207c9df793.tar.bz2
Adds MIXLeave Element, its Parser and Serializerswift-5.0alpha
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Added tests for MIXLeave Parser and Serializer based on examples in XEP 0369, which passes. Tested on Ubuntu 16.04 LTS. Change-Id: Ie9eb3341b23099de4dda2b9915d28115dbfe5837
-rw-r--r--Swiften/Elements/MIXLeave.h37
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MIXLeaveParser.cpp37
-rw-r--r--Swiften/Parser/PayloadParsers/MIXLeaveParser.h30
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MIXLeaveParserTest.cpp32
-rw-r--r--Swiften/Parser/SConscript1
-rw-r--r--Swiften/SConscript3
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.cpp31
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h24
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXLeaveSerializerTest.cpp30
11 files changed, 229 insertions, 0 deletions
diff --git a/Swiften/Elements/MIXLeave.h b/Swiften/Elements/MIXLeave.h
new file mode 100644
index 0000000..76ca09d
--- /dev/null
+++ b/Swiften/Elements/MIXLeave.h
@@ -0,0 +1,37 @@
+/*
+ * 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 <boost/optional.hpp>
+
+#include <Swiften/Base/API.h>
+#include <Swiften/JID/JID.h>
+#include <Swiften/Elements/Payload.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXLeave : public Payload {
+ public:
+ using ref = std::shared_ptr<MIXLeave>;
+
+ public:
+
+ MIXLeave() {}
+
+ const boost::optional<JID>& getChannel() const {
+ return channel_;
+ }
+
+ void setChannel(const JID& channel) {
+ channel_ = channel;
+ }
+
+ private:
+ boost::optional<JID> channel_;
+ };
+}
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());
+}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 3c778f5..c7113df 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -70,6 +70,7 @@ sources = [
"PayloadParsers/MIXParticipantParser.cpp",
"PayloadParsers/MIXDestroyParser.cpp",
"PayloadParsers/MIXCreateParser.cpp",
+ "PayloadParsers/MIXLeaveParser.cpp",
"PayloadParsers/MIXJoinParser.cpp",
"PayloadParsers/MIXSubscribeParser.cpp",
"PayloadParsers/MIXUserPreferenceParser.cpp",
diff --git a/Swiften/SConscript b/Swiften/SConscript
index e0f87ce..36b1dd8 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -211,6 +211,7 @@ if env["SCONS_STAGE"] == "build" :
"Serializer/PayloadSerializers/MIXDestroySerializer.cpp",
"Serializer/PayloadSerializers/MIXCreateSerializer.cpp",
"Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp",
+ "Serializer/PayloadSerializers/MIXLeaveSerializer.cpp",
"Serializer/PayloadSerializers/MIXJoinSerializer.cpp",
"Serializer/PayloadSerializers/MIXSubscribeSerializer.cpp",
"Serializer/PayloadSerializers/MUCPayloadSerializer.cpp",
@@ -438,6 +439,7 @@ if env["SCONS_STAGE"] == "build" :
File("Parser/PayloadParsers/UnitTest/JingleParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp"),
+ File("Parser/PayloadParsers/UnitTest/MIXLeaveParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/MIXUserPreferenceParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp"),
@@ -524,6 +526,7 @@ if env["SCONS_STAGE"] == "build" :
File("Serializer/PayloadSerializers/UnitTest/MIXDestroySerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/MIXCreateSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp"),
+ File("Serializer/PayloadSerializers/UnitTest/MIXLeaveSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp"),
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 9832bd5..c0ee620 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -50,6 +50,7 @@
#include <Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h>
@@ -162,6 +163,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new MIXParticipantSerializer());
serializers_.push_back(new MIXCreateSerializer());
serializers_.push_back(new MIXUserPreferenceSerializer());
+ serializers_.push_back(new MIXLeaveSerializer());
serializers_.push_back(new MIXJoinSerializer());
serializers_.push_back(new MIXDestroySerializer());
serializers_.push_back(new MAMResultSerializer(this));
diff --git a/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.cpp
new file mode 100644
index 0000000..9025e3f
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h>
+
+#include <memory>
+
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+namespace Swift {
+
+MIXLeaveSerializer::MIXLeaveSerializer() {
+}
+
+MIXLeaveSerializer::~MIXLeaveSerializer() {
+}
+
+std::string MIXLeaveSerializer::serializePayload(std::shared_ptr<MIXLeave> payload) const {
+ if (!payload) {
+ return "";
+ }
+ XMLElement element("leave", "urn:xmpp:mix:1");
+ if (payload->getChannel()) {
+ element.setAttribute("channel", *payload->getChannel());
+ }
+ return element.serialize();
+}
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h b/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h
new file mode 100644
index 0000000..d44f471
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h
@@ -0,0 +1,24 @@
+/*
+ * 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/Serializer/GenericPayloadSerializer.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXLeaveSerializer : public GenericPayloadSerializer<MIXLeave> {
+ public:
+ MIXLeaveSerializer();
+ virtual ~MIXLeaveSerializer();
+
+ virtual std::string serializePayload(std::shared_ptr<MIXLeave>) const SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXLeaveSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXLeaveSerializerTest.cpp
new file mode 100644
index 0000000..03e3e76
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXLeaveSerializerTest.cpp
@@ -0,0 +1,30 @@
+/*
+ * 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/Serializer/PayloadSerializers/MIXLeaveSerializer.h>
+
+using namespace Swift;
+
+TEST(MIXLeaveSerializerTest, XEP0369_Example33) {
+ MIXLeaveSerializer testling;
+
+ auto leave = std::shared_ptr<MIXLeave>(new MIXLeave());
+ leave->setChannel(JID("coven@mix.shakespeare.example"));
+
+ std::string expectedResult = "<leave channel=\"coven@mix.shakespeare.example\" xmlns=\"urn:xmpp:mix:1\"/>";
+ ASSERT_EQ(expectedResult, testling.serialize(leave));
+}
+
+TEST(MIXLeaveSerializerTest, XEP0369_Example34) {
+ MIXLeaveSerializer testling;
+
+ auto leave = std::shared_ptr<MIXLeave>(new MIXLeave());
+
+ std::string expectedResult = "<leave xmlns=\"urn:xmpp:mix:1\"/>";
+ ASSERT_EQ(expectedResult, testling.serialize(leave));
+}