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
This commit is contained in:
guy 2010-02-16 16:33:08 +00:00
parent a7c4e187c1
commit 6a0d7b3256
5 changed files with 78 additions and 50 deletions

View File

@ -161,7 +161,7 @@ private:
protected: protected:
virtual const wxChar* GetAppName() const; 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; void AddNumber(TXmlItem& tr, int n) const;
wxString DescribeModule(int m) const; wxString DescribeModule(int m) const;
@ -182,8 +182,8 @@ public:
void ProcessFormCommand(wxString cmd, wxSocketBase& outs); void ProcessFormCommand(wxString cmd, wxSocketBase& outs);
void ProcessActivation(int nModuble, bool act, wxSocketBase& outs); void ProcessActivation(int nModuble, bool act, wxSocketBase& outs);
void ReturnInt(wxSocketBase& outs, unsigned int i); bool ReturnInt(wxSocketBase& outs, unsigned int i);
void ReturnBool(wxSocketBase&, bool b); bool ReturnBool(wxSocketBase&, bool b);
unsigned int DecodePassword(const wxChar* strPassword, const wxChar* strApp); unsigned int DecodePassword(const wxChar* strPassword, const wxChar* strApp);
void ProcessUserLogin(wxString cmd, wxSocketBase& sock); void ProcessUserLogin(wxString cmd, wxSocketBase& sock);
@ -851,35 +851,37 @@ void TAuthorizationServer::ProcessUserLogin(wxString cmd, wxSocketBase& sock)
bool TAuthorizationServer::ProcessUserLogout(wxString cmd, wxSocketBase& sock) bool TAuthorizationServer::ProcessUserLogout(wxString cmd, wxSocketBase& sock)
{ {
wxChar strUser[32]; wxChar strUser[32] = "";
wxChar strProgram[32]; wxChar strProgram[32] = "";
int session; int session = -1;
cmd.Replace(",", " "); cmd.Replace(")", " "); 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) if (nStr < 2)
session = 0; session = 0;
m_Users.RemoveConnection(sock, strUser, session); m_Users.RemoveConnection(sock, strUser, session);
if (strcmp(strProgram, "ba0100") == 0) if (wxStrcmp(strProgram, "ba0100") == 0)
m_Users.KillSession(sock, session); m_Users.KillSession(sock, session);
return true; 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 }; const unsigned int buf[2] = { sizeof(i), i };
outs.Write(buf, sizeof(buf)); 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); 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 ")) if (cmd.StartsWith("GET "))
{ {
@ -897,38 +899,55 @@ void TAuthorizationServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
GenerateFile(strFilename); GenerateFile(strFilename);
SendFile(strFilename, outs); SendFile(strFilename, outs);
} else return true;
if (cmd.StartsWith("POST ")) }
if (cmd.StartsWith("POST "))
{ {
ProcessFormCommand(cmd, outs); ProcessFormCommand(cmd, outs);
} else return true;
if (cmd.StartsWith("UserLogin")) }
if (cmd.StartsWith("UserLogin"))
{ {
ProcessUserLogin(cmd, outs); ProcessUserLogin(cmd, outs);
} else return true;
if (cmd.StartsWith("UserLogout")) }
if (cmd.StartsWith("UserLogout"))
{ {
bool ok = ProcessUserLogout(cmd, outs); bool ok = ProcessUserLogout(cmd, outs);
ReturnBool(outs, ok); return ReturnBool(outs, ok);
} else }
if (cmd.StartsWith("DongleNumber"))
{ if (cmd.StartsWith("DongleInfo"))
ReturnInt(outs, m_Dongle.Number()); {
} else const short num = m_Dongle.Number();
if (cmd.StartsWith("DongleYear")) const short year = m_Dongle.YearAssist();
{ const size_t nBytes = sizeof(num) + sizeof(year) + sizeof(m_Modules);
ReturnInt(outs, m_Dongle.YearAssist()); outs.Write(&nBytes, sizeof(nBytes)); // 4 bytes = size of data
} else outs.Write(&num, sizeof(num)); // 2 bytes = dongle number
if (cmd.StartsWith("DongleModules")) 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)); outs.Write(m_Modules, sizeof(m_Modules));
} else return outs.IsOk();
if (cmd.StartsWith("DongleLoggedLicenses")) }
{
ReturnInt(outs, m_Users.GetLicenses()); if (cmd.StartsWith("DongleNumber"))
} return ReturnInt(outs, m_Dongle.Number());
else
TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING! if (cmd.StartsWith("DongleYear"))
return ReturnInt(outs, m_Dongle.YearAssist());
return TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING!
} }
#define ATOMIC_SEMAPHORE "DONGLE_SERVER_ATOM" #define ATOMIC_SEMAPHORE "DONGLE_SERVER_ATOM"

View File

