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.

704 lines
19 KiB

  1. /*
  2. File gentab.c
  3. Implements the ui behind the general tab for the
  4. connections dialup server ui.
  5. Paul Mayfield, 10/2/97
  6. */
  7. #include "rassrv.h"
  8. #include <tapi.h>
  9. // Help maps
  10. static const DWORD phmGenTab[] =
  11. {
  12. CID_GenTab_LV_Devices, IDH_GenTab_LV_Devices,
  13. CID_GenTab_CB_Multilink, IDH_GenTab_CB_Multilink,
  14. CID_GenTab_PB_Properties, IDH_GenTab_PB_Properties,
  15. CID_GenTab_CB_Vpn, IDH_GenTab_CB_Vpn,
  16. CID_GenTab_CB_ShowIcons, IDH_GenTab_CB_ShowIcons,
  17. 0, 0
  18. };
  19. // Fills in the property sheet structure with the information
  20. // required to display the general tab.
  21. //
  22. DWORD
  23. GenTabGetPropertyPage(
  24. IN LPPROPSHEETPAGE ppage,
  25. IN LPARAM lpUserData)
  26. {
  27. // Initialize
  28. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  29. // Fill in the values
  30. ppage->dwSize = sizeof(PROPSHEETPAGE);
  31. ppage->hInstance = Globals.hInstDll;
  32. ppage->pszTemplate = MAKEINTRESOURCE(PID_GenTab);
  33. ppage->pfnDlgProc = GenTabDialogProc;
  34. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  35. ppage->lParam = lpUserData;
  36. ppage->dwFlags = PSP_USECALLBACK;
  37. return NO_ERROR;
  38. }
  39. // Error reporting
  40. //
  41. VOID
  42. GenTabDisplayError(
  43. IN HWND hwnd,
  44. IN DWORD dwErr)
  45. {
  46. ErrDisplayError(
  47. hwnd,
  48. dwErr,
  49. ERR_GENERALTAB_CATAGORY,
  50. 0,
  51. Globals.dwErrorData);
  52. }
  53. //
  54. // Returns the index of an to display icon based on the type of incoming
  55. // connection and whether or not it should be checked.
  56. //
  57. INT
  58. GenTabGetIconIndex(
  59. IN DWORD dwType,
  60. IN BOOL bEnabled)
  61. {
  62. if (dwType == INCOMING_TYPE_PHONE)
  63. {
  64. return DI_Phone;
  65. }
  66. else
  67. {
  68. return DI_Direct;
  69. }
  70. }
  71. //
  72. // Fills in the device list with the list of the devices stored in the
  73. // device database. Also, initializes the checked/unchecked status
  74. // of each device.
  75. //
  76. DWORD
  77. GenTabFillDeviceList(
  78. IN HWND hwndDlg,
  79. IN HWND hwndLV,
  80. IN HANDLE hDevDatabase)
  81. {
  82. LV_ITEM lvi;
  83. LV_COLUMN lvc;
  84. DWORD dwCount, i, dwErr, dwType;
  85. HANDLE hDevice;
  86. PWCHAR pszName;
  87. char pszAName[1024];
  88. BOOL bEnabled;
  89. // Get the count of all the users
  90. dwErr = devGetDeviceCount(hDevDatabase, &dwCount);
  91. if (dwErr != NO_ERROR)
  92. {
  93. GenTabDisplayError(hwndLV, ERR_DEVICE_DATABASE_CORRUPT);
  94. return dwErr;
  95. }
  96. // Initialize the list item
  97. ZeroMemory(&lvi, sizeof(LV_ITEM));
  98. lvi.mask = LVIF_TEXT | LVIF_IMAGE;
  99. // If there are devices to display then populate the list box
  100. // with them
  101. if (dwCount > 0)
  102. {
  103. ListView_SetDeviceImageList(hwndLV, Globals.hInstDll);
  104. // Looop through all of the devices adding them to the list
  105. for (i=0; i<dwCount; i++)
  106. {
  107. dwErr = devGetDeviceHandle(hDevDatabase, i, &hDevice);
  108. if (dwErr == NO_ERROR)
  109. {
  110. devGetDeviceName (hDevice, &pszName);
  111. devGetDeviceEnable (hDevice, &bEnabled);
  112. devGetDeviceType (hDevice, &dwType);
  113. lvi.iImage = GenTabGetIconIndex(dwType, bEnabled);
  114. lvi.iItem = i;
  115. lvi.pszText = pszName;
  116. lvi.cchTextMax = wcslen(pszName)+1;
  117. ListView_InsertItem(hwndLV,&lvi);
  118. ListView_SetCheck(hwndLV, i, bEnabled);
  119. }
  120. }
  121. // Select the first item in the list view if any items exist
  122. //
  123. ListView_SetItemState(
  124. hwndLV,
  125. 0,
  126. LVIS_SELECTED | LVIS_FOCUSED,
  127. LVIS_SELECTED | LVIS_FOCUSED);
  128. // Initialize the alignment of the text that gets displayed
  129. lvc.mask = LVCF_FMT;
  130. lvc.fmt = LVCFMT_LEFT;
  131. }
  132. // If there are no devices then we display a message in the big
  133. // white box explaining that we have no devices to show.
  134. else
  135. {
  136. PWCHAR pszLine1, pszLine2;
  137. HWND hwndGenTab = NULL;
  138. pszLine1 = (PWCHAR)
  139. PszLoadString(Globals.hInstDll, SID_NO_DEVICES1);
  140. pszLine2 = (PWCHAR)
  141. PszLoadString(Globals.hInstDll, SID_NO_DEVICES2);
  142. lvi.mask = LVIF_TEXT;
  143. lvi.iItem = 0;
  144. lvi.pszText = pszLine1;
  145. lvi.cchTextMax = wcslen(pszLine1);
  146. ListView_InsertItem(hwndLV, &lvi);
  147. lvi.iItem = 1;
  148. lvi.pszText = pszLine2;
  149. lvi.cchTextMax = wcslen(pszLine2);
  150. ListView_InsertItem(hwndLV, &lvi);
  151. // Initialize the alignment of the text that gets displayed
  152. lvc.mask = LVCF_FMT;
  153. lvc.fmt = LVCFMT_CENTER;
  154. // Disable the list view
  155. EnableWindow(hwndLV, FALSE);
  156. // Disable the properties button while you're at it
  157. hwndGenTab = GetDlgItem(hwndDlg, CID_GenTab_PB_Properties);
  158. if (NULL != hwndGenTab)
  159. {
  160. EnableWindow(hwndGenTab, FALSE);
  161. }
  162. }
  163. // Add a colum so that we'll display in report view
  164. ListView_InsertColumn(hwndLV, 0, &lvc);
  165. ListView_SetColumnWidth(hwndLV, 0, LVSCW_AUTOSIZE_USEHEADER);
  166. return NO_ERROR;
  167. }
  168. //
  169. // This function causes the multilink check box behave in a way that
  170. // allows the user to see how multilink works.
  171. //
  172. DWORD
  173. GenTabAdjustMultilinkAppearance(
  174. IN HWND hwndDlg,
  175. IN HANDLE hDevDatabase,
  176. IN HANDLE hMiscDatabase)
  177. {
  178. DWORD dwErr = NO_ERROR, i, dwEndpointsEnabled;
  179. HWND hwndML = GetDlgItem(hwndDlg, CID_GenTab_CB_Multilink);
  180. BOOL bDisable, bUncheck, bFlag = FALSE, bIsServer;
  181. do
  182. {
  183. // Initialize default behavior in case of an error
  184. //
  185. bDisable = TRUE;
  186. bUncheck = FALSE;
  187. // Find out how many endpoints are enabled for inbound calls
  188. //
  189. dwErr = devGetEndpointEnableCount(
  190. hDevDatabase,
  191. &dwEndpointsEnabled);
  192. if (dwErr != NO_ERROR)
  193. {
  194. break;
  195. }
  196. // If multiple devices are not enabled for inbound calls then
  197. // multilink is meaningless. Disable the multilink control and
  198. // uncheck it.
  199. //
  200. if (dwEndpointsEnabled < 2)
  201. {
  202. bUncheck = TRUE;
  203. bDisable = TRUE;
  204. dwErr = NO_ERROR;
  205. break;
  206. }
  207. // The multilink check only makes sense on NT Server. This is
  208. // based on the following assumptions
  209. // 1. You only disable multilink so that you can free lines
  210. // for additional callers.
  211. // 2. PPP will enforce that you only have one caller over
  212. // modem device on nt wks anyway.
  213. //
  214. miscGetProductType(hMiscDatabase, &bIsServer);
  215. if (! bIsServer)
  216. {
  217. bDisable = TRUE;
  218. bUncheck = FALSE;
  219. dwErr = NO_ERROR;
  220. break;
  221. }
  222. // Otherwise, multilink makes sense. Enable the multilink
  223. // control and set its check according to what the system says
  224. bDisable = FALSE;
  225. bUncheck = FALSE;
  226. dwErr = miscGetMultilinkEnable(hMiscDatabase, &bFlag);
  227. if (dwErr != NO_ERROR)
  228. {
  229. GenTabDisplayError(hwndDlg, ERR_DEVICE_DATABASE_CORRUPT);
  230. break;
  231. }
  232. } while (FALSE);
  233. // Cleanup
  234. {
  235. if (hwndML)
  236. {
  237. EnableWindow(hwndML, !bDisable);
  238. if (bUncheck)
  239. {
  240. SendMessage(
  241. hwndML,
  242. BM_SETCHECK,
  243. BST_UNCHECKED,
  244. 0);
  245. }
  246. else
  247. {
  248. SendMessage(
  249. hwndML,
  250. BM_SETCHECK,
  251. (bFlag) ? BST_CHECKED : BST_UNCHECKED,
  252. 0);
  253. }
  254. }
  255. }
  256. return dwErr;
  257. }
  258. //
  259. // Initializes the general tab. By now a handle to the general
  260. // database has been placed in the user data of the dialog
  261. //
  262. DWORD
  263. GenTabInitializeDialog(
  264. IN HWND hwndDlg,
  265. IN WPARAM wParam,
  266. IN LPARAM lParam)
  267. {
  268. DWORD dwErr, dwCount;
  269. BOOL bFlag, bIsServer = FALSE;
  270. HWND hwndVPN = NULL;
  271. HWND hwndShowIcons = NULL;
  272. HANDLE hDevDatabase = NULL, hMiscDatabase = NULL;
  273. HWND hwndLV = GetDlgItem(hwndDlg, CID_GenTab_LV_Devices);
  274. // Get handles to the databases we're interested in
  275. //
  276. RasSrvGetDatabaseHandle(
  277. hwndDlg,
  278. ID_DEVICE_DATABASE,
  279. &hDevDatabase);
  280. RasSrvGetDatabaseHandle(
  281. hwndDlg,
  282. ID_MISC_DATABASE,
  283. &hMiscDatabase);
  284. // Set the logging level
  285. //
  286. miscSetRasLogLevel(hMiscDatabase, MISCDB_RAS_LEVEL_ERR_AND_WARN);
  287. // Fill in the list view will all available devices
  288. //
  289. if (hwndLV) ListView_InstallChecks(hwndLV, Globals.hInstDll);
  290. GenTabFillDeviceList(hwndDlg, hwndLV, hDevDatabase);
  291. // Adjust the multilink control
  292. //
  293. miscGetProductType(hMiscDatabase, &bIsServer);
  294. if (bIsServer)
  295. {
  296. GenTabAdjustMultilinkAppearance(
  297. hwndDlg,
  298. hDevDatabase,
  299. hMiscDatabase);
  300. }
  301. else
  302. {
  303. HWND hwndMultiLink = GetDlgItem(hwndDlg, CID_GenTab_CB_Multilink);
  304. if (hwndMultiLink)
  305. {
  306. ShowWindow(hwndMultiLink, SW_HIDE);
  307. }
  308. }
  309. // Initialize the vpn check
  310. //
  311. dwErr = devGetVpnEnable(hDevDatabase, &bFlag);
  312. if (dwErr != NO_ERROR)
  313. {
  314. GenTabDisplayError(hwndDlg, ERR_DEVICE_DATABASE_CORRUPT);
  315. return dwErr;
  316. }
  317. hwndVPN = GetDlgItem(hwndDlg, CID_GenTab_CB_Vpn);
  318. if (hwndVPN)
  319. {
  320. SendMessage(hwndVPN,
  321. BM_SETCHECK,
  322. (bFlag) ? BST_CHECKED : BST_UNCHECKED,
  323. 0);
  324. }
  325. // Initialize the show icons check
  326. //
  327. dwErr = miscGetIconEnable(hMiscDatabase, &bFlag);
  328. if (dwErr != NO_ERROR)
  329. {
  330. GenTabDisplayError(hwndDlg, ERR_DEVICE_DATABASE_CORRUPT);
  331. return dwErr;
  332. }
  333. hwndShowIcons = GetDlgItem(hwndDlg, CID_GenTab_CB_ShowIcons);
  334. if (hwndShowIcons)
  335. {
  336. SendMessage(hwndShowIcons,
  337. BM_SETCHECK,
  338. (bFlag) ? BST_CHECKED : BST_UNCHECKED,
  339. 0);
  340. }
  341. //
  342. //for bug 154607 whistler, Enable/Disable Show Icon on taskbar
  343. //check box according to Policy
  344. //
  345. {
  346. BOOL fShowStatistics = TRUE;
  347. HRESULT hr;
  348. INetConnectionUiUtilities * pNetConUtilities = NULL;
  349. hr = HrCreateNetConnectionUtilities(&pNetConUtilities);
  350. if ( SUCCEEDED(hr))
  351. {
  352. fShowStatistics =
  353. INetConnectionUiUtilities_UserHasPermission(
  354. pNetConUtilities, NCPERM_Statistics);
  355. EnableWindow( GetDlgItem(hwndDlg, CID_GenTab_CB_ShowIcons), fShowStatistics );
  356. INetConnectionUiUtilities_Release(pNetConUtilities);
  357. }
  358. }
  359. return NO_ERROR;
  360. }
  361. //
  362. // Deals with changes in the check of a device
  363. //
  364. DWORD
  365. GenTabHandleDeviceCheck(
  366. IN HWND hwndDlg,
  367. IN INT iItem)
  368. {
  369. HANDLE hDevDatabase = NULL, hMiscDatabase = NULL, hDevice = NULL;
  370. DWORD dwErr;
  371. HWND hwndLVDevices;
  372. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  373. RasSrvGetDatabaseHandle(hwndDlg, ID_MISC_DATABASE, &hMiscDatabase);
  374. hwndLVDevices = GetDlgItem(hwndDlg, CID_GenTab_LV_Devices);
  375. // Set the enabling of the given device
  376. dwErr = devGetDeviceHandle(hDevDatabase, (DWORD)iItem, &hDevice);
  377. if ((NO_ERROR == dwErr) && hwndLVDevices)
  378. {
  379. // Set the device
  380. devSetDeviceEnable(
  381. hDevice,
  382. ListView_GetCheck(hwndLVDevices,
  383. iItem));
  384. // Update the multilink check
  385. GenTabAdjustMultilinkAppearance(
  386. hwndDlg,
  387. hDevDatabase,
  388. hMiscDatabase);
  389. }
  390. return NO_ERROR;
  391. }
  392. //
  393. // Go through the list view and get the device enablings and
  394. // commit them to the database.
  395. //
  396. DWORD
  397. GenTabCommitDeviceSettings(
  398. IN HWND hwndLV,
  399. IN HANDLE hDevDatabase)
  400. {
  401. return NO_ERROR;
  402. }
  403. //
  404. // Processes the activation of the general tab. Return TRUE to
  405. // report that the message has been handled.
  406. //
  407. BOOL
  408. GenTabSetActive (
  409. IN HWND hwndDlg)
  410. {
  411. HANDLE hDevDatabase = NULL;
  412. DWORD dwErr, dwCount, dwId;
  413. PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
  414. // Find out if we're the device page in the incoming wizard.
  415. dwErr = RasSrvGetPageId (hwndDlg, &dwId);
  416. if (dwErr != NO_ERROR)
  417. {
  418. return dwErr;
  419. }
  420. if (dwId == RASSRVUI_DEVICE_WIZ_TAB)
  421. {
  422. // Find out if there are any devices to show
  423. RasSrvGetDatabaseHandle(
  424. hwndDlg,
  425. ID_DEVICE_DATABASE,
  426. &hDevDatabase);
  427. dwErr = devGetDeviceCount (hDevDatabase, &dwCount);
  428. // If there are no devices or if there's a database problem,
  429. // don't allow this page to be activated.
  430. if ((dwErr != NO_ERROR) || (dwCount == 0))
  431. {
  432. SetWindowLongPtr (hwndDlg, DWLP_MSGRESULT, (LONG_PTR)-1);
  433. }
  434. }
  435. PropSheet_SetWizButtons(
  436. GetParent(hwndDlg),
  437. PSWIZB_NEXT | PSWIZB_BACK);
  438. return TRUE;
  439. }
  440. //
  441. // Displays properties for the given device
  442. //
  443. DWORD
  444. GenTabRaiseProperties (
  445. IN HWND hwndDlg,
  446. IN DWORD dwIndex)
  447. {
  448. HANDLE hDevDatabase = NULL, hDevice = NULL;
  449. DWORD dwId, dwErr;
  450. // Get the device id
  451. RasSrvGetDatabaseHandle(
  452. hwndDlg,
  453. ID_DEVICE_DATABASE,
  454. &hDevDatabase);
  455. dwErr = devGetDeviceHandle(hDevDatabase, dwIndex, &hDevice);
  456. if (dwErr != NO_ERROR)
  457. {
  458. return ERROR_CAN_NOT_COMPLETE;
  459. }
  460. if (devGetDeviceId(hDevice, &dwId) != NO_ERROR)
  461. {
  462. return ERROR_CAN_NOT_COMPLETE;
  463. }
  464. // Launch the device properties dialog
  465. dwErr = lineConfigDialogW(dwId, hwndDlg, NULL);
  466. if (dwErr == LINEERR_OPERATIONUNAVAIL)
  467. {
  468. GenTabDisplayError(hwndDlg, ERR_DEVICE_HAS_NO_CONFIG);
  469. dwErr = NO_ERROR;
  470. }
  471. return dwErr;
  472. }
  473. //
  474. // WM_COMMAND handler
  475. //
  476. DWORD
  477. GenTabCommand(
  478. IN HWND hwndDlg,
  479. IN WPARAM wParam)
  480. {
  481. HANDLE hMiscDatabase = NULL, hDevDatabase = NULL;
  482. RasSrvGetDatabaseHandle(
  483. hwndDlg,
  484. ID_MISC_DATABASE,
  485. &hMiscDatabase);
  486. RasSrvGetDatabaseHandle(
  487. hwndDlg,
  488. ID_DEVICE_DATABASE,
  489. &hDevDatabase);
  490. switch (wParam)
  491. {
  492. case CID_GenTab_CB_Multilink:
  493. miscSetMultilinkEnable(
  494. hMiscDatabase,
  495. (BOOL)SendDlgItemMessage(
  496. hwndDlg,
  497. CID_GenTab_CB_Multilink,
  498. BM_GETCHECK,
  499. 0,
  500. 0));
  501. break;
  502. case CID_GenTab_CB_Vpn:
  503. devSetVpnEnable(
  504. hDevDatabase,
  505. (BOOL)SendDlgItemMessage(
  506. hwndDlg,
  507. CID_GenTab_CB_Vpn,
  508. BM_GETCHECK,
  509. 0,
  510. 0));
  511. break;
  512. case CID_GenTab_CB_ShowIcons:
  513. miscSetIconEnable(
  514. hMiscDatabase,
  515. (BOOL)SendDlgItemMessage(
  516. hwndDlg,
  517. CID_GenTab_CB_ShowIcons,
  518. BM_GETCHECK,
  519. 0,
  520. 0));
  521. break;
  522. case CID_GenTab_PB_Properties:
  523. {
  524. HWND hwndLVDevices = GetDlgItem(hwndDlg, CID_GenTab_LV_Devices);
  525. if (hwndLVDevices)
  526. {
  527. GenTabRaiseProperties (
  528. hwndDlg,
  529. ListView_GetSelectionMark(hwndLVDevices));
  530. }
  531. break;
  532. }
  533. }
  534. return NO_ERROR;
  535. }
  536. //
  537. // This is the dialog procedure that responds to messages sent
  538. // to the general tab.
  539. //
  540. INT_PTR
  541. CALLBACK
  542. GenTabDialogProc(
  543. IN HWND hwndDlg,
  544. IN UINT uMsg,
  545. IN WPARAM wParam,
  546. IN LPARAM lParam)
  547. {
  548. // Filter the customized list view messages
  549. if (ListView_OwnerHandler(
  550. hwndDlg,
  551. uMsg,
  552. wParam,
  553. lParam,
  554. LvDrawInfoCallback )
  555. )
  556. {
  557. return TRUE;
  558. }
  559. // Filter the customized ras server ui page messages. By
  560. // filtering messages through here, we are able to call
  561. // RasSrvGetDatabaseHandle below
  562. //
  563. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  564. {
  565. return TRUE;
  566. }
  567. // Process other messages as normal
  568. switch (uMsg)
  569. {
  570. case WM_INITDIALOG:
  571. return FALSE;
  572. break;
  573. case WM_HELP:
  574. case WM_CONTEXTMENU:
  575. RasSrvHelp (hwndDlg, uMsg, wParam, lParam, phmGenTab);
  576. break;
  577. case WM_NOTIFY:
  578. {
  579. NM_LISTVIEW* pLvNotifyData;
  580. NMHDR* pNotifyData = (NMHDR*)lParam;
  581. switch (pNotifyData->code) {
  582. //
  583. // Note: PSN_APPLY and PSN_CANCEL are handled
  584. // by RasSrvMessageFilter
  585. //
  586. case PSN_SETACTIVE:
  587. // Initailize the dialog if it isn't already
  588. //
  589. if (! GetWindowLongPtr(hwndDlg, GWLP_USERDATA))
  590. {
  591. GenTabInitializeDialog(hwndDlg, wParam, lParam);
  592. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)1);
  593. }
  594. if (GenTabSetActive (hwndDlg))
  595. return TRUE;
  596. break;
  597. // The check of an item is changing
  598. case LVXN_SETCHECK:
  599. pLvNotifyData = (NM_LISTVIEW*)lParam;
  600. GenTabHandleDeviceCheck(
  601. hwndDlg,
  602. pLvNotifyData->iItem);
  603. break;
  604. case LVXN_DBLCLK:
  605. pLvNotifyData = (NM_LISTVIEW*)lParam;
  606. GenTabRaiseProperties(
  607. hwndDlg,
  608. pLvNotifyData->iItem);
  609. break;
  610. }
  611. }
  612. break;
  613. case WM_COMMAND:
  614. GenTabCommand(hwndDlg, wParam);
  615. break;
  616. }
  617. return FALSE;
  618. }