mirror of https://github.com/BOINC/boinc.git
confirm before connecting
svn path=/trunk/boinc/; revision=762
This commit is contained in:
parent
106bad3219
commit
4bbcedddd5
|
@ -21,38 +21,117 @@
|
||||||
#include <winsock.h>
|
#include <winsock.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <wininet.h>
|
||||||
|
#include <raserror.h>
|
||||||
|
|
||||||
#include "win_net.h"
|
#include "win_net.h"
|
||||||
|
#include "wingui.h"
|
||||||
|
#include "client_state.h"
|
||||||
|
|
||||||
|
#define CONFIRM_WAIT 60 // seconds after user says not to connect to ask again
|
||||||
|
#define CLOSE_WAIT 5 // seconds after last call to close that the connection should be terminated
|
||||||
|
|
||||||
|
int net_ref_count = -1; // -1 closed, 0 open but not used, >0 number of users
|
||||||
|
double net_last_req_time = 0; // last time user was requested to connect in seconds
|
||||||
|
double net_close_time = 0; // 0 don't close, >0 time when network connection should be terminated in seconds
|
||||||
|
bool dialed = false;
|
||||||
|
|
||||||
int NetOpen( void )
|
int NetOpen( void )
|
||||||
{
|
{
|
||||||
|
if(net_ref_count >= 0) {
|
||||||
|
net_ref_count ++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
WSADATA wsdata;
|
WSADATA wsdata;
|
||||||
WORD wVersionRequested;
|
WORD wVersionRequested;
|
||||||
int rc, addrlen = 16;
|
int rc, addrlen = 16;
|
||||||
|
|
||||||
// TODO: return if already open
|
if(gstate.global_prefs.confirm_before_connecting) {
|
||||||
|
if((double)time(NULL) < net_last_req_time + CONFIRM_WAIT) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
net_last_req_time = (double)time(NULL);
|
||||||
|
if(!RequestNetConnect()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Handle permission logic here
|
typedef BOOL (WINAPI *GetStateProc)( OUT LPDWORD lpdwFlags, IN DWORD dwReserved);
|
||||||
|
typedef BOOL (WINAPI *AutoDialProc)( IN DWORD dwFlags, IN DWORD dwReserved);
|
||||||
|
|
||||||
wVersionRequested = MAKEWORD(1,1);
|
GetStateProc GetState = NULL;
|
||||||
rc = WSAStartup(wVersionRequested, &wsdata);
|
AutoDialProc AutoDial = NULL;
|
||||||
|
DWORD connectionFlags;
|
||||||
|
HMODULE libmodule = NULL;
|
||||||
|
|
||||||
if (rc)
|
libmodule = LoadLibrary("wininet.dll");
|
||||||
{
|
if (libmodule) {
|
||||||
//printf("WSAStartup failed: error code = %d\n", rc);
|
GetState = (GetStateProc)GetProcAddress(libmodule, "InternetGetConnectedState");
|
||||||
return -1; //CANT_CONNECT;
|
AutoDial = (AutoDialProc)GetProcAddress(libmodule, "InternetAutodial");
|
||||||
}
|
|
||||||
|
|
||||||
|
if (GetState && AutoDial) {
|
||||||
|
rc = (*GetState)(&connectionFlags, 0);
|
||||||
|
|
||||||
|
// Don't Autodial if already connected to Internet by Modem or LAN
|
||||||
|
if (!rc) {
|
||||||
|
rc = (*AutoDial)(INTERNET_AUTODIAL_FORCE_UNATTENDED, 0);
|
||||||
|
if (rc) {
|
||||||
|
dialed = true;
|
||||||
|
} else {
|
||||||
|
// InternetAutodial() returns error 86 for some users
|
||||||
|
// and 668 for some other users, but a subsequent call
|
||||||
|
// to gethostbyname() or connect() autodials successfully.
|
||||||
|
// So (with one exception) we ignore failure returns
|
||||||
|
// from InternetAutodial() to work around this problem.
|
||||||
|
// Error 86 is "The specified Network Password is not correct."
|
||||||
|
// Error 668 is RAS Error "The connection dropped."
|
||||||
|
rc = GetLastError();
|
||||||
|
// Don't continue if busy signal, no answer or user cancelled
|
||||||
|
if (rc == ERROR_USER_DISCONNECTION) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wVersionRequested = MAKEWORD(1, 1);
|
||||||
|
rc = WSAStartup(wVersionRequested, &wsdata);
|
||||||
|
if (rc) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
net_ref_count = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NetClose( void )
|
void NetClose( void )
|
||||||
{
|
{
|
||||||
WSACleanup();
|
if(net_ref_count > 0) net_ref_count --;
|
||||||
|
if(net_ref_count == 0) {
|
||||||
|
net_close_time = (double)time(NULL) + CLOSE_WAIT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetCheck( void ) {
|
||||||
|
if(net_ref_count == 0 && net_close_time > 0 && net_close_time < (double)time(NULL)) {
|
||||||
|
WSACleanup();
|
||||||
|
|
||||||
|
typedef BOOL (WINAPI *HangupProc)(IN DWORD dwReserved);
|
||||||
|
HangupProc HangUp = NULL;
|
||||||
|
HMODULE libmodule = NULL;
|
||||||
|
|
||||||
|
// Hang up the modem if we dialed it
|
||||||
|
if (dialed && gstate.global_prefs.hangup_if_dialed) {
|
||||||
|
libmodule = LoadLibrary("wininet.dll");
|
||||||
|
if (libmodule) {
|
||||||
|
HangUp = (HangupProc)GetProcAddress(libmodule, "InternetAutodialHangup");
|
||||||
|
if (HangUp) int rc = (* HangUp)(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dialed = false;
|
||||||
|
net_ref_count = -1;
|
||||||
|
net_close_time = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,11 +13,15 @@
|
||||||
|
|
||||||
extern int NetOpen( void );
|
extern int NetOpen( void );
|
||||||
extern void NetClose( void );
|
extern void NetClose( void );
|
||||||
|
extern void NetCheck( void );
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* $Log$
|
* $Log$
|
||||||
|
* Revision 1.2 2002/12/18 20:20:04 eheien
|
||||||
|
* confirm before connecting
|
||||||
|
*
|
||||||
* Revision 1.1 2002/08/09 21:43:19 eheien
|
* Revision 1.1 2002/08/09 21:43:19 eheien
|
||||||
* Moved win files, fixed compile bugs, added user requestable quit.
|
* Moved win files, fixed compile bugs, added user requestable quit.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue