#include <cstdlib>
#include <cstdio> // snprintf
#include <cerrno>
+#include <cmath>
#include <algorithm>
#include "stg/common.h"
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, "---");
}
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, "---");
}
#include "stg/message.h"
#include "stg/common.h"
-#include "utils.h"
#include "messages_methods.h"
#include "rpcconfig.h"
+#include <cmath>
+
#include "stg/tariffs.h"
#include "stg/admin.h"
#include "stg/store.h"
#include "stg/common.h"
#include "stg/user_property.h"
#include "user_helper.h"
-#include "utils.h"
//------------------------------------------------------------------------------
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,
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,
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,
#include "users_methods.h"
#include "rpcconfig.h"
#include "user_helper.h"
-#include "utils.h"
//------------------------------------------------------------------------------
+++ /dev/null
-#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;
-}
+++ /dev/null
-#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
#include "tables.h"
#include "types.h"
-extern "C" PLUGIN * GetPlugin();
-
class USER;
class SETTINGS;
class SMUX;
smux.UpdateTables();
}
-extern "C" PLUGIN * GetPlugin();
-
#endif
*
*/
+#include <cmath>
+
#include "firebird_store.h"
#include "stg/ibpp.h"
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;
}
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__);
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;
#include <string>
#include <vector>
#include <sstream>
+#include <cmath>
#include <libpq-fe.h>
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;
}
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();
#include <cassert>
#include <cstdlib>
+#include <cmath>
#include "stg/users.h"
#include "stg/common.h"
scriptOnConnect.c_str(),
login.c_str(),
inet_ntostring(currIP).c_str(),
- (double)cash,
+ cash.ConstData(),
id,
dirsStr);
scriptOnDisonnect.c_str(),
login.c_str(),
inet_ntostring(lastIPForDisconnect).c_str(),
- (double)cash,
+ cash.ConstData(),
id,
dirsStr);
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()
double fee = tariff->GetFee() / DaysInCurrentMonth();
-if (fee == 0.0)
+if (std::fabs(fee) < 1.0e-3)
return;
double c = cash;
ResetPassiveTime();
-if (fee == 0.0)
+if (std::fabs(fee) < 1.0e-3)
{
SetPrepaidTraff();
return;
#include <string>
-const char * LogDate(time_t t);
-//-----------------------------------------------------------------------------
class STG_LOGGER;
STG_LOGGER & GetStgLogger();
//-----------------------------------------------------------------------------