From 5bb5e4eb3024dfba3ae2b5041b90472ee478aebe Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Fri, 29 Aug 2014 13:36:17 +0100 Subject: Handle Isode's IQ Forwarding Change-Id: I3b358e6a60f1ff546f2e578b6e0a54072b4c6da5 diff --git a/Sluift/ElementConvertors/ElementConvertors.ipp b/Sluift/ElementConvertors/ElementConvertors.ipp index 234ed66..ef2416c 100644 --- a/Sluift/ElementConvertors/ElementConvertors.ipp +++ b/Sluift/ElementConvertors/ElementConvertors.ipp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Remko Tronçon + * Copyright (c) 2013-2014 Remko Tronçon and Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,7 @@ void LuaElementConvertors::registerConvertors() { convertors.push_back(boost::make_shared(this)); convertors.push_back(boost::make_shared(this)); convertors.push_back(boost::make_shared(this)); + convertors.push_back(boost::make_shared(this)); convertors.push_back(boost::make_shared(this)); convertors.push_back(boost::make_shared(this)); convertors.push_back(boost::make_shared(this)); diff --git a/Sluift/ElementConvertors/IsodeIQDelegationConvertor.cpp b/Sluift/ElementConvertors/IsodeIQDelegationConvertor.cpp new file mode 100644 index 0000000..889c32b --- /dev/null +++ b/Sluift/ElementConvertors/IsodeIQDelegationConvertor.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include + +#include +#include + + +#include + +#pragma clang diagnostic ignored "-Wunused-private-field" + +using namespace Swift; + +IsodeIQDelegationConvertor::IsodeIQDelegationConvertor(LuaElementConvertors* convertors) : + GenericLuaElementConvertor("isode_iq_delegation"), + convertors(convertors) { +} + +IsodeIQDelegationConvertor::~IsodeIQDelegationConvertor() { +} + +boost::shared_ptr IsodeIQDelegationConvertor::doConvertFromLua(lua_State* L) { + boost::shared_ptr result = boost::make_shared(); + lua_getfield(L, -1, "forward"); + if (!lua_isnil(L, -1)) { + if (boost::shared_ptr payload = boost::dynamic_pointer_cast(convertors->convertFromLuaUntyped(L, -1, "forwarded"))) { + result->setForward(payload); + } + } + lua_pop(L, 1); + return result; +} + +void IsodeIQDelegationConvertor::doConvertToLua(lua_State* L, boost::shared_ptr payload) { + lua_createtable(L, 0, 0); + if (convertors->convertToLuaUntyped(L, payload->getForward()) > 0) { + lua_setfield(L, -2, "forward"); + } +} + +boost::optional IsodeIQDelegationConvertor::getDocumentation() const { + return Documentation( + "IsodeIQDelegation", + "This table has the following fields:\n\n" + "- `forward`: @{Forwarded}\n" + ); +} diff --git a/Sluift/ElementConvertors/IsodeIQDelegationConvertor.h b/Sluift/ElementConvertors/IsodeIQDelegationConvertor.h new file mode 100644 index 0000000..079423d --- /dev/null +++ b/Sluift/ElementConvertors/IsodeIQDelegationConvertor.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include +#include + +namespace Swift { + class LuaElementConvertors; + + class IsodeIQDelegationConvertor : public GenericLuaElementConvertor { + public: + IsodeIQDelegationConvertor(LuaElementConvertors* convertors); + virtual ~IsodeIQDelegationConvertor(); + + virtual boost::shared_ptr doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; + virtual void doConvertToLua(lua_State*, boost::shared_ptr) SWIFTEN_OVERRIDE; + virtual boost::optional getDocumentation() const SWIFTEN_OVERRIDE; + + private: + LuaElementConvertors* convertors; + }; +} diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript index b9bfc22..5ff5379 100644 --- a/Sluift/ElementConvertors/SConscript +++ b/Sluift/ElementConvertors/SConscript @@ -48,6 +48,7 @@ convertors = [ env.File("MAMResultConvertor.cpp"), env.File("MAMQueryConvertor.cpp"), env.File("MAMArchivedConvertor.cpp"), - env.File("SubjectConvertor.cpp") + env.File("SubjectConvertor.cpp"), + env.File("IsodeIQDelegationConvertor.cpp") ] Return('convertors') diff --git a/Swiften/Elements/IsodeIQDelegation.cpp b/Swiften/Elements/IsodeIQDelegation.cpp new file mode 100644 index 0000000..ce13e2a --- /dev/null +++ b/Swiften/Elements/IsodeIQDelegation.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include + +using namespace Swift; + +IsodeIQDelegation::IsodeIQDelegation() { +} + +IsodeIQDelegation::~IsodeIQDelegation() { +} diff --git a/Swiften/Elements/IsodeIQDelegation.h b/Swiften/Elements/IsodeIQDelegation.h new file mode 100644 index 0000000..7935a4f --- /dev/null +++ b/Swiften/Elements/IsodeIQDelegation.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include +#include +#include +#include + +#include + +namespace Swift { + class SWIFTEN_API IsodeIQDelegation : public Payload { + public: + + IsodeIQDelegation(); + + virtual ~IsodeIQDelegation(); + + boost::shared_ptr getForward() const { + return forward; + } + + void setForward(boost::shared_ptr value) { + this->forward = value ; + } + + + private: + boost::shared_ptr forward; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 4541b3b..49dd1e3 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -5,82 +5,86 @@ */ #include + #include + +#include #include #include -#include + #include #include #include #include -#include -#include -#include #include -#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include -#include -#include -#include +#include +#include #include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include #include +#include #include +#include #include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include +#include +#include +#include using namespace boost; @@ -154,6 +158,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(boost::make_shared >("result", "urn:xmpp:mam:0", this)); factories_.push_back(boost::make_shared >("query", "urn:xmpp:mam:0")); factories_.push_back(boost::make_shared >("archived", "urn:xmpp:mam:0")); + factories_.push_back(boost::make_shared >("delegate", "http://isode.com/iq_delegation", this)); foreach(shared_ptr factory, factories_) { addFactory(factory.get()); diff --git a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp new file mode 100644 index 0000000..d085d09 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include + +#include + + +#include +#include + + +using namespace Swift; + +IsodeIQDelegationParser::IsodeIQDelegationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +IsodeIQDelegationParser::~IsodeIQDelegationParser() { +} + +void IsodeIQDelegationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + + + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; +} + +void IsodeIQDelegationParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->setForward(boost::dynamic_pointer_cast(currentPayloadParser->getPayload())); + currentPayloadParser.reset(); + } + } +} + +void IsodeIQDelegationParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h new file mode 100644 index 0000000..83bf95e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include +#include +#include +#include + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API IsodeIQDelegationParser : public GenericPayloadParser { + public: + IsodeIQDelegationParser(PayloadParserFactoryCollection* parsers); + virtual ~IsodeIQDelegationParser(); + + 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: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr currentPayloadParser; + }; +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 056862f..e748320 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -82,6 +82,7 @@ sources = [ "PayloadParsers/MAMResultParser.cpp", "PayloadParsers/MAMQueryParser.cpp", "PayloadParsers/MAMArchivedParser.cpp", + "PayloadParsers/IsodeIQDelegationParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", "SerializingParser.cpp", diff --git a/Swiften/SConscript b/Swiften/SConscript index 0314118..a37767c 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -147,6 +147,7 @@ if env["SCONS_STAGE"] == "build" : "Elements/MAMResult.cpp", "Elements/MAMQuery.cpp", "Elements/MAMArchived.cpp", + "Elements/IsodeIQDelegation.cpp", "Entity/Entity.cpp", "Entity/PayloadPersister.cpp", "MUC/MUC.cpp", @@ -230,6 +231,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/MAMResultSerializer.cpp", "Serializer/PayloadSerializers/MAMQuerySerializer.cpp", "Serializer/PayloadSerializers/MAMArchivedSerializer.cpp", + "Serializer/PayloadSerializers/IsodeIQDelegationSerializer.cpp", "Serializer/PresenceSerializer.cpp", "Serializer/StanzaSerializer.cpp", "Serializer/StreamErrorSerializer.cpp", diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index b5269d1..dcfb4ed 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -10,71 +10,71 @@ #include #include #include -#include -#include #include -#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include - -#include +#include +#include +#include +#include #include #include #include #include #include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace Swift { @@ -148,6 +148,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new MAMResultSerializer(this)); serializers_.push_back(new MAMQuerySerializer()); serializers_.push_back(new MAMArchivedSerializer()); + serializers_.push_back(new IsodeIQDelegationSerializer(this)); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); diff --git a/Swiften/Serializer/PayloadSerializers/IsodeIQDelegationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/IsodeIQDelegationSerializer.cpp new file mode 100644 index 0000000..8e782b4 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/IsodeIQDelegationSerializer.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include +#include +#include + +#include +#include + +using namespace Swift; + +IsodeIQDelegationSerializer::IsodeIQDelegationSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +IsodeIQDelegationSerializer::~IsodeIQDelegationSerializer() { +} + +std::string IsodeIQDelegationSerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; + } + XMLElement element("delegate", "http://isode.com/iq_delegation"); + element.addNode(boost::make_shared(serializers->getPayloadSerializer(payload->getForward())->serialize(payload->getForward()))); + return element.serialize(); +} + + diff --git a/Swiften/Serializer/PayloadSerializers/IsodeIQDelegationSerializer.h b/Swiften/Serializer/PayloadSerializers/IsodeIQDelegationSerializer.h new file mode 100644 index 0000000..1bcd993 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/IsodeIQDelegationSerializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API IsodeIQDelegationSerializer : public GenericPayloadSerializer { + public: + IsodeIQDelegationSerializer(PayloadSerializerCollection* serializers); + virtual ~IsodeIQDelegationSerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + + private: + + + private: + PayloadSerializerCollection* serializers; + }; +} -- cgit v0.10.2-6-g49f6