[NETCFGX]
[reactos.git] / reactos / dll / win32 / netcfgx / tcpipconf_notify.c
1 #include "precomp.h"
2
3 typedef struct
4 {
5 DWORD EnableSecurityFilters;
6 LPWSTR szTCPAllowedPorts; // KEY: Tcpip\Parameter\{InstanceGuid}\TCPAllowedPorts
7 LPWSTR szUDPAllowedPorts; // KEY: Tcpip\Parameter\{InstanceGuid}\UDPAllowedPorts
8 LPWSTR szRawIPAllowedProtocols; // KEY: Tcpip\Parameter\{InstanceGuid}\RawIPAllowedProtocols
9 DWORD IPSize;
10 DWORD TCPSize;
11 DWORD UDPSize;
12 }TcpFilterSettings;
13
14 // KEY: Tcpip\Parameter\{InstanceGuid}\IpAddress | DhcpIpAddress
15 // KEY: Tcpip\Parameter\{InstanceGuid}\SubnetMask | DhcpSubnetMask
16 // KEY: Tcpip\Parameter\{InstanceGuid}\DefaultGateway | DhcpDefaultGateway
17 // KEY: Tcpip\Parameter\{InstanceGuid}\NameServer | DhcpNameServer
18 // KEY: Services\NetBT\Parameters\Interfaces\Tcpip_{INSTANCE_GUID}
19
20 typedef struct
21 {
22 DWORD RegisterAdapterName;
23 DWORD RegistrationEnabled;
24 DWORD UseDomainNameDevolution;
25 WCHAR szDomain[100];
26 LPWSTR szSearchList;
27 }TcpipAdvancedDNSDlgSettings;
28
29 typedef struct tagIP_ADDR
30 {
31 DWORD IpAddress;
32 union
33 {
34 DWORD Subnetmask;
35 USHORT Metric;
36 }u;
37 ULONG NTEContext;
38 struct tagIP_ADDR * Next;
39 }IP_ADDR;
40
41 typedef enum
42 {
43 METRIC = 1,
44 SUBMASK = 2,
45 IPADDR = 3
46 }COPY_TYPE;
47
48 typedef struct
49 {
50 IP_ADDR * Ip;
51 IP_ADDR * Ns;
52 IP_ADDR * Gw;
53
54 UINT DhcpEnabled;
55 UINT AutoconfigActive;
56 DWORD Index;
57 TcpFilterSettings * pFilter;
58 TcpipAdvancedDNSDlgSettings * pDNS;
59 }TcpipSettings;
60
61 typedef struct
62 {
63 const INetCfgComponentPropertyUi * lpVtbl;
64 const INetCfgComponentControl * lpVtblCompControl;
65 LONG ref;
66 IUnknown * pUnknown;
67 INetCfg * pNCfg;
68 INetCfgComponent * pNComp;
69 TcpipSettings *pCurrentConfig;
70 CLSID NetCfgInstanceId;
71 }TcpipConfNotifyImpl, *LPTcpipConfNotifyImpl;
72
73 typedef struct
74 {
75 BOOL bAdd;
76 HWND hDlgCtrl;
77 WCHAR szIP[16];
78 UINT Metric;
79 }TcpipGwSettings;
80
81 typedef struct
82 {
83 BOOL bAdd;
84 HWND hDlgCtrl;
85 WCHAR szIP[16];
86 WCHAR szMask[16];
87 }TcpipIpSettings;
88
89 typedef struct
90 {
91 BOOL bAdd;
92 HWND hDlgCtrl;
93 WCHAR szIP[16];
94 }TcpipDnsSettings;
95
96 typedef struct
97 {
98 BOOL bAdd;
99 HWND hDlgCtrl;
100 LPWSTR Suffix;
101 }TcpipSuffixSettings;
102
103 typedef struct
104 {
105 HWND hDlgCtrl;
106 UINT ResId;
107 UINT MaxNum;
108 }TcpipPortSettings;
109
110 static __inline LPTcpipConfNotifyImpl impl_from_INetCfgComponentControl(INetCfgComponentControl *iface)
111 {
112 return (TcpipConfNotifyImpl*)((char *)iface - FIELD_OFFSET(TcpipConfNotifyImpl, lpVtblCompControl));
113 }
114
115 INT GetSelectedItem(HWND hDlgCtrl);
116 HRESULT InitializeTcpipBasicDlgCtrls(HWND hwndDlg, TcpipSettings * pCurSettings);
117 VOID InsertColumnToListView(HWND hDlgCtrl, UINT ResId, UINT SubItem, UINT Size);
118 INT_PTR StoreTcpipBasicSettings(HWND hwndDlg, TcpipConfNotifyImpl * This, BOOL bApply);
119 HRESULT Initialize(TcpipConfNotifyImpl * This);
120
121 VOID
122 DisplayError(UINT ResTxt, UINT ResTitle, UINT Type)
123 {
124 WCHAR szBuffer[300];
125 WCHAR szTitle[100];
126
127 if (LoadStringW(netcfgx_hInstance, ResTxt, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
128 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
129 else
130 szBuffer[0] = L'\0';
131
132 if (LoadStringW(netcfgx_hInstance, ResTitle, szTitle, sizeof(szTitle)/sizeof(WCHAR)))
133 szTitle[(sizeof(szTitle)/sizeof(WCHAR))-1] = L'\0';
134 else
135 szTitle[0] = L'\0';
136
137 MessageBoxW(NULL, szBuffer, szTitle, Type);
138 }
139
140
141 /***************************************************************
142 * TCP/IP Filter Dialog
143 *
144 */
145
146 INT_PTR
147 CALLBACK
148 TcpipFilterPortDlg(
149 HWND hwndDlg,
150 UINT uMsg,
151 WPARAM wParam,
152 LPARAM lParam
153 )
154 {
155 TcpipPortSettings * pPort;
156 UINT Num;
157 LVFINDINFOW find;
158 LVITEMW li;
159 WCHAR szBuffer[100];
160
161 switch(uMsg)
162 {
163 case WM_INITDIALOG:
164 pPort = (TcpipPortSettings*)lParam;
165 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pPort);
166 if (LoadStringW(netcfgx_hInstance, pPort->ResId, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
167 {
168 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
169 SendDlgItemMessageW(hwndDlg, IDC_PORT_DESC, WM_SETTEXT, 0, (LPARAM)szBuffer);
170 }
171
172 if (pPort->MaxNum == 65536)
173 SendDlgItemMessageW(hwndDlg, IDC_PORT_VAL, EM_LIMITTEXT, 5, 0);
174 else
175 SendDlgItemMessageW(hwndDlg, IDC_PORT_VAL, EM_LIMITTEXT, 3, 0);
176
177 return TRUE;
178 case WM_COMMAND:
179 if (LOWORD(wParam) == IDCANCEL)
180 {
181 EndDialog(hwndDlg, FALSE);
182 break;
183 }
184 else if (LOWORD(wParam) == IDC_OK)
185 {
186 pPort = (TcpipPortSettings*)GetWindowLongPtr(hwndDlg, DWLP_USER);
187 Num = GetDlgItemInt(hwndDlg, IDC_PORT_VAL, NULL, TRUE);
188 if (Num > pPort->MaxNum || Num == 0)
189 {
190 if (pPort->MaxNum == 65536)
191 DisplayError(IDS_PORT_RANGE, IDS_TCPIP, MB_ICONWARNING);
192 else
193 DisplayError(IDS_PROT_RANGE, IDS_TCPIP, MB_ICONWARNING);
194
195 SetFocus(GetDlgItem(hwndDlg, IDC_PORT_VAL));
196 break;
197 }
198 if (GetWindowTextW(GetDlgItem(hwndDlg, IDC_PORT_VAL), szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
199 {
200 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
201 ZeroMemory(&find, sizeof(LVFINDINFOW));
202 find.flags = LVFI_STRING;
203 find.psz = szBuffer;
204 if (SendMessageW(pPort->hDlgCtrl, LVM_FINDITEMW, (WPARAM)-1, (LPARAM)&find) == -1)
205 {
206 ZeroMemory(&li, sizeof(LVITEMW));
207 li.mask = LVIF_TEXT;
208 li.iItem = ListView_GetItemCount(pPort->hDlgCtrl);
209 li.pszText = szBuffer;
210 SendMessageW(pPort->hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&li);
211 EndDialog(hwndDlg, TRUE);
212 break;
213 }
214 DisplayError(IDS_DUP_NUMBER, IDS_PROT_RANGE, MB_ICONWARNING);
215 SetFocus(GetDlgItem(hwndDlg, IDC_PORT_VAL));
216 break;
217 }
218 }
219 }
220 return FALSE;
221 }
222
223 VOID
224 InitFilterListBox(LPWSTR pData, HWND hwndDlg, HWND hDlgCtrl, UINT AllowButton, UINT RestrictButton, UINT AddButton, UINT DelButton)
225 {
226 LVITEMW li;
227 LPWSTR pCur;
228 INT iItem;
229
230 if (!pData || !_wtoi(pData))
231 {
232 SendDlgItemMessageW(hwndDlg, AllowButton, BM_SETCHECK, BST_CHECKED, 0);
233 EnableWindow(GetDlgItem(hwndDlg, AddButton), FALSE);
234 EnableWindow(GetDlgItem(hwndDlg, DelButton), FALSE);
235 return;
236 }
237
238 pCur = pData;
239 memset(&li, 0x0, sizeof(LVITEMW));
240 li.mask = LVIF_TEXT;
241 iItem = 0;
242
243 while(pCur[0])
244 {
245 li.pszText = pCur;
246 li.iItem = iItem;
247 SendMessageW(hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&li);
248 iItem++;
249 pCur += wcslen(pCur) + 1;
250 }
251
252 if (!iItem)
253 SendDlgItemMessageW(hwndDlg, AllowButton, BM_SETCHECK, BST_CHECKED, 0);
254 else
255 SendDlgItemMessageW(hwndDlg, RestrictButton, BM_SETCHECK, BST_CHECKED, 0);
256 }
257
258 LPWSTR
259 CreateFilterList(
260 HWND hDlgCtrl,
261 LPDWORD Size)
262 {
263 INT iCount, iIndex;
264 LVITEMW li;
265 LPWSTR pData, pCur;
266 DWORD dwSize;
267 WCHAR szBuffer[10];
268
269 iCount = ListView_GetItemCount(hDlgCtrl);
270 if (!iCount)
271 {
272 pData = (LPWSTR)CoTaskMemAlloc(3 * sizeof(WCHAR));
273 if (!pData)
274 return NULL;
275 pData[0] = L'0';
276 pData[1] = L'\0';
277 pData[2] = L'\0';
278 *Size = 3 * sizeof(WCHAR);
279 return pData;
280 }
281
282 pData = CoTaskMemAlloc((6 * iCount + 1) * sizeof(WCHAR));
283 if (!pData)
284 return NULL;
285
286 pCur = pData;
287 dwSize = 0;
288 for(iIndex = 0; iIndex < iCount; iIndex++)
289 {
290 ZeroMemory(&li, sizeof(LVITEMW));
291 li.mask = LVIF_TEXT;
292 li.iItem = iIndex;
293 li.pszText = szBuffer;
294 li.cchTextMax = sizeof(szBuffer) /sizeof(WCHAR);
295 if (SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
296 {
297 wcscpy(pCur, szBuffer);
298 dwSize += wcslen(szBuffer) + 1;
299 pCur += wcslen(szBuffer) + 1;
300 }
301 }
302 pCur[0] = L'\0';
303 *Size = (dwSize+1) * sizeof(WCHAR);
304 return pData;
305 }
306
307 TcpFilterSettings *
308 StoreTcpipFilterSettings(
309 HWND hwndDlg)
310 {
311 TcpFilterSettings * pFilter;
312
313 pFilter = CoTaskMemAlloc(sizeof(TcpFilterSettings));
314 if (!pFilter)
315 return NULL;
316
317 if (SendDlgItemMessageW(hwndDlg, IDC_USE_FILTER, BM_GETCHECK, 0, 0) == BST_CHECKED)
318 pFilter->EnableSecurityFilters = TRUE;
319 else
320 pFilter->EnableSecurityFilters = FALSE;
321
322 pFilter->szTCPAllowedPorts = CreateFilterList(GetDlgItem(hwndDlg, IDC_TCP_LIST), &pFilter->TCPSize);
323 pFilter->szUDPAllowedPorts = CreateFilterList(GetDlgItem(hwndDlg, IDC_UDP_LIST), &pFilter->UDPSize);
324 pFilter->szRawIPAllowedProtocols = CreateFilterList(GetDlgItem(hwndDlg, IDC_IP_LIST), &pFilter->IPSize);
325
326 return pFilter;
327 }
328
329 static
330 VOID
331 AddItem(
332 HWND hwndDlg,
333 HWND hDlgCtrl,
334 UINT MaxItem,
335 UINT ResId)
336 {
337 TcpipPortSettings Port;
338
339 Port.MaxNum = MaxItem;
340 Port.hDlgCtrl = hDlgCtrl;
341 Port.ResId = ResId;
342
343 DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIP_PORT_DLG), hwndDlg, TcpipFilterPortDlg, (LPARAM)&Port);
344 }
345
346 static
347 VOID
348 DelItem(
349 HWND hDlgCtrl)
350 {
351 INT iIndex = GetSelectedItem(hDlgCtrl);
352
353 if (iIndex != -1)
354 {
355 (void)ListView_DeleteItem(hDlgCtrl, iIndex);
356 return;
357 }
358 DisplayError(IDS_NOITEMSEL, IDS_TCPIP, MB_ICONWARNING);
359 }
360
361 INT_PTR
362 CALLBACK
363 TcpipFilterSettingsDlg(
364 HWND hwndDlg,
365 UINT uMsg,
366 WPARAM wParam,
367 LPARAM lParam
368 )
369 {
370 TcpipConfNotifyImpl *pContext;
371 TcpFilterSettings *pFilter;
372
373 switch(uMsg)
374 {
375 case WM_INITDIALOG:
376 pContext = (TcpipConfNotifyImpl*)lParam;
377 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_TCP_LIST), IDS_TCP_PORTS, 0, 100);
378 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_UDP_LIST), IDS_UDP_PORTS, 0, 100);
379 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_IP_LIST), IDS_IP_PROTO, 0, 100);
380 if (pContext->pCurrentConfig->pFilter)
381 {
382 InitFilterListBox(pContext->pCurrentConfig->pFilter->szTCPAllowedPorts, hwndDlg, GetDlgItem(hwndDlg, IDC_TCP_LIST), IDC_TCP_ALLOW_ALL, IDC_TCP_RESTRICT, IDC_TCP_ADD, IDC_TCP_DEL);
383 InitFilterListBox(pContext->pCurrentConfig->pFilter->szUDPAllowedPorts, hwndDlg, GetDlgItem(hwndDlg, IDC_UDP_LIST), IDC_UDP_ALLOW_ALL, IDC_UDP_RESTRICT, IDC_UDP_ADD, IDC_UDP_DEL);
384 InitFilterListBox(pContext->pCurrentConfig->pFilter->szRawIPAllowedProtocols, hwndDlg, GetDlgItem(hwndDlg, IDC_IP_LIST), IDC_IP_ALLOW_ALL, IDC_IP_RESTRICT, IDC_IP_ADD, IDC_IP_DEL);
385 if (pContext->pCurrentConfig->pFilter->EnableSecurityFilters)
386 SendDlgItemMessageW(hwndDlg, IDC_USE_FILTER, BM_SETCHECK, BST_CHECKED, 0);
387 }
388 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
389 return TRUE;
390 case WM_COMMAND:
391 if (HIWORD(wParam) == BN_CLICKED)
392 {
393 switch (LOWORD(wParam))
394 {
395 case IDC_TCP_ALLOW_ALL:
396 if (SendDlgItemMessageW(hwndDlg, IDC_TCP_ALLOW_ALL, BM_GETCHECK, 0, 0) == BST_CHECKED)
397 {
398 SendDlgItemMessageW(hwndDlg, IDC_TCP_RESTRICT, BM_SETCHECK, BST_UNCHECKED, 0);
399 EnableWindow(GetDlgItem(hwndDlg, IDC_TCP_LIST), FALSE);
400 EnableWindow(GetDlgItem(hwndDlg, IDC_TCP_ADD), FALSE);
401 EnableWindow(GetDlgItem(hwndDlg, IDC_TCP_DEL), FALSE);
402 }
403 break;
404 case IDC_TCP_RESTRICT:
405 if (SendDlgItemMessageW(hwndDlg, IDC_TCP_RESTRICT, BM_GETCHECK, 0, 0) == BST_CHECKED)
406 {
407 SendDlgItemMessageW(hwndDlg, IDC_TCP_ALLOW_ALL, BM_SETCHECK, BST_UNCHECKED, 0);
408 EnableWindow(GetDlgItem(hwndDlg, IDC_TCP_LIST), TRUE);
409 EnableWindow(GetDlgItem(hwndDlg, IDC_TCP_ADD), TRUE);
410 EnableWindow(GetDlgItem(hwndDlg, IDC_TCP_DEL), TRUE);
411 }
412 break;
413 case IDC_UDP_ALLOW_ALL:
414 if (SendDlgItemMessageW(hwndDlg, IDC_UDP_ALLOW_ALL, BM_GETCHECK, 0, 0) == BST_CHECKED)
415 {
416 SendDlgItemMessageW(hwndDlg, IDC_UDP_RESTRICT, BM_SETCHECK, BST_UNCHECKED, 0);
417 EnableWindow(GetDlgItem(hwndDlg, IDC_UDP_LIST), FALSE);
418 EnableWindow(GetDlgItem(hwndDlg, IDC_UDP_ADD), FALSE);
419 EnableWindow(GetDlgItem(hwndDlg, IDC_UDP_DEL), FALSE);
420 }
421 break;
422 case IDC_UDP_RESTRICT:
423 if (SendDlgItemMessageW(hwndDlg, IDC_UDP_RESTRICT, BM_GETCHECK, 0, 0) == BST_CHECKED)
424 {
425 SendDlgItemMessageW(hwndDlg, IDC_UDP_ALLOW_ALL, BM_SETCHECK, BST_UNCHECKED, 0);
426 EnableWindow(GetDlgItem(hwndDlg, IDC_UDP_LIST), TRUE);
427 EnableWindow(GetDlgItem(hwndDlg, IDC_UDP_ADD), TRUE);
428 EnableWindow(GetDlgItem(hwndDlg, IDC_UDP_DEL), TRUE);
429 }
430 break;
431 case IDC_IP_ALLOW_ALL:
432 if (SendDlgItemMessageW(hwndDlg, IDC_IP_ALLOW_ALL, BM_GETCHECK, 0, 0) == BST_CHECKED)
433 {
434 SendDlgItemMessageW(hwndDlg, IDC_IP_RESTRICT, BM_SETCHECK, BST_UNCHECKED, 0);
435 EnableWindow(GetDlgItem(hwndDlg, IDC_IP_LIST), FALSE);
436 EnableWindow(GetDlgItem(hwndDlg, IDC_IP_ADD), FALSE);
437 EnableWindow(GetDlgItem(hwndDlg, IDC_IP_DEL), FALSE);
438 }
439 break;
440 case IDC_IP_RESTRICT:
441 if (SendDlgItemMessageW(hwndDlg, IDC_IP_RESTRICT, BM_GETCHECK, 0, 0) == BST_CHECKED)
442 {
443 SendDlgItemMessageW(hwndDlg, IDC_IP_ALLOW_ALL, BM_SETCHECK, BST_UNCHECKED, 0);
444 EnableWindow(GetDlgItem(hwndDlg, IDC_IP_LIST), TRUE);
445 EnableWindow(GetDlgItem(hwndDlg, IDC_IP_ADD), TRUE);
446 EnableWindow(GetDlgItem(hwndDlg, IDC_IP_DEL), TRUE);
447 }
448 break;
449 case IDC_USE_FILTER:
450 if (SendDlgItemMessageW(hwndDlg, IDC_USE_FILTER, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
451 DisplayError(IDS_DISABLE_FILTER, IDS_TCPIP, MB_OK);
452
453 break;
454 }
455 }
456 switch(LOWORD(wParam))
457 {
458 case IDC_OK:
459 pContext = (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER);
460 pFilter = StoreTcpipFilterSettings(hwndDlg);
461 if (pFilter)
462 {
463 if (pContext->pCurrentConfig->pFilter)
464 {
465 CoTaskMemFree(pContext->pCurrentConfig->pFilter->szTCPAllowedPorts);
466 CoTaskMemFree(pContext->pCurrentConfig->pFilter->szUDPAllowedPorts);
467 CoTaskMemFree(pContext->pCurrentConfig->pFilter->szRawIPAllowedProtocols);
468 CoTaskMemFree(pContext->pCurrentConfig->pFilter);
469 }
470 pContext->pCurrentConfig->pFilter = pFilter;
471 }
472 EndDialog(hwndDlg, (INT_PTR)TRUE);
473 break;
474 case IDCANCEL:
475 EndDialog(hwndDlg, FALSE);
476 break;
477 case IDC_TCP_ADD:
478 AddItem(hwndDlg, GetDlgItem(hwndDlg, IDC_TCP_LIST), 65536, IDS_TCP_PORTS);
479 break;
480 case IDC_TCP_DEL:
481 DelItem(GetDlgItem(hwndDlg, IDC_TCP_LIST));
482 break;
483 case IDC_UDP_ADD:
484 AddItem(hwndDlg, GetDlgItem(hwndDlg, IDC_UDP_LIST), 65536, IDS_UDP_PORTS);
485 break;
486 case IDC_UDP_DEL:
487 DelItem(GetDlgItem(hwndDlg, IDC_UDP_LIST));
488 break;
489 case IDC_IP_ADD:
490 AddItem(hwndDlg, GetDlgItem(hwndDlg, IDC_IP_LIST), 256, IDS_IP_PROTO);
491 break;
492 case IDC_IP_DEL:
493 DelItem(GetDlgItem(hwndDlg, IDC_IP_LIST));
494 break;
495 default:
496 break;
497 }
498 default:
499 break;
500 }
501
502 return FALSE;
503 }
504
505
506 HPROPSHEETPAGE
507 InitializePropertySheetPage(LPWSTR resname, DLGPROC dlgproc, LPARAM lParam, LPWSTR szTitle)
508 {
509 PROPSHEETPAGEW ppage;
510
511 memset(&ppage, 0x0, sizeof(PROPSHEETPAGEW));
512 ppage.dwSize = sizeof(PROPSHEETPAGEW);
513 ppage.dwFlags = PSP_DEFAULT;
514 ppage.u.pszTemplate = resname;
515 ppage.pfnDlgProc = dlgproc;
516 ppage.lParam = lParam;
517 ppage.hInstance = netcfgx_hInstance;
518 if (szTitle)
519 {
520 ppage.dwFlags |= PSP_USETITLE;
521 ppage.pszTitle = szTitle;
522 }
523 return CreatePropertySheetPageW(&ppage);
524 }
525
526 /***************************************************************
527 * TCP/IP Advanced Option Dialog
528 *
529 */
530
531 VOID
532 InitializeTcpipAdvancedOptDlg(
533 HWND hwndDlg,
534 TcpipConfNotifyImpl * This)
535 {
536 WCHAR szText[500];
537 /* store context */
538 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)This);
539
540 if (LoadStringW(netcfgx_hInstance, IDS_TCPFILTER, szText, sizeof(szText)/sizeof(WCHAR)))
541 {
542 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
543 if (SendDlgItemMessageW(hwndDlg, IDC_OPTLIST, LB_ADDSTRING, 0, (LPARAM)szText) != LB_ERR)
544 SendDlgItemMessageW(hwndDlg, IDC_OPTLIST, LB_SETCURSEL, 0, 0);
545 }
546
547 if (LoadStringW(netcfgx_hInstance, IDS_TCPFILTERDESC, szText, sizeof(szText)/sizeof(WCHAR)))
548 {
549 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
550 SendDlgItemMessageW(hwndDlg, IDC_OPTDESC, WM_SETTEXT, 0, (LPARAM)szText);
551 }
552 }
553
554
555
556 INT_PTR
557 CALLBACK
558 TcpipAdvancedOptDlg(
559 HWND hwndDlg,
560 UINT uMsg,
561 WPARAM wParam,
562 LPARAM lParam
563 )
564 {
565 TcpipConfNotifyImpl * This;
566 LPPROPSHEETPAGE page;
567 int res;
568
569 switch(uMsg)
570 {
571 case WM_INITDIALOG:
572 page = (LPPROPSHEETPAGE)lParam;
573 This = (TcpipConfNotifyImpl*)page->lParam;
574 InitializeTcpipAdvancedOptDlg(hwndDlg, This);
575 return TRUE;
576 case WM_COMMAND:
577 if (LOWORD(wParam) == IDC_OPTPROP)
578 {
579 res = DialogBoxParamW(netcfgx_hInstance,
580 MAKEINTRESOURCEW(IDD_TCPIP_FILTER_DLG),
581 GetParent(hwndDlg),
582 TcpipFilterSettingsDlg,
583 (LPARAM)GetWindowLongPtr(hwndDlg, DWLP_USER));
584 break;
585 }
586 }
587 return FALSE;
588 }
589
590 VOID
591 InsertColumnToListView(
592 HWND hDlgCtrl,
593 UINT ResId,
594 UINT SubItem,
595 UINT Size)
596 {
597 WCHAR szBuffer[200];
598 LVCOLUMNW lc;
599
600 if (!LoadStringW(netcfgx_hInstance, ResId, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
601 return;
602
603 memset(&lc, 0, sizeof(LV_COLUMN) );
604 lc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT;
605 lc.iSubItem = SubItem;
606 lc.fmt = LVCFMT_FIXED_WIDTH;
607 lc.cx = Size;
608 lc.cchTextMax = wcslen(szBuffer);
609 lc.pszText = szBuffer;
610
611 (void)SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, SubItem, (LPARAM)&lc);
612 }
613
614 VOID
615 InsertIpAddressToListView(
616 HWND hDlgCtrl,
617 IP_ADDR * pAddr,
618 BOOL bSubMask)
619 {
620 WCHAR szBuffer[70];
621 DWORD dwIpAddr;
622 UINT itemCount = 0;
623 LVITEMW li;
624
625 while(pAddr)
626 {
627 ZeroMemory(&li, sizeof(li));
628 li.mask = LVIF_TEXT;
629 li.iItem = itemCount;
630 li.iSubItem = 0;
631 dwIpAddr = pAddr->IpAddress;
632 swprintf(szBuffer, L"%lu.%lu.%lu.%lu",
633 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
634
635 li.pszText = szBuffer;
636 li.iItem = SendMessageW(hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&li);
637 if (li.iItem != -1)
638 {
639 if (bSubMask)
640 {
641 dwIpAddr = pAddr->u.Subnetmask;
642 swprintf(szBuffer, L"%lu.%lu.%lu.%lu",
643 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
644 }
645 else
646 {
647 if (pAddr->u.Metric)
648 swprintf(szBuffer, L"%u", pAddr->u.Metric);
649 else
650 LoadStringW(netcfgx_hInstance, IDS_AUTOMATIC, szBuffer, sizeof(szBuffer)/sizeof(WCHAR));
651 }
652
653 li.mask = LVIF_TEXT;
654 li.iSubItem = 1;
655 li.pszText = szBuffer;
656 SendMessageW(hDlgCtrl, LVM_SETITEMW, 0, (LPARAM)&li);
657 }
658 itemCount++;
659 pAddr = pAddr->Next;
660 }
661 }
662
663
664 VOID
665 InitializeTcpipAdvancedIpDlg(
666 HWND hwndDlg,
667 TcpipConfNotifyImpl * This)
668 {
669
670 RECT rect;
671 LVITEMW li;
672 WCHAR szBuffer[100];
673
674 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_IPLIST), IDS_IPADDR, 0, 100);
675 GetClientRect(GetDlgItem(hwndDlg, IDC_IPLIST), &rect);
676 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_IPLIST), IDS_SUBMASK, 1, (rect.right - rect.left - 100));
677
678 if (This->pCurrentConfig->DhcpEnabled)
679 {
680 if (LoadStringW(netcfgx_hInstance, IDS_DHCPACTIVE, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
681 {
682 ZeroMemory(&li, sizeof(LVITEMW));
683 li.mask = LVIF_TEXT;
684 li.pszText = szBuffer;
685 SendDlgItemMessageW(hwndDlg, IDC_IPLIST, LVM_INSERTITEMW, 0, (LPARAM)&li);
686 }
687 EnableWindow(GetDlgItem(hwndDlg, IDC_IPADD), FALSE);
688 EnableWindow(GetDlgItem(hwndDlg, IDC_IPMOD), FALSE);
689 EnableWindow(GetDlgItem(hwndDlg, IDC_IPDEL), FALSE);
690 }
691 else
692 {
693 InsertIpAddressToListView(GetDlgItem(hwndDlg, IDC_IPLIST), This->pCurrentConfig->Ip, TRUE);
694 }
695
696 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_GWLIST), IDS_GATEWAY, 0, 100);
697 GetClientRect(GetDlgItem(hwndDlg, IDC_IPLIST), &rect);
698 InsertColumnToListView(GetDlgItem(hwndDlg, IDC_GWLIST), IDS_METRIC, 1, (rect.right - rect.left - 100));
699
700 InsertIpAddressToListView(GetDlgItem(hwndDlg, IDC_GWLIST), This->pCurrentConfig->Gw, FALSE);
701 SendDlgItemMessageW(hwndDlg, IDC_METRIC, EM_LIMITTEXT, 4, 0);
702
703 }
704
705 INT_PTR
706 CALLBACK
707 TcpipAdvGwDlg(
708 HWND hwndDlg,
709 UINT uMsg,
710 WPARAM wParam,
711 LPARAM lParam
712 )
713 {
714 WCHAR szBuffer[70];
715 TcpipGwSettings *pGwSettings;
716 DWORD dwIpAddr;
717 LPNMIPADDRESS lpnmipa;
718 LVFINDINFOW find;
719
720 switch(uMsg)
721 {
722 case WM_INITDIALOG:
723 pGwSettings = (TcpipGwSettings *)lParam;
724 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
725 if (pGwSettings->bAdd)
726 {
727 if (LoadStringW(netcfgx_hInstance, IDS_ADD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
728 {
729 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
730 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
731 }
732 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), FALSE);
733 SendDlgItemMessageW(hwndDlg, IDC_USEMETRIC, BM_SETCHECK, BST_CHECKED, 0);
734 }
735 else
736 {
737 if (LoadStringW(netcfgx_hInstance, IDS_MOD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
738 {
739 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
740 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
741 }
742 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_SETTEXT, 0, (LPARAM)pGwSettings->szIP);
743 if (pGwSettings->Metric)
744 {
745 SetDlgItemInt(hwndDlg, IDC_METRIC, pGwSettings->Metric, FALSE);
746 EnableWindow(GetDlgItem(hwndDlg, IDC_METRIC), TRUE);
747 EnableWindow(GetDlgItem(hwndDlg, IDC_METRICTXT), TRUE);
748 }
749 else
750 {
751 SendDlgItemMessageW(hwndDlg, IDC_USEMETRIC, BM_SETCHECK, BST_CHECKED, 0);
752 EnableWindow(GetDlgItem(hwndDlg, IDC_METRIC), FALSE);
753 EnableWindow(GetDlgItem(hwndDlg, IDC_METRICTXT), FALSE);
754 }
755 }
756 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 0, MAKEIPRANGE(1, 223));
757 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 1, MAKEIPRANGE(0, 255));
758 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 2, MAKEIPRANGE(0, 255));
759 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 3, MAKEIPRANGE(0, 255));
760 return TRUE;
761 case WM_COMMAND:
762 if (LOWORD(wParam) == IDC_USEMETRIC)
763 {
764 if (SendDlgItemMessage(hwndDlg, IDC_USEMETRIC, BM_GETCHECK, 0, 0) == BST_CHECKED)
765 {
766 EnableWindow(GetDlgItem(hwndDlg, IDC_METRIC), FALSE);
767 EnableWindow(GetDlgItem(hwndDlg, IDC_METRICTXT), FALSE);
768 SendDlgItemMessageW(hwndDlg, IDC_METRIC, WM_SETTEXT, 0, (LPARAM)L"");
769 }
770 else
771 {
772 EnableWindow(GetDlgItem(hwndDlg, IDC_METRIC), TRUE);
773 EnableWindow(GetDlgItem(hwndDlg, IDC_METRICTXT), TRUE);
774 }
775 break;
776 }
777 else if (LOWORD(wParam) == IDCANCEL)
778 {
779 EndDialog(hwndDlg, FALSE);
780 break;
781 }
782 else if (LOWORD(wParam) == IDC_OK)
783 {
784 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
785 {
786 pGwSettings = (TcpipGwSettings*)GetWindowLongPtr(hwndDlg, DWLP_USER);
787 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_GETTEXT, 16, (LPARAM)pGwSettings->szIP);
788
789 ZeroMemory(&find, sizeof(LVFINDINFOW));
790 find.flags = LVFI_STRING;
791 find.psz = pGwSettings->szIP;
792
793 if (SendDlgItemMessage(hwndDlg, IDC_USEMETRIC, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
794 pGwSettings->Metric = GetDlgItemInt(hwndDlg, IDC_METRIC, NULL, FALSE);
795 else
796 pGwSettings->Metric = 0;
797
798
799 if (SendMessageW(pGwSettings->hDlgCtrl, LVM_FINDITEMW, (WPARAM)-1, (LPARAM)&find) == -1)
800 {
801 EndDialog(hwndDlg, TRUE);
802 break;
803 }
804 if (!pGwSettings->bAdd)
805 {
806 EndDialog(hwndDlg, FALSE);
807 break;
808 }
809 DisplayError(IDS_DUP_GW, IDS_TCPIP, MB_ICONINFORMATION);
810 }
811 break;
812 }
813 break;
814 case WM_NOTIFY:
815 lpnmipa = (LPNMIPADDRESS) lParam;
816 if (lpnmipa->hdr.code == IPN_FIELDCHANGED)
817 {
818 if (lpnmipa->hdr.idFrom == IDC_IPADDR)
819 {
820 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
821 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), TRUE);
822 }
823 }
824 break;
825 }
826 return FALSE;
827 }
828
829 BOOL
830 GetGWListEntry(HWND hDlgCtrl, INT Index, TcpipGwSettings * pGwSettings)
831 {
832 LVITEMW li;
833 WCHAR szBuffer[30];
834 BOOL bRet;
835
836 ZeroMemory(&li, sizeof(LVITEMW));
837 li.mask = LVIF_TEXT;
838 li.cchTextMax = 16;
839 li.pszText = pGwSettings->szIP;
840 li.iItem = Index;
841
842 if (!SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
843 return FALSE;
844 li.pszText = szBuffer;
845 li.cchTextMax = 30;
846 li.iSubItem = 1;
847
848 bRet = SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li);
849 if (bRet)
850 {
851 pGwSettings->Metric = _wtoi(szBuffer);
852 }
853
854 return bRet;
855 }
856
857 INT_PTR
858 CALLBACK
859 TcpipAddIpDlg(
860 HWND hwndDlg,
861 UINT uMsg,
862 WPARAM wParam,
863 LPARAM lParam
864 )
865 {
866 LPNMIPADDRESS lpnmipa;
867 DWORD dwIpAddr;
868 TcpipIpSettings *pIpSettings;
869 WCHAR szBuffer[50];
870 LVFINDINFOW find;
871 LRESULT lResult;
872
873 switch(uMsg)
874 {
875 case WM_INITDIALOG:
876 pIpSettings = (TcpipIpSettings*)lParam;
877 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
878
879 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 0, MAKEIPRANGE(1, 223));
880 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 1, MAKEIPRANGE(0, 255));
881 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 2, MAKEIPRANGE(0, 255));
882 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 3, MAKEIPRANGE(0, 255));
883 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETRANGE, 0, MAKEIPRANGE(0, 255));
884 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETRANGE, 1, MAKEIPRANGE(0, 255));
885 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETRANGE, 2, MAKEIPRANGE(0, 255));
886 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETRANGE, 3, MAKEIPRANGE(0, 255));
887
888 if (pIpSettings->bAdd)
889 {
890 if (LoadStringW(netcfgx_hInstance, IDS_ADD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
891 {
892 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
893 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
894 }
895 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), FALSE);
896 }
897 else
898 {
899 if (LoadStringW(netcfgx_hInstance, IDS_MOD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
900 {
901 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
902 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
903 }
904 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_SETTEXT, 0, (LPARAM)pIpSettings->szIP);
905 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, WM_SETTEXT, 0, (LPARAM)pIpSettings->szMask);
906 }
907 return TRUE;
908 case WM_NOTIFY:
909 lpnmipa = (LPNMIPADDRESS) lParam;
910 if (lpnmipa->hdr.code == IPN_FIELDCHANGED)
911 {
912 if (lpnmipa->hdr.idFrom == IDC_IPADDR)
913 {
914 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
915 {
916 if (dwIpAddr <= MAKEIPADDRESS(127, 255, 255, 255))
917 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)MAKEIPADDRESS(255, 0, 0, 0));
918 else if (dwIpAddr <= MAKEIPADDRESS(191, 255, 255, 255))
919 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)MAKEIPADDRESS(255, 255, 0, 0));
920 else if (dwIpAddr <= MAKEIPADDRESS(223, 255, 255, 255))
921 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)MAKEIPADDRESS(255, 255, 255, 0));
922 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), TRUE);
923 }
924 }
925 }
926 break;
927 case WM_COMMAND:
928 if (LOWORD(wParam) == IDC_OK)
929 {
930 pIpSettings = (TcpipIpSettings*)GetWindowLongPtr(hwndDlg, DWLP_USER);
931 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_GETTEXT, 16, (LPARAM)pIpSettings->szIP);
932 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, WM_GETTEXT, 16, (LPARAM)pIpSettings->szMask);
933
934 ZeroMemory(&find, sizeof(LVFINDINFOW));
935 find.flags = LVFI_STRING;
936 find.psz = pIpSettings->szIP;
937 lResult = SendMessageW(pIpSettings->hDlgCtrl, LVM_FINDITEMW, (WPARAM)-1, (LPARAM)&find);
938
939 if (lResult == -1)
940 {
941 EndDialog(hwndDlg, TRUE);
942 break;
943 }
944 else if (!pIpSettings->bAdd)
945 {
946 EndDialog(hwndDlg, FALSE);
947 break;
948 }
949 DisplayError(IDS_DUP_IPADDR, IDS_TCPIP, MB_ICONINFORMATION);
950 break;
951 }
952 else if (LOWORD(wParam) == IDCANCEL)
953 {
954 EndDialog(hwndDlg, FALSE);
955 }
956 break;
957 }
958 return FALSE;
959 }
960
961 BOOL
962 VerifyDNSSuffix(
963 LPWSTR szName)
964 {
965 UINT Index;
966 UINT Length = wcslen(szName);
967
968 for(Index = 0; Index < Length; Index++)
969 if (iswalnum(szName[Index]) == 0 && szName[Index] != '.' && szName[Index] != '-')
970 return FALSE;
971
972 return TRUE;
973 }
974
975 INT_PTR
976 CALLBACK
977 TcpipAddSuffixDlg(
978 HWND hwndDlg,
979 UINT uMsg,
980 WPARAM wParam,
981 LPARAM lParam
982 )
983 {
984 WCHAR szBuffer[100];
985 TcpipSuffixSettings * pSettings;
986 LRESULT lLength;
987
988 switch(uMsg)
989 {
990 case WM_INITDIALOG:
991 pSettings = (TcpipSuffixSettings*)lParam;
992 if (!pSettings->bAdd)
993 {
994 SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_SETTEXT, 0, (LPARAM)pSettings->Suffix);
995 if (LoadStringW(netcfgx_hInstance, IDS_MOD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
996 {
997 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
998 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
999 }
1000 CoTaskMemFree(pSettings->Suffix);
1001 pSettings->Suffix = NULL;
1002 }
1003 else
1004 {
1005 if (LoadStringW(netcfgx_hInstance, IDS_ADD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1006 {
1007 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1008 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
1009 }
1010 }
1011 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSettings);
1012 return TRUE;
1013 case WM_COMMAND:
1014 if (LOWORD(wParam) == IDCANCEL)
1015 {
1016 EndDialog(hwndDlg, FALSE);
1017 break;
1018 }
1019 else if (LOWORD(wParam) == IDC_OK)
1020 {
1021 lLength = SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_GETTEXTLENGTH, 0, 0);
1022 if (lLength)
1023 {
1024 pSettings = (TcpipSuffixSettings*) GetWindowLongPtr(hwndDlg, DWLP_USER);
1025 pSettings->Suffix = (LPWSTR)CoTaskMemAlloc((lLength + 1)* sizeof(WCHAR));
1026 if (pSettings->Suffix)
1027 {
1028 SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_GETTEXT, lLength + 1, (LPARAM)pSettings->Suffix);
1029 if (SendMessageW(pSettings->hDlgCtrl, LB_FINDSTRING, 0, (LPARAM)pSettings->Suffix) != LB_ERR)
1030 {
1031 DisplayError(IDS_DUP_SUFFIX, IDS_TCPIP, MB_ICONWARNING);
1032 CoTaskMemFree(pSettings->Suffix);
1033 break;
1034 }
1035
1036 if (!VerifyDNSSuffix(pSettings->Suffix))
1037 {
1038 DisplayError(IDS_DOMAIN_SUFFIX, IDS_TCPIP, MB_ICONWARNING);
1039 CoTaskMemFree(pSettings->Suffix);
1040 break;
1041 }
1042 EndDialog(hwndDlg, TRUE);
1043 }
1044 }
1045 break;
1046 }
1047 }
1048 return FALSE;
1049 }
1050
1051
1052
1053 INT
1054 GetSelectedItem(HWND hDlgCtrl)
1055 {
1056 LVITEMW li;
1057 UINT iItemCount, iIndex;
1058
1059 iItemCount = ListView_GetItemCount(hDlgCtrl);
1060 if (!iItemCount)
1061 return -1;
1062
1063 for (iIndex = 0; iIndex < iItemCount; iIndex++)
1064 {
1065 ZeroMemory(&li, sizeof(LVITEMW));
1066 li.mask = LVIF_STATE;
1067 li.stateMask = (UINT)-1;
1068 li.iItem = iIndex;
1069 if (SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
1070 {
1071 if (li.state & LVIS_SELECTED)
1072 return iIndex;
1073 }
1074 }
1075 return -1;
1076 }
1077
1078
1079 BOOL
1080 GetIPListEntry(HWND hDlgCtrl, INT Index, TcpipIpSettings * pIpSettings)
1081 {
1082 LVITEMW li;
1083
1084 ZeroMemory(&li, sizeof(LVITEMW));
1085 li.mask = LVIF_TEXT;
1086 li.cchTextMax = 16;
1087 li.pszText = pIpSettings->szIP;
1088 li.iItem = Index;
1089
1090 if (!SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
1091 return FALSE;
1092
1093 ZeroMemory(&li, sizeof(LVITEMW));
1094 li.mask = LVIF_TEXT;
1095 li.cchTextMax = 16;
1096 li.pszText = pIpSettings->szMask;
1097 li.iSubItem = 1;
1098 li.iItem = Index;
1099
1100 return SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li);
1101 }
1102
1103 VOID
1104 DeleteItemFromList(HWND hDlgCtrl)
1105 {
1106 LVITEMW li;
1107
1108 memset(&li, 0x0, sizeof(LVITEMW));
1109 li.iItem = GetSelectedItem(hDlgCtrl);
1110 if (li.iItem < 0)
1111 {
1112 DisplayError(IDS_NOITEMSEL, IDS_TCPIP, MB_ICONINFORMATION);
1113 SetFocus(hDlgCtrl);
1114 }
1115 else
1116 {
1117 (void)ListView_DeleteItem(hDlgCtrl, li.iItem);
1118 }
1119 }
1120
1121 UINT
1122 GetIpAddressFromStringW(
1123 WCHAR * szBuffer)
1124 {
1125 DWORD dwIpAddr = 0;
1126 INT Val;
1127 UINT Index = 3;
1128 LPWSTR pLast = szBuffer;
1129 LPWSTR pNext = szBuffer;
1130
1131
1132 while((pNext = wcschr(pNext, L'.')))
1133 {
1134 pNext[0] = L'\0';
1135 Val = _wtoi(pLast);
1136 dwIpAddr |= (Val << Index * 8);
1137 Index--;
1138 pNext++;
1139 pLast = pNext;
1140 }
1141 dwIpAddr |= _wtoi(pLast);
1142
1143 return dwIpAddr;
1144 }
1145
1146 UINT
1147 GetIpAddressFromStringA(
1148 char * sBuffer)
1149 {
1150 WCHAR szIp[16];
1151
1152 if (MultiByteToWideChar(CP_ACP, 0, sBuffer, -1, szIp, 16))
1153 {
1154 szIp[15] = L'\0';
1155 return GetIpAddressFromStringW(szIp);
1156 }
1157 return (UINT)-1;
1158 }
1159
1160
1161 VOID
1162 FreeIPAddr(IP_ADDR *pAddr)
1163 {
1164 IP_ADDR *pNext;
1165
1166 if (!pAddr)
1167 return;
1168
1169 while(pAddr)
1170 {
1171 pNext = pAddr->Next;
1172 CoTaskMemFree(pAddr);
1173 pAddr = pNext;
1174 }
1175 }
1176
1177 BOOL
1178 GetListViewItem(HWND hDlgCtrl, UINT Index, UINT SubIndex, WCHAR * szBuffer, UINT BufferSize)
1179 {
1180 LVITEMW li;
1181
1182 ZeroMemory(&li, sizeof(LVITEMW));
1183 li.mask = LVIF_TEXT;
1184 li.pszText = szBuffer;
1185 li.iItem = Index;
1186 li.iSubItem = SubIndex;
1187 li.cchTextMax = BufferSize;
1188 return SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li);
1189 }
1190
1191 VOID
1192 StoreIPSettings(
1193 HWND hDlgCtrl,
1194 TcpipConfNotifyImpl * This,
1195 BOOL bSubmask)
1196 {
1197 WCHAR szBuffer[30];
1198
1199 INT iIndex, iCount;
1200 IP_ADDR *pCur, *pLast;
1201
1202 iCount = ListView_GetItemCount(hDlgCtrl);
1203 if (!iCount)
1204 {
1205 return;
1206 }
1207
1208 pLast = NULL;
1209 for(iIndex = 0; iIndex < iCount; iIndex++)
1210 {
1211 if (GetListViewItem(hDlgCtrl, iIndex, 0, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1212 {
1213 pCur = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
1214 if (!pCur)
1215 break;
1216 ZeroMemory(pCur, sizeof(IP_ADDR));
1217
1218 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1219 pCur->IpAddress = GetIpAddressFromStringW(szBuffer);
1220
1221 if (GetListViewItem(hDlgCtrl, iIndex, 1, szBuffer, sizeof(szBuffer)/sizeof(WCHAR) ))
1222 {
1223 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1224 if (bSubmask)
1225 pCur->u.Subnetmask = GetIpAddressFromStringW(szBuffer);
1226 else
1227 pCur->u.Metric = _wtoi(szBuffer);
1228 }
1229
1230 if (!pLast)
1231 {
1232 if (bSubmask)
1233 This->pCurrentConfig->Ip = pCur;
1234 else
1235 This->pCurrentConfig->Gw = pCur;
1236 }
1237 else
1238 {
1239 pLast->Next = pCur;
1240 }
1241
1242 pLast = pCur;
1243 }
1244 }
1245 }
1246
1247
1248 INT_PTR
1249 CALLBACK
1250 TcpipAdvancedIpDlg(
1251 HWND hwndDlg,
1252 UINT uMsg,
1253 WPARAM wParam,
1254 LPARAM lParam
1255 )
1256 {
1257 TcpipConfNotifyImpl * This;
1258 LPPROPSHEETPAGE page;
1259 INT_PTR res;
1260 WCHAR szBuffer[200];
1261 LPPSHNOTIFY lppsn;
1262 TcpipGwSettings Gw;
1263 TcpipIpSettings Ip;
1264
1265 LVITEMW li;
1266
1267 switch(uMsg)
1268 {
1269 case WM_INITDIALOG:
1270 page = (LPPROPSHEETPAGE)lParam;
1271 This = (TcpipConfNotifyImpl*)page->lParam;
1272 InitializeTcpipAdvancedIpDlg(hwndDlg, This);
1273 SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)This);
1274 return TRUE;
1275 case WM_NOTIFY:
1276 lppsn = (LPPSHNOTIFY) lParam;
1277 if (lppsn->hdr.code == PSN_KILLACTIVE)
1278 {
1279 This = (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER);
1280 if (!This->pCurrentConfig->DhcpEnabled && ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_IPLIST)) == 0)
1281 {
1282 DisplayError(IDS_NO_IPADDR_SET, IDS_TCPIP, MB_ICONWARNING);
1283 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, TRUE);
1284 return TRUE;
1285 }
1286 }
1287 else if (lppsn->hdr.code == PSN_APPLY)
1288 {
1289 This = (TcpipConfNotifyImpl*) GetWindowLongPtr(hwndDlg, DWLP_USER);
1290 FreeIPAddr(This->pCurrentConfig->Gw);
1291 This->pCurrentConfig->Gw = NULL;
1292 FreeIPAddr(This->pCurrentConfig->Ip);
1293 This->pCurrentConfig->Ip = NULL;
1294 StoreIPSettings(GetDlgItem(hwndDlg, IDC_IPLIST), This, TRUE);
1295 StoreIPSettings(GetDlgItem(hwndDlg, IDC_GWLIST), This, FALSE);
1296 SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
1297 return TRUE;
1298 }
1299 break;
1300 case WM_COMMAND:
1301 if (LOWORD(wParam) == IDC_AUTOMETRIC)
1302 {
1303 if (SendDlgItemMessageW(hwndDlg, IDC_AUTOMETRIC, BM_GETCHECK, 0, 0) == BST_CHECKED)
1304 EnableWindow(GetDlgItem(hwndDlg, IDC_METRIC), FALSE);
1305 else
1306 EnableWindow(GetDlgItem(hwndDlg, IDC_METRIC), TRUE);
1307 }
1308 else if (LOWORD(wParam) == IDC_IPADD)
1309 {
1310 Ip.bAdd = TRUE;
1311 Ip.hDlgCtrl = GetDlgItem(hwndDlg, IDC_IPLIST);
1312 res = DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIPADDIP_DLG), hwndDlg, TcpipAddIpDlg, (LPARAM)&Ip);
1313 if (res)
1314 {
1315 memset(&li, 0x0, sizeof(LVITEMW));
1316 li.mask = LVIF_TEXT | LVIF_PARAM;
1317 li.iItem = ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_IPLIST));
1318 li.pszText = Ip.szIP;
1319 li.iItem = SendDlgItemMessageW(hwndDlg, IDC_IPLIST, LVM_INSERTITEMW, 0, (LPARAM)&li);
1320 if (li.iItem != -1)
1321 {
1322 li.mask = LVIF_TEXT;
1323 li.iSubItem = 1;
1324 li.pszText = Ip.szMask;
1325 SendDlgItemMessageW(hwndDlg, IDC_IPLIST, LVM_SETITEMW, 0, (LPARAM)&li);
1326 }
1327 }
1328 }
1329 else if (LOWORD(wParam) == IDC_IPMOD)
1330 {
1331 memset(&li, 0x0, sizeof(LVITEMW));
1332 li.iItem = GetSelectedItem(GetDlgItem(hwndDlg, IDC_IPLIST));
1333 if (li.iItem < 0)
1334 {
1335 /* no item selected */
1336 DisplayError(IDS_NOITEMSEL, IDS_TCPIP, MB_ICONINFORMATION);
1337 SetFocus(GetDlgItem(hwndDlg, IDC_IPLIST));
1338 break;
1339 }
1340 Ip.bAdd = FALSE;
1341 Ip.hDlgCtrl = GetDlgItem(hwndDlg, IDC_IPLIST);
1342 if (GetIPListEntry(GetDlgItem(hwndDlg, IDC_IPLIST), li.iItem, &Ip))
1343 {
1344 res = DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIPADDIP_DLG), hwndDlg, TcpipAddIpDlg, (LPARAM)&Ip);
1345 if (res)
1346 {
1347 li.mask = LVIF_TEXT;
1348 li.pszText = Ip.szIP;
1349 SendDlgItemMessageW(hwndDlg, IDC_IPLIST, LVM_SETITEMW, 0, (LPARAM)&li);
1350 li.pszText = Ip.szMask;
1351 li.iSubItem = 1;
1352 SendDlgItemMessageW(hwndDlg, IDC_IPLIST, LVM_SETITEMW, 0, (LPARAM)&li);
1353 }
1354 }
1355 }
1356 else if (LOWORD(wParam) == IDC_IPDEL)
1357 {
1358 DeleteItemFromList(GetDlgItem(hwndDlg, IDC_IPLIST));
1359 break;
1360 }
1361 else if (LOWORD(wParam) == IDC_GWADD)
1362 {
1363 Gw.bAdd = TRUE;
1364 Gw.hDlgCtrl = GetDlgItem(hwndDlg, IDC_GWLIST);
1365 res = DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIPGW_DLG), hwndDlg, TcpipAdvGwDlg, (LPARAM)&Gw);
1366 if (res)
1367 {
1368 memset(&li, 0x0, sizeof(LVITEMW));
1369 li.mask = LVIF_TEXT;
1370 li.iItem = ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_GWLIST));
1371 li.pszText = Gw.szIP;
1372 li.iItem = SendDlgItemMessageW(hwndDlg, IDC_GWLIST, LVM_INSERTITEMW, 0, (LPARAM)&li);
1373 if (li.iItem >= 0)
1374 {
1375 if (Gw.Metric)
1376 {
1377 swprintf(szBuffer, L"%u", Gw.Metric);
1378 li.iSubItem = 1;
1379 li.pszText = szBuffer;
1380 SendDlgItemMessageW(hwndDlg, IDC_GWLIST, LVM_SETITEMW, 0, (LPARAM)&li);
1381 }
1382 else
1383 {
1384 if (LoadStringW(netcfgx_hInstance, IDS_AUTOMATIC, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1385 {
1386 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1387 li.iSubItem = 1;
1388 li.pszText = szBuffer;
1389 SendDlgItemMessageW(hwndDlg, IDC_GWLIST, LVM_SETITEMW, 0, (LPARAM)&li);
1390 }
1391 }
1392 }
1393 }
1394 break;
1395 }
1396 else if (LOWORD(wParam) == IDC_GWMOD)
1397 {
1398 memset(&li, 0x0, sizeof(LVITEMW));
1399 li.iItem = GetSelectedItem(GetDlgItem(hwndDlg, IDC_GWLIST));
1400 if (li.iItem < 0)
1401 {
1402 /* no item selected */
1403 DisplayError(IDS_NOITEMSEL, IDS_TCPIP, MB_ICONINFORMATION);
1404 SetFocus(GetDlgItem(hwndDlg, IDC_GWLIST));
1405 break;
1406 }
1407 if (GetGWListEntry(GetDlgItem(hwndDlg, IDC_GWLIST), li.iItem, &Gw))
1408 {
1409 Gw.bAdd = FALSE;
1410 Gw.hDlgCtrl = GetDlgItem(hwndDlg, IDC_GWLIST);
1411 res = DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIPGW_DLG), hwndDlg, TcpipAdvGwDlg, (LPARAM)&Gw);
1412 if (res)
1413 {
1414 li.mask = LVIF_TEXT;
1415 li.pszText = Gw.szIP;
1416 (void)SendDlgItemMessageW(hwndDlg, IDC_GWLIST, LVM_SETITEMW, 0, (LPARAM)&li);
1417 if (Gw.Metric)
1418 {
1419 swprintf(szBuffer, L"%u", Gw.Metric);
1420 li.iSubItem = 1;
1421 li.pszText = szBuffer;
1422 SendDlgItemMessageW(hwndDlg, IDC_GWLIST, LVM_SETITEMW, 0, (LPARAM)&li);
1423 }
1424 else
1425 {
1426 if (LoadStringW(netcfgx_hInstance, IDS_AUTOMATIC, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1427 {
1428 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1429 li.iSubItem = 1;
1430 li.pszText = szBuffer;
1431 SendDlgItemMessageW(hwndDlg, IDC_GWLIST, LVM_SETITEMW, 0, (LPARAM)&li);
1432 }
1433 }
1434 }
1435 }
1436 break;
1437 }
1438 else if (LOWORD(wParam) == IDC_GWDEL)
1439 {
1440 DeleteItemFromList(GetDlgItem(hwndDlg, IDC_GWLIST));
1441 break;
1442 }
1443 }
1444 return FALSE;
1445 }
1446
1447 INT_PTR
1448 CALLBACK
1449 TcpipAddDNSDlg(
1450 HWND hwndDlg,
1451 UINT uMsg,
1452 WPARAM wParam,
1453 LPARAM lParam
1454 )
1455 {
1456 TcpipDnsSettings * pSettings;
1457 WCHAR szBuffer[100];
1458 DWORD dwIpAddr;
1459 LPNMIPADDRESS lpnmipa;
1460
1461 switch(uMsg)
1462 {
1463 case WM_INITDIALOG:
1464 pSettings = (TcpipDnsSettings*)lParam;
1465 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
1466 if (!pSettings->bAdd)
1467 {
1468 if (LoadStringW(netcfgx_hInstance, IDS_MOD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1469 {
1470 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1471 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
1472 }
1473 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_SETTEXT, 0, (LPARAM)pSettings->szIP);
1474 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), TRUE);
1475 }
1476 else
1477 {
1478 if (LoadStringW(netcfgx_hInstance, IDS_ADD, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1479 {
1480 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1481 SendDlgItemMessageW(hwndDlg, IDC_OK, WM_SETTEXT, 0, (LPARAM)szBuffer);
1482 }
1483 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), FALSE);
1484 }
1485 return TRUE;
1486 case WM_COMMAND:
1487 if (LOWORD(wParam) == IDCANCEL)
1488 {
1489 EndDialog(hwndDlg, FALSE);
1490 break;
1491 }
1492 else if (LOWORD(wParam) == IDC_OK)
1493 {
1494 pSettings = (TcpipDnsSettings*)GetWindowLongPtr(hwndDlg, DWLP_USER);
1495 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, WM_GETTEXT, 16, (LPARAM)pSettings->szIP);
1496 if (SendMessageW(pSettings->hDlgCtrl, LB_FINDSTRING, 0, (LPARAM)pSettings->szIP) == LB_ERR)
1497 {
1498 if (pSettings->bAdd)
1499 SendMessageW(pSettings->hDlgCtrl, LB_ADDSTRING, 0, (LPARAM)pSettings->szIP);
1500 EndDialog(hwndDlg, TRUE);
1501 break;
1502 }
1503 if (!pSettings->bAdd)
1504 {
1505 EndDialog(hwndDlg, FALSE);
1506 break;
1507 }
1508 DisplayError(IDS_DUP_SUFFIX, IDS_TCPIP, MB_ICONERROR);
1509 break;
1510 }
1511 break;
1512 case WM_NOTIFY:
1513 lpnmipa = (LPNMIPADDRESS) lParam;
1514 if (lpnmipa->hdr.code == IPN_FIELDCHANGED)
1515 {
1516 if (lpnmipa->hdr.idFrom == IDC_IPADDR)
1517 {
1518 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
1519 EnableWindow(GetDlgItem(hwndDlg, IDC_OK), TRUE);
1520 }
1521 }
1522 break;
1523 }
1524 return FALSE;
1525 }
1526
1527
1528
1529 VOID
1530 InitializeTcpipAdvancedDNSDlg(
1531 HWND hwndDlg,
1532 TcpipConfNotifyImpl * This)
1533 {
1534 WCHAR szBuffer[200];
1535 LPWSTR pFirst, pSep, pList;
1536 IP_ADDR * pAddr;
1537 DWORD dwIpAddr;
1538
1539 /* insert DNS addresses */
1540 pAddr = This->pCurrentConfig->Ns;
1541 while(pAddr)
1542 {
1543 dwIpAddr = pAddr->IpAddress;
1544 swprintf(szBuffer, L"%lu.%lu.%lu.%lu",
1545 FIRST_IPADDRESS(dwIpAddr), SECOND_IPADDRESS(dwIpAddr), THIRD_IPADDRESS(dwIpAddr), FOURTH_IPADDRESS(dwIpAddr));
1546
1547 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_ADDSTRING, 0, (LPARAM)szBuffer);
1548 pAddr = pAddr->Next;
1549 }
1550 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_SETCURSEL, 0, 0);
1551
1552 if (!This->pCurrentConfig->pDNS)
1553 return;
1554
1555 if (This->pCurrentConfig->pDNS->RegisterAdapterName)
1556 SendDlgItemMessageW(hwndDlg, IDC_REGSUFFIX, BM_SETCHECK, BST_CHECKED, 0);
1557 else
1558 EnableWindow(GetDlgItem(hwndDlg, IDC_USESUFFIX), FALSE);
1559
1560 if (This->pCurrentConfig->pDNS->RegistrationEnabled)
1561 SendDlgItemMessageW(hwndDlg, IDC_USESUFFIX, BM_SETCHECK, BST_CHECKED, 0);
1562
1563 if (This->pCurrentConfig->pDNS->szDomain[0])
1564 SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_SETTEXT, 0, (LPARAM)szBuffer);
1565
1566 if (This->pCurrentConfig->pDNS->UseDomainNameDevolution)
1567 SendDlgItemMessageW(hwndDlg, IDC_TOPPRIMSUFFIX, BM_SETCHECK, BST_CHECKED, 0);
1568
1569 if (!This->pCurrentConfig->pDNS->szSearchList || (wcslen(This->pCurrentConfig->pDNS->szSearchList) == 0))
1570 {
1571 SendDlgItemMessageW(hwndDlg, IDC_PRIMSUFFIX, BM_SETCHECK, BST_CHECKED, 0);
1572 EnableWindow(GetDlgItem(hwndDlg, IDC_DNSSUFFIXADD), FALSE);
1573
1574 return;
1575 }
1576
1577 pList = This->pCurrentConfig->pDNS->szSearchList;
1578 if (wcslen(pList))
1579 {
1580 pFirst = pList;
1581 do
1582 {
1583 pSep = wcschr(pFirst, L',');
1584 if (pSep)
1585 {
1586 pSep[0] = L'\0';
1587 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_ADDSTRING, 0, (LPARAM)pFirst);
1588 pFirst = pSep + 1;
1589 pSep[0] = L',';
1590 }
1591 else
1592 {
1593 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_ADDSTRING, 0, (LPARAM)pFirst);
1594 break;
1595 }
1596 }while(TRUE);
1597
1598 EnableWindow(GetDlgItem(hwndDlg, IDC_TOPPRIMSUFFIX), FALSE);
1599 SendDlgItemMessageW(hwndDlg, IDC_SELSUFFIX, BM_SETCHECK, BST_CHECKED, 0);
1600 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_SETCURSEL, 0, 0);
1601 }
1602 }
1603
1604 VOID
1605 ToggleUpDown(HWND hwndDlg, HWND hDlgCtrl, UINT UpButton, UINT DownButton, UINT ModButton, UINT DelButton)
1606 {
1607 LRESULT lResult, lCount;
1608
1609 lResult = SendMessageW(hDlgCtrl, LB_GETCURSEL, 0, 0);
1610 lCount = SendMessageW(hDlgCtrl, LB_GETCOUNT, 0, 0);
1611 if (lResult != LB_ERR)
1612 {
1613 if (lResult == 0)
1614 EnableWindow(GetDlgItem(hwndDlg, UpButton), FALSE);
1615 else
1616 EnableWindow(GetDlgItem(hwndDlg, UpButton), TRUE);
1617
1618 if (lResult < lCount -1)
1619 EnableWindow(GetDlgItem(hwndDlg, DownButton), TRUE);
1620 else
1621 EnableWindow(GetDlgItem(hwndDlg, DownButton), FALSE);
1622 }
1623
1624 if (lCount)
1625 {
1626 EnableWindow(GetDlgItem(hwndDlg, ModButton), TRUE);
1627 EnableWindow(GetDlgItem(hwndDlg, DelButton), TRUE);
1628 }
1629 else
1630 {
1631 EnableWindow(GetDlgItem(hwndDlg, ModButton), FALSE);
1632 EnableWindow(GetDlgItem(hwndDlg, DelButton), FALSE);
1633 EnableWindow(GetDlgItem(hwndDlg, UpButton), FALSE);
1634 EnableWindow(GetDlgItem(hwndDlg, DownButton), FALSE);
1635 }
1636 }
1637
1638 VOID
1639 MoveItem(
1640 HWND hDlgCtrl,
1641 INT pos)
1642 {
1643 WCHAR szBuffer[100];
1644 LRESULT lResult;
1645
1646 lResult = SendMessageW(hDlgCtrl, LB_GETCURSEL, 0, 0);
1647 if (lResult != LB_ERR)
1648 {
1649 if (SendMessageW(hDlgCtrl, LB_GETTEXTLEN, (WPARAM)lResult, 0) < sizeof(szBuffer)/sizeof(WCHAR) - 1)
1650 {
1651 if (SendMessageW(hDlgCtrl, LB_GETTEXT, (WPARAM)lResult, (LPARAM)szBuffer) != LB_ERR)
1652 {
1653 SendMessageW(hDlgCtrl, LB_DELETESTRING, (WPARAM)lResult, 0);
1654 SendMessageW(hDlgCtrl, LB_INSERTSTRING, (WPARAM)lResult + pos, (LPARAM)szBuffer);
1655 SendMessageW(hDlgCtrl, LB_SETCURSEL, (WPARAM)lResult + pos, 0);
1656 }
1657 }
1658 }
1659 }
1660 VOID
1661 RemoveItem(
1662 HWND hDlgCtrl)
1663 {
1664 LRESULT lResult, lCount;
1665
1666 lResult = SendMessageW(hDlgCtrl, LB_GETCURSEL, 0, 0);
1667 if (lResult != LB_ERR)
1668 {
1669 SendMessageW(hDlgCtrl, LB_DELETESTRING, (WPARAM)lResult, 0);
1670 lCount = SendMessageW(hDlgCtrl, LB_GETCOUNT, 0, 0);
1671 if (lResult + 1 < lCount)
1672 SendMessageW(hDlgCtrl, LB_SETCURSEL, (WPARAM)lResult, 0);
1673 else
1674 SendMessageW(hDlgCtrl, LB_SETCURSEL, (WPARAM)lCount-1, 0);
1675 }
1676 }
1677
1678 LPWSTR
1679 GetListViewEntries(
1680 HWND hDlgCtrl)
1681 {
1682 DWORD dwSize;
1683 INT iCount, iIndex;
1684 INT_PTR lResult;
1685 LPWSTR pszSearchList, pItem;
1686
1687 iCount = SendMessageW(hDlgCtrl, LB_GETCOUNT, 0, 0);
1688 if (!iCount || iCount == LB_ERR)
1689 return NULL; //BUGBUG
1690
1691 dwSize = 0;
1692
1693 for (iIndex = 0; iIndex < iCount; iIndex++)
1694 {
1695 lResult = SendMessageW(hDlgCtrl, LB_GETTEXTLEN, iIndex, 0);
1696 if (lResult == LB_ERR)
1697 return NULL;
1698
1699 dwSize += lResult + 1;
1700 }
1701
1702 pszSearchList = (LPWSTR)CoTaskMemAlloc((dwSize + 1) * sizeof(WCHAR));
1703 if (!pszSearchList)
1704 return NULL;
1705
1706 pItem = pszSearchList;
1707 for (iIndex = 0; iIndex < iCount; iIndex++)
1708 {
1709 lResult = SendMessageW(hDlgCtrl, LB_GETTEXT, iIndex, (LPARAM)pItem);
1710 if (lResult == LB_ERR)
1711 {
1712 CoTaskMemFree(pszSearchList);
1713 return NULL;
1714 }
1715 dwSize -= lResult + 1;
1716 pItem += wcslen(pItem);
1717 if (iIndex != iCount -1)
1718 {
1719 pItem[0] = L',';
1720 pItem++;
1721 }
1722 }
1723 pItem[0] = L'\0';
1724 return pszSearchList;
1725 }
1726
1727 VOID
1728 StoreDNSSettings(
1729 HWND hDlgCtrl,
1730 TcpipConfNotifyImpl *This)
1731 {
1732 INT iCount, iIndex;
1733 WCHAR Ip[16];
1734 IP_ADDR *pCur, *pLast;
1735
1736 FreeIPAddr(This->pCurrentConfig->Ns);
1737 This->pCurrentConfig->Ns = NULL;
1738
1739 iCount = SendMessageW(hDlgCtrl, LB_GETCOUNT, 0, 0);
1740 if (!iCount || iCount == LB_ERR)
1741 {
1742 return;
1743 }
1744
1745 pLast = NULL;
1746 for(iIndex = 0; iIndex < iCount; iIndex++)
1747 {
1748 if (SendMessageW(hDlgCtrl, LB_GETTEXT, iIndex, (LPARAM)Ip) == LB_ERR)
1749 break;
1750
1751 pCur = CoTaskMemAlloc(sizeof(IP_ADDR));
1752 if (!pCur)
1753 break;
1754 ZeroMemory(pCur, sizeof(IP_ADDR));
1755 pCur->IpAddress = GetIpAddressFromStringW(Ip);
1756
1757 if (!pLast)
1758 This->pCurrentConfig->Ns = pCur;
1759 else
1760 pLast->Next = pCur;
1761
1762 pLast = pCur;
1763 pCur = pCur->Next;
1764 }
1765 This->pCurrentConfig->AutoconfigActive = FALSE;
1766 }
1767
1768 INT_PTR
1769 CALLBACK
1770 TcpipAdvancedDnsDlg(
1771 HWND hwndDlg,
1772 UINT uMsg,
1773 WPARAM wParam,
1774 LPARAM lParam
1775 )
1776 {
1777 TcpipConfNotifyImpl * This;
1778 LPPROPSHEETPAGE page;
1779 TcpipDnsSettings Dns;
1780 LRESULT lIndex, lLength;
1781 TcpipSuffixSettings Suffix;
1782 LPPSHNOTIFY lppsn;
1783 WCHAR szSuffix[100];
1784 WCHAR szFormat[200];
1785 WCHAR szBuffer[300];
1786
1787
1788 switch(uMsg)
1789 {
1790 case WM_INITDIALOG:
1791 page = (LPPROPSHEETPAGE)lParam;
1792 This = (TcpipConfNotifyImpl*)page->lParam;
1793 SetWindowLongPtr(hwndDlg, DWLP_USER, (INT_PTR)This);
1794 InitializeTcpipAdvancedDNSDlg(hwndDlg, This);
1795 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSADDRLIST), IDC_DNSADDRUP, IDC_DNSADDRDOWN, IDC_DNSADDRMOD, IDC_DNSADDRDEL);
1796 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), IDC_DNSSUFFIXUP, IDC_DNSSUFFIXDOWN, IDC_DNSSUFFIXMOD, IDC_DNSSUFFIXDEL);
1797 return TRUE;
1798 case WM_NOTIFY:
1799 lppsn = (LPPSHNOTIFY) lParam;
1800 if (lppsn->hdr.code == PSN_KILLACTIVE)
1801 {
1802 if (SendDlgItemMessageW(hwndDlg, IDC_SELSUFFIX, BM_GETCHECK, 0, 0) == BST_CHECKED &&
1803 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_GETCOUNT, 0, 0) == 0)
1804 {
1805 DisplayError(IDS_NO_SUFFIX, IDS_TCPIP, MB_ICONWARNING);
1806 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, TRUE);
1807 return TRUE;
1808 }
1809 if (SendDlgItemMessageW(hwndDlg, IDC_SUFFIX, WM_GETTEXT, sizeof(szSuffix)/sizeof(WCHAR), (LPARAM)szSuffix))
1810 {
1811 szSuffix[(sizeof(szSuffix)/sizeof(WCHAR))-1] = L'\0';
1812 if (VerifyDNSSuffix(szSuffix) == FALSE)
1813 {
1814 if (LoadStringW(netcfgx_hInstance, IDS_DNS_SUFFIX, szFormat, sizeof(szFormat)/sizeof(WCHAR)))
1815 {
1816 szFormat[(sizeof(szFormat)/sizeof(WCHAR))-1] = L'\0';
1817 swprintf(szBuffer, szFormat, szSuffix);
1818 if (LoadStringW(netcfgx_hInstance, IDS_TCPIP, szFormat, sizeof(szFormat)/sizeof(WCHAR)))
1819 szFormat[(sizeof(szFormat)/sizeof(WCHAR))-1] = L'\0';
1820 else
1821 szFormat[0] = L'\0';
1822
1823 MessageBoxW(hwndDlg, szBuffer, szFormat, MB_ICONWARNING);
1824 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, TRUE);
1825 SetFocus(GetDlgItem(hwndDlg, IDC_SUFFIX));
1826 return TRUE;
1827 }
1828 }
1829 }
1830 }
1831 else if (lppsn->hdr.code == PSN_APPLY)
1832 {
1833 This = (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER);
1834 if (!This->pCurrentConfig->pDNS)
1835 break;
1836
1837 StoreDNSSettings(GetDlgItem(hwndDlg, IDC_DNSADDRLIST), This);
1838 if (SendDlgItemMessageW(hwndDlg, IDC_PRIMSUFFIX, BM_GETCHECK, 0, 0) == BST_CHECKED)
1839 {
1840 CoTaskMemFree(This->pCurrentConfig->pDNS->szSearchList);
1841 This->pCurrentConfig->pDNS->szSearchList = NULL;
1842 if (SendDlgItemMessageW(hwndDlg, IDC_TOPPRIMSUFFIX, BM_GETCHECK, 0, 0) == BST_CHECKED)
1843 This->pCurrentConfig->pDNS->UseDomainNameDevolution = TRUE;
1844 else
1845 This->pCurrentConfig->pDNS->UseDomainNameDevolution = FALSE;
1846 }
1847 else
1848 {
1849 CoTaskMemFree(This->pCurrentConfig->pDNS->szSearchList);
1850 This->pCurrentConfig->pDNS->szSearchList = NULL;
1851 This->pCurrentConfig->pDNS->UseDomainNameDevolution = FALSE;
1852 This->pCurrentConfig->pDNS->szSearchList = GetListViewEntries(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST));
1853 }
1854
1855 if (SendDlgItemMessageW(hwndDlg, IDC_REGSUFFIX, BM_GETCHECK, 0, 0) == BST_CHECKED)
1856 {
1857 This->pCurrentConfig->pDNS->RegisterAdapterName = TRUE;
1858 if (SendDlgItemMessageW(hwndDlg, IDC_USESUFFIX, BM_GETCHECK, 0, 0) == BST_CHECKED)
1859 This->pCurrentConfig->pDNS->RegistrationEnabled = TRUE;
1860 else
1861 This->pCurrentConfig->pDNS->RegistrationEnabled = FALSE;
1862 }
1863 else
1864 {
1865 This->pCurrentConfig->pDNS->RegisterAdapterName = FALSE;
1866 This->pCurrentConfig->pDNS->RegistrationEnabled = FALSE;
1867 }
1868 }
1869 break;
1870 case WM_COMMAND:
1871 if (LOWORD(wParam) == IDC_DNSADDRLIST && HIWORD(wParam) == LBN_SELCHANGE)
1872 {
1873 ToggleUpDown(hwndDlg, (HWND)lParam, IDC_DNSADDRUP, IDC_DNSADDRDOWN, IDC_DNSADDRMOD, IDC_DNSADDRDEL);
1874 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1875 break;
1876 }
1877 else if (LOWORD(wParam) == IDC_DNSSUFFIXLIST && HIWORD(wParam) == LBN_SELCHANGE)
1878 {
1879 ToggleUpDown(hwndDlg, (HWND)lParam, IDC_DNSSUFFIXUP, IDC_DNSSUFFIXDOWN, IDC_DNSSUFFIXMOD, IDC_DNSSUFFIXDEL);
1880 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1881 break;
1882 }
1883 else if (LOWORD(wParam) == IDC_PRIMSUFFIX && HIWORD(wParam) == BN_CLICKED)
1884 {
1885 if (SendMessageW((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED)
1886 {
1887 EnableWindow(GetDlgItem(hwndDlg, IDC_DNSSUFFIXUP), FALSE);
1888 EnableWindow(GetDlgItem(hwndDlg, IDC_DNSSUFFIXDOWN), FALSE);
1889 EnableWindow(GetDlgItem(hwndDlg, IDC_DNSSUFFIXADD), FALSE);
1890 EnableWindow(GetDlgItem(hwndDlg, IDC_DNSSUFFIXMOD), FALSE);
1891 EnableWindow(GetDlgItem(hwndDlg, IDC_DNSSUFFIXDEL), FALSE);
1892 EnableWindow(GetDlgItem(hwndDlg, IDC_TOPPRIMSUFFIX), TRUE);
1893 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_RESETCONTENT, 0, 0);
1894 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1895 }
1896 }
1897 else if (LOWORD(wParam) == IDC_SELSUFFIX && HIWORD(wParam) == BN_CLICKED)
1898 {
1899 if (SendMessageW((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED)
1900 {
1901 EnableWindow(GetDlgItem(hwndDlg, IDC_DNSSUFFIXADD), TRUE);
1902 EnableWindow(GetDlgItem(hwndDlg, IDC_TOPPRIMSUFFIX), FALSE);
1903 ToggleUpDown(hwndDlg, (HWND)lParam, IDC_DNSSUFFIXUP, IDC_DNSSUFFIXDOWN, IDC_DNSSUFFIXMOD, IDC_DNSSUFFIXDEL);
1904 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1905 }
1906 break;
1907 }
1908 else if (LOWORD(wParam) == IDC_REGSUFFIX && HIWORD(wParam) == BN_CLICKED)
1909 {
1910 if (SendMessageW((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED)
1911 EnableWindow(GetDlgItem(hwndDlg, IDC_USESUFFIX), TRUE);
1912 else
1913 EnableWindow(GetDlgItem(hwndDlg, IDC_USESUFFIX), FALSE);
1914 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1915 }
1916 else if (LOWORD(wParam) == IDC_DNSADDRUP && HIWORD(wParam) == BN_CLICKED)
1917 {
1918 MoveItem(GetDlgItem(hwndDlg, IDC_DNSADDRLIST), -1);
1919 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSADDRLIST), IDC_DNSADDRUP, IDC_DNSADDRDOWN, IDC_DNSADDRMOD, IDC_DNSADDRDEL);
1920 SetFocus(GetDlgItem(hwndDlg, IDC_DNSADDRLIST));
1921 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1922 break;
1923 }
1924 else if (LOWORD(wParam) == IDC_DNSADDRDOWN && HIWORD(wParam) == BN_CLICKED)
1925 {
1926 MoveItem(GetDlgItem(hwndDlg, IDC_DNSADDRLIST), 1);
1927 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSADDRLIST), IDC_DNSADDRUP, IDC_DNSADDRDOWN, IDC_DNSADDRMOD, IDC_DNSADDRDEL);
1928 SetFocus(GetDlgItem(hwndDlg, IDC_DNSADDRLIST));
1929 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1930 break;
1931 }
1932 else if (LOWORD(wParam) == IDC_DNSSUFFIXUP && HIWORD(wParam) == BN_CLICKED)
1933 {
1934 MoveItem(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), -1);
1935 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), IDC_DNSSUFFIXUP, IDC_DNSSUFFIXDOWN, IDC_DNSSUFFIXMOD, IDC_DNSSUFFIXDEL);
1936 SetFocus(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST));
1937 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1938 break;
1939 }
1940 else if (LOWORD(wParam) == IDC_DNSSUFFIXDOWN && HIWORD(wParam) == BN_CLICKED)
1941 {
1942 MoveItem(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), 1);
1943 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), IDC_DNSSUFFIXUP, IDC_DNSSUFFIXDOWN, IDC_DNSSUFFIXMOD, IDC_DNSSUFFIXDEL);
1944 SetFocus(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST));
1945 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1946 break;
1947 }
1948 else if (LOWORD(wParam) == IDC_DNSADDRDEL && HIWORD(wParam) == BN_CLICKED)
1949 {
1950 RemoveItem(GetDlgItem(hwndDlg, IDC_DNSADDRLIST));
1951 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSADDRLIST), IDC_DNSADDRUP, IDC_DNSADDRDOWN, IDC_DNSADDRMOD, IDC_DNSADDRDEL);
1952 SetFocus(GetDlgItem(hwndDlg, IDC_DNSADDRLIST));
1953 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1954 break;
1955 }
1956 else if (LOWORD(wParam) == IDC_DNSSUFFIXDEL && HIWORD(wParam) == BN_CLICKED)
1957 {
1958 RemoveItem(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST));
1959 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), IDC_DNSSUFFIXUP, IDC_DNSSUFFIXDOWN, IDC_DNSSUFFIXMOD, IDC_DNSSUFFIXDEL);
1960 SetFocus(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST));
1961 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1962 break;
1963 }
1964 else if (LOWORD(wParam) == IDC_DNSADDRADD && HIWORD(wParam) == BN_CLICKED)
1965 {
1966 Dns.bAdd = TRUE;
1967 Dns.hDlgCtrl = GetDlgItem(hwndDlg, IDC_DNSADDRLIST);
1968 if (DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIPDNS_DLG), NULL, TcpipAddDNSDlg, (LPARAM)&Dns))
1969 {
1970 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSADDRLIST), IDC_DNSADDRUP, IDC_DNSADDRDOWN, IDC_DNSADDRMOD, IDC_DNSADDRDEL);
1971 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1972 }
1973 break;
1974 }
1975 else if (LOWORD(wParam) == IDC_DNSADDRMOD && HIWORD(wParam) == BN_CLICKED)
1976 {
1977 lIndex = SendDlgItemMessage(hwndDlg, IDC_DNSADDRLIST, LB_GETCURSEL, 0, 0);
1978 if (lIndex != LB_ERR)
1979 {
1980 Dns.bAdd = FALSE;
1981 Dns.hDlgCtrl = GetDlgItem(hwndDlg, IDC_DNSADDRLIST);
1982 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_GETTEXT, (WPARAM)lIndex, (LPARAM)Dns.szIP);
1983 if (DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIPDNS_DLG), NULL, TcpipAddDNSDlg, (LPARAM)&Dns))
1984 {
1985 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_DELETESTRING, lIndex, 0);
1986 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_INSERTSTRING, lIndex, (LPARAM)Dns.szIP);
1987 SendDlgItemMessageW(hwndDlg, IDC_DNSADDRLIST, LB_SETCURSEL, lIndex, 0);
1988 SetFocus(GetDlgItem(hwndDlg, IDC_DNSADDRLIST));
1989 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
1990 }
1991 }
1992 break;
1993 }
1994 else if (LOWORD(wParam) == IDC_DNSSUFFIXADD && HIWORD(wParam) == BN_CLICKED)
1995 {
1996 Suffix.bAdd = TRUE;
1997 Suffix.hDlgCtrl = GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST);
1998 Suffix.Suffix = NULL;
1999 if (DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIPSUFFIX_DLG), NULL, TcpipAddSuffixDlg, (LPARAM)&Suffix))
2000 {
2001 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), IDC_DNSSUFFIXUP, IDC_DNSSUFFIXDOWN, IDC_DNSSUFFIXMOD, IDC_DNSSUFFIXDEL);
2002 lIndex = SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_ADDSTRING, 0, (LPARAM)Suffix.Suffix);
2003 if (lIndex != LB_ERR)
2004 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_SETCURSEL, lIndex, 0);
2005 SetFocus(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST));
2006 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2007 CoTaskMemFree(Suffix.Suffix);
2008 }
2009 break;
2010 }
2011 else if (LOWORD(wParam) == IDC_DNSSUFFIXMOD && HIWORD(wParam) == BN_CLICKED)
2012 {
2013 lIndex = SendDlgItemMessage(hwndDlg, IDC_DNSSUFFIXLIST, LB_GETCURSEL, 0, 0);
2014 if (lIndex != LB_ERR)
2015 {
2016 Suffix.bAdd = FALSE;
2017 Suffix.hDlgCtrl = GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST);
2018 lLength = SendMessageW(Suffix.hDlgCtrl, LB_GETTEXTLEN, lIndex, 0);
2019 if (lLength != LB_ERR)
2020 {
2021 Suffix.Suffix = (LPWSTR)CoTaskMemAlloc((lLength + 1) * sizeof(WCHAR));
2022 if (Suffix.Suffix)
2023 {
2024 SendMessageW(Suffix.hDlgCtrl, LB_GETTEXT, lIndex, (LPARAM)Suffix.Suffix);
2025 Suffix.Suffix[lLength] = L'\0';
2026 if (DialogBoxParamW(netcfgx_hInstance, MAKEINTRESOURCEW(IDD_TCPIPSUFFIX_DLG), NULL, TcpipAddSuffixDlg, (LPARAM)&Suffix))
2027 {
2028 if (Suffix.Suffix)
2029 {
2030 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_DELETESTRING, lIndex, 0);
2031 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_INSERTSTRING, lIndex, (LPARAM)Suffix.Suffix);
2032 SendDlgItemMessageW(hwndDlg, IDC_DNSSUFFIXLIST, LB_SETCURSEL, lIndex, 0);
2033 SetFocus(GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST));
2034 CoTaskMemFree(Suffix.Suffix);
2035 }
2036 ToggleUpDown(hwndDlg, GetDlgItem(hwndDlg, IDC_DNSSUFFIXLIST), IDC_DNSSUFFIXUP, IDC_DNSSUFFIXDOWN, IDC_DNSSUFFIXMOD, IDC_DNSSUFFIXDEL);
2037 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2038 }
2039 }
2040 }
2041 }
2042 break;
2043 }
2044 }
2045 return FALSE;
2046 }
2047
2048 VOID
2049 LaunchAdvancedTcpipSettings(
2050 HWND hwndDlg,
2051 TcpipConfNotifyImpl * This)
2052 {
2053 PROPSHEETHEADERW pinfo;
2054 HPROPSHEETPAGE hppages[3];
2055 WCHAR szBuffer[100];
2056
2057 hppages[0] = InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_TCPIP_ADVIP_DLG), TcpipAdvancedIpDlg, (LPARAM)This, NULL);
2058 hppages[1] = InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_TCPIP_ADVDNS_DLG), TcpipAdvancedDnsDlg, (LPARAM)This, NULL);
2059 hppages[2] = InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_TCPIP_ADVOPT_DLG), TcpipAdvancedOptDlg, (LPARAM)This, NULL);
2060
2061
2062 if (LoadStringW(netcfgx_hInstance, IDS_TCPIP, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
2063 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
2064 else
2065 szBuffer[0] = L'\0';
2066
2067 ZeroMemory(&pinfo, sizeof(PROPSHEETHEADERW));
2068 pinfo.dwSize = sizeof(PROPSHEETHEADERW);
2069 pinfo.dwFlags = PSH_NOCONTEXTHELP | PSH_PROPTITLE | PSH_NOAPPLYNOW;
2070 pinfo.u3.phpage = hppages;
2071 pinfo.nPages = 3;
2072 pinfo.hwndParent = hwndDlg;
2073 pinfo.pszCaption = szBuffer;
2074
2075 StoreTcpipBasicSettings(hwndDlg, This, FALSE);
2076 PropertySheetW(&pinfo);
2077
2078 InitializeTcpipBasicDlgCtrls(hwndDlg, This->pCurrentConfig);
2079 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2080 }
2081
2082 INT_PTR
2083 CALLBACK
2084 TcpipAltConfDlg(
2085 HWND hwndDlg,
2086 UINT uMsg,
2087 WPARAM wParam,
2088 LPARAM lParam)
2089 {
2090 switch(uMsg)
2091 {
2092 case WM_INITDIALOG:
2093 return TRUE;
2094 }
2095 return FALSE;
2096 }
2097
2098 VOID
2099 AddAlternativeDialog(
2100 HWND hDlg,
2101 TcpipConfNotifyImpl * This)
2102 {
2103 HPROPSHEETPAGE hpage;
2104
2105 hpage = InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_TCPIP_ALTCF_DLG), TcpipAltConfDlg, (LPARAM)This, NULL);
2106 if (!hpage)
2107 return;
2108
2109 SendMessageW(hDlg, PSM_INSERTPAGE, 1, (LPARAM)hpage);
2110 }
2111
2112 INT_PTR
2113 StoreTcpipBasicSettings(
2114 HWND hwndDlg,
2115 TcpipConfNotifyImpl * This,
2116 BOOL bApply)
2117 {
2118 DWORD dwIpAddr;
2119
2120 if (SendDlgItemMessageW(hwndDlg, IDC_NODHCP, BM_GETCHECK, 0, 0) == BST_CHECKED)
2121 {
2122 This->pCurrentConfig->DhcpEnabled = FALSE;
2123 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) != 4)
2124 {
2125 if (bApply)
2126 {
2127 DisplayError(IDS_NO_IPADDR_SET, IDS_TCPIP, MB_ICONWARNING);
2128 SetFocus(GetDlgItem(hwndDlg, IDC_IPADDR));
2129 return E_FAIL;
2130 }
2131 }
2132 if (!This->pCurrentConfig->Ip)
2133 {
2134 This->pCurrentConfig->Ip = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2135 if (!This->pCurrentConfig->Ip)
2136 return E_OUTOFMEMORY;
2137 ZeroMemory(This->pCurrentConfig->Ip, sizeof(IP_ADDR));
2138 }
2139 This->pCurrentConfig->Ip->IpAddress = dwIpAddr;
2140
2141 if (SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) != 4)
2142 {
2143 if (bApply)
2144 DisplayError(IDS_NO_SUBMASK_SET, IDS_TCPIP, MB_ICONWARNING);
2145 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2146 {
2147 if (dwIpAddr <= MAKEIPADDRESS(127, 255, 255, 255))
2148 dwIpAddr = MAKEIPADDRESS(255, 0, 0, 0);
2149 else if (dwIpAddr <= MAKEIPADDRESS(191, 255, 255, 255))
2150 dwIpAddr = MAKEIPADDRESS(255, 255, 0, 0);
2151 else if (dwIpAddr <= MAKEIPADDRESS(223, 255, 255, 255))
2152 dwIpAddr = MAKEIPADDRESS(255, 255, 255, 0);
2153
2154 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)dwIpAddr);
2155 }
2156 if (bApply)
2157 {
2158 SetFocus(GetDlgItem(hwndDlg, IDC_SUBNETMASK));
2159 return E_FAIL;
2160 }
2161 }
2162 /* store subnetmask */
2163 This->pCurrentConfig->Ip->u.Subnetmask = dwIpAddr;
2164
2165 if (SendDlgItemMessageW(hwndDlg, IDC_DEFGATEWAY, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2166 {
2167 if (!This->pCurrentConfig->Gw)
2168 {
2169 This->pCurrentConfig->Gw = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2170 if (!This->pCurrentConfig->Gw)
2171 return E_OUTOFMEMORY;
2172 ZeroMemory(This->pCurrentConfig->Gw, sizeof(IP_ADDR));
2173 }
2174 /* store default gateway */
2175 This->pCurrentConfig->Gw->IpAddress = dwIpAddr;
2176 }
2177 else
2178 {
2179 if (This->pCurrentConfig->Gw)
2180 {
2181 IP_ADDR * pNextGw = This->pCurrentConfig->Gw->Next;
2182 CoTaskMemFree(This->pCurrentConfig->Gw);
2183 This->pCurrentConfig->Gw = pNextGw;
2184 }
2185 }
2186 }
2187 else
2188 {
2189 This->pCurrentConfig->DhcpEnabled = TRUE;
2190 }
2191 if (SendDlgItemMessageW(hwndDlg, IDC_FIXEDDNS, BM_GETCHECK, 0, 0) == BST_CHECKED)
2192 {
2193 BOOL bSkip = FALSE;
2194 This->pCurrentConfig->AutoconfigActive = FALSE;
2195 if (SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2196 {
2197 if (!This->pCurrentConfig->Ns)
2198 {
2199 This->pCurrentConfig->Ns = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2200 if (!This->pCurrentConfig->Ns)
2201 return E_OUTOFMEMORY;
2202 ZeroMemory(This->pCurrentConfig->Ns, sizeof(IP_ADDR));
2203 }
2204 This->pCurrentConfig->Ns->IpAddress = dwIpAddr;
2205 }
2206 else if (This->pCurrentConfig->Ns)
2207 {
2208 IP_ADDR *pTemp = This->pCurrentConfig->Ns->Next;
2209
2210 CoTaskMemFree(This->pCurrentConfig->Ns);
2211 This->pCurrentConfig->Ns = pTemp;
2212 bSkip = TRUE;
2213 }
2214
2215
2216 if (SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2217 {
2218 if (!This->pCurrentConfig->Ns || bSkip)
2219 {
2220 if (!This->pCurrentConfig->Ns)
2221 {
2222 This->pCurrentConfig->Ns = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2223 if (!This->pCurrentConfig->Ns)
2224 return E_OUTOFMEMORY;
2225 ZeroMemory(This->pCurrentConfig->Ns, sizeof(IP_ADDR));
2226 }
2227 This->pCurrentConfig->Ns->IpAddress = dwIpAddr;
2228 }
2229 else if (!This->pCurrentConfig->Ns->Next)
2230 {
2231 This->pCurrentConfig->Ns->Next = (IP_ADDR*)CoTaskMemAlloc(sizeof(IP_ADDR));
2232 if (!This->pCurrentConfig->Ns->Next)
2233 return E_OUTOFMEMORY;
2234 ZeroMemory(This->pCurrentConfig->Ns->Next, sizeof(IP_ADDR));
2235 This->pCurrentConfig->Ns->Next->IpAddress = dwIpAddr;
2236 }
2237 else
2238 {
2239 This->pCurrentConfig->Ns->Next->IpAddress = dwIpAddr;
2240 }
2241 }
2242 else
2243 {
2244 if (This->pCurrentConfig->Ns && This->pCurrentConfig->Ns->Next)
2245 {
2246 if (This->pCurrentConfig->Ns->Next->Next)
2247 {
2248 IP_ADDR *pTemp = This->pCurrentConfig->Ns->Next->Next;
2249 CoTaskMemFree(This->pCurrentConfig->Ns->Next);
2250 This->pCurrentConfig->Ns->Next = pTemp;
2251 }
2252 else
2253 {
2254 CoTaskMemFree(This->pCurrentConfig->Ns->Next);
2255 This->pCurrentConfig->Ns->Next = NULL;
2256 }
2257 }
2258 }
2259 }
2260 else
2261 {
2262 This->pCurrentConfig->AutoconfigActive = TRUE;
2263 }
2264 return S_OK;
2265 }
2266
2267 HRESULT
2268 InitializeTcpipBasicDlgCtrls(
2269 HWND hwndDlg,
2270 TcpipSettings * pCurSettings)
2271 {
2272 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 0, MAKEIPRANGE(1, 223));
2273 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 1, MAKEIPRANGE(0, 255));
2274 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 2, MAKEIPRANGE(0, 255));
2275 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_SETRANGE, 3, MAKEIPRANGE(0, 255));
2276
2277 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETRANGE, 0, MAKEIPRANGE(0, 255));
2278 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETRANGE, 1, MAKEIPRANGE(0, 255));
2279 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETRANGE, 2, MAKEIPRANGE(0, 255));
2280 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETRANGE, 3, MAKEIPRANGE(0, 255));
2281
2282 SendDlgItemMessageW(hwndDlg, IDC_DEFGATEWAY, IPM_SETRANGE, 0, MAKEIPRANGE(1, 223));
2283 SendDlgItemMessageW(hwndDlg, IDC_DEFGATEWAY, IPM_SETRANGE, 1, MAKEIPRANGE(0, 255));
2284 SendDlgItemMessageW(hwndDlg, IDC_DEFGATEWAY, IPM_SETRANGE, 2, MAKEIPRANGE(0, 255));
2285 SendDlgItemMessageW(hwndDlg, IDC_DEFGATEWAY, IPM_SETRANGE, 3, MAKEIPRANGE(0, 255));
2286
2287 SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_SETRANGE, 0, MAKEIPRANGE(1, 223));
2288 SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_SETRANGE, 1, MAKEIPRANGE(0, 255));
2289 SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_SETRANGE, 2, MAKEIPRANGE(0, 255));
2290 SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_SETRANGE, 3, MAKEIPRANGE(0, 255));
2291
2292 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_SETRANGE, 0, MAKEIPRANGE(1, 223));
2293 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_SETRANGE, 1, MAKEIPRANGE(0, 255));
2294 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_SETRANGE, 2, MAKEIPRANGE(0, 255));
2295 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_SETRANGE, 3, MAKEIPRANGE(0, 255));
2296
2297 if (pCurSettings->DhcpEnabled)
2298 {
2299 SendDlgItemMessageW(hwndDlg, IDC_USEDHCP, BM_SETCHECK, BST_CHECKED, 0);
2300 EnableWindow(GetDlgItem(hwndDlg, IDC_IPADDR), FALSE);
2301 EnableWindow(GetDlgItem(hwndDlg, IDC_SUBNETMASK), FALSE);
2302 EnableWindow(GetDlgItem(hwndDlg, IDC_DEFGATEWAY), FALSE);
2303 EnableWindow(GetDlgItem(hwndDlg, IDC_AUTODNS), TRUE);
2304 }
2305 else
2306 {
2307 SendDlgItemMessageW(hwndDlg, IDC_NODHCP, BM_SETCHECK, BST_CHECKED, 0);
2308
2309 if (pCurSettings->Ip)
2310 {
2311 /* set current ip address */
2312 SendDlgItemMessageA(hwndDlg, IDC_IPADDR, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ip->IpAddress);
2313 /* set current hostmask */
2314 SendDlgItemMessageA(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ip->u.Subnetmask);
2315 }
2316 if (pCurSettings->Gw && pCurSettings->Gw->IpAddress)
2317 {
2318 /* set current gateway */
2319 SendDlgItemMessageA(hwndDlg, IDC_DEFGATEWAY, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Gw->IpAddress);
2320 }
2321 }
2322 if (pCurSettings->AutoconfigActive)
2323 {
2324 SendDlgItemMessageW(hwndDlg, IDC_AUTODNS, BM_SETCHECK, BST_CHECKED, 0);
2325 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS1), FALSE);
2326 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS2), FALSE);
2327 }
2328 else
2329 {
2330 SendDlgItemMessageW(hwndDlg, IDC_FIXEDDNS, BM_SETCHECK, BST_CHECKED, 0);
2331 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS1), TRUE);
2332 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS2), TRUE);
2333 if (pCurSettings->Ns)
2334 {
2335 SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ns->IpAddress);
2336 if (pCurSettings->Ns->Next)
2337 {
2338 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_SETADDRESS, 0, (LPARAM)pCurSettings->Ns->Next->IpAddress);
2339 }
2340 else
2341 {
2342 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_CLEARADDRESS, 0, 0);
2343 }
2344 }
2345 else
2346 {
2347 SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_CLEARADDRESS, 0, 0);
2348 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_CLEARADDRESS, 0, 0);
2349 }
2350 }
2351
2352 return S_OK;
2353 }
2354
2355 HRESULT
2356 CopyIpAddrString(
2357 IP_ADDR_STRING * pSrc,
2358 IP_ADDR ** pTarget,
2359 COPY_TYPE Type,
2360 LPWSTR szMetric)
2361 {
2362 LPWSTR szItem;
2363 IP_ADDR_STRING * pCurrent;
2364 IP_ADDR *pNew, *pLast;
2365
2366 pCurrent = pSrc;
2367 pLast = NULL;
2368
2369 szItem = szMetric;
2370
2371 while(pCurrent)
2372 {
2373 pNew = CoTaskMemAlloc(sizeof(IP_ADDR));
2374 if (!pNew)
2375 {
2376 break;
2377 }
2378 ZeroMemory(pNew, sizeof(IP_ADDR));
2379 pNew->IpAddress = GetIpAddressFromStringA(pCurrent->IpAddress.String);
2380 if (!pNew->IpAddress)
2381 {
2382 CoTaskMemFree(pNew);
2383 return E_FAIL;
2384 }
2385
2386 if (Type == SUBMASK)
2387 {
2388 pNew->u.Subnetmask = GetIpAddressFromStringA(pCurrent->IpMask.String);
2389 pNew->NTEContext = pCurrent->Context;
2390 }
2391 else if (Type == METRIC)
2392 {
2393 if (szMetric && szMetric[0] != L'\0')
2394 {
2395 pNew->u.Metric = _wtoi(szMetric);
2396 szMetric += wcslen(szMetric) + 1;
2397 }
2398 }
2399
2400 if (!pLast)
2401 *pTarget = pNew;
2402 else
2403 pLast->Next = pNew;
2404
2405 pLast = pNew;
2406 pCurrent = pCurrent->Next;
2407
2408 }
2409 pLast->Next = NULL;
2410 return S_OK;
2411 }
2412
2413
2414
2415 INT_PTR
2416 CALLBACK
2417 TcpipBasicDlg(
2418 HWND hwndDlg,
2419 UINT uMsg,
2420 WPARAM wParam,
2421 LPARAM lParam
2422 )
2423 {
2424 TcpipConfNotifyImpl * This;
2425 LPPROPSHEETPAGE page;
2426 LPNMIPADDRESS lpnmipa;
2427 LPPSHNOTIFY lppsn;
2428 DWORD dwIpAddr;
2429
2430
2431 switch(uMsg)
2432 {
2433 case WM_INITDIALOG:
2434 page = (LPPROPSHEETPAGE)lParam;
2435 This = (TcpipConfNotifyImpl*)page->lParam;
2436 if (This->pCurrentConfig)
2437 InitializeTcpipBasicDlgCtrls(hwndDlg, This->pCurrentConfig);
2438 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)This);
2439 return TRUE;
2440 case WM_NOTIFY:
2441 lppsn = (LPPSHNOTIFY) lParam;
2442 lpnmipa = (LPNMIPADDRESS) lParam;
2443 if (lpnmipa->hdr.code == IPN_FIELDCHANGED)
2444 {
2445 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2446 if (lpnmipa->hdr.idFrom == IDC_IPADDR)
2447 {
2448 if (SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_GETADDRESS, 0, (LPARAM)&dwIpAddr) == 4)
2449 {
2450 if (dwIpAddr <= MAKEIPADDRESS(127, 255, 255, 255))
2451 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)MAKEIPADDRESS(255, 0, 0, 0));
2452 else if (dwIpAddr <= MAKEIPADDRESS(191, 255, 255, 255))
2453 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)MAKEIPADDRESS(255, 255, 0, 0));
2454 else if (dwIpAddr <= MAKEIPADDRESS(223, 255, 255, 255))
2455 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0, (LPARAM)MAKEIPADDRESS(255, 255, 255, 0));
2456 }
2457 }
2458 }
2459 else if (lppsn->hdr.code == PSN_APPLY)
2460 {
2461 This = (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER);
2462 if (SUCCEEDED(StoreTcpipBasicSettings(hwndDlg, This, TRUE)))
2463 SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
2464 else
2465 SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID);
2466
2467 return TRUE;
2468 }
2469 break;
2470 case WM_COMMAND:
2471 if (HIWORD(wParam) == BN_CLICKED)
2472 {
2473 switch (LOWORD(wParam))
2474 {
2475 case IDC_USEDHCP:
2476 if (SendDlgItemMessageW(hwndDlg, IDC_USEDHCP, BM_GETCHECK, 0, 0) == BST_CHECKED)
2477 {
2478 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2479 SendDlgItemMessageW(hwndDlg, IDC_IPADDR, IPM_CLEARADDRESS, 0, 0);
2480 SendDlgItemMessageW(hwndDlg, IDC_SUBNETMASK, IPM_CLEARADDRESS, 0, 0);
2481 SendDlgItemMessageW(hwndDlg, IDC_DEFGATEWAY, IPM_CLEARADDRESS, 0, 0);
2482 EnableWindow(GetDlgItem(hwndDlg, IDC_IPADDR), FALSE);
2483 EnableWindow(GetDlgItem(hwndDlg, IDC_SUBNETMASK), FALSE);
2484 EnableWindow(GetDlgItem(hwndDlg, IDC_DEFGATEWAY), FALSE);
2485 EnableWindow(GetDlgItem(hwndDlg, IDC_AUTODNS), TRUE);
2486 AddAlternativeDialog(GetParent(hwndDlg), (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER));
2487 }
2488 break;
2489 case IDC_NODHCP:
2490 if (SendDlgItemMessageW(hwndDlg, IDC_NODHCP, BM_GETCHECK, 0, 0) == BST_CHECKED)
2491 {
2492 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2493 EnableWindow(GetDlgItem(hwndDlg, IDC_IPADDR), TRUE);
2494 EnableWindow(GetDlgItem(hwndDlg, IDC_SUBNETMASK), TRUE);
2495 EnableWindow(GetDlgItem(hwndDlg, IDC_DEFGATEWAY), TRUE);
2496 if (SendDlgItemMessageW(hwndDlg, IDC_AUTODNS, BM_GETCHECK, 0, 0) == BST_CHECKED)
2497 {
2498 SendDlgItemMessageW(hwndDlg, IDC_AUTODNS, BM_SETCHECK, BST_UNCHECKED, 0);
2499 }
2500 EnableWindow(GetDlgItem(hwndDlg, IDC_AUTODNS), FALSE);
2501 SendDlgItemMessageW(hwndDlg, IDC_FIXEDDNS, BM_SETCHECK, BST_CHECKED, 0);
2502 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS1), TRUE);
2503 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS2), TRUE);
2504 SendMessageW(GetParent(hwndDlg), PSM_REMOVEPAGE, 1, 0);
2505 }
2506 break;
2507 case IDC_AUTODNS:
2508 if (SendDlgItemMessageW(hwndDlg, IDC_AUTODNS, BM_GETCHECK, 0, 0) == BST_CHECKED)
2509 {
2510 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2511 SendDlgItemMessageW(hwndDlg, IDC_DNS1, IPM_CLEARADDRESS, 0, 0);
2512 SendDlgItemMessageW(hwndDlg, IDC_DNS2, IPM_CLEARADDRESS, 0, 0);
2513 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS1), FALSE);
2514 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS2), FALSE);
2515 }
2516 break;
2517 case IDC_FIXEDDNS:
2518 if (SendDlgItemMessageW(hwndDlg, IDC_FIXEDDNS, BM_GETCHECK, 0, 0) == BST_CHECKED)
2519 {
2520 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2521 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS1), TRUE);
2522 EnableWindow(GetDlgItem(hwndDlg, IDC_DNS2), TRUE);
2523 }
2524 break;
2525 case IDC_ADVANCED:
2526 LaunchAdvancedTcpipSettings(hwndDlg, (TcpipConfNotifyImpl*)GetWindowLongPtr(hwndDlg, DWLP_USER));
2527 break;
2528 }
2529 break;
2530 }
2531 default:
2532 break;
2533
2534 }
2535 return FALSE;
2536 }
2537
2538 /***************************************************************
2539 * INetCfgComponentPropertyUi interface
2540 */
2541
2542 HRESULT
2543 WINAPI
2544 INetCfgComponentPropertyUi_fnQueryInterface(
2545 INetCfgComponentPropertyUi * iface,
2546 REFIID iid,
2547 LPVOID * ppvObj)
2548 {
2549 //LPOLESTR pStr;
2550 TcpipConfNotifyImpl * This = (TcpipConfNotifyImpl*)iface;
2551
2552 *ppvObj = NULL;
2553
2554
2555 if (IsEqualIID (iid, &IID_IUnknown) ||
2556 IsEqualIID (iid, &IID_INetCfgComponentPropertyUi))
2557 {
2558 *ppvObj = This;
2559 INetCfgComponentPropertyUi_AddRef(iface);
2560 return S_OK;
2561 }
2562 else if (IsEqualIID(iid, &IID_INetCfgComponentControl))
2563 {
2564 *ppvObj = (LPVOID*)&This->lpVtblCompControl;
2565 INetCfgComponentPropertyUi_AddRef(iface);
2566 return S_OK;
2567 }
2568
2569 //StringFromCLSID(iid, &pStr);
2570 //MessageBoxW(NULL, pStr, L"INetConnectionPropertyUi_fnQueryInterface", MB_OK);
2571 //CoTaskMemFree(pStr);
2572
2573 return E_NOINTERFACE;
2574 }
2575
2576
2577 ULONG
2578 WINAPI
2579 INetCfgComponentPropertyUi_fnAddRef(
2580 INetCfgComponentPropertyUi * iface)
2581 {
2582 TcpipConfNotifyImpl * This = (TcpipConfNotifyImpl*)iface;
2583 ULONG refCount = InterlockedIncrement(&This->ref);
2584
2585 return refCount;
2586 }
2587
2588 ULONG
2589 WINAPI
2590 INetCfgComponentPropertyUi_fnRelease(
2591 INetCfgComponentPropertyUi * iface)
2592 {
2593 TcpipConfNotifyImpl * This = (TcpipConfNotifyImpl*)iface;
2594 ULONG refCount = InterlockedDecrement(&This->ref);
2595
2596 if (!refCount)
2597 {
2598 CoTaskMemFree(This);
2599 }
2600 return refCount;
2601 }
2602
2603 HRESULT
2604 WINAPI
2605 INetCfgComponentPropertyUi_fnQueryPropertyUi(
2606 INetCfgComponentPropertyUi * iface,
2607 IUnknown *pUnkReserved)
2608 {
2609 INetLanConnectionUiInfo * pLanInfo;
2610 HRESULT hr;
2611 TcpipConfNotifyImpl * This = (TcpipConfNotifyImpl*)iface;
2612
2613 hr = IUnknown_QueryInterface(pUnkReserved, &IID_INetLanConnectionUiInfo, (LPVOID*)&pLanInfo);
2614 if (FAILED(hr))
2615 return hr;
2616
2617 INetLanConnectionUiInfo_GetDeviceGuid(pLanInfo, &This->NetCfgInstanceId);
2618
2619 //FIXME
2620 // check if tcpip is enabled on that binding */
2621 IUnknown_Release(pUnkReserved);
2622 return S_OK;
2623 }
2624
2625 HRESULT
2626 WINAPI
2627 INetCfgComponentPropertyUi_fnSetContext(
2628 INetCfgComponentPropertyUi * iface,
2629 IUnknown *pUnkReserved)
2630 {
2631 TcpipConfNotifyImpl * This = (TcpipConfNotifyImpl*)iface;
2632
2633 if (!iface || !pUnkReserved)
2634 return E_POINTER;
2635
2636 This->pUnknown = pUnkReserved;
2637 return S_OK;
2638 }
2639
2640 HRESULT
2641 LoadDNSSettings(
2642 TcpipConfNotifyImpl * This)
2643 {
2644 LPOLESTR pStr;
2645 WCHAR szBuffer[200];
2646 HKEY hKey;
2647 DWORD dwSize;
2648
2649
2650 This->pCurrentConfig->pDNS = (TcpipAdvancedDNSDlgSettings*) CoTaskMemAlloc(sizeof(TcpipAdvancedDNSDlgSettings));
2651 if (!This->pCurrentConfig->pDNS)
2652 return E_FAIL;
2653
2654 ZeroMemory(This->pCurrentConfig->pDNS, sizeof(TcpipAdvancedDNSDlgSettings));
2655
2656 if (FAILED(StringFromCLSID(&This->NetCfgInstanceId, &pStr)))
2657 return E_FAIL;
2658
2659 swprintf(szBuffer, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s", pStr);
2660 CoTaskMemFree(pStr);
2661 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
2662 {
2663 dwSize = sizeof(DWORD);
2664 RegQueryValueExW(hKey, L"RegisterAdapterName", NULL, NULL, (LPBYTE)&This->pCurrentConfig->pDNS->RegisterAdapterName, &dwSize);
2665 RegQueryValueExW(hKey, L"RegistrationEnabled", NULL, NULL, (LPBYTE)&This->pCurrentConfig->pDNS->RegistrationEnabled, &dwSize);
2666
2667 dwSize = sizeof(This->pCurrentConfig->pDNS->szDomain) / sizeof(WCHAR);
2668 RegQueryValueExW(hKey, L"Domain", NULL, NULL, (LPBYTE)szBuffer, &dwSize);
2669
2670 RegCloseKey(hKey);
2671 }
2672
2673 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
2674 {
2675 dwSize = sizeof(DWORD);
2676 RegQueryValueExW(hKey, L"UseDomainNameDevolution", NULL, NULL, (LPBYTE)&This->pCurrentConfig->pDNS->UseDomainNameDevolution, &dwSize);
2677
2678 dwSize = 0;
2679 if (RegQueryValueExW(hKey, L"SearchList", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS)
2680 {
2681 This->pCurrentConfig->pDNS->szSearchList = (LPWSTR)CoTaskMemAlloc(dwSize);
2682 if (This->pCurrentConfig->pDNS->szSearchList)
2683 {
2684 if (RegQueryValueExW(hKey, L"SearchList", NULL, NULL, (LPBYTE)This->pCurrentConfig->pDNS->szSearchList, &dwSize) != ERROR_SUCCESS)
2685 {
2686 CoTaskMemFree(This->pCurrentConfig->pDNS->szSearchList);
2687 This->pCurrentConfig->pDNS->szSearchList = NULL;
2688 }
2689 }
2690 }
2691 RegCloseKey(hKey);
2692 }
2693 return S_OK;
2694 }
2695
2696 LPWSTR
2697 LoadTcpFilterSettingsFromRegistry(HKEY hKey, LPCWSTR szName, LPDWORD Size)
2698 {
2699 DWORD dwSize;
2700 LPWSTR pData;
2701
2702 if (RegQueryValueExW(hKey, szName, NULL, NULL, NULL, &dwSize) != ERROR_SUCCESS)
2703 return NULL;
2704
2705 pData = (LPWSTR)CoTaskMemAlloc(dwSize);
2706 if (!pData)
2707 return NULL;
2708
2709 if (RegQueryValueExW(hKey, szName, NULL, NULL, (LPBYTE)pData, &dwSize) != ERROR_SUCCESS)
2710 {
2711 CoTaskMemFree(pData);
2712 return NULL;
2713 }
2714 *Size = dwSize;
2715 return pData;
2716 }
2717
2718 HRESULT
2719 LoadFilterSettings(
2720 TcpipConfNotifyImpl * This)
2721 {
2722 HKEY hKey;
2723 TcpFilterSettings *pFilter;
2724 WCHAR szBuffer[200];
2725 LPOLESTR pStr;
2726 DWORD dwVal, dwSize;
2727
2728 pFilter = (TcpFilterSettings*)CoTaskMemAlloc(sizeof(TcpFilterSettings));
2729 if (!pFilter)
2730 return E_FAIL;
2731
2732 ZeroMemory(pFilter, sizeof(TcpFilterSettings));
2733 This->pCurrentConfig->pFilter = pFilter;
2734
2735
2736 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
2737 {
2738 dwSize = sizeof(DWORD);
2739 if (RegQueryValueExW(hKey, L"EnableSecurityFilters", NULL, NULL, (LPBYTE)&dwVal, &dwSize) == ERROR_SUCCESS)
2740 pFilter->EnableSecurityFilters = dwVal;
2741 RegCloseKey(hKey);
2742 }
2743 else
2744 {
2745 pFilter->EnableSecurityFilters = FALSE;
2746 }
2747
2748 if (FAILED(StringFromCLSID(&This->NetCfgInstanceId, &pStr)))
2749 return E_FAIL;
2750
2751 swprintf(szBuffer, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s", pStr);
2752 CoTaskMemFree(pStr);
2753 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szBuffer, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
2754 {
2755 return S_OK;
2756 }
2757 pFilter->szTCPAllowedPorts = LoadTcpFilterSettingsFromRegistry(hKey, L"TCPAllowedPorts", &pFilter->TCPSize);
2758 pFilter->szUDPAllowedPorts = LoadTcpFilterSettingsFromRegistry(hKey, L"UDPAllowedPorts", &pFilter->UDPSize);
2759 pFilter->szRawIPAllowedProtocols = LoadTcpFilterSettingsFromRegistry(hKey, L"RawIPAllowedProtocols", &pFilter->IPSize);
2760 RegCloseKey(hKey);
2761 return S_OK;
2762 }
2763
2764
2765 HRESULT
2766 Initialize(TcpipConfNotifyImpl * This)
2767 {
2768 DWORD dwSize;
2769 WCHAR szBuffer[50];
2770 IP_ADAPTER_INFO * pCurrentAdapter;
2771 IP_ADAPTER_INFO * pInfo;
2772 PIP_PER_ADAPTER_INFO pPerInfo;
2773 LPOLESTR pStr;
2774 HRESULT hr;
2775 BOOL bFound;
2776 TcpipSettings * pCurSettings;
2777 ULONG uLength;
2778
2779 if (This->pCurrentConfig)
2780 return S_OK;
2781
2782 hr = StringFromCLSID(&This->NetCfgInstanceId, &pStr);
2783 if (FAILED(hr))
2784 return hr;
2785
2786
2787 dwSize = 0;
2788 if (GetAdaptersInfo(NULL, &dwSize) != ERROR_BUFFER_OVERFLOW)
2789 {
2790 CoTaskMemFree(pStr);
2791 return E_FAIL;
2792 }
2793
2794 pInfo = CoTaskMemAlloc(dwSize);
2795 if (!pInfo)
2796 {
2797 CoTaskMemFree(pStr);
2798 return E_FAIL;
2799 }
2800
2801 if (GetAdaptersInfo(pInfo, &dwSize) != ERROR_SUCCESS)
2802 {
2803 CoTaskMemFree(pStr);
2804 CoTaskMemFree(pInfo);
2805 return E_FAIL;
2806 }
2807
2808 pCurrentAdapter = pInfo;
2809 bFound = FALSE;
2810 while(pCurrentAdapter)
2811 {
2812 szBuffer[0] = L'\0';
2813 if (MultiByteToWideChar(CP_ACP, 0, pCurrentAdapter->AdapterName, -1, szBuffer, sizeof(szBuffer)/sizeof(szBuffer[0])))
2814 {
2815 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
2816 }
2817 if (!_wcsicmp(szBuffer, pStr))
2818 {
2819 bFound = TRUE;
2820 break;
2821 }
2822 pCurrentAdapter = pCurrentAdapter->Next;
2823 }
2824 CoTaskMemFree(pStr);
2825
2826 if (!bFound)
2827 {
2828 CoTaskMemFree(pInfo);
2829 return E_FAIL;
2830 }
2831
2832 pCurSettings = CoTaskMemAlloc(sizeof(TcpipSettings));
2833 if (!pCurSettings)
2834 {
2835 CoTaskMemFree(pInfo);
2836 return E_FAIL;
2837 }
2838
2839 ZeroMemory(pCurSettings, sizeof(TcpipSettings));
2840 This->pCurrentConfig = pCurSettings;
2841 pCurSettings->DhcpEnabled = pCurrentAdapter->DhcpEnabled;
2842 pCurSettings->Index = pCurrentAdapter->Index;
2843
2844 if (!pCurrentAdapter->DhcpEnabled)
2845 {
2846 CopyIpAddrString(&pCurrentAdapter->IpAddressList, &pCurSettings->Ip, SUBMASK, NULL);
2847 CopyIpAddrString(&pCurrentAdapter->GatewayList, &pCurSettings->Gw, METRIC, NULL); //FIXME
2848 }
2849 uLength = 0;
2850 if (GetPerAdapterInfo(pCurrentAdapter->Index, NULL, &uLength) == ERROR_BUFFER_OVERFLOW)
2851 {
2852 pPerInfo = (PIP_PER_ADAPTER_INFO)CoTaskMemAlloc(uLength);
2853 if (pPerInfo)
2854 {
2855 if (GetPerAdapterInfo(pCurrentAdapter->Index, pPerInfo, &uLength) == NOERROR)
2856 {
2857 if (!pPerInfo->AutoconfigActive)
2858 {
2859 CopyIpAddrString(&pPerInfo->DnsServerList, &pCurSettings->Ns, IPADDR, NULL);
2860 }
2861 pCurSettings->AutoconfigActive = pPerInfo->AutoconfigActive;
2862 }