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.

1216 lines
29 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. faxarchiveinner.h
  5. Abstract:
  6. Declaration and Implementation of Fax Archive Inner Template Class.
  7. Author:
  8. Iv Garber (IvG) May, 2000
  9. Revision History:
  10. --*/
  11. #ifndef __FAXARCHIVEINNER_H_
  12. #define __FAXARCHIVEINNER_H_
  13. #include "resource.h" // main symbols
  14. #include "FaxCommon.h"
  15. //
  16. //================ FAX ARCHIVE INNER =========================================
  17. //
  18. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  19. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  20. class CFaxArchiveInner :
  21. public IDispatchImpl<T, piid, &LIBID_FAXCOMEXLib>,
  22. public CFaxInitInner
  23. {
  24. public:
  25. CFaxArchiveInner() : CFaxInitInner(_T("FAX ARCHIVE INNER"))
  26. {
  27. m_bInitialized = FALSE;
  28. }
  29. virtual ~CFaxArchiveInner()
  30. {};
  31. STDMETHOD(get_SizeLow)(/*[out, retval]*/ long *plSizeLow);
  32. STDMETHOD(get_SizeHigh)(/*[out, retval]*/ long *plSizeHigh);
  33. STDMETHOD(get_UseArchive)(/*[out, retval]*/ VARIANT_BOOL *pbUseArchive);
  34. STDMETHOD(put_UseArchive)(/*[in]*/ VARIANT_BOOL bUseArchive);
  35. STDMETHOD(get_ArchiveFolder)(BSTR *pbstrArchiveFolder);
  36. STDMETHOD(put_ArchiveFolder)(BSTR bstrArchiveFolder);
  37. STDMETHOD(get_SizeQuotaWarning)(VARIANT_BOOL *pbSizeQuotaWarning);
  38. STDMETHOD(put_SizeQuotaWarning)(VARIANT_BOOL bSizeQuotaWarning);
  39. STDMETHOD(get_HighQuotaWaterMark)(long *plHighQuotaWaterMark);
  40. STDMETHOD(put_HighQuotaWaterMark)(long lHighQuotaWaterMark);
  41. STDMETHOD(get_LowQuotaWaterMark)(long *plLowQuotaWaterMark);
  42. STDMETHOD(put_LowQuotaWaterMark)(long lLowQuotaWaterMark);
  43. STDMETHOD(get_AgeLimit)(long *plAgeLimit);
  44. STDMETHOD(put_AgeLimit)(long lAgeLimit);
  45. STDMETHOD(Refresh)();
  46. STDMETHOD(Save)();
  47. STDMETHOD(GetMessage)(BSTR bstrMessageId, MsgIfc **ppFaxMessage);
  48. STDMETHOD(GetMessages)(long lPrefetchSize, IteratorIfc **ppFaxMessageIterator);
  49. private:
  50. bool m_bInitialized;
  51. VARIANT_BOOL m_bUseArchive;
  52. CComBSTR m_bstrArchiveFolder;
  53. VARIANT_BOOL m_bSizeQuotaWarning;
  54. long m_lHighQuotaWaterMark;
  55. long m_lLowQuotaWaterMark;
  56. long m_lAgeLimit;
  57. ULARGE_INTEGER m_uliSize;
  58. };
  59. //
  60. //========================= REFRESH ====================================
  61. //
  62. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  63. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  64. STDMETHODIMP
  65. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  66. ::Refresh(
  67. )
  68. /*++
  69. Routine name : CFaxArchiveInner::Refresh
  70. Routine description:
  71. Retrieve Current Configuration of the Incoming / Outgoing Archive on Fax Server
  72. Author:
  73. Iv Garber (IvG), Apr, 2000
  74. Arguments:
  75. Return Value:
  76. Standard HRESULT code
  77. --*/
  78. {
  79. HRESULT hr = S_OK;
  80. DBG_ENTER (_T("CFaxArchiveInner::Refresh"), hr);
  81. //
  82. // Get Fax Server Handle
  83. //
  84. HANDLE hFaxHandle = NULL;
  85. hr = GetFaxHandle(&hFaxHandle);
  86. if (FAILED(hr))
  87. {
  88. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  89. return hr;
  90. }
  91. CFaxPtr<FAX_ARCHIVE_CONFIG> pFaxArchiveConfig;
  92. if ( 0 == ::FaxGetArchiveConfiguration(hFaxHandle, ArchiveType, &pFaxArchiveConfig))
  93. {
  94. //
  95. // Failed to Get Archive Configuration
  96. //
  97. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  98. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  99. CALL_FAIL(GENERAL_ERR, _T("::FaxGetArchiveConfiguration()"), hr);
  100. return hr;
  101. }
  102. if (!pFaxArchiveConfig || pFaxArchiveConfig->dwSizeOfStruct != sizeof(FAX_ARCHIVE_CONFIG))
  103. {
  104. //
  105. // Failed to Get Archive Configuration
  106. //
  107. hr = E_FAIL;
  108. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  109. CALL_FAIL(GENERAL_ERR, _T("Invalid pFaxArchiveConfig"), hr);
  110. return hr;
  111. }
  112. m_bUseArchive = bool2VARIANT_BOOL(pFaxArchiveConfig->bUseArchive);
  113. m_bSizeQuotaWarning = bool2VARIANT_BOOL(pFaxArchiveConfig->bSizeQuotaWarning);
  114. m_lHighQuotaWaterMark = pFaxArchiveConfig->dwSizeQuotaHighWatermark;
  115. m_lLowQuotaWaterMark = pFaxArchiveConfig->dwSizeQuotaLowWatermark;
  116. m_lAgeLimit = pFaxArchiveConfig->dwAgeLimit;
  117. m_uliSize.QuadPart = pFaxArchiveConfig->dwlArchiveSize;
  118. m_bstrArchiveFolder = pFaxArchiveConfig->lpcstrFolder;
  119. if (!m_bstrArchiveFolder && pFaxArchiveConfig->lpcstrFolder)
  120. {
  121. hr = E_OUTOFMEMORY;
  122. AtlReportError(*pcid, IDS_ERROR_OUTOFMEMORY, *piid, hr);
  123. CALL_FAIL(MEM_ERR, _T("CComBSTR& operator=()"), hr);
  124. return hr;
  125. }
  126. m_bInitialized = TRUE;
  127. return hr;
  128. }
  129. //
  130. //==================== USE ARCHIVE ====================================
  131. //
  132. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  133. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  134. STDMETHODIMP
  135. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  136. ::get_UseArchive(
  137. VARIANT_BOOL *pbUseArchive
  138. )
  139. /*++
  140. Routine name : CFaxArchiveInner::get_UseArchive
  141. Routine description:
  142. Return Flag indicating whether or not to Archive the Fax Messages
  143. Author:
  144. Iv Garber (IvG), Apr, 2000
  145. Arguments:
  146. pbUseArchive [out] - Ptr to the Place to put Current value of the Flag
  147. Return Value:
  148. Standard HRESULT code
  149. --*/
  150. {
  151. HRESULT hr = S_OK;
  152. DBG_ENTER (TEXT("CFaxArchiveInner::get_UseArchive"), hr);
  153. //
  154. // Initialize before first use
  155. //
  156. if (!m_bInitialized)
  157. {
  158. hr = Refresh();
  159. if (FAILED(hr))
  160. {
  161. return hr;
  162. }
  163. }
  164. hr = GetVariantBool(pbUseArchive, m_bUseArchive);
  165. if (FAILED(hr))
  166. {
  167. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  168. return hr;
  169. }
  170. return hr;
  171. }
  172. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  173. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  174. STDMETHODIMP
  175. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>::
  176. put_UseArchive(
  177. VARIANT_BOOL bUseArchive
  178. )
  179. /*++
  180. Routine name : CFaxArchiveInner::put_UseArchive
  181. Routine description:
  182. Set new Use Archive Flag
  183. Author:
  184. Iv Garber (IvG), Apr, 2000
  185. Arguments:
  186. bUseArchive [in] - the new Value for the Use Archive Flag
  187. Return Value:
  188. Standard HRESULT code
  189. --*/
  190. {
  191. HRESULT hr = S_OK;
  192. DBG_ENTER (_T("CFaxArchiveInner::put_UseArchive"), hr, _T("%ld"), bUseArchive);
  193. //
  194. // Initialize before first use
  195. //
  196. if (!m_bInitialized)
  197. {
  198. hr = Refresh();
  199. if (FAILED(hr))
  200. {
  201. return hr;
  202. }
  203. }
  204. m_bUseArchive = bUseArchive;
  205. return hr;
  206. }
  207. //
  208. //==================== ARCHIVE FOLDER ====================================
  209. //
  210. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  211. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  212. STDMETHODIMP
  213. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  214. ::get_ArchiveFolder(
  215. BSTR *pbstrArchiveFolder
  216. )
  217. /*++
  218. Routine name : CFaxArchiveInner::get_ArchiveFolder
  219. Routine description:
  220. return Archive Folder on Server
  221. Author:
  222. Iv Garber (IvG), Apr, 2000
  223. Arguments:
  224. pbstrArchiveFolder [out] - the Archive Folder
  225. Return Value:
  226. Standard HRESULT code
  227. --*/
  228. {
  229. HRESULT hr = S_OK;
  230. DBG_ENTER (TEXT("CFaxArchiveInner::get_ArchiveFolder"), hr);
  231. //
  232. // Initialize before first use
  233. //
  234. if (!m_bInitialized)
  235. {
  236. hr = Refresh();
  237. if (FAILED(hr))
  238. {
  239. return hr;
  240. }
  241. }
  242. hr = GetBstr(pbstrArchiveFolder, m_bstrArchiveFolder);
  243. if (FAILED(hr))
  244. {
  245. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  246. return hr;
  247. }
  248. return hr;
  249. }
  250. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  251. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  252. STDMETHODIMP
  253. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  254. ::put_ArchiveFolder (
  255. BSTR bstrArchiveFolder
  256. )
  257. /*++
  258. Routine name : CFaxArchiveInner::put_ArchiveFolder
  259. Routine description:
  260. Set Archive Folder
  261. Author:
  262. Iv Garber (IvG), Apr, 2000
  263. Arguments:
  264. bstrArchiveFolder [in] - new Archive Folder on Server
  265. Return Value:
  266. Standard HRESULT code
  267. --*/
  268. {
  269. HRESULT hr = S_OK;
  270. DBG_ENTER (_T("CFaxArchiveInner::put_ArchiveFolder"), hr, _T("%s"), bstrArchiveFolder);
  271. //
  272. // Initialize before first use
  273. //
  274. if (!m_bInitialized)
  275. {
  276. hr = Refresh();
  277. if (FAILED(hr))
  278. {
  279. return hr;
  280. }
  281. }
  282. m_bstrArchiveFolder = bstrArchiveFolder;
  283. if (bstrArchiveFolder && !m_bstrArchiveFolder)
  284. {
  285. //
  286. // Not enough memory
  287. //
  288. hr = E_OUTOFMEMORY;
  289. AtlReportError(*pcid,
  290. IDS_ERROR_OUTOFMEMORY,
  291. *piid,
  292. hr);
  293. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator="), hr);
  294. return hr;
  295. }
  296. return hr;
  297. }
  298. //
  299. //==================== SIZE QUOTA WARNING ================================
  300. //
  301. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  302. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  303. STDMETHODIMP
  304. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  305. ::get_SizeQuotaWarning(
  306. VARIANT_BOOL *pbSizeQuotaWarning
  307. )
  308. /*++
  309. Routine name : CFaxArchiveInner::get_SizeQuotaWarning
  310. Routine description:
  311. Return Flag indicating whether or not to issue event log warning when
  312. watermarks are crossed
  313. Author:
  314. Iv Garber (IvG), Apr, 2000
  315. Arguments:
  316. pbSizeQuotaWarning [out] - ptr to place where to put the Current value of the Flag
  317. Return Value:
  318. Standard HRESULT code
  319. --*/
  320. {
  321. HRESULT hr = S_OK;
  322. DBG_ENTER (TEXT("CFaxArchiveInner::get_SizeQuotaWarning"), hr);
  323. //
  324. // Initialize before first use
  325. //
  326. if (!m_bInitialized)
  327. {
  328. hr = Refresh();
  329. if (FAILED(hr))
  330. {
  331. return hr;
  332. }
  333. }
  334. hr = GetVariantBool(pbSizeQuotaWarning, m_bSizeQuotaWarning);
  335. if (FAILED(hr))
  336. {
  337. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  338. return hr;
  339. }
  340. return hr;
  341. }
  342. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  343. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  344. STDMETHODIMP
  345. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  346. ::put_SizeQuotaWarning(
  347. VARIANT_BOOL bSizeQuotaWarning
  348. )
  349. /*++
  350. Routine name : CFaxArchiveInner::put_SizeQuotaWarning
  351. Routine description:
  352. Set new SizeQuotaWarning Flag
  353. Author:
  354. Iv Garber (IvG), Apr, 2000
  355. Arguments:
  356. bSizeQuotaWarning [in] - the new Value for the SizeQuotaWarning Flag
  357. Return Value:
  358. Standard HRESULT code
  359. --*/
  360. {
  361. HRESULT hr = S_OK;
  362. DBG_ENTER (_T("CFaxArchiveInner::put_SizeQuotaWarning"), hr, _T("%ld"), bSizeQuotaWarning);
  363. //
  364. // Initialize before first use
  365. //
  366. if (!m_bInitialized)
  367. {
  368. hr = Refresh();
  369. if (FAILED(hr))
  370. {
  371. return hr;
  372. }
  373. }
  374. m_bSizeQuotaWarning = bSizeQuotaWarning;
  375. return hr;
  376. }
  377. //
  378. //================= QUOTA WATER MARKS ===============================
  379. //
  380. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  381. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  382. STDMETHODIMP
  383. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  384. ::get_HighQuotaWaterMark(
  385. long *plHighQuotaWaterMark
  386. )
  387. /*++
  388. Routine name : CFaxArchiveInner::get_HighQuotaWaterMark
  389. Routine description:
  390. Return HighQuotaWaterMark
  391. Author:
  392. Iv Garber (IvG), Apr, 2000
  393. Arguments:
  394. plHighQuotaWaterMark [out] - HighQuotaWaterMark
  395. Return Value:
  396. Standard HRESULT code
  397. --*/
  398. {
  399. HRESULT hr = S_OK;
  400. DBG_ENTER (TEXT("CFaxArchiveInner::get_HighQuotaWaterMark"), hr);
  401. //
  402. // Initialize before first use
  403. //
  404. if (!m_bInitialized)
  405. {
  406. hr = Refresh();
  407. if (FAILED(hr))
  408. {
  409. return hr;
  410. }
  411. }
  412. hr = GetLong(plHighQuotaWaterMark , m_lHighQuotaWaterMark);
  413. if (FAILED(hr))
  414. {
  415. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  416. return hr;
  417. }
  418. return hr;
  419. }
  420. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  421. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  422. STDMETHODIMP
  423. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  424. ::put_HighQuotaWaterMark(
  425. long lHighQuotaWaterMark
  426. )
  427. /*++
  428. Routine name : CFaxArchiveInner::put_HighQuotaWaterMark
  429. Routine description:
  430. Set HighQuotaWaterMark
  431. Author:
  432. Iv Garber (IvG), Apr, 2000
  433. Arguments:
  434. lHighQuotaWaterMark [in] - HighQuotaWaterMark to Set
  435. Return Value:
  436. Standard HRESULT code
  437. --*/
  438. {
  439. HRESULT hr = S_OK;
  440. DBG_ENTER (_T("CFaxArchiveInner::put_HighQuotaWaterMark"), hr, _T("%ld"), lHighQuotaWaterMark);
  441. //
  442. // Initialize before first use
  443. //
  444. if (!m_bInitialized)
  445. {
  446. hr = Refresh();
  447. if (FAILED(hr))
  448. {
  449. return hr;
  450. }
  451. }
  452. m_lHighQuotaWaterMark = lHighQuotaWaterMark;
  453. return hr;
  454. }
  455. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  456. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  457. STDMETHODIMP
  458. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  459. ::get_LowQuotaWaterMark(
  460. long *plLowQuotaWaterMark
  461. )
  462. /*++
  463. Routine name : CFaxArchiveInner::get_LowQuotaWaterMark
  464. Routine description:
  465. Return LowQuotaWaterMark
  466. Author:
  467. Iv Garber (IvG), Apr, 2000
  468. Arguments:
  469. plLowQuotaWaterMark [out] - LowQuotaWaterMark
  470. Return Value:
  471. Standard HRESULT code
  472. --*/
  473. {
  474. HRESULT hr = S_OK;
  475. DBG_ENTER (TEXT("CFaxArchiveInner::get_LowQuotaWaterMark"), hr);
  476. //
  477. // Initialize before first use
  478. //
  479. if (!m_bInitialized)
  480. {
  481. hr = Refresh();
  482. if (FAILED(hr))
  483. {
  484. return hr;
  485. }
  486. }
  487. hr = GetLong(plLowQuotaWaterMark , m_lLowQuotaWaterMark);
  488. if (FAILED(hr))
  489. {
  490. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  491. return hr;
  492. }
  493. return hr;
  494. }
  495. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  496. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  497. STDMETHODIMP
  498. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  499. ::put_LowQuotaWaterMark(
  500. long lLowQuotaWaterMark
  501. )
  502. /*++
  503. Routine name : CFaxArchiveInner::put_LowQuotaWaterMark
  504. Routine description:
  505. Set LowQuotaWaterMark
  506. Author:
  507. Iv Garber (IvG), Apr, 2000
  508. Arguments:
  509. lLowQuotaWaterMark [in] - LowQuotaWaterMark to Set
  510. Return Value:
  511. Standard HRESULT code
  512. --*/
  513. {
  514. HRESULT hr = S_OK;
  515. DBG_ENTER (_T("CFaxArchiveInner::put_LowQuotaWaterMark"), hr, _T("%ld"), lLowQuotaWaterMark);
  516. //
  517. // Initialize before first use
  518. //
  519. if (!m_bInitialized)
  520. {
  521. hr = Refresh();
  522. if (FAILED(hr))
  523. {
  524. return hr;
  525. }
  526. }
  527. m_lLowQuotaWaterMark = lLowQuotaWaterMark;
  528. return hr;
  529. }
  530. //
  531. //================= AGE LIMIT ===============================
  532. //
  533. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  534. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  535. STDMETHODIMP
  536. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  537. ::get_AgeLimit(
  538. long *plAgeLimit
  539. )
  540. /*++
  541. Routine name : CFaxArchiveInner::get_AgeLimit
  542. Routine description:
  543. Return how long in days Fax Message is stored at Fax Server
  544. Author:
  545. Iv Garber (IvG), Apr, 2000
  546. Arguments:
  547. plAgeLimit [out] - AgeLimit
  548. Return Value:
  549. Standard HRESULT code
  550. --*/
  551. {
  552. HRESULT hr = S_OK;
  553. DBG_ENTER (TEXT("CFaxArchiveInner::get_AgeLimit"), hr);
  554. //
  555. // Initialize before first use
  556. //
  557. if (!m_bInitialized)
  558. {
  559. hr = Refresh();
  560. if (FAILED(hr))
  561. {
  562. return hr;
  563. }
  564. }
  565. hr = GetLong(plAgeLimit, m_lAgeLimit);
  566. if (FAILED(hr))
  567. {
  568. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  569. return hr;
  570. }
  571. return hr;
  572. }
  573. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  574. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  575. STDMETHODIMP
  576. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  577. ::put_AgeLimit(
  578. long lAgeLimit
  579. )
  580. /*++
  581. Routine name : CFaxArchiveInner::put_AgeLimit
  582. Routine description:
  583. Set AgeLimit
  584. Author:
  585. Iv Garber (IvG), Apr, 2000
  586. Arguments:
  587. lAgeLimit [in] - AgeLimit to Set
  588. Return Value:
  589. Standard HRESULT code
  590. --*/
  591. {
  592. HRESULT hr = S_OK;
  593. DBG_ENTER (_T("CFaxArchiveInner::put_AgeLimit"), hr, _T("%ld"), lAgeLimit);
  594. //
  595. // Initialize before first use
  596. //
  597. if (!m_bInitialized)
  598. {
  599. hr = Refresh();
  600. if (FAILED(hr))
  601. {
  602. return hr;
  603. }
  604. }
  605. m_lAgeLimit = lAgeLimit;
  606. return hr;
  607. }
  608. //
  609. //================= SIZE ==============================================
  610. //
  611. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  612. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  613. STDMETHODIMP
  614. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  615. ::get_SizeLow(
  616. long *plSizeLow
  617. )
  618. /*++
  619. Routine name : CFaxArchiveInner::get_SizeLow
  620. Routine description:
  621. Return Size in Bytes of the Archive
  622. Author:
  623. Iv Garber (IvG), May, 2000
  624. Arguments:
  625. plSizeLow [out] - Ptr to the place to put the Size in
  626. Return Value:
  627. Standard HRESULT code
  628. --*/
  629. {
  630. HRESULT hr = S_OK;
  631. DBG_ENTER (TEXT("CFaxArchiveInner::get_SizeLow"), hr);
  632. //
  633. // Initialize before first use
  634. //
  635. if (!m_bInitialized)
  636. {
  637. hr = Refresh();
  638. if (FAILED(hr))
  639. {
  640. return hr;
  641. }
  642. }
  643. hr = GetLong(plSizeLow, long(m_uliSize.LowPart));
  644. if (FAILED(hr))
  645. {
  646. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  647. return hr;
  648. }
  649. return hr;
  650. }
  651. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  652. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  653. STDMETHODIMP
  654. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  655. ::get_SizeHigh(
  656. long *plSizeHigh
  657. )
  658. /*++
  659. Routine name : CFaxArchiveInner::get_SizeHigh
  660. Routine description:
  661. Return Size in Bytes of the Archive
  662. Author:
  663. Iv Garber (IvG), May, 2000
  664. Arguments:
  665. plSizeHigh [out] - Ptr to the place to put the Size in
  666. Return Value:
  667. Standard HRESULT code
  668. --*/
  669. {
  670. HRESULT hr = S_OK;
  671. DBG_ENTER (TEXT("CFaxArchiveInner::get_SizeHigh"), hr);
  672. //
  673. // Initialize before first use
  674. //
  675. if (!m_bInitialized)
  676. {
  677. hr = Refresh();
  678. if (FAILED(hr))
  679. {
  680. return hr;
  681. }
  682. }
  683. hr = GetLong(plSizeHigh, long(m_uliSize.HighPart));
  684. if (FAILED(hr))
  685. {
  686. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  687. return hr;
  688. }
  689. return hr;
  690. }
  691. //
  692. //========================= SAVE ====================================
  693. //
  694. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  695. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  696. STDMETHODIMP
  697. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  698. ::Save(
  699. )
  700. /*++
  701. Routine name : CFaxArchiveInner::Save
  702. Routine description:
  703. Save the Archive's Configuration
  704. Author:
  705. Iv Garber (IvG), Apr, 2000
  706. Arguments:
  707. Return Value:
  708. Standard HRESULT code
  709. --*/
  710. {
  711. HRESULT hr = S_OK;
  712. HANDLE hFaxHandle = NULL;
  713. FAX_ARCHIVE_CONFIG FaxArchiveConfig;
  714. DBG_ENTER (_T("CFaxArchiveInner::Save"), hr);
  715. //
  716. // Get Fax Server Handle
  717. //
  718. hr = GetFaxHandle(&hFaxHandle);
  719. if (FAILED(hr))
  720. {
  721. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  722. return hr;
  723. }
  724. if (hFaxHandle == NULL)
  725. {
  726. //
  727. // Fax Server Is Not Connected
  728. //
  729. hr = E_HANDLE;
  730. AtlReportError(*pcid,
  731. IDS_ERROR_SERVER_NOT_CONNECTED,
  732. *piid,
  733. hr);
  734. CALL_FAIL(GENERAL_ERR, _T("hFaxHandle == NULL"), hr);
  735. return hr;
  736. }
  737. //
  738. // FaxArchiveConfig.dwlArchiveSize is ignored for SetConfiguration()
  739. //
  740. FaxArchiveConfig.dwSizeOfStruct = sizeof(FAX_ARCHIVE_CONFIG);
  741. FaxArchiveConfig.bUseArchive = VARIANT_BOOL2bool(m_bUseArchive);
  742. FaxArchiveConfig.bSizeQuotaWarning = VARIANT_BOOL2bool(m_bSizeQuotaWarning);
  743. FaxArchiveConfig.dwSizeQuotaHighWatermark = m_lHighQuotaWaterMark;
  744. FaxArchiveConfig.dwSizeQuotaLowWatermark = m_lLowQuotaWaterMark;
  745. FaxArchiveConfig.dwAgeLimit = m_lAgeLimit;
  746. FaxArchiveConfig.lpcstrFolder = m_bstrArchiveFolder;
  747. if ( 0 == ::FaxSetArchiveConfiguration(hFaxHandle, ArchiveType, &FaxArchiveConfig))
  748. {
  749. //
  750. // Failed to Set Archive Configuration
  751. //
  752. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  753. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  754. CALL_FAIL(GENERAL_ERR, _T("::FaxSetArchiveConfiguration()"), hr);
  755. return hr;
  756. }
  757. return hr;
  758. }
  759. //
  760. //=============== GET MESSAGE ========================================
  761. //
  762. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  763. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  764. STDMETHODIMP
  765. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  766. ::GetMessage(
  767. BSTR bstrMessageId,
  768. MsgIfc **ppFaxMessage
  769. )
  770. /*++
  771. Routine name : CFaxArchiveInner::GetMessage
  772. Routine description:
  773. Return Message by given Id
  774. Author:
  775. Iv Garber (IvG), May, 2000
  776. Arguments:
  777. bstrMessageId [in] - Id of the Message to return
  778. ppFaxMessage [out] - Ptr to the place to put the Message
  779. Return Value:
  780. Standard HRESULT code
  781. --*/
  782. {
  783. HRESULT hr = S_OK;
  784. DBG_ENTER (TEXT("CFaxArchiveInner::GetMessage"), hr, _T("%s"), bstrMessageId);
  785. //
  786. // Check that we can write to the given pointer
  787. //
  788. if (::IsBadWritePtr(ppFaxMessage, sizeof(MsgIfc *)))
  789. {
  790. //
  791. // Got Bad Return Pointer
  792. //
  793. hr = E_POINTER;
  794. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  795. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr"), hr);
  796. return hr;
  797. }
  798. //
  799. // Get Fax Server Handle
  800. //
  801. HANDLE hFaxHandle = NULL;
  802. hr = GetFaxHandle(&hFaxHandle);
  803. if (FAILED(hr))
  804. {
  805. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  806. return hr;
  807. }
  808. //
  809. // convert Message Id that we've got to hexadecimal DWORDLONG
  810. //
  811. DWORDLONG dwlMsgId;
  812. int iParsed = _stscanf (bstrMessageId, _T("%I64x"), &dwlMsgId);
  813. if ( iParsed != 1)
  814. {
  815. //
  816. // Failed to conver the number
  817. //
  818. hr = E_INVALIDARG;
  819. CALL_FAIL(GENERAL_ERR, _T("_stscanf()"), hr);
  820. AtlReportError(*pcid, IDS_ERROR_INVALIDMSGID, *piid, hr);
  821. return hr;
  822. }
  823. CFaxPtr<FAX_MESSAGE> pFaxPtrMessage;
  824. if (!FaxGetMessage(hFaxHandle, dwlMsgId, ArchiveType, &pFaxPtrMessage))
  825. {
  826. //
  827. // Failed to retrieve the Message
  828. //
  829. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  830. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  831. CALL_FAIL(GENERAL_ERR, _T("FaxGetMessage()"), hr);
  832. return hr;
  833. }
  834. //
  835. // Check that pFaxPtrMessage is valid
  836. //
  837. if (!pFaxPtrMessage || pFaxPtrMessage->dwSizeOfStruct != sizeof(FAX_MESSAGE))
  838. {
  839. //
  840. // Failed to Get Message
  841. //
  842. hr = E_FAIL;
  843. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  844. CALL_FAIL(GENERAL_ERR, _T("Invalid pFaxMessage"), hr);
  845. return hr;
  846. }
  847. //
  848. // Create Message Object
  849. //
  850. CComPtr<MsgIfc> pTmpMessage;
  851. hr = MsgType::Create(&pTmpMessage);
  852. if (FAILED(hr))
  853. {
  854. //
  855. // Failed to create the Message object
  856. //
  857. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  858. CALL_FAIL(GENERAL_ERR, _T("MsgType::Create()"), hr);
  859. return hr;
  860. }
  861. //
  862. // Initialize the Message Object
  863. //
  864. hr = ((MsgType *)((MsgIfc *)pTmpMessage))->Init(pFaxPtrMessage, m_pIFaxServerInner);
  865. if (FAILED(hr))
  866. {
  867. //
  868. // Failed to Init the Message Object
  869. //
  870. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  871. CALL_FAIL(GENERAL_ERR, _T("<casted>pTmpMessage->Init(pFaxMessage, m_pIFaxServerInner)"), hr);
  872. return hr;
  873. }
  874. //
  875. // Return Message Object to the Caller
  876. //
  877. hr = pTmpMessage.CopyTo(ppFaxMessage);
  878. if (FAILED(hr))
  879. {
  880. //
  881. // Failed to Copy Interface
  882. //
  883. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  884. CALL_FAIL(GENERAL_ERR, _T("CComPtr::CopyTo"), hr);
  885. return hr;
  886. }
  887. return hr;
  888. }
  889. //
  890. //========================= GET MESSAGES ==============================================
  891. //
  892. template <class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER ArchiveType,
  893. class MsgIfc, class MsgType, class IteratorIfc, class IteratorType>
  894. STDMETHODIMP
  895. CFaxArchiveInner<T, piid, pcid, ArchiveType, MsgIfc, MsgType, IteratorIfc, IteratorType>
  896. ::GetMessages(
  897. long lPrefetchSize,
  898. IteratorIfc **ppFaxMessageIterator
  899. )
  900. /*++
  901. Routine name : CFaxArchiveInner::GetMessages
  902. Routine description:
  903. Return Iterator on Archive's Messages.
  904. Author:
  905. Iv Garber (IvG), May, 2000
  906. Arguments:
  907. lPrefetchSize [in] - Size of Prefetch Buffer for Messages.
  908. ppFaxMessageIterator [out] - Ptr to place to put Iterator Object
  909. Return Value:
  910. Standard HRESULT code
  911. --*/
  912. {
  913. HRESULT hr = S_OK;
  914. DBG_ENTER (TEXT("CFaxArchiveInner::GetMessages"), hr);
  915. CObjectHandler<IteratorType, IteratorIfc> objectCreator;
  916. CComPtr<IteratorIfc> pObjectTmp;
  917. hr = objectCreator.GetObject(&pObjectTmp, m_pIFaxServerInner);
  918. if (FAILED(hr))
  919. {
  920. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  921. return hr;
  922. }
  923. //
  924. // Set object prefetch size to default value
  925. //
  926. hr = pObjectTmp->put_PrefetchSize(lPrefetchSize);
  927. if (FAILED(hr))
  928. {
  929. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  930. return hr;
  931. }
  932. //
  933. // Object is successfully created and set - copy it back to caller
  934. //
  935. hr = pObjectTmp.CopyTo(ppFaxMessageIterator);
  936. if (FAILED(hr))
  937. {
  938. CALL_FAIL(GENERAL_ERR, _T("CComPtr::CopyTo"), hr);
  939. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  940. return hr;
  941. }
  942. return hr;
  943. } // CFaxArchiveInner::GetMessages
  944. #endif //__FAXARCHIVEINNER_H_