#include "stg/const.h"
#include "stg/blowfish.h"
#include "stg/logger.h"
-#include "stg/locker.h"
#include "stg/admin_conf.h"
#include "stg/tariff.h"
#include "stg/tariff_conf.h"
: m_version("file_store v.1.04"),
m_logger(STG::PluginLogger::get("store_files"))
{
-pthread_mutexattr_t attr;
-pthread_mutexattr_init(&attr);
-pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-pthread_mutex_init(&m_mutex, &attr);
}
//-----------------------------------------------------------------------------
int FILES_STORE::ParseSettings()
int ret = m_storeSettings.ParseSettings(m_settings);
if (ret)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = m_storeSettings.GetStrError();
}
return ret;
if (GetFileList(&files, m_storeSettings.GetUsersDir(), S_IFDIR, ""))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Failed to open '" + m_storeSettings.GetUsersDir() + "': " + std::string(strerror(errno));
return -1;
}
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
userList->swap(files);
if (GetFileList(&files, m_storeSettings.GetAdminsDir(), S_IFREG, ".adm"))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Failed to open '" + m_storeSettings.GetAdminsDir() + "': " + std::string(strerror(errno));
return -1;
}
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
adminList->swap(files);
if (GetFileList(&files, m_storeSettings.GetTariffsDir(), S_IFREG, ".tf"))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Failed to open '" + m_storeSettings.GetTariffsDir() + "': " + std::string(strerror(errno));
return -1;
}
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
tariffList->swap(files);
if (GetFileList(&files, m_storeSettings.GetServicesDir(), S_IFREG, ".serv"))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Failed to open '" + m_storeSettings.GetServicesDir() + "': " + std::string(strerror(errno));
return -1;
}
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
list->swap(files);
{
if (unlink(str.c_str()))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "unlink failed. Message: '";
m_errorStr += strerror(errno);
m_errorStr += "'";
if (rmdir(path))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "rmdir failed. Message: '";
m_errorStr += strerror(errno);
m_errorStr += "'";
if (mkdir(fileName.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = std::string("mkdir failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::AddUser - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
strprintf(&fileName, "%s%s/conf", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (Touch(fileName))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot create file \"" + fileName + "\'";
printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
strprintf(&fileName, "%s%s/stat", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (Touch(fileName))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot create file \"" + fileName + "\'";
printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
{
if (mkdir(dirName.c_str(), 0700) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Directory '" + dirName + "' cannot be created.";
printfd(__FILE__, "FILES_STORE::DelUser - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
strprintf(&dirName1, "%s/%s", m_storeSettings.GetUsersDir().c_str(), login.c_str());
if (rename(dirName1.c_str(), dirName.c_str()))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error moving dir from " + dirName1 + " to " + dirName;
printfd(__FILE__, "FILES_STORE::DelUser - rename failed. Message: '%s'\n", strerror(errno));
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' data not read.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - conf read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadString("Password", &conf->password, "") < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' data not read. Parameter Password.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - password read failed for user '%s'\n", login.c_str());
return -1;
}
if (conf->password.empty())
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' password is blank.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - password is blank for user '%s'\n", login.c_str());
return -1;
if (cf.ReadString("tariff", &conf->tariffName, "") < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' data not read. Parameter Tariff.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff read failed for user '%s'\n", login.c_str());
return -1;
}
if (conf->tariffName.empty())
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' tariff is blank.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff is blank for user '%s'\n", login.c_str());
return -1;
}
catch (const std::string & s)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' data not read. Parameter IP address. " + s;
printfd(__FILE__, "FILES_STORE::RestoreUserConf - ip read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' data not read. Parameter AlwaysOnline.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - alwaysonline read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadInt("down", &conf->disabled, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' data not read. Parameter Down.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - down read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadInt("passive", &conf->passive, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' data not read. Parameter Passive.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - passive read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadDouble("Credit", &conf->credit, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' data not read. Parameter Credit.";
printfd(__FILE__, "FILES_STORE::RestoreUserConf - credit read failed for user '%s'\n", login.c_str());
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Cannot open file " + fileName + ".";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - stat read failed for user '%s'\n", login.c_str());
return -1;
snprintf(s, 22, "D%d", i);
if (cf.ReadULongLongInt(s, &traff, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s);
printfd(__FILE__, "FILES_STORE::RestoreUserStat - download stat read failed for user '%s'\n", login.c_str());
return -1;
snprintf(s, 22, "U%d", i);
if (cf.ReadULongLongInt(s, &traff, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s);
printfd(__FILE__, "FILES_STORE::RestoreUserStat - upload stat read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadDouble("Cash", &stat->cash, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Parameter Cash";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - cash read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadDouble("FreeMb", &stat->freeMb, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Parameter FreeMb";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - freemb read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadTime("LastCashAddTime", &stat->lastCashAddTime, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Parameter LastCashAddTime";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastcashaddtime read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadTime("PassiveTime", &stat->passiveTime, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Parameter PassiveTime";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - passivetime read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadDouble("LastCashAdd", &stat->lastCashAdd, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Parameter LastCashAdd";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastcashadd read failed for user '%s'\n", login.c_str());
return -1;
if (cf.ReadTime("LastActivityTime", &stat->lastActivityTime, 0) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "User \'" + login + "\' stat not read. Parameter LastActivityTime";
printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastactivitytime read failed for user '%s'\n", login.c_str());
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = std::string("User \'") + login + "\' conf not written\n";
printfd(__FILE__, "FILES_STORE::SaveUserConf - conf write failed for user '%s'\n", login.c_str());
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
printfd(__FILE__, "FILES_STORE::SaveUserConf - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = std::string("User \'") + login + "\' stat not written\n";
printfd(__FILE__, "FILES_STORE::SaveUserStat - stat write failed for user '%s'\n", login.c_str());
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
printfd(__FILE__, "FILES_STORE::SaveUserStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
}
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot open \'" + fileName + "\'";
printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str());
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
}
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot open \'" + fileName + "\'";
printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str());
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
if (s.Error())
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot create file '" + stat1 + "'";
printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str());
return -1;
if (s2.Error())
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot create file '" + stat2 + "'";
printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str());
return -1;
if (Touch(fileName))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot create file " + fileName;
printfd(__FILE__, "FILES_STORE::AddAdmin - failed to add admin '%s'\n", login.c_str());
return -1;
strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), login.c_str());
if (unlink(fileName.c_str()))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "unlink failed. Message: '";
m_errorStr += strerror(errno);
m_errorStr += "'";
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot write admin " + ac.login + ". " + fileName;
printfd(__FILE__, "FILES_STORE::SaveAdmin - failed to save admin '%s'\n", ac.login.c_str());
return -1;
if (cf.Error())
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot open " + fileName;
printfd(__FILE__, "FILES_STORE::RestoreAdmin - failed to restore admin '%s'\n", ac->login.c_str());
return -1;
if (cf.ReadString("password", &p, "*"))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter password";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - password read failed for admin '%s'\n", ac->login.c_str());
return -1;
ac->priv.userConf = a;
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter ChgConf";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgconf read failed for admin '%s'\n", ac->login.c_str());
return -1;
ac->priv.userPasswd = a;
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter ChgPassword";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgpassword read failed for admin '%s'\n", ac->login.c_str());
return -1;
ac->priv.userStat = a;
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter ChgStat";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgstat read failed for admin '%s'\n", ac->login.c_str());
return -1;
ac->priv.userCash = a;
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter ChgCash";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgcash read failed for admin '%s'\n", ac->login.c_str());
return -1;
ac->priv.userAddDel = a;
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter UsrAddDel";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - usradddel read failed for admin '%s'\n", ac->login.c_str());
return -1;
ac->priv.adminChg = a;
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter ChgAdmin";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgadmin read failed for admin '%s'\n", ac->login.c_str());
return -1;
ac->priv.tariffChg = a;
else
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter ChgTariff";
printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgtariff read failed for admin '%s'\n", ac->login.c_str());
return -1;
strprintf(&fileName, "%s/%s.tf", m_storeSettings.GetTariffsDir().c_str(), name.c_str());
if (Touch(fileName))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot create file " + fileName;
printfd(__FILE__, "FILES_STORE::AddTariff - failed to add tariff '%s'\n", name.c_str());
return -1;
strprintf(&fileName, "%s/%s.tf", m_storeSettings.GetTariffsDir().c_str(), name.c_str());
if (unlink(fileName.c_str()))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "unlink failed. Message: '";
m_errorStr += strerror(errno);
m_errorStr += "'";
if (conf.Error() != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read file " + fileName;
printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to read tariff '%s'\n", tariffName.c_str());
return -1;
strprintf(¶m, "Time%d", i);
if (conf.ReadString(param, &str, "00:00-00:00") < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - time%d read failed for tariff '%s'\n", i, tariffName.c_str());
return -1;
strprintf(¶m, "PriceDayA%d", i);
if (conf.ReadDouble(param, &td->dirPrice[i].priceDayA, 0.0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedaya read failed for tariff '%s'\n", tariffName.c_str());
return -1;
strprintf(¶m, "PriceDayB%d", i);
if (conf.ReadDouble(param, &td->dirPrice[i].priceDayB, 0.0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedayb read failed for tariff '%s'\n", tariffName.c_str());
return -1;
strprintf(¶m, "PriceNightA%d", i);
if (conf.ReadDouble(param, &td->dirPrice[i].priceNightA, 0.0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenighta read failed for tariff '%s'\n", tariffName.c_str());
return -1;
strprintf(¶m, "PriceNightB%d", i);
if (conf.ReadDouble(param, &td->dirPrice[i].priceNightB, 0.0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenightb read failed for tariff '%s'\n", tariffName.c_str());
return -1;
strprintf(¶m, "Threshold%d", i);
if (conf.ReadInt(param, &td->dirPrice[i].threshold, 0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - threshold read failed for tariff '%s'\n", tariffName.c_str());
return -1;
strprintf(¶m, "SinglePrice%d", i);
if (conf.ReadInt(param, &td->dirPrice[i].singlePrice, 0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - singleprice read failed for tariff '%s'\n", tariffName.c_str());
return -1;
strprintf(¶m, "NoDiscount%d", i);
if (conf.ReadInt(param, &td->dirPrice[i].noDiscount, 0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
printfd(__FILE__, "FILES_STORE::RestoreTariff - nodiscount read failed for tariff '%s'\n", tariffName.c_str());
return -1;
if (conf.ReadDouble("Fee", &td->tariffConf.fee, 0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter Fee";
printfd(__FILE__, "FILES_STORE::RestoreTariff - fee read failed for tariff '%s'\n", tariffName.c_str());
return -1;
if (conf.ReadDouble("Free", &td->tariffConf.free, 0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter Free";
printfd(__FILE__, "FILES_STORE::RestoreTariff - free read failed for tariff '%s'\n", tariffName.c_str());
return -1;
if (conf.ReadDouble("PassiveCost", &td->tariffConf.passiveCost, 0) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter PassiveCost";
printfd(__FILE__, "FILES_STORE::RestoreTariff - passivecost read failed for tariff '%s'\n", tariffName.c_str());
return -1;
if (conf.ReadString("TraffType", &str, "") < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read tariff " + tariffName + ". Parameter TraffType";
printfd(__FILE__, "FILES_STORE::RestoreTariff - trafftype read failed for tariff '%s'\n", tariffName.c_str());
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error writing tariff " + tariffName;
printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to save tariff '%s'\n", tariffName.c_str());
return e;
if (Touch(fileName))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot create file " + fileName;
printfd(__FILE__, "FILES_STORE::AddService - failed to add service '%s'\n", name.c_str());
return -1;
strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), name.c_str());
if (unlink(fileName.c_str()))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "unlink failed. Message: '";
m_errorStr += strerror(errno);
m_errorStr += "'";
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot write service " + conf.name + ". " + fileName;
printfd(__FILE__, "FILES_STORE::SaveService - failed to save service '%s'\n", conf.name.c_str());
return -1;
if (cf.Error())
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot open " + fileName;
printfd(__FILE__, "FILES_STORE::RestoreService - failed to restore service '%s'\n", name.c_str());
return -1;
if (cf.ReadString("name", &conf->name, name))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter 'name'";
printfd(__FILE__, "FILES_STORE::RestoreService - name read failed for service '%s'\n", name.c_str());
return -1;
if (cf.ReadString("comment", &conf->comment, ""))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter 'comment'";
printfd(__FILE__, "FILES_STORE::RestoreService - comment read failed for service '%s'\n", name.c_str());
return -1;
if (cf.ReadDouble("cost", &conf->cost, 0.0))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter 'cost'";
printfd(__FILE__, "FILES_STORE::RestoreService - cost read failed for service '%s'\n", name.c_str());
return -1;
unsigned short value = 0;
if (cf.ReadUShortInt("pay_day", &value, 0))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error in parameter 'pay_day'";
printfd(__FILE__, "FILES_STORE::RestoreService - pay day read failed for service '%s'\n", name.c_str());
return -1;
{
if (mkdir(dn, 0700) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
{
if (mkdir(dn, 0700) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
{
if (mkdir(dn, 0700) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
return -1;
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
if (!statFile)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "File \'" + std::string(fn) + "\' cannot be written.";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
if (fprintf(statFile, "-> %02d.%02d.%02d - %02d.%02d.%02d\n",
h1, m1, s1, h2, m2, s2) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = std::string("fprint failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno));
fclose(statFile);
u.c_str(),
stIter->second.cash) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "fprint failed. Message: '";
m_errorStr += strerror(errno);
m_errorStr += "'";
u.c_str(),
stIter->second.cash) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = std::string("fprint failed. Message: '");
m_errorStr += strerror(errno);
m_errorStr += "'";
if (e)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
{
if (mkdir(dn.c_str(), 0700) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Directory \'";
m_errorStr += dn;
m_errorStr += "\' cannot be created.";
if (Touch(fn))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "File \'";
m_errorStr += fn;
m_errorStr += "\' cannot be writen.";
if (access(fileName.c_str(), F_OK) != 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Message for user \'";
m_errorStr += login + "\' with ID \'";
m_errorStr += std::to_string(msg.header.id) + "\' does not exist.";
msgFile = fopen((fileName + ".new").c_str(), "wt");
if (!msgFile)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "File \'" + fileName + "\' cannot be writen.";
printfd(__FILE__, "FILES_STORE::EditMessage - fopen failed. Message: '%s'\n", strerror(errno));
return -1;
if (!res)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = std::string("fprintf failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::EditMessage - fprintf failed. Message: '%s'\n", strerror(errno));
fclose(msgFile);
if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
printfd(__FILE__, "FILES_STORE::EditMessage - rename failed. Message: '%s'\n", strerror(errno));
return -1;
{
if (unlink((dn + messages[i]).c_str()))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno));
return -1;
{
if (unlink((dn + messages[i]).c_str()))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno));
return -1;
msgFile = fopen(fileName.c_str(), "rt");
if (!msgFile)
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "File \'";
m_errorStr += fileName;
m_errorStr += "\' cannot be openned.";
for (int pos = 0; pos < 6; pos++)
{
if (fgets(p, sizeof(p) - 1, msgFile) == NULL) {
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read file \'";
m_errorStr += fileName;
m_errorStr += "\'. Missing data.";
if (feof(msgFile))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read file \'";
m_errorStr += fileName;
m_errorStr += "\'. Missing data.";
if (str2x(p, *(d[pos])))
{
- STG_LOCKER lock(&m_mutex);
+ std::lock_guard lock(m_mutex);
m_errorStr = "Cannot read file \'";
m_errorStr += fileName;
m_errorStr += "\'. Incorrect value. \'";