diff --git a/CMakeLists.txt b/CMakeLists.txt index e88b70e..6c27c5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,16 +188,6 @@ if(HAVE_OPEN_SSL) ) 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}) target_link_libraries(TeaSpeak PUBLIC threadpool::static jsoncpp_lib) target_compile_options(TeaSpeak PRIVATE "-Wall") diff --git a/src/Error.cpp b/src/Error.cpp index 9bb5dbc..cc3710b 100644 --- a/src/Error.cpp +++ b/src/Error.cpp @@ -36,7 +36,8 @@ const std::vector ts::avariableErrors = { {0x0211, "client_unknown" , "client is not known" }, {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_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" }, {0x0301, "channel_protocol_limit_reached" , "max channels protocol limit reached" }, diff --git a/src/Error.h b/src/Error.h index c2feb38..c4b8af7 100644 --- a/src/Error.h +++ b/src/Error.h @@ -49,6 +49,7 @@ namespace ts { client_join_rate_limit_reached = 0x0212, client_is_already_member_of_group = 0x0213, client_is_not_member_of_group = 0x0214, + client_type_is_not_allowed = 0x0215, channel_invalid_id = 0x300, channel_protocol_limit_reached = 0x301, diff --git a/src/EventLoop.h b/src/EventLoop.h index b0a7a54..9696f43 100644 --- a/src/EventLoop.h +++ b/src/EventLoop.h @@ -24,6 +24,7 @@ namespace ts { class ProxiedEventEntry : public event::EventEntry { public: 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& _instance, callback_t callback) : instance(_instance), callback(callback) { } @@ -35,7 +36,8 @@ namespace ts { if(!_instance) 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); } }; diff --git a/src/PermissionManager.cpp b/src/PermissionManager.cpp index c232cc2..688383e 100644 --- a/src/PermissionManager.cpp +++ b/src/PermissionManager.cpp @@ -1120,7 +1120,6 @@ void v2::PermissionManager::load_permission(const ts::permission::PermissionType 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) { if(permission < 0 || permission >= PermissionType::permission_id_max) return empty_flags; @@ -1175,7 +1174,6 @@ const v2::PermissionFlaggedValue v2::PermissionManager::permission_granted_flagg 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) { if(permission < 0 || permission >= PermissionType::permission_id_max) return empty_channel_permission; diff --git a/src/PermissionManager.h b/src/PermissionManager.h index 4d43de4..079185e 100644 --- a/src/PermissionManager.h +++ b/src/PermissionManager.h @@ -775,6 +775,8 @@ namespace ts { ChannelId channel_id; }; 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) diff --git a/src/protocol/Packet.cpp b/src/protocol/Packet.cpp index f863a37..a5c7582 100644 --- a/src/protocol/Packet.cpp +++ b/src/protocol/Packet.cpp @@ -216,24 +216,24 @@ namespace ts { } - uint16_t IncomingClientPacketParser::packet_id() const { return be2le16(this->_buffer.data_ptr(), IncomingClientPacketParser::kHeaderOffset + 0); } - uint16_t IncomingClientPacketParser::client_id() const { return be2le16(this->_buffer.data_ptr(), IncomingClientPacketParser::kHeaderOffset + 2); } - uint8_t IncomingClientPacketParser::type() const { return this->_buffer[IncomingClientPacketParser::kHeaderOffset + 4] & 0xF; } - uint8_t IncomingClientPacketParser::flags() const { return this->_buffer[IncomingClientPacketParser::kHeaderOffset + 4] & 0xF0; } + uint16_t ClientPacketParser::packet_id() const { return be2le16(this->_buffer.data_ptr(), ClientPacketParser::kHeaderOffset + 0); } + uint16_t ClientPacketParser::client_id() const { return be2le16(this->_buffer.data_ptr(), ClientPacketParser::kHeaderOffset + 2); } + uint8_t ClientPacketParser::type() const { return (uint8_t) this->_buffer[ClientPacketParser::kHeaderOffset + 4] & 0xFU; } + 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; return (this->flags() & PacketFlag::Unencrypted) == 0; } - bool IncomingClientPacketParser::is_compressed() const { + bool ClientPacketParser::is_compressed() const { if(this->uncompressed) return false; return (this->flags() & PacketFlag::Compressed) > 0; } - bool IncomingClientPacketParser::is_fragmented() const { + bool ClientPacketParser::is_fragmented() const { if(this->defragmented) return false; return (this->flags() & PacketFlag::Fragmented) > 0; diff --git a/src/protocol/Packet.h b/src/protocol/Packet.h index 8729393..5581be7 100644 --- a/src/protocol/Packet.h +++ b/src/protocol/Packet.h @@ -286,14 +286,14 @@ namespace ts { void setPacketId(uint16_t, uint16_t) override; }; - class IncomingClientPacketParser { + class ClientPacketParser { public: constexpr static auto kHeaderOffset = 8; constexpr static auto kHeaderLength = CLIENT_HEADER_SIZE; constexpr static auto kPayloadOffset = kHeaderOffset + CLIENT_HEADER_SIZE; - explicit IncomingClientPacketParser(pipes::buffer_view buffer) : _buffer{std::move(buffer)} {} - IncomingClientPacketParser(const IncomingClientPacketParser&) = delete; + explicit ClientPacketParser(pipes::buffer_view buffer) : _buffer{std::move(buffer)} {} + ClientPacketParser(const ClientPacketParser&) = delete; [[nodiscard]] inline bool valid() const { 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 pipes::buffer_view buffer() const { return this->_buffer; } - [[nodiscard]] inline const 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 mac() const { return this->_buffer.view(0, 8); } + [[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]] uint16_t client_id() const; @@ -318,7 +318,7 @@ namespace ts { [[nodiscard]] bool is_fragmented() const; [[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_uncompressed() { this->uncompressed = true; } diff --git a/src/query/Command.h b/src/query/Command.h index 0cf6c88..215f4b0 100644 --- a/src/query/Command.h +++ b/src/query/Command.h @@ -198,6 +198,7 @@ operator type(){ \ void push_bulk_front(); bool hasParm(std::string); + void clear_parameters() { this->paramethers.clear(); } std::deque parms(); void enableParm(const std::string& key){ toggleParm(key, true); } void disableParm(const std::string& key){ toggleParm(key, false); } diff --git a/src/sql/mysql/MySQL.cpp b/src/sql/mysql/MySQL.cpp index f3e8635..ac33c39 100644 --- a/src/sql/mysql/MySQL.cpp +++ b/src/sql/mysql/MySQL.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #define CR_CONNECTION_ERROR (2002) #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)}; { - my_bool reconnect = 1; + bool reconnect{true}; mysql_options(connection->handle, MYSQL_OPT_RECONNECT, &reconnect); } mysql_options(connection->handle, MYSQL_SET_CHARSET_NAME, "utf8"); diff --git a/src/sql/mysql/MySQL.h b/src/sql/mysql/MySQL.h index dc1df66..8986774 100644 --- a/src/sql/mysql/MySQL.h +++ b/src/sql/mysql/MySQL.h @@ -7,70 +7,68 @@ #include "sql/SqlQuery.h" #include "../../misc/spin_lock.h" -#include +#include #define ERROR_MYSQL_MISSING_DRIVER -1 #define ERROR_MYSQL_INVLID_CONNECT -2 #define ERROR_MYSQL_INVLID_PROPERTIES -3 #define ERROR_MYSQL_INVLID_URL -4 -namespace sql { - namespace mysql { - class MySQLManager; +namespace sql::mysql { + class MySQLManager; - bool evaluate_sql_query(std::string& sql, const std::vector& vars, std::vector& result); + bool evaluate_sql_query(std::string& sql, const std::vector& vars, std::vector& result); - class MySQLCommand : public CommandData { }; + class MySQLCommand : public CommandData { }; - struct Connection { - MYSQL* handle = nullptr; + struct Connection { + MYSQL* handle = nullptr; - spin_lock used_lock; - bool used = false; + spin_lock used_lock; + bool used = false; - ~Connection(); - }; + ~Connection(); + }; - struct AcquiredConnection { - MySQLManager* owner; - std::shared_ptr connection; + struct AcquiredConnection { + MySQLManager* owner; + std::shared_ptr connection; - AcquiredConnection(MySQLManager* owner, std::shared_ptr ); - ~AcquiredConnection(); - }; + AcquiredConnection(MySQLManager* owner, std::shared_ptr ); + ~AcquiredConnection(); + }; - class MySQLManager : public SqlManager { - friend struct AcquiredConnection; - public: - //typedef std::function&)> ListenerConnectionDisconnect; - //typedef std::function&)> ListenerConnectionCreated; + class MySQLManager : public SqlManager { + friend struct AcquiredConnection; + public: + //typedef std::function&)> ListenerConnectionDisconnect; + //typedef std::function&)> ListenerConnectionCreated; - typedef std::function ListenerConnected; - typedef std::function ListenerDisconnected; + typedef std::function ListenerConnected; + typedef std::function ListenerDisconnected; - MySQLManager(); - virtual ~MySQLManager(); + MySQLManager(); + virtual ~MySQLManager(); - result connect(const std::string &string) override; - bool connected() override; - result disconnect() override; + result connect(const std::string &string) override; + bool connected() override; + result disconnect() override; - ListenerDisconnected listener_disconnected; - protected: - std::shared_ptr copyCommandData(std::shared_ptr ptr) override; - std::shared_ptr allocateCommandData() override; - result executeCommand(std::shared_ptr ptr) override; - result queryCommand(std::shared_ptr ptr, const QueryCallback &fn) override; + ListenerDisconnected listener_disconnected; + protected: + std::shared_ptr copyCommandData(std::shared_ptr ptr) override; + std::shared_ptr allocateCommandData() override; + result executeCommand(std::shared_ptr ptr) override; + result queryCommand(std::shared_ptr ptr, const QueryCallback &fn) override; - public: - std::unique_ptr next_connection(); - void connection_closed(const std::shared_ptr& /* connection */); + public: + std::unique_ptr next_connection(); + void connection_closed(const std::shared_ptr& /* connection */); - std::mutex connections_lock; - std::condition_variable connections_condition; - std::deque> connections; + std::mutex connections_lock; + std::condition_variable connections_condition; + std::deque> connections; - bool disconnecting = false; - }; - } + bool disconnecting = false; + }; } \ No newline at end of file