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.

768 lines
18 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : ppFaxServerGeneral.cpp //
  3. // //
  4. // DESCRIPTION : prop pages of //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Oct 25 1999 yossg created //
  10. // Nov 22 1999 yossg Call RPC func //
  11. // Nov 24 1999 yossg OnApply create call to all tabs from parent //
  12. // Mar 15 2000 yossg New design add controls //
  13. // Mar 20 2000 yossg Add activity notification //
  14. // //
  15. // Copyright (C) 1999 - 2000 Microsoft Corporation All Rights Reserved //
  16. /////////////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "MSFxsSnp.h"
  19. #include "ppFaxServerGeneral.h"
  20. #include "FaxServer.h"
  21. #include "FaxServerNode.h"
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. class CSnapinNode;
  27. //
  28. // Constructor
  29. //
  30. CppFaxServerGeneral::CppFaxServerGeneral(
  31. LONG_PTR hNotificationHandle,
  32. CSnapInItem *pNode,
  33. BOOL bOwnsNotificationHandle,
  34. HINSTANCE hInst)
  35. : CPropertyPageExImpl<CppFaxServerGeneral>(pNode, NULL)
  36. {
  37. m_pParentNode = static_cast<CFaxServerNode *> (pNode);
  38. m_FaxVersionConfig.dwSizeOfStruct = sizeof(FAX_VERSION);
  39. m_hActivityNotification = NULL;
  40. m_fIsDialogInitiated = FALSE;
  41. m_fIsDirty = FALSE;
  42. m_lpNotifyHandle = hNotificationHandle;
  43. }
  44. //
  45. // Destructor
  46. //
  47. CppFaxServerGeneral::~CppFaxServerGeneral()
  48. {
  49. DEBUG_FUNCTION_NAME( _T("CppFaxServerGeneral::~CppFaxServerGeneral()"));
  50. if (m_hActivityNotification)
  51. {
  52. //
  53. // Unregister server notifications
  54. //
  55. if (!FaxUnregisterForServerEvents (m_hActivityNotification))
  56. {
  57. DWORD ec = GetLastError ();
  58. DebugPrintEx(
  59. DEBUG_ERR,
  60. _T("Fail to Unregister For Server Events. (ec: %ld)"),
  61. ec);
  62. }
  63. }
  64. // Note - This needs to be called only once per property sheet.
  65. // In our convention called in the general tab.
  66. if (NULL != m_lpNotifyHandle)
  67. {
  68. MMCFreeNotifyHandle(m_lpNotifyHandle);
  69. m_lpNotifyHandle = NULL;
  70. }
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CppFaxServerGeneral message handlers
  74. /*
  75. - CppFaxServerGeneral::InitRPC
  76. -
  77. * Purpose:
  78. * Initiates the configuration structure from RPC get Call.
  79. *
  80. * Arguments:
  81. *
  82. * Return:
  83. * OLE error code
  84. */
  85. HRESULT CppFaxServerGeneral::InitRPC( )
  86. {
  87. DEBUG_FUNCTION_NAME( _T("CppFaxServerGeneral::InitRPC"));
  88. HRESULT hRc = S_OK;
  89. DWORD ec = ERROR_SUCCESS;
  90. if (!m_pFaxServer->GetFaxServerHandle())
  91. {
  92. ec= GetLastError();
  93. DebugPrintEx(
  94. DEBUG_ERR,
  95. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  96. ec);
  97. goto Error;
  98. }
  99. //
  100. // Retrieve the fax Archive configuration
  101. //
  102. if (!FaxGetVersion(m_pFaxServer->GetFaxServerHandle(),
  103. &m_FaxVersionConfig))
  104. {
  105. ec = GetLastError();
  106. DebugPrintEx(
  107. DEBUG_ERR,
  108. _T("Fail to get version configuration. (ec: %ld)"),
  109. ec);
  110. if (IsNetworkError(ec))
  111. {
  112. DebugPrintEx(
  113. DEBUG_ERR,
  114. _T("Network Error was found. (ec: %ld)"),
  115. ec);
  116. m_pFaxServer->Disconnect();
  117. }
  118. goto Error;
  119. }
  120. ZeroMemory (&m_FaxServerActivityConfig, sizeof(FAX_SERVER_ACTIVITY));
  121. m_FaxServerActivityConfig.dwSizeOfStruct = sizeof(FAX_SERVER_ACTIVITY);
  122. if (!FaxGetServerActivity(
  123. m_pFaxServer->GetFaxServerHandle(),
  124. &m_FaxServerActivityConfig
  125. )
  126. )
  127. {
  128. ec = GetLastError();
  129. DebugPrintEx(
  130. DEBUG_ERR,
  131. _T("Fail to get Server Activity configuration. (ec: %ld)"),
  132. ec);
  133. if (IsNetworkError(ec))
  134. {
  135. DebugPrintEx(
  136. DEBUG_ERR,
  137. _T("Network Error was found. (ec: %ld)"),
  138. ec);
  139. m_pFaxServer->Disconnect();
  140. }
  141. goto Error;
  142. }
  143. if (!FaxGetQueueStates(
  144. m_pFaxServer->GetFaxServerHandle(),
  145. &m_dwQueueStates
  146. )
  147. )
  148. {
  149. ec = GetLastError();
  150. DebugPrintEx(
  151. DEBUG_ERR,
  152. _T("Fail to get Queue States configuration. (ec: %ld)"),
  153. ec);
  154. if (IsNetworkError(ec))
  155. {
  156. DebugPrintEx(
  157. DEBUG_ERR,
  158. _T("Network Error was found. (ec: %ld)"),
  159. ec);
  160. m_pFaxServer->Disconnect();
  161. }
  162. goto Error;
  163. }
  164. ATLASSERT(S_OK == hRc);
  165. DebugPrintEx( DEBUG_MSG,
  166. _T("Succeed to get version configuration."));
  167. goto Exit;
  168. Error:
  169. ATLASSERT(ERROR_SUCCESS != ec);
  170. hRc = HRESULT_FROM_WIN32(ec);
  171. ATLASSERT(NULL != m_pParentNode);
  172. m_pParentNode->NodeMsgBox(GetFaxServerErrorMsg(ec));
  173. Exit:
  174. return (hRc);
  175. }
  176. /*
  177. - CFaxServerNode::UpdateActivityCounters
  178. -
  179. * Purpose:
  180. * Inits and updates the activity counters: Queued, outgoing and incoming faxes.
  181. *
  182. * Arguments:
  183. *
  184. * Return:
  185. * OLE error code
  186. */
  187. HRESULT CppFaxServerGeneral::UpdateActivityCounters()
  188. {
  189. DEBUG_FUNCTION_NAME( _T("CppFaxServerGeneral::UpdateActivityCounters"));
  190. HRESULT hRc = S_OK;
  191. int count;
  192. WCHAR szQueuedMessagesBuff[FXS_DWORD_LEN +1];
  193. WCHAR szOutgoingMessagesBuff[FXS_DWORD_LEN +1];
  194. WCHAR szIncomingMessagesBuff[FXS_DWORD_LEN +1];
  195. //
  196. // QueuedMessages
  197. //
  198. count =0;
  199. count = swprintf( szQueuedMessagesBuff,
  200. L"%ld",
  201. m_FaxServerActivityConfig.dwQueuedMessages
  202. );
  203. if( count > 0 )
  204. {
  205. m_QueuedEdit.SetWindowText(szQueuedMessagesBuff);
  206. }
  207. else
  208. {
  209. DebugPrintEx(
  210. DEBUG_ERR,
  211. _T("Out of memory. Failed to allocate string."));
  212. PageError(IDS_MEMORY,m_hWnd);
  213. goto Exit;
  214. }
  215. //
  216. // OutgoingMessages
  217. //
  218. count =0;
  219. count = swprintf( szOutgoingMessagesBuff,
  220. L"%ld",
  221. ( m_FaxServerActivityConfig.dwOutgoingMessages +
  222. m_FaxServerActivityConfig.dwDelegatedOutgoingMessages )
  223. );
  224. if( count > 0 )
  225. {
  226. m_OutgoingEdit.SetWindowText(szOutgoingMessagesBuff);
  227. }
  228. else
  229. {
  230. DebugPrintEx(
  231. DEBUG_ERR,
  232. _T("Out of memory. Failed to allocate string."));
  233. PageError(IDS_MEMORY,m_hWnd);
  234. goto Exit;
  235. }
  236. //
  237. // IncomingMessages
  238. //
  239. count =0;
  240. count = swprintf( szIncomingMessagesBuff,
  241. L"%ld",
  242. ( m_FaxServerActivityConfig.dwIncomingMessages +
  243. m_FaxServerActivityConfig.dwRoutingMessages )
  244. );
  245. if( count > 0 )
  246. {
  247. m_IncomingEdit.SetWindowText(szIncomingMessagesBuff);
  248. }
  249. else
  250. {
  251. DebugPrintEx(
  252. DEBUG_ERR,
  253. _T("Out of memory. Failed to allocate string."));
  254. PageError(IDS_MEMORY,m_hWnd);
  255. goto Exit;
  256. }
  257. Exit:
  258. return hRc;
  259. }
  260. /*
  261. - CFaxServerNode::OnInitDialog
  262. -
  263. * Purpose:
  264. * Initiates all controls when dialog is called.
  265. *
  266. * Arguments:
  267. *
  268. * Return:
  269. *
  270. */
  271. LRESULT CppFaxServerGeneral::OnInitDialog( UINT uiMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled )
  272. {
  273. DEBUG_FUNCTION_NAME( _T("CppFaxServerGeneral::OnInitDialog"));
  274. UNREFERENCED_PARAMETER( uiMsg );
  275. UNREFERENCED_PARAMETER( wParam );
  276. UNREFERENCED_PARAMETER( lParam );
  277. UNREFERENCED_PARAMETER( fHandled );
  278. CComBSTR bstrVersion, bstrChecked;
  279. // a Buffer to collect all version DWORDs in
  280. // 256 >> 4*DWORD in chars +3*char ('.') + chars of (" (Checked)")
  281. WCHAR buffer[256];
  282. int count;
  283. DWORD ec = ERROR_SUCCESS;
  284. HRESULT hRc = S_OK;
  285. //
  286. // init controls
  287. //
  288. //
  289. // Version
  290. //
  291. //bstrVersion = L"5.0.813.0 (Chk)" or L"5.0.813.0"
  292. count = swprintf(
  293. buffer,
  294. L"%ld.%ld.%ld.%ld",
  295. m_FaxVersionConfig.wMajorVersion,
  296. m_FaxVersionConfig.wMinorVersion,
  297. m_FaxVersionConfig.wMajorBuildNumber,
  298. m_FaxVersionConfig.wMinorBuildNumber
  299. );
  300. bstrVersion = SysAllocString (buffer);
  301. if (m_FaxVersionConfig.dwFlags & FAX_VER_FLAG_CHECKED)
  302. {
  303. if (!bstrChecked.LoadString(IDS_CHK))
  304. {
  305. DebugPrintEx(
  306. DEBUG_ERR,
  307. _T("Out of memory. Failed to load string."));
  308. m_pParentNode->NodeMsgBox(IDS_MEMORY);
  309. goto Exit;
  310. }
  311. bstrVersion += bstrChecked;
  312. }
  313. SetDlgItemText(IDC_VERSION_DTEXT, bstrVersion);
  314. //
  315. // Queue states
  316. //
  317. // submission
  318. if( m_dwQueueStates & FAX_OUTBOX_BLOCKED )
  319. {
  320. CheckDlgButton(IDC_SUBMISSION_CHECK, BST_CHECKED);
  321. }
  322. //transmission
  323. if( m_dwQueueStates & FAX_OUTBOX_PAUSED )
  324. {
  325. CheckDlgButton(IDC_TRANSSMI_CHECK, BST_CHECKED);
  326. }
  327. // reception
  328. if( m_dwQueueStates & FAX_INCOMING_BLOCKED )
  329. {
  330. CheckDlgButton(IDC_RECEPTION_CHECK, BST_CHECKED);
  331. }
  332. //
  333. // Activity
  334. //
  335. m_QueuedEdit.Attach( GetDlgItem(IDC_QUED_ROEDIT) );
  336. m_OutgoingEdit.Attach( GetDlgItem(IDC_OUTGOING_INPROC_ROEDIT) );
  337. m_IncomingEdit.Attach( GetDlgItem(IDC_INCOM_INPROC_ROEDIT) );
  338. hRc = UpdateActivityCounters();
  339. if (S_OK != hRc)
  340. {
  341. DebugPrintEx(
  342. DEBUG_ERR,
  343. _T("Failed to UpdateActivityCounters()"));
  344. goto Exit;
  345. }
  346. //
  347. // Register for Queue states changes notification
  348. //
  349. ATLASSERT(::IsWindow(m_hWnd));
  350. if (!m_hActivityNotification)
  351. {
  352. //
  353. // get RPC Handle
  354. //
  355. if (!m_pFaxServer->GetFaxServerHandle())
  356. {
  357. ec= GetLastError();
  358. DebugPrintEx(
  359. DEBUG_ERR,
  360. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  361. ec);
  362. goto Exit; //Error;
  363. }
  364. if (!FaxRegisterForServerEvents (
  365. m_pFaxServer->GetFaxServerHandle(),
  366. FAX_EVENT_TYPE_ACTIVITY,
  367. NULL,
  368. 0,
  369. m_hWnd,
  370. WM_ACTIVITY_STATUS_CHANGES,
  371. &m_hActivityNotification
  372. )
  373. )
  374. {
  375. ec = GetLastError();
  376. DebugPrintEx(
  377. DEBUG_ERR,
  378. _T("Fail to Register For Server Events (ec: %ld)"), ec);
  379. m_hActivityNotification = NULL;
  380. goto Exit;
  381. }
  382. }
  383. m_fIsDialogInitiated = TRUE;
  384. Exit:
  385. return(1);
  386. }
  387. /*
  388. - CFaxServerNode::OnActivityStatusChange
  389. -
  390. * Purpose:
  391. * Treats notifications about changes in Queue States.
  392. *
  393. * Arguments:
  394. *
  395. * Return:
  396. *
  397. */
  398. LRESULT CppFaxServerGeneral::OnActivityStatusChange( UINT uiMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled )
  399. {
  400. UNREFERENCED_PARAMETER( wParam );
  401. UNREFERENCED_PARAMETER( fHandled );
  402. DEBUG_FUNCTION_NAME( _T("CppFaxServerGeneral::OnActivityStatusChange"));
  403. HRESULT hRc = S_OK;
  404. ATLASSERT( uiMsg == WM_ACTIVITY_STATUS_CHANGES );
  405. PFAX_EVENT_EX pFaxEvent = NULL;
  406. pFaxEvent = reinterpret_cast<PFAX_EVENT_EX>(lParam);
  407. ATLASSERT( pFaxEvent );
  408. //
  409. // Updating the required fields
  410. //
  411. m_FaxServerActivityConfig.dwIncomingMessages = pFaxEvent->EventInfo.ActivityInfo.dwIncomingMessages;
  412. m_FaxServerActivityConfig.dwRoutingMessages = pFaxEvent->EventInfo.ActivityInfo.dwRoutingMessages;
  413. m_FaxServerActivityConfig.dwOutgoingMessages = pFaxEvent->EventInfo.ActivityInfo.dwOutgoingMessages;
  414. m_FaxServerActivityConfig.dwDelegatedOutgoingMessages =
  415. pFaxEvent->EventInfo.ActivityInfo.dwDelegatedOutgoingMessages;
  416. m_FaxServerActivityConfig.dwQueuedMessages = pFaxEvent->EventInfo.ActivityInfo.dwQueuedMessages;
  417. hRc = UpdateActivityCounters();
  418. if (S_OK != hRc)
  419. {
  420. DebugPrintEx(
  421. DEBUG_ERR,
  422. _T("Failed to UpdateActivityCounters()"));
  423. }
  424. if (pFaxEvent)
  425. {
  426. FaxFreeBuffer (pFaxEvent);
  427. pFaxEvent = NULL;
  428. }
  429. return(1);
  430. }
  431. /*
  432. - CFaxServerGeneral::SetProps
  433. -
  434. * Purpose:
  435. * Sets properties on apply.
  436. *
  437. * Arguments:
  438. * IN pCtrlFocus - focus pointer (int)
  439. *
  440. * Return:
  441. * OLE error code
  442. */
  443. HRESULT CppFaxServerGeneral::SetProps(int *pCtrlFocus)
  444. {
  445. DEBUG_FUNCTION_NAME( _T("CppFaxServerGeneral::SetProps"));
  446. HRESULT hRc = S_OK;
  447. DWORD ec = ERROR_SUCCESS;
  448. DWORD dwQueueStates;
  449. //
  450. // Collects Queue states
  451. //
  452. //init
  453. dwQueueStates = 0;
  454. //Submission
  455. if (IsDlgButtonChecked(IDC_SUBMISSION_CHECK) == BST_CHECKED)
  456. {
  457. dwQueueStates |= FAX_OUTBOX_BLOCKED;
  458. }
  459. //Transmission
  460. if (IsDlgButtonChecked(IDC_TRANSSMI_CHECK) == BST_CHECKED)
  461. {
  462. dwQueueStates |= FAX_OUTBOX_PAUSED;
  463. }
  464. //Reception
  465. if (IsDlgButtonChecked(IDC_RECEPTION_CHECK) == BST_CHECKED)
  466. {
  467. dwQueueStates |= FAX_INCOMING_BLOCKED;
  468. }
  469. //
  470. // Set Queue States through RPC call
  471. //
  472. if (!m_pFaxServer->GetFaxServerHandle())
  473. {
  474. ec= GetLastError();
  475. DebugPrintEx(
  476. DEBUG_ERR,
  477. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  478. ec);
  479. goto Error;
  480. }
  481. if (!FaxSetQueue(
  482. m_pFaxServer->GetFaxServerHandle(),
  483. dwQueueStates
  484. )
  485. )
  486. {
  487. ec = GetLastError();
  488. DebugPrintEx(
  489. DEBUG_ERR,
  490. _T("Fail to get Queue States configuration. (ec: %ld)"),
  491. ec);
  492. if (IsNetworkError(ec))
  493. {
  494. DebugPrintEx(
  495. DEBUG_ERR,
  496. _T("Network Error was found. (ec: %ld)"),
  497. ec);
  498. m_pFaxServer->Disconnect();
  499. }
  500. goto Error;
  501. }
  502. ATLASSERT(S_OK == hRc);
  503. m_fIsDirty = FALSE;
  504. goto Exit;
  505. Error:
  506. ATLASSERT(ERROR_SUCCESS != ec);
  507. hRc = HRESULT_FROM_WIN32(ec);
  508. PropSheet_SetCurSelByID( GetParent(), IDD);
  509. ATLASSERT(::IsWindow(m_hWnd));
  510. PageError(GetFaxServerErrorMsg(ec),m_hWnd);
  511. Exit:
  512. return(hRc);
  513. }
  514. /*
  515. - CFaxServerNode::PreApply
  516. -
  517. * Purpose:
  518. * Checks properties before apply.
  519. *
  520. * Arguments:
  521. *
  522. * Return:
  523. * OLE error code
  524. */
  525. HRESULT CppFaxServerGeneral::PreApply(int *pCtrlFocus)
  526. {
  527. return(S_OK);
  528. }
  529. /*
  530. - CppFaxServerGeneral::OnApply
  531. -
  532. * Purpose:
  533. * Calls PreApply and SetProp to Apply changes.
  534. *
  535. * Arguments:
  536. *
  537. * Return:
  538. * TRUE or FALSE
  539. */
  540. BOOL CppFaxServerGeneral::OnApply()
  541. {
  542. DEBUG_FUNCTION_NAME( _T("CppFaxServerInbox::OnApply"));
  543. HRESULT hRc = S_OK;
  544. int CtrlFocus = 0;
  545. if (!m_fIsDirty)
  546. {
  547. return TRUE;
  548. }
  549. hRc = SetProps(&CtrlFocus);
  550. if (FAILED(hRc))
  551. {
  552. //Error Msg by called func.
  553. if (CtrlFocus)
  554. {
  555. GotoDlgCtrl(GetDlgItem(CtrlFocus));
  556. }
  557. return FALSE;
  558. }
  559. else //(Succeeded(hRc))
  560. {
  561. return TRUE;
  562. }
  563. }
  564. /*
  565. - CppFaxServerGeneral::SetApplyButton
  566. -
  567. * Purpose:
  568. * set Apply buttom modified.
  569. *
  570. * Arguments:
  571. *
  572. * Return:
  573. * 1
  574. */
  575. LRESULT CppFaxServerGeneral::SetApplyButton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  576. {
  577. if (!m_fIsDialogInitiated) //event receieved in too early stage
  578. {
  579. return 0;
  580. }
  581. else
  582. {
  583. m_fIsDirty = TRUE;
  584. }
  585. SetModified(TRUE);
  586. bHandled = TRUE;
  587. return(1);
  588. }
  589. //////////////////////////////////////////////////////////////////////////////
  590. /*++
  591. CppFaxServerGeneral::OnHelpRequest
  592. This is called in response to the WM_HELP Notify
  593. message and to the WM_CONTEXTMENU Notify message.
  594. WM_HELP Notify message.
  595. This message is sent when the user presses F1 or <Shift>-F1
  596. over an item or when the user clicks on the ? icon and then
  597. presses the mouse over an item.
  598. WM_CONTEXTMENU Notify message.
  599. This message is sent when the user right clicks over an item
  600. and then clicks "What's this?"
  601. --*/
  602. /////////////////////////////////////////////////////////////////////////////
  603. LRESULT
  604. CppFaxServerGeneral::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  605. {
  606. DEBUG_FUNCTION_NAME(_T("CppFaxServerGeneral::OnHelpRequest"));
  607. switch (uMsg)
  608. {
  609. case WM_HELP:
  610. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  611. break;
  612. case WM_CONTEXTMENU:
  613. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  614. break;
  615. }
  616. return TRUE;
  617. }
  618. /////////////////////////////////////////////////////////////////////////////