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.

643 lines
16 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. */
  7. #include "stdafx.h"
  8. //nclude "rtrcomp.h" // columns information
  9. #include "htmlhelp.h"
  10. #include "dmvstrm.h"
  11. #include "dmvcomp.h"
  12. #include "dmvroot.h"
  13. #include "dvsview.h"
  14. #include "statreg.h"
  15. #include "statreg.cpp"
  16. #include "atlimpl.cpp"
  17. #include "ifadmin.h"
  18. #include "dialin.h"
  19. #include "ports.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /*---------------------------------------------------------------------------
  26. Icon list
  27. This is used to initialize the image list.
  28. ---------------------------------------------------------------------------*/
  29. UINT g_uIconMap[IMAGE_IDX_MAX + 1][2] =
  30. {
  31. { IDI_FOLDER_OPEN, IMAGE_IDX_FOLDER_OPEN },
  32. { IDI_FOLDER_CLOSED , IMAGE_IDX_FOLDER_CLOSED},
  33. { IDI_MACHINE, IMAGE_IDX_MACHINE },
  34. { IDI_MACHINE_ERROR, IMAGE_IDX_MACHINE_ERROR },
  35. { IDI_MACHINE_ACCESS_DENIED, IMAGE_IDX_MACHINE_ACCESS_DENIED },
  36. { IDI_MACHINE_STARTED, IMAGE_IDX_MACHINE_STARTED },
  37. { IDI_MACHINE_STOPPED, IMAGE_IDX_MACHINE_STOPPED },
  38. { IDI_MACHINE_WAIT, IMAGE_IDX_MACHINE_WAIT },
  39. { IDI_DOMAIN, IMAGE_IDX_DOMAIN },
  40. { IDI_NET_INTERFACES, IMAGE_IDX_INTERFACES },
  41. { IDI_NET_LAN_CARD, IMAGE_IDX_LAN_CARD },
  42. { IDI_NET_WAN_CARD, IMAGE_IDX_WAN_CARD },
  43. {0, 0}
  44. };
  45. /*---------------------------------------------------------------------------
  46. CDomainComponent
  47. ---------------------------------------------------------------------------*/
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CDomainComponent implementation
  50. CDMVComponent::CDMVComponent()
  51. {
  52. extern const ContainerColumnInfo s_rgDVSViewColumnInfo[];
  53. extern const ContainerColumnInfo s_rgIfAdminColumnInfo[];
  54. extern const ContainerColumnInfo s_rgDialInColumnInfo[];
  55. extern const ContainerColumnInfo s_rgPortsColumnInfo[];
  56. m_ComponentConfig.Init(DM_COLUMNS_MAX_COUNT);
  57. m_ComponentConfig.InitViewInfo(DM_COLUMNS_DVSUM,
  58. FALSE /* configurable columns */,
  59. DVS_SI_MAX_COLUMNS,
  60. TRUE,
  61. s_rgDVSViewColumnInfo);
  62. m_ComponentConfig.InitViewInfo(DM_COLUMNS_IFADMIN,
  63. FALSE /* configurable columns */,
  64. IFADMIN_MAX_COLUMNS,
  65. TRUE,
  66. s_rgIfAdminColumnInfo);
  67. m_ComponentConfig.InitViewInfo(DM_COLUMNS_DIALIN,
  68. FALSE /* configurable columns */,
  69. DIALIN_MAX_COLUMNS,
  70. TRUE,
  71. s_rgDialInColumnInfo);
  72. m_ComponentConfig.InitViewInfo(DM_COLUMNS_PORTS,
  73. FALSE /* configurable columns */,
  74. PORTS_MAX_COLUMNS,
  75. TRUE,
  76. s_rgPortsColumnInfo);
  77. m_ulUserData = reinterpret_cast<LONG_PTR>(&m_ComponentConfig);
  78. }
  79. CDMVComponent::~CDMVComponent()
  80. {
  81. }
  82. STDMETHODIMP_(ULONG) CDMVComponent::AddRef()
  83. {
  84. return TFSComponent::AddRef();
  85. }
  86. STDMETHODIMP_(ULONG) CDMVComponent::Release()
  87. {
  88. return TFSComponent::Release();
  89. }
  90. STDMETHODIMP CDMVComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  91. {
  92. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  93. // Is the pointer bad?
  94. if (ppv == NULL)
  95. return E_INVALIDARG;
  96. // Place NULL in *ppv in case of failure
  97. *ppv = NULL;
  98. if (riid == IID_IPersistStreamInit)
  99. *ppv = static_cast<IPersistStreamInit *>(this);
  100. // If we're going to return an interface, AddRef it first
  101. if (*ppv)
  102. {
  103. ((LPUNKNOWN) *ppv)->AddRef();
  104. return hrOK;
  105. }
  106. else
  107. return TFSComponent::QueryInterface(riid, ppv);
  108. }
  109. STDMETHODIMP CDMVComponent::OnUpdateView(LPDATAOBJECT pDataObject, LPARAM arg, LPARAM param)
  110. {
  111. return TFSComponent::OnUpdateView(pDataObject, arg, param);
  112. }
  113. STDMETHODIMP CDMVComponent::InitializeBitmaps(MMC_COOKIE cookie)
  114. {
  115. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  116. ASSERT(m_spImageList != NULL);
  117. HRESULT hr = hrOK;
  118. COM_PROTECT_TRY
  119. {
  120. // Set the images
  121. HICON hIcon;
  122. for (int i = 0; i < IMAGE_IDX_MAX; i++)
  123. {
  124. hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  125. if (hIcon)
  126. {
  127. // call mmc
  128. m_spImageList->ImageListSetIcon(reinterpret_cast<LONG_PTR*>(hIcon), g_uIconMap[i][1]);
  129. }
  130. }
  131. }
  132. COM_PROTECT_CATCH;
  133. return hr;
  134. }
  135. STDMETHODIMP CDMVComponent::QueryDataObject(MMC_COOKIE cookie,
  136. DATA_OBJECT_TYPES type,
  137. LPDATAOBJECT *ppDataObject)
  138. {
  139. HRESULT hr = hrOK;
  140. SPITFSNode spNode;
  141. SPITFSResultHandler spResultHandler;
  142. COM_PROTECT_TRY
  143. {
  144. CORg( m_spNodeMgr->FindNode(cookie, &spNode) );
  145. CORg( spNode->GetResultHandler(&spResultHandler) );
  146. CORg( spResultHandler->OnCreateDataObject(this, cookie,
  147. type, ppDataObject) );
  148. COM_PROTECT_ERROR_LABEL;
  149. }
  150. COM_PROTECT_CATCH;
  151. return hr;
  152. }
  153. /*!--------------------------------------------------------------------------
  154. CDMVComponent::OnSnapinHelp
  155. -
  156. ---------------------------------------------------------------------------*/
  157. STDMETHODIMP
  158. CDMVComponent::OnSnapinHelp
  159. (
  160. LPDATAOBJECT pDataObject,
  161. LPARAM arg,
  162. LPARAM param
  163. )
  164. {
  165. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  166. SPIConsole spConsole;
  167. HWND hwndMain;
  168. HRESULT hr = hrOK;
  169. GetConsole(&spConsole);
  170. spConsole->GetMainWindow(&hwndMain);
  171. HtmlHelpA(hwndMain, "mprsnap.chm", HH_DISPLAY_TOPIC, 0);
  172. return hr;
  173. }
  174. STDMETHODIMP CDMVComponent::GetClassID(LPCLSID lpClassID)
  175. {
  176. ASSERT(lpClassID != NULL);
  177. // Copy the CLSID for this snapin
  178. *lpClassID = CLSID_RouterSnapin;
  179. return hrOK;
  180. }
  181. STDMETHODIMP CDMVComponent::IsDirty()
  182. {
  183. HRESULT hr = hrOK;
  184. COM_PROTECT_TRY
  185. {
  186. hr = m_ComponentConfig.GetDirty() ? hrOK : hrFalse;
  187. }
  188. COM_PROTECT_CATCH;
  189. return hr;
  190. }
  191. STDMETHODIMP CDMVComponent::Load(LPSTREAM pStm)
  192. {
  193. HRESULT hr = hrOK;
  194. COM_PROTECT_TRY
  195. {
  196. hr = m_ComponentConfig.LoadFrom(pStm);
  197. }
  198. COM_PROTECT_CATCH;
  199. return hr;
  200. }
  201. STDMETHODIMP CDMVComponent::Save(LPSTREAM pStm, BOOL fClearDirty)
  202. {
  203. HRESULT hr = hrOK;
  204. SPITFSResultHandler spResultHandler;
  205. COM_PROTECT_TRY
  206. {
  207. // Need to see if we can save the selected node
  208. // -------------------------------------------------------------
  209. if (m_spSelectedNode)
  210. {
  211. m_spSelectedNode->GetResultHandler(&spResultHandler);
  212. if (spResultHandler)
  213. spResultHandler->UserResultNotify(m_spSelectedNode,
  214. RRAS_ON_SAVE, (LPARAM)(ITFSComponent *) this);
  215. }
  216. hr = m_ComponentConfig.SaveTo(pStm);
  217. if (FHrSucceeded(hr) && fClearDirty)
  218. m_ComponentConfig.SetDirty(FALSE);
  219. }
  220. COM_PROTECT_CATCH;
  221. return hr;
  222. }
  223. STDMETHODIMP CDMVComponent::GetSizeMax(ULARGE_INTEGER FAR *pcbSize)
  224. {
  225. Assert(pcbSize);
  226. HRESULT hr = hrOK;
  227. ULONG cbSize = 0;
  228. COM_PROTECT_TRY
  229. {
  230. hr = m_ComponentConfig.GetSize(&cbSize);
  231. if (FHrSucceeded(hr))
  232. {
  233. pcbSize->HighPart = 0;
  234. pcbSize->LowPart = cbSize;
  235. }
  236. }
  237. COM_PROTECT_CATCH;
  238. return hr;
  239. }
  240. STDMETHODIMP CDMVComponent::InitNew()
  241. {
  242. HRESULT hr = hrOK;
  243. COM_PROTECT_TRY
  244. {
  245. hr = m_ComponentConfig.InitNew();
  246. }
  247. COM_PROTECT_CATCH;
  248. return hr;
  249. }
  250. /////////////////////////////////////////////////////////////////////////////
  251. // CDomainComponentData implementation
  252. CDMVComponentData::CDMVComponentData()
  253. {
  254. }
  255. /*!--------------------------------------------------------------------------
  256. CDomainComponentData::OnInitialize
  257. -
  258. Author: EricDav, KennT
  259. ---------------------------------------------------------------------------*/
  260. STDMETHODIMP CDMVComponentData::OnInitialize(LPIMAGELIST pScopeImage)
  261. {
  262. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  263. // Set the images
  264. HICON hIcon;
  265. Assert(pScopeImage);
  266. // add the images for the scope tree
  267. HRESULT hr = hrOK;
  268. COM_PROTECT_TRY
  269. {
  270. for (int i = 0; i < IMAGE_IDX_MAX; i++)
  271. {
  272. hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  273. if (hIcon)
  274. {
  275. // call mmc
  276. VERIFY(SUCCEEDED(pScopeImage->ImageListSetIcon(reinterpret_cast<LONG_PTR*>(hIcon), g_uIconMap[i][1])));
  277. }
  278. }
  279. }
  280. COM_PROTECT_CATCH;
  281. return hr;
  282. }
  283. /*!--------------------------------------------------------------------------
  284. CDomainComponentData::OnInitializeNodeMgr
  285. -
  286. Author: KennT
  287. ---------------------------------------------------------------------------*/
  288. STDMETHODIMP CDMVComponentData::OnInitializeNodeMgr(ITFSComponentData *pTFSCompData, ITFSNodeMgr *pNodeMgr)
  289. {
  290. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  291. // For now create a new node handler for each new node,
  292. // this is rather bogus as it can get expensive. We can
  293. // consider creating only a single node handler for each
  294. // node type.
  295. DMVRootHandler * pHandler = NULL;
  296. SPITFSNodeHandler spHandler;
  297. SPITFSNode spNode;
  298. HRESULT hr = hrOK;
  299. COM_PROTECT_TRY
  300. {
  301. pHandler = new DMVRootHandler(pTFSCompData);
  302. // Do this so that it will get released correctly
  303. spHandler = pHandler;
  304. // Create the root node for this sick puppy
  305. CORg( CreateContainerTFSNode(&spNode,
  306. &GUID_RouterDomainNodeType,
  307. pHandler,
  308. pHandler /* result handler */,
  309. pNodeMgr) );
  310. // Construct the node
  311. CORg( pHandler->ConstructNode(spNode) );
  312. CORg( pHandler->Init(spNode) );
  313. CORg( pNodeMgr->SetRootNode(spNode) );
  314. // setup watermark info
  315. /*
  316. InitWatermarkInfo(AfxGetInstanceHandle(),
  317. &m_WatermarkInfo,
  318. IDB_WIZBANNER, // Header ID
  319. IDB_WIZWATERMARK, // Watermark ID
  320. NULL, // hPalette
  321. FALSE); // bStretch
  322. pTFSCompData->SetWatermarkInfo(&m_WatermarkInfo);
  323. */
  324. // Reference the help file name.
  325. pTFSCompData->SetHTMLHelpFileName(_T("mprsnap.chm"));
  326. COM_PROTECT_ERROR_LABEL;
  327. }
  328. COM_PROTECT_CATCH;
  329. return hr;
  330. }
  331. CDMVComponentData::~CDMVComponentData()
  332. {
  333. //ResetWatermarkInfo(&m_WatermarkInfo);
  334. }
  335. /*!--------------------------------------------------------------------------
  336. CDomainComponentData::OnCreateComponent
  337. -
  338. Author: EricDav, KennT
  339. ---------------------------------------------------------------------------*/
  340. STDMETHODIMP CDMVComponentData::OnCreateComponent(LPCOMPONENT *ppComponent)
  341. {
  342. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  343. ASSERT(ppComponent != NULL);
  344. HRESULT hr = hrOK;
  345. CDMVComponent * pComp = NULL;
  346. COM_PROTECT_TRY
  347. {
  348. pComp = new CDMVComponent;
  349. if (FHrSucceeded(hr))
  350. {
  351. pComp->Construct(m_spNodeMgr,
  352. static_cast<IComponentData *>(this),
  353. m_spTFSComponentData);
  354. *ppComponent = static_cast<IComponent *>(pComp);
  355. }
  356. }
  357. COM_PROTECT_CATCH;
  358. return hr;
  359. }
  360. STDMETHODIMP CDMVComponentData::OnDestroy()
  361. {
  362. m_spNodeMgr.Release();
  363. return hrOK;
  364. }
  365. /*!--------------------------------------------------------------------------
  366. CDomainComponentData::GetCoClassID
  367. -
  368. Author: KennT
  369. ---------------------------------------------------------------------------*/
  370. STDMETHODIMP_(const CLSID *) CDMVComponentData::GetCoClassID()
  371. {
  372. return &CLSID_RouterSnapin;
  373. }
  374. /*!--------------------------------------------------------------------------
  375. CDomainComponentData::OnCreateDataObject
  376. -
  377. Author: KennT
  378. ---------------------------------------------------------------------------*/
  379. STDMETHODIMP CDMVComponentData::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  380. {
  381. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  382. Assert(ppDataObject != NULL);
  383. CDataObject * pObject = NULL;
  384. SPIDataObject spDataObject;
  385. HRESULT hr = hrOK;
  386. SPITFSNode spNode;
  387. SPITFSNodeHandler spHandler;
  388. if ( IS_SPECIAL_COOKIE(cookie) )
  389. {
  390. CDataObject * pObject = NULL;
  391. SPIDataObject spDataObject;
  392. pObject = new CDataObject;
  393. spDataObject = pObject; // do this so that it gets released correctly
  394. Assert(pObject != NULL);
  395. // Save cookie and type for delayed rendering
  396. pObject->SetType(type);
  397. pObject->SetCookie(cookie);
  398. // Store the coclass with the data object
  399. pObject->SetClsid(CLSID_RouterSnapin);
  400. pObject->SetTFSComponentData(m_spTFSComponentData);
  401. hr = pObject->QueryInterface(IID_IDataObject, reinterpret_cast<void**>(ppDataObject));
  402. }
  403. else
  404. {
  405. COM_PROTECT_TRY
  406. {
  407. CORg( m_spNodeMgr->FindNode(cookie, &spNode) );
  408. CORg( spNode->GetHandler(&spHandler) );
  409. CORg( spHandler->OnCreateDataObject(cookie, type, &spDataObject) );
  410. *ppDataObject = spDataObject.Transfer();
  411. COM_PROTECT_ERROR_LABEL;
  412. }
  413. COM_PROTECT_CATCH;
  414. }
  415. return hr;
  416. }
  417. ///////////////////////////////////////////////////////////////////////////////
  418. //// IPersistStream interface members
  419. STDMETHODIMP CDMVComponentData::GetClassID
  420. (
  421. CLSID *pClassID
  422. )
  423. {
  424. ASSERT(pClassID != NULL);
  425. // Copy the CLSID for this snapin
  426. *pClassID = CLSID_RouterSnapin;
  427. return hrOK;
  428. }
  429. STDMETHODIMP CDMVComponentData::IsDirty()
  430. {
  431. SPITFSNode spNode;
  432. SPITFSNodeHandler spHandler;
  433. SPIPersistStreamInit spStm;
  434. m_spNodeMgr->GetRootNode(&spNode);
  435. spNode->GetHandler(&spHandler);
  436. spStm.Query(spHandler);
  437. Assert(spStm);
  438. return (spNode->GetData(TFS_DATA_DIRTY) || spStm->IsDirty()) ? hrOK : hrFalse;
  439. }
  440. STDMETHODIMP CDMVComponentData::Load
  441. (
  442. IStream *pStm
  443. )
  444. {
  445. SPITFSNode spNode;
  446. SPITFSNodeHandler spHandler;
  447. SPIPersistStreamInit spStm;
  448. m_spNodeMgr->GetRootNode(&spNode);
  449. spNode->GetHandler(&spHandler);
  450. spStm.Query(spHandler);
  451. Assert(spStm);
  452. return spStm->Load(pStm);
  453. }
  454. STDMETHODIMP CDMVComponentData::Save
  455. (
  456. IStream *pStm,
  457. BOOL fClearDirty
  458. )
  459. {
  460. SPITFSNode spNode;
  461. SPITFSNodeHandler spHandler;
  462. SPIPersistStreamInit spStm;
  463. m_spNodeMgr->GetRootNode(&spNode);
  464. spNode->GetHandler(&spHandler);
  465. spStm.Query(spHandler);
  466. Assert(spStm);
  467. return spStm->Save(pStm, fClearDirty);
  468. }
  469. STDMETHODIMP CDMVComponentData::GetSizeMax
  470. (
  471. ULARGE_INTEGER *pcbSize
  472. )
  473. {
  474. SPITFSNode spNode;
  475. SPITFSNodeHandler spHandler;
  476. SPIPersistStreamInit spStm;
  477. m_spNodeMgr->GetRootNode(&spNode);
  478. spNode->GetHandler(&spHandler);
  479. spStm.Query(spHandler);
  480. Assert(spStm);
  481. return spStm->GetSizeMax(pcbSize);
  482. }
  483. STDMETHODIMP CDMVComponentData::InitNew()
  484. {
  485. SPITFSNode spNode;
  486. SPITFSNodeHandler spHandler;
  487. SPIPersistStreamInit spStm;
  488. m_spNodeMgr->GetRootNode(&spNode);
  489. spNode->GetHandler(&spHandler);
  490. spStm.Query(spHandler);
  491. Assert(spStm);
  492. return spStm->InitNew();
  493. }
  494. HRESULT CDMVComponentData::FinalConstruct()
  495. {
  496. HRESULT hr = hrOK;
  497. hr = CComponentData::FinalConstruct();
  498. if (FHrSucceeded(hr))
  499. {
  500. m_spTFSComponentData->GetNodeMgr(&m_spNodeMgr);
  501. }
  502. return hr;
  503. }
  504. void CDMVComponentData::FinalRelease()
  505. {
  506. CComponentData::FinalRelease();
  507. }