Changeset - e3b73ba020dd
[Not reviewed]
Merge
0 12 0
Vitaly Takmazov - 13 years ago 2013-02-04 10:27:09
vitalyster@gmail.com
Merge branch 'master' of https://github.com/hanzz/libtransport
11 files changed with 147 insertions and 13 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -1092,25 +1092,25 @@ static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotif
 
		vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
 
		if (purple_notify_user_info_entry_get_label_wrapped(vcardEntry) && purple_notify_user_info_entry_get_value_wrapped(vcardEntry)){
 
			label = purple_notify_user_info_entry_get_label_wrapped(vcardEntry);
 
			if (label == "Given Name" || label == "First Name") {
 
				firstName = purple_notify_user_info_entry_get_value_wrapped(vcardEntry);
 
			}
 
			else if (label == "Family Name" || label == "Last Name") {
 
				lastName = purple_notify_user_info_entry_get_value_wrapped(vcardEntry);
 
			}
 
			else if (label=="Nickname" || label == "Nick") {
 
				nickname = purple_notify_user_info_entry_get_value_wrapped(vcardEntry);
 
			}
 
			else if (label=="Full Name") {
 
			else if (label=="Full Name" || label == "Display name") {
 
				fullName = purple_notify_user_info_entry_get_value_wrapped(vcardEntry);
 
			}
 
			else {
 
				LOG4CXX_WARN(logger, "Unhandled VCard Label '" << purple_notify_user_info_entry_get_label_wrapped(vcardEntry) << "' " << purple_notify_user_info_entry_get_value_wrapped(vcardEntry));
 
			}
 
		}
 
		vcardEntries = vcardEntries->next;
 
	}
 

	
 
	if ((!firstName.empty() || !lastName.empty()) && fullName.empty())
 
		fullName = firstName + " " + lastName;
 

	
backends/skype/main.cpp
Show inline comments
 
@@ -13,42 +13,72 @@
 
#include "transport/rostermanager.h"
 
#include "transport/conversation.h"
 
#include "transport/networkplugin.h"
 
#include <boost/filesystem.hpp>
 
#include "sys/wait.h"
 
#include "sys/signal.h"
 
// #include "valgrind/memcheck.h"
 
#ifndef __FreeBSD__
 
#include "malloc.h"
 
#endif
 
#include <dbus-1.0/dbus/dbus-glib-lowlevel.h>
 

	
 
#include "sqlite3.h"
 

	
 

	
 
DEFINE_LOGGER(logger, "backend");
 

	
 
using namespace Transport;
 

	
 
class SpectrumNetworkPlugin;
 

	
 
#define GET_RESPONSE_DATA(RESP, DATA) ((RESP.find(std::string(DATA) + " ") != std::string::npos) ? RESP.substr(RESP.find(DATA) + strlen(DATA) + 1) : "");
 
#define GET_PROPERTY(VAR, OBJ, WHICH, PROP) std::string VAR = sk->send_command(std::string("GET ") + OBJ + " " + WHICH + " " + PROP); \
 
					try {\
 
						VAR = GET_RESPONSE_DATA(VAR, PROP);\
 
					}\
 
					catch (std::out_of_range& oor) {\
 
						VAR="";\
 
					}
 
					
 

	
 
					
 
// Prepare the SQL statement
 
#define PREP_STMT(sql, str) \
 
	if(sqlite3_prepare_v2(db, std::string(str).c_str(), -1, &sql, NULL)) { \
 
		LOG4CXX_ERROR(logger, str<< (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db))); \
 
		sql = NULL; \
 
	}
 

	
 
// Finalize the prepared statement
 
#define FINALIZE_STMT(prep) \
 
	if(prep != NULL) { \
 
		sqlite3_finalize(prep); \
 
	}
 
	
 
#define BEGIN(STATEMENT) 	sqlite3_reset(STATEMENT);\
 
							int STATEMENT##_id = 1;\
 
							int STATEMENT##_id_get = 0;\
 
							(void)STATEMENT##_id_get;
 

	
 
#define BIND_INT(STATEMENT, VARIABLE) sqlite3_bind_int(STATEMENT, STATEMENT##_id++, VARIABLE)
 
