This commit is contained in:
WolverinDEV 2020-04-18 11:37:11 +02:00
parent 4b48f2741c
commit 7ebad685b1
6 changed files with 2499 additions and 2499 deletions

View File

@ -21,7 +21,7 @@ BasicChannel::BasicChannel(ChannelId parentId, ChannelId channelId) {
this->properties()[property::CHANNEL_PID] = parentId; this->properties()[property::CHANNEL_PID] = parentId;
} }
void BasicChannel::setPermissionManager(const std::shared_ptr<permission::v2::PermissionRegister>& manager) { void BasicChannel::setPermissionManager(const std::shared_ptr<permission::v2::PermissionManager>& manager) {
this->_permissions = manager; this->_permissions = manager;
this->update_properties_from_permissions(); this->update_properties_from_permissions();
} }

View File

@ -6,7 +6,7 @@
#include "channel/TreeView.h" #include "channel/TreeView.h"
#include "Definitions.h" #include "Definitions.h"
#include "Properties.h" #include "Properties.h"
#include "PermissionRegister.h" #include "PermissionManager.h"
namespace ts { namespace ts {
@ -74,8 +74,8 @@ namespace ts {
return this->permission_granted(permission::i_client_needed_talk_power, granted_value, false); return this->permission_granted(permission::i_client_needed_talk_power, granted_value, false);
} }
ts_always_inline std::shared_ptr<permission::v2::PermissionRegister> permissions(){ return this->_permissions; } ts_always_inline std::shared_ptr<permission::v2::PermissionManager> permissions(){ return this->_permissions; }
virtual void setPermissionManager(const std::shared_ptr<permission::v2::PermissionRegister>&); virtual void setPermissionManager(const std::shared_ptr<permission::v2::PermissionManager>&);
virtual void setProperties(const std::shared_ptr<Properties>&); virtual void setProperties(const std::shared_ptr<Properties>&);
private: private:
ts_always_inline ts_always_inline
@ -98,7 +98,7 @@ namespace ts {
protected: protected:
std::weak_ptr<TreeView::LinkedTreeEntry> _link; std::weak_ptr<TreeView::LinkedTreeEntry> _link;
std::shared_ptr<Properties> _properties; std::shared_ptr<Properties> _properties;
std::shared_ptr<permission::v2::PermissionRegister> _permissions; std::shared_ptr<permission::v2::PermissionManager> _permissions;
ChannelId _channel_order = 0; ChannelId _channel_order = 0;
ChannelId _channel_id = 0; ChannelId _channel_id = 0;

View File

@ -1073,17 +1073,17 @@ deque<update::UpdateEntry> update::migrate = {
AQB("b_client_ban_trigger_list") AQB("b_client_ban_trigger_list")
}; };
v2::PermissionRegister::PermissionRegister() { v2::PermissionManager::PermissionManager() {
memset(this->block_use_count, 0, sizeof(this->block_use_count)); memset(this->block_use_count, 0, sizeof(this->block_use_count));
memset(this->block_containers, 0, sizeof(this->block_containers)); memset(this->block_containers, 0, sizeof(this->block_containers));
} }
v2::PermissionRegister::~PermissionRegister() { v2::PermissionManager::~PermissionManager() {
for(auto& block : this->block_containers) for(auto& block : this->block_containers)
delete block; delete block;
} }
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) { 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) {
if(permission < 0 || permission >= PermissionType::permission_id_max) if(permission < 0 || permission >= PermissionType::permission_id_max)
return; return;
@ -1100,7 +1100,7 @@ void v2::PermissionRegister::load_permission(const ts::permission::PermissionTyp
this->unref_block(block); this->unref_block(block);
} }
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) { 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) {
if(permission < 0 || permission >= PermissionType::permission_id_max) if(permission < 0 || permission >= PermissionType::permission_id_max)
return; return;
@ -1136,7 +1136,7 @@ void v2::PermissionRegister::load_permission(const ts::permission::PermissionTyp
permission_container->flags.grant_set = flag_grant; permission_container->flags.grant_set = flag_grant;
} }
const v2::PermissionFlags v2::PermissionRegister::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;
@ -1149,7 +1149,7 @@ const v2::PermissionFlags v2::PermissionRegister::permission_flags(const ts::per
return result; return result;
} }
const v2::PermissionValues v2::PermissionRegister::permission_values(const ts::permission::PermissionType &permission) { const v2::PermissionValues v2::PermissionManager::permission_values(const ts::permission::PermissionType &permission) {
if(permission < 0 || permission >= PermissionType::permission_id_max) if(permission < 0 || permission >= PermissionType::permission_id_max)
return v2::empty_permission_values; return v2::empty_permission_values;
@ -1162,7 +1162,7 @@ const v2::PermissionValues v2::PermissionRegister::permission_values(const ts::p
return data; return data;
} }
const v2::PermissionFlaggedValue v2::PermissionRegister::permission_value_flagged(const ts::permission::PermissionType &permission) { const v2::PermissionFlaggedValue v2::PermissionManager::permission_value_flagged(const ts::permission::PermissionType &permission) {
if(permission < 0 || permission >= PermissionType::permission_id_max) if(permission < 0 || permission >= PermissionType::permission_id_max)
return v2::empty_permission_flagged_value; return v2::empty_permission_flagged_value;
@ -1176,7 +1176,7 @@ const v2::PermissionFlaggedValue v2::PermissionRegister::permission_value_flagge
return result; return result;
} }
const v2::PermissionFlaggedValue v2::PermissionRegister::permission_granted_flagged(const ts::permission::PermissionType &permission) { const v2::PermissionFlaggedValue v2::PermissionManager::permission_granted_flagged(const ts::permission::PermissionType &permission) {
if(permission < 0 || permission >= PermissionType::permission_id_max) if(permission < 0 || permission >= PermissionType::permission_id_max)
return v2::empty_permission_flagged_value; return v2::empty_permission_flagged_value;
@ -1190,7 +1190,7 @@ const v2::PermissionFlaggedValue v2::PermissionRegister::permission_granted_flag
return result; return result;
} }
const v2::PermissionContainer v2::PermissionRegister::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;
@ -1201,7 +1201,7 @@ const v2::PermissionContainer v2::PermissionRegister::channel_permission(const P
return empty_channel_permission; return empty_channel_permission;
} }
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) { 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) {
if(permission < 0 || permission >= PermissionType::permission_id_max) if(permission < 0 || permission >= PermissionType::permission_id_max)
return; return;
@ -1243,7 +1243,7 @@ void v2::PermissionRegister::set_permission(const PermissionType &permission, co
this->trigger_db_update(); this->trigger_db_update();
} }
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) { 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) {
if(permission < 0 || permission >= PermissionType::permission_id_max) if(permission < 0 || permission >= PermissionType::permission_id_max)
return; return;
@ -1319,7 +1319,7 @@ void v2::PermissionRegister::set_channel_permission(const PermissionType &permis
this->trigger_db_update(); this->trigger_db_update();
} }
const std::vector<std::tuple<PermissionType, const v2::PermissionContainer>> v2::PermissionRegister::permissions() { const std::vector<std::tuple<PermissionType, const v2::PermissionContainer>> v2::PermissionManager::permissions() {
std::unique_lock use_lock(this->block_use_count_lock); std::unique_lock use_lock(this->block_use_count_lock);
decltype(this->block_containers) block_containers; /* save the states/nullptr's */ decltype(this->block_containers) block_containers; /* save the states/nullptr's */
memcpy(block_containers, this->block_containers, sizeof(this->block_containers)); memcpy(block_containers, this->block_containers, sizeof(this->block_containers));
@ -1360,7 +1360,7 @@ const std::vector<std::tuple<PermissionType, const v2::PermissionContainer>> v2:
return result; return result;
} }
const vector<tuple<PermissionType, const v2::PermissionContainer>> v2::PermissionRegister::channel_permissions(ts::ChannelId channel_id) { const vector<tuple<PermissionType, const v2::PermissionContainer>> v2::PermissionManager::channel_permissions(ts::ChannelId channel_id) {
shared_lock channel_perm_lock(this->channel_list_lock); shared_lock channel_perm_lock(this->channel_list_lock);
vector<tuple<PermissionType, const v2::PermissionContainer>> result; vector<tuple<PermissionType, const v2::PermissionContainer>> result;
@ -1370,7 +1370,7 @@ const vector<tuple<PermissionType, const v2::PermissionContainer>> v2::Permissio
return result; return result;
} }
const vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> v2::PermissionRegister::channel_permissions() { const vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> v2::PermissionManager::channel_permissions() {
shared_lock channel_perm_lock(this->channel_list_lock); shared_lock channel_perm_lock(this->channel_list_lock);
vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> result; vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> result;
@ -1380,7 +1380,7 @@ const vector<tuple<PermissionType, ChannelId, const v2::PermissionContainer>> v2
return result; return result;
} }
const std::vector<v2::PermissionDBUpdateEntry> v2::PermissionRegister::flush_db_updates() { const std::vector<v2::PermissionDBUpdateEntry> v2::PermissionManager::flush_db_updates() {
if(!this->requires_db_save) if(!this->requires_db_save)
return {}; return {};
@ -1497,7 +1497,7 @@ const std::vector<v2::PermissionDBUpdateEntry> v2::PermissionRegister::flush_db_
return result; return result;
} }
size_t v2::PermissionRegister::used_memory() { size_t v2::PermissionManager::used_memory() {
size_t result = sizeof(*this); size_t result = sizeof(*this);
for (auto &block_container : block_containers) { for (auto &block_container : block_containers) {
@ -1514,7 +1514,7 @@ size_t v2::PermissionRegister::used_memory() {
return result; return result;
} }
void v2::PermissionRegister::cleanup() { void v2::PermissionManager::cleanup() {
lock_guard use_lock(this->block_use_count_lock); lock_guard use_lock(this->block_use_count_lock);
for (auto &block_container : block_containers) { for (auto &block_container : block_containers) {

View File

@ -842,15 +842,15 @@ namespace ts {
return permission_granted({required, true}, given, requires_given); return permission_granted({required, true}, given, requires_given);
} }
class PermissionRegister { class PermissionManager {
public: public:
static constexpr size_t PERMISSIONS_BULK_BITS = 4; /* 16 permissions per block */ 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 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 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); static_assert(PERMISSIONS_BULK_ENTRY_COUNT * BULK_COUNT >= PermissionType::permission_id_max);
PermissionRegister(); PermissionManager();
virtual ~PermissionRegister(); virtual ~PermissionManager();
/* load permissions from the database */ /* 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 */); void load_permission(const PermissionType&, const PermissionValues& /* values */, bool /* flag skip */, bool /* flag negate */, bool /* value present */,bool /* grant present */);

View File

@ -8,7 +8,7 @@
#include <src/License.h> #include <src/License.h>
#include <functional> #include <functional>
#include <src/query/Command.h> #include <src/query/Command.h>
#include "PermissionRegister.h" #include "PermissionManager.h"
#include "src/query/command_handler.h" #include "src/query/command_handler.h"
#include "src/query/command_constants.h" #include "src/query/command_constants.h"

View File

@ -2,14 +2,14 @@
// Created by wolverindev on 15.07.19. // Created by wolverindev on 15.07.19.
// //
#include "PermissionRegister.h" #include "PermissionManager.h"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
using namespace ts::permission::v2; using namespace ts::permission::v2;
using PermissionType = ts::permission::PermissionType; using PermissionType = ts::permission::PermissionType;
void print_permissions(PermissionRegister& manager) { void print_permissions(PermissionManager& manager) {
{ {
auto permissions = manager.permissions(); auto permissions = manager.permissions();
cout << "Permissions: " << permissions.size() << endl; cout << "Permissions: " << permissions.size() << endl;
@ -22,7 +22,7 @@ void print_permissions(PermissionRegister& manager) {
cout << "Used memory: " << manager.used_memory() << endl; cout << "Used memory: " << manager.used_memory() << endl;
} }
void print_updates(PermissionRegister& manager) { void print_updates(PermissionManager& manager) {
const auto updates = manager.flush_db_updates(); const auto updates = manager.flush_db_updates();
cout << "Permission updates: " << updates.size() << endl; cout << "Permission updates: " << updates.size() << endl;
for(auto& update : updates) { for(auto& update : updates) {
@ -40,12 +40,12 @@ Structure size of PermissionManager: 176
Structure size of PermissionContainerBulk<16>: 192 Structure size of PermissionContainerBulk<16>: 192
Structure size of PermissionContainer: 12 Structure size of PermissionContainer: 12
*/ */
cout << "Structure size of PermissionManager: " << sizeof(PermissionRegister) << endl; cout << "Structure size of PermissionManager: " << sizeof(PermissionManager) << endl;
cout << "Structure size of PermissionContainerBulk<16>: " << sizeof(PermissionContainerBulk<16>) << endl; cout << "Structure size of PermissionContainerBulk<16>: " << sizeof(PermissionContainerBulk<16>) << endl;
cout << "Structure size of PermissionContainer: " << sizeof(PermissionContainer) << endl; cout << "Structure size of PermissionContainer: " << sizeof(PermissionContainer) << 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; 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;
PermissionRegister manager{}; PermissionManager manager{};
print_permissions(manager); print_permissions(manager);
manager.set_permission(PermissionType::b_client_ban_ip, {1, 0}, PermissionUpdateType::set_value, PermissionUpdateType::do_nothing); 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); manager.set_channel_permission(PermissionType::b_client_ban_ip, 2, {1, 0}, PermissionUpdateType::set_value, PermissionUpdateType::do_nothing);