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.

477 lines
14 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // NetProp.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the network property sheet and pages.
  10. //
  11. // Author:
  12. // David Potter (davidp) June 9, 1997
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "CluAdmin.h"
  21. #include "NetProp.h"
  22. #include "HelpData.h"
  23. #include "ExcOper.h"
  24. #include "DDxDDv.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CNetworkPropSheet
  32. /////////////////////////////////////////////////////////////////////////////
  33. IMPLEMENT_DYNAMIC(CNetworkPropSheet, CBasePropertySheet)
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Message Maps
  36. BEGIN_MESSAGE_MAP(CNetworkPropSheet, CBasePropertySheet)
  37. //{{AFX_MSG_MAP(CNetworkPropSheet)
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. //++
  42. //
  43. // CNetworkPropSheet::CNetworkPropSheet
  44. //
  45. // Routine Description:
  46. // Constructor.
  47. //
  48. // Arguments:
  49. // pParentWnd [IN OUT] Parent window for this property sheet.
  50. // iSelectPage [IN] Page to show first.
  51. //
  52. // Return Value:
  53. // None.
  54. //
  55. //--
  56. /////////////////////////////////////////////////////////////////////////////
  57. CNetworkPropSheet::CNetworkPropSheet(
  58. IN OUT CWnd * pParentWnd,
  59. IN UINT iSelectPage
  60. )
  61. : CBasePropertySheet(pParentWnd, iSelectPage)
  62. {
  63. m_rgpages[0] = &PageGeneral();
  64. } //*** CNetworkPropSheet::CNetworkPropSheet()
  65. /////////////////////////////////////////////////////////////////////////////
  66. //++
  67. //
  68. // CNetworkPropSheet::BInit
  69. //
  70. // Routine Description:
  71. // Initialize the property sheet.
  72. //
  73. // Arguments:
  74. // pci [IN OUT] Cluster item whose properties are to be displayed.
  75. // iimgIcon [IN] Index in the large image list for the image to use
  76. // as the icon on each page.
  77. //
  78. // Return Value:
  79. // TRUE Property sheet initialized successfully.
  80. // FALSE Error initializing property sheet.
  81. //
  82. //--
  83. /////////////////////////////////////////////////////////////////////////////
  84. BOOL CNetworkPropSheet::BInit(
  85. IN OUT CClusterItem * pci,
  86. IN IIMG iimgIcon
  87. )
  88. {
  89. // Call the base class method.
  90. if (!CBasePropertySheet::BInit(pci, iimgIcon))
  91. return FALSE;
  92. // Set the read-only flag if the handles are invalid.
  93. m_bReadOnly = PciNet()->BReadOnly()
  94. || (PciNet()->Cns() == ClusterNetworkStateUnknown);
  95. return TRUE;
  96. } //*** CNetworkPropSheet::BInit()
  97. /////////////////////////////////////////////////////////////////////////////
  98. //++
  99. //
  100. // CNetworkPropSheet::Ppages
  101. //
  102. // Routine Description:
  103. // Returns the array of pages to add to the property sheet.
  104. //
  105. // Arguments:
  106. // None.
  107. //
  108. // Return Value:
  109. // Page array.
  110. //
  111. //--
  112. /////////////////////////////////////////////////////////////////////////////
  113. CBasePropertyPage ** CNetworkPropSheet::Ppages(void)
  114. {
  115. return m_rgpages;
  116. } //*** CNetworkPropSheet::Pppges()
  117. /////////////////////////////////////////////////////////////////////////////
  118. //++
  119. //
  120. // CNetworkPropSheet::Cpages
  121. //
  122. // Routine Description:
  123. // Returns the count of pages in the array.
  124. //
  125. // Arguments:
  126. // None.
  127. //
  128. // Return Value:
  129. // Count of pages in the array.
  130. //
  131. //--
  132. /////////////////////////////////////////////////////////////////////////////
  133. int CNetworkPropSheet::Cpages(void)
  134. {
  135. return sizeof(m_rgpages) / sizeof(CBasePropertyPage *);
  136. } //*** CNetworkPropSheet::Cpages()
  137. //*************************************************************************//
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CNetworkGeneralPage property page
  140. /////////////////////////////////////////////////////////////////////////////
  141. IMPLEMENT_DYNCREATE(CNetworkGeneralPage, CBasePropertyPage)
  142. /////////////////////////////////////////////////////////////////////////////
  143. // Message Maps
  144. BEGIN_MESSAGE_MAP(CNetworkGeneralPage, CBasePropertyPage)
  145. //{{AFX_MSG_MAP(CNetworkGeneralPage)
  146. ON_BN_CLICKED(IDC_PP_NET_ROLE_ENABLE_NETWORK, OnEnableNetwork)
  147. //}}AFX_MSG_MAP
  148. ON_EN_CHANGE(IDC_PP_NET_NAME, CBasePropertyPage::OnChangeCtrl)
  149. ON_EN_CHANGE(IDC_PP_NET_DESC, CBasePropertyPage::OnChangeCtrl)
  150. ON_BN_CLICKED(IDC_PP_NET_ROLE_ALL_COMM, CBasePropertyPage::OnChangeCtrl)
  151. ON_BN_CLICKED(IDC_PP_NET_ROLE_INTERNAL_ONLY, CBasePropertyPage::OnChangeCtrl)
  152. ON_BN_CLICKED(IDC_PP_NET_ROLE_CLIENT_ONLY, CBasePropertyPage::OnChangeCtrl)
  153. ON_EN_CHANGE(IDC_PP_NET_ADDRESS_MASK, CBasePropertyPage::OnChangeCtrl)
  154. END_MESSAGE_MAP()
  155. /////////////////////////////////////////////////////////////////////////////
  156. //++
  157. //
  158. // CNetworkGeneralPage::CNetworkGeneralPage
  159. //
  160. // Routine Description:
  161. // Constructor.
  162. //
  163. // Arguments:
  164. // None.
  165. //
  166. // Return Value:
  167. // None.
  168. //
  169. //--
  170. /////////////////////////////////////////////////////////////////////////////
  171. CNetworkGeneralPage::CNetworkGeneralPage(void)
  172. : CBasePropertyPage(IDD, g_aHelpIDs_IDD_PP_NET_GENERAL)
  173. {
  174. //{{AFX_DATA_INIT(CNetworkGeneralPage)
  175. m_strName = _T("");
  176. m_strDesc = _T("");
  177. m_bEnabled = FALSE;
  178. m_nRole = -1;
  179. m_strAddressMask = _T("");
  180. m_strState = _T("");
  181. //}}AFX_DATA_INIT
  182. } //*** CNetworkGeneralPage::CNetworkGeneralPage()
  183. /////////////////////////////////////////////////////////////////////////////
  184. //++
  185. //
  186. // CNetworkGeneralPage::BInit
  187. //
  188. // Routine Description:
  189. // Initialize the page.
  190. //
  191. // Arguments:
  192. // psht [IN OUT] Property sheet to which this page belongs.
  193. //
  194. // Return Value:
  195. // TRUE Page initialized successfully.
  196. // FALSE Page failed to initialize.
  197. //
  198. //--
  199. /////////////////////////////////////////////////////////////////////////////
  200. BOOL CNetworkGeneralPage::BInit(IN OUT CBaseSheet * psht)
  201. {
  202. BOOL bSuccess;
  203. ASSERT_KINDOF(CNetworkPropSheet, psht);
  204. bSuccess = CBasePropertyPage::BInit(psht);
  205. if (bSuccess)
  206. {
  207. try
  208. {
  209. m_strName = PciNet()->StrName();
  210. m_strDesc = PciNet()->StrDescription();
  211. m_cnr = PciNet()->Cnr();
  212. m_strAddressMask = PciNet()->StrAddressMask();
  213. PciNet()->GetStateName(m_strState);
  214. if (m_cnr == ClusterNetworkRoleNone)
  215. {
  216. m_bEnabled = FALSE;
  217. m_nRole = -1;
  218. } // if: network is disabled
  219. else
  220. {
  221. m_bEnabled = TRUE;
  222. if (m_cnr == ClusterNetworkRoleClientAccess)
  223. m_nRole = 0;
  224. else if (m_cnr == ClusterNetworkRoleInternalUse)
  225. m_nRole = 1;
  226. else if (m_cnr == ClusterNetworkRoleInternalAndClient)
  227. m_nRole = 2;
  228. else
  229. {
  230. ASSERT(0);
  231. m_nRole = -1;
  232. m_bEnabled = FALSE;
  233. } // else; Unknown role
  234. } // else: network not disabled
  235. } // try
  236. catch (CException * pe)
  237. {
  238. pe->ReportError();
  239. pe->Delete();
  240. bSuccess = FALSE;
  241. } // catch: CException
  242. } // if: base class method was successful
  243. return bSuccess;
  244. } //*** CNetworkGeneralPage::BInit()
  245. /////////////////////////////////////////////////////////////////////////////
  246. //++
  247. //
  248. // CNetworkGeneralPage::DoDataExchange
  249. //
  250. // Routine Description:
  251. // Do data exchange between the dialog and the class.
  252. //
  253. // Arguments:
  254. // pDX [IN OUT] Data exchange object
  255. //
  256. // Return Value:
  257. // None.
  258. //
  259. //--
  260. /////////////////////////////////////////////////////////////////////////////
  261. void CNetworkGeneralPage::DoDataExchange(CDataExchange* pDX)
  262. {
  263. CBasePropertyPage::DoDataExchange(pDX);
  264. //{{AFX_DATA_MAP(CNetworkGeneralPage)
  265. DDX_Control(pDX, IDC_PP_NET_ADDRESS_MASK, m_editAddressMask);
  266. DDX_Control(pDX, IDC_PP_NET_ROLE_ENABLE_NETWORK, m_ckbEnable);
  267. DDX_Control(pDX, IDC_PP_NET_ROLE_CLIENT_ONLY, m_rbRoleClientOnly);
  268. DDX_Control(pDX, IDC_PP_NET_ROLE_INTERNAL_ONLY, m_rbRoleInternalOnly);
  269. DDX_Control(pDX, IDC_PP_NET_ROLE_ALL_COMM, m_rbRoleAllComm);
  270. DDX_Control(pDX, IDC_PP_NET_DESC, m_editDesc);
  271. DDX_Control(pDX, IDC_PP_NET_NAME, m_editName);
  272. DDX_Text(pDX, IDC_PP_NET_NAME, m_strName);
  273. DDX_Text(pDX, IDC_PP_NET_DESC, m_strDesc);
  274. DDX_Text(pDX, IDC_PP_NET_ADDRESS_MASK, m_strAddressMask);
  275. DDX_Text(pDX, IDC_PP_NET_CURRENT_STATE, m_strState);
  276. DDX_Radio(pDX, IDC_PP_NET_ROLE_CLIENT_ONLY, m_nRole);
  277. DDX_Check(pDX, IDC_PP_NET_ROLE_ENABLE_NETWORK, m_bEnabled);
  278. //}}AFX_DATA_MAP
  279. if (pDX->m_bSaveAndValidate)
  280. {
  281. if ( ! BReadOnly() )
  282. {
  283. DDV_RequiredText(pDX, IDC_PP_NET_NAME, IDC_PP_NET_NAME_LABEL, m_strName);
  284. // Validate the name.
  285. if (!NcIsValidConnectionName(m_strName))
  286. {
  287. ThrowStaticException((IDS) IDS_INVALID_NETWORK_CONNECTION_NAME);
  288. } // if: error validating the name
  289. // Convert address and address mask.
  290. if (m_bEnabled)
  291. {
  292. switch (m_nRole)
  293. {
  294. case 0:
  295. m_cnr = ClusterNetworkRoleClientAccess;
  296. break;
  297. case 1:
  298. m_cnr = ClusterNetworkRoleInternalUse;
  299. break;
  300. case 2:
  301. m_cnr = ClusterNetworkRoleInternalAndClient;
  302. break;
  303. default:
  304. ASSERT(0);
  305. break;
  306. } // switch: m_nRole
  307. } // if: not read only
  308. } // if: network is enabled
  309. else
  310. m_cnr = ClusterNetworkRoleNone;
  311. } // if: saving data from dialog
  312. } //*** CNetworkGeneralPage::DoDataExchange()
  313. /////////////////////////////////////////////////////////////////////////////
  314. //++
  315. //
  316. // CNetworkGeneralPage::OnInitDialog
  317. //
  318. // Routine Description:
  319. // Handler for the WM_INITDIALOG message.
  320. //
  321. // Arguments:
  322. // None.
  323. //
  324. // Return Value:
  325. // TRUE Focus needs to be set.
  326. // FALSE Focus already set.
  327. //
  328. //--
  329. /////////////////////////////////////////////////////////////////////////////
  330. BOOL CNetworkGeneralPage::OnInitDialog(void)
  331. {
  332. CBasePropertyPage::OnInitDialog();
  333. // If read-only, set all controls to be either disabled or read-only.
  334. if (BReadOnly())
  335. {
  336. m_editName.SetReadOnly(TRUE);
  337. m_editDesc.SetReadOnly(TRUE);
  338. m_ckbEnable.EnableWindow(FALSE);
  339. m_rbRoleAllComm.EnableWindow(FALSE);
  340. m_rbRoleInternalOnly.EnableWindow(FALSE);
  341. m_rbRoleClientOnly.EnableWindow(FALSE);
  342. m_editAddressMask.SetReadOnly(TRUE);
  343. } // if: sheet is read-only
  344. else
  345. {
  346. m_editName.SetLimitText(NETCON_MAX_NAME_LEN);
  347. } // else: sheet is read/write
  348. OnEnableNetwork();
  349. return TRUE; // return TRUE unless you set the focus to a control
  350. // EXCEPTION: OCX Property Pages should return FALSE
  351. } //*** CNetworkGeneralPage::OnInitDialog()
  352. /////////////////////////////////////////////////////////////////////////////
  353. //++
  354. //
  355. // CNetworkGeneralPage::OnApply
  356. //
  357. // Routine Description:
  358. // Handler for when the Apply button is pressed.
  359. //
  360. // Arguments:
  361. // None.
  362. //
  363. // Return Value:
  364. // TRUE Page successfully applied.
  365. // FALSE Error applying page.
  366. //
  367. //--
  368. /////////////////////////////////////////////////////////////////////////////
  369. BOOL CNetworkGeneralPage::OnApply(void)
  370. {
  371. // Set the data from the page in the cluster item.
  372. try
  373. {
  374. CWaitCursor wc;
  375. PciNet()->SetName(m_strName);
  376. PciNet()->SetCommonProperties(
  377. m_strDesc,
  378. m_cnr
  379. );
  380. } // try
  381. catch (CException * pe)
  382. {
  383. pe->ReportError();
  384. pe->Delete();
  385. return FALSE;
  386. } // catch: CException
  387. return CBasePropertyPage::OnApply();
  388. } //*** CNetworkGeneralPage::OnApply()
  389. /////////////////////////////////////////////////////////////////////////////
  390. //++
  391. //
  392. // CNetworkGeneralPage::OnEnableNetwork
  393. //
  394. // Routine Description:
  395. // Handler for the BN_CLICKED message on the Enable network checkbox.
  396. //
  397. // Arguments:
  398. // None.
  399. //
  400. // Return Value:
  401. // None.
  402. //
  403. //--
  404. /////////////////////////////////////////////////////////////////////////////
  405. void CNetworkGeneralPage::OnEnableNetwork(void)
  406. {
  407. BOOL bEnabled;
  408. OnChangeCtrl();
  409. bEnabled = (!BReadOnly() && (m_ckbEnable.GetCheck() == BST_CHECKED));
  410. m_rbRoleAllComm.EnableWindow(bEnabled);
  411. m_rbRoleInternalOnly.EnableWindow(bEnabled);
  412. m_rbRoleClientOnly.EnableWindow(bEnabled);
  413. GetDlgItem(IDC_PP_NET_ROLE_CAPTION)->EnableWindow(bEnabled);
  414. if ( bEnabled
  415. && (m_rbRoleAllComm.GetCheck() != BST_CHECKED)
  416. && (m_rbRoleInternalOnly.GetCheck() != BST_CHECKED)
  417. && (m_rbRoleClientOnly.GetCheck() != BST_CHECKED))
  418. {
  419. m_rbRoleAllComm.SetCheck(BST_CHECKED);
  420. } // if:
  421. if ( ! bEnabled )
  422. {
  423. m_cnr = ClusterNetworkRoleNone;
  424. } // if:
  425. } //*** CNetworkGeneralPage::OnEnableNetwork()