ReactOS  0.4.14-dev-49-gfb4591c
connections.c
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Piotr cabna 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 <wininet.h>
24 #include <winuser.h>
25 #include <winreg.h>
26 
27 #include "inetcpl.h"
28 #include "wine/debug.h"
29 #include "wine/heap.h"
30 #include "wine/unicode.h"
31 
33 
34 static const WCHAR auto_config_url[] = {'A','u','t','o','C','o','n','f','i','g','U','R','L',0};
35 static 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};
39 static const WCHAR proxy_enable[] = {'P','r','o','x','y','E','n','a','b','l','e',0};
40 static const WCHAR proxy_server[] = {'P','r','o','x','y','S','e','r','v','e','r',0};
41 static const WCHAR connections[] = {'C','o','n','n','e','c','t','i','o','n','s',0};
42 static 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 
52 typedef struct {
56  BYTE data[1];
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  {
164  connection_settings *new_settings = heap_realloc(settings, size);
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  {
177  if(settings->version != CONNECTION_SETTINGS_VERSION)
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 = strchrW(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  {
222  case IDC_USE_PAC_SCRIPT:
225  break;
230  }
231 
232  switch (wparam)
233  {
234  case IDC_USE_WPAD:
235  case IDC_USE_PAC_SCRIPT:
240  if(initdialog_done)
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  {
296  res = ERROR_SUCCESS;
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  {
318  res = ERROR_SUCCESS;
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 
327  use_wpad = IsDlgButtonChecked(hwnd, IDC_USE_WPAD);
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 }
#define EM_LIMITTEXT
Definition: winuser.h:1982
struct mke2fs_defaults settings[]
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
WINE_DEFAULT_DEBUG_CHANNEL(inetcpl)
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2208
int proxy
Definition: main.c:67
#define TRUE
Definition: types.h:120
#define IDC_USE_WPAD
Definition: inetcpl.h:96
static const WCHAR internet_settings[]
Definition: connections.c:35
#define MAKEWPARAM(l, h)
Definition: winuser.h:3948
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
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
#define REG_BINARY
Definition: nt_native.h:1496
#define CONNECTION_SETTINGS_VERSION
Definition: connections.c:47
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define CALLBACK
Definition: compat.h:27
#define IDC_USE_PAC_SCRIPT
Definition: inetcpl.h:97
static const WCHAR default_connection_settings[]
Definition: connections.c:42
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
UINT_PTR WPARAM
Definition: windef.h:207
#define PSN_APPLY
Definition: prsht.h:117
int32_t INT_PTR
Definition: typedefs.h:62
#define DWORD
Definition: nt_native.h:44
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
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:1091
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
UINT code
Definition: winuser.h:3133
NMHDR hdr
Definition: prsht.h:312
#define CONNECTION_SETTINGS_WPAD
Definition: connections.c:50
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define CP_UTF8
Definition: nls.h:20
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define IDC_EDIT_PAC_SCRIPT
Definition: inetcpl.h:98
static UINT WPARAM LPARAM lparam
Definition: combo.c:716
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3296
#define FIXME(fmt,...)
Definition: debug.h:110
static const WCHAR connections[]
Definition: connections.c:41
smooth NULL
Definition: ftsmooth.c:416
#define INTERNET_MAX_URL_LENGTH
Definition: session.c:1380
LONG_PTR LPARAM
Definition: windef.h:208
#define IDC_EDIT_PROXY_PORT
Definition: inetcpl.h:101
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define KEY_WRITE
Definition: nt_native.h:1031
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:4895
#define TRACE(s)
Definition: solgame.cpp:4
INT_PTR CALLBACK connections_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Definition: connections.c:349
GLsizeiptr size
Definition: glext.h:5919
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint address
Definition: glext.h:9393
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int ret
unsigned char BYTE
Definition: mem.h:68
static BOOL initdialog_done
Definition: connections.c:45
static const WCHAR proxy_enable[]
Definition: connections.c:39
static INT_PTR connections_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
Definition: connections.c:248
#define WM_COMMAND
Definition: winuser.h:1722
#define ERROR_MORE_DATA
Definition: dderror.h:13
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HWND WINAPI GetParent(_In_ HWND)
#define IDC_EDIT_PROXY_SERVER
Definition: inetcpl.h:100
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2355
#define CONNECTION_SETTINGS_PAC_SCRIPT
Definition: connections.c:49
#define ARRAY_SIZE(a)
Definition: main.h:24
static void connections_on_initdialog(HWND hwnd)
Definition: connections.c:123
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static INT_PTR connections_on_command(HWND hwnd, WPARAM wparam)
Definition: connections.c:216
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int UINT
Definition: ndis.h:50
#define PSM_CHANGED
Definition: prsht.h:164
#define BST_CHECKED
Definition: winuser.h:197
static const WCHAR proxy_server[]
Definition: connections.c:40
#define msg(x)
Definition: auth_time.c:54
GLuint res
Definition: glext.h:9613
#define IDC_USE_PROXY_SERVER
Definition: inetcpl.h:99
LONG_PTR LRESULT
Definition: windef.h:209
USHORT port
Definition: uri.c:227
#define REG_DWORD
Definition: sdbapi.c:596
#define WM_INITDIALOG
Definition: winuser.h:1721
#define CONNECTION_SETTINGS_MANUAL_PROXY
Definition: connections.c:48
#define WM_NOTIFY
Definition: richedit.h:61
static const WCHAR auto_config_url[]
Definition: connections.c:34
static UINT WPARAM wparam
Definition: combo.c:716
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
#define REG_SZ
Definition: layer.c:22
#define EN_CHANGE
Definition: winuser.h:2004