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.

569 lines
12 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxInboundRoutingMethod.cpp
  5. Abstract:
  6. Implementation of CFaxInboundRoutingMethod Class.
  7. Author:
  8. Iv Garber (IvG) Jun, 2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "FaxComEx.h"
  13. #include "FaxInboundRoutingMethod.h"
  14. //
  15. //==================== REFRESH ========================================
  16. //
  17. STDMETHODIMP
  18. CFaxInboundRoutingMethod::Refresh()
  19. /*++
  20. Routine name : CFaxInboundRoutingMethod::Refresh
  21. Routine description:
  22. Bring from the Server new Method Data ( only Priority may change ).
  23. Author:
  24. Iv Garber (IvG), Jun, 2000
  25. Return Value:
  26. Standard HRESULT code
  27. --*/
  28. {
  29. HRESULT hr = S_OK;
  30. DBG_ENTER (TEXT("CFaxInboundRoutingMethod::Refresh"), hr);
  31. //
  32. // Get Fax Server Handle
  33. //
  34. HANDLE faxHandle;
  35. hr = m_pIFaxServerInner->GetHandle(&faxHandle);
  36. ATLASSERT(SUCCEEDED(hr));
  37. if (faxHandle == NULL)
  38. {
  39. //
  40. // Fax Server is not connected
  41. //
  42. hr = Fax_HRESULT_FROM_WIN32(ERROR_NOT_CONNECTED);
  43. CALL_FAIL(GENERAL_ERR, _T("(faxHandle == NULL)"), hr);
  44. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  45. return hr;
  46. }
  47. //
  48. // Bring from the Server all Inbound Routing Methods
  49. //
  50. DWORD dwNum = 0;
  51. CFaxPtr<FAX_GLOBAL_ROUTING_INFO> pMethods;
  52. if (!FaxEnumGlobalRoutingInfo(faxHandle, &pMethods, &dwNum))
  53. {
  54. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  55. CALL_FAIL(GENERAL_ERR, _T("FaxEnumGlobalRoutingInfo(faxHandle, &pMethods, &dwNum)"), hr);
  56. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  57. return hr;
  58. }
  59. //
  60. // find our Method
  61. //
  62. for ( DWORD i=0 ; i<dwNum ; i++ )
  63. {
  64. if ( _tcsicmp(pMethods[i].Guid, m_bstrGUID) == 0 )
  65. {
  66. hr = Init(&pMethods[i], NULL);
  67. return hr;
  68. }
  69. }
  70. return hr;
  71. }
  72. //
  73. //==================== INIT ========================================
  74. //
  75. STDMETHODIMP
  76. CFaxInboundRoutingMethod::Init(
  77. FAX_GLOBAL_ROUTING_INFO *pInfo,
  78. IFaxServerInner *pServer
  79. )
  80. /*++
  81. Routine name : CFaxInboundRoutingMethod::Init
  82. Routine description:
  83. Initialize the IR Method Object with given Information.
  84. Allocates memory and stores given pInfo.
  85. Author:
  86. Iv Garber (IvG), Jun, 2000
  87. Arguments:
  88. pInfo [in] -- the Info of the IR Method Object
  89. pServer [in] -- Ptr to the Server
  90. Return Value:
  91. Standard HRESULT code
  92. --*/
  93. {
  94. HRESULT hr = S_OK;
  95. DBG_ENTER (TEXT("CFaxInboundRoutingMethod::Init"), hr);
  96. //
  97. // Copy the FAX_GLOBAL_ROUTING_INFO structure
  98. //
  99. m_lPriority = pInfo->Priority;
  100. m_bstrGUID = pInfo->Guid;
  101. m_bstrImageName = pInfo->ExtensionImageName;
  102. m_bstrFriendlyName = pInfo->ExtensionFriendlyName;
  103. m_bstrFunctionName = pInfo->FunctionName;
  104. m_bstrName = pInfo->FriendlyName;
  105. if ( (pInfo->Guid && !m_bstrGUID) ||
  106. (pInfo->FriendlyName && !m_bstrName) ||
  107. (pInfo->ExtensionImageName && !m_bstrImageName) ||
  108. (pInfo->ExtensionFriendlyName && !m_bstrFriendlyName) ||
  109. (pInfo->FunctionName && !m_bstrFunctionName) )
  110. {
  111. hr = E_OUTOFMEMORY;
  112. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator=()"), hr);
  113. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  114. return hr;
  115. }
  116. if (pServer)
  117. {
  118. //
  119. // Store Ptr to the Server
  120. //
  121. hr = CFaxInitInnerAddRef::Init(pServer);
  122. }
  123. return hr;
  124. }
  125. //
  126. //===================== SAVE ================================================
  127. //
  128. STDMETHODIMP
  129. CFaxInboundRoutingMethod::Save()
  130. /*++
  131. Routine name : CFaxInboundRoutingMethod::Save
  132. Routine description:
  133. Save the Method's Priority.
  134. Author:
  135. Iv Garber (IvG), Jun, 2000
  136. Return Value:
  137. Standard HRESULT code
  138. --*/
  139. {
  140. HRESULT hr = S_OK;
  141. DBG_ENTER(_T("CFaxInboundRoutingMethod::Save"), hr);
  142. //
  143. // Get Fax Server Handle
  144. //
  145. HANDLE faxHandle;
  146. hr = m_pIFaxServerInner->GetHandle(&faxHandle);
  147. ATLASSERT(SUCCEEDED(hr));
  148. if (faxHandle == NULL)
  149. {
  150. //
  151. // Fax Server is not connected
  152. //
  153. hr = Fax_HRESULT_FROM_WIN32(ERROR_NOT_CONNECTED);
  154. CALL_FAIL(GENERAL_ERR, _T("(faxHandle == NULL)"), hr);
  155. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  156. return hr;
  157. }
  158. //
  159. // Prepare Structure
  160. //
  161. FAX_GLOBAL_ROUTING_INFO Data;
  162. Data.Guid = m_bstrGUID;
  163. Data.Priority = m_lPriority;
  164. Data.SizeOfStruct = sizeof(FAX_GLOBAL_ROUTING_INFO);
  165. Data.ExtensionFriendlyName = NULL;
  166. Data.ExtensionImageName = NULL;
  167. Data.FriendlyName = NULL;
  168. Data.FunctionName = NULL;
  169. //
  170. // Call Server to update its data about the Method
  171. //
  172. if (!FaxSetGlobalRoutingInfo(faxHandle, &Data))
  173. {
  174. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  175. CALL_FAIL(GENERAL_ERR, _T("FaxSetGlobalRoutingInfo(faxHandle, &Data)"), hr);
  176. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  177. return hr;
  178. }
  179. return hr;
  180. }
  181. //
  182. //===================== PUT PRIORITY ================================================
  183. //
  184. STDMETHODIMP
  185. CFaxInboundRoutingMethod::put_Priority(
  186. /*[in]*/ long lPriority
  187. )
  188. /*++
  189. Routine name : CFaxInboundRoutingMethod::put_Priority
  190. Routine description:
  191. Set the Method's Priority -- Order within the Collection of all Methods.
  192. Author:
  193. Iv Garber (IvG), Jun, 2000
  194. Arguments:
  195. lPriority [out] - the value to set
  196. Return Value:
  197. Standard HRESULT code
  198. --*/
  199. {
  200. HRESULT hr = S_OK;
  201. DBG_ENTER(_T("CFaxInboundRoutingMethod::put_Priority"), hr, _T("PR=%d"), lPriority);
  202. if (lPriority < 1)
  203. {
  204. //
  205. // Out Of Range
  206. //
  207. hr = E_INVALIDARG;
  208. AtlReportError(CLSID_FaxInboundRoutingMethod, IDS_ERROR_OUTOFRANGE, IID_IFaxInboundRoutingMethod, hr);
  209. CALL_FAIL(GENERAL_ERR, _T("(lPriority < 1)"), hr);
  210. return hr;
  211. }
  212. m_lPriority = lPriority;
  213. return hr;
  214. }
  215. //
  216. //===================== GET PRIORITY ================================================
  217. //
  218. STDMETHODIMP
  219. CFaxInboundRoutingMethod::get_Priority(
  220. /*[out, retval]*/ long *plPriority
  221. )
  222. /*++
  223. Routine name : CFaxInboundRoutingMethod::get_Priority
  224. Routine description:
  225. Return the Method's Priority -- Order within the Collection of all Methods.
  226. Author:
  227. Iv Garber (IvG), Jun, 2000
  228. Arguments:
  229. plPriority [out] - the Ptr where to put the value
  230. Return Value:
  231. Standard HRESULT code
  232. --*/
  233. {
  234. HRESULT hr = S_OK;
  235. DBG_ENTER(_T("CFaxInboundRoutingMethod::get_Priority"), hr);
  236. hr = GetLong(plPriority, m_lPriority);
  237. if (FAILED(hr))
  238. {
  239. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  240. return hr;
  241. }
  242. return hr;
  243. }
  244. //
  245. //===================== GET EXTENSION IMAGE NAME ================================================
  246. //
  247. STDMETHODIMP
  248. CFaxInboundRoutingMethod::get_ExtensionImageName(
  249. /*[out, retval]*/ BSTR *pbstrExtensionImageName
  250. )
  251. /*++
  252. Routine name : CFaxInboundRoutingMethod::get_ExtensionImageName
  253. Routine description:
  254. Return the Method's Extension Image Name.
  255. Author:
  256. Iv Garber (IvG), Jun, 2000
  257. Arguments:
  258. pbstrExtensionImageName [out] - the Ptr where to put the value
  259. Return Value:
  260. Standard HRESULT code
  261. --*/
  262. {
  263. HRESULT hr = S_OK;
  264. DBG_ENTER(_T("CFaxInboundRoutingMethod::get_ExtensionImageName"), hr);
  265. hr = GetBstr(pbstrExtensionImageName, m_bstrImageName);
  266. if (FAILED(hr))
  267. {
  268. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  269. return hr;
  270. }
  271. return hr;
  272. }
  273. //
  274. //===================== GET EXTENSION FRIENDLY NAME ================================================
  275. //
  276. STDMETHODIMP
  277. CFaxInboundRoutingMethod::get_ExtensionFriendlyName(
  278. /*[out, retval]*/ BSTR *pbstrExtensionFriendlyName
  279. )
  280. /*++
  281. Routine name : CFaxInboundRoutingMethod::get_ExtensionFriendlyName
  282. Routine description:
  283. Return the Method's Extension Friendly Name.
  284. Author:
  285. Iv Garber (IvG), Jun, 2000
  286. Arguments:
  287. pbstrExtensionFriendlyName [out] - the Ptr where to put the value
  288. Return Value:
  289. Standard HRESULT code
  290. --*/
  291. {
  292. HRESULT hr = S_OK;
  293. DBG_ENTER(_T("CFaxInboundRoutingMethod::get_ExtensionFriendlyName"), hr);
  294. hr = GetBstr(pbstrExtensionFriendlyName, m_bstrFriendlyName);
  295. if (FAILED(hr))
  296. {
  297. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  298. return hr;
  299. }
  300. return hr;
  301. }
  302. //
  303. //===================== GET FUNCTION NAME ================================================
  304. //
  305. STDMETHODIMP
  306. CFaxInboundRoutingMethod::get_FunctionName(
  307. /*[out, retval]*/ BSTR *pbstrFunctionName
  308. )
  309. /*++
  310. Routine name : CFaxInboundRoutingMethod::get_FunctionName
  311. Routine description:
  312. Return the Method's Function Name.
  313. Author:
  314. Iv Garber (IvG), Jun, 2000
  315. Arguments:
  316. pbstrFunctionName [out] - the Ptr where to put the value
  317. Return Value:
  318. Standard HRESULT code
  319. --*/
  320. {
  321. HRESULT hr = S_OK;
  322. DBG_ENTER(_T("CFaxInboundRoutingMethod::get_FunctionName"), hr);
  323. hr = GetBstr(pbstrFunctionName, m_bstrFunctionName);
  324. if (FAILED(hr))
  325. {
  326. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  327. return hr;
  328. }
  329. return hr;
  330. }
  331. //
  332. //===================== GET GUID ================================================
  333. //
  334. STDMETHODIMP
  335. CFaxInboundRoutingMethod::get_GUID(
  336. /*[out, retval]*/ BSTR *pbstrGUID
  337. )
  338. /*++
  339. Routine name : CFaxInboundRoutingMethod::get_GUID
  340. Routine description:
  341. Return the Method's GUID.
  342. Author:
  343. Iv Garber (IvG), Jun, 2000
  344. Arguments:
  345. pbstrGUID [out] - the Ptr where to put the value
  346. Return Value:
  347. Standard HRESULT code
  348. --*/
  349. {
  350. HRESULT hr = S_OK;
  351. DBG_ENTER(_T("CFaxInboundRoutingMethod::get_GUID"), hr);
  352. hr = GetBstr(pbstrGUID, m_bstrGUID);
  353. if (FAILED(hr))
  354. {
  355. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  356. return hr;
  357. }
  358. return hr;
  359. }
  360. //
  361. //===================== GET NAME ================================================
  362. //
  363. STDMETHODIMP
  364. CFaxInboundRoutingMethod::get_Name(
  365. /*[out, retval]*/ BSTR *pbstrName
  366. )
  367. /*++
  368. Routine name : CFaxInboundRoutingMethod::get_Name
  369. Routine description:
  370. Return the Method's Name.
  371. Author:
  372. Iv Garber (IvG), Jun, 2000
  373. Arguments:
  374. pbstrName [out] - the Ptr where to put the value
  375. Return Value:
  376. Standard HRESULT code
  377. --*/
  378. {
  379. HRESULT hr = S_OK;
  380. DBG_ENTER(_T("CFaxInboundRoutingMethod::get_Name"), hr);
  381. hr = GetBstr(pbstrName, m_bstrName);
  382. if (FAILED(hr))
  383. {
  384. AtlReportError(CLSID_FaxInboundRoutingMethod, GetErrorMsgId(hr), IID_IFaxInboundRoutingMethod, hr);
  385. return hr;
  386. }
  387. return hr;
  388. }
  389. //
  390. //========================= SUPPORT ERROR INFO ====================================
  391. //
  392. STDMETHODIMP
  393. CFaxInboundRoutingMethod::InterfaceSupportsErrorInfo(
  394. REFIID riid
  395. )
  396. /*++
  397. Routine name : CFaxInboundRoutingMethod::InterfaceSupportsErrorInfo
  398. Routine description:
  399. ATL's implementation of Support Error Info.
  400. Author:
  401. Iv Garber (IvG), Jun, 2000
  402. Arguments:
  403. riid [in] - Reference to the Interface.
  404. Return Value:
  405. Standard HRESULT code
  406. --*/
  407. {
  408. static const IID* arr[] =
  409. {
  410. &IID_IFaxInboundRoutingMethod
  411. };
  412. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  413. {
  414. if (InlineIsEqualGUID(*arr[i],riid))
  415. return S_OK;
  416. }
  417. return S_FALSE;
  418. }