From 51257b9f61b32dcce59b9453c987fc7a73c2af39 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 25 Jul 2016 15:41:43 -0700 Subject: [PATCH] client (Win): add config option to not do proxy autodetect --- client/sysmon_win.cpp | 52 ++++++++++++++++++++++++++----------------- lib/proxy_info.cpp | 9 +++++--- lib/proxy_info.h | 6 ++++- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/client/sysmon_win.cpp b/client/sysmon_win.cpp index cec8e692a4..a201b9860d 100644 --- a/client/sysmon_win.cpp +++ b/client/sysmon_win.cpp @@ -179,7 +179,7 @@ static LRESULT CALLBACK WindowsMonitorSystemPowerWndProc( // PBT_APMBATTERYLOW // PBT_APMPOWERSTATUSCHANGE // PBT_APMOEMEVENT - // PBT_APMRESUMEAUTOMATIC + // PBT_APMRESUMEAUTOMATIC case WM_POWERBROADCAST: switch(wParam) { // System is preparing to suspend. This is valid on @@ -277,6 +277,7 @@ static DWORD WINAPI WindowsMonitorSystemPowerThread( LPVOID ) { } // Detect any proxy configuration settings automatically. +// static void windows_detect_autoproxy_settings() { if (log_flags.proxy_debug) { post_sysmon_msg("[proxy] automatic proxy check in progress"); @@ -332,7 +333,7 @@ static void windows_detect_autoproxy_settings() { // Trim string if more than one proxy is defined // proxy list is defined as: // ([=]["://"][":"]) - + // Find and erase first delimeter type. pos = proxy.find(';'); if (pos != -1 ) { @@ -424,14 +425,16 @@ int initialize_system_monitor(int /*argc*/, char** /*argv*/) { } } - // Create a window to receive system power events. + // Create a thread to receive system power events. + // g_hWindowsMonitorSystemPowerThread = CreateThread( NULL, 0, WindowsMonitorSystemPowerThread, NULL, 0, - NULL); + NULL + ); if (!g_hWindowsMonitorSystemPowerThread) { g_hWindowsMonitorSystemPowerThread = NULL; @@ -439,16 +442,20 @@ int initialize_system_monitor(int /*argc*/, char** /*argv*/) { } // Create a thread to handle proxy auto-detection. - g_hWindowsMonitorSystemProxyThread = CreateThread( - NULL, - 0, - WindowsMonitorSystemProxyThread, - NULL, - 0, - NULL); + // + if (!cc_config.no_autodetect) { + g_hWindowsMonitorSystemProxyThread = CreateThread( + NULL, + 0, + WindowsMonitorSystemProxyThread, + NULL, + 0, + NULL + ); - if (!g_hWindowsMonitorSystemProxyThread) { - g_hWindowsMonitorSystemProxyThread = NULL; + if (!g_hWindowsMonitorSystemProxyThread) { + g_hWindowsMonitorSystemProxyThread = NULL; + } } return 0; @@ -525,14 +532,17 @@ void WINAPI BOINCServiceMain(DWORD /*dwArgc*/, LPTSTR * /*lpszArgv*/) { // register our service control handler: // sshStatusHandle = RegisterServiceCtrlHandler( TEXT(SZSERVICENAME), BOINCServiceCtrl); - if (!sshStatusHandle) + if (!sshStatusHandle) { goto cleanup; + } if (!ReportStatus( SERVICE_RUNNING, // service state ERROR_SUCCESS, // exit code - 0)) // wait hint + 0) // wait hint + ){ goto cleanup; + } dwErr = boinc_main_loop(); @@ -638,10 +648,11 @@ BOOL ReportStatus( static DWORD dwCheckPoint = 1; BOOL fResult = TRUE; - if (dwCurrentState == SERVICE_START_PENDING) + if (dwCurrentState == SERVICE_START_PENDING) { ssStatus.dwControlsAccepted = 0; - else + } else { ssStatus.dwControlsAccepted = SERVICE_ACCEPTED_ACTIONS; + } ssStatus.dwCurrentState = dwCurrentState; ssStatus.dwWin32ExitCode = dwWin32ExitCode; @@ -745,7 +756,8 @@ VOID LogEventWarningMessage(LPTSTR lpszMsg) { 2, // strings in lpszStrings 0, // no bytes of raw data (LPCSTR*)lpszStrings, // array of error strings - NULL); // no raw data + NULL // no raw data + ); (VOID) DeregisterEventSource(hEventSource); } @@ -785,9 +797,9 @@ VOID LogEventInfoMessage(LPTSTR lpszMsg) { 2, // strings in lpszStrings 0, // no bytes of raw data (LPCSTR*)lpszStrings, // array of error strings - NULL); // no raw data + NULL // no raw data + ); (VOID) DeregisterEventSource(hEventSource); } } - diff --git a/lib/proxy_info.cpp b/lib/proxy_info.cpp index 814dd433ec..9bde56016b 100644 --- a/lib/proxy_info.cpp +++ b/lib/proxy_info.cpp @@ -42,6 +42,7 @@ int PROXY_INFO::parse(XML_PARSER& xp) { if (xp.parse_str("http_user_name", http_user_name,sizeof(http_user_name))) continue; if (xp.parse_str("http_user_passwd", http_user_passwd,sizeof(http_user_passwd))) continue; if (xp.parse_str("no_proxy", noproxy_hosts, sizeof(noproxy_hosts))) continue; + if (xp.parse_bool("no_autodetect", no_autodetect)) continue; } return ERR_XML_PARSE; } @@ -74,7 +75,8 @@ int PROXY_INFO::write(MIOFILE& out) { " %s\n" " %s\n" " %s\n" - " %s\n", + " %s\n" + " %d\n", use_http_proxy?" \n":"", use_socks_proxy?" \n":"", use_http_auth?" \n":"", @@ -86,7 +88,8 @@ int PROXY_INFO::write(MIOFILE& out) { s5up, hun, hup, - noproxy_hosts + noproxy_hosts, + no_autodetect?1:0 ); if (strlen(autodetect_server_name)) { out.printf( @@ -119,6 +122,7 @@ void PROXY_INFO::clear() { safe_strcpy(http_user_name, ""); safe_strcpy(http_user_passwd, ""); safe_strcpy(noproxy_hosts, ""); + no_autodetect = false; safe_strcpy(autodetect_server_name, ""); autodetect_proxy_supported = false; need_autodetect_proxy_settings = false; @@ -126,4 +130,3 @@ void PROXY_INFO::clear() { autodetect_port = 80; autodetect_protocol = 0; } - diff --git a/lib/proxy_info.h b/lib/proxy_info.h index e6b78a3527..a82d161755 100644 --- a/lib/proxy_info.h +++ b/lib/proxy_info.h @@ -50,12 +50,16 @@ struct PROXY_INFO { // char noproxy_hosts[256]; + // don't autodetect proxy (Win) + // + bool no_autodetect; + // On Windows, if neither HTTP nor SOCKS proxy is specified, // we try the "autodetect" mechanism. // If it gets anything, the info is filled in below // bool autodetect_proxy_supported; - // if true, some mechinism for detecting proxy servers is + // if true, some mechanism for detecting proxy servers is // supported by the client. int autodetect_protocol; // URL_PROTOCOL_SOCKS, URL_PROTOCOL_HTTP, or URL_PROTOCOL_HTTPS