diff options
Diffstat (limited to 'Swiften/Parser')
6 files changed, 93 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 17fb478..939e1af 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -53,6 +53,7 @@ #include <Swiften/Parser/PayloadParsers/MAMResultParser.h> #include <Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h> #include <Swiften/Parser/PayloadParsers/MIXCreateParser.h> +#include <Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h> #include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h> #include <Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h> #include <Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h> @@ -138,6 +139,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { 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:0")); + factories_.push_back(std::make_shared<MIXSetNickParserFactory>()); factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXCreateParser> >("create", "urn:xmpp:mix:0")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXUserPreferenceParser> >("user-preference", "urn:xmpp:mix:0")); factories_.push_back(std::make_shared<MIXPayloadParserFactory>()); diff --git a/Swiften/Parser/PayloadParsers/MIXSetNickParser.cpp b/Swiften/Parser/PayloadParsers/MIXSetNickParser.cpp new file mode 100644 index 0000000..34fec70 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXSetNickParser.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXSetNickParser.h> + +namespace Swift { + +void MIXSetNickParser::handleTree(ParserElement::ref root) { + for (const auto& child : root->getAllChildren()) { + if (child->getName() == "nick" && child->getNamespace() == root->getNamespace()) { + getPayloadInternal()->setNick(child->getText()); + } + } +} + +} diff --git a/Swiften/Parser/PayloadParsers/MIXSetNickParser.h b/Swiften/Parser/PayloadParsers/MIXSetNickParser.h new file mode 100644 index 0000000..85a5ba9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXSetNickParser.h @@ -0,0 +1,20 @@ +/* + * 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/Base/Override.h> +#include <Swiften/Elements/MIXSetNick.h> +#include <Swiften/Parser/GenericPayloadTreeParser.h> + +namespace Swift { + class SWIFTEN_API MIXSetNickParser : public GenericPayloadTreeParser<MIXSetNick> { + public: + MIXSetNickParser() {} + virtual void handleTree(ParserElement::ref root) SWIFTEN_OVERRIDE; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h b/Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h new file mode 100644 index 0000000..4b11bb5 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h @@ -0,0 +1,28 @@ +/* + * 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/Base/Override.h> +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXSetNickParser.h> + +namespace Swift { + class SWIFTEN_API MIXSetNickParserFactory : public PayloadParserFactory { + public: + MIXSetNickParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const SWIFTEN_OVERRIDE { + return element == "setnick" && ns == "urn:xmpp:mix:0"; + } + + virtual PayloadParser* createPayloadParser() SWIFTEN_OVERRIDE { + return new MIXSetNickParser(); + } + }; +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXSetNickParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXSetNickParserTest.cpp new file mode 100644 index 0000000..84f8a5e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXSetNickParserTest.cpp @@ -0,0 +1,23 @@ +/* + * 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/MIXSetNick.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXSetNickParserTest, WithNick) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<setnick xmlns=\"urn:xmpp:mix:0\"> <nick>thirdwitch</nick> </setnick>" + )); + + auto payload = parser.getPayload<MIXSetNick>(); + ASSERT_TRUE(payload); + ASSERT_EQ("thirdwitch", payload->getNick()); +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 20dc3f4..d185052 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -68,6 +68,7 @@ sources = [ "PayloadParsers/VCardUpdateParser.cpp", "PayloadParsers/DelayParser.cpp", "PayloadParsers/MIXParticipantParser.cpp", + "PayloadParsers/MIXSetNickParser.cpp", "PayloadParsers/MIXDestroyParser.cpp", "PayloadParsers/MIXCreateParser.cpp", "PayloadParsers/MIXPayloadParser.cpp", |