ReactOS 0.4.15-dev-7705-g2320c37
connections.c
Go to the documentation of this file.
1/*
2 * Copyright 2018 Piotr Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 *
18 */
19
20#include <stdarg.h>
21#include <windef.h>
22#include <winbase.h>
23#include <winnls.h>
24#include <wininet.h>
25#include <winuser.h>
26#include <winreg.h>
27
28#include "inetcpl.h"
29#include "wine/debug.h"
30#include "wine/heap.h"
31
33
34static const WCHAR auto_config_url[] = {'A','u','t','o','C','o','n','f','i','g','U','R','L',0};
35static const WCHAR internet_settings[] = {'S','o','f','t','w','a','r','e','\\',
36 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
37 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
38 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
39static const WCHAR proxy_enable[] = {'P','r','o','x','y','E','n','a','b','l','e',0};
40static const WCHAR proxy_server[] = {'P','r','o','x','y','S','e','r','v','e','r',0};
41static const WCHAR connections[] = {'C','o','n','n','e','c','t','i','o','n','s',0};
42static const WCHAR default_connection_settings[] = {'D','e','f','a','u','l','t',
43 'C','o','n','n','e','c','t','i','o','n','S','e','t','t','i','n','g','s',0};
44
46
47#define CONNECTION_SETTINGS_VERSION 0x46
48#define CONNECTION_SETTINGS_MANUAL_PROXY 0x2
49#define CONNECTION_SETTINGS_PAC_SCRIPT 0x4
50#define CONNECTION_SETTINGS_WPAD 0x8
51
52typedef struct {
57 /* DWORD proxy_server_len; */
58 /* UTF8 proxy_server[proxy_server_len]; */
59 /* DWORD bypass_list_len; */
60 /* UTF8 bypass_list[bypass_list_len]; */
61 /* DWORD configuration_script_len; */
62 /* UTF8 configuration_script[configuration_script_len]; */
63 /* DWORD unk[8]; set to 0 */
65
67 BOOL use_wpad, BOOL use_pac_script, const WCHAR *pac_url, connection_settings **ret)
68{
70 DWORD proxy_server_len;
71 DWORD pac_url_len;
72
73 size += sizeof(DWORD);
74 if(proxy_server)
75 {
76 proxy_server_len = WideCharToMultiByte(CP_UTF8, 0, proxy_server, -1,
77 NULL, 0, NULL, NULL);
78 if(!proxy_server_len) return 0;
79 proxy_server_len--;
80 }
81 else
82 proxy_server_len = 0;
83 size += proxy_server_len;
84 if(pac_url)
85 {
86 pac_url_len = WideCharToMultiByte(CP_UTF8, 0, pac_url, -1,
87 NULL, 0, NULL, NULL);
88 if(!pac_url_len) return 0;
89 pac_url_len--;
90 }
91 else
92 pac_url_len = 0;
93 size += sizeof(DWORD)*10;
94
95 *ret = heap_alloc_zero(size);
96 if(!*ret) return 0;
97
98 (*ret)->version = CONNECTION_SETTINGS_VERSION;
99 (*ret)->flags = 1;
100 if(manual_proxy) (*ret)->flags |= CONNECTION_SETTINGS_MANUAL_PROXY;
101 if(use_pac_script) (*ret)->flags |= CONNECTION_SETTINGS_PAC_SCRIPT;
102 if(use_wpad) (*ret)->flags |= CONNECTION_SETTINGS_WPAD;
103 ((DWORD*)(*ret)->data)[0] = proxy_server_len;
104 pos = sizeof(DWORD);
105 if(proxy_server_len)
106 {
108 (char*)(*ret)->data+pos, proxy_server_len, NULL, NULL);
109 pos += proxy_server_len;
110 }
111 pos += sizeof(DWORD); /* skip proxy bypass list */
112 ((DWORD*)((*ret)->data+pos))[0] = pac_url_len;
113 pos += sizeof(DWORD);
114 if(pac_url_len)
115 {
116 WideCharToMultiByte(CP_UTF8, 0, pac_url, -1,
117 (char*)(*ret)->data+pos, pac_url_len, NULL, NULL);
118 pos += pac_url_len;
119 }
120 return size;
121}
122
124{
128 HKEY hkey, con;
129 LONG res;
130
136
138 if(res)
139 return;
140
141 size = sizeof(enabled);
143 if(res || type != REG_DWORD)
144 enabled = 0;
145 size = sizeof(address);
147 if(res || type != REG_SZ)
148 address[0] = 0;
149 size = sizeof(pac_url);
150 res = RegQueryValueExW(hkey, auto_config_url, NULL, &type, (BYTE*)pac_url, &size);
151 if(res || type != REG_SZ)
152 pac_url[0] = 0;
153
154 res = RegOpenKeyW(hkey, connections, &con);
155 RegCloseKey(hkey);
156 if(!res)
157 {
159 size = 0;
160
163 {
165 if(!new_settings)
166 {
167 RegCloseKey(con);
169 return;
170 }
171 settings = new_settings;
172 }
173 RegCloseKey(con);
174
175 if(!res && type == REG_BINARY)
176 {
178 FIXME("unexpected structure version (%x)\n", settings->version);
179 else if(settings->flags & CONNECTION_SETTINGS_WPAD)
181 }
183 }
184
185 TRACE("ProxyEnable = %x\n", enabled);
186 TRACE("ProxyServer = %s\n", wine_dbgstr_w(address));
187 TRACE("AutoConfigURL = %s\n", wine_dbgstr_w(auto_config_url));
188
189 if(enabled)
190 {
194 }
195
196 port = wcschr(address, ':');
197 if(port)
198 {
199 *port = 0;
200 port++;
201 }
203 if(port)
205
206 if(pac_url[0])
207 {
211 }
212
213 return;
214}
215
217{
218 BOOL checked;
219
220 switch (wparam)
221 {
225 break;
230 }
231
232 switch (wparam)
233 {
234 case IDC_USE_WPAD:
242 return TRUE;
243 }
244
245 return FALSE;
246}
247
249{
250 connection_settings *default_connection;
253 PSHNOTIFY *psn = (PSHNOTIFY*)lparam;
254 DWORD proxy_len, port_len, pac_script_len;
255 DWORD use_proxy, use_pac_script, use_wpad, size;
256 LRESULT res;
257 HKEY hkey, con;
258
259 if(psn->hdr.code != PSN_APPLY)
260 return FALSE;
261
263 if(res)
264 return FALSE;
265
268 (BYTE*)&use_proxy, sizeof(use_proxy));
269 if(res)
270 {
271 RegCloseKey(hkey);
272 return FALSE;
273 }
274 TRACE("ProxyEnable set to %x\n", use_proxy);
275
277 if(proxy_len)
278 {
279 proxy[proxy_len++] = ':';
280 port_len = GetDlgItemTextW(hwnd, IDC_EDIT_PROXY_PORT, proxy+proxy_len,
281 ARRAY_SIZE(proxy)-proxy_len);
282 if(!port_len)
283 {
284 proxy[proxy_len++] = '8';
285 proxy[proxy_len++] = '0';
286 proxy[proxy_len] = 0;
287 }
288
290 (BYTE*)proxy, (proxy_len+port_len)*sizeof(WCHAR));
291 }
292 else
293 {
297 }
298 if(res)
299 {
300 RegCloseKey(hkey);
301 return FALSE;
302 }
303 TRACE("ProxtServer set to %s\n", wine_dbgstr_w(proxy));
304
305 use_pac_script = IsDlgButtonChecked(hwnd, IDC_USE_PAC_SCRIPT);
306 pac_script_len = GetDlgItemTextW(hwnd, IDC_EDIT_PAC_SCRIPT,
308 if(!pac_script_len) use_pac_script = FALSE;
309 if(use_pac_script)
310 {
312 (BYTE*)pac_script, pac_script_len*sizeof(WCHAR));
313 }
314 else
315 {
319 }
320 if(res)
321 {
322 RegCloseKey(hkey);
323 return FALSE;
324 }
325 TRACE("AutoConfigURL set to %s\n", wine_dbgstr_w(use_pac_script ? pac_script : NULL));
326
328
329 res = RegCreateKeyExW(hkey, connections, 0, NULL, 0, KEY_WRITE, NULL, &con, NULL);
330 RegCloseKey(hkey);
331 if(res)
332 return FALSE;
333
334 size = create_connection_settings(use_proxy, proxy, use_wpad,
335 use_pac_script, pac_script, &default_connection);
336 if(!size)
337 {
338 RegCloseKey(con);
339 return FALSE;
340 }
341
343 (BYTE*)default_connection, size);
344 heap_free(default_connection);
345 RegCloseKey(con);
346 return !res;
347}
348
350{
351 switch (msg)
352 {
353 case WM_INITDIALOG:
356 break;
357 case WM_COMMAND:
359 case WM_NOTIFY:
361 }
362 return FALSE;
363}
struct mke2fs_defaults settings[]
@ lparam
Definition: SystemMenu.c:31
@ wparam
Definition: SystemMenu.c:30
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:71
#define msg(x)
Definition: auth_time.c:54
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:33
#define FIXME(fmt,...)
Definition: debug.h:111
#define RegCloseKey(hKey)
Definition: registry.h:49
static const WCHAR auto_config_url[]
Definition: connections.c:34
static INT_PTR connections_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
Definition: connections.c:248
#define CONNECTION_SETTINGS_VERSION
Definition: connections.c:47
static const WCHAR connections[]
Definition: connections.c:41
static const WCHAR proxy_enable[]
Definition: connections.c:39
#define CONNECTION_SETTINGS_WPAD
Definition: connections.c:50
#define CONNECTION_SETTINGS_PAC_SCRIPT
Definition: connections.c:49
static void connections_on_initdialog(HWND hwnd)
Definition: connections.c:123
static BOOL initdialog_done
Definition: connections.c:45
#define CONNECTION_SETTINGS_MANUAL_PROXY
Definition: connections.c:48
static const WCHAR default_connection_settings[]
Definition: connections.c:42
static const WCHAR internet_settings[]
Definition: connections.c:35
static DWORD create_connection_settings(BOOL manual_proxy, const WCHAR *proxy_server, BOOL use_wpad, BOOL use_pac_script, const WCHAR *pac_url, connection_settings **ret)
Definition: connections.c:66
INT_PTR CALLBACK connections_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Definition: connections.c:349
static INT_PTR connections_on_command(HWND hwnd, WPARAM wparam)
Definition: connections.c:216
static const WCHAR proxy_server[]
Definition: connections.c:40
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3297
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4911
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2361
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4132
#define wcschr
Definition: compat.h:17
#define CALLBACK
Definition: compat.h:35
#define WideCharToMultiByte
Definition: compat.h:111
USHORT port
Definition: uri.c:228
#define INTERNET_MAX_URL_LENGTH
Definition: session.c:1418
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
int proxy
Definition: main.c:67
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
GLuint res
Definition: glext.h:9613
GLuint address
Definition: glext.h:9393
#define IDC_EDIT_PROXY_PORT
Definition: inetcpl.h:101
#define IDC_EDIT_PAC_SCRIPT
Definition: inetcpl.h:98
#define IDC_USE_PAC_SCRIPT
Definition: inetcpl.h:97
#define IDC_EDIT_PROXY_SERVER
Definition: inetcpl.h:100
#define IDC_USE_PROXY_SERVER
Definition: inetcpl.h:99
#define IDC_USE_WPAD
Definition: inetcpl.h:96
#define wine_dbgstr_w
Definition: kernel32.h:34
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
unsigned int UINT
Definition: ndis.h:50
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_WRITE
Definition: nt_native.h:1031
#define DWORD
Definition: nt_native.h:44
long LONG
Definition: pedump.c:60
#define PSM_CHANGED
Definition: prsht.h:164
#define PSN_APPLY
Definition: prsht.h:117
#define WM_NOTIFY
Definition: richedit.h:61
#define REG_DWORD
Definition: sdbapi.c:596
#define CP_UTF8
Definition: nls.h:20
#define TRACE(s)
Definition: solgame.cpp:4
NMHDR hdr
Definition: prsht.h:330
UINT code
Definition: winuser.h:3158
int32_t INT_PTR
Definition: typedefs.h:64
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
int ret
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define MAKEWPARAM(l, h)
Definition: winuser.h:4008
#define EM_LIMITTEXT
Definition: winuser.h:1999
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define WM_COMMAND
Definition: winuser.h:1739
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1738
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HWND WINAPI GetParent(_In_ HWND)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BST_CHECKED
Definition: winuser.h:197
#define EN_CHANGE
Definition: winuser.h:2021
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193