]> git.stg.codes - stg.git/commitdiff
Merge branch 'naffanya-dev'
authorMaxim Mamontov <faust@stg.dp.ua>
Fri, 23 Aug 2013 18:59:58 +0000 (21:59 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Fri, 9 Jan 2015 19:25:19 +0000 (21:25 +0200)
include/stg/settings.h
include/stg/user.h
include/stg/user_property.h
include/stg/users.h
projects/stargazer/main.cpp
projects/stargazer/settings_impl.cpp
projects/stargazer/settings_impl.h
projects/stargazer/user_impl.cpp
projects/stargazer/user_impl.h

index d23494bc5edd1aa91edd25ed3a7f4a864d76b52d..170f71cada5dc1f3edfbe0c475830ebdcd1ec214 100644 (file)
 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<std::string> & GetScriptParams() const = 0;
 };
 //-----------------------------------------------------------------------------
 
index 44d3e5b2293988020425518bcceaabd5ef84a7b2..a8f61105ec3adb3e04cf64be201615703d2d2189 100644 (file)
@@ -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;
index 2ff8909cdc25331ef800d40b7ee61d355432d16b..1716296acd7300482c53f3014c41d7f13869574d 100644 (file)
@@ -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<varT> & va
 return stream << value.ConstData();
 }
 //-----------------------------------------------------------------------------
-
+template<typename varT>
+std::string USER_PROPERTY<varT>::ToString() const
+{
+std::stringstream stream;
+stream << value;
+return stream.str();
+}
 #endif // USER_PROPERTY_H
index 19a9d7b7446a8b01cc647b8ad7b63a496ddbd59e..a1d5d295ced2f91adaac53ac95589e5c5c1ad42f 100644 (file)
@@ -62,6 +62,7 @@ public:
 
     virtual int  Start() = 0;
     virtual int  Stop() = 0;
+
 };
 
 #endif
index 11fad552504730f7aa5b86b837fd4ca070c2b468..7cc8eccc6e54c32f7ead49ad48bd01357b7d88bf 100644 (file)
@@ -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
index 16a2ac47130f1497fdb47ec1ee33e923989c5e42..92670cb5082a345768582a2173ce06803fa0d43f 100644 (file)
@@ -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
index 4a048333a4a5049ead5a6a19b19e10b77f797dd0..7ba2708fd7ae6aace5260277b5421140918a2c4c 100644 (file)
@@ -98,6 +98,7 @@ public:
         { return storeModuleSettings; }
     const std::vector<MODULE_SETTINGS> & GetModulesSettings() const
         { return modulesSettings; }
+    const std::vector<std::string> & GetScriptParams() const { return scriptParams; }
 
 private:
 
@@ -117,6 +118,7 @@ private:
     std::string logFile;
     std::string pidFile;
     std::string monitorDir;
+    std::vector<std::string> scriptParams;
     bool        monitoring;
     unsigned    detailStatWritePeriod;
     unsigned    statWritePeriod;
@@ -136,7 +138,6 @@ private:
 
     std::vector<MODULE_SETTINGS> modulesSettings;
     MODULE_SETTINGS storeModuleSettings;
-
     STG_LOGGER & logger;
 };
 //-----------------------------------------------------------------------------
index 4f216b06e561674dc8f96c5d570e61ba7ef7f988..13cf0b77dc87cd4c1337c6cefc530db7e728572a 100644 (file)
@@ -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<std::string>::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<std::string>::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)
index 96317f06f369181d7317f2341cfc14c7a3f7a580..26ff58fc2b8d902f093739e4cc867f1670a43794 100644 (file)
@@ -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);