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.

451 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: svfltdlg.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // SvFltDlg.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "ipxadmin.h"
  14. #include "ipxutil.h"
  15. #include "listctrl.h"
  16. #include "SvFltDlg.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. // CServiceFltDlg dialog
  29. CServiceFltDlg::CServiceFltDlg(BOOL bOutputDlg, IInfoBase *pInfoBase, CWnd* pParent /*=NULL*/)
  30. : CBaseDialog( (bOutputDlg ? CServiceFltDlg::IDD_OUTPUT : CServiceFltDlg::IDD_INPUT), pParent)
  31. {
  32. //{{AFX_DATA_INIT(CServiceFltDlg)
  33. m_fActionDeny = FALSE;
  34. //}}AFX_DATA_INIT
  35. m_bOutput = bOutputDlg;
  36. m_spInfoBase.Set(pInfoBase);
  37. // SetHelpMap(m_dwHelpMap);
  38. }
  39. void CServiceFltDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  42. CBaseDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CServiceFltDlg)
  44. DDX_Control(pDX, IDC_SFS_LIST, m_FilterList);
  45. DDX_Radio(pDX, IDC_SFS_BTN_DENY, m_fActionDeny);
  46. //}}AFX_DATA_MAP
  47. if (pDX->m_bSaveAndValidate)
  48. {
  49. PSAP_SERVICE_FILTER_INFO pFltInfo;
  50. UINT count;
  51. UINT i;
  52. DWORD dwSize;
  53. PSAP_IF_CONFIG pSapIfCfg = NULL;
  54. // Get the SAP_IF_CONFIG
  55. m_spInfoBase->GetData(IPX_PROTOCOL_SAP, 0, (PBYTE *) &pSapIfCfg);
  56. Assert(pSapIfCfg);
  57. count = m_FilterList.GetItemCount ();
  58. if (m_bOutput)
  59. {
  60. if (count != pSapIfCfg->SapIfFilters.SupplyFilterCount)
  61. {
  62. dwSize = FIELD_OFFSET (
  63. SAP_IF_CONFIG,
  64. SapIfFilters.ServiceFilter[
  65. count
  66. +pSapIfCfg->SapIfFilters.ListenFilterCount]);
  67. PSAP_IF_CONFIG pNewConfig = (PSAP_IF_CONFIG) new BYTE[dwSize];
  68. if (pNewConfig==NULL)
  69. AfxThrowMemoryException();
  70. memcpy (pNewConfig, pSapIfCfg,
  71. FIELD_OFFSET (SAP_IF_CONFIG, SapIfFilters.ServiceFilter));
  72. memcpy (&pNewConfig->SapIfFilters.ServiceFilter[count],
  73. &pSapIfCfg->SapIfFilters.ServiceFilter[
  74. pSapIfCfg->SapIfFilters.SupplyFilterCount],
  75. sizeof (SAP_SERVICE_FILTER_INFO)
  76. *pSapIfCfg->SapIfFilters.ListenFilterCount);
  77. pNewConfig->SapIfFilters.SupplyFilterCount = count;
  78. m_spInfoBase->SetData(IPX_PROTOCOL_SAP,
  79. dwSize,
  80. (BYTE *) pNewConfig,
  81. 1, 0);
  82. pSapIfCfg = pNewConfig;
  83. }
  84. pSapIfCfg->SapIfFilters.SupplyFilterAction = m_fActionDeny ?
  85. IPX_SERVICE_FILTER_DENY : IPX_SERVICE_FILTER_PERMIT;
  86. pFltInfo = &pSapIfCfg->SapIfFilters.ServiceFilter[0];
  87. }
  88. else {
  89. if (count!=pSapIfCfg->SapIfFilters.ListenFilterCount)
  90. {
  91. dwSize = FIELD_OFFSET (
  92. SAP_IF_CONFIG,
  93. SapIfFilters.ServiceFilter[
  94. count
  95. +pSapIfCfg->SapIfFilters.SupplyFilterCount]);
  96. PSAP_IF_CONFIG pNewConfig = (PSAP_IF_CONFIG) new BYTE[dwSize];
  97. if (pNewConfig==NULL)
  98. AfxThrowMemoryException();
  99. memcpy (pNewConfig, pSapIfCfg,
  100. FIELD_OFFSET (SAP_IF_CONFIG, SapIfFilters.ServiceFilter));
  101. memcpy (&pNewConfig->SapIfFilters.ServiceFilter[0],
  102. &pSapIfCfg->SapIfFilters.ServiceFilter[0],
  103. sizeof (SAP_SERVICE_FILTER_INFO)
  104. *pSapIfCfg->SapIfFilters.SupplyFilterCount);
  105. pNewConfig->SapIfFilters.ListenFilterCount = count;
  106. m_spInfoBase->SetData(IPX_PROTOCOL_SAP,
  107. dwSize,
  108. (BYTE *) pNewConfig,
  109. 1, 0);
  110. pSapIfCfg = pNewConfig;
  111. }
  112. pSapIfCfg->SapIfFilters.ListenFilterAction = m_fActionDeny ?
  113. IPX_SERVICE_FILTER_DENY : IPX_SERVICE_FILTER_PERMIT;
  114. pFltInfo = &pSapIfCfg->SapIfFilters.ServiceFilter[
  115. pSapIfCfg->SapIfFilters.SupplyFilterCount];
  116. }
  117. CString sAnyName, sAnyType;
  118. VERIFY (sAnyName.LoadString (IDS_ANY_SERVICE_NAME));
  119. VERIFY (sAnyType.LoadString (IDS_ANY_SERVICE_TYPE));
  120. for (i=0; i<count; i++)
  121. {
  122. CString aStr;
  123. aStr = m_FilterList.GetItemText (i, 0);
  124. if (aStr.CompareNoCase (sAnyType)!=0)
  125. {
  126. pFltInfo[i].ServiceType = (SHORT) _tcstoul((LPCTSTR) aStr, NULL, 16);
  127. }
  128. else
  129. pFltInfo[i].ServiceType = 0xFFFF;
  130. aStr = m_FilterList.GetItemText (i, 1);
  131. if (aStr.CompareNoCase (sAnyType)!=0)
  132. {
  133. StrnCpyAFromT((char *) pFltInfo[i].ServiceName,
  134. aStr,
  135. DimensionOf(pFltInfo[i].ServiceName));
  136. }
  137. else
  138. pFltInfo[i].ServiceName[0] = 0;
  139. }
  140. }
  141. }
  142. BEGIN_MESSAGE_MAP(CServiceFltDlg, CBaseDialog)
  143. //{{AFX_MSG_MAP(CServiceFltDlg)
  144. ON_BN_CLICKED(IDC_SFS_BTN_ADD, OnAdd)
  145. ON_BN_CLICKED(IDC_SFS_BTN_DELETE, OnDelete)
  146. ON_BN_CLICKED(IDC_SFS_BTN_EDIT, OnEdit)
  147. ON_NOTIFY(LVN_ITEMCHANGED, IDC_SFS_LIST, OnItemchangedFilterList)
  148. ON_NOTIFY(NM_DBLCLK, IDC_SFS_LIST, OnListDblClk)
  149. //}}AFX_MSG_MAP
  150. END_MESSAGE_MAP()
  151. DWORD CServiceFltDlg::m_dwHelpMap[] =
  152. {
  153. // IDC_DENY, HIDC_DENY,
  154. // IDC_PERMIT, HIDC_PERMIT,
  155. // IDC_FILTER_LIST, HIDC_FILTER_LIST,
  156. // IDC_ADD, HIDC_ADD,
  157. // IDC_EDIT, HIDC_EDIT,
  158. // IDC_DELETE, HIDC_DELETE,
  159. 0,0
  160. };
  161. /////////////////////////////////////////////////////////////////////////////
  162. // CServiceFltDlg message handlers
  163. BOOL CServiceFltDlg::OnInitDialog()
  164. {
  165. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  166. CString aStr;
  167. CBaseDialog::OnInitDialog();
  168. if (m_bOutput)
  169. aStr.FormatMessage (IDS_SERVICEFILTER_OUTPUT_CAP, (LPCTSTR)m_sIfName);
  170. else
  171. aStr.FormatMessage (IDS_SERVICEFILTER_INPUT_CAP, (LPCTSTR)m_sIfName);
  172. SetWindowText (aStr);
  173. // Get the current window style.
  174. DWORD dwStyle = GetWindowLong(m_FilterList.m_hWnd, GWL_STYLE);
  175. // Only set the window style if the view bits have changed.
  176. if ((dwStyle & LVS_TYPEMASK) != LVS_REPORT)
  177. SetWindowLong(m_FilterList.m_hWnd, GWL_STYLE,
  178. (dwStyle & ~LVS_TYPEMASK) | LVS_REPORT);
  179. ListView_SetExtendedListViewStyle(m_FilterList.m_hWnd,
  180. LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP);
  181. VERIFY (aStr.LoadString (IDS_SERVICEFILTER_TYPE_HDR));
  182. VERIFY (m_FilterList.InsertColumn (0, aStr)!=-1);
  183. AdjustColumnWidth (m_FilterList, 0, aStr);
  184. VERIFY (aStr.LoadString (IDS_SERVICEFILTER_NAME_HDR));
  185. VERIFY (m_FilterList.InsertColumn (1, aStr)!=-1);
  186. AdjustColumnWidth (m_FilterList, 1, aStr);
  187. PSAP_SERVICE_FILTER_INFO pFltInfo;
  188. UINT count;
  189. UINT i, item;
  190. PSAP_IF_CONFIG pSapIfCfg;
  191. m_spInfoBase->GetData(IPX_PROTOCOL_SAP, 0, (PBYTE *) &pSapIfCfg);
  192. Assert(pSapIfCfg);
  193. if (m_bOutput) {
  194. pFltInfo = &pSapIfCfg->SapIfFilters.ServiceFilter[0];
  195. count = pSapIfCfg->SapIfFilters.SupplyFilterCount;
  196. if (count>0)
  197. {
  198. m_fActionDeny = (pSapIfCfg->SapIfFilters.SupplyFilterAction == IPX_SERVICE_FILTER_DENY);
  199. }
  200. }
  201. else {
  202. pFltInfo = &pSapIfCfg->SapIfFilters.ServiceFilter[
  203. pSapIfCfg->SapIfFilters.SupplyFilterCount];
  204. count = pSapIfCfg->SapIfFilters.ListenFilterCount;
  205. if (count>0)
  206. {
  207. m_fActionDeny = (pSapIfCfg->SapIfFilters.ListenFilterAction == IPX_SERVICE_FILTER_DENY);
  208. }
  209. }
  210. for (i=0; i<count; i++) {
  211. CString aStr;
  212. if (pFltInfo[i].ServiceType!=0xFFFF)
  213. {
  214. aStr.Format(_T("%hx"), pFltInfo[i].ServiceType);
  215. }
  216. else
  217. VERIFY (aStr.LoadString (IDS_ANY_SERVICE_TYPE));
  218. VERIFY ((item=m_FilterList.InsertItem (LVIF_TEXT|LVIF_PARAM,
  219. i, aStr,
  220. 0, 0, 0,
  221. (LPARAM)i))!=-1);
  222. if (pFltInfo[i].ServiceName[0]!=0)
  223. {
  224. aStr.Format(_T("%.48hs"), pFltInfo[i].ServiceName);
  225. }
  226. else
  227. VERIFY (aStr.LoadString (IDS_ANY_SERVICE_NAME));
  228. VERIFY (m_FilterList.SetItemText (item, 1, aStr));
  229. }
  230. UpdateData (FALSE);
  231. return TRUE; // return TRUE unless you set the focus to a control
  232. // EXCEPTION: OCX Property Pages should return FALSE
  233. }
  234. void CServiceFltDlg::OnAdd()
  235. {
  236. CServiceFilter dlgFlt (this);
  237. dlgFlt.m_sIfName = m_sIfName;
  238. if (dlgFlt.DoModal ()==IDOK) {
  239. UINT item;
  240. UINT count = m_FilterList.GetItemCount ();
  241. if(dlgFlt.m_sType.IsEmpty())
  242. dlgFlt.m_sType = L'0';
  243. if (dlgFlt.m_sName.IsEmpty())
  244. dlgFlt.m_sName.LoadString (IDS_ANY_SERVICE_NAME);
  245. VERIFY ((item=m_FilterList.InsertItem (LVIF_TEXT|LVIF_PARAM,
  246. count, dlgFlt.m_sType,
  247. 0, 0, 0,
  248. (LPARAM)count))!=-1);
  249. VERIFY (m_FilterList.SetItemText (item, 1, dlgFlt.m_sName));
  250. }
  251. // Want to keep m_fActionDeny same over update
  252. m_fActionDeny = (BOOL) GetDlgItem(IDC_SFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL);
  253. UpdateData (FALSE);
  254. }
  255. void CServiceFltDlg::OnDelete()
  256. {
  257. UINT item;
  258. VERIFY ((item=m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED))!=-1);
  259. VERIFY (m_FilterList.DeleteItem (item));
  260. // Want to keep m_fActionDeny same over update
  261. m_fActionDeny = (BOOL)GetDlgItem(IDC_SFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL);
  262. UpdateData (FALSE);
  263. }
  264. void CServiceFltDlg::OnListDblClk(NMHDR *pNmHdr, LRESULT *pResult)
  265. {
  266. if (m_FilterList.GetNextItem(-1, LVNI_SELECTED) == -1)
  267. return;
  268. OnEdit();
  269. *pResult = 0;
  270. }
  271. void CServiceFltDlg::OnEdit()
  272. {
  273. UINT item;
  274. CServiceFilter dlgFlt (this);
  275. VERIFY ((item=m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED))!=-1);
  276. dlgFlt.m_sIfName = m_sIfName;
  277. dlgFlt.m_sType = m_FilterList.GetItemText (item, 0);
  278. dlgFlt.m_sName = m_FilterList.GetItemText (item, 1);
  279. if (dlgFlt.DoModal ()==IDOK) {
  280. VERIFY (m_FilterList.SetItemText (item, 0, dlgFlt.m_sType));
  281. VERIFY (m_FilterList.SetItemText (item, 1, dlgFlt.m_sName));
  282. // Want to keep m_fActionDeny same over update
  283. m_fActionDeny = (BOOL)GetDlgItem(IDC_SFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL);
  284. UpdateData (FALSE);
  285. }
  286. }
  287. void CServiceFltDlg::OnOK()
  288. {
  289. DWORD dwCount;
  290. HRESULT hr = hrOK;
  291. m_fActionDeny = (BOOL)GetDlgItem(IDC_SFS_BTN_PERMIT)->SendMessage(BM_GETCHECK, NULL, NULL);
  292. dwCount = (DWORD) m_FilterList.GetItemCount();
  293. if (!dwCount && m_fActionDeny )
  294. {
  295. if (m_bOutput)
  296. AfxMessageBox(IDS_TRANSMIT_NO_SAP, MB_OK);
  297. else
  298. AfxMessageBox(IDS_RECEIVE_NO_SAP, MB_OK);
  299. return;
  300. }
  301. CBaseDialog::OnOK();
  302. }
  303. void CServiceFltDlg::OnItemchangedFilterList(NMHDR* pNMHDR, LRESULT* pResult)
  304. {
  305. BOOL fEnable;
  306. fEnable = (m_FilterList.GetNextItem (-1, LVNI_ALL|LVNI_SELECTED)!=-1);
  307. MultiEnableWindow(GetSafeHwnd(),
  308. fEnable,
  309. IDC_SFS_BTN_EDIT,
  310. IDC_SFS_BTN_DELETE,
  311. 0);
  312. *pResult = 0;
  313. }
  314. /////////////////////////////////////////////////////////////////////////////
  315. // CServiceFilter dialog
  316. CServiceFilter::CServiceFilter(CWnd* pParent /*=NULL*/)
  317. : CBaseDialog(CServiceFilter::IDD, pParent)
  318. {
  319. //{{AFX_DATA_INIT(CServiceFilter)
  320. m_sIfName = _T("");
  321. m_sName = _T("");
  322. m_sType = _T("");
  323. //}}AFX_DATA_INIT
  324. // SetHelpMap(m_dwHelpMap);
  325. }
  326. void CServiceFilter::DoDataExchange(CDataExchange* pDX)
  327. {
  328. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  329. CBaseDialog::DoDataExchange(pDX);
  330. //{{AFX_DATA_MAP(CServiceFilter)
  331. DDX_Text(pDX, IDC_SF_EDIT_INTERFACE, m_sIfName);
  332. DDX_Text(pDX, IDC_SF_EDIT_SERVICE_NAME, m_sName);
  333. DDV_MaxChars(pDX, m_sName, 48);
  334. DDX_Text(pDX, IDC_SF_EDIT_SERVICE_TYPE, m_sType);
  335. DDV_MaxChars(pDX, m_sType, 4);
  336. //}}AFX_DATA_MAP
  337. if (pDX->m_bSaveAndValidate) {
  338. try {
  339. SAP_SERVICE_FILTER_INFO SvFltInfo;
  340. CString sAnyName, sAnyType;
  341. VERIFY (sAnyName.LoadString (IDS_ANY_SERVICE_NAME));
  342. VERIFY (sAnyType.LoadString (IDS_ANY_SERVICE_TYPE));
  343. pDX->PrepareEditCtrl (IDC_SF_EDIT_SERVICE_TYPE);
  344. if (m_sType.CompareNoCase (sAnyType)!=0)
  345. {
  346. SvFltInfo.ServiceType = (SHORT) _tcstoul((LPCTSTR) m_sType, NULL, 16);
  347. // m_sType >> CIPX_SERVICE_TYPE (&SvFltInfo.ServiceType);
  348. }
  349. pDX->PrepareEditCtrl (IDC_SF_EDIT_SERVICE_NAME);
  350. if (m_sName.CompareNoCase (sAnyType)!=0)
  351. {
  352. StrnCpyAFromT((char *) SvFltInfo.ServiceName,
  353. m_sName,
  354. DimensionOf(SvFltInfo.ServiceName));
  355. // m_sName >> CIPX_SERVICE_NAME (SvFltInfo.ServiceName);
  356. }
  357. }
  358. catch (DWORD error) {
  359. if (error==ERROR_INVALID_DATA)
  360. pDX->Fail ();
  361. else
  362. throw;
  363. }
  364. }
  365. }
  366. BEGIN_MESSAGE_MAP(CServiceFilter, CBaseDialog)
  367. //{{AFX_MSG_MAP(CServiceFilter)
  368. //}}AFX_MSG_MAP
  369. END_MESSAGE_MAP()
  370. DWORD CServiceFilter::m_dwHelpMap[] =
  371. {
  372. // IDC_INTERFACE, HIDC_INTERFACE,
  373. // IDC_SERVICE_TYPE, HIDC_SERVICE_TYPE,
  374. // IDC_SERVICE_NAME, HIDC_SERVICE_NAME,
  375. 0,0,
  376. };