#define BIND_STR(STATEMENT, VARIABLE) sqlite3_bind_text(STATEMENT, STATEMENT##_id++, VARIABLE.c_str(), -1, SQLITE_STATIC)
 
#define RESET_GET_COUNTER(STATEMENT)	STATEMENT##_id_get = 0;
 
#define GET_INT(STATEMENT)	sqlite3_column_int(STATEMENT, STATEMENT##_id_get++)
 
#define GET_STR(STATEMENT)	(const char *) sqlite3_column_text(STATEMENT, STATEMENT##_id_get++)
 
#define GET_BLOB(STATEMENT)	(const void *) sqlite3_column_blob(STATEMENT, STATEMENT##_id_get++)
 
#define EXECUTE_STATEMENT(STATEMENT, NAME) 	if(sqlite3_step(STATEMENT) != SQLITE_DONE) {\
 
		LOG4CXX_ERROR(logger, NAME<< (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db)));\
 
			}
 

	
 
SpectrumNetworkPlugin *np;
 

	
 
int m_sock;
 
static int writeInput;
 

	
 
static std::string host;
 
static int port = 10000;
 

	
 
DBusHandlerResult skype_notify_handler(DBusConnection *connection, DBusMessage *message, gpointer user_data);
 

	
 
static pbnetwork::StatusType getStatus(const std::string &st) {
 
	pbnetwork::StatusType status = pbnetwork::STATUS_ONLINE;
 
@@ -91,24 +121,25 @@ class Skype {
 
		}
 

	
 
	private:
 
		std::string m_username;
 
		std::string m_password;
 
		GPid m_pid;
 
		DBusGConnection *m_connection;
 
		DBusGProxy *m_proxy;
 
		std::string m_user;
 
		int m_timer;
 
		int m_counter;
 
		int fd_output;
 
		std::map<std::string, std::string> m_groups;
 
};
 

	
 
class SpectrumNetworkPlugin : public NetworkPlugin {
 
	public:
 
		SpectrumNetworkPlugin(Config *config, const std::string &host, int port) : NetworkPlugin() {
 
			this->config = config;
 
			LOG4CXX_INFO(logger, "Starting the backend.");
 
		}
 

	
 
