Source code of Windows XP (NT5)
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.

517 lines
13 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. ModeNode.cpp
  7. This file contains all of the "Main Mode" and "Quick Mode"
  8. objects that appear in the scope pane of the MMC framework.
  9. The objects are:
  10. FILE HISTORY:
  11. */
  12. #include "stdafx.h"
  13. #include "ipsmhand.h"
  14. #include "spddb.h"
  15. #include "FltrNode.h"
  16. #include "SFltNode.h"
  17. #include "ModeNode.h"
  18. #include "MmPol.h"
  19. #include "QmPol.h"
  20. #include "MmFltr.h"
  21. #include "MmSpFltr.h"
  22. #include "MmSA.h"
  23. #include "QmSA.h"
  24. /*---------------------------------------------------------------------------
  25. CQmNodeHandler::CQmNodeHandler
  26. Description
  27. Author: NSun
  28. ---------------------------------------------------------------------------*/
  29. CQmNodeHandler::CQmNodeHandler(ITFSComponentData *pCompData) :
  30. CIpsmHandler(pCompData)
  31. {
  32. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  33. }
  34. /*!--------------------------------------------------------------------------
  35. CQmNodeHandler::InitializeNode
  36. Initializes node specific data
  37. Author: NSun
  38. ---------------------------------------------------------------------------*/
  39. HRESULT
  40. CQmNodeHandler::InitializeNode
  41. (
  42. ITFSNode * pNode
  43. )
  44. {
  45. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  46. CString strTemp;
  47. strTemp.LoadString(IDS_QUICK_MODE_NODENAME);
  48. SetDisplayName(strTemp);
  49. // Make the node immediately visible
  50. pNode->SetVisibilityState(TFS_VIS_SHOW);
  51. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  52. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_FOLDER_CLOSED);
  53. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_FOLDER_OPEN);
  54. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  55. pNode->SetData(TFS_DATA_TYPE, IPSECMON_QUICK_MODE);
  56. return hrOK;
  57. }
  58. /*---------------------------------------------------------------------------
  59. Overridden base handler functions
  60. ---------------------------------------------------------------------------*/
  61. /*!--------------------------------------------------------------------------
  62. CQmNodeHandler::GetString
  63. Implementation of ITFSNodeHandler::GetString
  64. Author: KennT
  65. ---------------------------------------------------------------------------*/
  66. /*
  67. STDMETHODIMP_(LPCTSTR)
  68. CQmNodeHandler::GetString
  69. (
  70. ITFSNode * pNode,
  71. int nCol
  72. )
  73. {
  74. if (nCol == 0 || nCol == -1)
  75. return GetDisplayName();
  76. else
  77. return NULL;
  78. }
  79. */
  80. /*---------------------------------------------------------------------------
  81. CQmNodeHandler::OnExpand
  82. Handles enumeration of a scope item
  83. Author: NSun
  84. ---------------------------------------------------------------------------*/
  85. HRESULT
  86. CQmNodeHandler::OnExpand
  87. (
  88. ITFSNode * pNode,
  89. LPDATAOBJECT pDataObject,
  90. DWORD dwType,
  91. LPARAM arg,
  92. LPARAM param
  93. )
  94. {
  95. HRESULT hr = hrOK;
  96. if (m_bExpanded)
  97. return hr;
  98. // do the default handling
  99. hr = CIpsmHandler::OnExpand(pNode, pDataObject, dwType, arg, param);
  100. int iVisibleCount = 0;
  101. int iTotalCount = 0;
  102. pNode->GetChildCount(&iVisibleCount, &iTotalCount);
  103. if (0 == iTotalCount)
  104. {
  105. {
  106. // add the filters node
  107. SPITFSNode spFilterNode;
  108. CFilterHandler * pFilterHandler = new CFilterHandler(m_spTFSCompData);
  109. CreateContainerTFSNode(&spFilterNode,
  110. &GUID_IpsmFilterNodeType,
  111. pFilterHandler,
  112. pFilterHandler,
  113. m_spNodeMgr);
  114. pFilterHandler->InitData(m_spSpdInfo);
  115. pFilterHandler->InitializeNode(spFilterNode);
  116. pFilterHandler->Release();
  117. pNode->AddChild(spFilterNode);
  118. }
  119. {
  120. // add Specific filters node
  121. SPITFSNode spSpecificFilterNode;
  122. CSpecificFilterHandler * pSpecificFilterHandler = new CSpecificFilterHandler(m_spTFSCompData);
  123. CreateContainerTFSNode(&spSpecificFilterNode,
  124. &GUID_IpsmSpecificFilterNodeType,
  125. pSpecificFilterHandler,
  126. pSpecificFilterHandler,
  127. m_spNodeMgr);
  128. pSpecificFilterHandler->InitData(m_spSpdInfo);
  129. pSpecificFilterHandler->InitializeNode(spSpecificFilterNode);
  130. pSpecificFilterHandler->Release();
  131. pNode->AddChild(spSpecificFilterNode);
  132. }
  133. {
  134. // add Quick mode policy node
  135. SPITFSNode spQmPolicyNode;
  136. CQmPolicyHandler * pQmPolicyHandler = new CQmPolicyHandler(m_spTFSCompData);
  137. CreateContainerTFSNode(&spQmPolicyNode,
  138. &GUID_IpsmQmPolicyNodeType,
  139. pQmPolicyHandler,
  140. pQmPolicyHandler,
  141. m_spNodeMgr);
  142. pQmPolicyHandler->InitData(m_spSpdInfo);
  143. pQmPolicyHandler->InitializeNode(spQmPolicyNode);
  144. pQmPolicyHandler->Release();
  145. pNode->AddChild(spQmPolicyNode);
  146. }
  147. {
  148. // add the SA node
  149. SPITFSNode spSANode;
  150. CQmSAHandler *pSAHandler = new CQmSAHandler(m_spTFSCompData);
  151. CreateContainerTFSNode(&spSANode,
  152. &GUID_IpsmQmSANodeType,
  153. pSAHandler,
  154. pSAHandler,
  155. m_spNodeMgr);
  156. pSAHandler->InitData(m_spSpdInfo);
  157. pSAHandler->InitializeNode(spSANode);
  158. pSAHandler->Release();
  159. pNode->AddChild(spSANode);
  160. }
  161. }
  162. return hr;
  163. }
  164. /*---------------------------------------------------------------------------
  165. CQmNodeHandler::InitData
  166. Initializes data for this node
  167. Author: NSun
  168. ---------------------------------------------------------------------------*/
  169. HRESULT
  170. CQmNodeHandler::InitData
  171. (
  172. ISpdInfo * pSpdInfo
  173. )
  174. {
  175. m_spSpdInfo.Set(pSpdInfo);
  176. return hrOK;
  177. }
  178. HRESULT
  179. CQmNodeHandler::UpdateStatus
  180. (
  181. ITFSNode * pNode
  182. )
  183. {
  184. HRESULT hr = hrOK;
  185. Trace0("CQmNodeHandler::UpdateStatus");
  186. //We got a refresh notification from the background thread
  187. //The Mode node is just a container. Simply pass the update status
  188. //notification to the child nodes
  189. SPITFSNodeEnum spNodeEnum;
  190. SPITFSNode spCurrentNode;
  191. ULONG nNumReturned;
  192. CORg(pNode->GetEnum(&spNodeEnum));
  193. CORg(spNodeEnum->Next(1, &spCurrentNode, &nNumReturned));
  194. while (nNumReturned)
  195. {
  196. LONG_PTR dwDataType = spCurrentNode->GetData(TFS_DATA_TYPE);
  197. switch (dwDataType)
  198. {
  199. case IPSECMON_FILTER:
  200. {
  201. CFilterHandler * pFltrHandler = GETHANDLER(CFilterHandler, spCurrentNode);
  202. pFltrHandler->UpdateStatus(spCurrentNode);
  203. }
  204. break;
  205. case IPSECMON_SPECIFIC_FILTER:
  206. {
  207. CSpecificFilterHandler * pSpFilterHandler = GETHANDLER(CSpecificFilterHandler, spCurrentNode);
  208. pSpFilterHandler->UpdateStatus(spCurrentNode);
  209. }
  210. break;
  211. case IPSECMON_QM_SA:
  212. {
  213. CQmSAHandler * pSaHandler = GETHANDLER(CQmSAHandler, spCurrentNode);
  214. pSaHandler->UpdateStatus(spCurrentNode);
  215. }
  216. break;
  217. case IPSECMON_QM_POLICY:
  218. {
  219. CQmPolicyHandler * pQmPolHandler = GETHANDLER(CQmPolicyHandler, spCurrentNode);
  220. pQmPolHandler->UpdateStatus(spCurrentNode);
  221. }
  222. break;
  223. default:
  224. Trace0("CQmNodeHandler::UpdateStatus Unknow data type of the child node.");
  225. break;
  226. }
  227. spCurrentNode.Release();
  228. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  229. }
  230. COM_PROTECT_ERROR_LABEL;
  231. return hr;
  232. }
  233. /*---------------------------------------------------------------------------
  234. CMmNodeHandler::CMmNodeHandler
  235. Description
  236. Author: NSun
  237. ---------------------------------------------------------------------------*/
  238. CMmNodeHandler::CMmNodeHandler(ITFSComponentData *pCompData) :
  239. CIpsmHandler(pCompData)
  240. {
  241. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  242. }
  243. /*!--------------------------------------------------------------------------
  244. CMmNodeHandler::InitializeNode
  245. Initializes node specific data
  246. Author: NSun
  247. ---------------------------------------------------------------------------*/
  248. HRESULT
  249. CMmNodeHandler::InitializeNode
  250. (
  251. ITFSNode * pNode
  252. )
  253. {
  254. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  255. CString strTemp;
  256. strTemp.LoadString(IDS_MAIN_MODE_NODENAME);
  257. SetDisplayName(strTemp);
  258. // Make the node immediately visible
  259. pNode->SetVisibilityState(TFS_VIS_SHOW);
  260. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  261. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_FOLDER_CLOSED);
  262. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_FOLDER_OPEN);
  263. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  264. pNode->SetData(TFS_DATA_TYPE, IPSECMON_MAIN_MODE);
  265. return hrOK;
  266. }
  267. /*---------------------------------------------------------------------------
  268. Overridden base handler functions
  269. ---------------------------------------------------------------------------*/
  270. /*---------------------------------------------------------------------------
  271. CMmNodeHandler::OnExpand
  272. Handles enumeration of a scope item
  273. Author: NSun
  274. ---------------------------------------------------------------------------*/
  275. HRESULT
  276. CMmNodeHandler::OnExpand
  277. (
  278. ITFSNode * pNode,
  279. LPDATAOBJECT pDataObject,
  280. DWORD dwType,
  281. LPARAM arg,
  282. LPARAM param
  283. )
  284. {
  285. HRESULT hr = hrOK;
  286. if (m_bExpanded)
  287. return hr;
  288. // do the default handling
  289. hr = CIpsmHandler::OnExpand(pNode, pDataObject, dwType, arg, param);
  290. int iVisibleCount = 0;
  291. int iTotalCount = 0;
  292. pNode->GetChildCount(&iVisibleCount, &iTotalCount);
  293. if (0 == iTotalCount)
  294. {
  295. {
  296. // add the MM Filter node
  297. SPITFSNode spMmFltrNode;
  298. CMmFilterHandler * pMmFltrHandler = new CMmFilterHandler(m_spTFSCompData);
  299. CreateContainerTFSNode(&spMmFltrNode,
  300. &GUID_IpsmMmFilterNodeType,
  301. pMmFltrHandler,
  302. pMmFltrHandler,
  303. m_spNodeMgr);
  304. pMmFltrHandler->InitData(m_spSpdInfo);
  305. pMmFltrHandler->InitializeNode(spMmFltrNode);
  306. pMmFltrHandler->Release();
  307. pNode->AddChild(spMmFltrNode);
  308. }
  309. {
  310. // add the MM Specific Filter node
  311. SPITFSNode spMmSpFltrNode;
  312. CMmSpFilterHandler * pMmSpFltrHandler = new CMmSpFilterHandler(m_spTFSCompData);
  313. CreateContainerTFSNode(&spMmSpFltrNode,
  314. &GUID_IpsmMmSpFilterNodeType,
  315. pMmSpFltrHandler,
  316. pMmSpFltrHandler,
  317. m_spNodeMgr);
  318. pMmSpFltrHandler->InitData(m_spSpdInfo);
  319. pMmSpFltrHandler->InitializeNode(spMmSpFltrNode);
  320. pMmSpFltrHandler->Release();
  321. pNode->AddChild(spMmSpFltrNode);
  322. }
  323. {
  324. // add the MM Policy node
  325. SPITFSNode spMmPolNode;
  326. CMmPolicyHandler * pMmPolHandler = new CMmPolicyHandler(m_spTFSCompData);
  327. CreateContainerTFSNode(&spMmPolNode,
  328. &GUID_IpsmMmPolicyNodeType,
  329. pMmPolHandler,
  330. pMmPolHandler,
  331. m_spNodeMgr);
  332. pMmPolHandler->InitData(m_spSpdInfo);
  333. pMmPolHandler->InitializeNode(spMmPolNode);
  334. pMmPolHandler->Release();
  335. pNode->AddChild(spMmPolNode);
  336. }
  337. /* TODO completely remove auth node
  338. {
  339. // add the MM Auth node
  340. SPITFSNode spMmAuthNode;
  341. CMmAuthHandler * pMmAuthHandler = new CMmAuthHandler(m_spTFSCompData);
  342. CreateContainerTFSNode(&spMmAuthNode,
  343. &GUID_IpsmMmAuthNodeType,
  344. pMmAuthHandler,
  345. pMmAuthHandler,
  346. m_spNodeMgr);
  347. pMmAuthHandler->InitData(m_spSpdInfo);
  348. pMmAuthHandler->InitializeNode(spMmAuthNode);
  349. pMmAuthHandler->Release();
  350. pNode->AddChild(spMmAuthNode);
  351. }
  352. */
  353. {
  354. // add the MM SA node
  355. SPITFSNode spMmSANode;
  356. CMmSAHandler * pMmSAHandler = new CMmSAHandler(m_spTFSCompData);
  357. CreateContainerTFSNode(&spMmSANode,
  358. &GUID_IpsmMmSANodeType,
  359. pMmSAHandler,
  360. pMmSAHandler,
  361. m_spNodeMgr);
  362. pMmSAHandler->InitData(m_spSpdInfo);
  363. pMmSAHandler->InitializeNode(spMmSANode);
  364. pMmSAHandler->Release();
  365. pNode->AddChild(spMmSANode);
  366. }
  367. }
  368. return hr;
  369. }
  370. /*---------------------------------------------------------------------------
  371. CMmNodeHandler::InitData
  372. Initializes data for this node
  373. Author: NSun
  374. ---------------------------------------------------------------------------*/
  375. HRESULT
  376. CMmNodeHandler::InitData
  377. (
  378. ISpdInfo * pSpdInfo
  379. )
  380. {
  381. m_spSpdInfo.Set(pSpdInfo);
  382. return hrOK;
  383. }
  384. HRESULT
  385. CMmNodeHandler::UpdateStatus
  386. (
  387. ITFSNode * pNode
  388. )
  389. {
  390. HRESULT hr = hrOK;
  391. Trace0("CMmNodeHandler::UpdateStatus");
  392. //We got a refresh notification from the background thread
  393. //The Mode node is just a container. Simply pass the update status
  394. //notification to the child nodes
  395. SPITFSNodeEnum spNodeEnum;
  396. SPITFSNode spCurrentNode;
  397. ULONG nNumReturned;
  398. CORg(pNode->GetEnum(&spNodeEnum));
  399. CORg(spNodeEnum->Next(1, &spCurrentNode, &nNumReturned));
  400. while (nNumReturned)
  401. {
  402. LONG_PTR dwDataType = spCurrentNode->GetData(TFS_DATA_TYPE);
  403. //update child nodes here
  404. switch (dwDataType)
  405. {
  406. //update child nodes here
  407. case IPSECMON_MM_POLICY:
  408. {
  409. CMmPolicyHandler * pMmPolHandler = GETHANDLER(CMmPolicyHandler, spCurrentNode);
  410. pMmPolHandler->UpdateStatus(spCurrentNode);
  411. }
  412. break;
  413. case IPSECMON_MM_FILTER:
  414. {
  415. CMmFilterHandler * pMmFltrHandler = GETHANDLER(CMmFilterHandler, spCurrentNode);
  416. pMmFltrHandler->UpdateStatus(spCurrentNode);
  417. }
  418. break;
  419. case IPSECMON_MM_SP_FILTER:
  420. {
  421. CMmSpFilterHandler * pMmSpFltrHandler = GETHANDLER(CMmSpFilterHandler, spCurrentNode);
  422. pMmSpFltrHandler->UpdateStatus(spCurrentNode);
  423. }
  424. break;
  425. case IPSECMON_MM_SA:
  426. {
  427. CMmSAHandler * pMmSaHandler = GETHANDLER(CMmSAHandler, spCurrentNode);
  428. pMmSaHandler->UpdateStatus(spCurrentNode);
  429. }
  430. break;
  431. default:
  432. Trace0("CMmNodeHandler::UpdateStatus Unknow data type of the child node.");
  433. break;
  434. }
  435. spCurrentNode.Release();
  436. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  437. }
  438. COM_PROTECT_ERROR_LABEL;
  439. return hr;
  440. }