Files
@ 5adb3d1f9733
Branch filter:
Location: libtransport.git/include/transport/SQLite3Backend.h - annotation
5adb3d1f9733
4.5 KiB
text/plain
Support for registering OAuth2 users using spectrum2_manager + lot of Slack improvements
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa 7664202b38dc 7664202b38dc c5edfd19b1aa c5edfd19b1aa 78e71f9345c7 7e8720849725 c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa 78e71f9345c7 78e71f9345c7 599469670eec c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa 599469670eec 599469670eec 599469670eec 599469670eec bf4183c181eb 599469670eec 599469670eec c5edfd19b1aa c5edfd19b1aa 599469670eec 599469670eec 599469670eec c5edfd19b1aa 599469670eec 599469670eec 599469670eec 599469670eec 599469670eec c5edfd19b1aa c5edfd19b1aa 599469670eec 599469670eec c5edfd19b1aa 599469670eec 599469670eec 599469670eec 599469670eec 599469670eec c5edfd19b1aa 599469670eec 599469670eec 599469670eec 599469670eec c5edfd19b1aa c5edfd19b1aa 56dd64999814 56dd64999814 5adb3d1f9733 5adb3d1f9733 599469670eec 599469670eec 599469670eec 599469670eec 599469670eec 599469670eec 599469670eec 599469670eec 599469670eec e58ede7d51dc c5edfd19b1aa ebebf04f69f1 ebebf04f69f1 5855e6608cdc 9cb2171e0095 9cb2171e0095 9cb2171e0095 9cb2171e0095 16d484457f90 c0a01941fc10 7cad7380383f c0a01941fc10 5855e6608cdc 5855e6608cdc 16d484457f90 c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa bf4183c181eb c5edfd19b1aa cd9c7ad00bb7 cd9c7ad00bb7 cd9c7ad00bb7 cd9c7ad00bb7 c0a01941fc10 c0a01941fc10 7cad7380383f 123c52e618aa 123c52e618aa 123c52e618aa 123c52e618aa 9cb2171e0095 9cb2171e0095 ebebf04f69f1 5855e6608cdc 96fb9b61e85a 9cb2171e0095 e58ede7d51dc 125264c226c8 12a207a3a393 56dd64999814 5adb3d1f9733 c5edfd19b1aa c5edfd19b1aa c5edfd19b1aa 7664202b38dc 7664202b38dc | /**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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
*/
#pragma once
#ifdef WITH_SQLITE
#include <string>
#include <map>
#include "transport/StorageBackend.h"
#include "sqlite3.h"
namespace Transport {
class Config;
/// Used to store transport data into SQLite3 database.
class SQLite3Backend : public StorageBackend
{
public:
/// Creates new SQLite3Backend instance.
/// \param config cofiguration, this class uses following Config values:
/// - database.database - path to SQLite3 database file, database file is created automatically
/// - service.prefix - prefix for tables created by createDatabase method
SQLite3Backend(Config *config);
/// Destructor.
~SQLite3Backend();
/// Connects to the database and creates it if it's needed. This method call createDatabase() function
/// automatically.
/// \return true if database is opened successfully.
bool connect();
/// Creates database structure.
/// \see connect()
/// \return true if database structure has been created successfully. Note that it returns True also if database structure
/// already exists.
bool createDatabase();
/// Stores user into database.
/// \param user user struct containing all information about user which have to be stored
void setUser(const UserInfo &user);
/// Gets user data from database and stores them into user reference.
/// \param barejid barejid of user
/// \param user UserInfo object where user data will be stored
/// \return true if user has been found in database
bool getUser(const std::string &barejid, UserInfo &user);
/// Changes users online state variable in database.
/// \param id id of user - UserInfo.id
/// \param online online state
void setUserOnline(long id, bool online);
bool getOnlineUsers(std::vector<std::string> &users);
bool getUsers(std::vector<std::string> &users);
/// Removes user and all connected data from database.
/// \param id id of user - UserInfo.id
/// \return true if user has been found in database and removed
bool removeUser(long id);
/// Returns JIDs of all buddies in user's roster.
/// \param id id of user - UserInfo.id
/// \param roster string list used to store user's roster
/// \return true if user has been found in database and roster has been fetched
bool getBuddies(long id, std::list<BuddyInfo> &roster);
long addBuddy(long userId, const BuddyInfo &buddyInfo);
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);
void beginTransaction();
void commitTransaction();
private:
bool exec(const std::string &query);
sqlite3 *m_db;
Config *m_config;
std::string m_prefix;
// statements
sqlite3_stmt *m_setUser;
sqlite3_stmt *m_getUser;
sqlite3_stmt *m_getUserSetting;
sqlite3_stmt *m_setUserSetting;
sqlite3_stmt *m_updateUserSetting;
sqlite3_stmt *m_removeUser;
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;
sqlite3_stmt *m_getOnlineUsers;
sqlite3_stmt *m_getUsers;
};
}
#endif
|