From 25c5bd4fe8c9fd7c4898e7dfbbdbf68dc172dcd7 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Tue, 1 Jan 2013 18:05:51 +0200 Subject: [PATCH 1/1] Code cleanup. --- .../authorization/inetaccess/inetaccess.cpp | 9 ++- .../rpcconfig/messages_methods.cpp | 1 - .../configuration/rpcconfig/user_helper.cpp | 9 ++- .../configuration/rpcconfig/users_methods.cpp | 1 - .../plugins/configuration/rpcconfig/utils.cpp | 78 ------------------- .../plugins/configuration/rpcconfig/utils.h | 10 --- projects/stargazer/plugins/other/smux/smux.h | 4 - .../store/firebird/firebird_store_tariffs.cpp | 6 +- .../store/firebird/firebird_store_users.cpp | 6 +- .../plugins/store/mysql/mysql_store.cpp | 4 +- .../postgresql/postgresql_store_tariffs.cpp | 5 +- projects/stargazer/store_loader.cpp | 2 +- projects/stargazer/user_impl.cpp | 14 ++-- stglibs/logger.lib/include/stg/logger.h | 2 - 14 files changed, 31 insertions(+), 120 deletions(-) delete mode 100644 projects/stargazer/plugins/configuration/rpcconfig/utils.cpp delete mode 100644 projects/stargazer/plugins/configuration/rpcconfig/utils.h diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index d3c1b960..5a92cff5 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -36,6 +36,7 @@ #include #include // snprintf #include +#include #include #include "stg/common.h" @@ -1433,8 +1434,8 @@ if (dn < DIR_NUM) aliveSyn6.md[dn], dn, stgTime); - p *= (1024 * 1024); - if (p == 0) + p *= 1024 * 1024; + if (std::fabs(p) < 1.0e-3) { snprintf((char*)aliveSyn6.freeMb, IA_FREEMB_LEN, "---"); } @@ -1523,8 +1524,8 @@ if (dn < DIR_NUM) aliveSyn8.md[dn], dn, stgTime); - p *= (1024 * 1024); - if (p == 0) + p *= 1024 * 1024; + if (std::fabs(p) < 1.0e-3) { snprintf((char*)aliveSyn8.freeMb, IA_FREEMB_LEN, "---"); } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp index e4d05636..e6a4df6f 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp @@ -2,7 +2,6 @@ #include "stg/message.h" #include "stg/common.h" -#include "utils.h" #include "messages_methods.h" #include "rpcconfig.h" diff --git a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp index ce339573..e2cfb13a 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp @@ -1,3 +1,5 @@ +#include + #include "stg/tariffs.h" #include "stg/admin.h" #include "stg/store.h" @@ -5,7 +7,6 @@ #include "stg/common.h" #include "stg/user_property.h" #include "user_helper.h" -#include "utils.h" //------------------------------------------------------------------------------ @@ -225,7 +226,7 @@ if ((it = structVal.find("email")) != structVal.end()) if ((it = structVal.find("cash")) != structVal.end()) { double value(xmlrpc_c::value_double(it->second)); - if (ptr->GetProperty().cash.Get() != value) + if (std::fabs(ptr->GetProperty().cash.Get() - value) > 1.0e-3) if (!ptr->GetProperty().cash.Set(value, admin, login, @@ -247,7 +248,7 @@ if ((it = structVal.find("creditexpire")) != structVal.end()) if ((it = structVal.find("credit")) != structVal.end()) { double value(xmlrpc_c::value_double(it->second)); - if (ptr->GetProperty().credit.Get() != value) + if (std::fabs(ptr->GetProperty().credit.Get() - value) > 1.0e-3) if (!ptr->GetProperty().credit.Set(value, admin, login, @@ -258,7 +259,7 @@ if ((it = structVal.find("credit")) != structVal.end()) if ((it = structVal.find("freemb")) != structVal.end()) { double value(xmlrpc_c::value_double(it->second)); - if (ptr->GetProperty().freeMb.Get() != value) + if (std::fabs(ptr->GetProperty().freeMb.Get() - value) > 1.0e-3) if (!ptr->GetProperty().freeMb.Set(value, admin, login, diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp index 48ef3103..130051be 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp @@ -10,7 +10,6 @@ #include "users_methods.h" #include "rpcconfig.h" #include "user_helper.h" -#include "utils.h" //------------------------------------------------------------------------------ diff --git a/projects/stargazer/plugins/configuration/rpcconfig/utils.cpp b/projects/stargazer/plugins/configuration/rpcconfig/utils.cpp deleted file mode 100644 index 18999aa9..00000000 --- a/projects/stargazer/plugins/configuration/rpcconfig/utils.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include - -#include "utils.h" -#include "common.h" - -//----------------------------------------------------------------------------- -std::string IconvString(const std::string & src, - const std::string & from, - const std::string & to) -{ -if (src.empty()) - return std::string(); - -size_t inBytesLeft = src.length() + 1; -size_t outBytesLeft = src.length() * 2 + 1; - -char * inBuf = new char[inBytesLeft]; -char * outBuf = new char[outBytesLeft]; - -strncpy(inBuf, src.c_str(), src.length()); - -inBuf[src.length()] = 0; - -#if defined(FREE_BSD) || defined(FREE_BSD5) -const char * srcPos = inBuf; -#else -char * srcPos = inBuf; -#endif -char * dstPos = outBuf; - -iconv_t handle = iconv_open(to.c_str(), - from.c_str()); - -if (handle == iconv_t(-1)) - { - if (errno == EINVAL) - { - printfd(__FILE__, "IconvString(): iconv from %s to %s failed\n", from.c_str(), to.c_str()); - delete[] outBuf; - delete[] inBuf; - return src; - } - else - printfd(__FILE__, "IconvString(): iconv_open error\n"); - - delete[] outBuf; - delete[] inBuf; - return src; - } - -size_t res = iconv(handle, - &srcPos, &inBytesLeft, - &dstPos, &outBytesLeft); - -if (res == size_t(-1)) - { - printfd(__FILE__, "IconvString(): '%s'\n", strerror(errno)); - - iconv_close(handle); - delete[] outBuf; - delete[] inBuf; - return src; - } - -dstPos = 0; - -std::string dst(outBuf); - -iconv_close(handle); - -delete[] outBuf; -delete[] inBuf; - -return dst; -} diff --git a/projects/stargazer/plugins/configuration/rpcconfig/utils.h b/projects/stargazer/plugins/configuration/rpcconfig/utils.h deleted file mode 100644 index d273e3d2..00000000 --- a/projects/stargazer/plugins/configuration/rpcconfig/utils.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __UTILS_H__ -#define __UTILS_H__ - -#include - -std::string IconvString(const std::string & src, - const std::string & from = "UTF-8", - const std::string & to = "KOI8-R"); - -#endif diff --git a/projects/stargazer/plugins/other/smux/smux.h b/projects/stargazer/plugins/other/smux/smux.h index ef7b191c..a33f3b27 100644 --- a/projects/stargazer/plugins/other/smux/smux.h +++ b/projects/stargazer/plugins/other/smux/smux.h @@ -21,8 +21,6 @@ #include "tables.h" #include "types.h" -extern "C" PLUGIN * GetPlugin(); - class USER; class SETTINGS; class SMUX; @@ -216,6 +214,4 @@ smux.UnsetNotifier(userPtr); smux.UpdateTables(); } -extern "C" PLUGIN * GetPlugin(); - #endif diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp index 8967d6ea..0fd3f2cd 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp @@ -26,6 +26,8 @@ * */ +#include + #include "firebird_store.h" #include "stg/ibpp.h" @@ -284,8 +286,8 @@ try st->Get(7, td->dirPrice[dir].priceNightB); td->dirPrice[dir].priceNightB /= 1024*1024; st->Get(8, td->dirPrice[dir].threshold); - if (td->dirPrice[dir].priceDayA == td->dirPrice[dir].priceNightA && - td->dirPrice[dir].priceDayB == td->dirPrice[dir].priceNightB) + if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 && + std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3) { td->dirPrice[dir].singlePrice = true; } diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp index a31ca3f8..aaa44f6b 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp @@ -667,9 +667,9 @@ int FIREBIRD_STORE::WriteUserDisconnect(const string & login, const DIR_TRAFF & down, const DIR_TRAFF & sessionUp, const DIR_TRAFF & sessionDown, - double cash, - double freeMb, - const std::string & reason) const + double /*cash*/, + double /*freeMb*/, + const std::string & /*reason*/) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.cpp b/projects/stargazer/plugins/store/mysql/mysql_store.cpp index 8e04f5a5..79ec39e3 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@ -1070,8 +1070,8 @@ int MYSQL_STORE::WriteUserDisconnect(const string & login, const DIR_TRAFF & sessionUp, const DIR_TRAFF & sessionDown, double cash, - double freeMb, - const std::string & reason) const + double /*freeMb*/, + const std::string & /*reason*/) const { string logStr = "Disconnect, "; stringstream sssu; diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp index bb647563..7d63b574 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -543,8 +544,8 @@ for (int i = 0; i < std::min(tuples, DIR_NUM); ++i) tuple >> td->dirPrice[dir].hNight; tuple >> td->dirPrice[dir].mNight; - if (td->dirPrice[dir].priceDayA == td->dirPrice[dir].priceNightA && - td->dirPrice[dir].priceDayB == td->dirPrice[dir].priceNightB) + if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) > 1.0e-3 && + std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) > 1.0e-3) { td->dirPrice[dir].singlePrice = true; } diff --git a/projects/stargazer/store_loader.cpp b/projects/stargazer/store_loader.cpp index c54bdb36..d27c0902 100644 --- a/projects/stargazer/store_loader.cpp +++ b/projects/stargazer/store_loader.cpp @@ -79,7 +79,7 @@ if (!handle) isLoaded = true; STORE * (*GetStore)(); -GetStore = (STORE * (*)())dlsym(handle, "GetStore"); +GetStore = reinterpret_cast(dlsym(handle, "GetStore")); if (!GetStore) { errorStr = std::string("GetStore() not found! ") + dlerror(); diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 41f3f567..80568561 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -37,6 +37,7 @@ #include #include +#include #include "stg/users.h" #include "stg/common.h" @@ -592,7 +593,7 @@ if (!fakeConnect) scriptOnConnect.c_str(), login.c_str(), inet_ntostring(currIP).c_str(), - (double)cash, + cash.ConstData(), id, dirsStr); @@ -649,7 +650,7 @@ if (!fakeDisconnect) scriptOnDisonnect.c_str(), login.c_str(), inet_ntostring(lastIPForDisconnect).c_str(), - (double)cash, + cash.ConstData(), id, dirsStr); @@ -1175,9 +1176,10 @@ time_t t = stgTime; struct tm tm; localtime_r(&t, &tm); int daysCurrMon = DaysInCurrentMonth(); -double pt = (tm.tm_mday - 1) / (double)daysCurrMon; +double pt = tm.tm_mday - 1; +pt /= daysCurrMon; -passiveTime = (time_t)(pt * 24 * 3600 * daysCurrMon); +passiveTime = static_cast(pt * 24 * 3600 * daysCurrMon); } //----------------------------------------------------------------------------- void USER_IMPL::MidnightResetSessionStat() @@ -1240,7 +1242,7 @@ if (passive.ConstData() || tariff == NULL) double fee = tariff->GetFee() / DaysInCurrentMonth(); -if (fee == 0.0) +if (std::fabs(fee) < 1.0e-3) return; double c = cash; @@ -1289,7 +1291,7 @@ double fee = tariff->GetFee() * passiveTimePart; ResetPassiveTime(); -if (fee == 0.0) +if (std::fabs(fee) < 1.0e-3) { SetPrepaidTraff(); return; diff --git a/stglibs/logger.lib/include/stg/logger.h b/stglibs/logger.lib/include/stg/logger.h index 8cc25cad..dc87178e 100644 --- a/stglibs/logger.lib/include/stg/logger.h +++ b/stglibs/logger.lib/include/stg/logger.h @@ -5,8 +5,6 @@ #include -const char * LogDate(time_t t); -//----------------------------------------------------------------------------- class STG_LOGGER; STG_LOGGER & GetStgLogger(); //----------------------------------------------------------------------------- -- 2.44.2