diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-08-28 09:19:46 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-08-28 09:19:46 (GMT) |
commit | 5f1cb0d768265347bc80862c33f5967f07759b10 (patch) | |
tree | 979eceddcd0f5e6a651180b91d0908e1e1e319b7 /Swiften/Queries/Request.cpp | |
parent | 8dbae452004e7bc3c3a6e855f365b9bb348e8f2d (diff) | |
download | swift-contrib-5f1cb0d768265347bc80862c33f5967f07759b10.zip swift-contrib-5f1cb0d768265347bc80862c33f5967f07759b10.tar.bz2 |
Check sender on incoming IQ responses.
Release-Notes: Fixed a bug whereby the sender of an iq wasn't being checked before matching it to a request.
Diffstat (limited to 'Swiften/Queries/Request.cpp')
-rw-r--r-- | Swiften/Queries/Request.cpp | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp index a77cf49..0ffae26 100644 --- a/Swiften/Queries/Request.cpp +++ b/Swiften/Queries/Request.cpp @@ -41,27 +41,46 @@ bool Request::handleIQ(boost::shared_ptr<IQ> iq) { bool handled = false; if (iq->getType() == IQ::Result || iq->getType() == IQ::Error) { if (sent_ && iq->getID() == id_) { - if (iq->getType() == IQ::Result) { - boost::shared_ptr<Payload> payload = iq->getPayloadOfSameType(payload_); - if (!payload && boost::dynamic_pointer_cast<RawXMLPayload>(payload_) && !iq->getPayloads().empty()) { - payload = iq->getPayloads().front(); - } - handleResponse(payload, ErrorPayload::ref()); - } - else { - ErrorPayload::ref errorPayload = iq->getPayload<ErrorPayload>(); - if (errorPayload) { - handleResponse(boost::shared_ptr<Payload>(), errorPayload); + if (isCorrectSender(iq->getFrom())) { + if (iq->getType() == IQ::Result) { + boost::shared_ptr<Payload> payload = iq->getPayloadOfSameType(payload_); + if (!payload && boost::dynamic_pointer_cast<RawXMLPayload>(payload_) && !iq->getPayloads().empty()) { + payload = iq->getPayloads().front(); + } + handleResponse(payload, ErrorPayload::ref()); } else { - handleResponse(boost::shared_ptr<Payload>(), ErrorPayload::ref(new ErrorPayload(ErrorPayload::UndefinedCondition))); + ErrorPayload::ref errorPayload = iq->getPayload<ErrorPayload>(); + if (errorPayload) { + handleResponse(boost::shared_ptr<Payload>(), errorPayload); + } + else { + handleResponse(boost::shared_ptr<Payload>(), ErrorPayload::ref(new ErrorPayload(ErrorPayload::UndefinedCondition))); + } } + router_->removeHandler(this); + handled = true; } - router_->removeHandler(this); - handled = true; } } return handled; } +bool Request::isCorrectSender(const JID& jid) { + if (isAccountJID(receiver_)) { + return isAccountJID(jid); + } + else { + return jid.equals(receiver_, JID::WithResource); + } +} + +bool Request::isAccountJID(const JID& jid) { + // If the router's JID is not set, we don't check anything + if (!router_->getJID().isValid()) { + return true; + } + return jid.isValid() ? router_->getJID().equals(jid, JID::WithoutResource) : true; +} + } |