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.

1615 lines
45 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1997.
  5. //
  6. // File: epprops.cpp
  7. //
  8. // Contents: Implements the classes CEndpointDetails which manage the
  9. // Endpoint properties dialog.
  10. //
  11. // Classes:
  12. //
  13. // Methods:
  14. //
  15. // History: 03-Dec-96 RonanS Created.
  16. //
  17. //----------------------------------------------------------------------
  18. #include "stdafx.h"
  19. #include "olecnfg.h"
  20. #include "Epoptppg.h"
  21. #include "Epprops.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CEndpointData
  29. //
  30. // The CEndpointData object is used to hold information about a users choices for
  31. // a specific protocol and endpoint combination.
  32. // Each endpoint will also contain an user readable description to be displayed in
  33. // protocol lists and user displays
  34. IMPLEMENT_DYNAMIC(CEndpointData, CObject)
  35. // change this to point to index of ncacn_ip_tcp or other default protocol
  36. #define TCP_INDEX 4
  37. ProtocolDesc aProtocols [] =
  38. {
  39. { _T("*"), // default system protocols
  40. IDS_EPDESC_DEFAULT,
  41. ProtocolDesc::ef_IpPortNum,
  42. IDS_INETADDR,
  43. IDS_INETPORT ,
  44. TRUE,
  45. TRUE
  46. },
  47. { _T("ncacn_nb_tcp"),
  48. IDS_EPDESC_NCACN_NB_TCP,
  49. ProtocolDesc::ef_Integer255,
  50. IDS_NTMACHINENAME,
  51. IDS_INTEGER255,
  52. FALSE,
  53. FALSE
  54. },
  55. { _T("ncacn_nb_ipx"),
  56. IDS_EPDESC_NCACN_NB_IPX,
  57. ProtocolDesc::ef_Integer255,
  58. IDS_NTMACHINENAME,
  59. IDS_INTEGER255 ,
  60. FALSE,
  61. TRUE
  62. },
  63. { _T("ncacn_nb_nb"),
  64. IDS_EPDESC_NCACN_NB_NB,
  65. ProtocolDesc::ef_Integer255,
  66. IDS_NTMACHINENAME,
  67. IDS_INTEGER255 ,
  68. FALSE,
  69. TRUE
  70. },
  71. { _T("ncacn_ip_tcp"),
  72. IDS_EPDESC_NCACN_IP_TCP,
  73. ProtocolDesc::ef_IpPortNum,
  74. IDS_INETADDR,
  75. IDS_INETPORT ,
  76. TRUE,
  77. TRUE
  78. },
  79. { _T("ncacn_np"),
  80. IDS_EPDESC_NCACN_NP,
  81. ProtocolDesc::ef_NamedPipe,
  82. IDS_NTSERVER,
  83. IDS_NAMEDPIPE ,
  84. FALSE,
  85. FALSE
  86. },
  87. { _T("ncacn_spx"),
  88. IDS_EPDESC_NCACN_SPX,
  89. ProtocolDesc::ef_Integer,
  90. IDS_IPXINETADDR,
  91. IDS_INTEGER ,
  92. FALSE,
  93. TRUE
  94. },
  95. { _T("ncacn_dnet_nsp"),
  96. IDS_EPDESC_NCACN_DNET_NSP,
  97. ProtocolDesc::ef_DecNetObject,
  98. IDS_DECNET,
  99. IDS_DECNETOBJECT ,
  100. FALSE,
  101. FALSE
  102. },
  103. { _T("ncacn_at_dsp"),
  104. IDS_EPDESC_NCACN_AT_DSP,
  105. ProtocolDesc::ef_Char22,
  106. IDS_APPLETALK,
  107. IDS_ATSTRING ,
  108. FALSE,
  109. FALSE
  110. },
  111. { _T("ncacn_vnns_spp"),
  112. IDS_EPDESC_NCACN_VNNS_SPP,
  113. ProtocolDesc::ef_VinesSpPort,
  114. IDS_VINES,
  115. IDS_VINESPORT ,
  116. FALSE,
  117. FALSE
  118. },
  119. { _T("ncadg_ip_udp"),
  120. IDS_EPDESC_NCADG_IP_UDP,
  121. ProtocolDesc::ef_IpPortNum,
  122. IDS_INETADDR,
  123. IDS_INETPORT ,
  124. TRUE,
  125. TRUE
  126. },
  127. { _T("ncadg_ipx"),
  128. IDS_EPDESC_NCADG_IPX,
  129. ProtocolDesc::ef_Integer,
  130. IDS_IPXINETADDR,
  131. IDS_INTEGER ,
  132. FALSE,
  133. TRUE
  134. },
  135. { _T("ncacn_http"),
  136. IDS_EPDESC_NCACN_HTTP,
  137. ProtocolDesc::ef_IpPortNum,
  138. IDS_INETADDR,
  139. IDS_INETPORT ,
  140. TRUE ,
  141. TRUE
  142. },
  143. };
  144. //+-------------------------------------------------------------------------
  145. //
  146. // Member: CEndpointData::CEndpointData
  147. //
  148. // Synopsis: Constructor
  149. //
  150. // Arguments: None
  151. //
  152. // Returns: Nothing
  153. //
  154. // Algorithm: N/A
  155. //
  156. // History: 02-Dec-96 Ronans Created
  157. //
  158. //--------------------------------------------------------------------------
  159. CEndpointData::CEndpointData(LPCTSTR szProtseq, EndpointFlags nDynamic, LPCTSTR szEndpoint)
  160. : m_szProtseq(szProtseq), m_nDynamicFlags(nDynamic), m_szEndpoint(szEndpoint)
  161. {
  162. int i = FindProtocol(szProtseq);
  163. if (i != (-1))
  164. m_pProtocol = (&aProtocols[i]);
  165. else
  166. m_pProtocol = NULL;
  167. }
  168. //+-------------------------------------------------------------------------
  169. //
  170. // Member: CEndpointData::CEndpointData
  171. //
  172. // Synopsis: Constructor
  173. //
  174. // Arguments: None
  175. //
  176. // Returns: Nothing
  177. //
  178. // Algorithm: N/A
  179. //
  180. // History: 02-Dec-96 Ronans Created
  181. //
  182. //--------------------------------------------------------------------------
  183. CEndpointData::CEndpointData()
  184. {
  185. m_szProtseq = aProtocols[0].pszProtseq;
  186. m_nDynamicFlags = edUseStaticEP;
  187. m_pProtocol = &aProtocols[0];
  188. }
  189. BOOL CEndpointData::GetDescription(CString &rsDesc)
  190. {
  191. if (m_pProtocol)
  192. {
  193. rsDesc .LoadString(m_pProtocol -> nResidDesc);
  194. return TRUE;
  195. }
  196. return FALSE;
  197. }
  198. BOOL CEndpointData::AllowGlobalProperties()
  199. {
  200. if (m_pProtocol)
  201. {
  202. return m_pProtocol -> bAllowDynamic;
  203. }
  204. return FALSE;
  205. }
  206. /////////////////////////////////////////////////////////////////////////////
  207. // CEndpointDetails dialog
  208. //
  209. // The CEndpointDetails dialog is used for adding or modifying an existing endpoint
  210. //
  211. //+-------------------------------------------------------------------------
  212. //
  213. // Member: CEndpointDetails::CEndpointDetails
  214. //
  215. // Synopsis: Constructor
  216. //
  217. // Arguments:
  218. // CWnd* pParent The parent window
  219. //
  220. // Returns: Nothing
  221. //
  222. // Algorithm: N/A
  223. //
  224. // History: 02-Dec-96 Ronans Created
  225. //
  226. //--------------------------------------------------------------------------
  227. CEndpointDetails::CEndpointDetails(CWnd* pParent /*=NULL*/)
  228. : CDialog(CEndpointDetails::IDD, pParent)
  229. {
  230. //{{AFX_DATA_INIT(CEndpointDetails)
  231. m_szEndpoint = _T("");
  232. m_nDynamic = -1;
  233. //}}AFX_DATA_INIT
  234. m_nProtocolIndex = -1;
  235. m_opTask = opAddProtocol;
  236. m_pCurrentEPData = NULL;
  237. m_nDynamic = (int) rbiDefault;
  238. }
  239. //+-------------------------------------------------------------------------
  240. //
  241. // Member: CEndpointDetails::SetOperation
  242. //
  243. // Synopsis: Sets the operation to one of update or add new data
  244. // This method determines whether the dialog is being
  245. // used to select a new end point or modify an existing one
  246. //
  247. // Arguments:
  248. // opTask The operation to select
  249. //
  250. // Returns: Nothing
  251. //
  252. // Algorithm: N/A
  253. //
  254. // History: 02-Dec-96 Ronans Created
  255. //
  256. //--------------------------------------------------------------------------
  257. void CEndpointDetails::SetOperation ( operation opTask )
  258. {
  259. m_opTask = opTask;
  260. }
  261. BOOL isNumericCStr(CString &rString)
  262. {
  263. int i = 0;
  264. for (i = 0; i < rString.GetLength(); i++)
  265. {
  266. if ((rString[i] < TEXT('0')) || (rString[i] > TEXT('9')))
  267. return FALSE;
  268. }
  269. return TRUE;
  270. }
  271. void ReportEndpointError(CDataExchange *pDX, int nProtocol)
  272. {
  273. if (nProtocol != -1)
  274. {
  275. CString sTmpTemplate, sTmpSpecific, sTmpOverall;
  276. sTmpTemplate.LoadString(IDS_ERR_ENDPOINT);
  277. sTmpSpecific.LoadString(aProtocols[nProtocol].nEndpointTip);
  278. sTmpOverall.Format(sTmpTemplate, (LPCTSTR)sTmpSpecific);
  279. AfxMessageBox(sTmpOverall, MB_OK | MB_ICONEXCLAMATION);
  280. pDX -> Fail();
  281. }
  282. }
  283. void PASCAL DDV_ValidateEndpoint(CDataExchange* pDX, int nProtocol, CEndpointDetails::btnOrder bo, CString & rszEndpoint)
  284. {
  285. if (pDX -> m_bSaveAndValidate)
  286. {
  287. rszEndpoint.TrimLeft();
  288. rszEndpoint.TrimRight();
  289. // a non empty endpoint is only acceptable when choosing a static endpoint
  290. if (!rszEndpoint.IsEmpty())
  291. {
  292. if (bo == CEndpointDetails::rbiStatic)
  293. {
  294. if (nProtocol!= -1)
  295. {
  296. switch (aProtocols[nProtocol].nEndpFmt)
  297. {
  298. case ProtocolDesc::ef_Integer255:
  299. if (!isNumericCStr(rszEndpoint))
  300. ReportEndpointError(pDX, nProtocol);
  301. if (_ttol((LPCTSTR)rszEndpoint) > 255)
  302. ReportEndpointError(pDX, nProtocol);
  303. break;
  304. case ProtocolDesc::ef_IpPortNum:
  305. if (!isNumericCStr(rszEndpoint))
  306. ReportEndpointError(pDX, nProtocol);
  307. if (_ttol((LPCTSTR)rszEndpoint) > 65535)
  308. ReportEndpointError(pDX, nProtocol);
  309. break;
  310. case ProtocolDesc::ef_Integer:
  311. if (!isNumericCStr(rszEndpoint))
  312. ReportEndpointError(pDX, nProtocol);
  313. break;
  314. case ProtocolDesc::ef_Char22:
  315. if (rszEndpoint.GetLength() > 22)
  316. ReportEndpointError(pDX, nProtocol);
  317. break;
  318. case ProtocolDesc::ef_VinesSpPort:
  319. case ProtocolDesc::ef_sAppService:
  320. case ProtocolDesc::ef_NamedPipe:
  321. case ProtocolDesc::ef_DecNetObject:
  322. default:
  323. // no validation
  324. break;
  325. }
  326. }
  327. return;
  328. }
  329. else
  330. ReportEndpointError(pDX, nProtocol);
  331. }
  332. else
  333. {
  334. if (bo == CEndpointDetails::rbiStatic)
  335. ReportEndpointError(pDX, nProtocol);
  336. }
  337. }
  338. }
  339. //+-------------------------------------------------------------------------
  340. //
  341. // Member: CEndpointDetails::DoDataExchange
  342. //
  343. // Synopsis: Performs standard dialog data exchange
  344. //
  345. // Arguments:
  346. // CDataExchange* pDx The data exchange object
  347. //
  348. // Returns: Nothing
  349. //
  350. // Algorithm: N/A
  351. //
  352. // History: 02-Dec-96 Ronans Created
  353. //
  354. //--------------------------------------------------------------------------
  355. void CEndpointDetails::DoDataExchange(CDataExchange* pDX)
  356. {
  357. if (!pDX -> m_bSaveAndValidate)
  358. {
  359. switch(m_nDynamicFlags)
  360. {
  361. case CEndpointData::edDisableEP:
  362. m_nDynamic = rbiDisable;
  363. break;
  364. case CEndpointData::edUseStaticEP:
  365. if (m_szEndpoint.IsEmpty())
  366. m_nDynamic = rbiDefault;
  367. else
  368. m_nDynamic = rbiStatic;
  369. break;
  370. case CEndpointData::edUseIntranetEP:
  371. m_nDynamic = rbiIntranet;
  372. break;
  373. case CEndpointData::edUseInternetEP:
  374. m_nDynamic = rbiInternet;
  375. break;
  376. }
  377. }
  378. CDialog::DoDataExchange(pDX);
  379. //{{AFX_DATA_MAP(CEndpointDetails)
  380. DDX_Control(pDX, IDC_EPDISABLE, m_rbDisableEP);
  381. DDX_Control(pDX, IDC_SPROTSEQ, m_stProtseq);
  382. DDX_Control(pDX, IDC_SINSTRUCTIONS, m_stInstructions);
  383. DDX_Control(pDX, IDC_EENDPOINT, m_edtEndpoint);
  384. DDX_Control(pDX, IDC_EPSTATICEP, m_rbStaticEP);
  385. DDX_Control(pDX, IDC_CBPROTSEQ, m_cbProtseq);
  386. DDX_Radio(pDX, IDC_EPDISABLE, m_nDynamic);
  387. //}}AFX_DATA_MAP
  388. DDX_Text(pDX, IDC_EENDPOINT, m_szEndpoint);
  389. if(((btnOrder)m_nDynamic) == rbiStatic)
  390. DDV_ValidateEndpoint(pDX, m_nProtocolIndex, (btnOrder)m_nDynamic, m_szEndpoint);
  391. DDX_Control(pDX, IDC_EPDYNAMIC_INTER, m_rbDynamicInternet);
  392. DDX_Control(pDX, IDC_EPDYNAMIC_INTRA, m_rbDynamicIntranet);
  393. if (pDX -> m_bSaveAndValidate)
  394. switch((btnOrder)m_nDynamic)
  395. {
  396. case rbiDisable:
  397. m_nDynamicFlags = CEndpointData::edDisableEP;
  398. break;
  399. case rbiDefault:
  400. case rbiStatic:
  401. m_nDynamicFlags = CEndpointData::edUseStaticEP;
  402. break;
  403. case rbiIntranet:
  404. m_nDynamicFlags = CEndpointData::edUseIntranetEP;
  405. break;
  406. case rbiInternet:
  407. m_nDynamicFlags = CEndpointData::edUseInternetEP;
  408. break;
  409. }
  410. }
  411. BEGIN_MESSAGE_MAP(CEndpointDetails, CDialog)
  412. //{{AFX_MSG_MAP(CEndpointDetails)
  413. ON_CBN_SELCHANGE(IDC_CBPROTSEQ, OnChooseProtocol)
  414. ON_BN_CLICKED(IDC_EPDYNAMIC_INTER, OnEndpointAssignment)
  415. ON_BN_CLICKED(IDC_EPDYNAMIC_INTRA, OnEndpointAssignment)
  416. ON_BN_CLICKED(IDC_EPSTATICEP, OnEndpointAssignmentStatic)
  417. ON_BN_CLICKED(IDC_EPDISABLE, OnEndpointAssignment)
  418. ON_BN_CLICKED(IDC_EPDYNAMIC_DEFAULT, OnEndpointAssignment)
  419. ON_WM_HELPINFO()
  420. //}}AFX_MSG_MAP
  421. END_MESSAGE_MAP()
  422. /////////////////////////////////////////////////////////////////////////////
  423. // CEndpointDetails message handlers
  424. int FindProtocol(LPCTSTR lpszProtSeq)
  425. {
  426. int i = 0;
  427. while(i < sizeof(aProtocols) / sizeof(ProtocolDesc))
  428. {
  429. if (lstrcmp(lpszProtSeq, aProtocols[i].pszProtseq) == 0)
  430. return i;
  431. i++;
  432. }
  433. return -1;
  434. }
  435. //+-------------------------------------------------------------------------
  436. //
  437. // Member: CEndpointDetails::OnInitDialog
  438. //
  439. // Synopsis: Called by MFC when the dialog message WM_INITDIALOG is recieved.
  440. // Used to initialise the dialog state
  441. //
  442. // Arguments: None
  443. //
  444. // Returns: TRUE - to set focus to the default push button
  445. // FALSE - if focus has been set to some other control.
  446. //
  447. // Algorithm: N/A
  448. //
  449. // History: 02-Dec-96 Ronans Created
  450. //
  451. //--------------------------------------------------------------------------
  452. BOOL CEndpointDetails::OnInitDialog()
  453. {
  454. CDialog::OnInitDialog();
  455. int i = 0;
  456. int index = 0;
  457. int defaultItem = -1;
  458. // initialise combobox with list of protocols
  459. for (i = 1; i < sizeof(aProtocols) / sizeof(ProtocolDesc); i++)
  460. {
  461. if (aProtocols[i].m_bSupportedInCOM)
  462. {
  463. CString tmp((LPCTSTR) UIntToPtr( aProtocols[i].nResidDesc )); // get string from resource
  464. index = m_cbProtseq.AddString(tmp);
  465. if (index >= 0)
  466. m_cbProtseq.SetItemData(index, (DWORD)i);
  467. if (m_nProtocolIndex != -1)
  468. {
  469. if (i == m_nProtocolIndex)
  470. defaultItem = index;
  471. }
  472. else if (i == TCP_INDEX)
  473. {
  474. m_nProtocolIndex = i;
  475. defaultItem = index;
  476. }
  477. }
  478. }
  479. // set up prompt and instructions for dialog
  480. if (m_opTask == opAddProtocol)
  481. {
  482. CString sInstructions((LPCTSTR)IDS_INSTRUCTIONS_ADDPROTOCOL) ;
  483. CString sCaption((LPCTSTR) IDS_CAPTION_ADDPROTOCOL);
  484. m_stInstructions.SetWindowText(sInstructions);
  485. SetWindowText(sCaption);
  486. m_stProtseq.ShowWindow(SW_HIDE);
  487. }
  488. else
  489. {
  490. CString sInstructions((LPCTSTR)IDS_INSTRUCTIONS_UPDATEPROTOCOL) ;
  491. CString sCaption((LPCTSTR) IDS_CAPTION_UPDATEPROTOCOL);
  492. m_stInstructions.SetWindowText(sInstructions);
  493. SetWindowText(sCaption);
  494. m_cbProtseq.ShowWindow(SW_HIDE);
  495. m_cbProtseq.EnableWindow(FALSE);
  496. }
  497. // default to tcpip - unless we are updating an existing
  498. // protocol
  499. if (m_nProtocolIndex != (-1))
  500. m_cbProtseq.SetCurSel(defaultItem);
  501. UpdateProtocolUI();
  502. m_edtEndpoint.EnableWindow(((btnOrder)m_nDynamic) == rbiStatic);
  503. return TRUE; // return TRUE unless you set the focus to a control
  504. }
  505. //+-------------------------------------------------------------------------
  506. //
  507. // Member: OnChooseProtocol
  508. //
  509. // Synopsis: Updates UI after protocol has been chosen
  510. //
  511. // Arguments: None
  512. //
  513. // Returns: Nothing
  514. //
  515. // Algorithm: N/A
  516. //
  517. // History: 02-Dec-96 Ronans Created
  518. //
  519. //--------------------------------------------------------------------------
  520. void CEndpointDetails::OnChooseProtocol()
  521. {
  522. int sel = m_cbProtseq.GetCurSel();
  523. if (sel >= 0)
  524. {
  525. m_nProtocolIndex = (int) m_cbProtseq.GetItemData(sel);
  526. m_nDynamic = (int) rbiDefault;
  527. m_szEndpoint.Empty();
  528. UpdateProtocolUI();
  529. UpdateData(FALSE);
  530. }
  531. }
  532. //+-------------------------------------------------------------------------
  533. //
  534. // Member: OnEndpointAssignment
  535. //
  536. // Synopsis: Handles radio buttons for endpoint assignment
  537. //
  538. // Arguments: None
  539. //
  540. // Returns: Nothing
  541. //
  542. // Algorithm: N/A
  543. //
  544. // History: 02-Dec-96 Ronans Created
  545. //
  546. //--------------------------------------------------------------------------
  547. void CEndpointDetails::OnEndpointAssignment()
  548. {
  549. int i = m_nDynamic;
  550. if (m_edtEndpoint.IsWindowEnabled())
  551. {
  552. m_szEndpoint.Empty();
  553. m_edtEndpoint.SetWindowText(NULL);
  554. m_edtEndpoint.EnableWindow(FALSE);
  555. }
  556. }
  557. //+-------------------------------------------------------------------------
  558. //
  559. // Member: OnEndpointAssignmentStatic
  560. //
  561. // Synopsis: Handles radio buttons for endpoint assignment
  562. //
  563. // Arguments: None
  564. //
  565. // Returns: Nothing
  566. //
  567. // Algorithm: N/A
  568. //
  569. // History: 02-Dec-96 Ronans Created
  570. //
  571. //--------------------------------------------------------------------------
  572. void CEndpointDetails::OnEndpointAssignmentStatic()
  573. {
  574. int i = m_nDynamic;
  575. if (!m_edtEndpoint.IsWindowEnabled())
  576. {
  577. m_szEndpoint.Empty();
  578. m_edtEndpoint.SetWindowText(NULL);
  579. m_edtEndpoint.EnableWindow(TRUE);
  580. }
  581. }
  582. //+-------------------------------------------------------------------------
  583. //
  584. // Member: GetEndpointData
  585. //
  586. // Synopsis: Fills out CEndpointData structure according to current selections
  587. //
  588. // Arguments: CEndpointData * Pointer to CEndpointData structure to fill out
  589. //
  590. // Returns: CEndpointData * Pointer to filled out CEndpointData *
  591. //
  592. // Algorithm: N/A
  593. //
  594. // History: 02-Dec-96 Ronans Created
  595. //
  596. //--------------------------------------------------------------------------
  597. CEndpointData* CEndpointDetails::GetEndpointData(CEndpointData *pData)
  598. {
  599. if (m_nProtocolIndex != -1)
  600. pData -> m_pProtocol = &aProtocols[m_nProtocolIndex];
  601. else
  602. pData -> m_pProtocol = NULL;
  603. pData -> m_szProtseq = aProtocols[m_nProtocolIndex].pszProtseq;
  604. pData -> m_nDynamicFlags = m_nDynamicFlags;
  605. pData -> m_szEndpoint = m_szEndpoint;
  606. return pData;
  607. }
  608. //+-------------------------------------------------------------------------
  609. //
  610. // Member: SetEndpointData
  611. //
  612. // Synopsis: Sets endpoint data for updating
  613. //
  614. // Arguments: pData The endpoint to update
  615. //
  616. // Returns: Nothing
  617. //
  618. // Algorithm: N/A
  619. //
  620. // History: 02-Dec-96 Ronans Created
  621. //
  622. //--------------------------------------------------------------------------
  623. void CEndpointDetails::SetEndpointData(CEndpointData* pData)
  624. {
  625. ASSERT(pData != NULL);
  626. m_pCurrentEPData = pData;
  627. if (pData)
  628. {
  629. m_nDynamicFlags = pData -> m_nDynamicFlags;
  630. m_nDynamic = (int)(pData -> m_nDynamicFlags);
  631. m_szEndpoint = pData -> m_szEndpoint;
  632. m_nProtocolIndex = FindProtocol(pData -> m_szProtseq);
  633. }
  634. else
  635. {
  636. m_nDynamicFlags = CEndpointData::edUseStaticEP;
  637. m_szEndpoint .Empty();
  638. }
  639. }
  640. //+-------------------------------------------------------------------------
  641. //
  642. // Member: CEndpointDetails::UpdateProtocolUI
  643. //
  644. // Synopsis: Updates protocol UI based on m_nProtocolIndex and m_pCurrentData
  645. //
  646. // Arguments: None
  647. //
  648. // Returns: Nothing
  649. //
  650. // Algorithm: N/A
  651. //
  652. // History: 08-Jan-97 Ronans Created
  653. //
  654. //--------------------------------------------------------------------------
  655. void CEndpointDetails::UpdateProtocolUI()
  656. {
  657. ASSERT(m_nProtocolIndex >= 0);
  658. ASSERT(m_nProtocolIndex < (sizeof(aProtocols) / sizeof(ProtocolDesc)));
  659. // set static to point to protocol description string
  660. CString tmp((LPCTSTR) UIntToPtr( aProtocols[m_nProtocolIndex].nResidDesc )); // get string from resource
  661. m_stProtseq.SetWindowText(tmp);
  662. // check if dynamic endpoint options are enabled for this
  663. m_rbDynamicInternet.EnableWindow(aProtocols[m_nProtocolIndex].bAllowDynamic);
  664. m_rbDynamicIntranet.EnableWindow(aProtocols[m_nProtocolIndex].bAllowDynamic);
  665. }
  666. /////////////////////////////////////////////////////////////////////////////
  667. // CAddProtocolDlg dialog
  668. CAddProtocolDlg::CAddProtocolDlg(CWnd* pParent /*=NULL*/)
  669. : CDialog(CAddProtocolDlg::IDD, pParent)
  670. {
  671. //{{AFX_DATA_INIT(CAddProtocolDlg)
  672. // NOTE: the ClassWizard will add member initialization here
  673. //}}AFX_DATA_INIT
  674. m_nProtocolIndex = -1;
  675. m_pCurrentEPData = NULL;
  676. }
  677. void CAddProtocolDlg::DoDataExchange(CDataExchange* pDX)
  678. {
  679. CDialog::DoDataExchange(pDX);
  680. //{{AFX_DATA_MAP(CAddProtocolDlg)
  681. DDX_Control(pDX, IDC_CBPROTSEQ, m_cbProtseq);
  682. DDX_Control(pDX, IDC_SINSTRUCTIONS, m_stInstructions);
  683. //}}AFX_DATA_MAP
  684. }
  685. BEGIN_MESSAGE_MAP(CAddProtocolDlg, CDialog)
  686. //{{AFX_MSG_MAP(CAddProtocolDlg)
  687. ON_CBN_SELCHANGE(IDC_CBPROTSEQ, OnChooseProtocol)
  688. ON_WM_HELPINFO()
  689. //}}AFX_MSG_MAP
  690. END_MESSAGE_MAP()
  691. /////////////////////////////////////////////////////////////////////////////
  692. // CAddProtocolDlg message handlers
  693. void CAddProtocolDlg::OnChooseProtocol()
  694. {
  695. int sel = m_cbProtseq.GetCurSel();
  696. if (sel >= 0)
  697. m_nProtocolIndex = (int) m_cbProtseq.GetItemData(sel);
  698. }
  699. BOOL CAddProtocolDlg::OnInitDialog()
  700. {
  701. CDialog::OnInitDialog();
  702. int i = 0;
  703. int index = 0;
  704. // initialise combobox with list of protocols
  705. for (i = 1; i < sizeof(aProtocols) / sizeof(ProtocolDesc); i++)
  706. {
  707. if (aProtocols[i].m_bSupportedInCOM)
  708. {
  709. CString tmp((LPCTSTR) UIntToPtr( aProtocols[i].nResidDesc )); // get string from resource
  710. index = m_cbProtseq.AddString(tmp);
  711. if (index >= 0)
  712. m_cbProtseq.SetItemData(index, (DWORD)i);
  713. }
  714. }
  715. CString sInstructions((LPCTSTR)IDS_INSTRUCTIONS_ADDPROTOCOL) ;
  716. CString sCaption((LPCTSTR) IDS_CAPTION_ADDPROTOCOL);
  717. m_stInstructions.SetWindowText(sInstructions);
  718. SetWindowText(sCaption);
  719. // default to tcpip - unless we are updating an existing
  720. // protocol
  721. if (m_nProtocolIndex == (-1))
  722. {
  723. m_nProtocolIndex = (int)m_cbProtseq.GetItemData(TCP_INDEX - 1);
  724. m_cbProtseq.SetCurSel(TCP_INDEX - 1);
  725. }
  726. else
  727. m_cbProtseq.SetCurSel(m_nProtocolIndex - 1);
  728. return TRUE; // return TRUE unless you set the focus to a control
  729. }
  730. //+-------------------------------------------------------------------------
  731. //
  732. // Member: GetEndpointData
  733. //
  734. // Synopsis: Fills out CEndpointData structure according to current selections
  735. //
  736. // Arguments: CEndpointData * Pointer to CEndpointData structure to fill out
  737. //
  738. // Returns: CEndpointData * Pointer to filled out CEndpointData *
  739. //
  740. // Algorithm: N/A
  741. //
  742. // History: 02-Dec-96 Ronans Created
  743. //
  744. //--------------------------------------------------------------------------
  745. CEndpointData* CAddProtocolDlg::GetEndpointData(CEndpointData *pData)
  746. {
  747. if (m_nProtocolIndex != -1)
  748. pData -> m_pProtocol = &aProtocols[m_nProtocolIndex];
  749. else
  750. pData -> m_pProtocol = NULL;
  751. pData -> m_szProtseq = aProtocols[m_nProtocolIndex].pszProtseq;
  752. pData -> m_szEndpoint.Empty();
  753. return pData;
  754. }
  755. /////////////////////////////////////////////////////////////////////////////
  756. // CPortRangesDlg dialog
  757. CPortRangesDlg::CPortRangesDlg(CWnd* pParent /*=NULL*/)
  758. : CDialog(CPortRangesDlg::IDD, pParent)
  759. {
  760. //{{AFX_DATA_INIT(CPortRangesDlg)
  761. m_nrbDefaultAssignment = -1;
  762. m_nrbRangeAssignment = -1;
  763. //}}AFX_DATA_INIT
  764. m_nSelection = -1;
  765. m_nrbDefaultAssignment = (int)cprDefaultIntranet;
  766. m_nrbRangeAssignment = (int)cprIntranet;
  767. m_pRanges = &m_arrInternetRanges;
  768. m_bChanged = FALSE;
  769. }
  770. void CPortRangesDlg::DoDataExchange(CDataExchange* pDX)
  771. {
  772. CDialog::DoDataExchange(pDX);
  773. //{{AFX_DATA_MAP(CPortRangesDlg)
  774. DDX_Control(pDX, IDC_ASSIGN_RANGE_INTERNET, m_rbRangeInternet);
  775. DDX_Control(pDX, IDC_SINSTRUCTIONS, m_stInstructions);
  776. DDX_Control(pDX, IDC_LIST1, m_lbRanges);
  777. DDX_Control(pDX, IDC_BTNREMOVEALL, m_btnRemoveAll);
  778. DDX_Control(pDX, IDC_BTNREMOVE, m_btnRemove);
  779. DDX_Control(pDX, IDC_BTNADD, m_btnAdd);
  780. DDX_Radio(pDX, IDC_DEFAULT_INTERNET, m_nrbDefaultAssignment); // 1 = intranet, 0 = internet
  781. DDX_Radio(pDX, IDC_ASSIGN_RANGE_INTERNET, m_nrbRangeAssignment); // 1 = intranet, 0 = internet
  782. //}}AFX_DATA_MAP
  783. DDX_Control(pDX, IDC_ASSIGN_RANGE_INTRANET, m_rbRangeIntranet);
  784. }
  785. CPortRangesDlg::~CPortRangesDlg()
  786. {
  787. int nIndex;
  788. for (nIndex = 0; nIndex < m_arrInternetRanges.GetSize(); nIndex++)
  789. {
  790. CPortRange *pRange = (CPortRange*) m_arrInternetRanges.GetAt(nIndex);
  791. delete pRange;
  792. }
  793. m_arrInternetRanges.RemoveAll();
  794. for (nIndex = 0; nIndex < m_arrIntranetRanges.GetSize(); nIndex++)
  795. {
  796. CPortRange *pRange = (CPortRange*) m_arrIntranetRanges.GetAt(nIndex);
  797. delete pRange;
  798. }
  799. m_arrIntranetRanges.RemoveAll();
  800. }
  801. BEGIN_MESSAGE_MAP(CPortRangesDlg, CDialog)
  802. //{{AFX_MSG_MAP(CPortRangesDlg)
  803. ON_BN_CLICKED(IDC_BTNADD, OnAddPortRange)
  804. ON_BN_CLICKED(IDC_BTNREMOVE, OnRemovePortRange)
  805. ON_BN_CLICKED(IDC_BTNREMOVEALL, OnRemoveAllRanges)
  806. ON_BN_CLICKED(IDC_ASSIGN_RANGE_INTERNET, OnAssignRangeInternet)
  807. ON_BN_CLICKED(IDC_ASSIGN_RANGE_INTRANET, OnAssignRangeIntranet)
  808. ON_LBN_SELCHANGE(IDC_LIST1, OnSelChangeRanges)
  809. ON_WM_HELPINFO()
  810. ON_BN_CLICKED(IDC_DEFAULT_INTERNET, OnDefaultInternet)
  811. ON_BN_CLICKED(IDC_DEFAULT_INTRANET, OnDefaultIntranet)
  812. //}}AFX_MSG_MAP
  813. END_MESSAGE_MAP()
  814. /////////////////////////////////////////////////////////////////////////////
  815. // CPortRangesDlg message handlers
  816. BOOL ExtractPortsFromString(CString &rPortRange, long &dwStartPort, long &dwEndPort)
  817. {
  818. if (!rPortRange.IsEmpty())
  819. {
  820. int nRangeLength = rPortRange.GetLength();
  821. // extract the two numbers
  822. CString sStartPort,sEndPort;
  823. sStartPort = rPortRange.SpanIncluding(TEXT("0123456789"));
  824. if (!sStartPort.IsEmpty())
  825. dwEndPort = dwStartPort = _tcstol((LPCTSTR)sStartPort, NULL, 10);
  826. if (sStartPort.IsEmpty() || (dwStartPort > MAX_PORT) || (dwStartPort < MIN_PORT))
  827. return FALSE;
  828. int nIndex = sStartPort.GetLength();
  829. // skip - or whitespace
  830. while ((nIndex < nRangeLength) &&
  831. ((rPortRange.GetAt(nIndex) == TEXT(' ')) ||
  832. (rPortRange.GetAt(nIndex) == TEXT('\t')) ||
  833. (rPortRange.GetAt(nIndex) == TEXT('-'))))
  834. nIndex++;
  835. // extract second port
  836. sEndPort = rPortRange.Mid(nIndex);
  837. // check for second valid number
  838. if (!sEndPort.IsEmpty())
  839. {
  840. CString sTmp = sEndPort.SpanIncluding(TEXT("0123456789"));
  841. dwEndPort = _tcstol((LPCTSTR)sTmp, NULL, 10);
  842. // ensure all characters are numeric
  843. if (sEndPort.GetLength() != sTmp.GetLength())
  844. return FALSE;
  845. if (dwEndPort > MAX_PORT)
  846. return FALSE;
  847. if (dwEndPort < dwStartPort)
  848. return FALSE;
  849. }
  850. return TRUE;
  851. }
  852. return FALSE;
  853. }
  854. BOOL PortsToString(CString &rsPort, long dwStartPort, long dwEndPort)
  855. {
  856. rsPort.Empty();
  857. if (dwStartPort == dwEndPort)
  858. rsPort.Format(TEXT("%d"), dwStartPort);
  859. else
  860. rsPort.Format(TEXT("%d-%d"), dwStartPort, dwEndPort);
  861. return TRUE;
  862. }
  863. BOOL CPortRangesDlg::OnInitDialog()
  864. {
  865. CDialog::OnInitDialog();
  866. // set up instructions
  867. CString sTmp((LPCTSTR)IDS_INSTRUCTIONS_PORTRANGES);
  868. m_stInstructions.SetWindowText(sTmp);
  869. m_btnAdd.EnableWindow(TRUE);
  870. m_btnRemoveAll.EnableWindow(TRUE);
  871. // Attempt to read HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Rpc\PortsInternetAvailable
  872. // this determines whether the range read later refers to internet or intranet port range
  873. int err;
  874. // read in whether ports are available for internet
  875. err = g_virtreg.ReadRegSzNamedValue(HKEY_LOCAL_MACHINE,
  876. TEXT("SOFTWARE\\Microsoft\\RPC\\Internet"),
  877. TEXT("PortsInternetAvailable"),
  878. &m_nInetPortsAvailableIdx);
  879. if (err == ERROR_SUCCESS)
  880. {
  881. CRegSzNamedValueDp * pCdp = (CRegSzNamedValueDp*)g_virtreg.GetAt(m_nInetPortsAvailableIdx);
  882. CString sTmp = pCdp -> Value();
  883. if ((sTmp == TEXT("y")) || (sTmp == TEXT("Y")))
  884. {
  885. m_nrbRangeAssignment = (int)cprInternet;
  886. m_pRanges = &m_arrInternetRanges;
  887. }
  888. else
  889. {
  890. m_nrbRangeAssignment = (int)cprIntranet;
  891. m_pRanges = &m_arrIntranetRanges;
  892. }
  893. }
  894. else if (err != ERROR_ACCESS_DENIED && err !=
  895. ERROR_FILE_NOT_FOUND)
  896. {
  897. g_util.PostErrorMessage();
  898. }
  899. // read in ports list
  900. err = g_virtreg.ReadRegMultiSzNamedValue(HKEY_LOCAL_MACHINE,
  901. TEXT("SOFTWARE\\Microsoft\\RPC\\Internet"),
  902. TEXT("Ports"),
  903. &m_nInetPortsIdx);
  904. if (err == ERROR_SUCCESS)
  905. {
  906. CRegMultiSzNamedValueDp * pCdp = (CRegMultiSzNamedValueDp*)g_virtreg.GetAt(m_nInetPortsIdx);
  907. CStringArray& rPorts = pCdp -> Values();
  908. // copy protocols
  909. int nIndex;
  910. for (nIndex = 0; nIndex < rPorts.GetSize(); nIndex++)
  911. {
  912. CString sTmp = rPorts.GetAt(nIndex);
  913. long dwStartPort, dwEndPort;
  914. ExtractPortsFromString(sTmp, dwStartPort, dwEndPort);
  915. m_pRanges -> Add(new CPortRange(dwStartPort, dwEndPort));
  916. }
  917. // set selection to first item
  918. m_nSelection = 0;
  919. }
  920. else if (err != ERROR_ACCESS_DENIED && err !=
  921. ERROR_FILE_NOT_FOUND)
  922. {
  923. g_util.PostErrorMessage();
  924. }
  925. // read in default policy
  926. err = g_virtreg.ReadRegSzNamedValue(HKEY_LOCAL_MACHINE,
  927. TEXT("SOFTWARE\\Microsoft\\RPC\\Internet"),
  928. TEXT("UseInternetPorts"),
  929. &m_nInetDefaultPortsIdx);
  930. if (err == ERROR_SUCCESS)
  931. {
  932. CRegSzNamedValueDp * pCdp = (CRegSzNamedValueDp*)g_virtreg.GetAt(m_nInetDefaultPortsIdx);
  933. CString sTmp = pCdp -> Value();
  934. if ((sTmp == TEXT("y")) || (sTmp == TEXT("Y")))
  935. m_nrbDefaultAssignment = (int)cprDefaultInternet;
  936. else
  937. m_nrbDefaultAssignment = (int)cprDefaultIntranet;
  938. }
  939. else if (err != ERROR_ACCESS_DENIED && err !=
  940. ERROR_FILE_NOT_FOUND)
  941. {
  942. g_util.PostErrorMessage();
  943. }
  944. m_bChanged = FALSE;
  945. RefreshRanges(NULL, TRUE);
  946. // focus and selection will be set to listbox
  947. // if (m_nSelection != -1)
  948. // return FALSE;
  949. UpdateData(FALSE);
  950. return TRUE; // return TRUE unless you set the focus to a control
  951. // EXCEPTION: OCX Property Pages should return FALSE
  952. }
  953. void CPortRangesDlg::OnAddPortRange()
  954. {
  955. CAddPortDlg capd;
  956. if (capd.DoModal() == IDOK)
  957. {
  958. CPortRange* pNewPort = capd.GetPortRange();
  959. m_pRanges -> Add(pNewPort);
  960. SortRangeSet(*m_pRanges);
  961. RefreshRanges(pNewPort, TRUE);
  962. m_bChanged = TRUE;
  963. }
  964. SetFocus();
  965. }
  966. void CPortRangesDlg::OnRemovePortRange()
  967. {
  968. if (m_nSelection != -1)
  969. {
  970. CPortRange *pRange = (CPortRange*)m_pRanges -> GetAt(m_nSelection);
  971. m_pRanges -> RemoveAt(m_nSelection);
  972. m_lbRanges.DeleteString(m_nSelection);
  973. RefreshRanges(pRange, FALSE);
  974. delete pRange;
  975. m_bChanged = TRUE;
  976. if (!m_lbRanges.GetCount())
  977. {
  978. m_nrbDefaultAssignment = (int)cprDefaultIntranet;
  979. m_nrbRangeAssignment = (int)cprIntranet;
  980. UpdateData(FALSE);
  981. }
  982. }
  983. }
  984. void CPortRangesDlg::OnRemoveAllRanges()
  985. {
  986. RemoveAllRanges(*m_pRanges);
  987. RefreshRanges(NULL, TRUE);
  988. m_nrbDefaultAssignment = (int)cprDefaultIntranet;
  989. m_nrbRangeAssignment = (int)cprIntranet;
  990. UpdateData(FALSE);
  991. m_bChanged = TRUE;
  992. }
  993. void CPortRangesDlg::RefreshRanges(CPortRange *pModifiedRange, BOOL bAdded)
  994. {
  995. if (!pModifiedRange && bAdded)
  996. {
  997. m_nSelection = 0;
  998. m_lbRanges.ResetContent();
  999. }
  1000. // for a deleted item we only need to update the selection
  1001. for (int nIndex = 0; bAdded && (nIndex < m_pRanges -> GetSize()); nIndex++)
  1002. {
  1003. CPortRange *pRange = (CPortRange*) m_pRanges -> GetAt(nIndex);
  1004. int nNewIndex = -1;
  1005. if (!pModifiedRange || (pModifiedRange == pRange))
  1006. {
  1007. // add string for range
  1008. CString sTmp;
  1009. PortsToString(sTmp, pRange -> m_dwStart, pRange -> m_dwFinish);
  1010. ;
  1011. if ((nNewIndex = m_lbRanges.InsertString(nIndex, sTmp))!= LB_ERR)
  1012. m_lbRanges.SetItemDataPtr(nNewIndex, pRange);
  1013. if (pModifiedRange)
  1014. {
  1015. m_nSelection = nNewIndex;
  1016. break;
  1017. }
  1018. }
  1019. }
  1020. // check if selection is out of range
  1021. int nCount = m_lbRanges.GetCount();
  1022. if (m_nSelection >= nCount)
  1023. m_nSelection = nCount -1;
  1024. // update selection settings
  1025. m_btnRemove.EnableWindow(m_nSelection != -1);
  1026. m_btnRemoveAll.EnableWindow(nCount > 0);
  1027. CWnd * pTmpRadioBtn = NULL;
  1028. pTmpRadioBtn = GetDlgItem(IDC_ASSIGN_RANGE_INTERNET);
  1029. if (pTmpRadioBtn)
  1030. pTmpRadioBtn -> EnableWindow(nCount > 0);
  1031. pTmpRadioBtn = GetDlgItem(IDC_ASSIGN_RANGE_INTRANET);
  1032. if (pTmpRadioBtn)
  1033. pTmpRadioBtn -> EnableWindow(nCount > 0);
  1034. pTmpRadioBtn = GetDlgItem(IDC_DEFAULT_INTERNET);
  1035. if (pTmpRadioBtn)
  1036. pTmpRadioBtn -> EnableWindow(nCount > 0);
  1037. pTmpRadioBtn = GetDlgItem(IDC_DEFAULT_INTRANET);
  1038. if (pTmpRadioBtn)
  1039. pTmpRadioBtn -> EnableWindow(nCount > 0);
  1040. if (m_nSelection != -1)
  1041. m_lbRanges.SetCurSel(m_nSelection);
  1042. }
  1043. void CPortRangesDlg::CreateInverseRangeSet(CObArray & arrSrc, CObArray & arrDest)
  1044. {
  1045. CondenseRangeSet(arrSrc);
  1046. int nIndex;
  1047. long nPreviousFinish = -1;
  1048. // dont bother creating inverse range set for empty range set
  1049. if (arrSrc.GetSize() != 0)
  1050. {
  1051. for (nIndex = 0; nIndex < arrSrc.GetSize(); nIndex++)
  1052. {
  1053. CPortRange *pRange = (CPortRange*) arrSrc.GetAt(nIndex);
  1054. if ((pRange -> m_dwStart - nPreviousFinish) > 1)
  1055. {
  1056. CPortRange *pNewRange = new CPortRange(nPreviousFinish+1,pRange -> m_dwStart -1);
  1057. arrDest.Add(pNewRange);
  1058. }
  1059. nPreviousFinish = pRange -> m_dwFinish;
  1060. }
  1061. // special case for last item
  1062. if (MAX_PORT > nPreviousFinish)
  1063. {
  1064. CPortRange *pFinalRange = new CPortRange(nPreviousFinish+1,MAX_PORT);
  1065. arrDest.Add(pFinalRange);
  1066. }
  1067. }
  1068. }
  1069. void CPortRangesDlg::SortRangeSet(CObArray& arrSrc)
  1070. {
  1071. // bubble sort of port range set
  1072. BOOL bChange;
  1073. int nIndex;
  1074. // iterate until no changes
  1075. do
  1076. {
  1077. bChange = FALSE;
  1078. for (nIndex = 0; nIndex < (arrSrc.GetSize() -1 ); nIndex++)
  1079. {
  1080. CPortRange *pRange1 = (CPortRange*) arrSrc.GetAt(nIndex);
  1081. CPortRange *pRange2 = (CPortRange*) arrSrc.GetAt(nIndex+1);
  1082. if (*pRange2 < *pRange1)
  1083. {
  1084. arrSrc.SetAt(nIndex, (CObject*)pRange2);
  1085. arrSrc.SetAt(nIndex+1, (CObject*)pRange1);
  1086. bChange = TRUE;
  1087. }
  1088. }
  1089. }
  1090. while (bChange);
  1091. }
  1092. void CPortRangesDlg::CondenseRangeSet(CObArray &arrSrc)
  1093. {
  1094. SortRangeSet(arrSrc);
  1095. int nIndex;
  1096. for (nIndex = 0; nIndex < (arrSrc.GetSize() -1 ); nIndex++)
  1097. {
  1098. CPortRange *pRange1 = (CPortRange*) arrSrc.GetAt(nIndex);
  1099. CPortRange *pRange2 = (CPortRange*) arrSrc.GetAt(nIndex+1);
  1100. if (pRange1 -> m_dwFinish >= pRange2 -> m_dwStart)
  1101. {
  1102. if (pRange1 -> m_dwFinish < pRange2 -> m_dwFinish)
  1103. pRange1 -> m_dwFinish = pRange2 -> m_dwFinish;
  1104. arrSrc.RemoveAt(nIndex+1);
  1105. delete pRange2;
  1106. }
  1107. }
  1108. }
  1109. void CPortRangesDlg::RemoveAllRanges(CObArray & arrSrc)
  1110. {
  1111. int nIndex;
  1112. for (nIndex = 0; nIndex < arrSrc.GetSize(); nIndex++)
  1113. {
  1114. CPortRange *pRange = (CPortRange*) arrSrc.GetAt(nIndex);
  1115. arrSrc.SetAt(nIndex, NULL);
  1116. delete pRange;
  1117. }
  1118. arrSrc.RemoveAll();
  1119. RefreshRanges(NULL, TRUE);
  1120. }
  1121. void CPortRangesDlg::OnAssignRangeInternet()
  1122. {
  1123. if (m_pRanges != &m_arrInternetRanges)
  1124. {
  1125. m_pRanges = &m_arrInternetRanges;
  1126. RemoveAllRanges(*m_pRanges);
  1127. CreateInverseRangeSet(m_arrIntranetRanges, m_arrInternetRanges);
  1128. RefreshRanges(NULL, TRUE);
  1129. m_bChanged = TRUE;
  1130. }
  1131. }
  1132. void CPortRangesDlg::OnAssignRangeIntranet()
  1133. {
  1134. if (m_pRanges != &m_arrIntranetRanges)
  1135. {
  1136. m_pRanges = &m_arrIntranetRanges;
  1137. RemoveAllRanges(*m_pRanges);
  1138. CreateInverseRangeSet(m_arrInternetRanges, m_arrIntranetRanges);
  1139. RefreshRanges(NULL, TRUE);
  1140. m_bChanged = TRUE;
  1141. }
  1142. }
  1143. void CPortRangesDlg::OnDefaultInternet()
  1144. {
  1145. m_bChanged = TRUE;
  1146. }
  1147. void CPortRangesDlg::OnDefaultIntranet()
  1148. {
  1149. m_bChanged = TRUE;
  1150. }
  1151. void CPortRangesDlg::OnSelChangeRanges()
  1152. {
  1153. if ((m_nSelection = m_lbRanges.GetCurSel()) == LB_ERR)
  1154. m_nSelection = -1;
  1155. }
  1156. void CPortRangesDlg::OnOK()
  1157. {
  1158. UpdateData(TRUE);
  1159. if (m_bChanged)
  1160. {
  1161. // write out registry data if necessary
  1162. // if there are no port ranges - then delete the keys
  1163. if ((m_arrInternetRanges.GetSize() == 0) &&
  1164. (m_arrIntranetRanges.GetSize() == 0))
  1165. {
  1166. if (m_nInetPortsIdx != -1)
  1167. g_virtreg.MarkHiveForDeletion(m_nInetPortsIdx);
  1168. if (m_nInetPortsAvailableIdx != -1)
  1169. g_virtreg.MarkHiveForDeletion(m_nInetPortsAvailableIdx);
  1170. if (m_nInetDefaultPortsIdx != -1)
  1171. g_virtreg.MarkHiveForDeletion(m_nInetDefaultPortsIdx);
  1172. }
  1173. else
  1174. {
  1175. // write out updated / new key values
  1176. // port range assignments
  1177. TCHAR* pTmp = ((m_nrbRangeAssignment == (int)cprInternet) ? TEXT("Y") : TEXT("N"));
  1178. if (m_nInetPortsAvailableIdx != -1)
  1179. g_virtreg.ChgRegSzNamedValue(m_nInetPortsAvailableIdx, pTmp);
  1180. else
  1181. {
  1182. g_virtreg.NewRegSzNamedValue(HKEY_LOCAL_MACHINE,
  1183. TEXT("SOFTWARE\\Microsoft\\RPC\\Internet"),
  1184. TEXT("PortsInternetAvailable"),
  1185. pTmp,
  1186. &m_nInetPortsAvailableIdx);
  1187. }
  1188. // default port assignments
  1189. pTmp = ((m_nrbDefaultAssignment == (int)cprDefaultInternet) ? TEXT("Y") : TEXT("N"));
  1190. if (m_nInetDefaultPortsIdx != -1)
  1191. g_virtreg.ChgRegSzNamedValue(m_nInetDefaultPortsIdx, pTmp);
  1192. else
  1193. {
  1194. g_virtreg.NewRegSzNamedValue(HKEY_LOCAL_MACHINE,
  1195. TEXT("SOFTWARE\\Microsoft\\RPC\\Internet"),
  1196. TEXT("UseInternetPorts"),
  1197. pTmp,
  1198. &m_nInetDefaultPortsIdx);
  1199. }
  1200. // Actual port ranges
  1201. if (m_nInetPortsIdx == -1)
  1202. g_virtreg.NewRegMultiSzNamedValue(HKEY_LOCAL_MACHINE,
  1203. TEXT("SOFTWARE\\Microsoft\\RPC\\Internet"),
  1204. TEXT("Ports"),
  1205. &m_nInetPortsIdx);
  1206. if (m_nInetPortsIdx != -1)
  1207. {
  1208. CRegMultiSzNamedValueDp * pMszdp = (CRegMultiSzNamedValueDp*)g_virtreg.GetAt( m_nInetPortsIdx);
  1209. pMszdp -> Clear();
  1210. CStringArray& rStrings = pMszdp -> Values();
  1211. for (int nIndex = 0; nIndex < m_pRanges -> GetSize(); nIndex++)
  1212. {
  1213. CPortRange *pRange = (CPortRange*) m_pRanges -> GetAt(nIndex);
  1214. CString sTmp;
  1215. PortsToString(sTmp, pRange -> Start(), pRange -> Finish());
  1216. rStrings.Add(sTmp);
  1217. }
  1218. pMszdp -> SetModified(TRUE);
  1219. }
  1220. }
  1221. }
  1222. CDialog::OnOK();
  1223. }
  1224. /////////////////////////////////////////////////////////////////////////////
  1225. // CAddPortDlg dialog
  1226. CAddPortDlg::CAddPortDlg(CWnd* pParent /*=NULL*/)
  1227. : CDialog(CAddPortDlg::IDD, pParent)
  1228. {
  1229. //{{AFX_DATA_INIT(CAddPortDlg)
  1230. m_sRange = _T("");
  1231. //}}AFX_DATA_INIT
  1232. m_dwStartPort = -1;
  1233. m_dwEndPort = -1;
  1234. }
  1235. void CAddPortDlg::DoDataExchange(CDataExchange* pDX)
  1236. {
  1237. CDialog::DoDataExchange(pDX);
  1238. //{{AFX_DATA_MAP(CAddPortDlg)
  1239. DDX_Control(pDX, IDC_PORTRANGE, m_edtPortRange);
  1240. DDX_Control(pDX, IDOK, m_btnOk);
  1241. DDX_Control(pDX, IDC_SINSTRUCTIONS, m_stInstructions);
  1242. DDX_Text(pDX, IDC_PORTRANGE, m_sRange);
  1243. //}}AFX_DATA_MAP
  1244. if (pDX -> m_bSaveAndValidate)
  1245. {
  1246. m_sRange.TrimLeft();
  1247. m_sRange.TrimRight();
  1248. }
  1249. }
  1250. BEGIN_MESSAGE_MAP(CAddPortDlg, CDialog)
  1251. //{{AFX_MSG_MAP(CAddPortDlg)
  1252. ON_EN_CHANGE(IDC_PORTRANGE, OnChangePortrange)
  1253. ON_WM_HELPINFO()
  1254. //}}AFX_MSG_MAP
  1255. END_MESSAGE_MAP()
  1256. /////////////////////////////////////////////////////////////////////////////
  1257. // CAddPortDlg message handlers
  1258. BOOL CAddPortDlg::OnInitDialog()
  1259. {
  1260. CDialog::OnInitDialog();
  1261. CString sTmp((LPCTSTR)IDS_ADDPORT_INSTRUCTIONS);
  1262. m_stInstructions.SetWindowText(sTmp);
  1263. m_btnOk.EnableWindow(FALSE);
  1264. m_edtPortRange.SetFocus();
  1265. return FALSE; // return TRUE unless you set the focus to a control
  1266. // EXCEPTION: OCX Property Pages should return FALSE
  1267. }
  1268. void CAddPortDlg::OnOK()
  1269. {
  1270. UpdateData(TRUE);
  1271. if (Validate())
  1272. CDialog::OnOK();
  1273. else
  1274. {
  1275. CString sTmp((LPCTSTR)IDS_INVALID_PORTRANGE);
  1276. AfxMessageBox((LPCTSTR)sTmp);
  1277. }
  1278. }
  1279. BOOL CAddPortDlg::Validate()
  1280. {
  1281. // check contents of m_sRange
  1282. long dwStartPort = -1, dwEndPort = -1;
  1283. return ExtractPortsFromString(m_sRange, m_dwStartPort, m_dwEndPort);
  1284. }
  1285. void CAddPortDlg::OnChangePortrange()
  1286. {
  1287. UpdateData(TRUE);
  1288. m_btnOk.EnableWindow(!m_sRange.IsEmpty());
  1289. }
  1290. CPortRange* CAddPortDlg::GetPortRange()
  1291. {
  1292. return new CPortRange(m_dwStartPort, m_dwEndPort);
  1293. }
  1294. BOOL CAddPortDlg::OnHelpInfo(HELPINFO* pHelpInfo)
  1295. {
  1296. if(-1 != pHelpInfo->iCtrlId)
  1297. {
  1298. WORD hiWord = 0x8000 | CAddPortDlg::IDD;
  1299. WORD loWord = (WORD) pHelpInfo->iCtrlId;
  1300. DWORD dwLong = MAKELONG(loWord,hiWord);
  1301. WinHelp(dwLong, HELP_CONTEXTPOPUP);
  1302. TRACE1("Help Id 0x%lx\n", dwLong);
  1303. return TRUE;
  1304. }
  1305. else
  1306. {
  1307. return CDialog::OnHelpInfo(pHelpInfo);
  1308. }
  1309. }
  1310. BOOL CAddProtocolDlg::OnHelpInfo(HELPINFO* pHelpInfo)
  1311. {
  1312. if(-1 != pHelpInfo->iCtrlId)
  1313. {
  1314. WORD hiWord = 0x8000 | CAddProtocolDlg::IDD;
  1315. WORD loWord = (WORD) pHelpInfo->iCtrlId;
  1316. DWORD dwLong = MAKELONG(loWord,hiWord);
  1317. WinHelp(dwLong, HELP_CONTEXTPOPUP);
  1318. TRACE1("Help Id 0x%lx\n", dwLong);
  1319. return TRUE;
  1320. }
  1321. else
  1322. {
  1323. return CDialog::OnHelpInfo(pHelpInfo);
  1324. }
  1325. }
  1326. BOOL CEndpointDetails::OnHelpInfo(HELPINFO* pHelpInfo)
  1327. {
  1328. if(-1 != pHelpInfo->iCtrlId)
  1329. {
  1330. WORD hiWord = 0x8000 | CEndpointDetails::IDD;
  1331. WORD loWord = (WORD) pHelpInfo->iCtrlId;
  1332. DWORD dwLong = MAKELONG(loWord,hiWord);
  1333. WinHelp(dwLong, HELP_CONTEXTPOPUP);
  1334. TRACE1("Help Id 0x%lx\n", dwLong);
  1335. return TRUE;
  1336. }
  1337. else
  1338. {
  1339. return CDialog::OnHelpInfo(pHelpInfo);
  1340. }
  1341. }
  1342. BOOL CPortRangesDlg::OnHelpInfo(HELPINFO* pHelpInfo)
  1343. {
  1344. if(-1 != pHelpInfo->iCtrlId)
  1345. {
  1346. WORD hiWord = 0x8000 | CPortRangesDlg::IDD;
  1347. WORD loWord = (WORD) pHelpInfo->iCtrlId;
  1348. // both radio button pairs should generate same help id
  1349. if (loWord == IDC_DEFAULT_INTRANET)
  1350. loWord = IDC_DEFAULT_INTERNET;
  1351. // both radio button pairs should generate same help id
  1352. if (loWord == IDC_ASSIGN_RANGE_INTRANET)
  1353. loWord = IDC_ASSIGN_RANGE_INTERNET;
  1354. DWORD dwLong = MAKELONG(loWord,hiWord);
  1355. WinHelp(dwLong, HELP_CONTEXTPOPUP);
  1356. TRACE1("Help Id 0x%lx\n", dwLong);
  1357. return TRUE;
  1358. }
  1359. else
  1360. {
  1361. return CDialog::OnHelpInfo(pHelpInfo);
  1362. }
  1363. }