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.

778 lines
23 KiB

  1. /*****************************************************************************
  2. *
  3. * $Workfile: CfgPort.cpp $
  4. *
  5. * Copyright (C) 1997 Hewlett-Packard Company.
  6. * Copyright (c) 1997 Microsoft Corporation.
  7. * All rights reserved.
  8. *
  9. * 11311 Chinden Blvd.
  10. * Boise, Idaho 83714
  11. *
  12. *****************************************************************************/
  13. /*
  14. * Author: Becky Jacobsen
  15. */
  16. #include "precomp.h"
  17. #include "TCPMonUI.h"
  18. #include "UIMgr.h"
  19. #include "InptChkr.h"
  20. #include "CfgPort.h"
  21. #include "Resource.h"
  22. #include "LPRData.h"
  23. #include "RTcpData.h"
  24. #include "..\TcpMon\LPRIfc.h"
  25. //
  26. // FUNCTION: CConfigPortDlg constructor
  27. //
  28. // PURPOSE: initialize a CConfigPortDlg class
  29. //
  30. CConfigPortDlg::CConfigPortDlg()
  31. {
  32. m_bDontAllowThisPageToBeDeactivated = FALSE;
  33. } // constructor
  34. //
  35. // FUNCTION: CConfigPortDlg destructor
  36. //
  37. // PURPOSE: deinitialize a CConfigPortDlg class
  38. //
  39. CConfigPortDlg::~CConfigPortDlg()
  40. {
  41. } // destructor
  42. //
  43. // FUNCTION: ConfigurePortPage(HWND, UINT, WPARAM, LPARAM)
  44. //
  45. // PURPOSE: To process messages from the summary dialog for adding a port.
  46. //
  47. // MESSAGES:
  48. //
  49. // WM_INITDIALOG - intializes the page
  50. // WM_COMMAND - handles button presses and text changes in edit controls.
  51. //
  52. //
  53. INT_PTR CALLBACK ConfigurePortPage(
  54. HWND hDlg,
  55. UINT message,
  56. WPARAM wParam,
  57. LPARAM lParam)
  58. {
  59. CConfigPortDlg *wndDlg = NULL;
  60. wndDlg = (CConfigPortDlg *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  61. switch (message) {
  62. case WM_INITDIALOG:
  63. wndDlg = new CConfigPortDlg;
  64. if( wndDlg == NULL )
  65. return( FALSE );
  66. //
  67. // If the function succeeds, the return value is the previous value of the specified offset.
  68. //
  69. // If the function fails, the return value is zero. To get extended error
  70. // information, call GetLastError.
  71. //
  72. // If the previous value is zero and the function succeeds, the return value is zero,
  73. // but the function does not clear the last error information. To determine success or failure,
  74. // clear the last error information by calling SetLastError(0), then call SetWindowLongPtr.
  75. // Function failure will be indicated by a return value of zero and a GetLastError result that is nonzero.
  76. //
  77. SetLastError (0);
  78. if (!SetWindowLongPtr(hDlg, GWLP_USERDATA, (UINT_PTR)wndDlg) && GetLastError()) {
  79. delete wndDlg;
  80. return FALSE;
  81. }
  82. else
  83. return wndDlg->OnInitDialog(hDlg, wParam, lParam);
  84. break;
  85. case WM_COMMAND:
  86. return wndDlg->OnCommand(hDlg, wParam, lParam);
  87. break;
  88. case WM_NOTIFY:
  89. return wndDlg->OnNotify(hDlg, wParam, lParam);
  90. break;
  91. case WM_HELP:
  92. case WM_CONTEXTMENU:
  93. OnHelp(IDD_PORT_SETTINGS, hDlg, message, wParam, lParam);
  94. break;
  95. case WM_DESTROY:
  96. if (wndDlg)
  97. delete wndDlg;
  98. break;
  99. default:
  100. return FALSE;
  101. }
  102. return TRUE;
  103. } // AddPortDialog
  104. //
  105. // FUNCTION: OnInitDialog(HWND hDlg)
  106. //
  107. // PURPOSE: Initialize the dialog.
  108. //
  109. BOOL CConfigPortDlg::OnInitDialog(HWND hDlg, WPARAM, LPARAM lParam)
  110. {
  111. m_pParams = (CFG_PARAM_PACKAGE *) ((PROPSHEETPAGE *) lParam)->lParam;
  112. if(m_pParams->bNewPort == FALSE) {
  113. SendMessage(GetDlgItem(hDlg, IDC_EDIT_PORT_NAME), EM_SETREADONLY, TRUE, 0);
  114. }
  115. Edit_LimitText(GetDlgItem(hDlg, IDC_EDIT_DEVICE_ADDRESS), MAX_ADDRESS_LENGTH - 1);
  116. Edit_LimitText(GetDlgItem(hDlg, IDC_EDIT_PORT_NAME), MAX_PORTNAME_LEN - 1);
  117. Edit_LimitText(GetDlgItem(hDlg, IDC_EDIT_RAW_PORT_NUM), MAX_PORTNUM_STRING_LENGTH - 1);
  118. Edit_LimitText(GetDlgItem(hDlg, IDC_EDIT_LPR_QNAME), MAX_QUEUENAME_LEN - 1);
  119. Edit_LimitText(GetDlgItem(hDlg, IDC_EDIT_COMMUNITY_NAME), MAX_SNMP_COMMUNITY_STR_LEN);
  120. Edit_LimitText(GetDlgItem(hDlg, IDC_EDIT_DEVICE_INDEX), MAX_SNMP_DEVICENUM_STRING_LENGTH - 1);
  121. OnSetActive(hDlg);
  122. return TRUE;
  123. } // OnInitDialog
  124. //
  125. // Function: OnSetActive()
  126. //
  127. // Purpose: To Set all the text fields and make sure the proper buttons are checked.
  128. //
  129. void CConfigPortDlg::OnSetActive(HWND hDlg)
  130. {
  131. TCHAR psztPortNumber[MAX_PORTNUM_STRING_LENGTH] = NULLSTR;
  132. TCHAR psztSNMPDevIndex[MAX_SNMP_DEVICENUM_STRING_LENGTH] = NULLSTR;
  133. TCHAR szTemp[MAX_PATH];
  134. lstrcpyn(szTemp, m_pParams->pData->sztHostAddress, SIZEOF_IN_CHAR(szTemp));
  135. m_InputChkr.MakePortName( szTemp, COUNTOF (szTemp) );
  136. if ( m_pParams->bNewPort &&
  137. ((_tcscmp(m_pParams->pData->sztHostAddress,
  138. m_pParams->pData->sztPortName) == 0) ||
  139. (_tcscmp(m_pParams->pData->sztPortName, szTemp) == 0 ))) {
  140. m_InputChkr.LinkPortNameAndAddressInput();
  141. } else {
  142. m_InputChkr.UnlinkPortNameAndAddressInput();
  143. }
  144. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_DEVICE_ADDRESS),
  145. m_pParams->pData->sztHostAddress);
  146. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_PORT_NAME),
  147. m_pParams->pData->sztPortName);
  148. switch (m_pParams->pData->dwProtocol) {
  149. case PROTOCOL_LPR_TYPE :
  150. CheckProtocolAndEnable(hDlg, IDC_RADIO_LPR);
  151. break;
  152. case PROTOCOL_RAWTCP_TYPE:
  153. CheckProtocolAndEnable(hDlg, IDC_RADIO_RAW);
  154. break;
  155. default:
  156. break;
  157. }
  158. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_LPR_QNAME),
  159. m_pParams->pData->sztQueue);
  160. if( m_pParams->pData->dwDoubleSpool )
  161. {
  162. CheckDlgButton(hDlg, IDC_CHECK_LPR_DOUBLESPOOL, BST_CHECKED);
  163. }
  164. else
  165. {
  166. CheckDlgButton(hDlg, IDC_CHECK_LPR_DOUBLESPOOL, BST_UNCHECKED);
  167. }
  168. StringCchPrintf (psztPortNumber, COUNTOF (psztPortNumber), TEXT("%d"), m_pParams->pData->dwPortNumber);
  169. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_RAW_PORT_NUM),
  170. psztPortNumber);
  171. CheckSNMPAndEnable(hDlg, m_pParams->pData->dwSNMPEnabled);
  172. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_COMMUNITY_NAME),
  173. m_pParams->pData->sztSNMPCommunity);
  174. StringCchPrintf (psztSNMPDevIndex, COUNTOF (psztSNMPDevIndex), TEXT("%d"), m_pParams->pData->dwSNMPDevIndex);
  175. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_DEVICE_INDEX), psztSNMPDevIndex);
  176. m_bDontAllowThisPageToBeDeactivated = FALSE;
  177. } // OnSetActive
  178. //
  179. // FUNCTION: CheckProtocolAndEnable()
  180. //
  181. // PURPOSE: Check the radio button whose id is passed in
  182. // in idButton. Enable the corresponding set of controls
  183. // and disable the controls corresponding to the other
  184. // radio button.
  185. //
  186. void CConfigPortDlg::CheckProtocolAndEnable(HWND hDlg, int idButton)
  187. {
  188. CheckRadioButton(hDlg, IDC_RADIO_RAW, IDC_RADIO_LPR, idButton);
  189. switch ( idButton ) {
  190. case IDC_RADIO_LPR:
  191. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_RAW_PORT_NUM), FALSE);
  192. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_RAW_PORT_NUM), FALSE);
  193. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_LPR_QNAME), TRUE);
  194. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_LPR_QNAME), TRUE);
  195. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_LPR_DOUBLESPOOL), TRUE);
  196. break;
  197. case IDC_RADIO_RAW: {
  198. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_RAW_PORT_NUM), TRUE);
  199. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_RAW_PORT_NUM), TRUE);
  200. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_LPR_QNAME), FALSE);
  201. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_LPR_QNAME), FALSE);
  202. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_LPR_DOUBLESPOOL), FALSE);
  203. const int iSize = 6;
  204. TCHAR pString[iSize] = NULLSTR;
  205. TCHAR pCompareString[iSize] = NULLSTR;
  206. StringCchPrintf (pCompareString, COUNTOF (pCompareString), TEXT("%d"), LPR_PORT_1);
  207. GetWindowText(GetDlgItem(hDlg, IDC_EDIT_RAW_PORT_NUM), pString, iSize);
  208. if( _tcscmp(pString, pCompareString) == 0 ) {
  209. StringCchPrintf (pString, COUNTOF (pString), TEXT("%d"), SUPPORTED_PORT_1);
  210. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_RAW_PORT_NUM), pString);
  211. }
  212. }
  213. break;
  214. default:
  215. break;
  216. }
  217. } // CheckProtocolAndEnable
  218. //
  219. // FUNCTION: CheckSNMPAndEnable()
  220. //
  221. // PURPOSE: Check the SNMP CheckBox and Enable the corresponding controls
  222. // or uncheck and disable.
  223. //
  224. void CConfigPortDlg::CheckSNMPAndEnable(HWND hDlg, BOOL Check)
  225. {
  226. if(Check != FALSE) {
  227. CheckDlgButton(hDlg, IDC_CHECK_SNMP, BST_CHECKED);
  228. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_COMMUNITY_NAME), TRUE);
  229. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_COMMUNITY_NAME), TRUE);
  230. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_DEVICE_INDEX), TRUE);
  231. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_DEVICE_INDEX), TRUE);
  232. } else {
  233. CheckDlgButton(hDlg, IDC_CHECK_SNMP, BST_UNCHECKED);
  234. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_COMMUNITY_NAME), FALSE);
  235. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_COMMUNITY_NAME), FALSE);
  236. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_DEVICE_INDEX), FALSE);
  237. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_DEVICE_INDEX), FALSE);
  238. }
  239. } // CheckSNMPAndEnable
  240. //
  241. // FUNCTION: OnCommand()
  242. //
  243. // PURPOSE: Process WM_COMMAND message
  244. //
  245. BOOL CConfigPortDlg::OnCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
  246. {
  247. switch(HIWORD(wParam)) {
  248. case BN_CLICKED:
  249. return OnButtonClicked(hDlg, wParam, lParam);
  250. break;
  251. case EN_UPDATE:
  252. // one of the text controls had text changed in it.
  253. return OnEnUpdate(hDlg, wParam, lParam);
  254. break;
  255. default:
  256. break;
  257. }
  258. return TRUE;
  259. } // OnCommand
  260. //
  261. // FUNCTION: OnEnUpdate()
  262. //
  263. // PURPOSE: Process EN_UPDATE message
  264. //
  265. BOOL CConfigPortDlg::OnEnUpdate(HWND hDlg, WPARAM wParam, LPARAM lParam)
  266. {
  267. int idEditCtrl = (int) LOWORD(wParam);
  268. HWND hwndEditCtrl = NULL;
  269. hwndEditCtrl = (HWND) lParam;
  270. if(idEditCtrl == IDC_EDIT_DEVICE_ADDRESS) {
  271. m_InputChkr.OnUpdateAddress(hDlg, idEditCtrl, hwndEditCtrl, m_pParams->pszServer);
  272. }
  273. //
  274. // Port name is a read-only field
  275. //
  276. // if(idEditCtrl == IDC_EDIT_PORT_NAME)
  277. // m_InputChkr.OnUpdatePortName(idEditCtrl, hwndEditCtrl);
  278. //
  279. if(idEditCtrl == IDC_EDIT_RAW_PORT_NUM) {
  280. m_InputChkr.OnUpdatePortNumber(idEditCtrl, hwndEditCtrl);
  281. }
  282. if(idEditCtrl == IDC_EDIT_LPR_QNAME) {
  283. m_InputChkr.OnUpdateQueueName(idEditCtrl, hwndEditCtrl);
  284. }
  285. if(idEditCtrl == IDC_EDIT_COMMUNITY_NAME) {
  286. // No function needed since any character is ok.
  287. }
  288. if(idEditCtrl == IDC_EDIT_DEVICE_INDEX) {
  289. m_InputChkr.OnUpdateDeviceIndex(idEditCtrl, hwndEditCtrl);
  290. }
  291. return TRUE;
  292. } // OnEnUpdate
  293. //
  294. // FUNCTION: OnButtonClicked()
  295. //
  296. // PURPOSE: Process BN_CLICKED message
  297. //
  298. BOOL CConfigPortDlg::OnButtonClicked(HWND hDlg, WPARAM wParam, LPARAM lParam)
  299. {
  300. int idButton = (int) LOWORD(wParam); // identifier of button
  301. HWND hwndButton = NULL;
  302. hwndButton = (HWND) lParam;
  303. switch(idButton) {
  304. case IDC_CHECK_SNMP:
  305. {
  306. LRESULT iCheck = SendMessage(hwndButton, BM_GETCHECK, 0, 0);
  307. switch( iCheck ) {
  308. case BST_UNCHECKED:
  309. CheckSNMPAndEnable(hDlg, FALSE);
  310. break;
  311. case BST_CHECKED:
  312. CheckSNMPAndEnable(hDlg, TRUE);
  313. break;
  314. default:
  315. //
  316. // False by Default
  317. CheckSNMPAndEnable(hDlg, FALSE);
  318. break;
  319. }
  320. }
  321. break;
  322. case IDC_RADIO_RAW:
  323. case IDC_RADIO_LPR:
  324. CheckProtocolAndEnable(hDlg, idButton);
  325. break;
  326. default:
  327. break;
  328. }
  329. return TRUE;
  330. } // OnButtonClicked
  331. //
  332. // FUNCTION: OnNotify()
  333. //
  334. // PURPOSE: Process WM_NOTIFY message
  335. //
  336. BOOL CConfigPortDlg::OnNotify(HWND hDlg, WPARAM wParam, LPARAM lParam)
  337. {
  338. switch (((NMHDR FAR *) lParam)->code)
  339. {
  340. case PSN_APPLY:
  341. OnOk(hDlg);
  342. // If the page requires additional user input before losing the
  343. // activation, it should use the SetWindowLong function to set the
  344. // DWL_MSGRESULT value of the page to TRUE. Also, the page should
  345. // display a message box that describes the problem and provides
  346. // the recommended action. The page should set DWL_MSGRESULT to FALSE
  347. // when it is okay to lose the activation.
  348. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, m_bDontAllowThisPageToBeDeactivated);
  349. return TRUE;
  350. break;
  351. case PSN_RESET:
  352. // reset to the original values
  353. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  354. break;
  355. case PSN_SETACTIVE:
  356. OnSetActive(hDlg);
  357. break;
  358. case PSN_KILLACTIVE:
  359. SaveSettings(hDlg);
  360. // If the page requires additional user input before losing the
  361. // activation, it should use the SetWindowLong function to set the
  362. // DWL_MSGRESULT value of the page to TRUE. Also, the page should
  363. // display a message box that describes the problem and provides
  364. // the recommended action. The page should set DWL_MSGRESULT to FALSE
  365. // when it is okay to lose the activation.
  366. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, m_bDontAllowThisPageToBeDeactivated);
  367. return TRUE;
  368. break;
  369. case PSN_QUERYCANCEL:
  370. m_pParams->dwLastError = ERROR_CANCELLED;
  371. return FALSE;
  372. break;
  373. default:
  374. return FALSE;
  375. }
  376. return TRUE;
  377. } // OnCommand
  378. //
  379. // FUNCTION: RemoteTellPortMonToModifyThePort
  380. //
  381. // PURPOSE: Loads the spooler drv and calls XcvData.
  382. //
  383. DWORD CConfigPortDlg::RemoteTellPortMonToModifyThePort()
  384. {
  385. DWORD dwRet = NO_ERROR;
  386. XCVDATAPARAM pfnXcvData = NULL;
  387. // load & assign the function pointer
  388. if(g_hWinSpoolLib != NULL) {
  389. // initialize the library
  390. pfnXcvData = (XCVDATAPARAM)::GetProcAddress(g_hWinSpoolLib, "XcvDataW");
  391. if(pfnXcvData != NULL) {
  392. DWORD dwOutputNeeded = 0;
  393. DWORD dwStatus = 0;
  394. // here's the call we've all been waiting for:
  395. DWORD dwReturn = (*pfnXcvData)(m_pParams->hXcvPrinter,
  396. (PCWSTR)TEXT("ConfigPort"),
  397. (PBYTE)m_pParams->pData,
  398. m_pParams->pData->cbSize,
  399. NULL,
  400. 0,
  401. &dwOutputNeeded,
  402. &dwStatus
  403. );
  404. if(!dwReturn) {
  405. dwRet = GetLastError();
  406. } else {
  407. if(dwStatus != NO_ERROR) {
  408. dwRet = dwStatus;
  409. }
  410. }
  411. } else {
  412. dwRet = ERROR_DLL_NOT_FOUND; // TODO: change to an appropriate error code.
  413. }
  414. } else {
  415. dwRet = ERROR_DLL_NOT_FOUND;
  416. }
  417. m_pParams->dwLastError = dwRet;
  418. return dwRet;
  419. } // RemoteTellPortMonToModifyThePort
  420. //
  421. // FUNCTION: LocalTellPortMonToModifyThePort
  422. //
  423. // Purpose: To load the port monitor dll and call ConfigPortUIEx
  424. //
  425. DWORD CConfigPortDlg::LocalTellPortMonToModifyThePort()
  426. {
  427. DWORD dwRet = NO_ERROR;
  428. UIEXPARAM pfnConfigPortUIEx = NULL ;
  429. if(g_hPortMonLib != NULL) {
  430. // initialize the library
  431. pfnConfigPortUIEx = (UIEXPARAM)::GetProcAddress(g_hPortMonLib, "ConfigPortUIEx");
  432. if(pfnConfigPortUIEx != NULL) {
  433. // here's the call we've all been waiting for:
  434. BOOL bReturn = (*pfnConfigPortUIEx)(m_pParams->pData);
  435. if(bReturn == FALSE) {
  436. dwRet = GetLastError();
  437. }
  438. } else {
  439. dwRet = ERROR_DLL_NOT_FOUND;
  440. }
  441. } else {
  442. dwRet = ERROR_DLL_NOT_FOUND;
  443. }
  444. m_pParams->dwLastError = dwRet;
  445. return dwRet;
  446. } // LocalTellPortMonToModifyThePort
  447. //
  448. // FUNCTION OnOk()
  449. //
  450. // PURPOSE: To validate the input and set the values in m_pParams->pData
  451. //
  452. void CConfigPortDlg::OnOk(HWND hDlg)
  453. {
  454. m_bDontAllowThisPageToBeDeactivated = FALSE;
  455. HostAddressOk(hDlg);
  456. if(IsDlgButtonChecked(hDlg, IDC_RADIO_LPR) == BST_CHECKED) {
  457. m_pParams->pData->dwProtocol = PROTOCOL_LPR_TYPE;
  458. m_pParams->pData->dwPortNumber = LPR_DEFAULT_PORT_NUMBER;
  459. QueueNameOk(hDlg);
  460. } else { // IDC_RADIO_RAW
  461. m_pParams->pData->dwProtocol = PROTOCOL_RAWTCP_TYPE;
  462. PortNumberOk(hDlg);
  463. }
  464. if(IsDlgButtonChecked(hDlg, IDC_CHECK_SNMP) == BST_CHECKED) {
  465. m_pParams->pData->dwSNMPEnabled = TRUE;
  466. CommunityNameOk(hDlg);
  467. DeviceIndexOk(hDlg);
  468. } else {
  469. m_pParams->pData->dwSNMPEnabled = FALSE;
  470. }
  471. if(m_pParams->bNewPort == FALSE &&
  472. m_bDontAllowThisPageToBeDeactivated == FALSE) {
  473. HCURSOR hOldCursor = NULL;
  474. HCURSOR hNewCursor = NULL;
  475. hNewCursor = LoadCursor(NULL, IDC_WAIT);
  476. if( hNewCursor )
  477. {
  478. hOldCursor = SetCursor(hNewCursor);
  479. }
  480. // The port is not just being created so we can tell the PortMon to
  481. // modify the port... it is an existing port.
  482. // There were no errors, so we can go ahead and modify this port.
  483. if(m_pParams->hXcvPrinter != NULL) {
  484. RemoteTellPortMonToModifyThePort();
  485. } else {
  486. LocalTellPortMonToModifyThePort();
  487. }
  488. if( hNewCursor )
  489. {
  490. SetCursor(hOldCursor);
  491. }
  492. }
  493. } // OnOk
  494. //
  495. // FUNCTION OnOk()
  496. //
  497. // PURPOSE: To validate the input and set the values in m_pParams->pData
  498. //
  499. void CConfigPortDlg::SaveSettings(HWND hDlg)
  500. {
  501. m_bDontAllowThisPageToBeDeactivated = FALSE;
  502. HostAddressOk(hDlg);
  503. if(IsDlgButtonChecked(hDlg, IDC_RADIO_LPR) == BST_CHECKED) {
  504. m_pParams->pData->dwProtocol = PROTOCOL_LPR_TYPE;
  505. m_pParams->pData->dwPortNumber = LPR_DEFAULT_PORT_NUMBER;
  506. if( IsDlgButtonChecked(hDlg, IDC_CHECK_LPR_DOUBLESPOOL) == BST_CHECKED )
  507. {
  508. m_pParams->pData->dwDoubleSpool = TRUE;
  509. }
  510. else
  511. {
  512. m_pParams->pData->dwDoubleSpool = FALSE;
  513. }
  514. QueueNameOk(hDlg);
  515. } else {// IDC_RADIO_RAW
  516. m_pParams->pData->dwProtocol = PROTOCOL_RAWTCP_TYPE;
  517. PortNumberOk(hDlg);
  518. }
  519. if(IsDlgButtonChecked(hDlg, IDC_CHECK_SNMP) == BST_CHECKED) {
  520. m_pParams->pData->dwSNMPEnabled = TRUE;
  521. CommunityNameOk(hDlg);
  522. DeviceIndexOk(hDlg);
  523. } else {
  524. m_pParams->pData->dwSNMPEnabled = FALSE;
  525. }
  526. } // SaveSettings
  527. //
  528. // FUNCTION HostAddressOk()
  529. //
  530. // PURPOSE: To validate the input and set the values in m_pParams->pData
  531. //
  532. void CConfigPortDlg::HostAddressOk(HWND hDlg)
  533. {
  534. TCHAR ptcsAddress[MAX_ADDRESS_LENGTH] = NULLSTR;
  535. GetWindowText(GetDlgItem(hDlg, IDC_EDIT_DEVICE_ADDRESS), ptcsAddress, MAX_ADDRESS_LENGTH);
  536. if(! m_InputChkr.AddressIsLegal(ptcsAddress)) {
  537. m_bDontAllowThisPageToBeDeactivated = TRUE;
  538. DisplayErrorMessage(hDlg, IDS_STRING_ERROR_TITLE, IDS_STRING_ERROR_ADDRESS_NOT_VALID);
  539. return;
  540. }
  541. lstrcpyn(m_pParams->pData->sztHostAddress, ptcsAddress, MAX_NETWORKNAME_LEN);
  542. } // HostAddressOk
  543. //
  544. // FUNCTION PortNumberOk()
  545. //
  546. // PURPOSE: To validate the input and set the values in m_pParams->pData
  547. //
  548. void CConfigPortDlg::PortNumberOk(HWND hDlg)
  549. {
  550. TCHAR psztPortNumber[MAX_PORTNUM_STRING_LENGTH] = NULLSTR;
  551. GetWindowText(GetDlgItem(hDlg, IDC_EDIT_RAW_PORT_NUM),
  552. psztPortNumber,
  553. MAX_PORTNUM_STRING_LENGTH);
  554. if(! m_InputChkr.PortNumberIsLegal(psztPortNumber)) {
  555. m_bDontAllowThisPageToBeDeactivated = TRUE;
  556. DisplayErrorMessage(hDlg,
  557. IDS_STRING_ERROR_TITLE,
  558. IDS_STRING_ERROR_PORT_NUMBER_NOT_VALID);
  559. return;
  560. }
  561. m_pParams->pData->dwPortNumber = _ttol(psztPortNumber);
  562. } // PortNumberOk
  563. //
  564. // FUNCTION QueueNameOk()
  565. //
  566. // PURPOSE: To validate the input and set the values in m_pParams->pData
  567. //
  568. void CConfigPortDlg::QueueNameOk(HWND hDlg)
  569. {
  570. TCHAR ptcsQueueName[MAX_QUEUENAME_LEN] = NULLSTR;
  571. GetWindowText(GetDlgItem(hDlg, IDC_EDIT_LPR_QNAME),
  572. ptcsQueueName,
  573. MAX_QUEUENAME_LEN);
  574. if(! m_InputChkr.QueueNameIsLegal(ptcsQueueName))
  575. {
  576. m_bDontAllowThisPageToBeDeactivated = TRUE;
  577. DisplayErrorMessage(hDlg,
  578. IDS_STRING_ERROR_TITLE,
  579. IDS_STRING_ERROR_QNAME_NOT_VALID);
  580. return;
  581. }
  582. lstrcpyn(m_pParams->pData->sztQueue, ptcsQueueName, MAX_QUEUENAME_LEN);
  583. } // QueueNameOk
  584. //
  585. // FUNCTION CommunityNameOk()
  586. //
  587. // PURPOSE: To validate the input and set the values in m_pParams->pData
  588. //
  589. void CConfigPortDlg::CommunityNameOk(HWND hDlg)
  590. {
  591. TCHAR ptcsCommunityName[MAX_SNMP_COMMUNITY_STR_LEN] = NULLSTR;
  592. GetWindowText(GetDlgItem(hDlg, IDC_EDIT_COMMUNITY_NAME),
  593. ptcsCommunityName,
  594. MAX_SNMP_COMMUNITY_STR_LEN);
  595. if(! m_InputChkr.CommunityNameIsLegal(ptcsCommunityName)) {
  596. m_bDontAllowThisPageToBeDeactivated = TRUE;
  597. DisplayErrorMessage(hDlg,
  598. IDS_STRING_ERROR_TITLE,
  599. IDS_STRING_ERROR_COMMUNITY_NAME_NOT_VALID);
  600. return;
  601. }
  602. lstrcpyn(m_pParams->pData->sztSNMPCommunity, ptcsCommunityName, MAX_SNMP_COMMUNITY_STR_LEN);
  603. } // CommunityNameOk
  604. //
  605. // FUNCTION DeviceIndexOk()
  606. //
  607. // PURPOSE: To validate the input and set the values in m_pParams->pData
  608. //
  609. void CConfigPortDlg::DeviceIndexOk(HWND hDlg)
  610. {
  611. TCHAR psztSNMPDevIndex[MAX_SNMP_DEVICENUM_STRING_LENGTH] = NULLSTR;
  612. GetWindowText(GetDlgItem(hDlg,
  613. IDC_EDIT_DEVICE_INDEX),
  614. psztSNMPDevIndex,
  615. MAX_SNMP_DEVICENUM_STRING_LENGTH);
  616. if(! m_InputChkr.SNMPDevIndexIsLegal(psztSNMPDevIndex)) {
  617. m_bDontAllowThisPageToBeDeactivated = TRUE;
  618. DisplayErrorMessage(hDlg,
  619. IDS_STRING_ERROR_TITLE,
  620. IDS_STRING_ERROR_SNMP_DEVINDEX_NOT_VALID);
  621. return;
  622. }
  623. m_pParams->pData->dwSNMPDevIndex = _ttol(psztSNMPDevIndex);
  624. } // DeviceIndexOk