2 * Copyright 2018 Piotr Caban for CodeWeavers
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.
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.
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
29 #include "wine/debug.h"
30 #include "wine/heap.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(inetcpl
);
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};
45 static BOOL initdialog_done
;
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
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 */
64 } connection_settings
;
66 static DWORD
create_connection_settings(BOOL manual_proxy
, const WCHAR
*proxy_server
,
67 BOOL use_wpad
, BOOL use_pac_script
, const WCHAR
*pac_url
, connection_settings
**ret
)
69 DWORD size
= FIELD_OFFSET(connection_settings
, data
), pos
;
70 DWORD proxy_server_len
;
73 size
+= sizeof(DWORD
);
76 proxy_server_len
= WideCharToMultiByte(CP_UTF8
, 0, proxy_server
, -1,
78 if(!proxy_server_len
) return 0;
83 size
+= proxy_server_len
;
86 pac_url_len
= WideCharToMultiByte(CP_UTF8
, 0, pac_url
, -1,
88 if(!pac_url_len
) return 0;
93 size
+= sizeof(DWORD
)*10;
95 *ret
= heap_alloc_zero(size
);
98 (*ret
)->version
= CONNECTION_SETTINGS_VERSION
;
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
;
107 WideCharToMultiByte(CP_UTF8
, 0, proxy_server
, -1,
108 (char*)(*ret
)->data
+pos
, proxy_server_len
, NULL
, NULL
);
109 pos
+= proxy_server_len
;
111 pos
+= sizeof(DWORD
); /* skip proxy bypass list */
112 ((DWORD
*)((*ret
)->data
+pos
))[0] = pac_url_len
;
113 pos
+= sizeof(DWORD
);
116 WideCharToMultiByte(CP_UTF8
, 0, pac_url
, -1,
117 (char*)(*ret
)->data
+pos
, pac_url_len
, NULL
, NULL
);
123 static void connections_on_initdialog(HWND hwnd
)
125 DWORD type
, size
, enabled
;
126 WCHAR address
[INTERNET_MAX_URL_LENGTH
], *port
;
127 WCHAR pac_url
[INTERNET_MAX_URL_LENGTH
];
131 SendMessageW(GetDlgItem(hwnd
, IDC_EDIT_PAC_SCRIPT
),
132 EM_LIMITTEXT
, INTERNET_MAX_URL_LENGTH
, 0);
133 SendMessageW(GetDlgItem(hwnd
, IDC_EDIT_PROXY_SERVER
),
134 EM_LIMITTEXT
, INTERNET_MAX_URL_LENGTH
-10, 0);
135 SendMessageW(GetDlgItem(hwnd
, IDC_EDIT_PROXY_PORT
), EM_LIMITTEXT
, 8, 0);
137 res
= RegOpenKeyW(HKEY_CURRENT_USER
, internet_settings
, &hkey
);
141 size
= sizeof(enabled
);
142 res
= RegQueryValueExW(hkey
, proxy_enable
, NULL
, &type
, (BYTE
*)&enabled
, &size
);
143 if(res
|| type
!= REG_DWORD
)
145 size
= sizeof(address
);
146 res
= RegQueryValueExW(hkey
, proxy_server
, NULL
, &type
, (BYTE
*)address
, &size
);
147 if(res
|| type
!= REG_SZ
)
149 size
= sizeof(pac_url
);
150 res
= RegQueryValueExW(hkey
, auto_config_url
, NULL
, &type
, (BYTE
*)pac_url
, &size
);
151 if(res
|| type
!= REG_SZ
)
154 res
= RegOpenKeyW(hkey
, connections
, &con
);
158 connection_settings
*settings
= NULL
;
161 while((res
= RegQueryValueExW(con
, default_connection_settings
, NULL
, &type
,
162 (BYTE
*)settings
, &size
)) == ERROR_MORE_DATA
|| !settings
)
164 connection_settings
*new_settings
= heap_realloc(settings
, size
);
171 settings
= new_settings
;
175 if(!res
&& type
== REG_BINARY
)
177 if(settings
->version
!= CONNECTION_SETTINGS_VERSION
)
178 FIXME("unexpected structure version (%x)\n", settings
->version
);
179 else if(settings
->flags
& CONNECTION_SETTINGS_WPAD
)
180 CheckDlgButton(hwnd
, IDC_USE_WPAD
, BST_CHECKED
);
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
));
191 CheckDlgButton(hwnd
, IDC_USE_PROXY_SERVER
, BST_CHECKED
);
192 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PROXY_SERVER
), TRUE
);
193 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PROXY_PORT
), TRUE
);
196 port
= wcschr(address
, ':');
202 SetDlgItemTextW(hwnd
, IDC_EDIT_PROXY_SERVER
, address
);
204 SetDlgItemTextW(hwnd
, IDC_EDIT_PROXY_PORT
, port
);
208 CheckDlgButton(hwnd
, IDC_USE_PAC_SCRIPT
, BST_CHECKED
);
209 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PAC_SCRIPT
), TRUE
);
210 SetDlgItemTextW(hwnd
, IDC_EDIT_PAC_SCRIPT
, pac_url
);
216 static INT_PTR
connections_on_command(HWND hwnd
, WPARAM wparam
)
222 case IDC_USE_PAC_SCRIPT
:
223 checked
= IsDlgButtonChecked(hwnd
, IDC_USE_PAC_SCRIPT
);
224 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PAC_SCRIPT
), checked
);
226 case IDC_USE_PROXY_SERVER
:
227 checked
= IsDlgButtonChecked(hwnd
, IDC_USE_PROXY_SERVER
);
228 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PROXY_SERVER
), checked
);
229 EnableWindow(GetDlgItem(hwnd
, IDC_EDIT_PROXY_PORT
), checked
);
235 case IDC_USE_PAC_SCRIPT
:
236 case IDC_USE_PROXY_SERVER
:
237 case MAKEWPARAM(IDC_EDIT_PAC_SCRIPT
, EN_CHANGE
):
238 case MAKEWPARAM(IDC_EDIT_PROXY_SERVER
, EN_CHANGE
):
239 case MAKEWPARAM(IDC_EDIT_PROXY_PORT
, EN_CHANGE
):
241 SendMessageW(GetParent(hwnd
), PSM_CHANGED
, (WPARAM
)hwnd
, 0);
248 static INT_PTR
connections_on_notify(HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
250 connection_settings
*default_connection
;
251 WCHAR proxy
[INTERNET_MAX_URL_LENGTH
];
252 WCHAR pac_script
[INTERNET_MAX_URL_LENGTH
];
253 PSHNOTIFY
*psn
= (PSHNOTIFY
*)lparam
;
254 DWORD proxy_len
, port_len
, pac_script_len
;
255 DWORD use_proxy
, use_pac_script
, use_wpad
, size
;
259 if(psn
->hdr
.code
!= PSN_APPLY
)
262 res
= RegOpenKeyW(HKEY_CURRENT_USER
, internet_settings
, &hkey
);
266 use_proxy
= IsDlgButtonChecked(hwnd
, IDC_USE_PROXY_SERVER
);
267 res
= RegSetValueExW(hkey
, proxy_enable
, 0, REG_DWORD
,
268 (BYTE
*)&use_proxy
, sizeof(use_proxy
));
274 TRACE("ProxyEnable set to %x\n", use_proxy
);
276 proxy_len
= GetDlgItemTextW(hwnd
, IDC_EDIT_PROXY_SERVER
, proxy
, ARRAY_SIZE(proxy
));
279 proxy
[proxy_len
++] = ':';
280 port_len
= GetDlgItemTextW(hwnd
, IDC_EDIT_PROXY_PORT
, proxy
+proxy_len
,
281 ARRAY_SIZE(proxy
)-proxy_len
);
284 proxy
[proxy_len
++] = '8';
285 proxy
[proxy_len
++] = '0';
286 proxy
[proxy_len
] = 0;
289 res
= RegSetValueExW(hkey
, proxy_server
, 0, REG_SZ
,
290 (BYTE
*)proxy
, (proxy_len
+port_len
)*sizeof(WCHAR
));
294 res
= RegDeleteValueW(hkey
, proxy_server
);
295 if(res
== ERROR_FILE_NOT_FOUND
)
303 TRACE("ProxtServer set to %s\n", wine_dbgstr_w(proxy
));
305 use_pac_script
= IsDlgButtonChecked(hwnd
, IDC_USE_PAC_SCRIPT
);
306 pac_script_len
= GetDlgItemTextW(hwnd
, IDC_EDIT_PAC_SCRIPT
,
307 pac_script
, ARRAY_SIZE(pac_script
));
308 if(!pac_script_len
) use_pac_script
= FALSE
;
311 res
= RegSetValueExW(hkey
, auto_config_url
, 0, REG_SZ
,
312 (BYTE
*)pac_script
, pac_script_len
*sizeof(WCHAR
));
316 res
= RegDeleteValueW(hkey
, auto_config_url
);
317 if(res
== ERROR_FILE_NOT_FOUND
)
325 TRACE("AutoConfigURL set to %s\n", wine_dbgstr_w(use_pac_script
? pac_script
: NULL
));
327 use_wpad
= IsDlgButtonChecked(hwnd
, IDC_USE_WPAD
);
329 res
= RegCreateKeyExW(hkey
, connections
, 0, NULL
, 0, KEY_WRITE
, NULL
, &con
, NULL
);
334 size
= create_connection_settings(use_proxy
, proxy
, use_wpad
,
335 use_pac_script
, pac_script
, &default_connection
);
342 res
= RegSetValueExW(con
, default_connection_settings
, 0, REG_BINARY
,
343 (BYTE
*)default_connection
, size
);
344 heap_free(default_connection
);
349 INT_PTR CALLBACK
connections_dlgproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
354 connections_on_initdialog(hwnd
);
355 initdialog_done
= TRUE
;
358 return connections_on_command(hwnd
, wparam
);
360 return connections_on_notify(hwnd
, wparam
, lparam
);