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.

531 lines
12 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxEventLogging.cpp
  5. Abstract:
  6. Implementation of Event Logging Class.
  7. Author:
  8. Iv Garber (IvG) Jun, 2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "FaxComEx.h"
  13. #include "FaxEventLogging.h"
  14. //
  15. //================= PUT LEVEL =======================================
  16. //
  17. STDMETHODIMP
  18. CFaxEventLogging::PutLevel(
  19. FAX_ENUM_LOG_CATEGORIES faxCategory,
  20. FAX_LOG_LEVEL_ENUM faxLevel
  21. )
  22. /*++
  23. Routine name : CFaxEventLogging::PutLevel
  24. Routine description:
  25. Set the Level of given Category.
  26. Author:
  27. Iv Garber (IvG), Jun, 2000
  28. Arguments:
  29. faxCategory [in] - the Category for which level is desired.
  30. faxLevel [in] - the result : level of the given category
  31. Return Value:
  32. Standard HRESULT code
  33. --*/
  34. {
  35. HRESULT hr = S_OK;
  36. DBG_ENTER(_T("CFaxEventLogging::PutLevel"), hr, _T("Category : %d"), faxCategory);
  37. //
  38. // check the range
  39. //
  40. if (faxLevel > fllMAX || faxLevel < fllNONE)
  41. {
  42. //
  43. // Out of range
  44. //
  45. hr = E_INVALIDARG;
  46. AtlReportError(CLSID_FaxEventLogging,
  47. IDS_ERROR_OUTOFRANGE,
  48. IID_IFaxEventLogging,
  49. hr);
  50. CALL_FAIL(GENERAL_ERR, _T("Level is out of range"), hr);
  51. return hr;
  52. }
  53. //
  54. // Sync with the Server for the first time
  55. //
  56. if (!m_bInited)
  57. {
  58. hr = Refresh();
  59. if (FAILED(hr))
  60. {
  61. return hr;
  62. }
  63. }
  64. switch(faxCategory)
  65. {
  66. case FAXLOG_CATEGORY_INIT:
  67. m_InitLevel = faxLevel;
  68. break;
  69. case FAXLOG_CATEGORY_OUTBOUND:
  70. m_OutboundLevel = faxLevel;
  71. break;
  72. case FAXLOG_CATEGORY_INBOUND:
  73. m_InboundLevel = faxLevel;
  74. break;
  75. default:
  76. m_GeneralLevel = faxLevel;
  77. break;
  78. }
  79. return hr;
  80. }
  81. //
  82. //================= GET LEVEL =======================================
  83. //
  84. STDMETHODIMP
  85. CFaxEventLogging::GetLevel(
  86. FAX_ENUM_LOG_CATEGORIES faxCategory,
  87. FAX_LOG_LEVEL_ENUM *pLevel
  88. )
  89. /*++
  90. Routine name : CFaxEventLogging::GetLevel
  91. Routine description:
  92. Return current Level of given Category.
  93. Author:
  94. Iv Garber (IvG), Jun, 2000
  95. Arguments:
  96. faxCategory [in] - the Category for which level is desired.
  97. pLevel [out] - the result : level of the given category
  98. Return Value:
  99. Standard HRESULT code
  100. --*/
  101. {
  102. HRESULT hr = S_OK;
  103. DBG_ENTER(_T("CFaxEventLogging::GetLevel"), hr, _T("Category : %d"), faxCategory);
  104. //
  105. // Check that we have a good pointer
  106. //
  107. if (::IsBadWritePtr(pLevel, sizeof(FAX_LOG_LEVEL_ENUM)))
  108. {
  109. //
  110. // Got Bad Return Pointer
  111. //
  112. hr = E_POINTER;
  113. AtlReportError(CLSID_FaxEventLogging,
  114. IDS_ERROR_INVALID_ARGUMENT,
  115. IID_IFaxEventLogging,
  116. hr);
  117. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr(pLevel, sizeof(FAX_LOG_LEVEL_ENUM))"), hr);
  118. return hr;
  119. }
  120. //
  121. // Sync with the Server for the first time
  122. //
  123. if (!m_bInited)
  124. {
  125. hr = Refresh();
  126. if (FAILED(hr))
  127. {
  128. return hr;
  129. }
  130. }
  131. switch(faxCategory)
  132. {
  133. case FAXLOG_CATEGORY_INIT:
  134. *pLevel = m_InitLevel;
  135. break;
  136. case FAXLOG_CATEGORY_OUTBOUND:
  137. *pLevel = m_OutboundLevel;
  138. break;
  139. case FAXLOG_CATEGORY_INBOUND:
  140. *pLevel = m_InboundLevel;
  141. break;
  142. default:
  143. *pLevel = m_GeneralLevel;
  144. break;
  145. }
  146. return hr;
  147. }
  148. //
  149. //====================== PUT INIT EVENTS LEVEL ======================================
  150. //
  151. STDMETHODIMP
  152. CFaxEventLogging::put_InitEventsLevel(
  153. /*[out, retval]*/ FAX_LOG_LEVEL_ENUM InitEventLevel
  154. )
  155. {
  156. HRESULT hr = S_OK;
  157. DBG_ENTER(_T("CFaxEventLogging::put_InitEventsLogging"), hr, _T("Level=%d"), InitEventLevel);
  158. hr = PutLevel(FAXLOG_CATEGORY_INIT, InitEventLevel);
  159. return hr;
  160. }
  161. //
  162. //====================== PUT INBOUND EVENTS LEVEL ======================================
  163. //
  164. STDMETHODIMP
  165. CFaxEventLogging::put_InboundEventsLevel(
  166. /*[out, retval]*/ FAX_LOG_LEVEL_ENUM InboundEventLevel
  167. )
  168. {
  169. HRESULT hr = S_OK;
  170. DBG_ENTER(_T("CFaxEventLogging::put_InboundEventsLogging"), hr, _T("Level=%d"), InboundEventLevel);
  171. hr = PutLevel(FAXLOG_CATEGORY_INBOUND, InboundEventLevel);
  172. return hr;
  173. }
  174. //
  175. //====================== PUT OUTBOUND EVENTS LEVEL ======================================
  176. //
  177. STDMETHODIMP
  178. CFaxEventLogging::put_OutboundEventsLevel(
  179. /*[out, retval]*/ FAX_LOG_LEVEL_ENUM OutboundEventLevel
  180. )
  181. {
  182. HRESULT hr = S_OK;
  183. DBG_ENTER(_T("CFaxEventLogging::put_OutboundEventsLogging"), hr, _T("Level=%d"), OutboundEventLevel);
  184. hr = PutLevel(FAXLOG_CATEGORY_OUTBOUND, OutboundEventLevel);
  185. return hr;
  186. }
  187. //
  188. //====================== PUT GENERAL EVENTS LEVEL ======================================
  189. //
  190. STDMETHODIMP
  191. CFaxEventLogging::put_GeneralEventsLevel(
  192. /*[out, retval]*/ FAX_LOG_LEVEL_ENUM GeneralEventLevel
  193. )
  194. {
  195. HRESULT hr = S_OK;
  196. DBG_ENTER(_T("CFaxEventLogging::put_GeneralEventsLogging"), hr, _T("Level=%d"), GeneralEventLevel);
  197. hr = PutLevel(FAXLOG_CATEGORY_UNKNOWN, GeneralEventLevel);
  198. return hr;
  199. }
  200. //
  201. //====================== GET_INIT EVENTS LEVEL ======================================
  202. //
  203. STDMETHODIMP
  204. CFaxEventLogging::get_InitEventsLevel(
  205. /*[out, retval]*/ FAX_LOG_LEVEL_ENUM *pInitEventLevel
  206. )
  207. {
  208. HRESULT hr = S_OK;
  209. DBG_ENTER(_T("CFaxEventLogging::get_InitEventsLogging"), hr);
  210. hr = GetLevel(FAXLOG_CATEGORY_INIT, pInitEventLevel);
  211. return hr;
  212. }
  213. //
  214. //====================== GET INBOUND EVENTS LEVEL ======================================
  215. //
  216. STDMETHODIMP
  217. CFaxEventLogging::get_InboundEventsLevel(
  218. /*[out, retval]*/ FAX_LOG_LEVEL_ENUM *pInboundEventLevel
  219. )
  220. {
  221. HRESULT hr = S_OK;
  222. DBG_ENTER(_T("CFaxEventLogging::get_InboundEventsLogging"), hr);
  223. hr = GetLevel(FAXLOG_CATEGORY_INBOUND, pInboundEventLevel);
  224. return hr;
  225. }
  226. //
  227. //====================== GET OUTBOUND EVENTS LEVEL ======================================
  228. //
  229. STDMETHODIMP
  230. CFaxEventLogging::get_OutboundEventsLevel(
  231. /*[out, retval]*/ FAX_LOG_LEVEL_ENUM *pOutboundEventLevel
  232. )
  233. {
  234. HRESULT hr = S_OK;
  235. DBG_ENTER(_T("CFaxEventLogging::get_OutboundEventsLogging"), hr);
  236. hr = GetLevel(FAXLOG_CATEGORY_OUTBOUND, pOutboundEventLevel);
  237. return hr;
  238. }
  239. //
  240. //====================== GET GENERAL EVENTS LEVEL ======================================
  241. //
  242. STDMETHODIMP
  243. CFaxEventLogging::get_GeneralEventsLevel(
  244. /*[out, retval]*/ FAX_LOG_LEVEL_ENUM *pGeneralEventLevel
  245. )
  246. {
  247. HRESULT hr = S_OK;
  248. DBG_ENTER(_T("CFaxEventLogging::get_GeneralEventsLogging"), hr);
  249. hr = GetLevel(FAXLOG_CATEGORY_UNKNOWN, pGeneralEventLevel);
  250. return hr;
  251. }
  252. //
  253. //================== SAVE ===============================================================
  254. //
  255. STDMETHODIMP
  256. CFaxEventLogging::Save()
  257. /*++
  258. Routine name : CFaxEventLogging::Save
  259. Routine description:
  260. Save the Object's contents : bring its current logging categories settings to the Server.
  261. Author:
  262. Iv Garber (IvG), Jun, 2000
  263. Arguments:
  264. Return Value:
  265. Standard HRESULT code
  266. --*/
  267. {
  268. HRESULT hr = S_OK;
  269. DBG_ENTER(_T("CFaxEventLogging::Save"), hr);
  270. if (!m_bInited)
  271. {
  272. //
  273. // No changes
  274. //
  275. return hr;
  276. }
  277. //
  278. // Get Fax Server Handle
  279. //
  280. HANDLE hFaxHandle = NULL;
  281. hr = GetFaxHandle(&hFaxHandle);
  282. if (FAILED(hr))
  283. {
  284. AtlReportError(CLSID_FaxEventLogging,
  285. GetErrorMsgId(hr),
  286. IID_IFaxEventLogging,
  287. hr);
  288. return hr;
  289. }
  290. DWORD dwNum = 4;
  291. FAX_LOG_CATEGORY faxCategories[4];
  292. faxCategories[0].Category = FAXLOG_CATEGORY_INIT;
  293. faxCategories[0].Name = m_bstrInitName;
  294. faxCategories[0].Level = FAX_ENUM_LOG_LEVELS(m_InitLevel);
  295. faxCategories[1].Category = FAXLOG_CATEGORY_INBOUND;
  296. faxCategories[1].Name = m_bstrInboundName;
  297. faxCategories[1].Level = FAX_ENUM_LOG_LEVELS(m_InboundLevel);
  298. faxCategories[2].Category = FAXLOG_CATEGORY_OUTBOUND;
  299. faxCategories[2].Name = m_bstrOutboundName;
  300. faxCategories[2].Level = FAX_ENUM_LOG_LEVELS(m_OutboundLevel);
  301. faxCategories[3].Category = FAXLOG_CATEGORY_UNKNOWN;
  302. faxCategories[3].Name = m_bstrGeneralName;
  303. faxCategories[3].Level = FAX_ENUM_LOG_LEVELS(m_GeneralLevel);
  304. //
  305. // Store out setting at the Server
  306. //
  307. if (!FaxSetLoggingCategories(hFaxHandle, faxCategories, dwNum))
  308. {
  309. //
  310. // Failed to put the Logging Categories to the Server
  311. //
  312. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  313. AtlReportError(CLSID_FaxEventLogging,
  314. GetErrorMsgId(hr),
  315. IID_IFaxEventLogging,
  316. hr);
  317. CALL_FAIL(GENERAL_ERR, _T("FaxSetLoggingCategories(hFaxHandle, faxCategories, dwNum)"), hr);
  318. return hr;
  319. }
  320. return hr;
  321. }
  322. //
  323. //================== REFRESH ===========================================
  324. //
  325. STDMETHODIMP
  326. CFaxEventLogging::Refresh()
  327. /*++
  328. Routine name : CFaxEventLogging::Refresh
  329. Routine description:
  330. Refresh the Object's contents : bring new logging categories settings from the Server.
  331. Author:
  332. Iv Garber (IvG), Jun, 2000
  333. Arguments:
  334. Return Value:
  335. Standard HRESULT code
  336. --*/
  337. {
  338. HRESULT hr = S_OK;
  339. DBG_ENTER(_T("CFaxEventLogging::Refresh"), hr);
  340. //
  341. // Get Fax Server Handle
  342. //
  343. HANDLE hFaxHandle = NULL;
  344. hr = GetFaxHandle(&hFaxHandle);
  345. if (FAILED(hr))
  346. {
  347. AtlReportError(CLSID_FaxEventLogging,
  348. GetErrorMsgId(hr),
  349. IID_IFaxEventLogging,
  350. hr);
  351. return hr;
  352. }
  353. //
  354. // Ask the Server for the Logging Settings
  355. //
  356. DWORD dwNum;
  357. CFaxPtr<FAX_LOG_CATEGORY> pLogCategory;
  358. if (!FaxGetLoggingCategories(hFaxHandle, &pLogCategory, &dwNum))
  359. {
  360. //
  361. // Failed to get the Logging Categories from the Server
  362. //
  363. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  364. AtlReportError(CLSID_FaxEventLogging,
  365. GetErrorMsgId(hr),
  366. IID_IFaxEventLogging,
  367. hr);
  368. CALL_FAIL(GENERAL_ERR, _T("FaxGetLoggingCategories(hFaxHandle, &pLogCategory, &dwNum)"), hr);
  369. return hr;
  370. }
  371. //
  372. // must be 4 categories
  373. //
  374. ATLASSERT(dwNum == 4);
  375. for (DWORD i=0; i<dwNum; i++)
  376. {
  377. switch(pLogCategory[i].Category)
  378. {
  379. case FAXLOG_CATEGORY_INIT:
  380. m_bstrInitName = pLogCategory[i].Name;
  381. m_InitLevel = FAX_LOG_LEVEL_ENUM(pLogCategory[i].Level);
  382. break;
  383. case FAXLOG_CATEGORY_OUTBOUND:
  384. m_bstrOutboundName = pLogCategory[i].Name;
  385. m_OutboundLevel = FAX_LOG_LEVEL_ENUM(pLogCategory[i].Level);
  386. break;
  387. case FAXLOG_CATEGORY_INBOUND:
  388. m_bstrInboundName = pLogCategory[i].Name;
  389. m_InboundLevel = FAX_LOG_LEVEL_ENUM(pLogCategory[i].Level);
  390. break;
  391. case FAXLOG_CATEGORY_UNKNOWN:
  392. m_bstrGeneralName = pLogCategory[i].Name;
  393. m_GeneralLevel = FAX_LOG_LEVEL_ENUM(pLogCategory[i].Level);
  394. break;
  395. default:
  396. //
  397. // ASSERT(FALSE)
  398. //
  399. ATLASSERT(pLogCategory[i].Category == FAXLOG_CATEGORY_INIT);
  400. break;
  401. }
  402. }
  403. m_bInited = true;
  404. return hr;
  405. }
  406. //
  407. //================== SUPPORT ERROR INFO =====================================
  408. //
  409. STDMETHODIMP
  410. CFaxEventLogging::InterfaceSupportsErrorInfo(
  411. REFIID riid
  412. )
  413. /*++
  414. Routine name : CFaxEventLogging::InterfaceSupportsErrorInfo
  415. Routine description:
  416. ATL's implementation of Support Error Info.
  417. Author:
  418. Iv Garber (IvG), Jun, 2000
  419. Arguments:
  420. riid [in] - Reference to the IID
  421. Return Value:
  422. Standard HRESULT code
  423. --*/
  424. {
  425. static const IID* arr[] =
  426. {
  427. &IID_IFaxEventLogging
  428. };
  429. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  430. {
  431. if (InlineIsEqualGUID(*arr[i],riid))
  432. return S_OK;
  433. }
  434. return S_FALSE;
  435. }