Begining with the new VS structure
This commit is contained in:
parent
ece70e4df4
commit
ae4751ee6f
@ -117,7 +117,7 @@ set(SOURCE_FILES
|
||||
src/protocol/Packet.cpp
|
||||
src/protocol/buffers.cpp
|
||||
src/protocol/buffers_allocator_c.cpp
|
||||
src/PermissionManager.cpp
|
||||
src/PermissionRegister.cpp
|
||||
src/Properties.cpp
|
||||
src/BasicChannel.cpp
|
||||
src/Error.cpp
|
||||
@ -153,7 +153,7 @@ set(HEADER_FILES
|
||||
src/log/translation.h
|
||||
src/log/LogUtils.h
|
||||
|
||||
src/PermissionManager.h
|
||||
src/PermissionRegister.h
|
||||
src/protocol/buffers.h
|
||||
src/protocol/Packet.h
|
||||
src/Properties.h
|
||||
|
@ -21,7 +21,7 @@ BasicChannel::BasicChannel(ChannelId parentId, ChannelId channelId) {
|
||||
this->properties()[property::CHANNEL_PID] = parentId;
|
||||
}
|
||||
|
||||
void BasicChannel::setPermissionManager(const std::shared_ptr<permission::v2::PermissionManager>& manager) {
|
||||
void BasicChannel::setPermissionManager(const std::shared_ptr<permission::v2::PermissionRegister>& manager) {
|
||||
this->_permissions = manager;
|
||||
this->update_properties_from_permissions();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "channel/TreeView.h"
|
||||
#include "Definitions.h"
|
||||
#include "Properties.h"
|
||||
#include "PermissionManager.h"
|
||||
#include "PermissionRegister.h"
|
||||
|
||||
namespace ts {
|
||||
|
||||
@ -74,8 +74,8 @@ namespace ts {
|
||||
return this->permission_granted(permission::i_client_needed_talk_power, granted_value, false);
|
||||
}
|
||||
|
||||
ts_always_inline std::shared_ptr<permission::v2::PermissionManager> permissions(){ return this->_permissions; }
|
||||
virtual void setPermissionManager(const std::shared_ptr<permission::v2::PermissionManager>&);
|
||||
ts_always_inline std::shared_ptr<permission::v2::PermissionRegister> permissions(){ return this->_permissions; }
|
||||
virtual void setPermissionManager(const std::shared_ptr<permission::v2::PermissionRegister>&);
|
||||
virtual void setProperties(const std::shared_ptr<Properties>&);
|
||||
private:
|
||||
ts_always_inline
|
||||
@ -98,7 +98,7 @@ namespace ts {
|
||||
protected:
|
||||
std::weak_ptr<TreeView::LinkedTreeEntry> _link;
|
||||
std::shared_ptr<Properties> _properties;
|
||||
std::shared_ptr<permission::v2::PermissionManager> _permissions;
|
||||
std::shared_ptr<permission::v2::PermissionRegister> _permissions;
|
||||
|
||||
ChannelId _channel_order = 0;
|
||||
ChannelId _channel_id = 0;
|
||||
|
@ -94,7 +94,9 @@ namespace ts {
|
||||
CLIENT_WEB,
|
||||
CLIENT_MUSIC,
|
||||
CLIENT_TEASPEAK,
|
||||
MAX
|
||||
MAX,
|
||||
|
||||
UNKNOWN = 0xFF
|
||||
};
|
||||
|
||||
enum ConnectionState {
|
||||
|
@ -1057,17 +1057,17 @@ deque<update::UpdateEntry> update::migrate = {
|
||||
AQB("b_client_ban_trigger_list")
|
||||
};
|
||||
|
||||
v2::PermissionManager::PermissionManager() {
|
||||
v2::PermissionRegister::PermissionRegister() {
|
||||
memset(this->block_use_count, 0, sizeof(this->block_use_count));
|
||||
memset(this->block_containers, 0, sizeof(this->block_containers));
|
||||
}
|
||||
|
||||
v2::PermissionManager::~PermissionManager() {
|
||||
v2::PermissionRegister::~PermissionRegister() {
|
||||
for(auto& block : this->block_containers)
|
||||
delete block;
|
||||
}
|
||||
|
||||
void v2::PermissionManager::load_permission(const ts::permission::PermissionType &permission, const ts::permission::v2::PermissionValues &values, bool flag_skip, bool flag_negate, bool flag_value, bool flag_grant) {
|
||||
void v2::PermissionRegister::load_permission(const ts::permission::PermissionType &permission, const ts::permission::v2::PermissionValues &values, bool flag_skip, bool flag_negate, bool flag_value, bool flag_grant) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return;
|
||||
|
||||
@ -1084,7 +1084,7 @@ void v2::PermissionManager::load_permission(const ts::permission::PermissionType
|
||||
this->unref_block(block);
|
||||
}
|
||||
|
||||
void v2::PermissionManager::load_permission(const ts::permission::PermissionType &permission, const ts::permission::v2::PermissionValues &values, ChannelId channel_id, bool flag_skip, bool flag_negate, bool flag_value, bool flag_grant) {
|
||||
void v2::PermissionRegister::load_permission(const ts::permission::PermissionType &permission, const ts::permission::v2::PermissionValues &values, ChannelId channel_id, bool flag_skip, bool flag_negate, bool flag_value, bool flag_grant) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return;
|
||||
|
||||
@ -1120,7 +1120,7 @@ void v2::PermissionManager::load_permission(const ts::permission::PermissionType
|
||||
permission_container->flags.grant_set = flag_grant;
|
||||
}
|
||||
|
||||
const v2::PermissionFlags v2::PermissionManager::permission_flags(const ts::permission::PermissionType &permission) {
|
||||
const v2::PermissionFlags v2::PermissionRegister::permission_flags(const ts::permission::PermissionType &permission) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return empty_flags;
|
||||
|
||||
@ -1133,7 +1133,7 @@ const v2::PermissionFlags v2::PermissionManager::permission_flags(const ts::perm
|
||||
return result;
|
||||
}
|
||||
|
||||
const v2::PermissionValues v2::PermissionManager::permission_values(const ts::permission::PermissionType &permission) {
|
||||
const v2::PermissionValues v2::PermissionRegister::permission_values(const ts::permission::PermissionType &permission) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return v2::empty_permission_values;
|
||||
|
||||
@ -1146,7 +1146,7 @@ const v2::PermissionValues v2::PermissionManager::permission_values(const ts::pe
|
||||
return data;
|
||||
}
|
||||
|
||||
const v2::PermissionFlaggedValue v2::PermissionManager::permission_value_flagged(const ts::permission::PermissionType &permission) {
|
||||
const v2::PermissionFlaggedValue v2::PermissionRegister::permission_value_flagged(const ts::permission::PermissionType &permission) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return v2::empty_permission_flagged_value;
|
||||
|
||||
@ -1160,7 +1160,7 @@ const v2::PermissionFlaggedValue v2::PermissionManager::permission_value_flagged
|
||||
return result;
|
||||
}
|
||||
|
||||
const v2::PermissionFlaggedValue v2::PermissionManager::permission_granted_flagged(const ts::permission::PermissionType &permission) {
|
||||
const v2::PermissionFlaggedValue v2::PermissionRegister::permission_granted_flagged(const ts::permission::PermissionType &permission) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return v2::empty_permission_flagged_value;
|
||||
|
||||
@ -1174,7 +1174,7 @@ const v2::PermissionFlaggedValue v2::PermissionManager::permission_granted_flagg
|
||||
return result;
|
||||
}
|
||||
|
||||
const v2::PermissionContainer v2::PermissionManager::channel_permission(const PermissionType &permission, ts::ChannelId channel_id) {
|
||||
const v2::PermissionContainer v2::PermissionRegister::channel_permission(const PermissionType &permission, ts::ChannelId channel_id) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return empty_channel_permission;
|
||||
|
||||
@ -1185,7 +1185,7 @@ const v2::PermissionContainer v2::PermissionManager::channel_permission(const Pe
|
||||
return empty_channel_permission;
|
||||
}
|
||||
|
||||
void v2::PermissionManager::set_permission(const PermissionType &permission, const v2::PermissionValues &values, const v2::PermissionUpdateType &action_value, const v2::PermissionUpdateType &action_grant, int flag_skip, int flag_negate) {
|
||||
void v2::PermissionRegister::set_permission(const PermissionType &permission, const v2::PermissionValues &values, const v2::PermissionUpdateType &action_value, const v2::PermissionUpdateType &action_grant, int flag_skip, int flag_negate) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return;
|
||||
|
||||
@ -1227,7 +1227,7 @@ void v2::PermissionManager::set_permission(const PermissionType &permission, con
|
||||
this->trigger_db_update();
|
||||
}
|
||||
|
||||
void v2::PermissionManager::set_channel_permission(const PermissionType &permission, ChannelId channel_id, const v2::PermissionValues &values, const v2::PermissionUpdateType &action_value, const v2::PermissionUpdateType &action_grant, int flag_skip, int flag_negate) {
|
||||
void v2::PermissionRegister::set_channel_permission(const PermissionType &permission, ChannelId channel_id, const v2::PermissionValues &values, const v2::PermissionUpdateType &action_value, const v2::PermissionUpdateType &action_grant, int flag_skip, int flag_negate) {
|
||||
if(permission < 0 || permission >= PermissionType::permission_id_max)
|
||||
return;
|
||||
|
||||
@ -1303,7 +1303,7 @@ void v2::PermissionManager::set_channel_permission(const PermissionType &permiss
|
||||
this->trigger_db_update();
|
||||
}
|
||||
|
||||
const std::vector<std::tuple<PermissionType, const v2::PermissionContainer>> v2::PermissionManager::permissions() {
|
||||
const std::vector<std::tuple<PermissionType, const v2::PermissionContainer>> v2::PermissionRegister::permissions() {
|
||||
std::unique_lock use_lock(this->block_use_count_lock);
|
||||
decltype(this->block_containers) block_containers; /* save the states/nullptr's */
|
||||
memcpy(block_containers, this->block_containers, sizeof(this->block_containers));
|
||||
@ -1344,7 +1344,7 @@ const std::vector<std::tuple<PermissionType, const v2::PermissionContainer>> v2:
|
||||
return result;
|
||||
}
|
||||
|
||||
const vector<tuple<PermissionType, const v2::PermissionContainer>> v2::PermissionManager::channel_permissions(ts::ChannelId channel_id) {
|
||||
const vector<tuple<PermissionType, const v2::PermissionContainer>> v2::PermissionRegister::channel_permissions(ts::ChannelId channel_id) {
|
||||
shared_lock channel_perm_lock(this->channel_list_lock);
|
||||
|
||||
vector<tuple<PermissionType, const v2::PermissionContainer>> result;
|
||||
@ -1354,7 +1354,7 @@ const vector<tuple<PermissionType, const v2::PermissionContainer>> v2::Permissio
|
||||
return result;
|
||||
}
|
||||
|
||||
const vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> v2::PermissionManager::channel_permissions() {
|
||||
const vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> v2::PermissionRegister::channel_permissions() {
|
||||
shared_lock channel_perm_lock(this->channel_list_lock);
|
||||
|
||||
vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> result;
|
||||
@ -1364,7 +1364,7 @@ const vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> v2
|
||||
return result;
|
||||
}
|
||||
|
||||
const std::vector<v2::PermissionDBUpdateEntry> v2::PermissionManager::flush_db_updates() {
|
||||
const std::vector<v2::PermissionDBUpdateEntry> v2::PermissionRegister::flush_db_updates() {
|
||||
if(!this->requires_db_save)
|
||||
return {};
|
||||
|
||||
@ -1481,7 +1481,7 @@ const std::vector<v2::PermissionDBUpdateEntry> v2::PermissionManager::flush_db_u
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t v2::PermissionManager::used_memory() {
|
||||
size_t v2::PermissionRegister::used_memory() {
|
||||
size_t result = sizeof(*this);
|
||||
|
||||
for (auto &block_container : block_containers) {
|
||||
@ -1498,7 +1498,7 @@ size_t v2::PermissionManager::used_memory() {
|
||||
return result;
|
||||
}
|
||||
|
||||
void v2::PermissionManager::cleanup() {
|
||||
void v2::PermissionRegister::cleanup() {
|
||||
lock_guard use_lock(this->block_use_count_lock);
|
||||
|
||||
for (auto &block_container : block_containers) {
|
@ -841,15 +841,15 @@ namespace ts {
|
||||
return permission_granted({required, true}, given, requires_given);
|
||||
}
|
||||
|
||||
class PermissionManager {
|
||||
class PermissionRegister {
|
||||
public:
|
||||
static constexpr size_t PERMISSIONS_BULK_BITS = 4; /* 16 permissions per block */
|
||||
static constexpr size_t PERMISSIONS_BULK_ENTRY_COUNT = 1 << PERMISSIONS_BULK_BITS;
|
||||
static constexpr size_t BULK_COUNT = (PermissionType::permission_id_max / (1 << PERMISSIONS_BULK_BITS)) + ((PermissionType::permission_id_max % PERMISSIONS_BULK_ENTRY_COUNT == 0) ? 0 : 1);
|
||||
static_assert(PERMISSIONS_BULK_ENTRY_COUNT * BULK_COUNT >= PermissionType::permission_id_max);
|
||||
|
||||
PermissionManager();
|
||||
virtual ~PermissionManager();
|
||||
PermissionRegister();
|
||||
virtual ~PermissionRegister();
|
||||
|
||||
/* load permissions from the database */
|
||||
void load_permission(const PermissionType&, const PermissionValues& /* values */, bool /* flag skip */, bool /* flag negate */, bool /* value present */,bool /* grant present */);
|
@ -194,14 +194,33 @@ namespace ts {
|
||||
typedef rw_mutex_impl<rw_mutex_options<true>, mutex_action_validator> rw_unsafe_mutex;
|
||||
typedef rw_safe_mutex rw_mutex;
|
||||
|
||||
struct rw_lock_defered_t {};
|
||||
struct rw_lock_shared_t {};
|
||||
struct rw_lock_exclusive_t {};
|
||||
|
||||
constexpr rw_lock_defered_t rw_lock_defered{};
|
||||
constexpr rw_lock_shared_t rw_lock_shared{};
|
||||
constexpr rw_lock_exclusive_t rw_lock_exclusive{};
|
||||
|
||||
template <typename lock_t>
|
||||
struct rwshared_lock {
|
||||
public:
|
||||
explicit rwshared_lock(lock_t& lock) : lock_{lock} {
|
||||
explicit rwshared_lock(lock_t& lock) : rwshared_lock{lock, rw_lock_shared} {}
|
||||
|
||||
explicit rwshared_lock(lock_t& lock, const rw_lock_defered_t&) : lock_{lock} {
|
||||
this->lock_type_ = unlocked;
|
||||
}
|
||||
|
||||
explicit rwshared_lock(lock_t& lock, const rw_lock_shared_t&) : lock_{lock} {
|
||||
this->lock_.lock_shared();
|
||||
this->lock_type_ = locked_shared;
|
||||
}
|
||||
|
||||
explicit rwshared_lock(lock_t& lock, const rw_lock_exclusive_t&) : lock_{lock} {
|
||||
this->lock_.lock();
|
||||
this->lock_type_ = locked_exclusive;
|
||||
}
|
||||
|
||||
~rwshared_lock() {
|
||||
if(this->lock_type_ == locked_shared) {
|
||||
this->lock_.unlock_shared();
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <misc/lambda.h>
|
||||
|
||||
#define ALLOW_STACK_ALLOCATION
|
||||
#define LOG_SQL_CMD [](const sql::result &res){ if(!res) logCritical(LOG_GENERAL, "Failed to execute sql command: " + std::to_string(res.code()) + "/" + res.msg() + " (" __FILE__ + ":" + to_string(__LINE__) + ")"); }
|
||||
#define LOG_SQL_CMD [](const sql::result &res){ if(!res) logCritical(LOG_GENERAL, "Failed to execute sql command: " + std::to_string(res.code()) + "/" + res.msg() + " (" __FILE__ + ":" + std::to_string(__LINE__) + ")"); }
|
||||
namespace sql {
|
||||
class result;
|
||||
class SqlManager;
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <src/License.h>
|
||||
#include <functional>
|
||||
#include <src/query/Command.h>
|
||||
#include "PermissionManager.h"
|
||||
#include "PermissionRegister.h"
|
||||
|
||||
#include "src/query/command_handler.h"
|
||||
#include "src/query/command_constants.h"
|
||||
|
@ -2,14 +2,14 @@
|
||||
// Created by wolverindev on 15.07.19.
|
||||
//
|
||||
|
||||
#include "PermissionManager.h"
|
||||
#include "PermissionRegister.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace ts::permission::v2;
|
||||
using PermissionType = ts::permission::PermissionType;
|
||||
|
||||
void print_permissions(PermissionManager& manager) {
|
||||
void print_permissions(PermissionRegister& manager) {
|
||||
{
|
||||
auto permissions = manager.permissions();
|
||||
cout << "Permissions: " << permissions.size() << endl;
|
||||
@ -22,7 +22,7 @@ void print_permissions(PermissionManager& manager) {
|
||||
cout << "Used memory: " << manager.used_memory() << endl;
|
||||
}
|
||||
|
||||
void print_updates(PermissionManager& manager) {
|
||||
void print_updates(PermissionRegister& manager) {
|
||||
const auto updates = manager.flush_db_updates();
|
||||
cout << "Permission updates: " << updates.size() << endl;
|
||||
for(auto& update : updates) {
|
||||
@ -40,12 +40,12 @@ Structure size of PermissionManager: 176
|
||||
Structure size of PermissionContainerBulk<16>: 192
|
||||
Structure size of PermissionContainer: 12
|
||||
*/
|
||||
cout << "Structure size of PermissionManager: " << sizeof(PermissionManager) << endl;
|
||||
cout << "Structure size of PermissionManager: " << sizeof(PermissionRegister) << endl;
|
||||
cout << "Structure size of PermissionContainerBulk<16>: " << sizeof(PermissionContainerBulk<16>) << endl;
|
||||
cout << "Structure size of PermissionContainer: " << sizeof(PermissionContainer) << endl;
|
||||
cout << "Permissions/bulk: " << PermissionManager::PERMISSIONS_BULK_ENTRY_COUNT << ". Bulks: " << PermissionManager::BULK_COUNT << " (Max permissions: " << (PermissionManager::PERMISSIONS_BULK_ENTRY_COUNT * PermissionManager::BULK_COUNT) << "; Avl: " << (uint32_t) PermissionType::permission_id_max << ")" << endl;
|
||||
cout << "Permissions/bulk: " << PermissionRegister::PERMISSIONS_BULK_ENTRY_COUNT << ". Bulks: " << PermissionRegister::BULK_COUNT << " (Max permissions: " << (PermissionRegister::PERMISSIONS_BULK_ENTRY_COUNT * PermissionRegister::BULK_COUNT) << "; Avl: " << (uint32_t) PermissionType::permission_id_max << ")" << endl;
|
||||
|
||||
PermissionManager manager{};
|
||||
PermissionRegister manager{};
|
||||
print_permissions(manager);
|
||||
manager.set_permission(PermissionType::b_client_ban_ip, {1, 0}, PermissionUpdateType::set_value, PermissionUpdateType::do_nothing);
|
||||
manager.set_channel_permission(PermissionType::b_client_ban_ip, 2, {1, 0}, PermissionUpdateType::set_value, PermissionUpdateType::do_nothing);
|
||||
|
Loading…
Reference in New Issue
Block a user