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.

788 lines
20 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2002 **/
  4. /**********************************************************************/
  5. /*
  6. edituser.h
  7. Edit user dialog implementation file
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "SrchFltr.h"
  12. #include "spdutil.h"
  13. #include "ncglobal.h" // network console global defines
  14. const DWORD c_dwOtherProtocol = 0xFFFFFFFF;
  15. const DWORD c_dwMaxProtocolID = 0xFF;
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CSearchFilters dialog
  23. CSearchFilters::CSearchFilters(ISpdInfo * pSpdInfo)
  24. : CModelessDlg()
  25. {
  26. //{{AFX_DATA_INIT(CSearchFilters)
  27. // NOTE: the ClassWizard will add member initialization here
  28. //}}AFX_DATA_INIT
  29. m_spSpdInfo.Set(pSpdInfo);
  30. }
  31. void CSearchFilters::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CBaseDialog::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CSearchFilters)
  35. DDX_Control(pDX, IDC_SRCH_LIST, m_listResult);
  36. DDX_Control(pDX, IDC_SRCH_PROTO, m_cmbProtocol);
  37. DDX_Control(pDX, IDC_SRCH_PROTO_NUMBER, m_editProtID);
  38. DDX_Control(pDX, IDC_SRCH_PROTO_SPIN, m_spinProtID);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CSearchFilters, CBaseDialog)
  42. //{{AFX_MSG_MAP(CSearchFilters)
  43. ON_BN_CLICKED(IDC_SEARCH, OnButtonSearch)
  44. ON_BN_CLICKED(IDC_SRCH_SRC_ANY, OnSrcOptionClicked)
  45. ON_BN_CLICKED(IDC_SRCH_SRC_SPEC, OnSrcOptionClicked)
  46. ON_BN_CLICKED(IDC_SRCH_DEST_ANY, OnDestOptionClicked)
  47. ON_BN_CLICKED(IDC_SRCH_DEST_SPEC, OnDestOptionClicked)
  48. ON_BN_CLICKED(IDC_SRCH_SRC_ME, OnSrcMeOptionClicked)
  49. ON_BN_CLICKED(IDC_SRCH_DST_ME, OnDstMeOptionClicked)
  50. ON_BN_CLICKED(IDC_SRCH_SRC_ANYPORT, OnSrcPortClicked)
  51. ON_BN_CLICKED(IDC_SRCH_SRC_SPPORT, OnSrcPortClicked)
  52. ON_BN_CLICKED(IDC_SRCH_DEST_ANYPORT, OnDestPortClicked)
  53. ON_BN_CLICKED(IDC_SRCH_DEST_SPPORT, OnDestPortClicked)
  54. ON_CBN_SELENDOK(IDC_SRCH_PROTO, OnSelEndOkCbprotocoltype)
  55. ON_EN_CHANGE(IDC_SRCH_PROTO_NUMBER, OnEnChangeProtocolID)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. //To manually create the IP control and disable mirroring if the parent dialog is mirrored
  59. //
  60. //Arguments:
  61. // uID [IN] the control that the new IP control should overwrite
  62. // uIDIpCtr [IN] the ID of the IP control to create
  63. //
  64. //Note: $REVIEW (nsun) this should be removed after the snapin is themed since IP controls
  65. // in comctl v6 will handle the mirroring by itself
  66. //
  67. HWND CSearchFilters::CreateIPControl(UINT uID, UINT uIDIpCtl)
  68. {
  69. HWND hwndIPControl = NULL;
  70. RECT rcClient; // client area of parent window
  71. CWnd* pWnd = GetDlgItem(uID);
  72. if (pWnd)
  73. {
  74. // get pos info from our template static and then make sure it is hidden
  75. pWnd->GetWindowRect(&rcClient);
  76. pWnd->ShowWindow (SW_HIDE);
  77. ScreenToClient (&rcClient);
  78. //$REVIEW WS_EX_NOINHERITLAYOUT is to fix the mirroring problem of IP control
  79. //See WinXP bug 261926. We should remove that we switch the comctl32 v6
  80. LONG lExStyles = 0;
  81. LONG lExStyles0 = 0;
  82. if (m_hWnd)
  83. {
  84. lExStyles0 = lExStyles = GetWindowLong(m_hWnd, GWL_EXSTYLE);
  85. if (lExStyles & WS_EX_LAYOUTRTL)
  86. {
  87. lExStyles |= WS_EX_NOINHERITLAYOUT;
  88. SetWindowLong(m_hWnd, GWL_EXSTYLE, lExStyles);
  89. }
  90. }
  91. // create the new edit control
  92. hwndIPControl = ::CreateWindowEx(WS_EX_NOINHERITLAYOUT, WC_IPADDRESS, NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
  93. rcClient.left,
  94. rcClient.top,
  95. rcClient.right - rcClient.left,
  96. rcClient.bottom - rcClient.top,
  97. GetSafeHwnd(),
  98. (HMENU) IntToPtr(uIDIpCtl),
  99. AfxGetInstanceHandle (), //g_hinst,
  100. NULL);
  101. if (lExStyles0 != lExStyles && m_hWnd)
  102. {
  103. SetWindowLong(m_hWnd, GWL_EXSTYLE, lExStyles0);
  104. }
  105. // move the control directly behind the pWnd in the Z order
  106. if (hwndIPControl)
  107. {
  108. ::SetWindowPos (hwndIPControl, pWnd->GetSafeHwnd(), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  109. }
  110. }
  111. return hwndIPControl;
  112. }
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CSearchFilters message handlers
  115. BOOL CSearchFilters::OnInitDialog()
  116. {
  117. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  118. HWND hwndIPControl = CreateIPControl(IDC_SRCH_SRC_IP_TEXT, IDC_SRCH_SRC_IP);
  119. m_ipSrc.Create(hwndIPControl);
  120. hwndIPControl = CreateIPControl(IDC_SRCH_DEST_IP_TEXT, IDC_SRCH_DEST_IP);
  121. m_ipDest.Create(hwndIPControl);
  122. m_ipSrc.SetFieldRange(0, 1, 223);
  123. m_ipDest.SetFieldRange(0, 1, 223);
  124. CBaseDialog::OnInitDialog();
  125. CString st;
  126. CheckDlgButton(IDC_SRCH_SRC_ANY, BST_CHECKED);
  127. OnSrcOptionClicked();
  128. CheckDlgButton(IDC_SRCH_DEST_ANY, BST_CHECKED);
  129. OnDestOptionClicked();
  130. AddIpAddrsToCombo();
  131. //disable the two combo boxes
  132. ((CWnd*)GetDlgItem(IDC_SRCH_SRC_ME_COMBO))->EnableWindow(FALSE);
  133. ((CWnd*)GetDlgItem(IDC_SRCH_DST_ME_COMBO))->EnableWindow(FALSE);
  134. int nIndex;
  135. for (int i = 0; i < c_nProtocols; i++)
  136. {
  137. st.LoadString(c_ProtocolStringMap[i].nStringID);
  138. nIndex = m_cmbProtocol.AddString(st);
  139. Assert(CB_ERR != nIndex);
  140. if (CB_ERR != nIndex)
  141. m_cmbProtocol.SetItemData(nIndex, c_ProtocolStringMap[i].dwProtocol);
  142. }
  143. //Add the other protocol selection
  144. st.LoadString(IDS_OTHER);
  145. nIndex = m_cmbProtocol.AddString(st);
  146. m_cmbProtocol.SetItemData(nIndex, c_dwOtherProtocol);
  147. m_cmbProtocol.SetCurSel(0);
  148. CheckDlgButton(IDC_SRCH_INBOUND, BST_CHECKED);
  149. CheckDlgButton(IDC_SRCH_OUTBOUND, BST_CHECKED);
  150. CheckDlgButton(IDC_SRCH_RADIO_BEST, BST_CHECKED);
  151. int nWidth;
  152. nWidth = m_listResult.GetStringWidth(_T("555.555.555.555 - "));
  153. st.LoadString(IDS_COL_FLTR_SRC);
  154. m_listResult.InsertColumn(0, st, LVCFMT_LEFT, nWidth);
  155. nWidth = m_listResult.GetStringWidth(_T("555.555.555.555 - "));
  156. st.LoadString(IDS_COL_FLTR_DEST);
  157. m_listResult.InsertColumn(1, st, LVCFMT_LEFT, nWidth);
  158. st.LoadString(IDS_COL_FLTR_SRC_PORT);
  159. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 15;
  160. m_listResult.InsertColumn(2, st, LVCFMT_LEFT, nWidth);
  161. st.LoadString(IDS_COL_FLTR_DEST_PORT);
  162. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 15;
  163. m_listResult.InsertColumn(3, st, LVCFMT_LEFT, nWidth);
  164. st.LoadString(IDS_COL_FLTR_PROT);
  165. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 15;
  166. m_listResult.InsertColumn(4, st, LVCFMT_LEFT, nWidth);
  167. st.LoadString(IDS_FLTR_DIR_OUT);
  168. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  169. st.LoadString(IDS_FILTER_PP_COL_DIRECTION);
  170. m_listResult.InsertColumn(5, st, LVCFMT_LEFT, nWidth);
  171. st.LoadString(IDS_FILTER_PP_COL_FLAG);
  172. nWidth = m_listResult.GetStringWidth(st) + 40;
  173. st.LoadString(IDS_FILTER_PP_COL_FLAG);
  174. m_listResult.InsertColumn(6, st, LVCFMT_LEFT, nWidth);
  175. st.LoadString(IDS_FILTER_PP_COL_WEIGHT);
  176. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  177. m_listResult.InsertColumn(7, st, LVCFMT_LEFT, nWidth);
  178. st.LoadString(IDS_FILTER_PP_COL_POLICY);
  179. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  180. m_listResult.InsertColumn(8, st, LVCFMT_LEFT, nWidth);
  181. st.Format(_T("%u"), c_dwMaxProtocolID);
  182. m_editProtID.SetLimitText(st.GetLength());
  183. m_spinProtID.SetRange(0, c_dwMaxProtocolID);
  184. EnableControls();
  185. return TRUE; // return TRUE unless you set the focus to a control
  186. // EXCEPTION: OCX Property Pages should return FALSE
  187. }
  188. void CSearchFilters::AddIpAddrsToCombo()
  189. {
  190. PMIB_IPADDRTABLE pIpTable;
  191. ULONG dwSize=0;
  192. ULONG index;
  193. DWORD dwRet;
  194. CString strIP;
  195. dwRet = GetIpAddrTable(
  196. NULL, // buffer for mapping table
  197. &dwSize, // size of buffer
  198. FALSE // sort the table
  199. );
  200. if( ERROR_INSUFFICIENT_BUFFER != dwRet && ERROR_SUCCESS != dwRet ) {
  201. return;
  202. } else {
  203. pIpTable = (PMIB_IPADDRTABLE) LocalAlloc(LMEM_ZEROINIT,dwSize);
  204. }
  205. dwRet = GetIpAddrTable(
  206. pIpTable, // buffer for mapping table
  207. &dwSize, // size of buffer
  208. FALSE // sort the table
  209. );
  210. if(ERROR_SUCCESS != dwRet) {
  211. if(pIpTable)
  212. LocalFree(pIpTable);
  213. return;
  214. }
  215. CComboBox* pComboSrc = (CComboBox*) GetDlgItem(IDC_SRCH_SRC_ME_COMBO);
  216. CComboBox* pComboDst = (CComboBox*) GetDlgItem(IDC_SRCH_DST_ME_COMBO);
  217. for(index=0; index<pIpTable->dwNumEntries; index++) {
  218. strIP.Format(_T("%d.%d.%d.%d"),GET_SOCKADDR(pIpTable->table[index].dwAddr));
  219. if(lstrcmp(strIP, _T("127.0.0.1"))) {
  220. pComboSrc->AddString(strIP);
  221. pComboDst->AddString(strIP);
  222. }
  223. }
  224. if(pIpTable)
  225. LocalFree(pIpTable);
  226. }
  227. void CSearchFilters::EnableControls()
  228. {
  229. CWnd * pWndSrcPort = NULL;
  230. CWnd * pWndDestPort = NULL;
  231. CWnd * pWnd = NULL;
  232. int nIndex;
  233. DWORD dwData;
  234. nIndex = m_cmbProtocol.GetCurSel();
  235. dwData = (DWORD)m_cmbProtocol.GetItemData(nIndex);
  236. pWnd = GetDlgItem(IDC_SRCH_PROTO_NUMBER);
  237. if (pWnd)
  238. pWnd->EnableWindow(c_dwOtherProtocol == dwData);
  239. if (c_dwOtherProtocol == dwData)
  240. {
  241. dwData = GetDlgItemInt(IDC_SRCH_PROTO_NUMBER);
  242. }
  243. else
  244. {
  245. CString st;
  246. st.Format(_T("%u"), dwData);
  247. m_editProtID.SetWindowText(st);
  248. }
  249. //Enable the port selection only when the protocol is TCP or UDP
  250. BOOL fEnable = IPSM_PROTOCOL_TCP == dwData || IPSM_PROTOCOL_UDP == dwData;
  251. pWndSrcPort = GetDlgItem(IDC_SRCH_SRC_PORT);
  252. pWndDestPort = GetDlgItem(IDC_SRCH_DEST_PORT);
  253. SafeEnableWindow(IDC_SRCH_SRC_ANYPORT, fEnable);
  254. SafeEnableWindow(IDC_SRCH_SRC_SPPORT, fEnable);
  255. SafeEnableWindow(IDC_SRCH_DEST_ANYPORT, fEnable);
  256. SafeEnableWindow(IDC_SRCH_DEST_SPPORT, fEnable);
  257. if (!fEnable)
  258. {
  259. //if port option doesn't apply to the seclect protocol, unselect all port
  260. //settings
  261. CheckDlgButton(IDC_SRCH_SRC_ANYPORT, 0);
  262. CheckDlgButton(IDC_SRCH_SRC_SPPORT, 0);
  263. CheckDlgButton(IDC_SRCH_DEST_ANYPORT, 0);
  264. CheckDlgButton(IDC_SRCH_DEST_SPPORT, 0);
  265. }
  266. else
  267. {
  268. //if neither any nor specific port is selected, select the "any ports"
  269. if (!IsDlgButtonChecked(IDC_SRCH_SRC_ANYPORT) &&
  270. !IsDlgButtonChecked(IDC_SRCH_SRC_SPPORT))
  271. {
  272. CheckDlgButton(IDC_SRCH_SRC_ANYPORT, 1);
  273. }
  274. if (!IsDlgButtonChecked(IDC_SRCH_DEST_ANYPORT) &&
  275. !IsDlgButtonChecked(IDC_SRCH_DEST_SPPORT))
  276. {
  277. CheckDlgButton(IDC_SRCH_DEST_ANYPORT, 1);
  278. }
  279. }
  280. BOOL fSpSrcPort = fEnable && IsDlgButtonChecked(IDC_SRCH_SRC_SPPORT);
  281. BOOL fSpDestPort = fEnable && IsDlgButtonChecked(IDC_SRCH_DEST_SPPORT);
  282. if (pWndSrcPort)
  283. {
  284. pWndSrcPort->EnableWindow(fSpSrcPort);
  285. if (!fSpSrcPort)
  286. pWndSrcPort->SetWindowText(_T(""));
  287. }
  288. if (pWndDestPort)
  289. {
  290. pWndDestPort->EnableWindow(fSpDestPort);
  291. if (!fSpDestPort)
  292. pWndDestPort->SetWindowText(_T(""));
  293. }
  294. }
  295. void CSearchFilters::SafeEnableWindow(int nId, BOOL fEnable)
  296. {
  297. CWnd * pWnd = GetDlgItem(nId);
  298. if (pWnd)
  299. {
  300. pWnd->EnableWindow(fEnable);
  301. }
  302. }
  303. void CSearchFilters::OnButtonSearch()
  304. {
  305. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  306. CFilterInfo fltr;
  307. CFilterInfoArray arrMatchFltrs;
  308. if (!LoadConditionInfoFromControls(&fltr))
  309. {
  310. return;
  311. }
  312. DWORD dwNum = 1000; //TODO, should change to 0 to mean search all matches
  313. if(IsDlgButtonChecked(IDC_SRCH_RADIO_BEST))
  314. {
  315. dwNum = 1;
  316. }
  317. m_spSpdInfo->GetMatchFilters(&fltr, dwNum, &arrMatchFltrs);
  318. PopulateFilterListToControl(&arrMatchFltrs);
  319. FreeItemsAndEmptyArray(arrMatchFltrs);
  320. }
  321. BOOL CSearchFilters::LoadConditionInfoFromControls(CFilterInfo * pFltr)
  322. {
  323. CString st;
  324. if (IsDlgButtonChecked(IDC_SRCH_SRC_ANY))
  325. {
  326. pFltr->m_SrcAddr.AddrType = IP_ADDR_SUBNET;
  327. pFltr->m_SrcAddr.uIpAddr = 0;
  328. pFltr->m_SrcAddr.uSubNetMask = 0;
  329. }
  330. else if (IsDlgButtonChecked(IDC_SRCH_SRC_ME))
  331. {
  332. USES_CONVERSION;
  333. pFltr->m_SrcAddr.AddrType = IP_ADDR_UNIQUE;
  334. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_SRCH_SRC_ME_COMBO);
  335. INT nSelected = pCombo->GetCurSel();
  336. if( CB_ERR != nSelected)
  337. {
  338. pCombo->GetLBText(nSelected, st);
  339. try
  340. {
  341. pFltr->m_SrcAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  342. }
  343. catch(...)
  344. {
  345. AfxMessageBox(IDS_ERR_OUTOFMEMORY);
  346. return FALSE;
  347. }
  348. pFltr->m_SrcAddr.uSubNetMask = 0xFFFFFFFF;
  349. }
  350. }
  351. else
  352. {
  353. USES_CONVERSION;
  354. pFltr->m_SrcAddr.AddrType = IP_ADDR_UNIQUE;
  355. m_ipSrc.GetAddress(st);
  356. try
  357. {
  358. pFltr->m_SrcAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  359. }
  360. catch(...)
  361. {
  362. AfxMessageBox(IDS_ERR_OUTOFMEMORY);
  363. return FALSE;
  364. }
  365. pFltr->m_SrcAddr.uSubNetMask = 0xFFFFFFFF;
  366. }
  367. if (IsDlgButtonChecked(IDC_SRCH_DEST_ANY))
  368. {
  369. pFltr->m_DesAddr.AddrType = IP_ADDR_SUBNET;
  370. pFltr->m_DesAddr.uIpAddr = 0;
  371. pFltr->m_DesAddr.uSubNetMask = 0;
  372. }
  373. else if (IsDlgButtonChecked(IDC_SRCH_DST_ME))
  374. {
  375. USES_CONVERSION;
  376. pFltr->m_DesAddr.AddrType = IP_ADDR_UNIQUE;
  377. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_SRCH_DST_ME_COMBO);
  378. INT nSelected = pCombo->GetCurSel();
  379. if( CB_ERR != nSelected)
  380. {
  381. pCombo->GetLBText(nSelected, st);
  382. try
  383. {
  384. pFltr->m_DesAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  385. }
  386. catch(...)
  387. {
  388. AfxMessageBox(IDS_ERR_OUTOFMEMORY);
  389. return FALSE;
  390. }
  391. pFltr->m_DesAddr.uSubNetMask = 0xFFFFFFFF;
  392. }
  393. }
  394. else
  395. {
  396. USES_CONVERSION;
  397. pFltr->m_DesAddr.AddrType = IP_ADDR_UNIQUE;
  398. m_ipDest.GetAddress(st);
  399. try
  400. {
  401. pFltr->m_DesAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  402. }
  403. catch(...)
  404. {
  405. AfxMessageBox(IDS_ERR_OUTOFMEMORY);
  406. return FALSE;
  407. }
  408. pFltr->m_DesAddr.uSubNetMask = 0xFFFFFFFF;
  409. }
  410. //Protocol and Port conditions
  411. int nIndex = m_cmbProtocol.GetCurSel();
  412. DWORD dwData = (DWORD)m_cmbProtocol.GetItemData(nIndex);
  413. if (c_dwOtherProtocol == dwData)
  414. {
  415. dwData = GetDlgItemInt(IDC_SRCH_PROTO_NUMBER);
  416. }
  417. if (dwData > c_dwMaxProtocolID)
  418. {
  419. st.Format(IDS_ERR_INVALID_PROTOCOLID, c_dwMaxProtocolID);
  420. ::AfxMessageBox(st);
  421. return FALSE;
  422. }
  423. pFltr->m_Protocol.ProtocolType = PROTOCOL_UNIQUE;
  424. pFltr->m_Protocol.dwProtocol = (DWORD)dwData;
  425. pFltr->m_SrcPort.PortType = PORT_UNIQUE;
  426. pFltr->m_DesPort.PortType = PORT_UNIQUE;
  427. pFltr->m_SrcPort.wPort = 0;
  428. pFltr->m_DesPort.wPort = 0;
  429. if (IPSM_PROTOCOL_TCP == dwData || IPSM_PROTOCOL_UDP == dwData)
  430. {
  431. BOOL fTrans = FALSE;
  432. if (IsDlgButtonChecked(IDC_SRCH_SRC_ANYPORT))
  433. {
  434. pFltr->m_SrcPort.wPort = 0;
  435. }
  436. else
  437. {
  438. pFltr->m_SrcPort.wPort = (WORD)GetDlgItemInt(IDC_SRCH_SRC_PORT, &fTrans, FALSE);
  439. if (!fTrans || 0 == pFltr->m_SrcPort.wPort)
  440. {
  441. ::AfxMessageBox(IDS_ERR_INVALID_SRC_PORT);
  442. return FALSE;
  443. }
  444. }
  445. if (IsDlgButtonChecked(IDC_SRCH_DEST_ANYPORT))
  446. {
  447. pFltr->m_DesPort.wPort = 0;
  448. }
  449. else
  450. {
  451. pFltr->m_DesPort.wPort = (WORD)GetDlgItemInt(IDC_SRCH_DEST_PORT, &fTrans, FALSE);
  452. if (!fTrans || 0 == pFltr->m_DesPort.wPort)
  453. {
  454. ::AfxMessageBox(IDS_ERR_INVALID_DEST_PORT);
  455. return FALSE;
  456. }
  457. }
  458. }
  459. if (IsDlgButtonChecked(IDC_SRCH_INBOUND))
  460. {
  461. //if both inbound and outbound are chosen, then
  462. //set the driection valude as 0
  463. if (IsDlgButtonChecked(IDC_SRCH_OUTBOUND))
  464. {
  465. pFltr->m_dwDirection = 0;
  466. }
  467. else
  468. {
  469. pFltr->m_dwDirection = FILTER_DIRECTION_INBOUND;
  470. }
  471. }
  472. else if (IsDlgButtonChecked(IDC_SRCH_OUTBOUND))
  473. {
  474. pFltr->m_dwDirection = FILTER_DIRECTION_OUTBOUND;
  475. }
  476. else
  477. {
  478. ::AfxMessageBox(IDS_ERR_NO_DIRECTION);
  479. return FALSE;
  480. }
  481. return TRUE;
  482. }
  483. void CSearchFilters::PopulateFilterListToControl(CFilterInfoArray * parrFltrs)
  484. {
  485. CString st;
  486. m_listResult.DeleteAllItems();
  487. int nRows = -1;
  488. int nCol = 0;
  489. for (int i = 0; i < parrFltrs->GetSize(); i++)
  490. {
  491. nRows++;
  492. nRows = m_listResult.InsertItem(nRows, _T(""));
  493. if (-1 != nRows)
  494. {
  495. AddressToString((*parrFltrs)[i]->m_SrcAddr, &st);
  496. m_listResult.SetItemText(nRows, 0, st);
  497. AddressToString((*parrFltrs)[i]->m_DesAddr, &st);
  498. m_listResult.SetItemText(nRows, 1, st);
  499. PortToString((*parrFltrs)[i]->m_SrcPort, &st);
  500. m_listResult.SetItemText(nRows, 2, st);
  501. PortToString((*parrFltrs)[i]->m_DesPort, &st);
  502. m_listResult.SetItemText(nRows, 3, st);
  503. ProtocolToString((*parrFltrs)[i]->m_Protocol, &st);
  504. m_listResult.SetItemText(nRows, 4, st);
  505. DirectionToString((*parrFltrs)[i]->m_dwDirection, &st);
  506. m_listResult.SetItemText(nRows, 5, st);
  507. FilterFlagToString((FILTER_DIRECTION_INBOUND == (*parrFltrs)[i]->m_dwDirection) ?
  508. (*parrFltrs)[i]->m_InboundFilterAction :
  509. (*parrFltrs)[i]->m_OutboundFilterAction,
  510. &st
  511. );
  512. m_listResult.SetItemText(nRows, 6, st);
  513. st.Format(_T("%d"), (*parrFltrs)[i]->m_dwWeight);
  514. m_listResult.SetItemText(nRows, 7, st);
  515. st = (*parrFltrs)[i]->m_stPolicyName;
  516. m_listResult.SetItemText(nRows, 8, st);
  517. m_listResult.SetItemData(nRows, i);
  518. }
  519. }
  520. if ( 0 == parrFltrs->GetSize() )
  521. {
  522. AfxMessageBox(IDS_ERROR_NOMATCH_FILTER);
  523. }
  524. }
  525. void CSearchFilters::OnSrcOptionClicked()
  526. {
  527. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  528. BOOL fAny = IsDlgButtonChecked(IDC_SRCH_SRC_ANY);
  529. if (fAny)
  530. {
  531. m_ipSrc.ClearAddress();
  532. }
  533. if (m_ipSrc.m_hIPaddr)
  534. {
  535. ::EnableWindow(m_ipSrc.m_hIPaddr, !fAny);
  536. }
  537. ((CWnd*)GetDlgItem(IDC_SRCH_SRC_ME_COMBO))->EnableWindow(FALSE);
  538. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_SRCH_SRC_ME_COMBO);
  539. pCombo->SetCurSel(-1);
  540. }
  541. void CSearchFilters::OnDestOptionClicked()
  542. {
  543. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  544. BOOL fAny = IsDlgButtonChecked(IDC_SRCH_DEST_ANY);
  545. if (fAny)
  546. {
  547. m_ipDest.ClearAddress();
  548. }
  549. if (m_ipDest.m_hIPaddr)
  550. {
  551. ::EnableWindow(m_ipDest.m_hIPaddr, !fAny);
  552. }
  553. ((CWnd*)GetDlgItem(IDC_SRCH_DST_ME_COMBO))->EnableWindow(FALSE);
  554. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_SRCH_DST_ME_COMBO);
  555. pCombo->SetCurSel(-1);
  556. }
  557. void CSearchFilters::OnSrcMeOptionClicked()
  558. {
  559. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  560. ((CWnd*)GetDlgItem(IDC_SRCH_SRC_ME_COMBO))->EnableWindow(TRUE);
  561. ::EnableWindow(m_ipSrc.m_hIPaddr, FALSE);
  562. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_SRCH_SRC_ME_COMBO);
  563. int nCount = pCombo->GetCount();
  564. if (nCount > 0) {
  565. pCombo->SetCurSel(0);
  566. }
  567. }
  568. void CSearchFilters::OnDstMeOptionClicked()
  569. {
  570. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  571. ((CWnd*)GetDlgItem(IDC_SRCH_DST_ME_COMBO))->EnableWindow(TRUE);
  572. ::EnableWindow(m_ipDest.m_hIPaddr, FALSE);
  573. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_SRCH_DST_ME_COMBO);
  574. int nCount = pCombo->GetCount();
  575. if (nCount > 0) {
  576. pCombo->SetCurSel(0);
  577. }
  578. }
  579. void CSearchFilters::OnSrcPortClicked()
  580. {
  581. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  582. BOOL fSpecifc = IsDlgButtonChecked(IDC_SRCH_SRC_SPPORT);
  583. SafeEnableWindow(IDC_SRCH_SRC_PORT, fSpecifc);
  584. if (!fSpecifc)
  585. {
  586. CWnd * pWnd = GetDlgItem(IDC_SRCH_SRC_PORT);
  587. if (pWnd)
  588. pWnd->SetWindowText(_T(""));
  589. }
  590. }
  591. void CSearchFilters::OnDestPortClicked()
  592. {
  593. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  594. BOOL fSpecifc = IsDlgButtonChecked(IDC_SRCH_DEST_SPPORT);
  595. SafeEnableWindow(IDC_SRCH_DEST_PORT, fSpecifc);
  596. if (!fSpecifc)
  597. {
  598. CWnd * pWnd = GetDlgItem(IDC_SRCH_DEST_PORT);
  599. if (pWnd)
  600. pWnd->SetWindowText(_T(""));
  601. }
  602. }
  603. void CSearchFilters::OnOK()
  604. {
  605. }
  606. void CSearchFilters::OnCancel()
  607. {
  608. DestroyWindow();
  609. // Explicitly kill this thread.
  610. AfxPostQuitMessage(0);
  611. }
  612. void CSearchFilters::OnSelEndOkCbprotocoltype()
  613. {
  614. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  615. EnableControls();
  616. }
  617. void CSearchFilters::OnEnChangeProtocolID()
  618. {
  619. CWnd * pWnd = NULL;
  620. pWnd = GetDlgItem(IDC_SRCH_PROTO_NUMBER);
  621. //only update control state when the edit box is enabled
  622. //otherwise, there will be a infinite recursive call to OnEnChangeProtocolID()
  623. //because EnableControls will update the text of the edit box if the protocol
  624. //is not "Other" (at that time, the edit box is disabled
  625. if (pWnd && pWnd->IsWindowEnabled())
  626. {
  627. EnableControls();
  628. }
  629. }