Changeset - cbcf2f145298
CMakeLists.txt
Show inline comments
 
@@ -150,6 +150,7 @@ include_directories(${Boost_INCLUDE_DIRS})
 

	
 

	
 
ADD_SUBDIRECTORY(src)
 
ADD_SUBDIRECTORY(plugin)
 
ADD_SUBDIRECTORY(include)
 
#ADD_SUBDIRECTORY(examples)
 
ADD_SUBDIRECTORY(spectrum)
backends/frotz/CMakeLists.txt
Show inline comments
 
@@ -6,7 +6,7 @@ FILE(GLOB SRC *.c *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_frotz_backend ${SRC})
 
 
target_link_libraries(spectrum2_frotz_backend transport pthread)
 
target_link_libraries(spectrum2_frotz_backend transport pthread transport-plugin)
 
 
INSTALL(TARGETS spectrum2_frotz_backend RUNTIME DESTINATION bin)
 
backends/frotz/main.cpp
Show inline comments
 
@@ -10,6 +10,7 @@
 

	
 
#include "transport/config.h"
 
#include "transport/networkplugin.h"
 
#include "Swiften/Swiften.h"
 
#include <boost/filesystem.hpp>
 
#include "unistd.h"
 
#include "signal.h"
 
@@ -145,14 +146,13 @@ static void start_dfrotz(dfrotz &p, const std::string &game) {
 

	
 
class FrotzNetworkPlugin : public NetworkPlugin {
 
	public:
 
		FrotzNetworkPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin(loop, host, port) {
 
		FrotzNetworkPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
 
			this->config = config;
 
		}
 

	
 
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
 
			np->handleConnected(user);
 
			Swift::StatusShow status;
 
			np->handleBuddyChanged(user, "zcode", "ZCode", "ZCode", status.getType());
 
			np->handleBuddyChanged(user, "zcode", "ZCode", "ZCode", pbnetwork::STATUS_ONLINE);
 
// 			sleep(1);
 
// 			np->handleMessage(np->m_user, "zork", first_msg);
 
		}
backends/libircclient-qt/CMakeLists.txt
Show inline comments
 
@@ -4,7 +4,7 @@ FILE(GLOB HEADERS *.h)
 
QT4_WRAP_CPP(SRC ${HEADERS})
 
ADD_EXECUTABLE(spectrum2_libircclient-qt_backend ${SRC})
 
 
target_link_libraries(spectrum2_libircclient-qt_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport pthread)
 
target_link_libraries(spectrum2_libircclient-qt_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport-plugin transport pthread)
 
 
INSTALL(TARGETS spectrum2_libircclient-qt_backend RUNTIME DESTINATION bin)
 
backends/libircclient-qt/main.cpp
Show inline comments
 
@@ -22,16 +22,15 @@ IRCNetworkPlugin * np = NULL;
 

	
 
class IRCNetworkPlugin : public NetworkPlugin {
 
	public:
 
		IRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port) : NetworkPlugin(loop, host, port) {
 
		IRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
 
			this->config = config;
 
		}
 

	
 
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
 
			Swift::JID jid(legacyName);
 
			MyIrcSession *session = new MyIrcSession(user, this);
 
			session->setNick(QString::fromStdString(jid.getNode()));
 
			session->connectToServer(QString::fromStdString(jid.getDomain()), 6667);
 
			std::cout << "CONNECTING IRC NETWORK " << jid.getNode() << " " << jid.getDomain() << "\n";
 
			session->setNick(QString::fromStdString(user.substr(0, user.find("@"))));
 
			session->connectToServer(QString::fromStdString(user.substr(user.find("@") + 1)), 6667);
 
// 			std::cout << "CONNECTING IRC NETWORK " << jid.getNode() << " " << jid.getDomain() << "\n";
 
			m_sessions[user] = session;
 
		}
 

	
backends/libircclient-qt/session.cpp
Show inline comments
 
@@ -79,10 +79,10 @@ void MyIrcBuffer::on_receiverChanged(const QString& receiver)
 
    qDebug() << "receiver changed:" << receiver;
 
}
 

	
 
Conversation::ParticipantFlag MyIrcBuffer::correctNickname(std::string &nickname) {
 
	Conversation::ParticipantFlag flags = Conversation::None;
 
bool MyIrcBuffer::correctNickname(std::string &nickname) {
 
	bool flags = 0;
 
	switch(nickname.at(0)) {
 
		case '@': nickname = nickname.substr(1); flags = Conversation::Moderator; break;
 
		case '@': nickname = nickname.substr(1); flags = 1; break;
 
		case '+': nickname = nickname.substr(1); break;
 
		default: break;
 
	}
 
@@ -91,18 +91,18 @@ Conversation::ParticipantFlag MyIrcBuffer::correctNickname(std::string &nickname
 

	
 
void MyIrcBuffer::on_joined(const QString& origin) {
 
	qDebug() << "joined:" << receiver() << origin;
 
	Conversation::ParticipantFlag flags = Conversation::None;
 
	bool flags = 0;
 
	std::string nickname = origin.toStdString();
 
	flags = correctNickname(nickname);
 
	np->handleParticipantChanged(user, origin.toStdString(), receiver().toStdString(), flags, Swift::StatusShow::Online);
 
	np->handleParticipantChanged(user, origin.toStdString(), receiver().toStdString(), (int) flags, pbnetwork::STATUS_ONLINE);
 
}
 

	
 
void MyIrcBuffer::on_parted(const QString& origin, const QString& message) {
 
	qDebug() << "parted:" << receiver() << origin << message;
 
	Conversation::ParticipantFlag flags = Conversation::None;
 
	bool flags = 0;
 
	std::string nickname = origin.toStdString();
 
	flags = correctNickname(nickname);
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(), flags, Swift::StatusShow::None, message.toStdString());
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(),(int) flags, pbnetwork::STATUS_NONE, message.toStdString());
 
}
 

	
 
void MyIrcBuffer::on_quit(const QString& origin, const QString& message)
 
@@ -114,9 +114,9 @@ void MyIrcBuffer::on_quit(const QString& origin, const QString& message)
 
void MyIrcBuffer::on_nickChanged(const QString& origin, const QString& nick) {
 
	qDebug() << "nick changed:" << receiver() << origin << nick;
 
	std::string nickname = origin.toStdString();
 
	Conversation::ParticipantFlag flags = p->m_modes[receiver().toStdString() + nickname];
 
	bool flags = p->m_modes[receiver().toStdString() + nickname];
 
// 	std::cout << receiver().toStdString() + nickname << " " << flags <<  "\n";
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(), flags, Swift::StatusShow::Online, "", nick.toStdString());
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(),(int) flags, pbnetwork::STATUS_ONLINE, "", nick.toStdString());
 
}
 

	
 
void MyIrcBuffer::on_modeChanged(const QString& origin, const QString& mode, const QString& args) {
 
@@ -126,13 +126,13 @@ void MyIrcBuffer::on_modeChanged(const QString& origin, const QString& mode, con
 
	if (nickname.empty())
 
		return;
 
	if (mode == "+o") {
 
		p->m_modes[receiver().toStdString() + nickname] = Conversation::Moderator;
 
		p->m_modes[receiver().toStdString() + nickname] = 1;
 
	}
 
	else {
 
		p->m_modes[receiver().toStdString() + nickname] = Conversation::None;
 
		p->m_modes[receiver().toStdString() + nickname] = 0;
 
	}
 
	Conversation::ParticipantFlag flags = p->m_modes[receiver().toStdString() + nickname];
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(), flags, Swift::StatusShow::Online, "");
 
	bool flags = p->m_modes[receiver().toStdString() + nickname];
 
	np->handleParticipantChanged(user, nickname, receiver().toStdString(),(int) flags, pbnetwork::STATUS_ONLINE, "");
 
}
 

	
 
