Changeset - 96476b9a8a3e
[Not reviewed]
Merge
! ! !
Sarang Bharadwaj - 13 years ago 2012-07-16 19:24:59
sarang.bh@gmail.com
Merge branch 'master' of git://github.com/hanzz/libtransport into twitter-backend
13 files changed with 560 insertions and 14 deletions:
0 comments (0 inline, 0 general)
include/transport/adhoccommand.h
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include <map>
 
#include "Swiften/Swiften.h"
 

	
 
namespace Transport {
 

	
 
class Component;
 

	
 
class AdHocCommand {
 
	public:
 
		/// Creates new AdHocManager.
 

	
 
		/// \param component Transport instance associated with this AdHocManager.
 
		AdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to);
 

	
 
		/// Destructor.
 
		virtual ~AdHocCommand();
 

	
 
		virtual boost::shared_ptr<Swift::Command> handleRequest(boost::shared_ptr<Swift::Command> payload) = 0;
 

	
 
		const std::string &getId() {
 
			return m_id;
 
		}
 

	
 
		void refreshLastActivity() {
 
			m_lastActivity = time(NULL);
 
		}
 

	
 
		time_t getLastActivity() {
 
			return m_lastActivity;
 
		}
 

	
 
	protected:
 
		Component *m_component;
 
		Swift::JID m_initiator;
 
		Swift::JID m_to;
 

	
 
	private:
 
		std::string m_id;
 
		// This is used to remove AdHocCommand after long inactivity to prevent memory leaks
 
		// caused by users which disconnect before they finish the command.
 
		// AdHocManager uses this to garbage collect old AdHocCommands.
 
		time_t m_lastActivity;
 
};
 

	
 
}
include/transport/adhoccommandfactory.h
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include <map>
 
#include "transport/adhoccommand.h"
 
#include "Swiften/Swiften.h"
 

	
 
namespace Transport {
 

	
 
class Component;
 

	
 
class AdHocCommandFactory {
 
	public:
 
		AdHocCommandFactory() {}
 

	
 
		/// Destructor.
 
		virtual ~AdHocCommandFactory() {}
 

	
 
		virtual AdHocCommand *createAdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to) = 0;
 

	
 
		virtual std::string getNode() = 0;
 

	
 
		virtual std::string getName() = 0;
 
};
 

	
 
}
include/transport/adhocmanager.h
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include <map>
 
#include "Swiften/Swiften.h"
 

	
 
namespace Transport {
 

	
 
class Conversation;
 
class User;
 
class Component;
 
class DiscoItemsResponder;
 
class AdHocCommandFactory;
 
class AdHocCommand;
 

	
 
/// Listens for AdHoc commands and manages all AdHoc commands sessions
 
class AdHocManager : public Swift::Responder<Swift::Command> {
 
	public:
 
		typedef std::map<std::string, AdHocCommand *> CommandsMap;
 
		typedef std::map<Swift::JID, CommandsMap> SessionsMap;
 
		/// Creates new AdHocManager.
 

	
 
		/// \param component Transport instance associated with this AdHocManager.
 
		AdHocManager(Component *component, DiscoItemsResponder *discoItemsResponder);
 

	
 
		/// Destructor.
 
		virtual ~AdHocManager();
 

	
 
		/// Starts handling AdHoc commands payloads.
 
		void start();
 

	
 
		/// Stops handling AdHoc commands payloads and destroys all existing
 
		/// AdHoc commands sessions.
 
		void stop();
 

	
 
		/// Adds factory to create new AdHoc commands sessions of particular type.
 
		void addAdHocCommand(AdHocCommandFactory *factory);
 

	
 
		/// Remove sessions older than N seconds.
 
		void removeOldSessions();
 

	
 

	
 
	private:
 
		virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::Command> payload);
 
		virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::Command> payload);
 

	
 
		Component *m_component;
 
		DiscoItemsResponder *m_discoItemsResponder;
 
		std::map<std::string, AdHocCommandFactory *> m_factories;
 
		SessionsMap m_sessions;
 
		Swift::Timer::ref m_collectTimer;
 
};
 

	
 
}
include/transport/discoitemsresponder.h
Show inline comments
 
file renamed from src/discoitemsresponder.h to include/transport/discoitemsresponder.h
 
@@ -24,17 +24,25 @@
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Queries/GetResponder.h"
 
