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.

413 lines
14 KiB

  1. #include "stdafx.h"
  2. #include "wlbsparm.h"
  3. #include "PortsPage.h"
  4. #include "ClusterPortsDlg.h"
  5. #include "ResourceString.h"
  6. BEGIN_MESSAGE_MAP(ClusterPortsDlg, CDialog)
  7. ON_BN_CLICKED(IDC_RADIO_DISABLED, OnRadioDisabled)
  8. ON_BN_CLICKED(IDC_RADIO_MULTIPLE, OnRadioMultiple)
  9. ON_BN_CLICKED(IDC_RADIO_SINGLE, OnRadioSingle)
  10. ON_WM_HELPINFO()
  11. ON_WM_CONTEXTMENU()
  12. END_MESSAGE_MAP()
  13. ClusterPortsDlg::ClusterPortsDlg( PortsPage::PortData& portData,
  14. CWnd* parent,
  15. const int& index
  16. )
  17. :
  18. m_portData( portData ),
  19. CDialog( ClusterPortsDlg::IDD, parent ),
  20. m_index( index )
  21. {
  22. m_parent = (PortsPage *) parent;
  23. }
  24. void
  25. ClusterPortsDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange( pDX );
  28. }
  29. BOOL
  30. ClusterPortsDlg::OnInitDialog()
  31. {
  32. CDialog::OnInitDialog();
  33. SetControlData();
  34. return TRUE;
  35. }
  36. void
  37. ClusterPortsDlg::OnOK()
  38. {
  39. PortsPage::PortData portData;
  40. //
  41. // get port information.
  42. //
  43. BOOL fError;
  44. long start_port = ::GetDlgItemInt (m_hWnd, IDC_EDIT_START, &fError, FALSE);
  45. if( fError == FALSE )
  46. {
  47. // some problem with the data input.
  48. // it has been left blank.
  49. wchar_t buffer[Common::BUF_SIZE];
  50. swprintf( buffer, GETRESOURCEIDSTRING( IDS_PARM_PORT_BLANK ), CVY_MIN_PORT,CVY_MAX_PORT );
  51. MessageBox( buffer,
  52. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  53. MB_ICONSTOP | MB_OK );
  54. return;
  55. }
  56. wchar_t buf[Common::BUF_SIZE];
  57. swprintf( buf, L"%d", start_port );
  58. portData.start_port = buf;
  59. long end_port = ::GetDlgItemInt (m_hWnd, IDC_EDIT_END, &fError, FALSE);
  60. if( fError == FALSE )
  61. {
  62. // some problem with the data input.
  63. // it has been left blank.
  64. wchar_t buffer[Common::BUF_SIZE];
  65. swprintf( buffer, GETRESOURCEIDSTRING( IDS_PARM_PORT_BLANK ), CVY_MIN_PORT,CVY_MAX_PORT );
  66. MessageBox( buffer,
  67. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  68. MB_ICONSTOP | MB_OK );
  69. return;
  70. }
  71. swprintf( buf, L"%d", end_port );
  72. portData.end_port = buf;
  73. // check if start port and end port both are in
  74. // proper range.
  75. if( !( start_port >= CVY_MIN_PORT
  76. &&
  77. start_port <= CVY_MAX_PORT
  78. &&
  79. end_port >= CVY_MIN_PORT
  80. &&
  81. end_port <= CVY_MAX_PORT )
  82. )
  83. {
  84. wchar_t buffer[Common::BUF_SIZE];
  85. swprintf( buffer, GETRESOURCEIDSTRING( IDS_PARM_PORT_VAL ), CVY_MIN_PORT,CVY_MAX_PORT );
  86. MessageBox( buffer,
  87. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  88. MB_ICONSTOP | MB_OK );
  89. return;
  90. }
  91. // check if start port is less than or equal to end port.
  92. if( !(start_port <= end_port ) )
  93. {
  94. // start port is not less than or equal to end port.
  95. MessageBox( GETRESOURCEIDSTRING(IDS_PARM_RANGE ),
  96. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  97. MB_ICONSTOP | MB_OK );
  98. ::SetDlgItemInt(m_hWnd, IDC_EDIT_END, end_port, FALSE);
  99. return;
  100. }
  101. // check if there are are overlapped port rules.
  102. wchar_t portBuf[Common::BUF_SIZE];
  103. for( int i = 0; i < m_parent->m_portList.GetItemCount(); ++i )
  104. {
  105. if( i != m_index ) // not comparing against self
  106. {
  107. m_parent->m_portList.GetItemText( i, 0, portBuf, Common::BUF_SIZE );
  108. long start_port_existing = _wtoi( portBuf );
  109. m_parent->m_portList.GetItemText( i, 1, portBuf, Common::BUF_SIZE );
  110. long end_port_existing = _wtoi( portBuf );
  111. if ( (start_port < start_port_existing &&
  112. end_port >= start_port_existing) ||
  113. ( start_port >= start_port_existing &&
  114. start_port <= end_port_existing))
  115. {
  116. MessageBox( GETRESOURCEIDSTRING(IDS_PARM_OVERLAP ),
  117. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  118. MB_ICONSTOP | MB_OK );
  119. return;
  120. }
  121. }
  122. }
  123. // get protocol
  124. if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_TCP))
  125. {
  126. portData.protocol = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP );
  127. }
  128. else if( ::IsDlgButtonChecked (m_hWnd, IDC_RADIO_UDP))
  129. {
  130. portData.protocol = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP );
  131. }
  132. else
  133. {
  134. portData.protocol = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH);
  135. }
  136. // get filtering mode
  137. if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_MULTIPLE))
  138. {
  139. portData.mode = GETRESOURCEIDSTRING( IDS_REPORT_MODE_MULTIPLE );
  140. // get affinity
  141. if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_AFF_NONE))
  142. {
  143. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_NONE );
  144. }
  145. else if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_AFF_SINGLE))
  146. {
  147. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_SINGLE );
  148. }
  149. else
  150. {
  151. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_CLASSC );
  152. }
  153. // get load balancing.
  154. if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_EQUAL))
  155. {
  156. portData.load = GETRESOURCEIDSTRING( IDS_REPORT_LOAD_EQUAL );
  157. }
  158. else
  159. {
  160. portData.load = GETRESOURCEIDSTRING( IDS_REPORT_LOAD_UNEQUAL );
  161. }
  162. // for multiple mode, priority is empty.
  163. portData.priority = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  164. }
  165. else if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_SINGLE))
  166. {
  167. portData.mode = GETRESOURCEIDSTRING( IDS_REPORT_MODE_SINGLE );
  168. portData.priority = GETRESOURCEIDSTRING( IDS_REPORT_NA );
  169. // for single mode load and affinity are empty.
  170. portData.load = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  171. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  172. }
  173. else
  174. {
  175. portData.mode = GETRESOURCEIDSTRING( IDS_REPORT_MODE_DISABLED );
  176. // for single mode priority load and affinity are empty.
  177. portData.priority = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  178. portData.load = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  179. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  180. }
  181. // set the new port rule.
  182. m_portData = portData;
  183. EndDialog( IDOK );
  184. }
  185. void
  186. ClusterPortsDlg::SetControlData()
  187. {
  188. ::SendDlgItemMessage(m_hWnd, IDC_EDIT_START, EM_SETLIMITTEXT, 5, 0);
  189. ::SendDlgItemMessage(m_hWnd, IDC_EDIT_END, EM_SETLIMITTEXT, 5, 0);
  190. ::SendDlgItemMessage(m_hWnd, IDC_SPIN_START, UDM_SETRANGE32, CVY_MIN_PORT, CVY_MAX_PORT);
  191. ::SendDlgItemMessage(m_hWnd, IDC_SPIN_END, UDM_SETRANGE32, CVY_MIN_PORT, CVY_MAX_PORT);
  192. // set the port range.
  193. ::SetDlgItemInt (m_hWnd, IDC_EDIT_START, _wtoi( m_portData.start_port), FALSE);
  194. ::SetDlgItemInt (m_hWnd, IDC_EDIT_END, _wtoi( m_portData.end_port ), FALSE);
  195. // set the protocol.
  196. if( m_portData.protocol == GETRESOURCEIDSTRING(IDS_REPORT_PROTOCOL_TCP) )
  197. {
  198. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_CHECKED );
  199. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_UNCHECKED );
  200. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_UNCHECKED );
  201. }
  202. else if( m_portData.protocol == GETRESOURCEIDSTRING(IDS_REPORT_PROTOCOL_UDP) )
  203. {
  204. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_UNCHECKED );
  205. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_CHECKED );
  206. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_UNCHECKED );
  207. }
  208. else
  209. {
  210. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_UNCHECKED );
  211. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_UNCHECKED );
  212. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_CHECKED );
  213. }
  214. // set the mode.
  215. if( m_portData.mode == GETRESOURCEIDSTRING(IDS_REPORT_MODE_MULTIPLE) )
  216. {
  217. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_CHECKED );
  218. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_UNCHECKED );
  219. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_UNCHECKED );
  220. :: EnableWindow (GetDlgItem (IDC_RADIO_UNEQUAL)->m_hWnd, TRUE);
  221. :: EnableWindow (GetDlgItem (IDC_RADIO_EQUAL)->m_hWnd, TRUE);
  222. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, TRUE);
  223. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, TRUE);
  224. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, TRUE);
  225. if( m_portData.load == GETRESOURCEIDSTRING(IDS_REPORT_LOAD_EQUAL) )
  226. {
  227. ::CheckDlgButton( m_hWnd, IDC_RADIO_EQUAL, BST_CHECKED );
  228. ::CheckDlgButton( m_hWnd, IDC_RADIO_UNEQUAL, BST_UNCHECKED );
  229. }
  230. else
  231. {
  232. ::CheckDlgButton( m_hWnd, IDC_RADIO_EQUAL, BST_UNCHECKED );
  233. ::CheckDlgButton( m_hWnd, IDC_RADIO_UNEQUAL, BST_CHECKED );
  234. }
  235. if( m_portData.affinity == GETRESOURCEIDSTRING(IDS_REPORT_AFFINITY_NONE ) )
  236. {
  237. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_CHECKED );
  238. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_UNCHECKED );
  239. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  240. }
  241. else if ( m_portData.affinity == GETRESOURCEIDSTRING(IDS_REPORT_AFFINITY_SINGLE) )
  242. {
  243. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  244. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_CHECKED );
  245. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  246. }
  247. else
  248. {
  249. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  250. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_UNCHECKED );
  251. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_CHECKED );
  252. }
  253. }
  254. else if( m_portData.mode == GETRESOURCEIDSTRING(IDS_REPORT_MODE_SINGLE) )
  255. {
  256. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_UNCHECKED );
  257. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_CHECKED );
  258. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_UNCHECKED );
  259. :: EnableWindow (GetDlgItem (IDC_RADIO_UNEQUAL)->m_hWnd, FALSE);
  260. :: EnableWindow (GetDlgItem (IDC_RADIO_EQUAL)->m_hWnd, FALSE);
  261. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, FALSE);
  262. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, FALSE);
  263. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, FALSE);
  264. }
  265. else
  266. {
  267. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_UNCHECKED );
  268. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_UNCHECKED );
  269. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_CHECKED );
  270. :: EnableWindow (GetDlgItem (IDC_RADIO_UNEQUAL)->m_hWnd, FALSE);
  271. :: EnableWindow (GetDlgItem (IDC_RADIO_EQUAL)->m_hWnd, FALSE);
  272. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, FALSE);
  273. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, FALSE);
  274. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, FALSE);
  275. }
  276. }
  277. void
  278. ClusterPortsDlg::OnRadioMultiple()
  279. {
  280. // TODO: Add your control notification handler code here
  281. :: EnableWindow (GetDlgItem (IDC_RADIO_UNEQUAL)->m_hWnd, TRUE);
  282. :: EnableWindow (GetDlgItem (IDC_RADIO_EQUAL)->m_hWnd, TRUE);
  283. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, TRUE);
  284. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, TRUE);
  285. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, TRUE);
  286. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  287. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_CHECKED );
  288. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  289. ::CheckDlgButton( m_hWnd, IDC_RADIO_EQUAL, BST_CHECKED );
  290. ::CheckDlgButton( m_hWnd, IDC_RADIO_UNEQUAL, BST_UNCHECKED );
  291. }
  292. void
  293. ClusterPortsDlg::OnRadioSingle()
  294. {
  295. // TODO: Add your control notification handler code here
  296. :: EnableWindow (GetDlgItem (IDC_RADIO_UNEQUAL)->m_hWnd, FALSE);
  297. :: EnableWindow (GetDlgItem (IDC_RADIO_EQUAL)->m_hWnd, FALSE);
  298. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, FALSE);
  299. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, FALSE);
  300. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, FALSE);
  301. }
  302. void
  303. ClusterPortsDlg::OnRadioDisabled()
  304. {
  305. // TODO: Add your control notification handler code here
  306. :: EnableWindow (GetDlgItem (IDC_RADIO_UNEQUAL)->m_hWnd, FALSE);
  307. :: EnableWindow (GetDlgItem (IDC_RADIO_EQUAL)->m_hWnd, FALSE);
  308. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, FALSE);
  309. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, FALSE);
  310. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, FALSE);
  311. }
  312. void ClusterPortsDlg::PrintRangeError (unsigned int ids, int low, int high)
  313. {
  314. /* Pop-up a message box. */
  315. wchar_t buffer[Common::BUF_SIZE];
  316. swprintf( buffer, GETRESOURCEIDSTRING( ids ), low, high );
  317. MessageBox( buffer,
  318. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  319. MB_ICONSTOP | MB_OK );
  320. }
  321. BOOL
  322. ClusterPortsDlg::OnHelpInfo (HELPINFO* helpInfo )
  323. {
  324. if( helpInfo->iContextType == HELPINFO_WINDOW )
  325. {
  326. ::WinHelp( static_cast<HWND> ( helpInfo->hItemHandle ),
  327. CVY_CTXT_HELP_FILE, HELP_WM_HELP,
  328. (ULONG_PTR ) g_aHelpIDs_IDD_PORT_RULE_PROP_CLUSTER );
  329. }
  330. return TRUE;
  331. }
  332. void
  333. ClusterPortsDlg::OnContextMenu( CWnd* pWnd, CPoint point )
  334. {
  335. ::WinHelp( m_hWnd,
  336. CVY_CTXT_HELP_FILE,
  337. HELP_CONTEXTMENU,
  338. (ULONG_PTR ) g_aHelpIDs_IDD_PORT_RULE_PROP_CLUSTER );
  339. }