summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.cpp29
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.h20
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXRegisterNickSerializerTest.cpp22
4 files changed, 73 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 7f76b31..d1b2e97 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/MIXRegisterNickSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXSetNickSerializer.h>
@@ -164,6 +165,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new ForwardedSerializer(this));
serializers_.push_back(new MIXParticipantSerializer());
serializers_.push_back(new MIXCreateSerializer());
+ serializers_.push_back(new MIXRegisterNickSerializer());
serializers_.push_back(new MIXPayloadSerializer());
serializers_.push_back(new MIXSetNickSerializer());
serializers_.push_back(new MIXUserPreferenceSerializer());
diff --git a/Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.cpp
new file mode 100644
index 0000000..9045ffe
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.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 <Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.h>
+
+#include <memory>
+
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLTextNode.h>
+
+namespace Swift {
+
+MIXRegisterNickSerializer::MIXRegisterNickSerializer() : GenericPayloadSerializer<MIXRegisterNick>() {
+}
+
+std::string MIXRegisterNickSerializer::serializePayload(std::shared_ptr<MIXRegisterNick> payload) const {
+ XMLElement registernickElement("register", "urn:xmpp:mix:0");
+
+ auto nickElement = std::make_shared<XMLElement>("nick");
+ nickElement->addNode(std::make_shared<XMLTextNode>(payload->getNick()));
+ registernickElement.addNode(nickElement);
+
+ return registernickElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.h b/Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.h
new file mode 100644
index 0000000..011fb18
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXRegisterNickSerializer.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/MIXRegisterNick.h>
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXRegisterNickSerializer : public GenericPayloadSerializer<MIXRegisterNick> {
+ public:
+ MIXRegisterNickSerializer();
+
+ virtual std::string serializePayload(std::shared_ptr<MIXRegisterNick> payload) const override;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXRegisterNickSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXRegisterNickSerializerTest.cpp
new file mode 100644
index 0000000..dc6cf0c
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXRegisterNickSerializerTest.cpp
@@ -0,0 +1,22 @@
+/*
+ * 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/MIXRegisterNickSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+using namespace Swift;
+
+TEST(MIXRegisterNickSerializerTest, testSerializeNick) {
+ MIXRegisterNickSerializer testling;
+
+ auto mix = std::shared_ptr<MIXRegisterNick>(new MIXRegisterNick());
+ mix->setNick(std::string("thirdwitch"));
+
+ std::string expectedResult = "<register xmlns=\"urn:xmpp:mix:0\"><nick>thirdwitch</nick></register>";
+ ASSERT_EQ(expectedResult, testling.serialize(mix));
+}