		~SpectrumNetworkPlugin() {
 
			for (std::map<Skype *, std::string>::iterator it = m_accounts.begin(); it != m_accounts.end(); it++) {
 
				delete (*it).first;
 
@@ -268,24 +299,60 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
										image_data_len = img_end - img_start + 2;
 
										photo = std::string(img_start, image_data_len);
 
									}
 
								}
 
							}
 
						}
 
						g_free(image_data);
 
					}
 
					g_free(filename);
 
				}
 
				g_free(username);
 

	
 
				if (photo.empty()) {
 
					sqlite3 *db;
 
					std::string db_path = std::string("/tmp/skype/") + skype->getUsername() + "/" + skype->getUsername() + "/main.db";
 
					LOG4CXX_INFO(logger, "Opening database " << db_path);
 
					if (sqlite3_open(db_path.c_str(), &db)) {
 
						sqlite3_close(db);
 
						LOG4CXX_ERROR(logger, "Can't open database");
 
					}
 
					else {
 
						sqlite3_stmt *stmt;
 
						PREP_STMT(stmt, "SELECT avatar_image FROM Contacts WHERE skypename=?");
 
						if (stmt) {
 
							BEGIN(stmt);
 
							BIND_STR(stmt, name);
 
							if(sqlite3_step(stmt) == SQLITE_ROW) {
 
								int size = sqlite3_column_bytes(stmt, 0);
 
								const void *data = sqlite3_column_blob(stmt, 0);
 
								photo = std::string((const char *)data + 1, size - 1);
 
							}
 
							else {
 
								LOG4CXX_ERROR(logger, (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db)));
 
							}
 

	
 
							int ret;
 
							while((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
 
							}
 
							FINALIZE_STMT(stmt);
 
						}
 
						else {
 
							LOG4CXX_ERROR(logger, "Can't created prepared statement");
 
							LOG4CXX_ERROR(logger, (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db)));
 
						}
 
						sqlite3_close(db);
 
					}
 
				}
 

	
 
				std::string alias = "";
 
				std::cout << skype->getUsername() << " " << name << "\n";
 
				if (skype->getUsername() == name) {
 
					alias = skype->send_command("GET PROFILE FULLNAME");
 
					alias = GET_RESPONSE_DATA(alias, "FULLNAME")
 
				}
 
				handleVCard(user, id, legacyName, "", alias, photo);
 
			}
 
		}
 

	
 
		void sendData(const std::string &string) {
 
			write(m_sock, string.c_str(), string.size());
 
@@ -693,24 +760,73 @@ static void handle_skype_message(std::string &message, Skype *sk) {
 
			GET_PROPERTY(alias, "USER", cmd[1], "FULLNAME");
 
			GET_PROPERTY(mood_text, "USER", cmd[1], "MOOD_TEXT");
 
			GET_PROPERTY(st, "USER", cmd[1], "ONLINESTATUS");
 
			pbnetwork::StatusType status = getStatus(st);
 

	
 
			std::vector<std::string> groups;
 
			np->handleBuddyChanged(sk->getUser(), cmd[1], alias, groups, status, mood_text);
 
		}
 
		else if(cmd[2] == "RECEIVEDAUTHREQUEST") {
 
			np->handleAuthorization(sk->getUser(), cmd[1]);
 
		}
 
	}
 
	else if (cmd[0] == "GROUP") {
 
// 		if (cmd[2] == "DISPLAYNAME") {
 
// 			//GROUP 810 DISPLAYNAME My Friends
 
// 			std::string grp = GET_RESPONSE_DATA(message, "DISPLAYNAME");
 
// 			std::string users = sk->send_command("GET GROUP " + cmd[1] + " USERS");
 
// 			try {
 
// 				users = GET_RESPONSE_DATA(users, "USERS");
 
// 			}
 
// 			catch (std::out_of_range& oor) {
 
// 				return;
 
// 			}
 
// 
 
// 			std::vector<std::string> data;
 
// 			boost::split(data, users, boost::is_any_of(","));
 
// 			BOOST_FOREACH(std::string u, data) {
 
// 				GET_PROPERTY(alias, "USER", u, "FULLNAME");
 
// 				GET_PROPERTY(mood_text, "USER", u, "MOOD_TEXT");
 
// 				GET_PROPERTY(st, "USER", u, "ONLINESTATUS");
 
// 				pbnetwork::StatusType status = getStatus(st);
 
// 
 
// 				std::vector<std::string> groups;
 
// 				groups.push_back(grp);
 
// 				np->handleBuddyChanged(sk->getUser(), u, alias, groups, status, mood_text);
 
// 			}
 
// 		}
 
		if (cmd[2] == "NROFUSERS" && cmd[3] != "0") {
 
			GET_PROPERTY(grp, "GROUP", cmd[1], "DISPLAYNAME");
 
			std::string users = sk->send_command("GET GROUP " + cmd[1] + " USERS");
 
			try {
 
				users = GET_RESPONSE_DATA(users, "USERS");
 
			}
 
			catch (std::out_of_range& oor) {
 
				return;
 
			}
 

	
 
			std::vector<std::string> data;
 
			boost::split(data, users, boost::is_any_of(","));
 
			BOOST_FOREACH(std::string u, data) {
 
				GET_PROPERTY(alias, "USER", u, "FULLNAME");
 
				GET_PROPERTY(mood_text, "USER", u, "MOOD_TEXT");
 
				GET_PROPERTY(st, "USER", u, "ONLINESTATUS");
 
				pbnetwork::StatusType status = getStatus(st);
 

	
 
				std::vector<std::string> groups;
 
				groups.push_back(grp);
 
				np->handleBuddyChanged(sk->getUser(), u, alias, groups, status, mood_text);
 
			}
 
		}
 
	}
 
	else if (cmd[0] == "CHATMESSAGE") {
 
		if (cmd[3] == "RECEIVED") {
 
			GET_PROPERTY(body, "CHATMESSAGE", cmd[1], "BODY");
 
			GET_PROPERTY(from_handle, "CHATMESSAGE", cmd[1], "FROM_HANDLE");
 

	
 
			if (from_handle == sk->getUsername())
 
				return;
 

	
 
			np->handleMessage(sk->getUser(), from_handle, body);
 

	
 
			sk->send_command("SET CHATMESSAGE " + cmd[1] + " SEEN");
 
		}
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -265,25 +265,25 @@ void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std:
 
														boost::bind(&TwitterPlugin::statusUpdateResponse, this, _1, _2)));
 
			} else {
 
				data = message.substr(message.find(":")+1); //Can parse better??:P
 
				tp->runAsThread(new DirectMessageRequest(userdb[user].sessions, user, buddy, data,
 
												 		 boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3, _4)));
 
			}
 
		}
 
		else handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
				                 "Unknown command! Type #help for a list of available commands.", userdb[user].twitterMode == CHATROOM ? adminNickName : "");
 
	} 
 

	
 
	else {	
 
		std::string buddy;
 
		std::string buddy = legacyName;
 
		if(userdb[user].twitterMode == CHATROOM) buddy = legacyName.substr(legacyName.find("/") + 1);
 
		if(legacyName != "twitter") {
 
			tp->runAsThread(new DirectMessageRequest(userdb[user].sessions, user, buddy, message,
 
												 boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3, _4)));
 
		}
 
	}
 
}
 

	
 
