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.

352 lines
10 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. root.cpp
  7. Root node information (the root node is not displayed
  8. in the MMC framework but contains information such as
  9. all of the subnodes in this snapin).
  10. FILE HISTORY:
  11. */
  12. #include "stdafx.h"
  13. #include "util.h"
  14. #include "saproot.h"
  15. #include "reg.h"
  16. #include "sapview.h" // SAP handlers
  17. #include "sapstats.h"
  18. #include "routprot.h" // IP_BOOTP
  19. /*---------------------------------------------------------------------------
  20. SapRootHandler implementation
  21. ---------------------------------------------------------------------------*/
  22. DEBUG_DECLARE_INSTANCE_COUNTER(SapRootHandler)
  23. extern const ContainerColumnInfo s_rgSAPParamsStatsColumnInfo[];
  24. struct _ViewInfoColumnEntry
  25. {
  26. UINT m_ulId;
  27. UINT m_cColumns;
  28. const ContainerColumnInfo *m_prgColumn;
  29. };
  30. static const struct _ViewInfoColumnEntry s_rgViewColumnInfo[] =
  31. {
  32. { SAPSTRM_STATS_SAPPARAMS, MVR_SAPPARAMS_COUNT, s_rgSAPParamsStatsColumnInfo },
  33. };
  34. SapRootHandler::SapRootHandler(ITFSComponentData *pCompData)
  35. : RootHandler(pCompData)
  36. {
  37. DEBUG_INCREMENT_INSTANCE_COUNTER(SapRootHandler)
  38. m_ConfigStream.Init(DimensionOf(s_rgViewColumnInfo));
  39. // This will initialize the view information for the statistics
  40. // dialogs. (which is why the fConfigurableColumns is set to TRUE).
  41. for (int i=0; i<DimensionOf(s_rgViewColumnInfo); i++)
  42. {
  43. m_ConfigStream.InitViewInfo(s_rgViewColumnInfo[i].m_ulId,
  44. TRUE /*fConfigurableColumns*/,
  45. s_rgViewColumnInfo[i].m_cColumns,
  46. TRUE,
  47. s_rgViewColumnInfo[i].m_prgColumn);
  48. }
  49. }
  50. STDMETHODIMP SapRootHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  51. {
  52. // Is the pointer bad?
  53. if (ppv == NULL)
  54. return E_INVALIDARG;
  55. // Place NULL in *ppv in case of failure
  56. *ppv = NULL;
  57. // This is the non-delegating IUnknown implementation
  58. if (riid == IID_IUnknown)
  59. *ppv = (LPVOID) this;
  60. else if (riid == IID_IRtrAdviseSink)
  61. *ppv = &m_IRtrAdviseSink;
  62. else
  63. return RootHandler::QueryInterface(riid, ppv);
  64. // If we're going to return an interface, AddRef it first
  65. if (*ppv)
  66. {
  67. ((LPUNKNOWN) *ppv)->AddRef();
  68. return hrOK;
  69. }
  70. else
  71. return E_NOINTERFACE;
  72. }
  73. ///////////////////////////////////////////////////////////////////////////////
  74. //// IPersistStream interface members
  75. STDMETHODIMP SapRootHandler::GetClassID
  76. (
  77. CLSID *pClassID
  78. )
  79. {
  80. ASSERT(pClassID != NULL);
  81. // Copy the CLSID for this snapin
  82. *pClassID = CLSID_IPXSapExtension;
  83. return hrOK;
  84. }
  85. /*!--------------------------------------------------------------------------
  86. SapRootHandler::OnExpand
  87. -
  88. Author: KennT
  89. ---------------------------------------------------------------------------*/
  90. HRESULT SapRootHandler::OnExpand(ITFSNode *pNode,
  91. LPDATAOBJECT pDataObject,
  92. DWORD dwType,
  93. LPARAM arg,
  94. LPARAM lParam)
  95. {
  96. HRESULT hr = hrOK;
  97. SPITFSNode spNode;
  98. SPIRtrMgrProtocolInfo spRmProt;
  99. SPIRtrMgrInfo spRm;
  100. SPIRouterInfo spRouterInfo;
  101. LONG_PTR ulConnId;
  102. // Grab the router info from the dataobject
  103. spRm.Query(pDataObject);
  104. Assert(spRm);
  105. spRm->GetParentRouterInfo(&spRouterInfo);
  106. // Setup the advise on the RtrMgr (to see when BootP is added/removed)
  107. spRm->RtrAdvise(&m_IRtrAdviseSink, &ulConnId, 0);
  108. // add things to our map for later
  109. AddRtrObj(ulConnId, IID_IRtrMgrInfo, spRm);
  110. AddScopeItem(spRm->GetMachineName(), (HSCOPEITEM) lParam);
  111. hr = spRm->FindRtrMgrProtocol(IPX_PROTOCOL_SAP, &spRmProt);
  112. if (!FHrOK(hr))
  113. {
  114. // Treat this as an already expanded node, we depend on
  115. // the notification mechanism to let us know if something
  116. // changes
  117. goto Error;
  118. }
  119. CORg( AddProtocolNode(pNode, spRouterInfo) );
  120. SetProtocolAdded(ulConnId, TRUE);
  121. Error:
  122. return hr;
  123. }
  124. /*!--------------------------------------------------------------------------
  125. SapRootHandler::OnCreateDataObject
  126. Implementation of ITFSNodeHandler::OnCreateDataObject
  127. Author: KennT
  128. ---------------------------------------------------------------------------*/
  129. STDMETHODIMP SapRootHandler::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  130. {
  131. HRESULT hr = hrOK;
  132. SPIRouterInfo spRouterInfo;
  133. COM_PROTECT_TRY
  134. {
  135. // this will always be null
  136. if (spRouterInfo == NULL)
  137. {
  138. // If we haven't created the sub nodes yet, we still have to
  139. // create a dataobject.
  140. CDataObject * pObject = NULL;
  141. SPIDataObject spDataObject;
  142. SPITFSNode spNode;
  143. SPITFSNodeHandler spHandler;
  144. pObject = new CDataObject;
  145. spDataObject = pObject; // do this so that it gets released correctly
  146. Assert(pObject != NULL);
  147. // Save cookie and type for delayed rendering
  148. pObject->SetType(type);
  149. pObject->SetCookie(cookie);
  150. // Store the coclass with the data object
  151. pObject->SetClsid(*(m_spTFSCompData->GetCoClassID()));
  152. pObject->SetTFSComponentData(m_spTFSCompData);
  153. hr = pObject->QueryInterface(IID_IDataObject,
  154. reinterpret_cast<void**>(ppDataObject));
  155. }
  156. else
  157. hr = CreateDataObjectFromRouterInfo(spRouterInfo,
  158. type, cookie, m_spTFSCompData,
  159. ppDataObject);
  160. }
  161. COM_PROTECT_CATCH;
  162. return hr;
  163. }
  164. ImplementEmbeddedUnknown(SapRootHandler, IRtrAdviseSink)
  165. STDMETHODIMP SapRootHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  166. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  167. {
  168. InitPThis(SapRootHandler, IRtrAdviseSink);
  169. HRESULT hr = hrOK;
  170. SPITFSNode spNode;
  171. SPIRtrMgrInfo spRm;
  172. SPIRouterInfo spRouterInfo;
  173. if (dwObjectType != ROUTER_OBJ_RmProt)
  174. return hr;
  175. COM_PROTECT_TRY
  176. {
  177. CORg (pThis->GetRtrObj(ulConn, (IUnknown **) &spRm));
  178. if (dwChangeType == ROUTER_CHILD_ADD)
  179. {
  180. // check to see if BootP is in the current list
  181. if (spRm->FindRtrMgrProtocol(IPX_PROTOCOL_SAP, NULL) == hrOK)
  182. {
  183. // We found Bootp, add our child node if we
  184. // don't have a child node
  185. if (!pThis->IsProtocolAdded(ulConn))
  186. {
  187. spRm->GetParentRouterInfo(&spRouterInfo);
  188. pThis->m_spNodeMgr->GetRootNode(&spNode);
  189. pThis->AddProtocolNode(spNode, spRouterInfo);
  190. pThis->SetProtocolAdded(ulConn, TRUE);
  191. }
  192. }
  193. }
  194. else if (dwChangeType == ROUTER_CHILD_DELETE)
  195. {
  196. if (spRm->FindRtrMgrProtocol(IPX_PROTOCOL_SAP, NULL) == hrFalse)
  197. {
  198. // couldn't find Bootp, delete all of our child nodes
  199. pThis->m_spNodeMgr->GetRootNode(&spNode);
  200. pThis->RemoveNode(spNode, spRm->GetMachineName());
  201. pThis->SetProtocolAdded(ulConn, FALSE);
  202. }
  203. }
  204. COM_PROTECT_ERROR_LABEL;
  205. }
  206. COM_PROTECT_CATCH;
  207. return hr;
  208. }
  209. /*!--------------------------------------------------------------------------
  210. SapRootHandler::DestroyHandler
  211. -
  212. Author: KennT
  213. ---------------------------------------------------------------------------*/
  214. STDMETHODIMP SapRootHandler::DestroyHandler(ITFSNode *pNode)
  215. {
  216. RemoveAllNodes(pNode);
  217. RemoveAllRtrObj();
  218. return hrOK;
  219. }
  220. /*!--------------------------------------------------------------------------
  221. SapRootHandler::AddProtocolNode
  222. -
  223. Author: KennT
  224. ---------------------------------------------------------------------------*/
  225. HRESULT SapRootHandler::AddProtocolNode(ITFSNode *pNode, IRouterInfo * pRouterInfo)
  226. {
  227. SPITFSNodeHandler spHandler;
  228. SapNodeHandler * pHandler = NULL;
  229. HRESULT hr = hrOK;
  230. SPITFSNode spNode;
  231. HSCOPEITEM hScopeItem, hOldScopeItem;
  232. // Windows NT Bug : 246822
  233. // Due to the server list programming model, we need to setup
  234. // the proper scopeitem (so that MMC adds this to the proper
  235. // node).
  236. // Get the proper scope item for this node.
  237. // ----------------------------------------------------------------
  238. Verify( GetScopeItem(pRouterInfo->GetMachineName(), &hScopeItem) == hrOK);
  239. // Get the old one and save it. place the new one in the node.
  240. // ----------------------------------------------------------------
  241. hOldScopeItem = pNode->GetData(TFS_DATA_SCOPEID);
  242. pNode->SetData(TFS_DATA_SCOPEID, hScopeItem);
  243. pHandler = new SapNodeHandler(m_spTFSCompData);
  244. spHandler = pHandler;
  245. CORg( pHandler->Init(pRouterInfo, &m_ConfigStream) );
  246. CreateContainerTFSNode(&spNode,
  247. &GUID_IPXSapNodeType,
  248. static_cast<ITFSNodeHandler *>(pHandler),
  249. static_cast<ITFSResultHandler *>(pHandler),
  250. m_spNodeMgr);
  251. // Call to the node handler to init the node data
  252. pHandler->ConstructNode(spNode);
  253. // Make the node immediately visible
  254. spNode->SetVisibilityState(TFS_VIS_SHOW);
  255. pNode->AddChild(spNode);
  256. Error:
  257. // Restore the scope item
  258. pNode->SetData(TFS_DATA_SCOPEID, hOldScopeItem);
  259. return hr;
  260. }
  261. /*!--------------------------------------------------------------------------
  262. SapRootHandler::CompareNodeToMachineName
  263. This function is used by the RemoveNode() function.
  264. Returns hrOK if this node is a DHCP relay node and corresponds
  265. to the pszMachineName.
  266. Returns hrFalse if this is not the indicated node.
  267. Returns errors otherwise.
  268. Author: KennT
  269. ---------------------------------------------------------------------------*/
  270. HRESULT SapRootHandler::CompareNodeToMachineName(ITFSNode *pNode,
  271. LPCTSTR pszMachineName)
  272. {
  273. HRESULT hr = hrFalse;
  274. // Should check that this is a SAP node
  275. if (*(pNode->GetNodeType()) != GUID_IPXSapNodeType)
  276. hr = hrFalse;
  277. else
  278. {
  279. IPXConnection * pIPXConn;
  280. pIPXConn = GET_SAP_NODEDATA(pNode);
  281. if (StriCmp(pszMachineName, pIPXConn->GetMachineName()) == 0)
  282. hr = hrOK;
  283. }
  284. return hr;
  285. }