diff options
author | Kevin Smith <git@kismith.co.uk> | 2014-08-29 12:36:17 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2014-09-17 09:52:35 (GMT) |
commit | 5bb5e4eb3024dfba3ae2b5041b90472ee478aebe (patch) | |
tree | 6e3c47ba3236a65fa0a49eb6595f3e09db31bb3e /Swiften/Parser/PayloadParsers | |
parent | fc2714bf30ddd447405082ba4f8fa93bda369a6f (diff) | |
download | swift-5bb5e4eb3024dfba3ae2b5041b90472ee478aebe.zip swift-5bb5e4eb3024dfba3ae2b5041b90472ee478aebe.tar.bz2 |
Handle Isode's IQ Forwarding
Change-Id: I3b358e6a60f1ff546f2e578b6e0a54072b4c6da5
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
3 files changed, 152 insertions, 54 deletions
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 <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> + #include <Swiften/Base/foreach.h> + +#include <Swiften/Elements/BlockListPayload.h> #include <Swiften/Elements/BlockPayload.h> #include <Swiften/Elements/UnblockPayload.h> -#include <Swiften/Elements/BlockListPayload.h> + #include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/GenericPayloadParserFactory2.h> #include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Parser/PayloadParsers/ErrorParser.h> -#include <Swiften/Parser/PayloadParsers/ErrorParserFactory.h> -#include <Swiften/Parser/PayloadParsers/BodyParser.h> #include <Swiften/Parser/PayloadParsers/BlockParser.h> -#include <Swiften/Parser/PayloadParsers/SubjectParser.h> +#include <Swiften/Parser/PayloadParsers/BodyParser.h> +#include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> +#include <Swiften/Parser/PayloadParsers/CapsInfoParser.h> #include <Swiften/Parser/PayloadParsers/ChatStateParserFactory.h> -#include <Swiften/Parser/PayloadParsers/PriorityParser.h> -#include <Swiften/Parser/PayloadParsers/ResourceBindParser.h> -#include <Swiften/Parser/PayloadParsers/StartSessionParser.h> -#include <Swiften/Parser/PayloadParsers/StatusParser.h> -#include <Swiften/Parser/PayloadParsers/StatusShowParser.h> -#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h> -#include <Swiften/Parser/PayloadParsers/RosterParser.h> -#include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h> -#include <Swiften/Parser/PayloadParsers/StorageParser.h> +#include <Swiften/Parser/PayloadParsers/CommandParser.h> +#include <Swiften/Parser/PayloadParsers/DelayParser.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h> #include <Swiften/Parser/PayloadParsers/DiscoInfoParser.h> #include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h> -#include <Swiften/Parser/PayloadParsers/CapsInfoParser.h> -#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h> -#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h> +#include <Swiften/Parser/PayloadParsers/ErrorParser.h> +#include <Swiften/Parser/PayloadParsers/ErrorParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParserFactory.h> -#include <Swiften/Parser/PayloadParsers/CommandParser.h> -#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/SearchPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h> -#include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> +#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> #include <Swiften/Parser/PayloadParsers/IBBParser.h> -#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> -#include <Swiften/Parser/PayloadParsers/VCardParser.h> -#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h> -#include <Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h> -#include <Swiften/Parser/PayloadParsers/DelayParser.h> -#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/IdleParser.h> +#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h> +#include <Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h> +#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/JingleParserFactory.h> +#include <Swiften/Parser/PayloadParsers/JingleReasonParser.h> +#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/LastParser.h> +#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h> +#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h> +#include <Swiften/Parser/PayloadParsers/MAMResultParser.h> #include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/NicknameParser.h> +#include <Swiften/Parser/PayloadParsers/PriorityParser.h> +#include <Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubParser.h> +#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/ReplaceParser.h> -#include <Swiften/Parser/PayloadParsers/LastParser.h> -#include <Swiften/Parser/PayloadParsers/JingleParserFactory.h> -#include <Swiften/Parser/PayloadParsers/JingleReasonParser.h> -#include <Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h> -#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h> -#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h> +#include <Swiften/Parser/PayloadParsers/ResourceBindParser.h> +#include <Swiften/Parser/PayloadParsers/ResultSetParser.h> +#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h> +#include <Swiften/Parser/PayloadParsers/RosterParser.h> #include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h> -#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> -#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h> -#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h> -#include <Swiften/Parser/PayloadParsers/WhiteboardParser.h> -#include <Swiften/Parser/PayloadParsers/IdleParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SearchPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h> +#include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h> +#include <Swiften/Parser/PayloadParsers/StartSessionParser.h> +#include <Swiften/Parser/PayloadParsers/StatusParser.h> +#include <Swiften/Parser/PayloadParsers/StatusShowParser.h> +#include <Swiften/Parser/PayloadParsers/StorageParser.h> +#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h> +#include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h> +#include <Swiften/Parser/PayloadParsers/SubjectParser.h> #include <Swiften/Parser/PayloadParsers/UserLocationParser.h> #include <Swiften/Parser/PayloadParsers/UserTuneParser.h> -#include <Swiften/Parser/PayloadParsers/ResultSetParser.h> -#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> -#include <Swiften/Parser/PayloadParsers/MAMResultParser.h> -#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h> -#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h> +#include <Swiften/Parser/PayloadParsers/VCardParser.h> +#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> +#include <Swiften/Parser/PayloadParsers/WhiteboardParser.h> using namespace boost; @@ -154,6 +158,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this)); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMQueryParser> >("query", "urn:xmpp:mam:0")); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMArchivedParser> >("archived", "urn:xmpp:mam:0")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<IsodeIQDelegationParser> >("delegate", "http://isode.com/iq_delegation", this)); foreach(shared_ptr<PayloadParserFactory> 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 <Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +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<Forwarded>(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 <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/IsodeIQDelegation.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API IsodeIQDelegationParser : public GenericPayloadParser<IsodeIQDelegation> { + 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<PayloadParser> currentPayloadParser; + }; +} |