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.

1036 lines
31 KiB

  1. //============================================================================
  2. // Copyright (C) 1996, Microsoft Corp.
  3. //
  4. // File: add.cpp
  5. //
  6. // History:
  7. // Abolade-Gbadegesin Mar-15-1996 Created
  8. //
  9. // Contains implementation for dialogs listing components for addition
  10. // to the router. All of the dialogs consists of a listview and two buttons,
  11. // labelled "OK" and "Cancel".
  12. //============================================================================
  13. #include "stdafx.h"
  14. #include "rtrres.h" // RTRLIB resource header
  15. #include "info.h"
  16. #include "dialog.h" // common code dialog class
  17. #include "add.h"
  18. #include "rtrui.h" // common router UI utility functions
  19. #include "rtrstr.h" // common router strings
  20. #include "mprapi.h"
  21. #include "rtrcomn.h" // common router utilities
  22. #include "format.h"
  23. #include "rtrutil.h" // for smart pointers
  24. #include "routprot.h" // routing protocol IDs
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. //----------------------------------------------------------------------------
  31. // Class: CRmAddInterface
  32. //
  33. //----------------------------------------------------------------------------
  34. //----------------------------------------------------------------------------
  35. // Function: CRmAddInterface::DoDataExchange
  36. //----------------------------------------------------------------------------
  37. CRmAddInterface::~CRmAddInterface()
  38. {
  39. while (!m_pIfList.IsEmpty())
  40. {
  41. m_pIfList.RemoveTail()->Release();
  42. }
  43. }
  44. VOID
  45. CRmAddInterface::DoDataExchange(
  46. CDataExchange* pDX
  47. ) {
  48. CBaseDialog::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CRmAddInterface)
  50. DDX_Control(pDX, IDC_ADD_LIST, m_listCtrl);
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CRmAddInterface, CBaseDialog)
  54. //{{AFX_MSG_MAP(CRmAddInterface)
  55. ON_NOTIFY(NM_DBLCLK, IDC_ADD_LIST, OnDblclkListctrl)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. DWORD CRmAddInterface::m_dwHelpMap[] =
  59. {
  60. // IDC_ADD_PROMPT, HIDC_ADD_PROMPT,
  61. // IDC_ADD_LISTTITLE, HIDC_ADD_LISTTITLE,
  62. // IDC_ADD_LISTCTRL, HIDC_ADD_LISTCTRL,
  63. 0,0
  64. };
  65. //----------------------------------------------------------------------------
  66. // Function: CRmAddInterface::OnInitDialog
  67. //----------------------------------------------------------------------------
  68. BOOL
  69. CRmAddInterface::OnInitDialog(
  70. ) {
  71. CBaseDialog::OnInitDialog();
  72. //
  73. // Set the window title, the list-title, prompt-text, and icon.
  74. //
  75. HICON hIcon;
  76. CString sItem;
  77. CStringList stIpxIfList;
  78. DWORD dwIfType;
  79. InterfaceCB ifcb;
  80. sItem.FormatMessage(IDS_SELECT_INTERFACE_FOR, m_spRtrMgrInfo->GetTitle());
  81. SetWindowText(sItem);
  82. sItem.LoadString(IDS_ADD_INTERFACES);
  83. SetDlgItemText(IDC_ADD_TEXT_TITLE, sItem);
  84. sItem.LoadString(IDS_CLICK_RMINTERFACE);
  85. SetDlgItemText(IDC_ADD_TEXT_PROMPT, sItem);
  86. //
  87. // Set the list-view's imagelist
  88. //
  89. CreateRtrLibImageList(&m_imageList);
  90. m_listCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
  91. ListView_SetExtendedListViewStyle(m_listCtrl.m_hWnd, LVS_EX_FULLROWSELECT);
  92. //
  93. // Insert the single column in the listview
  94. //
  95. RECT rc;
  96. m_listCtrl.GetClientRect(&rc);
  97. rc.right -= ::GetSystemMetrics(SM_CXVSCROLL);
  98. m_listCtrl.InsertColumn(0, c_szEmpty, LVCFMT_LEFT, rc.right);
  99. //
  100. // Get a list of the interfaces available
  101. //
  102. SPIEnumInterfaceInfo spEnumIf;
  103. SPIInterfaceInfo spIf;
  104. DWORD dwTransportId;
  105. m_spRouterInfo->EnumInterface(&spEnumIf);
  106. dwTransportId = m_spRtrMgrInfo->GetTransportId();
  107. // Make an initial pass to look for the IPX interfaces
  108. if (dwTransportId == PID_IPX)
  109. {
  110. CString stBaseId;
  111. int iPos;
  112. for (; spEnumIf->Next(1, &spIf, NULL) == hrOK; spIf.Release())
  113. {
  114. if ((iPos = IfInterfaceIdHasIpxExtensions((LPCTSTR) spIf->GetId())))
  115. {
  116. // We've found one, add the base Id (w/o) the extension
  117. // to the stIpxIfList
  118. stBaseId = spIf->GetId();
  119. // Cut off the IPX extension
  120. stBaseId.SetAt(iPos, 0);
  121. // If it's NOT in the list, add it
  122. if (!stIpxIfList.Find(stBaseId))
  123. stIpxIfList.AddTail(stBaseId);
  124. }
  125. }
  126. spEnumIf->Reset();
  127. }
  128. for (; spEnumIf->Next(1, &spIf, NULL) == hrOK ; spIf.Release())
  129. {
  130. //
  131. // Windows NT Bugs 103770
  132. //
  133. // We will need to filter out the interfaces depending on
  134. // the transport. If IP, filter out the IPX frame types.
  135. if (dwTransportId != PID_IPX)
  136. {
  137. // If we found one of these IPX interfaces, skip it
  138. if (IfInterfaceIdHasIpxExtensions((LPCTSTR) spIf->GetId()))
  139. continue;
  140. }
  141. else
  142. {
  143. // If we are in IPX we should make sure that if these
  144. // interfaces exist in the list (already) than we need
  145. // to get rid of the general interface.
  146. if (stIpxIfList.Find(spIf->GetId()))
  147. continue;
  148. }
  149. dwIfType = spIf->GetInterfaceType();
  150. // If the interface is already added or is an internal
  151. // interface, continue
  152. if ((dwIfType == ROUTER_IF_TYPE_INTERNAL) ||
  153. (dwIfType == ROUTER_IF_TYPE_HOME_ROUTER))
  154. continue;
  155. // IPX should not show loopback or tunnel interfaces
  156. if ((dwTransportId == PID_IPX) &&
  157. ((dwIfType == ROUTER_IF_TYPE_LOOPBACK) ||
  158. (dwIfType == ROUTER_IF_TYPE_TUNNEL1) ))
  159. continue;
  160. if (spIf->FindRtrMgrInterface(dwTransportId, NULL) == hrOK)
  161. continue;
  162. // Windows NT Bug : 273424
  163. // check the bind state of the adapter.
  164. // ------------------------------------------------------------
  165. spIf->CopyCB(&ifcb);
  166. // If we are adding to IP and IP is not bound, continue.
  167. // ------------------------------------------------------------
  168. if ((dwTransportId == PID_IP) && !(ifcb.dwBindFlags & InterfaceCB_BindToIp))
  169. continue;
  170. // Similarly for IPX
  171. // ------------------------------------------------------------
  172. if ((dwTransportId == PID_IPX) && !(ifcb.dwBindFlags & InterfaceCB_BindToIpx))
  173. continue;
  174. //
  175. // Insert a list-item for the interface
  176. //
  177. // We need to ensure that the interface is live.
  178. m_pIfList.AddTail(spIf);
  179. spIf->AddRef();
  180. m_listCtrl.InsertItem(
  181. LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE,
  182. 0,
  183. spIf->GetTitle(),
  184. 0,
  185. 0,
  186. spIf->GetInterfaceType() == (DWORD)ROUTER_IF_TYPE_DEDICATED ?
  187. ILI_RTRLIB_NETCARD
  188. : ILI_RTRLIB_MODEM,
  189. (LPARAM) (IInterfaceInfo *) spIf
  190. );
  191. }
  192. //
  193. // If there are no items, explain this and end the dialog
  194. //
  195. if (!m_listCtrl.GetItemCount())
  196. {
  197. ::AfxMessageBox(IDS_ERR_NOINTERFACES, MB_OK|MB_ICONINFORMATION);
  198. OnCancel(); return FALSE;
  199. }
  200. //
  201. // Select the first item
  202. //
  203. m_listCtrl.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
  204. return TRUE;
  205. }
  206. //----------------------------------------------------------------------------
  207. // Function: CRmAddInterface::OnDblclkListctrl
  208. //----------------------------------------------------------------------------
  209. VOID
  210. CRmAddInterface::OnDblclkListctrl(
  211. NMHDR* pNMHDR,
  212. LRESULT* pResult
  213. ) {
  214. OnOK();
  215. *pResult = 0;
  216. }
  217. //----------------------------------------------------------------------------
  218. // Function: CRmAddInterface::OnOK
  219. //----------------------------------------------------------------------------
  220. VOID
  221. CRmAddInterface::OnOK(
  222. ) {
  223. //
  224. // Get the currently selected item
  225. //
  226. INT iSel = m_listCtrl.GetNextItem(-1, LVNI_SELECTED);
  227. if (iSel == -1) { return; }
  228. //
  229. // Get the item's data, which is a IInterfaceInfo pointer
  230. //
  231. IInterfaceInfo *pIf = (IInterfaceInfo *) m_listCtrl.GetItemData(iSel);
  232. //
  233. // Construct a new CRmInterfaceInfo object
  234. //
  235. CreateRtrMgrInterfaceInfo(m_ppRtrMgrInterfaceInfo,
  236. m_spRtrMgrInfo->GetId(),
  237. m_spRtrMgrInfo->GetTransportId(),
  238. pIf->GetId(),
  239. pIf->GetInterfaceType()
  240. );
  241. if (!*m_ppRtrMgrInterfaceInfo) { OnCancel(); return; }
  242. (*m_ppRtrMgrInterfaceInfo)->SetTitle(pIf->GetTitle());
  243. (*m_ppRtrMgrInterfaceInfo)->SetMachineName(m_spRouterInfo->GetMachineName());
  244. CBaseDialog::OnOK();
  245. }
  246. //----------------------------------------------------------------------------
  247. // Class: CRpAddInterface
  248. //
  249. //----------------------------------------------------------------------------
  250. CRpAddInterface::CRpAddInterface(IRouterInfo *pRouterInfo,
  251. IRtrMgrProtocolInfo *pRmProt,
  252. IRtrMgrProtocolInterfaceInfo **ppRmProtIf,
  253. CWnd *pParent)
  254. : CBaseDialog(CRpAddInterface::IDD, pParent)
  255. {
  256. m_spRouterInfo.Set(pRouterInfo);
  257. m_spRmProt.Set(pRmProt);
  258. m_ppRmProtIf = ppRmProtIf;
  259. }
  260. CRpAddInterface::~CRpAddInterface()
  261. {
  262. while (!m_pIfList.IsEmpty())
  263. {
  264. m_pIfList.RemoveTail()->Release();
  265. }
  266. }
  267. //----------------------------------------------------------------------------
  268. // Function: CRpAddInterface::DoDataExchange
  269. //----------------------------------------------------------------------------
  270. VOID
  271. CRpAddInterface::DoDataExchange(
  272. CDataExchange* pDX
  273. ) {
  274. CBaseDialog::DoDataExchange(pDX);
  275. //{{AFX_DATA_MAP(CRpAddInterface)
  276. DDX_Control(pDX, IDC_ADD_LIST, m_listCtrl);
  277. //}}AFX_DATA_MAP
  278. }
  279. BEGIN_MESSAGE_MAP(CRpAddInterface, CBaseDialog)
  280. //{{AFX_MSG_MAP(CRpAddInterface)
  281. ON_NOTIFY(NM_DBLCLK, IDC_ADD_LIST, OnDblclkListctrl)
  282. //}}AFX_MSG_MAP
  283. END_MESSAGE_MAP()
  284. DWORD CRpAddInterface::m_dwHelpMap[] =
  285. {
  286. // IDC_ADD_PROMPT, HIDC_ADD_PROMPT,
  287. // IDC_ADD_LISTTITLE, HIDC_ADD_LISTTITLE,
  288. // IDC_ADD_LISTCTRL, HIDC_ADD_LISTCTRL,
  289. 0,0
  290. };
  291. //----------------------------------------------------------------------------
  292. // Function: CRpAddInterface::OnInitDialog
  293. //----------------------------------------------------------------------------
  294. BOOL
  295. CRpAddInterface::OnInitDialog(
  296. ) {
  297. SPIEnumInterfaceInfo spEnumIf;
  298. SPIInterfaceInfo spIf;
  299. HRESULT hr = hrOK;
  300. DWORD dwIfType;
  301. DWORD dwProtocolId;
  302. UINT idi;
  303. CBaseDialog::OnInitDialog();
  304. //
  305. // Set the window title, the list-title, prompt-text, and icon.
  306. //
  307. HICON hIcon;
  308. CString sItem;
  309. // increase the deafault buffer size (128) first to accomodate
  310. // longer strings
  311. sItem.GetBuffer(512);
  312. sItem.ReleaseBuffer();
  313. // display the protocol name in the window title
  314. sItem.FormatMessage(IDS_SELECT_INTERFACE_FOR, m_spRmProt->GetTitle());
  315. SetWindowText(sItem);
  316. sItem.LoadString(IDS_ADD_INTERFACES);
  317. SetDlgItemText(IDC_ADD_TEXT_TITLE, sItem);
  318. sItem.LoadString(IDS_CLICK_RPINTERFACE);
  319. SetDlgItemText(IDC_ADD_TEXT_PROMPT, sItem);
  320. //
  321. // Set the imagelist for the listview
  322. //
  323. CreateRtrLibImageList(&m_imageList);
  324. m_listCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
  325. ListView_SetExtendedListViewStyle(m_listCtrl.m_hWnd, LVS_EX_FULLROWSELECT);
  326. //
  327. // Insert the single column in the listview
  328. //
  329. RECT rc;
  330. m_listCtrl.GetClientRect(&rc);
  331. rc.right -= ::GetSystemMetrics(SM_CXVSCROLL);
  332. m_listCtrl.InsertColumn(0, c_szEmpty, LVCFMT_LEFT, rc.right);
  333. //
  334. // Get a list of the interfaces available on our router-manager
  335. //
  336. m_spRouterInfo->EnumInterface(&spEnumIf);
  337. for ( ; spEnumIf->Next(1, &spIf, NULL) == hrOK; spIf.Release())
  338. {
  339. dwIfType = spIf->GetInterfaceType();
  340. //
  341. // Only allow if this is not a loopback interface
  342. //
  343. if ((dwIfType == ROUTER_IF_TYPE_LOOPBACK) ||
  344. (dwIfType == ROUTER_IF_TYPE_HOME_ROUTER))
  345. continue;
  346. // Get the protocol id
  347. dwProtocolId = m_spRmProt->GetProtocolId();
  348. //
  349. // The only protocols that we can add the internal interface
  350. // to are BOOTP and IGMP.
  351. //
  352. if (dwIfType == ROUTER_IF_TYPE_INTERNAL)
  353. {
  354. if ((dwProtocolId != MS_IP_BOOTP) &&
  355. (dwProtocolId != MS_IP_IGMP) &&
  356. (dwProtocolId != MS_IP_NAT))
  357. continue;
  358. }
  359. //
  360. // Only list adapters which have IP
  361. //
  362. if (spIf->FindRtrMgrInterface(PID_IP, NULL) != hrOK)
  363. continue;
  364. // Windows NT Bug : 234696
  365. // Tunnels can only be added to IGMP
  366. if (dwIfType == ROUTER_IF_TYPE_TUNNEL1)
  367. {
  368. if (dwProtocolId != MS_IP_IGMP)
  369. continue;
  370. }
  371. //
  372. // Fill the list with the adapters which haven't been added already
  373. //
  374. CORg( LookupRtrMgrProtocolInterface(spIf,
  375. m_spRmProt->GetTransportId(),
  376. m_spRmProt->GetProtocolId(),
  377. NULL));
  378. // This interface has this protocol, so try the next interface
  379. if (FHrOk(hr))
  380. continue;
  381. Assert(hr == hrFalse);
  382. //
  383. // Insert a list-item for the protocol
  384. //
  385. m_pIfList.AddTail(spIf);
  386. spIf->AddRef();
  387. if (!IsWanInterface(dwIfType))
  388. idi = ILI_RTRLIB_NETCARD;
  389. else
  390. idi = ILI_RTRLIB_MODEM;
  391. m_listCtrl.InsertItem(
  392. LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE, 0, spIf->GetTitle(), 0, 0,
  393. idi, (LPARAM)(IInterfaceInfo *) spIf);
  394. }
  395. //
  396. // If there are no items, explain this and end the dialog
  397. //
  398. if (!m_listCtrl.GetItemCount()) {
  399. ::AfxMessageBox(IDS_ERR_NOINTERFACES, MB_OK|MB_ICONINFORMATION);
  400. OnCancel(); return FALSE;
  401. }
  402. //
  403. // Select the first item
  404. //
  405. m_listCtrl.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
  406. Error:
  407. return TRUE;
  408. }
  409. //----------------------------------------------------------------------------
  410. // Function: CRpAddInterface::OnDblclkListctrl
  411. //----------------------------------------------------------------------------
  412. VOID
  413. CRpAddInterface::OnDblclkListctrl(
  414. NMHDR* pNMHDR,
  415. LRESULT* pResult
  416. ) {
  417. OnOK();
  418. *pResult = 0;
  419. }
  420. //----------------------------------------------------------------------------
  421. // Function: CRpAddInterface::OnOK
  422. //----------------------------------------------------------------------------
  423. VOID
  424. CRpAddInterface::OnOK(
  425. ) {
  426. //
  427. // Get the currently selected item
  428. //
  429. INT iSel = m_listCtrl.GetNextItem(-1, LVNI_SELECTED);
  430. if (iSel == -1) { return; }
  431. //
  432. // Get the item's data, which is a CInterfaceInfo pointer
  433. //
  434. IInterfaceInfo *pIf = (IInterfaceInfo *)m_listCtrl.GetItemData(iSel);
  435. //
  436. // Construct a new CRmProtInterfaceInfo object
  437. //
  438. RtrMgrProtocolInterfaceCB RmProtIfCB;
  439. RtrMgrProtocolCB RmProtCB;
  440. m_spRmProt->CopyCB(&RmProtCB);
  441. RmProtIfCB.dwProtocolId = RmProtCB.dwProtocolId;
  442. StrnCpyW(RmProtIfCB.szId, RmProtCB.szId, RTR_ID_MAX);
  443. RmProtIfCB.dwTransportId = RmProtCB.dwTransportId;
  444. StrnCpyW(RmProtIfCB.szRtrMgrId, RmProtCB.szRtrMgrId, RTR_ID_MAX);
  445. StrnCpyW(RmProtIfCB.szInterfaceId, pIf->GetId(), RTR_ID_MAX);
  446. RmProtIfCB.dwIfType = pIf->GetInterfaceType();
  447. RmProtIfCB.szTitle[0] = 0;
  448. CreateRtrMgrProtocolInterfaceInfo(m_ppRmProtIf,
  449. &RmProtIfCB);
  450. if (!*m_ppRmProtIf) { OnCancel(); return; }
  451. (*m_ppRmProtIf)->SetTitle(pIf->GetTitle());
  452. CBaseDialog::OnOK();
  453. }
  454. //----------------------------------------------------------------------------
  455. // Class: CAddRoutingProtocol
  456. //
  457. //----------------------------------------------------------------------------
  458. //----------------------------------------------------------------------------
  459. // Function: CAddRoutingProtocol::~CAddRoutingProtocol
  460. //----------------------------------------------------------------------------
  461. CAddRoutingProtocol::~CAddRoutingProtocol(
  462. )
  463. {
  464. }
  465. //----------------------------------------------------------------------------
  466. // Function: CAddRoutingProtocol::DoDataExchange
  467. //----------------------------------------------------------------------------
  468. VOID
  469. CAddRoutingProtocol::DoDataExchange(
  470. CDataExchange* pDX
  471. ) {
  472. CBaseDialog::DoDataExchange(pDX);
  473. //{{AFX_DATA_MAP(CAddRoutingProtocol)
  474. DDX_Control(pDX, IDC_ADD_LIST, m_listCtrl);
  475. //}}AFX_DATA_MAP
  476. }
  477. BEGIN_MESSAGE_MAP(CAddRoutingProtocol, CBaseDialog)
  478. //{{AFX_MSG_MAP(CAddRoutingProtocol)
  479. ON_NOTIFY(NM_DBLCLK, IDC_ADD_LIST, OnDblclkListctrl)
  480. //}}AFX_MSG_MAP
  481. END_MESSAGE_MAP()
  482. // This should be merged with all of the other IDD_ADD dialogs but we
  483. // could actually add different help topics here, so I'll leave them
  484. // separated.
  485. DWORD CAddRoutingProtocol::m_dwHelpMap[] =
  486. {
  487. // IDC_ADD_PROMPT, HIDC_ADD_PROMPT,
  488. // IDC_ADD_LISTTITLE, HIDC_ADD_LISTTITLE,
  489. // IDC_ADD_LISTCTRL, HIDC_ADD_LISTCTRL,
  490. 0,0
  491. };
  492. //----------------------------------------------------------------------------
  493. // Function: CAddRoutingProtocol::OnInitDialog
  494. //----------------------------------------------------------------------------
  495. BOOL
  496. CAddRoutingProtocol::OnInitDialog(
  497. ) {
  498. CBaseDialog::OnInitDialog();
  499. //
  500. // Set the window title, the list-title, prompt-text, and icon.
  501. //
  502. HICON hIcon;
  503. CString sItem;
  504. SPIEnumRtrMgrProtocolCB spEnumRmProtCB;
  505. RtrMgrProtocolCB rmprotCB;
  506. sItem.LoadString(IDS_SELECT_PROTOCOL);
  507. SetWindowText(sItem);
  508. sItem.LoadString(IDS_ADD_PROTOCOL);
  509. SetDlgItemText(IDC_ADD_TEXT_TITLE, sItem);
  510. sItem.LoadString(IDS_CLICK_PROTOCOL);
  511. SetDlgItemText(IDC_ADD_TEXT_PROMPT, sItem);
  512. //
  513. // Set the list-view's imagelist
  514. //
  515. CreateRtrLibImageList(&m_imageList);
  516. m_listCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
  517. ListView_SetExtendedListViewStyle(m_listCtrl.m_hWnd, LVS_EX_FULLROWSELECT);
  518. //
  519. // Insert the single column in the listview
  520. //
  521. RECT rc;
  522. m_listCtrl.GetClientRect(&rc);
  523. rc.right -= ::GetSystemMetrics(SM_CXVSCROLL);
  524. m_listCtrl.InsertColumn(0, c_szEmpty, LVCFMT_LEFT, rc.right);
  525. //
  526. // Get a list of the routing-protocols available for this router-manager
  527. //
  528. m_spRouter->EnumRtrMgrProtocolCB(&spEnumRmProtCB);
  529. while (spEnumRmProtCB->Next(1, &rmprotCB, NULL) == hrOK)
  530. {
  531. //
  532. // Fill the list with the protocols that aren't already added
  533. //
  534. // If this is the wrong mgr, skip it
  535. if (m_spRm->GetTransportId() != rmprotCB.dwTransportId)
  536. continue;
  537. // If the protocol is hidden, don't show it
  538. if (rmprotCB.dwFlags & RtrMgrProtocolCBFlagHidden)
  539. continue;
  540. //
  541. // If the protocol is already added, continue
  542. //
  543. if (m_spRm->FindRtrMgrProtocol(rmprotCB.dwProtocolId, NULL) == hrOK)
  544. continue;
  545. //
  546. // Insert a list-item for the protocol
  547. //
  548. if ( rmprotCB.dwProtocolId == MS_IP_NAT )
  549. {
  550. CString sNewTitle;
  551. sNewTitle.LoadString(IDS_PROTO_NAT_BASIC_FIREWALL);
  552. m_listCtrl.InsertItem(
  553. LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE, 0, (LPCTSTR)sNewTitle,
  554. 0, 0, ILI_RTRLIB_PROTOCOL, (LPARAM) rmprotCB.dwProtocolId
  555. );
  556. }
  557. else
  558. {
  559. m_listCtrl.InsertItem(
  560. LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE, 0, (LPCTSTR)rmprotCB.szTitle,
  561. 0, 0, ILI_RTRLIB_PROTOCOL, (LPARAM) rmprotCB.dwProtocolId
  562. );
  563. }
  564. }
  565. //
  566. // If there are no items, explain this and end the dialog
  567. //
  568. if (!m_listCtrl.GetItemCount()) {
  569. ::AfxMessageBox(IDS_ERR_NOROUTINGPROTOCOLS, MB_OK|MB_ICONINFORMATION);
  570. OnCancel(); return FALSE;
  571. }
  572. //
  573. // Select the first item
  574. //
  575. m_listCtrl.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
  576. return TRUE;
  577. }
  578. //----------------------------------------------------------------------------
  579. // Function: CAddRoutingProtocol::OnDblclkListctrl
  580. //----------------------------------------------------------------------------
  581. VOID
  582. CAddRoutingProtocol::OnDblclkListctrl(
  583. NMHDR* pNMHDR,
  584. LRESULT* pResult
  585. ) {
  586. OnOK();
  587. *pResult = 0;
  588. }
  589. //----------------------------------------------------------------------------
  590. // Function: CAddRoutingProtocol::OnOK
  591. //----------------------------------------------------------------------------
  592. VOID
  593. CAddRoutingProtocol::OnOK(
  594. ) {
  595. SPIEnumRtrMgrProtocolCB spEnumRmProtCB;
  596. RtrMgrProtocolCB rmprotCB;
  597. RtrMgrProtocolCB oldrmprotCB;
  598. SPIEnumRtrMgrProtocolInfo spEnumRmProt;
  599. SPIRtrMgrProtocolInfo spRmProt;
  600. DWORD_PTR dwData;
  601. HRESULT hr = hrOK;
  602. CString stFormat;
  603. SPIRtrMgrProtocolInfo spRmProtReturn;
  604. //
  605. // Get the currently selected item
  606. // ----------------------------------------------------------------
  607. INT iSel = m_listCtrl.GetNextItem(-1, LVNI_SELECTED);
  608. if (iSel == -1) { return; }
  609. // Retrieve its data, which is the protocol ID
  610. // ----------------------------------------------------------------
  611. // Look up the protocol ID in the protocol list
  612. // ----------------------------------------------------------------
  613. m_spRouter->EnumRtrMgrProtocolCB(&spEnumRmProtCB);
  614. dwData = (DWORD)(m_listCtrl.GetItemData(iSel));
  615. // Construct a routing-protocol item
  616. // ----------------------------------------------------------------
  617. while (spEnumRmProtCB->Next(1, &rmprotCB, NULL) == hrOK)
  618. {
  619. if (rmprotCB.dwProtocolId == dwData)
  620. {
  621. hr = CreateRtrMgrProtocolInfo(&spRmProtReturn,
  622. &rmprotCB);
  623. if (!FHrSucceeded(hr))
  624. {
  625. OnCancel();
  626. return;
  627. }
  628. break;
  629. }
  630. }
  631. // What happens if we can't find the matching item
  632. // ----------------------------------------------------------------
  633. if (spRmProtReturn == NULL)
  634. {
  635. //$ Todo: what error message do we want to put up here?
  636. // ------------------------------------------------------------
  637. return;
  638. }
  639. // Now check to see if there are any protocol conflicts
  640. // ----------------------------------------------------------------
  641. stFormat.LoadString(IDS_WARN_ADD_PROTOCOL_CONFLICT);
  642. m_spRm->EnumRtrMgrProtocol(&spEnumRmProt);
  643. for (;spEnumRmProt->Next(1, &spRmProt, NULL) == hrOK; spRmProt.Release())
  644. {
  645. if (PROTO_FROM_PROTOCOL_ID(spRmProt->GetProtocolId()) ==
  646. PROTO_FROM_PROTOCOL_ID(dwData))
  647. {
  648. SPIRouterProtocolConfig spRouterConfig;
  649. TCHAR szWarning[2048];
  650. DWORD_PTR rgArgs[4];
  651. // There is a conflict, ask the user if they
  652. // wish to remove this protocol, if yes then
  653. // we have to remove the protocol from our internal
  654. // router info and from the actual router.
  655. // --------------------------------------------------------
  656. spRmProt->CopyCB(&oldrmprotCB);
  657. rgArgs[0] = (DWORD_PTR) oldrmprotCB.szTitle;
  658. rgArgs[1] = (DWORD_PTR) oldrmprotCB.szVendorName;
  659. rgArgs[2] = (DWORD_PTR) rmprotCB.szTitle;
  660. rgArgs[3] = (DWORD_PTR) rmprotCB.szVendorName;
  661. // This may be the same protocol, but installed again
  662. // due to some timing problems.
  663. // --------------------------------------------------------
  664. if ((dwData == spRmProt->GetProtocolId()) &&
  665. (StriCmp((LPCTSTR) oldrmprotCB.szVendorName,
  666. (LPCTSTR) rmprotCB.szVendorName) == 0) &&
  667. (StriCmp((LPCTSTR) oldrmprotCB.szTitle,
  668. (LPCTSTR) rmprotCB.szTitle) == 0))
  669. {
  670. CString stMultipleProtocol;
  671. // Ok, this may be the same protocol, warn
  672. // the user about this potentially confusing
  673. // situation.
  674. // ----------------------------------------------------
  675. stMultipleProtocol.LoadString(IDS_WARN_PROTOCOL_ALREADY_INSTALLED);
  676. ::FormatMessage(FORMAT_MESSAGE_FROM_STRING |
  677. FORMAT_MESSAGE_ARGUMENT_ARRAY,
  678. (LPCTSTR) stMultipleProtocol,
  679. 0,
  680. 0,
  681. szWarning,
  682. DimensionOf(szWarning),
  683. (va_list *) rgArgs);
  684. if (AfxMessageBox(szWarning, MB_YESNO) == IDNO)
  685. return;
  686. }
  687. else
  688. {
  689. ::FormatMessage(FORMAT_MESSAGE_FROM_STRING |
  690. FORMAT_MESSAGE_ARGUMENT_ARRAY,
  691. (LPCTSTR) stFormat,
  692. 0,
  693. 0,
  694. szWarning,
  695. DimensionOf(szWarning),
  696. (va_list *) rgArgs);
  697. if (AfxMessageBox(szWarning, MB_YESNO) == IDNO)
  698. return;
  699. }
  700. // Remove the protocol from the RtrMgr
  701. // --------------------------------------------------------
  702. hr = m_spRm->DeleteRtrMgrProtocol(spRmProt->GetProtocolId(), TRUE);
  703. if (!FHrSucceeded(hr))
  704. {
  705. DisplayIdErrorMessage2(GetSafeHwnd(),
  706. IDS_ERR_UNABLE_TO_REMOVE_PROTOCOL, hr);
  707. return;
  708. }
  709. // Instantiate the configuration object
  710. // and tell it to remove the protocol
  711. // --------------------------------------------------------
  712. hr = CoCreateProtocolConfig(oldrmprotCB.guidConfig,
  713. m_spRouter,
  714. spRmProt->GetTransportId(),
  715. spRmProt->GetProtocolId(),
  716. &spRouterConfig);
  717. if (!FHrSucceeded(hr))
  718. {
  719. //$ Todo: what error do we want to put up here?
  720. // What can the user do at this point?
  721. // ----------------------------------------------------
  722. DisplayErrorMessage(GetSafeHwnd(), hr);
  723. continue;
  724. }
  725. // Note that we can return success for CoCreateProtocolConfig
  726. // and have a NULL spRouterConfig.
  727. // --------------------------------------------------------
  728. if (spRouterConfig)
  729. hr = spRouterConfig->RemoveProtocol(m_spRm->GetMachineName(),
  730. spRmProt->GetTransportId(),
  731. spRmProt->GetProtocolId(),
  732. GetSafeHwnd(),
  733. 0,
  734. m_spRouter,
  735. 0);
  736. //$ Todo: if the Uninstall failed, we should warn the
  737. // user that something failed, what would the text of
  738. // the error message be?
  739. // --------------------------------------------------------
  740. if (!FHrSucceeded(hr))
  741. DisplayErrorMessage(GetSafeHwnd(), hr);
  742. }
  743. }
  744. (*m_ppRmProt) = spRmProtReturn.Transfer();
  745. CBaseDialog::OnOK();
  746. }
  747. /*!--------------------------------------------------------------------------
  748. AddRoutingProtocol
  749. This will take RtrMgr (that is being added to) and a
  750. RtrMgrProtocol (the protocol that is being added) and will add it.
  751. Author: KennT
  752. ---------------------------------------------------------------------------*/
  753. HRESULT AddRoutingProtocol(IRtrMgrInfo *pRm, IRtrMgrProtocolInfo *pRmProt, HWND hWnd)
  754. {
  755. RtrMgrProtocolCB rmprotCB;
  756. HRESULT hr = hrOK;
  757. SPIRouterProtocolConfig spRouterConfig;
  758. SPIRouterInfo spRouter;
  759. // Create the configuration object
  760. // ----------------------------------------------------------------
  761. CORg( pRmProt->CopyCB(&rmprotCB) );
  762. // We can ignore any error code.
  763. // ----------------------------------------------------------------
  764. pRm->GetParentRouterInfo(&spRouter);
  765. // Create the actual configuration object.
  766. // ----------------------------------------------------------------
  767. hr = CoCreateProtocolConfig(rmprotCB.guidConfig,
  768. spRouter,
  769. pRmProt->GetTransportId(),
  770. pRmProt->GetProtocolId(),
  771. &spRouterConfig);
  772. CORg( hr );
  773. // Go ahead and add the protocol.
  774. // ----------------------------------------------------------------
  775. if (spRouterConfig)
  776. hr = spRouterConfig->AddProtocol(pRm->GetMachineName(),
  777. pRmProt->GetTransportId(),
  778. pRmProt->GetProtocolId(),
  779. hWnd,
  780. 0,
  781. spRouter,
  782. 0);
  783. CORg( hr );
  784. Error:
  785. return hr;
  786. }