diff options
Diffstat (limited to 'Swiften/Parser')
6 files changed, 91 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 939e1af..8f57704 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/MIXRegisterNickParserFactory.h> #include <Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h> #include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h> #include <Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h> @@ -139,6 +140,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<MIXRegisterNickParserFactory>()); 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")); diff --git a/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp new file mode 100644 index 0000000..945e9b2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.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/MIXRegisterNickParser.h> + +namespace Swift { + +void MIXRegisterNickParser::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/MIXRegisterNickParser.h b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h new file mode 100644 index 0000000..cfb618e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h @@ -0,0 +1,19 @@ +/* + * 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/MIXRegisterNick.h> +#include <Swiften/Parser/GenericPayloadTreeParser.h> + +namespace Swift { + class SWIFTEN_API MIXRegisterNickParser : public GenericPayloadTreeParser<MIXRegisterNick> { + public: + MIXRegisterNickParser() {} + virtual void handleTree(ParserElement::ref root) override; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h b/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h new file mode 100644 index 0000000..e03392c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h @@ -0,0 +1,27 @@ +/* + * 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/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h> + +namespace Swift { + class SWIFTEN_API MIXRegisterNickParserFactory : public PayloadParserFactory { + public: + MIXRegisterNickParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const override { + return element == "register" && ns == "urn:xmpp:mix:0"; + } + + virtual PayloadParser* createPayloadParser() override { + return new MIXRegisterNickParser(); + } + }; +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp new file mode 100644 index 0000000..d0539fd --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.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/MIXRegisterNick.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXRegisterNickParserTest, WithNick) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<register xmlns=\"urn:xmpp:mix:0\"> <nick>thirdwitch</nick> </register>" + )); + + auto payload = parser.getPayload<MIXRegisterNick>(); + ASSERT_TRUE(payload); + ASSERT_EQ("thirdwitch", payload->getNick()); +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index d185052..bfc7850 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -69,6 +69,7 @@ sources = [ "PayloadParsers/DelayParser.cpp", "PayloadParsers/MIXParticipantParser.cpp", "PayloadParsers/MIXSetNickParser.cpp", + "PayloadParsers/MIXRegisterNickParser.cpp", "PayloadParsers/MIXDestroyParser.cpp", "PayloadParsers/MIXCreateParser.cpp", "PayloadParsers/MIXPayloadParser.cpp", |