Merge branch 'master' of github.com:hanzz/libtransport
This commit is contained in:
commit
1b1d1e0500
11 changed files with 76 additions and 4 deletions
|
@ -390,8 +390,6 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
|||
purple_account_disconnect(account);
|
||||
purple_account_set_enabled(account, "spectrum", FALSE);
|
||||
|
||||
g_free(account->ui_data);
|
||||
account->ui_data = NULL;
|
||||
m_accounts.erase(account);
|
||||
|
||||
purple_accounts_delete(account);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
#include "Swiften/Network/TLSConnectionFactory.h"
|
||||
#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h"
|
||||
|
||||
// for signal handler
|
||||
|
|
|
@ -89,6 +89,9 @@ class MySQLBackend : public StorageBackend
|
|||
void updateBuddy(long userId, const BuddyInfo &buddyInfo);
|
||||
void removeBuddy(long id) {}
|
||||
|
||||
void getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value) {}
|
||||
void updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value) {}
|
||||
|
||||
void getUserSetting(long userId, const std::string &variable, int &type, std::string &value);
|
||||
void updateUserSetting(long userId, const std::string &variable, const std::string &value);
|
||||
|
||||
|
|
|
@ -89,6 +89,9 @@ class PQXXBackend : public StorageBackend
|
|||
void updateBuddy(long userId, const BuddyInfo &buddyInfo);
|
||||
void removeBuddy(long id) {}
|
||||
|
||||
void getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value) {}
|
||||
void updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value) {}
|
||||
|
||||
void getUserSetting(long userId, const std::string &variable, int &type, std::string &value);
|
||||
void updateUserSetting(long userId, const std::string &variable, const std::string &value);
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ class RosterStorage {
|
|||
// will happen if buddy is already added.
|
||||
void storeBuddy(Buddy *buddy);
|
||||
|
||||
void removeBuddy(Buddy *buddy);
|
||||
|
||||
// Store all buddies from queue immediately. Returns true
|
||||
// if some buddies were stored.
|
||||
bool storeBuddies();
|
||||
|
|
|
@ -86,7 +86,10 @@ class SQLite3Backend : public StorageBackend
|
|||
long addBuddy(long userId, const BuddyInfo &buddyInfo);
|
||||
|
||||
void updateBuddy(long userId, const BuddyInfo &buddyInfo);
|
||||
void removeBuddy(long id) {}
|
||||
void removeBuddy(long id);
|
||||
|
||||
void getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value);
|
||||
void updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value);
|
||||
|
||||
void getUserSetting(long userId, const std::string &variable, int &type, std::string &value);
|
||||
void updateUserSetting(long userId, const std::string &variable, const std::string &value);
|
||||
|
@ -111,9 +114,12 @@ class SQLite3Backend : public StorageBackend
|
|||
sqlite3_stmt *m_removeUserBuddies;
|
||||
sqlite3_stmt *m_removeUserSettings;
|
||||
sqlite3_stmt *m_removeUserBuddiesSettings;
|
||||
sqlite3_stmt *m_removeBuddy;
|
||||
sqlite3_stmt *m_removeBuddySettings;
|
||||
sqlite3_stmt *m_addBuddy;
|
||||
sqlite3_stmt *m_updateBuddy;
|
||||
sqlite3_stmt *m_updateBuddySetting;
|
||||
sqlite3_stmt *m_getBuddySetting;
|
||||
sqlite3_stmt *m_getBuddies;
|
||||
sqlite3_stmt *m_getBuddiesSettings;
|
||||
sqlite3_stmt *m_setUserOnline;
|
||||
|
|
|
@ -119,6 +119,9 @@ class StorageBackend
|
|||
virtual void updateBuddy(long userId, const BuddyInfo &buddyInfo) = 0;
|
||||
virtual void removeBuddy(long id) = 0;
|
||||
|
||||
virtual void getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value) = 0;
|
||||
virtual void updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value) = 0;
|
||||
|
||||
virtual void getUserSetting(long userId, const std::string &variable, int &type, std::string &value) = 0;
|
||||
virtual void updateUserSetting(long userId, const std::string &variable, const std::string &value) = 0;
|
||||
|
||||
|
|
|
@ -205,7 +205,6 @@ static void handleBuddyPayload(LocalBuddy *buddy, const pbnetwork::Buddy &payloa
|
|||
// Set alias only if it's not empty. Backends are allowed to send empty alias if it has
|
||||
// not changed.
|
||||
if (!payload.alias().empty()) {
|
||||
LOG4CXX_INFO(logger, "Setting alias to " << payload.alias() << " " << buddy->getAlias());
|
||||
buddy->setAlias(payload.alias());
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,9 @@ void RosterManager::removeBuddy(const std::string &name) {
|
|||
sendBuddyUnsubscribePresence(buddy);
|
||||
}
|
||||
|
||||
if (m_rosterStorage)
|
||||
m_rosterStorage->removeBuddy(buddy);
|
||||
|
||||
unsetBuddy(buddy);
|
||||
delete buddy;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,12 @@ RosterStorage::~RosterStorage() {
|
|||
m_storageTimer->stop();
|
||||
}
|
||||
|
||||
void RosterStorage::removeBuddy(Buddy *buddy) {
|
||||
if (buddy->getID() != -1) {
|
||||
m_storageBackend->removeBuddy(buddy->getID());
|
||||
}
|
||||
}
|
||||
|
||||
void RosterStorage::storeBuddy(Buddy *buddy) {
|
||||
if (!buddy) {
|
||||
return;
|
||||
|
|
|
@ -88,6 +88,8 @@ SQLite3Backend::~SQLite3Backend(){
|
|||
FINALIZE_STMT(m_removeUserBuddies);
|
||||
FINALIZE_STMT(m_removeUserSettings);
|
||||
FINALIZE_STMT(m_removeUserBuddiesSettings);
|
||||
FINALIZE_STMT(m_removeBuddy);
|
||||
FINALIZE_STMT(m_removeBuddySettings);
|
||||
FINALIZE_STMT(m_addBuddy);
|
||||
FINALIZE_STMT(m_updateBuddy);
|
||||
FINALIZE_STMT(m_getBuddies);
|
||||
|
@ -96,6 +98,7 @@ SQLite3Backend::~SQLite3Backend(){
|
|||
FINALIZE_STMT(m_setUserSetting);
|
||||
FINALIZE_STMT(m_updateUserSetting);
|
||||
FINALIZE_STMT(m_updateBuddySetting);
|
||||
FINALIZE_STMT(m_getBuddySetting);
|
||||
FINALIZE_STMT(m_setUserOnline);
|
||||
FINALIZE_STMT(m_getOnlineUsers);
|
||||
sqlite3_close(m_db);
|
||||
|
@ -122,11 +125,15 @@ bool SQLite3Backend::connect() {
|
|||
PREP_STMT(m_removeUserSettings, "DELETE FROM " + m_prefix + "users_settings WHERE user_id=?");
|
||||
PREP_STMT(m_removeUserBuddiesSettings, "DELETE FROM " + m_prefix + "buddies_settings WHERE user_id=?");
|
||||
|
||||
PREP_STMT(m_removeBuddy, "DELETE FROM " + m_prefix + "buddies WHERE id=?");
|
||||
PREP_STMT(m_removeBuddySettings, "DELETE FROM " + m_prefix + "buddies_settings WHERE buddy_id=?");
|
||||
|
||||
PREP_STMT(m_addBuddy, "INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
PREP_STMT(m_updateBuddy, "UPDATE " + m_prefix + "buddies SET groups=?, nickname=?, flags=?, subscription=? WHERE user_id=? AND uin=?");
|
||||
PREP_STMT(m_getBuddies, "SELECT id, uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC");
|
||||
PREP_STMT(m_getBuddiesSettings, "SELECT buddy_id, type, var, value FROM " + m_prefix + "buddies_settings WHERE user_id=? ORDER BY buddy_id ASC");
|
||||
PREP_STMT(m_updateBuddySetting, "INSERT OR REPLACE INTO " + m_prefix + "buddies_settings (user_id, buddy_id, var, type, value) VALUES (?, ?, ?, ?, ?)");
|
||||
PREP_STMT(m_getBuddySetting, "SELECT type, value FROM " + m_prefix + "buddies_settings WHERE user_id=? AND buddy_id=? AND var=?");
|
||||
|
||||
PREP_STMT(m_getUserSetting, "SELECT type, value FROM " + m_prefix + "users_settings WHERE user_id=? AND var=?");
|
||||
PREP_STMT(m_setUserSetting, "INSERT INTO " + m_prefix + "users_settings (user_id, var, type, value) VALUES (?,?,?,?)");
|
||||
|
@ -405,6 +412,22 @@ bool SQLite3Backend::getBuddies(long id, std::list<BuddyInfo> &roster) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void SQLite3Backend::removeBuddy(long id) {
|
||||
sqlite3_reset(m_removeBuddy);
|
||||
sqlite3_bind_int(m_removeBuddy, 1, id);
|
||||
if(sqlite3_step(m_removeBuddy) != SQLITE_DONE) {
|
||||
LOG4CXX_ERROR(logger, "removeBuddy query"<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
|
||||
return;
|
||||
}
|
||||
|
||||
sqlite3_reset(m_removeBuddySettings);
|
||||
sqlite3_bind_int(m_removeBuddySettings, 1, id);
|
||||
if(sqlite3_step(m_removeBuddySettings) != SQLITE_DONE) {
|
||||
LOG4CXX_ERROR(logger, "removeBuddySettings query"<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool SQLite3Backend::removeUser(long id) {
|
||||
sqlite3_reset(m_removeUser);
|
||||
sqlite3_bind_int(m_removeUser, 1, id);
|
||||
|
@ -467,6 +490,31 @@ void SQLite3Backend::updateUserSetting(long id, const std::string &variable, con
|
|||
EXECUTE_STATEMENT(m_updateUserSetting, "m_updateUserSetting");
|
||||
}
|
||||
|
||||
void SQLite3Backend::getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value) {
|
||||
BEGIN(m_getBuddySetting);
|
||||
BIND_INT(m_getBuddySetting, userId);
|
||||
BIND_INT(m_getBuddySetting, buddyId);
|
||||
BIND_STR(m_getBuddySetting, variable);
|
||||
if(sqlite3_step(m_getBuddySetting) == SQLITE_ROW) {
|
||||
type = GET_INT(m_getBuddySetting);
|
||||
value = GET_STR(m_getBuddySetting);
|
||||
}
|
||||
|
||||
int ret;
|
||||
while((ret = sqlite3_step(m_getBuddySetting)) == SQLITE_ROW) {
|
||||
}
|
||||
}
|
||||
|
||||
void SQLite3Backend::updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value) {
|
||||
BEGIN(m_updateBuddySetting);
|
||||
BIND_INT(m_updateBuddySetting, userId);
|
||||
BIND_INT(m_updateBuddySetting, buddyId);
|
||||
BIND_STR(m_updateBuddySetting, variable);
|
||||
BIND_INT(m_updateBuddySetting, type);
|
||||
BIND_STR(m_updateBuddySetting, value);
|
||||
EXECUTE_STATEMENT(m_updateBuddySetting, "m_updateBuddySetting");
|
||||
}
|
||||
|
||||
void SQLite3Backend::beginTransaction() {
|
||||
exec("BEGIN TRANSACTION;");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue