campo-sirio/fd/gtSSA.cpp

106 lines
2.3 KiB
C++
Raw Normal View History

#include "wxinc.h"
#include "gtDialog.h"
#include "gtSSA.h"
#include "../ssa/h/ssadll.h"
#include "../ssa/h/ssaerr.h"
#include <wx/filename.h>
class SSA_dongle : public wxObject
{
int m_nSerial;
wxString m_strUserID;
wxString m_strProduct, m_strModule;
protected:
const wxString& UserID();
int Login(const char* product, const char* module);
public:
int Login();
int Logout();
SSA_dongle() : m_nSerial(SSA_UTENTE_NON_LOGGATO) {}
} __SSA;
const wxString& SSA_dongle::UserID()
{
if (m_strUserID.IsEmpty())
{
const wxString strUser = ::wxGetUserId(); // User name
const wxString strHost = ::wxGetHostName(); // host name
const unsigned long sess = ::WTSGetActiveConsoleSessionId(); // Session ID the modern way!
m_strUserID.Printf("%s@%s:%lu", (const char*)strUser, (const char*)strHost, sess);
}
return m_strUserID;
}
int SSA_dongle::Login(const char* product, const char* module)
{
if (!m_strProduct.IsEmpty())
Logout();
int err = SSA_Login(UserID(), product);
if (err == 0)
{
m_strProduct = product;
m_nSerial = SSA_NumeroSerie(product);
}
if (err == 0)
{
wxString m = module; m.MakeLower();
err = SSA_ApriModulo(UserID(), m);
if (err == SSA_MOD_NOTFOUND)
{
m.MakeUpper();
err = SSA_ApriModulo(UserID(), m);
}
#ifndef _NDEBUG
if (err != 0)
{
gtWarning("Versione DEMO");
err = 0;
}
#endif
if (err == 0)
m_strModule = m;
}
return err;
}
int SSA_dongle::Login()
{
int err = Login("FIRMA DIGITALE", "fd");
if (err != 0 && wxFileName::FileExists("campo.ini"))
err = Login("CAMPO", "pa") || Login("CAMPO", "fd");
return err;
}
int SSA_dongle::Logout()
{
int err = 0;
if (!m_strModule.IsEmpty())
{
err = SSA_ChiudiModulo(UserID(), m_strModule);
if (err == 0)
m_strModule.Empty();
}
if (!m_strProduct.IsEmpty())
{
err = SSA_Logout(UserID(), m_strProduct);
if (err == 0)
{
m_nSerial = SSA_UTENTE_NON_LOGGATO;
m_strProduct.Empty();
m_strModule.Empty();
}
}
return err;
}
int SSA_Login() { return __SSA.Login(); }
int SSA_Logout() { return __SSA.Logout(); }