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.

317 lines
10 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #include "private.h"
  4. #include "PortsPage.h"
  5. #include "HostPortsDlg.h"
  6. BEGIN_MESSAGE_MAP(HostPortsDlg, CDialog)
  7. ON_BN_CLICKED(IDC_CHECK_EQUAL, OnCheckEqualLoad)
  8. ON_WM_HELPINFO()
  9. ON_WM_CONTEXTMENU()
  10. END_MESSAGE_MAP()
  11. HostPortsDlg::HostPortsDlg( PortsPage::PortData& portData,
  12. ENGINEHANDLE ehCluster, // OPTIONAL
  13. CWnd* parent
  14. )
  15. :
  16. m_portData( portData ),
  17. m_ehCluster( ehCluster ),
  18. CDialog( HostPortsDlg::IDD, parent )
  19. {
  20. m_parent = (PortsPage *) parent;
  21. }
  22. void
  23. HostPortsDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange( pDX );
  26. DDX_Control(pDX, IDC_EDIT_SINGLE, m_priority);
  27. DDX_Control(pDX, IDC_EDIT_PORT_RULE_VIP, ipAddress);
  28. }
  29. BOOL
  30. HostPortsDlg::OnInitDialog()
  31. {
  32. CDialog::OnInitDialog();
  33. SetControlData();
  34. return TRUE;
  35. }
  36. void
  37. HostPortsDlg::OnOK()
  38. {
  39. wchar_t buffer[Common::BUF_SIZE];
  40. //
  41. // The only thing which potentially could change
  42. // is the load weight if mode is multiple and the priority
  43. // if mode is single.
  44. //
  45. // set the new port rule.
  46. if( m_portData.mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_MULTIPLE ))
  47. {
  48. BOOL fEqualLoad = FALSE;
  49. if (::IsDlgButtonChecked (m_hWnd, IDC_CHECK_EQUAL))
  50. {
  51. fEqualLoad = TRUE;
  52. m_portData.load = GETRESOURCEIDSTRING( IDS_REPORT_LOAD_EQUAL );
  53. }
  54. if(!fEqualLoad)
  55. {
  56. // set the load here.
  57. BOOL fError;
  58. int weight = ::GetDlgItemInt (m_hWnd, IDC_EDIT_MULTI, &fError, FALSE);
  59. if( fError == FALSE )
  60. {
  61. // some problem with the data input.
  62. // it has been left blank.
  63. StringCbPrintf( buffer, sizeof(buffer), GETRESOURCEIDSTRING( IDS_PARM_LOAD_BLANK ), CVY_MIN_LOAD, CVY_MAX_LOAD);
  64. MessageBox( buffer,
  65. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  66. MB_ICONSTOP | MB_OK );
  67. return;
  68. }
  69. if( !( weight >= CVY_MIN_LOAD
  70. &&
  71. weight <= CVY_MAX_LOAD )
  72. )
  73. {
  74. // the weight value is not in valid range.
  75. // These controls are all screwed up, even
  76. // after setting the limits we need to all
  77. // this checking, it is amazing!!!
  78. //
  79. StringCbPrintf( buffer, sizeof(buffer), GETRESOURCEIDSTRING( IDS_PARM_LOAD ), CVY_MIN_LOAD,CVY_MAX_LOAD );
  80. MessageBox( buffer,
  81. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  82. MB_ICONSTOP | MB_OK );
  83. return;
  84. }
  85. StringCbPrintf( buffer, sizeof(buffer), L"%d", weight );
  86. m_portData.load = buffer;
  87. }
  88. }
  89. else if( m_portData.mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_SINGLE ) )
  90. {
  91. ::GetDlgItemText(m_hWnd, IDC_EDIT_SINGLE, buffer, Common::BUF_SIZE );
  92. m_portData.priority = buffer;
  93. }
  94. EndDialog( IDOK );
  95. }
  96. void
  97. HostPortsDlg::SetControlData()
  98. {
  99. // set ranges.
  100. ::SendDlgItemMessage(m_hWnd, IDC_EDIT_MULTI, EM_SETLIMITTEXT, 3, 0);
  101. ::SendDlgItemMessage(m_hWnd, IDC_SPIN_MULTI, UDM_SETRANGE32, CVY_MIN_LOAD, CVY_MAX_LOAD);
  102. ::SendDlgItemMessage(m_hWnd, IDC_EDIT_SINGLE, EM_SETLIMITTEXT, 2, 0);
  103. ::SendDlgItemMessage(m_hWnd, IDC_SPIN_SINGLE, UDM_SETRANGE32, CVY_MIN_MAX_HOSTS, CVY_MAX_MAX_HOSTS);
  104. // set the vip.
  105. ::EnableWindow(GetDlgItem (IDC_EDIT_PORT_RULE_VIP)->m_hWnd, FALSE);
  106. if (!lstrcmpi(m_portData.virtual_ip_addr, GETRESOURCEIDSTRING(IDS_REPORT_VIP_ALL))) {
  107. ::CheckDlgButton(m_hWnd, IDC_CHECK_PORT_RULE_ALL_VIP, BST_CHECKED);
  108. } else {
  109. CommonUtils::fillCIPAddressCtrlString(ipAddress, m_portData.virtual_ip_addr);
  110. ::CheckDlgButton(m_hWnd, IDC_CHECK_PORT_RULE_ALL_VIP, BST_UNCHECKED);
  111. }
  112. // set the ports
  113. ::SetDlgItemInt (m_hWnd, IDC_EDIT_START, _wtoi( m_portData.start_port), FALSE);
  114. ::SetDlgItemInt (m_hWnd, IDC_EDIT_END, _wtoi( m_portData.end_port ), FALSE);
  115. // set the protocol.
  116. if( m_portData.protocol == GETRESOURCEIDSTRING(IDS_REPORT_PROTOCOL_TCP) )
  117. {
  118. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_CHECKED );
  119. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_UNCHECKED );
  120. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_UNCHECKED );
  121. }
  122. else if( m_portData.protocol == GETRESOURCEIDSTRING(IDS_REPORT_PROTOCOL_UDP) )
  123. {
  124. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_UNCHECKED );
  125. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_CHECKED );
  126. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_UNCHECKED );
  127. }
  128. else
  129. {
  130. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_UNCHECKED );
  131. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_UNCHECKED );
  132. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_CHECKED );
  133. }
  134. // set the mode.
  135. if( m_portData.mode == GETRESOURCEIDSTRING(IDS_REPORT_MODE_MULTIPLE) )
  136. {
  137. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_CHECKED );
  138. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_UNCHECKED );
  139. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_UNCHECKED );
  140. :: EnableWindow (GetDlgItem (IDC_CHECK_EQUAL)->m_hWnd, TRUE);
  141. if (m_portData.load == GETRESOURCEIDSTRING(IDS_REPORT_LOAD_EQUAL))
  142. {
  143. ::CheckDlgButton( m_hWnd, IDC_CHECK_EQUAL, BST_CHECKED );
  144. ::SetDlgItemInt (m_hWnd, IDC_EDIT_MULTI, 50, FALSE);
  145. }
  146. else
  147. {
  148. ::CheckDlgButton( m_hWnd, IDC_CHECK_EQUAL, BST_UNCHECKED );
  149. ::SetDlgItemInt (m_hWnd, IDC_EDIT_MULTI, _wtoi( m_portData.load), FALSE);
  150. :: EnableWindow (GetDlgItem (IDC_TEXT_MULTI)->m_hWnd, TRUE);
  151. :: EnableWindow (GetDlgItem (IDC_EDIT_MULTI)->m_hWnd, TRUE);
  152. :: EnableWindow (GetDlgItem (IDC_SPIN_MULTI)->m_hWnd, TRUE);
  153. }
  154. if( m_portData.affinity == GETRESOURCEIDSTRING(IDS_REPORT_AFFINITY_NONE ) )
  155. {
  156. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_CHECKED );
  157. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_UNCHECKED );
  158. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  159. }
  160. else if ( m_portData.affinity == GETRESOURCEIDSTRING(IDS_REPORT_AFFINITY_SINGLE) )
  161. {
  162. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  163. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_CHECKED );
  164. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  165. }
  166. else
  167. {
  168. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  169. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_UNCHECKED );
  170. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_CHECKED );
  171. }
  172. }
  173. else if( m_portData.mode == GETRESOURCEIDSTRING(IDS_REPORT_MODE_SINGLE) )
  174. {
  175. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_UNCHECKED );
  176. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_CHECKED );
  177. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_UNCHECKED );
  178. BOOL fError;
  179. // fill in priority.
  180. wchar_t buf[Common::BUF_SIZE];
  181. ULONG availPriorities = 0xffffffff;
  182. UINT CurrentPriority = _wtoi(m_portData.priority);
  183. WLBS_PORT_RULE Rule;
  184. ZeroMemory(&Rule, sizeof(Rule));
  185. ARRAYSTRCPY(Rule.virtual_ip_addr, m_portData.virtual_ip_addr);
  186. Rule.start_port = _wtoi(m_portData.start_port);
  187. Rule.mode = CVY_SINGLE;
  188. NLBERROR nerr;
  189. nerr = gEngine.GetAvailablePortRulePriorities(
  190. m_ehCluster,
  191. 1,
  192. &Rule,
  193. &availPriorities
  194. );
  195. if (NLBFAILED(nerr))
  196. {
  197. availPriorities = 0xffffffff;
  198. }
  199. if (CurrentPriority>0 && CurrentPriority<=32)
  200. {
  201. availPriorities |= (((ULONG)1)<<(CurrentPriority-1));
  202. }
  203. // Delete any current entries in the priorities combobox
  204. {
  205. int iLeft;
  206. do
  207. {
  208. iLeft = m_priority.DeleteString(0);
  209. } while(iLeft != 0 && iLeft != CB_ERR);
  210. }
  211. for(ULONG u=0; u<32; u++)
  212. {
  213. if (availPriorities & (((ULONG)1)<<u))
  214. {
  215. StringCbPrintf( buf, sizeof(buf), L"%d", (u+1));
  216. m_priority.AddString( buf );
  217. if (CurrentPriority == 0)
  218. {
  219. CurrentPriority = u+1; // let's pick the first available one.
  220. }
  221. }
  222. }
  223. // set selection to present hostid
  224. StringCbPrintf( buf, sizeof(buf), L"%d", CurrentPriority);
  225. m_priority.SelectString( -1, buf );
  226. :: EnableWindow (GetDlgItem (IDC_TEXT_SINGLE)->m_hWnd, TRUE);
  227. :: EnableWindow (GetDlgItem (IDC_EDIT_SINGLE)->m_hWnd, TRUE);
  228. }
  229. }
  230. BOOL
  231. HostPortsDlg::OnHelpInfo (HELPINFO* helpInfo )
  232. {
  233. if( helpInfo->iContextType == HELPINFO_WINDOW )
  234. {
  235. ::WinHelp( static_cast<HWND> ( helpInfo->hItemHandle ),
  236. CVY_CTXT_HELP_FILE, HELP_WM_HELP,
  237. (ULONG_PTR ) g_aHelpIDs_IDD_PORT_RULE_PROP_HOSTS );
  238. }
  239. return TRUE;
  240. }
  241. void
  242. HostPortsDlg::OnContextMenu( CWnd* pWnd, CPoint point )
  243. {
  244. ::WinHelp( m_hWnd,
  245. CVY_CTXT_HELP_FILE,
  246. HELP_CONTEXTMENU,
  247. (ULONG_PTR ) g_aHelpIDs_IDD_PORT_RULE_PROP_HOSTS );
  248. }
  249. void HostPortsDlg::OnCheckEqualLoad()
  250. //
  251. // If the equal-load checkbox is Checked
  252. // Enable the load-weight controls
  253. // else
  254. // Disable the controls
  255. //
  256. {
  257. BOOL fEnable = FALSE;
  258. fEnable = !::IsDlgButtonChecked(m_hWnd, IDC_CHECK_EQUAL);
  259. :: EnableWindow (GetDlgItem (IDC_TEXT_MULTI)->m_hWnd, fEnable);
  260. :: EnableWindow (GetDlgItem (IDC_EDIT_MULTI)->m_hWnd, fEnable);
  261. :: EnableWindow (GetDlgItem (IDC_SPIN_MULTI)->m_hWnd, fEnable);
  262. }