]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/other/rscript/rscript.cpp
stg-2.409 pre-merge.
[stg.git] / projects / stargazer / plugins / other / rscript / rscript.cpp
index 4a9e8d32920108ce0dd325e2946effc7c9cedd36..4433dafda702d019ff7da1d405cd330a6ddea92f 100644 (file)
@@ -73,12 +73,7 @@ return rsc.GetPlugin();
 //-----------------------------------------------------------------------------
 RS::SETTINGS::SETTINGS()
     : sendPeriod(0),
-      port(0),
-      errorStr(),
-      netRouters(),
-      userParams(),
-      password(),
-      subnetFile()
+      port(0)
 {
 }
 //-----------------------------------------------------------------------------
@@ -91,7 +86,7 @@ netRouters.clear();
 ///////////////////////////
 pv.param = "Port";
 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
     {
     errorStr = "Parameter \'Port\' not found.";
     printfd(__FILE__, "Parameter 'Port' not found\n");
@@ -107,7 +102,7 @@ port = static_cast<uint16_t>(p);
 ///////////////////////////
 pv.param = "SendPeriod";
 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
     {
     errorStr = "Parameter \'SendPeriod\' not found.";
     printfd(__FILE__, "Parameter 'SendPeriod' not found\n");
@@ -123,7 +118,7 @@ if (ParseIntInRange(pvi->value[0], 5, 600, &sendPeriod))
 ///////////////////////////
 pv.param = "UserParams";
 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
     {
     errorStr = "Parameter \'UserParams\' not found.";
     printfd(__FILE__, "Parameter 'UserParams' not found\n");
@@ -133,7 +128,7 @@ userParams = pvi->value;
 ///////////////////////////
 pv.param = "Password";
 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
     {
     errorStr = "Parameter \'Password\' not found.";
     printfd(__FILE__, "Parameter 'Password' not found\n");
@@ -143,7 +138,7 @@ password = pvi->value[0];
 ///////////////////////////
 pv.param = "SubnetFile";
 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
     {
     errorStr = "Parameter \'SubnetFile\' not found.";
     printfd(__FILE__, "Parameter 'SubnetFile' not found\n");
@@ -301,7 +296,7 @@ if (isRunning)
 return 0;
 }
 //-----------------------------------------------------------------------------
-int REMOTE_SCRIPT::Reload()
+int REMOTE_SCRIPT::Reload(const MODULE_SETTINGS & /*ms*/)
 {
 NRMapParser nrMapParser;
 
@@ -313,7 +308,7 @@ if (nrMapParser.ReadFile(rsSettings.GetMapFileName()))
     }
 
     {
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+    STG_LOCKER lock(&mutex);
 
     printfd(__FILE__, "REMOTE_SCRIPT::Reload()\n");
 
@@ -353,7 +348,7 @@ return false;
 //-----------------------------------------------------------------------------
 void REMOTE_SCRIPT::PeriodicSend()
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
 
 std::map<uint32_t, RS::USER>::iterator it(authorizedUsers.begin());
 while (it != authorizedUsers.end())
@@ -429,13 +424,12 @@ for(it = rsSettings.GetUserParams().begin();
     it != rsSettings.GetUserParams().end();
     ++it)
     {
-    std::string parameter;
-    if (it->c_str() == "tariffName") 
-        parameter = rsu.user->GetParamValue("tariff");
-    else 
-        parameter = rsu.user->GetParamValue(it->c_str());
+    std::string parameter(rsu.user->GetParamValue(it->c_str()));
     if (params.length() + parameter.length() > RS_PARAMS_LEN - 1)
+    {
+        logger("Script params string length %d exceeds the limit of %d symbols.", params.length() + parameter.length(), RS_PARAMS_LEN);
         break;
+    }
     params += parameter + " ";
     }
 strncpy((char *)packetTail.params, params.c_str(), RS_PARAMS_LEN);
@@ -511,7 +505,7 @@ return false;
 //-----------------------------------------------------------------------------
 std::vector<uint32_t> REMOTE_SCRIPT::IP2Routers(uint32_t ip)
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
 for (size_t i = 0; i < netRouters.size(); ++i)
     {
     if ((ip & netRouters[i].subnetMask) == (netRouters[i].subnetIP & netRouters[i].subnetMask))
@@ -546,13 +540,13 @@ void REMOTE_SCRIPT::AddRSU(USER_PTR user)
 RS::USER rsu(IP2Routers(user->GetCurrIP()), user);
 Send(rsu);
 
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
 authorizedUsers.insert(std::make_pair(user->GetCurrIP(), rsu));
 }
 //-----------------------------------------------------------------------------
 void REMOTE_SCRIPT::DelRSU(USER_PTR user)
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
 std::map<uint32_t, RS::USER>::iterator it(authorizedUsers.begin());
 while (it != authorizedUsers.end())
     {