summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-06-24 16:09:39 (GMT)
committerTobias Markmann <tm@ayena.de>2017-07-03 19:02:35 (GMT)
commit4f61e116c83be5e38a8406ac3285a07b84712ec1 (patch)
tree1e7b2c908b1bc8e59b675ff940c32f2b505ccb55 /Swiften/Parser/PayloadParsers
parente142d11c3fa6ae2bdfc95ee9cea54bb0000917c9 (diff)
downloadswift-4f61e116c83be5e38a8406ac3285a07b84712ec1.zip
swift-4f61e116c83be5e38a8406ac3285a07b84712ec1.tar.bz2
Adds MIX Create Element, its Parser and Serializer
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Added tests for MIX Create Parser and Serializer based on examples in XEP 0369, which passes. Change-Id: I33b85c8243d55cd293c886f2607bdd9dec6c7bdb
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MIXCreateParser.cpp61
-rw-r--r--Swiften/Parser/PayloadParsers/MIXCreateParser.h32
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp89
4 files changed, 184 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 76827bb..bd9bdaa 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -25,60 +25,61 @@
#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>
#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h>
#include <Swiften/Parser/PayloadParsers/DiscoInfoParser.h>
#include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h>
#include <Swiften/Parser/PayloadParsers/ErrorParser.h>
#include <Swiften/Parser/PayloadParsers/ErrorParserFactory.h>
#include <Swiften/Parser/PayloadParsers/FormParserFactory.h>
#include <Swiften/Parser/PayloadParsers/ForwardedParser.h>
#include <Swiften/Parser/PayloadParsers/IBBParser.h>
#include <Swiften/Parser/PayloadParsers/IdleParser.h>
#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h>
#include <Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h>
#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h>
#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h>
#include <Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h>
#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/JingleParserFactory.h>
#include <Swiften/Parser/PayloadParsers/JingleReasonParser.h>
#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/LastParser.h>
#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/MIXCreateParser.h>
#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h>
#include <Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h>
#include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/NicknameParser.h>
#include <Swiften/Parser/PayloadParsers/PriorityParser.h>
#include <Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h>
#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h>
#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h>
#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h>
#include <Swiften/Parser/PayloadParsers/PubSubParser.h>
#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/ReplaceParser.h>
#include <Swiften/Parser/PayloadParsers/ResourceBindParser.h>
#include <Swiften/Parser/PayloadParsers/ResultSetParser.h>
#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h>
#include <Swiften/Parser/PayloadParsers/RosterParser.h>
#include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h>
#include <Swiften/Parser/PayloadParsers/SearchPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h>
#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h>
#include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h>
#include <Swiften/Parser/PayloadParsers/StartSessionParser.h>
#include <Swiften/Parser/PayloadParsers/StatusParser.h>
#include <Swiften/Parser/PayloadParsers/StatusShowParser.h>
#include <Swiften/Parser/PayloadParsers/StorageParser.h>
@@ -107,60 +108,61 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(std::make_shared<GenericPayloadParserFactory<PriorityParser> >("priority"));
factories_.push_back(std::make_shared<ErrorParserFactory>(this));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<DelayParser> >("delay", "urn:xmpp:delay"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<SoftwareVersionParser> >("query", "jabber:iq:version"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<StorageParser> >("storage", "storage:bookmarks"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<RosterItemExchangeParser> >("x", "http://jabber.org/protocol/rosterx"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<RosterParser> >("query", "jabber:iq:roster"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<DiscoInfoParser> >("query", "http://jabber.org/protocol/disco#info"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<DiscoItemsParser> >("query", "http://jabber.org/protocol/disco#items"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<CapsInfoParser> >("c", "http://jabber.org/protocol/caps"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<ResourceBindParser> >("bind", "urn:ietf:params:xml:ns:xmpp-bind"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<StartSessionParser> >("session", "urn:ietf:params:xml:ns:xmpp-session"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<BlockParser<BlockPayload> > >("block", "urn:xmpp:blocking"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<BlockParser<BlockListPayload> > >("blocklist", "urn:xmpp:blocking"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<BlockParser<UnblockPayload> > >("unblock", "urn:xmpp:blocking"));
factories_.push_back(std::make_shared<SecurityLabelParserFactory>());
factories_.push_back(std::make_shared<GenericPayloadParserFactory<SecurityLabelsCatalogParser> >("catalog", "urn:xmpp:sec-label:catalog:2"));
factories_.push_back(std::make_shared<FormParserFactory>());
factories_.push_back(std::make_shared<GenericPayloadParserFactory<CommandParser> >("command", "http://jabber.org/protocol/commands"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<InBandRegistrationPayloadParser> >("query", "jabber:iq:register"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<SearchPayloadParser> >("query", "jabber:iq:search"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<StreamInitiationParser> >("si", "http://jabber.org/protocol/si"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<BytestreamsParser> >("query", "http://jabber.org/protocol/bytestreams"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<VCardUpdateParser> >("x", "vcard-temp:x:update"));
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<MIXParticipantParserFactory>());
factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXDestroyParser> >("destroy", "urn:xmpp:mix:1"));
+ factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXCreateParser> >("create", "urn:xmpp:mix:1"));
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"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<MUCAdminPayloadParser> >("query", "http://jabber.org/protocol/muc#admin"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#user"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#owner"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<NicknameParser> >("nick", "http://jabber.org/protocol/nick"));
factories_.push_back(std::make_shared<JingleParserFactory>(this));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleReasonParser> >("reason", "urn:xmpp:jingle:1"));
factories_.push_back(std::make_shared<JingleContentPayloadParserFactory>(this));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleIBBTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:ibb:1"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleS5BTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:s5b:1"));
factories_.push_back(std::make_shared<JingleFileTransferDescriptionParserFactory>(this));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<StreamInitiationFileInfoParser> >("file", "http://jabber.org/protocol/si/profile/file-transfer"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleFileTransferFileInfoParser> >("file", "urn:xmpp:jingle:apps:file-transfer:4"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory<UserTuneParser> >("tune", "http://jabber.org/protocol/tune"));
factories_.push_back(std::make_shared<DeliveryReceiptParserFactory>());
factories_.push_back(std::make_shared<DeliveryReceiptRequestParserFactory>());
factories_.push_back(std::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory2<PubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub", this));
factories_.push_back(std::make_shared<GenericPayloadParserFactory2<PubSubOwnerPubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub#owner", this));
factories_.push_back(std::make_shared<GenericPayloadParserFactory2<PubSubEventParser> >("event", "http://jabber.org/protocol/pubsub#event", this));
factories_.push_back(std::make_shared<PubSubErrorParserFactory>());
factories_.push_back(std::make_shared<GenericPayloadParserFactory<ResultSetParser> >("set", "http://jabber.org/protocol/rsm"));
factories_.push_back(std::make_shared<GenericPayloadParserFactory2<ForwardedParser> >("forwarded", "urn:xmpp:forward:0", this));
factories_.push_back(std::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this));
diff --git a/Swiften/Parser/PayloadParsers/MIXCreateParser.cpp b/Swiften/Parser/PayloadParsers/MIXCreateParser.cpp
new file mode 100644
index 0000000..8c4ec8a
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXCreateParser.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/MIXCreateParser.h>
+
+#include <boost/optional.hpp>
+
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/FormParser.h>
+
+using namespace Swift;
+
+MIXCreateParser::MIXCreateParser() : level_(0) {
+}
+
+MIXCreateParser::~MIXCreateParser() {
+}
+
+void MIXCreateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level_ == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("channel")) {
+ getPayloadInternal()->setChannel(*attributeValue);
+ }
+ }
+
+ if (level_ == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ currentPayloadParser_ = std::make_shared<FormParser>();
+ }
+ }
+
+ if (level_ >= 1 && currentPayloadParser_) {
+ currentPayloadParser_->handleStartElement(element, ns, attributes);
+ }
+ ++level_;
+}
+
+void MIXCreateParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level_;
+ if (currentPayloadParser_) {
+ if (level_ >= 1) {
+ currentPayloadParser_->handleEndElement(element, ns);
+ }
+
+ if (level_ == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ getPayloadInternal()->setData(std::dynamic_pointer_cast<Form>(currentPayloadParser_->getPayload()));
+ }
+ currentPayloadParser_.reset();
+ }
+ }
+}
+
+void MIXCreateParser::handleCharacterData(const std::string& data) {
+ if (level_ > 1 && currentPayloadParser_) {
+ currentPayloadParser_->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/MIXCreateParser.h b/Swiften/Parser/PayloadParsers/MIXCreateParser.h
new file mode 100644
index 0000000..60e3040
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MIXCreateParser.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Base/Override.h>
+#include <Swiften/Elements/MIXCreate.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParser;
+
+ class SWIFTEN_API MIXCreateParser : public GenericPayloadParser<MIXCreate> {
+ public:
+ MIXCreateParser();
+ virtual ~MIXCreateParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ int level_;
+ std::shared_ptr<PayloadParser> currentPayloadParser_;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp
new file mode 100644
index 0000000..85c79c6
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp
@@ -0,0 +1,89 @@
+/*
+ * 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/MIXCreate.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+TEST(MIXCreateParserTest, XEP0369_Example68) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<create xmlns=\"urn:xmpp:mix:1\"/>"
+ ));
+
+ auto payload = parser.getPayload<MIXCreate>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_FALSE(payload->getData());
+ ASSERT_FALSE(payload->getChannel());
+}
+
+TEST(MIXCreateParserTest, XEP0369_Example66) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<create channel=\"coven\" xmlns=\"urn:xmpp:mix:1\"/>"
+ ));
+
+ auto payload = parser.getPayload<MIXCreate>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_FALSE(payload->getData());
+
+ ASSERT_TRUE(payload->getChannel());
+ ASSERT_EQ(std::string("coven"), *payload->getChannel());
+}
+
+TEST(MIXCreateParserTest, XEP0369_Example67) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<create channel=\"coven\" xmlns=\"urn:xmpp:mix:1\">"
+ "<x xmlns=\"jabber:x:data\" type=\"result\">"
+ "<field var=\"FORM_TYPE\" type=\"hidden\">"
+ "<value>urn:xmpp:mix:1</value>"
+ "</field>"
+ "<field var=\"Owner\">"
+ "<value>hecate@shakespeare.lit</value>"
+ "<value>greymalkin@shakespeare.lit</value>"
+ "</field>"
+ "<field var=\"Messages Node Subscription\">"
+ "<value>allowed</value>"
+ "</field>"
+ "<field var=\"JID Visibility\">"
+ "<value>jid-mandatory-visible</value>"
+ "</field>"
+ "<field var=\"No Private Messages\">"
+ "<value>true</value>"
+ "</field>"
+ "</x>"
+ "</create>"
+ ));
+
+ auto payload = parser.getPayload<MIXCreate>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_TRUE(payload->getData());
+ ASSERT_EQ(Form::Type::ResultType, payload->getData()->getType());
+ std::shared_ptr<FormField> fieldType = payload->getData()->getField("FORM_TYPE");
+ ASSERT_TRUE(fieldType);
+
+ std::shared_ptr<FormField> fieldJIDVisibility = payload->getData()->getField("JID Visibility");
+ ASSERT_TRUE(fieldJIDVisibility);
+ ASSERT_EQ(std::string("jid-mandatory-visible"), fieldJIDVisibility->getTextSingleValue());
+
+ std::shared_ptr<FormField> fieldprivateMessages = payload->getData()->getField("No Private Messages");
+ ASSERT_TRUE(fieldprivateMessages);
+ ASSERT_EQ(std::string("true"), fieldprivateMessages->getTextSingleValue());
+
+ std::shared_ptr<FormField> nodeSubs = payload->getData()->getField("Messages Node Subscription");
+ ASSERT_TRUE(nodeSubs);
+ ASSERT_EQ(std::string("allowed"), nodeSubs->getTextSingleValue());
+
+ ASSERT_TRUE(payload->getChannel());
+ ASSERT_EQ(std::string("coven"), *payload->getChannel());
+}