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.

1435 lines
35 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxMessageInner.h
  5. Abstract:
  6. Implementation of Fax Message Inner Class :
  7. Base Class for Inbound and Outbound Message Classes.
  8. Author:
  9. Iv Garber (IvG) May, 2000
  10. Revision History:
  11. --*/
  12. #ifndef __FAXMESSAGEINNER_H_
  13. #define __FAXMESSAGEINNER_H_
  14. #include "FaxCommon.h"
  15. #include "FaxSender.h"
  16. //
  17. //===================== FAX MESSAGE INNER CLASS ===============================
  18. //
  19. template<class T, const IID* piid, const CLSID* pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  20. class CFaxMessageInner :
  21. public IDispatchImpl<T, piid, &LIBID_FAXCOMEXLib>,
  22. public CFaxInitInnerAddRef
  23. {
  24. public:
  25. CFaxMessageInner() : CFaxInitInnerAddRef(_T("FAX MESSAGE INNER"))
  26. {
  27. m_pSender = NULL;
  28. m_pRecipient = NULL;
  29. };
  30. virtual ~CFaxMessageInner()
  31. {
  32. if (m_pSender)
  33. {
  34. m_pSender->Release();
  35. }
  36. if (m_pRecipient)
  37. {
  38. m_pRecipient->Release();
  39. }
  40. };
  41. STDMETHOD(Init)(PFAX_MESSAGE pFaxMessage, IFaxServerInner* pFaxServerInner);
  42. STDMETHOD(get_Id)(/*[out, retval]*/ BSTR *pbstrId);
  43. STDMETHOD(get_SubmissionId)(/*[out, retval] */BSTR *pbstrSubmissionId);
  44. STDMETHOD(get_DeviceName)(/*[out, retval]*/ BSTR *pbstrDeviceName);
  45. STDMETHOD(get_TSID)(/*[out, retval]*/ BSTR *pbstrTSID);
  46. STDMETHOD(get_CSID)(/*[out, retval]*/ BSTR *pbstrCSID);
  47. STDMETHOD(get_CallerId)(/*[out, retval]*/ BSTR *pbstrCallerId);
  48. STDMETHOD(get_RoutingInformation)(/*[out, retval]*/ BSTR *pbstrRoutingInformation);
  49. STDMETHOD(get_DocumentName)(/*[out, retval] */BSTR *pbstrDocumentName);
  50. STDMETHOD(get_Subject)(/*[out, retval] */BSTR *pbstrSubject);
  51. STDMETHOD(get_Size)(/*[out, retval]*/ long *plSize);
  52. STDMETHOD(get_Pages)(/*[out, retval]*/ long *plPages);
  53. STDMETHOD(get_Retries)(/*[out, retval]*/ long *plRetries);
  54. STDMETHOD(get_Priority)(/*[out, retval] */FAX_PRIORITY_TYPE_ENUM *pPriority);
  55. STDMETHOD(get_TransmissionStart)(/*[out, retval]*/ DATE *pdateTransmissionStart);
  56. STDMETHOD(get_TransmissionEnd)(/*[out, retval]*/ DATE *pdateTransmissionEnd);
  57. STDMETHOD(get_OriginalScheduledTime)(/*[out, retval] */DATE *pdateOriginalScheduledTime);
  58. STDMETHOD(get_SubmissionTime)(/*[out, retval] */DATE *pdateSubmissionTime);
  59. STDMETHOD(CopyTiff)(/*[in]*/ BSTR bstrTiffPath);
  60. STDMETHOD(Delete)();
  61. STDMETHOD(get_Sender)(/*[out, retval] */IFaxSender **ppFaxSender);
  62. STDMETHOD(get_Recipient)(/*[out, retval] */IFaxRecipient **ppFaxRecipient);
  63. private:
  64. CComBSTR m_bstrSubmissionId;
  65. CComBSTR m_bstrTSID;
  66. CComBSTR m_bstrDeviceName;
  67. CComBSTR m_bstrCSID;
  68. CComBSTR m_bstrCallerId;
  69. CComBSTR m_bstrRoutingInfo;
  70. CComBSTR m_bstrDocName;
  71. CComBSTR m_bstrSubject;
  72. CComBSTR m_bstrNote;
  73. long m_lSize;
  74. long m_lPages;
  75. long m_lRetries;
  76. DATE m_dtTransmissionStart;
  77. DATE m_dtTransmissionEnd;
  78. DATE m_dtOriginalScheduledTime;
  79. DATE m_dtSubmissionTime;
  80. DWORD m_dwValidityMask;
  81. DWORDLONG m_dwlMsgId;
  82. FAX_PRIORITY_TYPE_ENUM m_Priority;
  83. CComObject<CFaxSender> *m_pSender;
  84. CComObject<CFaxRecipient> *m_pRecipient;
  85. };
  86. //
  87. //====================== GET ID ================================================
  88. //
  89. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  90. STDMETHODIMP
  91. CFaxMessageInner<T, piid, pcid, FolderType>::get_Id(
  92. BSTR *pbstrId
  93. )
  94. /*++
  95. Routine name : CFaxMessageInner::get_Id
  96. Routine description:
  97. Return Unique ID of the Message
  98. Author:
  99. Iv Garber (IvG), May, 2000
  100. Arguments:
  101. pbstrId [out] - pointer to the place to put the ID
  102. Return Value:
  103. Standard HRESULT code
  104. --*/
  105. {
  106. HRESULT hr = S_OK;
  107. DBG_ENTER (TEXT("CFaxMessageInner::get_Id"), hr);
  108. //
  109. // Check that we can write to the given pointer
  110. //
  111. if (::IsBadWritePtr(pbstrId, sizeof(BSTR)))
  112. {
  113. //
  114. // got bad pointer
  115. //
  116. hr = E_POINTER;
  117. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  118. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  119. return hr;
  120. }
  121. //
  122. // Convert m_dwlMsgId into BSTR pbstrId
  123. //
  124. hr = GetBstrFromDwordlong(m_dwlMsgId, pbstrId);
  125. if (FAILED(hr))
  126. {
  127. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  128. return hr;
  129. }
  130. return hr;
  131. }
  132. //
  133. //====================== GET SIZE ================================================
  134. //
  135. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  136. STDMETHODIMP
  137. CFaxMessageInner<T, piid, pcid, FolderType>::get_Size(
  138. long *plSize
  139. )
  140. /*++
  141. Routine name : CFaxMessageInner::get_Size
  142. Routine description:
  143. Return Size ( in bytes ) of Fax Message's TIFF File
  144. Author:
  145. Iv Garber (IvG), May, 2000
  146. Arguments:
  147. plSize [out] - Pointer to the place to put Size
  148. Return Value:
  149. Standard HRESULT code
  150. --*/
  151. {
  152. HRESULT hr = S_OK;
  153. DBG_ENTER (TEXT("CFaxMessageInner::get_Size"), hr);
  154. hr = GetLong(plSize, m_lSize);
  155. if (FAILED(hr))
  156. {
  157. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  158. return hr;
  159. }
  160. return hr;
  161. }
  162. //
  163. //====================== GET PAGES ================================================
  164. //
  165. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  166. STDMETHODIMP
  167. CFaxMessageInner<T, piid, pcid, FolderType>::get_Pages(
  168. long *plPages
  169. )
  170. /*++
  171. Routine name : CFaxMessageInner::get_Pages
  172. Routine description:
  173. Return total number of pages of the message
  174. Author:
  175. Iv Garber (IvG), May, 2000
  176. Arguments:
  177. plPages [out] - Pointer to the place to put the value
  178. Return Value:
  179. Standard HRESULT code
  180. --*/
  181. {
  182. HRESULT hr = S_OK;
  183. DBG_ENTER (TEXT("CFaxMessageInner::get_Pages"), hr);
  184. hr = GetLong(plPages, m_lPages);
  185. if (FAILED(hr))
  186. {
  187. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  188. return hr;
  189. }
  190. return hr;
  191. }
  192. //
  193. //====================== GET TSID ================================================
  194. //
  195. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  196. STDMETHODIMP
  197. CFaxMessageInner<T, piid, pcid, FolderType>::get_TSID(
  198. BSTR *pbstrTSID
  199. )
  200. /*++
  201. Routine name : CFaxMessageInner::get_TSID
  202. Routine description:
  203. Return Transmitting Station ID of the Message
  204. Author:
  205. Iv Garber (IvG), May, 2000
  206. Arguments:
  207. pbstrTSID [out] - pointer to the place to put the TSID
  208. Return Value:
  209. Standard HRESULT code
  210. --*/
  211. {
  212. HRESULT hr = S_OK;
  213. DBG_ENTER (TEXT("CFaxMessageInner::get_TSID"), hr);
  214. hr = GetBstr(pbstrTSID, m_bstrTSID);
  215. if (FAILED(hr))
  216. {
  217. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  218. return hr;
  219. }
  220. return hr;
  221. }
  222. //
  223. //====================== GET CSID ================================================
  224. //
  225. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  226. STDMETHODIMP
  227. CFaxMessageInner<T, piid, pcid, FolderType>::get_CSID(
  228. BSTR *pbstrCSID
  229. )
  230. /*++
  231. Routine name : CFaxMessageInner::get_CSID
  232. Routine description:
  233. Return Called Station ID of the Message
  234. Author:
  235. Iv Garber (IvG), May, 2000
  236. Arguments:
  237. pbstrCSID [out] - pointer to the place to put the CSID
  238. Return Value:
  239. Standard HRESULT code
  240. --*/
  241. {
  242. HRESULT hr = S_OK;
  243. DBG_ENTER (TEXT("CFaxMessageInner::get_CSID"), hr);
  244. hr = GetBstr(pbstrCSID, m_bstrCSID);
  245. if (FAILED(hr))
  246. {
  247. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  248. return hr;
  249. }
  250. return hr;
  251. }
  252. //
  253. //====================== GET PRIORITY ================================================
  254. //
  255. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  256. STDMETHODIMP
  257. CFaxMessageInner<T, piid, pcid, FolderType>::get_Priority(
  258. FAX_PRIORITY_TYPE_ENUM *pPriority
  259. )
  260. /*++
  261. Routine name : CFaxMessageInner::get_Priority
  262. Routine description:
  263. Return the Priority of Fax Message
  264. Author:
  265. Iv Garber (IvG), May, 2000
  266. Arguments:
  267. pPriority [out] - Pointer to the place to put the Priority
  268. Return Value:
  269. Standard HRESULT code
  270. --*/
  271. {
  272. HRESULT hr = S_OK;
  273. DBG_ENTER (TEXT("CFaxMessageInner::get_Priority"), hr);
  274. //
  275. // Check that we can write to the given pointer
  276. //
  277. if (::IsBadWritePtr(pPriority, sizeof(FAX_PRIORITY_TYPE_ENUM)))
  278. {
  279. //
  280. // Got Bad Return Pointer
  281. //
  282. hr = E_POINTER;
  283. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  284. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr"), hr);
  285. return hr;
  286. }
  287. *pPriority = FAX_PRIORITY_TYPE_ENUM(m_Priority);
  288. return hr;
  289. }
  290. //
  291. //====================== GET RETRIES ================================================
  292. //
  293. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  294. STDMETHODIMP
  295. CFaxMessageInner<T, piid, pcid, FolderType>::get_Retries(
  296. long *plRetries
  297. )
  298. /*++
  299. Routine name : CFaxMessageInner::get_Retries
  300. Routine description:
  301. Number of failed transmission retries
  302. Author:
  303. Iv Garber (IvG), May, 2000
  304. Arguments:
  305. plRetries [out] - Pointer to the place to put Retries value
  306. Return Value:
  307. Standard HRESULT code
  308. --*/
  309. {
  310. HRESULT hr = S_OK;
  311. DBG_ENTER (TEXT("CFaxMessageInner::get_Retries"), hr);
  312. hr = GetLong(plRetries, m_lRetries);
  313. if (FAILED(hr))
  314. {
  315. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  316. return hr;
  317. }
  318. return hr;
  319. }
  320. //
  321. //====================== GET DEVICE NAME ================================================
  322. //
  323. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  324. STDMETHODIMP
  325. CFaxMessageInner<T, piid, pcid, FolderType>::get_DeviceName(
  326. BSTR *pbstrDeviceName
  327. )
  328. /*++
  329. Routine name : CFaxMessageInner::get_DeviceName
  330. Routine description:
  331. Return the Name of the Device by which the Message was Received / Transmitted.
  332. Author:
  333. Iv Garber (IvG), May, 2000
  334. Arguments:
  335. pbstrDeviceName [out] - pointer to the place to put the Device Name
  336. Return Value:
  337. Standard HRESULT code
  338. --*/
  339. {
  340. HRESULT hr = S_OK;
  341. DBG_ENTER (TEXT("CFaxMessageInner::get_DeviceName"), hr);
  342. hr = GetBstr(pbstrDeviceName, m_bstrDeviceName);
  343. if (FAILED(hr))
  344. {
  345. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  346. return hr;
  347. }
  348. return hr;
  349. }
  350. //
  351. //====================== GET DOCUMENT NAME ================================================
  352. //
  353. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  354. STDMETHODIMP
  355. CFaxMessageInner<T, piid, pcid, FolderType>::get_DocumentName(
  356. BSTR *pbstrDocumentName
  357. )
  358. /*++
  359. Routine name : CFaxMessageInner::get_DocumentName
  360. Routine description:
  361. Return the Friendly Name of the Document
  362. Author:
  363. Iv Garber (IvG), May, 2000
  364. Arguments:
  365. pbstrDocumentName [out] - pointer to the place to put Document Name
  366. Return Value:
  367. Standard HRESULT code
  368. --*/
  369. {
  370. HRESULT hr = S_OK;
  371. DBG_ENTER (TEXT("CFaxMessageInner::get_DocumentName"), hr);
  372. hr = GetBstr(pbstrDocumentName, m_bstrDocName);
  373. if (FAILED(hr))
  374. {
  375. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  376. return hr;
  377. }
  378. return hr;
  379. }
  380. //
  381. //====================== GET SUBJECT ================================================
  382. //
  383. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  384. STDMETHODIMP
  385. CFaxMessageInner<T, piid, pcid, FolderType>::get_Subject(
  386. BSTR *pbstrSubject
  387. )
  388. /*++
  389. Routine name : CFaxMessageInner::get_Subject
  390. Routine description:
  391. Return the Subject field of the Cover Page
  392. Author:
  393. Iv Garber (IvG), May, 2000
  394. Arguments:
  395. pbstrSubject [out] - pointer to the place to put Subject contents
  396. Return Value:
  397. Standard HRESULT code
  398. --*/
  399. {
  400. HRESULT hr = S_OK;
  401. DBG_ENTER (TEXT("CFaxMessageInner::get_Subject"), hr);
  402. hr = GetBstr(pbstrSubject, m_bstrSubject);
  403. if (FAILED(hr))
  404. {
  405. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  406. return hr;
  407. }
  408. return hr;
  409. }
  410. //
  411. //====================== GET CALLER ID ================================================
  412. //
  413. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  414. STDMETHODIMP
  415. CFaxMessageInner<T, piid, pcid, FolderType>::get_CallerId(
  416. BSTR *pbstrCallerId
  417. )
  418. /*++
  419. Routine name : CFaxMessageInner::get_CallerId
  420. Routine description:
  421. Return the Caller Id of Message's Phone Call
  422. Author:
  423. Iv Garber (IvG), May, 2000
  424. Arguments:
  425. pbstrCallerId [out] - pointer to the place to put the Caller Id
  426. Return Value:
  427. Standard HRESULT code
  428. --*/
  429. {
  430. HRESULT hr = S_OK;
  431. DBG_ENTER (TEXT("CFaxMessageInner::get_CallerId"), hr);
  432. hr = GetBstr(pbstrCallerId, m_bstrCallerId);
  433. if (FAILED(hr))
  434. {
  435. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  436. return hr;
  437. }
  438. return hr;
  439. }
  440. //
  441. //====================== GET ROUTING INFORMATION ======================================
  442. //
  443. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  444. STDMETHODIMP
  445. CFaxMessageInner<T, piid, pcid, FolderType>::get_RoutingInformation(
  446. BSTR *pbstrRoutingInformation
  447. )
  448. /*++
  449. Routine name : CFaxMessageInner::get_RoutingInformation
  450. Routine description:
  451. Return the Routing Information of the Message
  452. Author:
  453. Iv Garber (IvG), May, 2000
  454. Arguments:
  455. pbstrRoutingInformation [out] - pointer to place to put Routing Information
  456. Return Value:
  457. Standard HRESULT code
  458. --*/
  459. {
  460. HRESULT hr = S_OK;
  461. DBG_ENTER (TEXT("CFaxMessageInner::get_RoutingInformation"), hr);
  462. hr = GetBstr(pbstrRoutingInformation, m_bstrRoutingInfo);
  463. if (FAILED(hr))
  464. {
  465. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  466. return hr;
  467. }
  468. return hr;
  469. }
  470. //
  471. //========================= GET TRANSMITTION START TIME ===============================
  472. //
  473. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  474. STDMETHODIMP
  475. CFaxMessageInner<T, piid, pcid, FolderType>::get_TransmissionStart(
  476. DATE *pdateTransmissionStart
  477. )
  478. /*++
  479. Routine name : CFaxMessageInner::get_TransmissionStart
  480. Routine description:
  481. Return Time the Message started its Transmission
  482. Author:
  483. Iv Garber (IvG), May, 2000
  484. Arguments:
  485. pbstrTransmissionStart [out] - pointer to place to put Transmission Start
  486. Return Value:
  487. Standard HRESULT code
  488. --*/
  489. {
  490. HRESULT hr = S_OK;
  491. DBG_ENTER (TEXT("CFaxMessageInner::get_TransmissionStart"), hr);
  492. //
  493. // Check that we can write to the given pointer
  494. //
  495. if (::IsBadWritePtr(pdateTransmissionStart, sizeof(DATE)))
  496. {
  497. //
  498. // Got Bad Ptr
  499. //
  500. hr = E_POINTER;
  501. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  502. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  503. return hr;
  504. }
  505. *pdateTransmissionStart = m_dtTransmissionStart;
  506. return hr;
  507. }
  508. //
  509. //========================= GET TRANSMITTION END TIME ===============================
  510. //
  511. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  512. STDMETHODIMP
  513. CFaxMessageInner<T, piid, pcid, FolderType>::get_TransmissionEnd(
  514. DATE *pdateTransmissionEnd
  515. )
  516. /*++
  517. Routine name : CFaxMessageInner::get_TransmissionEnd
  518. Routine description:
  519. Return Time the Message ended its Transmission
  520. Author:
  521. Iv Garber (IvG), May, 2000
  522. Arguments:
  523. pbstrTransmissionEnd [out] - pointer to place to put Transmission End
  524. Return Value:
  525. Standard HRESULT code
  526. --*/
  527. {
  528. HRESULT hr = S_OK;
  529. DBG_ENTER (TEXT("CFaxMessageInner::get_TransmissionEnd"), hr);
  530. //
  531. // Check that we can write to the given pointer
  532. //
  533. if (::IsBadWritePtr(pdateTransmissionEnd, sizeof(DATE)))
  534. {
  535. //
  536. // Got Bad Ptr
  537. //
  538. hr = E_POINTER;
  539. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  540. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  541. return hr;
  542. }
  543. *pdateTransmissionEnd = m_dtTransmissionEnd;
  544. return hr;
  545. }
  546. //
  547. //========================= GET ORIGINAL SCHEDULED TIME ===============================
  548. //
  549. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  550. STDMETHODIMP
  551. CFaxMessageInner<T, piid, pcid, FolderType>::get_OriginalScheduledTime(
  552. DATE *pdateOriginalScheduledTime
  553. )
  554. /*++
  555. Routine name : CFaxMessageInner::get_OriginalScheduledTime
  556. Routine description:
  557. Return Time the Message was originally scheduled
  558. Author:
  559. Iv Garber (IvG), May, 2000
  560. Arguments:
  561. pbstrOriginalScheduledTime [out] - pointer to place to put Original Scheduled Time
  562. Return Value:
  563. Standard HRESULT code
  564. --*/
  565. {
  566. HRESULT hr = S_OK;
  567. DBG_ENTER (TEXT("CFaxMessageInner::get_OriginalScheduledTime"), hr);
  568. //
  569. // Check that we can write to the given pointer
  570. //
  571. if (::IsBadWritePtr(pdateOriginalScheduledTime, sizeof(DATE)))
  572. {
  573. //
  574. // Got Bad Ptr
  575. //
  576. hr = E_POINTER;
  577. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  578. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  579. return hr;
  580. }
  581. *pdateOriginalScheduledTime = m_dtOriginalScheduledTime;
  582. return hr;
  583. }
  584. //
  585. //========================= GET SUBMISSION TIME ===============================
  586. //
  587. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  588. STDMETHODIMP
  589. CFaxMessageInner<T, piid, pcid, FolderType>::get_SubmissionTime(
  590. DATE *pdateSubmissionTime
  591. )
  592. /*++
  593. Routine name : CFaxMessageInner::get_SubmissionTime
  594. Routine description:
  595. Return Time the Message was submitted
  596. Author:
  597. Iv Garber (IvG), May, 2000
  598. Arguments:
  599. pdateSubmissionTime [out] - pointer to place to put Submission Time
  600. Return Value:
  601. Standard HRESULT code
  602. --*/
  603. {
  604. HRESULT hr = S_OK;
  605. DBG_ENTER (TEXT("CFaxMessageInner::get_SubmissionTime"), hr);
  606. //
  607. // Check that we can write to the given pointer
  608. //
  609. if (::IsBadWritePtr(pdateSubmissionTime, sizeof(DATE)))
  610. {
  611. //
  612. // Got Bad Ptr
  613. //
  614. hr = E_POINTER;
  615. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  616. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  617. return hr;
  618. }
  619. *pdateSubmissionTime = m_dtSubmissionTime;
  620. return hr;
  621. }
  622. //
  623. //====================== GET SUBMISSION ID ================================================
  624. //
  625. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  626. STDMETHODIMP
  627. CFaxMessageInner<T, piid, pcid, FolderType>::get_SubmissionId(
  628. BSTR *pbstrSubmissionId
  629. )
  630. /*++
  631. Routine name : CFaxMessageInner::get_SubmissionId
  632. Routine description:
  633. Return Submission ID of the Message
  634. Author:
  635. Iv Garber (IvG), May, 2000
  636. Arguments:
  637. pbstrSubmissionId [out] - pointer to the place to put the Submission ID
  638. Return Value:
  639. Standard HRESULT code
  640. --*/
  641. {
  642. HRESULT hr = S_OK;
  643. DBG_ENTER (TEXT("CFaxMessageInner::get_SubmissionId"), hr);
  644. hr = GetBstr(pbstrSubmissionId, m_bstrSubmissionId);
  645. if (FAILED(hr))
  646. {
  647. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  648. return hr;
  649. }
  650. return hr;
  651. }
  652. //
  653. //====================== DELETE ================================================
  654. //
  655. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  656. STDMETHODIMP
  657. CFaxMessageInner<T, piid, pcid, FolderType>::Delete()
  658. /*++
  659. Routine name : CFaxMessageInner::Delete
  660. Routine description:
  661. Delete the Message from the Archive
  662. Author:
  663. Iv Garber (IvG), May, 2000
  664. Return Value:
  665. Standard HRESULT code
  666. --*/
  667. {
  668. HRESULT hr = S_OK;
  669. HANDLE hFaxHandle = NULL;
  670. DBG_ENTER (TEXT("CFaxMessageInner::Delete"), hr);
  671. //
  672. // Get Fax Server Handle
  673. //
  674. hr = GetFaxHandle(&hFaxHandle);
  675. if (FAILED(hr))
  676. {
  677. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  678. return hr;
  679. }
  680. if (!FaxRemoveMessage(hFaxHandle, m_dwlMsgId, FolderType))
  681. {
  682. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  683. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  684. CALL_FAIL(GENERAL_ERR,
  685. _T("FaxRemoveMessage(hFaxHandle, m_FaxMsg.dwlMessageId, FolderType)"),
  686. hr);
  687. return hr;
  688. }
  689. return hr;
  690. }
  691. //
  692. //====================== COPY TIFF ================================================
  693. //
  694. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  695. STDMETHODIMP
  696. CFaxMessageInner<T, piid, pcid, FolderType>::CopyTiff(
  697. /*[in]*/ BSTR bstrTiffPath
  698. )
  699. /*++
  700. Routine name : CFaxMessageInner::CopyTiff
  701. Routine description:
  702. Copies the Fax Message Tiff Image to a file on the local computer.
  703. Author:
  704. Iv Garber (IvG), May, 2000
  705. Arguments:
  706. bstrTiffPath [in] - the file to copy to
  707. Return Value:
  708. Standard HRESULT code
  709. --*/
  710. {
  711. HRESULT hr = S_OK;
  712. HANDLE hFaxHandle = NULL;
  713. DBG_ENTER (TEXT("CFaxMessageInner::CopyTiff"), hr, _T("%s"), bstrTiffPath);
  714. //
  715. // Get Fax Server Handle
  716. //
  717. hr = GetFaxHandle(&hFaxHandle);
  718. if (FAILED(hr))
  719. {
  720. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  721. return hr;
  722. }
  723. if (!FaxGetMessageTiff(hFaxHandle, m_dwlMsgId, FolderType, bstrTiffPath))
  724. {
  725. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  726. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  727. CALL_FAIL(GENERAL_ERR,
  728. _T("FaxGetMessageTiff(hFaxHandle, m_FaxMsg.dwlMessageId, FolderType, bstrTiffPath)"),
  729. hr);
  730. return hr;
  731. }
  732. return hr;
  733. }
  734. //
  735. //==================== INIT ===================================================
  736. //
  737. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  738. STDMETHODIMP
  739. CFaxMessageInner<T, piid, pcid, FolderType>::Init(
  740. /*[in]*/ PFAX_MESSAGE pFaxMessage,
  741. IFaxServerInner* pFaxServerInner
  742. )
  743. /*++
  744. Routine name : CFaxMessageInner::Init
  745. Routine description:
  746. Initialize the Message Inner Class : put Message Information and Ptr to Server
  747. Author:
  748. Iv Garber (IvG), May, 2000
  749. Arguments:
  750. pFaxMessage [in] - Message Info
  751. pFaxServerInner [in] - Ptr to Server
  752. Return Value:
  753. Standard HRESULT code
  754. --*/
  755. {
  756. HRESULT hr = S_OK;
  757. DBG_ENTER (TEXT("CFaxMessageInner::Init"), hr);
  758. //
  759. // dwlBroadcastId is DWORDLONG, we need to convert it to the BSTR
  760. //
  761. TCHAR tcBuffer[25];
  762. ::_i64tot(pFaxMessage->dwlBroadcastId, tcBuffer, 16);
  763. m_bstrSubmissionId = tcBuffer;
  764. m_bstrTSID = pFaxMessage->lpctstrTsid;
  765. m_bstrCSID = pFaxMessage->lpctstrCsid;
  766. m_bstrDeviceName = pFaxMessage->lpctstrDeviceName;
  767. m_bstrDocName = pFaxMessage->lpctstrDocumentName;
  768. m_bstrSubject = pFaxMessage->lpctstrSubject;
  769. m_bstrCallerId = pFaxMessage->lpctstrCallerID;
  770. m_bstrRoutingInfo = pFaxMessage->lpctstrRoutingInfo;
  771. m_dwValidityMask = pFaxMessage->dwValidityMask;
  772. if ( (!m_bstrSubmissionId) ||
  773. (pFaxMessage->lpctstrTsid && !m_bstrTSID) ||
  774. (pFaxMessage->lpctstrCsid && !m_bstrCSID) ||
  775. (pFaxMessage->lpctstrDeviceName && !m_bstrDeviceName) ||
  776. (pFaxMessage->lpctstrDocumentName && !m_bstrDocName) ||
  777. (pFaxMessage->lpctstrSubject && !m_bstrSubject) ||
  778. (pFaxMessage->lpctstrCallerID && !m_bstrCallerId) ||
  779. (pFaxMessage->lpctstrRoutingInfo && !m_bstrRoutingInfo) )
  780. {
  781. //
  782. // Not Enough Memory
  783. //
  784. hr = E_OUTOFMEMORY;
  785. AtlReportError(*pcid, IDS_ERROR_OUTOFMEMORY, *piid, hr);
  786. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator="), hr);
  787. return hr;
  788. }
  789. m_lSize = pFaxMessage->dwSize;
  790. m_lPages = pFaxMessage->dwPageCount;
  791. m_Priority = FAX_PRIORITY_TYPE_ENUM(pFaxMessage->Priority);
  792. m_lRetries = pFaxMessage->dwRetries;
  793. m_dwlMsgId = pFaxMessage->dwlMessageId;
  794. //
  795. // convert time fields to local variant date
  796. //
  797. if (m_dwValidityMask & FAX_JOB_FIELD_TRANSMISSION_START_TIME)
  798. {
  799. hr = SystemTime2LocalDate(pFaxMessage->tmTransmissionStartTime, &m_dtTransmissionStart);
  800. if (FAILED(hr))
  801. {
  802. hr = E_FAIL;
  803. CALL_FAIL(GENERAL_ERR, _T("SystemTime2LocalDate(TransmissionStartTime)"), hr);
  804. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  805. return hr;
  806. }
  807. }
  808. else
  809. {
  810. m_dtTransmissionStart = DATE(0);
  811. }
  812. if (m_dwValidityMask & FAX_JOB_FIELD_TRANSMISSION_END_TIME)
  813. {
  814. hr = SystemTime2LocalDate(pFaxMessage->tmTransmissionEndTime, &m_dtTransmissionEnd);
  815. if (FAILED(hr))
  816. {
  817. hr = E_FAIL;
  818. CALL_FAIL(GENERAL_ERR, _T("SystemTime2LocalDate(TransmissionEndTime)"), hr);
  819. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  820. return hr;
  821. }
  822. }
  823. else
  824. {
  825. m_dtTransmissionStart = DATE(0);
  826. }
  827. if (m_dwValidityMask & FAX_JOB_FIELD_ORIGINAL_SCHEDULE_TIME)
  828. {
  829. hr = SystemTime2LocalDate(pFaxMessage->tmOriginalScheduleTime, &m_dtOriginalScheduledTime);
  830. if (FAILED(hr))
  831. {
  832. hr = E_FAIL;
  833. CALL_FAIL(GENERAL_ERR, _T("SystemTime2LocalDate(OriginalScheduledTime)"), hr);
  834. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  835. return hr;
  836. }
  837. }
  838. else
  839. {
  840. m_dtTransmissionStart = DATE(0);
  841. }
  842. if (m_dwValidityMask & FAX_JOB_FIELD_SUBMISSION_TIME)
  843. {
  844. hr = SystemTime2LocalDate(pFaxMessage->tmSubmissionTime, &m_dtSubmissionTime);
  845. if (FAILED(hr))
  846. {
  847. hr = E_FAIL;
  848. CALL_FAIL(GENERAL_ERR, _T("SystemTime2LocalDate(SubmissionTime)"), hr);
  849. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  850. return hr;
  851. }
  852. }
  853. else
  854. {
  855. m_dtTransmissionStart = DATE(0);
  856. }
  857. hr = CFaxInitInnerAddRef::Init(pFaxServerInner);
  858. return hr;
  859. }
  860. //
  861. //====================== GET SENDER ================================================
  862. //
  863. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  864. STDMETHODIMP
  865. CFaxMessageInner<T, piid, pcid, FolderType>::get_Sender(
  866. /*[out, retval] */IFaxSender **ppFaxSender
  867. )
  868. /*++
  869. Routine name : CFaxMessageInner::get_Sender
  870. Routine description:
  871. Return Message Sender Information
  872. Author:
  873. Iv Garber (IvG), May, 2000
  874. Arguments:
  875. ppFaxSender [out] - Ptr to the Place to put Sender object
  876. Return Value:
  877. Standard HRESULT code
  878. --*/
  879. {
  880. HRESULT hr = S_OK;
  881. DBG_ENTER (TEXT("CFaxMessageInner::get_Sender"), hr);
  882. //
  883. // Check that we can write to the given pointer
  884. //
  885. if (::IsBadWritePtr(ppFaxSender, sizeof(IFaxSender* )))
  886. {
  887. //
  888. // got bad pointer
  889. //
  890. hr = E_POINTER;
  891. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  892. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  893. return hr;
  894. }
  895. if (!m_pSender)
  896. {
  897. //
  898. // We have been called for the First Time. Bring Sender's data from the Server
  899. //
  900. //
  901. // Get Fax Server Handle
  902. //
  903. HANDLE hFaxHandle = NULL;
  904. hr = GetFaxHandle(&hFaxHandle);
  905. if (FAILED(hr))
  906. {
  907. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  908. return hr;
  909. }
  910. //
  911. // Get Sender Info
  912. //
  913. CFaxPtr<FAX_PERSONAL_PROFILE> pPersonalProfile;
  914. if (!FaxGetSenderInfo(hFaxHandle, m_dwlMsgId, FolderType, &pPersonalProfile))
  915. {
  916. //
  917. // Failed to get Sender Info
  918. //
  919. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  920. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  921. CALL_FAIL(GENERAL_ERR, _T("FaxGetSenderInfo()"), hr);
  922. return hr;
  923. }
  924. //
  925. // Check that pPersonalProfile is valid
  926. //
  927. if (!pPersonalProfile || pPersonalProfile->dwSizeOfStruct != sizeof(FAX_PERSONAL_PROFILE))
  928. {
  929. //
  930. // Failed to Get Personal Profile
  931. //
  932. hr = E_FAIL;
  933. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  934. CALL_FAIL(GENERAL_ERR, _T("Invalid pPersonalProfile"), hr);
  935. return hr;
  936. }
  937. //
  938. // Create Sender Object
  939. //
  940. hr = CComObject<CFaxSender>::CreateInstance(&m_pSender);
  941. if (FAILED(hr) || !m_pSender)
  942. {
  943. hr = E_OUTOFMEMORY;
  944. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  945. CALL_FAIL(GENERAL_ERR, _T("CComObject<CFaxSender>::CreateInstance(&m_pSender)"), hr);
  946. return hr;
  947. }
  948. //
  949. // We want Sender object to live
  950. //
  951. m_pSender->AddRef();
  952. //
  953. // Fill the Data
  954. //
  955. hr = m_pSender->PutSenderProfile(pPersonalProfile);
  956. if (FAILED(hr))
  957. {
  958. //
  959. // Failed to fill the Sender's Object with RPC's data
  960. //
  961. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  962. CALL_FAIL(GENERAL_ERR, _T("m_pSender->PutSenderProfile(pPersonalProfile)"), hr);
  963. m_pSender->Release();
  964. m_pSender = NULL;
  965. return hr;
  966. }
  967. }
  968. //
  969. // Return Sender Object to Caller
  970. //
  971. hr = m_pSender->QueryInterface(ppFaxSender);
  972. if (FAILED(hr))
  973. {
  974. //
  975. // Failed to query interface
  976. //
  977. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  978. CALL_FAIL(MEM_ERR, _T("CComObject<CFaxSender>::QueryInterface()"), hr);
  979. return hr;
  980. }
  981. return hr;
  982. }
  983. //
  984. //====================== GET RECIPIENT ================================================
  985. //
  986. template<class T, const IID* piid, const CLSID *pcid, FAX_ENUM_MESSAGE_FOLDER FolderType>
  987. STDMETHODIMP
  988. CFaxMessageInner<T, piid, pcid, FolderType>::get_Recipient(
  989. /*[out, retval] */IFaxRecipient **ppRecipient
  990. )
  991. /*++
  992. Routine name : CFaxMessageInner::get_Recipient
  993. Routine description:
  994. Return Message Recipient object
  995. Author:
  996. Iv Garber (IvG), May, 2000
  997. Arguments:
  998. ppFaxRecipient [out] - Ptr to the Place to put Recipient object
  999. Return Value:
  1000. Standard HRESULT code
  1001. --*/
  1002. {
  1003. HRESULT hr = S_OK;
  1004. DBG_ENTER (_T("CFaxMessageInner::get_Recipient"), hr);
  1005. //
  1006. // Check that we can write to the given pointer
  1007. //
  1008. if (::IsBadWritePtr(ppRecipient, sizeof(IFaxRecipient* )))
  1009. {
  1010. //
  1011. // got bad pointer
  1012. //
  1013. hr = E_POINTER;
  1014. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  1015. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  1016. return hr;
  1017. }
  1018. if (!m_pRecipient)
  1019. {
  1020. //
  1021. // We have been called for the first time
  1022. //
  1023. //
  1024. // Get Fax Server Handle
  1025. //
  1026. HANDLE hFaxHandle = NULL;
  1027. hr = GetFaxHandle(&hFaxHandle);
  1028. if (FAILED(hr))
  1029. {
  1030. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  1031. return hr;
  1032. }
  1033. //
  1034. // Get Recipient Info
  1035. //
  1036. CFaxPtr<FAX_PERSONAL_PROFILE> pPersonalProfile;
  1037. if (!FaxGetRecipientInfo(hFaxHandle, m_dwlMsgId, FolderType, &pPersonalProfile))
  1038. {
  1039. //
  1040. // Failed to get Recipient Info
  1041. //
  1042. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  1043. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  1044. CALL_FAIL(GENERAL_ERR, _T("FaxGetRecipientInfo()"), hr);
  1045. return hr;
  1046. }
  1047. //
  1048. // Check that pPersonalProfile is valid
  1049. //
  1050. if (!pPersonalProfile || pPersonalProfile->dwSizeOfStruct != sizeof(FAX_PERSONAL_PROFILE))
  1051. {
  1052. //
  1053. // Failed to Get Personal Profile
  1054. //
  1055. hr = E_FAIL;
  1056. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  1057. CALL_FAIL(GENERAL_ERR, _T("Invalid pPersonalProfile"), hr);
  1058. return hr;
  1059. }
  1060. //
  1061. // Create Recipient Object
  1062. //
  1063. hr = CComObject<CFaxRecipient>::CreateInstance(&m_pRecipient);
  1064. if (FAILED(hr) || !m_pRecipient)
  1065. {
  1066. hr = E_OUTOFMEMORY;
  1067. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  1068. CALL_FAIL(GENERAL_ERR, _T("CComObject<CFaxRecipient>::CreateInstance(&m_pRecipient)"), hr);
  1069. return hr;
  1070. }
  1071. //
  1072. // We want Recipient object to live
  1073. //
  1074. m_pRecipient->AddRef();
  1075. //
  1076. // Fill the Data
  1077. //
  1078. hr = m_pRecipient->PutRecipientProfile(pPersonalProfile);
  1079. if (FAILED(hr))
  1080. {
  1081. //
  1082. // Failed to fill the Recipient's Object with RPC's data
  1083. //
  1084. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  1085. CALL_FAIL(GENERAL_ERR, _T("m_pRecipient->PutRecipientProfile(pPersonalProfile)"), hr);
  1086. m_pRecipient->Release();
  1087. m_pRecipient = NULL;
  1088. return hr;
  1089. }
  1090. }
  1091. //
  1092. // Return Recipient Object to Caller
  1093. //
  1094. hr = m_pRecipient->QueryInterface(ppRecipient);
  1095. if (FAILED(hr))
  1096. {
  1097. //
  1098. // Failed to Query Interface
  1099. //
  1100. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  1101. CALL_FAIL(MEM_ERR, _T("CComObject<CFaxRecipient>::QueryInterface()"), hr);
  1102. return hr;
  1103. }
  1104. return hr;
  1105. }
  1106. #endif // __FAXMESSAGEINNER_H_