#include "Swiften/Elements/DiscoItems.h"
 

	
 
namespace Transport {
 

	
 
class Component;
 

	
 
class DiscoItemsResponder : public Swift::GetResponder<Swift::DiscoItems> {
 
	public:
 
		DiscoItemsResponder(Swift::IQRouter *router);
 
		DiscoItemsResponder(Component *component);
 
		~DiscoItemsResponder();
 

	
 
		void addAdHocCommand(const std::string &node, const std::string &name);
 
// 		void removeAdHocCommand(const std::string &node);
 

	
 

	
 
	private:
 
		virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::DiscoItems> payload);
 

	
 
		Component *m_component;
 
		boost::shared_ptr<Swift::DiscoItems> m_commands;
 
};
 

	
 
}
 
\ No newline at end of file
include/transport/settingsadhoccommand.h
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include <map>
 
#include "Swiften/Swiften.h"
 
#include "transport/adhoccommand.h"
 
#include "transport/adhoccommandfactory.h"
 

	
 

	
 
namespace Transport {
 

	
 
class Component;
 

	
 
class SettingsAdHocCommand : public AdHocCommand {
 
	public:
 
		SettingsAdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to);
 

	
 
		/// Destructor.
 
		virtual ~SettingsAdHocCommand();
 

	
 
		virtual boost::shared_ptr<Swift::Command> handleRequest(boost::shared_ptr<Swift::Command> payload);
 
};
 

	
 
class SettingsAdHocCommandFactory : public AdHocCommandFactory {
 
	public:
 
		SettingsAdHocCommandFactory() {}
 
		virtual ~SettingsAdHocCommandFactory() {}
 

	
 
		AdHocCommand *createAdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to) {
 
			return new SettingsAdHocCommand(component, initiator, to);
 
		}
 

	
 
		std::string getNode() {
 
			return "settings";
 
		}
 

	
 
		std::string getName() {
 
			return "Transport settings";
 
		}
 
};
 

	
 
}
include/transport/transport.h
Show inline comments
 
