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.

641 lines
15 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : OutboundRules.cpp //
  3. // //
  4. // DESCRIPTION : Fax Outbound Rules MMC node. //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Sep 29 1999 yossg Create //
  10. // Dec 24 1999 yossg Reogenize as node with result children list //
  11. // Dec 30 1999 yossg create ADD/REMOVE rule //
  12. // Oct 17 2000 yossg //
  13. // //
  14. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "StdAfx.h"
  17. #include "snapin.h"
  18. #include "FaxServer.h"
  19. #include "FaxServerNode.h"
  20. #include "OutboundRules.h"
  21. #include "OutboundRouting.h"
  22. #include "dlgNewRule.h"
  23. #include "oaidl.h"
  24. #include "Icons.h"
  25. //////////////////////////////////////////////////////////////
  26. // {D17BA53F-0992-4404-8760-7D2933D9FC46}
  27. static const GUID CFaxOutboundRoutingRulesNodeGUID_NODETYPE =
  28. { 0xd17ba53f, 0x992, 0x4404, { 0x87, 0x60, 0x7d, 0x29, 0x33, 0xd9, 0xfc, 0x46 } };
  29. const GUID* CFaxOutboundRoutingRulesNode::m_NODETYPE = &CFaxOutboundRoutingRulesNodeGUID_NODETYPE;
  30. const OLECHAR* CFaxOutboundRoutingRulesNode::m_SZNODETYPE = OLESTR("D17BA53F-0992-4404-8760-7D2933D9FC46");
  31. const CLSID* CFaxOutboundRoutingRulesNode::m_SNAPIN_CLASSID = &CLSID_Snapin;
  32. CColumnsInfo CFaxOutboundRoutingRulesNode::m_ColsInfo;
  33. /*
  34. - CFaxOutboundRoutingRulesNode::InsertColumns
  35. -
  36. * Purpose:
  37. * Adds columns to the default result pane.
  38. *
  39. * Arguments:
  40. * [in] pHeaderCtrl - IHeaderCtrl in the console-provided default result view pane
  41. *
  42. * Return:
  43. * OLE error code
  44. */
  45. HRESULT
  46. CFaxOutboundRoutingRulesNode::InsertColumns(IHeaderCtrl *pHeaderCtrl)
  47. {
  48. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRulesNode::InsertColumns"));
  49. HRESULT hRc = S_OK;
  50. static ColumnsInfoInitData ColumnsInitData[] =
  51. {
  52. {IDS_OUTRRULES_COL1, AUTO_WIDTH},
  53. {IDS_OUTRRULES_COL2, AUTO_WIDTH},
  54. {IDS_OUTRRULES_COL3, FXS_WIDE_COLUMN_WIDTH},
  55. {IDS_OUTRRULES_COL4, AUTO_WIDTH},
  56. {LAST_IDS, 0}
  57. };
  58. hRc = m_ColsInfo.InsertColumnsIntoMMC(pHeaderCtrl,
  59. _Module.GetResourceInstance(),
  60. ColumnsInitData);
  61. CHECK_RETURN_VALUE_AND_PRINT_DEBUG (_T("m_ColsInfo.InsertColumnsIntoMMC"))
  62. Cleanup:
  63. return(hRc);
  64. }
  65. /*
  66. - CFaxOutboundRoutingRulesNode::initRPC
  67. -
  68. * Purpose:
  69. * Initiates the configuration structure from RPC get Call.
  70. *
  71. * Arguments:
  72. *
  73. * Return:
  74. * OLE error code
  75. */
  76. HRESULT CFaxOutboundRoutingRulesNode::InitRPC(PFAX_OUTBOUND_ROUTING_RULE *pFaxRulesConfig)
  77. {
  78. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRulesNode::InitRPC"));
  79. HRESULT hRc = S_OK;
  80. DWORD ec = ERROR_SUCCESS;
  81. CFaxServer * pFaxServer = NULL;
  82. ATLASSERT(NULL == (*pFaxRulesConfig) );
  83. //
  84. // get Fax Handle
  85. //
  86. pFaxServer = ((CFaxServerNode *)GetRootNode())->GetFaxServer();
  87. ATLASSERT(pFaxServer);
  88. if (!pFaxServer->GetFaxServerHandle())
  89. {
  90. ec= GetLastError();
  91. DebugPrintEx(
  92. DEBUG_ERR,
  93. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  94. ec);
  95. goto Error;
  96. }
  97. //
  98. // Retrieve the fax Outbound Rules configuration
  99. //
  100. if (!FaxEnumOutboundRules(pFaxServer->GetFaxServerHandle(),
  101. pFaxRulesConfig,
  102. &m_dwNumOfOutboundRules))
  103. {
  104. ec = GetLastError();
  105. DebugPrintEx(
  106. DEBUG_ERR,
  107. _T("Fail to get Outbound Rules configuration. (ec: %ld)"),
  108. ec);
  109. if (IsNetworkError(ec))
  110. {
  111. DebugPrintEx(
  112. DEBUG_ERR,
  113. _T("Network Error was found. (ec: %ld)"),
  114. ec);
  115. pFaxServer->Disconnect();
  116. }
  117. goto Error;
  118. }
  119. //For max verification
  120. ATLASSERT(*pFaxRulesConfig);
  121. ATLASSERT(ERROR_SUCCESS == ec);
  122. DebugPrintEx( DEBUG_MSG,
  123. _T("Succeed to get outbound rules configuration."));
  124. goto Exit;
  125. Error:
  126. ATLASSERT(ERROR_SUCCESS != ec);
  127. hRc = HRESULT_FROM_WIN32(ec);
  128. ATLASSERT(NULL != m_pParentNode);
  129. m_pParentNode->NodeMsgBox(GetFaxServerErrorMsg(ec));
  130. Exit:
  131. return (hRc);
  132. }
  133. /*
  134. - CFaxOutboundRoutingRulesNode::PopulateResultChildrenList
  135. -
  136. * Purpose:
  137. * Create the FaxInboundRoutingMethods children nodes
  138. *
  139. * Arguments:
  140. *
  141. * Return:
  142. * OLE error code
  143. */
  144. HRESULT CFaxOutboundRoutingRulesNode::PopulateResultChildrenList()
  145. {
  146. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRulesNode::PopulateResultChildrenList"));
  147. HRESULT hRc = S_OK;
  148. CFaxOutboundRoutingRuleNode * pRule = NULL;
  149. PFAX_OUTBOUND_ROUTING_RULE pFaxOutboundRulesConfig = NULL ;
  150. DWORD i;
  151. //
  152. // Get the Config. structure
  153. //
  154. hRc = InitRPC(&pFaxOutboundRulesConfig);
  155. if (FAILED(hRc))
  156. {
  157. //DebugPrint and MsgBox by called func.
  158. //to be safe actually done by InitRPC on error.
  159. pFaxOutboundRulesConfig = NULL;
  160. goto Error;
  161. }
  162. ATLASSERT(NULL != pFaxOutboundRulesConfig);
  163. ATLASSERT(1 <= m_dwNumOfOutboundRules);
  164. for ( i=0; i< m_dwNumOfOutboundRules; i++ )
  165. {
  166. pRule = NULL;
  167. pRule = new CFaxOutboundRoutingRuleNode(this, m_pComponentData);
  168. if (!pRule)
  169. {
  170. hRc = E_OUTOFMEMORY;
  171. NodeMsgBox(IDS_MEMORY);
  172. DebugPrintEx(
  173. DEBUG_ERR,
  174. TEXT("Out of memory. (hRc: %08X)"),
  175. hRc);
  176. goto Error;
  177. }
  178. else
  179. {
  180. pRule->InitParentNode(this);
  181. hRc = pRule->Init(&pFaxOutboundRulesConfig[i]);
  182. if (FAILED(hRc))
  183. {
  184. DebugPrintEx(
  185. DEBUG_ERR,
  186. TEXT("Fail to init rule node. (hRc: %08X)"),
  187. hRc);
  188. NodeMsgBox(IDS_FAIL2INIT_OUTBOUNDRULE);
  189. goto Error;
  190. }
  191. hRc = this->AddChildToList(pRule);
  192. if (FAILED(hRc))
  193. {
  194. DebugPrintEx(
  195. DEBUG_ERR,
  196. TEXT("Fail to add rule to the view. (hRc: %08X)"),
  197. hRc);
  198. NodeMsgBox(IDS_FAIL2ADD_OUTBOUNDRULE);
  199. goto Error;
  200. }
  201. else
  202. {
  203. pRule = NULL;
  204. }
  205. }
  206. }
  207. ATLASSERT(S_OK == hRc);
  208. goto Exit;
  209. Error:
  210. ATLASSERT(S_OK != hRc);
  211. if ( NULL != pRule )
  212. {
  213. delete pRule;
  214. pRule = NULL;
  215. }
  216. //
  217. // Get rid of what we had.
  218. //
  219. {
  220. // Delete each node in the list of children
  221. int iSize = m_ResultChildrenList.GetSize();
  222. for (int j = 0; j < iSize; j++)
  223. {
  224. pRule = (CFaxOutboundRoutingRuleNode *)
  225. m_ResultChildrenList[j];
  226. ATLASSERT(pRule);
  227. delete pRule;
  228. pRule = NULL;
  229. }
  230. // Empty the list
  231. m_ResultChildrenList.RemoveAll();
  232. // We no longer have a populated list.
  233. m_bResultChildrenListPopulated = FALSE;
  234. }
  235. Exit:
  236. if (NULL != pFaxOutboundRulesConfig)
  237. {
  238. FaxFreeBuffer(pFaxOutboundRulesConfig);
  239. }
  240. return hRc;
  241. }
  242. /*
  243. - CFaxOutboundRoutingRulesNode::SetVerbs
  244. -
  245. * Purpose:
  246. * What verbs to enable/disable when this object is selected
  247. *
  248. * Arguments:
  249. * [in] pConsoleVerb - MMC ConsoleVerb interface
  250. *
  251. * Return:
  252. * OLE Error code
  253. */
  254. HRESULT CFaxOutboundRoutingRulesNode::SetVerbs(IConsoleVerb *pConsoleVerb)
  255. {
  256. HRESULT hRc = S_OK;
  257. //
  258. // Refresh
  259. //
  260. hRc = pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  261. //
  262. // We want the default verb to be expand node children
  263. //
  264. hRc = pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  265. return hRc;
  266. }
  267. /*
  268. - CFaxOutboundRoutingRulesNode::OnRefresh
  269. -
  270. * Purpose:
  271. * Called when refreshing the object.
  272. *
  273. * Arguments:
  274. *
  275. * Return:
  276. * OLE error code
  277. */
  278. /* virtual */HRESULT
  279. CFaxOutboundRoutingRulesNode::OnRefresh(LPARAM arg,
  280. LPARAM param,
  281. IComponentData *pComponentData,
  282. IComponent * pComponent,
  283. DATA_OBJECT_TYPES type)
  284. {
  285. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRulesNode::OnRefresh"));
  286. HRESULT hRc = S_OK;
  287. //
  288. // Call the base class
  289. //
  290. hRc = CBaseFaxOutboundRulesNode::OnRefresh(arg,
  291. param,
  292. pComponentData,
  293. pComponent,
  294. type);
  295. if ( FAILED(hRc) )
  296. {
  297. DebugPrintEx(
  298. DEBUG_ERR,
  299. _T("Fail to call base class's OnRefresh. (hRc: %08X)"),
  300. hRc);
  301. goto Cleanup;
  302. }
  303. Cleanup:
  304. return hRc;
  305. }
  306. /*
  307. - CFaxOutboundRoutingRulesNode::OnNewRule
  308. -
  309. * Purpose:
  310. *
  311. *
  312. * Arguments:
  313. * [out] bHandled - Do we handle it?
  314. * [in] pRoot - The root node
  315. *
  316. * Return:
  317. * OLE Error code
  318. */
  319. HRESULT
  320. CFaxOutboundRoutingRulesNode::OnNewRule(bool &bHandled, CSnapInObjectRootBase *pRoot)
  321. {
  322. DEBUG_FUNCTION_NAME( _T("CFaxOutboundRoutingRulesNode::OnNewRule"));
  323. HRESULT hRc = S_OK;
  324. INT_PTR rc = IDOK;
  325. CDlgNewFaxOutboundRule DlgNewRule( ((CFaxServerNode *)GetRootNode())->GetFaxServer() );
  326. //
  327. // Dialog to add rule
  328. //
  329. hRc = DlgNewRule.InitRuleDlg();
  330. if (FAILED(hRc))
  331. {
  332. NodeMsgBox(IDS_FAIL2OPEN_DLG);
  333. return hRc;
  334. }
  335. rc = DlgNewRule.DoModal();
  336. if (rc != IDOK)
  337. {
  338. goto Cleanup;
  339. }
  340. //
  341. // Repopulate (with RPC) and Refresh the view
  342. //
  343. DoRefresh(pRoot);
  344. Cleanup:
  345. return S_OK;
  346. }
  347. /*
  348. - CFaxOutboundRoutingRulesNode::DoRefresh
  349. -
  350. * Purpose:
  351. * Refresh the view
  352. *
  353. * Arguments:
  354. * [in] pRoot - The root node
  355. *
  356. * Return:
  357. * OLE Error code
  358. */
  359. HRESULT
  360. CFaxOutboundRoutingRulesNode::DoRefresh(CSnapInObjectRootBase *pRoot)
  361. {
  362. CComPtr<IConsole> spConsole;
  363. //
  364. // Repopulate childs
  365. //
  366. RepopulateResultChildrenList();
  367. if (pRoot)
  368. {
  369. //
  370. // Get the console pointer
  371. //
  372. ATLASSERT(pRoot->m_nType == 1 || pRoot->m_nType == 2);
  373. if (pRoot->m_nType == 1)
  374. {
  375. //
  376. // m_ntype == 1 means the IComponentData implementation
  377. //
  378. CSnapin *pCComponentData = static_cast<CSnapin *>(pRoot);
  379. spConsole = pCComponentData->m_spConsole;
  380. }
  381. else
  382. {
  383. //
  384. // m_ntype == 2 means the IComponent implementation
  385. //
  386. CSnapinComponent *pCComponent = static_cast<CSnapinComponent *>(pRoot);
  387. spConsole = pCComponent->m_spConsole;
  388. }
  389. }
  390. else
  391. {
  392. ATLASSERT(m_pComponentData);
  393. spConsole = m_pComponentData->m_spConsole;
  394. }
  395. ATLASSERT(spConsole);
  396. spConsole->UpdateAllViews(NULL, NULL, NULL);
  397. return S_OK;
  398. }
  399. /*
  400. - CFaxOutboundRoutingRulesNode::InitDisplayName
  401. -
  402. * Purpose:
  403. * To load the node's Displaed-Name string.
  404. *
  405. * Arguments:
  406. *
  407. * Return:
  408. * OLE error code
  409. */
  410. HRESULT CFaxOutboundRoutingRulesNode::InitDisplayName()
  411. {
  412. DEBUG_FUNCTION_NAME(_T("CFaxOutboundRoutingRulesNode::InitDisplayName"));
  413. HRESULT hRc = S_OK;
  414. if (!m_bstrDisplayName.LoadString(_Module.GetResourceInstance(),
  415. IDS_DISPLAY_STR_OUTBOUNDRULES))
  416. {
  417. hRc = E_OUTOFMEMORY;
  418. goto Error;
  419. }
  420. ATLASSERT( S_OK == hRc);
  421. goto Exit;
  422. Error:
  423. ATLASSERT( S_OK != hRc);
  424. m_bstrDisplayName = L"";
  425. DebugPrintEx(
  426. DEBUG_ERR,
  427. TEXT("Fail to Load server name string."));
  428. NodeMsgBox(IDS_MEMORY);
  429. Exit:
  430. return hRc;
  431. }
  432. /*
  433. - CFaxOutboundRoutingRulesNode::DeleteRule
  434. -
  435. * Purpose:
  436. * Delete rule
  437. *
  438. * Arguments:
  439. * [in] dwAreaCode - The Rule Area Code
  440. * [in] dwCountryCode - The Rule Country Code
  441. * [in] pChildNode - The node to be deleted
  442. *
  443. * Return:
  444. * OLE Error code
  445. */
  446. HRESULT
  447. CFaxOutboundRoutingRulesNode::DeleteRule(DWORD dwAreaCode, DWORD dwCountryCode, CFaxOutboundRoutingRuleNode *pChildNode)
  448. {
  449. DEBUG_FUNCTION_NAME(_T("CFaxOutboundRoutingRulesNode::DeleteRule"));
  450. HRESULT hRc = S_OK;
  451. DWORD ec = ERROR_SUCCESS;
  452. CFaxServer * pFaxServer = NULL;
  453. //
  454. // get RPC Handle
  455. //
  456. pFaxServer = ((CFaxServerNode *)GetRootNode())->GetFaxServer();
  457. ATLASSERT(pFaxServer);
  458. if (!pFaxServer->GetFaxServerHandle())
  459. {
  460. ec= GetLastError();
  461. DebugPrintEx(
  462. DEBUG_ERR,
  463. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  464. ec);
  465. goto Error;
  466. }
  467. //
  468. // Remove with RPC from the server
  469. //
  470. if (!FaxRemoveOutboundRule (
  471. pFaxServer->GetFaxServerHandle(),
  472. dwAreaCode,
  473. dwCountryCode))
  474. {
  475. ec = GetLastError();
  476. DebugPrintEx(
  477. DEBUG_ERR,
  478. _T("Fail to remove rule. (ec: %ld)"),
  479. ec);
  480. if (IsNetworkError(ec))
  481. {
  482. DebugPrintEx(
  483. DEBUG_ERR,
  484. _T("Network Error was found. (ec: %ld)"),
  485. ec);
  486. pFaxServer->Disconnect();
  487. }
  488. goto Error;
  489. }
  490. //
  491. // Remove from MMC result pane
  492. //
  493. ATLASSERT(pChildNode);
  494. hRc = RemoveChild(pChildNode);
  495. if (FAILED(hRc))
  496. {
  497. DebugPrintEx(
  498. DEBUG_ERR,
  499. TEXT("Fail to remove rule. (hRc: %08X)"),
  500. hRc);
  501. NodeMsgBox(IDS_FAIL_TO_REMOVE_RULE);
  502. return hRc;
  503. }
  504. //
  505. // Call the rule destructor
  506. //
  507. delete pChildNode;
  508. ATLASSERT(ERROR_SUCCESS == ec);
  509. DebugPrintEx( DEBUG_MSG,
  510. _T("The rule was removed successfully."));
  511. goto Exit;
  512. Error:
  513. ATLASSERT(ERROR_SUCCESS != ec);
  514. hRc = HRESULT_FROM_WIN32(ec);
  515. NodeMsgBox(GetFaxServerErrorMsg(ec));
  516. Exit:
  517. return hRc;
  518. }
  519. /*
  520. +
  521. + CFaxOutboundRoutingRulesNode::OnShowContextHelp
  522. *
  523. * Purpose:
  524. * Overrides CSnapinNode::OnShowContextHelp.
  525. *
  526. * Arguments:
  527. *
  528. * Return:
  529. - OLE error code
  530. -
  531. */
  532. HRESULT CFaxOutboundRoutingRulesNode::OnShowContextHelp(
  533. IDisplayHelp* pDisplayHelp, LPOLESTR helpFile)
  534. {
  535. return DisplayContextHelp(pDisplayHelp, helpFile, HLP_GROUPS);
  536. }
  537. ///////////////////////////////////////////////////////////////////