Changeset - e31c07794705
[Not reviewed]
0 7 0
HanzZ - 14 years ago 2011-07-20 02:16:58
hanzz.k@gmail.com
Call finishSession in User destructor in server mode
7 files changed with 51 insertions and 4 deletions:
0 comments (0 inline, 0 general)
include/Swiften/Server/Server.cpp
Show inline comments
 
@@ -138,12 +138,13 @@ void Server::handleSessionFinished(boost::shared_ptr<ServerFromClientSession> se
 
		Swift::Presence::ref presence = Swift::Presence::create();
 
		presence->setFrom(session->getBareJID());
 
		presence->setType(Swift::Presence::Unavailable);
 
		dynamic_cast<ServerStanzaChannel *>(stanzaChannel_)->onPresenceReceived(presence);
 
	}
 
	serverFromClientSessions.erase(std::remove(serverFromClientSessions.begin(), serverFromClientSessions.end(), session), serverFromClientSessions.end());
 
	std::cout << "FINISH SESSION2 " << serverFromClientSessions.size() << "\n";
 
	session->onSessionStarted.disconnect(
 
			boost::bind(&Server::handleSessionStarted, this, session));
 
	session->onSessionFinished.disconnect(
 
			boost::bind(&Server::handleSessionFinished, this, session));
 
}
 

	
include/Swiften/Server/ServerFromClientSession.cpp
Show inline comments
 
@@ -45,12 +45,14 @@ ServerFromClientSession::ServerFromClientSession(
 
	userRegistry->onPasswordValid.connect(boost::bind(&ServerFromClientSession::handlePasswordValid, this, _1));
 
	userRegistry->onPasswordInvalid.connect(boost::bind(&ServerFromClientSession::handlePasswordInvalid, this, _1));
 
}
 

	
 
ServerFromClientSession::~ServerFromClientSession() {
 
	std::cout << "DESTRUCTOR;\n";
 
	userRegistry_->onPasswordValid.disconnect(boost::bind(&ServerFromClientSession::handlePasswordValid, this, _1));
 
	userRegistry_->onPasswordInvalid.disconnect(boost::bind(&ServerFromClientSession::handlePasswordInvalid, this, _1));
 
	if (tlsLayer) {
 
		delete tlsLayer;
 
	}
 
}
 

	
 
