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")
backends/libpurple/main.cpp
Show inline comments
 
@@ -189,12 +189,13 @@ static std::string getAlias(PurpleBuddy *m_buddy) {
 
}
 

	
 
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) {
 
@@ -431,12 +432,18 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
            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);
 

	
 
@@ -473,15 +480,12 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
				}
 
// 				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;
 
@@ -1514,17 +1518,23 @@ static void connection_report_disconnect(PurpleConnection *gc, PurpleConnectionE
 
// 	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,
 
@@ -2004,23 +2014,91 @@ static PurpleRoomlistUiOps roomlist_ui_ops =
 
	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 *****/
 
@@ -2353,17 +2431,17 @@ int main(int argc, char **argv) {
 
		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;
 
		}
backends/libpurple/purple_defs.cpp
Show inline comments
 
@@ -25,12 +25,13 @@ purple_account_get_connection_wrapped_fnc purple_account_get_connection_wrapped
 
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;
 
@@ -256,12 +257,15 @@ bool resolvePurpleFunctions() {
 
	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");
backends/libpurple/purple_defs.h
Show inline comments
 
@@ -92,12 +92,15 @@ 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;
 

	
 
@@ -505,12 +508,13 @@ extern wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_wi
 
#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
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
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
 
@@ -7,21 +7,24 @@
 
#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) {
 
		}
 

	
 
@@ -63,10 +66,34 @@ class UtilTest : public CPPUNIT_NS :: TestFixture{
 
		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)