Leaked source code of windows server 2003
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.

589 lines
17 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // tcpipcom.c
  8. //
  9. // Description: Functions common to all the Advanced TCP/IP pages
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "pch.h"
  13. #include "resource.h"
  14. #include "tcpip.h"
  15. //----------------------------------------------------------------------------
  16. //
  17. // Function: TcpipNameListInsertIdx
  18. //
  19. // Purpose: Whenever a TCP/IP item needs to inserted into a specific position
  20. // in a list this function needs to be called. It checks for a duplicate.
  21. // If one exists, it removes it and then does the insertion. Subnet masks
  22. // should not use this function because duplicates are allowed for them.
  23. //
  24. // Arguments:
  25. // IN OUT NAMELIST* TcpipNameList - namelist to add to
  26. // IN TCHAR* pString - string to add (input)
  27. // IN UINT idx - 0-based index on where to do the insertion
  28. //
  29. // Returns: if a duplicate was removed the index where the duplicate was,
  30. // -1 if there was no duplicate
  31. //
  32. //----------------------------------------------------------------------------
  33. INT
  34. TcpipNameListInsertIdx( IN OUT NAMELIST* TcpipNameList,
  35. IN TCHAR* pString,
  36. IN UINT idx )
  37. {
  38. INT iFound = -1;
  39. iFound = FindNameInNameList( TcpipNameList, pString );
  40. //
  41. // if it is already in the list, then remove it
  42. //
  43. if( iFound != NOT_FOUND )
  44. {
  45. RemoveNameFromNameListIdx( TcpipNameList, iFound );
  46. }
  47. AddNameToNameListIdx( TcpipNameList, pString, idx );
  48. return( iFound );
  49. }
  50. //----------------------------------------------------------------------------
  51. //
  52. // Function: TcpipAddNameToNameList
  53. //
  54. // Purpose: Whenever a TCP/IP item needs to inserted at the end of a list
  55. // this function needs to be called. It checks for a duplicate. If one
  56. // exists, it removes it and then does the insertion. Subnet masks should
  57. // not use this function because duplicates are allowed for them.
  58. //
  59. // Arguments:
  60. // IN OUT NAMELIST* TcpipNameList - namelist to add to
  61. // IN TCHAR* pString - string to add (input)
  62. //
  63. // Returns: if a duplicate was removed the index where the duplicate was,
  64. // -1 if there was no duplicate
  65. //
  66. //----------------------------------------------------------------------------
  67. INT
  68. TcpipAddNameToNameList( IN OUT NAMELIST* TcpipNameList,
  69. IN TCHAR* pString )
  70. {
  71. return( TcpipNameListInsertIdx( TcpipNameList,
  72. pString,
  73. TcpipNameList->nEntries ) );
  74. }
  75. //----------------------------------------------------------------------------
  76. //
  77. // Function: OnAddButtonPressed
  78. //
  79. // Purpose: Generic procedure called whenever a user clicks the Add button on
  80. // any of the property pages
  81. //
  82. // this function displays the appropriate dialog box, gets the data
  83. // from the user and then inserts the data into the list box
  84. //
  85. // Arguments:
  86. // IN HWND hwnd - handle to the dialog
  87. // IN WORD ListBoxControlID - the list box to add the entry to
  88. // IN WORD EditButtonControlID - the edit button associated with the
  89. // list box
  90. // IN WORD RemoveButtonControlID - the remove button associated with the
  91. // list box
  92. // IN LPCTSTR Dialog - the dialog control ID as a string
  93. // IN DLGPROC DialogProc - the dialog procedure for the add button behavior
  94. //
  95. // Returns: VOID
  96. //
  97. //----------------------------------------------------------------------------
  98. VOID
  99. OnAddButtonPressed( IN HWND hwnd,
  100. IN WORD ListBoxControlID,
  101. IN WORD EditButtonControlID,
  102. IN WORD RemoveButtonControlID,
  103. IN LPCTSTR Dialog,
  104. IN DLGPROC DialogProc )
  105. {
  106. //
  107. // make the string blank since we will be adding a new IP address
  108. //
  109. szIPString[0] = _T('\0');
  110. if( DialogBox( FixedGlobals.hInstance, Dialog, hwnd, DialogProc ) )
  111. {
  112. HWND hListBox = GetDlgItem( hwnd, ListBoxControlID );
  113. HWND hEditButton = GetDlgItem( hwnd, EditButtonControlID );
  114. HWND hRemoveButton = GetDlgItem( hwnd, RemoveButtonControlID );
  115. //
  116. // Add the string to the list box and make it the current selection
  117. //
  118. SendMessage( hListBox,
  119. LB_ADDSTRING,
  120. 0,
  121. (LPARAM) szIPString );
  122. SendMessage( hListBox,
  123. LB_SELECTSTRING,
  124. -1,
  125. (LPARAM) szIPString );
  126. //
  127. // an entry was just added so make sure the edit and remove buttons
  128. // are enabled
  129. //
  130. EnableWindow( hEditButton, TRUE );
  131. EnableWindow( hRemoveButton, TRUE );
  132. }
  133. }
  134. //----------------------------------------------------------------------------
  135. //
  136. // Function: OnEditButtonPressed
  137. //
  138. // Purpose: Generic procedure called whenever a user clicks the Edit button
  139. // on any of the property pages
  140. //
  141. // this function displays the appropriate dialog box, gets the data
  142. // from the user and then deletes the old string and reinserts the
  143. // new string into the list box
  144. //
  145. // Arguments:
  146. // IN HWND hwnd - handle to the dialog
  147. // IN WORD ListBoxControlID - the list box to in which to edit the entry
  148. // IN LPCTSTR Dialog - the dialog control ID as a string
  149. // IN DLGPROC DialogProc - the dialog procedure for the edit button
  150. // behavior
  151. //
  152. // Returns: VOID
  153. //
  154. //----------------------------------------------------------------------------
  155. VOID
  156. OnEditButtonPressed( IN HWND hwnd,
  157. IN WORD ListBoxControlID,
  158. IN LPCTSTR Dialog,
  159. IN DLGPROC DialogProc )
  160. {
  161. INT_PTR iIndex;
  162. HWND hListBox = GetDlgItem( hwnd, ListBoxControlID );
  163. iIndex = SendMessage( hListBox, LB_GETCURSEL, 0, 0 );
  164. SendMessage( hListBox, LB_GETTEXT, iIndex, (LPARAM)szIPString );
  165. if( DialogBox( FixedGlobals.hInstance, Dialog, hwnd, DialogProc ) )
  166. {
  167. //
  168. // Remove the old one and insert the new one
  169. //
  170. SendMessage( hListBox, LB_DELETESTRING, iIndex, 0 );
  171. SendMessage( hListBox, LB_INSERTSTRING, iIndex, (LPARAM) szIPString );
  172. SendMessage( hListBox, LB_SETCURSEL, iIndex, 0 );
  173. }
  174. }
  175. //----------------------------------------------------------------------------
  176. //
  177. // Function: OnRemoveButtonPressed
  178. //
  179. // Purpose: Generic procedure called whenever a user clicks the Remove button
  180. // on any of the property pages
  181. //
  182. // this function determines which entry is currently selected in the
  183. // list box and deletes that item
  184. //
  185. // Arguments:
  186. // IN HWND hwnd - handle to the dialog
  187. // IN WORD ListBoxControlID - the list box to remove the entry from
  188. // IN WORD EditButtonControlID - the edit button associated with the
  189. // list box
  190. // IN WORD RemoveButtonControlID - the remove button associated with the
  191. // list box
  192. //
  193. // Returns: VOID
  194. //
  195. //----------------------------------------------------------------------------
  196. VOID
  197. OnRemoveButtonPressed( IN HWND hwnd,
  198. IN WORD ListBoxControlID,
  199. IN WORD EditButtonControlID,
  200. IN WORD RemoveButtonControlID )
  201. {
  202. INT_PTR iIndex;
  203. INT_PTR iCount;
  204. HWND hListBox = GetDlgItem( hwnd, ListBoxControlID );
  205. HWND hEditButton = GetDlgItem( hwnd, EditButtonControlID );
  206. HWND hRemoveButton = GetDlgItem( hwnd, RemoveButtonControlID );
  207. //
  208. // Remove the item from the list box by finding the index of the currently
  209. // selected item and deleting
  210. //
  211. iIndex = SendMessage( hListBox, LB_GETCURSEL, 0, 0 );
  212. SendMessage( hListBox, LB_DELETESTRING, iIndex, 0 );
  213. //
  214. // if there are no more items in the list box then grey-out the edit and remove buttons
  215. //
  216. iCount = SendMessage( hListBox, LB_GETCOUNT, 0, 0 );
  217. if( iCount == 0 )
  218. {
  219. EnableWindow( hEditButton, FALSE );
  220. EnableWindow( hRemoveButton, FALSE );
  221. }
  222. else // else select the first item
  223. {
  224. SendMessage( hListBox, LB_SETCURSEL, 0, 0 );
  225. }
  226. }
  227. //----------------------------------------------------------------------------
  228. //
  229. // Function: GenericIPDlgProc
  230. //
  231. // Purpose: Generic Dialog Procedure called to handle a dialog box where a
  232. // user can enter an IP address and then press OK or Cancel
  233. // - the switch at the beginning determines which Dialog Box to
  234. // display so every dialog box that calls this function will need
  235. // a case inside this switch statement
  236. //
  237. // Arguments: standard Win32 dialog proc arguments
  238. //
  239. // Returns: standard Win32 dialog proc return value
  240. //
  241. //----------------------------------------------------------------------------
  242. INT_PTR CALLBACK
  243. GenericIPDlgProc( IN HWND hwnd,
  244. IN UINT uMsg,
  245. IN WPARAM wParam,
  246. IN LPARAM lParam )
  247. {
  248. HWND hEditbox;
  249. BOOL bStatus = TRUE;
  250. //
  251. // Determine which dialog box to display
  252. //
  253. switch( g_CurrentEditBox )
  254. {
  255. case GATEWAY_EDITBOX:
  256. hEditbox = GetDlgItem( hwnd, IDC_IPADDR_ADV_CHANGE_GATEWAY );
  257. break;
  258. case DNS_SERVER_EDITBOX:
  259. hEditbox = GetDlgItem( hwnd, IDC_DNS_CHANGE_SERVER );
  260. break;
  261. case DNS_SUFFIX_EDITBOX:
  262. hEditbox = GetDlgItem( hwnd, IDC_DNS_CHANGE_SUFFIX );
  263. break;
  264. case WINS_EDITBOX:
  265. hEditbox = GetDlgItem( hwnd, IDC_WINS_CHANGE_SERVER );
  266. break;
  267. }
  268. switch( uMsg )
  269. {
  270. case WM_INITDIALOG:
  271. {
  272. SetWindowText( hEditbox, szIPString );
  273. SetFocus( hEditbox );
  274. bStatus = FALSE; // return FALSE, we set the keyboard focus
  275. break;
  276. }
  277. case WM_COMMAND:
  278. {
  279. int nButtonId = LOWORD( wParam );
  280. switch ( nButtonId )
  281. {
  282. case IDOK:
  283. {
  284. //
  285. // return a 1 to show an IP was added
  286. //
  287. GetWindowText( hEditbox, szIPString, MAX_IP_LENGTH + 1 );
  288. EndDialog( hwnd, 1 );
  289. break;
  290. }
  291. case IDCANCEL:
  292. {
  293. //
  294. // return a 0 to show no IP was added
  295. //
  296. EndDialog( hwnd, 0 );
  297. break;
  298. }
  299. }
  300. }
  301. default:
  302. bStatus = FALSE;
  303. break;
  304. }
  305. return( bStatus );
  306. }
  307. //----------------------------------------------------------------------------
  308. //
  309. // Function: SetButtons
  310. //
  311. // Purpose: Sets the windows states for the Edit and Remove buttons
  312. //
  313. // Arguments: IN HWND hListBox - the list box the edit and remove buttons are
  314. // associated with
  315. // IN HWND hEditButton - handle to the Edit button
  316. // IN HWND hRemoveButton - handle to the Remove button
  317. //
  318. // Returns: VOID
  319. //
  320. //----------------------------------------------------------------------------
  321. VOID
  322. SetButtons( IN HWND hListBox, IN HWND hEditButton, IN HWND hRemoveButton )
  323. {
  324. INT_PTR iCount;
  325. iCount = SendMessage( hListBox, LB_GETCOUNT, 0, 0 );
  326. if( iCount > 0 )
  327. {
  328. EnableWindow( hEditButton, TRUE );
  329. EnableWindow( hRemoveButton, TRUE );
  330. }
  331. else
  332. {
  333. EnableWindow( hEditButton, FALSE );
  334. EnableWindow( hRemoveButton, FALSE );
  335. }
  336. }
  337. //----------------------------------------------------------------------------
  338. //
  339. // Function: AddValuesToListBox
  340. //
  341. // Purpose: Uses the contents of a Namelist to populate a list box, then
  342. // selects the first entry.
  343. //
  344. // Arguments: IN HWND hListBox - list box the data is to be added to
  345. // IN NAMELIST* pNameList - namelist to extract the data from
  346. // IN INT iPosition - position in the list to start taking names
  347. // from
  348. //
  349. // Returns: VOID
  350. //
  351. //----------------------------------------------------------------------------
  352. VOID
  353. AddValuesToListBox( IN HWND hListBox, IN NAMELIST* pNameList, IN INT iPosition )
  354. {
  355. INT i;
  356. INT nEntries;
  357. LPTSTR pszIPAddressString;
  358. nEntries = GetNameListSize( pNameList );
  359. for( i = iPosition; i < nEntries; i++ ) {
  360. pszIPAddressString = GetNameListName( pNameList, i );
  361. SendMessage( hListBox, LB_INSERTSTRING, i, (LPARAM) pszIPAddressString );
  362. }
  363. //
  364. // select the first entry
  365. //
  366. SendMessage( hListBox, LB_SETCURSEL, 0, 0 );
  367. }
  368. //----------------------------------------------------------------------------
  369. //
  370. // Function: TCPIPProp_PropertySheetProc
  371. //
  372. // Purpose: Standard Property Sheet dialog proc.
  373. //
  374. //----------------------------------------------------------------------------
  375. int CALLBACK
  376. TCPIPProp_PropertySheetProc( HWND hwndDlg,
  377. UINT uMsg,
  378. LPARAM lParam )
  379. {
  380. switch (uMsg) {
  381. case PSCB_INITIALIZED :
  382. // Process PSCB_INITIALIZED
  383. break ;
  384. case PSCB_PRECREATE :
  385. // Process PSCB_PRECREATE
  386. break ;
  387. default :
  388. // Unknown message
  389. break ;
  390. }
  391. return( 0 );
  392. }
  393. //----------------------------------------------------------------------------
  394. //
  395. // Function: Create_TCPIPProp_PropertySheet
  396. //
  397. // Purpose: Sets up settings for the entire property sheet and each
  398. // individual page. Lastly, calls the PropertySheet function to
  399. // display the property sheet, the return value of this function is
  400. // what is passed back as the return value
  401. //
  402. // Arguments: HWND hwndParent - handle to the dialog that will be spawning
  403. // the property sheet
  404. //
  405. // Returns: BOOL - the return value from the property sheet
  406. //
  407. //----------------------------------------------------------------------------
  408. BOOL
  409. Create_TCPIPProp_PropertySheet( HWND hwndParent )
  410. {
  411. INT i;
  412. // Initialize property sheet HEADER data
  413. ZeroMemory( &TCPIPProp_pshead, sizeof( PROPSHEETHEADER ) );
  414. TCPIPProp_pshead.dwSize = sizeof( PROPSHEETHEADER );
  415. TCPIPProp_pshead.dwFlags = PSH_PROPSHEETPAGE |
  416. PSH_USECALLBACK |
  417. PSH_USEHICON |
  418. PSH_NOAPPLYNOW;
  419. TCPIPProp_pshead.hwndParent = hwndParent;
  420. TCPIPProp_pshead.hInstance = FixedGlobals.hInstance;
  421. TCPIPProp_pshead.pszCaption = g_StrAdvancedTcpipSettings;
  422. TCPIPProp_pshead.nPages = cTCPIPPropertyPages;
  423. TCPIPProp_pshead.nStartPage = 0;
  424. TCPIPProp_pshead.ppsp = TCPIPProp_pspage;
  425. TCPIPProp_pshead.pfnCallback = TCPIPProp_PropertySheetProc;
  426. // Zero out property PAGE data
  427. ZeroMemory( &TCPIPProp_pspage, cTCPIPPropertyPages * sizeof(PROPSHEETPAGE) );
  428. for( i = 0; i < cTCPIPPropertyPages; i++ ) {
  429. TCPIPProp_pspage[i].dwSize = sizeof(PROPSHEETPAGE);
  430. TCPIPProp_pspage[i].dwFlags = PSP_USECALLBACK;
  431. TCPIPProp_pspage[i].hInstance = FixedGlobals.hInstance;
  432. }
  433. // PAGE 1 -- IP settings page
  434. TCPIPProp_pspage[0].pszTemplate = MAKEINTRESOURCE (IDD_IPADDR_ADV);
  435. TCPIPProp_pspage[0].pfnDlgProc = TCPIP_IPSettingsDlgProc;
  436. TCPIPProp_pspage[0].pfnCallback = TCPIP_IPSettingsPageProc;
  437. // PAGE 2 -- DNS page
  438. TCPIPProp_pspage[1].pszTemplate = MAKEINTRESOURCE (IDD_TCP_DNS);
  439. TCPIPProp_pspage[1].pfnDlgProc = TCPIP_DNSDlgProc;
  440. TCPIPProp_pspage[1].pfnCallback = TCPIP_DNSPageProc;
  441. // PAGE 3 -- WINS page
  442. TCPIPProp_pspage[2].pszTemplate = MAKEINTRESOURCE (IDD_TCP_WINS);
  443. TCPIPProp_pspage[2].pfnDlgProc = TCPIP_WINSDlgProc;
  444. TCPIPProp_pspage[2].pfnCallback = TCPIP_WINSPageProc;
  445. /*
  446. // ISSUE-2002/02/28-stelo- There are currently no unattend settings for IPSEC or TCP/IP
  447. // filter so do not display this page of the property sheet.
  448. // PAGE 4 -- Options page
  449. TCPIPProp_pspage[3].pszTemplate = MAKEINTRESOURCE (IDD_TCP_OPTIONS);
  450. TCPIPProp_pspage[3].pfnDlgProc = TCPIP_OptionsDlgProc;
  451. TCPIPProp_pspage[3].pfnCallback = TCPIP_OptionsPageProc;
  452. */
  453. // --------- Create & display property sheet ---------
  454. if( PropertySheet( &TCPIPProp_pshead ) )
  455. return( TRUE ); // pass back return value from PropertySheet
  456. else
  457. return( FALSE );
  458. }