X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/f907011b4827e85763372cdea76944b3b1cc3fd2..91002d861d8e0729e84f9ef65a19001d515d7dbe:/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 fa0483a8..689f5fab 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -58,15 +58,18 @@ #define adm_enc_passwd "cjeifY8m3" -using namespace std; - -int GetFileList(vector * fileList, const string & directory, mode_t mode, const string & ext); +int GetFileList(std::vector * fileList, const std::string & directory, mode_t mode, const std::string & ext); const int pt_mega = 1024 * 1024; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR fsc; +} + +extern "C" STORE * GetStore(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -96,11 +99,11 @@ FILES_STORE_SETTINGS::FILES_STORE_SETTINGS() { } //----------------------------------------------------------------------------- -int FILES_STORE_SETTINGS::ParseOwner(const vector & moduleParams, const string & owner, uid_t * uid) +int FILES_STORE_SETTINGS::ParseOwner(const std::vector & moduleParams, const std::string & owner, uid_t * uid) { PARAM_VALUE pv; pv.param = owner; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); if (pvi == moduleParams.end()) { @@ -117,11 +120,11 @@ if (User2UID(pvi->value[0].c_str(), uid) < 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE_SETTINGS::ParseGroup(const vector & moduleParams, const string & group, gid_t * gid) +int FILES_STORE_SETTINGS::ParseGroup(const std::vector & moduleParams, const std::string & group, gid_t * gid) { PARAM_VALUE pv; pv.param = group; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); if (pvi == moduleParams.end()) { @@ -138,7 +141,7 @@ if (Group2GID(pvi->value[0].c_str(), gid) < 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE_SETTINGS::ParseYesNo(const string & value, bool * val) +int FILES_STORE_SETTINGS::ParseYesNo(const std::string & value, bool * val) { if (0 == strcasecmp(value.c_str(), "yes")) { @@ -155,11 +158,11 @@ errorStr = "Incorrect value \'" + value + "\'."; return -1; } //----------------------------------------------------------------------------- -int FILES_STORE_SETTINGS::ParseMode(const vector & moduleParams, const string & modeStr, mode_t * mode) +int FILES_STORE_SETTINGS::ParseMode(const std::vector & moduleParams, const std::string & modeStr, mode_t * mode) { PARAM_VALUE pv; pv.param = modeStr; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); if (pvi == moduleParams.end()) { @@ -199,7 +202,7 @@ if (ParseGroup(s.moduleParams, "UserLogGroup", &userLogGID) < 0) if (ParseMode(s.moduleParams, "UserLogMode", &userLogMode) < 0) return -1; -vector::const_iterator pvi; +std::vector::const_iterator pvi; PARAM_VALUE pv; pv.param = "RemoveBak"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -252,7 +255,7 @@ adminsDir = workDir + "/admins/"; return 0; } //----------------------------------------------------------------------------- -const string & FILES_STORE_SETTINGS::GetStrError() const +const std::string & FILES_STORE_SETTINGS::GetStrError() const { return errorStr; } @@ -263,7 +266,7 @@ struct passwd * pw; pw = getpwnam(user); if (!pw) { - errorStr = string("User \'") + string(user) + string("\' not found in system."); + errorStr = std::string("User \'") + std::string(user) + std::string("\' not found in system."); printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } @@ -278,7 +281,7 @@ struct group * grp; grp = getgrnam(gr); if (!grp) { - errorStr = string("Group \'") + string(gr) + string("\' not found in system."); + errorStr = std::string("Group \'") + std::string(gr) + std::string("\' not found in system."); printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } @@ -294,7 +297,7 @@ char b; char c; if (strlen(str) > 3) { - errorStr = string("Error parsing mode \'") + str + string("\'"); + errorStr = std::string("Error parsing mode \'") + str + std::string("\'"); printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } @@ -302,7 +305,7 @@ if (strlen(str) > 3) for (int i = 0; i < 3; i++) if (str[i] > '7' || str[i] < '0') { - errorStr = string("Error parsing mode \'") + str + string("\'"); + errorStr = std::string("Error parsing mode \'") + str + std::string("\'"); printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } @@ -341,73 +344,74 @@ FILES_STORE::FILES_STORE() version("file_store v.1.04"), storeSettings(), settings(), - mutex() + mutex(), + logger(GetPluginLogger(GetStgLogger(), "store_files")) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&mutex, &attr); -}; +} //----------------------------------------------------------------------------- int FILES_STORE::ParseSettings() { int ret = storeSettings.ParseSettings(settings); if (ret) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = storeSettings.GetStrError(); } return ret; } //----------------------------------------------------------------------------- -int FILES_STORE::GetUsersList(vector * userList) const +int FILES_STORE::GetUsersList(std::vector * userList) const { -vector files; +std::vector files; if (GetFileList(&files, storeSettings.GetUsersDir(), S_IFDIR, "")) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Failed to open '" + storeSettings.GetUsersDir() + "': " + string(strerror(errno)); + STG_LOCKER lock(&mutex); + errorStr = "Failed to open '" + storeSettings.GetUsersDir() + "': " + std::string(strerror(errno)); return -1; } -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); userList->swap(files); return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::GetAdminsList(vector * adminList) const +int FILES_STORE::GetAdminsList(std::vector * adminList) const { -vector files; +std::vector files; if (GetFileList(&files, storeSettings.GetAdminsDir(), S_IFREG, ".adm")) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Failed to open '" + storeSettings.GetAdminsDir() + "': " + string(strerror(errno)); + STG_LOCKER lock(&mutex); + errorStr = "Failed to open '" + storeSettings.GetAdminsDir() + "': " + std::string(strerror(errno)); return -1; } -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); adminList->swap(files); return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::GetTariffsList(vector * tariffList) const +int FILES_STORE::GetTariffsList(std::vector * tariffList) const { -vector files; +std::vector files; if (GetFileList(&files, storeSettings.GetTariffsDir(), S_IFREG, ".tf")) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Failed to open '" + storeSettings.GetTariffsDir() + "': " + string(strerror(errno)); + STG_LOCKER lock(&mutex); + errorStr = "Failed to open '" + storeSettings.GetTariffsDir() + "': " + std::string(strerror(errno)); return -1; } -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); tariffList->swap(files); @@ -433,8 +437,8 @@ while ((entry = readdir(d))) if (!(strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))) continue; - string str = path; - str += "/" + string(entry->d_name); + std::string str = path; + str += "/" + std::string(entry->d_name); struct stat st; if (stat(str.c_str(), &st)) @@ -444,7 +448,7 @@ while ((entry = readdir(d))) { if (unlink(str.c_str())) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "unlink failed. Message: '"; errorStr += strerror(errno); errorStr += "'"; @@ -469,7 +473,7 @@ closedir(d); if (rmdir(path)) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "rmdir failed. Message: '"; errorStr += strerror(errno); errorStr += "'"; @@ -480,16 +484,16 @@ if (rmdir(path)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::AddUser(const string & login) const +int FILES_STORE::AddUser(const std::string & login) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s%s", 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(&mutex, __FILE__, __LINE__); - errorStr = string("mkdir failed. Message: '") + strerror(errno) + "'"; + STG_LOCKER lock(&mutex); + errorStr = std::string("mkdir failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::AddUser - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -497,7 +501,7 @@ if (mkdir(fileName.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == strprintf(&fileName, "%s%s/conf", storeSettings.GetUsersDir().c_str(), login.c_str()); if (Touch(fileName)) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot create file \"" + fileName + "\'"; printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); return -1; @@ -506,7 +510,7 @@ if (Touch(fileName)) strprintf(&fileName, "%s%s/stat", storeSettings.GetUsersDir().c_str(), login.c_str()); if (Touch(fileName)) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot create file \"" + fileName + "\'"; printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); return -1; @@ -514,17 +518,17 @@ if (Touch(fileName)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::DelUser(const string & login) const +int FILES_STORE::DelUser(const std::string & login) const { -string dirName; -string dirName1; +std::string dirName; +std::string dirName1; -strprintf(&dirName, "%s/"DELETED_USERS_DIR, storeSettings.GetWorkDir().c_str()); +strprintf(&dirName, "%s/%s", storeSettings.GetWorkDir().c_str(), DELETED_USERS_DIR); if (access(dirName.c_str(), F_OK) != 0) { if (mkdir(dirName.c_str(), 0700) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Directory '" + dirName + "' cannot be created."; printfd(__FILE__, "FILES_STORE::DelUser - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; @@ -533,11 +537,11 @@ if (access(dirName.c_str(), F_OK) != 0) if (access(dirName.c_str(), F_OK) == 0) { - strprintf(&dirName, "%s/"DELETED_USERS_DIR"/%s.%lu", storeSettings.GetWorkDir().c_str(), login.c_str(), time(NULL)); + strprintf(&dirName, "%s/%s/%s.%lu", storeSettings.GetWorkDir().c_str(), DELETED_USERS_DIR, login.c_str(), time(NULL)); strprintf(&dirName1, "%s/%s", storeSettings.GetUsersDir().c_str(), login.c_str()); if (rename(dirName1.c_str(), dirName.c_str())) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error moving dir from " + dirName1 + " to " + dirName; printfd(__FILE__, "FILES_STORE::DelUser - rename failed. Message: '%s'\n", strerror(errno)); return -1; @@ -554,9 +558,9 @@ else return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreUserConf(USER_CONF * conf, const string & login) const +int FILES_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login) const { -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/conf"; if (RestoreUserConf(conf, login, fileName)) { @@ -569,15 +573,14 @@ if (RestoreUserConf(conf, login, fileName)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreUserConf(USER_CONF * conf, const string & login, const string & fileName) const +int FILES_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login, const std::string & fileName) const { CONFIGFILE cf(fileName); int e = cf.Error(); -string str; if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "User \'" + login + "\' data not read."; printfd(__FILE__, "FILES_STORE::RestoreUserConf - conf read failed for user '%s'\n", login.c_str()); return -1; @@ -585,14 +588,14 @@ if (e) if (cf.ReadString("Password", &conf->password, "") < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "User \'" + login + "\' password is blank."; printfd(__FILE__, "FILES_STORE::RestoreUserConf - password is blank for user '%s'\n", login.c_str()); return -1; @@ -600,38 +603,38 @@ if (conf->password.empty()) if (cf.ReadString("tariff", &conf->tariffName, "") < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "User \'" + login + "\' tariff is blank."; printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff is blank for user '%s'\n", login.c_str()); return -1; } -string ipStr; +std::string ipStr; cf.ReadString("IP", &ipStr, "?"); -USER_IPS i; +USER_IPS ips; try { - i = StrToIPS(ipStr); + ips = StrToIPS(ipStr); } -catch (const string & s) +catch (const std::string & s) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; } -conf->ips = i; +conf->ips = ips; if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -639,7 +642,7 @@ if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0) if (cf.ReadInt("down", &conf->disabled, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -647,7 +650,7 @@ if (cf.ReadInt("down", &conf->disabled, 0) != 0) if (cf.ReadInt("passive", &conf->passive, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -672,7 +675,7 @@ for (int i = 0; i < USERDATA_NUM; i++) if (cf.ReadDouble("Credit", &conf->credit, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -681,9 +684,9 @@ if (cf.ReadDouble("Credit", &conf->credit, 0) != 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreUserStat(USER_STAT * stat, const string & login) const +int FILES_STORE::RestoreUserStat(USER_STAT * stat, const std::string & login) const { -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/stat"; if (RestoreUserStat(stat, login, fileName)) @@ -697,7 +700,7 @@ if (RestoreUserStat(stat, login, fileName)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreUserStat(USER_STAT * stat, const string & login, const string & fileName) const +int FILES_STORE::RestoreUserStat(USER_STAT * stat, const std::string & login, const std::string & fileName) const { CONFIGFILE cf(fileName); @@ -705,7 +708,7 @@ int e = cf.Error(); if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -719,27 +722,27 @@ for (int i = 0; i < DIR_NUM; i++) snprintf(s, 22, "D%d", i); if (cf.ReadULongLongInt(s, &traff, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "User \'" + login + "\' stat not read. Parameter " + string(s); + STG_LOCKER lock(&mutex); + 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; } - stat->down[i] = traff; + stat->monthDown[i] = traff; snprintf(s, 22, "U%d", i); if (cf.ReadULongLongInt(s, &traff, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "User \'" + login + "\' stat not read. Parameter " + string(s); + STG_LOCKER lock(&mutex); + 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; } - stat->up[i] = traff; + stat->monthUp[i] = traff; } if (cf.ReadDouble("Cash", &stat->cash, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -747,7 +750,7 @@ if (cf.ReadDouble("Cash", &stat->cash, 0) != 0) if (cf.ReadDouble("FreeMb", &stat->freeMb, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -755,7 +758,7 @@ if (cf.ReadDouble("FreeMb", &stat->freeMb, 0) != 0) if (cf.ReadTime("LastCashAddTime", &stat->lastCashAddTime, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -763,7 +766,7 @@ if (cf.ReadTime("LastCashAddTime", &stat->lastCashAddTime, 0) != 0) if (cf.ReadTime("PassiveTime", &stat->passiveTime, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -771,7 +774,7 @@ if (cf.ReadTime("PassiveTime", &stat->passiveTime, 0) != 0) if (cf.ReadDouble("LastCashAdd", &stat->lastCashAdd, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -779,7 +782,7 @@ if (cf.ReadDouble("LastCashAdd", &stat->lastCashAdd, 0) != 0) if (cf.ReadTime("LastActivityTime", &stat->lastActivityTime, 0) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); 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; @@ -788,9 +791,9 @@ if (cf.ReadTime("LastActivityTime", &stat->lastActivityTime, 0) != 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::SaveUserConf(const USER_CONF & conf, const string & login) const +int FILES_STORE::SaveUserConf(const USER_CONF & conf, const std::string & login) const { -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/conf"; CONFIGFILE cfstat(fileName, true); @@ -799,8 +802,8 @@ int e = cfstat.Error(); if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("User \'") + login + "\' conf not written\n"; + STG_LOCKER lock(&mutex); + 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; } @@ -810,7 +813,7 @@ e += chown(fileName.c_str(), storeSettings.GetConfUID(), storeSettings.GetConfGI if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); printfd(__FILE__, "FILES_STORE::SaveUserConf - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno)); } @@ -837,17 +840,16 @@ for (int i = 0; i < USERDATA_NUM; i++) } cfstat.WriteInt("CreditExpire", conf.creditExpire); -stringstream ipStr; +std::ostringstream ipStr; ipStr << conf.ips; cfstat.WriteString("IP", ipStr.str()); return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::SaveUserStat(const USER_STAT & stat, const string & login) const +int FILES_STORE::SaveUserStat(const USER_STAT & stat, const std::string & login) const { -char s[22]; -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/stat"; { @@ -856,18 +858,19 @@ fileName = storeSettings.GetUsersDir() + "/" + login + "/stat"; if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("User \'") + login + "\' stat not written\n"; + STG_LOCKER lock(&mutex); + 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; } for (int i = 0; i < DIR_NUM; i++) { + char s[22]; snprintf(s, 22, "D%d", i); - cfstat.WriteInt(s, stat.down[i]); + cfstat.WriteInt(s, stat.monthDown[i]); snprintf(s, 22, "U%d", i); - cfstat.WriteInt(s, stat.up[i]); + cfstat.WriteInt(s, stat.monthUp[i]); } cfstat.WriteDouble("Cash", stat.cash); @@ -883,18 +886,18 @@ e += chown(fileName.c_str(), storeSettings.GetStatUID(), storeSettings.GetStatGI if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); printfd(__FILE__, "FILES_STORE::SaveUserStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno)); } return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::WriteLogString(const string & str, const string & login) const +int FILES_STORE::WriteLogString(const std::string & str, const std::string & login) const { FILE * f; time_t tm = time(NULL); -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/log"; f = fopen(fileName.c_str(), "at"); @@ -908,7 +911,7 @@ if (f) } else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot open \'" + fileName + "\'"; printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str()); return -1; @@ -919,18 +922,18 @@ e += chown(fileName.c_str(), storeSettings.GetLogUID(), storeSettings.GetLogGID( if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno)); } return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::WriteLog2String(const string & str, const string & login) const +int FILES_STORE::WriteLog2String(const std::string & str, const std::string & login) const { FILE * f; time_t tm = time(NULL); -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/log2"; f = fopen(fileName.c_str(), "at"); @@ -944,7 +947,7 @@ if (f) } else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot open \'" + fileName + "\'"; printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str()); return -1; @@ -955,55 +958,55 @@ e += chown(fileName.c_str(), storeSettings.GetLogUID(), storeSettings.GetLogGID( if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno)); } return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::WriteUserChgLog(const string & login, - const string & admLogin, +int FILES_STORE::WriteUserChgLog(const std::string & login, + const std::string & admLogin, uint32_t admIP, - const string & paramName, - const string & oldValue, - const string & newValue, - const string & message) const + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message) const { -string userLogMsg = "Admin \'" + admLogin + "\', " + inet_ntostring(admIP) + ": \'" +std::string userLogMsg = "Admin \'" + admLogin + "\', " + inet_ntostring(admIP) + ": \'" + paramName + "\' parameter changed from \'" + oldValue + "\' to \'" + newValue + "\'. " + message; return WriteLogString(userLogMsg, login); } //----------------------------------------------------------------------------- -int FILES_STORE::WriteUserConnect(const string & login, uint32_t ip) const +int FILES_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const { -string logStr = "Connect, " + inet_ntostring(ip); +std::string logStr = "Connect, " + inet_ntostring(ip); if (WriteLogString(logStr, login)) return -1; return WriteLog2String(logStr, login); } //----------------------------------------------------------------------------- -int FILES_STORE::WriteUserDisconnect(const string & login, - const DIR_TRAFF & up, - const DIR_TRAFF & down, +int FILES_STORE::WriteUserDisconnect(const std::string & login, + const DIR_TRAFF & monthUp, + const DIR_TRAFF & monthDown, const DIR_TRAFF & sessionUp, const DIR_TRAFF & sessionDown, double cash, double freeMb, const std::string & reason) const { -stringstream logStr; +std::ostringstream logStr; logStr << "Disconnect, " << " session upload: \'" << sessionUp << "\' session download: \'" << sessionDown << "\' month upload: \'" - << up + << monthUp << "\' month download: \'" - << down + << monthDown << "\' cash: \'" << cash << "\'"; @@ -1021,10 +1024,10 @@ logStr << " freeMb: \'" return WriteLog2String(logStr.str(), login); } //----------------------------------------------------------------------------- -int FILES_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const +int FILES_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const { // Classic stats -string stat1; +std::string stat1; strprintf(&stat1,"%s/%s/stat.%d.%02d", storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1); @@ -1032,14 +1035,14 @@ CONFIGFILE s(stat1, true); if (s.Error()) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot create file '" + stat1 + "'"; printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str()); return -1; } // New stats -string stat2; +std::string stat2; strprintf(&stat2,"%s/%s/stat2.%d.%02d", storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1); @@ -1047,7 +1050,7 @@ CONFIGFILE s2(stat2, true); if (s2.Error()) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot create file '" + stat2 + "'"; printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str()); return -1; @@ -1057,11 +1060,11 @@ for (size_t i = 0; i < DIR_NUM; i++) { char dirName[3]; snprintf(dirName, 3, "U%llu", (unsigned long long)i); - s.WriteInt(dirName, stat.up[i]); // Classic - s2.WriteInt(dirName, stat.up[i]); // New + s.WriteInt(dirName, stat.monthUp[i]); // Classic + s2.WriteInt(dirName, stat.monthUp[i]); // New snprintf(dirName, 3, "D%llu", (unsigned long long)i); - s.WriteInt(dirName, stat.down[i]); // Classic - s2.WriteInt(dirName, stat.down[i]); // New + s.WriteInt(dirName, stat.monthDown[i]); // Classic + s2.WriteInt(dirName, stat.monthDown[i]); // New } // Classic @@ -1078,14 +1081,14 @@ s2.WriteInt("LastActivityTime", stat.lastActivityTime); return 0; } //-----------------------------------------------------------------------------*/ -int FILES_STORE::AddAdmin(const string & login) const +int FILES_STORE::AddAdmin(const std::string & login) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str()); if (Touch(fileName)) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot create file " + fileName; printfd(__FILE__, "FILES_STORE::AddAdmin - failed to add admin '%s'\n", login.c_str()); return -1; @@ -1094,13 +1097,13 @@ if (Touch(fileName)) return 0; } //-----------------------------------------------------------------------------*/ -int FILES_STORE::DelAdmin(const string & login) const +int FILES_STORE::DelAdmin(const std::string & login) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str()); if (unlink(fileName.c_str())) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "unlink failed. Message: '"; errorStr += strerror(errno); errorStr += "'"; @@ -1111,11 +1114,7 @@ return 0; //-----------------------------------------------------------------------------*/ int FILES_STORE::SaveAdmin(const ADMIN_CONF & ac) const { -char passwordE[2 * ADM_PASSWD_LEN + 2]; -char pass[ADM_PASSWD_LEN + 1]; -char adminPass[ADM_PASSWD_LEN + 1]; - -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login.c_str()); @@ -1126,27 +1125,31 @@ strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot write admin " + ac.login + ". " + fileName; printfd(__FILE__, "FILES_STORE::SaveAdmin - failed to save admin '%s'\n", ac.login.c_str()); return -1; } + char pass[ADM_PASSWD_LEN + 1]; memset(pass, 0, sizeof(pass)); + + char adminPass[ADM_PASSWD_LEN + 1]; memset(adminPass, 0, sizeof(adminPass)); BLOWFISH_CTX ctx; - EnDecodeInit(adm_enc_passwd, strlen(adm_enc_passwd), &ctx); + InitContext(adm_enc_passwd, strlen(adm_enc_passwd), &ctx); strncpy(adminPass, ac.password.c_str(), ADM_PASSWD_LEN); adminPass[ADM_PASSWD_LEN - 1] = 0; for (int i = 0; i < ADM_PASSWD_LEN/8; i++) { - EncodeString(pass + 8*i, adminPass + 8*i, &ctx); + EncryptBlock(pass + 8*i, adminPass + 8*i, &ctx); } pass[ADM_PASSWD_LEN - 1] = 0; + char passwordE[2 * ADM_PASSWD_LEN + 2]; Encode12(passwordE, pass, ADM_PASSWD_LEN); cf.WriteString("password", passwordE); @@ -1164,9 +1167,9 @@ strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreAdmin(ADMIN_CONF * ac, const string & login) const +int FILES_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str()); CONFIGFILE cf(fileName); char pass[ADM_PASSWD_LEN + 1]; @@ -1174,21 +1177,19 @@ char password[ADM_PASSWD_LEN + 1]; char passwordE[2 * ADM_PASSWD_LEN + 2]; BLOWFISH_CTX ctx; -string p; +std::string p; if (cf.Error()) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot open " + fileName; printfd(__FILE__, "FILES_STORE::RestoreAdmin - failed to restore admin '%s'\n", ac->login.c_str()); return -1; } -int a; - if (cf.ReadString("password", &p, "*")) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error in parameter password"; printfd(__FILE__, "FILES_STORE::RestoreAdmin - password read failed for admin '%s'\n", ac->login.c_str()); return -1; @@ -1202,11 +1203,11 @@ memset(pass, 0, sizeof(pass)); if (passwordE[0] != 0) { Decode21(pass, passwordE); - EnDecodeInit(adm_enc_passwd, strlen(adm_enc_passwd), &ctx); + InitContext(adm_enc_passwd, strlen(adm_enc_passwd), &ctx); for (int i = 0; i < ADM_PASSWD_LEN/8; i++) { - DecodeString(password + 8*i, pass + 8*i, &ctx); + DecryptBlock(password + 8*i, pass + 8*i, &ctx); } } else @@ -1216,82 +1217,84 @@ else ac->password = password; -if (cf.ReadInt("ChgConf", &a, 0) == 0) +uint16_t a; + +if (cf.ReadUShortInt("ChgConf", &a, 0) == 0) ac->priv.userConf = a; else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error in parameter ChgConf"; printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgconf read failed for admin '%s'\n", ac->login.c_str()); return -1; } -if (cf.ReadInt("ChgPassword", &a, 0) == 0) +if (cf.ReadUShortInt("ChgPassword", &a, 0) == 0) ac->priv.userPasswd = a; else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error in parameter ChgPassword"; printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgpassword read failed for admin '%s'\n", ac->login.c_str()); return -1; } -if (cf.ReadInt("ChgStat", &a, 0) == 0) +if (cf.ReadUShortInt("ChgStat", &a, 0) == 0) ac->priv.userStat = a; else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error in parameter ChgStat"; printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgstat read failed for admin '%s'\n", ac->login.c_str()); return -1; } -if (cf.ReadInt("ChgCash", &a, 0) == 0) +if (cf.ReadUShortInt("ChgCash", &a, 0) == 0) ac->priv.userCash = a; else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error in parameter ChgCash"; printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgcash read failed for admin '%s'\n", ac->login.c_str()); return -1; } -if (cf.ReadInt("UsrAddDel", &a, 0) == 0) +if (cf.ReadUShortInt("UsrAddDel", &a, 0) == 0) ac->priv.userAddDel = a; else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error in parameter UsrAddDel"; printfd(__FILE__, "FILES_STORE::RestoreAdmin - usradddel read failed for admin '%s'\n", ac->login.c_str()); return -1; } -if (cf.ReadInt("ChgAdmin", &a, 0) == 0) +if (cf.ReadUShortInt("ChgAdmin", &a, 0) == 0) ac->priv.adminChg = a; else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error in parameter ChgAdmin"; printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgadmin read failed for admin '%s'\n", ac->login.c_str()); return -1; } -if (cf.ReadInt("ChgTariff", &a, 0) == 0) +if (cf.ReadUShortInt("ChgTariff", &a, 0) == 0) ac->priv.tariffChg = a; else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error in parameter ChgTariff"; printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgtariff read failed for admin '%s'\n", ac->login.c_str()); return -1; } -if (cf.ReadInt("ChgService", &a, 0) == 0) +if (cf.ReadUShortInt("ChgService", &a, 0) == 0) ac->priv.serviceChg = a; else ac->priv.serviceChg = 0; -if (cf.ReadInt("ChgCorp", &a, 0) == 0) +if (cf.ReadUShortInt("ChgCorp", &a, 0) == 0) ac->priv.corpChg = a; else ac->priv.corpChg = 0; @@ -1299,13 +1302,13 @@ else return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::AddTariff(const string & name) const +int FILES_STORE::AddTariff(const std::string & name) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.tf", storeSettings.GetTariffsDir().c_str(), name.c_str()); if (Touch(fileName)) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot create file " + fileName; printfd(__FILE__, "FILES_STORE::AddTariff - failed to add tariff '%s'\n", name.c_str()); return -1; @@ -1313,13 +1316,13 @@ if (Touch(fileName)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::DelTariff(const string & name) const +int FILES_STORE::DelTariff(const std::string & name) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.tf", storeSettings.GetTariffsDir().c_str(), name.c_str()); if (unlink(fileName.c_str())) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "unlink failed. Message: '"; errorStr += strerror(errno); errorStr += "'"; @@ -1328,28 +1331,28 @@ if (unlink(fileName.c_str())) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreTariff(TARIFF_DATA * td, const string & tariffName) const +int FILES_STORE::RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const { -string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; +std::string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; CONFIGFILE conf(fileName); -string str; +std::string str; td->tariffConf.name = tariffName; if (conf.Error() != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read file " + fileName; printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to read tariff '%s'\n", tariffName.c_str()); return -1; } -string param; +std::string param; for (int i = 0; idirPrice[i].priceDayA, 0.0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedaya read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1374,7 +1377,7 @@ for (int i = 0; idirPrice[i].priceDayB, 0.0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedayb read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1384,7 +1387,7 @@ for (int i = 0; idirPrice[i].priceNightA, 0.0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenighta read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1394,7 +1397,7 @@ for (int i = 0; idirPrice[i].priceNightB, 0.0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenightb read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1404,7 +1407,7 @@ for (int i = 0; idirPrice[i].threshold, 0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; printfd(__FILE__, "FILES_STORE::RestoreTariff - threshold read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1413,7 +1416,7 @@ for (int i = 0; idirPrice[i].singlePrice, 0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; printfd(__FILE__, "FILES_STORE::RestoreTariff - singleprice read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1422,7 +1425,7 @@ for (int i = 0; idirPrice[i].noDiscount, 0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; printfd(__FILE__, "FILES_STORE::RestoreTariff - nodiscount read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1431,7 +1434,7 @@ for (int i = 0; itariffConf.fee, 0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter Fee"; printfd(__FILE__, "FILES_STORE::RestoreTariff - fee read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1439,7 +1442,7 @@ if (conf.ReadDouble("Fee", &td->tariffConf.fee, 0) < 0) if (conf.ReadDouble("Free", &td->tariffConf.free, 0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter Free"; printfd(__FILE__, "FILES_STORE::RestoreTariff - free read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1447,7 +1450,7 @@ if (conf.ReadDouble("Free", &td->tariffConf.free, 0) < 0) if (conf.ReadDouble("PassiveCost", &td->tariffConf.passiveCost, 0) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter PassiveCost"; printfd(__FILE__, "FILES_STORE::RestoreTariff - passivecost read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1455,7 +1458,7 @@ if (conf.ReadDouble("PassiveCost", &td->tariffConf.passiveCost, 0) < 0) if (conf.ReadString("TraffType", &str, "") < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter TraffType"; printfd(__FILE__, "FILES_STORE::RestoreTariff - trafftype read failed for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1474,7 +1477,7 @@ else td->tariffConf.traffType = TRAFF_MAX; else { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read tariff " + tariffName + ". Parameter TraffType incorrect"; printfd(__FILE__, "FILES_STORE::RestoreTariff - invalid trafftype for tariff '%s'\n", tariffName.c_str()); return -1; @@ -1487,9 +1490,9 @@ else return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::SaveTariff(const TARIFF_DATA & td, const string & tariffName) const +int FILES_STORE::SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const { -string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; +std::string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; { CONFIGFILE cf(fileName, true); @@ -1498,13 +1501,13 @@ string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error writing tariff " + tariffName; printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to save tariff '%s'\n", tariffName.c_str()); return e; } - string param; + std::string param; for (int i = 0; i < DIR_NUM; i++) { strprintf(¶m, "PriceDayA%d", i); @@ -1522,7 +1525,7 @@ string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; strprintf(¶m, "Threshold%d", i); cf.WriteInt(param, td.dirPrice[i].threshold); - string s; + std::string s; strprintf(¶m, "Time%d", i); strprintf(&s, "%0d:%0d-%0d:%0d", @@ -1566,9 +1569,9 @@ string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::WriteDetailedStat(const map & statTree, +int FILES_STORE::WriteDetailedStat(const std::map & statTree, time_t lastStat, - const string & login) const + const std::string & login) const { char fn[FN_STR_LEN]; char dn[FN_STR_LEN]; @@ -1583,8 +1586,8 @@ if (access(dn, F_OK) != 0) { if (mkdir(dn, 0700) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Directory \'" + string(dn) + "\' cannot be created."; + STG_LOCKER lock(&mutex); + errorStr = "Directory \'" + std::string(dn) + "\' cannot be created."; printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1595,7 +1598,7 @@ e += chmod(dn, storeSettings.GetStatModeDir()); if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno)); } @@ -1616,8 +1619,8 @@ if (access(dn, F_OK) != 0) { if (mkdir(dn, 0700) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Directory \'" + string(dn) + "\' cannot be created."; + STG_LOCKER lock(&mutex); + errorStr = "Directory \'" + std::string(dn) + "\' cannot be created."; printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1628,7 +1631,7 @@ e += chmod(dn, storeSettings.GetStatModeDir()); if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno)); } @@ -1642,8 +1645,8 @@ if (access(dn, F_OK) != 0) { if (mkdir(dn, 0700) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Directory \'" + string(dn) + "\' cannot be created."; + STG_LOCKER lock(&mutex); + errorStr = "Directory \'" + std::string(dn) + "\' cannot be created."; printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1654,7 +1657,7 @@ e += chmod(dn, storeSettings.GetStatModeDir()); if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno)); } @@ -1664,8 +1667,8 @@ statFile = fopen (fn, "at"); if (!statFile) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "File \'" + string(fn) + "\' cannot be written."; + STG_LOCKER lock(&mutex); + errorStr = "File \'" + std::string(fn) + "\' cannot be written."; printfd(__FILE__, "FILES_STORE::WriteDetailStat - fopen failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1691,19 +1694,19 @@ s2 = lt2->tm_sec; if (fprintf(statFile, "-> %02d.%02d.%02d - %02d.%02d.%02d\n", h1, m1, s1, h2, m2, s2) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("fprint failed. Message: '") + strerror(errno) + "'"; + STG_LOCKER lock(&mutex); + errorStr = std::string("fprint failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno)); fclose(statFile); return -1; } -map::const_iterator stIter; +std::map::const_iterator stIter; stIter = statTree.begin(); while (stIter != statTree.end()) { - string u, d; + std::string u, d; x2str(stIter->second.up, u); x2str(stIter->second.down, d); #ifdef TRAFF_STAT_WITH_PORTS @@ -1715,7 +1718,7 @@ while (stIter != statTree.end()) u.c_str(), stIter->second.cash) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "fprint failed. Message: '"; errorStr += strerror(errno); errorStr += "'"; @@ -1731,8 +1734,8 @@ while (stIter != statTree.end()) u.c_str(), stIter->second.cash) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("fprint failed. Message: '"); + STG_LOCKER lock(&mutex); + errorStr = std::string("fprint failed. Message: '"); errorStr += strerror(errno); errorStr += "'"; printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno)); @@ -1751,17 +1754,17 @@ e += chmod(fn, storeSettings.GetStatMode()); if (e) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno)); } return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::AddMessage(STG_MSG * msg, const string & login) const +int FILES_STORE::AddMessage(STG_MSG * msg, const std::string & login) const { -string fn; -string dn; +std::string fn; +std::string dn; struct timeval tv; strprintf(&dn, "%s/%s/messages", storeSettings.GetUsersDir().c_str(), login.c_str()); @@ -1769,7 +1772,7 @@ if (access(dn.c_str(), F_OK) != 0) { if (mkdir(dn.c_str(), 0700) != 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Directory \'"; errorStr += dn; errorStr += "\' cannot be created."; @@ -1787,7 +1790,7 @@ strprintf(&fn, "%s/%lld", dn.c_str(), msg->header.id); if (Touch(fn)) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "File \'"; errorStr += fn; errorStr += "\' cannot be writen."; @@ -1798,18 +1801,18 @@ if (Touch(fn)) return EditMessage(*msg, login); } //----------------------------------------------------------------------------- -int FILES_STORE::EditMessage(const STG_MSG & msg, const string & login) const +int FILES_STORE::EditMessage(const STG_MSG & msg, const std::string & login) const { -string fileName; +std::string fileName; FILE * msgFile; strprintf(&fileName, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), msg.header.id); if (access(fileName.c_str(), F_OK) != 0) { - string idstr; + std::string idstr; x2str(msg.header.id, idstr); - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Message for user \'"; errorStr += login + "\' with ID \'"; errorStr += idstr + "\' does not exist."; @@ -1822,14 +1825,14 @@ Touch(fileName + ".new"); msgFile = fopen((fileName + ".new").c_str(), "wt"); if (!msgFile) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "File \'" + fileName + "\' cannot be writen."; printfd(__FILE__, "FILES_STORE::EditMessage - fopen failed. Message: '%s'\n", strerror(errno)); return -1; } bool res = true; -res &= (fprintf(msgFile, "%d\n", msg.header.type) >= 0); +res &= (fprintf(msgFile, "%u\n", msg.header.type) >= 0); res &= (fprintf(msgFile, "%u\n", msg.header.lastSendTime) >= 0); res &= (fprintf(msgFile, "%u\n", msg.header.creationTime) >= 0); res &= (fprintf(msgFile, "%u\n", msg.header.showTime) >= 0); @@ -1839,8 +1842,8 @@ res &= (fprintf(msgFile, "%s", msg.text.c_str()) >= 0); if (!res) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("fprintf failed. Message: '") + strerror(errno) + "'"; + STG_LOCKER lock(&mutex); + errorStr = std::string("fprintf failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::EditMessage - fprintf failed. Message: '%s'\n", strerror(errno)); fclose(msgFile); return -1; @@ -1852,7 +1855,7 @@ chmod((fileName + ".new").c_str(), storeSettings.GetConfMode()); if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Error moving dir from " + fileName + ".new to " + fileName; printfd(__FILE__, "FILES_STORE::EditMessage - rename failed. Message: '%s'\n", strerror(errno)); return -1; @@ -1861,32 +1864,32 @@ if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::GetMessage(uint64_t id, STG_MSG * msg, const string & login) const +int FILES_STORE::GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const { -string fn; +std::string fn; strprintf(&fn, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), id); msg->header.id = id; return ReadMessage(fn, &msg->header, &msg->text); } //----------------------------------------------------------------------------- -int FILES_STORE::DelMessage(uint64_t id, const string & login) const +int FILES_STORE::DelMessage(uint64_t id, const std::string & login) const { -string fn; +std::string fn; strprintf(&fn, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), id); return unlink(fn.c_str()); } //----------------------------------------------------------------------------- -int FILES_STORE::GetMessageHdrs(vector * hdrsList, const string & login) const +int FILES_STORE::GetMessageHdrs(std::vector * hdrsList, const std::string & login) const { -string dn(storeSettings.GetUsersDir() + "/" + login + "/messages/"); +std::string dn(storeSettings.GetUsersDir() + "/" + login + "/messages/"); if (access(dn.c_str(), F_OK) != 0) { return 0; } -vector messages; +std::vector messages; GetFileList(&messages, dn, S_IFREG, ""); for (unsigned i = 0; i < messages.size(); i++) @@ -1897,8 +1900,8 @@ for (unsigned i = 0; i < messages.size(); i++) { if (unlink((dn + messages[i]).c_str())) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("unlink failed. Message: '") + strerror(errno) + "'"; + STG_LOCKER lock(&mutex); + errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1915,8 +1918,8 @@ for (unsigned i = 0; i < messages.size(); i++) { if (unlink((dn + messages[i]).c_str())) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("unlink failed. Message: '") + strerror(errno) + "'"; + STG_LOCKER lock(&mutex); + errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1929,15 +1932,15 @@ for (unsigned i = 0; i < messages.size(); i++) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::ReadMessage(const string & fileName, +int FILES_STORE::ReadMessage(const std::string & fileName, STG_MSG_HDR * hdr, - string * text) const + std::string * text) const { FILE * msgFile; msgFile = fopen(fileName.c_str(), "rt"); if (!msgFile) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "File \'"; errorStr += fileName; errorStr += "\' cannot be openned."; @@ -1958,7 +1961,7 @@ memset(p, 0, sizeof(p)); for (int pos = 0; pos < 6; pos++) { if (fgets(p, sizeof(p) - 1, msgFile) == NULL) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read file \'"; errorStr += fileName; errorStr += "\'. Missing data."; @@ -1976,7 +1979,7 @@ for (int pos = 0; pos < 6; pos++) if (feof(msgFile)) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read file \'"; errorStr += fileName; errorStr += "\'. Missing data."; @@ -1988,7 +1991,7 @@ for (int pos = 0; pos < 6; pos++) if (str2x(p, *(d[pos]))) { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); errorStr = "Cannot read file \'"; errorStr += fileName; errorStr += "\'. Incorrect value. \'"; @@ -2030,7 +2033,7 @@ if (f) return -1; } //----------------------------------------------------------------------------- -int GetFileList(vector * fileList, const string & directory, mode_t mode, const string & ext) +int GetFileList(std::vector * fileList, const std::string & directory, mode_t mode, const std::string & ext) { DIR * d = opendir(directory.c_str()); @@ -2046,7 +2049,7 @@ while ((entry = readdir(d))) if (!(strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))) continue; - string str = directory + "/" + string(entry->d_name); + std::string str = directory + "/" + std::string(entry->d_name); struct stat st; if (stat(str.c_str(), &st))