//+------------------------------------------------------------------------- // // Microsoft Windows // // Copyright (C) Microsoft Corporation, 1998 - 1999 // // File: rtfltdlg.cpp // //-------------------------------------------------------------------------- // RtFltDlg.cpp : implementation file // #include "stdafx.h" #include "ipxadmin.h" #include "ipxutil.h" #include "listctrl.h" #include "RtFltDlg.h" extern "C" { #include "routprot.h" }; //nclude "rtradmin.hm" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRouteFltDlg dialog CRouteFltDlg::CRouteFltDlg(BOOL bOutputDlg, IInfoBase *pInfoBase, CWnd* pParent /*=NULL*/) : CBaseDialog( (bOutputDlg ? CRouteFltDlg::IDD_OUTPUT : CRouteFltDlg::IDD_INPUT), pParent), m_bOutput(bOutputDlg) { //{{AFX_DATA_INIT(CRouteFltDlg) m_fActionDeny = FALSE; //}}AFX_DATA_INIT m_spInfoBase.Set(pInfoBase); // SetHelpMap(m_dwHelpMap); } void CRouteFltDlg::DoDataExchange(CDataExchange* pDX) { CBaseDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRouteFltDlg) DDX_Control(pDX, IDC_RFS_LIST, m_FilterList); DDX_Radio(pDX, IDC_RFS_BTN_DENY, m_fActionDeny); //}}AFX_DATA_MAP if (pDX->m_bSaveAndValidate) { PRIP_ROUTE_FILTER_INFO pFltInfo; UINT count; UINT i; DWORD dwSize; PRIP_IF_CONFIG pRipIfCfg = NULL; // Grab the RIP_IF_CONFIG m_spInfoBase->GetData(IPX_PROTOCOL_RIP, 0, (PBYTE *) &pRipIfCfg); Assert(pRipIfCfg); count = m_FilterList.GetItemCount (); if (m_bOutput) { if (count != pRipIfCfg->RipIfFilters.SupplyFilterCount) { dwSize = FIELD_OFFSET ( RIP_IF_CONFIG, RipIfFilters.RouteFilter[count +pRipIfCfg->RipIfFilters.ListenFilterCount]); PRIP_IF_CONFIG pNewConfig = (PRIP_IF_CONFIG) new BYTE[dwSize]; if (pNewConfig==NULL) AfxThrowMemoryException(); memcpy (pNewConfig, pRipIfCfg, FIELD_OFFSET (RIP_IF_CONFIG, RipIfFilters.RouteFilter)); memcpy (&pNewConfig->RipIfFilters.RouteFilter[count], &pRipIfCfg->RipIfFilters.RouteFilter[ pRipIfCfg->RipIfFilters.SupplyFilterCount], sizeof (RIP_ROUTE_FILTER_INFO) *pRipIfCfg->RipIfFilters.ListenFilterCount); pNewConfig->RipIfFilters.SupplyFilterCount = count; m_spInfoBase->SetData(IPX_PROTOCOL_RIP, dwSize, (BYTE *) pNewConfig, 1, 0 ); pRipIfCfg = pNewConfig; } pRipIfCfg->RipIfFilters.SupplyFilterAction = m_fActionDeny ? IPX_ROUTE_FILTER_DENY : IPX_ROUTE_FILTER_PERMIT; pFltInfo = &pRipIfCfg->RipIfFilters.RouteFilter[0]; } else { if (count != pRipIfCfg->RipIfFilters.ListenFilterCount) { dwSize = FIELD_OFFSET ( RIP_IF_CONFIG, RipIfFilters.RouteFilter[ count +pRipIfCfg->RipIfFilters.SupplyFilterCount]); PRIP_IF_CONFIG pNewConfig = (PRIP_IF_CONFIG) new BYTE[dwSize]; if (pNewConfig==NULL) AfxThrowMemoryException(); memcpy (pNewConfig, pRipIfCfg, FIELD_OFFSET (RIP_IF_CONFIG, RipIfFilters.RouteFilter)); memcpy (&pNewConfig->RipIfFilters.RouteFilter[0], &pRipIfCfg->RipIfFilters.RouteFilter[0], sizeof (RIP_ROUTE_FILTER_INFO) *pRipIfCfg->RipIfFilters.SupplyFilterCount); pNewConfig->RipIfFilters.ListenFilterCount = count; m_spInfoBase->SetData(IPX_PROTOCOL_RIP, dwSize, (BYTE *) pNewConfig, 1, 0 ); pRipIfCfg = pNewConfig; } pRipIfCfg->RipIfFilters.ListenFilterAction = m_fActionDeny ? IPX_ROUTE_FILTER_DENY : IPX_ROUTE_FILTER_PERMIT; pFltInfo = &pRipIfCfg->RipIfFilters.RouteFilter[ pRipIfCfg->RipIfFilters.SupplyFilterCount]; } for (i=0; iGetData(IPX_PROTOCOL_RIP, 0, (PBYTE *) &pRipIfCfg); Assert(pRipIfCfg); if (m_bOutput) { pFltInfo = &pRipIfCfg->RipIfFilters.RouteFilter[0]; count = pRipIfCfg->RipIfFilters.SupplyFilterCount; if (count>0) m_fActionDeny = (pRipIfCfg->RipIfFilters.SupplyFilterAction == IPX_ROUTE_FILTER_DENY); } else { pFltInfo = &pRipIfCfg->RipIfFilters.RouteFilter[ pRipIfCfg->RipIfFilters.SupplyFilterCount]; count = pRipIfCfg->RipIfFilters.ListenFilterCount; if (count>0) m_fActionDeny = (pRipIfCfg->RipIfFilters.ListenFilterAction == IPX_ROUTE_FILTER_DENY); } for (i=0; iSendMessage(BM_GETCHECK, NULL, NULL); UpdateData (FALSE); SetFocus(); } void CRouteFltDlg::OnDelete() { UINT item; VERIFY ((item=m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED))!=-1); VERIFY (m_FilterList.DeleteItem (item)); // Want to keep m_fActionDeny same over update m_fActionDeny = (BOOL) GetDlgItem(IDC_RFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL); UpdateData (FALSE); SetFocus(); } void CRouteFltDlg::OnListDblClk(NMHDR *pNmHdr, LRESULT *pResult) { if (m_FilterList.GetNextItem(-1, LVNI_SELECTED) == -1) return; OnEdit(); *pResult = 0; } void CRouteFltDlg::OnEdit() { UINT item; CRouteFilter dlgFlt (this); VERIFY ((item=m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED))!=-1); dlgFlt.m_sIfName = m_sIfName; dlgFlt.m_sNetwork = m_FilterList.GetItemText (item, 0); dlgFlt.m_sNetMask = m_FilterList.GetItemText (item, 1); if (dlgFlt.DoModal ()==IDOK) { VERIFY (m_FilterList.SetItemText (item, 0, dlgFlt.m_sNetwork)); VERIFY (m_FilterList.SetItemText (item, 1, dlgFlt.m_sNetMask)); // Want to keep m_fActionDeny same over update m_fActionDeny = (BOOL)GetDlgItem(IDC_RFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL); UpdateData (FALSE); } SetFocus(); } void CRouteFltDlg::OnOK() { DWORD dwCount; HRESULT hr = hrOK; m_fActionDeny = (BOOL)GetDlgItem(IDC_RFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL); dwCount = (DWORD) m_FilterList.GetItemCount(); if (!dwCount && m_fActionDeny ) { if (m_bOutput) AfxMessageBox(IDS_TRANSMIT_NO_RIP, MB_OK); else AfxMessageBox(IDS_RECEIVE_NO_RIP, MB_OK); return; } CBaseDialog::OnOK(); } void CRouteFltDlg::OnItemchangedFilterList(NMHDR* pNMHDR, LRESULT* pResult) { if (m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED)!=-1) { GetDlgItem (IDC_RFS_BTN_EDIT)->EnableWindow (TRUE); GetDlgItem (IDC_RFS_BTN_DELETE)->EnableWindow (TRUE); } else { GetDlgItem (IDC_RFS_BTN_EDIT)->EnableWindow (FALSE); GetDlgItem (IDC_RFS_BTN_DELETE)->EnableWindow (FALSE); } if (pResult) *pResult = 0; } ///////////////////////////////////////////////////////////////////////////// // CRouteFilter dialog CRouteFilter::CRouteFilter(CWnd* pParent /*=NULL*/) : CBaseDialog(CRouteFilter::IDD, pParent) { //{{AFX_DATA_INIT(CRouteFilter) m_sIfName = _T(""); m_sNetMask = _T(""); m_sNetwork = _T(""); //}}AFX_DATA_INIT // SetHelpMap(m_dwHelpMap); } void CRouteFilter::DoDataExchange(CDataExchange* pDX) { CBaseDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRouteFilter) DDX_Text(pDX, IDC_RF_EDIT_INTERFACE, m_sIfName); DDX_Text(pDX, IDC_RF_EDIT_NETMASK, m_sNetMask); DDV_MaxChars(pDX, m_sNetMask, 8); DDX_Text(pDX, IDC_RF_EDIT_NETWORK, m_sNetwork); DDV_MaxChars(pDX, m_sNetwork, 8); //}}AFX_DATA_MAP if (pDX->m_bSaveAndValidate) { try { RIP_ROUTE_FILTER_INFO RtFltInfo; pDX->PrepareEditCtrl (IDC_RF_EDIT_NETWORK); ConvertNetworkNumberToBytes(m_sNetwork, RtFltInfo.Network, sizeof(RtFltInfo.Network)); pDX->PrepareEditCtrl (IDC_RF_EDIT_NETMASK); ConvertNetworkNumberToBytes(m_sNetMask, RtFltInfo.Mask, sizeof(RtFltInfo.Mask)); if (((*((UNALIGNED ULONG *)RtFltInfo.Network)) &(*((UNALIGNED ULONG *)RtFltInfo.Mask))) !=(*((UNALIGNED ULONG *)RtFltInfo.Network))) { AfxMessageBox (IDS_ERR_INVALID_ROUTE_FILTER); throw (DWORD)ERROR_INVALID_DATA; } } catch (DWORD error) { if (error==ERROR_INVALID_DATA) pDX->Fail (); else throw; } } } BEGIN_MESSAGE_MAP(CRouteFilter, CBaseDialog) //{{AFX_MSG_MAP(CRouteFilter) //}}AFX_MSG_MAP END_MESSAGE_MAP() DWORD CRouteFilter::m_dwHelpMap[] = { // IDC_INTERFACE, HIDC_INTERFACE, // IDC_NETWORK, HIDC_NETWORK, // IDC_NETMASK, HIDC_NETMASK, 0,0 };