void TwitterPlugin::handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector<std::string> &groups) 
 
{
 
	if(userdb[user].connectionState != CONNECTED) {
 
		LOG4CXX_ERROR(logger, user << " is not connected to twitter!")
include/Swiften/Server/Server.cpp
Show inline comments
 
@@ -29,50 +29,57 @@
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Queries/IQRouter.h"
 
#include <iostream>
 

	
 

	
 
namespace Swift {
 

	
 
Server::Server(
 
		EventLoop* eventLoop,
 
		NetworkFactories* networkFactories,
 
		UserRegistry *userRegistry,
 
		const JID& jid,
 
		const std::string &address,
 
		int port) :
 
			userRegistry_(userRegistry),
 
			port_(port),
 
			eventLoop(eventLoop),
 
			networkFactories_(networkFactories),
 
			stopping(false),
 
			selfJID(jid),
 
			stanzaChannel_(){
 
			stanzaChannel_(),
 
			address_(address){
 
	stanzaChannel_ = new ServerStanzaChannel();
 
	iqRouter_ = new IQRouter(stanzaChannel_);
 
	tlsFactory = NULL;
 
	parserFactory_ = new PlatformXMLParserFactory();
 
}
 

	
 
Server::~Server() {
 
	stop();
 
	delete iqRouter_;
 
	delete stanzaChannel_;
 
	delete parserFactory_;
 
}
 

	
 
void Server::start() {
 
	if (serverFromClientConnectionServer) {
 
		return;
 
	}
 
	if (address_ == "0.0.0.0") {
 
		serverFromClientConnectionServer = networkFactories_->getConnectionServerFactory()->createConnectionServer(port_);
 
	}
 
	else {
 
		serverFromClientConnectionServer = networkFactories_->getConnectionServerFactory()->createConnectionServer(Swift::HostAddress(address_), port_);
 
	}
 
	serverFromClientConnectionServerSignalConnections.push_back(
 
		serverFromClientConnectionServer->onNewConnection.connect(
 
				boost::bind(&Server::handleNewClientConnection, this, _1)));
 
// 	serverFromClientConnectionServerSignalConnections.push_back(
 
// 		serverFromClientConnectionServer->onStopped.connect(
 
// 				boost::bind(&Server::handleClientConnectionServerStopped, this, _1)));
 

	
 
	serverFromClientConnectionServer->start();
 
}
 

	
 
void Server::stop() {
 
	if (stopping) {
include/Swiften/Server/Server.h
Show inline comments
 
@@ -26,25 +26,25 @@
 

	
 
namespace Swift {
 
	class ConnectionServer;
 
	class SessionTracer;
 
	class EventLoop;
 
	class NetworkFactories;
 
	class StanzaChannel;
 
	class IQRouter;
 
	class TLSServerContextFactory;
 

	
 
	class Server : public Entity {
 
		public:
 
			Server(EventLoop* eventLoop, NetworkFactories* networkFactories, UserRegistry *userRegistry, const JID& jid, int port);
 
			Server(EventLoop* eventLoop, NetworkFactories* networkFactories, UserRegistry *userRegistry, const JID& jid, const std::string &address, int port);
 
			~Server();
 

	
 
			void start();
 
			void stop();
 

	
 
			int getPort() const {
 
				return port_;
 
			}
 

	
 
			StanzaChannel* getStanzaChannel() const {
 
				return stanzaChannel_;
 
			}
 
@@ -77,14 +77,15 @@ namespace Swift {
 
			EventLoop* eventLoop;
 
			NetworkFactories* networkFactories_;
 
			bool stopping;
 
			boost::shared_ptr<ConnectionServer> serverFromClientConnectionServer;
 
			std::vector<boost::bsignals::connection> serverFromClientConnectionServerSignalConnections;
 
			std::list<boost::shared_ptr<ServerFromClientSession> > serverFromClientSessions;
 
			JID selfJID;
 
			StanzaChannel *stanzaChannel_;
 
			IQRouter *iqRouter_;
 
			TLSServerContextFactory *tlsFactory;
 
			CertificateWithKey::ref cert;
 
			PlatformXMLParserFactory *parserFactory_;
 
			std::string address_;
 
	};
 
}
munin/spectrum2_
Show inline comments
 
@@ -12,37 +12,35 @@
 
#     spectrum_online (how many users are online)
 
#     spectarm_contacts_registered
 
#     spectrum_contacts_online (same as above, only for the legacy network)
 
#     spectrum_messages (how many messages have been sent over this transport)
 
#     spectrum_memory (how much memory the transport consumes)
 
#
 
# Configuration:
 
#     You need to configure this plugin (just like any other plugin) in
 
#	     plugin-conf.d/munin-node.
 
#     You have to configure the plugin to run as user and group "spectrum".
 
#
 
#     By default, the plugin monitors all instances configured in a config-file
 
#     in /etc/spectrum. If you use a different directory, you can specify the
 
#     environment-variable "base". If you do not want to monitor all instances,
 
#     you can give an explicit listing of the corresponding configuration files
 
#     with the environment variable "cfgs".
 
#     in /etc/spectrum2/transports. If you do not want to monitor all instances,
 
#     you can give an explicit listing of the corresponding instances
 
#     with the environment variable "jids".
 
#     
 
#     Here is an example of a configuration. Note again that you can ommit both
 
#     env.cfgs and env.base:
 
#
 
#     [spectrum_*]
 
#     user spectrum
 
#     group spectrum
 
#     env.cfgs xmpp.example.com.cfg,irc.example.com.cfg
 
#     env.base /etc/spectrum
 
#     env.jids xmpp.example.com,irc.example.com
 
#
 
# Author:
 
#     Mathias Ertl <mati@fsinf.at>
 
# 
 
# Changelog:
 
#     2.0: Port to config_interface local socket
 
#     1.1: Suffixes that aggregate multiple values no longer show the individual
 
#     	values by default. This can be overridden by setting the "verbose"
 
#     	env-variable to any non-empty string.
 
#     1.0: Initial version
 
#
 
# [1] http://xmpp.org/extensions/xep-0039.html
 
@@ -85,24 +83,31 @@ memory""" )
 

	
 
import os, re
 

	
 
# filter forbidden characters for munin fieldnames
 
def handle_field( string ):
 
	for regexp in [ '^[^A-Za-z_]', '[^A-Za-z0-9_]' ]:
 
		string = re.compile( regexp ).sub( '_', string )
 
	return string
 

	
 
# get runtime variables
 
suffix = sys.argv[0].partition('_')[2]
 
verbose = os.environ.get( 'verbose' )
 

	
 
jids = []
 

	
 
base = os.environ.get( 'base', '/etc/spectrum' )
 
if 'jids' in os.environ.keys():
 
	jids = os.environ.get( 'jids' ).split(',')
 
else:
 
	proc = Popen(['spectrum2_manager', 'list'], stdout=PIPE, stderr=PIPE)
 
	out, err = proc.communicate()
 
	jids = out.split('\n')[:-1]
 

	
 
# set variables based on wildcard 
 
if suffix == 'uptime':
 
	stat = { 'uptime': None }
 
	title = "Uptime"
 
	vlabel = "days"
 
	info = ''
 
	transformer = lambda value: float(value)/60.0/60.0/24.0
 
elif suffix == 'backends_count':
spectrum/src/sample2.cfg
Show inline comments
 
@@ -5,25 +5,25 @@ server_mode = 1
 
# The name of user/group Spectrum runs as.
 
#user=spectrum
 
#group=spectrum
 

	
 
# JID of Spectrum instance.
 
jid = localhost
 

	
 
# Password used to connect the XMPP server in gateway mode.
 
# In server mode, this option is ignored.
 
password = secret
 

	
 
# XMPP server to which Spectrum connects in gateway mode.
 
# In server mode, this option is ignored.
 
# To bind to all ipv4 interfaces, use server=0.0.0.0
 
server = 127.0.0.1
 

	
 
# XMPP server port.
 
port = 5222
 

	
 
# Interface on which Spectrum listens for backends.
 
backend_host = localhost
 

	
 
# Port on which Spectrum listens for backends.
 
# By default Spectrum chooses random backend port and there's
 
# no need to change it normally
 
#backend_port=10001
src/networkpluginserver.cpp
Show inline comments
 
@@ -343,24 +343,28 @@ void NetworkPluginServer::start() {
 
		sleep(1);
 
		pid_t result;
 
		int status;
 
		result = waitpid(-1, &status, WNOHANG);
 
		if (result != 0) {
 
			if (WIFEXITED(status)) {
 
				if (WEXITSTATUS(status) != 0) {
 
					if (status == 254) {
 
						LOG4CXX_ERROR(logger, "Backend can not be started, because it needs database to store data, but the database backend is not configured.");
 
					}
 
					else {
 
						LOG4CXX_ERROR(logger, "Backend can not be started, exit_code=" << WEXITSTATUS(status) << ", possible error: " << strerror(WEXITSTATUS(status)));
 
						if (WEXITSTATUS(status) == ENOENT) {
 
							LOG4CXX_ERROR(logger, "This usually means the path to backend executable defined in config file as '[service] backend=\"...\"' is wrong or the executable does not exists.");
 
						}
 
						
 
					}
 
					LOG4CXX_ERROR(logger, "Check backend log for more details");
 
					continue;
 
				}
 
			}
 
			else {
 
				LOG4CXX_ERROR(logger, "Backend can not be started");
 
				continue;
 
			}
 
		}
 

	
 
		m_pids.push_back(pid);
src/sqlite3backend.cpp
Show inline comments
 
@@ -46,24 +46,25 @@
 
	}
 
	
 
#define BEGIN(STATEMENT) 	sqlite3_reset(STATEMENT);\
 
							int STATEMENT##_id = 1;\
 
							int STATEMENT##_id_get = 0;\
 
							(void)STATEMENT##_id_get;
 

	
 
#define BIND_INT(STATEMENT, VARIABLE) sqlite3_bind_int(STATEMENT, STATEMENT##_id++, VARIABLE)
 
#define BIND_STR(STATEMENT, VARIABLE) sqlite3_bind_text(STATEMENT, STATEMENT##_id++, VARIABLE.c_str(), -1, SQLITE_STATIC)
 
#define RESET_GET_COUNTER(STATEMENT)	STATEMENT##_id_get = 0;
 
#define GET_INT(STATEMENT)	sqlite3_column_int(STATEMENT, STATEMENT##_id_get++)
 
#define GET_STR(STATEMENT)	(const char *) sqlite3_column_text(STATEMENT, STATEMENT##_id_get++)
 
#define GET_BLOB(STATEMENT)	(const void *) sqlite3_column_blob(STATEMENT, STATEMENT##_id_get++)
 
#define EXECUTE_STATEMENT(STATEMENT, NAME) 	if(sqlite3_step(STATEMENT) != SQLITE_DONE) {\
 
		LOG4CXX_ERROR(logger, NAME<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));\
 
			}
 

	
 
using namespace boost;
 

	
 
namespace Transport {
 

	
 
DEFINE_LOGGER(logger, "SQLite3Backend");
 

	
 
SQLite3Backend::SQLite3Backend(Config *config) {
 
	m_config = config;
src/tests/userregistry.cpp
Show inline comments
 
@@ -27,25 +27,25 @@ class UserRegistryTest : public CPPUNIT_NS :: TestFixture {
 
			state2 = Init;
 
			std::istringstream ifs;
 
			cfg = new Config();
 
			cfg->load(ifs);
 

	
 
			loop = new Swift::DummyEventLoop();
 
			factories = new Swift::DummyNetworkFactories(loop);
 

	
 
			userRegistry = new UserRegistry(cfg, factories);
 
			userRegistry->onConnectUser.connect(bind(&UserRegistryTest::handleConnectUser, this, _1));
 
			userRegistry->onDisconnectUser.connect(bind(&UserRegistryTest::handleDisconnectUser, this, _1));
 

	
 
			server = new Swift::Server(loop, factories, userRegistry, "localhost", 5222);
 
			server = new Swift::Server(loop, factories, userRegistry, "localhost", "0.0.0.0", 5222);
 
			server->start();
 
			connectionServer = server->getConnectionServer();
 

	
 
			client1 = factories->getConnectionFactory()->createConnection();
 
			dynamic_cast<Swift::DummyConnectionServer *>(connectionServer.get())->acceptConnection(client1);
 

	
 
			dynamic_cast<Swift::DummyConnection *>(client1.get())->onDataSent.connect(boost::bind(&UserRegistryTest::handleDataReceived, this, _1, client1));
 

	
 
			client2 = factories->getConnectionFactory()->createConnection();
 
			dynamic_cast<Swift::DummyConnectionServer *>(connectionServer.get())->acceptConnection(client2);
 

	
 
			dynamic_cast<Swift::DummyConnection *>(client2.get())->onDataSent.connect(boost::bind(&UserRegistryTest::handleDataReceived, this, _1, client2));
src/transport.cpp
Show inline comments
 
@@ -71,25 +71,25 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
 
	m_loop = loop;
 
	m_userRegistry = userRegistry;
 

	
 
	m_jid = Swift::JID(CONFIG_STRING(m_config, "service.jid"));
 

	
 
	m_factories = factories;
 

	
 
	m_reconnectTimer = m_factories->getTimerFactory()->createTimer(3000);
 
	m_reconnectTimer->onTick.connect(bind(&Component::start, this)); 
 

	
 
	if (CONFIG_BOOL(m_config, "service.server_mode")) {
 
		LOG4CXX_INFO(logger, "Creating component in server mode on port " << CONFIG_INT(m_config, "service.port"));
 
		m_server = new Swift::Server(loop, m_factories, m_userRegistry, m_jid, CONFIG_INT(m_config, "service.port"));
 
		m_server = new Swift::Server(loop, m_factories, m_userRegistry, m_jid, CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port"));
 
		if (!CONFIG_STRING(m_config, "service.cert").empty()) {
 
#ifndef _WIN32
 
//TODO: fix
 
			LOG4CXX_INFO(logger, "Using PKCS#12 certificate " << CONFIG_STRING(m_config, "service.cert"));
 
			LOG4CXX_INFO(logger, "SSLv23_server_method used.");
 
			TLSServerContextFactory *f = new OpenSSLServerContextFactory();
 
			CertificateWithKey::ref certificate = boost::make_shared<PKCS12Certificate>(CONFIG_STRING(m_config, "service.cert"), createSafeByteArray(CONFIG_STRING(m_config, "service.cert_password")));
 
			m_server->addTLSEncryption(f, certificate);
 
#endif
 
			
 
		}
 
		else {
0 comments (0 inline, 0 general)