Changeset - 819c52172d94
CMakeLists.txt
Show inline comments
 
@@ -101,21 +101,22 @@ include_directories(include)
 

	
 

	
 
include_directories(${EVENT_INCLUDE_DIRS})
 
include_directories(${SWIFTEN_INCLUDE_DIR})
 
include_directories(${Boost_INCLUDE_DIRS})
 

	
 

	
 
ADD_SUBDIRECTORY(src)
 
ADD_SUBDIRECTORY(include)
 
ADD_SUBDIRECTORY(examples)
 
ADD_SUBDIRECTORY(spectrum)
 
ADD_SUBDIRECTORY(backends)
 
ADD_SUBDIRECTORY(tests)
 

	
 
if(DOXYGEN_FOUND)
 
	message("Docs              : yes")
 
	ADD_SUBDIRECTORY(docs)
 
else(DOXYGEN_FOUND)
 
	message("Docs              : no (install doxygen)")
 
endif(DOXYGEN_FOUND)
 

	
 
message("----------------------")
backends/libircclient-qt/session.cpp
Show inline comments
 
@@ -8,33 +8,35 @@
 
 * program, but you don't have to.
 
 */
 

	
 
#include "session.h"
 
#include <QtCore>
 
#include <iostream>
 
#include "Swiften/Elements/StatusShow.h"
 

	
 
MyIrcSession::MyIrcSession(const std::string &user, NetworkPlugin *np, QObject* parent) : Irc::Session(parent)
 
{
 
	this->np = np;
 
	this->user = user;
 
	connect(this, SIGNAL(disconnected()), SLOT(on_disconnected()));
 
}
 

	
 
void MyIrcSession::on_connected(){
 
	std::cout << "connected:\n";
 
}
 

	
 
void MyIrcSession::on_disconnected()
 
{
 
    std::cout << "disconnected:\n";
 
    np->handleDisconnected(user, "", 0, "");
 
}
 

	
 
void MyIrcSession::on_bufferAdded(Irc::Buffer* buffer)
 
{
 
    qDebug() << "buffer added:" << buffer->receiver();
 
}
 

	
 
void MyIrcSession::on_bufferRemoved(Irc::Buffer* buffer)
 
{
 
    qDebug() << "buffer removed:" << buffer->receiver();
 
}
 

	
backends/libpurple/main.cpp
Show inline comments
 
@@ -109,32 +109,44 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, legacyName.c_str(), account);
 
				if (!conv) {
 
					conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, legacyName.c_str());
 
				}
 
				gchar *_markup = purple_markup_escape_text(message.c_str(), -1);
 
				purple_conv_im_send(PURPLE_CONV_IM(conv), _markup);
 
				g_free(_markup);
 
			}
 
		}
 

	
 
		virtual void handleVCardRequest(const std::string &user, const std::string &legacyName, unsigned int id) {
 
		void handleVCardRequest(const std::string &user, const std::string &legacyName, unsigned int id) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				serv_get_info(purple_account_get_connection(account), legacyName.c_str());
 
				m_vcards[user + legacyName] = id;
 
			}
 
		}
 

	
 
		void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::string &groups) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				PurpleBuddy *buddy = purple_find_buddy(account, buddyName.c_str());
 
				if (buddy) {
 
					purple_blist_alias_buddy(buddy, alias.c_str());
 
					purple_blist_server_alias_buddy(buddy, alias.c_str());
 
					serv_alias_buddy(buddy);
 
				}
 
			}
 
		}
 

	
 
		std::map<std::string, PurpleAccount *> m_sessions;
 
		std::map<PurpleAccount *, std::string> m_accounts;
 
		std::map<std::string, unsigned int> m_vcards;
 
	private:
 
		Config *config;
 
};
 

	
 
