diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2017-06-24 17:07:44 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2017-06-25 09:01:13 (GMT) |
commit | 02763529a75970a1d57d9abf3448848f728c4101 (patch) | |
tree | 8eb5ee15eb01ed0c9c2a0924eb20a3556450aeac | |
parent | d46e946db8b25ddc34715e2e86c1e561f8381810 (diff) | |
download | swift-02763529a75970a1d57d9abf3448848f728c4101.zip swift-02763529a75970a1d57d9abf3448848f728c4101.tar.bz2 |
Adds MIX Destroy 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 Destroy Parser and Serializer based on
examples in XEP 0369, which passes.
Change-Id: I56810eb2fc26cc6aeb5e1cfb2a32e312f0607ba9
-rw-r--r-- | .circleci/config.yml | 8 | ||||
-rw-r--r-- | Swiften/Elements/MIXDestroy.h | 35 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp | 2 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp | 36 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/MIXDestroyParser.h | 31 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp | 25 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp | 24 | ||||
-rw-r--r-- | Swiften/Parser/SConscript | 1 | ||||
-rw-r--r-- | Swiften/SConscript | 15 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.cpp | 30 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.h | 25 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UnitTest/MIXDestroySerializerTest.cpp | 21 |
12 files changed, 240 insertions, 13 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml index 4ba10d9..81057c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,16 +3,10 @@ jobs: build: working_directory: ~/swift docker: - - image: debian:latest + - image: tfar/swift-gcc:latest steps: - checkout - run: - name: Install dependencies - command: | - apt-get -y update - apt-get -y install lsb-release locales python python3-setuptools python3-pip pkg-config libssl-dev qt5-default libqt5x11extras5-dev libqt5webkit5-dev qtmultimedia5-dev qttools5-dev-tools qt5-image-formats-plugins libqt5svg5-dev libminiupnpc-dev libnatpmp-dev libhunspell-dev g++-6 gcc-6 libboost-all-dev - pip3 -q install coala-bears[alldeps] - - run: name: Version information command: | lsb_release -a diff --git a/Swiften/Elements/MIXDestroy.h b/Swiften/Elements/MIXDestroy.h new file mode 100644 index 0000000..a674638 --- /dev/null +++ b/Swiften/Elements/MIXDestroy.h @@ -0,0 +1,35 @@ +/* + * 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 <string> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Payload.h> + +namespace Swift { + class SWIFTEN_API MIXDestroy : public Payload { + public: + using ref = std::shared_ptr<MIXDestroy>; + + public: + MIXDestroy() {} + virtual ~MIXDestroy() {} + + const std::string& getChannel() const { + return channel_; + } + + void setChannel(const std::string& channel) { + this->channel_ = channel; + } + + private: + std::string channel_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index f657e11..dbfcb6b 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -52,6 +52,7 @@ #include <Swiften/Parser/PayloadParsers/MAMQueryParser.h> #include <Swiften/Parser/PayloadParsers/MAMResultParser.h> #include <Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h> #include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h> @@ -131,6 +132,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { 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<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/MIXDestroyParser.cpp b/Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp new file mode 100644 index 0000000..0437b48 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +MIXDestroyParser::MIXDestroyParser() : level_(0) { +} + +MIXDestroyParser::~MIXDestroyParser() { +} + +void MIXDestroyParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("channel")) { + getPayloadInternal()->setChannel(*attributeValue); + } + } + ++level_; +} + +void MIXDestroyParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void MIXDestroyParser::handleCharacterData(const std::string&) { +} diff --git a/Swiften/Parser/PayloadParsers/MIXDestroyParser.h b/Swiften/Parser/PayloadParsers/MIXDestroyParser.h new file mode 100644 index 0000000..3a925de --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXDestroyParser.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 <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> +#include <Swiften/Elements/MIXDestroy.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParser; + + class SWIFTEN_API MIXDestroyParser : public GenericPayloadParser<MIXDestroy> { + public: + MIXDestroyParser(); + virtual ~MIXDestroyParser(); + + 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_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp new file mode 100644 index 0000000..fc2588a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.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 <gtest/gtest.h> + +#include <Swiften/Elements/MIXDestroy.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXDestroyParserTest, XEP0369_Example70) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<destroy channel=\"coven\" xmlns=\"urn:xmpp:mix:1\"/>" + )); + + auto payload = parser.getPayload<MIXDestroy>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(std::string("coven"), *payload->getChannel()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp new file mode 100644 index 0000000..8e4dff2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.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 <gtest/gtest.h> + +#include <Swiften/Elements/MIXDestroy.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXDestroyParserTest, XEP0369_Example70) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<destroy channel=\"coven\" xmlns=\"urn:xmpp:mix:1\"/>" + )); + + auto payload = parser.getPayload<MIXDestroy>(); + ASSERT_TRUE(payload); + + ASSERT_EQ(std::string("coven"), payload->getChannel()); +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 3ef6237..a01c1e1 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -68,6 +68,7 @@ sources = [ "PayloadParsers/VCardUpdateParser.cpp", "PayloadParsers/DelayParser.cpp", "PayloadParsers/MIXParticipantParser.cpp", + "PayloadParsers/MIXDestroyParser.cpp", "PayloadParsers/MUCUserPayloadParser.cpp", "PayloadParsers/MUCAdminPayloadParser.cpp", "PayloadParsers/MUCOwnerPayloadParser.cpp", diff --git a/Swiften/SConscript b/Swiften/SConscript index c2c3cb6..8b9ef12 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -23,7 +23,7 @@ if env["SCONS_STAGE"] == "flags" : env["SWIFTEN_LIBRARY"] = "Swiften" env["SWIFTEN_LIBRARY_FILE"] = "Swiften" env["SWIFTEN_LIBRARY_ALIASES"] = [] - + if env["SWIFTEN_DLL"] : if env["PLATFORM"] == "win32" : env["SWIFTEN_LIBRARY"] = env.subst("Swiften${SWIFTEN_VERSION_MAJOR}") @@ -65,7 +65,7 @@ if env["SCONS_STAGE"] == "flags" : if env.get("HAVE_SCHANNEL", 0) : dep_env.Append(LIBS = ["Winscard"]) - for var, e in [("SWIFTEN_FLAGS", swiften_env), ("SWIFTEN_DEP_FLAGS", dep_env)] : + for var, e in [("SWIFTEN_FLAGS", swiften_env), ("SWIFTEN_DEP_FLAGS", dep_env)] : env[var] = { "CPPDEFINES": e.get("CPPDEFINES", []), "CPPPATH": e.get("CPPPATH", []), @@ -92,7 +92,7 @@ if env["SCONS_STAGE"] == "build" : if env.get(module + "_BUNDLED", False) : swiften_env.Append(SWIFTEN_OBJECTS = env.get(module + "_OBJECTS", [])) swiften_env.UseFlags(swiften_env["PLATFORM_FLAGS"]) - + if swiften_env["SWIFTEN_DLL"] : swiften_env.AddMethod(lambda e,l,o : e.SharedLibrary(l,o), "SwiftenLibrary") else : @@ -208,6 +208,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/ErrorSerializer.cpp", "Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp", "Serializer/PayloadSerializers/MIXParticipantSerializer.cpp", + "Serializer/PayloadSerializers/MIXDestroySerializer.cpp", "Serializer/PayloadSerializers/MUCPayloadSerializer.cpp", "Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp", "Serializer/PayloadSerializers/MUCAdminPayloadSerializer.cpp", @@ -276,7 +277,7 @@ if env["SCONS_STAGE"] == "build" : "Elements/Whiteboard/WhiteboardColor.cpp", "Whiteboard/WhiteboardTransformer.cpp", ] - + elements = [ "PubSub", "PubSubAffiliations", "PubSubAffiliation", "PubSubConfigure", "PubSubCreate", "PubSubDefault", "PubSubItems", "PubSubItem", "PubSubOptions", "PubSubPublish", "PubSubRetract", "PubSubSubscribeOptions", @@ -294,7 +295,7 @@ if env["SCONS_STAGE"] == "build" : ] for element in elements : sources += [ - "Elements/" + element + ".cpp", + "Elements/" + element + ".cpp", "Serializer/PayloadSerializers/" + element + "Serializer.cpp", "Parser/PayloadParsers/" + element + "Parser.cpp", ] @@ -432,6 +433,7 @@ if env["SCONS_STAGE"] == "build" : File("Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/JingleParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp"), @@ -512,6 +514,7 @@ if env["SCONS_STAGE"] == "build" : File("Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/MIXParticipantSerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/MIXDestroySerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp"), @@ -545,7 +548,7 @@ if env["SCONS_STAGE"] == "build" : File("Whiteboard/UnitTest/WhiteboardServerTest.cpp"), File("Whiteboard/UnitTest/WhiteboardClientTest.cpp"), ]) - + # Generate the Swiften header def relpath(path, start) : i = len(os.path.commonprefix([path, start])) diff --git a/Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.cpp new file mode 100644 index 0000000..a395416 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.h> + +#include <memory> + +#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> + +using namespace Swift; + +MIXDestroySerializer::MIXDestroySerializer() { +} + +MIXDestroySerializer::~MIXDestroySerializer() { +} + +std::string MIXDestroySerializer::serializePayload(std::shared_ptr<MIXDestroy> payload) const { + if (!payload) { + return ""; + } + XMLElement element("destroy", "urn:xmpp:mix:1"); + element.setAttribute("channel", payload->getChannel()); + return element.serialize(); +} diff --git a/Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.h b/Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.h new file mode 100644 index 0000000..c14c0dd --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.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 <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> +#include <Swiften/Elements/MIXDestroy.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> + +namespace Swift { + + class SWIFTEN_API MIXDestroySerializer : public GenericPayloadSerializer<MIXDestroy> { + public: + MIXDestroySerializer(); + virtual ~MIXDestroySerializer(); + + virtual std::string serializePayload(std::shared_ptr<MIXDestroy>) const SWIFTEN_OVERRIDE; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXDestroySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXDestroySerializerTest.cpp new file mode 100644 index 0000000..e9cfa8b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXDestroySerializerTest.cpp @@ -0,0 +1,21 @@ +/* + * 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/Serializer/PayloadSerializers/MIXDestroySerializer.h> + +using namespace Swift; + +TEST(MIXDestroySerializerTest, XEP0369_Example31) { + MIXDestroySerializer testling; + + auto destroy = std::make_shared<MIXDestroy>(); + destroy->setChannel(std::string("coven")); + + std::string expectedResult = "<destroy channel=\"coven\" xmlns=\"urn:xmpp:mix:1\"/>"; + ASSERT_EQ(expectedResult, testling.serialize(destroy)); +} |