diff options
author | Tobias Markmann <tm@ayena.de> | 2015-03-02 15:05:17 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-03-28 10:32:15 (GMT) |
commit | 81f06ccf527dbbd3b9082d7c1a35e4e312a168e0 (patch) | |
tree | dcfd16db1077e8a26ee1e49265d76b06e06f972e | |
parent | 2d13a4a47a076efde64671bc8eac2b4363a8790f (diff) | |
download | swift-81f06ccf527dbbd3b9082d7c1a35e4e312a168e0.zip swift-81f06ccf527dbbd3b9082d7c1a35e4e312a168e0.tar.bz2 |
Change IQ handling to allow non-final IQ handlers/responders
Previously all IQ handlers were final. The IQ handles were processed
in last-added-first order and if the IQ payload matched the handler
payload, the IQ would only be passed to that handler.
This conflicts with our IBBReceiveSession. When running multiple
concurrent file-transfers using multiple IBBReceiveSessions there are
multiple IQ handlers for IBB content; one for every transfer.
This commit allows a Responder to be set as non-final. In this case
unhandled IQs will not be responded with an error but returned to
the IQRouter so it can pass it to the next possible IQ handler.
Test-Information:
Tested with ConcurrentFileTransferTest with runs multiple IBB transfers
in parallel.
Change-Id: I8237e234cbe5c110deaa8c3d6ba303b65fd53d00
-rw-r--r-- | Swiften/FileTransfer/IBBReceiveSession.cpp | 3 | ||||
-rw-r--r-- | Swiften/Queries/Responder.h | 16 |
2 files changed, 15 insertions, 4 deletions
diff --git a/Swiften/FileTransfer/IBBReceiveSession.cpp b/Swiften/FileTransfer/IBBReceiveSession.cpp index b4db9a6..ac58b34 100644 --- a/Swiften/FileTransfer/IBBReceiveSession.cpp +++ b/Swiften/FileTransfer/IBBReceiveSession.cpp @@ -1,8 +1,8 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/IBBReceiveSession.h> @@ -18,12 +18,13 @@ namespace Swift { class IBBReceiveSession::IBBResponder : public SetResponder<IBB> { public: IBBResponder(IBBReceiveSession* session, IQRouter* router) : SetResponder<IBB>(router), session(session), sequenceNumber(0), receivedSize(0) { + setFinal(false); } virtual bool handleSetRequest(const JID& from, const JID&, const std::string& id, IBB::ref ibb) { if (from == session->from && ibb->getStreamID() == session->id) { if (ibb->getAction() == IBB::Data) { if (sequenceNumber == ibb->getSequenceNumber()) { diff --git a/Swiften/Queries/Responder.h b/Swiften/Queries/Responder.h index 85b0589..84d232a 100644 --- a/Swiften/Queries/Responder.h +++ b/Swiften/Queries/Responder.h @@ -1,8 +1,8 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -20,13 +20,13 @@ namespace Swift { * \tparam PAYLOAD_TYPE The type of payload this Responder handles. Only IQ requests containing this * payload type will be passed to handleGetRequest() and handleSetRequest() */ template<typename PAYLOAD_TYPE> class Responder : public IQHandler { public: - Responder(IQRouter* router) : router_(router) { + Responder(IQRouter* router) : router_(router), isFinalResonder_(true) { } ~Responder() { } /** @@ -95,12 +95,16 @@ namespace Swift { } IQRouter* getIQRouter() const { return router_; } + void setFinal(bool isFinal) { + isFinalResonder_ = isFinal; + } + private: virtual bool handleIQ(boost::shared_ptr<IQ> iq) { if (iq->getType() == IQ::Set || iq->getType() == IQ::Get) { boost::shared_ptr<PAYLOAD_TYPE> payload(iq->getPayload<PAYLOAD_TYPE>()); if (payload) { bool result; @@ -108,18 +112,24 @@ namespace Swift { result = handleSetRequest(iq->getFrom(), iq->getTo(), iq->getID(), payload); } else { result = handleGetRequest(iq->getFrom(), iq->getTo(), iq->getID(), payload); } if (!result) { - router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::NotAllowed, ErrorPayload::Cancel)); + if (isFinalResonder_) { + router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::NotAllowed, ErrorPayload::Cancel)); + } + else { + return false; + } } return true; } } return false; } private: IQRouter* router_; + bool isFinalResonder_; }; } |