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.

487 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : ppFaxServerEvents.cpp //
  3. // //
  4. // DESCRIPTION : prop pages of event reports policies //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Oct 25 1999 yossg created //
  10. // Nov 24 1999 yossg OnApply create call to all tabs from parent //
  11. // Oct 17 2000 yossg //
  12. // //
  13. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  14. // //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "stdafx.h"
  17. #include "MSFxsSnp.h"
  18. #include "ppFaxServerEvents.h"
  19. #include "FaxServer.h"
  20. #include "FaxServerNode.h"
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. //
  26. // Constructor
  27. //
  28. CppFaxServerEvents::CppFaxServerEvents(
  29. LONG_PTR hNotificationHandle,
  30. CSnapInItem *pNode,
  31. BOOL bOwnsNotificationHandle,
  32. HINSTANCE hInst)
  33. : CPropertyPageExImpl<CppFaxServerEvents>(pNode, NULL)
  34. {
  35. m_pParentNode = static_cast <CFaxServerNode *> (pNode);
  36. m_pFaxLogCategories = NULL;
  37. m_fIsDialogInitiated = FALSE;
  38. m_fIsDirty = FALSE;
  39. }
  40. //
  41. // Destructor
  42. //
  43. CppFaxServerEvents::~CppFaxServerEvents()
  44. {
  45. if (NULL != m_pFaxLogCategories)
  46. {
  47. FaxFreeBuffer( m_pFaxLogCategories);
  48. }
  49. }
  50. #define FXS_NUM_OF_CATEGORIES 4
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CppFaxServerEvents message handlers
  53. /*
  54. - CppFaxServerEvents::InitRPC
  55. -
  56. * Purpose:
  57. * Initiates the configuration structure from RPC get Call.
  58. *
  59. * Arguments:
  60. *
  61. * Return:
  62. * OLE error code
  63. */
  64. HRESULT CppFaxServerEvents::InitRPC( )
  65. {
  66. DEBUG_FUNCTION_NAME( _T("CppFaxServerEvents::InitRPC"));
  67. HRESULT hRc = S_OK;
  68. DWORD ec = ERROR_SUCCESS;
  69. DWORD dwNumCategories;
  70. //
  71. // get RPC Handle
  72. //
  73. if (!m_pFaxServer->GetFaxServerHandle())
  74. {
  75. ec= GetLastError();
  76. DebugPrintEx(
  77. DEBUG_ERR,
  78. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  79. ec);
  80. goto Error;
  81. }
  82. //
  83. // Retrieve the fax Event Reports /Logging Policy configuration
  84. //
  85. if (!FaxGetLoggingCategories(m_pFaxServer->GetFaxServerHandle(),
  86. &m_pFaxLogCategories,
  87. &dwNumCategories))
  88. {
  89. ec = GetLastError();
  90. DebugPrintEx(
  91. DEBUG_ERR,
  92. _T("Fail to get Logging Categories configuration. (ec: %ld)"),
  93. ec);
  94. if (IsNetworkError(ec))
  95. {
  96. DebugPrintEx(
  97. DEBUG_ERR,
  98. _T("Network Error was found. (ec: %ld)"),
  99. ec);
  100. m_pFaxServer->Disconnect();
  101. }
  102. goto Error;
  103. }
  104. // for max verification
  105. ATLASSERT(m_pFaxLogCategories);
  106. // internal assumeption in this version
  107. ATLASSERT( FXS_NUM_OF_CATEGORIES == dwNumCategories);
  108. ATLASSERT(S_OK == hRc);
  109. DebugPrintEx( DEBUG_MSG,
  110. _T("Succeed to get Logging Categories configuration."));
  111. goto Exit;
  112. Error:
  113. ATLASSERT(ERROR_SUCCESS != ec);
  114. hRc = HRESULT_FROM_WIN32(ec);
  115. ATLASSERT(NULL != m_pParentNode);
  116. m_pParentNode->NodeMsgBox(GetFaxServerErrorMsg(ec));
  117. Exit:
  118. return (hRc);
  119. }
  120. /*
  121. - CppFaxServerEvents::OnInitDialog
  122. -
  123. * Purpose:
  124. * Initiates all controls when dialog is called.
  125. *
  126. * Arguments:
  127. *
  128. * Return:
  129. *
  130. */
  131. LRESULT CppFaxServerEvents::OnInitDialog( UINT uiMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled )
  132. {
  133. DEBUG_FUNCTION_NAME( _T("CppFaxServerEvents::OnInitDialog"));
  134. UNREFERENCED_PARAMETER( uiMsg );
  135. UNREFERENCED_PARAMETER( wParam );
  136. UNREFERENCED_PARAMETER( lParam );
  137. UNREFERENCED_PARAMETER( fHandled );
  138. int iInboundLevel = 0,
  139. iOutboundLevel = 0,
  140. iInitLevel = 0,
  141. iGeneralLevel = 0;
  142. // Retrieve the Number of Categories
  143. const int iNumCategories = FXS_NUM_OF_CATEGORIES;
  144. int i; // index
  145. //
  146. // Attach Controls
  147. //
  148. m_InitErrSlider.Attach(GetDlgItem(IDC_SLIDER4));
  149. m_InboundErrSlider.Attach(GetDlgItem(IDC_SLIDER2));
  150. m_OutboundErrSlider.Attach(GetDlgItem(IDC_SLIDER3));
  151. m_GeneralErrSlider.Attach(GetDlgItem(IDC_SLIDER1));
  152. //
  153. // Init sliders
  154. //
  155. m_InboundErrSlider.SetRange(0,FXS_MAX_LOG_REPORT_LEVEL - 1,TRUE);
  156. m_OutboundErrSlider.SetRange(0,FXS_MAX_LOG_REPORT_LEVEL - 1,TRUE);
  157. m_InitErrSlider.SetRange(0,FXS_MAX_LOG_REPORT_LEVEL - 1,TRUE);
  158. m_GeneralErrSlider.SetRange(0,FXS_MAX_LOG_REPORT_LEVEL - 1,TRUE);
  159. //
  160. // Verify the Number of Categories is the same
  161. // as the code assumes (This version).
  162. // To avoid replacement of defined contant elsewhere
  163. //
  164. ATLASSERT (iNumCategories == 4);
  165. for (i = 0; i < iNumCategories; i++)
  166. {
  167. //for each category
  168. switch (m_pFaxLogCategories[i].Category)
  169. {
  170. case FAXLOG_CATEGORY_INIT:
  171. iInitLevel= m_pFaxLogCategories[i].Level;
  172. break;
  173. case FAXLOG_CATEGORY_OUTBOUND:
  174. iOutboundLevel= m_pFaxLogCategories[i].Level;
  175. break;
  176. case FAXLOG_CATEGORY_INBOUND:
  177. iInboundLevel= m_pFaxLogCategories[i].Level;
  178. break;
  179. case FAXLOG_CATEGORY_UNKNOWN:
  180. iGeneralLevel= m_pFaxLogCategories[i].Level;
  181. break;
  182. }
  183. }
  184. //
  185. // Init slider Positions
  186. //
  187. m_InboundErrSlider.SetPos(iInboundLevel);
  188. m_OutboundErrSlider.SetPos(iOutboundLevel);
  189. m_InitErrSlider.SetPos(iInitLevel);
  190. m_GeneralErrSlider.SetPos(iGeneralLevel);
  191. m_fIsDialogInitiated = TRUE;
  192. return 1;
  193. }
  194. /*
  195. - CppFaxServerEvents::SetProps
  196. -
  197. * Purpose:
  198. * Sets properties on apply.
  199. *
  200. * Arguments:
  201. * pCtrlFocus - focus pointer (int)
  202. *
  203. * Return:
  204. * OLE error code
  205. */
  206. HRESULT CppFaxServerEvents::SetProps(int *pCtrlFocus)
  207. {
  208. DEBUG_FUNCTION_NAME( _T("CppFaxServerEvents::SetProps"));
  209. HRESULT hRc = S_OK;
  210. DWORD ec = ERROR_SUCCESS;
  211. int iInboundErrPos,
  212. iOutboundErrPos,
  213. iInitErrPos,
  214. iGeneralErrPos;
  215. FAX_LOG_CATEGORY FaxLogCategories[FXS_NUM_OF_CATEGORIES] = {0};
  216. //
  217. // Our base assumption for this version
  218. //
  219. const int iNumCategories = FXS_NUM_OF_CATEGORIES;
  220. ATLASSERT (iNumCategories == 4);
  221. //
  222. // Collect All Slider Positions
  223. //
  224. iInitErrPos = m_InitErrSlider.GetPos();
  225. iInboundErrPos = m_InboundErrSlider.GetPos();
  226. iOutboundErrPos = m_OutboundErrSlider.GetPos();
  227. iGeneralErrPos = m_GeneralErrSlider.GetPos();
  228. //
  229. // Prepare all structure fields
  230. //
  231. // notice: legacy EnumLoggingChanges in the server's code depends on the order only!
  232. // our code indentifies the categories by their unique id number - the Category DWORD field
  233. //
  234. FaxLogCategories[0].Name = L"Initialization/Termination"; //NOT to be localized a registry info only
  235. FaxLogCategories[0].Category = FAXLOG_CATEGORY_INIT;
  236. FaxLogCategories[0].Level = (DWORD)iInitErrPos;
  237. FaxLogCategories[1].Name = L"Outbound"; //NOT to be localized a registry info only
  238. FaxLogCategories[1].Category = FAXLOG_CATEGORY_OUTBOUND;
  239. FaxLogCategories[1].Level = (DWORD)iOutboundErrPos;
  240. FaxLogCategories[2].Name = L"Inbound"; //NOT to be localized a registry info only
  241. FaxLogCategories[2].Category = FAXLOG_CATEGORY_INBOUND;;
  242. FaxLogCategories[2].Level = (DWORD)iInboundErrPos;
  243. FaxLogCategories[3].Name = L"Unknown"; //NOT to be localized a registry info only
  244. FaxLogCategories[3].Category = FAXLOG_CATEGORY_UNKNOWN;
  245. FaxLogCategories[3].Level = (DWORD)iGeneralErrPos;
  246. //
  247. // get RPC Handle
  248. //
  249. if (!m_pFaxServer->GetFaxServerHandle())
  250. {
  251. ec= GetLastError();
  252. DebugPrintEx(
  253. DEBUG_ERR,
  254. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  255. ec);
  256. goto Error;
  257. }
  258. //
  259. // Set Config
  260. //
  261. if (!FaxSetLoggingCategories(
  262. m_pFaxServer->GetFaxServerHandle(),
  263. FaxLogCategories,
  264. (DWORD)iNumCategories))
  265. {
  266. ec = GetLastError();
  267. DebugPrintEx(
  268. DEBUG_ERR,
  269. _T("Fail to Set Logging Categories. (ec: %ld)"),
  270. ec);
  271. if (IsNetworkError(ec))
  272. {
  273. DebugPrintEx(
  274. DEBUG_ERR,
  275. _T("Network Error was found. (ec: %ld)"),
  276. ec);
  277. m_pFaxServer->Disconnect();
  278. }
  279. goto Error;
  280. }
  281. ATLASSERT(S_OK == hRc);
  282. m_fIsDirty = FALSE;
  283. DebugPrintEx( DEBUG_MSG,
  284. _T("Succeed to set Logging Categories configuration."));
  285. goto Exit;
  286. Error:
  287. ATLASSERT(ERROR_SUCCESS != ec);
  288. hRc = HRESULT_FROM_WIN32(ec);
  289. PropSheet_SetCurSelByID( GetParent(), IDD);
  290. ATLASSERT(::IsWindow(m_hWnd));
  291. PageError(GetFaxServerErrorMsg(ec),m_hWnd);
  292. Exit:
  293. return(hRc);
  294. }
  295. /*
  296. - CppFaxServerEvents::PreApply
  297. -
  298. * Purpose:
  299. * Checks properties before apply.
  300. *
  301. * Arguments:
  302. *
  303. * Return:
  304. * OLE error code
  305. */
  306. HRESULT CppFaxServerEvents::PreApply(int *pCtrlFocus)
  307. {
  308. return(S_OK);
  309. }
  310. /*
  311. - CppFaxServerEvents::OnApply
  312. -
  313. * Purpose:
  314. * Calls PreApply and SetProp to Apply changes.
  315. *
  316. * Arguments:
  317. *
  318. * Return:
  319. * TRUE or FALSE
  320. */
  321. BOOL CppFaxServerEvents::OnApply()
  322. {
  323. DEBUG_FUNCTION_NAME( _T("CppFaxServerEvents::OnApply"));
  324. HRESULT hRc = S_OK;
  325. int CtrlFocus = 0;
  326. if (!m_fIsDirty)
  327. {
  328. return TRUE;
  329. }
  330. hRc = SetProps(&CtrlFocus);
  331. if (FAILED(hRc))
  332. {
  333. //Error Msg by called func.
  334. if (CtrlFocus)
  335. {
  336. GotoDlgCtrl(GetDlgItem(CtrlFocus));
  337. }
  338. return FALSE;
  339. }
  340. else //(Succeeded(hRc))
  341. {
  342. return TRUE;
  343. }
  344. }
  345. /*
  346. - CppFaxServerEvents::SliderMoved
  347. -
  348. * Purpose:
  349. * set Apply buttom modified.
  350. * Arguments:
  351. * IN pParentNode - parent node pointer
  352. *
  353. * Return:
  354. * none
  355. */
  356. LRESULT CppFaxServerEvents::SliderMoved ( UINT uiMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled)
  357. {
  358. if (!m_fIsDialogInitiated) //event receieved in too early stage
  359. {
  360. return 0;
  361. }
  362. else
  363. {
  364. m_fIsDirty = TRUE;
  365. }
  366. SetModified(TRUE);
  367. fHandled = TRUE;
  368. return(1);
  369. }
  370. //////////////////////////////////////////////////////////////////////////////
  371. /*++
  372. CppFaxServerEvents::OnHelpRequest
  373. This is called in response to the WM_HELP Notify
  374. message and to the WM_CONTEXTMENU Notify message.
  375. WM_HELP Notify message.
  376. This message is sent when the user presses F1 or <Shift>-F1
  377. over an item or when the user clicks on the ? icon and then
  378. presses the mouse over an item.
  379. WM_CONTEXTMENU Notify message.
  380. This message is sent when the user right clicks over an item
  381. and then clicks "What's this?"
  382. --*/
  383. /////////////////////////////////////////////////////////////////////////////
  384. LRESULT
  385. CppFaxServerEvents::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  386. {
  387. DEBUG_FUNCTION_NAME(_T("CppFaxServerEvents::OnHelpRequest"));
  388. switch (uMsg)
  389. {
  390. case WM_HELP:
  391. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  392. break;
  393. case WM_CONTEXTMENU:
  394. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  395. break;
  396. }
  397. return TRUE;
  398. }
  399. /////////////////////////////////////////////////////////////////////////////