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.

530 lines
13 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : InboundRoutingMethods.cpp //
  3. // //
  4. // DESCRIPTION : Fax InboundRoutingMethods MMC node. //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Dec 1 1999 yossg Create //
  10. // Dec 14 1999 yossg add basic functionality //
  11. // Oct 17 2000 yossg //
  12. // //
  13. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  14. /////////////////////////////////////////////////////////////////////////////
  15. #include "StdAfx.h"
  16. #include "snapin.h"
  17. #include "FaxServer.h"
  18. #include "FaxServerNode.h"
  19. #include "InboundRoutingMethods.h"
  20. #include "Device.h"
  21. #include "Devices.h"
  22. #include "oaidl.h"
  23. #include "Icons.h"
  24. //////////////////////////////////////////////////////////////
  25. // {AA94A694-844B-4d3a-A82C-2FCBDE0FF430}
  26. static const GUID CFaxInboundRoutingMethodsNodeGUID_NODETYPE =
  27. { 0xaa94a694, 0x844b, 0x4d3a, { 0xa8, 0x2c, 0x2f, 0xcb, 0xde, 0xf, 0xf4, 0x30 } };
  28. const GUID* CFaxInboundRoutingMethodsNode::m_NODETYPE = &CFaxInboundRoutingMethodsNodeGUID_NODETYPE;
  29. const OLECHAR* CFaxInboundRoutingMethodsNode::m_SZNODETYPE = OLESTR("AA94A694-844B-4d3a-A82C-2FCBDE0FF430");
  30. const CLSID* CFaxInboundRoutingMethodsNode::m_SNAPIN_CLASSID = &CLSID_Snapin;
  31. CColumnsInfo CFaxInboundRoutingMethodsNode::m_ColsInfo;
  32. /*
  33. - CFaxInboundRoutingMethodsNode::InsertColumns
  34. -
  35. * Purpose:
  36. * Adds columns to the default result pane.
  37. *
  38. * Arguments:
  39. * [in] pHeaderCtrl - IHeaderCtrl in the console-provided default result view pane
  40. *
  41. * Return:
  42. * OLE error code
  43. */
  44. HRESULT
  45. CFaxInboundRoutingMethodsNode::InsertColumns(IHeaderCtrl *pHeaderCtrl)
  46. {
  47. DEBUG_FUNCTION_NAME( _T("CFaxInboundRoutingMethodsNode::InsertColumns"));
  48. HRESULT hRc = S_OK;
  49. static ColumnsInfoInitData ColumnsInitData[] =
  50. {
  51. {IDS_INBOUND_METHODS_COL1, FXS_WIDE_COLUMN_WIDTH},
  52. {IDS_INBOUND_METHODS_COL2, AUTO_WIDTH},
  53. {IDS_INBOUND_METHODS_COL3, FXS_LARGE_COLUMN_WIDTH},
  54. {LAST_IDS, 0}
  55. };
  56. hRc = m_ColsInfo.InsertColumnsIntoMMC(pHeaderCtrl,
  57. _Module.GetResourceInstance(),
  58. ColumnsInitData);
  59. CHECK_RETURN_VALUE_AND_PRINT_DEBUG (_T("m_ColsInfo.InsertColumnsIntoMMC"))
  60. Cleanup:
  61. return(hRc);
  62. }
  63. /*
  64. - CFaxInboundRoutingMethodsNode::initRPC
  65. -
  66. * Purpose:
  67. * Initiates the configuration structure from RPC get Call.
  68. *
  69. * Arguments:
  70. *
  71. * Return:
  72. * OLE error code
  73. */
  74. HRESULT CFaxInboundRoutingMethodsNode::InitRPC( )
  75. {
  76. DEBUG_FUNCTION_NAME( _T("CFaxInboundRoutingMethodsNode::InitRPC"));
  77. HRESULT hRc = S_OK;
  78. DWORD ec = ERROR_SUCCESS;
  79. HANDLE hFaxPortHandle = NULL;
  80. CFaxServer * pFaxServer = NULL;
  81. //
  82. // get Fax Handle
  83. //
  84. pFaxServer = ((CFaxServerNode *)GetRootNode())->GetFaxServer();
  85. ATLASSERT(pFaxServer);
  86. if (!pFaxServer->GetFaxServerHandle())
  87. {
  88. ec= GetLastError();
  89. DebugPrintEx(
  90. DEBUG_ERR,
  91. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  92. ec);
  93. goto Error;
  94. }
  95. ATLASSERT(NULL != m_pParentNode);
  96. //
  97. // get Fax Device Handle
  98. //
  99. //
  100. // only a PORT_OPEN_QUERY is needed to show the methods
  101. // the handle with PORT_OPEN_MODIFY priviledge will be
  102. // given for limited short period for opertion required it.
  103. //
  104. if (!FaxOpenPort( pFaxServer->GetFaxServerHandle(),
  105. m_pParentNode->GetDeviceID(),
  106. PORT_OPEN_QUERY,
  107. &hFaxPortHandle ))
  108. {
  109. ec = GetLastError();
  110. if (ERROR_INVALID_HANDLE == ec)
  111. {
  112. //Special case of ERROR_INVALID_HANDLE
  113. DebugPrintEx(DEBUG_ERR,
  114. _T("FaxOpenPort() failed with ERROR_INVALID_HANDLE. (ec:%ld)"),
  115. ec);
  116. NodeMsgBox(IDS_OPENPORT_INVALID_HANDLE);
  117. goto Exit;
  118. }
  119. DebugPrintEx(
  120. DEBUG_ERR,
  121. TEXT("FaxOpenPort() failed. (ec:%ld)"),
  122. ec);
  123. goto Error;
  124. }
  125. ATLASSERT(NULL != hFaxPortHandle);
  126. //
  127. // Retrieve the fax Inbound Methods configuration
  128. //
  129. if (!FaxEnumRoutingMethods(hFaxPortHandle,
  130. &m_pFaxInboundMethodsConfig,
  131. &m_dwNumOfInboundMethods))
  132. {
  133. ec = GetLastError();
  134. DebugPrintEx(
  135. DEBUG_ERR,
  136. _T("Fail to get Inbound Methods configuration. (ec: %ld)"),
  137. ec);
  138. if (IsNetworkError(ec))
  139. {
  140. DebugPrintEx(
  141. DEBUG_ERR,
  142. _T("Network Error was found. (ec: %ld)"),
  143. ec);
  144. pFaxServer->Disconnect();
  145. }
  146. goto Error;
  147. }
  148. //For max verification
  149. ATLASSERT(m_pFaxInboundMethodsConfig);
  150. ATLASSERT(ERROR_SUCCESS == ec);
  151. DebugPrintEx( DEBUG_MSG,
  152. _T("Succeed to get Inbound Methods configuration."));
  153. goto Exit;
  154. Error:
  155. ATLASSERT(ERROR_SUCCESS != ec);
  156. hRc = HRESULT_FROM_WIN32(ec);
  157. NodeMsgBox(GetFaxServerErrorMsg(ec));
  158. Exit:
  159. //
  160. // Close Fax Port handle
  161. //
  162. if (NULL != hFaxPortHandle)
  163. {
  164. if (!FaxClose( hFaxPortHandle ))
  165. {
  166. DebugPrintEx(
  167. DEBUG_ERR,
  168. TEXT("FaxClose() on port handle failed (ec: %ld)"),
  169. GetLastError());
  170. }
  171. }
  172. return (hRc);
  173. }
  174. /*
  175. - CFaxInboundRoutingMethodsNode::PopulateResultChildrenList
  176. -
  177. * Purpose:
  178. * Create the FaxInboundRoutingMethods children nodes
  179. *
  180. * Arguments:
  181. *
  182. * Return:
  183. * OLE error code
  184. */
  185. HRESULT CFaxInboundRoutingMethodsNode::PopulateResultChildrenList()
  186. {
  187. DEBUG_FUNCTION_NAME( _T("CFaxInboundRoutingMethodsNode::PopulateResultChildrenList"));
  188. HRESULT hRc = S_OK;
  189. CFaxInboundRoutingMethodNode * pMethod;
  190. DWORD i;
  191. //
  192. // Get the Config. structure
  193. //
  194. hRc = InitRPC();
  195. if (FAILED(hRc))
  196. {
  197. //DebugPrint and MsgBox by called func.
  198. //to be safe actually done by InitRPC on error.
  199. m_pFaxInboundMethodsConfig = NULL;
  200. goto Exit; //!!!
  201. }
  202. ATLASSERT(NULL != m_pFaxInboundMethodsConfig);
  203. //
  204. //
  205. //
  206. for ( i = 0; i < m_dwNumOfInboundMethods; i++ )
  207. {
  208. pMethod = NULL;
  209. pMethod = new CFaxInboundRoutingMethodNode(this,
  210. m_pComponentData,
  211. &m_pFaxInboundMethodsConfig[i]);
  212. if (!pMethod)
  213. {
  214. hRc = E_OUTOFMEMORY;
  215. NodeMsgBox(IDS_MEMORY);
  216. DebugPrintEx(
  217. DEBUG_ERR,
  218. TEXT("Out of memory. (hRc: %08X)"),
  219. hRc);
  220. goto Error;
  221. }
  222. else
  223. {
  224. pMethod->InitParentNode(this);
  225. pMethod->Init(&m_pFaxInboundMethodsConfig[i]);
  226. hRc = this->AddChildToList(pMethod);
  227. if (FAILED(hRc))
  228. {
  229. DebugPrintEx(
  230. DEBUG_ERR,
  231. TEXT("Fail to add Inbound Routing Method. (hRc: %08X)"),
  232. hRc);
  233. NodeMsgBox(IDS_FAILTOADD_INBOUNDROUTINGMETHODS);
  234. goto Error;
  235. }
  236. else
  237. {
  238. pMethod = NULL;
  239. }
  240. }
  241. }
  242. ATLASSERT(S_OK == hRc);
  243. goto Exit;
  244. Error:
  245. ATLASSERT(S_OK != hRc);
  246. if ( NULL != pMethod )
  247. {
  248. delete pMethod;
  249. pMethod = NULL;
  250. }
  251. //
  252. // Get rid of what we had.
  253. //
  254. {
  255. // Delete each node in the list of children
  256. int iSize = m_ResultChildrenList.GetSize();
  257. for (int j = 0; j < iSize; j++)
  258. {
  259. pMethod = (CFaxInboundRoutingMethodNode *)
  260. m_ResultChildrenList[j];
  261. delete pMethod;
  262. }
  263. // Empty the list
  264. m_ResultChildrenList.RemoveAll();
  265. // We no longer have a populated list.
  266. m_bResultChildrenListPopulated = FALSE;
  267. }
  268. Exit:
  269. return hRc;
  270. }
  271. /*
  272. - CFaxInboundRoutingMethodsNode::SetVerbs
  273. -
  274. * Purpose:
  275. * What verbs to enable/disable when this object is selected
  276. *
  277. * Arguments:
  278. * [in] pConsoleVerb - MMC ConsoleVerb interface
  279. *
  280. * Return:
  281. * OLE Error code
  282. */
  283. HRESULT CFaxInboundRoutingMethodsNode::SetVerbs(IConsoleVerb *pConsoleVerb)
  284. {
  285. HRESULT hRc = S_OK;
  286. //
  287. // Refresh
  288. //
  289. hRc = pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  290. //
  291. // We want the default verb to be expand node children
  292. //
  293. hRc = pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  294. return hRc;
  295. }
  296. /*
  297. - CFaxInboundRoutingMethodsNode::OnRefresh
  298. -
  299. * Purpose:
  300. * Called when refreshing the object.
  301. *
  302. * Arguments:
  303. *
  304. * Return:
  305. * OLE error code
  306. */
  307. /* virtual */HRESULT
  308. CFaxInboundRoutingMethodsNode::OnRefresh(LPARAM arg,
  309. LPARAM param,
  310. IComponentData *pComponentData,
  311. IComponent * pComponent,
  312. DATA_OBJECT_TYPES type)
  313. {
  314. DEBUG_FUNCTION_NAME( _T("CFaxInboundRoutingMethodsNode::OnRefresh"));
  315. HRESULT hRc = S_OK;
  316. //
  317. // Call the base class
  318. //
  319. hRc = CBaseFaxInboundRoutingMethodsNode::OnRefresh(arg,
  320. param,
  321. pComponentData,
  322. pComponent,
  323. type);
  324. if ( FAILED(hRc) )
  325. {
  326. DebugPrintEx(DEBUG_ERR, _T("Fail to call base class's OnRefresh. (hRc: %08X)"), hRc);
  327. CFaxDevicesNode * pFaxDevices = NULL;
  328. ATLASSERT(m_pParentNode);
  329. pFaxDevices = m_pParentNode->GetParent();
  330. ATLASSERT(pFaxDevices);
  331. hRc = pFaxDevices->DoRefresh();
  332. if ( FAILED(hRc) )
  333. {
  334. DebugPrintEx(DEBUG_ERR, _T("Fail to call parent node - Groups DoRefresh. (hRc: %08X)"), hRc);
  335. }
  336. goto Exit;
  337. }
  338. Exit:
  339. return hRc;
  340. }
  341. /*
  342. - CFaxInboundRoutingMethodsNode::DoRefresh
  343. -
  344. * Purpose:
  345. * Refresh the view
  346. *
  347. * Arguments:
  348. * [in] pRoot - The root node
  349. *
  350. * Return:
  351. * OLE Error code
  352. */
  353. HRESULT
  354. CFaxInboundRoutingMethodsNode::DoRefresh(CSnapInObjectRootBase *pRoot)
  355. {
  356. CComPtr<IConsole> spConsole;
  357. //
  358. // Repopulate childs
  359. //
  360. RepopulateResultChildrenList();
  361. if (pRoot)
  362. {
  363. //
  364. // Get the console pointer
  365. //
  366. ATLASSERT(pRoot->m_nType == 1 || pRoot->m_nType == 2);
  367. if (pRoot->m_nType == 1)
  368. {
  369. //
  370. // m_ntype == 1 means the IComponentData implementation
  371. //
  372. CSnapin *pCComponentData = static_cast<CSnapin *>(pRoot);
  373. spConsole = pCComponentData->m_spConsole;
  374. }
  375. else
  376. {
  377. //
  378. // m_ntype == 2 means the IComponent implementation
  379. //
  380. CSnapinComponent *pCComponent = static_cast<CSnapinComponent *>(pRoot);
  381. spConsole = pCComponent->m_spConsole;
  382. }
  383. }
  384. else
  385. {
  386. ATLASSERT(m_pComponentData);
  387. spConsole = m_pComponentData->m_spConsole;
  388. }
  389. ATLASSERT(spConsole);
  390. spConsole->UpdateAllViews(NULL, NULL, NULL);
  391. return S_OK;
  392. }
  393. /*
  394. - CFaxInboundRoutingMethodsNode::InitDisplayName
  395. -
  396. * Purpose:
  397. * To load the node's Displaed-Name string.
  398. *
  399. * Arguments:
  400. *
  401. * Return:
  402. * OLE error code
  403. */
  404. HRESULT CFaxInboundRoutingMethodsNode::InitDisplayName()
  405. {
  406. DEBUG_FUNCTION_NAME(_T("CFaxInboundRoutingMethodsNode::InitDisplayName"));
  407. HRESULT hRc = S_OK;
  408. if (!m_bstrDisplayName.LoadString(_Module.GetResourceInstance(),
  409. IDS_DISPLAY_STR_INROUTEMETHODSNODE))
  410. {
  411. hRc = E_OUTOFMEMORY;
  412. goto Error;
  413. }
  414. ATLASSERT( S_OK == hRc);
  415. goto Exit;
  416. Error:
  417. ATLASSERT( S_OK != hRc);
  418. m_bstrDisplayName = L"";
  419. DebugPrintEx(
  420. DEBUG_ERR,
  421. TEXT("Fail to Load server name string."));
  422. NodeMsgBox(IDS_MEMORY);
  423. Exit:
  424. return hRc;
  425. }
  426. /*
  427. +
  428. + CFaxInboundRoutingMethodsNode::OnShowContextHelp
  429. *
  430. * Purpose:
  431. * Overrides CSnapinNode::OnShowContextHelp.
  432. *
  433. * Arguments:
  434. *
  435. * Return:
  436. - OLE error code
  437. -
  438. */
  439. HRESULT CFaxInboundRoutingMethodsNode::OnShowContextHelp(
  440. IDisplayHelp* pDisplayHelp, LPOLESTR helpFile)
  441. {
  442. return DisplayContextHelp(pDisplayHelp, helpFile, HLP_INBOUND_ROUTING);
  443. }
  444. ///////////////////////////////////////////////////////////////////