X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/90e389f6ec12e60a62c362296ffcf314feb5b03d..b2b89723a2427bba8290bd6967a1ab39cbb630be:/include/stg/user.h diff --git a/include/stg/user.h b/include/stg/user.h index 51e8a76d..78b602ba 100644 --- a/include/stg/user.h +++ b/include/stg/user.h @@ -18,94 +18,110 @@ * Author : Maxim Mamontov */ -#ifndef USER_H -#define USER_H +#pragma once -#include +#include "message.h" +#include "user_property.h" + +#include #include -#include "os_int.h" -#include "notifer.h" -#include "message.h" -#include "tariff.h" -#include "user_traff.h" +#include +#include -class USER_PROPERTIES; -class AUTH; +namespace STG +{ -class USER { -public: - virtual int WriteConf() = 0; - virtual int WriteStat() = 0; +struct Tariff; +class UserProperties; +class DirTraff; +struct Auth; - virtual const std::string & GetLogin() const = 0; +class User +{ + public: + User() noexcept + : m_connectedBase(false), + m_currIPBase(0), + m_connected(m_connectedBase), + m_currIP(m_currIPBase) + { + } - virtual uint32_t GetCurrIP() const = 0; - virtual time_t GetCurrIPModificationTime() const = 0; + virtual ~User() = default; - virtual void AddCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - virtual void DelCurrIPBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + virtual int WriteConf() = 0; + virtual int WriteStat() = 0; - virtual void AddCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - virtual void DelCurrIPAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + virtual const std::string& GetLogin() const = 0; - virtual void AddConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - virtual void DelConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + uint32_t GetCurrIP() const { return m_currIP; } + time_t GetCurrIPModificationTime() const { return m_currIP.ModificationTime(); } - virtual void AddConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; - virtual void DelConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE * notifier) = 0; + template + auto beforeCurrIPChange(F&& f) { return m_currIP.beforeChange(std::forward(f)); } + template + auto afterCurrIPChange(F&& f) { return m_currIP.afterChange(std::forward(f)); } - virtual int GetID() const = 0; + template + auto beforeConnectedChange(F&& f) { return m_connected.beforeChange(std::forward(f)); } + template + auto afterConnectedChange(F&& f) { return m_connected.afterChange(std::forward(f)); } - virtual double GetPassiveTimePart() const = 0; + virtual int GetID() const = 0; - virtual const TARIFF * GetTariff() const = 0; - virtual void ResetNextTariff() = 0; + virtual double GetPassiveTimePart() const = 0; - #ifdef TRAFF_STAT_WITH_PORTS - virtual void AddTraffStatU(int dir, uint32_t ip, uint16_t port, uint32_t len) = 0; - virtual void AddTraffStatD(int dir, uint32_t ip, uint16_t port, uint32_t len) = 0; - #else - virtual void AddTraffStatU(int dir, uint32_t ip, uint32_t len) = 0; - virtual void AddTraffStatD(int dir, uint32_t ip, uint32_t len) = 0; - #endif + virtual const Tariff* GetTariff() const = 0; + virtual void ResetNextTariff() = 0; - virtual const DIR_TRAFF & GetSessionUpload() const = 0; - virtual const DIR_TRAFF & GetSessionDownload() const = 0; + virtual const DirTraff& GetSessionUpload() const = 0; + virtual const DirTraff& GetSessionDownload() const = 0; + virtual time_t GetSessionUploadModificationTime() const = 0; + virtual time_t GetSessionDownloadModificationTime() const = 0; - virtual bool GetConnected() const = 0; - virtual time_t GetConnectedModificationTime() const = 0; - virtual int GetAuthorized() const = 0; - virtual int Authorize(uint32_t ip, - uint32_t enabledDirs, - const AUTH * auth) = 0; - virtual void Unauthorize(const AUTH * auth) = 0; - virtual bool IsAuthorizedBy(const AUTH * auth) const = 0; + bool GetConnected() const { return m_connected; } + time_t GetConnectedModificationTime() const { return m_connected.ModificationTime(); } - virtual int AddMessage(STG_MSG * msg) = 0; + virtual const std::string& GetLastDisconnectReason() const = 0; + virtual int GetAuthorized() const = 0; + virtual time_t GetAuthorizedModificationTime() const = 0; - virtual void UpdatePingTime(time_t t = 0) = 0; - virtual time_t GetPingTime() const = 0; + virtual bool IsAuthorizedBy(const Auth * auth) const = 0; + virtual std::vector GetAuthorizers() const = 0; - virtual void Run() = 0; + virtual int AddMessage(Message* msg) = 0; - virtual const std::string & GetStrError() const = 0; + virtual void UpdatePingTime(time_t t = 0) = 0; + virtual time_t GetPingTime() const = 0; - virtual USER_PROPERTIES & GetProperty() = 0; - virtual const USER_PROPERTIES & GetProperty() const = 0; + virtual void Run() = 0; - virtual bool GetDeleted() const = 0; - virtual void SetDeleted() = 0; + virtual const std::string& GetStrError() const = 0; - virtual time_t GetLastWriteStatTime() const = 0; + virtual UserProperties& GetProperties() = 0; + virtual const UserProperties& GetProperties() const = 0; - virtual bool IsInetable() = 0; - virtual std::string GetEnabledDirs() = 0; + virtual bool GetDeleted() const = 0; + virtual void SetDeleted() = 0; - virtual void OnAdd() = 0; - virtual void OnDelete() = 0; -}; + virtual time_t GetLastWriteStatTime() const = 0; -typedef USER * USER_PTR; + virtual bool IsInetable() = 0; + virtual std::string GetEnabledDirs() const = 0; + + virtual void OnAdd() = 0; + virtual void OnDelete() = 0; + + virtual std::string GetParamValue(const std::string& name) const = 0; + + private: + bool m_connectedBase; + uint32_t m_currIPBase; + + protected: + UserProperty m_connected; + UserProperty m_currIP; +}; -#endif +}