From a94eb22e7620fbcc6665b8f55a7fd4e278e34376 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 17 Jan 2012 17:46:03 +0100 Subject: [PATCH] Handle properly --- include/Swiften/Server/ServerStanzaChannel.cpp | 11 +++++++++++ include/Swiften/Server/ServerStanzaChannel.h | 1 + 2 files changed, 12 insertions(+) diff --git a/include/Swiften/Server/ServerStanzaChannel.cpp b/include/Swiften/Server/ServerStanzaChannel.cpp index bb3fbf6e..9597cc1c 100644 --- a/include/Swiften/Server/ServerStanzaChannel.cpp +++ b/include/Swiften/Server/ServerStanzaChannel.cpp @@ -32,11 +32,13 @@ void ServerStanzaChannel::addSession(boost::shared_ptr sessions[session->getRemoteJID().toBare().toString()].push_back(session); session->onSessionFinished.connect(boost::bind(&ServerStanzaChannel::handleSessionFinished, this, _1, session)); session->onElementReceived.connect(boost::bind(&ServerStanzaChannel::handleElement, this, _1, session)); + session->onDataRead.connect(boost::bind(&ServerStanzaChannel::handleDataRead, this, _1, session)); } void ServerStanzaChannel::removeSession(boost::shared_ptr session) { session->onSessionFinished.disconnect(boost::bind(&ServerStanzaChannel::handleSessionFinished, this, _1, session)); session->onElementReceived.disconnect(boost::bind(&ServerStanzaChannel::handleElement, this, _1, session)); + session->onDataRead.disconnect(boost::bind(&ServerStanzaChannel::handleDataRead, this, _1, session)); std::list > &lst = sessions[session->getRemoteJID().toBare().toString()]; lst.erase(std::remove(lst.begin(), lst.end(), session), lst.end()); } @@ -53,6 +55,15 @@ void ServerStanzaChannel::sendPresence(boost::shared_ptr presence) { send(presence); } +void ServerStanzaChannel::handleDataRead(const SafeByteArray &data, const boost::shared_ptr &session) { + if (safeByteArrayToString(data).find("") != std::string::npos) { + Swift::Presence::ref presence = Swift::Presence::create(); + presence->setFrom(session->getRemoteJID()); + presence->setType(Swift::Presence::Unavailable); + onPresenceReceived(presence); + } +} + void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr element, bool last) { std::vector > candidateSessions; for (std::list >::const_iterator i = sessions[to.toBare().toString()].begin(); i != sessions[to.toBare().toString()].end(); ++i) { diff --git a/include/Swiften/Server/ServerStanzaChannel.h b/include/Swiften/Server/ServerStanzaChannel.h index 69158eea..99c857be 100644 --- a/include/Swiften/Server/ServerStanzaChannel.h +++ b/include/Swiften/Server/ServerStanzaChannel.h @@ -41,6 +41,7 @@ namespace Swift { void send(boost::shared_ptr stanza); void handleSessionFinished(const boost::optional&, const boost::shared_ptr &session); void handleElement(boost::shared_ptr element, const boost::shared_ptr &session); + void handleDataRead(const SafeByteArray &data, const boost::shared_ptr &session); void handleSessionInitialized(); private: