summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-03-22 09:18:20 (GMT)
committerTobias Markmann <tm@ayena.de>2017-03-23 21:07:53 (GMT)
commitcc873b3f00db4cd0a778bc2ec04f8748d70a92f9 (patch)
tree818b12d322fae76631668d8b64de082c6e20163e /Swiften/Parser
parent9bc6492fa3da165e0e3b9bb09b8f913d02275d11 (diff)
downloadswift-cc873b3f00db4cd0a778bc2ec04f8748d70a92f9.zip
swift-cc873b3f00db4cd0a778bc2ec04f8748d70a92f9.tar.bz2
Add Client State Indication Element, its Parser and Serializer
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Adds tests for Client State Parser and Serializer, which passes. Tests performed on Ubuntu 16.04 LTS. Change-Id: I60c63f63e1c0fdd55600ef42faa95989ca5ab75b
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/ClientStateParser.cpp35
-rw-r--r--Swiften/Parser/PayloadParsers/ClientStateParser.h25
-rw-r--r--Swiften/Parser/PayloadParsers/ClientStateParserFactory.h31
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/ClientStateParserTest.cpp32
-rw-r--r--Swiften/Parser/SConscript1
6 files changed, 126 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/ClientStateParser.cpp b/Swiften/Parser/PayloadParsers/ClientStateParser.cpp
new file mode 100644
index 0000000..8a6cc9c
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/ClientStateParser.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/ClientStateParser.h>
+
+namespace Swift {
+
+ClientStateParser::ClientStateParser() {
+}
+
+void ClientStateParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) {
+ if (level_ == 0) {
+ auto state = ClientState::ClientStateType::Active;
+ if (element == "active") {
+ state = ClientState::ClientStateType::Active;
+ } else if (element == "inactive") {
+ state = ClientState::ClientStateType::Inactive;
+ }
+ getPayloadInternal()->setClientState(state);
+ }
+ ++level_;
+}
+
+void ClientStateParser::handleEndElement(const std::string&, const std::string&) {
+ --level_;
+}
+
+void ClientStateParser::handleCharacterData(const std::string&) {
+
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/ClientStateParser.h b/Swiften/Parser/PayloadParsers/ClientStateParser.h
new file mode 100644
index 0000000..039ae37
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/ClientStateParser.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 <Swiften/Base/API.h>
+#include <Swiften/Elements/ClientState.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class SWIFTEN_API ClientStateParser : public GenericPayloadParser<ClientState> {
+ public:
+ ClientStateParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
+ virtual void handleEndElement(const std::string& element, const std::string&);
+ virtual void handleCharacterData(const std::string& data);
+
+ private:
+ int level_ = 0;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/ClientStateParserFactory.h b/Swiften/Parser/PayloadParsers/ClientStateParserFactory.h
new file mode 100644
index 0000000..95617a1
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/ClientStateParserFactory.h
@@ -0,0 +1,31 @@
+/*
+ * 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/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/ClientStateParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+
+ class SWIFTEN_API ClientStateParserFactory : public PayloadParserFactory {
+ public:
+ ClientStateParserFactory() {
+ }
+
+ virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const {
+ return ns == "urn:xmpp:csi:0" &&
+ (element == "active" || element == "inactive");
+ }
+
+ virtual PayloadParser* createPayloadParser() {
+ return new ClientStateParser();
+ }
+
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index b67556e..4ad943a 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -23,6 +23,7 @@
#include <Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h>
#include <Swiften/Parser/PayloadParsers/CarbonsSentParser.h>
#include <Swiften/Parser/PayloadParsers/ChatStateParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/ClientStateParserFactory.h>
#include <Swiften/Parser/PayloadParsers/CommandParser.h>
#include <Swiften/Parser/PayloadParsers/DelayParser.h>
#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h>
@@ -127,6 +128,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(std::make_shared<GenericPayloadParserFactory<VCardParser> >("vCard", "vcard-temp"));
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<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/UnitTest/ClientStateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ClientStateParserTest.cpp
new file mode 100644
index 0000000..ca89040
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/ClientStateParserTest.cpp
@@ -0,0 +1,32 @@
+/*
+ * 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/ClientState.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+TEST(ClientStateParserTest, testParse_Active) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<active xmlns='urn:xmpp:csi:0'/>"
+ ));
+
+ ClientState::ref payload = parser.getPayload<ClientState>();
+ ASSERT_EQ(ClientState::ClientStateType::Active, payload->getClientState());
+}
+
+TEST(ClientStateParserTest, testParse_Inactive) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<inactive xmlns='urn:xmpp:csi:0'/>"
+ ));
+
+ ClientState::ref payload = parser.getPayload<ClientState>();
+ ASSERT_EQ(ClientState::ClientStateType::Inactive, payload->getClientState());
+}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 840cbda..1797de1 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -30,6 +30,7 @@ sources = [
"PayloadParsers/CarbonsReceivedParser.cpp",
"PayloadParsers/CarbonsSentParser.cpp",
"PayloadParsers/ChatStateParser.cpp",
+ "PayloadParsers/ClientStateParser.cpp",
"PayloadParsers/CapsInfoParser.cpp",
"PayloadParsers/DiscoInfoParser.cpp",
"PayloadParsers/DiscoItemsParser.cpp",