Patch level : 10.0 644

Files correlati     : ba0.exe
Ricompilazione Demo : [ ]
Commento            :
Corretto riconoscimento di Windows 7
Ridotto traffico di rete vs server di chiavi


git-svn-id: svn://10.65.10.50/trunk@20136 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2010-02-17 12:15:28 +00:00
parent 0f2e3236fa
commit 742b7b7168
6 changed files with 108 additions and 29 deletions

View File

@ -432,23 +432,31 @@ bool TDongle::network_login(bool test_all_keys)
if (network() && ok()) if (network() && ok())
rpc_UserLogout(appname); rpc_UserLogout(appname);
TConfig ini(CONFIG_INSTALL, "Server"); TString server = "127.0.0.1";
const char* server = ini.get("Dongle"); if (!xvt_sys_dongle_server_is_running())
server = ini_get_string(CONFIG_INSTALL, "Server", "Dongle");
// const char* guest = "******"; // const char* guest = "******";
// const TString16 appname = main_app().name(); // const TString16 appname = main_app().name();
// const char* utente = (!main_app().is_running() && appname == "ba0100") ? guest : (const char *) user(); // const char* utente = (!main_app().is_running() && appname == "ba0100") ? guest : (const char *) user();
const char* utente = user(); const char* utente = user();
const bool ok = rpc_UserLogin(server, utente, "******", appname); bool ok = rpc_UserLogin(server, utente, "******", appname);
if (ok) if (ok)
{ {
_hardware = _dongle_network; _hardware = _dongle_network;
_type = _user_dongle; _type = _user_dongle;
_serno = rpc_DongleNumber();
_max_users = 1; _max_users = 1;
_last_update = TDate(TODAY); _last_update = TDate(TODAY);
// Let's try to spare some network band!
ok = rpc_DongleInfo(_serno, _year_assist, _module);
if (!ok)
{
_serno = rpc_DongleNumber();
_year_assist = rpc_DongleYear(); _year_assist = rpc_DongleYear();
rpc_DongleModules(_module); ok = rpc_DongleModules(_module);
}
} }
return ok; return ok;
} }
@ -720,7 +728,7 @@ const TString& TDongle::short_name() const
const TString& TDongle::server_name() const const TString& TDongle::server_name() const
{ {
if (network()) if (network() && !xvt_sys_dongle_server_is_running())
return ini_get_string(CONFIG_INSTALL, "Server", "Dongle"); return ini_get_string(CONFIG_INSTALL, "Server", "Dongle");
TString& tmp = get_tmp_string(32); TString& tmp = get_tmp_string(32);

View File

@ -42,6 +42,15 @@ bool rpc_Call(const char* cmd)
return ok; return ok;
} }
int rpc_Timeout(int sec)
{
CHECK(_client != NULL, "Client not initialized");
const int to = _client->Timeout();
if (sec >= 0)
_client->SetTimeout(sec);
return to;
}
char* rpc_Request(const char* cmd, size_t& size, real& total) char* rpc_Request(const char* cmd, size_t& size, real& total)
{ {
CHECK(_connection, "Server not connected"); CHECK(_connection, "Server not connected");
@ -206,6 +215,38 @@ unsigned rpc_DongleYear()
return (unsigned)IntCall(); return (unsigned)IntCall();
} }
bool rpc_DongleInfo(word& number, word& year, TBit_array& ba)
{
size_t size;
real time;
number = year = 0;
ba.reset(); ba.set(0, true);
const int to = rpc_Timeout(5); // change timeout
word* buff = (word*)rpc_Request("DongleInfo()", size, time);
rpc_Timeout(to); // restore timeout
if (buff && size > 4)
{
number = buff[0];
year = buff[1];
const int words = int(size/2);
int module = 1;
for (int i = 2; i < words; i++)
{
for (int b = 0; b < 16; b++)
{
if (buff[i] & (1 << b))
ba.set(module, true);
module++;
}
}
}
return (number >= 0) && (year > 2000);
}
static unsigned int CreatePassword(TString& pass) static unsigned int CreatePassword(TString& pass)
{ {
const int BASE = 19; const int BASE = 19;

View File

@ -1,10 +1,6 @@
#ifndef __ISAMRPC_H #ifndef __ISAMRPC_H
#define __ISAMRPC_H #define __ISAMRPC_H
#ifndef __ARRAY_H
#include <array.h>
#endif
#ifndef __REAL_H #ifndef __REAL_H
#include <real.h> #include <real.h>
#endif #endif
@ -16,6 +12,7 @@ bool rpc_DongleHasModule(word af);
bool rpc_DongleModules(TBit_array& ba); bool rpc_DongleModules(TBit_array& ba);
unsigned rpc_DongleNumber(); unsigned rpc_DongleNumber();
unsigned rpc_DongleYear(); unsigned rpc_DongleYear();
bool rpc_DongleInfo(word& number, word& year, TBit_array& ba);
bool rpc_UserLogin(const char* server, const char* user, bool rpc_UserLogin(const char* server, const char* user,
const char* password, const char* application); const char* password, const char* application);

View File

@ -523,12 +523,13 @@ protected:
bool connect(); bool connect();
public: public:
const TString & Server() const { return _server; } const TString& Server() const { return _server; }
virtual bool Execute(const char* cmd); virtual bool Execute(const char* cmd);
bool WriteLine(const char* cmd); bool WriteLine(const char* cmd);
bool ReadLine(TString& str); bool ReadLine(TString& str);
bool Read(byte* buf, size_t size); bool Read(byte* buf, size_t size);
bool ReadTimeout(byte* buf, size_t size, int timeout);
skstream* GetSocket(); skstream* GetSocket();
@ -572,8 +573,9 @@ bool TSocket_connection::ReadLine(TString& str)
bool ok = calza != NULL; bool ok = calza != NULL;
if (ok) if (ok)
{ {
char *buf = str.get_buffer(4096); char buf[4096]; memset(buf, 0, sizeof(buf));
calza->getline(buf, str.size(), '\n'); calza->getline(buf, sizeof(buf)-1, '\n');
str = buf;
} }
return ok; return ok;
} }
@ -584,12 +586,40 @@ bool TSocket_connection::Read(byte* buf, size_t size)
bool ok = calza != NULL; bool ok = calza != NULL;
if (ok) if (ok)
{ {
calza->read((char *)buf, size); calza->read((char*)buf, size);
ok = calza->good() != 0; ok = calza->good() != 0;
} }
return ok; return ok;
} }
bool TSocket_connection::ReadTimeout(byte* buf, size_t size, int timeout)
{
return Read(buf, size);
/* Non va micca
if (timeout <= 0)
return Read(buf, size);
skstream* calza = GetSocket();
bool ok = calza != NULL && calza->good();
if (ok)
{
SOCKET s = calza->getsocket();
// Set new timeout
struct timeval tv; memset(&tv, 0, sizeof(tv)); tv.tv_sec = timeout;
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(tv));
calza->read((char*)buf, size);
ok = calza->gcount() == size;
// Reset old timeout
memset(&tv, 0, sizeof(tv));
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(tv));
}
return ok;
*/
}
bool TSocket_connection::connect() bool TSocket_connection::connect()
{ {
if (_socket != NULL) if (_socket != NULL)
@ -645,7 +675,7 @@ TSocket_connection::~TSocket_connection()
} }
TSocketClient::TSocketClient() TSocketClient::TSocketClient()
: m_pData(NULL), m_dwSize(0) : m_pData(NULL), m_dwSize(0), m_nTimeout(0)
{ } { }
TSocketClient::~TSocketClient() TSocketClient::~TSocketClient()
@ -662,8 +692,6 @@ TConnection* TSocketClient::OnQueryConnection(const char* service, const char* s
delete pConnection; delete pConnection;
pConnection = NULL; pConnection = NULL;
} }
return pConnection; return pConnection;
} }
@ -682,6 +710,9 @@ bool TSocketClient::Request(CONNID id, const char* cmd)
{ {
TSocket_connection* conn = (TSocket_connection*)GetConnection(id); TSocket_connection* conn = (TSocket_connection*)GetConnection(id);
m_dwSize = 0; m_dwSize = 0;
if (m_nTimeout > 0)
conn->ReadTimeout((byte*)&m_dwSize, sizeof(m_dwSize), m_nTimeout);
else
conn->Read((byte*)&m_dwSize, sizeof(m_dwSize)); conn->Read((byte*)&m_dwSize, sizeof(m_dwSize));
ok = m_dwSize > 0; ok = m_dwSize > 0;
if (ok) if (ok)
@ -863,7 +894,7 @@ bool TSocketClient::HttpGetFile(CONNID id, const char* remote, const char* local
{ {
const int nchars = min(buf.size(), size - total); const int nchars = min(buf.size(), size - total);
cur_socket->read(buf.get_buffer(), nchars); cur_socket->read(buf.get_buffer(), nchars);
const int count = cur_socket->gcount(); const size_t count = (size_t)cur_socket->gcount();
if (count > 0) if (count > 0)
{ {
total += count; total += count;
@ -879,7 +910,7 @@ bool TSocketClient::HttpGetFile(CONNID id, const char* remote, const char* local
{ {
const int nchars = min(buf.size(), size - total); const int nchars = min(buf.size(), size - total);
cur_socket->read(buf.get_buffer(), nchars); cur_socket->read(buf.get_buffer(), nchars);
const int count = cur_socket->gcount(); const size_t count = (size_t)cur_socket->gcount();
if (count > 0) if (count > 0)
{ {
outfile.write(buf, count); outfile.write(buf, count);
@ -900,7 +931,7 @@ bool TSocketClient::HttpGetFile(CONNID id, const char* remote, const char* local
while (!cur_socket->eof() && !pi.iscancelled()) while (!cur_socket->eof() && !pi.iscancelled())
{ {
cur_socket->read(buf.get_buffer(), buf.size()); cur_socket->read(buf.get_buffer(), buf.size());
const int count = cur_socket->gcount(); const size_t count = (size_t)cur_socket->gcount();
if (count > 0) if (count > 0)
{ {
outfile.write(buf, count); outfile.write(buf, count);
@ -1068,7 +1099,7 @@ bool TSocketClient::HttpPostFile(CONNID id, const char* remote, const char* loca
while (!input.eof()) while (!input.eof())
{ {
input.read(buf.get_buffer(), buf.size()); input.read(buf.get_buffer(), buf.size());
const size_t count = input.gcount(); const size_t count = (size_t)input.gcount();
if (count > 0) if (count > 0)
{ {
skstream* cur_socket = conn->GetSocket(); skstream* cur_socket = conn->GetSocket();
@ -1187,8 +1218,8 @@ bool TSocketClient::FtpSendFile(CONNID id, const char* remote, const char* local
ifstream input(local, ios::binary); ifstream input(local, ios::binary);
while (!input.eof()) while (!input.eof())
{ {
input.read(response.get_buffer(), 1024*4); input.read(response.get_buffer(4096), 4096);
const size_t count = input.gcount(); const size_t count = (size_t)input.gcount();
if (count > 0) if (count > 0)
{ {
outstream.sync(); outstream.sync();

View File

@ -34,6 +34,7 @@ class TSocketClient : public TLanClient
{ {
byte* m_pData; byte* m_pData;
size_t m_dwSize; size_t m_dwSize;
int m_nTimeout;
protected: // TLanClient protected: // TLanClient
virtual TConnection* OnQueryConnection(const char* service, const char* server); virtual TConnection* OnQueryConnection(const char* service, const char* server);
@ -56,6 +57,8 @@ public:
bool HttpPutFile(CONNID id, const char* remote, const char* local); bool HttpPutFile(CONNID id, const char* remote, const char* local);
bool FtpSendFile(CONNID id, const char* remote, const char* local, const char* user, const char* pass); bool FtpSendFile(CONNID id, const char* remote, const char* local, const char* user, const char* pass);
int Timeout() const { return m_nTimeout; }
void SetTimeout(int sec) { m_nTimeout= sec; }
TSocketClient(); TSocketClient();
virtual ~TSocketClient(); virtual ~TSocketClient();
}; };

View File

@ -9,8 +9,7 @@ inline char match(char c)
{ return (c == '{') ? '}' : c; } { return (c == '{') ? '}' : c; }
TScanner::TScanner(const char* filename) TScanner::TScanner(const char* filename)
: _token(128), _key(2), : _token(128), _key(2), _tmp(1024*8), _pushed(false), _line(0)
_tmp(1024*8), _pushed(false), _line(0)
{ {
open(filename, ios::in); open(filename, ios::in);