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.

389 lines
9.0 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. Servpp.h
  7. Server properties implementation file
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "fltrpp.h"
  12. #include "spdutil.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. //
  20. // CFilterProperties holder
  21. //
  22. /////////////////////////////////////////////////////////////////////////////
  23. CFilterProperties::CFilterProperties
  24. (
  25. ITFSNode * pNode,
  26. IComponentData * pComponentData,
  27. ITFSComponentData * pTFSCompData,
  28. CFilterInfo * pFilterInfo,
  29. ISpdInfo * pSpdInfo,
  30. LPCTSTR pszSheetName
  31. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  32. {
  33. //ASSERT(pFolderNode == GetContainerNode());
  34. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  35. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  36. Assert(pTFSCompData != NULL);
  37. m_spTFSCompData.Set(pTFSCompData);
  38. m_spSpdInfo.Set(pSpdInfo);
  39. m_FltrInfo = *pFilterInfo;
  40. }
  41. CFilterProperties::~CFilterProperties()
  42. {
  43. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CFilterGenProp property page
  47. IMPLEMENT_DYNCREATE(CFilterGenProp, CPropertyPageBase)
  48. CFilterGenProp::CFilterGenProp() : CPropertyPageBase(CFilterGenProp::IDD)
  49. {
  50. //{{AFX_DATA_INIT(CFilterGenProp)
  51. // NOTE: the ClassWizard will add member initialization here
  52. //}}AFX_DATA_INIT
  53. }
  54. CFilterGenProp::~CFilterGenProp()
  55. {
  56. }
  57. void CFilterGenProp::DoDataExchange(CDataExchange* pDX)
  58. {
  59. CPropertyPageBase::DoDataExchange(pDX);
  60. //{{AFX_DATA_MAP(CFilterGenProp)
  61. DDX_Control(pDX, IDC_LIST_SPECIFIC, m_listSpecificFilters);
  62. //}}AFX_DATA_MAP
  63. }
  64. BEGIN_MESSAGE_MAP(CFilterGenProp, CPropertyPageBase)
  65. //{{AFX_MSG_MAP(CFilterGenProp)
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CFilterGenProp message handlers
  70. BOOL CFilterGenProp::OnInitDialog()
  71. {
  72. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  73. CPropertyPageBase::OnInitDialog();
  74. PopulateFilterInfo();
  75. LoadSpecificFilters();
  76. SetDirty(FALSE);
  77. return TRUE; // return TRUE unless you set the focus to a control
  78. // EXCEPTION: OCX Property Pages should return FALSE
  79. }
  80. void CFilterGenProp::PopulateFilterInfo()
  81. {
  82. CString st;
  83. CString stMask;
  84. CFilterProperties * pFltrProp;
  85. CFilterInfo * pFltrInfo;
  86. pFltrProp = (CFilterProperties *) GetHolder();
  87. Assert(pFltrProp);
  88. pFltrProp->GetFilterInfo(&pFltrInfo);
  89. BOOL fSrcIsName = FALSE;
  90. BOOL fHideMask = FALSE;
  91. BOOL fUseEditForAddr = FALSE;
  92. int iIDSrcAddr = IDC_FLTR_SRC_ADDR;
  93. switch (pFltrInfo->m_SrcAddr.AddrType)
  94. {
  95. case IP_ADDR_UNIQUE:
  96. if (IP_ADDRESS_ME == pFltrInfo->m_SrcAddr.uIpAddr)
  97. {
  98. st.LoadString(IDS_ADDR_ME);
  99. fHideMask = TRUE;
  100. }
  101. else
  102. {
  103. AddressToString(pFltrInfo->m_SrcAddr, &st, &fSrcIsName);
  104. if (fSrcIsName)
  105. {
  106. fUseEditForAddr = TRUE;
  107. fHideMask = TRUE;
  108. }
  109. else
  110. {
  111. stMask = c_szSingleAddressMask;
  112. IpToString(pFltrInfo->m_SrcAddr.uIpAddr, &st);
  113. }
  114. }
  115. break;
  116. case IP_ADDR_SUBNET:
  117. if (SUBNET_ADDRESS_ANY == pFltrInfo->m_SrcAddr.uSubNetMask)
  118. {
  119. st.LoadString(IDS_ADDR_ANY);
  120. fHideMask = TRUE;
  121. }
  122. else
  123. {
  124. IpToString(pFltrInfo->m_SrcAddr.uIpAddr, &st);
  125. IpToString(pFltrInfo->m_SrcAddr.uSubNetMask, &st);
  126. }
  127. break;
  128. }
  129. //Populate the SRC info to the controls now
  130. if (fHideMask)
  131. {
  132. GetDlgItem(IDC_FLTR_SRC_MASK)->ShowWindow(SW_HIDE);
  133. GetDlgItem(IDC_STATIC_SRC_MASK)->ShowWindow(SW_HIDE);
  134. }
  135. else
  136. {
  137. GetDlgItem(IDC_FLTR_SRC_MASK)->SetWindowText(stMask);
  138. }
  139. if (fUseEditForAddr)
  140. {
  141. iIDSrcAddr = IDC_FLTR_SRC_ADDR_EDIT;
  142. GetDlgItem(IDC_FLTR_SRC_ADDR)->ShowWindow(SW_HIDE);
  143. }
  144. else
  145. {
  146. iIDSrcAddr = IDC_FLTR_SRC_ADDR;
  147. GetDlgItem(IDC_FLTR_SRC_ADDR_EDIT)->ShowWindow(SW_HIDE);
  148. }
  149. GetDlgItem(iIDSrcAddr)->SetWindowText(st);
  150. //Start handling the destination now
  151. BOOL fDestDns = FALSE;
  152. int iIDDestAddr = IDC_FLTR_DEST_ADDR;
  153. fUseEditForAddr = FALSE;
  154. fHideMask = FALSE;
  155. st.Empty();
  156. stMask.Empty();
  157. switch (pFltrInfo->m_DesAddr.AddrType)
  158. {
  159. case IP_ADDR_UNIQUE:
  160. if (IP_ADDRESS_ME == pFltrInfo->m_DesAddr.uIpAddr)
  161. {
  162. st.LoadString(IDS_ADDR_ME);
  163. fHideMask = TRUE;
  164. }
  165. else
  166. {
  167. AddressToString(pFltrInfo->m_DesAddr, &st, &fDestDns);
  168. if (fDestDns)
  169. {
  170. fHideMask = TRUE;
  171. fUseEditForAddr = TRUE;
  172. }
  173. else
  174. {
  175. stMask = c_szSingleAddressMask;
  176. IpToString(pFltrInfo->m_DesAddr.uIpAddr, &st);
  177. }
  178. }
  179. break;
  180. case IP_ADDR_SUBNET:
  181. if (SUBNET_ADDRESS_ANY == pFltrInfo->m_DesAddr.uSubNetMask)
  182. {
  183. st.LoadString(IDS_ADDR_ANY);
  184. fHideMask = TRUE;
  185. }
  186. else
  187. {
  188. IpToString(pFltrInfo->m_DesAddr.uIpAddr, &st);
  189. IpToString(pFltrInfo->m_DesAddr.uSubNetMask, &stMask);
  190. }
  191. break;
  192. }
  193. if (fHideMask)
  194. {
  195. GetDlgItem(IDC_FLTR_DEST_MASK)->ShowWindow(SW_HIDE);
  196. GetDlgItem(IDC_STATIC_DEST_MASK)->ShowWindow(SW_HIDE);
  197. }
  198. else
  199. {
  200. GetDlgItem(IDC_FLTR_DEST_MASK)->SetWindowText(stMask);
  201. }
  202. if (fUseEditForAddr)
  203. {
  204. GetDlgItem(IDC_FLTR_DEST_ADDR)->ShowWindow(SW_HIDE);
  205. iIDDestAddr = IDC_FLTR_DEST_ADDR_EDIT;
  206. }
  207. else
  208. {
  209. GetDlgItem(IDC_FLTR_DEST_ADDR_EDIT)->ShowWindow(SW_HIDE);
  210. iIDDestAddr = IDC_FLTR_DEST_ADDR;
  211. }
  212. GetDlgItem(iIDDestAddr)->SetWindowText(st);
  213. //We are done with the destination now
  214. PortToString(pFltrInfo->m_SrcPort, &st);
  215. GetDlgItem(IDC_FLTR_SRC_PORT)->SetWindowText(st);
  216. PortToString(pFltrInfo->m_DesPort, &st);
  217. GetDlgItem(IDC_FLTR_DEST_PORT)->SetWindowText(st);
  218. FilterFlagToString(pFltrInfo->m_InboundFilterFlag, &st);
  219. GetDlgItem(IDC_FLTR_IN_FLAG)->SetWindowText(st);
  220. FilterFlagToString(pFltrInfo->m_OutboundFilterFlag, &st);
  221. GetDlgItem(IDC_FLTR_OUT_FLAG)->SetWindowText(st);
  222. ProtocolToString(pFltrInfo->m_Protocol, &st);
  223. GetDlgItem(IDC_FLTR_PROTOCOL)->SetWindowText(st);
  224. InterfaceTypeToString(pFltrInfo->m_InterfaceType, &st);
  225. GetDlgItem(IDC_FLTR_IF_TYPE)->SetWindowText(st);
  226. BoolToString(pFltrInfo->m_bCreateMirror, &st);
  227. GetDlgItem(IDC_FLTR_MIRROR)->SetWindowText(st);
  228. st = pFltrInfo->m_stPolicyName;
  229. GetDlgItem(IDC_FLTR_POLICY)->SetWindowText(st);
  230. }
  231. void CFilterGenProp::LoadSpecificFilters()
  232. {
  233. CFilterProperties * pFltrProp;
  234. CFilterInfo * pFltrInfo;
  235. CFilterInfoArray arraySpFilters;
  236. int nWidth;
  237. int nRows;
  238. CString st;
  239. pFltrProp = (CFilterProperties *) GetHolder();
  240. SPISpdInfo spSpdInfo;
  241. pFltrProp->GetSpdInfo(&spSpdInfo);
  242. pFltrProp->GetFilterInfo(&pFltrInfo);
  243. spSpdInfo->EnumSpecificFilters(
  244. &pFltrInfo->m_guidFltr,
  245. &arraySpFilters,
  246. pFltrInfo->m_FilterType
  247. );
  248. nWidth = m_listSpecificFilters.GetStringWidth(_T("555.555.555.555 - "));
  249. st.LoadString(IDS_FILTER_PP_COL_SRC);
  250. m_listSpecificFilters.InsertColumn(0, st, LVCFMT_LEFT, nWidth);
  251. nWidth = m_listSpecificFilters.GetStringWidth(_T("555.555.555.555 - "));
  252. st.LoadString(IDS_FILTER_PP_COL_DEST);
  253. m_listSpecificFilters.InsertColumn(1, st, LVCFMT_LEFT, nWidth);
  254. st.LoadString(IDS_FLTR_DIR_OUT);
  255. nWidth = m_listSpecificFilters.GetStringWidth((LPCTSTR)st) + 20;
  256. st.LoadString(IDS_FILTER_PP_COL_DIRECTION);
  257. m_listSpecificFilters.InsertColumn(2, st, LVCFMT_LEFT, nWidth);
  258. st.LoadString(IDS_NEG_SEC);
  259. nWidth = m_listSpecificFilters.GetStringWidth(st) + 20;
  260. st.LoadString(IDS_FILTER_PP_COL_FLAG);
  261. m_listSpecificFilters.InsertColumn(3, st, LVCFMT_LEFT, nWidth);
  262. st.LoadString(IDS_FILTER_PP_COL_WEIGHT);
  263. nWidth = m_listSpecificFilters.GetStringWidth((LPCTSTR)st) + 20;
  264. m_listSpecificFilters.InsertColumn(4, st, LVCFMT_LEFT, nWidth);
  265. nRows = 0;
  266. for (int i = 0; i < arraySpFilters.GetSize(); i++)
  267. {
  268. nRows = m_listSpecificFilters.InsertItem(nRows, _T(""));
  269. if (-1 != nRows)
  270. {
  271. AddressToString(arraySpFilters[i]->m_SrcAddr, &st);
  272. m_listSpecificFilters.SetItemText(nRows, 0, st);
  273. AddressToString(arraySpFilters[i]->m_DesAddr, &st);
  274. m_listSpecificFilters.SetItemText(nRows, 1, st);
  275. DirectionToString(arraySpFilters[i]->m_dwDirection, &st);
  276. m_listSpecificFilters.SetItemText(nRows, 2, st);
  277. FilterFlagToString((FILTER_DIRECTION_INBOUND == arraySpFilters[i]->m_dwDirection) ?
  278. arraySpFilters[i]->m_InboundFilterFlag :
  279. arraySpFilters[i]->m_OutboundFilterFlag,
  280. &st
  281. );
  282. m_listSpecificFilters.SetItemText(nRows, 3, st);
  283. st.Format(_T("%d"), arraySpFilters[i]->m_dwWeight);
  284. m_listSpecificFilters.SetItemText(nRows, 4, st);
  285. m_listSpecificFilters.SetItemData(nRows, i);
  286. }
  287. nRows++;
  288. }
  289. ::FreeItemsAndEmptyArray(arraySpFilters);
  290. }
  291. BOOL CFilterGenProp::OnApply()
  292. {
  293. if (!IsDirty())
  294. return TRUE;
  295. UpdateData();
  296. //TODO
  297. //Do nothing at this time
  298. //CPropertyPageBase::OnApply();
  299. return TRUE;
  300. }
  301. BOOL CFilterGenProp::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  302. {
  303. return FALSE;
  304. }