From 02763529a75970a1d57d9abf3448848f728c4101 Mon Sep 17 00:00:00 2001 From: Tarun Gupta Date: Sat, 24 Jun 2017 22:37:44 +0530 Subject: 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 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 +#include + +#include +#include + +namespace Swift { + class SWIFTEN_API MIXDestroy : public Payload { + public: + using ref = std::shared_ptr; + + 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 #include #include +#include #include #include #include @@ -131,6 +132,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(std::make_shared()); factories_.push_back(std::make_shared()); factories_.push_back(std::make_shared()); + factories_.push_back(std::make_shared >("destroy", "urn:xmpp:mix:1")); factories_.push_back(std::make_shared(this)); factories_.push_back(std::make_shared(this)); factories_.push_back(std::make_shared >("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 + +#include + +#include +#include + +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 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 + +#include +#include +#include +#include + +namespace Swift { + class PayloadParser; + + class SWIFTEN_API MIXDestroyParser : public GenericPayloadParser { + 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 + +#include +#include + +using namespace Swift; + +TEST(MIXDestroyParserTest, XEP0369_Example70) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "" + )); + + auto payload = parser.getPayload(); + 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 + +#include +#include + +using namespace Swift; + +TEST(MIXDestroyParserTest, XEP0369_Example70) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "" + )); + + auto payload = parser.getPayload(); + 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 + +#include + +#include +#include +#include + +using namespace Swift; + +MIXDestroySerializer::MIXDestroySerializer() { +} + +MIXDestroySerializer::~MIXDestroySerializer() { +} + +std::string MIXDestroySerializer::serializePayload(std::shared_ptr 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 + +#include +#include +#include +#include + +namespace Swift { + + class SWIFTEN_API MIXDestroySerializer : public GenericPayloadSerializer { + public: + MIXDestroySerializer(); + virtual ~MIXDestroySerializer(); + + virtual std::string serializePayload(std::shared_ptr) 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 + +#include + +using namespace Swift; + +TEST(MIXDestroySerializerTest, XEP0369_Example31) { + MIXDestroySerializer testling; + + auto destroy = std::make_shared(); + destroy->setChannel(std::string("coven")); + + std::string expectedResult = ""; + ASSERT_EQ(expectedResult, testling.serialize(destroy)); +} -- cgit v0.10.2-6-g49f6