Some updates
This commit is contained in:
parent
3f57ad4678
commit
9e2249462c
@ -188,16 +188,6 @@ if(HAVE_OPEN_SSL)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT WIN32)
|
|
||||||
#TODO: Do we really need that anymroe?
|
|
||||||
set(SOURCE_FILES ${SOURCE_FILES}
|
|
||||||
#src/misc/TraceUtils.cpp
|
|
||||||
)
|
|
||||||
set(HEADER_FILES ${HEADER_FILES}
|
|
||||||
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
add_library(TeaSpeak STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
add_library(TeaSpeak STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||||
target_link_libraries(TeaSpeak PUBLIC threadpool::static jsoncpp_lib)
|
target_link_libraries(TeaSpeak PUBLIC threadpool::static jsoncpp_lib)
|
||||||
target_compile_options(TeaSpeak PRIVATE "-Wall")
|
target_compile_options(TeaSpeak PRIVATE "-Wall")
|
||||||
|
@ -36,7 +36,8 @@ const std::vector<ErrorType> ts::avariableErrors = {
|
|||||||
{0x0211, "client_unknown" , "client is not known" },
|
{0x0211, "client_unknown" , "client is not known" },
|
||||||
{0x0212, "client_join_rate_limit_reached" , "client has reached his join attempt limit" },
|
{0x0212, "client_join_rate_limit_reached" , "client has reached his join attempt limit" },
|
||||||
{0x0213, "client_is_already_member_of_group" , "client is already a member of the group" },
|
{0x0213, "client_is_already_member_of_group" , "client is already a member of the group" },
|
||||||
{0x0213, "client_is_not_member_of_group" , "client is not a member of the group" },
|
{0x0214, "client_is_not_member_of_group" , "client is not a member of the group" },
|
||||||
|
{0x0215, "client_type_is_not_allowed" , "client type is not allowed to join the server" },
|
||||||
|
|
||||||
{0x0300, "channel_invalid_id" , "invalid channelID" },
|
{0x0300, "channel_invalid_id" , "invalid channelID" },
|
||||||
{0x0301, "channel_protocol_limit_reached" , "max channels protocol limit reached" },
|
{0x0301, "channel_protocol_limit_reached" , "max channels protocol limit reached" },
|
||||||
|
@ -49,6 +49,7 @@ namespace ts {
|
|||||||
client_join_rate_limit_reached = 0x0212,
|
client_join_rate_limit_reached = 0x0212,
|
||||||
client_is_already_member_of_group = 0x0213,
|
client_is_already_member_of_group = 0x0213,
|
||||||
client_is_not_member_of_group = 0x0214,
|
client_is_not_member_of_group = 0x0214,
|
||||||
|
client_type_is_not_allowed = 0x0215,
|
||||||
|
|
||||||
channel_invalid_id = 0x300,
|
channel_invalid_id = 0x300,
|
||||||
channel_protocol_limit_reached = 0x301,
|
channel_protocol_limit_reached = 0x301,
|
||||||
|
@ -24,6 +24,7 @@ namespace ts {
|
|||||||
class ProxiedEventEntry : public event::EventEntry {
|
class ProxiedEventEntry : public event::EventEntry {
|
||||||
public:
|
public:
|
||||||
using callback_t = void(class_t::*)(const std::chrono::system_clock::time_point &);
|
using callback_t = void(class_t::*)(const std::chrono::system_clock::time_point &);
|
||||||
|
using static_callback_t = void(*)(class_t *, const std::chrono::system_clock::time_point &);
|
||||||
|
|
||||||
ProxiedEventEntry(const std::shared_ptr<class_t>& _instance, callback_t callback) : instance(_instance), callback(callback) { }
|
ProxiedEventEntry(const std::shared_ptr<class_t>& _instance, callback_t callback) : instance(_instance), callback(callback) { }
|
||||||
|
|
||||||
@ -35,7 +36,8 @@ namespace ts {
|
|||||||
if(!_instance)
|
if(!_instance)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
((void(*)(class_t*, const std::chrono::system_clock::time_point &)) (void*) this->callback)(&*_instance, point);
|
auto callback_ptr = (void**) &this->callback;
|
||||||
|
(*(static_callback_t*) callback_ptr)(&*_instance, point);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1120,7 +1120,6 @@ void v2::PermissionManager::load_permission(const ts::permission::PermissionType
|
|||||||
permission_container->flags.grant_set = flag_grant;
|
permission_container->flags.grant_set = flag_grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr v2::PermissionFlags empty_flags = {false, false, false, false, false, false, 0};
|
|
||||||
const v2::PermissionFlags v2::PermissionManager::permission_flags(const ts::permission::PermissionType &permission) {
|
const v2::PermissionFlags v2::PermissionManager::permission_flags(const ts::permission::PermissionType &permission) {
|
||||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||||
return empty_flags;
|
return empty_flags;
|
||||||
@ -1175,7 +1174,6 @@ const v2::PermissionFlaggedValue v2::PermissionManager::permission_granted_flagg
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr v2::PermissionContainer empty_channel_permission = {empty_flags, v2::empty_permission_values};
|
|
||||||
const v2::PermissionContainer v2::PermissionManager::channel_permission(const PermissionType &permission, ts::ChannelId channel_id) {
|
const v2::PermissionContainer v2::PermissionManager::channel_permission(const PermissionType &permission, ts::ChannelId channel_id) {
|
||||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||||
return empty_channel_permission;
|
return empty_channel_permission;
|
||||||
|
@ -775,6 +775,8 @@ namespace ts {
|
|||||||
ChannelId channel_id;
|
ChannelId channel_id;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(ChannelPermissionContainer) == 19);
|
static_assert(sizeof(ChannelPermissionContainer) == 19);
|
||||||
|
static constexpr v2::PermissionFlags empty_flags = {false, false, false, false, false, false, false};
|
||||||
|
static constexpr v2::PermissionContainer empty_channel_permission = {empty_flags, v2::empty_permission_values};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
@ -216,24 +216,24 @@ namespace ts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t IncomingClientPacketParser::packet_id() const { return be2le16(this->_buffer.data_ptr<uint8_t>(), IncomingClientPacketParser::kHeaderOffset + 0); }
|
uint16_t ClientPacketParser::packet_id() const { return be2le16(this->_buffer.data_ptr<uint8_t>(), ClientPacketParser::kHeaderOffset + 0); }
|
||||||
uint16_t IncomingClientPacketParser::client_id() const { return be2le16(this->_buffer.data_ptr<uint8_t>(), IncomingClientPacketParser::kHeaderOffset + 2); }
|
uint16_t ClientPacketParser::client_id() const { return be2le16(this->_buffer.data_ptr<uint8_t>(), ClientPacketParser::kHeaderOffset + 2); }
|
||||||
uint8_t IncomingClientPacketParser::type() const { return this->_buffer[IncomingClientPacketParser::kHeaderOffset + 4] & 0xF; }
|
uint8_t ClientPacketParser::type() const { return (uint8_t) this->_buffer[ClientPacketParser::kHeaderOffset + 4] & 0xFU; }
|
||||||
uint8_t IncomingClientPacketParser::flags() const { return this->_buffer[IncomingClientPacketParser::kHeaderOffset + 4] & 0xF0; }
|
uint8_t ClientPacketParser::flags() const { return (uint8_t) this->_buffer[ClientPacketParser::kHeaderOffset + 4] & 0xF0U; }
|
||||||
|
|
||||||
bool IncomingClientPacketParser::is_encrypted() const {
|
bool ClientPacketParser::is_encrypted() const {
|
||||||
if(this->decrypted) return false;
|
if(this->decrypted) return false;
|
||||||
|
|
||||||
return (this->flags() & PacketFlag::Unencrypted) == 0;
|
return (this->flags() & PacketFlag::Unencrypted) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IncomingClientPacketParser::is_compressed() const {
|
bool ClientPacketParser::is_compressed() const {
|
||||||
if(this->uncompressed) return false;
|
if(this->uncompressed) return false;
|
||||||
|
|
||||||
return (this->flags() & PacketFlag::Compressed) > 0;
|
return (this->flags() & PacketFlag::Compressed) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IncomingClientPacketParser::is_fragmented() const {
|
bool ClientPacketParser::is_fragmented() const {
|
||||||
if(this->defragmented) return false;
|
if(this->defragmented) return false;
|
||||||
|
|
||||||
return (this->flags() & PacketFlag::Fragmented) > 0;
|
return (this->flags() & PacketFlag::Fragmented) > 0;
|
||||||
|
@ -286,14 +286,14 @@ namespace ts {
|
|||||||
void setPacketId(uint16_t, uint16_t) override;
|
void setPacketId(uint16_t, uint16_t) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IncomingClientPacketParser {
|
class ClientPacketParser {
|
||||||
public:
|
public:
|
||||||
constexpr static auto kHeaderOffset = 8;
|
constexpr static auto kHeaderOffset = 8;
|
||||||
constexpr static auto kHeaderLength = CLIENT_HEADER_SIZE;
|
constexpr static auto kHeaderLength = CLIENT_HEADER_SIZE;
|
||||||
|
|
||||||
constexpr static auto kPayloadOffset = kHeaderOffset + CLIENT_HEADER_SIZE;
|
constexpr static auto kPayloadOffset = kHeaderOffset + CLIENT_HEADER_SIZE;
|
||||||
explicit IncomingClientPacketParser(pipes::buffer_view buffer) : _buffer{std::move(buffer)} {}
|
explicit ClientPacketParser(pipes::buffer_view buffer) : _buffer{std::move(buffer)} {}
|
||||||
IncomingClientPacketParser(const IncomingClientPacketParser&) = delete;
|
ClientPacketParser(const ClientPacketParser&) = delete;
|
||||||
|
|
||||||
[[nodiscard]] inline bool valid() const {
|
[[nodiscard]] inline bool valid() const {
|
||||||
if(this->_buffer.length() < kPayloadOffset) return false;
|
if(this->_buffer.length() < kPayloadOffset) return false;
|
||||||
@ -304,8 +304,8 @@ namespace ts {
|
|||||||
[[nodiscard]] inline void* mutable_data_ptr() { return (void*) this->_buffer.data_ptr(); }
|
[[nodiscard]] inline void* mutable_data_ptr() { return (void*) this->_buffer.data_ptr(); }
|
||||||
|
|
||||||
[[nodiscard]] inline pipes::buffer_view buffer() const { return this->_buffer; }
|
[[nodiscard]] inline pipes::buffer_view buffer() const { return this->_buffer; }
|
||||||
[[nodiscard]] inline const pipes::buffer_view mac() const { return this->_buffer.view(0, 8); }
|
[[nodiscard]] inline pipes::buffer_view mac() const { return this->_buffer.view(0, 8); }
|
||||||
[[nodiscard]] inline const pipes::buffer_view payload() const { return this->_buffer.view(kPayloadOffset); }
|
[[nodiscard]] inline pipes::buffer_view payload() const { return this->_buffer.view(kPayloadOffset); }
|
||||||
[[nodiscard]] inline size_t payload_length() const { return this->_buffer.length() - kPayloadOffset; }
|
[[nodiscard]] inline size_t payload_length() const { return this->_buffer.length() - kPayloadOffset; }
|
||||||
|
|
||||||
[[nodiscard]] uint16_t client_id() const;
|
[[nodiscard]] uint16_t client_id() const;
|
||||||
@ -318,7 +318,7 @@ namespace ts {
|
|||||||
[[nodiscard]] bool is_fragmented() const;
|
[[nodiscard]] bool is_fragmented() const;
|
||||||
|
|
||||||
[[nodiscard]] uint16_t estimated_generation() const { return this->generation; }
|
[[nodiscard]] uint16_t estimated_generation() const { return this->generation; }
|
||||||
void set_estimated_generation(uint16_t generation) { this->generation = generation; }
|
void set_estimated_generation(uint16_t gen) { this->generation = gen; }
|
||||||
|
|
||||||
inline void set_decrypted() { this->decrypted = true; }
|
inline void set_decrypted() { this->decrypted = true; }
|
||||||
inline void set_uncompressed() { this->uncompressed = true; }
|
inline void set_uncompressed() { this->uncompressed = true; }
|
||||||
|
@ -198,6 +198,7 @@ operator type(){ \
|
|||||||
void push_bulk_front();
|
void push_bulk_front();
|
||||||
|
|
||||||
bool hasParm(std::string);
|
bool hasParm(std::string);
|
||||||
|
void clear_parameters() { this->paramethers.clear(); }
|
||||||
std::deque<std::string> parms();
|
std::deque<std::string> parms();
|
||||||
void enableParm(const std::string& key){ toggleParm(key, true); }
|
void enableParm(const std::string& key){ toggleParm(key, true); }
|
||||||
void disableParm(const std::string& key){ toggleParm(key, false); }
|
void disableParm(const std::string& key){ toggleParm(key, false); }
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <mysql/mysql.h>
|
#include <mysql.h>
|
||||||
|
|
||||||
#define CR_CONNECTION_ERROR (2002)
|
#define CR_CONNECTION_ERROR (2002)
|
||||||
#define CR_SERVER_GONE_ERROR (2006)
|
#define CR_SERVER_GONE_ERROR (2006)
|
||||||
@ -215,7 +215,7 @@ result MySQLManager::connect(const std::string &url) {
|
|||||||
return {-1, "failed to allocate connection " + to_string(index)};
|
return {-1, "failed to allocate connection " + to_string(index)};
|
||||||
|
|
||||||
{
|
{
|
||||||
my_bool reconnect = 1;
|
bool reconnect{true};
|
||||||
mysql_options(connection->handle, MYSQL_OPT_RECONNECT, &reconnect);
|
mysql_options(connection->handle, MYSQL_OPT_RECONNECT, &reconnect);
|
||||||
}
|
}
|
||||||
mysql_options(connection->handle, MYSQL_SET_CHARSET_NAME, "utf8");
|
mysql_options(connection->handle, MYSQL_SET_CHARSET_NAME, "utf8");
|
||||||
|
@ -7,70 +7,68 @@
|
|||||||
#include "sql/SqlQuery.h"
|
#include "sql/SqlQuery.h"
|
||||||
|
|
||||||
#include "../../misc/spin_lock.h"
|
#include "../../misc/spin_lock.h"
|
||||||
#include <mysql/mysql.h>
|
#include <mysql.h>
|
||||||
|
|
||||||
#define ERROR_MYSQL_MISSING_DRIVER -1
|
#define ERROR_MYSQL_MISSING_DRIVER -1
|
||||||
#define ERROR_MYSQL_INVLID_CONNECT -2
|
#define ERROR_MYSQL_INVLID_CONNECT -2
|
||||||
#define ERROR_MYSQL_INVLID_PROPERTIES -3
|
#define ERROR_MYSQL_INVLID_PROPERTIES -3
|
||||||
#define ERROR_MYSQL_INVLID_URL -4
|
#define ERROR_MYSQL_INVLID_URL -4
|
||||||
|
|
||||||
namespace sql {
|
namespace sql::mysql {
|
||||||
namespace mysql {
|
class MySQLManager;
|
||||||
class MySQLManager;
|
|
||||||
|
|
||||||
bool evaluate_sql_query(std::string& sql, const std::vector<variable>& vars, std::vector<variable>& result);
|
bool evaluate_sql_query(std::string& sql, const std::vector<variable>& vars, std::vector<variable>& result);
|
||||||
|
|
||||||
class MySQLCommand : public CommandData { };
|
class MySQLCommand : public CommandData { };
|
||||||
|
|
||||||
struct Connection {
|
struct Connection {
|
||||||
MYSQL* handle = nullptr;
|
MYSQL* handle = nullptr;
|
||||||
|
|
||||||
spin_lock used_lock;
|
spin_lock used_lock;
|
||||||
bool used = false;
|
bool used = false;
|
||||||
|
|
||||||
~Connection();
|
~Connection();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AcquiredConnection {
|
struct AcquiredConnection {
|
||||||
MySQLManager* owner;
|
MySQLManager* owner;
|
||||||
std::shared_ptr<Connection> connection;
|
std::shared_ptr<Connection> connection;
|
||||||
|
|
||||||
AcquiredConnection(MySQLManager* owner, std::shared_ptr<Connection> );
|
AcquiredConnection(MySQLManager* owner, std::shared_ptr<Connection> );
|
||||||
~AcquiredConnection();
|
~AcquiredConnection();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MySQLManager : public SqlManager {
|
class MySQLManager : public SqlManager {
|
||||||
friend struct AcquiredConnection;
|
friend struct AcquiredConnection;
|
||||||
public:
|
public:
|
||||||
//typedef std::function<void(const std::shared_ptr<ConnectionEntry>&)> ListenerConnectionDisconnect;
|
//typedef std::function<void(const std::shared_ptr<ConnectionEntry>&)> ListenerConnectionDisconnect;
|
||||||
//typedef std::function<void(const std::shared_ptr<ConnectionEntry>&)> ListenerConnectionCreated;
|
//typedef std::function<void(const std::shared_ptr<ConnectionEntry>&)> ListenerConnectionCreated;
|
||||||
|
|
||||||
typedef std::function<void()> ListenerConnected;
|
typedef std::function<void()> ListenerConnected;
|
||||||
typedef std::function<void(bool /* wanted */)> ListenerDisconnected;
|
typedef std::function<void(bool /* wanted */)> ListenerDisconnected;
|
||||||
|
|
||||||
MySQLManager();
|
MySQLManager();
|
||||||
virtual ~MySQLManager();
|
virtual ~MySQLManager();
|
||||||
|
|
||||||
result connect(const std::string &string) override;
|
result connect(const std::string &string) override;
|
||||||
bool connected() override;
|
bool connected() override;
|
||||||
result disconnect() override;
|
result disconnect() override;
|
||||||
|
|
||||||
ListenerDisconnected listener_disconnected;
|
ListenerDisconnected listener_disconnected;
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<CommandData> copyCommandData(std::shared_ptr<CommandData> ptr) override;
|
std::shared_ptr<CommandData> copyCommandData(std::shared_ptr<CommandData> ptr) override;
|
||||||
std::shared_ptr<CommandData> allocateCommandData() override;
|
std::shared_ptr<CommandData> allocateCommandData() override;
|
||||||
result executeCommand(std::shared_ptr<CommandData> ptr) override;
|
result executeCommand(std::shared_ptr<CommandData> ptr) override;
|
||||||
result queryCommand(std::shared_ptr<CommandData> ptr, const QueryCallback &fn) override;
|
result queryCommand(std::shared_ptr<CommandData> ptr, const QueryCallback &fn) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<AcquiredConnection> next_connection();
|
std::unique_ptr<AcquiredConnection> next_connection();
|
||||||
void connection_closed(const std::shared_ptr<Connection>& /* connection */);
|
void connection_closed(const std::shared_ptr<Connection>& /* connection */);
|
||||||
|
|
||||||
std::mutex connections_lock;
|
std::mutex connections_lock;
|
||||||
std::condition_variable connections_condition;
|
std::condition_variable connections_condition;
|
||||||
std::deque<std::shared_ptr<Connection>> connections;
|
std::deque<std::shared_ptr<Connection>> connections;
|
||||||
|
|
||||||
bool disconnecting = false;
|
bool disconnecting = false;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user