X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/b27841d687ec9e84983340b5581376dfb24010ea..2196a3a0cdc5384c082febb7f4aa5994cc7d80db:/projects/stargazer/plugins/store/files/file_store.cpp diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index eedb60e8..d654a28c 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -37,7 +37,6 @@ #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" @@ -369,10 +368,6 @@ FILES_STORE::FILES_STORE() : 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() @@ -380,7 +375,7 @@ 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; @@ -392,12 +387,12 @@ std::vector files; 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); @@ -410,12 +405,12 @@ std::vector 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); @@ -428,12 +423,12 @@ std::vector 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); @@ -446,12 +441,12 @@ std::vector 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); @@ -488,7 +483,7 @@ while ((entry = readdir(d))) { 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 += "'"; @@ -513,7 +508,7 @@ closedir(d); 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 += "'"; @@ -532,7 +527,7 @@ strprintf(&fileName, "%s%s", m_storeSettings.GetUsersDir().c_str(), login.c_str( 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; @@ -541,7 +536,7 @@ if (mkdir(fileName.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 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; @@ -550,7 +545,7 @@ if (Touch(fileName)) 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; @@ -568,7 +563,7 @@ if (access(dirName.c_str(), F_OK) != 0) { 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; @@ -581,7 +576,7 @@ if (access(dirName.c_str(), F_OK) == 0) 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; @@ -620,7 +615,7 @@ int e = cf.Error(); 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; @@ -628,14 +623,14 @@ if (e) 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; @@ -643,14 +638,14 @@ if (conf->password.empty()) 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; @@ -664,7 +659,7 @@ try } 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; @@ -672,7 +667,7 @@ catch (const std::string & s) 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; @@ -680,7 +675,7 @@ if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0) 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; @@ -688,7 +683,7 @@ if (cf.ReadInt("down", &conf->disabled, 0) != 0) 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; @@ -713,7 +708,7 @@ for (int i = 0; i < USERDATA_NUM; i++) 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; @@ -746,7 +741,7 @@ int e = cf.Error(); 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; @@ -760,7 +755,7 @@ for (int i = 0; i < DIR_NUM; i++) 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; @@ -770,7 +765,7 @@ for (int i = 0; i < DIR_NUM; i++) 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; @@ -780,7 +775,7 @@ for (int i = 0; i < DIR_NUM; i++) 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; @@ -788,7 +783,7 @@ if (cf.ReadDouble("Cash", &stat->cash, 0) != 0) 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; @@ -796,7 +791,7 @@ if (cf.ReadDouble("FreeMb", &stat->freeMb, 0) != 0) 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; @@ -804,7 +799,7 @@ if (cf.ReadTime("LastCashAddTime", &stat->lastCashAddTime, 0) != 0) 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; @@ -812,7 +807,7 @@ if (cf.ReadTime("PassiveTime", &stat->passiveTime, 0) != 0) 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; @@ -820,7 +815,7 @@ if (cf.ReadDouble("LastCashAdd", &stat->lastCashAdd, 0) != 0) 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; @@ -840,7 +835,7 @@ int e = cfstat.Error(); 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; @@ -851,7 +846,7 @@ e += chown(fileName.c_str(), m_storeSettings.GetConfUID(), m_storeSettings.GetCo 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)); } @@ -896,7 +891,7 @@ fileName = m_storeSettings.GetUsersDir() + "/" + login + "/stat"; 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; @@ -924,7 +919,7 @@ e += chown(fileName.c_str(), m_storeSettings.GetStatUID(), m_storeSettings.GetSt 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)); } @@ -949,7 +944,7 @@ if (f) } 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; @@ -960,7 +955,7 @@ e += chown(fileName.c_str(), m_storeSettings.GetLogUID(), m_storeSettings.GetLog 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)); } @@ -985,7 +980,7 @@ if (f) } 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; @@ -996,7 +991,7 @@ e += chown(fileName.c_str(), m_storeSettings.GetLogUID(), m_storeSettings.GetLog 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)); } @@ -1073,7 +1068,7 @@ CONFIGFILE s(stat1, true); 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; @@ -1088,7 +1083,7 @@ CONFIGFILE s2(stat2, true); 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; @@ -1126,7 +1121,7 @@ strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), login. 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; @@ -1141,7 +1136,7 @@ std::string fileName; 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 += "'"; @@ -1163,7 +1158,7 @@ strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), ac.log 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; @@ -1219,7 +1214,7 @@ std::string p; 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; @@ -1227,7 +1222,7 @@ if (cf.Error()) 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; @@ -1261,7 +1256,7 @@ if (cf.ReadUShortInt("ChgConf", &a, 0) == 0) 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; @@ -1271,7 +1266,7 @@ if (cf.ReadUShortInt("ChgPassword", &a, 0) == 0) 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; @@ -1281,7 +1276,7 @@ if (cf.ReadUShortInt("ChgStat", &a, 0) == 0) 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; @@ -1291,7 +1286,7 @@ if (cf.ReadUShortInt("ChgCash", &a, 0) == 0) 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; @@ -1301,7 +1296,7 @@ if (cf.ReadUShortInt("UsrAddDel", &a, 0) == 0) 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; @@ -1311,7 +1306,7 @@ if (cf.ReadUShortInt("ChgAdmin", &a, 0) == 0) 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; @@ -1321,7 +1316,7 @@ if (cf.ReadUShortInt("ChgTariff", &a, 0) == 0) 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; @@ -1346,7 +1341,7 @@ std::string fileName; 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; @@ -1360,7 +1355,7 @@ std::string fileName; 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 += "'"; @@ -1378,7 +1373,7 @@ td->tariffConf.name = tariffName; 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; @@ -1390,7 +1385,7 @@ for (int i = 0; idirPrice[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; @@ -1415,7 +1410,7 @@ for (int i = 0; idirPrice[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; @@ -1425,7 +1420,7 @@ for (int i = 0; idirPrice[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; @@ -1435,7 +1430,7 @@ for (int i = 0; idirPrice[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; @@ -1445,7 +1440,7 @@ for (int i = 0; idirPrice[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; @@ -1454,7 +1449,7 @@ for (int i = 0; idirPrice[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; @@ -1463,7 +1458,7 @@ for (int i = 0; idirPrice[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; @@ -1472,7 +1467,7 @@ for (int i = 0; itariffConf.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; @@ -1480,7 +1475,7 @@ if (conf.ReadDouble("Fee", &td->tariffConf.fee, 0) < 0) 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; @@ -1488,7 +1483,7 @@ if (conf.ReadDouble("Free", &td->tariffConf.free, 0) < 0) 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; @@ -1496,7 +1491,7 @@ if (conf.ReadDouble("PassiveCost", &td->tariffConf.passiveCost, 0) < 0) 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; @@ -1529,7 +1524,7 @@ std::string fileName = m_storeSettings.GetTariffsDir() + "/" + tariffName + ".tf 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; @@ -1590,7 +1585,7 @@ strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), nam 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; @@ -1605,7 +1600,7 @@ std::string fileName; 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 += "'"; @@ -1627,7 +1622,7 @@ strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), con 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; @@ -1650,7 +1645,7 @@ CONFIGFILE cf(fileName); 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; @@ -1658,7 +1653,7 @@ if (cf.Error()) 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; @@ -1666,7 +1661,7 @@ if (cf.ReadString("name", &conf->name, name)) 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; @@ -1674,7 +1669,7 @@ if (cf.ReadString("comment", &conf->comment, "")) 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; @@ -1683,7 +1678,7 @@ if (cf.ReadDouble("cost", &conf->cost, 0.0)) 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; @@ -1710,7 +1705,7 @@ if (access(dn, F_OK) != 0) { 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; @@ -1722,7 +1717,7 @@ e += chmod(dn, m_storeSettings.GetStatModeDir()); 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)); } @@ -1743,7 +1738,7 @@ if (access(dn, F_OK) != 0) { 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; @@ -1755,7 +1750,7 @@ e += chmod(dn, m_storeSettings.GetStatModeDir()); 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)); } @@ -1769,7 +1764,7 @@ if (access(dn, F_OK) != 0) { 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; @@ -1781,7 +1776,7 @@ e += chmod(dn, m_storeSettings.GetStatModeDir()); 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)); } @@ -1791,7 +1786,7 @@ statFile = fopen (fn, "at"); 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; @@ -1818,7 +1813,7 @@ s2 = lt2->tm_sec; 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); @@ -1840,7 +1835,7 @@ while (stIter != statTree.end()) 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 += "'"; @@ -1856,7 +1851,7 @@ while (stIter != statTree.end()) 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 += "'"; @@ -1876,7 +1871,7 @@ e += chmod(fn, m_storeSettings.GetStatMode()); 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)); } @@ -1894,7 +1889,7 @@ if (access(dn.c_str(), F_OK) != 0) { 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."; @@ -1912,7 +1907,7 @@ strprintf(&fn, "%s/%lld", dn.c_str(), msg->header.id); 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."; @@ -1932,7 +1927,7 @@ strprintf(&fileName, "%s/%s/messages/%lld", m_storeSettings.GetUsersDir().c_str( 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."; @@ -1945,7 +1940,7 @@ Touch(fileName + ".new"); 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; @@ -1962,7 +1957,7 @@ res &= (fprintf(msgFile, "%s", msg.text.c_str()) >= 0); 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); @@ -1975,7 +1970,7 @@ chmod((fileName + ".new").c_str(), m_storeSettings.GetConfMode()); 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; @@ -2020,7 +2015,7 @@ for (unsigned i = 0; i < messages.size(); i++) { 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; @@ -2038,7 +2033,7 @@ for (unsigned i = 0; i < messages.size(); i++) { 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; @@ -2060,7 +2055,7 @@ FILE * msgFile; 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."; @@ -2081,7 +2076,7 @@ memset(p, 0, sizeof(p)); 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."; @@ -2099,7 +2094,7 @@ for (int pos = 0; pos < 6; pos++) 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."; @@ -2111,7 +2106,7 @@ for (int pos = 0; pos < 6; pos++) 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. \'";