Patch level : 10.0
Files correlati : authoriz lurch Ricompilazione Demo : [ ] Commento : Migliorata gestione socket non validi git-svn-id: svn://10.65.10.50/trunk@20484 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
225c9c7c06
commit
f1c5a81588
@ -6,11 +6,6 @@
|
|||||||
#include <wx/hashset.h>
|
#include <wx/hashset.h>
|
||||||
#include <wx/textfile.h>
|
#include <wx/textfile.h>
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// TUserInfo
|
// TUserInfo
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
@ -335,6 +330,12 @@ void TAuthorizationServer::GenerateIndex(wxString& strFilename)
|
|||||||
ay.SetAttr("href", "year.htm") << "Assistance Year";
|
ay.SetAttr("href", "year.htm") << "Assistance Year";
|
||||||
AddNumber(tr1, m_Dongle.YearAssist());
|
AddNumber(tr1, m_Dongle.YearAssist());
|
||||||
|
|
||||||
|
int y, v, t, p; GetVersionInfo(y, v, t, p);
|
||||||
|
wxString strVersion; strVersion.Printf(wxT("%d.%d.%d"), v, t, p);
|
||||||
|
TXmlItem& tr1a = body.AddChild("tr");
|
||||||
|
tr1a.AddChild("td") << "Version";
|
||||||
|
tr1a.AddChild("td").SetAttr("align", "right") << strVersion;
|
||||||
|
|
||||||
TXmlItem& tr2 = body.AddChild("tr");
|
TXmlItem& tr2 = body.AddChild("tr");
|
||||||
TXmlItem& mu = tr2.AddChild("td").AddChild("a");
|
TXmlItem& mu = tr2.AddChild("td").AddChild("a");
|
||||||
mu.SetAttr("href", "maxusers.htm") << "Maximum Users";
|
mu.SetAttr("href", "maxusers.htm") << "Maximum Users";
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <wx/mimetype.h>
|
#include <wx/mimetype.h>
|
||||||
#include <wx/mstream.h>
|
#include <wx/mstream.h>
|
||||||
#include <wx/sckstrm.h>
|
#include <wx/sckstrm.h>
|
||||||
|
#include <wx/tokenzr.h>
|
||||||
|
|
||||||
#ifndef __WXMSW__
|
#ifndef __WXMSW__
|
||||||
#include <wx/fileconf.h>
|
#include <wx/fileconf.h>
|
||||||
@ -33,15 +34,13 @@
|
|||||||
// Utilities
|
// Utilities
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
IMPLEMENT_ABSTRACT_CLASS(TBaseServerApp, wxApp)
|
||||||
|
|
||||||
TBaseServerApp& GetServerApp()
|
TBaseServerApp& GetServerApp()
|
||||||
{
|
{ return *wxStaticCast(wxTheApp, TBaseServerApp); }
|
||||||
return (TBaseServerApp&)*wxTheApp;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString Date2String(const wxDateTime& date)
|
wxString Date2String(const wxDateTime& date)
|
||||||
{
|
{ return date.Format("%d-%m-%Y"); }
|
||||||
return date.Format("%d-%m-%Y");
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDateTime String2Date(const wxString& str)
|
wxDateTime String2Date(const wxString& str)
|
||||||
{
|
{
|
||||||
@ -66,9 +65,7 @@ wxSocketBase& operator<<(wxSocketBase& outf, wxString str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxSocketBase& operator<<(wxSocketBase& outf, size_t num)
|
wxSocketBase& operator<<(wxSocketBase& outf, size_t num)
|
||||||
{
|
{ return outf << wxString::Format("%u", num); }
|
||||||
return outf << wxString::Format("%u", num);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// classes
|
// classes
|
||||||
@ -147,13 +144,15 @@ void TTaskBarIcon::Init()
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
SERVER_ID = 1001,
|
SERVER_ID = 1001,
|
||||||
SOCKET_ID = 1002
|
SOCKET_ID = 1002,
|
||||||
|
DATAGRAM_ID = 1003,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(TBaseServerApp, wxApp)
|
BEGIN_EVENT_TABLE(TBaseServerApp, wxApp)
|
||||||
EVT_SOCKET(SERVER_ID, TBaseServerApp::OnServerEvent)
|
EVT_SOCKET(SERVER_ID, TBaseServerApp::OnServerEvent)
|
||||||
EVT_SOCKET(SOCKET_ID, TBaseServerApp::OnSocketEvent)
|
EVT_SOCKET(SOCKET_ID, TBaseServerApp::OnSocketEvent)
|
||||||
|
EVT_SOCKET(DATAGRAM_ID, TBaseServerApp::OnDatagramEvent)
|
||||||
EVT_IDLE(TBaseServerApp::OnIdle)
|
EVT_IDLE(TBaseServerApp::OnIdle)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
@ -504,10 +503,11 @@ void TBaseServerApp::OnSocketEvent(wxSocketEvent& e)
|
|||||||
switch(e.GetSocketEvent())
|
switch(e.GetSocketEvent())
|
||||||
{
|
{
|
||||||
case wxSOCKET_INPUT:
|
case wxSOCKET_INPUT:
|
||||||
|
if (sock != NULL && sock->IsOk())
|
||||||
{
|
{
|
||||||
// We disable input events, so that the test doesn't trigger wxSocketEvent again.
|
// We disable input events, so that the test doesn't trigger wxSocketEvent again.
|
||||||
sock->SetNotify(wxSOCKET_LOST_FLAG);
|
sock->SetNotify(wxSOCKET_LOST_FLAG);
|
||||||
TCommand * message = new TCommand;
|
TCommand* message = new TCommand;
|
||||||
message->m_Sock = sock;
|
message->m_Sock = sock;
|
||||||
|
|
||||||
// Read the data
|
// Read the data
|
||||||
@ -529,23 +529,38 @@ 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() || wxDateTime::Now().GetDay() > 15)
|
if (sock != NULL)
|
||||||
|
{
|
||||||
|
for (int i = m_Sockets.GetCount()-1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
TCommand& cmd = *(TCommand*)m_Sockets[i];
|
||||||
|
if (cmd.m_Sock == sock)
|
||||||
|
m_Sockets.RemoveAt(i);
|
||||||
|
}
|
||||||
|
if (sock->IsOk())
|
||||||
sock->Destroy();
|
sock->Destroy();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TBaseServerApp::OnDatagramEvent(wxSocketEvent& WXUNUSED(e))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void TBaseServerApp::OnIdle(wxIdleEvent& evt)
|
void TBaseServerApp::OnIdle(wxIdleEvent& evt)
|
||||||
{
|
{
|
||||||
if (m_Sockets.GetCount() > 0)
|
if (m_Sockets.GetCount() > 0)
|
||||||
{
|
{
|
||||||
wxSocketBase& sock = *(((TCommand*)m_Sockets[0])->m_Sock);
|
TCommand& cmd = *(TCommand*)m_Sockets[0];
|
||||||
|
wxSocketBase& sock = *cmd.m_Sock;
|
||||||
const bool valid_socket = sock.IsOk();
|
const bool valid_socket = sock.IsOk();
|
||||||
if (valid_socket)
|
if (valid_socket)
|
||||||
sock.SetNotify(wxSOCKET_LOST_FLAG);
|
sock.SetNotify(wxSOCKET_LOST_FLAG);
|
||||||
|
|
||||||
wxString & str = ((TCommand *) m_Sockets[0])->m_Command;
|
wxString& str = cmd.m_Command;
|
||||||
//scrive sul log solo se chiacchierone!
|
//scrive sul log solo se chiacchierone!
|
||||||
if (m_bLogVerbose)
|
if (m_bLogVerbose)
|
||||||
WriteLog(str);
|
WriteLog(str);
|
||||||
@ -669,6 +684,9 @@ bool TBaseServerApp::GetConfigBool(const wxChar* key, bool def, const wxChar* ap
|
|||||||
int TBaseServerApp::GetDefaultPort() const
|
int TBaseServerApp::GetDefaultPort() const
|
||||||
{ return GetConfigInt("Port", 3883); }
|
{ return GetConfigInt("Port", 3883); }
|
||||||
|
|
||||||
|
int TBaseServerApp::GetUDPPort() const
|
||||||
|
{ return GetConfigInt("PortUDP", 0); }
|
||||||
|
|
||||||
#define OEM_INI wxT("../setup/oem.ini")
|
#define OEM_INI wxT("../setup/oem.ini")
|
||||||
|
|
||||||
int TBaseServerApp::GetOemInt(const wxChar* key, int def) const
|
int TBaseServerApp::GetOemInt(const wxChar* key, int def) const
|
||||||
@ -715,7 +733,7 @@ wxString TBaseServerApp::GetInstallString(const wxChar* key, const wxChar* modul
|
|||||||
bool TBaseServerApp::IsAdvanced() const
|
bool TBaseServerApp::IsAdvanced() const
|
||||||
{
|
{
|
||||||
const int nOEM = GetOemInt(wxT("OEM"), -1);
|
const int nOEM = GetOemInt(wxT("OEM"), -1);
|
||||||
return nOEM==0 || nOEM>2;
|
return nOEM==0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString TBaseServerApp::GetLogFileName() const
|
wxString TBaseServerApp::GetLogFileName() const
|
||||||
@ -730,6 +748,7 @@ bool TBaseServerApp::IsRunning() const
|
|||||||
bool TBaseServerApp::OnInit()
|
bool TBaseServerApp::OnInit()
|
||||||
{
|
{
|
||||||
m_server = NULL;
|
m_server = NULL;
|
||||||
|
m_datagram = NULL;
|
||||||
m_log = NULL;
|
m_log = NULL;
|
||||||
m_bRunning = false;
|
m_bRunning = false;
|
||||||
|
|
||||||
@ -753,8 +772,9 @@ bool TBaseServerApp::OnInit()
|
|||||||
// Create the address - defaults to localhost:0 initially
|
// Create the address - defaults to localhost:0 initially
|
||||||
wxIPV4address addr;
|
wxIPV4address addr;
|
||||||
addr.AnyAddress(); // I docs affermano che AnyAddress sia meglio di LocalHost
|
addr.AnyAddress(); // I docs affermano che AnyAddress sia meglio di LocalHost
|
||||||
addr.Service(GetDefaultPort());
|
const int nTCPPort = GetDefaultPort();
|
||||||
// Create the socket
|
addr.Service(nTCPPort);
|
||||||
|
// Create the TCP socket
|
||||||
m_server = new wxSocketServer(addr);
|
m_server = new wxSocketServer(addr);
|
||||||
|
|
||||||
// Create the Log file
|
// Create the Log file
|
||||||
@ -793,7 +813,7 @@ bool TBaseServerApp::OnInit()
|
|||||||
// Setup the event handler and subscribe to connection events
|
// Setup the event handler and subscribe to connection events
|
||||||
m_server->SetEventHandler(*this, SERVER_ID);
|
m_server->SetEventHandler(*this, SERVER_ID);
|
||||||
m_server->SetNotify(wxSOCKET_CONNECTION_FLAG);
|
m_server->SetNotify(wxSOCKET_CONNECTION_FLAG);
|
||||||
m_server->Notify(TRUE);
|
m_server->Notify(true);
|
||||||
|
|
||||||
wxString str;
|
wxString str;
|
||||||
str << GetAppName() << _(" listening at ") << addr.Hostname() << wxT(":") << addr.Service();
|
str << GetAppName() << _(" listening at ") << addr.Hostname() << wxT(":") << addr.Service();
|
||||||
@ -817,6 +837,22 @@ bool TBaseServerApp::OnInit()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Create the UDP socket
|
||||||
|
const int nUDPPort = GetUDPPort();
|
||||||
|
if (m_bRunning && nUDPPort > nTCPPort)
|
||||||
|
{
|
||||||
|
wxIPV4address udp_addr;
|
||||||
|
udp_addr.AnyAddress(); // I docs affermano che AnyAddress sia meglio di LocalHost
|
||||||
|
udp_addr.Service(nUDPPort);
|
||||||
|
m_datagram = new wxDatagramSocket(udp_addr);
|
||||||
|
|
||||||
|
// Setup the event handler and subscribe to connection events
|
||||||
|
m_datagram->SetEventHandler(*this, DATAGRAM_ID);
|
||||||
|
m_datagram->Notify(true);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return m_bRunning;
|
return m_bRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -902,3 +938,20 @@ size_t TBaseServerApp::ParseArguments(wxString args, THashTable& hashArgs) const
|
|||||||
}
|
}
|
||||||
return hashArgs.GetCount();
|
return hashArgs.GetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TBaseServerApp::GetVersionInfo(int& year, int& release, int& tag, int& patch) const
|
||||||
|
{
|
||||||
|
const char* const VERSIONANDPATCH = "Don't cry for me Argentina.2091.10.00.0000.2101";
|
||||||
|
wxStringTokenizer tok(VERSIONANDPATCH, wxT("."));
|
||||||
|
|
||||||
|
tok.GetNextToken(); // Ignore string
|
||||||
|
year = wxAtoi(tok.GetNextToken());
|
||||||
|
release = wxAtoi(tok.GetNextToken());
|
||||||
|
tag = wxAtoi(tok.GetNextToken());
|
||||||
|
patch = wxAtoi(tok.GetNextToken());
|
||||||
|
int checksum = wxAtoi(tok.GetNextToken());
|
||||||
|
|
||||||
|
bool valid = year >= 2091 && release > 0 && tag >= 0 && patch >= 0 &&
|
||||||
|
checksum == (year + release + tag + patch);
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
@ -80,8 +80,11 @@ public:
|
|||||||
// Define a new application type
|
// Define a new application type
|
||||||
class TBaseServerApp : public wxApp
|
class TBaseServerApp : public wxApp
|
||||||
{
|
{
|
||||||
|
DECLARE_ABSTRACT_CLASS(TBaseServerApp)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxSocketServer* m_server;
|
wxSocketServer* m_server;
|
||||||
|
wxDatagramSocket* m_datagram;
|
||||||
wxFileOutputStream* m_log;
|
wxFileOutputStream* m_log;
|
||||||
wxString m_strPath, m_strTempDir, m_strIni;
|
wxString m_strPath, m_strTempDir, m_strIni;
|
||||||
bool m_bRunning;
|
bool m_bRunning;
|
||||||
@ -122,12 +125,14 @@ protected:
|
|||||||
wxString GetInstallString(const wxChar* key, const wxChar* module = wxEmptyString) const;
|
wxString GetInstallString(const wxChar* key, const wxChar* module = wxEmptyString) const;
|
||||||
|
|
||||||
bool IsAdvanced() const;
|
bool IsAdvanced() const;
|
||||||
|
bool GetVersionInfo(int& year, int& release, int& tag, int& patch) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Utilities
|
// Utilities
|
||||||
virtual const wxChar* GetAppName() const = 0;
|
virtual const wxChar* GetAppName() const = 0;
|
||||||
virtual const wxString& GetConfigName() const;
|
virtual const wxString& GetConfigName() const;
|
||||||
virtual int GetDefaultPort() const; // Retrieves Port usig GetConfigInt
|
virtual int GetDefaultPort() const; // Retrieves Port usig GetConfigInt
|
||||||
|
virtual int GetUDPPort() const; // Retrieves UDP Port usig GetConfigInt
|
||||||
virtual void SetConfigString(const wxChar* key, const wxChar* val, const wxChar* app = NULL) const;
|
virtual void SetConfigString(const wxChar* key, const wxChar* val, const wxChar* app = NULL) const;
|
||||||
|
|
||||||
void SetConfigInt(const wxChar* key, int val, const wxChar* app = NULL) const;
|
void SetConfigInt(const wxChar* key, int val, const wxChar* app = NULL) const;
|
||||||
@ -156,8 +161,10 @@ public:
|
|||||||
// Initialization (Do NOT use nor reimplement!)
|
// Initialization (Do NOT use nor reimplement!)
|
||||||
virtual bool OnInit();
|
virtual bool OnInit();
|
||||||
virtual int OnExit();
|
virtual int OnExit();
|
||||||
void OnServerEvent(wxSocketEvent& event);
|
|
||||||
void OnSocketEvent(wxSocketEvent& event);
|
void OnServerEvent(wxSocketEvent& evt);
|
||||||
|
void OnSocketEvent(wxSocketEvent& evt);
|
||||||
|
void OnDatagramEvent(wxSocketEvent& evt);
|
||||||
void OnIdle(wxIdleEvent& event);
|
void OnIdle(wxIdleEvent& event);
|
||||||
DECLARE_EVENT_TABLE();
|
DECLARE_EVENT_TABLE();
|
||||||
};
|
};
|
||||||
|
@ -75,16 +75,17 @@ bool TLurchServer::PingProcess(const wxString& strApp)
|
|||||||
{
|
{
|
||||||
bool bPinged = false;
|
bool bPinged = false;
|
||||||
|
|
||||||
const wxString strPort = GetConfigString("Port", "", strApp);
|
const unsigned short nPort = GetConfigInt("Port", 0, strApp);
|
||||||
if (!strPort.IsEmpty())
|
if (nPort > 0)
|
||||||
{
|
{
|
||||||
int nTimeOut = m_PingTimer.GetInterval()/4; // msec
|
int nTimeOut = m_PingTimer.GetInterval()/4; // msec
|
||||||
if (nTimeOut < 250) nTimeOut = 250; else
|
if (nTimeOut < 250) nTimeOut = 250; else
|
||||||
if (nTimeOut > 2000) nTimeOut = 2000;
|
if (nTimeOut > 2000) nTimeOut = 2000;
|
||||||
|
|
||||||
wxIPV4address ipAddress;
|
wxIPV4address ipAddress;
|
||||||
ipAddress.LocalHost();
|
ipAddress.AnyAddress();
|
||||||
ipAddress.Service(strPort);
|
ipAddress.Service(nPort);
|
||||||
|
|
||||||
wxSocketClient sSock(wxSOCKET_NOWAIT);
|
wxSocketClient sSock(wxSOCKET_NOWAIT);
|
||||||
sSock.Connect(ipAddress, false);
|
sSock.Connect(ipAddress, false);
|
||||||
if (sSock.WaitOnConnect(0, nTimeOut))
|
if (sSock.WaitOnConnect(0, nTimeOut))
|
||||||
@ -102,6 +103,11 @@ bool TLurchServer::PingProcess(const wxString& strApp)
|
|||||||
sSock.Discard(); // Tralascia ulteriori dati in arrivo
|
sSock.Discard(); // Tralascia ulteriori dati in arrivo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
wxDatagramSocket dSock(ipAddress, wxSOCKET_NOWAIT);
|
||||||
|
ipAddress.Service(1884);
|
||||||
|
dSock.SendTo(ipAddress, "PING\n", 5);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return bPinged;
|
return bPinged;
|
||||||
@ -302,17 +308,12 @@ void TLurchServer::GenerateFile(wxString& strFilename)
|
|||||||
wxString strHost; strHost << wxGetHostName() << wxT(":") << GetDefaultPort();
|
wxString strHost; strHost << wxGetHostName() << wxT(":") << GetDefaultPort();
|
||||||
AddTableRow(panel, wxT("Host Name"), strHost);
|
AddTableRow(panel, wxT("Host Name"), strHost);
|
||||||
|
|
||||||
const wxString strVersion = GetInstallString(wxT("Versione"));
|
int y, v, t, p; GetVersionInfo(y, v, t, p);
|
||||||
wxString str; str.Printf(wxT("%04d / %5.2lf"), wxAtoi(strVersion.Left(4)), wxAtoi(strVersion.Mid(4))/100.0);
|
wxString strVer; strVer.Printf(wxT("%d.%d.%d"), v, t, p);
|
||||||
AddTableRow(panel, wxT("Version"), str);
|
AddTableRow(panel, wxT("Version"), strVer);
|
||||||
AddTableRow(panel, wxT("Patch"), GetInstallString(wxT("Patch")));
|
|
||||||
AddTableRow(panel, wxT("Date"), GetInstallString(wxT("Data")));
|
|
||||||
|
|
||||||
if (IsAdvanced())
|
|
||||||
{
|
|
||||||
wxString strFreq; strFreq << m_PingTimer.GetInterval()/1000;
|
wxString strFreq; strFreq << m_PingTimer.GetInterval()/1000;
|
||||||
AddTableRow(panel, wxT("Ping Frequency"), strFreq);
|
AddTableRow(panel, wxT("Ping Frequency"), strFreq);
|
||||||
}
|
|
||||||
|
|
||||||
html.Save(strFilename);
|
html.Save(strFilename);
|
||||||
}
|
}
|
||||||
@ -657,15 +658,12 @@ bool TLurchServer::Initialization()
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < nAuto; i++)
|
for (size_t i = 0; i < nAuto; i++)
|
||||||
StartProcess(arr[i]);
|
StartProcess(arr[i]);
|
||||||
if (IsAdvanced())
|
|
||||||
{
|
|
||||||
const int nFreq = GetConfigInt("PingFreq");
|
const int nFreq = GetConfigInt("PingFreq");
|
||||||
if (nFreq > 0)
|
if (nFreq > 0)
|
||||||
{
|
{
|
||||||
m_PingTimer.Start(nFreq * 1000); // sec to msec
|
m_PingTimer.Start(nFreq * 1000); // sec to msec
|
||||||
m_Semaphore.Post(); // GREEN!
|
m_Semaphore.Post(); // GREEN!
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user