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.

1688 lines
48 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. sapview.cpp
  7. IPX SAP node implementation.
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "util.h"
  12. #include "sapview.h"
  13. #include "reg.h"
  14. #include "rtrutil.h" // smart MPR handle pointers
  15. #include "sapstrm.h" // IPAdminConfigStream
  16. #include "strmap.h" // XXXtoCString functions
  17. #include "service.h" // TFS service APIs
  18. #include "format.h" // FormatNumber function
  19. #include "coldlg.h" // columndlg
  20. #include "column.h" // ComponentConfigStream
  21. #include "rtrui.h"
  22. #include "sapprop.h" // SAP property pages
  23. #include "routprot.h" // IP_LOCAL
  24. #include "ipxstrm.h"
  25. #include "ipxutil.h" // String conversions
  26. #include "globals.h" // SAP defaults
  27. /*---------------------------------------------------------------------------
  28. Keep this in sync with the column ids in sapview.h
  29. ---------------------------------------------------------------------------*/
  30. extern const ContainerColumnInfo s_rgSapViewColumnInfo[];
  31. const ContainerColumnInfo s_rgSapViewColumnInfo[] =
  32. {
  33. { IDS_SAP_COL_INTERFACE, CON_SORT_BY_STRING, TRUE, COL_IF_NAME },
  34. { IDS_SAP_COL_TYPE, CON_SORT_BY_STRING, TRUE, COL_STRING },
  35. { IDS_SAP_COL_ACCEPT_ROUTES, CON_SORT_BY_STRING, FALSE, COL_STRING },
  36. { IDS_SAP_COL_SUPPLY_ROUTES, CON_SORT_BY_STRING, FALSE, COL_STRING },
  37. { IDS_SAP_COL_REPLY_GSNR, CON_SORT_BY_STRING, FALSE, COL_STRING },
  38. { IDS_SAP_COL_UPDATE_MODE, CON_SORT_BY_STRING, TRUE, COL_STRING },
  39. { IDS_SAP_COL_UPDATE_PERIOD, CON_SORT_BY_DWORD, FALSE, COL_DURATION },
  40. { IDS_SAP_COL_AGE_MULTIPLIER, CON_SORT_BY_DWORD, FALSE, COL_SMALL_NUM },
  41. { IDS_SAP_COL_ADMIN_STATE, CON_SORT_BY_STRING, TRUE, COL_STATUS },
  42. { IDS_SAP_COL_OPER_STATE, CON_SORT_BY_STRING, TRUE, COL_STATUS },
  43. { IDS_SAP_COL_PACKETS_SENT, CON_SORT_BY_DWORD, TRUE, COL_LARGE_NUM },
  44. { IDS_SAP_COL_PACKETS_RECEIVED, CON_SORT_BY_DWORD, TRUE, COL_LARGE_NUM },
  45. };
  46. /*---------------------------------------------------------------------------
  47. SapNodeHandler implementation
  48. ---------------------------------------------------------------------------*/
  49. SapNodeHandler::SapNodeHandler(ITFSComponentData *pCompData)
  50. : BaseContainerHandler(pCompData, SAP_COLUMNS,
  51. s_rgSapViewColumnInfo),
  52. m_ulConnId(0),
  53. m_ulRmConnId(0),
  54. m_ulRefreshConnId(0),
  55. m_ulStatsConnId(0)
  56. {
  57. // Setup the verb states
  58. m_rgButtonState[MMC_VERB_PROPERTIES_INDEX] = ENABLED;
  59. m_bState[MMC_VERB_PROPERTIES_INDEX] = TRUE;
  60. m_rgButtonState[MMC_VERB_REFRESH_INDEX] = ENABLED;
  61. m_bState[MMC_VERB_REFRESH_INDEX] = TRUE;
  62. }
  63. STDMETHODIMP SapNodeHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  64. {
  65. // Is the pointer bad?
  66. if (ppv == NULL)
  67. return E_INVALIDARG;
  68. // Place NULL in *ppv in case of failure
  69. *ppv = NULL;
  70. // This is the non-delegating IUnknown implementation
  71. if (riid == IID_IUnknown)
  72. *ppv = (LPVOID) this;
  73. else if (riid == IID_IRtrAdviseSink)
  74. *ppv = &m_IRtrAdviseSink;
  75. else
  76. return BaseContainerHandler::QueryInterface(riid, ppv);
  77. // If we're going to return an interface, AddRef it first
  78. if (*ppv)
  79. {
  80. ((LPUNKNOWN) *ppv)->AddRef();
  81. return hrOK;
  82. }
  83. else
  84. return E_NOINTERFACE;
  85. }
  86. /*!--------------------------------------------------------------------------
  87. SapNodeHandler::DestroyHandler
  88. Implementation of ITFSNodeHandler::DestroyHandler
  89. Author: KennT
  90. ---------------------------------------------------------------------------*/
  91. STDMETHODIMP SapNodeHandler::DestroyHandler(ITFSNode *pNode)
  92. {
  93. IPXConnection * pIPXConn;
  94. pIPXConn = GET_SAP_NODEDATA(pNode);
  95. pIPXConn->Release();
  96. if (m_ulRefreshConnId)
  97. {
  98. SPIRouterRefresh spRefresh;
  99. if (m_spRouterInfo)
  100. m_spRouterInfo->GetRefreshObject(&spRefresh);
  101. if (spRefresh)
  102. spRefresh->UnadviseRefresh(m_ulRefreshConnId);
  103. }
  104. m_ulRefreshConnId = 0;
  105. if (m_ulStatsConnId)
  106. {
  107. SPIRouterRefresh spRefresh;
  108. if (m_spRouterInfo)
  109. m_spRouterInfo->GetRefreshObject(&spRefresh);
  110. if (spRefresh)
  111. spRefresh->UnadviseRefresh(m_ulStatsConnId);
  112. }
  113. m_ulStatsConnId = 0;
  114. if (m_ulConnId)
  115. m_spRmProt->RtrUnadvise(m_ulConnId);
  116. m_ulConnId = 0;
  117. m_spRmProt.Release();
  118. if (m_ulRmConnId)
  119. m_spRm->RtrUnadvise(m_ulRmConnId);
  120. m_ulRmConnId = 0;
  121. m_spRm.Release();
  122. WaitForStatisticsWindow(&m_SAPParamsStats);
  123. m_spRouterInfo.Release();
  124. return hrOK;
  125. }
  126. /*!--------------------------------------------------------------------------
  127. SapNodeHandler::HasPropertyPages
  128. Implementation of ITFSNodeHandler::HasPropertyPages
  129. NOTE: the root node handler has to over-ride this function to
  130. handle the snapin manager property page (wizard) case!!!
  131. Author: KennT
  132. ---------------------------------------------------------------------------*/
  133. STDMETHODIMP
  134. SapNodeHandler::HasPropertyPages
  135. (
  136. ITFSNode * pNode,
  137. LPDATAOBJECT pDataObject,
  138. DATA_OBJECT_TYPES type,
  139. DWORD dwType
  140. )
  141. {
  142. return hrOK;
  143. }
  144. /*!--------------------------------------------------------------------------
  145. SapNodeHandler::CreatePropertyPages
  146. -
  147. Author: KennT
  148. ---------------------------------------------------------------------------*/
  149. STDMETHODIMP
  150. SapNodeHandler::CreatePropertyPages
  151. (
  152. ITFSNode * pNode,
  153. LPPROPERTYSHEETCALLBACK lpProvider,
  154. LPDATAOBJECT pDataObject,
  155. LONG_PTR handle,
  156. DWORD dwType
  157. )
  158. {
  159. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  160. HRESULT hr = hrOK;
  161. SapProperties * pProperties = NULL;
  162. SPIComponentData spComponentData;
  163. CString stTitle;
  164. CORg( m_spNodeMgr->GetComponentData(&spComponentData) );
  165. pProperties = new SapProperties(pNode, spComponentData,
  166. m_spTFSCompData, stTitle);
  167. CORg( pProperties->Init(m_spRm) );
  168. if (lpProvider)
  169. hr = pProperties->CreateModelessSheet(lpProvider, handle);
  170. else
  171. hr = pProperties->DoModelessSheet();
  172. Error:
  173. return hr;
  174. }
  175. /*---------------------------------------------------------------------------
  176. Menu data structure for our menus
  177. ---------------------------------------------------------------------------*/
  178. static const SRouterNodeMenu s_rgIfNodeMenu[] =
  179. {
  180. { IDS_MENU_SAP_SHOW_PARAMS, 0,
  181. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  182. };
  183. /*!--------------------------------------------------------------------------
  184. SapNodeHandler::OnAddMenuItems
  185. Implementation of ITFSNodeHandler::OnAddMenuItems
  186. Author: KennT
  187. ---------------------------------------------------------------------------*/
  188. STDMETHODIMP SapNodeHandler::OnAddMenuItems(
  189. ITFSNode *pNode,
  190. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  191. LPDATAOBJECT lpDataObject,
  192. DATA_OBJECT_TYPES type,
  193. DWORD dwType,
  194. long *pInsertionAllowed)
  195. {
  196. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  197. HRESULT hr = S_OK;
  198. SapNodeHandler::SMenuData menuData;
  199. COM_PROTECT_TRY
  200. {
  201. menuData.m_spNode.Set(pNode);
  202. hr = AddArrayOfMenuItems(pNode, s_rgIfNodeMenu,
  203. DimensionOf(s_rgIfNodeMenu),
  204. pContextMenuCallback,
  205. *pInsertionAllowed,
  206. reinterpret_cast<INT_PTR>(&menuData));
  207. }
  208. COM_PROTECT_CATCH;
  209. return hr;
  210. }
  211. /*!--------------------------------------------------------------------------
  212. SapNodeHandler::OnCommand
  213. Implementation of ITFSNodeHandler::OnCommand
  214. Author: KennT
  215. ---------------------------------------------------------------------------*/
  216. STDMETHODIMP SapNodeHandler::OnCommand(ITFSNode *pNode, long nCommandId,
  217. DATA_OBJECT_TYPES type,
  218. LPDATAOBJECT pDataObject,
  219. DWORD dwType)
  220. {
  221. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  222. HRESULT hr = S_OK;
  223. COM_PROTECT_TRY
  224. {
  225. switch (nCommandId)
  226. {
  227. case IDS_MENU_SAP_SHOW_PARAMS:
  228. CreateNewStatisticsWindow(&m_SAPParamsStats,
  229. ::FindMMCMainWindow(),
  230. IDD_STATS_NARROW);
  231. break;
  232. case IDS_MENU_SYNC:
  233. SynchronizeNodeData(pNode);
  234. break;
  235. }
  236. }
  237. COM_PROTECT_CATCH;
  238. return hr;
  239. }
  240. /*!--------------------------------------------------------------------------
  241. SapNodeHandler::OnExpand
  242. -
  243. Author: KennT
  244. ---------------------------------------------------------------------------*/
  245. HRESULT SapNodeHandler::OnExpand(ITFSNode *pNode,
  246. LPDATAOBJECT pDataObject,
  247. DWORD dwType,
  248. LPARAM arg,
  249. LPARAM lParam)
  250. {
  251. HRESULT hr = hrOK;
  252. SPIEnumInterfaceInfo spEnumIf;
  253. SPIInterfaceInfo spIf;
  254. SPIRtrMgrInterfaceInfo spRmIf;
  255. SPIInfoBase spInfoBase;
  256. if (m_bExpanded)
  257. return hrOK;
  258. COM_PROTECT_TRY
  259. {
  260. CORg( m_spRouterInfo->EnumInterface(&spEnumIf) );
  261. while (spEnumIf->Next(1, &spIf, NULL) == hrOK)
  262. {
  263. if (spIf->FindRtrMgrInterface(PID_IPX, &spRmIf) == hrOK)
  264. {
  265. if (spRmIf->FindRtrMgrProtocolInterface(IPX_PROTOCOL_SAP, NULL) == hrOK)
  266. {
  267. // Now we create an interface node for this interface
  268. AddInterfaceNode(pNode, spIf, FALSE);
  269. }
  270. }
  271. spRmIf.Release();
  272. spIf.Release();
  273. }
  274. //$CLIENT: Add the client interface (setup default data)
  275. // the only thing that we can do in synchronize is to
  276. // get the Administrative status
  277. AddInterfaceNode(pNode, NULL, TRUE);
  278. m_bExpanded = TRUE;
  279. // Now that we have all of the nodes, update the data for
  280. // all of the nodes
  281. SynchronizeNodeData(pNode);
  282. COM_PROTECT_ERROR_LABEL;
  283. }
  284. COM_PROTECT_CATCH;
  285. m_bExpanded = TRUE;
  286. return hr;
  287. }
  288. /*!--------------------------------------------------------------------------
  289. SapNodeHandler::GetString
  290. Implementation of ITFSNodeHandler::GetString
  291. We don't need to do anything, since our root node is an extension
  292. only and thus can't do anything to the node text.
  293. Author: KennT
  294. ---------------------------------------------------------------------------*/
  295. STDMETHODIMP_(LPCTSTR) SapNodeHandler::GetString(ITFSNode *pNode, int nCol)
  296. {
  297. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  298. HRESULT hr = hrOK;
  299. COM_PROTECT_TRY
  300. {
  301. if (m_stTitle.IsEmpty())
  302. m_stTitle.LoadString(IDS_IPX_SAP_TITLE);
  303. }
  304. COM_PROTECT_CATCH;
  305. return m_stTitle;
  306. }
  307. /*!--------------------------------------------------------------------------
  308. SapNodeHandler::OnCreateDataObject
  309. -
  310. Author: KennT
  311. ---------------------------------------------------------------------------*/
  312. STDMETHODIMP SapNodeHandler::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  313. {
  314. HRESULT hr = hrOK;
  315. COM_PROTECT_TRY
  316. {
  317. Assert(m_spRmProt);
  318. CORg( CreateDataObjectFromRtrMgrProtocolInfo(m_spRmProt,
  319. type, cookie, m_spTFSCompData,
  320. ppDataObject) );
  321. COM_PROTECT_ERROR_LABEL;
  322. }
  323. COM_PROTECT_CATCH;
  324. return hr;
  325. }
  326. /*!--------------------------------------------------------------------------
  327. SapNodeHandler::Init
  328. -
  329. Author: KennT
  330. ---------------------------------------------------------------------------*/
  331. HRESULT SapNodeHandler::Init(IRouterInfo *pRouter, SapConfigStream *pConfigStream)
  332. {
  333. m_spRouterInfo.Set(pRouter);
  334. m_spRm.Release();
  335. pRouter->FindRtrMgr(PID_IPX, &m_spRm);
  336. m_spRmProt.Release();
  337. m_spRm->FindRtrMgrProtocol(IPX_PROTOCOL_SAP, &m_spRmProt);
  338. m_pConfigStream = pConfigStream;
  339. // Also need to register for change notifications from IPX_PROTOCOL_SAP
  340. Assert(m_ulConnId == 0);
  341. m_spRmProt->RtrAdvise(&m_IRtrAdviseSink, &m_ulConnId, 0);
  342. // Need to register for change notifications on the Router manager
  343. // This way we can add the necessary protocols when an interface
  344. // gets added.
  345. Assert(m_ulRmConnId == 0);
  346. m_spRm->RtrAdvise(&m_IRtrAdviseSink, &m_ulRmConnId, 0);
  347. m_SAPParamsStats.SetConfigInfo(pConfigStream, SAPSTRM_STATS_SAPPARAMS);
  348. return hrOK;
  349. }
  350. /*!--------------------------------------------------------------------------
  351. SapNodeHandler::ConstructNode
  352. Initializes the root node (sets it up).
  353. Author: KennT
  354. ---------------------------------------------------------------------------*/
  355. HRESULT SapNodeHandler::ConstructNode(ITFSNode *pNode)
  356. {
  357. HRESULT hr = hrOK;
  358. IPXConnection * pIPXConn = NULL;
  359. if (pNode == NULL)
  360. return hrOK;
  361. COM_PROTECT_TRY
  362. {
  363. // Need to initialize the data for the root node
  364. pNode->SetData(TFS_DATA_IMAGEINDEX, IMAGE_IDX_IPX_NODE_GENERAL);
  365. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, IMAGE_IDX_IPX_NODE_GENERAL);
  366. pNode->SetData(TFS_DATA_SCOPEID, 0);
  367. // This is a leaf node in the scope pane
  368. pNode->SetData(TFS_DATA_SCOPE_LEAF_NODE, TRUE);
  369. m_cookie = reinterpret_cast<DWORD_PTR>(pNode);
  370. pNode->SetData(TFS_DATA_COOKIE, m_cookie);
  371. pNode->SetNodeType(&GUID_IPXSapNodeType);
  372. pIPXConn = new IPXConnection;
  373. pIPXConn->SetMachineName(m_spRouterInfo->GetMachineName());
  374. SET_SAP_NODEDATA(pNode, pIPXConn);
  375. m_SAPParamsStats.SetConnectionData(pIPXConn);
  376. }
  377. COM_PROTECT_CATCH;
  378. if (!FHrSucceeded(hr))
  379. {
  380. SET_SAP_NODEDATA(pNode, NULL);
  381. if (pIPXConn)
  382. pIPXConn->Release();
  383. }
  384. return hr;
  385. }
  386. /*!--------------------------------------------------------------------------
  387. SapNodeHandler::AddInterfaceNode
  388. -
  389. Author: KennT
  390. ---------------------------------------------------------------------------*/
  391. HRESULT SapNodeHandler::AddInterfaceNode(ITFSNode *pParent,
  392. IInterfaceInfo *pIf,
  393. BOOL fClient)
  394. {
  395. Assert(pParent);
  396. SapInterfaceHandler * pHandler;
  397. SPITFSResultHandler spHandler;
  398. SPITFSNode spNode;
  399. HRESULT hr = hrOK;
  400. BaseIPXResultNodeData * pData;
  401. IPXConnection * pIPXConn;
  402. SPIInfoBase spInfoBase;
  403. PSAP_IF_CONFIG pric = NULL;
  404. SPIRtrMgrInterfaceInfo spRmIf;
  405. // Create the handler for this node
  406. pHandler = new SapInterfaceHandler(m_spTFSCompData);
  407. spHandler = pHandler;
  408. CORg( pHandler->Init(pIf, m_spRouterInfo, pParent) );
  409. pIPXConn = GET_SAP_NODEDATA(pParent);
  410. // Create a result item node (or a leaf node)
  411. CORg( CreateLeafTFSNode(&spNode,
  412. NULL,
  413. static_cast<ITFSNodeHandler *>(pHandler),
  414. static_cast<ITFSResultHandler *>(pHandler),
  415. m_spNodeMgr) );
  416. CORg( pHandler->ConstructNode(spNode, pIf, pIPXConn) );
  417. pData = GET_BASEIPXRESULT_NODEDATA(spNode);
  418. Assert(pData);
  419. ASSERT_BASEIPXRESULT_NODEDATA(pData);
  420. pData->m_fClient = fClient;
  421. // If we don't have an interface, then this is a client node
  422. if (pIf)
  423. {
  424. pIf->FindRtrMgrInterface(PID_IPX, &spRmIf);
  425. if (spRmIf)
  426. spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase);
  427. if (spInfoBase)
  428. spInfoBase->GetData(IPX_PROTOCOL_SAP, 0, (LPBYTE *) &pric);
  429. Trace1("Adding SAP node : %s\n", pIf->GetTitle());
  430. }
  431. else
  432. {
  433. // This is a client, make it visible
  434. pric = (PSAP_IF_CONFIG) ULongToPtr(0xFFFFFFFF);
  435. Trace0("Adding client interface\n");
  436. }
  437. // if pric == NULL, then we are adding this protocol to the
  438. // interface and we need to hide the node.
  439. if (pric)
  440. {
  441. CORg( spNode->SetVisibilityState(TFS_VIS_SHOW) );
  442. CORg( spNode->Show() );
  443. }
  444. else
  445. CORg( spNode->SetVisibilityState(TFS_VIS_HIDE) );
  446. CORg( pParent->AddChild(spNode) );
  447. Error:
  448. return hr;
  449. }
  450. /*---------------------------------------------------------------------------
  451. This is the set of menus that will appear when a right-click is
  452. done on the blank area of the result pane.
  453. ---------------------------------------------------------------------------*/
  454. static const SRouterNodeMenu s_rgSapResultNodeMenu[] =
  455. {
  456. { IDS_MENU_SAP_SHOW_PARAMS, 0,
  457. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  458. };
  459. /*!--------------------------------------------------------------------------
  460. SapNodeHandler::AddMenuItems
  461. Implementation of ITFSResultHandler::AddMenuItems
  462. Use this to add commands to the context menu of the blank areas
  463. of the result pane.
  464. Author: KennT
  465. ---------------------------------------------------------------------------*/
  466. STDMETHODIMP SapNodeHandler::AddMenuItems(ITFSComponent *pComponent,
  467. MMC_COOKIE cookie,
  468. LPDATAOBJECT pDataObject,
  469. LPCONTEXTMENUCALLBACK pCallback,
  470. long *pInsertionAllowed)
  471. {
  472. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  473. HRESULT hr = hrOK;
  474. SPITFSNode spNode;
  475. SapNodeHandler::SMenuData menuData;
  476. COM_PROTECT_TRY
  477. {
  478. m_spNodeMgr->FindNode(cookie, &spNode);
  479. menuData.m_spNode.Set(spNode);
  480. hr = AddArrayOfMenuItems(spNode,
  481. s_rgSapResultNodeMenu,
  482. DimensionOf(s_rgSapResultNodeMenu),
  483. pCallback,
  484. *pInsertionAllowed,
  485. reinterpret_cast<INT_PTR>(&menuData));
  486. }
  487. COM_PROTECT_CATCH;
  488. return hr;
  489. }
  490. /*!--------------------------------------------------------------------------
  491. SapNodeHandler::Command
  492. -
  493. Author: KennT
  494. ---------------------------------------------------------------------------*/
  495. STDMETHODIMP SapNodeHandler::Command(ITFSComponent *pComponent,
  496. MMC_COOKIE cookie,
  497. int nCommandID,
  498. LPDATAOBJECT pDataObject)
  499. {
  500. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  501. HRESULT hr = hrOK;
  502. switch (nCommandID)
  503. {
  504. case IDS_MENU_SAP_SHOW_PARAMS:
  505. CreateNewStatisticsWindow(&m_SAPParamsStats,
  506. ::FindMMCMainWindow(),
  507. IDD_STATS_NARROW);
  508. break;
  509. }
  510. return hr;
  511. }
  512. ImplementEmbeddedUnknown(SapNodeHandler, IRtrAdviseSink)
  513. STDMETHODIMP SapNodeHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  514. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  515. {
  516. InitPThis(SapNodeHandler, IRtrAdviseSink);
  517. SPITFSNode spThisNode;
  518. SPITFSNode spNode;
  519. SPITFSNodeEnum spEnumNode;
  520. SPIEnumInterfaceInfo spEnumIf;
  521. SPIInterfaceInfo spIf;
  522. SPIRtrMgrInterfaceInfo spRmIf;
  523. SPIInfoBase spInfoBase;
  524. BOOL fPleaseAdd;
  525. BOOL fFound;
  526. BaseIPXResultNodeData * pData;
  527. HRESULT hr = hrOK;
  528. pThis->m_spNodeMgr->FindNode(pThis->m_cookie, &spThisNode);
  529. if (dwObjectType == ROUTER_OBJ_RmIf)
  530. {
  531. if (dwChangeType == ROUTER_CHILD_PREADD)
  532. {
  533. // Add SAP to the infobase
  534. pThis->AddProtocolToInfoBase(spThisNode);
  535. }
  536. else if (dwChangeType == ROUTER_CHILD_ADD)
  537. {
  538. // Add the protocol to the router mgr
  539. // We need to add the protocol to the interface (use
  540. // default values).
  541. pThis->AddProtocolToInterface(spThisNode);
  542. }
  543. }
  544. if (dwObjectType == ROUTER_OBJ_RmProtIf)
  545. {
  546. if (dwChangeType == ROUTER_CHILD_ADD)
  547. {
  548. // If the node hasn't been expanded yet, then we don't
  549. // need to do anything yet.
  550. if (pThis->m_bExpanded)
  551. {
  552. // Enumerate through the list of interfaces looking for
  553. // the interfaces that have this protocol. If we find
  554. // one, look for this interface in our list of nodes.
  555. spThisNode->GetEnum(&spEnumNode);
  556. CORg( pThis->m_spRouterInfo->EnumInterface(&spEnumIf) );
  557. spEnumIf->Reset();
  558. fPleaseAdd = FALSE;
  559. for (; spEnumIf->Next(1, &spIf, NULL) == hrOK; spIf.Release())
  560. {
  561. // Look for this interface in our list of nodes
  562. // If it's there than continue on
  563. fFound = FALSE;
  564. spEnumNode->Reset();
  565. spNode.Release();
  566. for (; spEnumNode->Next(1, &spNode, NULL) == hrOK; spNode.Release())
  567. {
  568. pData = GET_BASEIPXRESULT_NODEDATA(spNode);
  569. Assert(pData);
  570. ASSERT_BASEIPXRESULT_NODEDATA(pData);
  571. if (!pData->m_fClient && StriCmpW(pData->m_spIf->GetId(), spIf->GetId()) == 0)
  572. {
  573. fFound = TRUE;
  574. break;
  575. }
  576. }
  577. // If the interface was not found in the list of nodes,
  578. // then it is a candidate. Now we have to see if the
  579. // interface supports this transport.
  580. if (!fFound && (LookupRtrMgrProtocolInterface(spIf, PID_IPX, IPX_PROTOCOL_SAP, NULL) == hrOK))
  581. {
  582. // If this interface has this transport, and is NOT in
  583. // the current list of nodes then add this interface
  584. // to the UI
  585. // Grab the infobase
  586. // Load the infobase for this interface
  587. spRmIf.Release();
  588. spInfoBase.Release();
  589. hr = spIf->FindRtrMgrInterface(PID_IPX, &spRmIf);
  590. if (FHrOK(hr))
  591. {
  592. spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase);
  593. hr = pThis->AddInterfaceNode(spThisNode, spIf, FALSE);
  594. }
  595. fPleaseAdd = TRUE;
  596. }
  597. }
  598. // Now that we have all of the nodes, update the data for
  599. // all of the nodes
  600. if (fPleaseAdd)
  601. pThis->SynchronizeNodeData(spThisNode);
  602. }
  603. }
  604. else if (dwChangeType == ROUTER_CHILD_DELETE)
  605. {
  606. // Go through the list of nodes, if we cannot find the
  607. // node in the list of interfaces, delete the node
  608. spThisNode->GetEnum(&spEnumNode);
  609. spEnumNode->Reset();
  610. while (spEnumNode->Next(1, &spNode, NULL) == hrOK)
  611. {
  612. // Get the node data, look for the interface
  613. pData = GET_BASEIPXRESULT_NODEDATA(spNode);
  614. ASSERT_BASEIPXRESULT_NODEDATA(pData);
  615. if (pData->m_spIf &&
  616. LookupRtrMgrProtocolInterface(pData->m_spIf,
  617. PID_IPX, IPX_PROTOCOL_SAP, NULL) != hrOK)
  618. {
  619. // If this flag is set, then we are in the new
  620. // interface case, and we do not want to delete
  621. // this here since it will then deadlock.
  622. if ((spNode->GetVisibilityState() & TFS_VIS_DELETE) == 0)
  623. {
  624. // cannot find the interface, release this node!
  625. spThisNode->RemoveChild(spNode);
  626. spNode->Destroy();
  627. }
  628. }
  629. spNode.Release();
  630. spIf.Release();
  631. }
  632. }
  633. }
  634. else if (dwChangeType == ROUTER_REFRESH)
  635. {
  636. if (ulConn == pThis->m_ulStatsConnId)
  637. {
  638. pThis->m_SAPParamsStats.PostRefresh();
  639. }
  640. else
  641. pThis->SynchronizeNodeData(spThisNode);
  642. }
  643. else if (dwChangeType == ROUTER_DO_DISCONNECT)
  644. {
  645. IPXConnection * pIPXConn = NULL;
  646. pIPXConn = GET_SAP_NODEDATA(spThisNode);
  647. pIPXConn->DisconnectAll();
  648. }
  649. Error:
  650. return hr;
  651. }
  652. HRESULT SapNodeHandler::AddProtocolToInfoBase(ITFSNode *pThisNode)
  653. {
  654. HRESULT hr = hrOK;
  655. SPITFSNodeEnum spEnumNode;
  656. SPIRtrMgrInterfaceInfo spRmIf;
  657. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  658. SPIEnumInterfaceInfo spEnumIf;
  659. SPIInterfaceInfo spIf;
  660. SPITFSNode spNode;
  661. BaseIPXResultNodeData * pData;
  662. // Enumerate through the list of interfaces looking for
  663. // the interfaces that have this protocol. If we find
  664. // one, look for this interface in our list of nodes.
  665. pThisNode->GetEnum(&spEnumNode);
  666. CORg( m_spRouterInfo->EnumInterface(&spEnumIf) );
  667. spEnumIf->Reset();
  668. for (; spEnumIf->Next(1, &spIf, NULL) == hrOK; spIf.Release())
  669. {
  670. // Look for this interface in our list of nodes
  671. // If it's there than continue on
  672. spEnumNode->Reset();
  673. spNode.Release();
  674. spRmIf.Release();
  675. // If this interface has IPX but not SAP, add it
  676. if ((spIf->FindRtrMgrInterface(PID_IPX, &spRmIf) == hrOK) &&
  677. (LookupRtrMgrProtocolInterface(spIf, PID_IPX,
  678. IPX_PROTOCOL_SAP, NULL) != hrOK))
  679. {
  680. // Add SAP to this node
  681. SAP_IF_CONFIG sic;
  682. SPIInfoBase spInfoBase;
  683. // We need to get the infobase for this and create
  684. // the SAP blocks (but do NOT save, let the property
  685. // sheet take care of that).
  686. spInfoBase.Release();
  687. if (!FHrOK(spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase)))
  688. {
  689. spRmIf->Load(spRmIf->GetMachineName(), NULL, NULL, NULL);
  690. spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase);
  691. }
  692. if (!spInfoBase)
  693. CreateInfoBase(&spInfoBase);
  694. if (!FHrOK(spInfoBase->ProtocolExists(IPX_PROTOCOL_SAP)))
  695. {
  696. // Add a SAP_IF_CONFIG block
  697. BYTE * pDefault;
  698. if (spIf->GetInterfaceType() == ROUTER_IF_TYPE_DEDICATED)
  699. pDefault = g_pIpxSapLanInterfaceDefault;
  700. else
  701. pDefault = g_pIpxSapInterfaceDefault;
  702. spInfoBase->AddBlock(IPX_PROTOCOL_SAP,
  703. sizeof(SAP_IF_CONFIG),
  704. pDefault,
  705. 1,
  706. 0);
  707. spRmIf->SetInfoBase(NULL, NULL, NULL, spInfoBase);
  708. }
  709. }
  710. }
  711. // Now that we have all of the nodes, update the data for
  712. // all of the nodes
  713. // if (fPleaseAdd)
  714. // pThis->SynchronizeNodeData(spThisNode);
  715. Error:
  716. return hr;
  717. }
  718. HRESULT SapNodeHandler::AddProtocolToInterface(ITFSNode *pThisNode)
  719. {
  720. HRESULT hr = hrOK;
  721. SPITFSNodeEnum spEnumNode;
  722. SPIRtrMgrInterfaceInfo spRmIf;
  723. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  724. SPIEnumInterfaceInfo spEnumIf;
  725. SPIInterfaceInfo spIf;
  726. SPITFSNode spNode;
  727. BaseIPXResultNodeData * pData;
  728. // Enumerate through the list of interfaces looking for
  729. // the interfaces that have this protocol. If we find
  730. // one, look for this interface in our list of nodes.
  731. pThisNode->GetEnum(&spEnumNode);
  732. CORg( m_spRouterInfo->EnumInterface(&spEnumIf) );
  733. spEnumIf->Reset();
  734. for (; spEnumIf->Next(1, &spIf, NULL) == hrOK; spIf.Release())
  735. {
  736. // Look for this interface in our list of nodes
  737. // If it's there than continue on
  738. spEnumNode->Reset();
  739. spNode.Release();
  740. // If this interface has IPX but not SAP, add it
  741. if ((spIf->FindRtrMgrInterface(PID_IPX, NULL) == hrOK) &&
  742. (LookupRtrMgrProtocolInterface(spIf, PID_IPX,
  743. IPX_PROTOCOL_SAP, NULL) != hrOK))
  744. {
  745. // Add SAP to this node
  746. SAP_IF_CONFIG sic;
  747. RtrMgrProtocolCB RmProtCB;
  748. RtrMgrProtocolInterfaceCB RmProtIfCB;
  749. SPIInfoBase spInfoBase;
  750. // Need to create an RmProtIf
  751. m_spRmProt->CopyCB(&RmProtCB);
  752. spRmProtIf.Release();
  753. RmProtIfCB.dwProtocolId = RmProtCB.dwProtocolId;
  754. StrnCpyW(RmProtIfCB.szId, RmProtCB.szId, RTR_ID_MAX);
  755. RmProtIfCB.dwTransportId = RmProtCB.dwTransportId;
  756. StrnCpyW(RmProtIfCB.szRtrMgrId, RmProtCB.szRtrMgrId, RTR_ID_MAX);
  757. StrnCpyW(RmProtIfCB.szInterfaceId, spIf->GetId(), RTR_ID_MAX);
  758. RmProtIfCB.dwIfType = spIf->GetInterfaceType();
  759. RmProtIfCB.szTitle[0] = 0;
  760. CORg( CreateRtrMgrProtocolInterfaceInfo(&spRmProtIf,
  761. &RmProtIfCB) );
  762. spRmProtIf->SetTitle(spIf->GetTitle());
  763. // Add this to the spRmIf
  764. spRmIf.Release();
  765. CORg( spIf->FindRtrMgrInterface(PID_IPX, &spRmIf) );
  766. Assert(spRmIf);
  767. // We need to get the infobase for this and create
  768. // the SAP blocks (but do NOT save, let the property
  769. // sheet take care of that).
  770. spInfoBase.Release();
  771. // spRmIf->Load(spRmIf->GetMachineName(), NULL, NULL, NULL);
  772. spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase);
  773. if (!spInfoBase)
  774. CreateInfoBase(&spInfoBase);
  775. if (!FHrOK(spInfoBase->BlockExists(IPX_PROTOCOL_SAP)))
  776. {
  777. // Add a SAP_IF_CONFIG block
  778. BYTE * pDefault;
  779. if (spIf->GetInterfaceType() == ROUTER_IF_TYPE_DEDICATED)
  780. pDefault = g_pIpxSapLanInterfaceDefault;
  781. else
  782. pDefault = g_pIpxSapInterfaceDefault;
  783. spInfoBase->AddBlock(IPX_PROTOCOL_SAP,
  784. sizeof(SAP_IF_CONFIG),
  785. pDefault,
  786. 1,
  787. 0);
  788. }
  789. CORg(spRmIf->AddRtrMgrProtocolInterface(spRmProtIf,
  790. spInfoBase /* pInfoBase */));
  791. }
  792. }
  793. // Now that we have all of the nodes, update the data for
  794. // all of the nodes
  795. // if (fPleaseAdd)
  796. // pThis->SynchronizeNodeData(spThisNode);
  797. Error:
  798. return hr;
  799. }
  800. /*!--------------------------------------------------------------------------
  801. SapNodeHandler::SynchronizeNodeData
  802. -
  803. Author: KennT
  804. ---------------------------------------------------------------------------*/
  805. HRESULT SapNodeHandler::SynchronizeNodeData(ITFSNode *pThisNode)
  806. {
  807. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  808. HRESULT hr = hrOK;
  809. SPITFSNodeEnum spNodeEnum;
  810. SPITFSNode spNode;
  811. CStringList ifidList;
  812. BaseIPXResultNodeData * pNodeData;
  813. SapList sapList;
  814. SapListEntry * pSapEntry = NULL;
  815. SapListEntry * pSapCurrent = NULL;
  816. int i;
  817. CString stNotAvailable;
  818. POSITION pos;
  819. COM_PROTECT_TRY
  820. {
  821. // Do the data gathering work (separate this from the rest of the
  822. // code so that we can move this part to a background thread later).
  823. stNotAvailable.LoadString(IDS_IPX_NOT_AVAILABLE);
  824. // We need to build up a list of interface ids
  825. pThisNode->GetEnum(&spNodeEnum);
  826. for (; spNodeEnum->Next(1, &spNode, NULL) == hrOK; spNode.Release() )
  827. {
  828. pNodeData = GET_BASEIPXRESULT_NODEDATA(spNode);
  829. Assert(pNodeData);
  830. ASSERT_BASEIPXRESULT_NODEDATA(pNodeData);
  831. pSapEntry = new SapListEntry;
  832. pSapEntry->m_spIf.Set(pNodeData->m_spIf);
  833. pSapEntry->m_spNode.Set(spNode);
  834. ::ZeroMemory(&(pSapEntry->m_info), sizeof(pSapEntry->m_info));
  835. ::ZeroMemory(&(pSapEntry->m_stats), sizeof(pSapEntry->m_stats));
  836. pSapEntry->m_fClient = pNodeData->m_fClient;
  837. pSapEntry->m_fFoundIfIndex = FALSE;
  838. pSapEntry->m_dwIfIndex = 0;
  839. sapList.AddTail(pSapEntry);
  840. pSapEntry = NULL;
  841. // Fill in the result data with '-'
  842. // This is a little bogus, but it's the easiest way, we
  843. // don't want to touch interface and relay_mode.
  844. for (i=SAP_SI_INTERFACE; i<SAP_SI_MAX_COLUMNS; i++)
  845. {
  846. pNodeData->m_rgData[i].m_stData = stNotAvailable;
  847. pNodeData->m_rgData[i].m_dwData = 0xFFFFFFFF;
  848. }
  849. // Update the necessary data
  850. if (pNodeData->m_fClient)
  851. {
  852. pNodeData->m_rgData[SAP_SI_INTERFACE].m_stData.LoadString(
  853. IDS_IPX_DIAL_IN_CLIENTS);
  854. pNodeData->m_rgData[SAP_SI_TYPE].m_stData =
  855. IpxTypeToCString(ROUTER_IF_TYPE_CLIENT);
  856. }
  857. else
  858. {
  859. pNodeData->m_rgData[SAP_SI_INTERFACE].m_stData =
  860. pNodeData->m_spIf->GetTitle();
  861. pNodeData->m_rgData[SAP_SI_TYPE].m_stData =
  862. IpxTypeToCString(pNodeData->m_spIf->GetInterfaceType());
  863. }
  864. }
  865. spNode.Release();
  866. // We can now use this list of ids, to get the data for each item
  867. CORg( GetSapData(pThisNode, &sapList) );
  868. // Now for each data item, fill in the appropriate data in
  869. // the node
  870. pos = sapList.GetHeadPosition();
  871. while (pos)
  872. {
  873. pSapCurrent = sapList.GetNext(pos);
  874. pNodeData = GET_BASEIPXRESULT_NODEDATA(pSapCurrent->m_spNode);
  875. Assert(pNodeData);
  876. ASSERT_BASEIPXRESULT_NODEDATA(pNodeData);
  877. pNodeData->m_rgData[SAP_SI_ACCEPT_ROUTES].m_stData =
  878. IpxAdminStateToCString(pSapCurrent->m_info.Listen);
  879. pNodeData->m_rgData[SAP_SI_SUPPLY_ROUTES].m_stData =
  880. IpxAdminStateToCString(pSapCurrent->m_info.Supply);
  881. pNodeData->m_rgData[SAP_SI_GSNR].m_stData =
  882. IpxAdminStateToCString(pSapCurrent->m_info.GetNearestServerReply);
  883. pNodeData->m_rgData[SAP_SI_UPDATE_MODE].m_stData =
  884. RipSapUpdateModeToCString(pSapCurrent->m_info.UpdateMode);
  885. FillInNumberData(pNodeData, SAP_SI_UPDATE_PERIOD,
  886. pSapCurrent->m_info.PeriodicUpdateInterval);
  887. FillInNumberData(pNodeData, SAP_SI_AGE_MULTIPLIER,
  888. pSapCurrent->m_info.AgeIntervalMultiplier);
  889. pNodeData->m_rgData[SAP_SI_ADMIN_STATE].m_stData =
  890. IpxAdminStateToCString(pSapCurrent->m_info.AdminState);
  891. if (!pSapCurrent->m_fClient)
  892. {
  893. pNodeData->m_rgData[SAP_SI_OPER_STATE].m_stData =
  894. IpxOperStateToCString(pSapCurrent->m_stats.SapIfOperState);
  895. FillInNumberData(pNodeData, SAP_SI_PACKETS_SENT,
  896. pSapCurrent->m_stats.SapIfOutputPackets);
  897. FillInNumberData(pNodeData, SAP_SI_PACKETS_RECEIVED,
  898. pSapCurrent->m_stats.SapIfInputPackets);
  899. }
  900. pSapCurrent->m_spNode->ChangeNode(RESULT_PANE_CHANGE_ITEM_DATA);
  901. }
  902. COM_PROTECT_ERROR_LABEL;
  903. }
  904. COM_PROTECT_CATCH;
  905. delete pSapEntry;
  906. while (!sapList.IsEmpty())
  907. delete sapList.RemoveTail();
  908. return hr;
  909. }
  910. /*!--------------------------------------------------------------------------
  911. SapNodeHandler::GetSapData
  912. -
  913. Author: KennT
  914. ---------------------------------------------------------------------------*/
  915. HRESULT SapNodeHandler::GetSapData(ITFSNode *pThisNode, SapList *pSapList)
  916. {
  917. HRESULT hr = hrOK;
  918. BOOL fIsServiceRunning;
  919. IPXConnection * pIPXConn;
  920. SAP_MIB_GET_INPUT_DATA MibGetInputData;
  921. SPIInfoBase spInfoBase;
  922. POSITION pos;
  923. SapListEntry * pSapEntry;
  924. int i;
  925. PSAP_INTERFACE pSapIf = NULL;
  926. DWORD cbSapIf;
  927. SPMprMibBuffer spMib;
  928. DWORD dwErr;
  929. SPIRtrMgrInterfaceInfo spRmIf;
  930. PSAP_IF_CONFIG pric;
  931. // Retrieve the IP interface table; we will need this in order to
  932. // map interface-names to interface-indices, and we will need the
  933. // interface-indices in order to query for SAP MIB information.
  934. //
  935. CORg( IsRouterServiceRunning(m_spRouterInfo->GetMachineName(), NULL) );
  936. fIsServiceRunning = (hr == hrOK);
  937. // Get the connection data
  938. pIPXConn = GET_SAP_NODEDATA(pThisNode);
  939. // Iterate through the list filling in the interface indexes
  940. CORg( FillInInterfaceIndex(pIPXConn, pSapList) );
  941. // Iterate throught the list of entries, gathering data for each
  942. // interface
  943. pos = pSapList->GetHeadPosition();
  944. while (pos)
  945. {
  946. pSapEntry = pSapList->GetNext(pos);
  947. if (!fIsServiceRunning)
  948. continue;
  949. if (pSapEntry->m_fClient)
  950. {
  951. // Fill in the client data
  952. FillClientData(pSapEntry);
  953. continue;
  954. }
  955. // Load the infobase and get the data for this entry
  956. spRmIf.Release();
  957. spInfoBase.Release();
  958. CORg( pSapEntry->m_spIf->FindRtrMgrInterface(PID_IPX, &spRmIf) );
  959. if (!spRmIf)
  960. continue;
  961. CORg( spRmIf->Load(spRmIf->GetMachineName(), NULL, NULL, NULL) );
  962. CORg( spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase) );
  963. CORg( spInfoBase->GetData(IPX_PROTOCOL_SAP, 0, (LPBYTE *) &pric) );
  964. pSapEntry->m_info = pric->SapIfInfo;
  965. if (!pSapEntry->m_fFoundIfIndex)
  966. continue;
  967. // Now get the dynamic data from the MIBs
  968. spMib.Free();
  969. MibGetInputData.InterfaceIndex = pSapEntry->m_dwIfIndex;
  970. MibGetInputData.TableId = SAP_INTERFACE_TABLE;
  971. dwErr = ::MprAdminMIBEntryGet(pIPXConn->GetMibHandle(),
  972. PID_IPX,
  973. IPX_PROTOCOL_SAP,
  974. &MibGetInputData,
  975. sizeof(MibGetInputData),
  976. (LPVOID *) &pSapIf,
  977. &cbSapIf);
  978. spMib = (PBYTE) pSapIf;
  979. CWRg(dwErr);
  980. Assert(pSapIf);
  981. pSapEntry->m_stats = pSapIf->SapIfStats;
  982. }
  983. Error:
  984. return hr;
  985. }
  986. /*!--------------------------------------------------------------------------
  987. SapNodeHandler::FillInInterfaceIndex
  988. -
  989. Author: KennT
  990. ---------------------------------------------------------------------------*/
  991. HRESULT SapNodeHandler::FillInInterfaceIndex(IPXConnection *pIPXConn, SapList *pSapList)
  992. {
  993. HRESULT hr = hrOK;
  994. POSITION pos;
  995. SapListEntry * pSapEntry;
  996. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  997. DWORD IfSize = sizeof(IPX_INTERFACE);
  998. PIPX_INTERFACE pIpxIf;
  999. DWORD dwErr;
  1000. SPMprMibBuffer spMib;
  1001. USES_CONVERSION;
  1002. MibGetInputData.TableId = IPX_INTERFACE_TABLE;
  1003. dwErr = ::MprAdminMIBEntryGetFirst(pIPXConn->GetMibHandle(),
  1004. PID_IPX,
  1005. IPX_PROTOCOL_BASE,
  1006. &MibGetInputData,
  1007. sizeof(IPX_MIB_GET_INPUT_DATA),
  1008. (LPVOID *) &pIpxIf,
  1009. &IfSize);
  1010. hr = HRESULT_FROM_WIN32(dwErr);
  1011. spMib = (LPBYTE) pIpxIf;
  1012. while (FHrSucceeded(hr))
  1013. {
  1014. // go through the list of interfaces looking for a match
  1015. pos = pSapList->GetHeadPosition();
  1016. while (pos)
  1017. {
  1018. pSapEntry = pSapList->GetNext(pos);
  1019. // If this is the client interface, we don't need to
  1020. // look for an interface that matches
  1021. if (pSapEntry->m_fClient)
  1022. continue;
  1023. if (StriCmp(pSapEntry->m_spIf->GetId(),
  1024. A2CT((LPCSTR) pIpxIf->InterfaceName)) == 0)
  1025. {
  1026. Assert(pSapEntry->m_fFoundIfIndex == FALSE);
  1027. pSapEntry->m_dwIfIndex = pIpxIf->InterfaceIndex;
  1028. pSapEntry->m_fFoundIfIndex = TRUE;
  1029. break;
  1030. }
  1031. pSapEntry = NULL;
  1032. }
  1033. // Go onto the next interface
  1034. MibGetInputData.MibIndex.InterfaceTableIndex.InterfaceIndex =
  1035. pIpxIf->InterfaceIndex;
  1036. spMib.Free();
  1037. pIpxIf = NULL;
  1038. dwErr = ::MprAdminMIBEntryGetNext(pIPXConn->GetMibHandle(),
  1039. PID_IPX,
  1040. IPX_PROTOCOL_BASE,
  1041. &MibGetInputData,
  1042. sizeof(IPX_MIB_GET_INPUT_DATA),
  1043. (LPVOID *) &pIpxIf,
  1044. &IfSize);
  1045. hr = HRESULT_FROM_WIN32(dwErr);
  1046. spMib = (LPBYTE) pIpxIf;
  1047. }
  1048. //Error:
  1049. return hr == HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) ? hrOK : hr;
  1050. }
  1051. /*!--------------------------------------------------------------------------
  1052. SapNodeHandler::FillClientData
  1053. -
  1054. Author: KennT
  1055. ---------------------------------------------------------------------------*/
  1056. HRESULT SapNodeHandler::FillClientData(SapListEntry *pSapEntry)
  1057. {
  1058. HRESULT hr = hrOK;
  1059. SPIInfoBase spInfoBase;
  1060. PSAP_IF_CONFIG pric = NULL;
  1061. Assert(pSapEntry->m_fClient == TRUE);
  1062. Assert(pSapEntry->m_fFoundIfIndex == FALSE);
  1063. CORg( m_spRm->GetInfoBase(NULL, NULL, NULL, &spInfoBase) );
  1064. CORg( spInfoBase->GetData(IPX_PROTOCOL_SAP, 0, (LPBYTE *) &pric) );
  1065. pSapEntry->m_info = pric->SapIfInfo;
  1066. memset(&(pSapEntry->m_stats), 0xFF, sizeof(pSapEntry->m_stats));
  1067. pSapEntry->m_dwIfIndex = 0xFFFFFFFF;
  1068. Error:
  1069. return hr;
  1070. }
  1071. /*!--------------------------------------------------------------------------
  1072. SapNodeHandler::OnResultShow
  1073. -
  1074. Author: KennT
  1075. ---------------------------------------------------------------------------*/
  1076. HRESULT SapNodeHandler::OnResultShow(ITFSComponent *pTFSComponent, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  1077. {
  1078. BOOL bSelect = (BOOL) arg;
  1079. HRESULT hr = hrOK;
  1080. SPIRouterRefresh spRefresh;
  1081. SPITFSNode spNode;
  1082. BaseContainerHandler::OnResultShow(pTFSComponent, cookie, arg, lParam);
  1083. if (bSelect)
  1084. {
  1085. // Call synchronize on this node
  1086. m_spNodeMgr->FindNode(cookie, &spNode);
  1087. if (spNode)
  1088. SynchronizeNodeData(spNode);
  1089. }
  1090. // Un/Register for refresh advises
  1091. if (m_spRouterInfo)
  1092. m_spRouterInfo->GetRefreshObject(&spRefresh);
  1093. if (spRefresh)
  1094. {
  1095. if (bSelect)
  1096. {
  1097. if (m_ulRefreshConnId == 0)
  1098. spRefresh->AdviseRefresh(&m_IRtrAdviseSink, &m_ulRefreshConnId, 0);
  1099. if (m_ulStatsConnId == 0)
  1100. spRefresh->AdviseRefresh(&m_IRtrAdviseSink, &m_ulStatsConnId, 0);
  1101. }
  1102. else
  1103. {
  1104. if (m_ulRefreshConnId)
  1105. spRefresh->UnadviseRefresh(m_ulRefreshConnId);
  1106. m_ulRefreshConnId = 0;
  1107. }
  1108. }
  1109. return hr;
  1110. }
  1111. /*!--------------------------------------------------------------------------
  1112. SapNodeHandler::CompareItems
  1113. -
  1114. Author: KennT
  1115. ---------------------------------------------------------------------------*/
  1116. STDMETHODIMP_(int) SapNodeHandler::CompareItems(
  1117. ITFSComponent * pComponent,
  1118. MMC_COOKIE cookieA,
  1119. MMC_COOKIE cookieB,
  1120. int nCol)
  1121. {
  1122. // Get the strings from the nodes and use that as a basis for
  1123. // comparison.
  1124. SPITFSNode spNode;
  1125. SPITFSResultHandler spResult;
  1126. m_spNodeMgr->FindNode(cookieA, &spNode);
  1127. spNode->GetResultHandler(&spResult);
  1128. return spResult->CompareItems(pComponent, cookieA, cookieB, nCol);
  1129. }
  1130. /*---------------------------------------------------------------------------
  1131. Class: SapInterfaceHandler
  1132. ---------------------------------------------------------------------------*/
  1133. SapInterfaceHandler::SapInterfaceHandler(ITFSComponentData *pCompData)
  1134. : BaseIPXResultHandler(pCompData, SAP_COLUMNS),
  1135. m_ulConnId(0)
  1136. {
  1137. m_rgButtonState[MMC_VERB_PROPERTIES_INDEX] = ENABLED;
  1138. m_bState[MMC_VERB_PROPERTIES_INDEX] = TRUE;
  1139. m_rgButtonState[MMC_VERB_REFRESH_INDEX] = ENABLED;
  1140. m_bState[MMC_VERB_REFRESH_INDEX] = TRUE;
  1141. m_verbDefault = MMC_VERB_PROPERTIES;
  1142. }
  1143. static const DWORD s_rgInterfaceImageMap[] =
  1144. {
  1145. ROUTER_IF_TYPE_HOME_ROUTER, IMAGE_IDX_WAN_CARD,
  1146. ROUTER_IF_TYPE_FULL_ROUTER, IMAGE_IDX_WAN_CARD,
  1147. ROUTER_IF_TYPE_CLIENT, IMAGE_IDX_WAN_CARD,
  1148. ROUTER_IF_TYPE_DEDICATED, IMAGE_IDX_LAN_CARD,
  1149. ROUTER_IF_TYPE_INTERNAL, IMAGE_IDX_LAN_CARD,
  1150. ROUTER_IF_TYPE_LOOPBACK, IMAGE_IDX_LAN_CARD,
  1151. -1, IMAGE_IDX_WAN_CARD, // sentinel value
  1152. };
  1153. /*!--------------------------------------------------------------------------
  1154. SapInterfaceHandler::ConstructNode
  1155. Initializes the Domain node (sets it up).
  1156. Author: KennT
  1157. ---------------------------------------------------------------------------*/
  1158. HRESULT SapInterfaceHandler::ConstructNode(ITFSNode *pNode, IInterfaceInfo *pIfInfo, IPXConnection *pIPXConn)
  1159. {
  1160. HRESULT hr = hrOK;
  1161. int i;
  1162. DWORD dwIfType;
  1163. if (pNode == NULL)
  1164. return hrOK;
  1165. COM_PROTECT_TRY
  1166. {
  1167. // Need to initialize the data for the Domain node
  1168. // Find the right image index for this type of node
  1169. if (pIfInfo)
  1170. dwIfType = pIfInfo->GetInterfaceType();
  1171. else
  1172. dwIfType = ROUTER_IF_TYPE_CLIENT;
  1173. for (i=0; i<DimensionOf(s_rgInterfaceImageMap); i+=2)
  1174. {
  1175. if ((dwIfType == s_rgInterfaceImageMap[i]) ||
  1176. (-1 == s_rgInterfaceImageMap[i]))
  1177. break;
  1178. }
  1179. pNode->SetData(TFS_DATA_IMAGEINDEX, s_rgInterfaceImageMap[i+1]);
  1180. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, s_rgInterfaceImageMap[i+1]);
  1181. pNode->SetData(TFS_DATA_SCOPEID, 0);
  1182. pNode->SetData(TFS_DATA_COOKIE, reinterpret_cast<DWORD_PTR>(pNode));
  1183. //$ Review: kennt, what are the different type of interfaces
  1184. // do we distinguish based on the same list as above? (i.e. the
  1185. // one for image indexes).
  1186. pNode->SetNodeType(&GUID_IPXSapInterfaceNodeType);
  1187. BaseIPXResultNodeData::Init(pNode, pIfInfo, pIPXConn);
  1188. }
  1189. COM_PROTECT_CATCH
  1190. return hr;
  1191. }
  1192. /*!--------------------------------------------------------------------------
  1193. SapInterfaceHandler::OnCreateDataObject
  1194. -
  1195. Author: KennT
  1196. ---------------------------------------------------------------------------*/
  1197. STDMETHODIMP SapInterfaceHandler::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  1198. {
  1199. HRESULT hr = hrOK;
  1200. COM_PROTECT_TRY
  1201. {
  1202. CORg( CreateDataObjectFromInterfaceInfo(m_spInterfaceInfo,
  1203. type, cookie, m_spTFSCompData,
  1204. ppDataObject) );
  1205. COM_PROTECT_ERROR_LABEL;
  1206. }
  1207. COM_PROTECT_CATCH;
  1208. return hr;
  1209. }
  1210. /*!--------------------------------------------------------------------------
  1211. SapInterfaceHandler::OnCreateDataObject
  1212. Implementation of ITFSResultHandler::OnCreateDataObject
  1213. Author: KennT
  1214. ---------------------------------------------------------------------------*/
  1215. STDMETHODIMP SapInterfaceHandler::OnCreateDataObject(ITFSComponent *pComp, MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  1216. {
  1217. HRESULT hr = hrOK;
  1218. COM_PROTECT_TRY
  1219. {
  1220. CORg( CreateDataObjectFromInterfaceInfo(m_spInterfaceInfo,
  1221. type, cookie, m_spTFSCompData,
  1222. ppDataObject) );
  1223. COM_PROTECT_ERROR_LABEL;
  1224. }
  1225. COM_PROTECT_CATCH;
  1226. return hr;
  1227. }
  1228. /*!--------------------------------------------------------------------------
  1229. SapInterfaceHandler::RefreshInterface
  1230. -
  1231. Author: KennT
  1232. ---------------------------------------------------------------------------*/
  1233. void SapInterfaceHandler::RefreshInterface(MMC_COOKIE cookie)
  1234. {
  1235. SPITFSNode spNode;
  1236. m_spNodeMgr->FindNode(cookie, &spNode);
  1237. ForwardCommandToParent(spNode, IDS_MENU_SYNC,
  1238. CCT_RESULT, NULL, 0);
  1239. }
  1240. /*!--------------------------------------------------------------------------
  1241. SapInterfaceHandler::Init
  1242. -
  1243. Author: KennT
  1244. ---------------------------------------------------------------------------*/
  1245. HRESULT SapInterfaceHandler::Init(IInterfaceInfo *pIfInfo,
  1246. IRouterInfo *pRouterInfo,
  1247. ITFSNode *pParent)
  1248. {
  1249. m_spInterfaceInfo.Set(pIfInfo);
  1250. BaseIPXResultHandler::Init(pIfInfo, pParent);
  1251. m_spRouterInfo.Set(pRouterInfo);
  1252. return hrOK;
  1253. }
  1254. /*!--------------------------------------------------------------------------
  1255. SapInterfaceHandler::DestroyResultHandler
  1256. -
  1257. Author: KennT
  1258. ---------------------------------------------------------------------------*/
  1259. STDMETHODIMP SapInterfaceHandler::DestroyResultHandler(MMC_COOKIE cookie)
  1260. {
  1261. m_spInterfaceInfo.Release();
  1262. BaseIPXResultHandler::DestroyResultHandler(cookie);
  1263. return hrOK;
  1264. }
  1265. /*---------------------------------------------------------------------------
  1266. This is the list of commands that will show up for the result pane
  1267. nodes.
  1268. ---------------------------------------------------------------------------*/
  1269. struct SIPInterfaceNodeMenu
  1270. {
  1271. ULONG m_sidMenu; // string/command id for this menu item
  1272. ULONG (SapInterfaceHandler:: *m_pfnGetMenuFlags)(SapInterfaceHandler::SMenuData *);
  1273. ULONG m_ulPosition;
  1274. };
  1275. /*!--------------------------------------------------------------------------
  1276. SapInterfaceHandler::AddMenuItems
  1277. Implementation of ITFSResultHandler::AddMenuItems
  1278. Author: KennT
  1279. ---------------------------------------------------------------------------*/
  1280. STDMETHODIMP SapInterfaceHandler::AddMenuItems(
  1281. ITFSComponent *pComponent,
  1282. MMC_COOKIE cookie,
  1283. LPDATAOBJECT lpDataObject,
  1284. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1285. long *pInsertionAllowed)
  1286. {
  1287. return hrOK;
  1288. }
  1289. /*!--------------------------------------------------------------------------
  1290. SapInterfaceHandler::Command
  1291. -
  1292. Author: KennT
  1293. ---------------------------------------------------------------------------*/
  1294. STDMETHODIMP SapInterfaceHandler::Command(ITFSComponent *pComponent,
  1295. MMC_COOKIE cookie,
  1296. int nCommandID,
  1297. LPDATAOBJECT pDataObject)
  1298. {
  1299. return hrOK;
  1300. }
  1301. /*!--------------------------------------------------------------------------
  1302. SapInterfaceHandler::HasPropertyPages
  1303. -
  1304. Author: KennT
  1305. ---------------------------------------------------------------------------*/
  1306. STDMETHODIMP SapInterfaceHandler::HasPropertyPages
  1307. (
  1308. ITFSNode * pNode,
  1309. LPDATAOBJECT pDataObject,
  1310. DATA_OBJECT_TYPES type,
  1311. DWORD dwType
  1312. )
  1313. {
  1314. return hrTrue;
  1315. }
  1316. /*!--------------------------------------------------------------------------
  1317. SapInterfaceHandler::CreatePropertyPages
  1318. -
  1319. Author: KennT
  1320. ---------------------------------------------------------------------------*/
  1321. STDMETHODIMP SapInterfaceHandler::CreatePropertyPages
  1322. (
  1323. ITFSNode * pNode,
  1324. LPPROPERTYSHEETCALLBACK lpProvider,
  1325. LPDATAOBJECT pDataObject,
  1326. LONG_PTR handle,
  1327. DWORD dwType
  1328. )
  1329. {
  1330. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1331. HRESULT hr = hrOK;
  1332. SapInterfaceProperties * pProperties = NULL;
  1333. SPIComponentData spComponentData;
  1334. CString stTitle;
  1335. SPIRouterInfo spRouter;
  1336. SPIRtrMgrInfo spRm;
  1337. CORg( m_spNodeMgr->GetComponentData(&spComponentData) );
  1338. // stTitle.Format(IDS_IPSUMMARY_INTERFACE_PROPPAGE_TITLE,
  1339. // m_spInterfaceInfo->GetTitle());
  1340. pProperties = new SapInterfaceProperties(pNode, spComponentData,
  1341. m_spTFSCompData, stTitle);
  1342. CORg( m_spRouterInfo->FindRtrMgr(PID_IPX, &spRm) );
  1343. CORg( pProperties->Init(m_spInterfaceInfo, spRm) );
  1344. if (lpProvider)
  1345. hr = pProperties->CreateModelessSheet(lpProvider, handle);
  1346. else
  1347. hr = pProperties->DoModelessSheet();
  1348. Error:
  1349. // Is this the right way to destroy the sheet?
  1350. if (!FHrSucceeded(hr))
  1351. delete pProperties;
  1352. return hr;
  1353. }
  1354. /*!--------------------------------------------------------------------------
  1355. SapInterfaceHandler::CreatePropertyPages
  1356. Implementation of ResultHandler::CreatePropertyPages
  1357. Author: KennT
  1358. ---------------------------------------------------------------------------*/
  1359. STDMETHODIMP SapInterfaceHandler::CreatePropertyPages
  1360. (
  1361. ITFSComponent * pComponent,
  1362. MMC_COOKIE cookie,
  1363. LPPROPERTYSHEETCALLBACK lpProvider,
  1364. LPDATAOBJECT pDataObject,
  1365. LONG_PTR handle
  1366. )
  1367. {
  1368. // Forward this call onto the NodeHandler::CreatePropertyPages
  1369. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1370. HRESULT hr = hrOK;
  1371. SPITFSNode spNode;
  1372. Assert( m_spNodeMgr );
  1373. CORg( m_spNodeMgr->FindNode(cookie, &spNode) );
  1374. // Call the ITFSNodeHandler::CreatePropertyPages
  1375. hr = CreatePropertyPages(spNode, lpProvider, pDataObject, handle, 0);
  1376. Error:
  1377. return hr;
  1378. }