static std::string getAlias(PurpleBuddy *m_buddy) {
 
	std::string alias;
 
	if (purple_buddy_get_server_alias(m_buddy))
 
		alias = (std::string) purple_buddy_get_server_alias(m_buddy);
 
	else
 
@@ -470,24 +482,27 @@ static PurpleCoreUiOps coreUiOps =
 
	NULL,
 
// 	debug_init,
 
	NULL,
 
	transport_core_ui_init,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
static void signed_on(PurpleConnection *gc, gpointer unused) {
 
	for (int i = 0; i<1500; i++) {
 
		std::cout << "A\n";
 
	}
 
	PurpleAccount *account = purple_connection_get_account(gc);
 
	np->handleConnected(np->m_accounts[account]);
 
}
 

	
 
static void printDebug(PurpleDebugLevel level, const char *category, const char *arg_s) {
 
	std::string c("[LIBPURPLE");
 

	
 
	if (category) {
 
		c.push_back('/');
 
		c.append(category);
 
	}
 

	
include/transport/networkplugin.h
Show inline comments
 
@@ -55,34 +55,36 @@ class NetworkPlugin {
 
		void handleSubject(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "");
 

	
 
		void handleRoomChanged(const std::string &user, const std::string &room, const std::string &nickname);
 

	
 
		void handleVCard(const std::string &user, unsigned int id, const std::string &legacyName, const std::string &fullName, const std::string &nickname, const std::string &photo);
 

	
 
		virtual void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) = 0;
 
		virtual void handleLogoutRequest(const std::string &user, const std::string &legacyName) = 0;
 
		virtual void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message) = 0;
 
		virtual void handleVCardRequest(const std::string &/*user*/, const std::string &/*legacyName*/, unsigned int /*id*/) {}
 
		virtual void handleJoinRoomRequest(const std::string &/*user*/, const std::string &/*room*/, const std::string &/*nickname*/, const std::string &/*pasword*/) {}
 
		virtual void handleLeaveRoomRequest(const std::string &/*user*/, const std::string &/*room*/) {}
 
		virtual void handleBuddyUpdatedRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*alias*/, const std::string &/*groups*/) {}
 
		
 

	
 
	private:
 
		void connect();
 
		void handleLoginPayload(const std::string &payload);
 
		void handleLogoutPayload(const std::string &payload);
 
		void handleConvMessagePayload(const std::string &payload);
 
		void handleJoinRoomPayload(const std::string &payload);
 
		void handleLeaveRoomPayload(const std::string &payload);
 
		void handleVCardPayload(const std::string &payload);
 
		void handleBuddyChangedPayload(const std::string &payload);
 
		void handleDataRead(const Swift::SafeByteArray&);
 
		void _handleConnected(bool error);
 
		void handleDisconnected();
 

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

	
 
		Swift::SafeByteArray m_data;
 
		std::string m_host;
 
		int m_port;
 
		Swift::BoostNetworkFactories *m_factories;
include/transport/networkpluginserver.h
Show inline comments
 
