summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.cpp38
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h25
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXCreateSerializerTest.cpp29
4 files changed, 94 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 72b6128..4c3cf66 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -48,6 +48,7 @@
#include <Swiften/Serializer/PayloadSerializers/MIXJoinSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h>
@@ -158,6 +159,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new ResultSetSerializer());
serializers_.push_back(new ForwardedSerializer(this));
serializers_.push_back(new MIXParticipantSerializer());
+ serializers_.push_back(new MIXCreateSerializer());
serializers_.push_back(new MIXJoinSerializer());
serializers_.push_back(new MIXDestroySerializer());
serializers_.push_back(new MAMResultSerializer(this));
diff --git a/Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.cpp
new file mode 100644
index 0000000..9476df2
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h>
+
+#include <memory>
+
+#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLRawTextNode.h>
+
+using namespace Swift;
+
+MIXCreateSerializer::MIXCreateSerializer() {
+}
+
+MIXCreateSerializer::~MIXCreateSerializer() {
+}
+
+std::string MIXCreateSerializer::serializePayload(std::shared_ptr<MIXCreate> payload) const {
+ if (!payload) {
+ return "";
+ }
+ XMLElement element("create", "urn:xmpp:mix:1");
+
+ if(payload->getChannel()) {
+ element.setAttribute("channel", *payload->getChannel());
+ }
+
+ if(payload->getData()) {
+ element.addNode(std::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData())));
+ }
+
+ return element.serialize();
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h b/Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h
new file mode 100644
index 0000000..23cc65d
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h
@@ -0,0 +1,25 @@
+/*
+ * 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/MIXCreate.h>
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+
+namespace Swift {
+
+ class SWIFTEN_API MIXCreateSerializer : public GenericPayloadSerializer<MIXCreate> {
+ public:
+ MIXCreateSerializer();
+ virtual ~MIXCreateSerializer();
+
+ virtual std::string serializePayload(std::shared_ptr<MIXCreate>) const SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXCreateSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXCreateSerializerTest.cpp
new file mode 100644
index 0000000..78424be
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXCreateSerializerTest.cpp
@@ -0,0 +1,29 @@
+/*
+ * 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/MIXCreateSerializer.h>
+
+using namespace Swift;
+
+TEST(MIXCreateSerializerTest, XEP0369_Example31) {
+ MIXCreateSerializer testling;
+
+ auto create = std::make_shared<MIXCreate>();
+ std::string expectedResult = "<create xmlns=\"urn:xmpp:mix:1\"/>";
+ ASSERT_EQ(expectedResult, testling.serialize(create));
+}
+
+TEST(MIXCreateSerializerTest, XEP0369_Example66) {
+ MIXCreateSerializer testling;
+
+ auto create = std::make_shared<MIXCreate>();
+ create->setChannel(std::string("coven"));
+
+ std::string expectedResult = "<create channel=\"coven\" xmlns=\"urn:xmpp:mix:1\"/>";
+ ASSERT_EQ(expectedResult, testling.serialize(create));
+}