Changeset - deeafae6f037
[Not reviewed]
skypeweb_ts
0 7 0
Vitaly Takmazov - 7 years ago 2018-11-06 17:39:41
vitalyster@gmail.com
libpurple: store last_message_timestamp from skypeweb account into database
7 files changed with 126 insertions and 14 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
cmake_minimum_required(VERSION 3.0)
 
project(libtransport)
 
if(${CMAKE_MAJOR_VERSION} GREATER 2)
 
cmake_policy(SET CMP0037 OLD)
 
endif()
 
cmake_policy(SET CMP0042 NEW)
 
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 
include(CPack)
 
message(STATUS "Variables to override default places where to find libraries:")
 
message(STATUS "|- cppunit : -DCPPUNIT_INCLUDE_DIR,  -DCPPUNIT_LIBRARY")
 
message(STATUS "|- swiften : -DSWIFTEN_INCLUDE_DIR,  -DSWIFTEN_LIBRARY")
 
message(STATUS "  |- zlib  :                         -DZLIB_LIBRARY")
 
message(STATUS "  |- expat :                         -DEXPAT_LIBRARY")
 
message(STATUS "  |-libidn :                         -DLIBIDN_LIBRARY")
 
message(STATUS "  |-libxml :                         -DLIBXML_LIBRARY")
 
message(STATUS "|- boost   : -DBOOST_INCLUDEDIR,     -DBOOST_LIBRARYDIR")
 
message(STATUS "|- protobuf: -DPROTOBUF_INCLUDE_DIR, -DPROTOBUF_LIBRARY")
 
message(STATUS "           : -DPROTOBUF_PROTOC_EXECUTABLE")
 
message(STATUS "|- log4cxx : -DLOG4CXX_INCLUDE_DIR,  -DLOG4CXX_LIBRARY")
backends/libpurple/main.cpp
Show inline comments
 
@@ -183,24 +183,25 @@ static std::string getAlias(PurpleBuddy *m_buddy) {
 
		alias = (std::string) purple_buddy_get_alias_wrapped(m_buddy);
 
	}
 
	else {
 
		alias = (std::string) purple_buddy_get_server_alias_wrapped(m_buddy);
 
	}
 
	return alias;
 
}
 

	
 
static boost::mutex dblock;
 
static std::string OAUTH_TOKEN = "hangouts_oauth_token";
 
static std::string STEAM_ACCESS_TOKEN = "steammobile_access_token";
 
static std::string DISCORD_ACCESS_TOKEN = "discord_access_token";
 
static std::string LAST_MESSAGE_TIMESTAMP = "skypeweb_last_message_timestamp";
 

	
 
static bool getUserToken(const std::string user, const std::string token_name, std::string &token_value)
 
{
 
	boost::mutex::scoped_lock lock(dblock);
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return false;
 
	}
 
	token_value = "";
 
	int type = TYPE_STRING;
 
	storagebackend->getUserSetting((long)info.id, token_name, type, token_value);
 
@@ -425,24 +426,30 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			else if (protocol == "prpl-steam-mobile") {
 
				std::string token;
 
				if (getUserToken(user, STEAM_ACCESS_TOKEN, token)) {
 
					purple_account_set_string_wrapped(account, "access_token", token.c_str());
 
				}
 
			}
 
            else if (protocol == "prpl-eionrobb-discord") {
 
                std::string token;
 
                if (getUserToken(user, DISCORD_ACCESS_TOKEN, token)) {
 
                    purple_account_set_string_wrapped(account, "token", token.c_str());
 
                }
 
            }
 
            if (protocol == "prpl-skypeweb") {
 
                int ts = 0;
 
                if (getLastMessageTimestamp(user, ts)) {
 
                    purple_account_set_int_wrapped(account, "last_message_timestamp", ts);
 
                }
 
            }
 

	
 
			setDefaultAccountOptions(account);
 

	
 
			// Enable account + privacy lists
 
			purple_account_set_enabled_wrapped(account, "spectrum", TRUE);
 

	
 