void ServerFromClientSession::handlePasswordValid(const std::string &user) {
include/Swiften/Server/ServerStanzaChannel.cpp
Show inline comments
 
@@ -3,12 +3,13 @@
 
 * Licensed under the GNU General Public License v3.
 
 * See Documentation/Licenses/GPLv3.txt for more information.
 
 */
 

	
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Base/Error.h"
 
#include <iostream>
 

	
 
#include <boost/bind.hpp>
 

	
 
namespace Swift {
 

	
 
namespace {
 
@@ -52,19 +53,23 @@ void ServerStanzaChannel::sendPresence(boost::shared_ptr<Presence> presence) {
 
	send(presence);
 
}
 

	
 
void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr<Element> element) {
 
	std::vector<boost::shared_ptr<ServerFromClientSession> > candidateSessions;
 
	for (std::list<boost::shared_ptr<ServerFromClientSession> >::const_iterator i = sessions[to.toBare().toString()].begin(); i != sessions[to.toBare().toString()].end(); ++i) {
 
		(*i)->sendElement(element);
 
		if (element) {
 
			(*i)->sendElement(element);
 
		}
 
		candidateSessions.push_back(*i);
 
	}
 

	
 
	for (std::vector<boost::shared_ptr<ServerFromClientSession> >::const_iterator i = candidateSessions.begin(); i != candidateSessions.end(); ++i) {
 
		
 
		(*i)->finishSession();
 
		sessions[to.toBare().toString()].remove(*i);
 
		std::cout << "FINISH SESSION " << sessions[to.toBare().toString()].size() << "\n";
 
	}
 
}
 

	
 
std::string ServerStanzaChannel::getNewIQID() {
 
	return idGenerator.generateID();
 
}
spectrum/src/main.cpp
Show inline comments
 
@@ -4,19 +4,40 @@
 
#include "transport/logger.h"
 
#include "transport/sqlite3backend.h"
 
#include "transport/userregistration.h"
 
#include "transport/networkpluginserver.h"
 
#include "transport/admininterface.h"
 
#include "Swiften/EventLoop/SimpleEventLoop.h"
 
#include "sys/signal.h"
 
 
using namespace Transport;
 
 
Swift::SimpleEventLoop *eventLoop_ = NULL;
 
 
static void spectrum_sigint_handler(int sig) {
 
	eventLoop_->stop();
 
}
 
 
static void spectrum_sigterm_handler(int sig) {
 
	eventLoop_->stop();
 
}
 
 
int main(int argc, char **argv)
 
{
 
	Config config;
 
 
	if (signal(SIGINT, spectrum_sigint_handler) == SIG_ERR) {
 
		std::cout << "SIGINT handler can't be set\n";
 
		return -1;
 
	}
 
 
	if (signal(SIGTERM, spectrum_sigterm_handler) == SIG_ERR) {
 
		std::cout << "SIGTERM handler can't be set\n";
 
		return -1;
 
	}
 
 
	boost::program_options::options_description desc("Usage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
 
	desc.add_options()
 
		("help,h", "help")
 
		("no-daemonize,n", "Do not run spectrum as daemon")
 
		;
 
	try
 
@@ -66,19 +87,27 @@ int main(int argc, char **argv)
 
		if (!storageBackend->connect()) {
 
			std::cerr << "Can't connect to database.\n";
 
		}
 
	}
 
 
	UserManager userManager(&transport, &userRegistry, storageBackend);
 
	UserRegistration *userRegistration = NULL;
 
	if (storageBackend) {
 
		UserRegistration *userRegistration = new UserRegistration(&transport, &userManager, storageBackend);
 
		userRegistration = new UserRegistration(&transport, &userManager, storageBackend);
 
		userRegistration->start();
 
// 		logger.setUserRegistration(&userRegistration);
 
	}
 
// 	logger.setUserManager(&userManager);
 
 
	NetworkPluginServer plugin(&transport, &config, &userManager);
 
 
	AdminInterface adminInterface(&transport, &userManager, &plugin, storageBackend);
 
 
	eventLoop_ = &eventLoop;
 
 
	eventLoop.run();
 
	if (userRegistration) {
 
		userRegistration->stop();
 
		delete userRegistration;
 
	}
 
	delete storageBackend;
 
}
src/networkpluginserver.cpp
Show inline comments
 
@@ -165,12 +165,15 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
 

	
 
	exec_(CONFIG_STRING(m_config, "service.backend").c_str(), CONFIG_STRING(m_config, "service.backend_host").c_str(), CONFIG_STRING(m_config, "service.backend_port").c_str(), m_config->getConfigFile().c_str());
 
}
 

	
 
NetworkPluginServer::~NetworkPluginServer() {
 
	m_pingTimer->stop();
 
	m_server->stop();
 
	m_server.reset();
 
	delete m_component->m_factory;
 
	delete m_vcardResponder;
 
	delete m_rosterResponder;
 
}
 

	
 
void NetworkPluginServer::handleNewClientConnection(boost::shared_ptr<Swift::Connection> c) {
 
	Backend *client = new Backend;
src/transport.cpp
Show inline comments
 
@@ -131,16 +131,19 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory, T
 
Component::~Component() {
 
	delete m_presenceOracle;
 
	delete m_entityCapsManager;
 
	delete m_capsManager;
 
	delete m_capsMemoryStorage;
 
	delete m_discoInfoResponder;
 
	delete m_discoItemsResponder;
 
	if (m_component)
 
		delete m_component;
 
	if (m_server)
 
	if (m_server) {
 
		m_server->stop();
 
		delete m_server;
 
	}
 
	delete m_factories;
 
}
 

	
 
Swift::StanzaChannel *Component::getStanzaChannel() {
 
	return m_stanzaChannel;
 
}
src/user.cpp
Show inline comments
 
@@ -59,12 +59,16 @@ User::User(const Swift::JID &jid, UserInfo &userInfo, Component *component, User
 
	m_conversationManager = new ConversationManager(this, m_component);
 
	LOG4CXX_INFO(logger, m_jid.toString() << ": Created");
 
}
 

	
 
User::~User(){
 
	LOG4CXX_INFO(logger, m_jid.toString() << ": Destroying");
 
	if (m_component->inServerMode()) {
 
		dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::Element>());
 
	}
 

	
 
	m_reconnectTimer->stop();
 
	delete m_rosterManager;
 
	delete m_conversationManager;
 
}
 

	
 
const Swift::JID &User::getJID() {
 
@@ -191,13 +195,13 @@ void User::handleDisconnected(const std::string &error) {
 
	// so we can't removeUser() in server mode, because it would be removed twice.
 
	// Once in finishSession and once in m_userManager->removeUser.
 
	if (m_component->inServerMode()) {
 
		// Remove user later just to be sure there won't be double-free.
 
		// We can't be sure finishSession sends unavailable presence everytime, so check if user gets removed
 
		// in finishSession(...) call and if not, remove it here.
 
		std::string jid = m_jid.toBare().toString();
 
		std::string jid = m_jid.toBare().toString();		
 
		dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::Element>(new Swift::StreamError()));
 
		if (m_userManager->getUser(jid) != NULL) {
 
			m_userManager->removeUser(this);
 
		}
 
	}
 
	else {
0 comments (0 inline, 0 general)