summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MIXPayloadParser.cpp25
-rw-r--r--Swiften/Parser/PayloadParsers/MIXPayloadParser.h20
-rw-r--r--Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h27
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MIXPayloadParserTest.cpp85
5 files changed, 159 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index c5304a6..17fb478 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -55,6 +55,7 @@
#include <Swiften/Parser/PayloadParsers/MIXCreateParser.h>
#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h>
#include <Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.h>
#include <Swiften/Parser/PayloadParsers/MIXLeaveParser.h>
#include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h>
@@ -139,6 +140,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXDestroyParser> >("destroy", "urn:xmpp:mix:0"));
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"));
+ factories_.push_back(std::make_shared<MIXPayloadParserFactory>());
factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXLeaveParser> >("leave", "urn:xmpp:mix:0"));
factories_.push_back(std::make_shared<MUCUserPayloadParserFactory>(this));
factories_.push_back(std::make_shared<MUCOwnerPayloadParserFactory>(this));
diff --git a/Swiften/Parser/PayloadParsers/MIXPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MIXPayloadParser.cpp
new file mode 100644
index 0000000..51ef584
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXPayloadParser.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 <Swiften/Parser/PayloadParsers/MIXPayloadParser.h>
+
+namespace Swift {
+
+void MIXPayloadParser::handleTree(ParserElement::ref root) {
+ for (const auto& child : root->getAllChildren()) {
+ if (child->getName() == "nick" && child->getNamespace() == root->getNamespace()) {
+ getPayloadInternal()->setNick(child->getText());
+ } else if (child->getName() == "jid" && child->getNamespace() == root->getNamespace()) {
+ if (boost::optional<JID> jid = JID::parse(child->getText())) {
+ getPayloadInternal()->setJID(*jid);
+ }
+ } else if (child->getName() == "submission-id" && child->getNamespace() == root->getNamespace()) {
+ getPayloadInternal()->setSubmissionID(child->getText());
+ }
+ }
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/MIXPayloadParser.h b/Swiften/Parser/PayloadParsers/MIXPayloadParser.h
new file mode 100644
index 0000000..0225b3b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXPayloadParser.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/Base/Override.h>
+#include <Swiften/Elements/MIXPayload.h>
+#include <Swiften/Parser/GenericPayloadTreeParser.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXPayloadParser : public GenericPayloadTreeParser<MIXPayload> {
+ public:
+ MIXPayloadParser() {}
+ virtual void handleTree(ParserElement::ref root) SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h
new file mode 100644
index 0000000..066d2f0
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.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/MIXPayloadParser.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXPayloadParserFactory : public PayloadParserFactory {
+ public:
+ MIXPayloadParserFactory() {
+ }
+
+ virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const SWIFTEN_OVERRIDE {
+ return element == "mix" && ns == "urn:xmpp:mix:0";
+ }
+
+ virtual PayloadParser* createPayloadParser() SWIFTEN_OVERRIDE {
+ return new MIXPayloadParser();
+ }
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXPayloadParserTest.cpp
new file mode 100644
index 0000000..920aca7
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXPayloadParserTest.cpp
@@ -0,0 +1,85 @@
+/*
+ * 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/MIXPayload.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+TEST(MIXPayloadParserTest, WithNick) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<mix xmlns=\"urn:xmpp:mix:0\"> <nick>thirdwitch</nick> </mix>"
+ ));
+
+ auto payload = parser.getPayload<MIXPayload>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_TRUE(payload->getNick());
+ std::string nick = *payload->getNick();
+ ASSERT_EQ("thirdwitch", nick);
+
+ ASSERT_FALSE(payload->getJID());
+ ASSERT_FALSE(payload->getSubmissionID());
+}
+
+TEST(MIXPayloadParserTest, WithJID) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<mix xmlns=\"urn:xmpp:mix:0\"> <jid>hecate@mix.shakespeare.example</jid> </mix>"
+ ));
+
+ auto payload = parser.getPayload<MIXPayload>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_TRUE(payload->getJID());
+ JID jid = *payload->getJID();
+ ASSERT_EQ("hecate@mix.shakespeare.example", jid.toString());
+
+ ASSERT_FALSE(payload->getNick());
+ ASSERT_FALSE(payload->getSubmissionID());
+}
+
+TEST(MIXPayloadParserTest, WithAll) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<mix xmlns=\"urn:xmpp:mix:0\">"
+ "<nick>thirdwitch</nick>"
+ "<jid>hecate@mix.shakespeare.example</jid>"
+ "<submission-id>92vax143g</submission-id>"
+ "</mix>"
+ ));
+
+ auto payload = parser.getPayload<MIXPayload>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_TRUE(payload->getNick());
+ std::string nick = *payload->getNick();
+ ASSERT_EQ("thirdwitch", nick);
+
+ ASSERT_TRUE(payload->getJID());
+ JID jid = *payload->getJID();
+ ASSERT_EQ("hecate@mix.shakespeare.example", jid.toString());
+
+ ASSERT_TRUE(payload->getSubmissionID());
+ std::string subID = *payload->getSubmissionID();
+ ASSERT_EQ("92vax143g", subID);
+}
+
+TEST(MIXPayloadParserTest, Empty) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<mix xmlns=\"urn:xmpp:mix:0\"/>"
+ ));
+
+ auto payload = parser.getPayload<MIXPayload>();
+ ASSERT_TRUE(payload);
+ ASSERT_FALSE(payload->getNick());
+ ASSERT_FALSE(payload->getJID());
+ ASSERT_FALSE(payload->getSubmissionID());
+}