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.

682 lines
14 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxOutboundRoutingRule.cpp
  5. Abstract:
  6. Implementation of CFaxOutboundRoutingRule class.
  7. Author:
  8. Iv Garber (IvG) Jun, 2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "FaxComEx.h"
  13. #include "FaxOutboundRoutingRule.h"
  14. #include "..\..\inc\FaxUIConstants.h"
  15. //
  16. //====================== REFRESH ====================================
  17. //
  18. STDMETHODIMP
  19. CFaxOutboundRoutingRule::Refresh(
  20. )
  21. /*++
  22. Routine name : CFaxOutboundRoutingRule::Refresh
  23. Routine description:
  24. Bring up-to-dated Contents of the Rule Object from the Fax Server.
  25. Author:
  26. Iv Garber (IvG), Jun, 2000
  27. Return Value:
  28. Standard HRESULT code
  29. --*/
  30. {
  31. HRESULT hr = S_OK;
  32. DBG_ENTER(_T("CFaxOutboundRoutingRule::Refresh"), hr);
  33. //
  34. // Get Fax Handle
  35. //
  36. HANDLE faxHandle;
  37. hr = m_pIFaxServerInner->GetHandle(&faxHandle);
  38. ATLASSERT(SUCCEEDED(hr));
  39. if (faxHandle == NULL)
  40. {
  41. //
  42. // Fax Server is not connected
  43. //
  44. hr = Fax_HRESULT_FROM_WIN32(ERROR_NOT_CONNECTED);
  45. CALL_FAIL(GENERAL_ERR, _T("faxHandle == NULL"), hr);
  46. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  47. return hr;
  48. }
  49. //
  50. // Call Server for the Data
  51. //
  52. CFaxPtr<FAX_OUTBOUND_ROUTING_RULE> pRules;
  53. DWORD dwNum = 0;
  54. if (!FaxEnumOutboundRules(faxHandle, &pRules, &dwNum))
  55. {
  56. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  57. CALL_FAIL(GENERAL_ERR, _T("FaxEnumOutboundRules(faxHandle, &pRules, &dwNum)"), hr);
  58. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  59. return hr;
  60. }
  61. //
  62. // Find Current Rule
  63. //
  64. for ( DWORD i=0 ; i<dwNum ; i++ )
  65. {
  66. if ( (pRules[i].dwAreaCode == m_dwAreaCode) &&
  67. (pRules[i].dwCountryCode == m_dwCountryCode) )
  68. {
  69. hr = Init(&pRules[i], NULL);
  70. return hr;
  71. }
  72. }
  73. //
  74. // Rule not found
  75. //
  76. hr = Fax_HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  77. CALL_FAIL(GENERAL_ERR, _T("Such Rule is not found anymore"), hr);
  78. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  79. return hr;
  80. }
  81. //
  82. //====================== SAVE ====================================
  83. //
  84. STDMETHODIMP
  85. CFaxOutboundRoutingRule::Save(
  86. )
  87. /*++
  88. Routine name : CFaxOutboundRoutingRule::Save
  89. Routine description:
  90. Save the Contents of the Rule Object to the Fax Server.
  91. Author:
  92. Iv Garber (IvG), Jun, 2000
  93. Return Value:
  94. Standard HRESULT code
  95. --*/
  96. {
  97. HRESULT hr = S_OK;
  98. DBG_ENTER(_T("CFaxOutboundRoutingRule::Save"), hr);
  99. //
  100. // Get Fax Handle
  101. //
  102. HANDLE faxHandle;
  103. hr = m_pIFaxServerInner->GetHandle(&faxHandle);
  104. ATLASSERT(SUCCEEDED(hr));
  105. if (faxHandle == NULL)
  106. {
  107. //
  108. // Fax Server is not connected
  109. //
  110. hr = Fax_HRESULT_FROM_WIN32(ERROR_NOT_CONNECTED);
  111. CALL_FAIL(GENERAL_ERR, _T("faxHandle == NULL"), hr);
  112. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  113. return hr;
  114. }
  115. //
  116. // Create Structure with Rule's Data
  117. //
  118. FAX_OUTBOUND_ROUTING_RULE ruleData;
  119. ruleData.bUseGroup = (!m_bUseDevice);
  120. if (m_bUseDevice)
  121. {
  122. ruleData.Destination.dwDeviceId = m_dwDeviceId;
  123. }
  124. else
  125. {
  126. ruleData.Destination.lpcstrGroupName = m_bstrGroupName;
  127. }
  128. ruleData.dwAreaCode = m_dwAreaCode;
  129. ruleData.dwCountryCode = m_dwCountryCode;
  130. ruleData.dwSizeOfStruct = sizeof(FAX_OUTBOUND_ROUTING_RULE);
  131. ruleData.Status = FAX_ENUM_RULE_STATUS(m_Status);
  132. //
  133. // Call Server
  134. //
  135. if (!FaxSetOutboundRule(faxHandle, &ruleData))
  136. {
  137. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  138. CALL_FAIL(GENERAL_ERR, _T("FaxSetOutboundRule(faxHandle, &ruleData)"), hr);
  139. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  140. return hr;
  141. }
  142. return hr;
  143. }
  144. //
  145. //====================== PUT GROUP NAME ====================================
  146. //
  147. STDMETHODIMP
  148. CFaxOutboundRoutingRule::put_GroupName(
  149. /*[in]*/ BSTR bstrGroupName
  150. )
  151. /*++
  152. Routine name : CFaxOutboundRoutingRule::put_GroupName
  153. Routine description:
  154. Set new Group Name for the Rule.
  155. Author:
  156. Iv Garber (IvG), Jun, 2000
  157. Arguments:
  158. bstrGroupName [in] - the new value for the Group Name
  159. Return Value:
  160. Standard HRESULT code
  161. --*/
  162. {
  163. HRESULT hr = S_OK;
  164. DBG_ENTER(_T("CFaxOutboundRoutingRule::put_GroupName"), hr, _T("New Value=%s"), bstrGroupName);
  165. m_bstrGroupName = bstrGroupName;
  166. if (bstrGroupName && !m_bstrGroupName)
  167. {
  168. hr = E_OUTOFMEMORY;
  169. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator =()"), hr);
  170. AtlReportError(CLSID_FaxOutboundRoutingRule, IDS_ERROR_OUTOFMEMORY, IID_IFaxOutboundRoutingRule, hr);
  171. return hr;
  172. }
  173. return hr;
  174. }
  175. //
  176. //===================== GET GROUP NAME ======================================
  177. //
  178. STDMETHODIMP
  179. CFaxOutboundRoutingRule::get_GroupName(
  180. /*[out, retval]*/ BSTR *pbstrGroupName
  181. )
  182. /*++
  183. Routine name : CFaxOutboundRoutingRule::get_GroupName
  184. Routine description:
  185. Return the Group Name of the Rule.
  186. Author:
  187. Iv Garber (IvG), Jun, 2000
  188. Arguments:
  189. pbstrGroupName [out] - The Result
  190. Return Value:
  191. Standard HRESULT code
  192. --*/
  193. {
  194. HRESULT hr = S_OK;
  195. DBG_ENTER(_T("CFaxOutboundRoutingRule::get_GroupName"), hr);
  196. hr = GetBstr(pbstrGroupName, m_bstrGroupName);
  197. if (FAILED(hr))
  198. {
  199. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  200. return hr;
  201. }
  202. return hr;
  203. }
  204. //
  205. //====================== PUT DEVICE ID ====================================
  206. //
  207. STDMETHODIMP
  208. CFaxOutboundRoutingRule::put_DeviceId(
  209. /*[in]*/ long lDeviceId
  210. )
  211. /*++
  212. Routine name : CFaxOutboundRoutingRule::put_DeviceId
  213. Routine description:
  214. Set new Device Id for the Rule.
  215. Author:
  216. Iv Garber (IvG), Jun, 2000
  217. Arguments:
  218. lDeviceId [in] - the new value for the Device
  219. Return Value:
  220. Standard HRESULT code
  221. --*/
  222. {
  223. HRESULT hr = S_OK;
  224. DBG_ENTER(_T("CFaxOutboundRoutingRule::put_DeviceId"), hr, _T("New Value=%ld"), lDeviceId);
  225. if ((lDeviceId > FXS_MAX_PORT_NUM) || (lDeviceId < FXS_MIN_PORT_NUM))
  226. {
  227. //
  228. // Out of the Range
  229. //
  230. hr = E_INVALIDARG;
  231. AtlReportError(CLSID_FaxOutboundRoutingRule, IDS_ERROR_OUTOFRANGE, IID_IFaxOutboundRoutingRule, hr);
  232. CALL_FAIL(GENERAL_ERR, _T("Device ID is out of the Range"), hr);
  233. return hr;
  234. }
  235. m_dwDeviceId = lDeviceId;
  236. return hr;
  237. }
  238. //
  239. //===================== GET DEVICE ID ======================================
  240. //
  241. STDMETHODIMP
  242. CFaxOutboundRoutingRule::get_DeviceId(
  243. /*[out, retval]*/ long *plDeviceId
  244. )
  245. /*++
  246. Routine name : CFaxOutboundRoutingRule::get_DeviceId
  247. Routine description:
  248. Return the Device Id of the Rule.
  249. Author:
  250. Iv Garber (IvG), Jun, 2000
  251. Arguments:
  252. plDeviceId [out] - The Result
  253. Return Value:
  254. Standard HRESULT code
  255. --*/
  256. {
  257. HRESULT hr = S_OK;
  258. DBG_ENTER(_T("CFaxOutboundRoutingRule::get_DeviceId"), hr);
  259. hr = GetLong(plDeviceId, m_dwDeviceId);
  260. if (FAILED(hr))
  261. {
  262. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  263. return hr;
  264. }
  265. return hr;
  266. }
  267. //
  268. //====================== PUT USE DEVICE ====================================
  269. //
  270. STDMETHODIMP
  271. CFaxOutboundRoutingRule::put_UseDevice(
  272. /*[in]*/ VARIANT_BOOL bUseDevice
  273. )
  274. /*++
  275. Routine name : CFaxOutboundRoutingRule::put_UseDevice
  276. Routine description:
  277. Set new Value for Use Device Flag.
  278. Author:
  279. Iv Garber (IvG), Jun, 2000
  280. Arguments:
  281. bUseDevice [in] - the new value for the Flag
  282. Return Value:
  283. Standard HRESULT code
  284. --*/
  285. {
  286. HRESULT hr = S_OK;
  287. DBG_ENTER(_T("CFaxOutboundRoutingRule::put_UseDevice"), hr, _T("New Value=%d"), bUseDevice);
  288. m_bUseDevice = VARIANT_BOOL2bool(bUseDevice);
  289. return hr;
  290. }
  291. //
  292. //===================== GET USE DEVICE ======================================
  293. //
  294. STDMETHODIMP
  295. CFaxOutboundRoutingRule::get_UseDevice(
  296. /*[out, retval]*/ VARIANT_BOOL *pbUseDevice
  297. )
  298. /*++
  299. Routine name : CFaxOutboundRoutingRule::get_UseDevice
  300. Routine description:
  301. Return whether the Rule uses Device.
  302. Author:
  303. Iv Garber (IvG), Jun, 2000
  304. Arguments:
  305. pbUseDevice [out] - The Result
  306. Return Value:
  307. Standard HRESULT code
  308. --*/
  309. {
  310. HRESULT hr = S_OK;
  311. DBG_ENTER(_T("CFaxOutboundRoutingRule::get_UseDevice"), hr);
  312. hr = GetVariantBool(pbUseDevice, bool2VARIANT_BOOL(m_bUseDevice));
  313. if (FAILED(hr))
  314. {
  315. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  316. return hr;
  317. }
  318. return hr;
  319. }
  320. //
  321. //===================== GET STATUS ======================================
  322. //
  323. STDMETHODIMP
  324. CFaxOutboundRoutingRule::get_Status(
  325. /*[out, retval]*/ FAX_RULE_STATUS_ENUM *pStatus
  326. )
  327. /*++
  328. Routine name : CFaxOutboundRoutingRule::get_Status
  329. Routine description:
  330. Return Status of the Rule.
  331. Author:
  332. Iv Garber (IvG), Jun, 2000
  333. Arguments:
  334. pStatus [out] - The Result
  335. Return Value:
  336. Standard HRESULT code
  337. --*/
  338. {
  339. HRESULT hr = S_OK;
  340. DBG_ENTER(_T("CFaxOutboundRoutingRule::get_Status"), hr);
  341. //
  342. // Check that we have got good Ptr
  343. //
  344. if (::IsBadWritePtr(pStatus, sizeof(FAX_RULE_STATUS_ENUM)))
  345. {
  346. hr = E_POINTER;
  347. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr(pStatus, sizeof(FAX_RULE_STATUS_ENUM))"), hr);
  348. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  349. return hr;
  350. }
  351. *pStatus = m_Status;
  352. return hr;
  353. }
  354. //
  355. //===================== GET AREA CODE ======================================
  356. //
  357. STDMETHODIMP
  358. CFaxOutboundRoutingRule::get_AreaCode(
  359. /*[out, retval]*/ long *plAreaCode
  360. )
  361. /*++
  362. Routine name : CFaxOutboundRoutingRule::get_AreaCode
  363. Routine description:
  364. Return Area Code of the Rule.
  365. Author:
  366. Iv Garber (IvG), Jun, 2000
  367. Arguments:
  368. plAreaCode [out] - The Result
  369. Return Value:
  370. Standard HRESULT code
  371. --*/
  372. {
  373. HRESULT hr = S_OK;
  374. DBG_ENTER(_T("CFaxOutboundRoutingRule::get_AreaCode"), hr);
  375. hr = GetLong(plAreaCode, m_dwAreaCode);
  376. if (FAILED(hr))
  377. {
  378. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  379. return hr;
  380. }
  381. return hr;
  382. }
  383. //
  384. //===================== GET COUNTRY CODE ======================================
  385. //
  386. STDMETHODIMP
  387. CFaxOutboundRoutingRule::get_CountryCode(
  388. /*[out, retval]*/ long *plCountryCode
  389. )
  390. /*++
  391. Routine name : CFaxOutboundRoutingRule::get_CountryCode
  392. Routine description:
  393. Return Country Code of the Rule.
  394. Author:
  395. Iv Garber (IvG), Jun, 2000
  396. Arguments:
  397. plCountryCode [out] - The Result
  398. Return Value:
  399. Standard HRESULT code
  400. --*/
  401. {
  402. HRESULT hr = S_OK;
  403. DBG_ENTER(_T("CFaxOutboundRoutingRule::get_CountryCode"), hr);
  404. hr = GetLong(plCountryCode, m_dwCountryCode);
  405. if (FAILED(hr))
  406. {
  407. AtlReportError(CLSID_FaxOutboundRoutingRule, GetErrorMsgId(hr), IID_IFaxOutboundRoutingRule, hr);
  408. return hr;
  409. }
  410. return hr;
  411. }
  412. //
  413. //===================== SUPPORT ERROR INFO ======================================
  414. //
  415. STDMETHODIMP
  416. CFaxOutboundRoutingRule::InterfaceSupportsErrorInfo(
  417. REFIID riid
  418. )
  419. /*++
  420. Routine name : CFaxOutboundRoutingRule::InterfaceSupportsErrorInfo
  421. Routine description:
  422. ATL's implementation of Support Error Info.
  423. Author:
  424. Iv Garber (IvG), Jun, 2000
  425. Arguments:
  426. riid [in] - reference to the Interface.
  427. Return Value:
  428. Standard HRESULT code
  429. --*/
  430. {
  431. static const IID* arr[] =
  432. {
  433. &IID_IFaxOutboundRoutingRule
  434. };
  435. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  436. {
  437. if (InlineIsEqualGUID(*arr[i],riid))
  438. return S_OK;
  439. }
  440. return S_FALSE;
  441. }
  442. //
  443. //=================== INIT ======================================
  444. //
  445. STDMETHODIMP
  446. CFaxOutboundRoutingRule::Init(
  447. /*[in]*/ FAX_OUTBOUND_ROUTING_RULE *pInfo,
  448. /*[in]*/ IFaxServerInner *pServer
  449. )
  450. /*++
  451. Routine name : CFaxOutboundRoutingRule::Init
  452. Routine description:
  453. Initialize the Rule Object.
  454. Author:
  455. Iv Garber (IvG), Jun, 2000
  456. Arguments:
  457. pInfo [in] - Ptr to the Rule Info Structure
  458. pServer [in] - Ptr to the Fax Server Object.
  459. Return Value:
  460. Standard HRESULT code
  461. --*/
  462. {
  463. HRESULT hr = S_OK;
  464. DBG_ENTER(_T("CFaxOutboundRoutingRule::Init"), hr);
  465. //
  466. // Store data from the Struct internally
  467. //
  468. m_dwAreaCode = pInfo->dwAreaCode;
  469. m_dwCountryCode = pInfo->dwCountryCode;
  470. m_Status = FAX_RULE_STATUS_ENUM(pInfo->Status);
  471. m_bUseDevice = (!pInfo->bUseGroup);
  472. if (m_bUseDevice)
  473. {
  474. m_dwDeviceId = pInfo->Destination.dwDeviceId;
  475. m_bstrGroupName.Empty();
  476. }
  477. else
  478. {
  479. m_dwDeviceId = 0;
  480. m_bstrGroupName = pInfo->Destination.lpcstrGroupName;
  481. if (pInfo->Destination.lpcstrGroupName && !m_bstrGroupName)
  482. {
  483. hr = E_OUTOFMEMORY;
  484. CALL_FAIL(MEM_ERR, _T("CComBSTR::operator =()"), hr);
  485. AtlReportError(CLSID_FaxOutboundRoutingRule, IDS_ERROR_OUTOFMEMORY, IID_IFaxOutboundRoutingRule, hr);
  486. return hr;
  487. }
  488. }
  489. //
  490. // When called from Refresh, no need to update Ptr to Fax Server Object
  491. //
  492. if (pServer)
  493. {
  494. //
  495. // Store the Ptr to the Fax Server Object and make AddRef() on it
  496. //
  497. hr = CFaxInitInnerAddRef::Init(pServer);
  498. }
  499. return hr;
  500. }