summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MIXParticipantParser.cpp24
-rw-r--r--Swiften/Parser/PayloadParsers/MIXParticipantParser.h19
-rw-r--r--Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h27
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp59
-rw-r--r--Swiften/Parser/SConscript1
6 files changed, 132 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 4ad943a..f657e11 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -51,6 +51,7 @@
#include <Swiften/Parser/PayloadParsers/MAMFinParser.h>
#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h>
#include <Swiften/Parser/PayloadParsers/MAMResultParser.h>
+#include <Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h>
#include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h>
@@ -129,6 +130,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(std::make_shared<PrivateStorageParserFactory>(this));
factories_.push_back(std::make_shared<ChatStateParserFactory>());
factories_.push_back(std::make_shared<ClientStateParserFactory>());
+ factories_.push_back(std::make_shared<MIXParticipantParserFactory>());
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/MIXParticipantParser.cpp b/Swiften/Parser/PayloadParsers/MIXParticipantParser.cpp
new file mode 100644
index 0000000..0ab2b87
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXParticipantParser.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/MIXParticipantParser.h>
+
+namespace Swift {
+
+void MIXParticipantParser::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);
+ }
+ }
+ }
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/MIXParticipantParser.h b/Swiften/Parser/PayloadParsers/MIXParticipantParser.h
new file mode 100644
index 0000000..0a3ea57
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXParticipantParser.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/MIXParticipant.h>
+#include <Swiften/Parser/GenericPayloadTreeParser.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXParticipantParser : public GenericPayloadTreeParser<MIXParticipant> {
+ public:
+ MIXParticipantParser() {}
+ virtual void handleTree(ParserElement::ref root);
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h b/Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h
new file mode 100644
index 0000000..cd7c17e
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.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/MIXParticipantParser.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXParticipantParserFactory : public PayloadParserFactory {
+ public:
+ MIXParticipantParserFactory() {
+ }
+
+ virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const {
+ return element == "participant" && ns == "urn:xmpp:mix:0";
+ }
+
+ virtual PayloadParser* createPayloadParser() {
+ return new MIXParticipantParser();
+ }
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp
new file mode 100644
index 0000000..27c02e7
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp
@@ -0,0 +1,59 @@
+/*
+ * 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/MIXParticipant.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+TEST(MIXParticipantParserTest, XEP0369_Example1_ParticipantWithNick) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<participant xmlns='urn:xmpp:mix:0'> <nick>thirdwitch</nick> </participant>"
+ ));
+
+ MIXParticipant::ref payload = parser.getPayload<MIXParticipant>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_TRUE(payload->getNick());
+ std::string nick = *payload->getNick();
+ ASSERT_EQ("thirdwitch", nick);
+
+ ASSERT_FALSE(payload->getJID());
+}
+
+TEST(MIXParticipantParserTest, XEP0369_Example2_ParticipantWithJID) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<participant xmlns='urn:xmpp:mix:0'> <jid>hecate@mix.shakespeare.example</jid> </participant>"
+ ));
+
+ MIXParticipant::ref payload = parser.getPayload<MIXParticipant>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_TRUE(payload->getJID());
+ JID jid = *payload->getJID();
+ ASSERT_EQ("hecate@mix.shakespeare.example", jid.toString());
+
+ ASSERT_FALSE(payload->getNick());
+}
+
+TEST(MIXParticipantParserTest, XEP0369_Example27_ParticipantEmpty) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<participant xmlns='urn:xmpp:mix:0'/>"
+ ));
+
+ MIXParticipant::ref payload = parser.getPayload<MIXParticipant>();
+ ASSERT_TRUE(payload);
+ ASSERT_FALSE(payload->getNick());
+ ASSERT_FALSE(payload->getJID());
+}
+
+
+
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 1797de1..3ef6237 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -67,6 +67,7 @@ sources = [
"PayloadParsers/VCardParser.cpp",
"PayloadParsers/VCardUpdateParser.cpp",
"PayloadParsers/DelayParser.cpp",
+ "PayloadParsers/MIXParticipantParser.cpp",
"PayloadParsers/MUCUserPayloadParser.cpp",
"PayloadParsers/MUCAdminPayloadParser.cpp",
"PayloadParsers/MUCOwnerPayloadParser.cpp",