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.

1055 lines
26 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : OutboundRule.cpp //
  3. // //
  4. // DESCRIPTION : Implementation of the Outbound Routing Rule node. //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Dec 24 1999 yossg Create //
  10. // Dec 30 1999 yossg create ADD/REMOVE rule //
  11. // Oct 17 2000 yossg //
  12. // //
  13. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  14. // //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "StdAfx.h"
  17. #include "snapin.h"
  18. #include "OutboundRule.h"
  19. #include "OutboundRules.h"
  20. #include "ppFaxOutboundRoutingRule.h"
  21. #include "FaxServer.h"
  22. #include "FaxServerNode.h"
  23. #include "FaxMMCPropertyChange.h"
  24. #include "oaidl.h"
  25. #include "urlmon.h"
  26. #include "mshtmhst.h"
  27. #include "exdisp.h"
  28. /////////////////////////////////////////////////////////////////////////////
  29. // {4A7636D3-13A4-4496-873F-AD5CB7360D3B}
  30. static const GUID CFaxOutboundRoutingRuleNodeGUID_NODETYPE =
  31. { 0x4a7636d3, 0x13a4, 0x4496, { 0x87, 0x3f, 0xad, 0x5c, 0xb7, 0x36, 0xd, 0x3b } };
  32. const GUID* CFaxOutboundRoutingRuleNode::m_NODETYPE = &CFaxOutboundRoutingRuleNodeGUID_NODETYPE;
  33. const OLECHAR* CFaxOutboundRoutingRuleNode::m_SZNODETYPE = OLESTR("4A7636D3-13A4-4496-873F-AD5CB7360D3B");
  34. //const OLECHAR* CnotImplemented::m_SZDISPLAY_NAME = OLESTR("Outbound Routing Rules");
  35. const CLSID* CFaxOutboundRoutingRuleNode::m_SNAPIN_CLASSID = &CLSID_Snapin;
  36. /*
  37. - CFaxOutboundRoutingRuleNode::Init
  38. -
  39. * Purpose:
  40. * Init all members icon etc.
  41. *
  42. * Arguments:
  43. * [in] pRuleConfig - PFAX_OUTBOUND_ROUTING_RULE
  44. *
  45. * Return:
  46. * OLE error code
  47. */
  48. HRESULT CFaxOutboundRoutingRuleNode::Init(PFAX_OUTBOUND_ROUTING_RULE pRuleConfig)
  49. {
  50. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRuleNode::Init"));
  51. HRESULT hRc = S_OK;
  52. ATLASSERT(pRuleConfig);
  53. hRc = InitMembers( pRuleConfig );
  54. if (FAILED(hRc))
  55. {
  56. DebugPrintEx(
  57. DEBUG_ERR,
  58. _T("Failed to InitMembers"));
  59. //NodeMsgBox done by called func.
  60. goto Exit;
  61. }
  62. ATLASSERT(SUCCEEDED(hRc));
  63. //
  64. // Icon
  65. //
  66. InitIcons();
  67. Exit:
  68. return hRc;
  69. }
  70. /*
  71. - CFaxOutboundRoutingRuleNode::InitIcons
  72. -
  73. * Purpose:
  74. * Private method that initiate icons
  75. * due to the status member state.
  76. *
  77. * Arguments:
  78. * No.
  79. *
  80. * Return:
  81. * No.
  82. */
  83. void CFaxOutboundRoutingRuleNode::InitIcons ()
  84. {
  85. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRuleNode::InitIcons"));
  86. switch (m_enumStatus)
  87. {
  88. case FAX_RULE_STATUS_VALID:
  89. m_resultDataItem.nImage = IMAGE_RULE;
  90. break;
  91. case FAX_RULE_STATUS_SOME_GROUP_DEV_NOT_VALID:
  92. m_resultDataItem.nImage = IMAGE_RULE_WARNING;
  93. break;
  94. case FAX_RULE_STATUS_EMPTY_GROUP:
  95. case FAX_RULE_STATUS_ALL_GROUP_DEV_NOT_VALID:
  96. case FAX_RULE_STATUS_BAD_DEVICE:
  97. m_resultDataItem.nImage = IMAGE_RULE_ERROR;
  98. break;
  99. default:
  100. ATLASSERT(0); // "this enumStatus is not supported "
  101. break; //currently 999
  102. } // endswitch (enumStatus)
  103. return;
  104. }
  105. /*
  106. - CFaxOutboundRoutingRuleNode::InitMembers
  107. -
  108. * Purpose:
  109. * Private method to initiate members
  110. * Must be called after init of m_pParentNode
  111. *
  112. * Arguments:
  113. * [in] pRuleConfig - PFAX_OUTBOUND_ROUTING_RULE structure
  114. *
  115. * Return:
  116. * OLE error code
  117. */
  118. HRESULT CFaxOutboundRoutingRuleNode::InitMembers(PFAX_OUTBOUND_ROUTING_RULE pRuleConfig)
  119. {
  120. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRuleNode::InitMembers"));
  121. HRESULT hRc = S_OK;
  122. int iCount;
  123. WCHAR buff[2*FXS_MAX_CODE_LEN+1];
  124. ATLASSERT(pRuleConfig);
  125. //
  126. // status
  127. //
  128. m_enumStatus = pRuleConfig->Status;
  129. //
  130. // Country code and name
  131. //
  132. m_dwCountryCode = pRuleConfig->dwCountryCode;
  133. if (ROUTING_RULE_COUNTRY_CODE_ANY != m_dwCountryCode)
  134. {
  135. if (NULL != pRuleConfig->lpctstrCountryName)
  136. {
  137. m_bstrCountryName = pRuleConfig->lpctstrCountryName;
  138. //m_fIsAllCountries = FALSE; done at constructor. here only verify
  139. ATLASSERT( FALSE == m_fIsAllCountries );
  140. }
  141. else //special case
  142. {
  143. // Service did not provide the country names of countries with IDs
  144. // between 101 to 124
  145. //ec = GetCountryNameFromID(m_dwCountryCode);
  146. //if ( ERROR_SUCCESS != ec )
  147. //{
  148. //}
  149. m_bstrCountryName = L"";
  150. ATLASSERT( FALSE == m_fIsAllCountries );
  151. }
  152. }
  153. else //ROUTING_RULE_COUNTRY_CODE_ANY == m_dwCountryCode
  154. {
  155. m_bstrCountryName = L"";
  156. m_fIsAllCountries = TRUE;
  157. }
  158. if ( !m_bstrCountryName )
  159. {
  160. hRc = E_OUTOFMEMORY;
  161. goto Error;
  162. }
  163. //
  164. // area code
  165. //
  166. m_dwAreaCode = pRuleConfig->dwAreaCode;
  167. //
  168. // Group/Device
  169. //
  170. m_fIsGroup = pRuleConfig->bUseGroup;
  171. if ( m_fIsGroup )
  172. {
  173. m_bstrGroupName = pRuleConfig->Destination.lpcstrGroupName;
  174. if (!m_bstrGroupName)
  175. {
  176. hRc = E_OUTOFMEMORY;
  177. goto Error;
  178. }
  179. }
  180. else
  181. {
  182. m_dwDeviceID = pRuleConfig->Destination.dwDeviceId;
  183. DWORD ec = ERROR_SUCCESS;
  184. ec = InitDeviceNameFromID(m_dwDeviceID);
  185. if ( ERROR_SUCCESS != ec )
  186. {
  187. if (ERROR_BAD_UNIT != ec)
  188. {
  189. hRc = HRESULT_FROM_WIN32(ec);
  190. }
  191. else //The system cannot find the device specified
  192. {
  193. if ( FAX_RULE_STATUS_VALID != m_enumStatus)
  194. {
  195. m_enumStatus = FAX_RULE_STATUS_BAD_DEVICE;
  196. DebugPrintEx(
  197. DEBUG_MSG,
  198. TEXT("m_enumStatus was changed after ERROR_BAD_UNIT failure."));
  199. }
  200. //hRc stays S_OK !!! since we will intrduce this bad state
  201. }
  202. m_bstrDeviceName=L"???";
  203. //message box done by GetDeviceNameFromID
  204. goto Exit;
  205. }
  206. ATLASSERT(m_bstrDeviceName);
  207. }
  208. //
  209. // Pepare m_bstrDisplayName for NodeMsgBox
  210. //
  211. iCount = swprintf(buff, L"+%ld (%ld)", m_dwCountryCode, m_dwAreaCode);
  212. if( iCount <= 0 )
  213. {
  214. DebugPrintEx(
  215. DEBUG_ERR,
  216. TEXT("Fail to read CountryCode and/or AreaCode."));
  217. goto Error;
  218. }
  219. m_bstrDisplayName = buff;
  220. if (!m_bstrDisplayName)
  221. {
  222. hRc = E_OUTOFMEMORY;
  223. goto Error;
  224. }
  225. ATLASSERT(S_OK == hRc);
  226. goto Exit;
  227. Error:
  228. ATLASSERT(S_OK != hRc);
  229. DebugPrintEx(
  230. DEBUG_ERR,
  231. _T("Failed to allocate string - out of memory"));
  232. ATLASSERT(NULL != m_pParentNode);
  233. if (NULL != m_pParentNode)
  234. {
  235. m_pParentNode->NodeMsgBox(IDS_MEMORY);
  236. }
  237. Exit:
  238. return (hRc);
  239. }
  240. /*
  241. - CFaxOutboundRoutingRuleNode::GetResultPaneColInfo
  242. -
  243. * Purpose:
  244. * Return the text for specific column
  245. * Called for each column in the result pane
  246. *
  247. * Arguments:
  248. * [in] nCol - column number
  249. *
  250. * Return:
  251. * String to be displayed in the specific column
  252. */
  253. LPOLESTR CFaxOutboundRoutingRuleNode::GetResultPaneColInfo(int nCol)
  254. {
  255. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRuleNode::GetResultPaneColInfo"));
  256. HRESULT hRc = S_OK;
  257. UINT idsStatus;
  258. int iCount;
  259. WCHAR buffCountryCode[FXS_MAX_CODE_LEN+1];
  260. WCHAR buffAreaCode[FXS_MAX_CODE_LEN+1];
  261. m_buf.Empty();
  262. switch (nCol)
  263. {
  264. case 0:
  265. //
  266. // Country code
  267. //
  268. if (ROUTING_RULE_COUNTRY_CODE_ANY == m_dwCountryCode)
  269. {
  270. if (!m_buf.LoadString(IDS_COUNTRY_CODE_ANY))
  271. {
  272. hRc = E_OUTOFMEMORY;
  273. DebugPrintEx(
  274. DEBUG_ERR,
  275. TEXT("Out of memory. Failed to load country code string."));
  276. goto Error;
  277. }
  278. return m_buf;
  279. }
  280. else
  281. {
  282. iCount = swprintf(buffCountryCode, L"%ld", m_dwCountryCode);
  283. if( iCount <= 0 )
  284. {
  285. DebugPrintEx(
  286. DEBUG_ERR,
  287. TEXT("Fail to read member - CountryCode."));
  288. goto Error;
  289. }
  290. else
  291. {
  292. m_buf = buffCountryCode;
  293. return (m_buf);
  294. }
  295. }
  296. case 1:
  297. //
  298. // Area code
  299. //
  300. if (ROUTING_RULE_AREA_CODE_ANY == m_dwAreaCode)
  301. {
  302. if (!m_buf.LoadString(IDS_ALL_AREAS))
  303. {
  304. hRc = E_OUTOFMEMORY;
  305. DebugPrintEx(
  306. DEBUG_ERR,
  307. TEXT("Out of memory. Failed to load area code string."));
  308. goto Error;
  309. }
  310. return m_buf;
  311. }
  312. else
  313. {
  314. iCount = swprintf(buffAreaCode, L"%ld", m_dwAreaCode);
  315. if( iCount <= 0 )
  316. {
  317. DebugPrintEx(
  318. DEBUG_ERR,
  319. TEXT("Fail to read member - AreaCode."));
  320. goto Error;
  321. }
  322. else
  323. {
  324. m_buf = buffAreaCode;
  325. return (m_buf);
  326. }
  327. }
  328. case 2:
  329. //
  330. // Group/Device
  331. //
  332. if (m_fIsGroup)
  333. {
  334. if(0 == wcscmp(ROUTING_GROUP_ALL_DEVICES, m_bstrGroupName) )
  335. {
  336. if (!m_buf.LoadString(IDS_ALL_DEVICES))
  337. {
  338. hRc = E_OUTOFMEMORY;
  339. DebugPrintEx(
  340. DEBUG_ERR,
  341. TEXT("Out of memory. Failed to all-devices group string."));
  342. goto Error;
  343. }
  344. return m_buf;
  345. }
  346. else
  347. {
  348. if (!m_bstrGroupName)
  349. {
  350. DebugPrintEx(
  351. DEBUG_ERR,
  352. TEXT("Null memeber BSTR - m_bstrGroupName."));
  353. goto Error;
  354. }
  355. else
  356. {
  357. return (m_bstrGroupName);
  358. }
  359. }
  360. }
  361. else
  362. {
  363. if (!m_bstrDeviceName)
  364. {
  365. DebugPrintEx(
  366. DEBUG_ERR,
  367. TEXT("Null memeber BSTR - m_bstrDeviceName."));
  368. goto Error;
  369. }
  370. else
  371. {
  372. return (m_bstrDeviceName);
  373. }
  374. }
  375. case 3:
  376. //
  377. // Status
  378. //
  379. idsStatus = GetStatusIDS(m_enumStatus);
  380. if ( FXS_IDS_STATUS_ERROR == idsStatus)
  381. {
  382. DebugPrintEx(
  383. DEBUG_ERR,
  384. TEXT("Invalid Status value."));
  385. goto Error;
  386. }
  387. else
  388. {
  389. if (!m_buf.LoadString(idsStatus))
  390. {
  391. hRc = E_OUTOFMEMORY;
  392. DebugPrintEx(
  393. DEBUG_ERR,
  394. TEXT("Out of memory. Failed to load status string."));
  395. goto Error;
  396. }
  397. return m_buf;
  398. }
  399. default:
  400. ATLASSERT(0); // "this number of column is not supported "
  401. return(L"");
  402. } // endswitch (nCol)
  403. Error:
  404. return(L"???");
  405. }
  406. /*
  407. - CFaxOutboundRoutingRuleNode::CreatePropertyPages
  408. -
  409. * Purpose:
  410. * Called when creating a property page of the object
  411. *
  412. * Arguments:
  413. * [in] lpProvider - The property sheet
  414. * [in] handle - Handle for notification
  415. * [in] pUnk - Pointer to the data object
  416. * [in] type - CCT_* (SCOPE, RESULT, ...)
  417. *
  418. * Return:
  419. * OLE error code
  420. */
  421. HRESULT
  422. CFaxOutboundRoutingRuleNode::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  423. LONG_PTR handle,
  424. IUnknown *pUnk,
  425. DATA_OBJECT_TYPES type)
  426. {
  427. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRuleNode::CreatePropertyPages"));
  428. HRESULT hRc = S_OK;
  429. ATLASSERT(lpProvider);
  430. ATLASSERT(type == CCT_RESULT || type == CCT_SCOPE);
  431. //
  432. // Initiate
  433. //
  434. m_pRuleGeneralPP = NULL;
  435. //
  436. // General
  437. //
  438. m_pRuleGeneralPP = new CppFaxOutboundRoutingRule(
  439. handle,
  440. this,
  441. TRUE,
  442. _Module.GetResourceInstance());
  443. if (!m_pRuleGeneralPP)
  444. {
  445. hRc = E_OUTOFMEMORY;
  446. NodeMsgBox(IDS_MEMORY_FAIL_TO_OPEN_PP);
  447. goto Error;
  448. }
  449. hRc = m_pRuleGeneralPP->InitFaxRulePP(this);
  450. if (FAILED(hRc))
  451. {
  452. //DebugPrint by called func
  453. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  454. goto Error;
  455. }
  456. hRc = lpProvider->AddPage(m_pRuleGeneralPP->Create());
  457. if (FAILED(hRc))
  458. {
  459. DebugPrintEx(
  460. DEBUG_ERR,
  461. TEXT("Fail to add property page for General tab. (hRc: %08X)"),
  462. hRc);
  463. NodeMsgBox(IDS_FAIL_TO_OPEN_PROP_PAGE);
  464. goto Error;
  465. }
  466. ATLASSERT(S_OK == hRc);
  467. goto Exit;
  468. Error:
  469. ATLASSERT(S_OK != hRc);
  470. if ( NULL != m_pRuleGeneralPP )
  471. {
  472. delete m_pRuleGeneralPP;
  473. m_pRuleGeneralPP = NULL;
  474. }
  475. Exit:
  476. return hRc;
  477. }
  478. /*
  479. - CFaxOutboundRoutingRuleNode::SetVerbs
  480. -
  481. * Purpose:
  482. * What verbs to enable/disable when this object is selected
  483. *
  484. * Arguments:
  485. * [in] pConsoleVerb - MMC ConsoleVerb interface
  486. *
  487. * Return:
  488. * OLE Error code
  489. */
  490. HRESULT CFaxOutboundRoutingRuleNode::SetVerbs(IConsoleVerb *pConsoleVerb)
  491. {
  492. HRESULT hRc = S_OK;
  493. //
  494. // Display verbs that we support:
  495. // 1. Properties
  496. // 2. Delete
  497. // 3. Refresh
  498. //
  499. hRc = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  500. if (ROUTING_RULE_COUNTRY_CODE_ANY == m_dwCountryCode)
  501. {
  502. hRc = pConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, FALSE);
  503. hRc = pConsoleVerb->SetVerbState(MMC_VERB_DELETE, INDETERMINATE, TRUE);
  504. }
  505. else
  506. {
  507. hRc = pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  508. }
  509. // hRc = pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  510. //
  511. // We want the default verb to be Properties
  512. //
  513. hRc = pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  514. return hRc;
  515. }
  516. /*
  517. - CFaxOutboundRoutingRuleNode::OnRefresh
  518. -
  519. * Purpose:
  520. * Called when refreshing the object.
  521. *
  522. * Arguments:
  523. *
  524. * Return:
  525. * OLE error code
  526. */
  527. /* virtual */HRESULT
  528. CFaxOutboundRoutingRuleNode::OnRefresh(LPARAM arg,
  529. LPARAM param,
  530. IComponentData *pComponentData,
  531. IComponent * pComponent,
  532. DATA_OBJECT_TYPES type)
  533. {
  534. HRESULT hRc = S_OK;
  535. CComPtr<IConsole> spConsole;
  536. //
  537. // TBD - At The moment do nothing
  538. //
  539. return hRc;
  540. }
  541. /*
  542. - CFaxOutboundRoutingRuleNode::GetStatusIDS
  543. -
  544. * Purpose:
  545. * Transslate Status to IDS.
  546. *
  547. * Arguments:
  548. *
  549. * [in] enumStatus - unsigned int with the menu IDM value
  550. *
  551. * Return:
  552. * IDS of related status message
  553. */
  554. UINT CFaxOutboundRoutingRuleNode::GetStatusIDS(FAX_ENUM_RULE_STATUS enumStatus)
  555. {
  556. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRuleNode::GetStatusIDS"));
  557. switch (enumStatus)
  558. {
  559. case FAX_RULE_STATUS_VALID:
  560. return IDS_STATUS_RULE_VALID;
  561. case FAX_RULE_STATUS_EMPTY_GROUP:
  562. return IDS_STATUS_RULE_EMPTY;
  563. case FAX_RULE_STATUS_ALL_GROUP_DEV_NOT_VALID:
  564. return IDS_STATUS_RULE_ALLDEVICESINVALID;
  565. case FAX_RULE_STATUS_SOME_GROUP_DEV_NOT_VALID:
  566. return IDS_STATUS_RULE_SOMEDEVICESINVALID;
  567. case FAX_RULE_STATUS_BAD_DEVICE:
  568. return IDS_STATUS_RULE_INVALID_DEVICE;
  569. default:
  570. ATLASSERT(0); // "this enumStatus is not supported "
  571. return(FXS_IDS_STATUS_ERROR); //currently 999
  572. } // endswitch (enumStatus)
  573. }
  574. /*
  575. - CFaxOutboundRoutingRuleNode::InitDeviceNameFromID
  576. -
  577. * Purpose:
  578. * Transslate Device ID to Device Name and insert the data to
  579. * m_bstrDeviceName
  580. *
  581. * Arguments:
  582. *
  583. * [in] dwDeviceID - device ID
  584. *
  585. * Return:
  586. * Error Code DWORD //OLE error message
  587. */
  588. DWORD CFaxOutboundRoutingRuleNode::InitDeviceNameFromID(DWORD dwDeviceID)
  589. {
  590. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRuleNode::GetDeviceNameFromID"));
  591. DWORD ec = ERROR_SUCCESS;
  592. CFaxServer * pFaxServer = NULL;
  593. PFAX_PORT_INFO_EX pFaxDeviceConfig = NULL ;
  594. //
  595. // get RPC Handle
  596. //
  597. pFaxServer = ((CFaxServerNode *)GetRootNode())->GetFaxServer();
  598. ATLASSERT(pFaxServer);
  599. if (!pFaxServer->GetFaxServerHandle())
  600. {
  601. ec= GetLastError();
  602. DebugPrintEx(
  603. DEBUG_ERR,
  604. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  605. ec);
  606. goto Error;
  607. }
  608. //
  609. // Retrieve the Device configuration
  610. //
  611. if (!FaxGetPortEx(pFaxServer->GetFaxServerHandle(),
  612. m_dwDeviceID,
  613. &pFaxDeviceConfig))
  614. {
  615. ec = GetLastError();
  616. DebugPrintEx(
  617. DEBUG_ERR,
  618. _T("Fail to get device configuration. (ec: %ld)"),
  619. ec);
  620. if (IsNetworkError(ec))
  621. {
  622. DebugPrintEx(
  623. DEBUG_ERR,
  624. _T("Network Error was found. (ec: %ld)"),
  625. ec);
  626. pFaxServer->Disconnect();
  627. }
  628. goto Error;
  629. }
  630. //For max verification
  631. ATLASSERT(pFaxDeviceConfig);
  632. //
  633. // Retrieve the Device Name
  634. //
  635. m_bstrDeviceName = pFaxDeviceConfig->lpctstrDeviceName;
  636. if (!m_bstrDeviceName)
  637. {
  638. ec = ERROR_NOT_ENOUGH_MEMORY;
  639. goto Error;
  640. }
  641. ATLASSERT(ec == ERROR_SUCCESS);
  642. DebugPrintEx( DEBUG_MSG,
  643. _T("Succeed to get device configuration."));
  644. goto Exit;
  645. Error:
  646. ATLASSERT(ERROR_SUCCESS != ec);
  647. //Important!!!
  648. pFaxDeviceConfig = NULL;
  649. if (ERROR_BAD_UNIT != ec)
  650. {
  651. NodeMsgBox(GetFaxServerErrorMsg(ec));
  652. }
  653. else
  654. {
  655. NodeMsgBox(IDS_FAIL_TO_DISCOVERDEVICENAME);
  656. }
  657. Exit:
  658. if (NULL != pFaxDeviceConfig)
  659. {
  660. FaxFreeBuffer(pFaxDeviceConfig);
  661. pFaxDeviceConfig = NULL;
  662. }//any way function quits with memory allocation freed
  663. return ec;
  664. }
  665. /*
  666. - CFaxOutboundRoutingRuleNode::OnDelete
  667. -
  668. * Purpose:
  669. * Called when deleting this node
  670. *
  671. * Arguments:
  672. *
  673. * Return:
  674. * OLE error code
  675. */
  676. HRESULT CFaxOutboundRoutingRuleNode::OnDelete(
  677. LPARAM arg,
  678. LPARAM param,
  679. IComponentData *pComponentData,
  680. IComponent *pComponent,
  681. DATA_OBJECT_TYPES type,
  682. BOOL fSilent/* = FALSE*/
  683. )
  684. {
  685. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingGroupNode::OnDelete"));
  686. UNREFERENCED_PARAMETER (arg);
  687. UNREFERENCED_PARAMETER (param);
  688. UNREFERENCED_PARAMETER (pComponentData);
  689. UNREFERENCED_PARAMETER (pComponent);
  690. UNREFERENCED_PARAMETER (type);
  691. HRESULT hRc = S_OK;
  692. //
  693. // Are you sure?
  694. //
  695. if (! fSilent)
  696. {
  697. //
  698. // 1. Use pConsole as owner of the message box
  699. //
  700. int res;
  701. NodeMsgBox(IDS_CONFIRM, MB_YESNO | MB_ICONWARNING, &res);
  702. if (IDNO == res)
  703. {
  704. goto Cleanup;
  705. }
  706. }
  707. //
  708. // validation of rule's AreaCode and CountryCode
  709. //
  710. /* if ( !m_bstrRuleName || L"???" == m_bstrRuleName)
  711. {
  712. NodeMsgBox(IDS_INVALID_GROUP_NAME);
  713. goto Cleanup;
  714. }
  715. */
  716. //
  717. // Delete it
  718. //
  719. ATLASSERT(m_pParentNode);
  720. hRc = m_pParentNode->DeleteRule(m_dwAreaCode,
  721. m_dwCountryCode,
  722. this);
  723. if ( FAILED(hRc) )
  724. {
  725. goto Cleanup;
  726. }
  727. Cleanup:
  728. return hRc;
  729. }
  730. /*
  731. +
  732. +
  733. *
  734. * CFaxOutboundRoutingRuleNode::OnPropertyChange
  735. *
  736. *
  737. In our implementation, this method gets called when the
  738. MMCN_PROPERTY_CHANGE
  739. Notify message is sent for this node.
  740. *
  741. When the snap-in uses the MMCPropertyChangeNotify function to notify it's
  742. views about changes, MMC_PROPERTY_CHANGE is sent to the snap-in's
  743. IComponentData and IComponent implementations.
  744. *
  745. *
  746. Parameters
  747. arg
  748. [in] TRUE if the property change is for a scope pane item.
  749. lParam
  750. This is the param passed into MMCPropertyChangeNotify.
  751. * Return Values
  752. *
  753. -
  754. -
  755. */
  756. //////////////////////////////////////////////////////////////////////////////
  757. HRESULT CFaxOutboundRoutingRuleNode::OnPropertyChange(
  758. LPARAM arg
  759. , LPARAM param
  760. , IComponentData * pComponentData
  761. , IComponent * pComponent
  762. , DATA_OBJECT_TYPES type
  763. )
  764. {
  765. DEBUG_FUNCTION_NAME( _T("FaxOutboundRoutingRuleNode::OnPropertyChange"));
  766. HRESULT hRc = S_OK;
  767. CComPtr<IConsole> spConsole;
  768. CFaxRulePropertyChangeNotification * pNotification;
  769. //
  770. // Encode Property Change Notification data
  771. //
  772. pNotification = reinterpret_cast<CFaxRulePropertyChangeNotification *>(param);
  773. ATLASSERT(pNotification);
  774. ATLASSERT( RuleFaxPropNotification == pNotification->enumType );
  775. m_dwCountryCode = pNotification->dwCountryCode;
  776. m_bstrCountryName = pNotification->bstrCountryName;
  777. if ( !m_bstrCountryName )
  778. {
  779. hRc = E_OUTOFMEMORY;
  780. goto Error;
  781. }
  782. m_dwAreaCode = pNotification->dwAreaCode;
  783. m_fIsGroup = pNotification->fIsGroup;
  784. if (m_fIsGroup)
  785. {
  786. m_bstrGroupName = pNotification->bstrGroupName;
  787. }
  788. else
  789. {
  790. m_dwDeviceID = pNotification->dwDeviceID;
  791. DWORD ec = ERROR_SUCCESS;
  792. ec = InitDeviceNameFromID(m_dwDeviceID);
  793. if ( ERROR_SUCCESS != ec )
  794. {
  795. if (ERROR_BAD_UNIT != ec)
  796. {
  797. hRc = HRESULT_FROM_WIN32(ec);
  798. }
  799. else //The system cannot find the device specified
  800. {
  801. if ( FAX_RULE_STATUS_VALID != m_enumStatus)
  802. {
  803. m_enumStatus = FAX_RULE_STATUS_BAD_DEVICE;
  804. DebugPrintEx(
  805. DEBUG_MSG,
  806. TEXT("m_enumStatus was changed after ERROR_BAD_UNIT failure."));
  807. }
  808. //hRc stays S_OK !!! since we will intrduce this bad state
  809. }
  810. m_bstrDeviceName=L"???";
  811. //message box done by GetDeviceNameFromID
  812. goto Exit;
  813. }
  814. ATLASSERT(m_bstrDeviceName);
  815. }
  816. //
  817. // get IConsole
  818. //
  819. // if (pComponentData != NULL)
  820. // {
  821. // spConsole = ((CSnapin*)pComponentData)->m_spConsole;
  822. // }
  823. // else // We should have a non-null pComponent
  824. // {
  825. ATLASSERT(pComponent);
  826. spConsole = ((CSnapinComponent*)pComponent)->m_spConsole;
  827. // }
  828. ATLASSERT(spConsole != NULL);
  829. hRc = RefreshItemInView(spConsole);
  830. if ( FAILED(hRc) )
  831. {
  832. //msgbox done by called func.
  833. goto Exit;
  834. }
  835. ATLASSERT(S_OK == hRc);
  836. goto Exit;
  837. Error:
  838. ATLASSERT(S_OK != hRc);
  839. DebugPrintEx(
  840. DEBUG_ERR,
  841. _T("Failed to allocate string - out of memory"));
  842. NodeMsgBox(IDS_MEMORY);
  843. Exit:
  844. //
  845. // any way you get here, memory must be freed
  846. //
  847. delete pNotification;
  848. return hRc;
  849. }
  850. /*
  851. - CFaxOutboundRoutingRuleNode::RefreshItemInView
  852. -
  853. * Purpose:
  854. * Call IResultData::UpdateItem for single item
  855. *
  856. * Arguments:
  857. * [in] pConsole - the console interface
  858. *
  859. * Return: OLE error code
  860. */
  861. HRESULT CFaxOutboundRoutingRuleNode::RefreshItemInView(IConsole *pConsole)
  862. {
  863. DEBUG_FUNCTION_NAME( _T("FaxOutboundRoutingRuleNode::RefreshItemInView"));
  864. HRESULT hRc = S_OK;
  865. //
  866. // Need IResultData
  867. //
  868. CComQIPtr<IResultData, &IID_IResultData> pResultData(pConsole);
  869. ATLASSERT(pResultData != NULL);
  870. //
  871. // Update the result item
  872. //
  873. hRc = pResultData->UpdateItem(m_resultDataItem.itemID);
  874. if ( FAILED(hRc) )
  875. {
  876. DebugPrintEx(
  877. DEBUG_ERR,
  878. TEXT("Failure on pResultData->UpdateItem, (hRc: %08X)"),
  879. hRc);
  880. NodeMsgBox(IDS_FAIL2REFRESH_THEVIEW);
  881. goto Exit;
  882. }
  883. Exit:
  884. return hRc;
  885. }
  886. /*
  887. +
  888. + CFaxOutboundRoutingRuleNode::OnShowContextHelp
  889. *
  890. * Purpose:
  891. * Overrides CSnapinNode::OnShowContextHelp.
  892. *
  893. * Arguments:
  894. *
  895. * Return:
  896. - OLE error code
  897. -
  898. */
  899. HRESULT CFaxOutboundRoutingRuleNode::OnShowContextHelp(
  900. IDisplayHelp* pDisplayHelp, LPOLESTR helpFile)
  901. {
  902. return DisplayContextHelp(pDisplayHelp, helpFile, HLP_GROUPS);
  903. }