receiverStopped(true),
processorStopped(true),
userTimeout(0),
- listenSocket(0)
+ listenSocket(0),
+ version("rscriptd listener v.1.2")
{
-version = "rscriptd listener v.1.2";
-
pthread_mutex_init(&mutex, NULL);
}
//-----------------------------------------------------------------------------
int ParseReply(void * data, list<string> * ans)
{
int done = 0;
-int len;
parse_depth = 0;
parser = XML_ParserCreate(NULL);
list<string>::iterator n = ans->begin();
while (n != ans->end())
{
- len = strlen(n->c_str());
+ size_t len = strlen(n->c_str());
if (++n == ans->end())
done = 1;
return 0;
}
//-----------------------------------------------------------------------------
-void ADMINS_IMPL::PrintAdmins() const
-{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-const_admin_iter ai(data.begin());
-while (ai != data.end())
- {
- ai->Print();
- ai++;
- }
-}
-//-----------------------------------------------------------------------------
bool ADMINS_IMPL::Find(const string & l, ADMIN ** admin)
{
assert(admin != NULL && "Pointer to admin is not null");
int Add(const std::string & login, const ADMIN * admin);
int Del(const std::string & login, const ADMIN * admin);
int Change(const ADMIN_CONF & ac, const ADMIN * admin);
- void PrintAdmins() const;
const ADMIN * GetSysAdmin() const { return &stg; }
const ADMIN * GetNoAdmin() const { return &noAdmin; }
bool Find(const std::string & l, ADMIN ** admin);
userTimeout(0),
port(0),
errorStr(),
- freeMbShowType(freeMbCash)
+ freeMbShowType(freeMbCash),
+ logProtocolErrors(false)
{
}
//-----------------------------------------------------------------------------
gettimeofday(&phaseTime, NULL);
}
//-----------------------------------------------------------------------------
-void IA_PHASE::SetPhase5()
-{
-#ifdef IA_PHASE_DEBUG
-WritePhaseChange(5);
-#endif
-phase = 5;
-gettimeofday(&phaseTime, NULL);
-}
-//-----------------------------------------------------------------------------
int IA_PHASE::GetPhase() const
{
return phase;
std::map<uint32_t, IA_USER>::iterator it;
it = ip2user.begin();
-uint32_t sip;
while (it != ip2user.end())
{
- sip = it->first;
+ uint32_t sip = it->first;
static UTIME currTime;
gettimeofday(&currTime, NULL);
#ifdef ARCH_BE
SwapBytes(connSyn->dirs);
#endif
-int ret = Process_CONN_SYN_6((CONN_SYN_6*)connSyn, iaUser, sip);
+int ret = Process_CONN_SYN_6(reinterpret_cast<CONN_SYN_6 *>(connSyn), iaUser, sip);
enabledDirs = connSyn->dirs;
return ret;
}
void SetPhase2();
void SetPhase3();
void SetPhase4();
- void SetPhase5();
int GetPhase() const;
void UpdateTime();
DIVERT_CAP * dc = static_cast<DIVERT_CAP *>(d);
dc->isRunning = true;
-char buffer[64];
+char buffer[pcktSize + 14];
while (dc->nonstop)
{
RAW_PACKET rp;
- dc->DivertCapRead(buffer, 64, NULL);
+ dc->DivertCapRead(buffer, sizeof(buffer), NULL);
if (buffer[12] != 0x8)
continue;
return((struct nlmsghdr*)buf)->nlmsg_type;
}
//-----------------------------------------------------------------------------
-int ipq_get_msgerr(const unsigned char *buf)
-{
- struct nlmsghdr *h = (struct nlmsghdr *)buf;
- struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
- return -err->error;
-}
-//-----------------------------------------------------------------------------
ipq_packet_msg_t *ipq_get_packet(const unsigned char *buf)
{
return(ipq_packet_msg_t *)(NLMSG_DATA((struct nlmsghdr *)(buf)));
return ipq_netlink_sendmsg(h, &msg, 0);
}
//-----------------------------------------------------------------------------
-/* Not implemented yet */
-int ipq_ctl(const struct ipq_handle __attribute__((unused)) * handle, int __attribute__((unused)) request, ...)
-{
- return 1;
-}
-//-----------------------------------------------------------------------------
char *ipq_errstr(void)
{
return ipq_strerror(ipq_errno);
int ipq_message_type(const unsigned char *buf);
-int ipq_get_msgerr(const unsigned char *buf);
-
int ipq_set_verdict(const struct ipq_handle *h,
ipq_id_t id,
unsigned int verdict,
size_t data_len,
unsigned char *buf);
-int ipq_ctl(const struct ipq_handle *h, int request, ...);
-
char *ipq_errstr(void);
//void ipq_perror(const char *s);
nonstop(false),
isRunning(false),
queueNumber(0),
+ nfqHandle(NULL),
+ queueHandle(NULL),
traffCnt(NULL),
logger(GetPluginLogger(GetStgLogger(), "cap_nfqueue"))
{
std::string login = paramList.getString(1);
paramList.verifyEnd(2);
-std::map<std::string, xmlrpc_c::value> structVal;
ADMIN_INFO adminInfo;
if (config->GetAdminInfo(cookie, &adminInfo))
std::string cookie = paramList.getString(0);
paramList.verifyEnd(1);
-std::map<std::string, xmlrpc_c::value> structVal;
-
if (config->LogoutAdmin(cookie))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
if (strcasecmp(el, "traff") == 0)
{
int j = 0;
- int dir;
DIR_TRAFF dtu;
DIR_TRAFF dtd;
uint64_t t = 0;
while (attr[j])
{
- dir = attr[j][2] - '0';
+ int dir = attr[j][2] - '0';
if (strncasecmp(attr[j], "md", 2) == 0)
{
ADMIN_CONF ac;
int h = admins->OpenSearch();
-unsigned int p;
while (admins->SearchNext(h, &ac) == 0)
{
//memcpy(&p, &ac.priv, sizeof(unsigned int));
- p = (ac.priv.userStat << 0) +
- (ac.priv.userConf << 2) +
- (ac.priv.userCash << 4) +
- (ac.priv.userPasswd << 6) +
- (ac.priv.userAddDel << 8) +
- (ac.priv.adminChg << 10) +
- (ac.priv.tariffChg << 12);
+ unsigned int p = (ac.priv.userStat << 0) +
+ (ac.priv.userConf << 2) +
+ (ac.priv.userCash << 4) +
+ (ac.priv.userPasswd << 6) +
+ (ac.priv.userAddDel << 8) +
+ (ac.priv.adminChg << 10) +
+ (ac.priv.tariffChg << 12);
strprintf(&s, "<admin login=\"%s\" priv=\"%d\"/>", ac.login.c_str(), p);
answerList->push_back(s);
}
}
}
//-----------------------------------------------------------------------------
-int PARSER_DEL_ADMIN::CheckAttr(const char **attr)
-{
-/* <DelAdmin login=\"admin\">
- * attr[0] = "login" (word login)
- * attr[1] = login, value of login
- * attr[2] = NULL */
-
-if (strcasecmp(attr[0], "login") == 0 && attr[1] && !attr[2])
- {
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
// ADD ADMIN
//-----------------------------------------------------------------------------
int PARSER_ADD_ADMIN::ParseStart(void *, const char *el, const char **attr)
//-----------------------------------------------------------------------------
int PARSER_CHG_TARIFF::ParseStart(void *, const char * el, const char ** attr)
{
-char st[50];
double price[DIR_NUM];
int t[DIR_NUM];
depth++;
for (int j = 0; j < DIR_NUM; j++)
{
+ char st[50];
snprintf(st, 50, "Time%d", j);
if (strcasecmp(el, st) == 0)
{
//-----------------------------------------------------------------------------
int CONFIGPROTO::Prepare()
{
-std::list<std::string> ansList; //óÀÄÁ ÂÕÄÅÔ ÐÏÍÅÝÅÎ ÏÔ×ÅÔ ÄÌÑ ÍÅÎÅÄÖÅÒÁ ËÌÉÅÎÔÏ×
int res;
struct sockaddr_in listenAddr;
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
-STG_CONFIG * stgConf = (STG_CONFIG *)d;
+STG_CONFIG * stgConf = static_cast<STG_CONFIG *>(d);
stgConf->isRunning = true;
stgConf->config.Run();
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
-RADIUS * rad = (RADIUS *)d;
+RADIUS * rad = static_cast<RADIUS *>(d);
RAD_PACKET packet;
rad->isRunning = true;
return 0;
}
//-----------------------------------------------------------------------------
-void RADIUS::PrintServices(const std::list<std::string> & svcs)
-{
-for_each(svcs.begin(), svcs.end(), Printer());
-}
-//-----------------------------------------------------------------------------
bool RADIUS::FindUser(USER_PTR * ui, const std::string & login) const
{
if (users->FindByName(login, ui))
bool CanAcctService(const std::string & svc) const;
bool IsAllowedService(const std::string & svc) const;
- void PrintServices(const std::list<std::string> & svcs);
-
- struct Printer : public std::unary_function<std::string, void>
- {
- void operator()(const std::string & line)
- {
- printfd("radius.cpp", "'%s'\n", line.c_str());
- }
- };
struct SPrinter : public std::unary_function<std::pair<std::string, RAD_SESSION>, void>
- {
+ {
void operator()(const std::pair<std::string, RAD_SESSION> & it)
- {
- printfd("radius.cpp", "%s - ('%s', '%s')\n", it.first.c_str(), it.second.userName.c_str(), it.second.serviceType.c_str());
- }
+ {
+ printfd("radius.cpp", "%s - ('%s', '%s')\n", it.first.c_str(), it.second.userName.c_str(), it.second.serviceType.c_str());
+ }
};
BLOWFISH_CTX ctx;
USER(const std::vector<uint32_t> & r, USER_PTR it)
: user(it),
routers(r),
+ shortPacketsCount(0),
ip(user->GetCurrIP())
{}
{
CONFIGFILE cf(fileName);
int e = cf.Error();
-std::string str;
if (e)
{
//-----------------------------------------------------------------------------
int FILES_STORE::SaveUserStat(const USER_STAT & stat, const std::string & login) const
{
-char s[22];
std::string fileName;
fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
for (int i = 0; i < DIR_NUM; i++)
{
+ char s[22];
snprintf(s, 22, "D%d", i);
cfstat.WriteInt(s, stat.monthDown[i]);
snprintf(s, 22, "U%d", i);
//-----------------------------------------------------------------------------*/
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];
-
std::string fileName;
strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), 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;
}
pass[ADM_PASSWD_LEN - 1] = 0;
+ char passwordE[2 * ADM_PASSWD_LEN + 2];
Encode12(passwordE, pass, ADM_PASSWD_LEN);
cf.WriteString("password", passwordE);
}
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);
mutex(),
til(IBPP::ilConcurrency),
tlr(IBPP::lrWait),
+ schemaVersion(0),
logger(GetPluginLogger(GetStgLogger(), "store_firebird"))
{
pthread_mutex_init(&mutex, NULL);
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
-std::string name;
-
try
{
tr->Start();
IBPP::Statement st = IBPP::StatementFactory(db, tr);
int32_t id, i;
-double pda, pdb, pna, pnb;
-int threshold;
try
{
for(i = 0; i < DIR_NUM; i++)
{
- tb.SetTime(td.dirPrice[i].hDay, td.dirPrice[i].mDay, 0);
- te.SetTime(td.dirPrice[i].hNight, td.dirPrice[i].mNight, 0);
+ tb.SetTime(td.dirPrice[i].hDay, td.dirPrice[i].mDay, 0);
+ te.SetTime(td.dirPrice[i].hNight, td.dirPrice[i].mNight, 0);
- pda = td.dirPrice[i].priceDayA * 1024 * 1024;
- pdb = td.dirPrice[i].priceDayB * 1024 * 1024;
+ double pda = td.dirPrice[i].priceDayA * 1024 * 1024;
+ double pdb = td.dirPrice[i].priceDayB * 1024 * 1024;
+ double pna = 0;
+ double pnb = 0;
if (td.dirPrice[i].singlePrice)
{
pnb = td.dirPrice[i].priceNightB;
}
+ int threshold = 0;
if (td.dirPrice[i].noDiscount)
{
threshold = 0xffFFffFF;
threshold = td.dirPrice[i].threshold;
}
- st->Prepare("update tb_tariffs_params set \
- price_day_a = ?, \
- price_day_b = ?, \
- price_night_a = ?, \
- price_night_b = ?, \
- threshold = ?, \
- time_day_begins = ?, \
- time_day_ends = ? \
- where fk_tariff = ? and dir_num = ?");
- st->Set(1, pda);
- st->Set(2, pdb);
- st->Set(3, pna);
- st->Set(4, pnb);
- st->Set(5, threshold);
- st->Set(6, tb);
- st->Set(7, te);
- st->Set(8, id);
- st->Set(9, i);
- st->Execute();
- st->Close();
+ st->Prepare("update tb_tariffs_params set \
+ price_day_a = ?, \
+ price_day_b = ?, \
+ price_night_a = ?, \
+ price_night_b = ?, \
+ threshold = ?, \
+ time_day_begins = ?, \
+ time_day_ends = ? \
+ where fk_tariff = ? and dir_num = ?");
+ st->Set(1, pda);
+ st->Set(2, pdb);
+ st->Set(3, pna);
+ st->Set(4, pnb);
+ st->Set(5, threshold);
+ st->Set(6, tb);
+ st->Set(7, te);
+ st->Set(8, id);
+ st->Set(9, i);
+ st->Execute();
+ st->Close();
}
tr->Commit();
}
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
-int32_t id;
-int16_t dir;
-int i;
-IBPP::Time tb, te;
-int h, m, s;
td->tariffConf.name = tariffName;
tr->Rollback();
return -1;
}
+ int32_t id;
st->Get(1, id);
st->Get(3, td->tariffConf.fee);
st->Get(4, td->tariffConf.free);
st->Prepare("select * from tb_tariffs_params where fk_tariff = ?");
st->Set(1, id);
st->Execute();
- i = 0;
+ int i = 0;
while (st->Fetch())
{
i++;
tr->Rollback();
return -1;
}
+ int16_t dir;
st->Get(3, dir);
st->Get(4, td->dirPrice[dir].priceDayA);
td->dirPrice[dir].priceDayA /= 1024*1024;
td->dirPrice[dir].noDiscount = false;
}
+ IBPP::Time tb;
st->Get(9, tb);
+ IBPP::Time te;
st->Get(10, te);
+ int h, m, s;
tb.GetTime(h, m, s);
td->dirPrice[dir].hDay = h;
td->dirPrice[dir].mDay = m;
int year,
int month) const
{
-
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
-IBPP::Timestamp actTime;
-IBPP::Timestamp addTime;
-IBPP::Date dt;
-int i;
-int32_t sid, uid;
-
try
{
tr->Start();
printfd(__FILE__, "No stat info for user '%s'\n", login.c_str());
return -1;
}
+ int32_t sid;
st->Get(1, sid);
st->Close();
+ IBPP::Timestamp actTime;
time_t2ts(stat.lastActivityTime, &actTime);
+ IBPP::Timestamp addTime;
time_t2ts(stat.lastCashAddTime, &addTime);
+ IBPP::Date dt;
if (year != 0)
ym2date(year, month, &dt);
else
st->Execute();
st->Close();
- for(i = 0; i < DIR_NUM; i++)
+ for(int i = 0; i < DIR_NUM; i++)
{
st->Prepare("update tb_stats_traffic set \
upload = ?, \
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
-int i;
-int32_t uid;
-IBPP::Timestamp creditExpire;
-std::vector<std::string>::const_iterator it;
-
try
{
tr->Start();
tr->Rollback();
return -1;
}
+ int32_t uid;
st->Get(1, uid);
st->Close();
+ IBPP::Timestamp creditExpire;
time_t2ts(conf.creditExpire, &creditExpire);
st->Prepare("update tb_users set \
st->Prepare("insert into tb_users_services (fk_user, fk_service) \
values (?, (select pk_service from tb_services \
where name = ?))");
- for(it = conf.service.begin(); it != conf.service.end(); ++it)
+ for(std::vector<std::string>::const_iterator it = conf.service.begin(); it != conf.service.end(); ++it)
{
st->Set(1, uid);
st->Set(2, *it);
st->Execute();
st->Close();
- i = 0;
+ int i = 0;
st->Prepare("insert into tb_users_data (fk_user, data, num) values (?, ?, ?)");
- for (it = conf.userdata.begin(); it != conf.userdata.end(); ++it)
+ for (std::vector<std::string>::const_iterator it = conf.userdata.begin(); it != conf.userdata.end(); ++it)
{
st->Set(1, uid);
st->Set(2, *it);
}
tr->Commit();
}
-
catch (IBPP::Exception & ex)
{
tr->Rollback();
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
-IBPP::Timestamp actTime, addTime;
-int i, dir;
-int32_t uid, sid, passiveTime;
-
try
{
tr->Start();
printfd(__FILE__, "User '%s' not found in database\n", login.c_str());
return -1;
}
+ int32_t uid;
st->Get(1, uid);
st->Close();
return -1;
}
+ int32_t sid;
st->Get(1, sid);
st->Get(2, stat->cash);
st->Get(3, stat->freeMb);
+ IBPP::Timestamp actTime;
st->Get(4, actTime);
st->Get(5, stat->lastCashAdd);
+ IBPP::Timestamp addTime;
st->Get(6, addTime);
+ int32_t passiveTime;
st->Get(7, passiveTime);
stat->passiveTime = passiveTime;
st->Prepare("select * from tb_stats_traffic where fk_stat = ?");
st->Set(1, sid);
st->Execute();
- for(i = 0; i < DIR_NUM; i++)
+ for(int i = 0; i < DIR_NUM; i++)
{
if (st->Fetch())
{
+ int dir;
st->Get(3, dir);
st->Get(5, (int64_t &)stat->monthUp[dir]);
st->Get(4, (int64_t &)stat->monthDown[dir]);
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
-int32_t uid;
-int i;
-IBPP::Timestamp timestamp;
-IP_MASK im;
-std::string name;
-bool test;
-
try
{
tr->Start();
tr->Rollback();
return -1;
}
+ int32_t uid;
st->Get(1, uid);
// Getting base config
st->Get(2, conf->address);
+ bool test;
st->Get(3, test);
conf->alwaysOnline = test;
st->Get(4, conf->credit);
+ IBPP::Timestamp timestamp;
st->Get(5, timestamp);
conf->creditExpire = ts2time_t(timestamp);
st->Execute();
while (st->Fetch())
{
+ std::string name;
st->Get(1, name);
conf->service.push_back(name);
}
st->Execute();
while (st->Fetch())
{
+ int i;
st->Get(2, i);
st->Get(1, conf->userdata[i]);
}
conf->ips.Erase();
while (st->Fetch())
{
+ IP_MASK im;
st->Get(1, (int32_t &)im.ip);
st->Get(2, (int32_t &)im.mask);
conf->ips.Add(im);
tr->Commit();
}
-
catch (IBPP::Exception & ex)
{
tr->Rollback();
IBPP::Timestamp now;
now.Now();
-int32_t id;
-int i;
-
try
{
tr->Start();
st->Set(1, login);
st->Set(2, now);
st->Execute();
+ int32_t id;
st->Get(1, id);
st->Prepare("insert into tb_sessions_data \
(fk_session_log, dir_num, session_upload, \
session_download, month_upload, month_download) \
values (?, ?, ?, ?, ?, ?)");
- for(i = 0; i < DIR_NUM; i++)
+ for(int i = 0; i < DIR_NUM; i++)
{
st->Set(1, id);
st->Set(2, i);
IBPP::Date nowDate;
nowDate.Today();
now.Now();
-int32_t id;
-int i;
if (SaveStat(stat, login, year, month))
{
st->Set(4, nowDate);
st->Execute();
+ int32_t id;
st->Get(1, id);
st->Close();
(fk_stat, dir_num, upload, download) \
values (?, ?, 0, 0)");
- for(i = 0; i < DIR_NUM; i++)
+ for(int i = 0; i < DIR_NUM; i++)
{
st->Set(1, id);
st->Set(2, i);
tr->Commit();
}
-
catch (IBPP::Exception & ex)
{
tr->Rollback();
}
//-----------------------------------------------------------------------------
-std::string ReplaceStr(std::string source, const std::string symlist, const char chgsym)
+std::string ReplaceStr(std::string source, const std::string & symlist, const char chgsym)
{
std::string::size_type pos=0;
dbUser(),
dbPass(),
dbName(),
- dbHost()
+ dbHost(),
+ schemaVersion(0)
{
}
//-----------------------------------------------------------------------------
{
int ret = storeSettings.ParseSettings(settings);
MYSQL mysql;
-MYSQL * sock;
mysql_init(&mysql);
if (ret)
errorStr = storeSettings.GetStrError();
errorStr = "Database password must be not empty. Please read Manual.";
return -1;
}
-
+ MYSQL * sock;
if (!(sock = mysql_real_connect(&mysql,storeSettings.GetDBHost().c_str(),
storeSettings.GetDBUser().c_str(),storeSettings.GetDBPassword().c_str(),
0,0,NULL,0)))
row = mysql_fetch_row(res);
-std::string param;
-
conf->password = row[1];
if (conf->password.empty())
char passwordE[2*ADM_PASSWD_LEN + 2];
BLOWFISH_CTX ctx;
-memset(pass, 0, sizeof(pass));
memset(password, 0, sizeof(password));
-memset(passwordE, 0, sizeof(passwordE));
std::string p;
MYSQL_RES *res;
}
}
-std::string login;
PGresult * result;
if (StartTransaction())
return -1;
}
-int32_t id, i;
-double pda, pdb, pna, pnb;
-int threshold;
-
{
std::ostringstream query;
query << "SELECT pk_tariff FROM tb_tariffs WHERE name = '" << ename << "'";
PQclear(result);
+ int32_t id;
tuple >> id;
}
PQclear(result);
-for(i = 0; i < DIR_NUM; i++)
+for(int i = 0; i < DIR_NUM; i++)
{
-
- pda = td.dirPrice[i].priceDayA * 1024 * 1024;
- pdb = td.dirPrice[i].priceDayB * 1024 * 1024;
+ double pda = td.dirPrice[i].priceDayA * 1024 * 1024;
+ double pdb = td.dirPrice[i].priceDayB * 1024 * 1024;
+ double pna = 0;
+ double pnb = 0;
if (td.dirPrice[i].singlePrice)
{
pnb = td.dirPrice[i].priceNightB * 1024 * 1024;
}
+ int threshold = 0;
if (td.dirPrice[i].noDiscount)
{
threshold = 0xffFFffFF;
}
}
-PGresult * result;
-
if (StartTransaction())
{
printfd(__FILE__, "POSTGRESQL_STORE::WriteDetailedStat(): 'Failed to start transaction'\n");
<< it->second.up << ", "
<< it->second.cash << ")";
- result = PQexec(connection, query.str().c_str());
+ PGresult * result = PQexec(connection, query.str().c_str());
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
foundU = true;
*dirU = ln->dir;
//printfd(__FILE__, "Up rule ok! %d\n", ln->dir);
- //PrintRule(ln->rule);
}
} //if (!foundU)
foundD = true;
*dirD = ln->dir;
//printfd(__FILE__, "Down rule ok! %d\n", ln->dir);
- //PrintRule(ln->rule);
}
} //if (!foundD)
*dirD = DIR_NUM;
}
//-----------------------------------------------------------------------------
-void TRAFFCOUNTER_IMPL::SetRulesFile(const std::string & fn)
-{
-rulesFileName = fn;
-}
-//-----------------------------------------------------------------------------
bool TRAFFCOUNTER_IMPL::ReadRules(bool test)
{
//printfd(__FILE__, "TRAFFCOUNTER::ReadRules()\n");
}
if (!test)
rules.push_back(rul);
- //PrintRule(rul);
}
fclose(f);
if (!test)
rules.push_back(rul);
-//PrintRule(rul);
-
return false;
}
//-----------------------------------------------------------------------------
rules.clear();
}
//-----------------------------------------------------------------------------
-void TRAFFCOUNTER_IMPL::PrintRule(RULE rule) const
-{
-printf("%15s ", inet_ntostring(rule.ip).c_str());
-printf("mask=%08X ", rule.mask);
-printf("port1=%5d ", rule.port1);
-printf("port2=%5d ", rule.port2);
-switch (rule.proto)
- {
- case 0:
- printf("TCP ");
- break;
- case 1:
- printf("UDP ");
- break;
- case 2:
- printf("ICMP ");
- break;
- case 3:
- printf("TCP_UDP ");
- break;
- case 4:
- printf("ALL ");
- break;
- }
-printf("dir=%u \n", static_cast<unsigned>(rule.dir));
-}
-//-----------------------------------------------------------------------------
void TRAFFCOUNTER_IMPL::SetMonitorDir(const std::string & dir)
{
monitorDir = dir;
TRAFFCOUNTER_IMPL(USERS_IMPL * users, const std::string & rulesFileName);
~TRAFFCOUNTER_IMPL();
- void SetRulesFile(const std::string & rulesFileName);
-
int Reload();
int Start();
int Stop();
bool ParseAddress(const char * ta, RULE * rule) const;
uint32_t CalcMask(uint32_t msk) const;
void FreeRules();
- void PrintRule(RULE rule) const;
bool ReadRules(bool test = false);
static void * Run(void * data);
//---------------------------------------------------------------------------
void KOIToWin(const char * s1, char * s2, int l)
{
-unsigned char t;
for (int j = 0; j < l; j++)
{
- t = s1[j];
+ unsigned char t = s1[j];
s2[j] = koi2win[t];
if (s1[j] == 0)
//---------------------------------------------------------------------------
void WinToKOI(const char * s1, char * s2, int l)
{
-unsigned char t;
for (int j = 0; j < l; j++)
{
- t = s1[j];
+ unsigned char t = s1[j];
s2[j] = win2koi[t];
if (s1[j] == 0)
void KOIToWin(const std::string & s1, std::string * s2)
{
s2->erase(s2->begin(), s2->end());
-unsigned char t;
s2->reserve(s1.length());
for (int j = 0; j < (int)s1.length(); j++)
{
- t = s1[j];
+ unsigned char t = s1[j];
s2->push_back(koi2win[t]);
}
}
void WinToKOI(const std::string & s1, std::string * s2)
{
s2->erase(s2->begin(), s2->end());
-unsigned char t;
s2->reserve(s1.length());
for (int j = 0; j < (int)s1.length(); j++)
{
- t = s1[j];
+ unsigned char t = s1[j];
s2->push_back(win2koi[t]);
}
}
*/
char p[255];
-char * p1, *pp;
int n = 0;
strncpy(p, str, 254);
-pp = p;
+char * pp = p;
memset(ips, 0xFF, sizeof(unsigned long) * maxIP);
for (int i = 0; i < maxIP; i++)
{
- p1 = strtok(pp, ",\n ");
+ char * p1 = strtok(pp, ",\n ");
pp = NULL;
if (p1 == NULL && n == 0)// ÕËÁÚÁÔÅÌØ ÎÕÌØ É ÐÒÏÞÉÔÁÎÏ ÁÄÒÅÓÏ× ÔÏÖÅ ÎÏÌØ
//---------------------------------------------------------------------------
void DecodeStr(char * str, unsigned long serial, int useHDD)
{
-int len = strlen(str);
+size_t len = strlen(str);
char strdc[100];
-int i, j = 0;
-char c1, c2;
char serial_c[sizeof(serial)];
memcpy(serial_c, &serial, sizeof(serial));
-for (i = 0; i < len; i += 2)
+for (size_t i = 0; i < len; i += 2)
{
- c1 = (str[i] - 50);
- c2 = (str[i+1] - 50)<<4;
+ char c1 = (str[i] - 50);
+ char c2 = (str[i+1] - 50)<<4;
strdc[i/2] = c1+c2;
}
-for (i = 0; i < len/2; i++)
+for (size_t i = 0; i < len/2; i++)
{
if (!useHDD)
strdc[i] = strdc[i]^49;
DOTCONFDocument::~DOTCONFDocument()
{
- for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i != nodeTree.end(); i++){
+ for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i != nodeTree.end(); ++i){
delete(*i);
}
- for(std::list<char*>::iterator i = requiredOptions.begin(); i != requiredOptions.end(); i++){
+ for(std::list<char*>::iterator i = requiredOptions.begin(); i != requiredOptions.end(); ++i){
free(*i);
}
- for(std::list<char*>::iterator i = processedFiles.begin(); i != processedFiles.end(); i++){
+ for(std::list<char*>::iterator i = processedFiles.begin(); i != processedFiles.end(); ++i){
free(*i);
}
free(fileName);
DOTCONFDocumentNode * tagNode = NULL;
bool newNode = false;
- for(std::list<char*>::iterator i = words.begin(); i != words.end(); i++) {
+ for(std::list<char*>::iterator i = words.begin(); i != words.end(); ++i) {
word = *i;
if(*word == '<'){
} else { //closing tag
nodeName+=2;
std::list<DOTCONFDocumentNode*>::reverse_iterator i=nodeTree.rbegin();
- for(; i!=nodeTree.rend(); i++){
+ for(; i!=nodeTree.rend(); ++i){
if(!cmp_func(nodeName, (*i)->name) && !(*i)->closed){
(*i)->closed = true;
curParent = (*i)->parentNode;
curParent = _parent;
quoted = false;
- size_t slen = 0;
while(fgets(str, 511, file)){
curLine++;
- slen = strlen(str);
+ size_t slen = strlen(str);
if( slen >= 510 ){
error(curLine, fileName, "warning: line too long");
}
{
int ret = 0;
- DOTCONFDocumentNode * tagNode = NULL;
- int vi = 0;
- for(std::list<DOTCONFDocumentNode*>::iterator i = from; i != nodeTree.end(); i++){
- tagNode = *i;
+ for(std::list<DOTCONFDocumentNode*>::iterator i = from; i != nodeTree.end(); ++i){
+ DOTCONFDocumentNode * tagNode = *i;
if(!tagNode->closed){
error(tagNode->lineNum, tagNode->fileName, "unclosed tag %s", tagNode->name);
ret = -1;
break;
}
- vi = 0;
+ int vi = 0;
while( vi < tagNode->valuesCount ){
//if((tagNode->values[vi])[0] == '$' && (tagNode->values[vi])[1] == '{' && strchr(tagNode->values[vi], '}') ){
if(strstr(tagNode->values[vi], "${") && strchr(tagNode->values[vi], '}') ){
std::list<DOTCONFDocumentNode*>::iterator from;
DOTCONFDocumentNode * tagNode = NULL;
int vi = 0;
- for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); i++){
+ for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); ++i){
tagNode = *i;
if(!cmp_func("IncludeFile", tagNode->name)){
vi = 0;
}
bool processed = false;
- for(std::list<char*>::const_iterator itInode = processedFiles.begin(); itInode != processedFiles.end(); itInode++){
+ for(std::list<char*>::const_iterator itInode = processedFiles.begin(); itInode != processedFiles.end(); ++itInode){
if(!strcmp(*itInode, realpathBuf)){
processed = true;
break;
}
//free(fileName);
fileName = strdup(realpathBuf);
- from = nodeTree.end(); from--;
+ from = nodeTree.end(); --from;
if(tagNode->parentNode){
DOTCONFDocumentNode * nd = tagNode->parentNode->childNode;
int DOTCONFDocument::checkRequiredOptions()
{
- for(std::list<char*>::const_iterator ci = requiredOptions.begin(); ci != requiredOptions.end(); ci++){
+ for(std::list<char*>::const_iterator ci = requiredOptions.begin(); ci != requiredOptions.end(); ++ci){
bool matched = false;
- for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); i++){
+ for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); ++i){
if(!cmp_func((*i)->name, *ci)){
matched = true;
break;
buf = mempool->strdup(subs);
} else {
std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin();
- DOTCONFDocumentNode * tagNode = NULL;
- for(; i!=nodeTree.end(); i++){
- tagNode = *i;
+ for(; i!=nodeTree.end(); ++i){
+ DOTCONFDocumentNode * tagNode = *i;
if(!cmp_func(tagNode->name, variable)){
if(tagNode->valuesCount != 0){
buf = mempool->strdup(tagNode->values[0]);
if(startNode != NULL){
while( i != nodeTree.end() && (*i) != startNode ){
- i++;
+ ++i;
}
- if( i != nodeTree.end() ) i++;
+ if( i != nodeTree.end() ) ++i;
}
- for(; i!=nodeTree.end(); i++){
+ for(; i!=nodeTree.end(); ++i){
//if(parentNode != NULL && (*i)->parentNode != parentNode){
if((*i)->parentNode != parentNode){
continue;
#ifdef WIN32
unsigned long arg = 1;
-res = ioctlsocket(sockr, FIONBIO, &arg);
+ioctlsocket(sockr, FIONBIO, &arg);
#else
if (0 != fcntl(sockr, F_SETFL, O_NONBLOCK))
{
void Executer(int msgID, pid_t pid)
#endif
{
-int ret;
struct SCRIPT_DATA sd;
struct sigaction newsa, oldsa;
sigset_t sigmask;
while (nonstop)
{
sd.mtype = 1;
- ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
+ int ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
if (ret < 0)
{