Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1023 lines
30 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. m_listCtrl.InsertItem(
  549. LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE, 0, (LPCTSTR)rmprotCB.szTitle,
  550. 0, 0, ILI_RTRLIB_PROTOCOL, (LPARAM) rmprotCB.dwProtocolId
  551. );
  552. }
  553. //
  554. // If there are no items, explain this and end the dialog
  555. //
  556. if (!m_listCtrl.GetItemCount()) {
  557. ::AfxMessageBox(IDS_ERR_NOROUTINGPROTOCOLS, MB_OK|MB_ICONINFORMATION);
  558. OnCancel(); return FALSE;
  559. }
  560. //
  561. // Select the first item
  562. //
  563. m_listCtrl.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
  564. return TRUE;
  565. }
  566. //----------------------------------------------------------------------------
  567. // Function: CAddRoutingProtocol::OnDblclkListctrl
  568. //----------------------------------------------------------------------------
  569. VOID
  570. CAddRoutingProtocol::OnDblclkListctrl(
  571. NMHDR* pNMHDR,
  572. LRESULT* pResult
  573. ) {
  574. OnOK();
  575. *pResult = 0;
  576. }
  577. //----------------------------------------------------------------------------
  578. // Function: CAddRoutingProtocol::OnOK
  579. //----------------------------------------------------------------------------
  580. VOID
  581. CAddRoutingProtocol::OnOK(
  582. ) {
  583. SPIEnumRtrMgrProtocolCB spEnumRmProtCB;
  584. RtrMgrProtocolCB rmprotCB;
  585. RtrMgrProtocolCB oldrmprotCB;
  586. SPIEnumRtrMgrProtocolInfo spEnumRmProt;
  587. SPIRtrMgrProtocolInfo spRmProt;
  588. DWORD_PTR dwData;
  589. HRESULT hr = hrOK;
  590. CString stFormat;
  591. SPIRtrMgrProtocolInfo spRmProtReturn;
  592. //
  593. // Get the currently selected item
  594. // ----------------------------------------------------------------
  595. INT iSel = m_listCtrl.GetNextItem(-1, LVNI_SELECTED);
  596. if (iSel == -1) { return; }
  597. // Retrieve its data, which is the protocol ID
  598. // ----------------------------------------------------------------
  599. // Look up the protocol ID in the protocol list
  600. // ----------------------------------------------------------------
  601. m_spRouter->EnumRtrMgrProtocolCB(&spEnumRmProtCB);
  602. dwData = (DWORD)(m_listCtrl.GetItemData(iSel));
  603. // Construct a routing-protocol item
  604. // ----------------------------------------------------------------
  605. while (spEnumRmProtCB->Next(1, &rmprotCB, NULL) == hrOK)
  606. {
  607. if (rmprotCB.dwProtocolId == dwData)
  608. {
  609. hr = CreateRtrMgrProtocolInfo(&spRmProtReturn,
  610. &rmprotCB);
  611. if (!FHrSucceeded(hr))
  612. {
  613. OnCancel();
  614. return;
  615. }
  616. break;
  617. }
  618. }
  619. // What happens if we can't find the matching item
  620. // ----------------------------------------------------------------
  621. if (spRmProtReturn == NULL)
  622. {
  623. //$ Todo: what error message do we want to put up here?
  624. // ------------------------------------------------------------
  625. return;
  626. }
  627. // Now check to see if there are any protocol conflicts
  628. // ----------------------------------------------------------------
  629. stFormat.LoadString(IDS_WARN_ADD_PROTOCOL_CONFLICT);
  630. m_spRm->EnumRtrMgrProtocol(&spEnumRmProt);
  631. for (;spEnumRmProt->Next(1, &spRmProt, NULL) == hrOK; spRmProt.Release())
  632. {
  633. if (PROTO_FROM_PROTOCOL_ID(spRmProt->GetProtocolId()) ==
  634. PROTO_FROM_PROTOCOL_ID(dwData))
  635. {
  636. SPIRouterProtocolConfig spRouterConfig;
  637. TCHAR szWarning[2048];
  638. DWORD_PTR rgArgs[4];
  639. // There is a conflict, ask the user if they
  640. // wish to remove this protocol, if yes then
  641. // we have to remove the protocol from our internal
  642. // router info and from the actual router.
  643. // --------------------------------------------------------
  644. spRmProt->CopyCB(&oldrmprotCB);
  645. rgArgs[0] = (DWORD_PTR) oldrmprotCB.szTitle;
  646. rgArgs[1] = (DWORD_PTR) oldrmprotCB.szVendorName;
  647. rgArgs[2] = (DWORD_PTR) rmprotCB.szTitle;
  648. rgArgs[3] = (DWORD_PTR) rmprotCB.szVendorName;
  649. // This may be the same protocol, but installed again
  650. // due to some timing problems.
  651. // --------------------------------------------------------
  652. if ((dwData == spRmProt->GetProtocolId()) &&
  653. (StriCmp((LPCTSTR) oldrmprotCB.szVendorName,
  654. (LPCTSTR) rmprotCB.szVendorName) == 0) &&
  655. (StriCmp((LPCTSTR) oldrmprotCB.szTitle,
  656. (LPCTSTR) rmprotCB.szTitle) == 0))
  657. {
  658. CString stMultipleProtocol;
  659. // Ok, this may be the same protocol, warn
  660. // the user about this potentially confusing
  661. // situation.
  662. // ----------------------------------------------------
  663. stMultipleProtocol.LoadString(IDS_WARN_PROTOCOL_ALREADY_INSTALLED);
  664. ::FormatMessage(FORMAT_MESSAGE_FROM_STRING |
  665. FORMAT_MESSAGE_ARGUMENT_ARRAY,
  666. (LPCTSTR) stMultipleProtocol,
  667. 0,
  668. 0,
  669. szWarning,
  670. DimensionOf(szWarning),
  671. (va_list *) rgArgs);
  672. if (AfxMessageBox(szWarning, MB_YESNO) == IDNO)
  673. return;
  674. }
  675. else
  676. {
  677. ::FormatMessage(FORMAT_MESSAGE_FROM_STRING |
  678. FORMAT_MESSAGE_ARGUMENT_ARRAY,
  679. (LPCTSTR) stFormat,
  680. 0,
  681. 0,
  682. szWarning,
  683. DimensionOf(szWarning),
  684. (va_list *) rgArgs);
  685. if (AfxMessageBox(szWarning, MB_YESNO) == IDNO)
  686. return;
  687. }
  688. // Remove the protocol from the RtrMgr
  689. // --------------------------------------------------------
  690. hr = m_spRm->DeleteRtrMgrProtocol(spRmProt->GetProtocolId(), TRUE);
  691. if (!FHrSucceeded(hr))
  692. {
  693. DisplayIdErrorMessage2(GetSafeHwnd(),
  694. IDS_ERR_UNABLE_TO_REMOVE_PROTOCOL, hr);
  695. return;
  696. }
  697. // Instantiate the configuration object
  698. // and tell it to remove the protocol
  699. // --------------------------------------------------------
  700. hr = CoCreateProtocolConfig(oldrmprotCB.guidConfig,
  701. m_spRouter,
  702. spRmProt->GetTransportId(),
  703. spRmProt->GetProtocolId(),
  704. &spRouterConfig);
  705. if (!FHrSucceeded(hr))
  706. {
  707. //$ Todo: what error do we want to put up here?
  708. // What can the user do at this point?
  709. // ----------------------------------------------------
  710. DisplayErrorMessage(GetSafeHwnd(), hr);
  711. continue;
  712. }
  713. // Note that we can return success for CoCreateProtocolConfig
  714. // and have a NULL spRouterConfig.
  715. // --------------------------------------------------------
  716. if (spRouterConfig)
  717. hr = spRouterConfig->RemoveProtocol(m_spRm->GetMachineName(),
  718. spRmProt->GetTransportId(),
  719. spRmProt->GetProtocolId(),
  720. GetSafeHwnd(),
  721. 0,
  722. m_spRouter,
  723. 0);
  724. //$ Todo: if the Uninstall failed, we should warn the
  725. // user that something failed, what would the text of
  726. // the error message be?
  727. // --------------------------------------------------------
  728. if (!FHrSucceeded(hr))
  729. DisplayErrorMessage(GetSafeHwnd(), hr);
  730. }
  731. }
  732. (*m_ppRmProt) = spRmProtReturn.Transfer();
  733. CBaseDialog::OnOK();
  734. }
  735. /*!--------------------------------------------------------------------------
  736. AddRoutingProtocol
  737. This will take RtrMgr (that is being added to) and a
  738. RtrMgrProtocol (the protocol that is being added) and will add it.
  739. Author: KennT
  740. ---------------------------------------------------------------------------*/
  741. HRESULT AddRoutingProtocol(IRtrMgrInfo *pRm, IRtrMgrProtocolInfo *pRmProt, HWND hWnd)
  742. {
  743. RtrMgrProtocolCB rmprotCB;
  744. HRESULT hr = hrOK;
  745. SPIRouterProtocolConfig spRouterConfig;
  746. SPIRouterInfo spRouter;
  747. // Create the configuration object
  748. // ----------------------------------------------------------------
  749. CORg( pRmProt->CopyCB(&rmprotCB) );
  750. // We can ignore any error code.
  751. // ----------------------------------------------------------------
  752. pRm->GetParentRouterInfo(&spRouter);
  753. // Create the actual configuration object.
  754. // ----------------------------------------------------------------
  755. hr = CoCreateProtocolConfig(rmprotCB.guidConfig,
  756. spRouter,
  757. pRmProt->GetTransportId(),
  758. pRmProt->GetProtocolId(),
  759. &spRouterConfig);
  760. CORg( hr );
  761. // Go ahead and add the protocol.
  762. // ----------------------------------------------------------------
  763. if (spRouterConfig)
  764. hr = spRouterConfig->AddProtocol(pRm->GetMachineName(),
  765. pRmProt->GetTransportId(),
  766. pRmProt->GetProtocolId(),
  767. hWnd,
  768. 0,
  769. spRouter,
  770. 0);
  771. CORg( hr );
  772. Error:
  773. return hr;
  774. }