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.

727 lines
16 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxInboundRoutingExtension.cpp
  5. Abstract:
  6. Implementation of CFaxInboundRoutingExtension class.
  7. Author:
  8. Iv Garber (IvG) Jul, 2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "FaxComEx.h"
  13. #include "FaxInboundRoutingExtension.h"
  14. //
  15. //===================== GET METHODS =========================================
  16. //
  17. STDMETHODIMP
  18. CFaxInboundRoutingExtension::get_Methods(
  19. /*[out, retval]*/ VARIANT *pvMethods
  20. )
  21. /*++
  22. Routine name : CFaxInboundRoutingExtension::get_Methods
  23. Routine description:
  24. Return array of all Method GUIDS exposed by the IR Extension
  25. Author:
  26. Iv Garber (IvG), Jul, 2000
  27. Arguments:
  28. pvMethods [out] - Ptr to put Variant containing Safearray of Methods
  29. Return Value:
  30. Standard HRESULT code
  31. --*/
  32. {
  33. HRESULT hr = S_OK;
  34. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_Methods"), hr);
  35. //
  36. // Check that we can write to the given pointer
  37. //
  38. if (::IsBadWritePtr(pvMethods, sizeof(VARIANT)))
  39. {
  40. hr = E_POINTER;
  41. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  42. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr(pvMethods, sizeof(VARIANT))"), hr);
  43. return hr;
  44. }
  45. //
  46. // Allocate the safe array : vector of BSTR
  47. //
  48. SAFEARRAY *psaResult;
  49. hr = SafeArrayCopy(m_psaMethods, &psaResult);
  50. if (FAILED(hr) || !psaResult)
  51. {
  52. if (!psaResult)
  53. {
  54. hr = E_OUTOFMEMORY;
  55. }
  56. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  57. CALL_FAIL(MEM_ERR, _T("SafeArrayCopy(m_psaMethods, &psaResult)"), hr);
  58. return hr;
  59. }
  60. //
  61. // Return the Safe Array inside the VARIANT we got
  62. //
  63. VariantInit(pvMethods);
  64. pvMethods->vt = VT_BSTR | VT_ARRAY;
  65. pvMethods->parray = psaResult;
  66. return hr;
  67. }
  68. //
  69. //===================== GET STATUS =========================================
  70. //
  71. STDMETHODIMP
  72. CFaxInboundRoutingExtension::get_Status(
  73. FAX_PROVIDER_STATUS_ENUM *pStatus
  74. )
  75. /*++
  76. Routine name : CFaxInboundRoutingExtension::get_Status
  77. Routine description:
  78. Return Status of the IR Extension
  79. Author:
  80. Iv Garber (IvG), Jul, 2000
  81. Arguments:
  82. pStatus [out] - Ptr to put Status value
  83. Return Value:
  84. Standard HRESULT code
  85. --*/
  86. {
  87. HRESULT hr = S_OK;
  88. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_Status"), hr);
  89. //
  90. // Check that we have got good Ptr
  91. //
  92. if (::IsBadWritePtr(pStatus, sizeof(FAX_PROVIDER_STATUS_ENUM)))
  93. {
  94. hr = E_POINTER;
  95. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr(pStatus, sizeof(FAX_PROVIDER_STATUS_ENUM))"), hr);
  96. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  97. return hr;
  98. }
  99. *pStatus = m_Status;
  100. return hr;
  101. }
  102. //
  103. //========================= GET IMAGE NAME ========================================
  104. //
  105. STDMETHODIMP
  106. CFaxInboundRoutingExtension::get_ImageName(
  107. BSTR *pbstrImageName
  108. )
  109. /*++
  110. Routine name : CFaxInboundRoutingExtension::get_ImageName
  111. Routine description:
  112. Return Image Name of the IR Extension
  113. Author:
  114. Iv Garber (IvG), Jul, 2000
  115. Arguments:
  116. pbstrImageName [out] - Ptr to put the ImageName
  117. Return Value:
  118. Standard HRESULT code
  119. --*/
  120. {
  121. HRESULT hr = S_OK;
  122. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_ImageName"), hr);
  123. hr = GetBstr(pbstrImageName, m_bstrImageName);
  124. if (FAILED(hr))
  125. {
  126. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  127. return hr;
  128. }
  129. return hr;
  130. }
  131. //
  132. //========================= GET FRIENDLY NAME ========================================
  133. //
  134. STDMETHODIMP
  135. CFaxInboundRoutingExtension::get_FriendlyName(
  136. BSTR *pbstrFriendlyName
  137. )
  138. /*++
  139. Routine name : CFaxInboundRoutingExtension::get_FriendlyName
  140. Routine description:
  141. Return Friendly Name of the IR Extension
  142. Author:
  143. Iv Garber (IvG), Jul, 2000
  144. Arguments:
  145. pbstrFriendlyName [out] - Ptr to put the FriendlyName
  146. Return Value:
  147. Standard HRESULT code
  148. --*/
  149. {
  150. HRESULT hr = S_OK;
  151. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_FriendlyName"), hr);
  152. hr = GetBstr(pbstrFriendlyName, m_bstrFriendlyName);
  153. if (FAILED(hr))
  154. {
  155. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  156. return hr;
  157. }
  158. return hr;
  159. }
  160. //
  161. //========================= GET UNIQUE NAME ========================================
  162. //
  163. STDMETHODIMP
  164. CFaxInboundRoutingExtension::get_UniqueName(
  165. BSTR *pbstrUniqueName
  166. )
  167. /*++
  168. Routine name : CFaxInboundRoutingExtension::get_UniqueName
  169. Routine description:
  170. Return Unique Name of the IR Extension
  171. Author:
  172. Iv Garber (IvG), Jul, 2000
  173. Arguments:
  174. pbstrUniqueName [out] - Ptr to put the Unique Name
  175. Return Value:
  176. Standard HRESULT code
  177. --*/
  178. {
  179. HRESULT hr = S_OK;
  180. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_UniquName"), hr);
  181. hr = GetBstr(pbstrUniqueName, m_bstrUniqueName);
  182. if (FAILED(hr))
  183. {
  184. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  185. return hr;
  186. }
  187. return hr;
  188. }
  189. //
  190. //===================== GET DEBUG =========================================
  191. //
  192. STDMETHODIMP
  193. CFaxInboundRoutingExtension::get_Debug(
  194. VARIANT_BOOL *pbDebug
  195. )
  196. /*++
  197. Routine name : CFaxInboundRoutingExtension::get_Debug
  198. Routine description:
  199. Return if the IR Extension is compiled in Debug version
  200. Author:
  201. Iv Garber (IvG), Jul, 2000
  202. Arguments:
  203. pbDebug [out] - Ptr to put Debug value
  204. Return Value:
  205. Standard HRESULT code
  206. --*/
  207. {
  208. HRESULT hr = S_OK;
  209. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_Debug"), hr);
  210. hr = GetVariantBool(pbDebug, m_bDebug);
  211. if (FAILED(hr))
  212. {
  213. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  214. return hr;
  215. }
  216. return hr;
  217. }
  218. //
  219. //===================== GET MAJOR BUILD =========================================
  220. //
  221. STDMETHODIMP
  222. CFaxInboundRoutingExtension::get_MajorBuild(
  223. long *plMajorBuild
  224. )
  225. /*++
  226. Routine name : CFaxInboundRoutingExtension::get_MajorBuild
  227. Routine description:
  228. Return MajorBuild of the IR Extension
  229. Author:
  230. Iv Garber (IvG), Jul, 2000
  231. Arguments:
  232. plMajorBuild [out] - Ptr to put MajorBuild value
  233. Return Value:
  234. Standard HRESULT code
  235. --*/
  236. {
  237. HRESULT hr = S_OK;
  238. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_MajorBuild"), hr);
  239. hr = GetLong(plMajorBuild, m_dwMajorBuild);
  240. if (FAILED(hr))
  241. {
  242. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  243. return hr;
  244. }
  245. return hr;
  246. }
  247. //
  248. //===================== GET MINOR BUILD =========================================
  249. //
  250. STDMETHODIMP
  251. CFaxInboundRoutingExtension::get_MinorBuild(
  252. long *plMinorBuild
  253. )
  254. /*++
  255. Routine name : CFaxInboundRoutingExtension::get_MinorBuild
  256. Routine description:
  257. Return MinorBuild of the IR Extension
  258. Author:
  259. Iv Garber (IvG), Jul, 2000
  260. Arguments:
  261. plMinorBuild [out] - Ptr to put MinorBuild value
  262. Return Value:
  263. Standard HRESULT code
  264. --*/
  265. {
  266. HRESULT hr = S_OK;
  267. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_MinorBuild"), hr);
  268. hr = GetLong(plMinorBuild, m_dwMinorBuild);
  269. if (FAILED(hr))
  270. {
  271. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  272. return hr;
  273. }
  274. return hr;
  275. }
  276. //
  277. //===================== GET MAJOR VERSION =========================================
  278. //
  279. STDMETHODIMP
  280. CFaxInboundRoutingExtension::get_MajorVersion(
  281. long *plMajorVersion
  282. )
  283. /*++
  284. Routine name : CFaxInboundRoutingExtension::get_MajorVersion
  285. Routine description:
  286. Return MajorVersion of the IR Extension
  287. Author:
  288. Iv Garber (IvG), Jun, 2000
  289. Arguments:
  290. plMajorVersion [out] - Ptr to put MajorVersion value
  291. Return Value:
  292. Standard HRESULT code
  293. --*/
  294. {
  295. HRESULT hr = S_OK;
  296. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_MajorVersion"), hr);
  297. hr = GetLong(plMajorVersion, m_dwMajorVersion);
  298. if (FAILED(hr))
  299. {
  300. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  301. return hr;
  302. }
  303. return hr;
  304. }
  305. //
  306. //===================== GET MINOR VERSION =========================================
  307. //
  308. STDMETHODIMP
  309. CFaxInboundRoutingExtension::get_MinorVersion(
  310. long *plMinorVersion
  311. )
  312. /*++
  313. Routine name : CFaxInboundRoutingExtension::get_MinorVersion
  314. Routine description:
  315. Return MinorVersion of the IR Extension
  316. Author:
  317. Iv Garber (IvG), Jul, 2000
  318. Arguments:
  319. plMinorVersion [out] - Ptr to put MinorVersionvalue
  320. Return Value:
  321. Standard HRESULT code
  322. --*/
  323. {
  324. HRESULT hr = S_OK;
  325. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_MinorVersion"), hr);
  326. hr = GetLong(plMinorVersion, m_dwMinorVersion);
  327. if (FAILED(hr))
  328. {
  329. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  330. return hr;
  331. }
  332. return hr;
  333. }
  334. //
  335. //===================== GET INIT ERROR CODE =========================================
  336. //
  337. STDMETHODIMP
  338. CFaxInboundRoutingExtension::get_InitErrorCode(
  339. long *plInitErrorCode
  340. )
  341. /*++
  342. Routine name : CFaxInboundRoutingExtension::get_InitErrorCode
  343. Routine description:
  344. Return InitErrorCode of the IR Extension
  345. Author:
  346. Iv Garber (IvG), Jul, 2000
  347. Arguments:
  348. plInitErrorCode [out] - Ptr to put InitErrorCode value
  349. Return Value:
  350. Standard HRESULT code
  351. --*/
  352. {
  353. HRESULT hr = S_OK;
  354. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::get_InitErrorCode"), hr);
  355. hr = GetLong(plInitErrorCode, m_dwLastError);
  356. if (FAILED(hr))
  357. {
  358. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  359. return hr;
  360. }
  361. return hr;
  362. }
  363. //
  364. //==================== INIT ========================================
  365. //
  366. STDMETHODIMP
  367. CFaxInboundRoutingExtension::Init(
  368. FAX_ROUTING_EXTENSION_INFO *pInfo,
  369. FAX_GLOBAL_ROUTING_INFO *pMethods,
  370. DWORD dwNum
  371. )
  372. /*++
  373. Routine name : CFaxInboundRoutingExtesnion::Init
  374. Routine description:
  375. Initialize the IR Extension Object with given Information.
  376. Allocates memory and stores given pInfo.
  377. Find in the pMethods its own Methods, create Variant of SafeArray containing them.
  378. Author:
  379. Iv Garber (IvG), Jul, 2000
  380. Arguments:
  381. pInfo [in] -- the Info of the IR Extension Object
  382. pMethods [in] -- array of all available Methods
  383. dwNum [in] -- number of elements in pMethods array
  384. Return Value:
  385. Standard HRESULT code
  386. --*/
  387. {
  388. HRESULT hr = S_OK;
  389. DBG_ENTER (TEXT("CFaxInboundRoutingExtension::Init"), hr);
  390. //
  391. // Copy the FAX_ROUTING_EXTENSION_INFO
  392. //
  393. m_dwLastError = pInfo->dwLastError;
  394. m_Status = FAX_PROVIDER_STATUS_ENUM(pInfo->Status);
  395. if (!(pInfo->Version.bValid))
  396. {
  397. m_dwMajorBuild = 0;
  398. m_dwMinorBuild = 0;
  399. m_dwMajorVersion = 0;
  400. m_dwMinorVersion = 0;
  401. m_bDebug = VARIANT_FALSE;
  402. }
  403. else
  404. {
  405. m_dwMajorBuild = pInfo->Version.wMajorBuildNumber;
  406. m_dwMinorBuild = pInfo->Version.wMinorBuildNumber;
  407. m_dwMajorVersion = pInfo->Version.wMajorVersion;
  408. m_dwMinorVersion = pInfo->Version.wMinorVersion;
  409. m_bDebug = bool2VARIANT_BOOL((pInfo->Version.dwFlags & FAX_VER_FLAG_CHECKED) ? true : false);
  410. }
  411. m_bstrImageName = pInfo->lpctstrImageName;
  412. m_bstrFriendlyName = pInfo->lpctstrFriendlyName;
  413. m_bstrUniqueName = pInfo->lpctstrExtensionName;
  414. if ( (pInfo->lpctstrImageName && !m_bstrImageName) ||
  415. (pInfo->lpctstrFriendlyName && !m_bstrFriendlyName) ||
  416. (pInfo->lpctstrExtensionName && !m_bstrUniqueName) )
  417. {
  418. hr = E_OUTOFMEMORY;
  419. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator=()"), hr);
  420. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  421. return hr;
  422. }
  423. //
  424. // count the Methods of the IR Extension
  425. //
  426. DWORD dwCount = 0;
  427. for (DWORD i=0 ; i<dwNum ; i++ )
  428. {
  429. //
  430. // We may only compare Friendly Name and Image Name.
  431. // This is potentially a problem.
  432. // Extensions should be distinguished by their Unique Name.
  433. //
  434. if ( (_tcscmp(pMethods[i].ExtensionFriendlyName, m_bstrFriendlyName) == 0) &&
  435. (_tcscmp(pMethods[i].ExtensionImageName, m_bstrImageName) == 0) )
  436. {
  437. dwCount++;
  438. }
  439. }
  440. //
  441. // Allocate the safe array : vector of BSTR
  442. //
  443. m_psaMethods = ::SafeArrayCreateVector(VT_BSTR, 0, dwCount);
  444. if (!m_psaMethods)
  445. {
  446. //
  447. // Not Enough Memory
  448. //
  449. hr = E_OUTOFMEMORY;
  450. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  451. CALL_FAIL(MEM_ERR, _T("::SafeArrayCreateVector(VT_BSTR, 0, dwCount)"), hr);
  452. return hr;
  453. }
  454. if ( dwCount>0 )
  455. {
  456. //
  457. // get Access to the elements of the Safe Array
  458. //
  459. BSTR *pbstrElement;
  460. hr = ::SafeArrayAccessData(m_psaMethods, (void **) &pbstrElement);
  461. if (FAILED(hr))
  462. {
  463. //
  464. // Failed to access safearray
  465. //
  466. hr = E_FAIL;
  467. CALL_FAIL(GENERAL_ERR, _T("::SafeArrayAccessData(m_psaMethods, &pbstrElement)"), hr);
  468. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  469. return hr;
  470. }
  471. //
  472. // Fill the array with values
  473. //
  474. DWORD idx = 0;
  475. for ( i=0 ; i<dwNum ; i++ )
  476. {
  477. //
  478. // Like the previous comparison :
  479. // We may only compare Friendly Name and Image Name.
  480. // This is potentially a problem.
  481. // Extensions should be distinguished by their Unique Name.
  482. //
  483. if ( (_tcscmp(pMethods[i].ExtensionFriendlyName, m_bstrFriendlyName) == 0) &&
  484. (_tcscmp(pMethods[i].ExtensionImageName, m_bstrImageName) == 0) )
  485. {
  486. //
  487. // Allocate memory for the GUID and store ptr to it in the SafeArray
  488. //
  489. BSTR bstrTmp = NULL;
  490. bstrTmp = ::SysAllocString(pMethods[i].Guid);
  491. if (pMethods[i].Guid && !bstrTmp)
  492. {
  493. //
  494. // Not Enough Memory
  495. //
  496. hr = E_OUTOFMEMORY;
  497. AtlReportError(CLSID_FaxInboundRoutingExtension, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtension, hr);
  498. CALL_FAIL(MEM_ERR, _T("::SysAllocString(pMethods[i].Guid)"), hr);
  499. SafeArrayUnaccessData(m_psaMethods);
  500. SafeArrayDestroy(m_psaMethods);
  501. m_psaMethods = NULL;
  502. return hr;
  503. }
  504. pbstrElement[idx] = bstrTmp;
  505. idx++;
  506. }
  507. }
  508. ATLASSERT(idx == dwCount);
  509. //
  510. // free the safearray from the access
  511. //
  512. hr = ::SafeArrayUnaccessData(m_psaMethods);
  513. if (FAILED(hr))
  514. {
  515. CALL_FAIL(GENERAL_ERR, _T("::SafeArrayUnaccessData(m_psaMethods)"), hr);
  516. return hr;
  517. }
  518. }
  519. return hr;
  520. }
  521. //
  522. //==================== SUPPORT ERROR INFO =============================================
  523. //
  524. STDMETHODIMP
  525. CFaxInboundRoutingExtension::InterfaceSupportsErrorInfo(
  526. REFIID riid
  527. )
  528. /*++
  529. Routine name : CFaxInboundRoutingExtension::InterfaceSupportsErrorInfo
  530. Routine description:
  531. ATL's implementation of Support Error Info.
  532. Author:
  533. Iv Garber (IvG), Jun, 2000
  534. Arguments:
  535. riid [in] - Reference to the Interface.
  536. Return Value:
  537. Standard HRESULT code
  538. --*/
  539. {
  540. static const IID* arr[] =
  541. {
  542. &IID_IFaxInboundRoutingExtension
  543. };
  544. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  545. {
  546. if (InlineIsEqualGUID(*arr[i],riid))
  547. return S_OK;
  548. }
  549. return S_FALSE;
  550. }