#if PURPLE_MAJOR_VERSION >= 2 && PURPLE_MINOR_VERSION >= 7
 
			if (CONFIG_BOOL(config, "service.enable_privacy_lists")) {
 
				purple_account_set_privacy_type_wrapped(account, PURPLE_PRIVACY_DENY_USERS);
 
			}
 
#endif
 

	
 
@@ -467,27 +474,24 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
					delete cache;
 
					account->ui_data = NULL;
 
				}
 
				if (purple_account_get_int_wrapped(account, "version", 0) != 0) {
 
					std::string data = stringOf(purple_account_get_int_wrapped(account, "version", 0));
 
					g_file_set_contents ("gfire.cfg", data.c_str(), data.size(), NULL);
 
				}
 
// 				VALGRIND_DO_LEAK_CHECK;
 
				m_sessions.erase(user);
 
				purple_account_disconnect_wrapped(account);
 
				purple_account_set_enabled_wrapped(account, "spectrum", FALSE);
 

	
 
				m_accounts.erase(account);
 

	
 
				purple_accounts_delete_wrapped(account);
 
#ifndef WIN32
 
#if !defined(__FreeBSD__) && !defined(__APPLE__)
 
				malloc_trim(0);
 
#endif
 
#endif
 
// 				VALGRIND_DO_LEAK_CHECK;
 
			}
 
		}
 

	
 
		void handleStatusChangeRequest(const std::string &user, int status, const std::string &statusMessage) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
@@ -1508,29 +1512,35 @@ static gboolean pingTimeout(void *data) {
 
	return TRUE;
 
}
 

	
 
static void connection_report_disconnect(PurpleConnection *gc, PurpleConnectionError reason, const char *text){
 
	PurpleAccount *account = purple_connection_get_account_wrapped(gc);
 
	np->handleDisconnected(np->m_accounts[account], (int) reason, text ? text : "");
 
// 	Dis *d = new Dis;
 
// 	d->name = purple_account_get_username_wrapped(account);
 
// 	d->protocol = purple_account_get_protocol_id_wrapped(account);
 
// 	purple_timeout_add_seconds_wrapped(10, disconnectMe, d);
 
}
 

	
 
static void connection_disconnected(PurpleConnection *gc) {
 
	PurpleAccount *account = purple_connection_get_account_wrapped(gc);
 
	purple_accounts_delete_wrapped(account);
 
	np->m_accounts.erase(account);
 
}
 

	
 
static PurpleConnectionUiOps conn_ui_ops =
 
