diff options
Diffstat (limited to 'Swiften/Queries')
-rw-r--r-- | Swiften/Queries/IQRouter.h | 10 | ||||
-rw-r--r-- | Swiften/Queries/Request.cpp | 7 | ||||
-rw-r--r-- | Swiften/Queries/Request.h | 1 | ||||
-rw-r--r-- | Swiften/Queries/Responder.h | 4 |
4 files changed, 16 insertions, 6 deletions
diff --git a/Swiften/Queries/IQRouter.h b/Swiften/Queries/IQRouter.h index 167cb8f..8dba334 100644 --- a/Swiften/Queries/IQRouter.h +++ b/Swiften/Queries/IQRouter.h @@ -57,18 +57,28 @@ namespace Swift { * If a JID was specified using setFrom, the JID will * be set as the 'from' address on iq before sending * it. */ void sendIQ(boost::shared_ptr<IQ> iq); std::string getNewIQID(); bool isAvailable(); + /** + * Checks whether the given jid is the account JID (i.e. it is either + * the bare JID, or it is the empty JID). + * Can be used to check whether a stanza is sent by the server on behalf + * of the user's account. + */ + bool isAccountJID(const JID& jid) { + return jid.isValid() ? jid_.toBare().equals(jid, JID::WithResource) : true; + } + private: void handleIQ(boost::shared_ptr<IQ> iq); void processPendingRemoves(); private: IQChannel* channel_; JID jid_; JID from_; std::vector< boost::shared_ptr<IQHandler> > handlers_; diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp index 0126d62..382e44c 100644 --- a/Swiften/Queries/Request.cpp +++ b/Swiften/Queries/Request.cpp @@ -61,22 +61,19 @@ bool Request::handleIQ(boost::shared_ptr<IQ> iq) { router_->removeHandler(this); handled = true; } } } return handled; } bool Request::isCorrectSender(const JID& jid) { - if (isAccountJID(receiver_)) { - return isAccountJID(jid); + if (router_->isAccountJID(receiver_)) { + return router_->isAccountJID(jid); } else { return jid.equals(receiver_, JID::WithResource); } } -bool Request::isAccountJID(const JID& jid) { - return jid.isValid() ? router_->getJID().toBare().equals(jid, JID::WithResource) : true; -} } diff --git a/Swiften/Queries/Request.h b/Swiften/Queries/Request.h index a7139cf..677a758 100644 --- a/Swiften/Queries/Request.h +++ b/Swiften/Queries/Request.h @@ -54,19 +54,18 @@ namespace Swift { boost::shared_ptr<Payload> getPayload() const { return payload_; } virtual void handleResponse(boost::shared_ptr<Payload>, boost::shared_ptr<ErrorPayload>) = 0; private: bool handleIQ(boost::shared_ptr<IQ>); bool isCorrectSender(const JID& jid); - bool isAccountJID(const JID& jid); private: IQRouter* router_; IQ::Type type_; JID receiver_; boost::shared_ptr<Payload> payload_; std::string id_; bool sent_; }; diff --git a/Swiften/Queries/Responder.h b/Swiften/Queries/Responder.h index a9aab17..2ba9c24 100644 --- a/Swiften/Queries/Responder.h +++ b/Swiften/Queries/Responder.h @@ -88,18 +88,22 @@ namespace Swift { } /** * Convenience function for responding with an error from a specific from address. */ void sendError(const JID& to, const JID& from, const std::string& id, ErrorPayload::Condition condition, ErrorPayload::Type type) { router_->sendIQ(IQ::createError(to, from, id, condition, type)); } + IQRouter* getIQRouter() const { + return router_; + } + 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; if (iq->getType() == IQ::Set) { result = handleSetRequest(iq->getFrom(), iq->getTo(), iq->getID(), payload); } |