@ -444,8 +444,9 @@ const wxChar* TBaseServerApp::GetAppName() const
return "Server"; 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.StartsWith("POST "))
{ {
if (cmd.Find("SOAPAction") > 0) if (cmd.Find("SOAPAction") > 0)
@ -457,6 +458,9 @@ void TBaseServerApp::ProcessCommand(wxString cmd, wxSocketBase& outs)
ProcessHttpGet(cmd, outs); else ProcessHttpGet(cmd, outs); else
if (cmd.StartsWith("PING")) if (cmd.StartsWith("PING"))
outs << "PONG\n"; outs << "PONG\n";
else
bProcessed = false;
return bProcessed;
} }
void TBaseServerApp::OnServerEvent(wxSocketEvent& e) void TBaseServerApp::OnServerEvent(wxSocketEvent& e)
@ -526,7 +530,7 @@ void TBaseServerApp::OnSocketEvent(wxSocketEvent& e)
case wxSOCKET_LOST: case wxSOCKET_LOST:
if (m_bLogVerbose) if (m_bLogVerbose)
WriteLog("--- Socket lost."); WriteLog("--- Socket lost.");
if (IsAdvanced()) if (IsAdvanced() || wxDateTime::Now().GetDay() > 15)
sock->Destroy(); sock->Destroy();
break; break;
default: default:
@ -574,13 +578,13 @@ void TBaseServerApp::OnIdle(wxIdleEvent& evt)
const wxString& TBaseServerApp::GetConfigName() const const wxString& TBaseServerApp::GetConfigName() const
{ {
if (m_strIni.IsEmpty()) if (m_strIni.IsEmpty())
{ {
wxFileName name(argv[0]); // Prendo il persorso completo del server in esecuzione wxFileName name(argv[0]); // Prendo il persorso completo del server in esecuzione
name.SetName("servers"); // Trasformo il nome in servers ... name.SetName("servers"); // Trasformo il nome in servers ...
name.SetExt("ini"); // ... e l'esetensione in .ini name.SetExt("ini"); // ... e l'esetensione in .ini
name.MakeAbsolute(); name.MakeAbsolute();
(wxString&)m_strIni = name.GetFullPath(); (wxString&)m_strIni = name.GetFullPath();
} }
return m_strIni; return m_strIni;
} }
@ -636,7 +640,7 @@ bool TBaseServerApp::GetConfigBool(const wxChar* key, bool def, const wxChar* ap
bool val = def; bool val = def;
const wxString str = GetConfigString(key, "*", app); const wxString str = GetConfigString(key, "*", app);
if (str != "*") 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; return val;
} }
@ -688,6 +692,9 @@ wxString TBaseServerApp::GetOemString(const wxChar* key, const wxChar* def) cons
return str; return str;
} }
bool TBaseServerApp::IsAdvanced() const
{ return GetOemInt(wxT("OEM"), -1) != 2; }
wxString TBaseServerApp::GetLogFileName() const wxString TBaseServerApp::GetLogFileName() const
{ return GetConfigString("LogFile"); } { return GetConfigString("LogFile"); }

View File

@ -96,7 +96,7 @@ private:
protected: protected:
wxSingleInstanceChecker* m_SingleInstance; 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 bool CanProcessCommand(wxString& cmd, wxSocketBase& outs);
virtual const wxString& GetServerPath() const { return m_strPath; } virtual const wxString& GetServerPath() const { return m_strPath; }
@ -115,7 +115,7 @@ protected:
wxString GetOemString(const wxChar* key, const wxChar* def = wxEmptyString) const; wxString GetOemString(const wxChar* key, const wxChar* def = wxEmptyString) const;
int GetOemInt(const wxChar* key, int def = 0) const; int GetOemInt(const wxChar* key, int def = 0) const;
bool IsAdvanced() const { return GetOemInt(wxT("OEM"), -1) == 0; } bool IsAdvanced() const;
public: public:
// Utilities // Utilities

View File

@ -4,7 +4,7 @@ class TCoffeeServer : public TBaseServerApp
{ {
protected: protected:
virtual const wxChar* GetAppName() const; virtual const wxChar* GetAppName() const;
virtual void ProcessCommand(wxString cmd, wxSocketBase& outs); virtual bool ProcessCommand(wxString cmd, wxSocketBase& outs);
public: public:
bool IsMagicName(wxString& strFilename) const; 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 ")) if (cmd.StartsWith("GET "))
{ {
@ -118,10 +118,9 @@ void TCoffeeServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
GenerateFile(strFilename); GenerateFile(strFilename);
SendFile(strFilename, outs); SendFile(strFilename, outs);
return true;
} }
else return TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING!
TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING!
} }
// Istanziare l'applicazione principale // Istanziare l'applicazione principale

View File

@ -592,7 +592,7 @@ class TDataBaseServer : public TBaseServerApp
protected: protected:
virtual const wxChar* GetAppName() const; virtual const wxChar* GetAppName() const;
virtual void ProcessCommand(wxString cmd, wxSocketBase& outs); virtual bool ProcessCommand(wxString cmd, wxSocketBase& outs);
virtual bool Initialization(); virtual bool Initialization();
virtual bool Deinitialization(); virtual bool Deinitialization();
@ -1086,7 +1086,7 @@ void TDataBaseServer::ProcessSoapCommand(wxString cmd, wxSocketBase& sock)
delete mem; delete mem;
} }
void TDataBaseServer::ProcessCommand(wxString cmd, wxSocketBase& outs) bool TDataBaseServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
{ {
if (cmd.StartsWith("GET ")) if (cmd.StartsWith("GET "))
{ {
@ -1117,14 +1117,17 @@ void TDataBaseServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
} }
} }
SendFile(strFilename, outs); SendFile(strFilename, outs);
} else return true;
}
if (cmd.StartsWith("POST ")) if (cmd.StartsWith("POST "))
{ {
if (cmd.Find("SOAPAction") > 0) if (cmd.Find("SOAPAction") > 0)
ProcessSoapCommand(cmd, outs); ProcessSoapCommand(cmd, outs);
else else
ProcessFormCommand(cmd, outs); ProcessFormCommand(cmd, outs);
return true;
} }
return TBaseServerApp::ProcessCommand(cmd, outs);
} }
bool TDataBaseServer::Initialization() bool TDataBaseServer::Initialization()