{
 
	NULL,
 
	NULL,
 
	NULL,//connection_disconnected,
 
	connection_disconnected,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	connection_report_disconnect,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info) {
 
	PurpleAccount *account = purple_connection_get_account_wrapped(gc);
 
@@ -1998,35 +2008,103 @@ static PurpleRoomlistUiOps roomlist_ui_ops =
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	RoomlistProgress,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
#if PURPLE_MAJOR_VERSION >=2 && PURPLE_MINOR_VERSION >=11
 

	
 
static void preferencesIntChanged(PurpleAccount *account, const char *name, int value) {
 
	boost::mutex::scoped_lock lock(dblock);
 
        UserInfo info;
 
	std::string user = np->m_accounts[account];
 
	LOG4CXX_INFO(logger, "asking for " << user << " settings");
 
        if(storagebackend->getUser(user, info) == false) {
 
                LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
                return;
 
        }
 
        LOG4CXX_INFO(logger, "storing " << value << "as " << name << " for " << user);
 
        std::string defaultValue = "0";
 
        int type = TYPE_INT;
 
        storagebackend->getUserSetting((long)info.id, std::string(name), type, defaultValue);
 
        storagebackend->updateUserSetting((long)info.id, std::string(name), stringOf(value));
 
};
 

	
 
static void preferencesStringChanged(PurpleAccount *account, const char *name, const char *value) {
 
	boost::mutex::scoped_lock lock(dblock);
 
        UserInfo info;
 
	std::string user = np->m_accounts[account];
 
	LOG4CXX_INFO(logger, "asking for " << user << " settings");
 
        if(storagebackend->getUser(user, info) == false) {
 
                LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
                return;
 
        }
 
	LOG4CXX_INFO(logger, "storing " << value << "as " << name << " for " << user);
 
	std::string defaultValue = "";
 
	int type = TYPE_STRING;
 
	storagebackend->getUserSetting((long)info.id, std::string(name), type, defaultValue);
 
        storagebackend->updateUserSetting((long)info.id, std::string(name), std::string(value));
 
};
 

	
 
static void preferencesBoolChanged(PurpleAccount *account, const char *name, gboolean value) {
 
	boost::mutex::scoped_lock lock(dblock);
 
        UserInfo info;
 
	std::string user = np->m_accounts[account];
 
	LOG4CXX_INFO(logger, "asking for " << user << " settings");
 
        if(storagebackend->getUser(user, info) == false) {
 
                LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
                return;
 
        }
 
        LOG4CXX_INFO(logger, "storing " << value << "as " << name << " for " << user);
 
        std::string defaultValue = "false";
 
        int type = TYPE_BOOLEAN;
 
        storagebackend->getUserSetting((long)info.id, std::string(name), type, defaultValue);
 
        storagebackend->updateUserSetting((long)info.id, std::string(name), stringOf(value));
 
};
 

	
 
static PurpleAccountPrefsUiOps account_prefs_ui_ops =
 
{
 
	preferencesIntChanged,
 
	preferencesStringChanged,
 
	preferencesBoolChanged,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
#endif
 

	
 
static void transport_core_ui_init(void)
 
{
 
	purple_blist_set_ui_ops_wrapped(&blistUiOps);
 
	purple_accounts_set_ui_ops_wrapped(&accountUiOps);
 
	purple_notify_set_ui_ops_wrapped(&notifyUiOps);
 
	purple_request_set_ui_ops_wrapped(&requestUiOps);
 
	purple_xfers_set_ui_ops_wrapped(&xferUiOps);
 
	purple_connections_set_ui_ops_wrapped(&conn_ui_ops);
 
	purple_conversations_set_ui_ops_wrapped(&conversation_ui_ops);
 
	purple_roomlist_set_ui_ops_wrapped(&roomlist_ui_ops);
 

	
 
#if PURPLE_MAJOR_VERSION >=2 && PURPLE_MINOR_VERSION >= 11
 
	purple_account_prefs_set_ui_ops_wrapped(&account_prefs_ui_ops);
 
#endif
 
// #ifndef WIN32
 
// 	purple_dnsquery_set_ui_ops_wrapped(getDNSUiOps());
 
// #endif
 
}
 

	
 
/***** Core Ui Ops *****/
 
static void
 
spectrum_glib_log_handler(const gchar *domain,
 
						  GLogLevelFlags flags,
 
						  const gchar *message,
 
						  gpointer user_data)
 
{
 
@@ -2347,29 +2425,29 @@ int main(int argc, char **argv) {
 
#endif
 

	
 
	std::string error;
 
	Config *cfg = Config::createFromArgs(argc, argv, error, host, port);
 
	if (cfg == NULL) {
 
		std::cerr << error;
 
		return 1;
 
	}
 

	
 
	config = SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Config>(cfg);
 

	
 
	Logging::initBackendLogging(config.get());
 
	if (CONFIG_STRING(config, "service.protocol") == "prpl-hangouts" || CONFIG_STRING(config, "service.protocol") == "prpl-steam-mobile") {
 
	if (CONFIG_STRING(config, "service.protocol") == "prpl-hangouts" || CONFIG_STRING(config, "service.protocol") == "prpl-steam-mobile" || CONFIG_STRING(config, "service.protocol") == "prpl-skypeweb" || CONFIG_STRING(config, "service.protocol") == "prpl-eionrobb-discord") {
 
		storagebackend = StorageBackend::createBackend(config.get(), error);
 
		if (storagebackend == NULL) {
 
			LOG4CXX_ERROR(logger, "Error creating StorageBackend! " << error);
 
			LOG4CXX_ERROR(logger, "Hangouts and Steam backends need storage backend configured to work! " << error);
 
			LOG4CXX_ERROR(logger, "Selected libpurple protocol need storage backend configured to work! " << error);
 
			return NetworkPlugin::StorageBackendNeeded;
 
		}
 
		else if (!storagebackend->connect()) {
 
			LOG4CXX_ERROR(logger, "Can't connect to database!");
 
			return -1;
 
		}
 
	}
 

	
 
	initPurple();
 

	
 
	main_socket = create_socket(host.c_str(), port);
 
	purple_input_add_wrapped(main_socket, PURPLE_INPUT_READ, &transportDataReceived, NULL);
backends/libpurple/purple_defs.cpp
Show inline comments
 
@@ -19,24 +19,25 @@ purple_account_set_privacy_type_wrapped_fnc purple_account_set_privacy_type_wrap
 
purple_account_get_status_type_with_primitive_wrapped_fnc purple_account_get_status_type_with_primitive_wrapped = NULL;
 
purple_account_set_status_wrapped_fnc purple_account_set_status_wrapped = NULL;
 
purple_account_get_int_wrapped_fnc purple_account_get_int_wrapped = NULL;
 
purple_account_disconnect_wrapped_fnc purple_account_disconnect_wrapped = NULL;
 
purple_accounts_delete_wrapped_fnc purple_accounts_delete_wrapped = NULL;
 
purple_account_get_connection_wrapped_fnc purple_account_get_connection_wrapped = NULL;
 
purple_account_set_alias_wrapped_fnc purple_account_set_alias_wrapped = NULL;
 
purple_account_set_public_alias_wrapped_fnc purple_account_set_public_alias_wrapped = NULL;
 
purple_account_remove_buddy_wrapped_fnc purple_account_remove_buddy_wrapped = NULL;
 
purple_account_add_buddy_wrapped_fnc purple_account_add_buddy_wrapped = NULL;
 
purple_account_get_name_for_display_wrapped_fnc purple_account_get_name_for_display_wrapped = NULL;
 
purple_accounts_set_ui_ops_wrapped_fnc purple_accounts_set_ui_ops_wrapped = NULL;
 
purple_account_prefs_set_ui_ops_wrapped_fnc purple_account_prefs_set_ui_ops_wrapped = NULL;
 
purple_account_option_get_type_wrapped_fnc purple_account_option_get_type_wrapped = NULL;
 
purple_account_option_get_setting_wrapped_fnc purple_account_option_get_setting_wrapped = NULL;
 
purple_blist_node_get_type_wrapped_fnc purple_blist_node_get_type_wrapped = NULL;
 
purple_buddy_get_alias_wrapped_fnc purple_buddy_get_alias_wrapped = NULL;
 
purple_buddy_get_server_alias_wrapped_fnc purple_buddy_get_server_alias_wrapped = NULL;
 
purple_find_buddy_wrapped_fnc purple_find_buddy_wrapped = NULL;
 
purple_buddy_get_group_wrapped_fnc purple_buddy_get_group_wrapped = NULL;
 
purple_blist_remove_buddy_wrapped_fnc purple_blist_remove_buddy_wrapped = NULL;
 
purple_blist_alias_buddy_wrapped_fnc purple_blist_alias_buddy_wrapped = NULL;
 
purple_blist_server_alias_buddy_wrapped_fnc purple_blist_server_alias_buddy_wrapped = NULL;
 
purple_find_group_wrapped_fnc purple_find_group_wrapped = NULL;
 
purple_group_new_wrapped_fnc purple_group_new_wrapped = NULL;
 
@@ -250,24 +251,27 @@ bool resolvePurpleFunctions() {
 

	
 
	purple_account_add_buddy_wrapped = (purple_account_add_buddy_wrapped_fnc)GetProcAddress(f_hPurple, "purple_account_add_buddy");
 
	if (!purple_account_add_buddy_wrapped)
 
		return false;
 

	
 
	purple_account_get_name_for_display_wrapped = (purple_account_get_name_for_display_wrapped_fnc)GetProcAddress(f_hPurple, "purple_account_get_name_for_display");
 
	if (!purple_account_get_name_for_display_wrapped)
 
		return false;
 

	
 
	purple_accounts_set_ui_ops_wrapped = (purple_accounts_set_ui_ops_wrapped_fnc)GetProcAddress(f_hPurple, "purple_accounts_set_ui_ops");
 
	if (!purple_accounts_set_ui_ops_wrapped)
 
		return false;
 
	purple_account_prefs_set_ui_ops_wrapped = (purple_account_prefs_set_ui_ops_wrapped_fnc)GetProcAddress(f_hPurple, "purple_account_prefs_set_ui_ops");
 
	if (!purple_account_prefs_set_ui_ops_wrapped)
 
		return false;
 

	
 
	purple_account_option_get_type_wrapped = (purple_account_option_get_type_wrapped_fnc)GetProcAddress(f_hPurple, "purple_account_option_get_type");
 
	if (!purple_account_option_get_type_wrapped)
 
		return false;
 

	
 
	purple_account_option_get_setting_wrapped = (purple_account_option_get_setting_wrapped_fnc)GetProcAddress(f_hPurple, "purple_account_option_get_setting");
 
	if (!purple_account_option_get_setting_wrapped)
 
		return false;
 

	
 
	purple_blist_node_get_type_wrapped = (purple_blist_node_get_type_wrapped_fnc)GetProcAddress(f_hPurple, "purple_blist_node_get_type");
 
	if (!purple_blist_node_get_type_wrapped)
 
		return false;
backends/libpurple/purple_defs.h
Show inline comments
 
@@ -86,24 +86,27 @@ extern purple_account_set_public_alias_wrapped_fnc purple_account_set_public_ali
 
typedef void  (_cdecl * purple_account_remove_buddy_wrapped_fnc)(PurpleAccount *account, PurpleBuddy *buddy, PurpleGroup *group);
 
extern purple_account_remove_buddy_wrapped_fnc purple_account_remove_buddy_wrapped;
 

	
 
typedef void  (_cdecl * purple_account_add_buddy_wrapped_fnc)(PurpleAccount *account, PurpleBuddy *buddy);
 
extern purple_account_add_buddy_wrapped_fnc purple_account_add_buddy_wrapped;
 

	
 
typedef const gchar * (_cdecl * purple_account_get_name_for_display_wrapped_fnc)(const PurpleAccount *account);
 
extern purple_account_get_name_for_display_wrapped_fnc purple_account_get_name_for_display_wrapped;
 

	
 
typedef void  (_cdecl * purple_accounts_set_ui_ops_wrapped_fnc)(PurpleAccountUiOps *ops);
 
extern purple_accounts_set_ui_ops_wrapped_fnc purple_accounts_set_ui_ops_wrapped;
 

	
 
typedef void (_cdecl * purple_account_prefs_set_ui_ops_wrapped_fnc)(PurpleAccountPrefUiOps *ops);
 
extern purple_account_prefs_set_ui_ops_wrapped_fnc purple_account_pref_set_ui_ops_wrapped;
 

	
 
typedef PurplePrefType  (_cdecl * purple_account_option_get_type_wrapped_fnc)(const PurpleAccountOption *option);
 
extern purple_account_option_get_type_wrapped_fnc purple_account_option_get_type_wrapped;
 

	
 
typedef const char * (_cdecl * purple_account_option_get_setting_wrapped_fnc)(const PurpleAccountOption *option);
 
extern purple_account_option_get_setting_wrapped_fnc purple_account_option_get_setting_wrapped;
 

	
 
typedef PurpleBlistNodeType  (_cdecl * purple_blist_node_get_type_wrapped_fnc)(PurpleBlistNode *node);
 
extern purple_blist_node_get_type_wrapped_fnc purple_blist_node_get_type_wrapped;
 

	
 
typedef const char * (_cdecl * purple_buddy_get_alias_wrapped_fnc)(PurpleBuddy *buddy);
 
extern purple_buddy_get_alias_wrapped_fnc purple_buddy_get_alias_wrapped;
 

	
 
@@ -499,24 +502,25 @@ extern wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_wi
 
#define purple_account_get_status_type_with_primitive_wrapped purple_account_get_status_type_with_primitive
 
#define purple_account_set_status_wrapped purple_account_set_status
 
#define purple_account_get_int_wrapped purple_account_get_int
 
#define purple_account_disconnect_wrapped purple_account_disconnect
 
#define purple_accounts_delete_wrapped purple_accounts_delete
 
#define purple_account_get_connection_wrapped purple_account_get_connection
 
#define purple_account_set_alias_wrapped purple_account_set_alias
 
#define purple_account_set_public_alias_wrapped purple_account_set_public_alias
 
#define purple_account_remove_buddy_wrapped purple_account_remove_buddy
 
#define purple_account_add_buddy_wrapped purple_account_add_buddy
 
#define purple_account_get_name_for_display_wrapped purple_account_get_name_for_display
 
#define purple_accounts_set_ui_ops_wrapped purple_accounts_set_ui_ops
 
#define purple_account_prefs_set_ui_ops_wrapped purple_account_prefs_set_ui_ops
 
#define purple_account_option_get_type_wrapped purple_account_option_get_type
 
#define purple_account_option_get_setting_wrapped purple_account_option_get_setting
 
#define purple_blist_node_get_type_wrapped purple_blist_node_get_type
 
#define purple_buddy_get_alias_wrapped purple_buddy_get_alias
 
#define purple_buddy_get_server_alias_wrapped purple_buddy_get_server_alias
 
#define purple_find_buddy_wrapped purple_find_buddy
 
#define purple_buddy_get_group_wrapped purple_buddy_get_group
 
#define purple_blist_remove_buddy_wrapped purple_blist_remove_buddy
 
#define purple_blist_alias_buddy_wrapped purple_blist_alias_buddy
 
#define purple_blist_server_alias_buddy_wrapped purple_blist_server_alias_buddy
 
#define purple_find_group_wrapped purple_find_group
 
#define purple_group_new_wrapped purple_group_new
packaging/debian/debian/changelog
Show inline comments
 
spectrum2 (1:1760-89e377b-1) unstable; urgency=low
 
spectrum2 (1:2267-b80ba70a-1) unstable; urgency=low
 

	
 
  * Move package to git-buildpackage format
 
  * remove the -git suffix from package names
 
  * Change dependency from libswiften2-dev to libswiften-dev
 
  * remove some old cruft (debian/source/options, lintian-overrides, ...)
 
  * Add libevent-dev as build-dependency
 

	
 
 -- Mathias Ertl <apt-repository@fsinf.at>  Thu, 28 Jun 2012 21:39:27 +0200
 

	
 
spectrum2-git (2.0.0~beta+47-gdd8627b-1) unstable; urgency=low
 

	
 
  * Upstream development snapshot
tests/CMakeLists.txt
Show inline comments
 
ADD_SUBDIRECTORY(libtransport)
 

	
 

	
 
add_custom_target(test ${CMAKE_CURRENT_BINARY_DIR}/libtransport/libtransport_test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests_output)
 
add_custom_target(extended_test ${CMAKE_CURRENT_BINARY_DIR}/libtransport/libtransport_test COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/start.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests_output)
 
add_custom_target(test $<TARGET_FILE:libtransport_test> WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests_output)
 
add_custom_target(extended_test $<TARGET_FILE:libtransport_test> COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/start.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests_output)
tests/libtransport/util.cpp
Show inline comments
 
#include <cppunit/TestFixture.h>
 
#include <cppunit/extensions/HelperMacros.h>
 
#include <Swiften/Swiften.h>
 
#include <Swiften/EventLoop/DummyEventLoop.h>
 
#include <Swiften/Server/Server.h>
 
#include <Swiften/Network/DummyNetworkFactories.h>
 
#include <Swiften/Network/DummyConnectionServer.h>
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 
#include "transport/utf8.h"
 
#include <boost/lexical_cast.hpp>
 

	
 

	
 
using namespace Transport;
 
using boost::lexical_cast;
 

	
 
class UtilTest : public CPPUNIT_NS :: TestFixture{
 
	CPPUNIT_TEST_SUITE(UtilTest);
 
	CPPUNIT_TEST(encryptDecryptPassword);
 
	CPPUNIT_TEST(serializeGroups);
 
	CPPUNIT_TEST(replaceInvalid);
 
    CPPUNIT_TEST(storeUserSettings);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
		void setUp (void) {
 
		}
 

	
 
		void tearDown (void) {
 

	
 
		}
 

	
 
	void encryptDecryptPassword() {
 
		std::string encrypted = StorageBackend::encryptPassword("password", "key");
 
@@ -58,15 +61,39 @@ class UtilTest : public CPPUNIT_NS :: TestFixture{
 
	void replaceInvalid() {
 
		std::string x("test\x80\xe0\xa0\xc0\xaf\xed\xa0\x80test");
 
		std::string a;
 
		CPPUNIT_ASSERT(x.end() != utf8::find_invalid(x.begin(), x.end()));
 
		utf8::replace_invalid(x.begin(), x.end(), std::back_inserter(a), '_');
 
		CPPUNIT_ASSERT_EQUAL(std::string("test____test"), a);
 

	
 
		a = "";
 
		utf8::remove_invalid(x.begin(), x.end(), std::back_inserter(a));
 
		CPPUNIT_ASSERT_EQUAL(std::string("testtest"), a);
 
	}
 
    
 
    void storeUserSettings() {
 
        std::istringstream ifs("service.server_mode = 1\nservice.jid=localhost\nservice.more_resources=1\nservice.admin_jid=me@localhost\ndatabase.type=sqlite3\ndatabase.database=demo.s3db");
 
        Config *cfg = new Config();
 
        cfg->load(ifs);
 
        std::string err = "";
 
        StorageBackend *storage = StorageBackend::createBackend(cfg, err);
 
        UserInfo res;
 
        res.uin = "123456";
 
        res.jid = "test@localhost";
 
        res.password = "secret";
 
        storage->connect();
 
        storage->setUser(res);
 
        storage->getUser("test@localhost", res);
 
        int ts = time(NULL);
 
        std::string key = boost::lexical_cast<std::string>(ts);
 
        int type = TYPE_INT;
 
        storage->getUserSetting(res.id, "test_variable", type, key);
 
        std::string value = "";
 
        
 
        storage->getUserSetting(res.id, "test_variable", type, value);
 
        unlink("demo.s3db");
 
        CPPUNIT_ASSERT_EQUAL(ts, boost::lexical_cast<int>(value));
 
    }
 

	
 
};
 

	
 
CPPUNIT_TEST_SUITE_REGISTRATION (UtilTest);
0 comments (0 inline, 0 general)