X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/bccb08f374dba862369712669c4ca73ccbfb2170..7e2a4802f98a1e22841be0ed47f3db773a5d6070:/projects/stargazer/traffcounter_impl.cpp?ds=sidebyside diff --git a/projects/stargazer/traffcounter_impl.cpp b/projects/stargazer/traffcounter_impl.cpp index 83554e27..a605e284 100644 --- a/projects/stargazer/traffcounter_impl.cpp +++ b/projects/stargazer/traffcounter_impl.cpp @@ -29,6 +29,7 @@ */ /* inet_aton */ +#include #include #include #include @@ -37,9 +38,9 @@ #include #include // fopen and similar +#include "stg/common.h" +#include "stg/locker.h" #include "traffcounter_impl.h" -#include "common.h" -#include "stg_locker.h" #include "stg_timer.h" #define FLUSH_TIME (10) @@ -89,6 +90,7 @@ if (!stopped) if (ReadRules()) { + printfd(__FILE__, "TRAFFCOUNTER_IMPL::Start() - Cannot read rules\n"); WriteServLog("TRAFFCOUNTER: Cannot read rules."); return -1; } @@ -98,6 +100,7 @@ int h = users->OpenSearch(); USER_PTR u; if (!h) { + printfd(__FILE__, "TRAFFCOUNTER_IMPL::Start() - Cannot get users\n"); WriteServLog("TRAFFCOUNTER: Cannot get users."); return -1; } @@ -111,7 +114,8 @@ users->CloseSearch(h); running = true; if (pthread_create(&thread, NULL, Run, this)) { - WriteServLog("TRAFFCOUNTER: Error: Cannot start thread!"); + printfd(__FILE__, "TRAFFCOUNTER_IMPL::Start() - Cannot start thread\n"); + WriteServLog("TRAFFCOUNTER: Error: Cannot start thread."); return -1; } return 0; @@ -689,7 +693,8 @@ f = fopen(rulesFileName.c_str(), "rt"); if (!f) { - WriteServLog("File %s cannot be oppened.", rulesFileName.c_str()); + printfd(__FILE__, "TRAFFCOUNTER_IMPL::ReadRules() - File '%s' cannot be opened.\n", rulesFileName.c_str()); + WriteServLog("File '%s' cannot be oppened.", rulesFileName.c_str()); return true; } @@ -704,7 +709,8 @@ while (fgets(str, 1023, f)) r = sscanf(str,"%s %s %s", tp, ta, td); if (r != 3) { - WriteServLog("Error in file %s. There must be 3 parameters. Line %d.", rulesFileName.c_str(), lineNumber); + printfd(__FILE__, "TRAFFCOUNTER_IMPL::ReadRules() - Error in file '%s' at line %d. There must be 3 parameters.\n", rulesFileName.c_str(), lineNumber); + WriteServLog("Error in file '%s' at line %d. There must be 3 parameters.", rulesFileName.c_str(), lineNumber); fclose(f); return true; } @@ -726,6 +732,7 @@ while (fgets(str, 1023, f)) if (rul.dir == 0xff || rul.proto == 0xff) { + printfd(__FILE__, "TRAFFCOUNTER_IMPL::ReadRules() - Error in file '%s' at line %d.\n", rulesFileName.c_str(), lineNumber); WriteServLog("Error in file %s. Line %d.", rulesFileName.c_str(), lineNumber); fclose(f); @@ -734,6 +741,7 @@ while (fgets(str, 1023, f)) if (ParseAddress(ta, &rul) != 0) { + printfd(__FILE__, "TRAFFCOUNTER_IMPL::ReadRules() - Error in file '%s' at line %d. Error in adress.\n", rulesFileName.c_str(), lineNumber); WriteServLog("Error in file %s. Error in adress. Line %d.", rulesFileName.c_str(), lineNumber); fclose(f); @@ -768,12 +776,14 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); if (ReadRules(true)) { + printfd(__FILE__, "TRAFFCOUNTER_IMPL::Reload() - Failed to reload rules.\n"); WriteServLog("TRAFFCOUNTER: Cannot reload rules. Errors found."); return -1; } FreeRules(); ReadRules(); +printfd(__FILE__, "TRAFFCOUNTER_IMPL::Reload() - Reload rules successfull.\n"); WriteServLog("TRAFFCOUNTER: Reload rules successfull."); return 0; } @@ -828,6 +838,7 @@ if (n == ':') // port if (!(rule->proto == tcp || rule->proto == udp || rule->proto == tcp_udp)) { + printfd(__FILE__, "TRAFFCOUNTER_IMPL::ParseAddress() - No ports specified for this protocol.\n"); WriteServLog("No ports specified for this protocol."); return true; } @@ -886,6 +897,7 @@ rule->mask = CalcMask(msk); if ((ip & rule->mask) != ip) { + printfd(__FILE__, "TRAFFCOUNTER_IMPL::ParseAddress() - Address does'n match mask.\n"); WriteServLog("Address does'n match mask."); return true; }