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.

401 lines
10 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxInboundRoutingExtensions.cpp
  5. Abstract:
  6. Implementation of CFaxInboundRoutingExtensions class.
  7. Author:
  8. Iv Garber (IvG) Jul, 2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "FaxComEx.h"
  13. #include "FaxInboundRoutingExtensions.h"
  14. #include "FaxInboundRoutingExtension.h"
  15. //
  16. //==================== CREATE ========================================
  17. //
  18. HRESULT
  19. CFaxInboundRoutingExtensions::Create (
  20. IFaxInboundRoutingExtensions **ppIRExtensions
  21. )
  22. /*++
  23. Routine name : CFaxInboundRoutingExtensions::Create
  24. Routine description:
  25. Static function to create the Fax IR Extensions Collection Object
  26. Author:
  27. Iv Garber (IvG), Jul, 2000
  28. Arguments:
  29. ppIRExtensions [out] -- the new Fax IR Extensions Collection Object
  30. Return Value:
  31. Standard HRESULT code
  32. --*/
  33. {
  34. HRESULT hr = S_OK;
  35. DBG_ENTER (TEXT("CFaxInboundRoutingExtensions::Create"), hr);
  36. //
  37. // Create Instance of the Collection
  38. //
  39. CComObject<CFaxInboundRoutingExtensions> *pClass;
  40. hr = CComObject<CFaxInboundRoutingExtensions>::CreateInstance(&pClass);
  41. if (FAILED(hr))
  42. {
  43. CALL_FAIL(GENERAL_ERR, _T("CComObject<CFaxInboundRoutingExtensions>::CreateInstance(&pClass)"), hr);
  44. return hr;
  45. }
  46. //
  47. // Return the desired Interface Ptr
  48. //
  49. hr = pClass->QueryInterface(ppIRExtensions);
  50. if (FAILED(hr))
  51. {
  52. CALL_FAIL(GENERAL_ERR, _T("pClass->QueryInterface(ppIRExtensions)"), hr);
  53. return hr;
  54. }
  55. return hr;
  56. } // CFaxInboundRoutingExtensions::Create()
  57. //
  58. //============================= INIT ============================================
  59. //
  60. STDMETHODIMP
  61. CFaxInboundRoutingExtensions::Init(
  62. IFaxServerInner *pServerInner
  63. )
  64. /*++
  65. Routine name : CFaxInboundRoutingExtensions::Init
  66. Routine description:
  67. Initialize the Collection :
  68. 1) get from RPC all IR Extensions and all Methods Structures,
  69. 2) create COM objects for each structure,
  70. 3) init all these objects with the IR Extension structure and Methods array,
  71. 4) AddRef() each object,
  72. 5) put the Ptrs to Objects into the STL::vector.
  73. Author:
  74. Iv Garber (IvG), Jul, 2000
  75. Arguments:
  76. pServerInner [in] - Ptr to the Fax Server.
  77. Return Value:
  78. Standard HRESULT code
  79. --*/
  80. {
  81. HRESULT hr = S_OK;
  82. DBG_ENTER(_T("CFaxInboundRoutingExtensions::Init"), hr);
  83. //
  84. // Get Fax Server Handle
  85. //
  86. HANDLE faxHandle;
  87. hr = pServerInner->GetHandle(&faxHandle);
  88. ATLASSERT(SUCCEEDED(hr));
  89. if (faxHandle == NULL)
  90. {
  91. //
  92. // Fax Server is not connected
  93. //
  94. hr = Fax_HRESULT_FROM_WIN32(ERROR_NOT_CONNECTED);
  95. CALL_FAIL(GENERAL_ERR, _T("faxHandle == NULL"), hr);
  96. AtlReportError(CLSID_FaxInboundRoutingExtensions, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtensions, hr);
  97. return hr;
  98. }
  99. //
  100. // Bring from the Server all IR Extensions
  101. //
  102. DWORD dwNum = 0;
  103. CFaxPtr<FAX_ROUTING_EXTENSION_INFO> pIRExtensions;
  104. if (!FaxEnumRoutingExtensions(faxHandle, &pIRExtensions, &dwNum))
  105. {
  106. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  107. CALL_FAIL(GENERAL_ERR, _T("FaxEnumRoutingExtensions(faxHandle, &pIRExtensions, &dwNum"), hr);
  108. AtlReportError(CLSID_FaxInboundRoutingExtensions, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtensions, hr);
  109. return hr;
  110. }
  111. //
  112. // Bring all the Methods from the Server
  113. //
  114. DWORD dwNumMethods = 0;
  115. CFaxPtr<FAX_GLOBAL_ROUTING_INFO> pMethods;
  116. if (!FaxEnumGlobalRoutingInfo(faxHandle, &pMethods, &dwNumMethods))
  117. {
  118. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  119. AtlReportError(CLSID_FaxInboundRoutingExtensions, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtensions, hr);
  120. CALL_FAIL(GENERAL_ERR, _T("FaxEnumGlobalRoutingInfo(hFaxHandle, &pMethods, &dwNumMethods)"), hr);
  121. return hr;
  122. }
  123. //
  124. // Fill the Collection with Objects
  125. //
  126. CComObject<CFaxInboundRoutingExtension> *pClass = NULL;
  127. CComPtr<IFaxInboundRoutingExtension> pObject = NULL;
  128. for (DWORD i=0 ; i<dwNum ; i++ )
  129. {
  130. //
  131. // Create IR Extensin Object
  132. //
  133. hr = CComObject<CFaxInboundRoutingExtension>::CreateInstance(&pClass);
  134. if (FAILED(hr) || (!pClass))
  135. {
  136. if (!pClass)
  137. {
  138. hr = E_OUTOFMEMORY;
  139. CALL_FAIL(MEM_ERR, _T("CComObject<CFaxInboundRoutingExtension>::CreateInstance(&pClass)"), hr);
  140. }
  141. else
  142. {
  143. CALL_FAIL(GENERAL_ERR, _T("CComObject<CFaxInboundRoutingExtension>::CreateInstance(&pClass)"), hr);
  144. }
  145. AtlReportError(CLSID_FaxInboundRoutingExtensions, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtensions, hr);
  146. return hr;
  147. }
  148. //
  149. // Init the IR Extension Object
  150. //
  151. hr = pClass->Init(&pIRExtensions[i], pMethods, dwNumMethods);
  152. if (FAILED(hr))
  153. {
  154. CALL_FAIL(GENERAL_ERR, _T("pClass->Init(&pIRExtensions[i], pMethods, dwNumMethods)"), hr);
  155. AtlReportError(CLSID_FaxInboundRoutingExtensions, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtensions, hr);
  156. delete pClass;
  157. return hr;
  158. }
  159. //
  160. // Get Interface from the pClass.
  161. // This will make AddRef() on the Interface.
  162. // This is the Collection's AddRef, which is freed at Collection's Dtor.
  163. //
  164. hr = pClass->QueryInterface(&pObject);
  165. if (FAILED(hr) || (!pObject))
  166. {
  167. if (!pObject)
  168. {
  169. hr = E_FAIL;
  170. }
  171. CALL_FAIL(GENERAL_ERR, _T("pClass->QueryInterface(&pObject)"), hr);
  172. AtlReportError(CLSID_FaxInboundRoutingExtensions, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtensions, hr);
  173. delete pClass;
  174. return hr;
  175. }
  176. //
  177. // Put the Object in the collection
  178. //
  179. try
  180. {
  181. m_coll.push_back(pObject);
  182. }
  183. catch (exception &)
  184. {
  185. hr = E_OUTOFMEMORY;
  186. AtlReportError(CLSID_FaxInboundRoutingExtensions, IDS_ERROR_OUTOFMEMORY, IID_IFaxInboundRoutingExtensions, hr);
  187. CALL_FAIL(MEM_ERR, _T("m_coll.push_back(pObject)"), hr);
  188. //
  189. // pObject will call Release(), which will delete the pClass
  190. //
  191. return hr;
  192. }
  193. //
  194. // We want to save the current AddRef() to Collection
  195. //
  196. pObject.Detach();
  197. }
  198. return hr;
  199. }
  200. //
  201. //============================= GET ITEM =========================================
  202. //
  203. STDMETHODIMP
  204. CFaxInboundRoutingExtensions::get_Item(
  205. /*[in]*/ VARIANT vIndex,
  206. /*[out, retval]*/ IFaxInboundRoutingExtension **ppIRExtension
  207. )
  208. /*++
  209. Routine name : CFaxInboundRoutingExtensions::get_Item
  210. Routine description:
  211. Return an Item from the Collection.
  212. Author:
  213. Iv Garber (IvG), Jul, 2000
  214. Arguments:
  215. vIndex [in] - Identifier of the Item to return.
  216. ppIRExtension [out] - the result value
  217. Return Value:
  218. Standard HRESULT code
  219. --*/
  220. {
  221. HRESULT hr = S_OK;
  222. DBG_ENTER(_T("CFaxInboundRoutingExtensions::get_Item"), hr);
  223. //
  224. // Check the Ptr we have got
  225. //
  226. if (::IsBadWritePtr(ppIRExtension, sizeof(IFaxInboundRoutingExtension *)))
  227. {
  228. hr = E_POINTER;
  229. AtlReportError(CLSID_FaxInboundRoutingExtensions, IDS_ERROR_INVALID_ARGUMENT, IID_IFaxInboundRoutingExtensions, hr);
  230. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr(ppIRExtension)"), hr);
  231. return hr;
  232. }
  233. CComVariant var;
  234. if (vIndex.vt != VT_BSTR)
  235. {
  236. //
  237. // vIndex is not BSTR ==> convert to VT_I4
  238. //
  239. hr = var.ChangeType(VT_I4, &vIndex);
  240. if (SUCCEEDED(hr))
  241. {
  242. VERBOSE(DBG_MSG, _T("Parameter is Number : %d"), var.lVal);
  243. //
  244. // call default ATL's implementation
  245. //
  246. hr = ICollectionOnSTLImpl<IFaxInboundRoutingExtensions, ContainerType,
  247. IFaxInboundRoutingExtension*, CollectionCopyType, EnumType>::get_Item(var.lVal,
  248. ppIRExtension);
  249. return hr;
  250. }
  251. }
  252. //
  253. // convert to BSTR
  254. //
  255. hr = var.ChangeType(VT_BSTR, &vIndex);
  256. if (FAILED(hr))
  257. {
  258. hr = E_INVALIDARG;
  259. AtlReportError(CLSID_FaxInboundRoutingExtensions, IDS_ERROR_INVALID_ARGUMENT, IID_IFaxInboundRoutingExtensions, hr);
  260. CALL_FAIL(GENERAL_ERR, _T("var.ChangeType(VT_BSTR, &vIndex)"), hr);
  261. return hr;
  262. }
  263. VERBOSE(DBG_MSG, _T("Parameter is String : %s"), var.bstrVal);
  264. ContainerType::iterator it = m_coll.begin();
  265. while (it != m_coll.end())
  266. {
  267. CComBSTR bstrName;
  268. hr = (*it)->get_UniqueName(&bstrName);
  269. if (FAILED(hr))
  270. {
  271. CALL_FAIL(GENERAL_ERR, _T("(*it)->get_UniqueName(&bstrName)"), hr);
  272. AtlReportError(CLSID_FaxInboundRoutingExtensions, GetErrorMsgId(hr), IID_IFaxInboundRoutingExtensions, hr);
  273. return hr;
  274. }
  275. if (_tcsicmp(bstrName, var.bstrVal) == 0)
  276. {
  277. //
  278. // found the desired IR Extension
  279. //
  280. (*it)->AddRef();
  281. *ppIRExtension = *it;
  282. return hr;
  283. }
  284. it++;
  285. }
  286. //
  287. // IR Extension does not exist
  288. //
  289. hr = E_INVALIDARG;
  290. CALL_FAIL(GENERAL_ERR, _T("Inbound Routing Extension Is Not Found"), hr);
  291. AtlReportError(CLSID_FaxInboundRoutingExtensions, IDS_ERROR_WRONGEXTENSIONNAME, IID_IFaxInboundRoutingExtensions, hr);
  292. return hr;
  293. }
  294. //
  295. //================== SUPPORT ERROR INFO ========================================
  296. //
  297. STDMETHODIMP
  298. CFaxInboundRoutingExtensions::InterfaceSupportsErrorInfo(
  299. REFIID riid
  300. )
  301. /*++
  302. Routine name : CFaxInboundRoutingExtensions::InterfaceSupportsErrorInfo
  303. Routine description:
  304. ATL's implementation of Support Error Info.
  305. Author:
  306. Iv Garber (IvG), Jul, 2000
  307. Arguments:
  308. riid [in] - Reference to the Interface.
  309. Return Value:
  310. Standard HRESULT code
  311. --*/
  312. {
  313. static const IID* arr[] =
  314. {
  315. &IID_IFaxInboundRoutingExtensions
  316. };
  317. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  318. {
  319. if (InlineIsEqualGUID(*arr[i],riid))
  320. return S_OK;
  321. }
  322. return S_FALSE;
  323. }