X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/57f35d206c1155ff0d948a18cea4713617df8f3c..722a4fd38336dab14e00cb60c9e0c17867a0240e:/projects/stargazer/traffcounter.cpp?ds=sidebyside diff --git a/projects/stargazer/traffcounter.cpp b/projects/stargazer/traffcounter.cpp index e9c143ec..9697cde0 100644 --- a/projects/stargazer/traffcounter.cpp +++ b/projects/stargazer/traffcounter.cpp @@ -28,12 +28,19 @@ $Author: faust $ */ +/* inet_aton */ +#include +#include +#include + #include #include +#include // Functions fopen and similar #include "traffcounter.h" #include "common.h" #include "stg_locker.h" +#include "stg_timer.h" #define FLUSH_TIME (10) #define REMOVE_TIME (31) @@ -47,7 +54,7 @@ enum protoNum }; //----------------------------------------------------------------------------- -TRAFFCOUNTER::TRAFFCOUNTER(USERS * u, const TARIFFS *, const string & fn) +TRAFFCOUNTER::TRAFFCOUNTER(USERS * u, const TARIFFS *, const std::string & fn) : WriteServLog(GetStgLogger()), rulesFileName(fn), monitoring(false), @@ -88,7 +95,7 @@ if (ReadRules()) printfd(__FILE__, "TRAFFCOUNTER::Start()\n"); int h = users->OpenSearch(); -user_iter u; +USER_PTR u; if (!h) { WriteServLog("TRAFFCOUNTER: Cannot get users."); @@ -124,7 +131,7 @@ if (!h) return -1; } -user_iter u; +USER_PTR u; while (users->SearchNext(h, &u) == 0) { UnSetUserNotifiers(u); @@ -171,7 +178,7 @@ while (tc->running) if (tc->monitoring && (touchTime + MONITOR_TIME_DELAY_SEC <= stgTime)) { - string monFile(tc->monitorDir + "/traffcounter_r"); + std::string monFile(tc->monitorDir + "/traffcounter_r"); printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", tc->monitoring, monFile.c_str()); touchTime = stgTime; TouchFile(monFile.c_str()); @@ -194,7 +201,7 @@ static time_t touchTime = stgTime - MONITOR_TIME_DELAY_SEC; if (monitoring && (touchTime + MONITOR_TIME_DELAY_SEC <= stgTime)) { - static string monFile = monitorDir + "/traffcounter_p"; + static std::string monFile = monitorDir + "/traffcounter_p"; printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", monitoring, monFile.c_str()); touchTime = stgTime; TouchFile(monFile.c_str()); @@ -267,13 +274,12 @@ if (ed.userUPresent || //TODO use result of lower_bound to inserting new record // Adding packet to a tree. - pair insertResult = packets.insert(pair(rawPacket, ed)); + std::pair insertResult = packets.insert(std::make_pair(rawPacket, ed)); pp_iter newPacket = insertResult.first; // Adding packet reference to an IP index. - ip2packets.insert(pair(ipU, newPacket)); - ip2packets.insert(pair(ipD, newPacket)); + ip2packets.insert(std::make_pair(ipU, newPacket)); + ip2packets.insert(std::make_pair(ipD, newPacket)); } } //----------------------------------------------------------------------------- @@ -385,11 +391,11 @@ while (pi != packets.end()) }*/ if (stgTime - pi->second.updateTime < REMOVE_TIME) { - pair res = newPackets.insert(*pi); + std::pair res = newPackets.insert(*pi); if (res.second) { - ip2packets.insert(make_pair(pi->first.GetSrcIP(), res.first)); - ip2packets.insert(make_pair(pi->first.GetDstIP(), res.first)); + ip2packets.insert(std::make_pair(pi->first.GetSrcIP(), res.first)); + ip2packets.insert(std::make_pair(pi->first.GetDstIP(), res.first)); } } ++pi; @@ -403,11 +409,11 @@ printfd(__FILE__, "FlushAndRemove() packets: %d(rem %d) ip2packets: %d(rem %d)\n } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::AddUser(user_iter user) +void TRAFFCOUNTER::AddUser(USER_PTR user) { printfd(__FILE__, "AddUser: %s\n", user->GetLogin().c_str()); uint32_t uip = user->GetCurrIP(); -pair pi; +std::pair pi; STG_LOCKER lock(&mutex, __FILE__, __LINE__); // Find all packets with IP belongs to this user @@ -444,7 +450,7 @@ while (pi.first != pi.second) void TRAFFCOUNTER::DelUser(uint32_t uip) { printfd(__FILE__, "DelUser: %s \n", inet_ntostring(uip).c_str()); -pair pi; +std::pair pi; STG_LOCKER lock(&mutex, __FILE__, __LINE__); pi = ip2packets.equal_range(uip); @@ -494,7 +500,7 @@ while (pi.first != pi.second) ip2packets.erase(pi.first, pi.second); } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::SetUserNotifiers(user_iter user) +void TRAFFCOUNTER::SetUserNotifiers(USER_PTR user) { // Adding user. Adding notifiers to user. TRF_IP_BEFORE ipBNotifier(*this, user); @@ -506,11 +512,11 @@ ipAfterNotifiers.push_front(ipANotifier); user->AddCurrIPAfterNotifier(&(*ipAfterNotifiers.begin())); } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::UnSetUserNotifiers(user_iter user) +void TRAFFCOUNTER::UnSetUserNotifiers(USER_PTR user) { // Removing user. Removing notifiers from user. -list::iterator bi; -list::iterator ai; +std::list::iterator bi; +std::list::iterator ai; bi = ipBeforeNotifiers.begin(); while (bi != ipBeforeNotifiers.end()) @@ -551,7 +557,7 @@ bool foundD = false; // Was rule for D found ? enum { ICMP_RPOTO = 1, TCP_PROTO = 6, UDP_PROTO = 17 }; -list::const_iterator ln; +std::list::const_iterator ln; ln = rules.begin(); while (ln != rules.end()) @@ -661,7 +667,7 @@ if (!foundD) return; }; //----------------------------------------------------------------------------- -void TRAFFCOUNTER::SetRulesFile(const string & fn) +void TRAFFCOUNTER::SetRulesFile(const std::string & fn) { rulesFileName = fn; } @@ -929,7 +935,7 @@ printf("dir=%d \n", rule.dir); return; } //----------------------------------------------------------------------------- -void TRAFFCOUNTER::SetMonitorDir(const string & monitorDir) +void TRAFFCOUNTER::SetMonitorDir(const std::string & monitorDir) { TRAFFCOUNTER::monitorDir = monitorDir; monitoring = (monitorDir != "");