From 6a0d7b32568e012570b8a7b151cdf1c8deba5c00 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 16 Feb 2010 16:33:08 +0000 Subject: [PATCH] Patch level : 10.0 Files correlati : lurch.exe authoriz.exe Ricompilazione Demo : [ ] Commento : Aggiunto comando DongleInfo che riassume in se DongleNumber+DongleYear+DongleModules in modo da ridurre il traffico di rete col server git-svn-id: svn://10.65.10.50/trunk@20132 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- server/authoriz.cpp | 89 +++++++++++++++++++++++++++------------------ server/baseserv.cpp | 17 ++++++--- server/baseserv.h | 4 +- server/coffee.cpp | 9 ++--- server/dbserver.cpp | 9 +++-- 5 files changed, 78 insertions(+), 50 deletions(-) diff --git a/server/authoriz.cpp b/server/authoriz.cpp index 0a5819f15..361f246b6 100755 --- a/server/authoriz.cpp +++ b/server/authoriz.cpp @@ -161,7 +161,7 @@ private: protected: virtual const wxChar* GetAppName() const; - virtual void ProcessCommand(wxString cmd, wxSocketBase& outs); + virtual bool ProcessCommand(wxString cmd, wxSocketBase& outs); void AddNumber(TXmlItem& tr, int n) const; wxString DescribeModule(int m) const; @@ -182,8 +182,8 @@ public: void ProcessFormCommand(wxString cmd, wxSocketBase& outs); void ProcessActivation(int nModuble, bool act, wxSocketBase& outs); - void ReturnInt(wxSocketBase& outs, unsigned int i); - void ReturnBool(wxSocketBase&, bool b); + bool ReturnInt(wxSocketBase& outs, unsigned int i); + bool ReturnBool(wxSocketBase&, bool b); unsigned int DecodePassword(const wxChar* strPassword, const wxChar* strApp); void ProcessUserLogin(wxString cmd, wxSocketBase& sock); @@ -851,35 +851,37 @@ void TAuthorizationServer::ProcessUserLogin(wxString cmd, wxSocketBase& sock) bool TAuthorizationServer::ProcessUserLogout(wxString cmd, wxSocketBase& sock) { - wxChar strUser[32]; - wxChar strProgram[32]; - int session; + wxChar strUser[32] = ""; + wxChar strProgram[32] = ""; + int session = -1; cmd.Replace(",", " "); cmd.Replace(")", " "); - const int nStr = sscanf(cmd, "UserLogout(%s %d %s)", strUser, &session, strProgram); + const int nStr = wxSscanf(cmd, "UserLogout(%s %d %s)", strUser, &session, strProgram); if (nStr < 2) session = 0; m_Users.RemoveConnection(sock, strUser, session); - if (strcmp(strProgram, "ba0100") == 0) + if (wxStrcmp(strProgram, "ba0100") == 0) m_Users.KillSession(sock, session); return true; } -void TAuthorizationServer::ReturnInt(wxSocketBase& outs, unsigned int i) +bool TAuthorizationServer::ReturnInt(wxSocketBase& outs, unsigned int i) { const unsigned int buf[2] = { sizeof(i), i }; outs.Write(buf, sizeof(buf)); + return outs.IsOk(); } -void TAuthorizationServer::ReturnBool(wxSocketBase& outs, bool b) +bool TAuthorizationServer::ReturnBool(wxSocketBase& outs, bool b) { ReturnInt(outs, b ? 1 : 0); + return outs.IsOk(); } -void TAuthorizationServer::ProcessCommand(wxString cmd, wxSocketBase& outs) +bool TAuthorizationServer::ProcessCommand(wxString cmd, wxSocketBase& outs) { if (cmd.StartsWith("GET ")) { @@ -897,38 +899,55 @@ void TAuthorizationServer::ProcessCommand(wxString cmd, wxSocketBase& outs) GenerateFile(strFilename); SendFile(strFilename, outs); - } else - if (cmd.StartsWith("POST ")) + return true; + } + + if (cmd.StartsWith("POST ")) { ProcessFormCommand(cmd, outs); - } else - if (cmd.StartsWith("UserLogin")) + return true; + } + + if (cmd.StartsWith("UserLogin")) { ProcessUserLogin(cmd, outs); - } else - if (cmd.StartsWith("UserLogout")) + return true; + } + + if (cmd.StartsWith("UserLogout")) { bool ok = ProcessUserLogout(cmd, outs); - ReturnBool(outs, ok); - } else - if (cmd.StartsWith("DongleNumber")) - { - ReturnInt(outs, m_Dongle.Number()); - } else - if (cmd.StartsWith("DongleYear")) - { - ReturnInt(outs, m_Dongle.YearAssist()); - } else - if (cmd.StartsWith("DongleModules")) + return ReturnBool(outs, ok); + } + + if (cmd.StartsWith("DongleInfo")) + { + const short num = m_Dongle.Number(); + const short year = m_Dongle.YearAssist(); + const size_t nBytes = sizeof(num) + sizeof(year) + sizeof(m_Modules); + outs.Write(&nBytes, sizeof(nBytes)); // 4 bytes = size of data + outs.Write(&num, sizeof(num)); // 2 bytes = dongle number + outs.Write(&year, sizeof(year)); // 2 bytes = dongle year + outs.Write(&m_Modules,sizeof(m_Modules)); // 12 bytes = active modules bits + return outs.IsOk(); + } + + if (cmd.StartsWith("DongleLoggedLicenses")) + return ReturnInt(outs, m_Users.GetLicenses()); + + if (cmd.StartsWith("DongleModules")) { outs.Write(m_Modules, sizeof(m_Modules)); - } else - if (cmd.StartsWith("DongleLoggedLicenses")) - { - ReturnInt(outs, m_Users.GetLicenses()); - } - else - TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING! + return outs.IsOk(); + } + + if (cmd.StartsWith("DongleNumber")) + return ReturnInt(outs, m_Dongle.Number()); + + if (cmd.StartsWith("DongleYear")) + return ReturnInt(outs, m_Dongle.YearAssist()); + + return TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING! } #define ATOMIC_SEMAPHORE "DONGLE_SERVER_ATOM" diff --git a/server/baseserv.cpp b/server/baseserv.cpp index d2b8b6382..785d6d549 100755 --- a/server/baseserv.cpp +++ b/server/baseserv.cpp @@ -444,8 +444,9 @@ const wxChar* TBaseServerApp::GetAppName() const return "Server"; } -void TBaseServerApp::ProcessCommand(wxString cmd, wxSocketBase& outs) +bool TBaseServerApp::ProcessCommand(wxString cmd, wxSocketBase& outs) { + bool bProcessed = true; if (cmd.StartsWith("POST ")) { if (cmd.Find("SOAPAction") > 0) @@ -457,6 +458,9 @@ void TBaseServerApp::ProcessCommand(wxString cmd, wxSocketBase& outs) ProcessHttpGet(cmd, outs); else if (cmd.StartsWith("PING")) outs << "PONG\n"; + else + bProcessed = false; + return bProcessed; } void TBaseServerApp::OnServerEvent(wxSocketEvent& e) @@ -526,7 +530,7 @@ void TBaseServerApp::OnSocketEvent(wxSocketEvent& e) case wxSOCKET_LOST: if (m_bLogVerbose) WriteLog("--- Socket lost."); - if (IsAdvanced()) + if (IsAdvanced() || wxDateTime::Now().GetDay() > 15) sock->Destroy(); break; default: @@ -574,13 +578,13 @@ void TBaseServerApp::OnIdle(wxIdleEvent& evt) const wxString& TBaseServerApp::GetConfigName() const { if (m_strIni.IsEmpty()) - { + { wxFileName name(argv[0]); // Prendo il persorso completo del server in esecuzione name.SetName("servers"); // Trasformo il nome in servers ... name.SetExt("ini"); // ... e l'esetensione in .ini name.MakeAbsolute(); (wxString&)m_strIni = name.GetFullPath(); - } + } return m_strIni; } @@ -636,7 +640,7 @@ bool TBaseServerApp::GetConfigBool(const wxChar* key, bool def, const wxChar* ap bool val = def; const wxString str = GetConfigString(key, "*", app); if (str != "*") - val = (str[0u] == '1') || (str[0u] == 'X') || (str[0u] == 'Y') || (str.CmpNoCase("On") == 0); + val = (str[0u] == '1') || (str[0u] == 'T') || (str[0u] == 'X') || (str[0u] == 'Y') || (str.CmpNoCase("On") == 0); return val; } @@ -688,6 +692,9 @@ wxString TBaseServerApp::GetOemString(const wxChar* key, const wxChar* def) cons return str; } +bool TBaseServerApp::IsAdvanced() const +{ return GetOemInt(wxT("OEM"), -1) != 2; } + wxString TBaseServerApp::GetLogFileName() const { return GetConfigString("LogFile"); } diff --git a/server/baseserv.h b/server/baseserv.h index 59c57c452..43eba0a99 100755 --- a/server/baseserv.h +++ b/server/baseserv.h @@ -96,7 +96,7 @@ private: protected: wxSingleInstanceChecker* m_SingleInstance; - virtual void ProcessCommand(wxString cmd, wxSocketBase& outs); + virtual bool ProcessCommand(wxString cmd, wxSocketBase& outs); virtual bool CanProcessCommand(wxString& cmd, wxSocketBase& outs); virtual const wxString& GetServerPath() const { return m_strPath; } @@ -115,7 +115,7 @@ protected: wxString GetOemString(const wxChar* key, const wxChar* def = wxEmptyString) const; int GetOemInt(const wxChar* key, int def = 0) const; - bool IsAdvanced() const { return GetOemInt(wxT("OEM"), -1) == 0; } + bool IsAdvanced() const; public: // Utilities diff --git a/server/coffee.cpp b/server/coffee.cpp index 6345278e2..5d00bef82 100755 --- a/server/coffee.cpp +++ b/server/coffee.cpp @@ -4,7 +4,7 @@ class TCoffeeServer : public TBaseServerApp { protected: virtual const wxChar* GetAppName() const; - virtual void ProcessCommand(wxString cmd, wxSocketBase& outs); + virtual bool ProcessCommand(wxString cmd, wxSocketBase& outs); public: bool IsMagicName(wxString& strFilename) const; @@ -104,7 +104,7 @@ void TCoffeeServer::GenerateFile(wxString& strFilename) } } -void TCoffeeServer::ProcessCommand(wxString cmd, wxSocketBase& outs) +bool TCoffeeServer::ProcessCommand(wxString cmd, wxSocketBase& outs) { if (cmd.StartsWith("GET ")) { @@ -118,10 +118,9 @@ void TCoffeeServer::ProcessCommand(wxString cmd, wxSocketBase& outs) GenerateFile(strFilename); SendFile(strFilename, outs); + return true; } - else - TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING! - + return TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING! } // Istanziare l'applicazione principale diff --git a/server/dbserver.cpp b/server/dbserver.cpp index 00eb231ae..c3df06fb2 100755 --- a/server/dbserver.cpp +++ b/server/dbserver.cpp @@ -592,7 +592,7 @@ class TDataBaseServer : public TBaseServerApp protected: virtual const wxChar* GetAppName() const; - virtual void ProcessCommand(wxString cmd, wxSocketBase& outs); + virtual bool ProcessCommand(wxString cmd, wxSocketBase& outs); virtual bool Initialization(); virtual bool Deinitialization(); @@ -1086,7 +1086,7 @@ void TDataBaseServer::ProcessSoapCommand(wxString cmd, wxSocketBase& sock) delete mem; } -void TDataBaseServer::ProcessCommand(wxString cmd, wxSocketBase& outs) +bool TDataBaseServer::ProcessCommand(wxString cmd, wxSocketBase& outs) { if (cmd.StartsWith("GET ")) { @@ -1117,14 +1117,17 @@ void TDataBaseServer::ProcessCommand(wxString cmd, wxSocketBase& outs) } } SendFile(strFilename, outs); - } else + return true; + } if (cmd.StartsWith("POST ")) { if (cmd.Find("SOAPAction") > 0) ProcessSoapCommand(cmd, outs); else ProcessFormCommand(cmd, outs); + return true; } + return TBaseServerApp::ProcessCommand(cmd, outs); } bool TDataBaseServer::Initialization()