From 00c5298c6d00cbce32c1e678840b5e34bb8feea7 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 5 Jan 2011 16:51:47 +0200 Subject: [PATCH 01/16] =?utf8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D1=96=D0=B7=D0=BE?= =?utf8?q?=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D1=96?= =?utf8?q?=D1=88=D0=BD=D1=8E=20=D1=87=D0=B5=D1=80=D0=B3=D1=83=20=D0=BF?= =?utf8?q?=D0=BE=D0=B2=D1=96=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D1=8C=20?= =?utf8?q?=D1=96=20=D1=97=D1=97=20=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE?= =?utf8?q?=D0=BD=D1=96=D0=B7=D0=B0=D1=86=D1=96=D1=8E=20=D0=B7=20=D0=B1?= =?utf8?q?=D0=B0=D0=B7=D0=BE=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/user.cpp | 53 ++++++++++++++++++++++++++++++++++++- projects/stargazer/user.h | 2 ++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user.cpp index 46f6848b..93fd66dc 100644 --- a/projects/stargazer/user.cpp +++ b/projects/stargazer/user.cpp @@ -255,6 +255,24 @@ if (tariff == NULL) return -1; } +std::vector hdrsList; + +if (store->GetMessageHdrs(&hdrsList, login)) + { + printfd(__FILE__, "Error GetMessageHdrs %s\n", store->GetStrError().c_str()); + return -1; + } + +std::vector::const_iterator it; +for (it = hdrsList.begin(); it != hdrsList.end(); ++it) + { + STG_MSG msg; + if (store->GetMessage(it->id, &msg, login) == 0) + { + messages.push_back(msg); + } + } + return 0; } //----------------------------------------------------------------------------- @@ -1154,6 +1172,7 @@ if (SendMessage(*msg) == 0) WriteServLog("%s", store->GetStrError().c_str()); return -1; } + messages.push_back(*msg); } } else @@ -1166,6 +1185,7 @@ else WriteServLog("%s", store->GetStrError().c_str()); return -1; } + messages.push_back(*msg); } return 0; } @@ -1196,7 +1216,7 @@ int USER::ScanMessage() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -vector hdrsList; +/*vector hdrsList; if (store->GetMessageHdrs(&hdrsList, login)) { @@ -1241,7 +1261,38 @@ for (unsigned i = 0; i < hdrsList.size(); i++) WriteServLog("%s", store->GetStrError().c_str()); } } + }*/ + +std::list::iterator it(messages.begin()); +while (it != messages.end()) + { + if (SendMessage(*it)) + { + break; + } + it->header.repeat--; + if (it->header.repeat < 0) + { + printfd(__FILE__, "DelMessage\n"); + store->DelMessage(it->id, login); + messages.erase(it++); + } + else + { + #ifndef DEBUG + //TODO: gcc v. 4.x generate ICE on x86_64 + it->header.lastSendTime = time(NULL); + #else + it->header.lastSendTime = stgTime; + #endif + if (store->EditMessage(*it, login)) + { + printfd(__FILE__, "EditMessage Error %s\n", store->GetStrError().c_str()); + } + ++it; + } } + return 0; } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/user.h b/projects/stargazer/user.h index 8b0c4dba..496baa72 100644 --- a/projects/stargazer/user.h +++ b/projects/stargazer/user.h @@ -241,6 +241,8 @@ private: const map * ipIndex; + list messages; + bool deleted; time_t lastWriteStat; // ÷ÒÅÍÑ ÐÏÓÌÅÄÎÅÊ ÚÁÐÉÓÉ ÓÔÁÔÉÓÔÉËÉ -- 2.44.2 From 87b2d09bd02f7edfecc39d59a151240872b18b86 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 5 Jan 2011 16:57:57 +0200 Subject: [PATCH 02/16] =?utf8?q?=D0=92=D0=B8=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BC=D0=B8=D0=BB=D0=BA=D1=83?= =?utf8?q?=20=D0=BA=D0=BE=D0=BC=D0=BF=D1=96=D0=BB=D1=8F=D1=86=D1=96=D1=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/user.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user.cpp index 93fd66dc..50046fa5 100644 --- a/projects/stargazer/user.cpp +++ b/projects/stargazer/user.cpp @@ -1274,7 +1274,7 @@ while (it != messages.end()) if (it->header.repeat < 0) { printfd(__FILE__, "DelMessage\n"); - store->DelMessage(it->id, login); + store->DelMessage(it->header.id, login); messages.erase(it++); } else -- 2.44.2 From c03710e5962e640d8a8e23cd9144e753ff282a50 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 5 Jan 2011 17:25:43 +0200 Subject: [PATCH 03/16] =?utf8?q?=D0=9F=D1=80=D0=B8=20=D1=80=D0=BE=D0=B1?= =?utf8?q?=D0=BE=D1=82=D1=96=20=D0=B7=20=D0=BF=D0=BE=D0=B2=D1=96=D0=B4?= =?utf8?q?=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=BD=D1=8F=D0=BC=D0=B8=20=D0=BF?= =?utf8?q?=D1=80=D0=B8=D0=B1=D1=80=D0=B0=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B9?= =?utf8?q?=D0=B2=D1=96=20=D0=B1=D0=BB=D0=BE=D0=BA=D1=83=D0=B2=D0=B0=D0=BD?= =?utf8?q?=D0=BD=D1=8F=20=D1=96=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D1=96?= =?utf8?q?=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/user.cpp | 46 +++++++++++++++---------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user.cpp index 50046fa5..b68c632a 100644 --- a/projects/stargazer/user.cpp +++ b/projects/stargazer/user.cpp @@ -1153,7 +1153,19 @@ int USER::AddMessage(STG_MSG * msg) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -if (SendMessage(*msg) == 0) +if (SendMessage(*msg)) + { + if (store->AddMessage(msg, login)) + { + errorStr = store->GetStrError(); + STG_LOGGER & WriteServLog = GetStgLogger(); + WriteServLog("Error adding message %s", errorStr.c_str()); + WriteServLog("%s", store->GetStrError().c_str()); + return -1; + } + messages.push_back(*msg); + } +else { if (msg->header.repeat > 0) { @@ -1175,46 +1187,26 @@ if (SendMessage(*msg) == 0) messages.push_back(*msg); } } -else - { - if (store->AddMessage(msg, login)) - { - errorStr = store->GetStrError(); - STG_LOGGER & WriteServLog = GetStgLogger(); - WriteServLog("Error adding message %s", errorStr.c_str()); - WriteServLog("%s", store->GetStrError().c_str()); - return -1; - } - messages.push_back(*msg); - } return 0; } //----------------------------------------------------------------------------- int USER::SendMessage(const STG_MSG & msg) { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); - -if (authorizedBy.empty()) - { - return -1; - } - +// No lock `cause we are already locked from caller int ret = -1; -set::iterator it; - -it = authorizedBy.begin(); +set::iterator it(authorizedBy.begin()); while (it != authorizedBy.end()) { - if ((*it)->SendMessage(msg, currIP) == 0) + if (!(*it++)->SendMessage(msg, currIP)) ret = 0; - ++it; } return ret; } //----------------------------------------------------------------------------- int USER::ScanMessage() { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +// No lock `cause we are already locked from caller +// We need not check for the authorizedBy `cause it has already checked by caller /*vector hdrsList; @@ -1268,7 +1260,7 @@ while (it != messages.end()) { if (SendMessage(*it)) { - break; + return -1; } it->header.repeat--; if (it->header.repeat < 0) -- 2.44.2 From 26f0a7be9285009bcfbb743d61211be059ff8db8 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 5 Jan 2011 17:36:35 +0200 Subject: [PATCH 04/16] =?utf8?q?=D0=9A=D0=BE=D1=81=D0=BC=D0=B5=D1=82=D0=B8?= =?utf8?q?=D1=87=D0=BD=D1=96=20=D0=B2=D0=B8=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/user.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user.cpp index b68c632a..e63d37d3 100644 --- a/projects/stargazer/user.cpp +++ b/projects/stargazer/user.cpp @@ -1158,7 +1158,6 @@ if (SendMessage(*msg)) if (store->AddMessage(msg, login)) { errorStr = store->GetStrError(); - STG_LOGGER & WriteServLog = GetStgLogger(); WriteServLog("Error adding message %s", errorStr.c_str()); WriteServLog("%s", store->GetStrError().c_str()); return -1; @@ -1179,7 +1178,6 @@ else if (store->AddMessage(msg, login)) { errorStr = store->GetStrError(); - STG_LOGGER & WriteServLog = GetStgLogger(); WriteServLog("Error adding message %s", errorStr.c_str()); WriteServLog("%s", store->GetStrError().c_str()); return -1; @@ -1266,7 +1264,11 @@ while (it != messages.end()) if (it->header.repeat < 0) { printfd(__FILE__, "DelMessage\n"); - store->DelMessage(it->header.id, login); + if (store->DelMessage(it->header.id, login)) + { + WriteServLog("Error deleting message: '%s'", store->GetStrError().c_str()); + printfd(__FILE__, "Error deleting message: '%s'\n", store->GetStrError().c_str()); + } messages.erase(it++); } else @@ -1279,7 +1281,8 @@ while (it != messages.end()) #endif if (store->EditMessage(*it, login)) { - printfd(__FILE__, "EditMessage Error %s\n", store->GetStrError().c_str()); + WriteServLog("Error modifying message: '%s'", store->GetStrError().c_str()); + printfd(__FILE__, "Error modifying message: '%s'\n", store->GetStrError().c_str()); } ++it; } -- 2.44.2 From 63ec10fdcc402bf07f7a8c0dfb326feb60249038 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 6 Jan 2011 16:08:19 +0200 Subject: [PATCH 05/16] =?utf8?q?=D0=92=D0=B8=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BE=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=80=D0=B5=D0=BA?= =?utf8?q?=D1=82=D0=BD=D1=83=20=D1=80=D0=BE=D0=B1=D0=BE=D1=82=D1=83=20?= =?utf8?q?=D0=B7=20=D0=BF=D0=B5=D1=80=D1=96=D0=BE=D0=B4=D0=BE=D0=BC=20?= =?utf8?q?=D0=B2=D1=96=D0=B4=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?utf8?q?=D0=BE=D0=B2=D1=96=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/user.cpp | 58 ++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user.cpp index e63d37d3..3d9371fd 100644 --- a/projects/stargazer/user.cpp +++ b/projects/stargazer/user.cpp @@ -1158,8 +1158,8 @@ if (SendMessage(*msg)) if (store->AddMessage(msg, login)) { errorStr = store->GetStrError(); - WriteServLog("Error adding message %s", errorStr.c_str()); - WriteServLog("%s", store->GetStrError().c_str()); + WriteServLog("Error adding message: '%s'", errorStr.c_str()); + printfd(__FILE__, "Error adding message: '%s'\n", errorStr.c_str()); return -1; } messages.push_back(*msg); @@ -1178,8 +1178,8 @@ else if (store->AddMessage(msg, login)) { errorStr = store->GetStrError(); - WriteServLog("Error adding message %s", errorStr.c_str()); - WriteServLog("%s", store->GetStrError().c_str()); + WriteServLog("Error adding repeatable message: '%s'", errorStr.c_str()); + printfd(__FILE__, "Error adding repeatable message: '%s'\n", errorStr.c_str()); return -1; } messages.push_back(*msg); @@ -1256,34 +1256,40 @@ for (unsigned i = 0; i < hdrsList.size(); i++) std::list::iterator it(messages.begin()); while (it != messages.end()) { - if (SendMessage(*it)) - { - return -1; - } - it->header.repeat--; - if (it->header.repeat < 0) + if (static_cast(it->header.lastSendTime + it->header.repeatPeriod * 60) < stgTime) { - printfd(__FILE__, "DelMessage\n"); - if (store->DelMessage(it->header.id, login)) + if (SendMessage(*it)) { - WriteServLog("Error deleting message: '%s'", store->GetStrError().c_str()); - printfd(__FILE__, "Error deleting message: '%s'\n", store->GetStrError().c_str()); + return -1; + } + it->header.repeat--; + if (it->header.repeat < 0) + { + if (store->DelMessage(it->header.id, login)) + { + WriteServLog("Error deleting message: '%s'", store->GetStrError().c_str()); + printfd(__FILE__, "Error deleting message: '%s'\n", store->GetStrError().c_str()); + } + messages.erase(it++); + } + else + { + #ifndef DEBUG + //TODO: gcc v. 4.x generate ICE on x86_64 + it->header.lastSendTime = time(NULL); + #else + it->header.lastSendTime = stgTime; + #endif + if (store->EditMessage(*it, login)) + { + WriteServLog("Error modifying message: '%s'", store->GetStrError().c_str()); + printfd(__FILE__, "Error modifying message: '%s'\n", store->GetStrError().c_str()); + } + ++it; } - messages.erase(it++); } else { - #ifndef DEBUG - //TODO: gcc v. 4.x generate ICE on x86_64 - it->header.lastSendTime = time(NULL); - #else - it->header.lastSendTime = stgTime; - #endif - if (store->EditMessage(*it, login)) - { - WriteServLog("Error modifying message: '%s'", store->GetStrError().c_str()); - printfd(__FILE__, "Error modifying message: '%s'\n", store->GetStrError().c_str()); - } ++it; } } -- 2.44.2 From 327ec384624ea69aa0e02f89d5513e31752fef90 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 8 Jan 2011 15:41:40 +0200 Subject: [PATCH 06/16] =?utf8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D1=96=D1=8E?= =?utf8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D1=82=D0=B2=D0=BE=D1=80=D0=B5=D0=BD?= =?utf8?q?=D0=BD=D1=8F=20=D1=80=D0=B0=D0=B4=D0=BA=D1=83=20=D0=BD=D0=B0=20I?= =?utf8?q?P-=D0=B0=D0=B4=D1=80=D0=B5=D1=81=D1=83=20=D0=B7=D0=B0=D0=BC?= =?utf8?q?=D1=8B=D0=BD=D0=B5=D0=BD=D0=BE=20=D0=BD=D0=B0=20inet=5Fpton?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- stglibs/common.lib/common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 71246704..57b37bdf 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -415,7 +415,7 @@ for (int i = 0; i < maxIP; i++) } struct in_addr in; - if (!inet_aton(p1, &in)) + if (inet_pton(AF_INET, p1, &in) != 1) { //printf("INADDR_NONE\n"); return EINVAL; -- 2.44.2 From bd30fed6d51a05e51fe89175dc1b84c5cfc79262 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 8 Jan 2011 17:05:21 +0200 Subject: [PATCH 07/16] =?utf8?q?=D0=92=D0=B8=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BC=D0=B8=D0=BB=D0=BA=D0=B8?= =?utf8?q?=20=D0=BA=D0=BE=D0=BC=D0=BF=D1=96=D0=BB=D1=8F=D1=86=D1=96=D1=97?= =?utf8?q?=20=D0=BD=D0=B0=20=D0=BF=D0=BB=D0=B0=D1=82=D1=84=D0=BE=D1=80?= =?utf8?q?=D0=BC=D1=96=20WIN32?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- stglibs/common.lib/common.cpp | 72 ++++++++++++++++++++++++++++++++++- stglibs/common.lib/common.h | 2 + 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 57b37bdf..37ce079d 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -83,6 +83,44 @@ using namespace std; +#ifdef WIN32 +//----------------------------------------------------------------------------- +const char * inet_ntop(int af, const void * src, char * dst, unsigned long length) +{ +struct sockaddr_in addr; +addr.sin_family = af; +addr.sin_port = 0; +memcpy(&addr.sin_addr.s_addr, src, sizeof(addr.sin_addr.s_addr)); +if (WSAAddressToStringA(reinterpret_cast(&addr), sizeof(addr), 0, dst, &length)) + { + return NULL; + } +return dst; +} +//----------------------------------------------------------------------------- +int inet_pton(int af, const char * src, void * dst) +{ +// Fuck you Microsoft! +// Why the hell not to use const char *? +size_t slen = strlen(src); +char * buf = new char[slen + 1]; +strncpy(buf, src, slen + 1); +buf[slen] = 0; +struct sockaddr_in addr; +addr.sin_family = af; +addr.sin_port = 0; +addr.sin_addr.s_addr = 0; +int length = sizeof(addr); +if (WSAStringToAddressA(buf, af, 0, reinterpret_cast(&addr), &length)) + { + delete[] buf; + return -1; + } +memcpy(dst, &addr, sizeof(addr)); +delete[] buf; +return 1; +} +#endif //----------------------------------------------------------------------------- int strtodouble2(const char * s, double &a) { @@ -762,6 +800,7 @@ if (errno == ERANGE) return 0; } +#ifndef WIN32 //--------------------------------------------------------------------------- int str2x(const std::string & str, long long & x) { @@ -782,6 +821,7 @@ if (errno == ERANGE) return 0; } +#endif //--------------------------------------------------------------------------- const std::string & x2str(unsigned x, std::string & s) { @@ -827,8 +867,35 @@ std::string & Trim(std::string & val) return TrimR(TrimL(val)); } //--------------------------------------------------------------------------- +#ifdef WIN32 +static int is_leap(unsigned y) +{ + y += 1900; + return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); +} +#endif +//--------------------------------------------------------------------------- + time_t stg_timegm(struct tm * brokenTime) { +#ifdef WIN32 +static const unsigned ndays[2][12] ={ + {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, + {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; +time_t res = 0; +for (int i = 70; i < brokenTime->tm_year; ++i) + res += is_leap(i) ? 366 : 365; +for (int i = 0; i < brokenTime->tm_mon; ++i) + res += ndays[is_leap(brokenTime->tm_year)][i]; +res += brokenTime->tm_mday - 1; +res *= 24; +res += brokenTime->tm_hour; +res *= 60; +res += brokenTime->tm_min; +res *= 60; +res += brokenTime->tm_sec; +return res; +#else #ifdef HAVE_TIMEGM return timegm(brokenTime); #else @@ -844,7 +911,8 @@ else unsetenv("TZ"); tzset(); return ret; -#endif +#endif // HAVE_TIMEGM +#endif // WIN32 } //--------------------------------------------------------------------------- std::string IconvString(const std::string & source, @@ -864,7 +932,7 @@ strncpy(inBuf, source.c_str(), source.length()); inBuf[source.length()] = 0; -#if defined(FREE_BSD) || defined(FREE_BSD5) +#if defined(FREE_BSD) || defined(FREE_BSD5) || defined(WIN32) const char * srcPos = inBuf; #else char * srcPos = inBuf; diff --git a/stglibs/common.lib/common.h b/stglibs/common.lib/common.h index 6e957698..f924867b 100644 --- a/stglibs/common.lib/common.h +++ b/stglibs/common.lib/common.h @@ -221,8 +221,10 @@ int str2x(const std::string & str, int & x); int str2x(const std::string & str, unsigned & x); int str2x(const std::string & str, long & x); int str2x(const std::string & str, unsigned long & x); +#ifndef WIN32 int str2x(const std::string & str, long long & x); int str2x(const std::string & str, unsigned long long & x); +#endif //----------------------------------------------------------------------------- const std::string & x2str(unsigned x, std::string & s); const std::string & x2str(unsigned long x, std::string & s); -- 2.44.2 From 02c2e6246eb5f4a70a3be5f774b6a75f445d3115 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 13 Jan 2011 13:56:57 +0200 Subject: [PATCH 08/16] =?utf8?q?=D0=92=D0=B8=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BC=D0=B8=D0=BB=D0=BA=D1=83?= =?utf8?q?=20=D0=BA=D0=BE=D0=BC=D0=BF=D1=8B=D0=BB=D1=8F=D1=86=D1=8B=D1=8A?= =?utf8?q?=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20store=5Ffirebird?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/plugins/store/firebird/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/store/firebird/Makefile b/projects/stargazer/plugins/store/firebird/Makefile index 773d778a..7304d4de 100644 --- a/projects/stargazer/plugins/store/firebird/Makefile +++ b/projects/stargazer/plugins/store/firebird/Makefile @@ -17,7 +17,7 @@ SRCS = ./firebird_store.cpp \ ./firebird_store_users.cpp \ ./firebird_store_utils.cpp -STGLIBS = -libpp -lstg_common +STGLIBS = -libpp -lstg_common -lstg_locker -lstg_crypto include ../../Makefile.in -- 2.44.2 From 904a0bdb0da53217f6c8a42cd4f5eb5a027a0973 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 14 Jan 2011 17:58:16 +0200 Subject: [PATCH 09/16] =?utf8?q?=D0=92=D0=B8=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BC=D0=B8=D0=BB=D0=BA=D1=83?= =?utf8?q?=20=D1=89=D0=BE=20=D0=BF=D1=80=D0=B8=D0=B7=D0=B2=D0=BE=D0=B4?= =?utf8?q?=D0=B8=D0=BB=D0=B0=20=D0=B4=D0=BE=20=D0=BF=D0=B0=D0=B4=D1=96?= =?utf8?q?=D0=BD=D0=BD=D1=8F=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=B8?= =?utf8?q?=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BF=D1=80=D0=BE=D0=B1=D1=96=20?= =?utf8?q?=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D1=96?= =?utf8?q?=D1=97=20=D0=BA=D0=BE=D1=80=D0=B8=D1=81=D1=82=D1=83=D0=B2=D0=B0?= =?utf8?q?=D1=87=D0=B0=20=D0=B7=20=D0=BD=D0=B5=D0=BF=D1=80=D0=B0=D0=B2?= =?utf8?q?=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8=D0=BC=20=D0=BB=D0=BE=D0=B3=D1=96?= =?utf8?q?=D0=BD=D0=BE=D0=BC=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20FreeRADIUS?= =?utf8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/plugins/store/mysql/mysql_store.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.cpp b/projects/stargazer/plugins/store/mysql/mysql_store.cpp index fefadd5c..f62a846f 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@ -711,6 +711,13 @@ if (!(res=mysql_store_result(sock))) return -1; } +if (mysql_num_rows(res) != 1) +{ + errorStr = "User not found"; + mysql_close(sock); + return -1; +} + row = mysql_fetch_row(res); string param; -- 2.44.2 From 820288049b136a341da8815142ae44ac912b72ad Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 20 Jan 2011 17:42:30 +0200 Subject: [PATCH 10/16] =?utf8?q?=D0=92=D0=B8=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BE=20=D0=BD=D0=B5=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?utf8?q?=D0=BB=D1=8C=D0=BD=D1=83=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0?= =?utf8?q?=D1=87=D1=83=20ID=20=D0=BA=D0=BE=D1=80=D0=B8=D1=81=D1=82=D1=83?= =?utf8?q?=D0=B2=D0=B0=D1=87=D0=B0=20=D1=83=20=D1=81=D0=BA=D1=80=D0=B8?= =?utf8?q?=D0=BF=D1=82=D0=B8=20=D0=B2=20rscriptd?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/rscriptd/listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index 8737b3b8..f6d77c96 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -323,7 +323,7 @@ if (strncmp((char *)packetTail.magic, RS_ID, RS_MAGIC_LEN)) std::stringstream params; params << data.login << " " << inet_ntostring(data.ip) << " " - << ntohl(data.id) << " " + << data.id << " " << (char *)packetTail.params; data.params = params.str(); -- 2.44.2 From 1ed49c21260edc5b40aa2d0d4b8486bc1928f21b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 21 Jan 2011 17:57:35 +0200 Subject: [PATCH 11/16] =?utf8?q?=D0=A3=D1=81=D1=83=D0=BD=D1=83=D1=82=D0=BE?= =?utf8?q?=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D1=83=20race=20con?= =?utf8?q?ditions=20=D1=83=20rscriptd?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/rscriptd/listener.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index f6d77c96..aca5da44 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -333,9 +333,16 @@ return false; //----------------------------------------------------------------------------- void LISTENER::ProcessPending() { -printfd(__FILE__, "Pending data size: %d\n", pending.size()); -std::list::iterator it(pending.begin()); -while (it != pending.end()) +std::list localPending; + + { + STG_LOCKER lock(&mutex, __FILE__, __LINE__); + printfd(__FILE__, "Pending data size: %d\n", pending.size()); + localPending.swap(pending); + } + +std::list::iterator it(localPending.begin()); +while (it != localPending.end()) { std::vector::iterator uit( std::lower_bound( @@ -375,9 +382,7 @@ while (it != pending.end()) users.erase(uit); } } - - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - pending.erase(it++); + ++it; } } //----------------------------------------------------------------------------- -- 2.44.2 From 78e14695fc1b743f225a5aa30ca98784bce576c1 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 26 Jan 2011 17:52:49 +0200 Subject: [PATCH 12/16] =?utf8?q?=D0=94=D0=BE=D0=B4=D0=B0=D0=BD=D0=BE=20?= =?utf8?q?=D0=BF=D1=80=D0=BE=D0=BF=D1=83=D1=89=D0=B5=D0=BD=D1=96=20=D0=B7?= =?utf8?q?=D0=B0=D0=B3=D0=BE=D0=BB=D0=BE=D0=B2=D0=BE=D1=87=D0=BD=D1=96=20?= =?utf8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/main.cpp | 16 ++++++---------- .../authorization/inetaccess/inetaccess.cpp | 3 +++ .../configuration/rpcconfig/users_methods.cpp | 2 ++ .../configuration/sgconfig/parser_tariff.cpp | 2 +- .../plugins/configuration/sgconfig/rsconf.cpp | 3 ++- .../stargazer/plugins/other/radius/radius.cpp | 1 + projects/stargazer/traffcounter.cpp | 1 + 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 7a225ce5..2d5b808f 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -24,7 +24,7 @@ $Author: faust $ */ -#include +//#include #include #include #include @@ -35,9 +35,10 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -493,7 +494,6 @@ if (settings->ReadSettings()) string startFile(settings->GetConfDir() + START_FILE); #endif -//SetSignalHandlers(); if (ForkAndWait(settings->GetConfDir()) < 0) { STG_LOGGER & WriteServLog = GetStgLogger(); @@ -505,14 +505,13 @@ STG_LOGGER & WriteServLog = GetStgLogger(); WriteServLog.SetLogFileName(settings->GetLogFileName()); WriteServLog("Stg v. %s", SERVER_VERSION); -for (int i = 0; i < settings->GetExecutersNum(); i++) +for (size_t i = 0; i < settings->GetExecutersNum(); i++) { int ret = StartScriptExecuter(argv[0], settings->GetExecMsgKey(), &msgID, settings); if (ret < 0) { STG_LOGGER & WriteServLog = GetStgLogger(); WriteServLog("Start Script Executer error!"); - //goto exitLbl; return 1; } if (ret == 1) @@ -555,7 +554,6 @@ admins = new ADMINS(dataStore); users = new USERS(settings, dataStore, tariffs, admins->GetSysAdmin()); traffCnt = new TRAFFCOUNTER(users, tariffs, settings->GetRulesFileName()); traffCnt->SetMonitorDir(settings->GetMonitorDir()); -//tariffs->SetUsers(users); modSettings = settings->GetModulesSettings(); @@ -647,8 +645,6 @@ WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); creat(startFile.c_str(), S_IRUSR); #endif -//*a_kill_it = 0; - while (nonstop.GetStatus()) { if (needRulesReloading) @@ -702,7 +698,7 @@ if (loop.Stop()) exitLblNotStarted: -/*modIter = modules.begin(); +modIter = modules.begin(); while (modIter != modules.end()) { std::string name = modIter->GetFileName(); @@ -715,7 +711,7 @@ while (modIter != modules.end()) printfd(__FILE__, "Failed to unload module '%s'\n", name.c_str()); } ++modIter; - }*/ + } if (traffCnt) { diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 6d8db063..47ff002d 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -30,8 +30,11 @@ #include #include + #include #include +#include // snprintf +#include #include #include "inetaccess.h" diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp index 72fb399e..fd9f86be 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp @@ -1,3 +1,5 @@ +#include + #include "users_methods.h" #include "../../../users.h" diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp index aeb1c783..e3b26520 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp @@ -1,4 +1,4 @@ -//#include +#include // snprintf #include #include "parser.h" diff --git a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp index 8d2ce153..a3957f36 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp @@ -28,6 +28,7 @@ #include #include +#include // snprintf #include "configproto.h" #include "blowfish.h" @@ -545,7 +546,7 @@ void CONFIGPROTO::SendError(const char * text) { char s[255]; answerList.clear(); -sprintf(s, "", text); +snprintf(s, 255, "", text); answerList.push_back(s); } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 9b8c67d1..9c5ab1db 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -27,6 +27,7 @@ */ #include +#include #include #include "radius.h" diff --git a/projects/stargazer/traffcounter.cpp b/projects/stargazer/traffcounter.cpp index e9c143ec..1d088f48 100644 --- a/projects/stargazer/traffcounter.cpp +++ b/projects/stargazer/traffcounter.cpp @@ -30,6 +30,7 @@ #include #include +#include // Functions fopen and similar #include "traffcounter.h" #include "common.h" -- 2.44.2 From 56bcf61076cf2e51bd6ae9f0f50b53d48444b684 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 26 Jan 2011 17:53:25 +0200 Subject: [PATCH 13/16] =?utf8?q?=D0=9F=D1=80=D0=B8=D0=B1=D1=80=D0=B0=D0=BD?= =?utf8?q?=D0=BE=20"=D0=BC=D0=B5=D1=80=D1=82=D0=B2=D0=B8=D0=B9"=20=D0=BA?= =?utf8?q?=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/users.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/users.cpp b/projects/stargazer/users.cpp index f97a029f..e2f326e0 100644 --- a/projects/stargazer/users.cpp +++ b/projects/stargazer/users.cpp @@ -144,7 +144,7 @@ if (store->AddUser(login)) USER u(settings, store, tariffs, sysAdmin, &ipIndex); -struct tm * tms; +/*struct tm * tms; time_t t = stgTime; tms = localtime(&t); @@ -156,7 +156,7 @@ tms->tm_sec = 0; if (settings->GetDayResetTraff() > tms->tm_mday) tms->tm_mon -= 1; -tms->tm_mday = settings->GetDayResetTraff(); +tms->tm_mday = settings->GetDayResetTraff();*/ u.SetLogin(login); -- 2.44.2 From bf69e959b3e75cb3eb3748e93df9dcfe5b82aa17 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 26 Jan 2011 17:56:39 +0200 Subject: [PATCH 14/16] =?utf8?q?=D0=94=D0=BE=D0=B4=D0=B0=D0=BD=D0=BE=20?= =?utf8?q?=D0=BC=D0=BE=D0=B6=D0=BB=D0=B8=D0=B2=D1=96=D1=81=D1=82=D1=8C=20?= =?utf8?q?=D1=81=D1=82=D0=B8=D1=80=D0=B0=D0=BD=D0=BD=D1=8F=20=D0=BD=D0=B5?= =?utf8?q?=20=D0=B4=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D1=85=20=D0=BF=D0=BE=D0=B2=D1=96=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D1=8C=20=D0=B7=D0=B0=20=D1=82=D0=B0=D0=B9=D0=BC-=D0=B0?= =?utf8?q?=D1=83=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/settings.cpp | 132 +++++++++++++------------------- projects/stargazer/settings.h | 47 ++++++------ projects/stargazer/user.cpp | 19 ++++- 3 files changed, 97 insertions(+), 101 deletions(-) diff --git a/projects/stargazer/settings.cpp b/projects/stargazer/settings.cpp index 9fcacc01..7aa2950f 100644 --- a/projects/stargazer/settings.cpp +++ b/projects/stargazer/settings.cpp @@ -28,16 +28,15 @@ $Date: 2010/08/19 13:42:30 $ $Author: faust $ */ -#include -#include -#include -#include +#include +#include #include -using namespace std; - #include "settings.h" -#include "common.h" +#include "stg_logger.h" +#include "dotconfpp.h" + +using namespace std; //----------------------------------------------------------------------------- SETTINGS::SETTINGS() @@ -57,6 +56,7 @@ SETTINGS::SETTINGS() dayFeeIsLastDay(false), writeFreeMbTraffCost(false), showFeeInCash(true), + messageTimeout(0), logger(GetStgLogger()) { } @@ -64,7 +64,6 @@ SETTINGS::SETTINGS() SETTINGS::SETTINGS(const std::string & cd) : confDir(cd), scriptDir(cd), - pidFile(), monitoring(false), detailStatWritePeriod(dsPeriod_1_6), statWritePeriod(10), @@ -78,6 +77,7 @@ SETTINGS::SETTINGS(const std::string & cd) dayFeeIsLastDay(false), writeFreeMbTraffCost(false), showFeeInCash(true), + messageTimeout(0), logger(GetStgLogger()) { } @@ -85,22 +85,23 @@ SETTINGS::SETTINGS(const std::string & cd) SETTINGS::SETTINGS(const SETTINGS & rval) : confDir(rval.confDir), scriptDir(rval.scriptDir), + pidFile(rval.pidFile), + monitoring(rval.monitoring), detailStatWritePeriod(dsPeriod_1_6), statWritePeriod(10), + stgExecMsgKey(rval.stgExecMsgKey), + executersNum(rval.executersNum), + fullFee(rval.fullFee), dayFee(0), dayResetTraff(0), + spreadFee(rval.spreadFee), freeMbAllowInet(false), dayFeeIsLastDay(false), writeFreeMbTraffCost(false), + showFeeInCash(rval.showFeeInCash), + messageTimeout(rval.messageTimeout), logger(GetStgLogger()) { -spreadFee = rval.spreadFee; -pidFile = rval.pidFile; -stgExecMsgKey = rval.stgExecMsgKey; -executersNum = rval.executersNum; -showFeeInCash = rval.showFeeInCash; -fullFee = rval.fullFee; -monitoring = rval.monitoring; } //----------------------------------------------------------------------------- SETTINGS::~SETTINGS() @@ -126,8 +127,6 @@ return -1; //----------------------------------------------------------------------------- int SETTINGS::ParseInt(const string & value, int * val) { -/*char *res; -*val = strtol(value.c_str(), &res, 10);*/ if (str2x(value, *val)) { strError = "Cannot convert \'" + value + "\' to integer."; @@ -136,6 +135,16 @@ if (str2x(value, *val)) return 0; } //----------------------------------------------------------------------------- +int SETTINGS::ParseUnsigned(const string & value, unsigned * val) +{ +if (str2x(value, *val)) + { + strError = "Cannot convert \'" + value + "\' to unsigned integer."; + return -1; + } +return 0; +} +//----------------------------------------------------------------------------- int SETTINGS::ParseIntInRange(const string & value, int min, int max, int * val) { if (ParseInt(value, val) != 0) @@ -147,13 +156,25 @@ if (*val < min || *val > max) return -1; } +return 0; +} +//----------------------------------------------------------------------------- +int SETTINGS::ParseUnsignedInRange(const string & value, unsigned min, unsigned max, unsigned * val) +{ +if (ParseUnsigned(value, val) != 0) + return -1; + +if (*val < min || *val > max) + { + strError = "Value \'" + value + "\' out of range."; + return -1; + } + return 0; } //----------------------------------------------------------------------------- int SETTINGS::ParseModuleSettings(const DOTCONFDocumentNode * node, vector * params) { -/*if (!node) - return 0;*/ const DOTCONFDocumentNode * childNode; PARAM_VALUE pv; const char * value; @@ -179,34 +200,18 @@ while (childNode) { pv.param = childNode->getName(); int i = 0; - while ((value = childNode->getValue(i)) != NULL) + while ((value = childNode->getValue(i++)) != NULL) { - //printfd(__FILE__, "--> param=\'%s\' value=\'%s\'\n", childNode->getName(), value); pv.value.push_back(value); - i++; } params->push_back(pv); pv.value.clear(); childNode = childNode->getNextNode(); } -/*for (unsigned i = 0; i < params->size(); i++) - { - printfd(__FILE__, "param \'%s\'\n", (*params)[i].param.c_str()); - for (unsigned j = 0; j < (*params)[i].value.size(); j++) - { - printfd(__FILE__, "value \'%s\'\n", (*params)[i].value[j].c_str()); - } - }*/ - return 0; } //----------------------------------------------------------------------------- -string SETTINGS::GetStrError() const -{ -return strError; -} -//----------------------------------------------------------------------------- void SETTINGS::ErrorCallback(void * data, const char * buf) { printfd(__FILE__, buf); @@ -293,7 +298,7 @@ while (node) if (strcasecmp(node->getName(), "StatWritePeriod") == 0) { - if (ParseIntInRange(node->getValue(0), 1, 1440, &statWritePeriod) != 0) + if (ParseUnsignedInRange(node->getValue(0), 1, 1440, &statWritePeriod) != 0) { strError = "Incorrect StatWritePeriod value: \'" + string(node->getValue(0)) + "\'"; return -1; @@ -312,7 +317,7 @@ while (node) if (strcasecmp(node->getName(), "ExecutersNum") == 0) { - if (ParseIntInRange(node->getValue(0), 1, 1024, &executersNum) != 0) + if (ParseUnsignedInRange(node->getValue(0), 1, 1024, &executersNum) != 0) { strError = "Incorrect ExecutersNum value: \'" + string(node->getValue(0)) + "\'"; return -1; @@ -320,19 +325,9 @@ while (node) //printfd(__FILE__, "DayResetTraff: %d\n", dayResetTraff); } - /*if (strcasecmp(node->getName(), "ExecutersWaitTimeout") == 0) - { - if (ParseIntInRange(node->getValue(0), 1, 600, &executersWaitTimeout) != 0) - { - strError = "Incorrect ExecutersWaitTimeout value: \'" + string(node->getValue(0)) + "\'"; - return -1; - } - //printfd(__FILE__, "DayResetTraff: %d\n", dayResetTraff); - }*/ - if (strcasecmp(node->getName(), "DayFee") == 0) { - if (ParseIntInRange(node->getValue(0), 0, 31, &dayFee) != 0) + if (ParseUnsignedInRange(node->getValue(0), 0, 31, &dayFee) != 0) { strError = "Incorrect DayFee value: \'" + string(node->getValue(0)) + "\'"; return -1; @@ -352,7 +347,7 @@ while (node) if (strcasecmp(node->getName(), "DayResetTraff") == 0) { - if (ParseIntInRange(node->getValue(0), 0, 31, &dayResetTraff) != 0) + if (ParseUnsignedInRange(node->getValue(0), 0, 31, &dayResetTraff) != 0) { strError = "Incorrect DayResetTraff value: \'" + string(node->getValue(0)) + "\'"; return -1; @@ -422,6 +417,16 @@ while (node) } } + if (strcasecmp(node->getName(), "MessageTimeout") == 0) + { + if (ParseUnsigned(node->getValue(0), &messageTimeout) != 0) + { + strError = "Incorrect MessageTimeout value: \'" + string(node->getValue(0)) + "\'"; + return -1; + } + //printfd(__FILE__, "MessageTimeout: %d\n", messageTimeout); + } + if (strcasecmp(node->getName(), "DirNames") == 0) { // íÙ ×ÎÕÔÒÉ ÓÅËÃÉÉ DirNames @@ -437,7 +442,6 @@ while (node) if (dirNameNode && dirNameNode->getValue(0)) { dirName[i] = dirNameNode->getValue(0); - //printfd(__FILE__, "dirName[%d]: %s\n", i, dirName[i].c_str()); } } } @@ -463,8 +467,6 @@ while (node) } storeModulesCount++; - //storeModuleSettings.clear(); //TODO To make constructor - //printfd(__FILE__, "StoreModule %s\n", node->getValue()); storeModuleSettings.moduleName = node->getValue(0); ParseModuleSettings(node, &storeModuleSettings.moduleParams); } @@ -483,7 +485,6 @@ while (node) while (child) { // íÙ ×ÎÕÔÒÉ ÓÅËÃÉÉ - //printfd(__FILE__, "Module \'%s\'\n", child->getValue(0)); if (strcasecmp(child->getName(), "Module") != 0) { child = child->getNextNode(); @@ -504,9 +505,6 @@ while (node) node = node->getNextNode(); } -//sort(modulesSettings.begin(), modulesSettings.end()); -//modulesSettings.erase(unique(modulesSettings.begin(), modulesSettings.end()), modulesSettings.end()); - return 0; } //----------------------------------------------------------------------------- @@ -536,23 +534,3 @@ else if (detailStatPeriodStr == "1/6") return -1; } //----------------------------------------------------------------------------- -int SETTINGS::Reload () -{ -return ReadSettings(); -} -//----------------------------------------------------------------------------- -const MODULE_SETTINGS & SETTINGS::GetStoreModuleSettings() const -{ -return storeModuleSettings; -} -//----------------------------------------------------------------------------- -const vector & SETTINGS::GetModulesSettings() const -{ -return modulesSettings; -} -//----------------------------------------------------------------------------- -/*int SETTINGS::GetExecutersWaitTimeout() const -{ -return executersWaitTimeout; -}*/ -//----------------------------------------------------------------------------- diff --git a/projects/stargazer/settings.h b/projects/stargazer/settings.h index a9256cc9..03ace0a0 100644 --- a/projects/stargazer/settings.h +++ b/projects/stargazer/settings.h @@ -34,16 +34,13 @@ */ -#ifndef settingsh_h -#define settingsh_h 1 +#ifndef SETTINGS_H +#define SETTINGS_H -#include #include -#include #include "common.h" #include "base_settings.h" -#include "stg_logger.h" using namespace std; @@ -56,6 +53,9 @@ dsPeriod_1_4, dsPeriod_1_6, }; //----------------------------------------------------------------------------- +class STG_LOGGER; +class DOTCONFDocumentNode; +//----------------------------------------------------------------------------- class SETTINGS { public: @@ -63,26 +63,25 @@ public: SETTINGS(const std::string &); SETTINGS(const SETTINGS &); virtual ~SETTINGS(); - int Reload(); + int Reload() { return ReadSettings(); }; int ReadSettings(); - string GetStrError() const; + string GetStrError() const { return strError; }; int GetExecMsgKey() const { return stgExecMsgKey; }; - int GetExecutersNum() const { return executersNum; }; - //int GetExecutersWaitTimeout() const; + size_t GetExecutersNum() const { return executersNum; }; const string & GetDirName(int num) const { return dirName[num]; }; const string & GetConfDir() const { return confDir; }; const string & GetScriptDir() const { return scriptDir; }; const string & GetRulesFileName() const { return rules; }; const string & GetLogFileName() const { return logFile; }; const string & GetPIDFileName() const { return pidFile; }; - int GetDetailStatWritePeriod() const + unsigned GetDetailStatWritePeriod() const { return detailStatWritePeriod; }; - int GetStatWritePeriod() const { return statWritePeriod * 60; }; - int GetDayFee() const { return dayFee; }; + unsigned GetStatWritePeriod() const { return statWritePeriod * 60; }; + unsigned GetDayFee() const { return dayFee; }; bool GetFullFee() const { return fullFee; }; - int GetDayResetTraff() const { return dayResetTraff; }; + unsigned GetDayResetTraff() const { return dayResetTraff; }; bool GetSpreadFee() const { return spreadFee; }; bool GetFreeMbAllowInet() const { return freeMbAllowInet; }; bool GetDayFeeIsLastDay() const { return dayFeeIsLastDay; }; @@ -91,15 +90,20 @@ public: bool GetShowFeeInCash() const { return showFeeInCash; }; const string & GetMonitorDir() const { return monitorDir; }; bool GetMonitoring() const { return monitoring; }; + unsigned GetMessageTimeout() const { return messageTimeout * 3600 * 24; }; const string & GetModulesPath() const { return modulesPath; }; - const MODULE_SETTINGS & GetStoreModuleSettings() const; - const vector & GetModulesSettings() const; + const MODULE_SETTINGS & GetStoreModuleSettings() const + { return storeModuleSettings; }; + const vector & GetModulesSettings() const + { return modulesSettings; }; private: int ParseInt(const string & value, int * val); + int ParseUnsigned(const string & value, unsigned * val); int ParseIntInRange(const string & value, int min, int max, int * val); + int ParseUnsignedInRange(const string & value, unsigned min, unsigned max, unsigned * val); int ParseYesNo(const string & value, bool * val); int ParseDetailStatWritePeriod(const string & detailStatPeriodStr); @@ -118,19 +122,19 @@ private: string pidFile; string monitorDir; bool monitoring; - int detailStatWritePeriod; - int statWritePeriod; + unsigned detailStatWritePeriod; + unsigned statWritePeriod; int stgExecMsgKey; - int executersNum; - //int executersWaitTimeout; + size_t executersNum; bool fullFee; - int dayFee; // ÄÅÎØ ÓÎÑÔÉÑ ÁÂÏÎÐÌÁÔÙ - int dayResetTraff; // îÁÞÁÌÏ ÕÞÅÔÎÏÇÏ ÐÅÒÉÏÄÁ: ÄÅÎØ ÏÂÎÕÌÅÎÉÑ ÔÒÁÆÉËÁ É ÓÍÅÎÙ ÔÁÒÉÆÁ + unsigned dayFee; // ÄÅÎØ ÓÎÑÔÉÑ ÁÂÏÎÐÌÁÔÙ + unsigned dayResetTraff; // îÁÞÁÌÏ ÕÞÅÔÎÏÇÏ ÐÅÒÉÏÄÁ: ÄÅÎØ ÏÂÎÕÌÅÎÉÑ ÔÒÁÆÉËÁ É ÓÍÅÎÙ ÔÁÒÉÆÁ bool spreadFee; bool freeMbAllowInet; bool dayFeeIsLastDay; // áð ÓÎÉÍÁÅÔÓÑ × ËÏÎÃÅ ÍÅÓÑÃÁ (true) ÉÌÉ × ÎÁÞÁÌÅ (false) bool writeFreeMbTraffCost; // ðÉÓÁÔØ × ÄÅÔÁÌØÎÕÀ ÓÔÁÔÉÓÔÉËÕ ÓÔÏÉÍÏÓÔØ ÔÒÁÆÉËÁ, ÅÓÌÉ ÅÝÅ ÅÓÔØ ÐÒÅÄÏÐÌÁÞÅÎÎÙÊ ÔÒÁÆÉË bool showFeeInCash; // ðÏËÁÚÙ×ÁÔØ ÐÏÌØÚÏ×ÁÔÅÌÀ áð ÎÅ ÓÞÅÔÕ É ÐÏÚ×ÏÌÑÔØ ÅÅ ÉÓÐÏÌØÚÏ×ÁÔØ + unsigned messageTimeout; // ÷ÒÅÍÑ ÖÉÚÎÉ ÎÅÏÔÐÒÁ×ÌÅÎÎÏÇÏ ÓÏÏÂÝÅÎÉÑ × ÓÅËÕÎÄÁÈ vector modulesSettings; MODULE_SETTINGS storeModuleSettings; @@ -139,4 +143,3 @@ private: }; //----------------------------------------------------------------------------- #endif - diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user.cpp index 3d9371fd..267967d0 100644 --- a/projects/stargazer/user.cpp +++ b/projects/stargazer/user.cpp @@ -605,7 +605,7 @@ void USER::Run() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -if (stgTime - lastWriteStat > settings->GetStatWritePeriod()) +if (stgTime > static_cast(lastWriteStat + settings->GetStatWritePeriod())) { printfd(__FILE__, "USER::WriteStat user=%s\n", GetLogin().c_str()); WriteStat(); @@ -1256,11 +1256,26 @@ for (unsigned i = 0; i < hdrsList.size(); i++) std::list::iterator it(messages.begin()); while (it != messages.end()) { + printfd(__FILE__, "Message timeout: %d, delta: %f\n", settings->GetMessageTimeout(), difftime(stgTime, it->header.creationTime)); + if (settings->GetMessageTimeout() > 0 && + difftime(stgTime, it->header.creationTime) > settings->GetMessageTimeout()) + { + // Timeout exceeded + if (store->DelMessage(it->header.id, login)) + { + WriteServLog("Error deleting message: '%s'", store->GetStrError().c_str()); + printfd(__FILE__, "Error deleting message: '%s'\n", store->GetStrError().c_str()); + } + messages.erase(it++); + continue; + } if (static_cast(it->header.lastSendTime + it->header.repeatPeriod * 60) < stgTime) { if (SendMessage(*it)) { - return -1; + // We need to check all messages in queue for timeout + ++it; + continue; } it->header.repeat--; if (it->header.repeat < 0) -- 2.44.2 From ba88b015b893b3a1ba917a8f8dd6353cdfb60e9c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 27 Jan 2011 12:15:29 +0200 Subject: [PATCH 15/16] =?utf8?q?=D0=92=D0=B8=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=BE=20=D0=BF=D1=83=D1=81=D1=82=D0=B8=D0=B9=20=D1=80=D1=8F?= =?utf8?q?=D0=B4=D0=BE=D0=BA=20=D1=83=20=D0=BA=D1=96=D0=BD=D1=86=D1=96=20?= =?utf8?q?=D1=84=D0=B0=D0=B9=D0=BB=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/rscriptd/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/rscriptd/main.cpp b/projects/rscriptd/main.cpp index e633f9ad..7dc16564 100644 --- a/projects/rscriptd/main.cpp +++ b/projects/rscriptd/main.cpp @@ -437,4 +437,3 @@ delete cfg; return EXIT_SUCCESS; } //----------------------------------------------------------------------------- - -- 2.44.2 From cae8a878811382886af21000064ff659309f7e4c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 27 Jan 2011 12:16:20 +0200 Subject: [PATCH 16/16] =?utf8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=96=D0=BC=D0=B5?= =?utf8?q?=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=BF=D0=B0=D1=80=D1=83?= =?utf8?q?=20=D0=B7=D0=BC=D1=96=D0=BD=D0=BD=D0=B8=D1=85=20=D0=B4=D0=BB?= =?utf8?q?=D1=8F=20=D0=B7=D0=B1=D0=B5=D1=80=D0=B5=D0=B6=D0=B5=D0=BD=D0=BD?= =?utf8?q?=D1=8F=20=D1=81=D0=B5=D0=BC=D0=B0=D0=BD=D1=82=D0=B8=D0=BA=D0=B8,?= =?utf8?q?=20=D0=B2=D0=B8=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE?= =?utf8?q?=20=D1=80=D0=BE=D0=B7=D0=BC=D1=96=D1=80=20=D0=BE=D0=B4=D0=BD?= =?utf8?q?=D0=BE=D0=B3=D0=BE=20=D1=96=D0=B7=20=D0=B1=D1=83=D1=84=D0=B5?= =?utf8?q?=D1=80=D1=96=D0=B2=20iov=20=D0=BF=D1=80=D0=B8=20=D1=87=D0=B8?= =?utf8?q?=D1=82=D0=B0=D0=BD=D0=BD=D1=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/rscriptd/listener.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index aca5da44..82dd6318 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -162,9 +162,9 @@ return false; //----------------------------------------------------------------------------- void * LISTENER::Run(void * d) { -LISTENER * ia = static_cast(d); +LISTENER * listener = static_cast(d); -ia->Runner(); +listener->Runner(); return NULL; } @@ -183,9 +183,9 @@ receiverStopped = true; //----------------------------------------------------------------------------- void * LISTENER::RunProcessor(void * d) { -LISTENER * ia = static_cast(d); +LISTENER * listener = static_cast(d); -ia->ProcessorRunner(); +listener->ProcessorRunner(); return NULL; } @@ -215,8 +215,6 @@ if (listenSocket < 0) return true; } -printfd(__FILE__, "Port: %d\n", port); - struct sockaddr_in listenAddr; listenAddr.sin_family = AF_INET; listenAddr.sin_port = htons(port); @@ -250,7 +248,7 @@ RS_PACKET_HEADER packetHead; iov[0].iov_base = reinterpret_cast(&packetHead); iov[0].iov_len = sizeof(packetHead); iov[1].iov_base = buffer; -iov[1].iov_len = sizeof(buffer); +iov[1].iov_len = sizeof(buffer) - sizeof(packetHead); size_t dataLen = 0; while (dataLen < sizeof(buffer)) @@ -321,7 +319,7 @@ if (strncmp((char *)packetTail.magic, RS_ID, RS_MAGIC_LEN)) } std::stringstream params; -params << data.login << " " +params << "\"" << data.login << "\" " << inet_ntostring(data.ip) << " " << data.id << " " << (char *)packetTail.params; -- 2.44.2