Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

604 lines
17 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // tcpipdns.c
  8. //
  9. // Description: ISSUE-2002/02/28-stelo- fill description
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "pch.h"
  13. #include "resource.h"
  14. #include "tcpip.h"
  15. //----------------------------------------------------------------------------
  16. //
  17. // Function: OnTcpipDnsInitDialog
  18. //
  19. // Purpose:
  20. //
  21. // Arguments:
  22. //
  23. // Returns:
  24. //
  25. //----------------------------------------------------------------------------
  26. VOID
  27. OnTcpipDnsInitDialog( IN HWND hwnd )
  28. {
  29. HWND hServerEditButton, hServerRemoveButton;
  30. HWND hSuffixAddButton, hSuffixEditButton, hSuffixRemoveButton;
  31. //
  32. // Place up/down arrow icons on buttons
  33. //
  34. SendDlgItemMessage( hwnd,
  35. IDC_DNS_SERVER_UP,
  36. BM_SETIMAGE,
  37. (WPARAM)IMAGE_ICON,
  38. (LPARAM) g_hIconUpArrow );
  39. SendDlgItemMessage( hwnd,
  40. IDC_DNS_SERVER_DOWN,
  41. BM_SETIMAGE,
  42. (WPARAM)IMAGE_ICON,
  43. (LPARAM) g_hIconDownArrow );
  44. SendDlgItemMessage( hwnd,
  45. IDC_DNS_SUFFIX_UP,
  46. BM_SETIMAGE,
  47. (WPARAM)IMAGE_ICON,
  48. (LPARAM) g_hIconUpArrow );
  49. SendDlgItemMessage( hwnd,
  50. IDC_DNS_SUFFIX_DOWN,
  51. BM_SETIMAGE,
  52. (WPARAM)IMAGE_ICON,
  53. (LPARAM) g_hIconDownArrow );
  54. hServerEditButton = GetDlgItem( hwnd, IDC_DNS_SERVER_EDIT );
  55. hServerRemoveButton = GetDlgItem( hwnd, IDC_DNS_SERVER_REMOVE );
  56. hSuffixAddButton = GetDlgItem( hwnd, IDC_DNS_SUFFIX_ADD );
  57. hSuffixEditButton = GetDlgItem( hwnd, IDC_DNS_SUFFIX_EDIT );
  58. hSuffixRemoveButton = GetDlgItem( hwnd, IDC_DNS_SUFFIX_REMOVE );
  59. SetWindowText( GetDlgItem( hwnd, IDC_DNS_DOMAIN ),
  60. NetSettings.pCurrentAdapter->szDNSDomainName );
  61. //
  62. // fill the DNS Server list box with the appropriate initial value(s)
  63. //
  64. AddValuesToListBox( GetDlgItem( hwnd, IDC_DNS_SERVER_LIST ),
  65. &NetSettings.pCurrentAdapter->Tcpip_DnsAddresses,
  66. 0 );
  67. //
  68. // select the first entry in the DNS Server list box
  69. //
  70. SendDlgItemMessage( hwnd,
  71. IDC_DNS_SERVER_LIST,
  72. LB_SETCURSEL,
  73. 0,
  74. 0 );
  75. //
  76. // initialize the Edit and Remove buttons to the proper states
  77. //
  78. SetButtons( GetDlgItem( hwnd, IDC_DNS_SERVER_LIST ),
  79. hServerEditButton,
  80. hServerRemoveButton );
  81. //
  82. // Have to "figure out" what DNS radio button to set
  83. //
  84. if( NetSettings.bIncludeParentDomains )
  85. {
  86. CheckRadioButton( hwnd,
  87. IDC_DNS_SEARCH_DOMAIN,
  88. IDC_DNS_USE_SUFFIX_LIST,
  89. IDC_DNS_SEARCH_DOMAIN );
  90. EnableWindow( hSuffixAddButton, FALSE );
  91. CheckDlgButton( hwnd, IDC_DNS_SEARCH_PARENT_DOMAIN, BST_CHECKED );
  92. }
  93. else if( GetNameListSize( &NetSettings.TCPIP_DNS_Domains ) > 0 )
  94. {
  95. CheckRadioButton( hwnd,
  96. IDC_DNS_SEARCH_DOMAIN,
  97. IDC_DNS_USE_SUFFIX_LIST,
  98. IDC_DNS_USE_SUFFIX_LIST );
  99. EnableWindow( hSuffixAddButton, TRUE );
  100. EnableWindow( GetDlgItem( hwnd, IDC_DNS_SEARCH_PARENT_DOMAIN),
  101. FALSE );
  102. //
  103. // fill the DNS Suffix list box with the appropriate initial value(s)
  104. //
  105. AddValuesToListBox( GetDlgItem( hwnd, IDC_DNS_SUFFIX_LIST ),
  106. &NetSettings.TCPIP_DNS_Domains,
  107. 0 );
  108. }
  109. else {
  110. CheckRadioButton( hwnd,
  111. IDC_DNS_SEARCH_DOMAIN,
  112. IDC_DNS_USE_SUFFIX_LIST,
  113. IDC_DNS_SEARCH_DOMAIN );
  114. EnableWindow( hSuffixAddButton, FALSE );
  115. }
  116. //
  117. // initialize the Edit and Remove buttons to the proper states
  118. //
  119. SetButtons( GetDlgItem( hwnd, IDC_DNS_SUFFIX_LIST ),
  120. hSuffixEditButton,
  121. hSuffixRemoveButton );
  122. SetArrows( hwnd,
  123. IDC_DNS_SERVER_LIST,
  124. IDC_DNS_SERVER_UP,
  125. IDC_DNS_SERVER_DOWN );
  126. SetArrows( hwnd,
  127. IDC_DNS_SUFFIX_LIST,
  128. IDC_DNS_SUFFIX_UP,
  129. IDC_DNS_SUFFIX_DOWN );
  130. }
  131. //----------------------------------------------------------------------------
  132. //
  133. // Function: OnTcpipDnsApply
  134. //
  135. // Purpose: stores the contents on the TCP/IP advanced DNS page into
  136. // the global variables
  137. //
  138. // Arguments: IN HWND hwnd - handle to the dialog
  139. //
  140. // Returns: VOID
  141. //
  142. //----------------------------------------------------------------------------
  143. VOID
  144. OnTcpipDnsApply( IN HWND hwnd )
  145. {
  146. INT_PTR i;
  147. INT_PTR iCount;
  148. TCHAR szDns[IPSTRINGLENGTH + 1];
  149. //
  150. // delete any old settings in the Namelists
  151. //
  152. ResetNameList( &NetSettings.pCurrentAdapter->Tcpip_DnsAddresses );
  153. //
  154. // pull the IP address out of the DNS list box and put them in the
  155. // DNS Namelist
  156. //
  157. iCount = SendDlgItemMessage( hwnd,
  158. IDC_DNS_SERVER_LIST,
  159. LB_GETCOUNT,
  160. 0,
  161. 0 );
  162. for( i = 0; i < iCount; i++ )
  163. {
  164. //
  165. // get the DNS string from the list box
  166. //
  167. SendDlgItemMessage( hwnd,
  168. IDC_DNS_SERVER_LIST,
  169. LB_GETTEXT,
  170. i,
  171. (LPARAM) szDns );
  172. //
  173. // store the DNS string in to the Namelist
  174. //
  175. TcpipAddNameToNameList( &NetSettings.pCurrentAdapter->Tcpip_DnsAddresses, szDns );
  176. }
  177. ResetNameList( &NetSettings.TCPIP_DNS_Domains );
  178. iCount = SendDlgItemMessage( hwnd,
  179. IDC_DNS_SUFFIX_LIST,
  180. LB_GETCOUNT,
  181. 0,
  182. 0 );
  183. for( i = 0; i < iCount; i++ )
  184. {
  185. // ISSUE-2002/02/28-stelo- DNS suffix is going to get truncated
  186. // because szIPString is a short string so fix this
  187. //
  188. // get the IP string from the list box
  189. //
  190. SendDlgItemMessage( hwnd,
  191. IDC_DNS_SUFFIX_LIST,
  192. LB_GETTEXT,
  193. i,
  194. (LPARAM)szIPString );
  195. //
  196. // store the IP string in to the Namelist
  197. //
  198. AddNameToNameList( &NetSettings.TCPIP_DNS_Domains,
  199. szIPString );
  200. }
  201. GetWindowText( GetDlgItem( hwnd, IDC_DNS_DOMAIN ),
  202. NetSettings.pCurrentAdapter->szDNSDomainName,
  203. MAX_STRING_LEN );
  204. if( IsDlgButtonChecked( hwnd, IDC_DNS_SEARCH_PARENT_DOMAIN ) )
  205. {
  206. NetSettings.bIncludeParentDomains = TRUE;
  207. }
  208. else
  209. {
  210. NetSettings.bIncludeParentDomains = FALSE;
  211. }
  212. }
  213. //----------------------------------------------------------------------------
  214. //
  215. // Function: TCPIP_DNSPageProc
  216. //
  217. // Purpose: Required function for the property sheet page to function properly.
  218. // The important thing is to give the return value of 1 to the
  219. // message PSPCB_CREATE and 0 for PSPCB_RELEASE
  220. //
  221. // Arguments:
  222. //
  223. // Returns:
  224. //
  225. //----------------------------------------------------------------------------
  226. UINT CALLBACK
  227. TCPIP_DNSPageProc( HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp ) {
  228. switch( uMsg ) {
  229. case PSPCB_CREATE:
  230. return( 1 ); // needed for property sheet page to initialize correctly
  231. case PSPCB_RELEASE:
  232. return( 0 );
  233. default:
  234. return( -1 );
  235. }
  236. }
  237. //----------------------------------------------------------------------------
  238. //
  239. // Function: TCPIP_DNSDlgProc
  240. //
  241. // Purpose: Dialog procedure for the DNS page of the property sheet
  242. // handles all the messages sent to this window
  243. //
  244. // Arguments:
  245. //
  246. // Returns:
  247. //
  248. //----------------------------------------------------------------------------
  249. INT_PTR CALLBACK
  250. TCPIP_DNSDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  251. {
  252. switch( uMsg )
  253. {
  254. case WM_INITDIALOG:
  255. {
  256. OnTcpipDnsInitDialog( hwndDlg );
  257. return( TRUE );
  258. }
  259. case WM_COMMAND:
  260. {
  261. WORD wNotifyCode = HIWORD( wParam );
  262. WORD wButtonId = LOWORD( wParam );
  263. if( wNotifyCode == LBN_SELCHANGE )
  264. {
  265. if( wButtonId == IDC_DNS_SERVER_LIST )
  266. {
  267. SetArrows( hwndDlg,
  268. IDC_DNS_SERVER_LIST,
  269. IDC_DNS_SERVER_UP,
  270. IDC_DNS_SERVER_DOWN );
  271. }
  272. else
  273. {
  274. SetArrows( hwndDlg,
  275. IDC_DNS_SUFFIX_LIST,
  276. IDC_DNS_SUFFIX_UP,
  277. IDC_DNS_SUFFIX_DOWN );
  278. }
  279. }
  280. switch ( wButtonId )
  281. {
  282. case IDC_DNS_SEARCH_DOMAIN:
  283. if( wNotifyCode == BN_CLICKED )
  284. {
  285. CheckRadioButton( hwndDlg,
  286. IDC_DNS_SEARCH_DOMAIN,
  287. IDC_DNS_USE_SUFFIX_LIST,
  288. IDC_DNS_SEARCH_DOMAIN );
  289. EnableWindow( GetDlgItem( hwndDlg, IDC_DNS_SEARCH_PARENT_DOMAIN ),
  290. TRUE );
  291. EnableWindow( GetDlgItem( hwndDlg, IDC_DNS_SUFFIX_ADD ),
  292. FALSE );
  293. SetArrows( hwndDlg,
  294. IDC_DNS_SUFFIX_LIST,
  295. IDC_DNS_SUFFIX_UP,
  296. IDC_DNS_SUFFIX_DOWN );
  297. }
  298. return( TRUE );
  299. case IDC_DNS_USE_SUFFIX_LIST:
  300. if( wNotifyCode == BN_CLICKED )
  301. {
  302. CheckRadioButton( hwndDlg,
  303. IDC_DNS_SEARCH_DOMAIN,
  304. IDC_DNS_USE_SUFFIX_LIST,
  305. IDC_DNS_USE_SUFFIX_LIST );
  306. EnableWindow( GetDlgItem( hwndDlg, IDC_DNS_SEARCH_PARENT_DOMAIN ),
  307. FALSE );
  308. EnableWindow( GetDlgItem( hwndDlg, IDC_DNS_SUFFIX_ADD),
  309. TRUE );
  310. }
  311. return( TRUE );
  312. //
  313. // DNS Server Buttons
  314. //
  315. case IDC_DNS_SERVER_ADD:
  316. g_CurrentEditBox = DNS_SERVER_EDITBOX;
  317. OnAddButtonPressed( hwndDlg,
  318. IDC_DNS_SERVER_LIST,
  319. IDC_DNS_SERVER_EDIT,
  320. IDC_DNS_SERVER_REMOVE,
  321. (LPCTSTR) IDD_DNS_SERVER,
  322. GenericIPDlgProc );
  323. SetArrows( hwndDlg,
  324. IDC_DNS_SERVER_LIST,
  325. IDC_DNS_SERVER_UP,
  326. IDC_DNS_SERVER_DOWN );
  327. return( TRUE );
  328. case IDC_DNS_SERVER_EDIT:
  329. g_CurrentEditBox = DNS_SERVER_EDITBOX;
  330. OnEditButtonPressed( hwndDlg,
  331. IDC_DNS_SERVER_LIST,
  332. (LPCTSTR) IDD_DNS_SERVER,
  333. GenericIPDlgProc );
  334. SetArrows( hwndDlg,
  335. IDC_DNS_SERVER_LIST,
  336. IDC_DNS_SERVER_UP,
  337. IDC_DNS_SERVER_DOWN );
  338. return( TRUE );
  339. case IDC_DNS_SERVER_REMOVE:
  340. OnRemoveButtonPressed( hwndDlg,
  341. IDC_DNS_SERVER_LIST,
  342. IDC_DNS_SERVER_EDIT,
  343. IDC_DNS_SERVER_REMOVE );
  344. SetArrows( hwndDlg,
  345. IDC_DNS_SERVER_LIST,
  346. IDC_DNS_SERVER_UP,
  347. IDC_DNS_SERVER_DOWN );
  348. return( TRUE );
  349. case IDC_DNS_SERVER_UP:
  350. OnUpButtonPressed( hwndDlg, IDC_DNS_SERVER_LIST );
  351. SetArrows( hwndDlg,
  352. IDC_DNS_SERVER_LIST,
  353. IDC_DNS_SERVER_UP,
  354. IDC_DNS_SERVER_DOWN );
  355. return( TRUE );
  356. case IDC_DNS_SERVER_DOWN:
  357. OnDownButtonPressed( hwndDlg, IDC_DNS_SERVER_LIST );
  358. SetArrows( hwndDlg,
  359. IDC_DNS_SERVER_LIST,
  360. IDC_DNS_SERVER_UP,
  361. IDC_DNS_SERVER_DOWN );
  362. return( TRUE );
  363. //
  364. // DNS Suffix Buttons
  365. //
  366. case IDC_DNS_SUFFIX_ADD:
  367. g_CurrentEditBox = DNS_SUFFIX_EDITBOX;
  368. OnAddButtonPressed( hwndDlg,
  369. IDC_DNS_SUFFIX_LIST,
  370. IDC_DNS_SUFFIX_EDIT,
  371. IDC_DNS_SUFFIX_REMOVE,
  372. (LPCTSTR) IDD_DNS_SUFFIX,
  373. GenericIPDlgProc );
  374. SetArrows( hwndDlg,
  375. IDC_DNS_SUFFIX_LIST,
  376. IDC_DNS_SUFFIX_UP,
  377. IDC_DNS_SUFFIX_DOWN );
  378. return( TRUE );
  379. case IDC_DNS_SUFFIX_EDIT:
  380. g_CurrentEditBox = DNS_SUFFIX_EDITBOX;
  381. OnEditButtonPressed( hwndDlg,
  382. IDC_DNS_SUFFIX_LIST,
  383. (LPCTSTR) IDD_DNS_SUFFIX,
  384. GenericIPDlgProc );
  385. SetArrows( hwndDlg,
  386. IDC_DNS_SUFFIX_LIST,
  387. IDC_DNS_SUFFIX_UP,
  388. IDC_DNS_SUFFIX_DOWN );
  389. return( TRUE );
  390. case IDC_DNS_SUFFIX_REMOVE:
  391. OnRemoveButtonPressed( hwndDlg,
  392. IDC_DNS_SUFFIX_LIST,
  393. IDC_DNS_SUFFIX_EDIT,
  394. IDC_DNS_SUFFIX_REMOVE );
  395. SetArrows( hwndDlg,
  396. IDC_DNS_SUFFIX_LIST,
  397. IDC_DNS_SUFFIX_UP,
  398. IDC_DNS_SUFFIX_DOWN );
  399. return( TRUE );
  400. case IDC_DNS_SUFFIX_UP:
  401. OnUpButtonPressed( hwndDlg, IDC_DNS_SUFFIX_LIST );
  402. SetArrows( hwndDlg,
  403. IDC_DNS_SUFFIX_LIST,
  404. IDC_DNS_SUFFIX_UP,
  405. IDC_DNS_SUFFIX_DOWN );
  406. return( TRUE );
  407. case IDC_DNS_SUFFIX_DOWN:
  408. OnDownButtonPressed( hwndDlg, IDC_DNS_SUFFIX_LIST );
  409. SetArrows( hwndDlg,
  410. IDC_DNS_SUFFIX_LIST,
  411. IDC_DNS_SUFFIX_UP,
  412. IDC_DNS_SUFFIX_DOWN );
  413. return( TRUE );
  414. } // end switch
  415. return( FALSE );
  416. }
  417. case WM_NOTIFY:
  418. {
  419. LPNMHDR pnmh = (LPNMHDR) lParam ;
  420. switch( pnmh->code )
  421. {
  422. case PSN_APPLY:
  423. {
  424. //
  425. // user clicked the OK button on the property sheet
  426. //
  427. OnTcpipDnsApply( hwndDlg );
  428. return( TRUE );
  429. }
  430. default:
  431. return( FALSE );
  432. }
  433. }
  434. default:
  435. return( FALSE );
  436. }
  437. }