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.

1056 lines
27 KiB

  1. //============================================================================
  2. // Copyright(c) 1996, Microsoft Corporation
  3. //
  4. // File: ipxadd.cpp
  5. //
  6. // History:
  7. // 08/30/96 Ram Cherala Created
  8. //
  9. // Implementation of IPX Filter Add/Edit dialog code
  10. //============================================================================
  11. #include "stdafx.h"
  12. #include "rtrfiltr.h"
  13. #include "ipxfltr.h"
  14. #include "datafmt.h"
  15. #include "IpxAdd.h"
  16. extern "C" {
  17. #include <ipxrtdef.h>
  18. #include <ipxtfflt.h>
  19. }
  20. #include "rtradmin.hm"
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CIpxAddEdit dialog
  23. CIpxAddEdit::CIpxAddEdit(CWnd* pParent,
  24. FilterListEntry ** ppFilterEntry)
  25. : CBaseDialog(CIpxAddEdit::IDD, pParent),
  26. m_ppFilterEntry( ppFilterEntry ),
  27. m_bValidate( TRUE )
  28. {
  29. //{{AFX_DATA_INIT(CIpxAddEdit)
  30. // NOTE: the ClassWizard will add member initialization here
  31. //}}AFX_DATA_INIT
  32. // SetHelpMap(m_dwHelpMap);
  33. }
  34. void CIpxAddEdit::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CString cStr;
  37. CBaseDialog::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CIpxAddEdit)
  39. DDX_Control(pDX, IDC_AEIPX_EB_SRC_SOCKET, m_ebSrcSocket);
  40. DDX_Control(pDX, IDC_AEIPX_EB_SRC_NODE, m_ebSrcNode);
  41. DDX_Control(pDX, IDC_AEIPX_EB_SRC_NET, m_ebSrcNet);
  42. DDX_Control(pDX, IDC_AEIPX_EB_SRC_MASK, m_ebSrcMask);
  43. DDX_Control(pDX, IDC_AEIPX_EB_PACKET_TYPE, m_ebPacketType);
  44. DDX_Control(pDX, IDC_AEIPX_EB_DST_SOCKET, m_ebDstSocket);
  45. DDX_Control(pDX, IDC_AEIPX_EB_DST_NODE, m_ebDstNode);
  46. DDX_Control(pDX, IDC_AEIPX_EB_DST_NET, m_ebDstNet);
  47. DDX_Control(pDX, IDC_AEIPX_EB_DST_MASK, m_ebDstMask);
  48. DDX_Text(pDX, IDC_AEIPX_EB_SRC_SOCKET, cStr);
  49. DDV_MaxChars(pDX, cStr, 4);
  50. DDX_Text(pDX, IDC_AEIPX_EB_SRC_NODE, cStr);
  51. DDV_MaxChars(pDX, cStr, 12);
  52. DDX_Text(pDX, IDC_AEIPX_EB_SRC_NET, cStr);
  53. DDV_MaxChars(pDX, cStr, 8);
  54. DDX_Text(pDX, IDC_AEIPX_EB_SRC_MASK, cStr);
  55. DDV_MaxChars(pDX, cStr, 8);
  56. DDX_Text(pDX, IDC_AEIPX_EB_DST_SOCKET, cStr);
  57. DDV_MaxChars(pDX, cStr, 4);
  58. DDX_Text(pDX, IDC_AEIPX_EB_DST_NODE, cStr);
  59. DDV_MaxChars(pDX, cStr, 12);
  60. DDX_Text(pDX, IDC_AEIPX_EB_DST_NET, cStr);
  61. DDV_MaxChars(pDX, cStr, 8);
  62. DDX_Text(pDX, IDC_AEIPX_EB_DST_MASK, cStr);
  63. DDV_MaxChars(pDX, cStr, 8);
  64. DDX_Text(pDX, IDC_AEIPX_EB_PACKET_TYPE, cStr);
  65. DDV_MaxChars(pDX, cStr, 4);
  66. //}}AFX_DATA_MAP
  67. }
  68. // change not to use KILLFOCUS to do data entry validation:
  69. // reason: create dead loop when the one loosing focus and the one getting focus both have invalid entries
  70. // here we change to do validation with OnOK
  71. BEGIN_MESSAGE_MAP(CIpxAddEdit, CBaseDialog)
  72. //{{AFX_MSG_MAP(CIpxAddEdit)
  73. /*
  74. ON_MESSAGE(WM_EDITLOSTFOCUS, OnEditLostFocus)
  75. ON_EN_KILLFOCUS(IDC_AEIPX_EB_SRC_NET, OnKillFocusSrcNet)
  76. ON_EN_KILLFOCUS(IDC_AEIPX_EB_SRC_MASK, OnKillFocusSrcNetMask)
  77. ON_EN_KILLFOCUS(IDC_AEIPX_EB_SRC_NODE, OnKillFocusSrcNode)
  78. ON_EN_KILLFOCUS(IDC_AEIPX_EB_SRC_SOCKET, OnKillFocusSrcSocket)
  79. ON_EN_KILLFOCUS(IDC_AEIPX_EB_DST_NET, OnKillFocusDstNet)
  80. ON_EN_KILLFOCUS(IDC_AEIPX_EB_DST_MASK, OnKillFocusDstNetMask)
  81. ON_EN_KILLFOCUS(IDC_AEIPX_EB_DST_NODE, OnKillFocusDstNode)
  82. ON_EN_KILLFOCUS(IDC_AEIPX_EB_DST_SOCKET, OnKillFocusDstSocket)
  83. ON_EN_KILLFOCUS(IDC_AEIPX_EB_PACKET_TYPE, OnKillFocusPacketType)
  84. */
  85. ON_WM_PARENTNOTIFY()
  86. ON_WM_ACTIVATEAPP()
  87. ON_WM_QUERYENDSESSION()
  88. //}}AFX_MSG_MAP
  89. END_MESSAGE_MAP()
  90. DWORD CIpxAddEdit::m_dwHelpMap[] =
  91. {
  92. // IDC_AI_ST_SRC_NET, HIDC_AI_ST_SRC_NET,
  93. // IDC_AEIPX_EB_SRC_NET, HIDC_AEIPX_EB_SRC_NET,
  94. // IDC_AI_ST_SRC_MASK, HIDC_AI_ST_SRC_MASK,
  95. // IDC_AEIPX_EB_SRC_MASK, HIDC_AEIPX_EB_SRC_MASK,
  96. // IDC_AI_ST_SRC_NODE, HIDC_AI_ST_SRC_NODE,
  97. // IDC_AEIPX_EB_SRC_NODE, HIDC_AEIPX_EB_SRC_NODE,
  98. // IDC_AI_ST_SRC_SOCKET, HIDC_AI_ST_SRC_SOCKET,
  99. // IDC_AEIPX_EB_SRC_SOCKET, HIDC_AEIPX_EB_SRC_SOCKET,
  100. // IDC_AI_ST_DST_NET, HIDC_AI_ST_DST_NET,
  101. // IDC_AEIPX_EB_DST_NET, HIDC_AEIPX_EB_DST_NET,
  102. // IDC_AI_ST_DST_MASK, HIDC_AI_ST_DST_MASK,
  103. // IDC_AEIPX_EB_DST_MASK, HIDC_AEIPX_EB_DST_MASK,
  104. // IDC_AI_ST_DST_NODE, HIDC_AI_ST_DST_NODE,
  105. // IDC_AEIPX_EB_DST_NODE, HIDC_AEIPX_EB_DST_NODE,
  106. // IDC_AI_ST_DST_SOCKET, HIDC_AI_ST_DST_SOCKET,
  107. // IDC_AEIPX_EB_DST_SOCKET, HIDC_AEIPX_EB_DST_SOCKET,
  108. // IDC_AI_ST_PACKET_TYPE, HIDC_AI_ST_PACKET_TYPE,
  109. // IDC_AEIPX_EB_PACKET_TYPE, HIDC_AEIPX_EB_PACKET_TYPE,
  110. 0,0
  111. };
  112. /////////////////////////////////////////////////////////////////////////////
  113. // CIpxAddEdit message handlers
  114. //------------------------------------------------------------------------------
  115. // Function: CIpxAddEdit::OnInitDialog
  116. //
  117. // Handles 'WM_INITDIALOG' notification from the dialog
  118. //------------------------------------------------------------------------------
  119. BOOL CIpxAddEdit::OnInitDialog()
  120. {
  121. CBaseDialog::OnInitDialog();
  122. CString cStr;
  123. //
  124. // determine if a new filter is being added or if an
  125. // existing filter is being modified.
  126. //
  127. m_bEdit = ( *m_ppFilterEntry != NULL );
  128. cStr.LoadString(m_bEdit ? IDS_IPX_EDIT_FILTER : IDS_IPX_ADD_FILTER);
  129. SetWindowText(cStr);
  130. //
  131. // Remove this style so we get the WM_PARENTNOTIFY when
  132. // the user clicks on the Cancel button
  133. //
  134. GetDlgItem(IDCANCEL)->ModifyStyleEx(WS_EX_NOPARENTNOTIFY,0);
  135. //
  136. // fill in the controls if user is editing an existing filter
  137. //
  138. if(m_bEdit)
  139. {
  140. FilterListEntry * pfle = *m_ppFilterEntry;
  141. if (pfle->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCNET)
  142. {
  143. m_ebSrcNet.SetWindowText(cStr << CIPX_NETWORK(pfle->SourceNetwork));
  144. m_ebSrcMask.SetWindowText(cStr << CIPX_NETWORK(pfle->SourceNetworkMask));
  145. }
  146. if (pfle->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCNODE)
  147. {
  148. m_ebSrcNode.SetWindowText(cStr << CIPX_NODE(pfle->SourceNode));
  149. }
  150. if (pfle->FilterDefinition & IPX_TRAFFIC_FILTER_ON_SRCSOCKET)
  151. {
  152. m_ebSrcSocket.SetWindowText(cStr << CIPX_SOCKET(pfle->SourceSocket));
  153. }
  154. if (pfle->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTNET)
  155. {
  156. m_ebDstNet.SetWindowText(cStr << CIPX_NETWORK(pfle->DestinationNetwork));
  157. m_ebDstMask.SetWindowText(cStr << CIPX_NETWORK(pfle->DestinationNetworkMask));
  158. }
  159. if (pfle->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTNODE)
  160. {
  161. m_ebDstNode.SetWindowText(cStr << CIPX_NODE(pfle->DestinationNode));
  162. }
  163. if (pfle->FilterDefinition & IPX_TRAFFIC_FILTER_ON_DSTSOCKET)
  164. {
  165. m_ebDstSocket.SetWindowText(cStr << CIPX_SOCKET(pfle->DestinationSocket));
  166. }
  167. if (pfle->FilterDefinition & IPX_TRAFFIC_FILTER_ON_PKTTYPE)
  168. {
  169. m_ebPacketType.SetWindowText(cStr << CIPX_PACKET_TYPE(pfle->PacketType));
  170. }
  171. }
  172. return TRUE; // return TRUE unless you set the focus to a control
  173. // EXCEPTION: OCX Property Pages should return FALSE
  174. }
  175. DWORD IDCsToVerify[] = {
  176. IDC_AEIPX_EB_SRC_NET,
  177. IDC_AEIPX_EB_SRC_MASK,
  178. IDC_AEIPX_EB_SRC_NODE,
  179. IDC_AEIPX_EB_SRC_SOCKET,
  180. IDC_AEIPX_EB_DST_NET,
  181. IDC_AEIPX_EB_DST_MASK,
  182. IDC_AEIPX_EB_DST_NODE,
  183. IDC_AEIPX_EB_DST_SOCKET,
  184. IDC_AEIPX_EB_PACKET_TYPE,
  185. 0 };
  186. //------------------------------------------------------------------------------
  187. // Function: CIpxAddEdit::OnOK
  188. //
  189. // Handles 'BN_CLICKED' notification from the 'OK' button
  190. //------------------------------------------------------------------------------
  191. void CIpxAddEdit::OnOK()
  192. {
  193. DWORD net, mask;
  194. CString cStr, cNet, cMask;
  195. FilterListEntry * pfle;
  196. INT n = 0;
  197. // validate the data entries
  198. while(IDCsToVerify[n] != 0)
  199. {
  200. if (TRUE != ValidateAnEntry(IDCsToVerify[n++]))
  201. return;
  202. };
  203. if(!*m_ppFilterEntry)
  204. {
  205. //
  206. // new filter added, allocate memory and save information
  207. //
  208. *m_ppFilterEntry = new FilterListEntry;
  209. }
  210. VERIFY(*m_ppFilterEntry);
  211. pfle = *m_ppFilterEntry;
  212. do {
  213. //
  214. // init. flags field.
  215. //
  216. pfle->FilterDefinition = 0;
  217. //
  218. // Traffic filter source parameters
  219. //
  220. m_ebSrcNet.GetWindowText(cNet);
  221. m_ebSrcMask.GetWindowText(cMask);
  222. //
  223. // if net number is empty
  224. //
  225. if ( cNet.GetLength() == 0 )
  226. {
  227. CString cEmpty = _T("00000000");
  228. cEmpty >> CIPX_NETWORK(pfle->SourceNetwork);
  229. //
  230. // if net mask is also empty
  231. //
  232. if ( cMask.GetLength() == 0 )
  233. {
  234. cEmpty >> CIPX_NETWORK(pfle->SourceNetworkMask);
  235. }
  236. else
  237. {
  238. cMask >> CIPX_NETWORK( pfle-> SourceNetworkMask );
  239. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCNET;
  240. }
  241. }
  242. //
  243. // if net number is not empty
  244. //
  245. else
  246. {
  247. //
  248. // if net mask is empty
  249. //
  250. if ( cMask.GetLength() == 0 )
  251. {
  252. AfxMessageBox(IDS_ENTER_MASK);
  253. ::SetFocus((HWND)m_ebSrcMask);
  254. break;
  255. }
  256. //
  257. // both net and mask specified. Verify validity
  258. //
  259. if ( ( _stscanf (cNet, TEXT("%lx%n"), &net, &n) == 1 ) &&
  260. ( n == cNet.GetLength() ) &&
  261. ( _stscanf (cMask, TEXT("%lx%n"), &mask, &n) == 1 ) &&
  262. ( n == cMask.GetLength() ) )
  263. {
  264. if ( ( net & mask ) != net)
  265. {
  266. AfxMessageBox(IDS_ENTER_VALID_MASK);
  267. ::SetFocus((HWND)m_ebSrcMask);
  268. break;
  269. }
  270. }
  271. else
  272. {
  273. AfxMessageBox(IDS_ENTER_VALID_MASK);
  274. ::SetFocus((HWND)m_ebSrcMask);
  275. break;
  276. }
  277. //
  278. // valid network number and mask combination
  279. //
  280. cNet >> CIPX_NETWORK( pfle-> SourceNetwork );
  281. cMask >> CIPX_NETWORK( pfle-> SourceNetworkMask );
  282. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCNET;
  283. }
  284. //
  285. // get source node
  286. //
  287. m_ebSrcNode.GetWindowText( cStr );
  288. if ( cStr.GetLength() == 0 )
  289. {
  290. CString cEmpty = _T( "000000000000" );
  291. cEmpty >> CIPX_NODE(pfle->SourceNode);
  292. }
  293. else
  294. {
  295. cStr >> CIPX_NODE( pfle-> SourceNode );
  296. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCNODE;
  297. }
  298. //
  299. // get source socket
  300. //
  301. m_ebSrcSocket.GetWindowText( cStr );
  302. if ( cStr.GetLength() == 0 )
  303. {
  304. CString cEmpty = _T( "0000" );
  305. cEmpty >> CIPX_SOCKET( pfle->SourceSocket );
  306. }
  307. else
  308. {
  309. cStr >> CIPX_SOCKET( pfle-> SourceSocket );
  310. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_SRCSOCKET;
  311. }
  312. //
  313. // Traffic filter destination parameters
  314. //
  315. m_ebDstNet.GetWindowText(cNet);
  316. m_ebDstMask.GetWindowText(cMask);
  317. //
  318. // if net number is empty
  319. //
  320. if ( cNet.GetLength() == 0 )
  321. {
  322. CString cEmpty = _T("00000000");
  323. cEmpty >> CIPX_NETWORK(pfle->DestinationNetwork);
  324. //
  325. // if net mask is also empty
  326. //
  327. if ( cMask.GetLength() == 0 )
  328. {
  329. cEmpty >> CIPX_NETWORK(pfle->DestinationNetworkMask);
  330. }
  331. else
  332. {
  333. cMask >> CIPX_NETWORK( pfle-> DestinationNetworkMask );
  334. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTNET;
  335. }
  336. }
  337. //
  338. // if net number is not empty
  339. //
  340. else
  341. {
  342. //
  343. // if net mask is empty
  344. //
  345. if ( cMask.GetLength() == 0 )
  346. {
  347. AfxMessageBox(IDS_ENTER_MASK);
  348. ::SetFocus((HWND)m_ebDstMask);
  349. break;
  350. }
  351. //
  352. // both net and mask specified. Verify validity
  353. //
  354. if ( ( _stscanf (cNet, TEXT("%lx%n"), &net, &n) == 1 ) &&
  355. ( n == cNet.GetLength() ) &&
  356. ( _stscanf (cMask, TEXT("%lx%n"), &mask, &n) == 1 ) &&
  357. ( n == cMask.GetLength() ) )
  358. {
  359. if ( ( net & mask ) != net)
  360. {
  361. AfxMessageBox(IDS_ENTER_VALID_MASK);
  362. ::SetFocus((HWND)m_ebDstMask);
  363. break;
  364. }
  365. }
  366. else
  367. {
  368. AfxMessageBox(IDS_ENTER_VALID_MASK);
  369. ::SetFocus((HWND)m_ebDstMask);
  370. break;
  371. }
  372. //
  373. // valid network number and mask combination
  374. //
  375. cNet >> CIPX_NETWORK( pfle-> DestinationNetwork );
  376. cMask >> CIPX_NETWORK( pfle-> DestinationNetworkMask );
  377. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTNET;
  378. }
  379. //
  380. // get destination node
  381. //
  382. m_ebDstNode.GetWindowText( cStr );
  383. if ( cStr.GetLength() == 0 )
  384. {
  385. CString cEmpty = _T( "000000000000" );
  386. cEmpty >> CIPX_NODE(pfle->DestinationNode);
  387. }
  388. else
  389. {
  390. cStr >> CIPX_NODE( pfle-> DestinationNode );
  391. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTNODE;
  392. }
  393. //
  394. // get destination socket
  395. //
  396. m_ebDstSocket.GetWindowText( cStr );
  397. if ( cStr.GetLength() == 0 )
  398. {
  399. CString cEmpty = _T( "0000" );
  400. cEmpty >> CIPX_SOCKET( pfle->DestinationSocket );
  401. }
  402. else
  403. {
  404. cStr >> CIPX_SOCKET( pfle-> DestinationSocket );
  405. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_DSTSOCKET;
  406. }
  407. //
  408. // get packet type
  409. //
  410. m_ebPacketType.GetWindowText( cStr );
  411. if ( cStr.GetLength() == 0 )
  412. {
  413. CString cEmpty = _T( "0" );
  414. cEmpty >> CIPX_PACKET_TYPE( pfle-> PacketType );
  415. }
  416. else
  417. {
  418. cStr >> CIPX_PACKET_TYPE( &pfle-> PacketType );
  419. pfle-> FilterDefinition |= IPX_TRAFFIC_FILTER_ON_PKTTYPE;
  420. }
  421. CBaseDialog::OnOK();
  422. } while (FALSE);
  423. }
  424. //------------------------------------------------------------------------------
  425. // Function: CIpxAddEdit::OnCancel
  426. //
  427. // Handles 'BN_CLICKED' notification from the 'Cancel' button
  428. //------------------------------------------------------------------------------
  429. void CIpxAddEdit::OnCancel()
  430. {
  431. // TODO: Add extra cleanup here
  432. CBaseDialog::OnCancel();
  433. }
  434. //------------------------------------------------------------------------------
  435. // Function: CIpxAddEdit::OnKillFocusSrcNet
  436. //
  437. // Handles 'EN_KILLFOCUS' notification from the 'Source Network number' editbox
  438. //------------------------------------------------------------------------------
  439. void CIpxAddEdit::OnKillFocusSrcNet()
  440. {
  441. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_SRC_NET, 0 );
  442. }
  443. //------------------------------------------------------------------------------
  444. // Function: CIpxAddEdit::OnKillFocusSrcMask
  445. //
  446. // Handles 'EN_KILLFOCUS' notification from the 'Source Network Mask' editbox
  447. //------------------------------------------------------------------------------
  448. void CIpxAddEdit::OnKillFocusSrcNetMask()
  449. {
  450. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_SRC_MASK, 0 );
  451. }
  452. //------------------------------------------------------------------------------
  453. // Function: CIpxAddEdit::OnKillFocusSrcNode
  454. //
  455. // Handles 'EN_KILLFOCUS' notification from the 'Source Network Node' editbox
  456. //------------------------------------------------------------------------------
  457. void CIpxAddEdit::OnKillFocusSrcNode()
  458. {
  459. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_SRC_NODE, 0 );
  460. }
  461. //------------------------------------------------------------------------------
  462. // Function: CIpxAddEdit::OnKillFocusSrcSocket
  463. //
  464. // Handles 'EN_KILLFOCUS' notification from the 'Source Network Socket' editbox
  465. //------------------------------------------------------------------------------
  466. void CIpxAddEdit::OnKillFocusSrcSocket()
  467. {
  468. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_SRC_SOCKET, 0 );
  469. }
  470. //------------------------------------------------------------------------------
  471. // Function: CIpxAddEdit::OnKillFocusDstNet
  472. //
  473. // Handles 'EN_KILLFOCUS' notification from the 'Destination Network number'
  474. // editbox
  475. //------------------------------------------------------------------------------
  476. void CIpxAddEdit::OnKillFocusDstNet()
  477. {
  478. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_DST_NET, 0 );
  479. }
  480. //------------------------------------------------------------------------------
  481. // Function: CIpxAddEdit::OnKillFocusDstMask
  482. //
  483. // Handles 'EN_KILLFOCUS' notification from the 'Destination Network mask'
  484. // editbox
  485. //------------------------------------------------------------------------------
  486. void CIpxAddEdit::OnKillFocusDstNetMask()
  487. {
  488. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_DST_MASK, 0 );
  489. }
  490. //------------------------------------------------------------------------------
  491. // Function: CIpxAddEdit::OnKillFocusDstNode
  492. //
  493. // Handles 'EN_KILLFOCUS' notification from the 'Destination Node' editbox
  494. //------------------------------------------------------------------------------
  495. void CIpxAddEdit::OnKillFocusDstNode()
  496. {
  497. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_DST_NODE, 0 );
  498. }
  499. //------------------------------------------------------------------------------
  500. // Function: CIpxAddEdit::OnKillFocusSrcNet
  501. //
  502. // Handles 'EN_KILLFOCUS' notification from the 'Destination socket' editbox
  503. //------------------------------------------------------------------------------
  504. void CIpxAddEdit::OnKillFocusDstSocket()
  505. {
  506. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_DST_SOCKET, 0 );
  507. }
  508. //------------------------------------------------------------------------------
  509. // Function: CIpxAddEdit::OnKillFocusPacketType
  510. //
  511. // Handles 'EN_KILLFOCUS' notification from the 'Packet Type' editbox
  512. //------------------------------------------------------------------------------
  513. void CIpxAddEdit::OnKillFocusPacketType()
  514. {
  515. PostMessage( WM_EDITLOSTFOCUS, IDC_AEIPX_EB_PACKET_TYPE, 0 );
  516. }
  517. //------------------------------------------------------------------------------
  518. // Function: CIpxAddEdit::OnKillFocusPacketType
  519. //
  520. // Handles 'EN_KILLFOCUS' notification from the 'Packet Type' editbox
  521. //------------------------------------------------------------------------------
  522. afx_msg
  523. LONG CIpxAddEdit::OnEditLostFocus( UINT uId, LONG lParam )
  524. {
  525. ValidateAnEntry(uId);
  526. return 0;
  527. };
  528. BOOL CIpxAddEdit::ValidateAnEntry( UINT uId)
  529. {
  530. BOOL bOK = FALSE;
  531. CString cStr, cStr1;
  532. if ( m_bValidate )
  533. {
  534. if ( !UpdateData( TRUE ) )
  535. {
  536. return 0;
  537. }
  538. switch ( uId )
  539. {
  540. case IDC_AEIPX_EB_SRC_NET:
  541. m_ebSrcNet.GetWindowText( cStr );
  542. if ( !( bOK = VerifyEntry( uId, cStr, cStr1 ) ) )
  543. {
  544. ::AfxMessageBox( IDS_INVALID_NETWORK_NUMBER );
  545. }
  546. break;
  547. case IDC_AEIPX_EB_SRC_MASK:
  548. m_ebSrcMask.GetWindowText( cStr );
  549. m_ebSrcNet.GetWindowText( cStr1 );
  550. bOK = VerifyEntry( uId, cStr, cStr1 );
  551. break;
  552. case IDC_AEIPX_EB_SRC_NODE:
  553. m_ebSrcNode.GetWindowText( cStr );
  554. if ( !( bOK = VerifyEntry( uId, cStr, cStr1 ) ) )
  555. {
  556. ::AfxMessageBox( IDS_INVALID_NODE_NUMBER );
  557. }
  558. break;
  559. case IDC_AEIPX_EB_SRC_SOCKET:
  560. m_ebSrcSocket.GetWindowText( cStr );
  561. if ( !( bOK = VerifyEntry( uId, cStr, cStr1 ) ) )
  562. {
  563. ::AfxMessageBox( IDS_INVALID_SOCKET_NUMBER );
  564. }
  565. break;
  566. case IDC_AEIPX_EB_DST_NET:
  567. m_ebDstNet.GetWindowText( cStr );
  568. if ( !( bOK = VerifyEntry( uId, cStr, cStr1 ) ) )
  569. {
  570. ::AfxMessageBox( IDS_INVALID_NETWORK_NUMBER );
  571. }
  572. break;
  573. case IDC_AEIPX_EB_DST_MASK:
  574. m_ebDstMask.GetWindowText( cStr );
  575. m_ebDstNet.GetWindowText( cStr1 );
  576. bOK = VerifyEntry( uId, cStr, cStr1 );
  577. break;
  578. case IDC_AEIPX_EB_DST_NODE:
  579. m_ebDstNode.GetWindowText( cStr );
  580. if ( !( bOK = VerifyEntry( uId, cStr, cStr1 ) ) )
  581. {
  582. ::AfxMessageBox( IDS_INVALID_NODE_NUMBER );
  583. }
  584. break;
  585. case IDC_AEIPX_EB_DST_SOCKET:
  586. m_ebDstSocket.GetWindowText( cStr );
  587. if ( !( bOK = VerifyEntry( uId, cStr, cStr1 ) ) )
  588. {
  589. ::AfxMessageBox( IDS_INVALID_SOCKET_NUMBER );
  590. }
  591. break;
  592. case IDC_AEIPX_EB_PACKET_TYPE:
  593. m_ebPacketType.GetWindowText( cStr );
  594. if ( !( bOK = VerifyEntry( uId, cStr, cStr1 ) ) )
  595. {
  596. ::AfxMessageBox( IDS_INVALID_SERVICE_TYPE );
  597. }
  598. break;
  599. }
  600. if ( !bOK )
  601. {
  602. GetDlgItem( uId )-> SetFocus();
  603. }
  604. }
  605. m_bValidate = TRUE;
  606. return bOK;
  607. }
  608. //------------------------------------------------------------------------------
  609. // Function: CIpxAddEdit::OnParentNotify
  610. //
  611. // Handles 'WM_PARENTNOTIFY' notification caused by a mouse click on the CANCEL
  612. // button
  613. //------------------------------------------------------------------------------
  614. void CIpxAddEdit::OnParentNotify(UINT message, LPARAM lParam)
  615. {
  616. CBaseDialog::OnParentNotify(message, lParam);
  617. //
  618. // Mouse clicked on dialog.
  619. //
  620. CPoint ptButtonDown(LOWORD(lParam), HIWORD(lParam));
  621. //
  622. // Did the user click the mouse on the cancel button?
  623. //
  624. if ( ( message == WM_LBUTTONDOWN ) &&
  625. ( ChildWindowFromPoint( ptButtonDown ) == GetDlgItem(IDCANCEL) ) )
  626. {
  627. m_bValidate = FALSE;
  628. }
  629. }
  630. //------------------------------------------------------------------------------
  631. // Function: CIpxAddEdit::OnActivateApp
  632. //
  633. // Handles 'WM_ACTIVATEAPP' notification
  634. //------------------------------------------------------------------------------
  635. void CIpxAddEdit::OnActivateApp(BOOL bActive, HTASK hTask)
  636. {
  637. CBaseDialog::OnActivateApp(bActive, hTask);
  638. m_bValidate = bActive;
  639. }
  640. //------------------------------------------------------------------------------
  641. // Function: CIpxAddEdit::OnQuerySession
  642. //
  643. // Handles 'WM_QUERYENDSESSION' notification
  644. //------------------------------------------------------------------------------
  645. BOOL CIpxAddEdit::OnQueryEndSession()
  646. {
  647. if ( !CBaseDialog::OnQueryEndSession() )
  648. {
  649. return FALSE;
  650. }
  651. //
  652. // Before ending this Windows session,
  653. // validate the dialog controls.
  654. // This is basically the code from CDialog::OnOK();
  655. //
  656. if (!UpdateData(TRUE))
  657. {
  658. return FALSE;
  659. }
  660. EndDialog(IDOK);
  661. return TRUE;
  662. }
  663. #define ValidHexCharSet TEXT( "1234567890abcdefABCDEF" )
  664. //------------------------------------------------------------------------------
  665. // Function: CIpxAddEdit::VerifyEntry
  666. //
  667. // Verifies entered data in each edit control
  668. //------------------------------------------------------------------------------
  669. BOOL CIpxAddEdit::VerifyEntry(
  670. UINT uId,
  671. const CString& cStr,
  672. const CString& cNet
  673. )
  674. {
  675. INT n = 0;
  676. DWORD dwNet, dwMask;
  677. //
  678. // if the value in cStr is not a mask
  679. //
  680. if ( uId != IDC_AEIPX_EB_SRC_MASK &&
  681. uId != IDC_AEIPX_EB_DST_MASK )
  682. {
  683. //
  684. // if empty string skip it.
  685. //
  686. if ( cStr.GetLength() == 0 )
  687. {
  688. return TRUE;
  689. }
  690. //
  691. // check string has only valid hex characters
  692. //
  693. CString cTmp = cStr.SpanIncluding( (LPCTSTR) ValidHexCharSet );
  694. return ( cTmp.GetLength() == cStr.GetLength() );
  695. }
  696. //
  697. // the value in CStr is a mask.
  698. //
  699. //
  700. // Empty network and mask is a valid combination.
  701. //
  702. if ( cNet.GetLength() == 0 &&
  703. cStr.GetLength() == 0 )
  704. {
  705. return TRUE;
  706. }
  707. //
  708. // no network mask specified
  709. //
  710. if ( cStr.GetLength() == 0 )
  711. {
  712. //
  713. // check if network number is valid. If it isn't
  714. // the network number check will fire, so do not
  715. // pop a box here. HACK to circumvent the KILLFOCUS
  716. // processing
  717. //
  718. CString cTmp = cNet.SpanIncluding( (LPCTSTR) ValidHexCharSet );
  719. if ( cNet.GetLength() == cTmp.GetLength() )
  720. {
  721. ::AfxMessageBox( IDS_ENTER_MASK );
  722. return FALSE;
  723. }
  724. return TRUE;
  725. }
  726. //
  727. // verify mask has only hex chars.
  728. //
  729. CString cTmp = cStr.SpanIncluding( (LPCTSTR) ValidHexCharSet );
  730. if ( cTmp.GetLength() != cStr.GetLength() )
  731. {
  732. ::AfxMessageBox( IDS_ENTER_VALID_MASK );
  733. return FALSE;
  734. }
  735. //
  736. // If net number is empty, return TRUE.
  737. //
  738. if ( cNet.GetLength() == 0 )
  739. {
  740. return TRUE;
  741. }
  742. //
  743. // if net number contains invalid data, return TRUE.
  744. // Net number validation will take care of this.
  745. //
  746. cTmp = cNet.SpanIncluding( (LPCTSTR) ValidHexCharSet );
  747. if ( cNet.GetLength() != cTmp.GetLength() )
  748. {
  749. return TRUE;
  750. }
  751. //
  752. // verify net and mask jive
  753. //
  754. if ( ( _stscanf (cNet, TEXT("%lx%n"), &dwNet, &n) == 1 ) &&
  755. ( n == cNet.GetLength() ) &&
  756. ( _stscanf (cStr, TEXT("%lx%n"), &dwMask, &n) == 1 ) &&
  757. ( n == cStr.GetLength() ) )
  758. {
  759. if ( ( dwNet & dwMask ) != dwNet)
  760. {
  761. ::AfxMessageBox( (uId == IDC_AEIPX_EB_SRC_MASK) ?
  762. IDS_INVALID_SRC_MASK :
  763. IDS_INVALID_DST_MASK );
  764. return FALSE;
  765. }
  766. }
  767. else
  768. {
  769. ::AfxMessageBox( IDS_ENTER_VALID_MASK );
  770. return FALSE;
  771. }
  772. return TRUE;
  773. }