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.

1192 lines
24 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxReceiptOptions.cpp
  5. Abstract:
  6. Implementation of Fax Receipts Options Class.
  7. Author:
  8. Iv Garber (IvG) May, 2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "FaxComEx.h"
  13. #include "FaxReceiptOptions.h"
  14. //
  15. //========================= USE FOR INBOUND ROUTING ====================================================
  16. //
  17. STDMETHODIMP
  18. CFaxReceiptOptions::put_UseForInboundRouting(
  19. VARIANT_BOOL bUseForInboundRouting
  20. )
  21. /*++
  22. Routine name : CFaxReceiptOptions::put_UseForInboundRouting
  23. Routine description:
  24. Set flag indicating whether current IFaxReceiptsOptions configuration should be used within the MS Routing
  25. Extension to route the incoming faxed through SMTP e-mail.
  26. Author:
  27. Iv Garber (IvG), Feb, 2001
  28. Arguments:
  29. bUseForInboundRouting [out] - the flag. See description
  30. Return Value:
  31. Standard HRESULT code
  32. --*/
  33. {
  34. HRESULT hr = S_OK;
  35. DBG_ENTER (TEXT("CFaxReceiptOptions::put_UseForInboundRouting"), hr);
  36. //
  37. // Sync with the Server for the first time
  38. //
  39. if (!m_bInited)
  40. {
  41. hr = Refresh();
  42. if (FAILED(hr))
  43. {
  44. return hr;
  45. }
  46. }
  47. m_bUseForInboundRouting = bUseForInboundRouting;
  48. return hr;
  49. }
  50. //
  51. //========================= USE FOR INBOUND ROUTING ====================================================
  52. //
  53. STDMETHODIMP
  54. CFaxReceiptOptions::get_UseForInboundRouting(
  55. VARIANT_BOOL *pbUseForInboundRouting
  56. )
  57. /*++
  58. Routine name : CFaxReceiptOptions::get_UseForInboundRouting
  59. Routine description:
  60. Return flag indicating whether current IFaxReceiptsOptions configuration should be used within the MS Routing
  61. Extension to route the incoming faxed through SMTP e-mail.
  62. Author:
  63. Iv Garber (IvG), Feb, 2001
  64. Arguments:
  65. pbUseForInboundRouting [out] - the flag. See description
  66. Return Value:
  67. Standard HRESULT code
  68. --*/
  69. {
  70. HRESULT hr = S_OK;
  71. DBG_ENTER (TEXT("CFaxReceiptOptions::get_UseForInboundRouting"), hr);
  72. //
  73. // Sync with the Server for the first time
  74. //
  75. if (!m_bInited)
  76. {
  77. hr = Refresh();
  78. if (FAILED(hr))
  79. {
  80. return hr;
  81. }
  82. }
  83. hr = GetVariantBool(pbUseForInboundRouting, m_bUseForInboundRouting);
  84. if (FAILED(hr))
  85. {
  86. AtlReportError(CLSID_FaxReceiptOptions,
  87. GetErrorMsgId(hr),
  88. IID_IFaxReceiptOptions,
  89. hr);
  90. return hr;
  91. }
  92. return hr;
  93. }
  94. //
  95. //========================= ALLOWED RECEIPTS ====================================================
  96. //
  97. STDMETHODIMP
  98. CFaxReceiptOptions::get_AllowedReceipts(
  99. FAX_RECEIPT_TYPE_ENUM *pAllowedReceipts
  100. )
  101. /*++
  102. Routine name : CFaxReceiptOptions::get_AllowedReceipts
  103. Routine description:
  104. Return the Receipt Types allowed by the Server
  105. Author:
  106. Iv Garber (IvG), Jul, 2000
  107. Arguments:
  108. pAllowedReceipts [out] - the Bit-Wise Combination of Allowed Receipt Types
  109. Return Value:
  110. Standard HRESULT code
  111. --*/
  112. {
  113. HRESULT hr = S_OK;
  114. DBG_ENTER (TEXT("CFaxReceiptOptions::get_AllowedReceipts"), hr);
  115. //
  116. // Check that we can write to the given pointer
  117. //
  118. if (::IsBadWritePtr(pAllowedReceipts, sizeof(FAX_RECEIPT_TYPE_ENUM)))
  119. {
  120. //
  121. // Got Bad Return Pointer
  122. //
  123. hr = E_POINTER;
  124. AtlReportError(CLSID_FaxReceiptOptions, IDS_ERROR_INVALID_ARGUMENT, IID_IFaxReceiptOptions, hr);
  125. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  126. return hr;
  127. }
  128. //
  129. // Sync with the Server for the first time
  130. //
  131. if (!m_bInited)
  132. {
  133. hr = Refresh();
  134. if (FAILED(hr))
  135. {
  136. return hr;
  137. }
  138. }
  139. *pAllowedReceipts = FAX_RECEIPT_TYPE_ENUM(m_dwAllowedReceipts);
  140. return hr;
  141. }
  142. STDMETHODIMP
  143. CFaxReceiptOptions::put_AllowedReceipts(
  144. FAX_RECEIPT_TYPE_ENUM AllowedReceipts
  145. )
  146. /*++
  147. Routine name : CFaxReceiptOptions::put_AllowedReceipts
  148. Routine description:
  149. Change the Receipts Types on Server
  150. Author:
  151. Iv Garber (IvG), Jul, 2000
  152. Arguments:
  153. AllowedReceipts [in] - the new Bit-Wise Combination of Allowed Receipt Types
  154. Return Value:
  155. Standard HRESULT code
  156. --*/
  157. {
  158. HRESULT hr = S_OK;
  159. DBG_ENTER (_T("CFaxReceiptOptions::put_AllowedReceipts"), hr, _T("%d"), AllowedReceipts);
  160. //
  161. // Check that value is valid
  162. //
  163. if ((AllowedReceipts != frtNONE) && (AllowedReceipts & ~(frtMAIL | frtMSGBOX))) // Invalid bits
  164. {
  165. hr = E_INVALIDARG;
  166. AtlReportError(CLSID_FaxReceiptOptions, IDS_ERROR_INVALID_ARGUMENT, IID_IFaxReceiptOptions, hr);
  167. CALL_FAIL(GENERAL_ERR, _T("(AllowedReceipts is wrong)"), hr);
  168. return hr;
  169. }
  170. //
  171. // Sync with the Server for the first time
  172. //
  173. if (!m_bInited)
  174. {
  175. hr = Refresh();
  176. if (FAILED(hr))
  177. {
  178. return hr;
  179. }
  180. }
  181. m_dwAllowedReceipts = AllowedReceipts;
  182. return hr;
  183. }
  184. //
  185. //========================= SMTP PORT ====================================================
  186. //
  187. STDMETHODIMP
  188. CFaxReceiptOptions::get_SMTPPort(
  189. long *plSMTPPort
  190. )
  191. /*++
  192. Routine name : CFaxReceiptOptions::get_SMTPPort
  193. Routine description:
  194. Return the SMTPPort
  195. Author:
  196. Iv Garber (IvG), Apr, 2000
  197. Arguments:
  198. plSMTPPort [out] - the Current SMTPPort
  199. Return Value:
  200. Standard HRESULT code
  201. --*/
  202. {
  203. HRESULT hr = S_OK;
  204. DBG_ENTER (TEXT("CFaxReceiptOptions::get_SMTPPort"), hr);
  205. //
  206. // Sync with the Server for the first time
  207. //
  208. if (!m_bInited)
  209. {
  210. hr = Refresh();
  211. if (FAILED(hr))
  212. {
  213. return hr;
  214. }
  215. }
  216. hr = GetLong(plSMTPPort, m_dwPort);
  217. if (FAILED(hr))
  218. {
  219. AtlReportError(CLSID_FaxReceiptOptions, GetErrorMsgId(hr), IID_IFaxReceiptOptions, hr);
  220. return hr;
  221. }
  222. return hr;
  223. }
  224. STDMETHODIMP
  225. CFaxReceiptOptions::put_SMTPPort(
  226. long lSMTPPort
  227. )
  228. /*++
  229. Routine name : CFaxReceiptOptions::put_SMTPPort
  230. Routine description:
  231. Set new SMTPPort for Receipts
  232. Author:
  233. Iv Garber (IvG), Apr, 2000
  234. Arguments:
  235. SMTPPort [in] - the new Receipts SMTPPort
  236. Return Value:
  237. Standard HRESULT code
  238. --*/
  239. {
  240. HRESULT hr = S_OK;
  241. DBG_ENTER (_T("CFaxReceiptOptions::put_SMTPPort"), hr, _T("%d"), lSMTPPort);
  242. //
  243. // Sync with the Server for the first time
  244. //
  245. if (!m_bInited)
  246. {
  247. hr = Refresh();
  248. if (FAILED(hr))
  249. {
  250. return hr;
  251. }
  252. }
  253. m_dwPort = lSMTPPort;
  254. return hr;
  255. }
  256. //
  257. //========================= TYPE ====================================================
  258. //
  259. STDMETHODIMP
  260. CFaxReceiptOptions::get_AuthenticationType(
  261. FAX_SMTP_AUTHENTICATION_TYPE_ENUM *pType
  262. )
  263. /*++
  264. Routine name : CFaxReceiptOptions::get_AuthenticationType
  265. Routine description:
  266. Return the Authentication Type supported by the Server
  267. Author:
  268. Iv Garber (IvG), Jul, 2000
  269. Arguments:
  270. pType [out] - the result
  271. Return Value:
  272. Standard HRESULT code
  273. --*/
  274. {
  275. HRESULT hr = S_OK;
  276. DBG_ENTER (TEXT("CFaxReceiptOptions::get_AuthenticationType"), hr);
  277. //
  278. // Check that we can write to the given pointer
  279. //
  280. if (::IsBadWritePtr(pType, sizeof(FAX_SMTP_AUTHENTICATION_TYPE_ENUM)))
  281. {
  282. //
  283. // Got Bad Return Pointer
  284. //
  285. hr = E_POINTER;
  286. AtlReportError(CLSID_FaxReceiptOptions, IDS_ERROR_INVALID_ARGUMENT, IID_IFaxReceiptOptions, hr);
  287. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  288. return hr;
  289. }
  290. //
  291. // Sync with the Server for the first time
  292. //
  293. if (!m_bInited)
  294. {
  295. hr = Refresh();
  296. if (FAILED(hr))
  297. {
  298. return hr;
  299. }
  300. }
  301. *pType = m_AuthType;
  302. return hr;
  303. }
  304. STDMETHODIMP
  305. CFaxReceiptOptions::put_AuthenticationType(
  306. FAX_SMTP_AUTHENTICATION_TYPE_ENUM Type
  307. )
  308. /*++
  309. Routine name : CFaxReceiptOptions::put_AuthenticationType
  310. Routine description:
  311. Set new Authenticatin Type for the Server
  312. Author:
  313. Iv Garber (IvG), Jul, 2000
  314. Arguments:
  315. Type [in] - the new Authentication type for the Server
  316. Return Value:
  317. Standard HRESULT code
  318. --*/
  319. {
  320. HRESULT hr = S_OK;
  321. DBG_ENTER (_T("CFaxReceiptOptions::put_AuthenticationType"), hr, _T("%d"), Type);
  322. //
  323. // Sync with the Server for the first time
  324. //
  325. if (!m_bInited)
  326. {
  327. hr = Refresh();
  328. if (FAILED(hr))
  329. {
  330. return hr;
  331. }
  332. }
  333. //
  334. // Check Ranges
  335. //
  336. if (Type < fsatANONYMOUS || Type > fsatNTLM)
  337. {
  338. //
  339. // Out of the Range
  340. //
  341. hr = E_INVALIDARG;
  342. AtlReportError(CLSID_FaxReceiptOptions, IDS_ERROR_OUTOFRANGE, IID_IFaxReceiptOptions, hr);
  343. CALL_FAIL(GENERAL_ERR, _T("Type is out of the Range"), hr);
  344. return hr;
  345. }
  346. m_AuthType = FAX_SMTP_AUTHENTICATION_TYPE_ENUM(Type);
  347. return hr;
  348. }
  349. //
  350. //============================= SMTP SENDER ====================================
  351. //
  352. STDMETHODIMP
  353. CFaxReceiptOptions::put_SMTPSender(
  354. BSTR bstrSMTPSender
  355. )
  356. /*++
  357. Routine name : CFaxReceiptOptions::put_SMTPSender
  358. Routine description:
  359. Set the SMTPSender
  360. Author:
  361. Iv Garber (IvG), Apr, 2000
  362. Arguments:
  363. bstrSMTPSender [in] - the new value of SMTPSender
  364. Return Value:
  365. Standard HRESULT code
  366. --*/
  367. {
  368. HRESULT hr = S_OK;
  369. DBG_ENTER (_T("CFaxReceiptOptions::put_SMTPSender"), hr, _T("%s"), bstrSMTPSender);
  370. //
  371. // Sync with the Server for the first time
  372. //
  373. if (!m_bInited)
  374. {
  375. hr = Refresh();
  376. if (FAILED(hr))
  377. {
  378. return hr;
  379. }
  380. }
  381. m_bstrSender = bstrSMTPSender;
  382. if (bstrSMTPSender && !m_bstrSender)
  383. {
  384. //
  385. // not enough memory
  386. //
  387. hr = E_OUTOFMEMORY;
  388. AtlReportError(CLSID_FaxReceiptOptions,
  389. IDS_ERROR_OUTOFMEMORY,
  390. IID_IFaxReceiptOptions,
  391. hr);
  392. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator=()"), hr);
  393. return hr;
  394. }
  395. return hr;
  396. }
  397. STDMETHODIMP
  398. CFaxReceiptOptions::get_SMTPSender(
  399. BSTR *pbstrSMTPSender
  400. )
  401. /*++
  402. Routine name : CFaxReceiptOptions::get_SMTPSender
  403. Routine description:
  404. Return the SMTP Sender
  405. Author:
  406. Iv Garber (IvG), Apr, 2000
  407. Arguments:
  408. pbstrSMTPSender [out] - the SMTPSender
  409. Return Value:
  410. Standard HRESULT code
  411. --*/
  412. {
  413. HRESULT hr = S_OK;
  414. DBG_ENTER (TEXT("CFaxReceiptOptions::get_SMTPSender"), hr);
  415. //
  416. // Sync with the Server for the first time
  417. //
  418. if (!m_bInited)
  419. {
  420. hr = Refresh();
  421. if (FAILED(hr))
  422. {
  423. return hr;
  424. }
  425. }
  426. hr = GetBstr(pbstrSMTPSender, m_bstrSender);
  427. if (FAILED(hr))
  428. {
  429. AtlReportError(CLSID_FaxReceiptOptions, GetErrorMsgId(hr), IID_IFaxReceiptOptions, hr);
  430. return hr;
  431. }
  432. return hr;
  433. }
  434. //
  435. //============================= SMTP USER ====================================
  436. //
  437. STDMETHODIMP
  438. CFaxReceiptOptions::put_SMTPUser(
  439. BSTR bstrSMTPUser
  440. )
  441. /*++
  442. Routine name : CFaxReceiptOptions::put_SMTPUser
  443. Routine description:
  444. Set the SMTPUser
  445. Author:
  446. Iv Garber (IvG), Apr, 2000
  447. Arguments:
  448. bstrSMTPUser [in] - the new value of SMTPUser
  449. Return Value:
  450. Standard HRESULT code
  451. --*/
  452. {
  453. HRESULT hr = S_OK;
  454. DBG_ENTER (_T("CFaxReceiptOptions::put_SMTPUser"), hr, _T("%s"), bstrSMTPUser);
  455. //
  456. // Sync with the Server for the first time
  457. //
  458. if (!m_bInited)
  459. {
  460. hr = Refresh();
  461. if (FAILED(hr))
  462. {
  463. return hr;
  464. }
  465. }
  466. m_bstrUser = bstrSMTPUser;
  467. if (bstrSMTPUser && !m_bstrUser)
  468. {
  469. //
  470. // not enough memory
  471. //
  472. hr = E_OUTOFMEMORY;
  473. AtlReportError(CLSID_FaxReceiptOptions,
  474. IDS_ERROR_OUTOFMEMORY,
  475. IID_IFaxReceiptOptions,
  476. hr);
  477. CALL_FAIL(MEM_ERR, _T("::SysAllocString()"), hr);
  478. return hr;
  479. }
  480. return hr;
  481. }
  482. STDMETHODIMP
  483. CFaxReceiptOptions::get_SMTPUser(
  484. BSTR *pbstrSMTPUser
  485. )
  486. /*++
  487. Routine name : CFaxReceiptOptions::get_SMTPUser
  488. Routine description:
  489. Return the SMTP User
  490. Author:
  491. Iv Garber (IvG), Apr, 2000
  492. Arguments:
  493. pbstrSMTPUser [out] - the SMTPUser
  494. Return Value:
  495. Standard HRESULT code
  496. --*/
  497. {
  498. HRESULT hr = S_OK;
  499. DBG_ENTER (TEXT("CFaxReceiptOptions::get_SMTPUser"), hr);
  500. //
  501. // Sync with the Server for the first time
  502. //
  503. if (!m_bInited)
  504. {
  505. hr = Refresh();
  506. if (FAILED(hr))
  507. {
  508. return hr;
  509. }
  510. }
  511. hr = GetBstr(pbstrSMTPUser, m_bstrUser);
  512. if (FAILED(hr))
  513. {
  514. AtlReportError(CLSID_FaxReceiptOptions, GetErrorMsgId(hr), IID_IFaxReceiptOptions, hr);
  515. return hr;
  516. }
  517. return hr;
  518. }
  519. //
  520. //============================= SMTP PASSWORD ====================================
  521. //
  522. STDMETHODIMP
  523. CFaxReceiptOptions::put_SMTPPassword(
  524. BSTR bstrSMTPPassword
  525. )
  526. /*++
  527. Routine name : CFaxReceiptOptions::put_SMTPPassword
  528. Routine description:
  529. Set the SMTPPassword
  530. Author:
  531. Iv Garber (IvG), Apr, 2000
  532. Arguments:
  533. bstrSMTPPassword [in] - the new value of SMTPPassword
  534. Return Value:
  535. Standard HRESULT code
  536. --*/
  537. {
  538. HRESULT hr = S_OK;
  539. DBG_ENTER (_T("CFaxReceiptOptions::put_SMTPPassword"), hr, _T("%s"), bstrSMTPPassword);
  540. //
  541. // Sync with the Server for the first time
  542. //
  543. if (!m_bInited)
  544. {
  545. hr = Refresh();
  546. if (FAILED(hr))
  547. {
  548. return hr;
  549. }
  550. }
  551. SecureZeroMemory(m_bstrPassword.m_str, (m_bstrPassword.Length() * sizeof(OLECHAR)));
  552. m_bstrPassword = bstrSMTPPassword;
  553. if (bstrSMTPPassword && !m_bstrPassword)
  554. {
  555. //
  556. // not enough memory
  557. //
  558. hr = E_OUTOFMEMORY;
  559. AtlReportError(CLSID_FaxReceiptOptions,
  560. IDS_ERROR_OUTOFMEMORY,
  561. IID_IFaxReceiptOptions,
  562. hr);
  563. CALL_FAIL(MEM_ERR, _T("::SysAllocString()"), hr);
  564. return hr;
  565. }
  566. m_bPasswordDirty = true;
  567. return hr;
  568. } // CFaxReceiptOptions::put_SMTPPassword
  569. STDMETHODIMP
  570. CFaxReceiptOptions::get_SMTPPassword(
  571. BSTR *pbstrSMTPPassword
  572. )
  573. /*++
  574. Routine name : CFaxReceiptOptions::get_SMTPPassword
  575. Routine description:
  576. Return the SMTP Password
  577. Author:
  578. Iv Garber (IvG), Apr, 2000
  579. Arguments:
  580. pbstrSMTPPassword [out] - the SMTPPassword
  581. Return Value:
  582. Standard HRESULT code
  583. --*/
  584. {
  585. HRESULT hr = S_OK;
  586. DBG_ENTER (TEXT("CFaxReceiptOptions::get_SMTPPassword"), hr);
  587. //
  588. // Sync with the Server for the first time
  589. //
  590. if (!m_bInited)
  591. {
  592. hr = Refresh();
  593. if (FAILED(hr))
  594. {
  595. return hr;
  596. }
  597. }
  598. hr = GetBstr(pbstrSMTPPassword, m_bstrPassword);
  599. if (FAILED(hr))
  600. {
  601. AtlReportError(CLSID_FaxReceiptOptions, GetErrorMsgId(hr), IID_IFaxReceiptOptions, hr);
  602. return hr;
  603. }
  604. return hr;
  605. }
  606. //
  607. //============================= SMTP SERVER ====================================
  608. //
  609. STDMETHODIMP
  610. CFaxReceiptOptions::put_SMTPServer(
  611. BSTR bstrSMTPServer
  612. )
  613. /*++
  614. Routine name : CFaxReceiptOptions::put_SMTPServer
  615. Routine description:
  616. Set the SMTPServer
  617. Author:
  618. Iv Garber (IvG), Apr, 2000
  619. Arguments:
  620. bstrSMTPServer [in] - the new value of SMTPServer
  621. Return Value:
  622. Standard HRESULT code
  623. --*/
  624. {
  625. HRESULT hr = S_OK;
  626. DBG_ENTER (_T("CFaxReceiptOptions::put_SMTPServer"), hr, _T("%s"), bstrSMTPServer);
  627. //
  628. // Sync with the Server for the first time
  629. //
  630. if (!m_bInited)
  631. {
  632. hr = Refresh();
  633. if (FAILED(hr))
  634. {
  635. return hr;
  636. }
  637. }
  638. m_bstrServer = bstrSMTPServer;
  639. if (bstrSMTPServer && !m_bstrServer)
  640. {
  641. //
  642. // not enough memory
  643. //
  644. hr = E_OUTOFMEMORY;
  645. AtlReportError(CLSID_FaxReceiptOptions,
  646. IDS_ERROR_OUTOFMEMORY,
  647. IID_IFaxReceiptOptions,
  648. hr);
  649. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator=()"), hr);
  650. return hr;
  651. }
  652. return hr;
  653. }
  654. STDMETHODIMP
  655. CFaxReceiptOptions::get_SMTPServer(
  656. BSTR *pbstrSMTPServer
  657. )
  658. /*++
  659. Routine name : CFaxReceiptOptions::get_SMTPServer
  660. Routine description:
  661. Return the SMTP Server
  662. Author:
  663. Iv Garber (IvG), Apr, 2000
  664. Arguments:
  665. pbstrSMTPServer [out] - the SMTPServer
  666. Return Value:
  667. Standard HRESULT code
  668. --*/
  669. {
  670. HRESULT hr = S_OK;
  671. DBG_ENTER (TEXT("CFaxReceiptOptions::get_SMTPServer"), hr);
  672. //
  673. // Sync with the Server for the first time
  674. //
  675. if (!m_bInited)
  676. {
  677. hr = Refresh();
  678. if (FAILED(hr))
  679. {
  680. return hr;
  681. }
  682. }
  683. hr = GetBstr(pbstrSMTPServer, m_bstrServer);
  684. if (FAILED(hr))
  685. {
  686. AtlReportError(CLSID_FaxReceiptOptions, GetErrorMsgId(hr), IID_IFaxReceiptOptions, hr);
  687. return hr;
  688. }
  689. return hr;
  690. }
  691. //
  692. //==================== SAVE ========================================
  693. //
  694. STDMETHODIMP
  695. CFaxReceiptOptions::Save(
  696. )
  697. /*++
  698. Routine name : CFaxReceiptOptions::Save
  699. Routine description:
  700. Save current Receipt Options at the Server.
  701. Author:
  702. Iv Garber (IvG), May, 2000
  703. Return Value:
  704. Standard HRESULT code
  705. --*/
  706. {
  707. HRESULT hr = S_OK;
  708. DBG_ENTER(_T("CFaxReceiptOptions::Save"), hr);
  709. if (!m_bInited)
  710. {
  711. //
  712. // nothing was done to the Receipt Options
  713. //
  714. return hr;
  715. }
  716. if (m_dwAllowedReceipts & frtMAIL)
  717. {
  718. //
  719. // check validity of values
  720. //
  721. switch(m_AuthType)
  722. {
  723. case fsatNTLM:
  724. case fsatBASIC:
  725. if (m_bstrUser.Length() < 1)
  726. {
  727. hr = E_FAIL;
  728. AtlReportError(CLSID_FaxReceiptOptions, IDS_ERROR_NOUSERPASSWORD, IID_IFaxReceiptOptions, hr);
  729. CALL_FAIL(GENERAL_ERR, _T("ReceiptOptions = SMTP_NTLM/BASIC + User/Password is empty"), hr);
  730. return hr;
  731. }
  732. // no break, continue to SMTP_ANONYMOUS case
  733. case fsatANONYMOUS:
  734. if ((m_bstrServer.Length() < 1) || (m_bstrSender.Length() < 1) || m_dwPort < 1)
  735. {
  736. hr = E_FAIL;
  737. AtlReportError(CLSID_FaxReceiptOptions, IDS_ERROR_NOSERVERSENDERPORT, IID_IFaxReceiptOptions, hr);
  738. CALL_FAIL(GENERAL_ERR, _T("ReceiptOptions = SMTP_... + Server/Sender/Port is empty"), hr);
  739. return hr;
  740. }
  741. break;
  742. default:
  743. //
  744. // assert (FALSE)
  745. //
  746. ATLASSERT(m_AuthType == fsatANONYMOUS);
  747. break;
  748. }
  749. }
  750. //
  751. // Get Fax Server Handle
  752. //
  753. HANDLE hFaxHandle = NULL;
  754. hr = GetFaxHandle(&hFaxHandle);
  755. if (FAILED(hr))
  756. {
  757. AtlReportError(CLSID_FaxReceiptOptions, GetErrorMsgId(hr), IID_IFaxReceiptOptions, hr);
  758. return hr;
  759. }
  760. //
  761. // Create ReceiptOptions Struct
  762. //
  763. FAX_RECEIPTS_CONFIG ReceiptsConfig = {0};
  764. ReceiptsConfig.dwSizeOfStruct = sizeof(FAX_RECEIPTS_CONFIG);
  765. ReceiptsConfig.dwSMTPPort = m_dwPort;
  766. ReceiptsConfig.lptstrSMTPFrom = m_bstrSender;
  767. ReceiptsConfig.lptstrSMTPUserName = m_bstrUser;
  768. if (m_bPasswordDirty)
  769. {
  770. //
  771. // Password has changed since last save / refresh
  772. //
  773. ReceiptsConfig.lptstrSMTPPassword = m_bstrPassword;
  774. }
  775. else
  776. {
  777. //
  778. // Password has not changed since last save / refresh.
  779. // The fax service knows not to change it in the registry if we pass NULL here.
  780. //
  781. }
  782. ReceiptsConfig.lptstrSMTPServer = m_bstrServer;
  783. ReceiptsConfig.SMTPAuthOption = FAX_ENUM_SMTP_AUTH_OPTIONS(m_AuthType);
  784. ReceiptsConfig.dwAllowedReceipts = m_dwAllowedReceipts;
  785. ReceiptsConfig.bIsToUseForMSRouteThroughEmailMethod = VARIANT_BOOL2bool(m_bUseForInboundRouting);
  786. //
  787. // Ask the Server to set the Receipt Configuration
  788. //
  789. if (!FaxSetReceiptsConfiguration(hFaxHandle, &ReceiptsConfig))
  790. {
  791. //
  792. // Failed to set Receipts Options on the Server
  793. //
  794. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  795. AtlReportError(CLSID_FaxReceiptOptions, GetErrorMsgId(hr), IID_IFaxReceiptOptions, hr);
  796. CALL_FAIL(GENERAL_ERR, _T("FaxSetReceiptConfiguration(hFaxHandle, &ReceiptsConfig)"), hr);
  797. return hr;
  798. }
  799. m_bPasswordDirty = false;
  800. return hr;
  801. }
  802. //
  803. //==================== REFRESH ========================================
  804. //
  805. STDMETHODIMP
  806. CFaxReceiptOptions::Refresh(
  807. )
  808. /*++
  809. Routine name : CFaxReceiptOptions::Refresh
  810. Routine description:
  811. Bring new Receipt Options from the Server.
  812. Author:
  813. Iv Garber (IvG), May, 2000
  814. Return Value:
  815. Standard HRESULT code
  816. --*/
  817. {
  818. HRESULT hr = S_OK;
  819. DBG_ENTER(_T("CFaxReceiptOptions::Refresh"), hr);
  820. //
  821. // Get Fax Server Handle
  822. //
  823. HANDLE hFaxHandle = NULL;
  824. hr = GetFaxHandle(&hFaxHandle);
  825. if (FAILED(hr))
  826. {
  827. AtlReportError(CLSID_FaxReceiptOptions,
  828. GetErrorMsgId(hr),
  829. IID_IFaxReceiptOptions,
  830. hr);
  831. return hr;
  832. }
  833. //
  834. // Ask Server for the Receipts Options Struct
  835. //
  836. CFaxPtr<FAX_RECEIPTS_CONFIG> pReceiptsConfig;
  837. if (!FaxGetReceiptsConfiguration(hFaxHandle, &pReceiptsConfig))
  838. {
  839. //
  840. // Failed to get Receipts Options object from the Server
  841. //
  842. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  843. AtlReportError(CLSID_FaxReceiptOptions,
  844. GetErrorMsgId(hr),
  845. IID_IFaxReceiptOptions,
  846. hr);
  847. CALL_FAIL(GENERAL_ERR, _T("FaxGetReceiptConfiguration(hFaxHandle, &pReceiptsConfig)"), hr);
  848. return hr;
  849. }
  850. //
  851. // Check that pReceiptConfig is valid
  852. //
  853. if (!pReceiptsConfig || pReceiptsConfig->dwSizeOfStruct != sizeof(FAX_RECEIPTS_CONFIG))
  854. {
  855. hr = E_FAIL;
  856. AtlReportError(CLSID_FaxReceiptOptions,
  857. GetErrorMsgId(hr),
  858. IID_IFaxReceiptOptions,
  859. hr);
  860. CALL_FAIL(GENERAL_ERR, _T("(!m_pReceiptsConfig || SizeOfStruct != sizeof(FAX_RECEIPTS_CONFIG))"), hr);
  861. return hr;
  862. }
  863. m_dwPort = pReceiptsConfig->dwSMTPPort;
  864. m_AuthType = FAX_SMTP_AUTHENTICATION_TYPE_ENUM(pReceiptsConfig->SMTPAuthOption);
  865. m_dwAllowedReceipts = pReceiptsConfig->dwAllowedReceipts;
  866. m_bUseForInboundRouting = bool2VARIANT_BOOL(pReceiptsConfig->bIsToUseForMSRouteThroughEmailMethod);
  867. m_bstrSender = pReceiptsConfig->lptstrSMTPFrom;
  868. m_bstrUser = pReceiptsConfig->lptstrSMTPUserName;
  869. m_bstrServer = pReceiptsConfig->lptstrSMTPServer;
  870. SecureZeroMemory(m_bstrPassword.m_str, (m_bstrPassword.Length() * sizeof(OLECHAR)));
  871. m_bstrPassword = pReceiptsConfig->lptstrSMTPPassword;
  872. if ( ((pReceiptsConfig->lptstrSMTPFrom) && !m_bstrSender) ||
  873. ((pReceiptsConfig->lptstrSMTPUserName) && !m_bstrUser) ||
  874. ((pReceiptsConfig->lptstrSMTPPassword) && !m_bstrPassword) ||
  875. ((pReceiptsConfig->lptstrSMTPServer) && !m_bstrServer) )
  876. {
  877. //
  878. // Failed to Copy
  879. //
  880. hr = E_OUTOFMEMORY;
  881. AtlReportError(CLSID_FaxReceiptOptions, IDS_ERROR_OUTOFMEMORY, IID_IFaxReceiptOptions, hr);
  882. CALL_FAIL(MEM_ERR, _T("::SysAllocString()"), hr);
  883. return hr;
  884. }
  885. m_bPasswordDirty = false;
  886. m_bInited = true;
  887. return hr;
  888. }
  889. //
  890. //================ SUPPORT ERRRO INFO =========================================
  891. //
  892. STDMETHODIMP
  893. CFaxReceiptOptions::InterfaceSupportsErrorInfo(
  894. REFIID riid
  895. )
  896. /*++
  897. Routine name : CFaxReceiptOptions::InterfaceSupportsErrorInfo
  898. Routine description:
  899. ATL's implementation of Interface Support Error Info.
  900. Author:
  901. Iv Garber (IvG), May, 2000
  902. Arguments:
  903. riid [in] - IID of the Interface to check.
  904. Return Value:
  905. Standard HRESULT code
  906. --*/
  907. {
  908. static const IID* arr[] =
  909. {
  910. &IID_IFaxReceiptOptions
  911. };
  912. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  913. {
  914. if (InlineIsEqualGUID(*arr[i],riid))
  915. return S_OK;
  916. }
  917. return S_FALSE;
  918. }