X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..ba88b015b893b3a1ba917a8f8dd6353cdfb60e9c:/projects/rscriptd/listener.cpp diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index 87a85ebb..aca5da44 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,9 @@ #include "stg_locker.h" #include "common.h" +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); +void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); + //----------------------------------------------------------------------------- LISTENER::LISTENER() : WriteServLog(GetStgLogger()), @@ -52,7 +56,7 @@ version = "rscriptd listener v.1.2"; pthread_mutex_init(&mutex, NULL); } //----------------------------------------------------------------------------- -void LISTENER::SetPassword(const string & p) +void LISTENER::SetPassword(const std::string & p) { password = p; printfd(__FILE__, "Encryption initiated with password \'%s\'\n", password.c_str()); @@ -319,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(); @@ -329,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( @@ -371,9 +382,7 @@ while (it != pending.end()) users.erase(uit); } } - - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - pending.erase(it++); + ++it; } } //----------------------------------------------------------------------------- @@ -439,23 +448,6 @@ else return false; } //----------------------------------------------------------------------------- -void LISTENER::InitEncrypt(BLOWFISH_CTX * ctx, const string & password) -{ -unsigned char keyL[PASSWD_LEN]; -memset(keyL, 0, PASSWD_LEN); -strncpy((char *)keyL, password.c_str(), PASSWD_LEN); -Blowfish_Init(ctx, keyL, PASSWD_LEN); -} -//----------------------------------------------------------------------------- -void LISTENER::Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) -{ -if (dst != src) - memcpy(dst, src, len8 * 8); - -for (int i = 0; i < len8; i++) - Blowfish_Decrypt(ctx, (uint32_t *)(dst + i * 8), (uint32_t *)(dst + i * 8 + 4)); -} -//----------------------------------------------------------------------------- bool LISTENER::CheckHeader(const RS_PACKET_HEADER & header) const { if (strncmp((char *)header.magic, RS_ID, RS_MAGIC_LEN)) @@ -497,3 +489,22 @@ if (res == 0) // Timeout return true; } //----------------------------------------------------------------------------- +inline +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) +{ +unsigned char keyL[PASSWD_LEN]; +memset(keyL, 0, PASSWD_LEN); +strncpy((char *)keyL, password.c_str(), PASSWD_LEN); +Blowfish_Init(ctx, keyL, PASSWD_LEN); +} +//----------------------------------------------------------------------------- +inline +void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) +{ +if (dst != src) + memcpy(dst, src, len8 * 8); + +for (int i = 0; i < len8; i++) + Blowfish_Decrypt(ctx, (uint32_t *)(dst + i * 8), (uint32_t *)(dst + i * 8 + 4)); +} +//-----------------------------------------------------------------------------