X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/0907aa4037b12b6b88ee24495d4577a064d4f8db..73bee151e048054bde9a39c5ad2efec25af9c77b:/projects/stargazer/users_impl.h diff --git a/projects/stargazer/users_impl.h b/projects/stargazer/users_impl.h index ef5ee0ec..07c0e8ab 100644 --- a/projects/stargazer/users_impl.h +++ b/projects/stargazer/users_impl.h @@ -20,27 +20,27 @@ #pragma once -#include +#include "settings_impl.h" +#include "user_impl.h" +#include "stg/store.h" +#include "stg/users.h" +#include "stg/user.h" +#include "stg/tariffs.h" +#include "stg/logger.h" +#include "stg/noncopyable.h" #include #include #include #include +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#include +#pragma GCC diagnostic pop #include #include -#include "stg/store.h" -#include "stg/users.h" -#include "stg/user.h" -#include "stg/tariffs.h" -#include "stg/logger.h" -#include "stg/notifer.h" -#include "stg/noncopyable.h" -#include "actions.h" -#include "eventloop.h" -#include "settings_impl.h" -#include "user_impl.h" - namespace STG { @@ -49,7 +49,6 @@ const int userDeleteDelayTime = 120; typedef std::list::iterator user_iter; typedef std::list::const_iterator const_user_iter; -class UsersImpl; //----------------------------------------------------------------------------- struct USER_TO_DEL { USER_TO_DEL() @@ -61,111 +60,98 @@ std::list::iterator iter; time_t delTime; }; //----------------------------------------------------------------------------- -class UsersImpl : public Users { - friend class PROPERTY_NOTIFER_IP_BEFORE; - friend class PROPERTY_NOTIFER_IP_AFTER; - -public: - using UserImplPtr = UserImpl*; - - UsersImpl(SettingsImpl * s, Store * store, - Tariffs * tariffs, Services & svcs, - const Admin& sysAdmin); - virtual ~UsersImpl(); - - int FindByName(const std::string & login, UserPtr * user) override; - int FindByName(const std::string & login, ConstUserPtr * user) const override; - bool Exists(const std::string & login) const override; - - bool TariffInUse(const std::string & tariffName) const override; +class UsersImpl : public Users +{ + public: + using UserImplPtr = UserImpl*; - void AddNotifierUserAdd(NotifierBase *) override; - void DelNotifierUserAdd(NotifierBase *) override; + UsersImpl(SettingsImpl * s, Store * store, + Tariffs * tariffs, Services & svcs, + const Admin& sysAdmin); - void AddNotifierUserDel(NotifierBase *) override; - void DelNotifierUserDel(NotifierBase *) override; + int FindByName(const std::string & login, UserPtr * user) override; + int FindByName(const std::string & login, ConstUserPtr * user) const override; + bool Exists(const std::string & login) const override; - void AddNotifierUserAdd(NotifierBase *); - void DelNotifierUserAdd(NotifierBase *); + bool TariffInUse(const std::string & tariffName) const override; - void AddNotifierUserDel(NotifierBase *); - void DelNotifierUserDel(NotifierBase *); + template + auto onImplAdd(F&& f) { return m_onAddImplCallbacks.add(std::forward(f)); } + template + auto onImplDel(F&& f) { return m_onDelImplCallbacks.add(std::forward(f)); } - int Add(const std::string & login, const Admin * admin) override; - void Del(const std::string & login, const Admin * admin) override; + int Add(const std::string & login, const Admin * admin) override; + void Del(const std::string & login, const Admin * admin) override; - bool Authorize(const std::string & login, uint32_t ip, - uint32_t enabledDirs, const Auth * auth) override; - bool Unauthorize(const std::string & login, - const Auth * auth, - const std::string & reason) override; + bool Authorize(const std::string & login, uint32_t ip, + uint32_t enabledDirs, const Auth * auth) override; + bool Unauthorize(const std::string & login, + const Auth * auth, + const std::string & reason) override; - int ReadUsers() override; - size_t Count() const override { return users.size(); } + int ReadUsers() override; + size_t Count() const override { return users.size(); } - int FindByIPIdx(uint32_t ip, UserPtr * user) const override; - int FindByIPIdx(uint32_t ip, UserImpl ** user) const; - bool IsIPInIndex(uint32_t ip) const override; - bool IsIPInUse(uint32_t ip, const std::string & login, ConstUserPtr * user) const override; + int FindByIPIdx(uint32_t ip, UserPtr * user) const override; + int FindByIPIdx(uint32_t ip, UserImpl ** user) const; + bool IsIPInIndex(uint32_t ip) const override; + bool IsIPInUse(uint32_t ip, const std::string & login, ConstUserPtr * user) const override; - int OpenSearch() override; - int SearchNext(int handler, UserPtr * user) override; - int SearchNext(int handler, UserImpl ** user); - int CloseSearch(int handler) override; + unsigned int OpenSearch() override; + int SearchNext(int handler, UserPtr * user) override; + int SearchNext(int handler, UserImpl ** user); + int CloseSearch(int handler) override; - int Start() override; - int Stop() override; + int Start() override; + int Stop() override; -private: - UsersImpl(const UsersImpl & rvalue); - UsersImpl & operator=(const UsersImpl & rvalue); + private: + UsersImpl(const UsersImpl & rvalue); + UsersImpl & operator=(const UsersImpl & rvalue); - void AddToIPIdx(user_iter user); - void DelFromIPIdx(uint32_t ip); - bool FindByIPIdx(uint32_t ip, user_iter & iter) const; + void AddToIPIdx(user_iter user); + void DelFromIPIdx(uint32_t ip); + bool FindByIPIdx(uint32_t ip, user_iter & iter) const; - int FindByNameNonLock(const std::string & login, user_iter * user); - int FindByNameNonLock(const std::string & login, const_user_iter * user) const; + bool FindByNameNonLock(const std::string & login, user_iter * user); + bool FindByNameNonLock(const std::string & login, const_user_iter * user) const; - void RealDelUser(); - void ProcessActions(); + void RealDelUser(); + void ProcessActions(); - void AddUserIntoIndexes(user_iter user); - void DelUserFromIndexes(user_iter user); + void AddUserIntoIndexes(user_iter user); + void DelUserFromIndexes(user_iter user); - static void * Run(void *); - void NewMinute(const struct tm & t); - void NewDay(const struct tm & t); - void DayResetTraff(const struct tm & t); + void Run(std::stop_token token); + void NewMinute(const struct tm & t); + void NewDay(const struct tm & t); + void DayResetTraff(const struct tm & t); - bool TimeToWriteDetailStat(const struct tm & t); + bool TimeToWriteDetailStat(const struct tm & t); - std::list users; - std::list usersToDelete; + std::list users; + std::list usersToDelete; - std::map ipIndex; - std::map loginIndex; + std::map ipIndex; + std::map loginIndex; - SettingsImpl * settings; - Tariffs * tariffs; - Services & m_services; - Store * store; - const Admin& sysAdmin; - Logger & WriteServLog; + SettingsImpl * settings; + Tariffs * m_tariffs; + Services & m_services; + Store * m_store; + const Admin& m_sysAdmin; + Logger & WriteServLog; - bool nonstop; - bool isRunning; + bool isRunning; - mutable pthread_mutex_t mutex; - pthread_t thread; - mutable unsigned int handle; + mutable std::mutex m_mutex; + std::jthread m_thread; + mutable unsigned int handle; - mutable std::map searchDescriptors; + mutable std::map searchDescriptors; - std::set*> onAddNotifiers; - std::set*> onDelNotifiers; - std::set*> onAddNotifiersImpl; - std::set*> onDelNotifiersImpl; + Subscriptions m_onAddImplCallbacks; + Subscriptions m_onDelImplCallbacks; }; }