X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/c798b518dd51530b3e309f58de96cdc5c61f7355..e29c6f4d0a7c6ac6a84e321b12857a4aecc5b7e3:/projects/stargazer/user_property.h diff --git a/projects/stargazer/user_property.h b/projects/stargazer/user_property.h index 3ea1be45..704f371e 100644 --- a/projects/stargazer/user_property.h +++ b/projects/stargazer/user_property.h @@ -4,7 +4,6 @@ $Date: 2010/09/13 05:54:43 $ $Author: faust $ */ - #ifndef USER_PROPERTY_H #define USER_PROPERTY_H @@ -15,7 +14,7 @@ $Author: faust $ #include #include -#include "base_store.h" +#include "store.h" #include "stg_logger.h" #include "admin.h" #include "settings.h" @@ -24,20 +23,20 @@ $Author: faust $ #include "stg_locker.h" #include "script_executer.h" -using namespace std; - extern const volatile time_t stgTime; //----------------------------------------------------------------------------- template -class USER_PROPERTY - { +class USER_PROPERTY { public: USER_PROPERTY(varT& val); - USER_PROPERTY& operator= (const varT&); - USER_PROPERTY& operator-= (const varT&); virtual ~USER_PROPERTY(); + void Set(const varT & rvalue); + + USER_PROPERTY& operator= (const varT & rvalue); + USER_PROPERTY& operator-= (const varT & rvalue); + const varT * operator&() const throw(); const varT& ConstData() const throw(); @@ -46,8 +45,6 @@ public: return value; } - //bool IsEmpty() const throw(); - void AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); void DelBeforeNotifier(PROPERTY_NOTIFIER_BASE * n); @@ -57,20 +54,18 @@ public: time_t ModificationTime() const throw(); void ModifyTime() throw(); -protected: +private: varT & value; time_t modificationTime; - //typedef set *>::iterator notifier_iter_t; - mutable set *> beforeNotifiers; - mutable set *> afterNotifiers; + set *> beforeNotifiers; + set *> afterNotifiers; mutable pthread_mutex_t mutex; - }; +}; //----------------------------------------------------------------------------- template -class USER_PROPERTY_LOGGED: public USER_PROPERTY - { +class USER_PROPERTY_LOGGED: public USER_PROPERTY { public: - USER_PROPERTY_LOGGED(varT& val, + USER_PROPERTY_LOGGED(varT & val, const string n, bool isPassword, bool isStat, @@ -78,27 +73,26 @@ public: const SETTINGS * s); virtual ~USER_PROPERTY_LOGGED(); - //operator const varT&() const throw();; USER_PROPERTY_LOGGED * GetPointer() throw(); const varT & Get() const; const string & GetName() const; bool Set(const varT & val, const ADMIN & admin, const string & login, - const BASE_STORE * store, + const STORE * store, const string & msg = ""); -protected: +private: void WriteAccessDenied(const string & login, - const ADMIN & admin, + const ADMIN & admin, const string & parameter); - void WriteSuccessChange(const string & login, - const ADMIN & admin, - const string & parameter, - const string & oldValue, - const string & newValue, - const string & msg, - const BASE_STORE * store); + void WriteSuccessChange(const string & login, + const ADMIN & admin, + const string & parameter, + const string & oldValue, + const string & newValue, + const string & msg, + const STORE * store); void OnChange(const string & login, const string & paramName, @@ -112,11 +106,9 @@ protected: mutable pthread_mutex_t mutex; STG_LOGGER & stgLogger; // server's logger const SETTINGS * settings; - }; +}; //----------------------------------------------------------------------------- -class USER_PROPERTIES - { - friend class USER; +class USER_PROPERTIES { /* В этом месте важен порядок следования приватной и открытой частей. Это связано с тем, что часть которая находится в публичной секции @@ -132,6 +124,8 @@ private: public: USER_PROPERTIES(const SETTINGS * settings); + USER_STAT & Stat() { return stat; } + USER_CONF & Conf() { return conf; } const USER_STAT & GetStat() const { return stat; } const USER_CONF & GetConf() const { return conf; } void SetStat(const USER_STAT & s) { stat = s; } @@ -174,8 +168,7 @@ public: USER_PROPERTY_LOGGED userdata7; USER_PROPERTY_LOGGED userdata8; USER_PROPERTY_LOGGED userdata9; - }; - +}; //============================================================================= //----------------------------------------------------------------------------- @@ -183,8 +176,7 @@ public: //----------------------------------------------------------------------------- template USER_PROPERTY::USER_PROPERTY(varT& val) -: -value(val) + : value(val) { pthread_mutex_init(&mutex, NULL); modificationTime = stgTime; @@ -202,77 +194,53 @@ void USER_PROPERTY::ModifyTime() throw() } //----------------------------------------------------------------------------- template -USER_PROPERTY& USER_PROPERTY::operator= (const varT& newValue) +void USER_PROPERTY::Set(const varT & rvalue) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); -/* -TODO -if (value == newValue) - return *this;*/ - typename set *>::iterator ni; varT oldVal = value; ni = beforeNotifiers.begin(); while (ni != beforeNotifiers.end()) - (*ni++)->Notify(oldVal, newValue); + (*ni++)->Notify(oldVal, rvalue); -value = newValue; +value = rvalue; modificationTime = stgTime; ni = afterNotifiers.begin(); while (ni != afterNotifiers.end()) - (*ni++)->Notify(oldVal, newValue); - + (*ni++)->Notify(oldVal, rvalue); +} +//----------------------------------------------------------------------------- +template +USER_PROPERTY& USER_PROPERTY::operator= (const varT & newValue) +{ +Set(newValue); return *this; } //----------------------------------------------------------------------------- template -USER_PROPERTY& USER_PROPERTY::operator-= (const varT& delta) +USER_PROPERTY& USER_PROPERTY::operator-= (const varT & delta) { -STG_LOCKER locker(&mutex, __FILE__, __LINE__); - -typename set *>::iterator ni; - -varT oldVal = value; - -ni = beforeNotifiers.begin(); -while (ni != beforeNotifiers.end()) - (*ni++)->Notify(oldVal, oldVal - delta); - -value -= delta; -modificationTime = stgTime; - -ni = afterNotifiers.begin(); -while (ni != afterNotifiers.end()) - (*ni++)->Notify(oldVal, value); - +varT newValue = ConstData() - delta; +Set(newValue); return *this; } //----------------------------------------------------------------------------- template const varT * USER_PROPERTY::operator&() const throw() { -STG_LOCKER locker(&mutex, __FILE__, __LINE__); return &value; } //----------------------------------------------------------------------------- template const varT& USER_PROPERTY::ConstData() const throw() { -STG_LOCKER locker(&mutex, __FILE__, __LINE__); return value; } //----------------------------------------------------------------------------- -/*template -bool USER_PROPERTY::IsEmpty() const throw() -{ -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -return !is_set; -}*/ -//----------------------------------------------------------------------------- template void USER_PROPERTY::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) { @@ -304,27 +272,24 @@ afterNotifiers.erase(n); template time_t USER_PROPERTY::ModificationTime() const throw() { -STG_LOCKER locker(&mutex, __FILE__, __LINE__); return modificationTime; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- template -USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED( - varT& val, - string n, - bool isPass, - bool isSt, - STG_LOGGER & logger, - const SETTINGS * s) - -:USER_PROPERTY(val), -stgLogger(logger) +USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT& val, + string n, + bool isPass, + bool isSt, + STG_LOGGER & logger, + const SETTINGS * s) + + : USER_PROPERTY(val), + stgLogger(logger) { pthread_mutex_init(&mutex, NULL); STG_LOCKER locker(&mutex, __FILE__, __LINE__); -USER_PROPERTY::value = val; isPassword = isPass; isStat = isSt; name = n; @@ -334,27 +299,23 @@ settings = s; template USER_PROPERTY_LOGGED::~USER_PROPERTY_LOGGED() { -STG_LOCKER locker(&mutex, __FILE__, __LINE__); } //----------------------------------------------------------------------------- template USER_PROPERTY_LOGGED * USER_PROPERTY_LOGGED::GetPointer() throw() { -STG_LOCKER locker(&mutex, __FILE__, __LINE__); return this; } //----------------------------------------------------------------------------- template const varT & USER_PROPERTY_LOGGED::Get() const { -STG_LOCKER locker(&mutex, __FILE__, __LINE__); -return USER_PROPERTY::value; +return USER_PROPERTY::ConstData(); }; //------------------------------------------------------------------------- template const string & USER_PROPERTY_LOGGED::GetName() const { -STG_LOCKER locker(&mutex, __FILE__, __LINE__); return name; }; //------------------------------------------------------------------------- @@ -362,7 +323,7 @@ template bool USER_PROPERTY_LOGGED::Set(const varT & val, const ADMIN & admin, const string & login, - const BASE_STORE * store, + const STORE * store, const string & msg) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); @@ -373,7 +334,7 @@ STG_LOCKER locker(&mutex, __FILE__, __LINE__); const PRIV * priv = admin.GetPriv(); string adm_login = admin.GetLogin(); -string adm_ip = admin.GetAdminIPStr(); +string adm_ip = admin.GetIPStr(); if ((priv->userConf && !isStat) || (priv->userStat && isStat) || (priv->userPasswd && isPassword) || (priv->userCash && name == "cash")) { @@ -383,7 +344,7 @@ if ((priv->userConf && !isStat) || (priv->userStat && isStat) || (priv->userPass oldVal.flags(oldVal.flags() | ios::fixed); newVal.flags(newVal.flags() | ios::fixed); - oldVal << USER_PROPERTY::value; + oldVal << USER_PROPERTY::ConstData(); newVal << val; OnChange(login, name, oldVal.str(), newVal.str(), admin); @@ -396,7 +357,7 @@ if ((priv->userConf && !isStat) || (priv->userStat && isStat) || (priv->userPass { WriteSuccessChange(login, admin, name, oldVal.str(), newVal.str(), msg, store); } - USER_PROPERTY::operator =(val); + USER_PROPERTY::Set(val); return true; } else @@ -418,12 +379,12 @@ stgLogger("%s Change user \'%s.\' Parameter \'%s\'. Access denied.", //------------------------------------------------------------------------- template void USER_PROPERTY_LOGGED::WriteSuccessChange(const string & login, - const ADMIN & admin, - const string & parameter, - const string & oldValue, - const string & newValue, - const string & msg, - const BASE_STORE * store) + const ADMIN & admin, + const string & parameter, + const string & oldValue, + const string & newValue, + const string & msg, + const STORE * store) { stgLogger("%s User \'%s\': \'%s\' parameter changed from \'%s\' to \'%s\'. %s", admin.GetLogStr().c_str(), @@ -433,7 +394,7 @@ stgLogger("%s User \'%s\': \'%s\' parameter changed from \'%s\' to \'%s\'. %s", newValue.c_str(), msg.c_str()); -store->WriteUserChgLog(login, admin.GetLogin(), admin.GetAdminIP(), parameter, oldValue, newValue, msg); +store->WriteUserChgLog(login, admin.GetLogin(), admin.GetIP(), parameter, oldValue, newValue, msg); } //------------------------------------------------------------------------- template @@ -449,7 +410,7 @@ str1 = settings->GetConfDir() + "/OnChange"; if (access(str1.c_str(), X_OK) == 0) { - string str2("\"" + str1 + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin.GetLogin() + "\" \"" + admin.GetAdminIPStr() + "\""); + string str2("\"" + str1 + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin.GetLogin() + "\" \"" + admin.GetIPStr() + "\""); ScriptExec(str2); } else @@ -460,20 +421,18 @@ else //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- -template +/*template stringstream & operator<< (stringstream & s, const USER_PROPERTY & v) { s << v.ConstData(); return s; -} +}*/ //----------------------------------------------------------------------------- template -ostream & operator<< (ostream & o, const USER_PROPERTY & v) +ostream & operator<< (ostream & stream, const USER_PROPERTY & value) { -return o << v.ConstData(); +return stream << value.ConstData(); } //----------------------------------------------------------------------------- - #endif // USER_PROPERTY_H -