]> git.stg.codes - stg.git/commitdiff
Code cleanup.
authorMaxim Mamontov <faust.madf@gmail.com>
Tue, 1 Jan 2013 16:05:51 +0000 (18:05 +0200)
committerMaxim Mamontov <faust.madf@gmail.com>
Tue, 1 Jan 2013 16:05:51 +0000 (18:05 +0200)
14 files changed:
projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp
projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp
projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp
projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp
projects/stargazer/plugins/configuration/rpcconfig/utils.cpp [deleted file]
projects/stargazer/plugins/configuration/rpcconfig/utils.h [deleted file]
projects/stargazer/plugins/other/smux/smux.h
projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp
projects/stargazer/plugins/store/firebird/firebird_store_users.cpp
projects/stargazer/plugins/store/mysql/mysql_store.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp
projects/stargazer/store_loader.cpp
projects/stargazer/user_impl.cpp
stglibs/logger.lib/include/stg/logger.h

index d3c1b9605c7e4a419d015582e92e275998fb3779..5a92cff5f6701de2ed6e7fa4249d9031cabd1a05 100644 (file)
@@ -36,6 +36,7 @@
 #include <cstdlib>
 #include <cstdio> // snprintf
 #include <cerrno>
+#include <cmath>
 #include <algorithm>
 
 #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, "---");
         }
index e4d05636f67a0015c7641b46546eca9c37c46940..e6a4df6f0773bb6cfd9d423da1431b76e3f7bf01 100644 (file)
@@ -2,7 +2,6 @@
 
 #include "stg/message.h"
 #include "stg/common.h"
-#include "utils.h"
 #include "messages_methods.h"
 #include "rpcconfig.h"
 
index ce339573032cadedda24f2438b3726fb4eee43d4..e2cfb13a1be80ee2f8916e62c10b56d9b6694bea 100644 (file)
@@ -1,3 +1,5 @@
+#include <cmath>
+
 #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,
index 48ef3103123515633614d073fa2b0f9b445cefc7..130051be91d43a8f26871506e4098ed5deff8ec9 100644 (file)
@@ -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 (file)
index 18999aa..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-#include <string>
-#include <cerrno>
-#include <cstring>
-#include <iconv.h>
-
-#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 (file)
index d273e3d..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef __UTILS_H__
-#define __UTILS_H__
-
-#include <string>
-
-std::string IconvString(const std::string & src,
-                        const std::string & from = "UTF-8",
-                        const std::string & to = "KOI8-R");
-
-#endif
index ef7b191c1843589e38a6acee7ce2398695b6febd..a33f3b27877b6e0540cf4108950c0d3d7bdffb0c 100644 (file)
@@ -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
index 8967d6eaa55d4fcc57956e8a011bac2c7508a9b4..0fd3f2cd367071bb53b9d26f13ac7630f6e0dda4 100644 (file)
@@ -26,6 +26,8 @@
  *
  */
 
+#include <cmath>
+
 #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;
         }
index a31ca3f80c5c9921c77d1fadc5ed5bb667f2c63b..aaa44f6bd37c8baf791de04a940a8a94985c3307 100644 (file)
@@ -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__);
 
index 8e04f5a5b847c128726a691a7650f3367efd1ed7..79ec39e35f8edafb791f709d79ff88886e94592c 100644 (file)
@@ -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;
index bb64756369d712a801347f06d913d0eb35fc1f7c..7d63b57420cd2f4973f02a29a2413fde10094896 100644 (file)
@@ -29,6 +29,7 @@
 #include <string>
 #include <vector>
 #include <sstream>
+#include <cmath>
 
 #include <libpq-fe.h>
 
@@ -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;
         }
index c54bdb361cc2e0b0dfb9884ce1f080dcfa873fc3..d27c09023603f8745a02df66554d84cff694c862 100644 (file)
@@ -79,7 +79,7 @@ if (!handle)
 isLoaded = true;
 
 STORE * (*GetStore)();
-GetStore = (STORE * (*)())dlsym(handle, "GetStore");
+GetStore = reinterpret_cast<STORE * (*)()>(dlsym(handle, "GetStore"));
 if (!GetStore)
     {
     errorStr = std::string("GetStore() not found! ") + dlerror();
index 41f3f567953a21bb8fd90f823df51962ba54b591..80568561a3458b0c3265d76e11dbfc7bddae4cbc 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <cassert>
 #include <cstdlib>
+#include <cmath>
 
 #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<time_t>(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;
index 8cc25cad0d9f3954febd629b7cd007d6edee80c3..dc87178e4a487dedc58d8cedce793106edf450aa 100644 (file)
@@ -5,8 +5,6 @@
 
 #include <string>
 
-const char * LogDate(time_t t);
-//-----------------------------------------------------------------------------
 class STG_LOGGER;
 STG_LOGGER & GetStgLogger();
 //-----------------------------------------------------------------------------