X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/9421e4b0be3a6a59e93ad092e3904b3ff8092e84..980332313bffde590173f76fd006837e0c8f3bed:/projects/stargazer/plugins/other/rscript/rscript.cpp diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index 17b86c67..4433dafd 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -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(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::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 == "tariffName") - parameter = rsu.user->GetParamValue("tariff"); - else - parameter = rsu.user->GetParamValue(*it); + 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 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::iterator it(authorizedUsers.begin()); while (it != authorizedUsers.end()) {