@@ -45,13 +45,12 @@ namespace Transport {
 
	// 				CLIENT_FEATURE_FILETRANSFER = 8,
 
	// 				CLIENT_FEATURE_CHATSTATES = 16
 
	// 				} SpectrumImportantFeatures;
 
	// 
 
	class StorageBackend;
 
	class DiscoInfoResponder;
 
	class DiscoItemsResponder;
 
	class Factory;
 
	class UserRegistry;
 

	
 
	/// Represents one transport instance.
 

	
 
	/// It's used to connect the Jabber server and provides transaction layer
 
@@ -185,13 +184,12 @@ namespace Transport {
 
			Swift::StanzaChannel *m_stanzaChannel;
 
			Swift::IQRouter *m_iqRouter;
 
			
 
			Transport::UserRegistry *m_userRegistry;
 
			StorageBackend *m_storageBackend;
 
 			DiscoInfoResponder *m_discoInfoResponder;
 
			DiscoItemsResponder *m_discoItemsResponder;
 
			int m_reconnectCount;
 
			Config* m_config;
 
			std::string m_protocol;
 
			Swift::JID m_jid;
 
			Factory *m_factory;
 
			Swift::EventLoop *m_loop;
spectrum/src/main.cpp
Show inline comments
 
@@ -11,12 +11,15 @@
 
#include "transport/admininterface.h"
 
#include "transport/statsresponder.h"
 
#include "transport/usersreconnecter.h"
 
#include "transport/util.h"
 
#include "transport/gatewayresponder.h"
 
#include "transport/logging.h"
 
#include "transport/discoitemsresponder.h"
 
#include "transport/adhocmanager.h"
 
#include "transport/settingsadhoccommand.h"
 
#include "Swiften/EventLoop/SimpleEventLoop.h"
 
#include <boost/filesystem.hpp>
 
#include <boost/algorithm/string.hpp>
 
#ifndef WIN32
 
#include "sys/signal.h"
 
#include <pwd.h>
 
@@ -310,12 +313,21 @@ int main(int argc, char **argv)
 
	StatsResponder statsResponder(&transport, &userManager, &plugin, storageBackend);
 
	statsResponder.start();
 

	
 
	GatewayResponder gatewayResponder(transport.getIQRouter(), &userManager);
 
	gatewayResponder.start();
 

	
 
	DiscoItemsResponder discoItemsResponder(&transport);
 
	discoItemsResponder.start();
 

	
 
	AdHocManager adhocmanager(&transport, &discoItemsResponder);
 
	adhocmanager.start();
 

	
 
	SettingsAdHocCommandFactory settings;
 
	adhocmanager.addAdHocCommand(&settings);
 

	
 
	eventLoop_ = &eventLoop;
 

	
 
	eventLoop.run();
 

	
 
	if (userRegistration) {
 
		userRegistration->stop();
src/adhoccommand.cpp
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2012, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/adhoccommand.h"
 
#include "transport/adhoccommandfactory.h"
 
#include "transport/conversation.h"
 
#include "transport/usermanager.h"
 
#include "transport/buddy.h"
 
#include "transport/factory.h"
 
#include "transport/user.h"
 
#include "transport/logging.h"
 

	
 
namespace Transport {
 

	
 
DEFINE_LOGGER(logger, "AdHocCommand");
 

	
 
AdHocCommand::AdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to) {
 
	m_component = component;
 
	m_initiator = initiator;
 
	m_to = to;
 

	
 
	std::string bucket = "abcdefghijklmnopqrstuvwxyz";
 
	for (int i = 0; i < 32; i++) {
 
		m_id += bucket[rand() % bucket.size()];
 
	}
 
}
 

	
 
AdHocCommand::~AdHocCommand() {
 
}
 

	
 
}
src/adhocmanager.cpp
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2012, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/adhocmanager.h"
 
#include "transport/adhoccommandfactory.h"
 
#include "transport/discoitemsresponder.h"
 
#include "transport/conversation.h"
 
#include "transport/usermanager.h"
 
#include "transport/buddy.h"
 
#include "transport/factory.h"
 
#include "transport/user.h"
 
#include "transport/logging.h"
 

	
 
namespace Transport {
 

	
 
DEFINE_LOGGER(logger, "AdHocManager");
 

	
 
AdHocManager::AdHocManager(Component *component, DiscoItemsResponder *discoItemsResponder) : Swift::Responder<Swift::Command>(component->getIQRouter()){
 
	m_component = component;
 
	m_discoItemsResponder = discoItemsResponder;
 

	
 
	m_collectTimer = m_component->getNetworkFactories()->getTimerFactory()->createTimer(20);
 
	m_collectTimer->onTick.connect(boost::bind(&AdHocManager::removeOldSessions, this));
 
	m_collectTimer->start();
 
}
 

	
 
AdHocManager::~AdHocManager() {
 
	m_collectTimer->stop();
 
	stop();
 
}
 

	
 
void AdHocManager::start() {
 
	Swift::Responder<Swift::Command>::start();
 
}
 

	
 
void AdHocManager::stop() {
 
	Swift::Responder<Swift::Command>::stop();
 

	
 
	for (SessionsMap::iterator it = m_sessions.begin(); it != m_sessions.end(); it++) {
 
		std::vector<std::string> candidates;
 
		for (CommandsMap::iterator ct = it->second.begin(); ct != it->second.end(); ct++) {
 
			delete ct->second;
 
		}
 
	}
 

	
 
	m_sessions.clear();
 
}
 

	
 
void AdHocManager::addAdHocCommand(AdHocCommandFactory *factory) {
 
	if (m_factories.find(factory->getNode()) != m_factories.end()) {
 
		LOG4CXX_ERROR(logger, "Command with node " << factory->getNode() << " is already registered. Ignoring this attempt.");
 
		return;
 
	}
 

	
 
	m_factories[factory->getNode()] = factory;
 
	m_discoItemsResponder->addAdHocCommand(factory->getNode(), factory->getName());
 
}
 

	
 
void AdHocManager::removeOldSessions() {
 
	unsigned long removedCommands = 0;
 
	time_t now = time(NULL);
 

	
 
	std::vector<std::string> toRemove;
 
	for (SessionsMap::iterator it = m_sessions.begin(); it != m_sessions.end(); it++) {
 
		std::vector<std::string> candidates;
 
		for (CommandsMap::iterator ct = it->second.begin(); ct != it->second.end(); ct++) {
 
			if (now - ct->second->getLastActivity() > 15*60) {
 
				candidates.push_back(it->first);
 
				delete ct->second;
 
				removedCommands++;
 
			}
 
		}
 

	
 
		BOOST_FOREACH(std::string &key, candidates) {
 
			it->second.erase(key);
 
		}
 

	
 
		if (it->second.empty()) {
 
			toRemove.push_back(it->first);
 
		}
 
	}
 

	
 
	BOOST_FOREACH(std::string &key, toRemove) {
 
		m_sessions.erase(key);
 
	}
 

	
 
	if (removedCommands > 0) {
 
		LOG4CXX_INFO(logger, "Removed " << removedCommands << " old commands sessions.");
 
	}
 
}
 

	
 
bool AdHocManager::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::Command> payload) {
 
	return false;
 
}
 

	
 
bool AdHocManager::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::Command> payload) {
 
	AdHocCommand *command = NULL;
 
	// Try to find AdHocCommand according to 'from' and session_id
 
	if (m_sessions.find(from) != m_sessions.end() && m_sessions[from].find(payload->getSessionID()) != m_sessions[from].end()) {
 
		command = m_sessions[from][payload->getSessionID()];
 
	}
 
	// Check if we can create command with this node
 
	else if (m_factories.find(payload->getNode()) != m_factories.end()) {
 
		command = m_factories[payload->getNode()]->createAdHocCommand(m_component, from, to);
 
		m_sessions[from][command->getId()] = command;
 
		LOG4CXX_INFO(logger, from.toString() << ": Started new AdHoc command session with node " << payload->getNode());
 
	}
 
	else {
 
		LOG4CXX_INFO(logger, from.toString() << ": Unknown node " << payload->getNode() << ". Can't start AdHoc command session.");
 
		sendError(from, id, Swift::ErrorPayload::BadRequest, Swift::ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	if (!command) {
 
		LOG4CXX_ERROR(logger, from.toString() << ": createAdHocCommand for node " << payload->getNode() << " returned NULL pointer");
 
		sendError(from, id, Swift::ErrorPayload::BadRequest, Swift::ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	boost::shared_ptr<Swift::Command> response = command->handleRequest(payload);
 
	if (!response) {
 
		LOG4CXX_ERROR(logger, from.toString() << ": handleRequest for node " << payload->getNode() << " returned NULL pointer");
 
		sendError(from, id, Swift::ErrorPayload::BadRequest, Swift::ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	response->setSessionID(command->getId());
 

	
 
	sendResponse(from, id, response);
 

	
 
	command->refreshLastActivity();
 

	
 
	// Command completed, so we can remove it now
 
	if (response->getStatus() == Swift::Command::Completed) {
 
		m_sessions[from].erase(command->getId());
 
		if (m_sessions[from].empty()) {
 
			m_sessions.erase(from);
 
		}
 
		delete command;
 
	}
 
	
 

	
 
	return true;
 
}
 

	
 
}
src/discoitemsresponder.cpp
Show inline comments
 
@@ -15,38 +15,51 @@
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "discoitemsresponder.h"
 
#include "transport/discoitemsresponder.h"
 

	
 
#include <iostream>
 
#include <boost/bind.hpp>
 
#include "Swiften/Queries/IQRouter.h"
 
#include "Swiften/Elements/DiscoItems.h"
 
#include "Swiften/Swiften.h"
 
#include "transport/transport.h"
 
#include "transport/logging.h"
 

	
 
using namespace Swift;
 
using namespace boost;
 

	
 
namespace Transport {
 

	
 
DiscoItemsResponder::DiscoItemsResponder(Swift::IQRouter *router) : Swift::GetResponder<DiscoItems>(router) {
 
DEFINE_LOGGER(logger, "DiscoItemsResponder");
 

	
 
DiscoItemsResponder::DiscoItemsResponder(Component *component) : Swift::GetResponder<DiscoItems>(component->getIQRouter()) {
 
	m_component = component;
 
	m_commands = boost::shared_ptr<DiscoItems>(new DiscoItems());
 
	m_commands->setNode("http://jabber.org/protocol/commands");
 
}
 

	
 
DiscoItemsResponder::~DiscoItemsResponder() {
 
	
 
}
 

	
 
void DiscoItemsResponder::addAdHocCommand(const std::string &node, const std::string &name) {
 
	m_commands->addItem(DiscoItems::Item(name, m_component->getJID(), node));
 
}
 

	
 

	
 
bool DiscoItemsResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::DiscoItems> info) {
 
	// presence for transport
 
	if (to.getNode().empty()) {
 
	LOG4CXX_INFO(logger, "get request received with node " << info->getNode());
 
	if (info->getNode() == "http://jabber.org/protocol/commands") {
 
		sendResponse(from, id, m_commands);
 
	}
 
	else if (to.getNode().empty()) {
 
		sendResponse(from, id, boost::shared_ptr<DiscoItems>(new DiscoItems()));
 
	}
 
	// presence for buddy
 
	else {
 
		sendResponse(from, id, boost::shared_ptr<DiscoItems>(new DiscoItems()));
 
	}
 
	return true;
 
}
 

	
src/rosterstorage.cpp
Show inline comments
 
@@ -83,12 +83,19 @@ RosterStorage::RosterStorage(User *user, StorageBackend *storageBackend) {
 

	
 
RosterStorage::~RosterStorage() {
 
	m_storageTimer->stop();
 
}
 

	
 
void RosterStorage::storeBuddy(Buddy *buddy) {
 
	if (!buddy) {
 
		return;
 
	}
 
	if (buddy->getName().empty()) {
 
		return;
 
	}
 

	
 
	m_buddies[buddy->getName()] = buddy;
 
	m_storageTimer->start();
 
}
 

	
 
bool RosterStorage::storeBuddies() {
 
	if (m_buddies.size() == 0) {
 
@@ -126,12 +133,13 @@ bool RosterStorage::storeBuddies() {
 
// 			s->id = id;
 
// 			g_hash_table_foreach(buddy->node.settings, save_settings, s);
 
// 			delete s;
 
// 		}
 
	}
 

	
 
	m_buddies.clear();
 
	m_storageBackend->commitTransaction();
 
	return true;
 
}
 

	
 
void RosterStorage::removeBuddyFromQueue(Buddy *buddy) {
 
	m_buddies.erase(buddy->getName());
src/settingsadhoccommand.cpp
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2012, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/settingsadhoccommand.h"
 
#include "transport/conversation.h"
 
#include "transport/usermanager.h"
 
#include "transport/buddy.h"
 
#include "transport/factory.h"
 
#include "transport/user.h"
 
#include "transport/logging.h"
 

	
 
namespace Transport {
 

	
 
DEFINE_LOGGER(logger, "SettingsAdHocCommand");
 

	
 
SettingsAdHocCommand::SettingsAdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to) : AdHocCommand(component, initiator, to) {
 
}
 

	
 
SettingsAdHocCommand::~SettingsAdHocCommand() {
 
}
 

	
 
boost::shared_ptr<Swift::Command> SettingsAdHocCommand::handleRequest(boost::shared_ptr<Swift::Command> payload) {
 
	boost::shared_ptr<Swift::Command> response;
 
	
 
	
 
	
 
	return response;
 
}
 

	
 
}
src/transport.cpp
Show inline comments
 
@@ -23,13 +23,12 @@
 
#include <boost/algorithm/string/predicate.hpp>
 
#include "transport/storagebackend.h"
 
#include "transport/factory.h"
 
#include "transport/userregistry.h"
 
#include "transport/logging.h"
 
#include "discoinforesponder.h"
 
#include "discoitemsresponder.h"
 
#include "storageparser.h"
 
#include "Swiften/TLS/OpenSSL/OpenSSLServerContext.h"
 
#include "Swiften/TLS/PKCS12Certificate.h"
 
#include "Swiften/TLS/OpenSSL/OpenSSLServerContextFactory.h"
 
#include "Swiften/Parser/PayloadParsers/AttentionParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/AttentionSerializer.h"
 
@@ -146,27 +145,23 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
 
	m_presenceOracle = new Transport::PresenceOracle(m_stanzaChannel);
 
	m_presenceOracle->onPresenceChange.connect(bind(&Component::handlePresence, this, _1));
 

	
 
	m_discoInfoResponder = new DiscoInfoResponder(m_iqRouter, m_config);
 
	m_discoInfoResponder->start();
 

	
 
	m_discoItemsResponder = new DiscoItemsResponder(m_iqRouter);
 
	m_discoItemsResponder->start();
 

	
 
// 
 
// 	m_registerHandler = new SpectrumRegisterHandler(m_component);
 
// 	m_registerHandler->start();
 
}
 

	
 
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) {
 
		m_server->stop();
 
		delete m_server;
 
	}
0 comments (0 inline, 0 general)