Patch level : 10.0

Files correlati     : authoriz.exe
Ricompilazione Demo : [ ]
Commento            :
Migliorata gestione disconnessioni, soprattutto da parte di programmi mai connessi


git-svn-id: svn://10.65.10.50/branches/R_10_00@22312 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2011-06-23 14:17:15 +00:00
parent 32acfde9b6
commit 42f1e17b4a
2 changed files with 53 additions and 36 deletions

View File

@ -36,7 +36,8 @@ public:
TUserInfo* AddConnection(wxSocketBase& sock, const wxChar* user, int session); TUserInfo* AddConnection(wxSocketBase& sock, const wxChar* user, int session);
TUserInfo* Find(wxSocketBase& sock, const wxChar* user, int session); TUserInfo* Find(wxSocketBase& sock, const wxChar* user, int session);
void RemoveConnection(wxSocketBase& sock, const wxChar* user, int session); void RemoveConnection(wxSocketBase& sock, const wxChar* user, int session);
void Kill(const wxChar* strUserAtHost); bool Kill(const wxChar* strUserAtHost);
bool Kill(TUserInfo* ui);
void KillSession(wxSocketBase& sock, int session); void KillSession(wxSocketBase& sock, int session);
size_t GetCount() const { return size(); } size_t GetCount() const { return size(); }
@ -89,31 +90,43 @@ TUserInfo* TUserTable::Find(wxSocketBase& sock, const wxChar* user, int session)
for (TUsersHashMap::iterator it = begin(); it != end(); ++it) for (TUsersHashMap::iterator it = begin(); it != end(); ++it)
{ {
TUserInfo* ui = it->second; TUserInfo* ui = it->second;
if (ui->m_strHost == strHost) if (ui != NULL && ui->m_strHost == strHost)
return ui; return ui;
} }
return NULL; return NULL;
} }
bool TUserTable::Kill(const wxChar* strUserAtHost)
{
const int erased = erase(strUserAtHost);
return erased != 0;
}
bool TUserTable::Kill(TUserInfo* ui)
{
for (TUsersHashMap::iterator it = begin(); it != end(); ++it)
{
if (it->second == ui)
{
erase(it);
return true;
}
}
return false;
}
void TUserTable::RemoveConnection(wxSocketBase& sock, const wxChar* user, int session) void TUserTable::RemoveConnection(wxSocketBase& sock, const wxChar* user, int session)
{ {
TUserInfo* ui = Find(sock, user, session); TUserInfo* ui = Find(sock, user, session);
if (ui) if (ui != NULL)
{ {
ui->m_nPrograms--; ui->m_nPrograms--;
if (ui->m_nPrograms <= 0) if (ui->m_nPrograms <= 0)
{ Kill(ui);
const wxString strUserAtHost = BuildKey(sock, user, session);
erase(strUserAtHost);
} }
} }
}
void TUserTable::Kill(const wxChar* strUserAtHost)
{
erase(strUserAtHost);
}
void TUserTable::KillSession(wxSocketBase& sock, int session) void TUserTable::KillSession(wxSocketBase& sock, int session)
{ {
@ -121,10 +134,7 @@ void TUserTable::KillSession(wxSocketBase& sock, int session)
{ {
TUserInfo* ui = Find(sock, NULL, session); TUserInfo* ui = Find(sock, NULL, session);
if (ui != NULL) if (ui != NULL)
{ Kill(ui);
const wxString strUserAtHost = BuildKey(sock, ui->m_strName.c_str(), session);
erase(strUserAtHost);
}
else else
break; break;
} }
@ -343,22 +353,25 @@ void TAuthorizationServer::GenerateIndex(wxString& strFilename)
TXmlItem& tr = title.AddChild("table").SetAttr("width", "40%").AddChild("tr"); TXmlItem& tr = title.AddChild("table").SetAttr("width", "40%").AddChild("tr");
TXmlItem& td = tr.AddChild("td").SetAttr("width", "30%"); TXmlItem& td = tr.AddChild("td").SetAttr("width", "30%");
const bool hard = m_Dongle.hardware() == _dongle_hardlock;
TXmlItem& img = td.AddChild("img"); TXmlItem& img = td.AddChild("img");
wxString strModel;
switch (m_Dongle.hardware()) switch (m_Dongle.hardware())
{ {
case _dongle_aladdin: case _dongle_xsec:
img.SetAttr("src", "aladdin.gif"); img.SetAttr("src", "xsec.gif");
strModel = wxT("XSec");
break; break;
case _dongle_hardlock: case _dongle_hardlock:
img.SetAttr("src", "hardlock.gif"); img.SetAttr("src", "hardlock.gif");
strModel = wxT("Hardlock");
break; break;
default: default:
img.SetAttr("src", "eutron.gif"); img.SetAttr("src", "eutron.gif");
strModel = wxT("Eutron");
break; break;
} }
tr.AddChild("td").SetAttr("align", "center").AddChild("h1") << (hard ? "Hardlock EYE" : "Eutron Smartkey"); tr.AddChild("td").SetAttr("align", "center").AddChild("h1") << strModel;
} }
else else
{ {
@ -497,6 +510,8 @@ void TAuthorizationServer::GenerateUsers(wxString& strFilename)
for (TUsersHashMap::const_iterator it = m_Users.begin(); it != m_Users.end(); ++it ) for (TUsersHashMap::const_iterator it = m_Users.begin(); it != m_Users.end(); ++it )
{ {
const TUserInfo* ui = it->second; const TUserInfo* ui = it->second;
if (ui != NULL)
{
TXmlItem& tr = table.AddChild("tr"); TXmlItem& tr = table.AddChild("tr");
tr.AddChild("td").SetAttr("align", "right") << wxString::Format("%d", ++nUser); tr.AddChild("td").SetAttr("align", "right") << wxString::Format("%d", ++nUser);
tr.AddChild("td").AddChild("b") << ui->m_strName; tr.AddChild("td").AddChild("b") << ui->m_strName;
@ -508,6 +523,7 @@ void TAuthorizationServer::GenerateUsers(wxString& strFilename)
wxString strKey; strKey << ui->m_strName << wxT("@") << ui->m_strHost; wxString strKey; strKey << ui->m_strName << wxT("@") << ui->m_strHost;
wxString href = wxString::Format("kill.cgi?%s", strKey.c_str()); wxString href = wxString::Format("kill.cgi?%s", strKey.c_str());
AddLinkButton(tr.AddChild("td"), "Kill", href).SetAttr("width", "100%"); AddLinkButton(tr.AddChild("td"), "Kill", href).SetAttr("width", "100%");
}
} }
body.AddChild("br"); body.AddChild("br");
@ -986,8 +1002,9 @@ bool TAuthorizationServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
if (cmd.StartsWith("UserLogout")) if (cmd.StartsWith("UserLogout"))
{ {
bool ok = ProcessUserLogout(cmd, outs); ReturnBool(outs, true); // ATTENZIONE! Prima rispondo ok ...
return ReturnBool(outs, ok); ProcessUserLogout(cmd, outs); // ... poi chiudo la connessione
return true;
} }
if (cmd.StartsWith("DongleInfo")) if (cmd.StartsWith("DongleInfo"))

View File

@ -5,8 +5,8 @@
#include <wx/datetime.h> #include <wx/datetime.h>
#endif #endif
enum TDongleHardware { _dongle_unknown, _dongle_hardlock, _dongle_eutron, _dongle_aladdin }; enum TDongleHardware { _dongle_unknown, _dongle_hardlock, _dongle_eutron, _dongle_xsec };
enum TDongleType { _no_dongle, _user_dongle, _developer_dongle, _aga_dongle, _prassi_dongle, _procom_dongle }; enum TDongleType { _no_dongle, _user_dongle, _developer_dongle, _aga_dongle, _prassi_dongle };
enum { MAX_DONGLE_ASSIST = 8 }; enum { MAX_DONGLE_ASSIST = 8 };
class TBit_array : public wxObject class TBit_array : public wxObject