From 742b7b71682f7f51e4645743a753daa699549719 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 17 Feb 2010 12:15:28 +0000 Subject: [PATCH] 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 --- include/dongle.cpp | 24 ++++++++++++------ include/isamrpc.cpp | 41 ++++++++++++++++++++++++++++++ include/isamrpc.h | 5 +--- include/netsock.cpp | 61 ++++++++++++++++++++++++++++++++++----------- include/netsock.h | 3 +++ include/scanner.cpp | 3 +-- 6 files changed, 108 insertions(+), 29 deletions(-) diff --git a/include/dongle.cpp b/include/dongle.cpp index afd992ed2..579790b1c 100755 --- a/include/dongle.cpp +++ b/include/dongle.cpp @@ -432,23 +432,31 @@ bool TDongle::network_login(bool test_all_keys) if (network() && ok()) rpc_UserLogout(appname); - TConfig ini(CONFIG_INSTALL, "Server"); - const char* server = ini.get("Dongle"); + TString server = "127.0.0.1"; + if (!xvt_sys_dongle_server_is_running()) + server = ini_get_string(CONFIG_INSTALL, "Server", "Dongle"); + // const char* guest = "******"; // const TString16 appname = main_app().name(); // const char* utente = (!main_app().is_running() && appname == "ba0100") ? guest : (const char *) user(); const char* utente = user(); - const bool ok = rpc_UserLogin(server, utente, "******", appname); + bool ok = rpc_UserLogin(server, utente, "******", appname); if (ok) - { + { _hardware = _dongle_network; _type = _user_dongle; - _serno = rpc_DongleNumber(); _max_users = 1; _last_update = TDate(TODAY); - _year_assist = rpc_DongleYear(); - rpc_DongleModules(_module); + + // Let's try to spare some network band! + ok = rpc_DongleInfo(_serno, _year_assist, _module); + if (!ok) + { + _serno = rpc_DongleNumber(); + _year_assist = rpc_DongleYear(); + ok = rpc_DongleModules(_module); + } } return ok; } @@ -720,7 +728,7 @@ const TString& TDongle::short_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"); TString& tmp = get_tmp_string(32); diff --git a/include/isamrpc.cpp b/include/isamrpc.cpp index 7a81a8f32..72f43a768 100755 --- a/include/isamrpc.cpp +++ b/include/isamrpc.cpp @@ -42,6 +42,15 @@ bool rpc_Call(const char* cmd) 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) { CHECK(_connection, "Server not connected"); @@ -206,6 +215,38 @@ unsigned rpc_DongleYear() 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) { const int BASE = 19; diff --git a/include/isamrpc.h b/include/isamrpc.h index 96f6d7f0b..6a896db93 100755 --- a/include/isamrpc.h +++ b/include/isamrpc.h @@ -1,10 +1,6 @@ #ifndef __ISAMRPC_H #define __ISAMRPC_H -#ifndef __ARRAY_H -#include -#endif - #ifndef __REAL_H #include #endif @@ -16,6 +12,7 @@ bool rpc_DongleHasModule(word af); bool rpc_DongleModules(TBit_array& ba); unsigned rpc_DongleNumber(); unsigned rpc_DongleYear(); +bool rpc_DongleInfo(word& number, word& year, TBit_array& ba); bool rpc_UserLogin(const char* server, const char* user, const char* password, const char* application); diff --git a/include/netsock.cpp b/include/netsock.cpp index d0800eafc..1451a0f01 100755 --- a/include/netsock.cpp +++ b/include/netsock.cpp @@ -523,13 +523,14 @@ protected: bool connect(); public: - const TString & Server() const { return _server; } + const TString& Server() const { return _server; } virtual bool Execute(const char* cmd); bool WriteLine(const char* cmd); bool ReadLine(TString& str); bool Read(byte* buf, size_t size); - + bool ReadTimeout(byte* buf, size_t size, int timeout); + skstream* GetSocket(); TSocket_connection(TLanManager* lm, const char* service, const char* server); @@ -572,8 +573,9 @@ bool TSocket_connection::ReadLine(TString& str) bool ok = calza != NULL; if (ok) { - char *buf = str.get_buffer(4096); - calza->getline(buf, str.size(), '\n'); + char buf[4096]; memset(buf, 0, sizeof(buf)); + calza->getline(buf, sizeof(buf)-1, '\n'); + str = buf; } return ok; } @@ -584,12 +586,40 @@ bool TSocket_connection::Read(byte* buf, size_t size) bool ok = calza != NULL; if (ok) { - calza->read((char *)buf, size); + calza->read((char*)buf, size); ok = calza->good() != 0; } 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() { if (_socket != NULL) @@ -645,7 +675,7 @@ TSocket_connection::~TSocket_connection() } TSocketClient::TSocketClient() - : m_pData(NULL), m_dwSize(0) + : m_pData(NULL), m_dwSize(0), m_nTimeout(0) { } TSocketClient::~TSocketClient() @@ -662,8 +692,6 @@ TConnection* TSocketClient::OnQueryConnection(const char* service, const char* s delete pConnection; pConnection = NULL; } - - return pConnection; } @@ -682,7 +710,10 @@ bool TSocketClient::Request(CONNID id, const char* cmd) { TSocket_connection* conn = (TSocket_connection*)GetConnection(id); m_dwSize = 0; - conn->Read((byte*)&m_dwSize, sizeof(m_dwSize)); + if (m_nTimeout > 0) + conn->ReadTimeout((byte*)&m_dwSize, sizeof(m_dwSize), m_nTimeout); + else + conn->Read((byte*)&m_dwSize, sizeof(m_dwSize)); ok = m_dwSize > 0; 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); 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) { 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); 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) { 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()) { 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) { outfile.write(buf, count); @@ -1068,7 +1099,7 @@ bool TSocketClient::HttpPostFile(CONNID id, const char* remote, const char* loca while (!input.eof()) { input.read(buf.get_buffer(), buf.size()); - const size_t count = input.gcount(); + const size_t count = (size_t)input.gcount(); if (count > 0) { 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); while (!input.eof()) { - input.read(response.get_buffer(), 1024*4); - const size_t count = input.gcount(); + input.read(response.get_buffer(4096), 4096); + const size_t count = (size_t)input.gcount(); if (count > 0) { outstream.sync(); diff --git a/include/netsock.h b/include/netsock.h index 83c678a68..192d43d04 100755 --- a/include/netsock.h +++ b/include/netsock.h @@ -34,6 +34,7 @@ class TSocketClient : public TLanClient { byte* m_pData; size_t m_dwSize; + int m_nTimeout; protected: // TLanClient 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 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(); virtual ~TSocketClient(); }; diff --git a/include/scanner.cpp b/include/scanner.cpp index 8a0b19fae..e8590f79a 100755 --- a/include/scanner.cpp +++ b/include/scanner.cpp @@ -9,8 +9,7 @@ inline char match(char c) { return (c == '{') ? '}' : c; } TScanner::TScanner(const char* filename) -: _token(128), _key(2), - _tmp(1024*8), _pushed(false), _line(0) + : _token(128), _key(2), _tmp(1024*8), _pushed(false), _line(0) { open(filename, ios::in);