summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-06-26 13:18:09 (GMT)
committerTobias Markmann <tm@ayena.de>2017-07-14 13:19:16 (GMT)
commitf21c9448c5187493fd08574962d88c2db1405512 (patch)
treed8facf4bed5c792833719a1685084b8b4a676d87 /Swiften/Parser
parent0b4aaa1def9625ca3b4ddf869c988a68483135f8 (diff)
downloadswift-f21c9448c5187493fd08574962d88c2db1405512.zip
swift-f21c9448c5187493fd08574962d88c2db1405512.tar.bz2
Add MIXRegisterNick Element, its Parser and Serializer
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Added tests for MIXRegisterNick Parser and Serializer based on examples in XEP 0369, which passes. Tested on Ubuntu 16.04 LTS. Change-Id: I80796db9d540c58296afa3454f29e1fb81d04615
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp19
-rw-r--r--Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h19
-rw-r--r--Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h27
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp23
-rw-r--r--Swiften/Parser/SConscript1
6 files changed, 91 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 939e1af..8f57704 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -53,6 +53,7 @@
#include <Swiften/Parser/PayloadParsers/MAMResultParser.h>
#include <Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h>
#include <Swiften/Parser/PayloadParsers/MIXCreateParser.h>
+#include <Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h>
#include <Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h>
#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h>
#include <Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h>
@@ -139,6 +140,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
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:0"));
+ factories_.push_back(std::make_shared<MIXRegisterNickParserFactory>());
factories_.push_back(std::make_shared<MIXSetNickParserFactory>());
factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXCreateParser> >("create", "urn:xmpp:mix:0"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXUserPreferenceParser> >("user-preference", "urn:xmpp:mix:0"));
diff --git a/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp
new file mode 100644
index 0000000..945e9b2
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h>
+
+namespace Swift {
+
+void MIXRegisterNickParser::handleTree(ParserElement::ref root) {
+ for (const auto& child : root->getAllChildren()) {
+ if (child->getName() == "nick" && child->getNamespace() == root->getNamespace()) {
+ getPayloadInternal()->setNick(child->getText());
+ }
+ }
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h
new file mode 100644
index 0000000..cfb618e
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h
@@ -0,0 +1,19 @@
+/*
+ * 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/Parser/GenericPayloadTreeParser.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXRegisterNickParser : public GenericPayloadTreeParser<MIXRegisterNick> {
+ public:
+ MIXRegisterNickParser() {}
+ virtual void handleTree(ParserElement::ref root) override;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h b/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h
new file mode 100644
index 0000000..e03392c
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h
@@ -0,0 +1,27 @@
+/*
+ * 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/Parser/GenericPayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXRegisterNickParserFactory : public PayloadParserFactory {
+ public:
+ MIXRegisterNickParserFactory() {
+ }
+
+ virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const override {
+ return element == "register" && ns == "urn:xmpp:mix:0";
+ }
+
+ virtual PayloadParser* createPayloadParser() override {
+ return new MIXRegisterNickParser();
+ }
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp
new file mode 100644
index 0000000..d0539fd
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp
@@ -0,0 +1,23 @@
+/*
+ * 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/MIXRegisterNick.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+TEST(MIXRegisterNickParserTest, WithNick) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<register xmlns=\"urn:xmpp:mix:0\"> <nick>thirdwitch</nick> </register>"
+ ));
+
+ auto payload = parser.getPayload<MIXRegisterNick>();
+ ASSERT_TRUE(payload);
+ ASSERT_EQ("thirdwitch", payload->getNick());
+}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index d185052..bfc7850 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -69,6 +69,7 @@ sources = [
"PayloadParsers/DelayParser.cpp",
"PayloadParsers/MIXParticipantParser.cpp",
"PayloadParsers/MIXSetNickParser.cpp",
+ "PayloadParsers/MIXRegisterNickParser.cpp",
"PayloadParsers/MIXDestroyParser.cpp",
"PayloadParsers/MIXCreateParser.cpp",
"PayloadParsers/MIXPayloadParser.cpp",