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.

552 lines
11 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxActivityLogging.cpp
  5. Abstract:
  6. Implementation of Activity Logging Class.
  7. Author:
  8. Iv Garber (IvG) Jun, 2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "FaxComEx.h"
  13. #include "FaxActivityLogging.h"
  14. //
  15. //==================== SAVE ========================================
  16. //
  17. STDMETHODIMP
  18. CFaxActivityLogging::Save(
  19. )
  20. /*++
  21. Routine name : CFaxActivityLogging::Save
  22. Routine description:
  23. Save current Activity Logging Configuration to the Server.
  24. Author:
  25. Iv Garber (IvG), June, 2000
  26. Return Value:
  27. Standard HRESULT code
  28. --*/
  29. {
  30. HRESULT hr = S_OK;
  31. DBG_ENTER(_T("CFaxActivityLogging::Save"), hr);
  32. if (!m_bInited)
  33. {
  34. //
  35. // nothing was done to the Configuration
  36. //
  37. return hr;
  38. }
  39. //
  40. // Get Fax Server Handle
  41. //
  42. HANDLE hFaxHandle = NULL;
  43. hr = GetFaxHandle(&hFaxHandle);
  44. if (FAILED(hr))
  45. {
  46. AtlReportError(CLSID_FaxActivityLogging,
  47. GetErrorMsgId(hr),
  48. IID_IFaxActivityLogging,
  49. hr);
  50. return hr;
  51. }
  52. //
  53. // Create Activity Logging Configuration
  54. //
  55. FAX_ACTIVITY_LOGGING_CONFIG alConfig;
  56. alConfig.dwSizeOfStruct = sizeof(FAX_ACTIVITY_LOGGING_CONFIG);
  57. alConfig.bLogIncoming = VARIANT_BOOL2bool(m_bLogIncoming);
  58. alConfig.bLogOutgoing = VARIANT_BOOL2bool(m_bLogOutgoing);
  59. alConfig.lptstrDBPath = m_bstrDatabasePath;
  60. //
  61. // Ask the Server to set the Activity Configuration
  62. //
  63. if (!FaxSetActivityLoggingConfiguration(hFaxHandle, &alConfig))
  64. {
  65. //
  66. // Failed to set the Configuration to the Server
  67. //
  68. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  69. AtlReportError(CLSID_FaxActivityLogging,
  70. GetErrorMsgId(hr),
  71. IID_IFaxActivityLogging,
  72. hr);
  73. CALL_FAIL(GENERAL_ERR, _T("FaxSetActivityLoggingConfiguration()"), hr);
  74. return hr;
  75. }
  76. return hr;
  77. }
  78. //
  79. //==================== REFRESH ========================================
  80. //
  81. STDMETHODIMP
  82. CFaxActivityLogging::Refresh(
  83. )
  84. /*++
  85. Routine name : CFaxActivityLogging::Refresh
  86. Routine description:
  87. Bring new Activity Logging cofiguration from the Server.
  88. Author:
  89. Iv Garber (IvG), June, 2000
  90. Return Value:
  91. Standard HRESULT code
  92. --*/
  93. {
  94. HRESULT hr = S_OK;
  95. DBG_ENTER(_T("CFaxActivityLogging::Refresh"), hr);
  96. //
  97. // Get Fax Server Handle
  98. //
  99. HANDLE hFaxHandle = NULL;
  100. hr = GetFaxHandle(&hFaxHandle);
  101. if (FAILED(hr))
  102. {
  103. AtlReportError(CLSID_FaxActivityLogging,
  104. GetErrorMsgId(hr),
  105. IID_IFaxActivityLogging,
  106. hr);
  107. return hr;
  108. }
  109. //
  110. // Ask the Server for the Mail Configuration
  111. //
  112. CFaxPtr<FAX_ACTIVITY_LOGGING_CONFIG> pConfig;
  113. if (!FaxGetActivityLoggingConfiguration(hFaxHandle, &pConfig))
  114. {
  115. //
  116. // Failed to get the Configuration from the Server
  117. //
  118. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  119. AtlReportError(CLSID_FaxActivityLogging,
  120. GetErrorMsgId(hr),
  121. IID_IFaxActivityLogging,
  122. hr);
  123. CALL_FAIL(GENERAL_ERR, _T("FaxGetActivityLoggingConfiguration()"), hr);
  124. return hr;
  125. }
  126. //
  127. // Check that pConfig is valid
  128. //
  129. if (!pConfig || pConfig->dwSizeOfStruct != sizeof(FAX_ACTIVITY_LOGGING_CONFIG))
  130. {
  131. hr = E_FAIL;
  132. AtlReportError(CLSID_FaxActivityLogging,
  133. GetErrorMsgId(hr),
  134. IID_IFaxActivityLogging,
  135. hr);
  136. CALL_FAIL(GENERAL_ERR, _T("(!pConfig || SizeOfStruct != sizeof(FAX_ACTIVITY_LOGGING_CONFIG))"), hr);
  137. return hr;
  138. }
  139. m_bLogIncoming = bool2VARIANT_BOOL(pConfig->bLogIncoming);
  140. m_bLogOutgoing = bool2VARIANT_BOOL(pConfig->bLogOutgoing);
  141. m_bstrDatabasePath = pConfig->lptstrDBPath;
  142. if ( (pConfig->lptstrDBPath) && !m_bstrDatabasePath )
  143. {
  144. //
  145. // Failed to Copy
  146. //
  147. hr = E_OUTOFMEMORY;
  148. AtlReportError(CLSID_FaxActivityLogging,
  149. IDS_ERROR_OUTOFMEMORY,
  150. IID_IFaxActivityLogging,
  151. hr);
  152. CALL_FAIL(MEM_ERR, _T("::SysAllocString()"), hr);
  153. return hr;
  154. }
  155. m_bInited = true;
  156. return hr;
  157. }
  158. //
  159. //============================= DATABASE PATH ====================================
  160. //
  161. STDMETHODIMP
  162. CFaxActivityLogging::put_DatabasePath(
  163. BSTR bstrDatabasePath
  164. )
  165. /*++
  166. Routine name : CFaxActivityLogging::put_DatabasePath
  167. Routine description:
  168. Set the Database Path
  169. Author:
  170. Iv Garber (IvG), June, 2000
  171. Arguments:
  172. bstrDatabasePath [in] - the new value of Database Path
  173. Return Value:
  174. Standard HRESULT code
  175. --*/
  176. {
  177. HRESULT hr = S_OK;
  178. DBG_ENTER (_T("CFaxActivityLogging::put_DatabasePath"), hr, _T("%s"), bstrDatabasePath);
  179. //
  180. // Sync with the Server for the first time
  181. //
  182. if (!m_bInited)
  183. {
  184. hr = Refresh();
  185. if (FAILED(hr))
  186. {
  187. return hr;
  188. }
  189. }
  190. m_bstrDatabasePath = bstrDatabasePath;
  191. if (bstrDatabasePath && !m_bstrDatabasePath)
  192. {
  193. //
  194. // not enough memory
  195. //
  196. hr = E_OUTOFMEMORY;
  197. AtlReportError(CLSID_FaxActivityLogging,
  198. IDS_ERROR_OUTOFMEMORY,
  199. IID_IFaxActivityLogging,
  200. hr);
  201. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator=()"), hr);
  202. return hr;
  203. }
  204. return hr;
  205. }
  206. STDMETHODIMP
  207. CFaxActivityLogging::get_DatabasePath(
  208. BSTR *pbstrDatabasePath
  209. )
  210. /*++
  211. Routine name : CFaxActivityLogging::get_DatabasePath
  212. Routine description:
  213. Return current Database Path
  214. Author:
  215. Iv Garber (IvG), June, 2000
  216. Arguments:
  217. pbstrDatabasePath [out] - the current Database Path
  218. Return Value:
  219. Standard HRESULT code
  220. --*/
  221. {
  222. HRESULT hr = S_OK;
  223. DBG_ENTER (TEXT("CFaxActivityLogging::get_DatabasePath"), hr);
  224. //
  225. // Sync with the Server for the first time
  226. //
  227. if (!m_bInited)
  228. {
  229. hr = Refresh();
  230. if (FAILED(hr))
  231. {
  232. return hr;
  233. }
  234. }
  235. hr = GetBstr(pbstrDatabasePath, m_bstrDatabasePath);
  236. if (FAILED(hr))
  237. {
  238. AtlReportError(CLSID_FaxActivityLogging, GetErrorMsgId(hr), IID_IFaxActivityLogging, hr);
  239. return hr;
  240. }
  241. return hr;
  242. }
  243. //
  244. //===================== LOG OUTGOING ======================================
  245. //
  246. STDMETHODIMP
  247. CFaxActivityLogging::get_LogOutgoing(
  248. VARIANT_BOOL *pbLogOutgoing
  249. )
  250. /*++
  251. Routine name : CFaxActivityLogging::get_LogOutgoing
  252. Routine description:
  253. Return Log Incoming value
  254. Author:
  255. Iv Garber (IvG), Jun, 2000
  256. Arguments:
  257. pbLogOutgoing [out] - the value of the Log Incoming to return
  258. Return Value:
  259. Standard HRESULT code
  260. --*/
  261. {
  262. HRESULT hr = S_OK;
  263. DBG_ENTER(_T("CFaxActivityLogging::get_LogOutgoing"), hr);
  264. //
  265. // Sync with the Server for the first time
  266. //
  267. if (!m_bInited)
  268. {
  269. hr = Refresh();
  270. if (FAILED(hr))
  271. {
  272. return hr;
  273. }
  274. }
  275. hr = GetVariantBool(pbLogOutgoing, m_bLogOutgoing);
  276. if (FAILED(hr))
  277. if (FAILED(hr))
  278. {
  279. AtlReportError(CLSID_FaxActivityLogging, GetErrorMsgId(hr), IID_IFaxActivityLogging, hr);
  280. return hr;
  281. }
  282. return hr;
  283. }
  284. STDMETHODIMP
  285. CFaxActivityLogging::put_LogOutgoing(
  286. VARIANT_BOOL bLogOutgoing
  287. )
  288. /*++
  289. Routine name : CFaxActivityLogging::put_LogOutgoing
  290. Routine description:
  291. Set new Log Incoming value
  292. Author:
  293. Iv Garber (IvG), Jun, 2000
  294. Arguments:
  295. bLogOutgoing [in] - the value of the Log Incoming to set
  296. Return Value:
  297. Standard HRESULT code
  298. --*/
  299. {
  300. HRESULT hr = S_OK;
  301. DBG_ENTER(_T("CFaxActivityLogging::put_LogOutgoing"), hr, _T("Log Incoming : %d"), bLogOutgoing);
  302. //
  303. // Sync with the Server for the first time
  304. //
  305. if (!m_bInited)
  306. {
  307. hr = Refresh();
  308. if (FAILED(hr))
  309. {
  310. return hr;
  311. }
  312. }
  313. m_bLogOutgoing = bLogOutgoing;
  314. return hr;
  315. }
  316. //
  317. //===================== LOG INCOMING ======================================
  318. //
  319. STDMETHODIMP
  320. CFaxActivityLogging::get_LogIncoming(
  321. VARIANT_BOOL *pbLogIncoming
  322. )
  323. /*++
  324. Routine name : CFaxActivityLogging::get_LogIncoming
  325. Routine description:
  326. Return Log Incoming value
  327. Author:
  328. Iv Garber (IvG), Jun, 2000
  329. Arguments:
  330. pbLogIncoming [out] - the value of the Log Incoming to return
  331. Return Value:
  332. Standard HRESULT code
  333. --*/
  334. {
  335. HRESULT hr = S_OK;
  336. DBG_ENTER(_T("CFaxActivityLogging::get_LogIncoming"), hr);
  337. //
  338. // Sync with the Server for the first time
  339. //
  340. if (!m_bInited)
  341. {
  342. hr = Refresh();
  343. if (FAILED(hr))
  344. {
  345. return hr;
  346. }
  347. }
  348. hr = GetVariantBool(pbLogIncoming, m_bLogIncoming);
  349. if (FAILED(hr))
  350. {
  351. AtlReportError(CLSID_FaxActivityLogging, GetErrorMsgId(hr), IID_IFaxActivityLogging, hr);
  352. return hr;
  353. }
  354. return hr;
  355. }
  356. STDMETHODIMP
  357. CFaxActivityLogging::put_LogIncoming(
  358. VARIANT_BOOL bLogIncoming
  359. )
  360. /*++
  361. Routine name : CFaxActivityLogging::put_LogIncoming
  362. Routine description:
  363. Set new Log Incoming value
  364. Author:
  365. Iv Garber (IvG), Jun, 2000
  366. Arguments:
  367. bLogIncoming [in] - the value of the Log Incoming to set
  368. Return Value:
  369. Standard HRESULT code
  370. --*/
  371. {
  372. HRESULT hr = S_OK;
  373. DBG_ENTER(_T("CFaxActivityLogging::put_LogIncoming"), hr, _T("Log Incoming : %d"), bLogIncoming);
  374. //
  375. // Sync with the Server for the first time
  376. //
  377. if (!m_bInited)
  378. {
  379. hr = Refresh();
  380. if (FAILED(hr))
  381. {
  382. return hr;
  383. }
  384. }
  385. m_bLogIncoming = bLogIncoming;
  386. return hr;
  387. }
  388. //
  389. //================ SUPPORT ERROR INFO ====================================
  390. //
  391. STDMETHODIMP
  392. CFaxActivityLogging::InterfaceSupportsErrorInfo(
  393. REFIID riid
  394. )
  395. /*++
  396. Routine name : CFaxActivityLogging::InterfaceSupportsErrorInfo
  397. Routine description:
  398. ATL's implementation of Support Error Info.
  399. Author:
  400. Iv Garber (IvG), Jun, 2000
  401. Arguments:
  402. riid [in] - Reference to the IID
  403. Return Value:
  404. Standard HRESULT code
  405. --*/
  406. {
  407. static const IID* arr[] =
  408. {
  409. &IID_IFaxActivityLogging
  410. };
  411. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  412. {
  413. if (InlineIsEqualGUID(*arr[i],riid))
  414. return S_OK;
  415. }
  416. return S_FALSE;
  417. }