diff --git a/include/Swiften/Server/Server.cpp b/include/Swiften/Server/Server.cpp index 1c92fa6d40cf01d928b08d823a4960654d95e7cb..f12addf02e938ba11e4c93fcb869b3b1236859fc 100644 --- a/include/Swiften/Server/Server.cpp +++ b/include/Swiften/Server/Server.cpp @@ -111,8 +111,6 @@ void Server::handleNewClientConnection(boost::shared_ptr connection) serverFromClientSession->onDataRead.connect(boost::bind(&Server::handleDataRead, this, _1)); serverFromClientSession->onDataWritten.connect(boost::bind(&Server::handleDataWritten, this, _1)); - dynamic_cast(stanzaChannel_)->addSession(serverFromClientSession); - if (tlsFactory) { serverFromClientSession->addTLSEncryption(tlsFactory, cert); } @@ -130,8 +128,8 @@ void Server::handleDataWritten(const SafeByteArray& data) { onDataWritten(data); } -void Server::handleSessionStarted(boost::shared_ptr) { -// onSelfConnected(true); +void Server::handleSessionStarted(boost::shared_ptr session) { + dynamic_cast(stanzaChannel_)->addSession(session); } void Server::handleSessionFinished(boost::shared_ptr session) { diff --git a/include/Swiften/Server/ServerStanzaChannel.cpp b/include/Swiften/Server/ServerStanzaChannel.cpp index a04ab595fba60fbf539a2240c71861f92bcaaa8d..2ef100fd6e7402fa57995008813dca44e31c8482 100644 --- a/include/Swiften/Server/ServerStanzaChannel.cpp +++ b/include/Swiften/Server/ServerStanzaChannel.cpp @@ -28,7 +28,7 @@ namespace { } void ServerStanzaChannel::addSession(boost::shared_ptr session) { - sessions.push_back(session); + 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)); } @@ -36,7 +36,8 @@ void ServerStanzaChannel::addSession(boost::shared_ptr 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)); - sessions.erase(std::remove(sessions.begin(), sessions.end(), session), sessions.end()); + std::list > &lst = sessions[session->getRemoteJID().toBare().toString()]; + lst.erase(std::remove(lst.begin(), lst.end(), session), lst.end()); } void ServerStanzaChannel::sendIQ(boost::shared_ptr iq) { @@ -53,7 +54,7 @@ void ServerStanzaChannel::sendPresence(boost::shared_ptr presence) { void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr element) { std::vector > candidateSessions; - for (std::list >::const_iterator i = sessions.begin(); i != sessions.end(); ++i) { + for (std::list >::const_iterator i = sessions[to.toBare().toString()].begin(); i != sessions[to.toBare().toString()].end(); ++i) { if ((*i)->getRemoteJID().equals(to, JID::WithoutResource)) { (*i)->sendElement(element); candidateSessions.push_back(*i); @@ -62,6 +63,7 @@ void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr >::const_iterator i = candidateSessions.begin(); i != candidateSessions.end(); ++i) { (*i)->finishSession(); + sessions[to.toBare().toString()].remove(*i); } } @@ -75,8 +77,8 @@ void ServerStanzaChannel::send(boost::shared_ptr stanza) { // For a full JID, first try to route to a session with the full JID if (!to.isBare()) { - std::list >::const_iterator i = std::find_if(sessions.begin(), sessions.end(), HasJID(to)); - if (i != sessions.end()) { + std::list >::const_iterator i = std::find_if(sessions[stanza->getTo().toBare().toString()].begin(), sessions[stanza->getTo().toBare().toString()].end(), HasJID(to)); + if (i != sessions[stanza->getTo().toBare().toString()].end()) { (*i)->sendElement(stanza); return; } @@ -85,7 +87,7 @@ void ServerStanzaChannel::send(boost::shared_ptr stanza) { // Look for candidate sessions to = to.toBare(); std::vector > candidateSessions; - for (std::list >::const_iterator i = sessions.begin(); i != sessions.end(); ++i) { + for (std::list >::const_iterator i = sessions[stanza->getTo().toBare().toString()].begin(); i != sessions[stanza->getTo().toBare().toString()].end(); ++i) { if ((*i)->getRemoteJID().equals(to, JID::WithoutResource)) { candidateSessions.push_back(*i); (*i)->sendElement(stanza); diff --git a/include/Swiften/Server/ServerStanzaChannel.h b/include/Swiften/Server/ServerStanzaChannel.h index 1da89448acfa6ee8aef10dd46d028ff3266ad1f5..fc05294d974d7eb54bb3e220a62bf447adcc77c0 100644 --- a/include/Swiften/Server/ServerStanzaChannel.h +++ b/include/Swiften/Server/ServerStanzaChannel.h @@ -45,7 +45,8 @@ namespace Swift { private: IDGenerator idGenerator; - std::list > sessions; + // [JID][resources][ServerFromClientSession] + std::map > > sessions; }; }