From b078cd0fbf7dee4e222fcffffac2ded8a3c9d3a3 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 23 Aug 2013 21:59:58 +0300 Subject: [PATCH] Merge branch 'naffanya-dev' --- include/stg/settings.h | 35 ++++++++++--------- include/stg/user.h | 2 ++ include/stg/user_property.h | 9 ++++- include/stg/users.h | 1 + projects/stargazer/main.cpp | 1 - projects/stargazer/settings_impl.cpp | 9 ++++- projects/stargazer/settings_impl.h | 3 +- projects/stargazer/user_impl.cpp | 52 ++++++++++++++++++++++++++++ projects/stargazer/user_impl.h | 2 ++ 9 files changed, 93 insertions(+), 21 deletions(-) diff --git a/include/stg/settings.h b/include/stg/settings.h index d23494bc..170f71ca 100644 --- a/include/stg/settings.h +++ b/include/stg/settings.h @@ -26,23 +26,24 @@ class SETTINGS { public: virtual ~SETTINGS() {} - virtual const std::string & GetDirName(size_t num) const = 0; - virtual const std::string & GetScriptsDir() const = 0; - virtual unsigned GetDetailStatWritePeriod() const = 0; - virtual unsigned GetStatWritePeriod() const = 0; - virtual unsigned GetDayFee() const = 0; - virtual bool GetFullFee() const = 0; - virtual unsigned GetDayResetTraff() const = 0; - virtual bool GetSpreadFee() const = 0; - virtual bool GetFreeMbAllowInet() const = 0; - virtual bool GetDayFeeIsLastDay() const = 0; - virtual bool GetWriteFreeMbTraffCost() const = 0; - virtual bool GetShowFeeInCash() const = 0; - virtual unsigned GetMessageTimeout() const = 0; - virtual unsigned GetFeeChargeType() const = 0; - virtual bool GetReconnectOnTariffChange() const = 0; - virtual const std::string & GetMonitorDir() const = 0; - virtual bool GetMonitoring() const = 0; + virtual const std::string & GetDirName(size_t num) const = 0; + virtual const std::string & GetScriptsDir() const = 0; + virtual unsigned GetDetailStatWritePeriod() const = 0; + virtual unsigned GetStatWritePeriod() const = 0; + virtual unsigned GetDayFee() const = 0; + virtual bool GetFullFee() const = 0; + virtual unsigned GetDayResetTraff() const = 0; + virtual bool GetSpreadFee() const = 0; + virtual bool GetFreeMbAllowInet() const = 0; + virtual bool GetDayFeeIsLastDay() const = 0; + virtual bool GetWriteFreeMbTraffCost() const = 0; + virtual bool GetShowFeeInCash() const = 0; + virtual unsigned GetMessageTimeout() const = 0; + virtual unsigned GetFeeChargeType() const = 0; + virtual bool GetReconnectOnTariffChange() const = 0; + virtual const std::string & GetMonitorDir() const = 0; + virtual bool GetMonitoring() const = 0; + virtual const std::vector & GetScriptParams() const = 0; }; //----------------------------------------------------------------------------- diff --git a/include/stg/user.h b/include/stg/user.h index 44d3e5b2..a8f61105 100644 --- a/include/stg/user.h +++ b/include/stg/user.h @@ -102,6 +102,8 @@ public: virtual void OnAdd() = 0; virtual void OnDelete() = 0; + + virtual std::string GetParamValue(const std::string & name) const = 0; }; typedef USER * USER_PTR; diff --git a/include/stg/user_property.h b/include/stg/user_property.h index 2ff8909c..1716296a 100644 --- a/include/stg/user_property.h +++ b/include/stg/user_property.h @@ -51,6 +51,7 @@ public: time_t ModificationTime() const throw() { return modificationTime; } void ModifyTime() throw(); + std::string ToString() const; private: varT & value; time_t modificationTime; @@ -382,5 +383,11 @@ std::ostream & operator<< (std::ostream & stream, const USER_PROPERTY & va return stream << value.ConstData(); } //----------------------------------------------------------------------------- - +template +std::string USER_PROPERTY::ToString() const +{ +std::stringstream stream; +stream << value; +return stream.str(); +} #endif // USER_PROPERTY_H diff --git a/include/stg/users.h b/include/stg/users.h index 19a9d7b7..a1d5d295 100644 --- a/include/stg/users.h +++ b/include/stg/users.h @@ -62,6 +62,7 @@ public: virtual int Start() = 0; virtual int Stop() = 0; + }; #endif diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 11fad552..7cc8eccc 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -271,7 +271,6 @@ if (settings->ReadSettings()) WriteServLog("ReadSettings error. %s", settings->GetStrError().c_str()); exit(1); } - #ifndef NO_DAEMON std::string startFile(settings->GetConfDir() + START_FILE); #endif diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index 16a2ac47..92670cb5 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -457,6 +457,13 @@ while (node) } } + if (strcasecmp(node->getName(), "ScriptParams") == 0) + { + for (int i = 0; node->getValue(i) != NULL; ++i) + { + scriptParams.push_back(node->getValue(i)); + } + } node = node->getNextNode(); } @@ -488,4 +495,4 @@ else if (detailStatPeriodStr == "1/6") return -1; } -//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- \ No newline at end of file diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index 4a048333..7ba2708f 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -98,6 +98,7 @@ public: { return storeModuleSettings; } const std::vector & GetModulesSettings() const { return modulesSettings; } + const std::vector & GetScriptParams() const { return scriptParams; } private: @@ -117,6 +118,7 @@ private: std::string logFile; std::string pidFile; std::string monitorDir; + std::vector scriptParams; bool monitoring; unsigned detailStatWritePeriod; unsigned statWritePeriod; @@ -136,7 +138,6 @@ private: std::vector modulesSettings; MODULE_SETTINGS storeModuleSettings; - STG_LOGGER & logger; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 4f216b06..13cf0b77 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -579,6 +579,7 @@ if (!fakeConnect) } std::string scriptOnConnectParams; + strprintf(&scriptOnConnectParams, "%s \"%s\" \"%s\" \"%f\" \"%d\" \"%s\"", scriptOnConnect.c_str(), @@ -588,6 +589,13 @@ if (!fakeConnect) id, dirsStr); + std::vector::const_iterator it(settings->GetScriptParams().begin()); + while (it != settings->GetScriptParams().end()) + { + scriptOnConnectParams += " \"" + GetParamValue(it->c_str()) + "\""; + ++it; + } + ScriptExec(scriptOnConnectParams.c_str()); } else @@ -646,6 +654,13 @@ if (!fakeDisconnect) id, dirsStr); + std::vector::const_iterator it(settings->GetScriptParams().begin()); + while (it != settings->GetScriptParams().end()) + { + scriptOnDisonnectParams += " \"" + GetParamValue(it->c_str()) + "\""; + ++it; + } + ScriptExec(scriptOnDisonnectParams.c_str()); } else @@ -1449,6 +1464,43 @@ while (it != messages.end()) } } //----------------------------------------------------------------------------- +std::string USER_IMPL::GetParamValue(const std::string & name) const +{ +if (name == "freeMb") return property.freeMb.ToString(); +if (name == "passive") return property.passive.ToString(); +if (name == "disabled") return property.disabled.ToString(); +if (name == "alwaysOnline") return property.alwaysOnline.ToString(); +if (name == "tariffName") return property.tariffName; +if (name == "nextTariff") return property.nextTariff; +if (name == "address") return property.address; +if (name == "note") return property.note; +if (name == "group") return property.group; +if (name == "email") return property.email; +if (name == "phone") return property.phone; +if (name == "realName") return property.realName; +if (name == "credit") return property.credit.ToString(); +if (name == "userdata0") return property.userdata0; +if (name == "userdata1") return property.userdata1; +if (name == "userdata2") return property.userdata2; +if (name == "userdata3") return property.userdata3; +if (name == "userdata4") return property.userdata4; +if (name == "userdata5") return property.userdata5; +if (name == "userdata6") return property.userdata6; +if (name == "userdata7") return property.userdata7; +if (name == "userdata8") return property.userdata8; +if (name == "userdata9") return property.userdata9; +if (name == "cash") return property.cash.ToString(); +if (name == "id") + { + std::stringstream stream; + stream << id; + return stream.str();; + } +if (name == "login") return login; +if (name == "ip") return currIP.ToString(); +return ""; +} +//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CHG_PASSIVE_NOTIFIER::Notify(const int & oldPassive, const int & newPassive) diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index 96317f06..26ff58fc 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -221,6 +221,8 @@ public: void OnAdd(); void OnDelete(); + virtual std::string GetParamValue(const std::string & name) const; + private: USER_IMPL & operator=(const USER_IMPL & rvalue); -- 2.43.2