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.

452 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: rtfltdlg.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // RtFltDlg.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "ipxadmin.h"
  14. #include "ipxutil.h"
  15. #include "listctrl.h"
  16. #include "RtFltDlg.h"
  17. extern "C"
  18. {
  19. #include "routprot.h"
  20. };
  21. //nclude "rtradmin.hm"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CRouteFltDlg dialog
  29. CRouteFltDlg::CRouteFltDlg(BOOL bOutputDlg, IInfoBase *pInfoBase,
  30. CWnd* pParent /*=NULL*/)
  31. : CBaseDialog( (bOutputDlg ? CRouteFltDlg::IDD_OUTPUT : CRouteFltDlg::IDD_INPUT), pParent),
  32. m_bOutput(bOutputDlg)
  33. {
  34. //{{AFX_DATA_INIT(CRouteFltDlg)
  35. m_fActionDeny = FALSE;
  36. //}}AFX_DATA_INIT
  37. m_spInfoBase.Set(pInfoBase);
  38. // SetHelpMap(m_dwHelpMap);
  39. }
  40. void CRouteFltDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CBaseDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CRouteFltDlg)
  44. DDX_Control(pDX, IDC_RFS_LIST, m_FilterList);
  45. DDX_Radio(pDX, IDC_RFS_BTN_DENY, m_fActionDeny);
  46. //}}AFX_DATA_MAP
  47. if (pDX->m_bSaveAndValidate)
  48. {
  49. PRIP_ROUTE_FILTER_INFO pFltInfo;
  50. UINT count;
  51. UINT i;
  52. DWORD dwSize;
  53. PRIP_IF_CONFIG pRipIfCfg = NULL;
  54. // Grab the RIP_IF_CONFIG
  55. m_spInfoBase->GetData(IPX_PROTOCOL_RIP, 0, (PBYTE *) &pRipIfCfg);
  56. Assert(pRipIfCfg);
  57. count = m_FilterList.GetItemCount ();
  58. if (m_bOutput)
  59. {
  60. if (count != pRipIfCfg->RipIfFilters.SupplyFilterCount)
  61. {
  62. dwSize = FIELD_OFFSET (
  63. RIP_IF_CONFIG,
  64. RipIfFilters.RouteFilter[count
  65. +pRipIfCfg->RipIfFilters.ListenFilterCount]);
  66. PRIP_IF_CONFIG pNewConfig =
  67. (PRIP_IF_CONFIG) new BYTE[dwSize];
  68. if (pNewConfig==NULL)
  69. AfxThrowMemoryException();
  70. memcpy (pNewConfig, pRipIfCfg,
  71. FIELD_OFFSET (RIP_IF_CONFIG, RipIfFilters.RouteFilter));
  72. memcpy (&pNewConfig->RipIfFilters.RouteFilter[count],
  73. &pRipIfCfg->RipIfFilters.RouteFilter[
  74. pRipIfCfg->RipIfFilters.SupplyFilterCount],
  75. sizeof (RIP_ROUTE_FILTER_INFO)
  76. *pRipIfCfg->RipIfFilters.ListenFilterCount);
  77. pNewConfig->RipIfFilters.SupplyFilterCount = count;
  78. m_spInfoBase->SetData(IPX_PROTOCOL_RIP,
  79. dwSize,
  80. (BYTE *) pNewConfig,
  81. 1,
  82. 0
  83. );
  84. pRipIfCfg = pNewConfig;
  85. }
  86. pRipIfCfg->RipIfFilters.SupplyFilterAction = m_fActionDeny ?
  87. IPX_ROUTE_FILTER_DENY : IPX_ROUTE_FILTER_PERMIT;
  88. pFltInfo = &pRipIfCfg->RipIfFilters.RouteFilter[0];
  89. }
  90. else
  91. {
  92. if (count != pRipIfCfg->RipIfFilters.ListenFilterCount)
  93. {
  94. dwSize = FIELD_OFFSET (
  95. RIP_IF_CONFIG,
  96. RipIfFilters.RouteFilter[
  97. count
  98. +pRipIfCfg->RipIfFilters.SupplyFilterCount]);
  99. PRIP_IF_CONFIG pNewConfig =
  100. (PRIP_IF_CONFIG) new BYTE[dwSize];
  101. if (pNewConfig==NULL)
  102. AfxThrowMemoryException();
  103. memcpy (pNewConfig, pRipIfCfg,
  104. FIELD_OFFSET (RIP_IF_CONFIG, RipIfFilters.RouteFilter));
  105. memcpy (&pNewConfig->RipIfFilters.RouteFilter[0],
  106. &pRipIfCfg->RipIfFilters.RouteFilter[0],
  107. sizeof (RIP_ROUTE_FILTER_INFO)
  108. *pRipIfCfg->RipIfFilters.SupplyFilterCount);
  109. pNewConfig->RipIfFilters.ListenFilterCount = count;
  110. m_spInfoBase->SetData(IPX_PROTOCOL_RIP,
  111. dwSize,
  112. (BYTE *) pNewConfig,
  113. 1,
  114. 0
  115. );
  116. pRipIfCfg = pNewConfig;
  117. }
  118. pRipIfCfg->RipIfFilters.ListenFilterAction = m_fActionDeny ?
  119. IPX_ROUTE_FILTER_DENY : IPX_ROUTE_FILTER_PERMIT;
  120. pFltInfo = &pRipIfCfg->RipIfFilters.RouteFilter[
  121. pRipIfCfg->RipIfFilters.SupplyFilterCount];
  122. }
  123. for (i=0; i<count; i++) {
  124. CString aStr;
  125. aStr = m_FilterList.GetItemText (i, 0);
  126. ConvertNetworkNumberToBytes(aStr,
  127. pFltInfo[i].Network,
  128. sizeof(pFltInfo[i].Network));
  129. aStr = m_FilterList.GetItemText (i, 1);
  130. ConvertNetworkNumberToBytes(aStr,
  131. pFltInfo[i].Mask,
  132. sizeof(pFltInfo[i].Mask));
  133. }
  134. }
  135. }
  136. BEGIN_MESSAGE_MAP(CRouteFltDlg, CBaseDialog)
  137. //{{AFX_MSG_MAP(CRouteFltDlg)
  138. ON_BN_CLICKED(IDC_RFS_BTN_ADD, OnAdd)
  139. ON_BN_CLICKED(IDC_RFS_BTN_DELETE, OnDelete)
  140. ON_BN_CLICKED(IDC_RFS_BTN_EDIT, OnEdit)
  141. ON_NOTIFY(LVN_ITEMCHANGED, IDC_RFS_LIST, OnItemchangedFilterList)
  142. ON_NOTIFY(NM_DBLCLK, IDC_RFS_LIST, OnListDblClk)
  143. //}}AFX_MSG_MAP
  144. END_MESSAGE_MAP()
  145. DWORD CRouteFltDlg::m_dwHelpMap[] =
  146. {
  147. // IDC_DENY, HIDC_DENY,
  148. // IDC_PERMIT, HIDC_PERMIT,
  149. // IDC_FILTER_LIST, HIDC_FILTER_LIST,
  150. // IDC_ADD, HIDC_ADD,
  151. // IDC_EDIT, HIDC_EDIT,
  152. // IDC_DELETE, HIDC_DELETE,
  153. 0,0
  154. };
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CRouteFltDlg message handlers
  157. BOOL CRouteFltDlg::OnInitDialog()
  158. {
  159. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  160. CString aStr;
  161. PRIP_IF_CONFIG pRipIfCfg = NULL;
  162. CBaseDialog::OnInitDialog();
  163. if (m_bOutput)
  164. aStr.FormatMessage (IDS_ROUTEFILTER_OUTPUT_CAP, (LPCTSTR)m_sIfName);
  165. else
  166. aStr.FormatMessage (IDS_ROUTEFILTER_INPUT_CAP, (LPCTSTR)m_sIfName);
  167. SetWindowText (aStr);
  168. // Get the current window style.
  169. DWORD dwStyle = GetWindowLong(m_FilterList.m_hWnd, GWL_STYLE);
  170. // Only set the window style if the view bits have changed.
  171. if ((dwStyle & LVS_TYPEMASK) != LVS_REPORT)
  172. SetWindowLong(m_FilterList.m_hWnd, GWL_STYLE,
  173. (dwStyle & ~LVS_TYPEMASK) | LVS_REPORT);
  174. ListView_SetExtendedListViewStyle(m_FilterList.m_hWnd,
  175. LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP);
  176. VERIFY (aStr.LoadString (IDS_ROUTEFILTER_NETWORK_HDR));
  177. VERIFY (m_FilterList.InsertColumn (0, aStr)!=-1);
  178. AdjustColumnWidth (m_FilterList, 0, aStr);
  179. VERIFY (aStr.LoadString (IDS_ROUTEFILTER_NETMASK_HDR));
  180. VERIFY (m_FilterList.InsertColumn (1, aStr)!=-1);
  181. AdjustColumnWidth (m_FilterList, 1, aStr);
  182. PRIP_ROUTE_FILTER_INFO pFltInfo;
  183. UINT count;
  184. UINT i, item;
  185. // Grab the RIP_IF_CONFIG
  186. m_spInfoBase->GetData(IPX_PROTOCOL_RIP, 0, (PBYTE *) &pRipIfCfg);
  187. Assert(pRipIfCfg);
  188. if (m_bOutput)
  189. {
  190. pFltInfo = &pRipIfCfg->RipIfFilters.RouteFilter[0];
  191. count = pRipIfCfg->RipIfFilters.SupplyFilterCount;
  192. if (count>0)
  193. m_fActionDeny = (pRipIfCfg->RipIfFilters.SupplyFilterAction == IPX_ROUTE_FILTER_DENY);
  194. }
  195. else
  196. {
  197. pFltInfo = &pRipIfCfg->RipIfFilters.RouteFilter[
  198. pRipIfCfg->RipIfFilters.SupplyFilterCount];
  199. count = pRipIfCfg->RipIfFilters.ListenFilterCount;
  200. if (count>0)
  201. m_fActionDeny = (pRipIfCfg->RipIfFilters.ListenFilterAction == IPX_ROUTE_FILTER_DENY);
  202. }
  203. for (i=0; i<count; i++) {
  204. TCHAR szBuffer[32];
  205. FormatIpxNetworkNumber(szBuffer, DimensionOf(szBuffer),
  206. pFltInfo[i].Network, sizeof(pFltInfo[i].Network));
  207. VERIFY ((item=m_FilterList.InsertItem (LVIF_TEXT|LVIF_PARAM,
  208. i, szBuffer,
  209. 0, 0, 0,
  210. (LPARAM)i))!=-1);
  211. FormatIpxNetworkNumber(szBuffer, DimensionOf(szBuffer),
  212. pFltInfo[i].Mask, sizeof(pFltInfo[i].Mask));
  213. VERIFY (m_FilterList.SetItemText (item, 1, szBuffer));
  214. }
  215. OnItemchangedFilterList(NULL, NULL);
  216. UpdateData (FALSE);
  217. return TRUE; // return TRUE unless you set the focus to a control
  218. // EXCEPTION: OCX Property Pages should return FALSE
  219. }
  220. void CRouteFltDlg::OnAdd()
  221. {
  222. CRouteFilter dlgFlt (this);
  223. dlgFlt.m_sIfName = m_sIfName;
  224. if (dlgFlt.DoModal ()==IDOK) {
  225. UINT item;
  226. RIP_ROUTE_FILTER_INFO FltInfo;
  227. // make sure we shoule the right thing
  228. ConvertNetworkNumberToBytes(dlgFlt.m_sNetwork,
  229. FltInfo.Network,
  230. sizeof(FltInfo.Network));
  231. ConvertNetworkNumberToBytes(dlgFlt.m_sNetMask,
  232. FltInfo.Mask,
  233. sizeof(FltInfo.Mask));
  234. UINT count = m_FilterList.GetItemCount ();
  235. TCHAR szBuffer[32];
  236. FormatIpxNetworkNumber(szBuffer, DimensionOf(szBuffer),
  237. FltInfo.Network, sizeof(FltInfo.Network));
  238. VERIFY ((item=m_FilterList.InsertItem (LVIF_TEXT|LVIF_PARAM,
  239. count, szBuffer,
  240. 0, 0, 0,
  241. (LPARAM)count))!=-1);
  242. FormatIpxNetworkNumber(szBuffer, DimensionOf(szBuffer),
  243. FltInfo.Mask, sizeof(FltInfo.Mask));
  244. VERIFY (m_FilterList.SetItemText (item, 1, szBuffer));
  245. }
  246. // Want to keep m_fActionDeny same over update
  247. m_fActionDeny = (BOOL ) GetDlgItem(IDC_RFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL);
  248. UpdateData (FALSE);
  249. SetFocus();
  250. }
  251. void CRouteFltDlg::OnDelete()
  252. {
  253. UINT item;
  254. VERIFY ((item=m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED))!=-1);
  255. VERIFY (m_FilterList.DeleteItem (item));
  256. // Want to keep m_fActionDeny same over update
  257. m_fActionDeny = (BOOL) GetDlgItem(IDC_RFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL);
  258. UpdateData (FALSE);
  259. SetFocus();
  260. }
  261. void CRouteFltDlg::OnListDblClk(NMHDR *pNmHdr, LRESULT *pResult)
  262. {
  263. if (m_FilterList.GetNextItem(-1, LVNI_SELECTED) == -1)
  264. return;
  265. OnEdit();
  266. *pResult = 0;
  267. }
  268. void CRouteFltDlg::OnEdit()
  269. {
  270. UINT item;
  271. CRouteFilter dlgFlt (this);
  272. VERIFY ((item=m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED))!=-1);
  273. dlgFlt.m_sIfName = m_sIfName;
  274. dlgFlt.m_sNetwork = m_FilterList.GetItemText (item, 0);
  275. dlgFlt.m_sNetMask = m_FilterList.GetItemText (item, 1);
  276. if (dlgFlt.DoModal ()==IDOK) {
  277. VERIFY (m_FilterList.SetItemText (item, 0, dlgFlt.m_sNetwork));
  278. VERIFY (m_FilterList.SetItemText (item, 1, dlgFlt.m_sNetMask));
  279. // Want to keep m_fActionDeny same over update
  280. m_fActionDeny = (BOOL)GetDlgItem(IDC_RFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL);
  281. UpdateData (FALSE);
  282. }
  283. SetFocus();
  284. }
  285. void CRouteFltDlg::OnOK()
  286. {
  287. DWORD dwCount;
  288. HRESULT hr = hrOK;
  289. m_fActionDeny = (BOOL)GetDlgItem(IDC_RFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL);
  290. dwCount = (DWORD) m_FilterList.GetItemCount();
  291. if (!dwCount && m_fActionDeny )
  292. {
  293. if (m_bOutput)
  294. AfxMessageBox(IDS_TRANSMIT_NO_RIP, MB_OK);
  295. else
  296. AfxMessageBox(IDS_RECEIVE_NO_RIP, MB_OK);
  297. return;
  298. }
  299. CBaseDialog::OnOK();
  300. }
  301. void CRouteFltDlg::OnItemchangedFilterList(NMHDR* pNMHDR, LRESULT* pResult)
  302. {
  303. if (m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED)!=-1) {
  304. GetDlgItem (IDC_RFS_BTN_EDIT)->EnableWindow (TRUE);
  305. GetDlgItem (IDC_RFS_BTN_DELETE)->EnableWindow (TRUE);
  306. }
  307. else {
  308. GetDlgItem (IDC_RFS_BTN_EDIT)->EnableWindow (FALSE);
  309. GetDlgItem (IDC_RFS_BTN_DELETE)->EnableWindow (FALSE);
  310. }
  311. if (pResult)
  312. *pResult = 0;
  313. }
  314. /////////////////////////////////////////////////////////////////////////////
  315. // CRouteFilter dialog
  316. CRouteFilter::CRouteFilter(CWnd* pParent /*=NULL*/)
  317. : CBaseDialog(CRouteFilter::IDD, pParent)
  318. {
  319. //{{AFX_DATA_INIT(CRouteFilter)
  320. m_sIfName = _T("");
  321. m_sNetMask = _T("");
  322. m_sNetwork = _T("");
  323. //}}AFX_DATA_INIT
  324. // SetHelpMap(m_dwHelpMap);
  325. }
  326. void CRouteFilter::DoDataExchange(CDataExchange* pDX)
  327. {
  328. CBaseDialog::DoDataExchange(pDX);
  329. //{{AFX_DATA_MAP(CRouteFilter)
  330. DDX_Text(pDX, IDC_RF_EDIT_INTERFACE, m_sIfName);
  331. DDX_Text(pDX, IDC_RF_EDIT_NETMASK, m_sNetMask);
  332. DDV_MaxChars(pDX, m_sNetMask, 8);
  333. DDX_Text(pDX, IDC_RF_EDIT_NETWORK, m_sNetwork);
  334. DDV_MaxChars(pDX, m_sNetwork, 8);
  335. //}}AFX_DATA_MAP
  336. if (pDX->m_bSaveAndValidate) {
  337. try {
  338. RIP_ROUTE_FILTER_INFO RtFltInfo;
  339. pDX->PrepareEditCtrl (IDC_RF_EDIT_NETWORK);
  340. ConvertNetworkNumberToBytes(m_sNetwork,
  341. RtFltInfo.Network,
  342. sizeof(RtFltInfo.Network));
  343. pDX->PrepareEditCtrl (IDC_RF_EDIT_NETMASK);
  344. ConvertNetworkNumberToBytes(m_sNetMask,
  345. RtFltInfo.Mask,
  346. sizeof(RtFltInfo.Mask));
  347. if (((*((UNALIGNED ULONG *)RtFltInfo.Network))
  348. &(*((UNALIGNED ULONG *)RtFltInfo.Mask)))
  349. !=(*((UNALIGNED ULONG *)RtFltInfo.Network))) {
  350. AfxMessageBox (IDS_ERR_INVALID_ROUTE_FILTER);
  351. throw (DWORD)ERROR_INVALID_DATA;
  352. }
  353. }
  354. catch (DWORD error) {
  355. if (error==ERROR_INVALID_DATA)
  356. pDX->Fail ();
  357. else
  358. throw;
  359. }
  360. }
  361. }
  362. BEGIN_MESSAGE_MAP(CRouteFilter, CBaseDialog)
  363. //{{AFX_MSG_MAP(CRouteFilter)
  364. //}}AFX_MSG_MAP
  365. END_MESSAGE_MAP()
  366. DWORD CRouteFilter::m_dwHelpMap[] =
  367. {
  368. // IDC_INTERFACE, HIDC_INTERFACE,
  369. // IDC_NETWORK, HIDC_NETWORK,
  370. // IDC_NETMASK, HIDC_NETMASK,
  371. 0,0
  372. };