@@ -65,24 +65,28 @@ class NetworkPluginServer {
 
		void handleBuddyChangedPayload(const std::string &payload);
 
		void handleConvMessagePayload(const std::string &payload, bool subject = false);
 
		void handleParticipantChangedPayload(const std::string &payload);
 
		void handleRoomChangedPayload(const std::string &payload);
 
		void handleVCardPayload(const std::string &payload);
 

	
 
		void handleUserCreated(User *user);
 
		void handleRoomJoined(User *user, const std::string &room, const std::string &nickname, const std::string &password);
 
		void handleRoomLeft(User *user, const std::string &room);
 
		void handleUserReadyToConnect(User *user);
 
		void handleUserDestroyed(User *user);
 

	
 
		void handleBuddyUpdated(Buddy *buddy, const Swift::RosterItemPayload &item);
 
		void handleBuddyRemoved(Buddy *buddy);
 
		void handleBuddyAdded(Buddy *buddy, const Swift::RosterItemPayload &item);
 

	
 
		void handleVCardRequired(User *user, const std::string &name, unsigned int id);
 

	
 
		void send(boost::shared_ptr<Swift::Connection> &, const std::string &data);
 

	
 
		void pingTimeout();
 
		void sendPing(Client *c);
 
		Client *getFreeClient();
 

	
 
		UserManager *m_userManager;
 
		VCardResponder *m_vcardResponder;
 
		RosterResponder *m_rosterResponder;
 
		Config *m_config;
include/transport/rostermanager.h
Show inline comments
 
@@ -51,24 +51,26 @@ class RosterManager {
 
		/// the buddy is added to server-side roster using remote-roster protoXEP).
 
		/// \param buddy Buddy
 
		void setBuddy(Buddy *buddy);
 

	
 
		/// Deassociates the buddy with this roster.
 
		/// \param buddy Buddy.
 
		void unsetBuddy(Buddy *buddy);
 

	
 
		Buddy *getBuddy(const std::string &name);
 

	
 
		void setStorageBackend(StorageBackend *storageBackend);
 

	
 
		void storeBuddy(Buddy *buddy);
 

	
 
		Swift::RosterPayload::ref generateRosterPayload();
 

	
 
		/// Returns user associated with this roster.
 
		/// \return User
 
		User *getUser() { return m_user; }
 

	
 
		/// Called when new Buddy is added to this roster.
 
		/// \param buddy newly added Buddy
 
		boost::signal<void (Buddy *buddy)> onBuddySet;
 

	
 
		/// Called when Buddy has been removed from this roster.
 
		/// \param buddy removed Buddy
include/transport/rosterresponder.h
Show inline comments
 
@@ -19,25 +19,32 @@
 
 */
 

	
 
#pragma once
 

	
 
#include <vector>
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Queries/Responder.h"
 
#include "Swiften/Elements/RosterPayload.h"
 

	
 
namespace Transport {
 

	
 
class UserManager;
 
class Buddy;
 

	
 
class RosterResponder : public Swift::Responder<Swift::RosterPayload> {
 
	public:
 
		RosterResponder(Swift::IQRouter *router, UserManager *userManager);
 
		~RosterResponder();
 

	
 
		boost::signal<void (Buddy *, const Swift::RosterItemPayload &item)> onBuddyUpdated;
 

	
 
		boost::signal<void (Buddy *)> onBuddyRemoved;
 

	
 
		boost::signal<void (Buddy *, const Swift::RosterItemPayload &item)> onBuddyAdded;
 

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

	
 
}
 
\ No newline at end of file
include/transport/transport.h
Show inline comments
 
@@ -22,24 +22,25 @@
 

	
 
#include <vector>
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Server/Server.h"
 
#include "Swiften/Disco/GetDiscoInfoRequest.h"
 
#include "Swiften/Disco/EntityCapsManager.h"
 
#include "Swiften/Disco/CapsManager.h"
 
#include "Swiften/Disco/CapsMemoryStorage.h"
 
#include "Swiften/Presence/PresenceOracle.h"
 
#include "Swiften/Network/BoostTimerFactory.h"
 
#include "Swiften/Network/BoostIOServiceThread.h"
 
#include "Swiften/Server/UserRegistry.h"
 
#include "Swiften/Base/SafeByteArray.h"
 
#include <boost/bind.hpp>
 
#include "transport/config.h"
 
#include "transport/factory.h"
 

	
 
#define tr(lang,STRING)    (STRING)
 
#define _(STRING)    (STRING)
 

	
 
namespace Transport {
 
	// typedef enum { 	CLIENT_FEATURE_ROSTERX = 2,
 
	// 				CLIENT_FEATURE_XHTML_IM = 4,
 
	// 				CLIENT_FEATURE_FILETRANSFER = 8,
 
	// 				CLIENT_FEATURE_CHATSTATES = 16
src/localbuddy.cpp
Show inline comments
 
@@ -15,18 +15,19 @@
 
 *
 
 * 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/localbuddy.h"
 
#include "transport/user.h"
 

	
 
namespace Transport {
 

	
 
LocalBuddy::LocalBuddy(RosterManager *rosterManager, long id) : Buddy(rosterManager, id) {
 
	m_status = Swift::StatusShow::None;
 
}
 

	
 
LocalBuddy::~LocalBuddy() {
 
}
 

	
 
}
src/networkplugin.cpp
Show inline comments
 
@@ -256,26 +256,36 @@ void NetworkPlugin::handleLeaveRoomPayload(const std::string &data) {
 
}
 

	
 
void NetworkPlugin::handleVCardPayload(const std::string &data) {
 
	pbnetwork::VCard payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
		return;
 
	}
 

	
 
	handleVCardRequest(payload.username(), payload.buddyname(), payload.id());
 
}
 

	
 
void NetworkPlugin::handleBuddyChangedPayload(const std::string &data) {
 
	pbnetwork::Buddy payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
		return;
 
	}
 

	
 
	handleBuddyUpdatedRequest(payload.username(), payload.buddyname(), payload.alias(), payload.groups());
 
}
 

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

	
 
	while (m_data.size() != 0) {
 
		unsigned int expected_size;
 

	
 
		if (m_data.size() >= 4) {
 
			expected_size = *((unsigned int*) &m_data[0]);
 
			expected_size = ntohl(expected_size);
 
			if (m_data.size() - 4 < expected_size)
 
				return;
 
		}
 
		else {
 
			return;
 
@@ -301,24 +311,27 @@ void NetworkPlugin::handleDataRead(const Swift::SafeByteArray &data) {
 
			case pbnetwork::WrapperMessage_Type_TYPE_CONV_MESSAGE:
 
				handleConvMessagePayload(wrapper.payload());
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_JOIN_ROOM:
 
				handleJoinRoomPayload(wrapper.payload());
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_LEAVE_ROOM:
 
				handleLeaveRoomPayload(wrapper.payload());
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_VCARD:
 
				handleVCardPayload(wrapper.payload());
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_BUDDY_CHANGED:
 
				handleBuddyChangedPayload(wrapper.payload());
 
				break;
 
			default:
 
				return;
 
		}
 
	}
 
}
 

	
 
void NetworkPlugin::send(const std::string &data) {
 
	char header[4];
 
	*((int*)(header)) = htonl(data.size());
 
	m_conn->write(Swift::createSafeByteArray(std::string(header, 4) + data));
 
}
 

	
src/networkpluginserver.cpp
Show inline comments
 
@@ -81,25 +81,25 @@ class NetworkFactory : public Factory {
 
#define WRAP(MESSAGE, TYPE) 	pbnetwork::WrapperMessage wrap; \
 
	wrap.set_type(TYPE); \
 
	wrap.set_payload(MESSAGE); \
 
	wrap.SerializeToString(&MESSAGE);
 
	
 
static int exec_(const char *path, const char *host, const char *port, const char *config) {
 
// 	char *argv[] = {(char*)script_name, '\0'}; 
 
	int status = 0;
 
	pid_t pid = fork();
 
	if ( pid == 0 ) {
 
		// child process
 
		execlp(path, path, "--host", host, "--port", port, config, NULL);
 
		exit(1);
 
		abort();
 
	} else if ( pid < 0 ) {
 
		// fork failed
 
		status = -1;
 
	}
 
	return status;
 
}
 

	
 
static void SigCatcher(int n) {
 
	wait3(NULL,WNOHANG,NULL);
 
}
 

	
 
static void handleBuddyPayload(LocalBuddy *buddy, const pbnetwork::Buddy &payload) {
 
@@ -119,24 +119,27 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
 
	m_component->m_factory = new NetworkFactory(this);
 
	m_userManager->onUserCreated.connect(boost::bind(&NetworkPluginServer::handleUserCreated, this, _1));
 
	m_userManager->onUserDestroyed.connect(boost::bind(&NetworkPluginServer::handleUserDestroyed, this, _1));
 

	
 
	m_pingTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(10000);
 
	m_pingTimer->onTick.connect(boost::bind(&NetworkPluginServer::pingTimeout, this)); 
 

	
 
	m_vcardResponder = new VCardResponder(component->getIQRouter(), userManager);
 
	m_vcardResponder->onVCardRequired.connect(boost::bind(&NetworkPluginServer::handleVCardRequired, this, _1, _2, _3));
 
	m_vcardResponder->start();
 

	
 
	m_rosterResponder = new RosterResponder(component->getIQRouter(), userManager);
 
	m_rosterResponder->onBuddyAdded.connect(boost::bind(&NetworkPluginServer::handleBuddyAdded, this, _1, _2));
 
	m_rosterResponder->onBuddyRemoved.connect(boost::bind(&NetworkPluginServer::handleBuddyRemoved, this, _1));
 
	m_rosterResponder->onBuddyUpdated.connect(boost::bind(&NetworkPluginServer::handleBuddyUpdated, this, _1, _2));
 
	m_rosterResponder->start();
 

	
 
	m_server = component->getNetworkFactories()->getConnectionFactory()->createConnectionServer(10000);
 
	m_server->onNewConnection.connect(boost::bind(&NetworkPluginServer::handleNewClientConnection, this, _1));
 
	m_server->start();
 

	
 
	signal(SIGCHLD, SigCatcher);
 

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

	
 
NetworkPluginServer::~NetworkPluginServer() {
 
@@ -186,30 +189,30 @@ void NetworkPluginServer::handleConnectedPayload(const std::string &data) {
 
	std::cout << "CONNECTED LOGIN 3 " << payload.user() << "\n";
 
	m_component->m_userRegistry->onPasswordValid(payload.user());
 
// 	std::cout << payload.name() << "\n";
 
}
 

	
 
void NetworkPluginServer::handleDisconnectedPayload(const std::string &data) {
 
	pbnetwork::Disconnected payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
		return;
 
	}
 

	
 
	m_component->m_userRegistry->onPasswordInvalid(payload.user());
 

	
 
	User *user = m_userManager->getUser(payload.user());
 
	if (!user) {
 
		return;
 
	}
 

	
 
	m_component->m_userRegistry->onPasswordInvalid(payload.user());
 
	user->handleDisconnected(payload.message());
 
}
 

	
 
void NetworkPluginServer::handleVCardPayload(const std::string &data) {
 
	pbnetwork::VCard payload;
 
	if (payload.ParseFromString(data) == false) {
 
		std::cout << "PARSING ERROR\n";
 
		// TODO: ERROR
 
		return;
 
	}
 
	std::cout << "OMG?\n";
 
	boost::shared_ptr<Swift::VCard> vcard(new Swift::VCard());
 
@@ -313,43 +316,43 @@ void NetworkPluginServer::handleConvMessagePayload(const std::string &data, bool
 
	}
 

	
 
	NetworkConversation *conv = (NetworkConversation *) user->getConversationManager()->getConversation(payload.buddyname());
 
	if (!conv) {
 
		conv = new NetworkConversation(user->getConversationManager(), payload.buddyname());
 
		conv->onMessageToSend.connect(boost::bind(&NetworkPluginServer::handleMessageReceived, this, _1, _2));
 
	}
 

	
 
	conv->handleMessage(msg, payload.nickname());
 
}
 

	
 
void NetworkPluginServer::handleDataRead(Client *c, const Swift::SafeByteArray &data) {
 
	c->data.insert(c->data.begin(), data.begin(), data.end());
 

	
 
	c->data.insert(c->data.end(), data.begin(), data.end());
 
	while (c->data.size() != 0) {
 
		unsigned int expected_size;
 

	
 
		if (c->data.size() >= 4) {
 
			expected_size = *((unsigned int*) &c->data[0]);
 
			expected_size = ntohl(expected_size);
 
			if (c->data.size() - 4 < expected_size)
 
				return;
 
		}
 
		else {
 
			return;
 
		}
 

	
 
		pbnetwork::WrapperMessage wrapper;
 
		if (wrapper.ParseFromArray(&c->data[4], expected_size) == false) {
 
			std::cout << "PARSING ERROR " << expected_size << "\n";
 
			c->data.erase(c->data.begin(), c->data.begin() + 4 + expected_size);
 
			return;
 
			continue;
 
		}
 
		c->data.erase(c->data.begin(), c->data.begin() + 4 + expected_size);
 

	
 
		switch(wrapper.type()) {
 
			case pbnetwork::WrapperMessage_Type_TYPE_CONNECTED:
 
				handleConnectedPayload(wrapper.payload());
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_DISCONNECTED:
 
				handleDisconnectedPayload(wrapper.payload());
 
				break;
 
			case pbnetwork::WrapperMessage_Type_TYPE_BUDDY_CHANGED:
 
				handleBuddyChangedPayload(wrapper.payload());
 
@@ -390,24 +393,28 @@ void NetworkPluginServer::pingTimeout() {
 
		if ((*it)->pongReceived) {
 
			sendPing((*it));
 
			m_pingTimer->start();
 
		}
 
		else {
 
			exec_(CONFIG_STRING(m_config, "service.backend").c_str(), "localhost", "10000", m_config->getConfigFile().c_str());
 
		}
 
	}
 
}
 

	
 
void NetworkPluginServer::handleUserCreated(User *user) {
 
	Client *c = getFreeClient();
 
	if (!c) {
 
		user->handleDisconnected("Internal Server Error, please reconnect.");
 
		return;
 
	}
 
	user->setData(c);
 
	c->users.push_back(user);
 

	
 
// 	UserInfo userInfo = user->getUserInfo();
 
	user->onReadyToConnect.connect(boost::bind(&NetworkPluginServer::handleUserReadyToConnect, this, user));
 
	user->onRoomJoined.connect(boost::bind(&NetworkPluginServer::handleRoomJoined, this, user, _1, _2, _3));
 
	user->onRoomLeft.connect(boost::bind(&NetworkPluginServer::handleRoomLeft, this, user, _1));
 
}
 

	
 
void NetworkPluginServer::handleUserReadyToConnect(User *user) {
 
	UserInfo userInfo = user->getUserInfo();
 

	
 
@@ -504,24 +511,54 @@ void NetworkPluginServer::handleMessageReceived(NetworkConversation *conv, boost
 
	m.set_buddyname(conv->getLegacyName());
 
	m.set_message(msg->getBody());
 

	
 
	std::string message;
 
	m.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_CONV_MESSAGE);
 

	
 
	Client *c = (Client *) conv->getConversationManager()->getUser()->getData();
 
	send(c->connection, message);
 
}
 

	
 
void NetworkPluginServer::handleBuddyRemoved(Buddy *buddy) {
 
	
 
}
 

	
 
void NetworkPluginServer::handleBuddyUpdated(Buddy *b, const Swift::RosterItemPayload &item) {
 
	User *user = b->getRosterManager()->getUser();
 

	
 
	dynamic_cast<LocalBuddy *>(b)->setAlias(item.getName());
 
	user->getRosterManager()->storeBuddy(b);
 

	
 
	pbnetwork::Buddy buddy;
 
	buddy.set_username(user->getJID().toBare());
 
	buddy.set_buddyname(b->getName());
 
	buddy.set_alias(b->getAlias());
 
	buddy.set_groups(b->getGroups().size() == 0 ? "" : b->getGroups()[0]);
 
	buddy.set_status(Swift::StatusShow::None);
 

	
 
	std::string message;
 
	buddy.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_BUDDY_CHANGED);
 

	
 
	Client *c = (Client *) user->getData();
 
	send(c->connection, message);
 
}
 

	
 
void NetworkPluginServer::handleBuddyAdded(Buddy *buddy, const Swift::RosterItemPayload &item) {
 
	handleBuddyUpdated(buddy, item);
 
}
 

	
 
void NetworkPluginServer::handleVCardRequired(User *user, const std::string &name, unsigned int id) {
 
	std::cout << "VCARD REQUIRED " << name << " " << id << "\n";
 
	pbnetwork::VCard vcard;
 
	vcard.set_username(user->getJID().toBare());
 
	vcard.set_buddyname(name);
 
	vcard.set_id(id);
 

	
 
	std::string message;
 
	vcard.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_VCARD);
 

	
src/rostermanager.cpp
Show inline comments
 
@@ -110,24 +110,30 @@ void RosterManager::setBuddyCallback(Buddy *buddy) {
 

	
 
	if (m_rosterStorage)
 
		m_rosterStorage->storeBuddy(buddy);
 
}
 

	
 
void RosterManager::unsetBuddy(Buddy *buddy) {
 
	m_buddies.erase(buddy->getName());
 
	if (m_rosterStorage)
 
		m_rosterStorage->removeBuddyFromQueue(buddy);
 
	onBuddyUnset(buddy);
 
}
 

	
 
void RosterManager::storeBuddy(Buddy *buddy) {
 
	if (m_rosterStorage) {
 
		m_rosterStorage->storeBuddy(buddy);
 
	}
 
}
 

	
 
void RosterManager::handleBuddyRosterPushResponse(Swift::ErrorPayload::ref error, const std::string &key) {
 
	if (m_buddies[key] != NULL) {
 
		m_buddies[key]->handleBuddyChanged();
 
	}
 
}
 

	
 
Buddy *RosterManager::getBuddy(const std::string &name) {
 
	return m_buddies[name];
 
}
 

	
 
void RosterManager::sendRIE() {
 
	m_RIETimer->stop();
src/rosterresponder.cpp
Show inline comments
 
@@ -18,24 +18,25 @@
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/rosterresponder.h"
 

	
 
#include <iostream>
 
#include <boost/bind.hpp>
 
#include "Swiften/Queries/IQRouter.h"
 
#include "Swiften/Swiften.h"
 
#include "transport/user.h"
 
#include "transport/usermanager.h"
 
#include "transport/rostermanager.h"
 
#include "transport/buddy.h"
 

	
 
using namespace Swift;
 
using namespace boost;
 

	
 
namespace Transport {
 

	
 
RosterResponder::RosterResponder(Swift::IQRouter *router, UserManager *userManager) : Swift::Responder<RosterPayload>(router) {
 
	m_userManager = userManager;
 
}
 

	
 
RosterResponder::~RosterResponder() {
 
}
 
@@ -58,16 +59,51 @@ bool RosterResponder::handleGetRequest(const Swift::JID& from, const Swift::JID&
 
		user = m_userManager->getUser(from.toBare().toString());
 
		if (!user) {
 
			sendResponse(from, id, boost::shared_ptr<RosterPayload>(new RosterPayload()));
 
			return true;
 
		}
 
	}
 
	sendResponse(from, id, user->getRosterManager()->generateRosterPayload());
 
	return true;
 
}
 

	
 
bool RosterResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::RosterPayload> payload) {
 
	sendResponse(from, id, boost::shared_ptr<RosterPayload>(new RosterPayload()));
 

	
 
	User *user = m_userManager->getUser(from.toBare().toString());
 
	if (!user) {
 
		return true;
 
	}
 

	
 
	if (payload->getItems().size() == 0) {
 
		return true;
 
	}
 

	
 
	Swift::RosterItemPayload item = payload->getItems()[0];
 

	
 
	Buddy *buddy = user->getRosterManager()->getBuddy(Buddy::JIDToLegacyName(item.getJID()));
 
	if (buddy) {
 
		if (item.getSubscription() == Swift::RosterItemPayload::Remove) {
 
			onBuddyRemoved(buddy);
 
		}
 
		else {
 
			onBuddyUpdated(buddy, item);
 
		}
 
	}
 
	else if (item.getSubscription() != Swift::RosterItemPayload::Remove) {
 
		// Roster push for this new buddy is sent by RosterManager
 
		BuddyInfo buddyInfo;
 
		buddyInfo.id = -1;
 
		buddyInfo.alias = item.getName();
 
		buddyInfo.legacyName = Buddy::JIDToLegacyName(item.getJID());
 
		buddyInfo.subscription = "both";
 
		buddyInfo.flags = 0;
 

	
 
		buddy = user->getComponent()->getFactory()->createBuddy(user->getRosterManager(), buddyInfo);
 
		user->getRosterManager()->setBuddy(buddy);
 
		onBuddyAdded(buddy, item);
 
	}
 

	
 
	return true;
 
}
 

	
 
}
src/sqlite3backend.cpp
Show inline comments
 
@@ -231,25 +231,25 @@ bool SQLite3Backend::getUser(const std::string &barejid, UserInfo &user) {
 
}
 

	
 
void SQLite3Backend::setUserOnline(long id, bool online) {
 
	
 
}
 

	
 
long SQLite3Backend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
 
// 	"INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)"
 
	BEGIN(m_addBuddy);
 
	BIND_INT(m_addBuddy, userId);
 
	BIND_STR(m_addBuddy, buddyInfo.legacyName);
 
	BIND_STR(m_addBuddy, buddyInfo.subscription);
 
	BIND_STR(m_addBuddy, buddyInfo.groups[0]); // TODO: serialize groups
 
	BIND_STR(m_addBuddy, buddyInfo.groups.size() == 0 ? "" : buddyInfo.groups[0]); // TODO: serialize groups
 
	BIND_STR(m_addBuddy, buddyInfo.alias);
 
	BIND_INT(m_addBuddy, buddyInfo.flags);
 

	
 
	if(sqlite3_step(m_addBuddy) != SQLITE_DONE) {
 
		onStorageError("addBuddy query", (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
 
		return -1;
 
	}
 

	
 
	long id = (long) sqlite3_last_insert_rowid(m_db);
 

	
 
// 	INSERT OR REPLACE INTO " + m_prefix + "buddies_settings (user_id, buddy_id, var, type, value) VALUES (?, ?, ?, ?, ?)
 
	BEGIN(m_updateBuddySetting);
tests/CMakeLists.txt
Show inline comments
 
new file 100644
 
ADD_SUBDIRECTORY(login)
 
ADD_SUBDIRECTORY(login_bad_name)
 
ADD_SUBDIRECTORY(login_bad_name2)
 

	
 
add_custom_target(tests python runtests.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
tests/login/CMakeLists.txt
Show inline comments
 
new file 100644
 
FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(login_test ${SRC})
 
 
TARGET_LINK_LIBRARIES(login_test transport ${SWIFTEN_LIBRARIES} -lgconf-2 -lgobject-2.0 -lglib-2.0)
 
tests/login/main.cpp
Show inline comments
 
new file 100644
 
#include <iostream>
 
#include <boost/bind.hpp>
 

	
 
#include <Swiften/Swiften.h>
 
#include <Swiften/Client/ClientOptions.h>
 

	
 
using namespace Swift;
 
using namespace boost;
 

	
 
Client* client;
 

	
 
static void handleDisconnected(const boost::optional<ClientError> &) {
 
	exit(1);
 
}
 

	
 
static void handleConnected() {
 
	exit(0);
 
}
 

	
 
static void handleMessageReceived(Message::ref message) {
 
	// Echo back the incoming message
 
	message->setTo(message->getFrom());
 
	message->setFrom(JID());
 
	client->sendMessage(message);
 
}
 

	
 
int main(int, char **argv) {
 
	SimpleEventLoop eventLoop;
 
	BoostNetworkFactories networkFactories(&eventLoop);
 

	
 
	client = new Client(argv[1], argv[2], &networkFactories);
 
	client->setAlwaysTrustCertificates();
 
	client->onConnected.connect(&handleConnected);
 
	client->onDisconnected.connect(bind(&handleDisconnected, _1));
 
	client->onMessageReceived.connect(bind(&handleMessageReceived, _1));
 
	ClientOptions opt;
 
	opt.allowPLAINOverNonTLS = true;
 
	client->connect(opt);
 

	
 
	eventLoop.run();
 

	
 
	delete client;
 
	return 0;
 
}
tests/login_bad_name/CMakeLists.txt
Show inline comments
 
new file 100644
 
FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(login_bad_name_test ${SRC})
 
 
TARGET_LINK_LIBRARIES(login_bad_name_test transport ${SWIFTEN_LIBRARIES} -lgconf-2 -lgobject-2.0 -lglib-2.0)
 
tests/login_bad_name/main.cpp
Show inline comments
 
new file 100644
 
#include <iostream>
 
#include <boost/bind.hpp>
 

	
 
#include <Swiften/Swiften.h>
 
#include <Swiften/Client/ClientOptions.h>
 

	
 
using namespace Swift;
 
using namespace boost;
 

	
 
Client* client;
 

	
 
static void handleDisconnected(const boost::optional<ClientError> &error) {
 
	exit(error->getType() != ClientError::AuthenticationFailedError);
 
}
 

	
 
static void handleConnected() {
 
	exit(1);
 
}
 

	
 
static void handleMessageReceived(Message::ref message) {
 
	// Echo back the incoming message
 
	message->setTo(message->getFrom());
 
	message->setFrom(JID());
 
	client->sendMessage(message);
 
}
 

	
 
int main(int, char **argv) {
 
	SimpleEventLoop eventLoop;
 
	BoostNetworkFactories networkFactories(&eventLoop);
 

	
 
	JID jid(JID(argv[1]).getNode() + "something", JID(argv[1]).getDomain());
 
	client = new Client(jid, argv[2], &networkFactories);
 
	client->setAlwaysTrustCertificates();
 
	client->onConnected.connect(&handleConnected);
 
	client->onDisconnected.connect(bind(&handleDisconnected, _1));
 
	client->onMessageReceived.connect(bind(&handleMessageReceived, _1));
 
	ClientOptions opt;
 
	opt.allowPLAINOverNonTLS = true;
 
	client->connect(opt);
 

	
 
	eventLoop.run();
 

	
 
	delete client;
 
	return 0;
 
}
tests/login_bad_name2/.nolibircclient-qt
Show inline comments
 
new file 100644
tests/login_bad_name2/CMakeLists.txt
Show inline comments
 
new file 100644
 
FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(login_bad_name2_test ${SRC})
 
 
TARGET_LINK_LIBRARIES(login_bad_name2_test transport ${SWIFTEN_LIBRARIES} -lgconf-2 -lgobject-2.0 -lglib-2.0)
 
tests/login_bad_name2/main.cpp
Show inline comments
 
new file 100644
 
#include <iostream>
 
#include <boost/bind.hpp>
 

	
 
#include <Swiften/Swiften.h>
 
#include <Swiften/Client/ClientOptions.h>
 

	
 
using namespace Swift;
 
using namespace boost;
 

	
 
Client* client;
 

	
 
static void handleDisconnected(const boost::optional<ClientError> &error) {
 
	exit(error->getType() != ClientError::AuthenticationFailedError);
 
}
 

	
 
static void handleConnected() {
 
	exit(1);
 
}
 

	
 
static void handleMessageReceived(Message::ref message) {
 
	// Echo back the incoming message
 
	message->setTo(message->getFrom());
 
	message->setFrom(JID());
 
	client->sendMessage(message);
 
}
 

	
 
int main(int, char **argv) {
 
	SimpleEventLoop eventLoop;
 
	BoostNetworkFactories networkFactories(&eventLoop);
 

	
 
	JID jid(std::string("something") + JID(argv[1]).getNode(), JID(argv[1]).getDomain());
 
	client = new Client(jid, argv[2], &networkFactories);
 
	client->setAlwaysTrustCertificates();
 
	client->onConnected.connect(&handleConnected);
 
	client->onDisconnected.connect(bind(&handleDisconnected, _1));
 
	client->onMessageReceived.connect(bind(&handleMessageReceived, _1));
 
	ClientOptions opt;
 
	opt.allowPLAINOverNonTLS = true;
 
	client->connect(opt);
 

	
 
	eventLoop.run();
 

	
 
	delete client;
 
	return 0;
 
}
tests/runtests.py
Show inline comments
 
new file 100644
 
import os
 
import sys
 
from subprocess import *
 
import time
 

	
 
def run_spectrum(backend, test):
 
	os.system("rm test.sql")
 
	f = open("sample.cfg", "w")
 
	f.write("\
 
	[service]\n\
 
	jid = localhost\n\
 
	password = secret\n\
 
	server = 127.0.0.1\n\
 
	port = 5222\n\
 
	server_mode = 1\n\
 
	backend=../backends/%s/%s_backend\n\
 
	protocol=prpl-jabber\n\
 
\
 
	[database]\n\
 
	database = test.sql\n\
 
	prefix=icq\n\
 
	" % (backend, backend)
 
	)
 
	f.close()
 
	p = Popen("../spectrum/src/spectrum sample.cfg > " + backend + "_" + test + ".log 2>&1", shell=True)
 
	time.sleep(4)
 
	return p
 

	
 
def one_test_run():
 
	os.system("killall spectrum 2> /dev/null")
 
	os.system("rm *.log")
 

	
 
	for backend in os.listdir("../backends"):
 
		if not os.path.isdir("../backends/" + backend) or backend == "CMakeFiles":
 
			continue
 

	
 
		for d in os.listdir("."):
 
			binary = d + "/" + d + "_test"
 
			if not os.path.exists(binary):
 
				continue
 

	
 
			if os.path.exists(d + "/.no" + backend):
 
				continue
 

	
 
			p = run_spectrum(backend, d)
 

	
 
			if backend.find("purple") >= 0:
 
				p = Popen(binary + " pyjim%jabber.cz@localhost test", shell=True)
 
			else:
 
				p = Popen(binary + " testnickname%irc.freenode.net@localhost test", shell=True)
 

	
 
			seconds = 0
 
			while p.poll() is None and seconds < 20:
 
				time.sleep(1)
 
				seconds += 1
 

	
 
			if p.returncode == 0 and seconds < 20:
 
				print "[ PASS ]", backend, binary
 
				
 
			else:
 
				if seconds == 20:
 
					print "[ TIME ]", backend, binary
 
				else:
 
					print "[ FAIL ]", backend, binary
 

	
 
			os.system("killall spectrum 2> /dev/null")
 

	
 
one_test_run()
 

	
 

	
0 comments (0 inline, 0 general)