void MyIrcBuffer::on_topicChanged(const QString& origin, const QString& topic) {
 
@@ -199,12 +199,12 @@ void MyIrcBuffer::on_numericMessageReceived(const QString& origin, uint code, co
 
			QStringList members = params.value(3).split(" ");
 

	
 
			for (int i = 0; i < members.size(); i++) {
 
				Conversation::ParticipantFlag flags = Conversation::None;
 
				bool flags = 0;
 
				std::string nickname = members.at(i).toStdString();
 
				flags = correctNickname(nickname);
 
				p->m_modes[channel.toStdString() + nickname] = flags;
 
// 				std::cout << channel.toStdString() + nickname << " " << flags << "\n";
 
				np->handleParticipantChanged(user, nickname, channel.toStdString(), flags, Swift::StatusShow::Online);
 
				np->handleParticipantChanged(user, nickname, channel.toStdString(),(int) flags, pbnetwork::STATUS_ONLINE);
 
			}
 
			break;
 
	}
backends/libircclient-qt/session.h
Show inline comments
 
@@ -23,7 +23,7 @@ class MyIrcSession : public Irc::Session
 

	
 
public:
 
    MyIrcSession(const std::string &user, NetworkPlugin *np, QObject* parent = 0);
 
	std::map<std::string, Conversation::ParticipantFlag> m_modes;
 
	std::map<std::string, bool> m_modes;
 

	
 
protected Q_SLOTS:
 
    void on_connected();
 
@@ -67,7 +67,7 @@ protected Q_SLOTS:
 
    void on_numericMessageReceived(const QString& origin, uint code, const QStringList& params);
 
    void on_unknownMessageReceived(const QString& origin, const QStringList& params);
 

	
 
	Conversation::ParticipantFlag correctNickname(std::string &nickname);
 
	bool correctNickname(std::string &nickname);
 
};
 

	
 
#endif // SESSION_H
backends/libpurple/CMakeLists.txt
Show inline comments
 
@@ -3,7 +3,7 @@ FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_libpurple_backend ${SRC})
 
 
target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport pthread)
 
target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin pthread)
 
 
INSTALL(TARGETS spectrum2_libpurple_backend RUNTIME DESTINATION bin)
 
backends/libpurple/main.cpp
Show inline comments
 
@@ -2,18 +2,7 @@
 
#include "purple.h"
 
#include <iostream>
 

	
 
#include "transport/config.h"
 
#include "transport/transport.h"
 
#include "transport/usermanager.h"
 
#include "transport/logger.h"
 
#include "transport/sqlite3backend.h"
 
#include "transport/userregistration.h"
 
#include "transport/user.h"
 
#include "transport/storagebackend.h"
 
#include "transport/rostermanager.h"
 
#include "transport/conversation.h"
 
#include "transport/networkplugin.h"
 
#include "spectrumeventloop.h"
 
#include "geventloop.h"
 
#include "log4cxx/logger.h"
 
#include "log4cxx/consoleappender.h"
 
@@ -25,21 +14,62 @@
 
#include "sys/signal.h"
 
// #include "valgrind/memcheck.h"
 
#include "malloc.h"
 

	
 
#include <algorithm>
 
#include "errno.h"
 

	
 
#include <netinet/if_ether.h>
 
#include <netinet/ip.h>
 
#include <netinet/ip6.h>
 
#include <netinet/udp.h>
 
#include <netinet/tcp.h>
 
#include <netinet/ether.h>
 
#include "sys/socket.h"
 
#include <netdb.h>
 
#include <unistd.h>
 
#include <fcntl.h>
 

	
 
#ifdef WITH_LIBEVENT
 
#include <event.h>
 
#endif
 

	
 
using namespace log4cxx;
 

	
 
static LoggerPtr logger_libpurple = Logger::getLogger("backend.libpurple");
 
static LoggerPtr logger = Logger::getLogger("backend");
 
static LoggerPtr logger_libpurple = log4cxx::Logger::getLogger("libpurple");
 
static LoggerPtr logger = log4cxx::Logger::getLogger("backend");
 
int m_sock;
 

	
 
using namespace Transport;
 

	
 
class SpectrumNetworkPlugin;
 
template <class T> T fromString(const std::string &str) {
 
	T i;
 
	std::istringstream os(str);
 
	os >> i;
 
	return i;
 
}
 

	
 
template <class T> std::string stringOf(T object) {
 
	std::ostringstream os;
 
	os << object;
 
	return (os.str());
 
}
 

	
 
class SpectrumNetworkPlugin;
 

	
 
GKeyFile *keyfile;
 
SpectrumNetworkPlugin *np;
 

	
 
static std::string KEYFILE_STRING(const std::string &cat, const std::string &key, const std::string &def = "") {
 
	gchar *str = g_key_file_get_string(keyfile, cat.c_str(), key.c_str(), 0);
 
	if (!str) {
 
		return def;
 
	}
 
	std::string ret(str);
 
	free(str);
 
	return ret;
 
}
 

	
 
#define KEYFILE_BOOL(CAT, KEY) g_key_file_get_boolean(keyfile, CAT, KEY, 0)
 

	
 
static gboolean nodaemon = FALSE;
 
static gchar *logfile = NULL;
 
static gchar *lock_file = NULL;
 
