Patch level : 10.0
Files correlati : lurch.exe authoriz.exe Ricompilazione Demo : [ ] Commento : Resa piu' robusta la procedura di chiusura dei servizi git-svn-id: svn://10.65.10.50/trunk@20134 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
38b45187af
commit
5304308581
@ -810,7 +810,7 @@ void TAuthorizationServer::ProcessUserLogin(wxString cmd, wxSocketBase& sock)
|
||||
int session;
|
||||
|
||||
cmd.Replace(",", " "); cmd.Replace(")", " ");
|
||||
const int nStr = sscanf(cmd, "UserLogin(%s %s %s %d)", strUser, strPassword, strProgram, &session);
|
||||
const int nStr = wxSscanf(cmd, "UserLogin(%s %s %s %d)", strUser, strPassword, strProgram, &session);
|
||||
|
||||
if (nStr < 4)
|
||||
session = 0;
|
||||
@ -827,7 +827,7 @@ void TAuthorizationServer::ProcessUserLogin(wxString cmd, wxSocketBase& sock)
|
||||
{
|
||||
if (m_Users.GetLicenses() >= m_Dongle.MaxUsers() && m_Users.Find(sock, NULL, session) == NULL)
|
||||
{
|
||||
WriteLog("*** Maximum users exceeded");
|
||||
WriteLog(_("*** Maximum number of users exceeded"));
|
||||
num = 0;
|
||||
}
|
||||
else
|
||||
@ -839,12 +839,12 @@ void TAuthorizationServer::ProcessUserLogin(wxString cmd, wxSocketBase& sock)
|
||||
if (num > 0)
|
||||
m_Users.AddConnection(sock, strUser, session);
|
||||
else
|
||||
WriteLog("*** Bad password");
|
||||
WriteLog(_("*** Bad password"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
WriteLog("*** Dongle not responding");
|
||||
WriteLog(_("*** Dongle not responding"));
|
||||
|
||||
ReturnInt(sock, num);
|
||||
}
|
||||
@ -877,8 +877,7 @@ bool TAuthorizationServer::ReturnInt(wxSocketBase& outs, unsigned int i)
|
||||
|
||||
bool TAuthorizationServer::ReturnBool(wxSocketBase& outs, bool b)
|
||||
{
|
||||
ReturnInt(outs, b ? 1 : 0);
|
||||
return outs.IsOk();
|
||||
return ReturnInt(outs, b ? 1 : 0);
|
||||
}
|
||||
|
||||
bool TAuthorizationServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
|
||||
|
@ -98,7 +98,7 @@ THashTable::THashTable(size_t size) : m_Hash(wxKEY_STRING, size)
|
||||
m_Hash.DeleteContents(true);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef wxHAS_TASK_BAR_ICON
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TTaskbarIcon
|
||||
@ -110,13 +110,12 @@ END_EVENT_TABLE()
|
||||
|
||||
void TTaskBarIcon::OnTaskBarClick(wxTaskBarIconEvent& WXUNUSED(e))
|
||||
{
|
||||
wxString url;
|
||||
wxString strURL;
|
||||
// wxIPV4address addr; addr.AnyAddress();
|
||||
// addr.Service(GetServerApp().GetDefaultPort());
|
||||
// url << addr.Hostname() << ":" << addr.Service();
|
||||
url << "http://127.0.0.1:" << GetServerApp().GetDefaultPort();
|
||||
|
||||
::ShellExecute(0, "open", url, NULL, NULL, SW_SHOWNORMAL);
|
||||
strURL << "http://127.0.0.1:" << GetServerApp().GetDefaultPort();
|
||||
wxLaunchDefaultBrowser(strURL);
|
||||
}
|
||||
|
||||
void TTaskBarIcon::Init()
|
||||
@ -223,20 +222,20 @@ TXmlItem& TBaseServerApp::CreatePageBody(TXmlItem& html, wxString header) const
|
||||
|
||||
TXmlItem& body = html.AddChild("body");
|
||||
body.SetAttr("bgcolor", "#EFCEAD");
|
||||
if (m_bRunning)
|
||||
if (IsRunning())
|
||||
body.SetAttr("background", "back.gif");
|
||||
|
||||
TXmlItem& title = body.AddChild("table");
|
||||
title.SetAttr("border", "5"); title.SetAttr("width", "100%");
|
||||
TXmlItem& title_tr = title.AddChild("tr");
|
||||
|
||||
if (m_bRunning)
|
||||
if (IsRunning())
|
||||
AddLogo(title_tr);
|
||||
|
||||
TXmlItem& td1 = title_tr.AddChild("td");
|
||||
td1.AddChild("h1").AddChild("center") << header;
|
||||
|
||||
if (m_bRunning)
|
||||
if (IsRunning())
|
||||
AddLogo(title_tr);
|
||||
|
||||
body.AddChild("br");
|
||||
@ -279,7 +278,7 @@ void TBaseServerApp::MessageBox(const wxChar* caption, const wxChar* msg, wxSock
|
||||
|
||||
bool TBaseServerApp::CanProcessCommand(wxString& cmd, wxSocketBase& outs)
|
||||
{
|
||||
if (cmd.Find("stop.cgi") > 0)
|
||||
if (cmd.Find("stop.cgi") >= 0)
|
||||
{
|
||||
m_bRunning = false; // Disable gif on title
|
||||
if (outs.IsOk())
|
||||
@ -651,10 +650,10 @@ int TBaseServerApp::GetDefaultPort() const
|
||||
|
||||
int TBaseServerApp::GetOemInt(const wxChar* key, int def) const
|
||||
{
|
||||
static int _oem = -1;
|
||||
static int _oem = -883;
|
||||
|
||||
#ifdef __WXMSW__
|
||||
if (_oem < 0)
|
||||
if (_oem == -883)
|
||||
_oem = ::GetPrivateProfileInt("MAIN", "OEM", -1, OEM_INI);
|
||||
if (_oem >= 0)
|
||||
{
|
||||
@ -693,7 +692,9 @@ wxString TBaseServerApp::GetOemString(const wxChar* key, const wxChar* def) cons
|
||||
}
|
||||
|
||||
bool TBaseServerApp::IsAdvanced() const
|
||||
{ return GetOemInt(wxT("OEM"), -1) != 2; }
|
||||
{
|
||||
const int nOEM = GetOemInt(wxT("OEM"), -1);
|
||||
return nOEM==0 || nOEM>2; }
|
||||
|
||||
wxString TBaseServerApp::GetLogFileName() const
|
||||
{ return GetConfigString("LogFile"); }
|
||||
@ -701,14 +702,19 @@ wxString TBaseServerApp::GetLogFileName() const
|
||||
wxString TBaseServerApp::GetDocumentRoot() const
|
||||
{ return GetConfigString("DocumentRoot", m_strPath); }
|
||||
|
||||
bool TBaseServerApp::IsRunning() const
|
||||
{ return m_bRunning && IsMainLoopRunning() && Ok(); }
|
||||
|
||||
bool TBaseServerApp::OnInit()
|
||||
{
|
||||
m_server = NULL;
|
||||
m_log = NULL;
|
||||
m_bRunning = false;
|
||||
|
||||
m_SingleInstance = new wxSingleInstanceChecker(GetAppName());
|
||||
m_SingleInstance = new wxSingleInstanceChecker(GetAppName());
|
||||
if (m_SingleInstance->IsAnotherRunning())
|
||||
{
|
||||
wxMessageBox(_("Another instance is already running"), GetAppName(), wxICON_HAND);
|
||||
delete m_SingleInstance;
|
||||
m_SingleInstance = NULL;
|
||||
return false;
|
||||
@ -730,13 +736,12 @@ bool TBaseServerApp::OnInit()
|
||||
m_server = new wxSocketServer(addr);
|
||||
|
||||
// Create the Log file
|
||||
wxString str;
|
||||
//Prima di creare il nuovo log file (vuoto) salva quello vecchio aggiungendo al nome data e ora di ripartenza..
|
||||
//..Serve per monitorare i defungimenti dei server
|
||||
str = GetLogFileName();
|
||||
if (!str.IsEmpty())
|
||||
const wxString strLog = GetLogFileName();
|
||||
if (!strLog.IsEmpty())
|
||||
{
|
||||
wxFileName fnLogFileName(str);
|
||||
wxFileName fnLogFileName(strLog);
|
||||
if (fnLogFileName.FileExists())
|
||||
{
|
||||
const wxDateTime dtNow = wxDateTime::Now();
|
||||
@ -746,10 +751,10 @@ bool TBaseServerApp::OnInit()
|
||||
dtNow.GetHour(), dtNow.GetMinute());
|
||||
strWorkString << fnLogFileName.GetName();
|
||||
fnLogFileName.SetName(strWorkString);
|
||||
wxCopyFile(str, fnLogFileName.GetFullPath());
|
||||
wxCopyFile(strLog, fnLogFileName.GetFullPath());
|
||||
}
|
||||
|
||||
m_log = new wxFileOutputStream(str);
|
||||
m_log = new wxFileOutputStream(strLog);
|
||||
m_bLogVerbose = GetConfigBool("LogVerbose");
|
||||
}
|
||||
else
|
||||
@ -759,9 +764,8 @@ bool TBaseServerApp::OnInit()
|
||||
}
|
||||
|
||||
m_nTmpCounter = 0;
|
||||
|
||||
|
||||
// We use Ok() here to see if the server is really listening
|
||||
str.Empty();
|
||||
if (m_server->Ok())
|
||||
{
|
||||
// Setup the event handler and subscribe to connection events
|
||||
@ -769,35 +773,36 @@ bool TBaseServerApp::OnInit()
|
||||
m_server->SetNotify(wxSOCKET_CONNECTION_FLAG);
|
||||
m_server->Notify(TRUE);
|
||||
|
||||
str << GetAppName() << " listening at " << addr.Hostname() << ":" << addr.Service();
|
||||
m_bRunning = true;
|
||||
wxString str;
|
||||
str << GetAppName() << _(" listening at ") << addr.Hostname() << wxT(":") << addr.Service();
|
||||
WriteLog(str);
|
||||
|
||||
m_bRunning = Initialization();
|
||||
}
|
||||
else
|
||||
{
|
||||
str << GetAppName() << " could not listen to port " << addr.Service();
|
||||
wxString str;
|
||||
str << GetAppName() << _(" could not listen to port ") << addr.Service();
|
||||
WriteLog(str);
|
||||
}
|
||||
WriteLog(str);
|
||||
|
||||
bool ok = m_server->Ok();
|
||||
if (ok)
|
||||
ok = Initialization();
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef wxHAS_TASK_BAR_ICON
|
||||
m_Tray = NULL;
|
||||
if (ok)
|
||||
if (m_bRunning)
|
||||
{
|
||||
m_Tray = new TTaskBarIcon;
|
||||
m_Tray->Init();
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
return m_bRunning;
|
||||
}
|
||||
|
||||
int TBaseServerApp::OnExit()
|
||||
{
|
||||
if (m_server != NULL)
|
||||
{
|
||||
m_bRunning = false;
|
||||
Deinitialization();
|
||||
delete m_SingleInstance;
|
||||
m_SingleInstance = NULL;
|
||||
@ -813,9 +818,10 @@ int TBaseServerApp::OnExit()
|
||||
m_log = NULL;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef wxHAS_TASK_BAR_ICON
|
||||
if (m_Tray != NULL)
|
||||
{
|
||||
m_Tray->RemoveIcon();
|
||||
delete m_Tray;
|
||||
m_Tray = NULL;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
// TTaskbarIcon
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef wxHAS_TASK_BAR_ICON
|
||||
#include <wx/taskbar.h>
|
||||
|
||||
class TTaskBarIcon : public wxTaskBarIcon
|
||||
@ -89,7 +89,7 @@ private:
|
||||
int m_nTmpCounter;
|
||||
wxArrayPtrVoid m_Sockets;
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef wxHAS_TASK_BAR_ICON
|
||||
TTaskBarIcon* m_Tray;
|
||||
#endif
|
||||
|
||||
@ -141,9 +141,11 @@ public:
|
||||
size_t ParseArguments(wxString args, THashTable& hashArgs) const;
|
||||
|
||||
virtual void WriteLog(const wxChar* str) const; // Writes on log file if present
|
||||
virtual bool Ok() const { return m_server->Ok(); }
|
||||
virtual bool Ok() const { return m_server != NULL && m_server->Ok(); }
|
||||
virtual bool Initialization() { return true; }
|
||||
virtual bool Deinitialization() { return true; }
|
||||
|
||||
bool IsRunning() const;
|
||||
|
||||
// Initialization (Do NOT use nor reimplement!)
|
||||
virtual bool OnInit();
|
||||
|
@ -24,6 +24,7 @@ class TLurchServer : public TBaseServerApp
|
||||
protected:
|
||||
virtual const wxChar* GetAppName() const;
|
||||
virtual bool Initialization();
|
||||
virtual bool Deinitialization();
|
||||
void OnTimer(wxTimerEvent& evt);
|
||||
void OnEndProcess(wxProcessEvent& evt);
|
||||
|
||||
@ -32,7 +33,7 @@ protected:
|
||||
|
||||
const wxArrayString& GetServersList();
|
||||
const wxArrayString& GetAutoRunList();
|
||||
const TProcessHashMap& GetRunningServers() { return m_hmProcMap; }
|
||||
const TProcessHashMap& GetRunningServers() const { return m_hmProcMap; }
|
||||
|
||||
bool PingProcess(const wxString& strApp);
|
||||
void StopProcess(const wxString& strApp);
|
||||
@ -106,7 +107,7 @@ bool TLurchServer::PingProcess(const wxString& strApp)
|
||||
|
||||
void TLurchServer::OnTimer(wxTimerEvent& evt)
|
||||
{
|
||||
const wxSemaError se = m_Semaphore.TryWait();
|
||||
const wxSemaError se = IsRunning() ? m_Semaphore.TryWait() : wxSEMA_MISC_ERROR;
|
||||
if (se == wxSEMA_NO_ERROR)
|
||||
{
|
||||
const wxArrayString& aServers = GetAutoRunList();
|
||||
@ -446,23 +447,16 @@ void TLurchServer::ProcessFormStop(const THashTable& args, wxSocketBase& sock)
|
||||
{
|
||||
const wxString strApp = args.Get("App");
|
||||
if (strApp == GetAppName() || strApp.IsEmpty()) // Stop myself!
|
||||
{
|
||||
m_PingTimer.Stop(); // Stop ping process!
|
||||
// Fill a safe array of names before killing the processes stored in the hash map
|
||||
const TProcessHashMap& hmServers = GetRunningServers(); // Hash map of the running processes
|
||||
wxArrayString aRunner; // Array of the names of the runners
|
||||
TProcessHashMap::const_iterator it;
|
||||
for (it = hmServers.begin(); it != hmServers.end(); ++it)
|
||||
aRunner.Add(it->first);
|
||||
for (size_t i = 0; i < aRunner.GetCount(); i++)
|
||||
StopProcess(aRunner[i]);
|
||||
ExitMainLoop();
|
||||
}
|
||||
{
|
||||
wxString strCmd = wxT("stop.cgi"); // Exits main loop;
|
||||
TBaseServerApp::CanProcessCommand(strCmd, sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
StopProcess(strApp);
|
||||
MessageBox("Server stopped", strApp, sock);
|
||||
|
||||
m_Semaphore.Post(); // Inutile, ma cosi' non rompo la simmetria
|
||||
MessageBox("Server stopped", strApp, sock);
|
||||
}
|
||||
m_Semaphore.Post();
|
||||
}
|
||||
}
|
||||
|
||||
@ -667,6 +661,30 @@ bool TLurchServer::Initialization()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TLurchServer::Deinitialization()
|
||||
{
|
||||
m_PingTimer.Stop(); // Stop ping process!
|
||||
|
||||
// kill all autorun processes even if I didn't start them
|
||||
const wxArrayString& ar = GetAutoRunList();
|
||||
for (size_t i = 0; i < ar.GetCount(); i++)
|
||||
StopProcess(ar[i]);
|
||||
|
||||
// kill all still running (die hard) processes
|
||||
const TProcessHashMap& hmServers = GetRunningServers();
|
||||
if (!hmServers.empty())
|
||||
{
|
||||
// Fill a safe array of names before killing the processes stored in the hash map
|
||||
wxArrayString aRunner; // Array of the names of the runners
|
||||
TProcessHashMap::const_iterator it;
|
||||
for (it = hmServers.begin(); it != hmServers.end(); ++it)
|
||||
aRunner.Add(it->first);
|
||||
for (size_t i = 0; i < aRunner.GetCount(); i++)
|
||||
StopProcess(aRunner[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Istanziare l'applicazione principale
|
||||
|
||||
IMPLEMENT_APP(TLurchServer)
|
||||
|
Loading…
x
Reference in New Issue
Block a user