diff --git "a/dll/win32/wininet/internet.c" "b/dll/win32/wininet/internet.c" index a0444e07c3d..df893fffa27 100644 --- "a/dll/win32/wininet/internet.c" +++ "b/dll/win32/wininet/internet.c" @@ -87,13 +87,30 @@ static UINT_PTR handle_table_size; typedef struct { + DWORD flags; DWORD proxyEnabled; LPWSTR proxy; LPWSTR proxyBypass; LPWSTR proxyUsername; LPWSTR proxyPassword; + LPWSTR autoconf_url; } proxyinfo_t; +#define CONNECTION_SETTINGS_VERSION 0x46 +typedef struct { + DWORD version; + DWORD id; + DWORD flags; + BYTE data[1]; + /* DWORD proxy_server_len; */ + /* UTF8 proxy_server[proxy_server_len]; */ + /* DWORD bypass_list_len; */ + /* UTF8 bypass_list[bypass_list_len]; */ + /* DWORD configuration_script_len; */ + /* UTF8 configuration_script[configuration_script_len]; */ + /* DWORD unk[8]; set to 0 */ +} connection_settings; + static ULONG max_conns = 2, max_1_0_conns = 4; static ULONG connect_timeout = 60000; @@ -320,6 +337,48 @@ HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline) return S_OK; } +static void connection_settings_write( connection_settings *settings, DWORD *pos, DWORD size, const WCHAR *str ) +{ + int len = 0; + + if (str) + { + len = wcslen( str ); + len = WideCharToMultiByte( CP_UTF8, 0, str, len, settings ? (char*)settings->data + *pos + sizeof(len) : NULL, + settings ? size - *pos - sizeof(len) : 0, NULL, NULL ); + } + if (settings) + memcpy(settings->data + *pos, &len, sizeof(len)); + *pos += sizeof(len) + len; +} + +static LONG save_connection_settings( HKEY key, const WCHAR *connection, proxyinfo_t *lpwpi ) +{ + connection_settings *settings; + DWORD size = 0, pos = 0; + LONG ret; + + connection_settings_write( NULL, &size, 0, lpwpi->proxy ); + connection_settings_write( NULL, &size, 0, lpwpi->proxyBypass ); + connection_settings_write( NULL, &size, 0, lpwpi->autoconf_url ); + size += sizeof(DWORD) * 10; /* unknown fields */ + + settings = calloc( 1, FIELD_OFFSET(connection_settings, data[size]) ); + if (!settings) + return ERROR_OUTOFMEMORY; + + settings->version = CONNECTION_SETTINGS_VERSION; + settings->flags = lpwpi->flags; + connection_settings_write( settings, &pos, size, lpwpi->proxy ); + connection_settings_write( settings, &pos, size, lpwpi->proxyBypass ); + connection_settings_write( settings, &pos, size, lpwpi->autoconf_url ); + + ret = RegSetValueExW(key, connection, 0, REG_BINARY, (BYTE*)settings, + FIELD_OFFSET(connection_settings, data[size])); + free(settings); + return ret; +} + /*********************************************************************** * INTERNET_SaveProxySettings * @@ -330,12 +389,25 @@ HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline) */ static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi ) { - HKEY key; + HKEY key, con; LONG ret; if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key ))) return ret; + if ((ret = RegCreateKeyExW( key, L"Connections", 0, NULL, 0, KEY_WRITE, NULL, &con, NULL ))) + { + RegCloseKey( key ); + return ret; + } + ret = save_connection_settings( con, L"DefaultConnectionSettings", lpwpi ); + RegCloseKey( con ); + if (ret) + { + RegCloseKey( key ); + return ret; + } + if ((ret = RegSetValueExW( key, L"ProxyEnable", 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD)))) { RegCloseKey( key ); @@ -2538,7 +2610,7 @@ static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL u } case INTERNET_OPTION_PER_CONNECTION_OPTION: { - WCHAR *url; + WCHAR *url = NULL; INTERNET_PER_CONN_OPTION_LISTW *con = buffer; INTERNET_PER_CONN_OPTION_LISTA *conA = buffer; DWORD res = ERROR_SUCCESS, i; @@ -2560,7 +2632,8 @@ static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL u return ERROR_INSUFFICIENT_BUFFER; } - url = get_proxy_autoconfig_url(); + if (pi.flags & PROXY_TYPE_AUTO_DETECT) + url = get_proxy_autoconfig_url(); for (i = 0; i < con->dwOptionCount; i++) { INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i; @@ -2568,12 +2641,13 @@ static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL u switch (optionW->dwOption) { case INTERNET_PER_CONN_FLAGS: - if(pi.proxyEnabled) - optionW->Value.dwValue = PROXY_TYPE_PROXY; - else - optionW->Value.dwValue = PROXY_TYPE_DIRECT; - if (url) - /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */ + optionW->Value.dwValue = pi.flags; +// if(pi.proxyEnabled) +// optionW->Value.dwValue = PROXY_TYPE_PROXY; +// else +// optionW->Value.dwValue = PROXY_TYPE_DIRECT; +// if (url) +// /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */ optionW->Value.dwValue |= PROXY_TYPE_DIRECT|PROXY_TYPE_AUTO_PROXY_URL; break; @@ -2592,22 +2666,33 @@ static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL u break; case INTERNET_PER_CONN_AUTOCONFIG_URL: - if (!url) - optionW->Value.pszValue = NULL; - else if (unicode) - optionW->Value.pszValue = heap_strdupW(url); +// if (!url) +// optionW->Value.pszValue = NULL; +// else if (unicode) +// optionW->Value.pszValue = heap_strdupW(url); +// else +// optionA->Value.pszValue = heap_strdupWtoA(url); + if (unicode) + optionW->Value.pszValue = heap_strdupW(pi.autoconf_url); else - optionA->Value.pszValue = heap_strdupWtoA(url); + optionA->Value.pszValue = heap_strdupWtoA(pi.autoconf_url); break; case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS: optionW->Value.dwValue = AUTO_PROXY_FLAG_ALWAYS_DETECT; break; + case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL: + if (unicode) + optionW->Value.pszValue = heap_strdupW(url); + else + optionA->Value.pszValue = heap_strdupWtoA(url); + break; + case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL: case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS: case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME: - case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL: +// case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL: FIXME("Unhandled dwOption %d\n", optionW->dwOption); memset(&optionW->Value, 0, sizeof(optionW->Value)); break;