@@ -432,19 +462,18 @@ static std::string getAlias(PurpleBuddy *m_buddy) {
 

	
 
class SpectrumNetworkPlugin : public NetworkPlugin {
 
	public:
 
		SpectrumEventLoop *m_loop;
 
		SpectrumNetworkPlugin(Config *config, SpectrumEventLoop *loop, const std::string &host, int port) : NetworkPlugin(loop, host, port) {
 
			this->config = config;
 
			m_loop = loop;
 
		SpectrumNetworkPlugin(const std::string &host, int port) : NetworkPlugin() {
 

	
 
		}
 

	
 
		void handleExit() {
 
			m_loop->stop();
 
		void handleExitRequest() {
 
			LOG4CXX_INFO(logger, "Exiting...");
 
			exit(1);
 
		}
 

	
 
		void getProtocolAndName(const std::string &legacyName, std::string &name, std::string &protocol) {
 
			name = legacyName;
 
			protocol = CONFIG_STRING(config, "service.protocol");
 
			protocol = KEYFILE_STRING("service", "protocol");
 
			if (protocol == "any") {
 
				protocol = name.substr(0, name.find("."));
 
				name = name.substr(name.find(".") + 1);
 
@@ -455,13 +484,13 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			char* contents;
 
			gsize length;
 
			gboolean ret = false;
 
			if (!CONFIG_STRING(config, "backend.avatars_directory").empty()) {
 
				std::string f = CONFIG_STRING(config, "backend.avatars_directory") + "/" + legacyName;
 
			if (!KEYFILE_STRING("backend", "avatars_directory").empty()) {
 
				std::string f = KEYFILE_STRING("backend", "avatars_directory") + "/" + legacyName;
 
				ret = g_file_get_contents (f.c_str(), &contents, &length, NULL);
 
			}
 

	
 
			if (!CONFIG_STRING(config, "backend.default_avatar").empty() && !ret) {
 
				ret = g_file_get_contents (CONFIG_STRING(config, "backend.default_avatar").c_str(),
 
			if (!KEYFILE_STRING("backend", "default_avatar").empty() && !ret) {
 
				ret = g_file_get_contents (KEYFILE_STRING("backend", "default_avatar").c_str(),
 
											&contents, &length, NULL);
 
			}
 

	
 
@@ -471,47 +500,47 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
		}
 

	
 
		void setDefaultAccountOptions(PurpleAccount *account) {
 
			for (std::map<std::string,std::string>::const_iterator it = config->getUnregistered().begin();
 
				it != config->getUnregistered().end(); it++) {
 
				if ((*it).first.find("purple.") == 0) {
 
					std::string key = (*it).first.substr((*it).first.find(".") + 1);
 

	
 
					PurplePlugin *plugin = purple_find_prpl(purple_account_get_protocol_id(account));
 
					PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
 
					bool found = false;
 
					for (GList *l = prpl_info->protocol_options; l != NULL; l = l->next) {
 
						PurpleAccountOption *option = (PurpleAccountOption *) l->data;
 
						PurplePrefType type = purple_account_option_get_type(option);
 
						std::string key2(purple_account_option_get_setting(option));
 
						std::cout << key << " " << key2 << " " << (*it).second << "\n";
 
						if (key != key2)
 
							continue;
 
						
 
						found = true;
 
						switch (type) {
 
							case PURPLE_PREF_BOOLEAN:
 
								purple_account_set_bool(account, key.c_str(), boost::lexical_cast<bool>((*it).second));
 
								break;
 

	
 
							case PURPLE_PREF_INT:
 
								purple_account_set_int(account, key.c_str(), boost::lexical_cast<int>((*it).second));
 
								break;
 

	
 
							case PURPLE_PREF_STRING:
 
							case PURPLE_PREF_STRING_LIST:
 
								purple_account_set_string(account, key.c_str(), (*it).second.c_str());
 
								break;
 
							default:
 
								continue;
 
						}
 
						break;
 
					}
 

	
 
					if (!found) {
 
						purple_account_set_string(account, key.c_str(), (*it).second.c_str());
 
					}
 
				}
 
			}
 
// 			for (std::map<std::string,std::string>::const_iterator it = config->getUnregistered().begin();
 
// 				it != config->getUnregistered().end(); it++) {
 
// 				if ((*it).first.find("purple.") == 0) {
 
// 					std::string key = (*it).first.substr((*it).first.find(".") + 1);
 
// 
 
// 					PurplePlugin *plugin = purple_find_prpl(purple_account_get_protocol_id(account));
 
// 					PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
 
// 					bool found = false;
 
// 					for (GList *l = prpl_info->protocol_options; l != NULL; l = l->next) {
 
// 						PurpleAccountOption *option = (PurpleAccountOption *) l->data;
 
// 						PurplePrefType type = purple_account_option_get_type(option);
 
// 						std::string key2(purple_account_option_get_setting(option));
 
// 						std::cout << key << " " << key2 << " " << (*it).second << "\n";
 
// 						if (key != key2)
 
// 							continue;
 
// 						
 
// 						found = true;
 
// 						switch (type) {
 
// 							case PURPLE_PREF_BOOLEAN:
 
// 								purple_account_set_bool(account, key.c_str(), fromString<bool>((*it).second));
 
// 								break;
 
// 
 
// 							case PURPLE_PREF_INT:
 
// 								purple_account_set_int(account, key.c_str(), fromString<int>((*it).second));
 
// 								break;
 
// 
 
// 							case PURPLE_PREF_STRING:
 
// 							case PURPLE_PREF_STRING_LIST:
 
// 								purple_account_set_string(account, key.c_str(), (*it).second.c_str());
 
// 								break;
 
// 							default:
 
// 								continue;
 
// 						}
 
// 						break;
 
// 					}
 
// 
 
// 					if (!found) {
 
// 						purple_account_set_string(account, key.c_str(), (*it).second.c_str());
 
// 					}
 
// 				}
 
// 			}
 
		}
 

	
 
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
 
@@ -553,7 +582,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			setDefaultAccountOptions(account);
 

	
 
			purple_account_set_enabled(account, "spectrum", TRUE);
 
			if (CONFIG_BOOL(np->config, "service.enable_privacy_lists")) {
 
			if (KEYFILE_BOOL("service", "enable_privacy_lists")) {
 
				purple_account_set_privacy_type(account, PURPLE_PRIVACY_DENY_USERS);
 
			}
 

	
 
@@ -630,7 +659,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			if (account) {
 
				int st;
 
				switch(status) {
 
					case Swift::StatusShow::Away: {
 
					case pbnetwork::STATUS_AWAY: {
 
						st = PURPLE_STATUS_AWAY;
 
						if (!purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_AWAY))
 
							st = PURPLE_STATUS_EXTENDED_AWAY;
 
@@ -638,22 +667,22 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
							st = PURPLE_STATUS_AWAY;
 
						break;
 
					}
 
					case Swift::StatusShow::DND: {
 
					case pbnetwork::STATUS_DND: {
 
						st = PURPLE_STATUS_UNAVAILABLE;
 
						break;
 
					}
 
					case Swift::StatusShow::XA: {
 
					case pbnetwork::STATUS_XA: {
 
						if (!purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_EXTENDED_AWAY))
 
							st = PURPLE_STATUS_AWAY;
 
						else
 
							st = PURPLE_STATUS_EXTENDED_AWAY;
 
						break;
 
					}
 
					case Swift::StatusShow::None: {
 
					case pbnetwork::STATUS_NONE: {
 
						st = PURPLE_STATUS_OFFLINE;
 
						break;
 
					}
 
					case 6:
 
					case pbnetwork::STATUS_INVISIBLE:
 
						st = PURPLE_STATUS_INVISIBLE;
 
						break;
 
					default:
 
@@ -700,13 +729,13 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				std::string name = legacyName;
 
				if (CONFIG_STRING(config, "service.protocol") == "any" && legacyName.find("prpl-") == 0) {
 
				if (KEYFILE_STRING("service", "protocol") == "any" && legacyName.find("prpl-") == 0) {
 
					name = name.substr(name.find(".") + 1);
 
				}
 
				m_vcards[user + name] = id;
 

	
 
				std::cout << name << " " << purple_account_get_username(account) << "\n";
 
				if (CONFIG_BOOL(config, "backend.no_vcard_fetch") && name != purple_account_get_username(account)) {
 
				if (KEYFILE_BOOL("backend", "no_vcard_fetch") && name != purple_account_get_username(account)) {
 
					PurpleNotifyUserInfo *user_info = purple_notify_user_info_new();
 
					notify_user_info(purple_account_get_connection(account), name.c_str(), user_info);
 
					purple_notify_user_info_destroy(user_info);
 
@@ -787,7 +816,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
		}
 

	
 
		void handleBuddyBlockToggled(const std::string &user, const std::string &buddyName, bool blocked) {
 
			if (CONFIG_BOOL(np->config, "service.enable_privacy_lists")) {
 
			if (KEYFILE_BOOL("service", "enable_privacy_lists")) {
 
				PurpleAccount *account = m_sessions[user];
 
				if (account) {
 
					if (blocked) {
 
@@ -876,10 +905,10 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			std::vector<PurpleXfer *> tmp;
 
			tmp.swap(m_waitingXfers);
 

	
 
			BOOST_FOREACH(PurpleXfer *xfer, tmp) {
 
				FTData *ftData = (FTData *) xfer->ui_data;
 
			for (std::vector<PurpleXfer *>::const_iterator it = tmp.begin(); it != tmp.end(); it++) {
 
				FTData *ftData = (FTData *) (*it)->ui_data;
 
				if (ftData->timer == 0) {
 
					ftData->timer = purple_timeout_add(1, ft_ui_ready, xfer);
 
					ftData->timer = purple_timeout_add(1, ft_ui_ready, *it);
 
				}
 
// 				purple_xfer_ui_ready(xfer);
 
			}
 
@@ -892,10 +921,9 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
		std::map<unsigned long, PurpleXfer *> m_xfers;
 
		std::map<std::string, PurpleXfer *> m_unhandledXfers;
 
		std::vector<PurpleXfer *> m_waitingXfers;
 
		Config *config;
 
};
 

	
 
static bool getStatus(PurpleBuddy *m_buddy, Swift::StatusShow &status, std::string &statusMessage) {
 
static bool getStatus(PurpleBuddy *m_buddy, pbnetwork::StatusType &status, std::string &statusMessage) {
 
	PurplePresence *pres = purple_buddy_get_presence(m_buddy);
 
	if (pres == NULL)
 
		return false;
 
@@ -906,25 +934,27 @@ static bool getStatus(PurpleBuddy *m_buddy, Swift::StatusShow &status, std::stri
 

	
 
	switch(st) {
 
		case PURPLE_STATUS_AVAILABLE: {
 
			status = pbnetwork::STATUS_ONLINE;
 
			break;
 
		}
 
		case PURPLE_STATUS_AWAY: {
 
			status = Swift::StatusShow::Away;
 
			status = pbnetwork::STATUS_AWAY;
 
			break;
 
		}
 
		case PURPLE_STATUS_UNAVAILABLE: {
 
			status = Swift::StatusShow::DND;
 
			status = pbnetwork::STATUS_DND;
 
			break;
 
		}
 
		case PURPLE_STATUS_EXTENDED_AWAY: {
 
			status = Swift::StatusShow::XA;
 
			status = pbnetwork::STATUS_XA;
 
			break;
 
		}
 
		case PURPLE_STATUS_OFFLINE: {
 
			status = Swift::StatusShow::None;
 
			status = pbnetwork::STATUS_NONE;
 
			break;
 
		}
 
		default:
 
			status = pbnetwork::STATUS_ONLINE;
 
			break;
 
	}
 

	
 
@@ -986,7 +1016,7 @@ static void buddyListNewNode(PurpleBlistNode *node) {
 
	PurpleAccount *account = purple_buddy_get_account(buddy);
 

	
 
	// Status
 
	Swift::StatusShow status;
 
	pbnetwork::StatusType status;
 
	std::string message;
 
	getStatus(buddy, status, message);
 

	
 
@@ -995,7 +1025,7 @@ static void buddyListNewNode(PurpleBlistNode *node) {
 
	PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
 

	
 
	bool blocked = false;
 
	if (CONFIG_BOOL(np->config, "service.enable_privacy_lists")) {
 
	if (KEYFILE_BOOL("service", "enable_privacy_lists")) {
 
		if (prpl_info && prpl_info->tooltip_text) {
 
			PurpleNotifyUserInfo *user_info = purple_notify_user_info_new();
 
			prpl_info->tooltip_text(buddy, user_info, true);
 
@@ -1028,8 +1058,7 @@ static void buddyListNewNode(PurpleBlistNode *node) {
 
		}
 
	}
 

	
 
	std::cout << "BLOCKED?" << (purple_privacy_check(account, purple_buddy_get_name(buddy)) == false) << "\n";
 
	np->handleBuddyChanged(np->m_accounts[account], purple_buddy_get_name(buddy), getAlias(buddy), getGroups(buddy)[0], status.getType(), message, getIconHash(buddy),
 
	np->handleBuddyChanged(np->m_accounts[account], purple_buddy_get_name(buddy), getAlias(buddy), getGroups(buddy)[0], status, message, getIconHash(buddy),
 
		blocked
 
	);
 
}
 
@@ -1197,7 +1226,7 @@ static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotif
 
	std::string nickname;
 
	std::string header;
 
	std::string label;
 
	Swift::ByteArray photo;
 
	std::string photo;
 

	
 
	while (vcardEntries) {
 
		vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
 
@@ -1248,7 +1277,7 @@ static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotif
 
			const gchar * data = (const gchar *) purple_imgstore_get_data(avatar);
 
			size_t len = purple_imgstore_get_size(avatar);
 
			if (len < 300000 && data) {
 
				photo = Swift::createByteArray(data, len);
 
				photo = std::string(data, len);
 
			}
 
			purple_imgstore_unref(avatar);
 
		}
 
@@ -1264,7 +1293,7 @@ static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotif
 
				gchar *data;
 
				gchar *path = purple_buddy_icon_get_full_path(icon);
 
				if (g_file_get_contents (path, &data, &len, NULL)) {
 
					photo = Swift::createByteArray(data, len);
 
					photo = std::string(data, len);
 
					free(data);
 
				}
 
				free(path);
 
@@ -1272,14 +1301,14 @@ static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotif
 
			else {
 
				const gchar * data = (gchar*)purple_buddy_icon_get_data(icon, &len);
 
				if (len < 300000 && data) {
 
					photo = Swift::createByteArray(data, len);
 
					photo = std::string(data, len);
 
				}
 
			}
 
			purple_buddy_icon_unref(icon);
 
		}
 
	}
 

	
 
	np->handleVCard(np->m_accounts[account], np->m_vcards[np->m_accounts[account] + name], name, fullName, nickname, Swift::byteArrayToString(photo));
 
	np->handleVCard(np->m_accounts[account], np->m_vcards[np->m_accounts[account] + name], name, fullName, nickname, photo);
 
	np->m_vcards.erase(np->m_accounts[account] + name);
 

	
 
	return NULL;
 
@@ -1580,7 +1609,7 @@ static void gotAttention(PurpleAccount *account, const char *who, PurpleConversa
 
	np->handleAttention(np->m_accounts[account], w, "");
 
}
 

	
 
static bool initPurple(Config &cfg) {
 
static bool initPurple() {
 
	bool ret;
 

	
 
	purple_util_set_user_dir("./");
 
@@ -1592,20 +1621,13 @@ static bool initPurple(Config &cfg) {
 
		purple_debug_set_verbose(true);
 

	
 
	purple_core_set_ui_ops(&coreUiOps);
 
	std::map<std::string, std::string> unregistered = cfg.getUnregistered();
 
	if (unregistered.find("service.eventloop") != unregistered.end()) {
 
		if (unregistered["service.eventloop"] == "libev") {
 
			LOG4CXX_INFO(logger, "Will use libev based event loop");
 
		}
 
		else {
 
			LOG4CXX_INFO(logger, "Will use glib based event loop");
 
		}
 
		purple_eventloop_set_ui_ops(getEventLoopUiOps(unregistered["service.eventloop"] == "libev"));
 
	if (KEYFILE_STRING("service", "eventloop") == "libev") {
 
		LOG4CXX_INFO(logger, "Will use libev based event loop");
 
	}
 
	else {
 
		LOG4CXX_INFO(logger, "Will use glib based event loop");
 
		purple_eventloop_set_ui_ops(getEventLoopUiOps(false));
 
	}
 
	purple_eventloop_set_ui_ops(getEventLoopUiOps(KEYFILE_STRING("service", "eventloop") == "libev"));
 

	
 
	ret = purple_core_init("spectrum");
 
	if (ret) {
 
@@ -1681,12 +1703,15 @@ static void transportDataReceived(gpointer data, gint source, PurpleInputConditi
 
	char buffer[65535];
 
	char *ptr = buffer;
 
	ssize_t n = read(source, ptr, sizeof(buffer));
 
	Swift::SafeByteArray d = Swift::createSafeByteArray(buffer, n);
 
	if (n <= 0) {
 
		LOG4CXX_INFO(logger, "Diconnecting from spectrum2 server");
 
		exit(errno);
 
	}
 
	std::string d = std::string(buffer, n);
 
	np->handleDataRead(d);
 
}
 

	
 
int main(int argc, char **argv) {
 
	Swift::logging = true;
 
	GError *error = NULL;
 
	GOptionContext *context;
 
	context = g_option_context_new("config_file_name or profile name");
 
@@ -1748,27 +1773,27 @@ int main(int argc, char **argv) {
 
// 			return -1;
 
//		}
 
#endif
 
		Config config;
 
		if (!config.load(argv[1])) {
 
		keyfile = g_key_file_new ();
 
		if (!g_key_file_load_from_file (keyfile, argv[1], (GKeyFileFlags) 0, 0)) {
 
			std::cout << "Can't open " << argv[1] << " configuration file.\n";
 
			return 1;
 
		}
 

	
 
		if (CONFIG_STRING(&config, "logging.backend_config").empty()) {
 
		if (KEYFILE_STRING("logging", "backend_config").empty()) {
 
			LoggerPtr root = log4cxx::Logger::getRootLogger();
 
			root->addAppender(new ConsoleAppender(new PatternLayout("%d %-5p %c: %m%n")));
 
		}
 
		else {
 
			log4cxx::helpers::Properties p;
 
			log4cxx::helpers::FileInputStream *istream = new log4cxx::helpers::FileInputStream(CONFIG_STRING(&config, "logging.backend_config"));
 
			log4cxx::helpers::FileInputStream *istream = new log4cxx::helpers::FileInputStream(KEYFILE_STRING("logging", "backend_config"));
 

	
 
			p.load(istream);
 
			p.setProperty("pid", boost::lexical_cast<std::string>(getpid()));
 
			p.setProperty("jid", CONFIG_STRING(&config, "service.jid"));
 
			p.setProperty("pid", stringOf(getpid()));
 
			p.setProperty("jid", KEYFILE_STRING("service", "jid"));
 
			log4cxx::PropertyConfigurator::configure(p);
 
		}
 

	
 
		initPurple(config);
 
		initPurple();
 

	
 
		int portno = port;
 
		struct sockaddr_in serv_addr;
 
@@ -1797,11 +1822,30 @@ int main(int argc, char **argv) {
 

	
 
		purple_input_add(m_sock, PURPLE_INPUT_READ, &transportDataReceived, NULL);
 

	
 
		std::map<std::string, std::string> unregistered = config.getUnregistered();
 
		SpectrumEventLoop eventLoop(unregistered["service.eventloop"] == "libev");
 
		np = new SpectrumNetworkPlugin(&config, &eventLoop, host, port);
 
		eventLoop.run();
 
		np = new SpectrumNetworkPlugin(host, port);
 
		bool libev = KEYFILE_STRING("service", "eventloop") == "libev";
 

	
 
		GMainLoop *m_loop;
 
#ifdef WITH_LIBEVENT
 
		if (!libev) {
 
			m_loop = g_main_loop_new(NULL, FALSE);
 
		}
 
		else {
 
			event_init();
 
		}
 
#endif
 
		m_loop = g_main_loop_new(NULL, FALSE);
 

	
 
		if (m_loop) {
 
			g_main_loop_run(m_loop);
 
		}
 
#ifdef WITH_LIBEVENT
 
		else {
 
			event_loop(0);
 
		}
 
#endif
 
	}
 

	
 
	g_option_context_free(context);
 
	return 0;
 
}
backends/libpurple/spectrumeventloop.cpp
Show inline comments
 
deleted file
backends/libpurple/spectrumeventloop.h
Show inline comments
 
deleted file
cmake_modules/ProtobufConfig.cmake
Show inline comments
 
@@ -63,12 +63,12 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
 
    get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
 
    get_filename_component(FIL_WE ${FIL} NAME_WE)
 
    
 
    list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
 
    list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
 
    list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.cpp")
 
    list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.h")
 

	
 
    add_custom_command(
 
      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
 
             "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
 
    add_custom_target(pb
 
      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.cpp"
 
             "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.h"
 
      COMMAND  ${PROTOBUF_PROTOC_EXECUTABLE}
 
      ARGS --cpp_out  ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
 
      DEPENDS ${ABS_FIL}
include/transport/CMakeLists.txt
Show inline comments
 
FILE(GLOB HEADERS *.h)
 
if (PROTOBUF_FOUND)
 
	add_custom_target(pb
 
		${PROTOBUF_PROTOC_EXECUTABLE}
 
		--cpp_out  ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/protocol.proto
 
		COMMENT "Running C++ protocol buffer compiler on protocol.proto"
 
		DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/protocol.proto
 
		VERBATIM )
 
endif()
 

	
 
FILE(GLOB HEADERS *.h protocol.h)
 

	
 
INSTALL(FILES ${HEADERS} DESTINATION include/transport COMPONENT headers)
 
\ No newline at end of file
include/transport/memoryusage.h
Show inline comments
 
file renamed from src/memoryusage.h to include/transport/memoryusage.h
include/transport/networkplugin.h
Show inline comments
 
@@ -21,17 +21,9 @@
 
#pragma once
 

	
 
#include <time.h>
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Presence/PresenceOracle.h"
 
#include "Swiften/Disco/EntityCapsManager.h"
 
#include "Swiften/Network/ConnectionServer.h"
 
#include "Swiften/Network/Connection.h"
 
#include "Swiften/Network/BoostTimerFactory.h"
 
#include "Swiften/Network/BoostNetworkFactories.h"
 
#include "Swiften/Network/BoostIOServiceThread.h"
 
#include "Swiften/Network/Connection.h"
 
#include "storagebackend.h"
 
#include "conversation.h"
 
#include "transport/protocol.pb.h"
 
// #include "conversation.h"
 
#include <iostream>
 

	
 
namespace Transport {
 

	
 
@@ -46,12 +38,10 @@ class NetworkPlugin {
 
		/// \param loop Event loop.
 
		/// \param host Host where Spectrum2 NetworkPluginServer runs.
 
		/// \param port Port.
 
		NetworkPlugin(Swift::EventLoop *loop, const std::string &host, int port);
 
		NetworkPlugin();
 

	
 
		/// Destructor.
 
		virtual ~NetworkPlugin();
 
		
 
		virtual void readyForData() {}
 

	
 
		/// Call this function when legacy network buddy changed.
 
		/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
 
@@ -63,7 +53,7 @@ class NetworkPlugin {
 
		/// \param iconHash MD5 hash of buddy icon. Empty if none buddy icon.
 
		/// \param blocked True if this buddy is blocked in privacy lists in legacy network.
 
		void handleBuddyChanged(const std::string &user, const std::string &buddyName, const std::string &alias,
 
			const std::string &groups, Swift::StatusShow::Type status, const std::string &statusMessage = "", const std::string &iconHash = "",
 
			const std::string &groups, pbnetwork::StatusType status, const std::string &statusMessage = "", const std::string &iconHash = "",
 
			bool blocked = false
 
		);
 

	
 
@@ -75,8 +65,8 @@ class NetworkPlugin {
 
		/// \param status Current status of participant. Swift::StatusShow::None if participant left the room.
 
		/// \param statusMessage Current status message of participant.
 
		/// \param newname New name of participant if he changed the nickname. Otherwise empty.
 
		void handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, Conversation::ParticipantFlag flags = Conversation::None,
 
			Swift::StatusShow::Type status = Swift::StatusShow::None, const std::string &statusMessage = "", const std::string &newname = "");
 
		void handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, int flags,
 
			pbnetwork::StatusType = pbnetwork::STATUS_NONE, const std::string &statusMessage = "", const std::string &newname = "");
 

	
 
		/// Call this function when user disconnected the legacy network because of some legacy network error.
 
		/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
 
@@ -221,8 +211,8 @@ class NetworkPlugin {
 
		virtual void handleFTPauseRequest(unsigned long ftID) {}
 
		virtual void handleFTContinueRequest(unsigned long ftID) {}
 

	
 
		virtual void handleExit() { std::cout << "EXITING\n"; exit(1); }
 
		void handleDataRead(Swift::SafeByteArray &data);
 
		virtual void handleExitRequest() { exit(1); }
 
		void handleDataRead(std::string &data);
 
		virtual void sendData(const std::string &string) {}
 
		
 

	
 
@@ -237,28 +227,18 @@ class NetworkPlugin {
 
		void handleVCardPayload(const std::string &payload);
 
		void handleBuddyChangedPayload(const std::string &payload);
 
		void handleBuddyRemovedPayload(const std::string &payload);
 
		void handleChatStatePayload(const std::string &payload, Swift::ChatState::ChatStateType type);
 
		void handleChatStatePayload(const std::string &payload, int type);
 
		void handleAttentionPayload(const std::string &payload);
 
		void handleFTStartPayload(const std::string &payload);
 
		void handleFTFinishPayload(const std::string &payload);
 
		void handleFTPausePayload(const std::string &payload);
 
		void handleFTContinuePayload(const std::string &payload);
 
		void _handleConnected(bool error);
 
		void handleDisconnected();
 

	
 
		void send(const std::string &data);
 
		void sendPong();
 
		void sendMemoryUsage();
 
		void pingTimeout();
 

	
 
		Swift::SafeByteArray m_data;
 
		std::string m_host;
 
		int m_port;
 
		Swift::BoostNetworkFactories *m_factories;
 
		Swift::BoostIOServiceThread m_boostIOServiceThread;
 
		boost::shared_ptr<Swift::Connection> m_conn;
 
		Swift::EventLoop *m_loop;
 
		Swift::Timer::ref m_pingTimer;
 

	
 
		std::string m_data;
 
		bool m_pingReceived;
 
		double m_init_res;
 

	
include/transport/protocol.proto
Show inline comments
 
new file 100644
 
package pbnetwork;
 

	
 
enum StatusType {
 
	STATUS_ONLINE		= 0;
 
	STATUS_AWAY			= 1;
 
	STATUS_FFC			= 2;
 
	STATUS_XA			= 3;
 
	STATUS_DND			= 4;
 
	STATUS_NONE			= 5;
 
	STATUS_INVISIBLE	= 6;
 
}
 

	
 
message Connected {
 
	required string user = 1;
 
}
 

	
 
message Disconnected {
 
	required string user = 1;
 
	required int32 error = 2;
 
	optional string message = 3;
 
}
 

	
 
message Login {
 
	required string user = 1;
 
	required string legacyName = 2;
 
	required string password = 3;
 
}
 

	
 
message Logout {
 
	required string user = 1;
 
	required string legacyName = 2;
 
}
 

	
 
message Buddy {
 
	required string userName = 1;
 
	required string buddyName = 2;
 
	optional string alias = 3;
 
	optional string groups = 4;
 
	optional StatusType status = 5;
 
	optional string statusMessage = 6;
 
	optional string iconHash = 7;
 
	optional bool blocked = 8;
 
}
 

	
 
message ConversationMessage {
 
	required string userName = 1;
 
	required string buddyName = 2;
 
	required string message = 3;
 
	optional string nickname = 4;
 
	optional string xhtml = 5;
 
}
 

	
 
message Room {
 
	required string userName = 1;
 
	required string nickname = 2;
 
	required string room = 3;
 
	optional string password = 4;
 
}
 

	
 
message Participant {
 
	required string userName = 1;
 
	required string room = 2;
 
	required string nickname = 3;
 
	required int32 flag = 4;
 
	required StatusType status = 5;
 
	optional string statusMessage = 6;
 
	optional string newname = 7;
 
}
 

	
 
message VCard {
 
	required string userName = 1;
 
	required string buddyName = 2;
 
	required int32 id = 3;
 
	optional string fullname = 4;
 
	optional string nickname = 5;
 
	optional bytes photo = 6;
 
}
 

	
 
message Status {
 
	required string userName = 1;
 
	required StatusType status = 3;
 
	optional string statusMessage = 4;
 
}
 

	
 
message Stats {
 
	required int32 res = 1;
 
	required int32 init_res = 2;
 
	required int32 shared = 3;
 
}
 

	
 
message File {
 
	required string userName = 1;
 
	required string buddyName = 2;
 
	required string fileName = 3;
 
	required int32 size = 4;
 
	optional int32 ftID = 5;
 
}
 

	
 
message FileTransferData {
 
	required int32 ftID = 1;
 
	required bytes data = 2;
 
}
 

	
 
message WrapperMessage {
 
	enum Type { 
 
		TYPE_CONNECTED 				= 1;
 
		TYPE_DISCONNECTED 			= 2;
 
		TYPE_LOGIN 					= 3;
 
		TYPE_LOGOUT 				= 4;
 
		TYPE_BUDDY_CHANGED			= 6;
 
		TYPE_BUDDY_REMOVED			= 7;
 
		TYPE_CONV_MESSAGE			= 8;
 
		TYPE_PING					= 9;
 
		TYPE_PONG					= 10;
 
		TYPE_JOIN_ROOM				= 11;
 
		TYPE_LEAVE_ROOM				= 12;
 
		TYPE_PARTICIPANT_CHANGED	= 13;
 
		TYPE_ROOM_NICKNAME_CHANGED	= 14;
 
		TYPE_ROOM_SUBJECT_CHANGED	= 15;
 
		TYPE_VCARD					= 16;
 
		TYPE_STATUS_CHANGED			= 17;
 
		TYPE_BUDDY_TYPING			= 18;
 
		TYPE_BUDDY_STOPPED_TYPING	= 19;
 
		TYPE_BUDDY_TYPED			= 20;
 
		TYPE_AUTH_REQUEST			= 21;
 
		TYPE_ATTENTION				= 22;
 
		TYPE_STATS					= 23;
 
		TYPE_FT_START				= 24;
 
		TYPE_FT_FINISH				= 25;
 
		TYPE_FT_DATA				= 26;
 
		TYPE_FT_PAUSE				= 27;
 
		TYPE_FT_CONTINUE			= 28;
 
		TYPE_EXIT					= 29;
 
	}
 
	required Type type = 1;
 
	optional bytes payload = 2;
 
}
 
;
 
\ No newline at end of file
include/transport/storagebackend.h
Show inline comments
 
@@ -22,6 +22,10 @@
 

	
 
#include <string>
 
#include <map>
 
#include <list>
 
#include <vector>
 
#include <boost/bind.hpp>
 
// #include <boost/signal.hpp>
 

	
 
namespace Transport {
 

	
 
@@ -115,7 +119,7 @@ class StorageBackend
 
		virtual void commitTransaction() = 0;
 

	
 
		/// onStorageError
 
		boost::signal<void (const std::string &statement, const std::string &error)> onStorageError;
 
// 		boost::signal<void (const std::string &statement, const std::string &error)> onStorageError;
 

	
 
};
 

	
plugin/src/networkplugin.cpp
Show inline comments
 
file renamed from src/networkplugin.cpp to plugin/src/networkplugin.cpp
 
@@ -19,19 +19,11 @@
 
 */
 

	
 
#include "transport/networkplugin.h"
 
#include "transport/user.h"
 
#include "transport/transport.h"
 
#include "transport/storagebackend.h"
 
#include "transport/rostermanager.h"
 
#include "transport/usermanager.h"
 
#include "transport/conversationmanager.h"
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Elements/StreamError.h"
 
#include "pbnetwork.pb.h"
 
#include "log4cxx/logger.h"
 
#include "log4cxx/basicconfigurator.h"
 
#include "memoryusage.h"
 
#include "transport/memoryusage.h"
 

	
 
#include <arpa/inet.h>
 

	
 
using namespace log4cxx;
 

	
 
@@ -44,21 +36,8 @@ namespace Transport {
 
	wrap.set_payload(MESSAGE); \
 
	wrap.SerializeToString(&MESSAGE);
 

	
 
NetworkPlugin::NetworkPlugin(Swift::EventLoop *loop, const std::string &host, int port) {
 
// 	m_factories = new Swift::BoostNetworkFactories(loop);
 
	m_host = host;
 
	m_port = port;
 
NetworkPlugin::NetworkPlugin() {
 
	m_pingReceived = false;
 
	m_loop = loop;
 
// 	m_conn = m_factories->getConnectionFactory()->createConnection();
 
// 	m_conn->onDataRead.connect(boost::bind(&NetworkPlugin::handleDataRead, this, _1));
 
// 	m_conn->onDataWritten.connect(boost::bind(&NetworkPlugin::readyForData, this));
 
// 	m_conn->onConnectFinished.connect(boost::bind(&NetworkPlugin::_handleConnected, this, _1));
 
// 	m_conn->onDisconnected.connect(boost::bind(&NetworkPlugin::handleDisconnected, this));
 

	
 
// 	m_pingTimer = m_factories->getTimerFactory()->createTimer(30000);
 
// 	m_pingTimer->onTick.connect(boost::bind(&NetworkPlugin::pingTimeout, this)); 
 
	connect();
 

	
 
	double shared;
 
#ifndef WIN32
 
@@ -67,7 +46,6 @@ NetworkPlugin::NetworkPlugin(Swift::EventLoop *loop, const std::string &host, in
 
}
 

	
 
NetworkPlugin::~NetworkPlugin() {
 
	delete m_factories;
 
}
 

	
 
void NetworkPlugin::handleMessage(const std::string &user, const std::string &legacyName, const std::string &msg, const std::string &nickname, const std::string &xhtml) {
 
@@ -133,7 +111,7 @@ void NetworkPlugin::handleSubject(const std::string &user, const std::string &le
 
}
 

	
 
void NetworkPlugin::handleBuddyChanged(const std::string &user, const std::string &buddyName, const std::string &alias,
 
			const std::string &groups, Swift::StatusShow::Type status, const std::string &statusMessage, const std::string &iconHash, bool blocked) {
 
			const std::string &groups, pbnetwork::StatusType status, const std::string &statusMessage, const std::string &iconHash, bool blocked) {
 
	pbnetwork::Buddy buddy;
 
	buddy.set_username(user);
 
	buddy.set_buddyname(buddyName);
 
@@ -205,7 +183,6 @@ void NetworkPlugin::handleAuthorization(const std::string &user, const std::stri
 
}
 

	
 
void NetworkPlugin::handleConnected(const std::string &user) {
 
	std::cout << "LOGIN SENT\n";
 
	pbnetwork::Connected d;
 
	d.set_user(user);
 

	
 
@@ -231,7 +208,7 @@ void NetworkPlugin::handleDisconnected(const std::string &user, int error, const
 
	send(message);
 
}
 

	
 
void NetworkPlugin::handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, Conversation::ParticipantFlag flags, Swift::StatusShow::Type status, const std::string &statusMessage, const std::string &newname) {
 
void NetworkPlugin::handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, int flags, pbnetwork::StatusType status, const std::string &statusMessage, const std::string &newname) {
 
	pbnetwork::Participant d;
 
	d.set_username(user);
 
	d.set_nickname(nickname);
 
@@ -310,29 +287,6 @@ void NetworkPlugin::handleFTData(unsigned long ftID, const std::string &data) {
 
	send(message);
 
}
 

	
 
void NetworkPlugin::_handleConnected(bool error) {
 
	if (error) {
 
// 		LOG4CXX_ERROR(logger, "Connecting error. Exiting");
 
// 		m_pingTimer->stop();
 
		handleExit();
 
	}
 
	else {
 
// 		LOG4CXX_INFO(logger, "Connected to NetworkPluginServer");
 
// 		m_pingTimer->start();
 
	}
 
}
 

	
 
void NetworkPlugin::handleDisconnected() {
 
// 	LOG4CXX_INFO(logger, "Disconnected from NetworkPluginServer. Exiting.");
 
// 	m_pingTimer->stop();
 
	handleExit();
 
}
 

	
 
void NetworkPlugin::connect() {
 
	LOG4CXX_INFO(logger, "Connecting NetworkPluginServer host " << m_host << " port " << m_port);
 
// 	m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(m_host), m_port));
 
}
 

	
 
void NetworkPlugin::handleLoginPayload(const std::string &data) {
 
	pbnetwork::Login payload;
 
	if (payload.ParseFromString(data) == false) {
 
@@ -480,7 +434,7 @@ void NetworkPlugin::handleBuddyRemovedPayload(const std::string &data) {
 
	handleBuddyRemovedRequest(payload.username(), payload.buddyname(), payload.groups());
 
}
 

	
 
void NetworkPlugin::handleChatStatePayload(const std::string &data, Swift::ChatState::ChatStateType type) {
 
void NetworkPlugin::handleChatStatePayload(const std::string &data, int type) {
 
	pbnetwork::Buddy payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
@@ -488,13 +442,13 @@ void NetworkPlugin::handleChatStatePayload(const std::string &data, Swift::ChatS
 
	}
 

	
 
	switch(type) {
 
		case Swift::ChatState::Composing:
 
		case pbnetwork::WrapperMessage_Type_TYPE_BUDDY_TYPING:
 
			handleTypingRequest(payload.username(), payload.buddyname());
 
			break;
 
		case Swift::ChatState::Paused:
 
		case pbnetwork::WrapperMessage_Type_TYPE_BUDDY_TYPED:
 
			handleTypedRequest(payload.username(), payload.buddyname());
 
			break;
 
		case Swift::ChatState::Active:
 
		case pbnetwork::WrapperMessage_Type_TYPE_BUDDY_STOPPED_TYPING:
 
			handleStoppedTypingRequest(payload.username(), payload.buddyname());
 
			break;
 
		default:
 
@@ -502,7 +456,7 @@ void NetworkPlugin::handleChatStatePayload(const std::string &data, Swift::ChatS
 
	}
 
}
 

	
 
void NetworkPlugin::handleDataRead(Swift::SafeByteArray &data) {
 
void NetworkPlugin::handleDataRead(std::string &data) {
 
	m_data.insert(m_data.end(), data.begin(), data.end());
 

	
 
	while (m_data.size() != 0) {
 
@@ -558,13 +512,13 @@ void NetworkPlugin::handleDataRead(Swift::SafeByteArray &data) {
 
				handleStatusChangedPayload(wrapper.payload());
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_BUDDY_TYPING:
 
				handleChatStatePayload(wrapper.payload(), Swift::ChatState::Composing);
 
				handleChatStatePayload(wrapper.payload(), pbnetwork::WrapperMessage_Type_TYPE_BUDDY_TYPING);
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_BUDDY_TYPED:
 
				handleChatStatePayload(wrapper.payload(), Swift::ChatState::Paused);
 
				handleChatStatePayload(wrapper.payload(), pbnetwork::WrapperMessage_Type_TYPE_BUDDY_TYPED);
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_BUDDY_STOPPED_TYPING:
 
				handleChatStatePayload(wrapper.payload(), Swift::ChatState::Active);
 
				handleChatStatePayload(wrapper.payload(), pbnetwork::WrapperMessage_Type_TYPE_BUDDY_STOPPED_TYPING);
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_ATTENTION:
 
				handleAttentionPayload(wrapper.payload());
 
@@ -581,6 +535,9 @@ void NetworkPlugin::handleDataRead(Swift::SafeByteArray &data) {
 
			case pbnetwork::WrapperMessage_Type_TYPE_FT_CONTINUE:
 
				handleFTContinuePayload(wrapper.payload());
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_EXIT:
 
				handleExitRequest();
 
				break;
 
			default:
 
				return;
 
		}
 
@@ -625,13 +582,4 @@ void NetworkPlugin::sendMemoryUsage() {
 
	send(message);
 
}
 

	
 
void NetworkPlugin::pingTimeout() {
 
	if (m_pingReceived == false) {
 
// 		LOG4CXX_ERROR(logger, "No PING received for long time. Exiting");
 
		handleExit();
 
	}
 
	m_pingReceived = false;
 
// 	m_pingTimer->start();
 
}
 

	
 
}
plugin/src/pbnetwork.proto
Show inline comments
 
file renamed from src/pbnetwork.proto to plugin/src/pbnetwork.proto
src/CMakeLists.txt
Show inline comments
 
@@ -3,10 +3,6 @@ FILE(GLOB SRC *.cpp *.h)
 
FILE(GLOB_RECURSE SWIFTEN_SRC ../include/Swiften/*.cpp)
 
FILE(GLOB HEADERS ../include/transport/*.h)
 
 
if (PROTOBUF_FOUND)
 
	PROTOBUF_GENERATE_CPP(PROTOBUF_SRC PROTOBUF_HDRS "pbnetwork.proto")
 
endif()
 
 
if (CPPUNIT_FOUND)
 
	FILE(GLOB SRC_TEST tests/*.cpp)
 
 
@@ -19,7 +15,16 @@ include_directories(${POPT_INCLUDE_DIR})
 
 
# SOURCE_GROUP(headers FILES ${HEADERS})
 
 
ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC} ${PROTOBUF_SRC} ${PROTOBUF_HDRS})
 
 
 
 
if (PROTOBUF_FOUND)
 
	ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC} ../include/transport/protocol.pb.cc)
 
	ADD_DEPENDENCIES(transport pb)
 
else()
 
	ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC})
 
endif()
 
 
ADD_DEFINITIONS(-fPIC)
 
 
TARGET_LINK_LIBRARIES(transport ${Boost_LIBRARIES} ${SQLITE3_LIBRARIES} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} ${POPT_LIBRARY})
src/admininterface.cpp
Show inline comments
 
@@ -28,7 +28,7 @@
 
#include "transport/networkpluginserver.h"
 
#include "storageresponder.h"
 
#include "log4cxx/logger.h"
 
#include "memoryusage.h"
 
#include "transport/memoryusage.h"
 
#include <boost/foreach.hpp>
 

	
 
using namespace log4cxx;
src/logger.cpp
Show inline comments
 
@@ -43,7 +43,7 @@ Logger::~Logger(){
 
}
 

	
 
void Logger::setStorageBackend(StorageBackend *storage) {
 
	storage->onStorageError.connect(boost::bind(&Logger::handleStorageError, this, _1, _2));
 
// 	storage->onStorageError.connect(boost::bind(&Logger::handleStorageError, this, _1, _2));
 
}
 

	
 
void Logger::setUserRegistration(UserRegistration *userRegistration) {
src/memoryreadbytestream.cpp
Show inline comments
 
@@ -20,7 +20,6 @@
 

	
 
#include "transport/memoryreadbytestream.h"
 
#include "log4cxx/logger.h"
 
#include "memoryusage.h"
 
#include <boost/foreach.hpp>
 

	
 
using namespace log4cxx;
src/memoryusage.cpp
Show inline comments
 
@@ -18,7 +18,7 @@
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "memoryusage.h"
 
#include "transport/memoryusage.h"
 

	
 
#include <iostream>
 
#include <cstring>
src/networkpluginserver.cpp
Show inline comments
 
@@ -39,7 +39,7 @@
 
#include "Swiften/Elements/AttentionPayload.h"
 
#include "Swiften/Elements/XHTMLIMPayload.h"
 
#include "Swiften/Elements/InvisiblePayload.h"
 
#include "pbnetwork.pb.h"
 
#include "transport/protocol.pb.h"
 
#include "log4cxx/logger.h"
 

	
 
#include <Swiften/FileTransfer/ReadBytestream.h>
 
@@ -330,6 +330,13 @@ void NetworkPluginServer::handleSessionFinished(Backend *c) {
 
		(*it)->handleDisconnected("Internal Server Error, please reconnect.");
 
	}
 

	
 
	std::string message;
 
	pbnetwork::WrapperMessage wrap;
 
	wrap.set_type(pbnetwork::WrapperMessage_Type_TYPE_EXIT);
 
	wrap.SerializeToString(&message);
 

	
 
	send(c->connection, message);
 

	
 
	c->connection->onDisconnected.disconnect_all_slots();
 
	c->connection->onDataRead.disconnect_all_slots();
 
	c->connection->disconnect();
0 comments (0 inline, 0 general)