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.

8475 lines
269 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. info.cpp
  7. FILE HISTORY:
  8. Wei Jiang : 10/27/98 --- Add SetExternalRefreshObject to
  9. IRouterInfo and RouterInfo implementation
  10. to allow multiple router info the share
  11. the same AutoRefresh settings.
  12. */
  13. #include "stdafx.h"
  14. #include "lsa.h"
  15. #include "infoi.h"
  16. #include "rtrstr.h" // common router strings
  17. #include "refresh.h" // RouterRefreshObject
  18. #include "routprot.h"
  19. #include "rtrutilp.h"
  20. long s_cConnections = 1; // use for AdviseSink connection ids
  21. TFSCORE_API(HRESULT) CreateRouterInfo(IRouterInfo **ppRouterInfo, HWND hWndSync, LPCWSTR szMachine)
  22. {
  23. Assert(ppRouterInfo);
  24. HRESULT hr = hrOK;
  25. RouterInfo * pRouterInfo = NULL;
  26. COM_PROTECT_TRY
  27. {
  28. pRouterInfo = new RouterInfo(hWndSync, szMachine);
  29. *ppRouterInfo = pRouterInfo;
  30. }
  31. COM_PROTECT_CATCH;
  32. return hr;
  33. }
  34. IMPLEMENT_WEAKREF_ADDREF_RELEASE(RouterInfo);
  35. STDMETHODIMP RouterInfo::QueryInterface(REFIID iid,void **ppv)
  36. {
  37. *ppv = 0;
  38. if (iid == IID_IUnknown)
  39. *ppv = (IUnknown *) (IRouterInfo *) this;
  40. else if (iid == IID_IRouterInfo)
  41. *ppv = (IRouterInfo *) this;
  42. else if (iid == IID_IRouterRefreshAccess)
  43. *ppv = (IRouterRefreshAccess *) this;
  44. else if (iid == IID_IRouterAdminAccess)
  45. *ppv = (IRouterAdminAccess *) this;
  46. else
  47. return E_NOINTERFACE;
  48. ((IUnknown *) *ppv)->AddRef();
  49. return hrOK;
  50. }
  51. DEBUG_DECLARE_INSTANCE_COUNTER(RouterInfo)
  52. RouterInfo::RouterInfo(HWND hWndSync, LPCWSTR machineName)
  53. : m_bDisconnect(FALSE),
  54. m_hWndSync(hWndSync),
  55. m_dwRouterType(0),
  56. m_dwFlags(0),
  57. m_hMachineConfig(NULL),
  58. m_hMachineAdmin(NULL),
  59. m_fIsAdminInfoSet(FALSE),
  60. m_pbPassword(NULL),
  61. m_stMachine(machineName),
  62. m_cPassword(0)
  63. {
  64. DEBUG_INCREMENT_INSTANCE_COUNTER(RouterInfo);
  65. InitializeCriticalSection(&m_critsec);
  66. m_VersionInfo.dwRouterVersion = 0;
  67. m_VersionInfo.dwOsMajorVersion = 0;
  68. m_VersionInfo.dwOsMinorVersion = 0;
  69. m_VersionInfo.dwOsServicePack = 0;
  70. m_VersionInfo.dwOsBuildNo = 0;
  71. m_VersionInfo.dwOsFlags = 0;
  72. m_VersionInfo.dwRouterFlags = 0;
  73. }
  74. RouterInfo::~RouterInfo()
  75. {
  76. DEBUG_DECREMENT_INSTANCE_COUNTER(RouterInfo);
  77. Unload();
  78. DeleteCriticalSection(&m_critsec);
  79. ::SecureZeroMemory(m_pbPassword, m_cPassword);
  80. delete m_pbPassword;
  81. m_pbPassword = NULL;
  82. m_cPassword = 0;
  83. }
  84. STDMETHODIMP_(DWORD) RouterInfo::GetFlags()
  85. {
  86. RtrCriticalSection rtrCritSec(&m_critsec);
  87. return m_dwFlags;
  88. }
  89. STDMETHODIMP RouterInfo::SetFlags(DWORD dwFlags)
  90. {
  91. RtrCriticalSection rtrCritSec(&m_critsec);
  92. HRESULT hr = hrOK;
  93. COM_PROTECT_TRY
  94. {
  95. m_dwFlags = dwFlags;
  96. }
  97. COM_PROTECT_CATCH;
  98. return hr;
  99. }
  100. /*!--------------------------------------------------------------------------
  101. RouterInfo::Load
  102. Implementation of IRouterInfo::Load
  103. Author: KennT
  104. ---------------------------------------------------------------------------*/
  105. STDMETHODIMP RouterInfo::Load(LPCOLESTR pszMachine,
  106. HANDLE hMachine
  107. )
  108. {
  109. HRESULT hr = hrOK;
  110. RtrCriticalSection rtrCritSec(&m_critsec);
  111. TCHAR* psz;
  112. POSITION pos;
  113. DWORD dwErr, dwType, dwSize, dwRouterType;
  114. WCHAR* pwsz, wszMachine[MAX_PATH+3];
  115. HKEY hkMachine = NULL;
  116. USES_CONVERSION;
  117. COM_PROTECT_TRY
  118. {
  119. // Unload any existing information
  120. // ------------------------------------------------------------
  121. Unload();
  122. if (!pszMachine)
  123. {
  124. m_stMachine = TEXT("");
  125. pwsz = NULL;
  126. }
  127. else
  128. {
  129. m_stMachine = pszMachine;
  130. pwsz = StrnCpyWFromT(wszMachine, pszMachine, MAX_PATH);
  131. }
  132. // Get the version info
  133. // ------------------------------------------------------------
  134. CWRg( ConnectRegistry(GetMachineName(), &hkMachine) );
  135. CORg( QueryRouterVersionInfo(hkMachine, &m_VersionInfo) );
  136. // Get the router type
  137. // ------------------------------------------------------------
  138. CORg( QueryRouterType(hkMachine, &dwRouterType, &m_VersionInfo) );
  139. m_dwRouterType = dwRouterType;
  140. // If 'hmachine' was not specified, connect
  141. // ------------------------------------------------------------
  142. CORg( TryToConnect(pwsz, hMachine) );
  143. Assert(m_hMachineConfig);
  144. hMachine = m_hMachineConfig;
  145. MprConfigServerRefresh(m_hMachineConfig);
  146. // If the caller did not specify a list of LAN adapters,
  147. // load a list of the LAN adapters from HKLM\Soft\MS\NT\NetworkCards
  148. // ------------------------------------------------------------
  149. CORg( RouterInfo::LoadInstalledInterfaceList(OLE2CT(pszMachine),
  150. &m_IfCBList) );
  151. // This will fix a lot of weird bugs.
  152. // If the router has not been configured (if the configured flag
  153. // has not been set), then we can skip the rest of the
  154. // configuration section.
  155. // ------------------------------------------------------------
  156. // if (!(m_VersionInfo.dwRouterFlags & RouterSnapin_IsConfigured))
  157. // {
  158. // hr = hrOK;
  159. // goto Error;
  160. // }
  161. if (m_VersionInfo.dwRouterFlags & RouterSnapin_IsConfigured)
  162. {
  163. // If the caller did not specify a list of router-managers,
  164. // load a list of the router-managers from HKLM\Soft\MS\Router
  165. // ------------------------------------------------------------
  166. CORg( RouterInfo::LoadInstalledRtrMgrList(pszMachine,
  167. &m_RmCBList) );
  168. // Load a list with the routing-protocols for each router-manager
  169. // ------------------------------------------------------------
  170. pos = m_RmCBList.GetHeadPosition();
  171. while (pos)
  172. {
  173. SRtrMgrCB* pcb = m_RmCBList.GetNext(pos);
  174. CORg( RouterInfo::LoadInstalledRtrMgrProtocolList(
  175. pszMachine, pcb->dwTransportId,
  176. &m_RmProtCBList,
  177. this));
  178. }
  179. // Load router-level info
  180. // ------------------------------------------------------------
  181. MPR_SERVER_0* pInfo;
  182. dwErr = ::MprConfigServerGetInfo(m_hMachineConfig,
  183. 0,
  184. (LPBYTE *) &pInfo
  185. );
  186. if (dwErr == NO_ERROR)
  187. {
  188. m_SRouterCB.dwLANOnlyMode = pInfo->fLanOnlyMode;
  189. ::MprConfigBufferFree(pInfo);
  190. }
  191. // Load the router-managers
  192. // ------------------------------------------------------------
  193. CORg( LoadRtrMgrList() );
  194. }
  195. // Load the interfaces
  196. // ------------------------------------------------------------
  197. CORg( LoadInterfaceList() );
  198. hr = hrOK;
  199. COM_PROTECT_ERROR_LABEL;
  200. }
  201. COM_PROTECT_CATCH;
  202. if (hkMachine)
  203. DisconnectRegistry( hkMachine );
  204. if (!FHrSucceeded(hr))
  205. Unload();
  206. return hr;
  207. }
  208. /*!--------------------------------------------------------------------------
  209. RouterInfo::Save
  210. -
  211. Author: KennT
  212. ---------------------------------------------------------------------------*/
  213. STDMETHODIMP RouterInfo::Save(LPCOLESTR pszMachine,
  214. HANDLE hMachine )
  215. {
  216. RtrCriticalSection rtrCritSec(&m_critsec);
  217. return hrOK;
  218. }
  219. /*!--------------------------------------------------------------------------
  220. RouterInfo::Unload
  221. -
  222. Author: KennT
  223. ---------------------------------------------------------------------------*/
  224. STDMETHODIMP RouterInfo::Unload( )
  225. {
  226. HRESULT hr = hrOK;
  227. RtrCriticalSection rtrCritSec(&m_critsec);
  228. COM_PROTECT_TRY
  229. {
  230. // Destroy all COM objects, this includes interface and
  231. // router-manager objects
  232. // ------------------------------------------------------------
  233. Destruct();
  234. // Empty the list loaded using RouterInfo::LoadInstalledRtrMgrList
  235. // ------------------------------------------------------------
  236. while (!m_RmCBList.IsEmpty())
  237. delete m_RmCBList.RemoveHead();
  238. // Empty the list loaded using RouterInfo::LoadInstalledRmProtList
  239. // ------------------------------------------------------------
  240. while (!m_RmProtCBList.IsEmpty())
  241. delete m_RmProtCBList.RemoveHead();
  242. // Empty the list loaded using RouterInfo::LoadInstalledInterfaceList
  243. // ------------------------------------------------------------
  244. while (!m_IfCBList.IsEmpty())
  245. delete m_IfCBList.RemoveHead();
  246. DoDisconnect();
  247. m_dwRouterType = 0;
  248. }
  249. COM_PROTECT_CATCH;
  250. return hr;
  251. }
  252. /*!--------------------------------------------------------------------------
  253. RouterInfo::Merge
  254. -
  255. Author: KennT
  256. ---------------------------------------------------------------------------*/
  257. STDMETHODIMP RouterInfo::Merge(IRouterInfo *pNewRouter)
  258. {
  259. RtrCriticalSection rtrCritSec(&m_critsec);
  260. HRESULT hr = hrOK;
  261. RouterCB routerCB;
  262. COM_PROTECT_TRY
  263. {
  264. // There are several steps to this process, we need to sync
  265. // up the CBs and then the objects. However, we should also
  266. // do a sanity check to see that all of the objects have CBs
  267. // but not vice versa (there may be CBs that don't running
  268. // objects associated with them).
  269. // ------------------------------------------------------------
  270. // Merge the basic router dta
  271. // ------------------------------------------------------------
  272. pNewRouter->CopyCB(&routerCB);
  273. m_SRouterCB.LoadFrom(&routerCB);
  274. // Copy over the version information
  275. // ------------------------------------------------------------
  276. pNewRouter->GetRouterVersionInfo(&m_VersionInfo);
  277. // Sync up the RtrMgrCB
  278. // ------------------------------------------------------------
  279. CORg( MergeRtrMgrCB(pNewRouter) );
  280. // Sync up the InterfaceCB
  281. // ------------------------------------------------------------
  282. CORg( MergeInterfaceCB(pNewRouter) );
  283. // Sync up the RtrMgrProtocolCB
  284. // ------------------------------------------------------------
  285. CORg( MergeRtrMgrProtocolCB(pNewRouter) );
  286. // Sync up the RtrMgrs
  287. // ------------------------------------------------------------
  288. CORg( MergeRtrMgrs(pNewRouter) );
  289. // Sync up the Interfaces
  290. // ------------------------------------------------------------
  291. CORg( MergeInterfaces(pNewRouter) );
  292. m_dwRouterType = pNewRouter->GetRouterType();
  293. COM_PROTECT_ERROR_LABEL;
  294. }
  295. COM_PROTECT_CATCH;
  296. return hrOK;
  297. }
  298. /*!--------------------------------------------------------------------------
  299. RouterInfo::GetRefreshObject
  300. -
  301. Author: KennT
  302. ---------------------------------------------------------------------------*/
  303. STDMETHODIMP RouterInfo::GetRefreshObject(IRouterRefresh **ppRefresh)
  304. {
  305. HRESULT hr = hrOK;
  306. COM_PROTECT_TRY
  307. {
  308. // ------------------------------------------------------------
  309. if ((IRouterRefresh*)m_spRefreshObject && ppRefresh)
  310. {
  311. *ppRefresh = m_spRefreshObject;
  312. (*ppRefresh)->AddRef();
  313. }
  314. else
  315. {
  316. if (ppRefresh)
  317. *ppRefresh = NULL;
  318. hr = E_FAIL;
  319. }
  320. }
  321. COM_PROTECT_CATCH;
  322. return hr;
  323. }
  324. /*!--------------------------------------------------------------------------
  325. RouterInfo::SetExternalRefreshObject
  326. -
  327. To make multiple RouterInfo share the same AutoRefresh Object, use this
  328. function.
  329. Author: WeiJiang
  330. ---------------------------------------------------------------------------*/
  331. STDMETHODIMP RouterInfo::SetExternalRefreshObject(IRouterRefresh *pRefresh)
  332. {
  333. HRESULT hr = hrOK;
  334. m_spRefreshObject.Release();
  335. // set to nothing is also allowed
  336. m_spRefreshObject.Set(pRefresh);
  337. return hr;
  338. }
  339. /*!--------------------------------------------------------------------------
  340. RouterInfo::CopyCB
  341. -
  342. Author: KennT
  343. ---------------------------------------------------------------------------*/
  344. STDMETHODIMP RouterInfo::CopyCB(RouterCB *pRouterCB)
  345. {
  346. Assert(pRouterCB);
  347. RtrCriticalSection rtrCritSec(&m_critsec);
  348. HRESULT hr = hrOK;
  349. COM_PROTECT_TRY
  350. {
  351. pRouterCB->dwLANOnlyMode = m_SRouterCB.dwLANOnlyMode;
  352. }
  353. COM_PROTECT_CATCH;
  354. return hr;
  355. }
  356. /*!--------------------------------------------------------------------------
  357. RouterInfo::GetMachineName
  358. -
  359. Author: KennT
  360. ---------------------------------------------------------------------------*/
  361. STDMETHODIMP_(LPCOLESTR) RouterInfo::GetMachineName()
  362. {
  363. //$UNICODE : kennt, assumes that we are native UNICODE
  364. // Assumes OLE == W
  365. // ----------------------------------------------------------------
  366. RtrCriticalSection rtrCritSec(&m_critsec);
  367. return (LPCTSTR) m_stMachine;
  368. }
  369. /*!--------------------------------------------------------------------------
  370. RouterInfo::SetMachineName
  371. -
  372. Author: KennT
  373. ---------------------------------------------------------------------------*/
  374. STDMETHODIMP RouterInfo::SetMachineName(LPCOLESTR pszMachineName)
  375. {
  376. //$UNICODE : kennt, assumes that we are native UNICODE
  377. // Assumes OLE == W
  378. // ----------------------------------------------------------------
  379. RtrCriticalSection rtrCritSec(&m_critsec);
  380. HRESULT hr = hrOK;
  381. COM_PROTECT_TRY
  382. {
  383. m_stMachine = pszMachineName;
  384. }
  385. COM_PROTECT_CATCH;
  386. return hr;
  387. }
  388. /*!--------------------------------------------------------------------------
  389. RouterInfo::GetRouterType
  390. -
  391. Author: KennT
  392. ---------------------------------------------------------------------------*/
  393. STDMETHODIMP_(DWORD) RouterInfo::GetRouterType()
  394. {
  395. RtrCriticalSection rtrCritSec(&m_critsec);
  396. return m_dwRouterType;
  397. }
  398. STDMETHODIMP RouterInfo::GetRouterVersionInfo(RouterVersionInfo *pVerInfo)
  399. {
  400. RtrCriticalSection rtrCritSec(&m_critsec);
  401. HRESULT hr = hrOK;
  402. COM_PROTECT_TRY
  403. {
  404. *pVerInfo = m_VersionInfo;
  405. pVerInfo->dwSize = sizeof(RouterVersionInfo);
  406. }
  407. COM_PROTECT_CATCH;
  408. return hr;
  409. }
  410. /*!--------------------------------------------------------------------------
  411. RouterInfo::EnumRtrMgrCB
  412. -
  413. Author: KennT
  414. ---------------------------------------------------------------------------*/
  415. STDMETHODIMP RouterInfo::EnumRtrMgrCB( IEnumRtrMgrCB **ppEnumRtrMgrCB)
  416. {
  417. RtrCriticalSection rtrCritSec(&m_critsec);
  418. HRESULT hr = hrOK;
  419. COM_PROTECT_TRY
  420. {
  421. hr = CreateEnumFromSRmCBList(&m_RmCBList, ppEnumRtrMgrCB);
  422. }
  423. COM_PROTECT_CATCH;
  424. return hr;
  425. }
  426. /*!--------------------------------------------------------------------------
  427. RouterInfo::EnumInterfaceCB
  428. -
  429. Author: KennT
  430. ---------------------------------------------------------------------------*/
  431. STDMETHODIMP RouterInfo::EnumInterfaceCB( IEnumInterfaceCB **ppEnumInterfaceCB)
  432. {
  433. RtrCriticalSection rtrCritSec(&m_critsec);
  434. HRESULT hr = hrOK;
  435. COM_PROTECT_TRY
  436. {
  437. hr = CreateEnumFromSIfCBList(&m_IfCBList, ppEnumInterfaceCB);
  438. }
  439. COM_PROTECT_CATCH;
  440. return hr;
  441. }
  442. /*!--------------------------------------------------------------------------
  443. RouterInfo::EnumRtrMgrProtocolCB
  444. -
  445. Author: KennT
  446. ---------------------------------------------------------------------------*/
  447. HRESULT RouterInfo::EnumRtrMgrProtocolCB(IEnumRtrMgrProtocolCB **ppEnumRmProtCB)
  448. {
  449. RtrCriticalSection rtrCritSec(&m_critsec);
  450. HRESULT hr = hrOK;
  451. COM_PROTECT_TRY
  452. {
  453. hr = CreateEnumFromSRmProtCBList(&m_RmProtCBList, ppEnumRmProtCB);
  454. }
  455. COM_PROTECT_CATCH;
  456. return hr;
  457. }
  458. /*!--------------------------------------------------------------------------
  459. RouterInfo::EnumRtrMgrInterfaceCB
  460. -
  461. Author: KennT
  462. ---------------------------------------------------------------------------*/
  463. HRESULT RouterInfo::EnumRtrMgrInterfaceCB(IEnumRtrMgrInterfaceCB **ppEnumRmIfCB)
  464. {
  465. RtrCriticalSection rtrCritSec(&m_critsec);
  466. return E_NOTIMPL;
  467. }
  468. /*!--------------------------------------------------------------------------
  469. EnumRtrMgrProtocolInterfaceCB
  470. -
  471. Author: KennT
  472. ---------------------------------------------------------------------------*/
  473. HRESULT RouterInfo::EnumRtrMgrProtocolInterfaceCB(IEnumRtrMgrProtocolInterfaceCB **ppEnumRmProtIfCB)
  474. {
  475. RtrCriticalSection rtrCritSec(&m_critsec);
  476. return E_NOTIMPL;
  477. }
  478. /*!--------------------------------------------------------------------------
  479. RouterInfo::EnumRtrMgr
  480. -
  481. Author: KennT
  482. ---------------------------------------------------------------------------*/
  483. STDMETHODIMP RouterInfo::EnumRtrMgr( IEnumRtrMgrInfo **ppEnumRtrMgr)
  484. {
  485. RtrCriticalSection rtrCritSec(&m_critsec);
  486. HRESULT hr = hrOK;
  487. COM_PROTECT_TRY
  488. {
  489. hr = CreateEnumFromRmList(&m_RmList, ppEnumRtrMgr);
  490. }
  491. COM_PROTECT_CATCH;
  492. return hr;
  493. }
  494. /*!--------------------------------------------------------------------------
  495. RouterInfo::FindRtrMgr
  496. S_OK is returned if a RtrMgrInfo is found.
  497. S_FALSE is returned if a RtrMgrInfo was NOT found.
  498. error codes returned otherwise.
  499. Author: KennT
  500. ---------------------------------------------------------------------------*/
  501. STDMETHODIMP RouterInfo::FindRtrMgr( DWORD dwTransportId,
  502. IRtrMgrInfo **ppInfo)
  503. {
  504. RtrCriticalSection rtrCritSec(&m_critsec);
  505. HRESULT hr = hrFalse;
  506. POSITION pos;
  507. SPIRtrMgrInfo sprm;
  508. SRmData rmData;
  509. COM_PROTECT_TRY
  510. {
  511. if (ppInfo)
  512. *ppInfo = NULL;
  513. // Look through the list of rtr mgrs for the one that matches
  514. // ------------------------------------------------------------
  515. pos = m_RmList.GetHeadPosition();
  516. while (pos)
  517. {
  518. rmData = m_RmList.GetNext(pos);
  519. sprm.Set( rmData.m_pRmInfo );
  520. Assert(sprm);
  521. if (sprm->GetTransportId() == dwTransportId)
  522. {
  523. hr = hrOK;
  524. if (ppInfo)
  525. {
  526. *ppInfo = sprm.Transfer();
  527. }
  528. break;
  529. }
  530. }
  531. }
  532. COM_PROTECT_CATCH;
  533. return hr;
  534. }
  535. /*!--------------------------------------------------------------------------
  536. RouterInfo::AddRtrMgr
  537. -
  538. Author: KennT
  539. ---------------------------------------------------------------------------*/
  540. STDMETHODIMP RouterInfo::AddRtrMgr( IRtrMgrInfo *pInfo,
  541. IInfoBase *pGlobalInfo,
  542. IInfoBase *pClientInfo)
  543. {
  544. RtrCriticalSection rtrCritSec(&m_critsec);
  545. HRESULT hr = hrOK;
  546. DWORD dwConnection = 0;
  547. SRmData rmData;
  548. Assert(pInfo);
  549. COM_PROTECT_TRY
  550. {
  551. // Fail if there is a duplicate
  552. // ------------------------------------------------------------
  553. if (FHrOK(FindRtrMgr(pInfo->GetTransportId(), NULL)))
  554. CORg(E_INVALIDARG);
  555. //$ Review: kennt, if any of these calls fail, how do we
  556. // clean up correctly?
  557. // ------------------------------------------------------------
  558. // save the new structure
  559. // ------------------------------------------------------------
  560. CORg( pInfo->Save(GetMachineName(),
  561. m_hMachineConfig,
  562. NULL,
  563. pGlobalInfo,
  564. pClientInfo,
  565. 0) );
  566. // add the new structure to our list
  567. // ------------------------------------------------------------
  568. rmData.m_pRmInfo = pInfo;
  569. m_RmList.AddTail(rmData);
  570. pInfo->AddWeakRef();
  571. pInfo->SetParentRouterInfo(this);
  572. m_AdviseList.NotifyChange(ROUTER_CHILD_ADD, ROUTER_OBJ_Rm, 0);
  573. COM_PROTECT_ERROR_LABEL;
  574. }
  575. COM_PROTECT_CATCH;
  576. return hr;
  577. }
  578. /*!--------------------------------------------------------------------------
  579. RouterInfo::DeleteRtrMgr
  580. -
  581. This function deletes a router-manager from the router.
  582. A side-effect of this deletion is that all RtrMgrInterfaceInfo
  583. objects which refer to this router-manager are also deleted.
  584. Author: KennT
  585. ---------------------------------------------------------------------------*/
  586. STDMETHODIMP RouterInfo::DeleteRtrMgr( DWORD dwTransportId, BOOL fRemove )
  587. {
  588. RtrCriticalSection rtrCritSec(&m_critsec);
  589. HRESULT hr = hrOK;
  590. HRESULT hrIf;
  591. POSITION pos;
  592. POSITION posRM;
  593. POSITION posIf;
  594. SPIRtrMgrInfo sprm;
  595. SPIInterfaceInfo spIf;
  596. SRmData rmData;
  597. COM_PROTECT_TRY
  598. {
  599. pos = m_RmList.GetHeadPosition();
  600. while (pos)
  601. {
  602. posRM = pos;
  603. rmData = m_RmList.GetNext(pos);
  604. sprm.Set( rmData.m_pRmInfo );
  605. Assert(sprm);
  606. if (sprm->GetTransportId() == dwTransportId)
  607. break;
  608. sprm.Release();
  609. }
  610. // did we find a router-manager?
  611. // ------------------------------------------------------------
  612. if (sprm)
  613. {
  614. // get a list of the InterfaceInfo objects for
  615. // interfaces over which this router-manager is configured
  616. // --------------------------------------------------------
  617. posIf = m_IfList.GetHeadPosition();
  618. while (posIf)
  619. {
  620. spIf.Set( m_IfList.GetNext(posIf) );
  621. hrIf = spIf->FindRtrMgrInterface(dwTransportId, NULL);
  622. // go through the list and remove the router-manager from
  623. // each interface
  624. // ----------------------------------------------------
  625. if (hrIf == hrFalse)
  626. {
  627. spIf->DeleteRtrMgrInterface(dwTransportId, fRemove);
  628. }
  629. }
  630. // remove the router-manager from our list
  631. // --------------------------------------------------------
  632. Assert(rmData.m_pRmInfo == sprm);
  633. SRmData::Destroy( &rmData );
  634. m_RmList.RemoveAt(posRM);
  635. // finally, remove the router-manger itself
  636. // --------------------------------------------------------
  637. if (fRemove)
  638. sprm->Delete(GetMachineName(), NULL);
  639. m_AdviseList.NotifyChange(ROUTER_CHILD_DELETE, ROUTER_OBJ_Rm, 0);
  640. }
  641. else
  642. hr = E_INVALIDARG;
  643. }
  644. COM_PROTECT_CATCH;
  645. return hr;
  646. }
  647. /*!--------------------------------------------------------------------------
  648. RouterInfo::ReleaseRtrMgr
  649. This function will release the AddRef() that this object has
  650. on the child. This allows us to transfer child objects from
  651. one router to another.
  652. Author: KennT
  653. ---------------------------------------------------------------------------*/
  654. STDMETHODIMP RouterInfo::ReleaseRtrMgr( DWORD dwTransportId )
  655. {
  656. HRESULT hr = hrOK;
  657. POSITION pos, posRm;
  658. SRmData rmData;
  659. COM_PROTECT_TRY
  660. {
  661. pos = m_RmList.GetHeadPosition();
  662. while (pos)
  663. {
  664. // Save the position (so that we can delete it)
  665. posRm = pos;
  666. rmData = m_RmList.GetNext(pos);
  667. if (rmData.m_pRmInfo &&
  668. (rmData.m_pRmInfo->GetTransportId() == dwTransportId))
  669. {
  670. // When releasing, we need to disconnect (since the
  671. // main handle is controlled by the router info).
  672. rmData.m_pRmInfo->DoDisconnect();
  673. rmData.m_pRmInfo->ReleaseWeakRef();
  674. rmData.m_pRmInfo = NULL;
  675. // release this node from the list
  676. m_RmList.RemoveAt(posRm);
  677. break;
  678. }
  679. }
  680. }
  681. COM_PROTECT_CATCH;
  682. return hr;
  683. }
  684. /*!--------------------------------------------------------------------------
  685. RouterInfo::EnumInterface
  686. -
  687. Author: KennT
  688. ---------------------------------------------------------------------------*/
  689. STDMETHODIMP RouterInfo::EnumInterface(IEnumInterfaceInfo **ppEnumInterface)
  690. {
  691. RtrCriticalSection rtrCritSec(&m_critsec);
  692. HRESULT hr = hrOK;
  693. COM_PROTECT_TRY
  694. {
  695. hr = CreateEnumFromInterfaceList(&m_IfList, ppEnumInterface);
  696. }
  697. COM_PROTECT_CATCH;
  698. return hr;
  699. }
  700. /*!--------------------------------------------------------------------------
  701. RouterInfo::FindInterface
  702. S_OK is returned if an InterfaceInfo is found.
  703. S_FALSE is returned if an InterfaceInfo was NOT found.
  704. error codes returned otherwise.
  705. Author: KennT
  706. ---------------------------------------------------------------------------*/
  707. STDMETHODIMP RouterInfo::FindInterface(LPCOLESTR pszInterface,
  708. IInterfaceInfo **ppInfo)
  709. {
  710. RtrCriticalSection rtrCritSec(&m_critsec);
  711. HRESULT hr = hrFalse;
  712. POSITION pos;
  713. SPIInterfaceInfo spIf;
  714. COM_PROTECT_TRY
  715. {
  716. if (ppInfo)
  717. *ppInfo = NULL;
  718. // Look through the list of rtr mgrs for the one that matches
  719. // ------------------------------------------------------------
  720. pos = m_IfList.GetHeadPosition();
  721. while (pos)
  722. {
  723. spIf.Set(m_IfList.GetNext(pos));
  724. Assert(spIf);
  725. if (StriCmpW(spIf->GetId(), pszInterface) == 0)
  726. {
  727. hr = hrOK;
  728. if (ppInfo)
  729. {
  730. *ppInfo = spIf.Transfer();
  731. }
  732. break;
  733. }
  734. }
  735. }
  736. COM_PROTECT_CATCH;
  737. return hr;
  738. }
  739. /*!--------------------------------------------------------------------------
  740. RouterInfo::FindInterfaceByName
  741. -
  742. Author: KennT
  743. ---------------------------------------------------------------------------*/
  744. HRESULT RouterInfo::FindInterfaceByName(LPCOLESTR pszName,
  745. IInterfaceInfo **ppInfo)
  746. {
  747. RtrCriticalSection rtrCritSec(&m_critsec);
  748. HRESULT hr = hrFalse;
  749. POSITION pos;
  750. SPIInterfaceInfo spIf;
  751. COM_PROTECT_TRY
  752. {
  753. if (ppInfo)
  754. *ppInfo = NULL;
  755. // Look through the list of rtr mgrs for the one that matches
  756. // ------------------------------------------------------------
  757. pos = m_IfList.GetHeadPosition();
  758. while (pos)
  759. {
  760. spIf.Set(m_IfList.GetNext(pos));
  761. Assert(spIf);
  762. if (StriCmpW(spIf->GetTitle(), pszName) == 0)
  763. {
  764. hr = hrOK;
  765. if (ppInfo)
  766. {
  767. *ppInfo = spIf.Transfer();
  768. }
  769. break;
  770. }
  771. }
  772. }
  773. COM_PROTECT_CATCH;
  774. return hr;
  775. }
  776. /*!--------------------------------------------------------------------------
  777. RouterInfo::AddInterfaceInternal
  778. fForce - if this is TRUE, then we require that the Save succeeded.
  779. else, we ignore the error.
  780. fAddToRouter - if this is TRUE, we call the InterfaceInfo::Save,
  781. else, we do not call it (and do not change router state).
  782. fMoveRmIf - if this is TRUE, we have to convert the RtrMgrIf's to
  783. point to the one's in THIS router info.
  784. Author: KennT
  785. ---------------------------------------------------------------------------*/
  786. HRESULT RouterInfo::AddInterfaceInternal(IInterfaceInfo *pInfo,
  787. BOOL fForce,
  788. BOOL fAddToRouter)
  789. {
  790. RtrCriticalSection rtrCritSec(&m_critsec);
  791. HRESULT hr = hrOK;
  792. Assert(pInfo);
  793. COM_PROTECT_TRY
  794. {
  795. // Fail if there is a duplicate
  796. // ------------------------------------------------------------
  797. if (FHrOK(FindInterface(pInfo->GetId(), NULL)))
  798. CORg(E_INVALIDARG);
  799. // Also need to check that the friendly name is unique.
  800. // ------------------------------------------------------------
  801. if (FHrOK(FindInterfaceByName(pInfo->GetTitle(), NULL)))
  802. CORg(E_INVALIDARG);
  803. //$ Review: kennt, if any of these calls fail, how do we
  804. // clean up correctly?
  805. // ------------------------------------------------------------
  806. if (fAddToRouter)
  807. {
  808. // save the new structure
  809. // --------------------------------------------------------
  810. hr = pInfo->Save(GetMachineName(), m_hMachineConfig, NULL);
  811. if (fForce)
  812. CORg( hr );
  813. }
  814. // add the new structure to our list
  815. // ------------------------------------------------------------
  816. m_IfList.AddTail(pInfo);
  817. pInfo->AddWeakRef();
  818. pInfo->SetParentRouterInfo(this);
  819. m_AdviseList.NotifyChange(ROUTER_CHILD_ADD, ROUTER_OBJ_If, 0);
  820. COM_PROTECT_ERROR_LABEL;
  821. }
  822. COM_PROTECT_CATCH;
  823. return hr;
  824. }
  825. /*!--------------------------------------------------------------------------
  826. RouterInfo::NotifyRtrMgrInterfaceOfMove
  827. Notify the appropriate RouterManagers that a new interface
  828. has been added.
  829. Author: KennT
  830. ---------------------------------------------------------------------------*/
  831. HRESULT RouterInfo::NotifyRtrMgrInterfaceOfMove(IInterfaceInfo *pIf)
  832. {
  833. HRESULT hr = hrOK;
  834. SPIEnumRtrMgrInterfaceInfo spEnumRmIf;
  835. SPIRtrMgrInterfaceInfo spRmIf;
  836. SPIEnumRtrMgrProtocolInterfaceInfo spEnumRmProtIf;
  837. SPIRtrMgrInfo spRm;
  838. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  839. SPIRtrMgrProtocolInfo spRmProt;
  840. pIf->EnumRtrMgrInterface(&spEnumRmIf);
  841. while (spEnumRmIf->Next(1, &spRmIf, NULL) == hrOK)
  842. {
  843. // Find the appropriate router manager and have them
  844. // send a notification.
  845. // ------------------------------------------------------------
  846. FindRtrMgr(spRmIf->GetTransportId(), &spRm);
  847. if (spRm)
  848. {
  849. spRm->RtrNotify(ROUTER_CHILD_ADD, ROUTER_OBJ_RmIf, 0);
  850. // Now for each router-manager, enumerate the protocols
  851. // --------------------------------------------------------
  852. spRmIf->EnumRtrMgrProtocolInterface(&spEnumRmProtIf);
  853. while (spEnumRmProtIf->Next(1, &spRmProtIf, NULL) == hrOK)
  854. {
  855. spRm->FindRtrMgrProtocol(spRmProtIf->GetProtocolId(),
  856. &spRmProt);
  857. if (spRmProt)
  858. {
  859. spRmProt->RtrNotify(ROUTER_CHILD_ADD, ROUTER_OBJ_RmProtIf,
  860. 0);
  861. }
  862. spRmProt.Release();
  863. spRmProtIf.Release();
  864. }
  865. }
  866. spEnumRmProtIf.Release();
  867. spRm.Release();
  868. spRmIf.Release();
  869. }
  870. return hr;
  871. }
  872. /*!--------------------------------------------------------------------------
  873. RouterInfo::AddInterface
  874. -
  875. Author: KennT
  876. ---------------------------------------------------------------------------*/
  877. STDMETHODIMP RouterInfo::AddInterface(IInterfaceInfo *pInfo)
  878. {
  879. return AddInterfaceInternal(pInfo,
  880. TRUE /* bForce */,
  881. TRUE /* fAddToRouter */);
  882. }
  883. /*!--------------------------------------------------------------------------
  884. RouterInfo::DeleteInterface
  885. -
  886. This function deletes the named CInterfaceInfo from the router.
  887. As a side-effect, all the contained CRmInterfaceInfo objects
  888. are also deleted.
  889. Author: KennT
  890. ---------------------------------------------------------------------------*/
  891. STDMETHODIMP RouterInfo::DeleteInterface(LPCOLESTR pszInterface, BOOL fRemove)
  892. {
  893. return RemoveInterfaceInternal(pszInterface, fRemove);
  894. }
  895. /*!--------------------------------------------------------------------------
  896. RouterInfo::ReleaseInterface
  897. This function will release the AddRef() that this object has
  898. on the child. This allows us to transfer child objects from
  899. one router to another.
  900. Author: KennT
  901. ---------------------------------------------------------------------------*/
  902. STDMETHODIMP RouterInfo::ReleaseInterface( LPCOLESTR pszInterface )
  903. {
  904. HRESULT hr = hrOK;
  905. POSITION pos, posIf;
  906. SPIInterfaceInfo spIf;
  907. COM_PROTECT_TRY
  908. {
  909. pos = m_IfList.GetHeadPosition();
  910. while (pos)
  911. {
  912. // Save the position (so that we can delete it)
  913. posIf = pos;
  914. spIf.Set( m_IfList.GetNext(pos) );
  915. if (spIf &&
  916. (StriCmpW(spIf->GetId(), pszInterface) == 0))
  917. {
  918. // When releasing, we need to disconnect (since the
  919. // main handle is controlled by the router info).
  920. spIf->DoDisconnect();
  921. spIf->ReleaseWeakRef();
  922. spIf.Release();
  923. // release this node from the list
  924. m_IfList.RemoveAt(posIf);
  925. break;
  926. }
  927. spIf.Release();
  928. }
  929. }
  930. COM_PROTECT_CATCH;
  931. return hr;
  932. }
  933. HRESULT RouterInfo::RemoveInterfaceInternal(LPCOLESTR pszIf, BOOL fRemoveFromRouter)
  934. {
  935. RtrCriticalSection rtrCritSec(&m_critsec);
  936. HRESULT hr = hrOK;
  937. POSITION pos, posIf;
  938. SPIInterfaceInfo spIf;
  939. COM_PROTECT_TRY
  940. {
  941. pos = m_IfList.GetHeadPosition();
  942. while (pos)
  943. {
  944. posIf = pos;
  945. spIf.Set( m_IfList.GetNext(pos) );
  946. if (StriCmpW(spIf->GetId(), pszIf) == 0)
  947. break;
  948. spIf.Release();
  949. }
  950. if (!spIf)
  951. hr = E_INVALIDARG;
  952. else
  953. {
  954. // Remove the interface from our list
  955. // --------------------------------------------------------
  956. spIf->Destruct();
  957. spIf->ReleaseWeakRef(); // remove list addref
  958. m_IfList.RemoveAt(posIf);
  959. // Need to remove the RtrMgrInterfaceInfos from the list.
  960. // --------------------------------------------------------
  961. SPIEnumRtrMgrInterfaceInfo spEnumRmIf;
  962. SPIRtrMgrInterfaceInfo spRmIf;
  963. spIf->EnumRtrMgrInterface(&spEnumRmIf);
  964. for (spEnumRmIf->Reset();
  965. hrOK == spEnumRmIf->Next(1, &spRmIf, NULL);
  966. spRmIf.Release())
  967. {
  968. DWORD dwTransportId = spRmIf->GetTransportId();
  969. spRmIf.Release();
  970. spIf->DeleteRtrMgrInterface(dwTransportId, fRemoveFromRouter);
  971. }
  972. if (fRemoveFromRouter)
  973. {
  974. // Delete the interface from the router
  975. // ----------------------------------------------------
  976. spIf->Delete(GetMachineName(), NULL);
  977. // If this is a WAN interface, delete it from the
  978. // phonebook-file
  979. // version # greater than Win2K, this will be done in MprAdminInterfaceDelete, which is called in Delete
  980. // fix 91331
  981. DWORD dwMajor = 0, dwMinor = 0, dwBuildNo = 0;
  982. HKEY hkeyMachine = NULL;
  983. // Ignore the failure code, what else can we do?
  984. // ------------------------------------------------------------
  985. DWORD dwErr = ConnectRegistry(GetMachineName(), &hkeyMachine);
  986. if (dwErr == ERROR_SUCCESS)
  987. {
  988. dwErr = GetNTVersion(hkeyMachine, &dwMajor, &dwMinor, &dwBuildNo)
  989. ;
  990. DisconnectRegistry(hkeyMachine);
  991. }
  992. DWORD dwVersionCombine = MAKELONG( dwBuildNo, MAKEWORD(dwMinor, dwMajor));
  993. DWORD dwVersionCombineNT50 = MAKELONG ( VER_BUILD_WIN2K, MAKEWORD(VER_MINOR_WIN2K, VER_MAJOR_WIN2K));
  994. // if the version is greater than Win2K release
  995. if(dwVersionCombine > dwVersionCombineNT50)
  996. ; // skip
  997. else
  998. // end if fix 91331
  999. {
  1000. // ----------------------------------------------------
  1001. if (spIf->GetInterfaceType() == ROUTER_IF_TYPE_FULL_ROUTER)
  1002. hr = RasPhoneBookRemoveInterface(GetMachineName(),
  1003. pszIf);
  1004. }
  1005. }
  1006. m_AdviseList.NotifyChange(ROUTER_CHILD_DELETE, ROUTER_OBJ_If, 0);
  1007. }
  1008. }
  1009. COM_PROTECT_CATCH;
  1010. return hr;
  1011. }
  1012. STDMETHODIMP RouterInfo::RtrAdvise(IRtrAdviseSink *pRtrAdviseSink,
  1013. LONG_PTR *pulConnection,
  1014. LPARAM lUserParam)
  1015. {
  1016. Assert(pRtrAdviseSink);
  1017. Assert(pulConnection);
  1018. RtrCriticalSection rtrCritSec(&m_critsec);
  1019. LONG_PTR ulConnId;
  1020. HRESULT hr = hrOK;
  1021. COM_PROTECT_TRY
  1022. {
  1023. ulConnId = (LONG_PTR) InterlockedIncrement(&s_cConnections);
  1024. CORg( m_AdviseList.AddConnection(pRtrAdviseSink, ulConnId, lUserParam) );
  1025. *pulConnection = ulConnId;
  1026. COM_PROTECT_ERROR_LABEL;
  1027. }
  1028. COM_PROTECT_CATCH;
  1029. return hr;
  1030. }
  1031. STDMETHODIMP RouterInfo::RtrNotify(DWORD dwChangeType, DWORD dwObjectType,
  1032. LPARAM lParam)
  1033. {
  1034. RtrCriticalSection rtrCritSec(&m_critsec);
  1035. HRESULT hr = hrOK;
  1036. COM_PROTECT_TRY
  1037. {
  1038. m_AdviseList.NotifyChange(dwChangeType, dwObjectType, lParam);
  1039. }
  1040. COM_PROTECT_CATCH;
  1041. return hr;
  1042. }
  1043. STDMETHODIMP RouterInfo::RtrUnadvise(LONG_PTR dwConnection)
  1044. {
  1045. RtrCriticalSection rtrCritSec(&m_critsec);
  1046. return m_AdviseList.RemoveConnection(dwConnection);
  1047. }
  1048. //---------------------------------------------------------------------------
  1049. // Function: CRouterInfo::LoadInstalledRtrMgrList
  1050. //
  1051. // This function builds a list of the router manager's available
  1052. // for installation. The list contains RtrMgrCB structures.
  1053. //---------------------------------------------------------------------------
  1054. HRESULT RouterInfo::LoadInstalledRtrMgrList(LPCTSTR pszMachine,
  1055. SRtrMgrCBList *pRmCBList)
  1056. {
  1057. DWORD dwErr;
  1058. HKEY hkeyMachine = 0;
  1059. RegKey regkey;
  1060. RegKey regkeyRM;
  1061. RegKey::CREGKEY_KEY_INFO regKeyInfo;
  1062. RegKeyIterator regkeyIter;
  1063. HRESULT hr, hrIter;
  1064. CString stKey;
  1065. DWORD dwData;
  1066. DWORD cchValue;
  1067. SPSZ spszValue;
  1068. SPSRtrMgrCB spSRtrMgrCB;
  1069. // connect to the registry
  1070. // ----------------------------------------------------------------
  1071. CWRg( ConnectRegistry(pszMachine, &hkeyMachine) );
  1072. // open HKLM\Software\Microsoft\Router\CurrentVersion\RouterManagers
  1073. // ----------------------------------------------------------------
  1074. CWRg( regkey.Open(hkeyMachine, c_szRouterManagersKey, KEY_READ) );
  1075. // enumerate the keys
  1076. // ----------------------------------------------------------------
  1077. CORg( regkeyIter.Init(&regkey) );
  1078. for (hrIter = regkeyIter.Next(&stKey); hrIter == hrOK; hrIter = regkeyIter.Next(&stKey))
  1079. {
  1080. // cleanup from the previous loop
  1081. // ------------------------------------------------------------
  1082. regkeyRM.Close();
  1083. // open the key
  1084. // ------------------------------------------------------------
  1085. dwErr = regkeyRM.Open(regkey, stKey, KEY_READ);
  1086. if (dwErr == ERROR_SUCCESS)
  1087. {
  1088. // Get this information so that we can be more efficient
  1089. // at allocating space.
  1090. // --------------------------------------------------------
  1091. dwErr = regkeyRM.QueryKeyInfo(&regKeyInfo);
  1092. }
  1093. if (dwErr != ERROR_SUCCESS)
  1094. {
  1095. continue;
  1096. }
  1097. // Allocate a space for the largest value (we're reading
  1098. // in strings).
  1099. // ------------------------------------------------------------
  1100. spszValue.Free();
  1101. cchValue = MaxCchFromCb( regKeyInfo.dwMaxValueData );
  1102. spszValue = new TCHAR[ MinTCharNeededForCch(cchValue) ];
  1103. Assert(spszValue);
  1104. do {
  1105. // read the ProtocolId value
  1106. // --------------------------------------------------------
  1107. dwErr = regkeyRM.QueryValue(c_szProtocolId, dwData);
  1108. if (dwErr != ERROR_SUCCESS) { break; }
  1109. #if (WINVER >= 0x0501)
  1110. if(dwData == PID_IPX) { break; }
  1111. #endif
  1112. // allocate a new structure for this router-manager
  1113. // --------------------------------------------------------
  1114. spSRtrMgrCB = new SRtrMgrCB;
  1115. Assert(spSRtrMgrCB);
  1116. spSRtrMgrCB->stId = stKey;
  1117. spSRtrMgrCB->dwTransportId = dwData;
  1118. // read the DLLPath value
  1119. // --------------------------------------------------------
  1120. dwErr = regkeyRM.QueryValue(c_szDLLPath, spszValue, cchValue,TRUE);
  1121. if (dwErr != ERROR_SUCCESS) { break; }
  1122. spSRtrMgrCB->stDLLPath = spszValue;
  1123. //
  1124. // read the ConfigDLL value
  1125. //
  1126. //dwErr = regkeyRM.QueryValue(c_szConfigDLL,spszValue,cchValue,TRUE);
  1127. //if (dwErr != ERROR_SUCCESS) { break; }
  1128. //spSRtrMgrCB->stConfigDLL = spszValue;
  1129. // read the Title value
  1130. // --------------------------------------------------------
  1131. dwErr = regkeyRM.QueryValue(c_szTitle, spszValue, cchValue, FALSE);
  1132. if (dwErr != ERROR_SUCCESS)
  1133. spSRtrMgrCB->stTitle = spSRtrMgrCB->stId;
  1134. else
  1135. spSRtrMgrCB->stTitle = spszValue;
  1136. // add the object to our list
  1137. // --------------------------------------------------------
  1138. pRmCBList->AddTail(spSRtrMgrCB);
  1139. // Release the pointer, it belongs to pRmCBList now.
  1140. // --------------------------------------------------------
  1141. spSRtrMgrCB.Transfer();
  1142. } while(FALSE);
  1143. // If there was an error with the registry values, we
  1144. // ignore it and go onto the nextkey.
  1145. // ------------------------------------------------------------
  1146. regkeyRM.Close();
  1147. }
  1148. if (!FHrSucceeded(hrIter))
  1149. hr = hrIter;
  1150. Error:
  1151. if (hkeyMachine)
  1152. DisconnectRegistry(hkeyMachine);
  1153. return hr;
  1154. }
  1155. HRESULT RouterInfo::LoadInstalledRtrMgrProtocolList(LPCTSTR pszMachine,
  1156. DWORD dwTransportId, SRtrMgrProtocolCBList *pRmProtCBList, RouterInfo * pRouter)
  1157. {
  1158. WCHAR * pszPassword = NULL;
  1159. int nPasswordLen = 0;
  1160. UCHAR ucSeed = 0x83; //why?
  1161. HRESULT hr = hrOK;
  1162. if ( pRouter->IsAdminInfoSet() )
  1163. {
  1164. pRouter->GetUserPassword(NULL, &nPasswordLen );
  1165. pszPassword = (WCHAR *) new WCHAR [(nPasswordLen /sizeof(WCHAR)) + 1 ];
  1166. pRouter->GetUserPassword( (BYTE *)pszPassword, &nPasswordLen );
  1167. pszPassword[nPasswordLen/sizeof(WCHAR) ] = 0;
  1168. RtlDecodeW(ucSeed, pszPassword);
  1169. hr = RouterInfo::LoadInstalledRtrMgrProtocolList( pszMachine,
  1170. dwTransportId,
  1171. pRmProtCBList,
  1172. pRouter->GetUserName(),
  1173. pszPassword,
  1174. pRouter->GetDomainName() );
  1175. if ( pszPassword )
  1176. {
  1177. ::SecureZeroMemory ( pszPassword, nPasswordLen );
  1178. delete pszPassword;
  1179. }
  1180. }
  1181. else
  1182. {
  1183. hr = RouterInfo::LoadInstalledRtrMgrProtocolList( pszMachine,
  1184. dwTransportId,
  1185. pRmProtCBList,
  1186. NULL,
  1187. NULL,
  1188. NULL );
  1189. }
  1190. return hr;
  1191. }
  1192. HRESULT RouterInfo::LoadInstalledRtrMgrProtocolList(LPCTSTR pszMachine,
  1193. DWORD dwTransportId, SRtrMgrProtocolCBList *pRmProtCBList, IRouterInfo * pRouter)
  1194. {
  1195. WCHAR * pszPassword = NULL;
  1196. int nPasswordLen = 0;
  1197. UCHAR ucSeed = 0x83; //why?
  1198. HRESULT hr = hrOK;
  1199. SPIRouterAdminAccess spAdmin;
  1200. spAdmin.HrQuery(pRouter);
  1201. if (spAdmin && spAdmin->IsAdminInfoSet())
  1202. {
  1203. spAdmin->GetUserPassword(NULL, &nPasswordLen );
  1204. pszPassword = (WCHAR *) new WCHAR [(nPasswordLen /sizeof(WCHAR)) + 1 ];
  1205. spAdmin->GetUserPassword( (BYTE *)pszPassword, &nPasswordLen );
  1206. pszPassword[nPasswordLen/sizeof(WCHAR) ] = 0;
  1207. RtlDecodeW(ucSeed, pszPassword);
  1208. hr = RouterInfo::LoadInstalledRtrMgrProtocolList( pszMachine,
  1209. dwTransportId,
  1210. pRmProtCBList,
  1211. spAdmin->GetUserName(),
  1212. pszPassword,
  1213. spAdmin->GetDomainName() );
  1214. if ( pszPassword )
  1215. {
  1216. ::SecureZeroMemory ( pszPassword, nPasswordLen );
  1217. delete pszPassword;
  1218. }
  1219. }
  1220. else
  1221. {
  1222. hr = RouterInfo::LoadInstalledRtrMgrProtocolList( pszMachine,
  1223. dwTransportId,
  1224. pRmProtCBList,
  1225. NULL,
  1226. NULL,
  1227. NULL );
  1228. }
  1229. return hr;
  1230. }
  1231. //---------------------------------------------------------------------------
  1232. // Function: CRouterInfo::QueryInstalledRmProtList
  1233. //
  1234. // This function builds a list of the routing protocols which can be added
  1235. // to the specified router manager.
  1236. //---------------------------------------------------------------------------
  1237. HRESULT RouterInfo::LoadInstalledRtrMgrProtocolList(
  1238. LPCTSTR pszMachine,
  1239. DWORD dwTransportId,
  1240. SRtrMgrProtocolCBList * pSRmProtCBList,
  1241. LPCWSTR lpwszUserName,
  1242. LPCWSTR lpwszPassword ,
  1243. LPCWSTR lpwszDomain
  1244. )
  1245. {
  1246. Assert(pSRmProtCBList);
  1247. DWORD dwErr;
  1248. HKEY hkey, hkrm, hkeyMachine = 0;
  1249. HRESULT hr = hrOK;
  1250. RegKey regkeyRM;
  1251. RegKey regkeyProt;
  1252. RegKey::CREGKEY_KEY_INFO regKeyInfo;
  1253. RegKeyIterator regkeyIter;
  1254. HRESULT hrIter;
  1255. SPSZ spszValue;
  1256. SPSZ spszRm;
  1257. ULONG cchValue;
  1258. CString stKey;
  1259. SPSRtrMgrProtocolCB spSRmProtCB;
  1260. DWORD dwData;
  1261. BOOL f64BitAdmin = FALSE;
  1262. BOOL f64BitLocal = FALSE;
  1263. TCHAR szLocalMachineName[MAX_COMPUTERNAME_LENGTH + 1];
  1264. DWORD dwLocalMachineNameSize = MAX_COMPUTERNAME_LENGTH + 1;
  1265. if ( lpwszUserName )
  1266. CWRg( IsWindows64Bit(pszMachine, lpwszUserName, lpwszPassword, lpwszDomain, &f64BitAdmin) );
  1267. else
  1268. CWRg( IsWindows64Bit(pszMachine, NULL, NULL, NULL, &f64BitAdmin) );
  1269. GetComputerName ( szLocalMachineName, &dwLocalMachineNameSize );
  1270. if ( !lstrcmp ( szLocalMachineName, pszMachine ) )
  1271. {
  1272. f64BitLocal = f64BitAdmin;
  1273. }
  1274. else
  1275. {
  1276. CWRg( IsWindows64Bit(szLocalMachineName, NULL, NULL, NULL, &f64BitLocal) );
  1277. }
  1278. // connect to the registry
  1279. // ----------------------------------------------------------------
  1280. CWRg( ConnectRegistry(pszMachine, &hkeyMachine) );
  1281. // open the key for the specified router-manager
  1282. // under HKLM\Software\Microsoft\Router\RouterManagers
  1283. // ----------------------------------------------------------------
  1284. CWRg( FindRmSoftwareKey(hkeyMachine, dwTransportId, &hkrm, &spszRm) );
  1285. // The transport was found, so its registry key is in 'hkrm'
  1286. // ----------------------------------------------------------------
  1287. regkeyRM.Attach(hkrm);
  1288. // enumerate the keys
  1289. // ----------------------------------------------------------------
  1290. CORg( regkeyIter.Init(&regkeyRM) );
  1291. for (hrIter=regkeyIter.Next(&stKey); hrIter==hrOK; hrIter=regkeyIter.Next(&stKey))
  1292. {
  1293. // Cleanup from the previous loop
  1294. // ------------------------------------------------------------
  1295. regkeyProt.Close();
  1296. // open the key
  1297. // ------------------------------------------------------------
  1298. dwErr = regkeyProt.Open(regkeyRM, stKey, KEY_READ);
  1299. if (dwErr != ERROR_SUCCESS)
  1300. {
  1301. continue;
  1302. }
  1303. do {
  1304. // allocate a new structure for this protocol
  1305. // --------------------------------------------------------
  1306. spSRmProtCB.Free();
  1307. spSRmProtCB = new SRtrMgrProtocolCB;
  1308. Assert(spSRmProtCB);
  1309. spSRmProtCB->stId = stKey;
  1310. spSRmProtCB->dwTransportId = dwTransportId;
  1311. spSRmProtCB->stRtrMgrId = spszRm;
  1312. // get information about the key's values
  1313. // --------------------------------------------------------
  1314. dwErr = regkeyProt.QueryKeyInfo(&regKeyInfo);
  1315. if (dwErr != ERROR_SUCCESS) { break; }
  1316. // allocate space to hold the longest of the values
  1317. // --------------------------------------------------------
  1318. spszValue.Free();
  1319. cchValue = (regKeyInfo.dwMaxValueData)/sizeof(TCHAR);
  1320. spszValue = new TCHAR[cchValue * (2/sizeof(TCHAR))];
  1321. Assert(spszValue);
  1322. // read the ProtocolId value
  1323. // --------------------------------------------------------
  1324. dwErr = regkeyProt.QueryValue(c_szProtocolId, dwData);
  1325. if (dwErr != ERROR_SUCCESS) { break; }
  1326. //#if IA64
  1327. //OSPF node should be shown iff we are a 32 bit machine administering
  1328. //a 32 bit machine
  1329. if ( f64BitAdmin || f64BitLocal )
  1330. if( dwData == PROTO_IP_OSPF ) {break;}
  1331. //#endif
  1332. spSRmProtCB->dwProtocolId = dwData;
  1333. // read the Flags value
  1334. //
  1335. dwErr = regkeyProt.QueryValue(c_szFlags, dwData);
  1336. if (dwErr != ERROR_SUCCESS)
  1337. spSRmProtCB->dwFlags = 0;
  1338. else
  1339. spSRmProtCB->dwFlags = dwData;
  1340. //
  1341. // read the DLLName value
  1342. // --------------------------------------------------------
  1343. dwErr = regkeyProt.QueryValue(c_szDLLName, spszValue, cchValue,
  1344. TRUE);
  1345. if (dwErr != ERROR_SUCCESS)
  1346. spSRmProtCB->stDLLName.Empty();
  1347. else
  1348. spSRmProtCB->stDLLName = (LPCTSTR)spszValue;
  1349. //
  1350. // read the ConfigDLL value
  1351. //
  1352. //dwErr = regkeyProt.QueryValue(c_szConfigDLL, spszValue, cchValue,
  1353. // TRUE);
  1354. //if (dwErr != ERROR_SUCCESS) { break; }
  1355. //spSRmProtCB->stConfigDLL = (LPCTSTR)spszValue;
  1356. // read the ConfigCLSID value
  1357. // --------------------------------------------------------
  1358. dwErr = regkeyProt.QueryValue(c_szConfigCLSID, spszValue, cchValue, FALSE);
  1359. // Ignore the error code, if there is no CLSID, just NULL out
  1360. // the GUID, note that we can't depend on the key necessarily
  1361. // being there (for NT4 reasons).
  1362. // --------------------------------------------------------
  1363. ::ZeroMemory(&(spSRmProtCB->guidConfig), sizeof(GUID));
  1364. if ((dwErr != ERROR_SUCCESS) ||
  1365. !FHrSucceeded(CLSIDFromString(T2OLE((LPTSTR)(LPCTSTR) spszValue),
  1366. &(spSRmProtCB->guidConfig))))
  1367. memset(&(spSRmProtCB->guidConfig), 0xff, sizeof(GUID));
  1368. // read the AdminUICLSID value
  1369. // --------------------------------------------------------
  1370. dwErr = regkeyProt.QueryValue(c_szAdminUICLSID, spszValue, cchValue, FALSE);
  1371. // Ignore the error code, if there is no CLSID, just NULL out
  1372. // the GUID, note that we can't depend on the key necessarily
  1373. // being there (for NT4 reasons).
  1374. // --------------------------------------------------------
  1375. ::ZeroMemory(&(spSRmProtCB->guidAdminUI), sizeof(GUID));
  1376. if ((dwErr != ERROR_SUCCESS) ||
  1377. !FHrSucceeded(CLSIDFromString(T2OLE((LPTSTR)(LPCTSTR) spszValue),
  1378. &(spSRmProtCB->guidAdminUI))))
  1379. memset(&(spSRmProtCB->guidAdminUI), 0xff, sizeof(GUID));
  1380. // read the VendorName value
  1381. // --------------------------------------------------------
  1382. dwErr = regkeyProt.QueryValue(c_szVendorName, spszValue, cchValue, FALSE);
  1383. // Ignore the error code, if there is no value, just NULL out
  1384. // the value, note that we can't depend on the key necessarily
  1385. // being there (for NT4 reasons).
  1386. // --------------------------------------------------------
  1387. if (dwErr == ERROR_SUCCESS)
  1388. spSRmProtCB->stVendorName = spszValue;
  1389. // read the Title value
  1390. // --------------------------------------------------------
  1391. dwErr = regkeyProt.QueryValue(c_szTitle, spszValue, cchValue,
  1392. FALSE);
  1393. if (dwErr != ERROR_SUCCESS)
  1394. spSRmProtCB->stTitle = spSRmProtCB->stId;
  1395. else
  1396. spSRmProtCB->stTitle = (LPCTSTR)spszValue;
  1397. // add the object to our list
  1398. // --------------------------------------------------------
  1399. pSRmProtCBList->AddTail(spSRmProtCB);
  1400. // Let this go, it's under the control of the protList
  1401. // --------------------------------------------------------
  1402. spSRmProtCB.Transfer();
  1403. dwErr = ERROR_SUCCESS;
  1404. } while(FALSE);
  1405. }
  1406. Error:
  1407. if (hkeyMachine)
  1408. DisconnectRegistry(hkeyMachine);
  1409. return hr;
  1410. }
  1411. //---------------------------------------------------------------------------
  1412. // Function: CRouterInfo::LoadInstalledInterfaceList
  1413. //
  1414. // This function builds a list of network cards available for addition
  1415. // to the router manager.
  1416. //---------------------------------------------------------------------------
  1417. HRESULT RouterInfo::LoadInstalledInterfaceList(LPCTSTR pszMachine,
  1418. SInterfaceCBList *pSIfCBList)
  1419. {
  1420. DWORD dwErr;
  1421. HKEY hkeyMachine = 0;
  1422. RegKey regkeyNC;
  1423. RegKey regkeyCard;
  1424. CStringList ipCardList;
  1425. CStringList ipxCardList;
  1426. RegKeyIterator regkeyIter;
  1427. HRESULT hrIter;
  1428. CString stKey;
  1429. SPSInterfaceCB spSIfCB;
  1430. HRESULT hr = hrOK;
  1431. BOOL fNT4;
  1432. LPCTSTR pszKey;
  1433. CString stServiceName;
  1434. CNetcardRegistryHelper ncreghelp;
  1435. DWORD ifBindFlags = 0;
  1436. // connect to the registry
  1437. // ----------------------------------------------------------------
  1438. CWRg( ConnectRegistry(pszMachine, &hkeyMachine) );
  1439. //$NT5: kennt, changes made to read NT5 specific information
  1440. // ----------------------------------------------------------------
  1441. CWRg( IsNT4Machine(hkeyMachine, &fNT4) );
  1442. // open HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards
  1443. // ----------------------------------------------------------------
  1444. pszKey = fNT4 ? c_szNetworkCardsKey : c_szNetworkCardsNT5Key;
  1445. CWRg( regkeyNC.Open(hkeyMachine, pszKey, KEY_READ) );
  1446. // get the netcards that IP and IPX are bound to
  1447. // ----------------------------------------------------------------
  1448. CORg( ::LoadLinkageList(pszMachine, hkeyMachine, TEXT("tcpip"),
  1449. &ipCardList) );
  1450. CORg( ::LoadLinkageList(pszMachine, hkeyMachine, TEXT("nwlnkipx"),
  1451. &ipxCardList) );
  1452. // enumerate the subkeys, and for each key,
  1453. // make an addition to our list
  1454. // ----------------------------------------------------------------
  1455. CWRg( regkeyIter.Init(&regkeyNC) );
  1456. hrIter = regkeyIter.Next(&stKey);
  1457. for (; hrIter == hrOK; hrIter=regkeyIter.Next(&stKey))
  1458. {
  1459. ifBindFlags = 0;
  1460. regkeyCard.Close();
  1461. // now open the key
  1462. // ------------------------------------------------------------
  1463. dwErr = regkeyCard.Open(regkeyNC, stKey, KEY_READ);
  1464. if (dwErr != ERROR_SUCCESS)
  1465. continue;
  1466. // setup the helper class
  1467. // ------------------------------------------------------------
  1468. ncreghelp.Initialize(fNT4, regkeyCard, stKey,
  1469. pszMachine);
  1470. do {
  1471. // read the ServiceName
  1472. // --------------------------------------------------------
  1473. //$NT5: the service name is not in the same format as NT4
  1474. // this will need to be done differently.
  1475. // --------------------------------------------------------
  1476. if (fNT4)
  1477. {
  1478. dwErr = ncreghelp.ReadServiceName();
  1479. if (dwErr != ERROR_SUCCESS)
  1480. break;
  1481. stServiceName = ncreghelp.GetServiceName();
  1482. }
  1483. else
  1484. stServiceName = stKey;
  1485. // if the service name is not in the IP or IPX adapter list,
  1486. // then ignore this netcard because it is not a real netcard
  1487. // --------------------------------------------------------
  1488. if (ipCardList.Find((LPCTSTR) stServiceName))
  1489. {
  1490. ifBindFlags |= InterfaceCB_BindToIp;
  1491. }
  1492. // Now check IPX
  1493. // ------------------------------------------------
  1494. {
  1495. BOOL fFound = TRUE;
  1496. CString stNewServiceName;
  1497. do
  1498. {
  1499. if (ipxCardList.Find((LPCTSTR) stServiceName))
  1500. break;
  1501. stNewServiceName = stServiceName + c_szEthernetSNAP;
  1502. if (ipxCardList.Find((LPCTSTR) stNewServiceName))
  1503. break;
  1504. stNewServiceName = stServiceName + c_szEthernetII;
  1505. if (ipxCardList.Find((LPCTSTR) stNewServiceName))
  1506. break;
  1507. stNewServiceName = stServiceName + c_szEthernet8022;
  1508. if (ipxCardList.Find((LPCTSTR) stNewServiceName))
  1509. break;
  1510. stNewServiceName = stServiceName + c_szEthernet8023;
  1511. if (ipxCardList.Find((LPCTSTR) stNewServiceName))
  1512. break;
  1513. fFound = FALSE;
  1514. } while (FALSE);
  1515. if (fFound)
  1516. ifBindFlags |= InterfaceCB_BindToIpx;
  1517. }
  1518. // If we didn't find it in IP or IPX
  1519. // break out of the loop
  1520. // ----------------------------------------------------
  1521. if (ifBindFlags == 0)
  1522. break;
  1523. // ignore NdisWan adapters
  1524. // --------------------------------------------------------
  1525. if (_wcsnicmp( (const wchar_t *)stServiceName,
  1526. L"NdisWan",
  1527. (sizeof(L"NdisWan")-1)/sizeof (WCHAR)) == 0 ) {
  1528. break;
  1529. }
  1530. // allocate an SSInterfaceCB
  1531. // --------------------------------------------------------
  1532. spSIfCB = new SInterfaceCB;
  1533. Assert(spSIfCB);
  1534. spSIfCB->stId = (LPCTSTR) stServiceName;
  1535. spSIfCB->dwIfType = ROUTER_IF_TYPE_DEDICATED;
  1536. spSIfCB->dwBindFlags = ifBindFlags;
  1537. // read the title
  1538. // --------------------------------------------------------
  1539. dwErr = ncreghelp.ReadTitle();
  1540. if (dwErr != ERROR_SUCCESS)
  1541. spSIfCB->stTitle = spSIfCB->stId;
  1542. else
  1543. spSIfCB->stTitle = (LPCTSTR) ncreghelp.GetTitle();
  1544. // read the device
  1545. // --------------------------------------------------------
  1546. dwErr = ncreghelp.ReadDeviceName();
  1547. if (dwErr != ERROR_SUCCESS)
  1548. spSIfCB->stDeviceName = spSIfCB->stTitle;
  1549. else
  1550. spSIfCB->stDeviceName = (LPCTSTR) ncreghelp.GetDeviceName();
  1551. // add the SSInterfaceCB to the callers list
  1552. // --------------------------------------------------------
  1553. pSIfCBList->AddTail(spSIfCB);
  1554. spSIfCB.Transfer();
  1555. dwErr = NO_ERROR;
  1556. } while (FALSE);
  1557. if (dwErr != NO_ERROR)
  1558. {
  1559. hr = HRESULT_FROM_WIN32(dwErr);
  1560. break;
  1561. }
  1562. }
  1563. Error:
  1564. if (hkeyMachine)
  1565. DisconnectRegistry(hkeyMachine);
  1566. return dwErr;
  1567. }
  1568. //---------------------------------------------------------------------------
  1569. // Function: CRouterInfo::LoadRtrMgrList
  1570. //---------------------------------------------------------------------------
  1571. HRESULT RouterInfo::LoadRtrMgrList()
  1572. {
  1573. RtrCriticalSection rtrCritSec(&m_critsec);
  1574. BOOL bFound = TRUE;
  1575. SPIRtrMgrInfo spRmInfo;
  1576. BYTE* pItemTable = NULL;
  1577. MPR_TRANSPORT_0* ptransport;
  1578. DWORD dwErr, i, dwEntries, dwTotal;
  1579. HRESULT hr = hrOK;
  1580. USES_CONVERSION;
  1581. // Enumerate the transports configured
  1582. // ----------------------------------------------------------------
  1583. dwErr = ::MprConfigTransportEnum(
  1584. m_hMachineConfig,
  1585. 0,
  1586. &pItemTable,
  1587. (DWORD)-1,
  1588. &dwEntries,
  1589. &dwTotal,
  1590. NULL
  1591. );
  1592. if (dwErr != NO_ERROR && dwErr != ERROR_NO_MORE_ITEMS)
  1593. return HRESULT_FROM_WIN32(dwErr);
  1594. // Create router-manager objects for each transport
  1595. // ----------------------------------------------------------------
  1596. for (i = 0, ptransport = (MPR_TRANSPORT_0*)pItemTable;
  1597. i < dwEntries;
  1598. i++, ptransport++) {
  1599. #if (WINVER >= 0x0501)
  1600. if (ptransport->dwTransportId == PID_IPX) {continue;}
  1601. #endif
  1602. // See if the transport is already in our list,
  1603. // and if not create an object for it.
  1604. // ------------------------------------------------------------
  1605. FindRtrMgr(ptransport->dwTransportId, &spRmInfo);
  1606. if (spRmInfo == NULL)
  1607. {
  1608. // Construct a CRmInfo object on this transport
  1609. // --------------------------------------------------------
  1610. spRmInfo = new RtrMgrInfo(ptransport->dwTransportId,
  1611. W2T(ptransport->wszTransportName), this);
  1612. spRmInfo->SetFlags( RouterSnapin_InSyncWithRouter );
  1613. Assert(spRmInfo);
  1614. bFound = FALSE;
  1615. }
  1616. else
  1617. bFound = TRUE;
  1618. // Load the information for the transport,
  1619. // including its list of protocols
  1620. // ------------------------------------------------------------
  1621. hr = spRmInfo->Load(GetMachineName(),
  1622. m_hMachineConfig,
  1623. ptransport->hTransport);
  1624. if (!FHrSucceeded(hr))
  1625. {
  1626. spRmInfo->Destruct();
  1627. spRmInfo.Release();
  1628. continue;
  1629. }
  1630. // Add the router manager object to our list
  1631. // ------------------------------------------------------------
  1632. if (bFound == FALSE)
  1633. {
  1634. SRmData rmData;
  1635. rmData.m_pRmInfo = spRmInfo;
  1636. m_RmList.AddTail(rmData);
  1637. CONVERT_TO_WEAKREF(spRmInfo);
  1638. spRmInfo.Transfer();
  1639. }
  1640. }
  1641. //Error:
  1642. if (pItemTable)
  1643. ::MprConfigBufferFree(pItemTable);
  1644. return hr;
  1645. }
  1646. //---------------------------------------------------------------------------
  1647. // Function: RouterInfo::LoadInterfaceList
  1648. //---------------------------------------------------------------------------
  1649. HRESULT RouterInfo::LoadInterfaceList()
  1650. {
  1651. RtrCriticalSection rtrCritSec(&m_critsec);
  1652. BOOL bAdd;
  1653. BYTE* pItemTable = NULL;
  1654. SPIInterfaceInfo spIfInfo;
  1655. MPR_INTERFACE_0* pinterface;
  1656. DWORD dwErr, i;
  1657. DWORD dwEntries = 0, dwTotal = 0;
  1658. HRESULT hr = hrOK;
  1659. HRESULT tmpHr = hrOK;
  1660. SPMprServerHandle sphMprServer;
  1661. BOOL fMprAdmin = TRUE; // was MprAdminInterfaceEnum used?
  1662. USES_CONVERSION;
  1663. // Windows NT Bug : 180752
  1664. // Should try to enumerate with MprAdminInterfaceEnum first.
  1665. dwErr = ConnectRouter(GetMachineName(), &sphMprServer);
  1666. if (dwErr == NO_ERROR)
  1667. {
  1668. dwErr = ::MprAdminInterfaceEnum(sphMprServer,
  1669. 0,
  1670. (BYTE **) &pItemTable,
  1671. (DWORD) -1,
  1672. &dwEntries,
  1673. &dwTotal,
  1674. NULL);
  1675. }
  1676. if (dwErr != NO_ERROR)
  1677. {
  1678. Assert(pItemTable == NULL);
  1679. // MprConfigInterfaceEnum is used, not MprAdminIntefaceEnum
  1680. // ------------------------------------------------------------
  1681. fMprAdmin = FALSE;
  1682. // Enumerate the interfaces configured
  1683. // ------------------------------------------------------------
  1684. dwErr = ::MprConfigInterfaceEnum(
  1685. m_hMachineConfig,
  1686. 0,
  1687. &pItemTable,
  1688. (DWORD)-1,
  1689. &dwEntries,
  1690. &dwTotal,
  1691. NULL
  1692. );
  1693. }
  1694. if (dwErr != NO_ERROR && dwErr != ERROR_NO_MORE_ITEMS)
  1695. return HRESULT_FROM_WIN32(dwErr);
  1696. // Delete interface-objects for interfaces which don't exist anymore
  1697. // ----------------------------------------------------------------
  1698. POSITION pos = m_IfList.GetHeadPosition();
  1699. while (pos) {
  1700. POSITION postemp = pos;
  1701. spIfInfo.Set( m_IfList.GetNext(pos) );
  1702. // See if the interface is in the new table
  1703. // ------------------------------------------------------------
  1704. for (i = 0, pinterface = (MPR_INTERFACE_0*)pItemTable;
  1705. i < dwEntries;
  1706. i++, pinterface++)
  1707. {
  1708. if (StriCmpW(OLE2CW(spIfInfo->GetId()), pinterface->wszInterfaceName) == 0)
  1709. break;
  1710. }
  1711. // Go on if the interface was found
  1712. // ------------------------------------------------------------
  1713. if (i < dwEntries)
  1714. {
  1715. // Update the interface's settings
  1716. // --------------------------------------------------------
  1717. spIfInfo->SetInterfaceEnabledState( pinterface->fEnabled );
  1718. continue;
  1719. }
  1720. // The interface-object was not found and is obsolete; delete it
  1721. // ------------------------------------------------------------
  1722. m_IfList.RemoveAt(postemp);
  1723. spIfInfo->Destruct();
  1724. spIfInfo->ReleaseWeakRef(); // remove list addref
  1725. spIfInfo.Release(); // this will release the sp addref
  1726. }
  1727. // Create interface objects for each new interface
  1728. // ----------------------------------------------------------------
  1729. for (i = 0, pinterface = (MPR_INTERFACE_0*)pItemTable;
  1730. i < dwEntries;
  1731. i++, pinterface++)
  1732. {
  1733. spIfInfo.Release();
  1734. // See if the interface exists,
  1735. // and if not create a new interface object
  1736. // ------------------------------------------------------------
  1737. FindInterface(W2OLE(pinterface->wszInterfaceName), &spIfInfo);
  1738. if (spIfInfo == NULL)
  1739. {
  1740. SInterfaceCB * pSIfCB = NULL;
  1741. bAdd = TRUE;
  1742. // Find the CB that corresponds to this interface
  1743. // --------------------------------------------------------
  1744. pSIfCB = FindInterfaceCB(pinterface->wszInterfaceName);
  1745. // Construct a CInterfaceInfo object on this interface
  1746. // --------------------------------------------------------
  1747. spIfInfo = new InterfaceInfo(W2T(pinterface->wszInterfaceName),
  1748. pinterface->dwIfType,
  1749. pinterface->fEnabled,
  1750. pSIfCB ? pSIfCB->dwBindFlags :
  1751. (InterfaceCB_BindToIp | InterfaceCB_BindToIpx),
  1752. this);
  1753. spIfInfo->SetFlags( RouterSnapin_InSyncWithRouter );
  1754. Assert(spIfInfo);
  1755. }
  1756. else
  1757. bAdd = FALSE;
  1758. // Load the information for the interface
  1759. // ------------------------------------------------------------
  1760. tmpHr = spIfInfo->Load(GetMachineName(),
  1761. m_hMachineConfig, NULL);
  1762. if (!FHrSucceeded(tmpHr))
  1763. {
  1764. spIfInfo->Destruct();
  1765. spIfInfo.Release();
  1766. continue;
  1767. }
  1768. // add the object to our interface list
  1769. // ------------------------------------------------------------
  1770. if (bAdd)
  1771. {
  1772. m_IfList.AddTail(spIfInfo);
  1773. CONVERT_TO_WEAKREF(spIfInfo);
  1774. spIfInfo.Transfer();
  1775. }
  1776. }
  1777. //Error:
  1778. if (pItemTable)
  1779. {
  1780. if (fMprAdmin)
  1781. ::MprAdminBufferFree(pItemTable);
  1782. else
  1783. ::MprConfigBufferFree(pItemTable);
  1784. }
  1785. return hr;
  1786. }
  1787. /*!--------------------------------------------------------------------------
  1788. RouterInfo::ReviveStrongRef
  1789. Override of CWeakRef::ReviveStrongRef
  1790. Author: KennT
  1791. ---------------------------------------------------------------------------*/
  1792. void RouterInfo::ReviveStrongRef()
  1793. {
  1794. // Don't need to do anything
  1795. }
  1796. /*!--------------------------------------------------------------------------
  1797. RouterInfo::OnLastStrongRef
  1798. Override of CWeakRef::OnLastStrongRef
  1799. On the last strong reference for the router info indicates that
  1800. there are no strong pointers to any object in the hierarchy. Thus
  1801. we are free to remove all of our internal pointers.
  1802. Author: KennT
  1803. ---------------------------------------------------------------------------*/
  1804. void RouterInfo::OnLastStrongRef()
  1805. {
  1806. RtrCriticalSection rtrCritSec(&m_critsec);
  1807. Destruct();
  1808. }
  1809. /*!--------------------------------------------------------------------------
  1810. RouterInfo::Destruct
  1811. Implementation of IRouterInfo::Destruct
  1812. Author: KennT
  1813. ---------------------------------------------------------------------------*/
  1814. STDMETHODIMP RouterInfo::Destruct()
  1815. {
  1816. RtrCriticalSection rtrCritSec(&m_critsec);
  1817. IInterfaceInfo * pIf;
  1818. SRmData rmData;
  1819. // Destroy the interface objects
  1820. // ----------------------------------------------------------------
  1821. while (!m_IfList.IsEmpty())
  1822. {
  1823. pIf = m_IfList.RemoveHead();
  1824. pIf->Destruct();
  1825. pIf->ReleaseWeakRef();
  1826. }
  1827. // Destroy the router-manager objects
  1828. // ----------------------------------------------------------------
  1829. while (!m_RmList.IsEmpty())
  1830. {
  1831. rmData = m_RmList.RemoveHead();
  1832. SRmData::Destroy( &rmData );
  1833. }
  1834. return hrOK;
  1835. }
  1836. /*!--------------------------------------------------------------------------
  1837. RouterInfo::TryToConnect
  1838. If we are already connected, then the handle passed in is
  1839. ignored.
  1840. Otherwise, if "hMachine" was not specified, connect to the
  1841. config on the specified machine.
  1842. Author: KennT
  1843. ---------------------------------------------------------------------------*/
  1844. HRESULT RouterInfo::TryToConnect(LPCWSTR pswzMachine, HANDLE hMachine)
  1845. {
  1846. RtrCriticalSection rtrCritSec(&m_critsec);
  1847. HRESULT hr = hrOK;
  1848. if (m_hMachineConfig == NULL)
  1849. {
  1850. if (hMachine)
  1851. {
  1852. m_hMachineConfig = hMachine;
  1853. m_bDisconnect = FALSE;
  1854. }
  1855. else
  1856. {
  1857. CWRg( ::MprConfigServerConnect((LPWSTR) pswzMachine,
  1858. &m_hMachineConfig) );
  1859. m_bDisconnect = TRUE;
  1860. }
  1861. }
  1862. Error:
  1863. return hr;
  1864. }
  1865. STDMETHODIMP RouterInfo::OnChange(LONG_PTR ulConnection,
  1866. DWORD dwChangeType,
  1867. DWORD dwObjectType,
  1868. LPARAM lUserParam,
  1869. LPARAM lParam)
  1870. {
  1871. RtrCriticalSection rtrCritSec(&m_critsec);
  1872. HRESULT hr = hrOK;
  1873. COM_PROTECT_TRY
  1874. {
  1875. }
  1876. COM_PROTECT_CATCH;
  1877. return hr;
  1878. }
  1879. /*!--------------------------------------------------------------------------
  1880. RouterInfo::MergeRtrMgrCB
  1881. -
  1882. Author: KennT
  1883. ---------------------------------------------------------------------------*/
  1884. HRESULT RouterInfo::MergeRtrMgrCB(IRouterInfo *pNewRouter)
  1885. {
  1886. HRESULT hr = hrOK;
  1887. SPIEnumRtrMgrCB spRmCB;
  1888. RtrMgrCB rmCB;
  1889. SRtrMgrCB * pSRmCB;
  1890. POSITION pos, posDelete;
  1891. // Set the internal data on the SRtrMgrCBs to 0
  1892. // ----------------------------------------------------------------
  1893. pos = m_RmCBList.GetHeadPosition();
  1894. while (pos)
  1895. {
  1896. pSRmCB = m_RmCBList.GetNext(pos);
  1897. Assert(pSRmCB);
  1898. pSRmCB->dwPrivate = 0;
  1899. }
  1900. CORg( pNewRouter->EnumRtrMgrCB(&spRmCB) );
  1901. while (spRmCB->Next(1, &rmCB, NULL) == hrOK)
  1902. {
  1903. // Now look for this rmCB in our current list
  1904. // If we find it, mark the CB
  1905. // If we do not find it, add this RmCB
  1906. // ------------------------------------------------------------
  1907. pSRmCB = FindRtrMgrCB(rmCB.dwTransportId);
  1908. if (pSRmCB)
  1909. {
  1910. pSRmCB->dwPrivate = 1;
  1911. }
  1912. else
  1913. {
  1914. // Add this CB to the internal list
  1915. // --------------------------------------------------------
  1916. SRtrMgrCB * pNewSRmCB = new SRtrMgrCB;
  1917. pNewSRmCB->LoadFrom(&rmCB);
  1918. pNewSRmCB->dwPrivate = 1;
  1919. m_RmCBList.AddTail(pNewSRmCB);
  1920. }
  1921. }
  1922. // Now go through the internal list and delete all items that we
  1923. // didn't find in the new list
  1924. // ----------------------------------------------------------------
  1925. pos = m_RmCBList.GetHeadPosition();
  1926. while (pos)
  1927. {
  1928. pSRmCB = m_RmCBList.GetNext(pos);
  1929. Assert(pSRmCB);
  1930. if (pSRmCB->dwPrivate == 0)
  1931. {
  1932. posDelete = m_RmCBList.Find(pSRmCB);
  1933. m_RmCBList.RemoveAt(posDelete);
  1934. delete pSRmCB;
  1935. }
  1936. }
  1937. Error:
  1938. return hr;
  1939. }
  1940. /*!--------------------------------------------------------------------------
  1941. RouterInfo::MergeInterfaceCB
  1942. -
  1943. Author: KennT
  1944. ---------------------------------------------------------------------------*/
  1945. HRESULT RouterInfo::MergeInterfaceCB(IRouterInfo *pNewRouter)
  1946. {
  1947. HRESULT hr = hrOK;
  1948. SPIEnumInterfaceCB spIfCB;
  1949. InterfaceCB IfCB;
  1950. SInterfaceCB * pSIfCB;
  1951. POSITION pos, posDelete;
  1952. // Set the internal data on the SInterfaceCBs to 0
  1953. // ----------------------------------------------------------------
  1954. pos = m_IfCBList.GetHeadPosition();
  1955. while (pos)
  1956. {
  1957. pSIfCB = m_IfCBList.GetNext(pos);
  1958. Assert(pSIfCB);
  1959. pSIfCB->dwPrivate = 0;
  1960. }
  1961. CORg( pNewRouter->EnumInterfaceCB(&spIfCB) );
  1962. while (spIfCB->Next(1, &IfCB, NULL) == hrOK)
  1963. {
  1964. // Now look for this IfCB in our current list
  1965. // If we find it, mark the CB
  1966. // If we do not find it, add this IfCB
  1967. // ------------------------------------------------------------
  1968. pSIfCB = FindInterfaceCB(IfCB.szId);
  1969. if (pSIfCB)
  1970. {
  1971. // We found it, update the internal data
  1972. // --------------------------------------------------------
  1973. pSIfCB->bEnable = IfCB.bEnable;
  1974. pSIfCB->dwPrivate = 1;
  1975. }
  1976. else
  1977. {
  1978. // Add this CB to the internal list
  1979. // --------------------------------------------------------
  1980. SInterfaceCB * pNewSIfCB = new SInterfaceCB;
  1981. pNewSIfCB->LoadFrom(&IfCB);
  1982. pNewSIfCB->dwPrivate = 1;
  1983. m_IfCBList.AddTail(pNewSIfCB);
  1984. }
  1985. }
  1986. // Now go through the internal list and delete all items that we
  1987. // didn't find in the new list
  1988. // ----------------------------------------------------------------
  1989. pos = m_IfCBList.GetHeadPosition();
  1990. while (pos)
  1991. {
  1992. pSIfCB = m_IfCBList.GetNext(pos);
  1993. Assert(pSIfCB);
  1994. if (pSIfCB->dwPrivate == 0)
  1995. {
  1996. posDelete = m_IfCBList.Find(pSIfCB);
  1997. m_IfCBList.RemoveAt(posDelete);
  1998. delete pSIfCB;
  1999. }
  2000. }
  2001. Error:
  2002. return hr;
  2003. }
  2004. /*!--------------------------------------------------------------------------
  2005. RouterInfo::MergeRtrMgrProtocolCB
  2006. -
  2007. Author: KennT
  2008. ---------------------------------------------------------------------------*/
  2009. HRESULT RouterInfo::MergeRtrMgrProtocolCB(IRouterInfo *pNewRouter)
  2010. {
  2011. HRESULT hr = hrOK;
  2012. SPIEnumRtrMgrProtocolCB spRmProtCB;
  2013. RtrMgrProtocolCB RmProtCB;
  2014. SRtrMgrProtocolCB * pSRmProtCB;
  2015. POSITION pos, posDelete;
  2016. // Set the internal data on the SRtrMgrProtocolCBs to 0
  2017. // ----------------------------------------------------------------
  2018. pos = m_RmProtCBList.GetHeadPosition();
  2019. while (pos)
  2020. {
  2021. pSRmProtCB = m_RmProtCBList.GetNext(pos);
  2022. Assert(pSRmProtCB);
  2023. pSRmProtCB->dwPrivate = 0;
  2024. }
  2025. CORg( pNewRouter->EnumRtrMgrProtocolCB(&spRmProtCB) );
  2026. while (spRmProtCB->Next(1, &RmProtCB, NULL) == hrOK)
  2027. {
  2028. // Now look for this RmProtCB in our current list
  2029. // If we find it, mark the CB
  2030. // If we do not find it, add this RmProtCB
  2031. // ------------------------------------------------------------
  2032. pSRmProtCB = FindRtrMgrProtocolCB(RmProtCB.dwTransportId,
  2033. RmProtCB.dwProtocolId);
  2034. if (pSRmProtCB)
  2035. {
  2036. pSRmProtCB->dwPrivate = 1;
  2037. }
  2038. else
  2039. {
  2040. // Add this CB to the internal list
  2041. // --------------------------------------------------------
  2042. SRtrMgrProtocolCB * pNewSRmProtCB = new SRtrMgrProtocolCB;
  2043. pNewSRmProtCB->LoadFrom(&RmProtCB);
  2044. pNewSRmProtCB->dwPrivate = 1;
  2045. m_RmProtCBList.AddTail(pNewSRmProtCB);
  2046. }
  2047. }
  2048. // Now go through the internal list and delete all items that we
  2049. // didn't find in the new list
  2050. // ----------------------------------------------------------------
  2051. pos = m_RmProtCBList.GetHeadPosition();
  2052. while (pos)
  2053. {
  2054. pSRmProtCB = m_RmProtCBList.GetNext(pos);
  2055. Assert(pSRmProtCB);
  2056. if (pSRmProtCB->dwPrivate == 0)
  2057. {
  2058. posDelete = m_RmProtCBList.Find(pSRmProtCB);
  2059. m_RmProtCBList.RemoveAt(posDelete);
  2060. delete pSRmProtCB;
  2061. }
  2062. }
  2063. Error:
  2064. return hr;
  2065. }
  2066. /*!--------------------------------------------------------------------------
  2067. RouterInfo::MergeRtrMgrs
  2068. -
  2069. Author: KennT
  2070. ---------------------------------------------------------------------------*/
  2071. HRESULT RouterInfo::MergeRtrMgrs(IRouterInfo *pNewRouter)
  2072. {
  2073. RtrCriticalSection rtrCritSec(&m_critsec);
  2074. SPIEnumRtrMgrInfo spEnumRm;
  2075. SPIRtrMgrInfo spRm;
  2076. HRESULT hr = hrOK;
  2077. CDWordArray oldDWArray;
  2078. CDWordArray newDWArray;
  2079. int cOld, cNew;
  2080. int i, j;
  2081. DWORD dwTemp;
  2082. Assert(pNewRouter);
  2083. COM_PROTECT_TRY
  2084. {
  2085. // Need to sync up RtrMgrInfo
  2086. //
  2087. // The general algorithm is to build up two arrays
  2088. // the first array contains the transport ids for this object
  2089. // the second array contains the ids for the new object
  2090. //
  2091. // We then go through and remove all transports that are in
  2092. // BOTH lists.
  2093. //
  2094. // This will leave us with the first array containing the
  2095. // ids of the transports that need to be deleted from this object.
  2096. //
  2097. // The second array will have the list of ids of transports that
  2098. // have to be added to this object from the second object.
  2099. // ------------------------------------------------------------
  2100. // Get the list of transports that are in the new object
  2101. // ------------------------------------------------------------
  2102. CORg( pNewRouter->EnumRtrMgr(&spEnumRm) );
  2103. spEnumRm->Reset();
  2104. while (spEnumRm->Next(1, &spRm, NULL) == hrOK)
  2105. {
  2106. newDWArray.Add(spRm->GetTransportId());
  2107. spRm.Release();
  2108. }
  2109. spEnumRm.Release();
  2110. spRm.Release();
  2111. // Get the list of transports that are in this object
  2112. // ------------------------------------------------------------
  2113. CORg( this->EnumRtrMgr(&spEnumRm) );
  2114. spEnumRm->Reset();
  2115. while (spEnumRm->Next(1, &spRm, NULL) == hrOK)
  2116. {
  2117. oldDWArray.Add(spRm->GetTransportId());
  2118. spRm.Release();
  2119. }
  2120. spEnumRm.Release();
  2121. spRm.Release();
  2122. // Ok now go through both lists, removing from the lists
  2123. // transports that are in both lists.
  2124. // ------------------------------------------------------------
  2125. cOld = oldDWArray.GetSize();
  2126. cNew = newDWArray.GetSize();
  2127. for (i=cOld; --i>=0; )
  2128. {
  2129. dwTemp = oldDWArray.GetAt(i);
  2130. for (j=cNew; --j>=0; )
  2131. {
  2132. if (dwTemp == newDWArray.GetAt(j))
  2133. {
  2134. SPIRtrMgrInfo spRm1;
  2135. SPIRtrMgrInfo spRm2;
  2136. this->FindRtrMgr(dwTemp, &spRm1);
  2137. pNewRouter->FindRtrMgr(dwTemp, &spRm2);
  2138. Assert(spRm1);
  2139. Assert(spRm2);
  2140. spRm1->Merge(spRm2);
  2141. // remove both instances
  2142. // ------------------------------------------------
  2143. newDWArray.RemoveAt(j);
  2144. oldDWArray.RemoveAt(i);
  2145. // Need to update the size of the new array
  2146. // ------------------------------------------------
  2147. cNew--;
  2148. break;
  2149. }
  2150. }
  2151. }
  2152. // oldDWArray now contains the transports that should be
  2153. // removed.
  2154. // ------------------------------------------------------------
  2155. if (oldDWArray.GetSize())
  2156. {
  2157. for (i=oldDWArray.GetSize(); --i>=0; )
  2158. {
  2159. DeleteRtrMgr(oldDWArray.GetAt(i), FALSE);
  2160. }
  2161. }
  2162. // newDWArray contains the transports that should be added
  2163. // ------------------------------------------------------------
  2164. if (newDWArray.GetSize())
  2165. {
  2166. for (i=newDWArray.GetSize(); --i>= 0; )
  2167. {
  2168. hr = pNewRouter->FindRtrMgr(newDWArray.GetAt(i), &spRm);
  2169. Assert(hr == hrOK);
  2170. Assert(spRm);
  2171. // Do a sanity check, make sure that this RtrMgr is
  2172. // in the RtrMgrCB list
  2173. // ----------------------------------------------------
  2174. Assert(FindRtrMgrCB(spRm->GetTransportId()));
  2175. // Add this router manager, to the router info.
  2176. // ----------------------------------------------------
  2177. if (spRm)
  2178. {
  2179. AddRtrMgr(spRm, NULL, NULL);
  2180. // Remove this router manager from its previous router
  2181. // ------------------------------------------------
  2182. pNewRouter->ReleaseRtrMgr(spRm->GetTransportId());
  2183. }
  2184. spRm.Release();
  2185. }
  2186. }
  2187. COM_PROTECT_ERROR_LABEL;
  2188. }
  2189. COM_PROTECT_CATCH;
  2190. return hr;
  2191. }
  2192. /*!--------------------------------------------------------------------------
  2193. RouterInfo::MergeInterfaces
  2194. -
  2195. Author: KennT
  2196. ---------------------------------------------------------------------------*/
  2197. HRESULT RouterInfo::MergeInterfaces(IRouterInfo *pNewRouter)
  2198. {
  2199. RtrCriticalSection rtrCritSec(&m_critsec);
  2200. SPIEnumInterfaceInfo spEnumIf;
  2201. SPIInterfaceInfo spIf;
  2202. HRESULT hr = hrOK;
  2203. CStringArray oldStArray;
  2204. CStringArray newStArray;
  2205. int cOld, cNew;
  2206. int i, j;
  2207. CString stTemp;
  2208. Assert(pNewRouter);
  2209. COM_PROTECT_TRY
  2210. {
  2211. // Need to sync up InterfaceInfo
  2212. // ------------------------------------------------------------
  2213. //
  2214. // The general algorithm is to build up two arrays
  2215. // the first array contains the protocol ids for this object
  2216. // the second array contains the ids for the new object
  2217. //
  2218. // We then go through and remove all protocols that are in
  2219. // BOTH lists.
  2220. //
  2221. // This will leave us with the first array containing the
  2222. // ids of the protocols that need to be deleted from this object.
  2223. //
  2224. // The second array will have the list of ids of protocols that
  2225. // have to be added to this object from the second object.
  2226. // ------------------------------------------------------------
  2227. // Get the list of protocols that are in the new object
  2228. // ------------------------------------------------------------
  2229. CORg( pNewRouter->EnumInterface(&spEnumIf) );
  2230. spEnumIf->Reset();
  2231. while (spEnumIf->Next(1, &spIf, NULL) == hrOK)
  2232. {
  2233. newStArray.Add(spIf->GetId());
  2234. spIf.Release();
  2235. }
  2236. spEnumIf.Release();
  2237. spIf.Release();
  2238. // Get the list of protocols that are in this object
  2239. // ------------------------------------------------------------
  2240. CORg( this->EnumInterface(&spEnumIf) );
  2241. spEnumIf->Reset();
  2242. while (spEnumIf->Next(1, &spIf, NULL) == hrOK)
  2243. {
  2244. oldStArray.Add(spIf->GetId());
  2245. spIf.Release();
  2246. }
  2247. spEnumIf.Release();
  2248. spIf.Release();
  2249. // Ok now go through both lists, removing from the lists
  2250. // protocols that are in both lists.
  2251. // ------------------------------------------------------------
  2252. cOld = oldStArray.GetSize();
  2253. cNew = newStArray.GetSize();
  2254. for (i=cOld; --i>=0; )
  2255. {
  2256. stTemp = oldStArray.GetAt(i);
  2257. for (j=cNew; --j>=0; )
  2258. {
  2259. if (stTemp == newStArray.GetAt(j))
  2260. {
  2261. SPIInterfaceInfo spIf1;
  2262. SPIInterfaceInfo spIf2;
  2263. this->FindInterface(stTemp, &spIf1);
  2264. pNewRouter->FindInterface(stTemp, &spIf2);
  2265. Assert(spIf1);
  2266. Assert(spIf2);
  2267. spIf1->Merge(spIf2);
  2268. // remove both instances
  2269. // ------------------------------------------------
  2270. newStArray.RemoveAt(j);
  2271. oldStArray.RemoveAt(i);
  2272. // Need to update the size of the new array
  2273. // ------------------------------------------------
  2274. cNew--;
  2275. break;
  2276. }
  2277. }
  2278. }
  2279. // oldStArray now contains the protocols that should be
  2280. // removed.
  2281. // ------------------------------------------------------------
  2282. if (oldStArray.GetSize())
  2283. {
  2284. for (i=oldStArray.GetSize(); --i>=0; )
  2285. {
  2286. RemoveInterfaceInternal(oldStArray.GetAt(i),
  2287. FALSE /* fRemoveFromRouter */ );
  2288. }
  2289. }
  2290. // newStArray contains the protocols that should be added
  2291. // ------------------------------------------------------------
  2292. if (newStArray.GetSize())
  2293. {
  2294. for (i=newStArray.GetSize(); --i>= 0; )
  2295. {
  2296. hr = pNewRouter->FindInterface(newStArray.GetAt(i), &spIf);
  2297. Assert(hr == hrOK);
  2298. Assert(spIf);
  2299. // Do a sanity check, make sure that this Interface is
  2300. // in the InterfaceCB list
  2301. // This is only true if this is a LAN adapter.
  2302. // Assert(FindInterfaceCB(spIf->GetId()));
  2303. // We allow errors to not affect whether or not
  2304. // the interface is added to the UI (this allows us
  2305. // to stay in sync with the merged routerinfo).
  2306. // ----------------------------------------------------
  2307. if (spIf)
  2308. {
  2309. hr = AddInterfaceInternal(spIf, FALSE, FALSE);
  2310. // Send the RmIf notifications
  2311. // ------------------------------------------------
  2312. if (FHrOK(hr))
  2313. NotifyRtrMgrInterfaceOfMove(spIf);
  2314. // Remove this interface from its previous router
  2315. // ------------------------------------------------
  2316. pNewRouter->ReleaseInterface(spIf->GetId());
  2317. }
  2318. spIf.Release();
  2319. }
  2320. }
  2321. COM_PROTECT_ERROR_LABEL;
  2322. }
  2323. COM_PROTECT_CATCH;
  2324. return hr;
  2325. }
  2326. /*!--------------------------------------------------------------------------
  2327. RouterInfo::FindRtrMgrCB
  2328. -
  2329. Author: KennT
  2330. ---------------------------------------------------------------------------*/
  2331. SRtrMgrCB * RouterInfo::FindRtrMgrCB(DWORD dwTransportId)
  2332. {
  2333. POSITION pos;
  2334. SRtrMgrCB * pSRmCB = NULL;
  2335. pos = m_RmCBList.GetHeadPosition();
  2336. while (pos)
  2337. {
  2338. pSRmCB = m_RmCBList.GetNext(pos);
  2339. Assert(pSRmCB);
  2340. if (pSRmCB->dwTransportId == dwTransportId)
  2341. return pSRmCB;
  2342. }
  2343. return NULL;
  2344. }
  2345. /*!--------------------------------------------------------------------------
  2346. RouterInfo::FindRtrMgrProtocolCB
  2347. -
  2348. Author: KennT
  2349. ---------------------------------------------------------------------------*/
  2350. SRtrMgrProtocolCB * RouterInfo::FindRtrMgrProtocolCB(DWORD dwTransportId, DWORD dwProtocolId)
  2351. {
  2352. POSITION pos;
  2353. SRtrMgrProtocolCB * pSRmProtCB = NULL;
  2354. pos = m_RmProtCBList.GetHeadPosition();
  2355. while (pos)
  2356. {
  2357. pSRmProtCB = m_RmProtCBList.GetNext(pos);
  2358. Assert(pSRmProtCB);
  2359. if ((pSRmProtCB->dwTransportId == dwTransportId) &&
  2360. (pSRmProtCB->dwProtocolId == dwProtocolId))
  2361. return pSRmProtCB;
  2362. }
  2363. return NULL;
  2364. }
  2365. /*!--------------------------------------------------------------------------
  2366. RouterInfo::FindInterfaceCB
  2367. -
  2368. Author: KennT
  2369. ---------------------------------------------------------------------------*/
  2370. SInterfaceCB * RouterInfo::FindInterfaceCB(LPCTSTR pszInterfaceId)
  2371. {
  2372. POSITION pos;
  2373. SInterfaceCB * pSIfCB = NULL;
  2374. pos = m_IfCBList.GetHeadPosition();
  2375. while (pos)
  2376. {
  2377. pSIfCB = m_IfCBList.GetNext(pos);
  2378. Assert(pSIfCB);
  2379. if (StriCmp(pSIfCB->stTitle, pszInterfaceId) == 0)
  2380. return pSIfCB;
  2381. }
  2382. return NULL;
  2383. }
  2384. /*!--------------------------------------------------------------------------
  2385. RouterInfo::Disconnect
  2386. Removes connections made by this object.
  2387. Author: KennT
  2388. ---------------------------------------------------------------------------*/
  2389. void RouterInfo::Disconnect()
  2390. {
  2391. if (m_bDisconnect)
  2392. ::MprConfigServerDisconnect(m_hMachineConfig);
  2393. m_bDisconnect = FALSE;
  2394. m_hMachineConfig = NULL;
  2395. }
  2396. /*!--------------------------------------------------------------------------
  2397. RouterInfo::DoDisconnect
  2398. We are to disconnect our connections from the server.
  2399. This means calling MprConfigServerDisconnect() on our
  2400. connections.
  2401. Author: KennT
  2402. ---------------------------------------------------------------------------*/
  2403. STDMETHODIMP RouterInfo::DoDisconnect()
  2404. {
  2405. HRESULT hr = hrOK;
  2406. SPIEnumRtrMgrInfo spEnumRm;
  2407. SPIRtrMgrInfo spRm;
  2408. SPIEnumInterfaceInfo spEnumIf;
  2409. SPIInterfaceInfo spIf;
  2410. COM_PROTECT_TRY
  2411. {
  2412. // Disconnect ourselves
  2413. // ------------------------------------------------------------
  2414. Disconnect();
  2415. // Notify the advise sinks of a disconnect.
  2416. // ------------------------------------------------------------
  2417. RtrNotify(ROUTER_DO_DISCONNECT, 0, 0);
  2418. // Now tell all child objects to disconnect.
  2419. // ------------------------------------------------------------
  2420. HRESULT hrIter = hrOK;
  2421. // Tell each of the router-managers to disconnect.
  2422. // ------------------------------------------------------------
  2423. EnumRtrMgr(&spEnumRm);
  2424. spEnumRm->Reset();
  2425. while (spEnumRm->Next(1, &spRm, NULL) == hrOK)
  2426. {
  2427. spRm->DoDisconnect();
  2428. spRm.Release();
  2429. }
  2430. // Tell each interface to disconnect.
  2431. // ------------------------------------------------------------
  2432. EnumInterface(&spEnumIf);
  2433. spEnumIf->Reset();
  2434. while (spEnumIf->Next(1, &spIf, NULL) == hrOK)
  2435. {
  2436. spIf->DoDisconnect();
  2437. spIf.Release();
  2438. }
  2439. }
  2440. COM_PROTECT_CATCH;
  2441. return hr;
  2442. }
  2443. /*!--------------------------------------------------------------------------
  2444. RouterInfo::IsAdminInfoSet
  2445. -
  2446. Author: KennT
  2447. ---------------------------------------------------------------------------*/
  2448. STDMETHODIMP_(BOOL) RouterInfo::IsAdminInfoSet()
  2449. {
  2450. return m_fIsAdminInfoSet;
  2451. }
  2452. STDMETHODIMP_(LPCOLESTR) RouterInfo::GetUserName()
  2453. {
  2454. if (m_fIsAdminInfoSet)
  2455. return (LPCOLESTR) m_stUserName;
  2456. else
  2457. return NULL;
  2458. }
  2459. STDMETHODIMP_(LPCOLESTR) RouterInfo::GetDomainName()
  2460. {
  2461. if (m_fIsAdminInfoSet && !m_stDomain.IsEmpty())
  2462. return (LPCOLESTR) m_stDomain;
  2463. else
  2464. return NULL;
  2465. }
  2466. STDMETHODIMP RouterInfo::GetUserPassword(BYTE *pPassword, int *pcPassword)
  2467. {
  2468. HRESULT hr = hrOK;
  2469. if (pPassword == NULL)
  2470. {
  2471. Assert(pcPassword);
  2472. *pcPassword = m_cPassword;
  2473. return hr;
  2474. }
  2475. Assert(pPassword);
  2476. Assert(pcPassword);
  2477. COM_PROTECT_TRY
  2478. {
  2479. if (!m_fIsAdminInfoSet)
  2480. {
  2481. *pcPassword = 0;
  2482. }
  2483. else
  2484. {
  2485. CopyMemory(pPassword, m_pbPassword, m_cPassword);
  2486. *pcPassword = m_cPassword;
  2487. }
  2488. }
  2489. COM_PROTECT_CATCH;
  2490. return hr;
  2491. }
  2492. STDMETHODIMP RouterInfo::SetInfo(LPCOLESTR pszName,
  2493. LPCOLESTR pszDomain,
  2494. LPBYTE pPassword,
  2495. int cPassword)
  2496. {
  2497. HRESULT hr = hrOK;
  2498. Assert(pszName);
  2499. COM_PROTECT_TRY
  2500. {
  2501. m_stUserName = pszName;
  2502. m_stDomain = pszDomain;
  2503. // Allocate space for the password
  2504. delete m_pbPassword;
  2505. m_pbPassword = NULL;
  2506. m_cPassword = 0;
  2507. if (cPassword)
  2508. {
  2509. m_pbPassword = new BYTE[cPassword];
  2510. CopyMemory(m_pbPassword, pPassword, cPassword);
  2511. m_cPassword = cPassword;
  2512. }
  2513. m_fIsAdminInfoSet = TRUE;
  2514. }
  2515. COM_PROTECT_CATCH;
  2516. return hr;
  2517. }
  2518. /*---------------------------------------------------------------------------
  2519. RtrMgrInfo implementation
  2520. ---------------------------------------------------------------------------*/
  2521. IMPLEMENT_WEAKREF_ADDREF_RELEASE(RtrMgrInfo);
  2522. IMPLEMENT_SIMPLE_QUERYINTERFACE(RtrMgrInfo, IRtrMgrInfo)
  2523. DEBUG_DECLARE_INSTANCE_COUNTER(RtrMgrInfo)
  2524. RtrMgrInfo::RtrMgrInfo(DWORD dwTransportId,
  2525. LPCTSTR pszTransportName,
  2526. RouterInfo *pRouterInfo)
  2527. : m_hMachineConfig(NULL),
  2528. m_hTransport(NULL),
  2529. m_bDisconnect(FALSE),
  2530. m_dwFlags(0)
  2531. {
  2532. DEBUG_INCREMENT_INSTANCE_COUNTER(RtrMgrInfo);
  2533. m_cb.dwTransportId = dwTransportId;
  2534. m_cb.stId = pszTransportName;
  2535. // There is a case in the old code where pRouterInfo == NULL
  2536. // It is in the CAddRouterManager dialog, however this is
  2537. // not called from anywhere in the code.
  2538. // ----------------------------------------------------------------
  2539. Assert(pRouterInfo);
  2540. m_pRouterInfoParent = static_cast<IRouterInfo *>(pRouterInfo);
  2541. if (m_pRouterInfoParent)
  2542. m_pRouterInfoParent->AddRef();
  2543. InitializeCriticalSection(&m_critsec);
  2544. }
  2545. RtrMgrInfo::~RtrMgrInfo()
  2546. {
  2547. Assert(m_pRouterInfoParent == NULL);
  2548. Assert(m_AdviseList.IsEmpty());
  2549. Destruct();
  2550. DEBUG_DECREMENT_INSTANCE_COUNTER(RtrMgrInfo);
  2551. DeleteCriticalSection(&m_critsec);
  2552. }
  2553. void RtrMgrInfo::ReviveStrongRef()
  2554. {
  2555. RtrCriticalSection rtrCritSec(&m_critsec);
  2556. if (m_pRouterInfoParent)
  2557. {
  2558. CONVERT_TO_STRONGREF(m_pRouterInfoParent);
  2559. }
  2560. }
  2561. void RtrMgrInfo::OnLastStrongRef()
  2562. {
  2563. RtrCriticalSection rtrCritSec(&m_critsec);
  2564. if (m_pRouterInfoParent)
  2565. {
  2566. CONVERT_TO_WEAKREF(m_pRouterInfoParent);
  2567. }
  2568. if (m_fDestruct)
  2569. Destruct();
  2570. }
  2571. STDMETHODIMP RtrMgrInfo::Destruct()
  2572. {
  2573. RtrCriticalSection rtrCritSec(&m_critsec);
  2574. IRouterInfo * pParent;
  2575. m_fDestruct = TRUE;
  2576. if (!m_fStrongRef)
  2577. {
  2578. // Release the parent pointer
  2579. // ------------------------------------------------------------
  2580. pParent = m_pRouterInfoParent;
  2581. m_pRouterInfoParent = NULL;
  2582. if (pParent)
  2583. pParent->ReleaseWeakRef();
  2584. // Release the data
  2585. // ------------------------------------------------------------
  2586. Unload();
  2587. }
  2588. return hrOK;
  2589. }
  2590. STDMETHODIMP_(DWORD) RtrMgrInfo::GetFlags()
  2591. {
  2592. RtrCriticalSection rtrCritSec(&m_critsec);
  2593. return m_dwFlags;
  2594. }
  2595. STDMETHODIMP RtrMgrInfo::SetFlags(DWORD dwFlags)
  2596. {
  2597. RtrCriticalSection rtrCritSec(&m_critsec);
  2598. HRESULT hr = hrOK;
  2599. COM_PROTECT_TRY
  2600. {
  2601. m_dwFlags = dwFlags;
  2602. }
  2603. COM_PROTECT_CATCH;
  2604. return hr;
  2605. }
  2606. /*!--------------------------------------------------------------------------
  2607. RtrMgrInfo::Load
  2608. -
  2609. Loads a CRmInfo structure from the registry
  2610. Author: KennT
  2611. ---------------------------------------------------------------------------*/
  2612. STDMETHODIMP RtrMgrInfo::Load(LPCOLESTR pszMachine,
  2613. HANDLE hMachine,
  2614. HANDLE hTransport
  2615. )
  2616. {
  2617. RtrCriticalSection rtrCritSec(&m_critsec);
  2618. HRESULT hr = hrOK;
  2619. SPIEnumRtrMgrCB spEnumRmCB;
  2620. IEnumRtrMgrCB * pEnumRmCB;
  2621. BOOL bFound;
  2622. RtrMgrCB RmCBTemp;
  2623. USES_CONVERSION;
  2624. COM_PROTECT_TRY
  2625. {
  2626. // Discard any existing information
  2627. // ------------------------------------------------------------
  2628. Unload();
  2629. m_stMachine = (pszMachine ? pszMachine : TEXT(""));
  2630. // if 'hMachine' was not specified, connect to the config
  2631. // on the specified machine
  2632. // ------------------------------------------------------------
  2633. Assert(m_hMachineConfig == NULL);
  2634. CORg( TryToConnect(OLE2CW(pszMachine), &hMachine) );
  2635. // if 'hTransport' was not specified, connect to the transport
  2636. // ------------------------------------------------------------
  2637. if (hTransport)
  2638. m_hTransport = hTransport;
  2639. else
  2640. {
  2641. CWRg( ::MprConfigTransportGetHandle(hMachine,
  2642. GetTransportId(),
  2643. &hTransport));
  2644. m_hTransport = hTransport;
  2645. }
  2646. // Retrieve the title, dll-path, and config-dll from the Software key;
  2647. // ------------------------------------------------------------
  2648. Assert(m_pRouterInfoParent);
  2649. CORg( m_pRouterInfoParent->EnumRtrMgrCB(&pEnumRmCB) );
  2650. spEnumRmCB = pEnumRmCB;
  2651. // Find the control-block for the router-manager being loaded
  2652. // ------------------------------------------------------------
  2653. bFound = FALSE;
  2654. pEnumRmCB->Reset();
  2655. while (pEnumRmCB->Next(1, &RmCBTemp, NULL) == hrOK)
  2656. {
  2657. // Get the next control-block
  2658. // --------------------------------------------------------
  2659. if (RmCBTemp.dwTransportId != GetTransportId())
  2660. continue;
  2661. m_cb.stTitle = OLE2CT(RmCBTemp.szId);
  2662. m_cb.stDLLPath= OLE2CT(RmCBTemp.szTitle);
  2663. //m_cb.stConfigDLL = OLE2CT(RmCBTemp.szConfigDLL);
  2664. bFound = TRUE;
  2665. break;
  2666. }
  2667. if (!bFound)
  2668. m_cb.stTitle = m_cb.stId;
  2669. // Load the list of routing-protocols for this router-manager
  2670. // ------------------------------------------------------------
  2671. CWRg( LoadRtrMgrInfo(hMachine,
  2672. hTransport) );
  2673. COM_PROTECT_ERROR_LABEL;
  2674. }
  2675. COM_PROTECT_CATCH;
  2676. if (!FHrSucceeded(hr))
  2677. Unload();
  2678. return hr;
  2679. }
  2680. /*!--------------------------------------------------------------------------
  2681. RtrMgrInfo::Save
  2682. -
  2683. This function saves the information for a CRmInfo in the registry.
  2684. Author: KennT
  2685. ---------------------------------------------------------------------------*/
  2686. STDMETHODIMP RtrMgrInfo::Save(LPCOLESTR pszMachine,
  2687. HANDLE hMachine,
  2688. HANDLE hTransport,
  2689. IInfoBase * pGlobalInfo,
  2690. IInfoBase * pClientInfo,
  2691. DWORD dwDeleteProtocolId)
  2692. {
  2693. RtrCriticalSection rtrCritSec(&m_critsec);
  2694. HRESULT hr = hrOK;
  2695. DWORD dwErr;
  2696. LPWSTR pwsz = NULL;
  2697. WCHAR wszTransport[MAX_TRANSPORT_NAME_LEN+1];
  2698. SPWSZ spwszDll;
  2699. COM_PROTECT_TRY
  2700. {
  2701. // If we are already connected (i.e. 'm_hMachineConfig' is non-NULL)
  2702. // then the handle passed in is ignored.
  2703. //
  2704. // Otherwise, if 'hMachine' was not specified, connect to the config
  2705. // on the specified machine
  2706. // ------------------------------------------------------------
  2707. CORg( TryToConnect(OLE2CW(pszMachine), &hMachine) );
  2708. // If we are already connected (i.e. 'm_hTransport' is non-NULL)
  2709. // then the handle passed in is ignored.
  2710. //
  2711. // Otherwise, if 'hTransport' wasn't passed in, try to get a handle
  2712. // to the transport; if that fails, create the transport.
  2713. // ------------------------------------------------------------
  2714. if (m_hTransport)
  2715. hTransport = m_hTransport;
  2716. else if (hTransport)
  2717. m_hTransport = hTransport;
  2718. else
  2719. {
  2720. // Get a handle to the transport
  2721. // --------------------------------------------------------
  2722. dwErr = ::MprConfigTransportGetHandle(hMachine,
  2723. m_cb.dwTransportId, &hTransport);
  2724. if (dwErr != NO_ERROR)
  2725. {
  2726. // We couldn't get a handle to the transport,
  2727. // so now attempt to create it.
  2728. //
  2729. // Convert transport-name to Unicode
  2730. // ----------------------------------------------------
  2731. if (!m_cb.stId.GetLength())
  2732. pwsz = NULL;
  2733. else
  2734. pwsz = StrCpyWFromT(wszTransport, m_cb.stId);
  2735. // Convert the DLL path to Unicode
  2736. // ----------------------------------------------------
  2737. spwszDll = StrDupWFromT(m_cb.stDLLPath);
  2738. // Create the transport
  2739. // ----------------------------------------------------
  2740. CWRg( ::MprConfigTransportCreate(hMachine,
  2741. GetTransportId(),
  2742. pwsz,
  2743. NULL,
  2744. 0,
  2745. NULL,
  2746. 0,
  2747. spwszDll,
  2748. &hTransport
  2749. ));
  2750. }
  2751. }
  2752. // Now save the global info for the transport
  2753. // ------------------------------------------------------------
  2754. CWRg( SaveRtrMgrInfo(hMachine,
  2755. hTransport,
  2756. pGlobalInfo,
  2757. pClientInfo,
  2758. dwDeleteProtocolId) );
  2759. COM_PROTECT_ERROR_LABEL;
  2760. }
  2761. COM_PROTECT_CATCH;
  2762. return hr;
  2763. }
  2764. /*!--------------------------------------------------------------------------
  2765. RtrMgrInfo::Unload
  2766. Implementation of IRtrMgrInfo::Unload
  2767. Author: KennT
  2768. ---------------------------------------------------------------------------*/
  2769. STDMETHODIMP RtrMgrInfo::Unload( )
  2770. {
  2771. RtrCriticalSection rtrCritSec(&m_critsec);
  2772. HRESULT hr = hrOK;
  2773. IRtrMgrProtocolInfo * pRmProt;
  2774. COM_PROTECT_TRY
  2775. {
  2776. while (!m_RmProtList.IsEmpty())
  2777. {
  2778. pRmProt = m_RmProtList.RemoveHead();
  2779. pRmProt->Destruct();
  2780. pRmProt->ReleaseWeakRef();
  2781. }
  2782. DoDisconnect();
  2783. }
  2784. COM_PROTECT_CATCH;
  2785. return hr;
  2786. }
  2787. /*!--------------------------------------------------------------------------
  2788. RtrMgrInfo::Delete
  2789. -
  2790. This function removes the information associated with a router-manager
  2791. from the registry.
  2792. Author: KennT
  2793. ---------------------------------------------------------------------------*/
  2794. STDMETHODIMP RtrMgrInfo::Delete(LPCOLESTR pszMachine,
  2795. HANDLE hMachine)
  2796. {
  2797. RtrCriticalSection rtrCritSec(&m_critsec);
  2798. HRESULT hr = hrOK;
  2799. HANDLE hTransport = NULL;
  2800. COM_PROTECT_TRY
  2801. {
  2802. //
  2803. // If already connected, the handle passed in is ignored;
  2804. //
  2805. // Otherwise, if 'hMachine' was not specified, connect to the config
  2806. // on the specified machine
  2807. //
  2808. CORg( TryToConnect(OLE2CW(pszMachine), &hMachine) );
  2809. //
  2810. // Attempt to get a handle for the transport
  2811. //
  2812. CWRg( ::MprConfigTransportGetHandle(hMachine,
  2813. m_cb.dwTransportId,
  2814. &hTransport
  2815. ) );
  2816. //
  2817. // Delete the transport
  2818. //
  2819. CWRg( ::MprConfigTransportDelete(hMachine, hTransport) );
  2820. m_hTransport = NULL;
  2821. COM_PROTECT_ERROR_LABEL;
  2822. }
  2823. COM_PROTECT_CATCH;
  2824. return hr;
  2825. }
  2826. /*!--------------------------------------------------------------------------
  2827. RtrMgrInfo::SetInfoBase
  2828. -
  2829. Author: KennT
  2830. ---------------------------------------------------------------------------*/
  2831. STDMETHODIMP RtrMgrInfo::SetInfoBase(IInfoBase* pGlobalInfo,
  2832. IInfoBase* pClientInfo )
  2833. {
  2834. RtrCriticalSection rtrCritSec(&m_critsec);
  2835. HRESULT hr = hrOK;
  2836. MPR_SERVER_HANDLE hRouter = NULL;
  2837. BYTE* pGlobalInfoData = NULL, *pClientInfoData = NULL;
  2838. DWORD dwGlobalInfoDataSize = 0, dwClientInfoDataSize = 0;
  2839. DWORD dwErr;
  2840. COM_PROTECT_TRY
  2841. {
  2842. //
  2843. // Format the router-manager's data as an opaque block
  2844. //
  2845. if (pGlobalInfo)
  2846. CORg( pGlobalInfo->WriteTo(&pGlobalInfoData, &dwGlobalInfoDataSize) );
  2847. //
  2848. // Format the client-interface's data as an opaque block
  2849. //
  2850. if (pClientInfo)
  2851. CORg( pClientInfo->WriteTo(&pClientInfoData, &dwClientInfoDataSize) );
  2852. //
  2853. // Connect to the router
  2854. //
  2855. CORg( ConnectRouter(GetMachineName(), &hRouter) );
  2856. //
  2857. // Set the new info for the router-manager
  2858. //
  2859. dwErr = MprAdminTransportSetInfo(hRouter,
  2860. GetTransportId(),
  2861. pGlobalInfoData,
  2862. dwGlobalInfoDataSize,
  2863. pClientInfoData,
  2864. dwClientInfoDataSize
  2865. );
  2866. if ((dwErr == RPC_S_SERVER_UNAVAILABLE) ||
  2867. (dwErr == RPC_S_UNKNOWN_IF))
  2868. dwErr = NO_ERROR;
  2869. CWRg( dwErr );
  2870. COM_PROTECT_ERROR_LABEL;
  2871. }
  2872. COM_PROTECT_CATCH;
  2873. CoTaskMemFree( pGlobalInfoData );
  2874. CoTaskMemFree( pClientInfoData );
  2875. if (hRouter)
  2876. ::MprAdminServerDisconnect(hRouter);
  2877. return hr;
  2878. }
  2879. /*!--------------------------------------------------------------------------
  2880. RtrMgrInfo::GetInfoBase
  2881. -
  2882. Author: KennT
  2883. ---------------------------------------------------------------------------*/
  2884. STDMETHODIMP RtrMgrInfo::GetInfoBase(HANDLE hMachine,
  2885. HANDLE hTransport,
  2886. IInfoBase **ppGlobalInfo,
  2887. IInfoBase **ppClientInfo)
  2888. {
  2889. RtrCriticalSection rtrCritSec(&m_critsec);
  2890. HRESULT hr = hrOK;
  2891. COM_PROTECT_TRY
  2892. {
  2893. CORg( TryToGetAllHandles(m_stMachine,
  2894. &hMachine,
  2895. &hTransport) );
  2896. hr = ::LoadInfoBase(hMachine ? hMachine : m_hMachineConfig,
  2897. hTransport ? hTransport : m_hTransport,
  2898. ppGlobalInfo, ppClientInfo);
  2899. COM_PROTECT_ERROR_LABEL;
  2900. }
  2901. COM_PROTECT_CATCH;
  2902. return hr;
  2903. }
  2904. /*!--------------------------------------------------------------------------
  2905. RtrMgrInfo::Merge
  2906. -
  2907. Author: KennT
  2908. ---------------------------------------------------------------------------*/
  2909. STDMETHODIMP RtrMgrInfo::Merge(IRtrMgrInfo *pNewRm)
  2910. {
  2911. RtrCriticalSection rtrCritSec(&m_critsec);
  2912. SPIEnumRtrMgrProtocolInfo spEnumRmProt;
  2913. SPIRtrMgrProtocolInfo spRmProt;
  2914. HRESULT hr = hrOK;
  2915. CDWordArray oldDWArray;
  2916. CDWordArray newDWArray;
  2917. int cOld, cNew;
  2918. int i, j;
  2919. DWORD dwTemp;
  2920. RtrMgrCB rmCB;
  2921. Assert(pNewRm);
  2922. Assert(pNewRm->GetTransportId() == GetTransportId());
  2923. COM_PROTECT_TRY
  2924. {
  2925. pNewRm->CopyRtrMgrCB(&rmCB);
  2926. m_cb.LoadFrom(&rmCB);
  2927. //
  2928. // The general algorithm is to build up two arrays
  2929. // the first array contains the protocol ids for this object
  2930. // the second array contains the ids for the new object
  2931. //
  2932. // We then go through and remove all protocols that are in
  2933. // BOTH lists.
  2934. //
  2935. // This will leave us with the first array containing the
  2936. // ids of the protocols that need to be deleted from this object.
  2937. //
  2938. // The second array will have the list of ids of protocols that
  2939. // have to be added to this object from the second object.
  2940. //
  2941. // Get the list of protocols that are in the new object
  2942. CORg( pNewRm->EnumRtrMgrProtocol(&spEnumRmProt) );
  2943. spEnumRmProt->Reset();
  2944. while (spEnumRmProt->Next(1, &spRmProt, NULL) == hrOK)
  2945. {
  2946. newDWArray.Add(spRmProt->GetProtocolId());
  2947. spRmProt.Release();
  2948. }
  2949. spEnumRmProt.Release();
  2950. spRmProt.Release();
  2951. // Get the list of protocols that are in this object
  2952. CORg( this->EnumRtrMgrProtocol(&spEnumRmProt) );
  2953. spEnumRmProt->Reset();
  2954. while (spEnumRmProt->Next(1, &spRmProt, NULL) == hrOK)
  2955. {
  2956. oldDWArray.Add(spRmProt->GetProtocolId());
  2957. spRmProt.Release();
  2958. }
  2959. spEnumRmProt.Release();
  2960. spRmProt.Release();
  2961. // Ok now go through both lists, removing from the lists
  2962. // protocols that are in both lists.
  2963. cOld = oldDWArray.GetSize();
  2964. cNew = newDWArray.GetSize();
  2965. for (i=cOld; --i>=0; )
  2966. {
  2967. dwTemp = oldDWArray.GetAt(i);
  2968. for (j=cNew; --j>=0; )
  2969. {
  2970. if (dwTemp == newDWArray.GetAt(j))
  2971. {
  2972. // remove both instances
  2973. newDWArray.RemoveAt(j);
  2974. oldDWArray.RemoveAt(i);
  2975. // Need to update the size of the new array
  2976. cNew--;
  2977. break;
  2978. }
  2979. }
  2980. }
  2981. // oldDWArray now contains the protocols that should be
  2982. // removed.
  2983. if (oldDWArray.GetSize())
  2984. {
  2985. for (i=oldDWArray.GetSize(); --i>=0; )
  2986. {
  2987. DeleteRtrMgrProtocol(oldDWArray.GetAt(i), FALSE);
  2988. }
  2989. }
  2990. // newDWArray contains the protocols that should be added
  2991. if (newDWArray.GetSize())
  2992. {
  2993. for (i=newDWArray.GetSize(); --i>= 0; )
  2994. {
  2995. hr = pNewRm->FindRtrMgrProtocol(
  2996. newDWArray.GetAt(i), &spRmProt);
  2997. Assert(hr == hrOK);
  2998. if (spRmProt)
  2999. {
  3000. AddRtrMgrProtocol(spRmProt, NULL, NULL);
  3001. // Remove this rmprot from its old router
  3002. // ------------------------------------------------
  3003. pNewRm->ReleaseRtrMgrProtocol(spRmProt->GetProtocolId());
  3004. }
  3005. spRmProt.Release();
  3006. }
  3007. }
  3008. COM_PROTECT_ERROR_LABEL;
  3009. }
  3010. COM_PROTECT_CATCH;
  3011. return hr;
  3012. }
  3013. /*!--------------------------------------------------------------------------
  3014. RtrMgrInfo::GetId
  3015. -
  3016. Author: KennT
  3017. ---------------------------------------------------------------------------*/
  3018. STDMETHODIMP_(LPCOLESTR) RtrMgrInfo::GetId()
  3019. {
  3020. RtrCriticalSection rtrCritSec(&m_critsec);
  3021. return m_cb.stId;
  3022. }
  3023. /*!--------------------------------------------------------------------------
  3024. RtrMgrInfo::SetId
  3025. -
  3026. Author: KennT
  3027. ---------------------------------------------------------------------------*/
  3028. STDMETHODIMP RtrMgrInfo::SetId(LPCOLESTR pszId)
  3029. {
  3030. RtrCriticalSection rtrCritSec(&m_critsec);
  3031. HRESULT hr = hrOK;
  3032. COM_PROTECT_TRY
  3033. {
  3034. m_cb.stId = pszId;
  3035. }
  3036. COM_PROTECT_CATCH;
  3037. return hr;
  3038. }
  3039. /*!--------------------------------------------------------------------------
  3040. RtrMgrInfo::GetTransportId
  3041. -
  3042. Author: KennT
  3043. ---------------------------------------------------------------------------*/
  3044. STDMETHODIMP_(DWORD) RtrMgrInfo::GetTransportId()
  3045. {
  3046. RtrCriticalSection rtrCritSec(&m_critsec);
  3047. return m_cb.dwTransportId;
  3048. }
  3049. /*!--------------------------------------------------------------------------
  3050. RtrMgrInfo::GetTitle
  3051. -
  3052. Author: KennT
  3053. ---------------------------------------------------------------------------*/
  3054. STDMETHODIMP_(LPCOLESTR) RtrMgrInfo::GetTitle()
  3055. {
  3056. RtrCriticalSection rtrCritSec(&m_critsec);
  3057. //$UNICODE
  3058. // This assumes that we are native UNICODE
  3059. // and that OLECHAR == WCHAR
  3060. return m_cb.stTitle;
  3061. }
  3062. /*!--------------------------------------------------------------------------
  3063. RtrMgrInfo::CopyRtrMgrCB
  3064. -
  3065. Author: KennT
  3066. ---------------------------------------------------------------------------*/
  3067. STDMETHODIMP RtrMgrInfo::CopyRtrMgrCB(RtrMgrCB *pRmCB)
  3068. {
  3069. RtrCriticalSection rtrCritSec(&m_critsec);
  3070. HRESULT hr = hrOK;
  3071. COM_PROTECT_TRY
  3072. {
  3073. m_cb.SaveTo(pRmCB);
  3074. }
  3075. COM_PROTECT_CATCH;
  3076. return hr;
  3077. }
  3078. /*!--------------------------------------------------------------------------
  3079. RtrMgrInfo::GetMachineName
  3080. -
  3081. Author: KennT
  3082. ---------------------------------------------------------------------------*/
  3083. LPCOLESTR RtrMgrInfo::GetMachineName()
  3084. {
  3085. RtrCriticalSection rtrCritSec(&m_critsec);
  3086. //$UNICODE
  3087. // This assumes that we are native UNICODE and that
  3088. // OLECHAR == WCHAR
  3089. return m_stMachine;
  3090. }
  3091. /*!--------------------------------------------------------------------------
  3092. RtrMgrInfo::EnumRtrMgrProtocol
  3093. -
  3094. Author: KennT
  3095. ---------------------------------------------------------------------------*/
  3096. STDMETHODIMP RtrMgrInfo::EnumRtrMgrProtocol(IEnumRtrMgrProtocolInfo ** ppEnumRmProt)
  3097. {
  3098. RtrCriticalSection rtrCritSec(&m_critsec);
  3099. HRESULT hr = hrOK;
  3100. COM_PROTECT_TRY
  3101. {
  3102. hr = CreateEnumFromRtrMgrProtocolList(&m_RmProtList, ppEnumRmProt);
  3103. }
  3104. COM_PROTECT_CATCH;
  3105. return hr;
  3106. }
  3107. /*!--------------------------------------------------------------------------
  3108. RtrMgrInfo::FindRtrMgrProtocol
  3109. S_OK is returned if a RtrMgrInfo is found.
  3110. S_FALSE is returned if a RtrMgrInfo was NOT found.
  3111. error codes returned otherwise.
  3112. -
  3113. Author: KennT
  3114. ---------------------------------------------------------------------------*/
  3115. STDMETHODIMP RtrMgrInfo::FindRtrMgrProtocol(DWORD dwProtocolId,
  3116. IRtrMgrProtocolInfo **ppRmProtInfo)
  3117. {
  3118. RtrCriticalSection rtrCritSec(&m_critsec);
  3119. HRESULT hr = hrFalse;
  3120. POSITION pos;
  3121. SPIRtrMgrProtocolInfo spRmProt;
  3122. COM_PROTECT_TRY
  3123. {
  3124. if (ppRmProtInfo)
  3125. *ppRmProtInfo = NULL;
  3126. // Look through the list of rtr mgrs for the one that matches
  3127. pos = m_RmProtList.GetHeadPosition();
  3128. while (pos)
  3129. {
  3130. spRmProt.Set(m_RmProtList.GetNext(pos));
  3131. Assert(spRmProt);
  3132. if (spRmProt->GetProtocolId() == dwProtocolId)
  3133. {
  3134. hr = hrOK;
  3135. if (ppRmProtInfo)
  3136. {
  3137. // The spRmProt::Set, does a strong reference
  3138. // so we don't need to convert to a strong reference
  3139. *ppRmProtInfo = spRmProt.Transfer();
  3140. }
  3141. break;
  3142. }
  3143. }
  3144. }
  3145. COM_PROTECT_CATCH;
  3146. return hr;
  3147. }
  3148. /*!--------------------------------------------------------------------------
  3149. RtrMgrInfo::AddRtrMgrProtocol
  3150. -
  3151. Author: KennT
  3152. ---------------------------------------------------------------------------*/
  3153. STDMETHODIMP RtrMgrInfo::AddRtrMgrProtocol(IRtrMgrProtocolInfo *pInfo,
  3154. IInfoBase * pGlobalInfo,
  3155. IInfoBase * pClientInfo)
  3156. {
  3157. RtrCriticalSection rtrCritSec(&m_critsec);
  3158. Assert(pInfo);
  3159. HRESULT hr = hrOK;
  3160. COM_PROTECT_TRY
  3161. {
  3162. //
  3163. // Fail if there is a duplicate
  3164. //
  3165. if (FHrOK(FindRtrMgrProtocol(pInfo->GetProtocolId(), NULL)))
  3166. CORg(E_INVALIDARG);
  3167. //
  3168. // Save the router-manager's data
  3169. //
  3170. if (pGlobalInfo || pClientInfo)
  3171. {
  3172. CORg( Save(GetMachineName(),
  3173. m_hMachineConfig,
  3174. m_hTransport,
  3175. pGlobalInfo,
  3176. pClientInfo,
  3177. 0) );
  3178. }
  3179. //
  3180. // Add the routing-protocol to the list
  3181. //
  3182. m_RmProtList.AddTail(pInfo);
  3183. pInfo->AddWeakRef();
  3184. pInfo->SetParentRtrMgrInfo(this);
  3185. m_AdviseList.NotifyChange(ROUTER_CHILD_ADD, ROUTER_OBJ_RmProt, 0);
  3186. COM_PROTECT_ERROR_LABEL;
  3187. }
  3188. COM_PROTECT_CATCH;
  3189. return hr;
  3190. }
  3191. /*!--------------------------------------------------------------------------
  3192. RtrMgrInfo::DeleteRtrMgrProtocol
  3193. -
  3194. Author: KennT
  3195. ---------------------------------------------------------------------------*/
  3196. STDMETHODIMP RtrMgrInfo::DeleteRtrMgrProtocol( DWORD dwProtocolId, BOOL fRemove )
  3197. {
  3198. RtrCriticalSection rtrCritSec(&m_critsec);
  3199. HRESULT hr = hrOK;
  3200. SPIRtrMgrProtocolInfo spRmProt;
  3201. POSITION pos, posRmProt;
  3202. SPIEnumInterfaceInfo spEnumIf;
  3203. SPIEnumRtrMgrInterfaceInfo spEnumRmIf;
  3204. SPIInterfaceInfo spIf;
  3205. SPIRtrMgrInterfaceInfo spRmIf;
  3206. COM_PROTECT_TRY
  3207. {
  3208. //
  3209. // Find the routing-protocol to be deleted
  3210. //
  3211. pos = m_RmProtList.GetHeadPosition();
  3212. while (pos)
  3213. {
  3214. posRmProt = pos;
  3215. spRmProt.Set( m_RmProtList.GetNext(pos) );
  3216. Assert(spRmProt);
  3217. if (spRmProt->GetProtocolId() == dwProtocolId)
  3218. break;
  3219. spRmProt.Release();
  3220. }
  3221. if (!spRmProt)
  3222. CORg( E_INVALIDARG );
  3223. // We should also go through and remove the protocols
  3224. // from any interfaces that use the protocols
  3225. if (m_pRouterInfoParent)
  3226. {
  3227. // Ask the parent for its list of interfaces
  3228. m_pRouterInfoParent->EnumInterface(&spEnumIf);
  3229. for (;spEnumIf->Next(1, &spIf, NULL) == hrOK; spIf.Release())
  3230. {
  3231. // Now enumerate through all of the RtrMgrs on this interface
  3232. spEnumRmIf.Release();
  3233. spRmIf.Release();
  3234. spIf->EnumRtrMgrInterface(&spEnumRmIf);
  3235. for (;spEnumRmIf->Next(1, &spRmIf, NULL) == hrOK;
  3236. spRmIf.Release())
  3237. {
  3238. if (spRmIf->GetTransportId() == GetTransportId())
  3239. {
  3240. // Call this on all interfaces, it should just
  3241. // fail if the protocol is not on that interface
  3242. spRmIf->DeleteRtrMgrProtocolInterface(dwProtocolId,
  3243. fRemove);
  3244. break;
  3245. }
  3246. }
  3247. }
  3248. }
  3249. //
  3250. // save the updated information, removing any block
  3251. // belonging to the deleted routing-protocol
  3252. //
  3253. if (fRemove)
  3254. CORg( Save(GetMachineName(),
  3255. m_hMachineConfig,
  3256. m_hTransport,
  3257. NULL,
  3258. NULL,
  3259. dwProtocolId) );
  3260. //
  3261. // remove the protocol from our list
  3262. //
  3263. spRmProt->Destruct();
  3264. spRmProt->ReleaseWeakRef();
  3265. // spRmProt.Transfer();
  3266. m_RmProtList.RemoveAt(posRmProt);
  3267. m_AdviseList.NotifyChange(ROUTER_CHILD_DELETE, ROUTER_OBJ_RmProt, 0);
  3268. COM_PROTECT_ERROR_LABEL;
  3269. }
  3270. COM_PROTECT_CATCH;
  3271. return hr;
  3272. }
  3273. /*!--------------------------------------------------------------------------
  3274. RtrMgrInfo::ReleaseRtrMgrProtocol
  3275. This function will release the AddRef() that this object has
  3276. on the child. This allows us to transfer child objects from
  3277. one router to another.
  3278. Author: KennT
  3279. ---------------------------------------------------------------------------*/
  3280. STDMETHODIMP RtrMgrInfo::ReleaseRtrMgrProtocol( DWORD dwProtocolId )
  3281. {
  3282. HRESULT hr = hrOK;
  3283. POSITION pos, posRmProt;
  3284. SPIRtrMgrProtocolInfo spRmProt;
  3285. COM_PROTECT_TRY
  3286. {
  3287. pos = m_RmProtList.GetHeadPosition();
  3288. while (pos)
  3289. {
  3290. // Save the position (so that we can delete it)
  3291. posRmProt = pos;
  3292. spRmProt.Set( m_RmProtList.GetNext(pos) );
  3293. if (spRmProt &&
  3294. (spRmProt->GetProtocolId() == dwProtocolId))
  3295. {
  3296. // When releasing, we need to disconnect (since the
  3297. // main handle is controlled by the router info).
  3298. spRmProt->DoDisconnect();
  3299. spRmProt->ReleaseWeakRef();
  3300. spRmProt.Release();
  3301. // release this node from the list
  3302. m_RmProtList.RemoveAt(posRmProt);
  3303. break;
  3304. }
  3305. spRmProt.Release();
  3306. }
  3307. }
  3308. COM_PROTECT_CATCH;
  3309. return hr;
  3310. }
  3311. /*!--------------------------------------------------------------------------
  3312. RtrMgrInfo::RtrAdvise
  3313. -
  3314. Author: KennT
  3315. ---------------------------------------------------------------------------*/
  3316. STDMETHODIMP RtrMgrInfo::RtrAdvise(IRtrAdviseSink *pRtrAdviseSink,
  3317. LONG_PTR *pulConnection,
  3318. LPARAM lUserParam)
  3319. {
  3320. RtrCriticalSection rtrCritSec(&m_critsec);
  3321. Assert(pRtrAdviseSink);
  3322. Assert(pulConnection);
  3323. LONG_PTR ulConnId;
  3324. HRESULT hr = hrOK;
  3325. COM_PROTECT_TRY
  3326. {
  3327. ulConnId = (LONG_PTR) InterlockedIncrement(&s_cConnections);
  3328. CORg( m_AdviseList.AddConnection(pRtrAdviseSink, ulConnId, lUserParam) );
  3329. *pulConnection = ulConnId;
  3330. COM_PROTECT_ERROR_LABEL;
  3331. }
  3332. COM_PROTECT_CATCH;
  3333. return hr;
  3334. }
  3335. /*!--------------------------------------------------------------------------
  3336. RtrMgrInfo::RtrNotify
  3337. -
  3338. Author: KennT
  3339. ---------------------------------------------------------------------------*/
  3340. STDMETHODIMP RtrMgrInfo::RtrNotify(DWORD dwChangeType, DWORD dwObjectType,
  3341. LPARAM lParam)
  3342. {
  3343. RtrCriticalSection rtrCritSec(&m_critsec);
  3344. HRESULT hr = hrOK;
  3345. COM_PROTECT_TRY
  3346. {
  3347. m_AdviseList.NotifyChange(dwChangeType, dwObjectType, lParam);
  3348. }
  3349. COM_PROTECT_CATCH;
  3350. return hr;
  3351. }
  3352. /*!--------------------------------------------------------------------------
  3353. RtrMgrInfo::RtrUnadvise
  3354. -
  3355. Author: KennT
  3356. ---------------------------------------------------------------------------*/
  3357. STDMETHODIMP RtrMgrInfo::RtrUnadvise(LONG_PTR ulConnection)
  3358. {
  3359. RtrCriticalSection rtrCritSec(&m_critsec);
  3360. return m_AdviseList.RemoveConnection(ulConnection);
  3361. }
  3362. /*!--------------------------------------------------------------------------
  3363. RtrMgrInfo::LoadRtrMgrInfo
  3364. -
  3365. Author: KennT
  3366. ---------------------------------------------------------------------------*/
  3367. HRESULT RtrMgrInfo::LoadRtrMgrInfo(HANDLE hMachine,
  3368. HANDLE hTransport)
  3369. {
  3370. RtrCriticalSection rtrCritSec(&m_critsec);
  3371. HRESULT hr = hrOK;
  3372. SPIInfoBase spGlobalInfo;
  3373. SPIEnumInfoBlock spEnumInfoBlock;
  3374. SPIEnumRtrMgrProtocolCB spEnumRmProtCB;
  3375. InfoBlock * pBlock;
  3376. RtrMgrProtocolCB RmProtCB;
  3377. RtrMgrProtocolInfo *pRmProt = NULL;
  3378. //
  3379. // If reloading, always load the global info, whether or not
  3380. // the caller has requested that it be loaded, since it will be needed
  3381. // to build the list of installed protocols.
  3382. //
  3383. //$ Review: kennt, what do we do with an error? This case was not
  3384. // checked previously.
  3385. GetInfoBase(hMachine, hTransport, &spGlobalInfo, NULL);
  3386. //
  3387. // We are reloading, so we need to rebuild the list of protocols.
  3388. // Get a list of the installed routing-protocols;
  3389. //
  3390. CORg( m_pRouterInfoParent->EnumRtrMgrProtocolCB(&spEnumRmProtCB) );
  3391. //
  3392. // Go through the list of blocks in the global info
  3393. // constructing a CRmProtInfo for each one that corresponds
  3394. // to a routing-protocol
  3395. //
  3396. CORg( spGlobalInfo->QueryBlockList(&spEnumInfoBlock) );
  3397. spEnumInfoBlock->Reset();
  3398. while (spEnumInfoBlock->Next(1, &pBlock, NULL) == hrOK)
  3399. {
  3400. //
  3401. // When a routing protocol is removed, its block is left in place,
  3402. // but with zero-length data.
  3403. // We skip such blocks since they don't represent installed protocols.
  3404. //
  3405. if (!pBlock->dwSize)
  3406. continue;
  3407. //
  3408. // Try to find a routing protocol whose protocol-ID
  3409. // is the same as this block's type
  3410. //
  3411. spEnumRmProtCB->Reset();
  3412. while (spEnumRmProtCB->Next(1, &RmProtCB, NULL) == hrOK)
  3413. {
  3414. //
  3415. // If this isn't the protocol's control block, continue
  3416. //
  3417. if (RmProtCB.dwProtocolId != pBlock->dwType)
  3418. continue;
  3419. //
  3420. // This is the control block, so construct a new CRmProtInfo
  3421. //
  3422. pRmProt = new RtrMgrProtocolInfo(RmProtCB.dwProtocolId,
  3423. RmProtCB.szId,
  3424. GetTransportId(),
  3425. m_cb.stId,
  3426. this);
  3427. Assert(pRmProt);
  3428. pRmProt->SetCB(&RmProtCB);
  3429. //
  3430. // Add the new protocol to our list
  3431. //
  3432. m_RmProtList.AddTail(pRmProt);
  3433. CONVERT_TO_WEAKREF(pRmProt);
  3434. pRmProt = NULL;
  3435. break;
  3436. }
  3437. }
  3438. Error:
  3439. if (pRmProt)
  3440. pRmProt->Release();
  3441. return hr;
  3442. }
  3443. /*!--------------------------------------------------------------------------
  3444. RtrMgrInfo::SaveRtrMgrInfo
  3445. -
  3446. Author: KennT
  3447. ---------------------------------------------------------------------------*/
  3448. HRESULT RtrMgrInfo::SaveRtrMgrInfo(HANDLE hMachine,
  3449. HANDLE hTransport,
  3450. IInfoBase *pGlobalInfo,
  3451. IInfoBase *pClientInfo,
  3452. DWORD dwDeleteProtocolId)
  3453. {
  3454. RtrCriticalSection rtrCritSec(&m_critsec);
  3455. HRESULT hr = hrOK;
  3456. SPIInfoBase spGlobalInfoTemp;
  3457. SPIInfoBase spClientInfoTemp;
  3458. DWORD dwGlobalBytesSize, dwClientBytesSize;
  3459. LPBYTE pGlobalBytes = NULL, pClientBytes = NULL;
  3460. COM_PROTECT_TRY
  3461. {
  3462. //
  3463. // If asked to delete a protocol, delete it now
  3464. //
  3465. if (dwDeleteProtocolId)
  3466. {
  3467. //
  3468. // If either global-info or client info was not given
  3469. // load the unspecified parameters so that they can be updated
  3470. // after the protocol to be deleted has been removed
  3471. //
  3472. if (!pGlobalInfo || !pClientInfo)
  3473. {
  3474. GetInfoBase(hMachine, hTransport,
  3475. pGlobalInfo ? NULL : &spGlobalInfoTemp,
  3476. pClientInfo ? NULL : &spClientInfoTemp
  3477. );
  3478. if (pGlobalInfo == NULL)
  3479. pGlobalInfo = spGlobalInfoTemp;
  3480. if (pClientInfo == NULL)
  3481. pClientInfo = spClientInfoTemp;
  3482. }
  3483. //
  3484. // Now remove the protocol specified
  3485. //
  3486. pGlobalInfo->SetData(dwDeleteProtocolId, 0, NULL, 0, 0);
  3487. pClientInfo->SetData(dwDeleteProtocolId, 0, NULL, 0, 0);
  3488. }
  3489. //
  3490. // Now update the information in the registry
  3491. // Convert the global-info to raw bytes
  3492. //
  3493. if (pGlobalInfo)
  3494. CORg( pGlobalInfo->WriteTo(&pGlobalBytes, &dwGlobalBytesSize) );
  3495. //
  3496. // Now convert the client-info to raw bytes
  3497. //
  3498. if (pClientInfo)
  3499. CORg( pClientInfo->WriteTo(&pClientBytes, &dwClientBytesSize) );
  3500. //
  3501. // Save the information to the persistent store
  3502. //
  3503. CWRg( ::MprConfigTransportSetInfo(hMachine,
  3504. hTransport,
  3505. pGlobalBytes,
  3506. dwGlobalBytesSize,
  3507. pClientBytes,
  3508. dwClientBytesSize,
  3509. NULL
  3510. ) );
  3511. //
  3512. // Finally, update the info of the running router-manager if possible
  3513. //
  3514. CORg( SetInfoBase(pGlobalInfo, pClientInfo) );
  3515. COM_PROTECT_ERROR_LABEL;
  3516. }
  3517. COM_PROTECT_CATCH;
  3518. CoTaskMemFree( pGlobalBytes );
  3519. CoTaskMemFree( pClientBytes );
  3520. return hrOK;
  3521. }
  3522. /*!--------------------------------------------------------------------------
  3523. RtrMgrInfo::TryToConnect
  3524. -
  3525. Author: KennT
  3526. ---------------------------------------------------------------------------*/
  3527. HRESULT RtrMgrInfo::TryToConnect(LPCWSTR pswzMachine, HANDLE *phMachine)
  3528. {
  3529. RtrCriticalSection rtrCritSec(&m_critsec);
  3530. HRESULT hr = hrOK;
  3531. if (m_hMachineConfig)
  3532. *phMachine = m_hMachineConfig;
  3533. else if (*phMachine)
  3534. {
  3535. m_hMachineConfig = *phMachine;
  3536. m_bDisconnect = FALSE;
  3537. }
  3538. else
  3539. {
  3540. //$ Review: kennt, this function does not take a LPCWSTR,
  3541. // is this a mistake or does it modify the parameters?
  3542. CWRg( ::MprConfigServerConnect((LPWSTR) pswzMachine, phMachine) );
  3543. m_hMachineConfig = *phMachine;
  3544. m_bDisconnect = TRUE;
  3545. }
  3546. Error:
  3547. return hr;
  3548. }
  3549. /*!--------------------------------------------------------------------------
  3550. RtrMgrInfo::GetParentRouterInfo
  3551. -
  3552. Author: KennT
  3553. ---------------------------------------------------------------------------*/
  3554. HRESULT RtrMgrInfo::GetParentRouterInfo(IRouterInfo **ppParent)
  3555. {
  3556. RtrCriticalSection rtrCritSec(&m_critsec);
  3557. *ppParent = m_pRouterInfoParent;
  3558. if (*ppParent)
  3559. (*ppParent)->AddRef();
  3560. return hrOK;
  3561. }
  3562. /*!--------------------------------------------------------------------------
  3563. RtrMgrInfo::SetParentRouterInfo
  3564. -
  3565. Author: KennT
  3566. ---------------------------------------------------------------------------*/
  3567. HRESULT RtrMgrInfo::SetParentRouterInfo(IRouterInfo *pParent)
  3568. {
  3569. RtrCriticalSection rtrCritSec(&m_critsec);
  3570. IRouterInfo * pTemp;
  3571. pTemp = m_pRouterInfoParent;
  3572. m_pRouterInfoParent = NULL;
  3573. if (m_fStrongRef)
  3574. {
  3575. if (pTemp)
  3576. pTemp->Release();
  3577. if (pParent)
  3578. pParent->AddRef();
  3579. }
  3580. else
  3581. {
  3582. if (pTemp)
  3583. pTemp->ReleaseWeakRef();
  3584. if (pParent)
  3585. pParent->AddWeakRef();
  3586. }
  3587. m_pRouterInfoParent = pParent;
  3588. return hrOK;
  3589. }
  3590. /*!--------------------------------------------------------------------------
  3591. RtrMgrInfo::Disconnect
  3592. -
  3593. Author: KennT
  3594. ---------------------------------------------------------------------------*/
  3595. void RtrMgrInfo::Disconnect()
  3596. {
  3597. if (m_bDisconnect && m_hMachineConfig)
  3598. ::MprConfigServerDisconnect(m_hMachineConfig);
  3599. m_bDisconnect = FALSE;
  3600. m_hMachineConfig = NULL;
  3601. m_hTransport = NULL;
  3602. }
  3603. /*!--------------------------------------------------------------------------
  3604. RtrMgrInfo::DoDisconnect
  3605. Removes the connections held by this object.
  3606. Author: KennT
  3607. ---------------------------------------------------------------------------*/
  3608. STDMETHODIMP RtrMgrInfo::DoDisconnect()
  3609. {
  3610. HRESULT hr = hrOK;
  3611. SPIEnumRtrMgrProtocolInfo spEnumRmProt;
  3612. SPIRtrMgrProtocolInfo spRmProt;
  3613. COM_PROTECT_TRY
  3614. {
  3615. // Disconnect our data.
  3616. // ------------------------------------------------------------
  3617. Disconnect();
  3618. // Notify the advise sinks of a disconnect.
  3619. // ------------------------------------------------------------
  3620. RtrNotify(ROUTER_DO_DISCONNECT, 0, 0);
  3621. // Now tell all child objects to disconnect.
  3622. // ------------------------------------------------------------
  3623. HRESULT hrIter = hrOK;
  3624. EnumRtrMgrProtocol(&spEnumRmProt);
  3625. spEnumRmProt->Reset();
  3626. while (spEnumRmProt->Next(1, &spRmProt, NULL) == hrOK)
  3627. {
  3628. spRmProt->DoDisconnect();
  3629. spRmProt.Release();
  3630. }
  3631. }
  3632. COM_PROTECT_CATCH;
  3633. return hr;
  3634. }
  3635. HRESULT RtrMgrInfo::TryToGetAllHandles(LPCOLESTR pszMachine,
  3636. HANDLE *phMachine,
  3637. HANDLE *phTransport)
  3638. {
  3639. HRESULT hr = hrOK;
  3640. Assert(phMachine);
  3641. Assert(phTransport);
  3642. //
  3643. // If already loaded, the handle passed in is ignored.
  3644. //
  3645. // Otherwise, if 'hMachine' was not specified, connect to the config
  3646. // on the specified machine
  3647. //
  3648. CORg( TryToConnect(pszMachine, phMachine) );
  3649. //
  3650. // Get a handle to the interface-transport
  3651. //
  3652. //
  3653. // If 'hIfTransport' was not specified, connect
  3654. //
  3655. if (phTransport)
  3656. {
  3657. if (m_hTransport)
  3658. *phTransport = m_hTransport;
  3659. else if (*phTransport)
  3660. m_hTransport = *phTransport;
  3661. else
  3662. {
  3663. //
  3664. // Get a handle to the interface-transport
  3665. //
  3666. CWRg( ::MprConfigTransportGetHandle(
  3667. *phMachine,
  3668. GetTransportId(),
  3669. phTransport
  3670. ) );
  3671. m_hTransport = *phTransport;
  3672. }
  3673. }
  3674. Error:
  3675. return hr;
  3676. }
  3677. /*---------------------------------------------------------------------------
  3678. RtrMgrProtocolInfo Implementation
  3679. ---------------------------------------------------------------------------*/
  3680. TFSCORE_API(HRESULT) CreateRtrMgrProtocolInfo(
  3681. IRtrMgrProtocolInfo **ppRmProtInfo,
  3682. const RtrMgrProtocolCB *pRmProtCB)
  3683. {
  3684. Assert(ppRmProtInfo);
  3685. Assert(pRmProtCB);
  3686. HRESULT hr = hrOK;
  3687. IRtrMgrProtocolInfo * pRmProt = NULL;
  3688. RtrMgrProtocolInfo * prmp;
  3689. USES_CONVERSION;
  3690. COM_PROTECT_TRY
  3691. {
  3692. prmp = new RtrMgrProtocolInfo(pRmProtCB->dwProtocolId,
  3693. W2CT(pRmProtCB->szId),
  3694. pRmProtCB->dwTransportId,
  3695. W2CT(pRmProtCB->szRtrMgrId),
  3696. NULL);
  3697. prmp->SetCB(pRmProtCB);
  3698. *ppRmProtInfo = prmp;
  3699. }
  3700. COM_PROTECT_CATCH;
  3701. return hr;
  3702. }
  3703. IMPLEMENT_WEAKREF_ADDREF_RELEASE(RtrMgrProtocolInfo);
  3704. IMPLEMENT_SIMPLE_QUERYINTERFACE(RtrMgrProtocolInfo, IRtrMgrProtocolInfo)
  3705. DEBUG_DECLARE_INSTANCE_COUNTER(RtrMgrProtocolInfo)
  3706. RtrMgrProtocolInfo::RtrMgrProtocolInfo(DWORD dwProtocolId,
  3707. LPCTSTR lpszId,
  3708. DWORD dwTransportId,
  3709. LPCTSTR lpszRm,
  3710. RtrMgrInfo * pRmInfo)
  3711. : m_dwFlags(0)
  3712. {
  3713. DEBUG_INCREMENT_INSTANCE_COUNTER(RtrMgrProtocolInfo);
  3714. m_cb.dwProtocolId = dwProtocolId;
  3715. m_cb.stId = lpszId;
  3716. m_cb.dwTransportId = dwTransportId;
  3717. m_cb.stRtrMgrId = lpszRm;
  3718. m_pRtrMgrInfoParent = pRmInfo;
  3719. if (m_pRtrMgrInfoParent)
  3720. m_pRtrMgrInfoParent->AddRef();
  3721. InitializeCriticalSection(&m_critsec);
  3722. }
  3723. RtrMgrProtocolInfo::~RtrMgrProtocolInfo()
  3724. {
  3725. Assert(m_pRtrMgrInfoParent == NULL);
  3726. Destruct();
  3727. DEBUG_DECREMENT_INSTANCE_COUNTER(RtrMgrProtocolInfo);
  3728. DeleteCriticalSection(&m_critsec);
  3729. }
  3730. void RtrMgrProtocolInfo::ReviveStrongRef()
  3731. {
  3732. RtrCriticalSection rtrCritSec(&m_critsec);
  3733. if (m_pRtrMgrInfoParent)
  3734. {
  3735. CONVERT_TO_STRONGREF(m_pRtrMgrInfoParent);
  3736. }
  3737. }
  3738. void RtrMgrProtocolInfo::OnLastStrongRef()
  3739. {
  3740. RtrCriticalSection rtrCritSec(&m_critsec);
  3741. if (m_pRtrMgrInfoParent)
  3742. {
  3743. CONVERT_TO_WEAKREF(m_pRtrMgrInfoParent);
  3744. }
  3745. if (m_fDestruct)
  3746. Destruct();
  3747. }
  3748. STDMETHODIMP RtrMgrProtocolInfo::Destruct()
  3749. {
  3750. RtrCriticalSection rtrCritSec(&m_critsec);
  3751. IRtrMgrInfo * pParent;
  3752. m_fDestruct = TRUE;
  3753. if (!m_fStrongRef)
  3754. {
  3755. // Release the parent pointer
  3756. pParent = m_pRtrMgrInfoParent;
  3757. m_pRtrMgrInfoParent = NULL;
  3758. if (pParent)
  3759. pParent->ReleaseWeakRef();
  3760. // release any data
  3761. }
  3762. return hrOK;
  3763. }
  3764. STDMETHODIMP_(DWORD) RtrMgrProtocolInfo::GetFlags()
  3765. {
  3766. RtrCriticalSection rtrCritSec(&m_critsec);
  3767. return m_dwFlags;
  3768. }
  3769. STDMETHODIMP RtrMgrProtocolInfo::SetFlags(DWORD dwFlags)
  3770. {
  3771. RtrCriticalSection rtrCritSec(&m_critsec);
  3772. HRESULT hr = hrOK;
  3773. COM_PROTECT_TRY
  3774. {
  3775. m_dwFlags = dwFlags;
  3776. }
  3777. COM_PROTECT_CATCH;
  3778. return hr;
  3779. }
  3780. /*!--------------------------------------------------------------------------
  3781. RtrMgrProtocolInfo::GetProtocolId
  3782. -
  3783. Author: KennT
  3784. ---------------------------------------------------------------------------*/
  3785. STDMETHODIMP_(DWORD) RtrMgrProtocolInfo::GetProtocolId()
  3786. {
  3787. RtrCriticalSection rtrCritSec(&m_critsec);
  3788. return m_cb.dwProtocolId;
  3789. }
  3790. /*!--------------------------------------------------------------------------
  3791. RtrMgrProtocolInfo::GetTitle
  3792. -
  3793. Author: KennT
  3794. ---------------------------------------------------------------------------*/
  3795. STDMETHODIMP_(LPCOLESTR) RtrMgrProtocolInfo::GetTitle()
  3796. {
  3797. RtrCriticalSection rtrCritSec(&m_critsec);
  3798. //$UNICODE : kennt, assumes OLECHAR == WCHAR and that
  3799. // we are native UNICODE
  3800. return m_cb.stTitle;
  3801. }
  3802. /*!--------------------------------------------------------------------------
  3803. RtrMgrProtocolInfo::GetTransportId
  3804. -
  3805. Author: KennT
  3806. ---------------------------------------------------------------------------*/
  3807. STDMETHODIMP_(DWORD) RtrMgrProtocolInfo::GetTransportId()
  3808. {
  3809. RtrCriticalSection rtrCritSec(&m_critsec);
  3810. return m_cb.dwTransportId;
  3811. }
  3812. /*!--------------------------------------------------------------------------
  3813. RtrMgrProtocolInfo::CopyCB
  3814. -
  3815. Author: KennT
  3816. ---------------------------------------------------------------------------*/
  3817. STDMETHODIMP RtrMgrProtocolInfo::CopyCB(RtrMgrProtocolCB *pRmProtCB)
  3818. {
  3819. RtrCriticalSection rtrCritSec(&m_critsec);
  3820. HRESULT hr = hrOK;
  3821. COM_PROTECT_TRY
  3822. {
  3823. m_cb.SaveTo(pRmProtCB);
  3824. }
  3825. COM_PROTECT_CATCH;
  3826. return hr;
  3827. }
  3828. /*!--------------------------------------------------------------------------
  3829. RtrMgrProtocolInfo::SetCB
  3830. -
  3831. Author: KennT
  3832. ---------------------------------------------------------------------------*/
  3833. HRESULT RtrMgrProtocolInfo::SetCB(const RtrMgrProtocolCB *pcb)
  3834. {
  3835. RtrCriticalSection rtrCritSec(&m_critsec);
  3836. m_cb.LoadFrom(pcb);
  3837. return hrOK;
  3838. }
  3839. /*!--------------------------------------------------------------------------
  3840. RtrMgrProtocolInfo::GetParentRtrMgrInfo
  3841. -
  3842. Author: KennT
  3843. ---------------------------------------------------------------------------*/
  3844. STDMETHODIMP RtrMgrProtocolInfo::GetParentRtrMgrInfo(IRtrMgrInfo **ppParent)
  3845. {
  3846. RtrCriticalSection rtrCritSec(&m_critsec);
  3847. *ppParent = m_pRtrMgrInfoParent;
  3848. if (*ppParent)
  3849. (*ppParent)->AddRef();
  3850. return hrOK;
  3851. }
  3852. /*!--------------------------------------------------------------------------
  3853. RtrMgrProtocolInfo::SetParentRtrMgrInfo
  3854. -
  3855. Author: KennT
  3856. ---------------------------------------------------------------------------*/
  3857. STDMETHODIMP RtrMgrProtocolInfo::SetParentRtrMgrInfo(IRtrMgrInfo *pParent)
  3858. {
  3859. RtrCriticalSection rtrCritSec(&m_critsec);
  3860. IRtrMgrInfo * pTemp;
  3861. pTemp = m_pRtrMgrInfoParent;
  3862. m_pRtrMgrInfoParent = NULL;
  3863. if (m_fStrongRef)
  3864. {
  3865. if (pTemp)
  3866. pTemp->Release();
  3867. if (pParent)
  3868. pParent->AddRef();
  3869. }
  3870. else
  3871. {
  3872. if (pTemp)
  3873. pTemp->ReleaseWeakRef();
  3874. if (pParent)
  3875. pParent->AddWeakRef();
  3876. }
  3877. m_pRtrMgrInfoParent = pParent;
  3878. return hrOK;
  3879. }
  3880. /*!--------------------------------------------------------------------------
  3881. RtrMgrProtocolInfo::RtrAdvise
  3882. -
  3883. Author: KennT
  3884. ---------------------------------------------------------------------------*/
  3885. STDMETHODIMP RtrMgrProtocolInfo::RtrAdvise(IRtrAdviseSink *pRtrAdviseSink,
  3886. LONG_PTR *pulConnection,
  3887. LPARAM lUserParam)
  3888. {
  3889. Assert(pRtrAdviseSink);
  3890. Assert(pulConnection);
  3891. RtrCriticalSection rtrCritSec(&m_critsec);
  3892. LONG_PTR ulConnId;
  3893. HRESULT hr = hrOK;
  3894. COM_PROTECT_TRY
  3895. {
  3896. ulConnId = (LONG_PTR) InterlockedIncrement(&s_cConnections);
  3897. CORg( m_AdviseList.AddConnection(pRtrAdviseSink, ulConnId, lUserParam) );
  3898. *pulConnection = ulConnId;
  3899. COM_PROTECT_ERROR_LABEL;
  3900. }
  3901. COM_PROTECT_CATCH;
  3902. return hr;
  3903. }
  3904. /*!--------------------------------------------------------------------------
  3905. RtrMgrProtocolInfo::RtrNotify
  3906. -
  3907. Author: KennT
  3908. ---------------------------------------------------------------------------*/
  3909. STDMETHODIMP RtrMgrProtocolInfo::RtrNotify(DWORD dwChangeType, DWORD dwObjectType,
  3910. LPARAM lParam)
  3911. {
  3912. RtrCriticalSection rtrCritSec(&m_critsec);
  3913. HRESULT hr = hrOK;
  3914. COM_PROTECT_TRY
  3915. {
  3916. m_AdviseList.NotifyChange(dwChangeType, dwObjectType, lParam);
  3917. }
  3918. COM_PROTECT_CATCH;
  3919. return hr;
  3920. }
  3921. /*!--------------------------------------------------------------------------
  3922. RtrMgrProtocolInfo::RtrUnadvise
  3923. -
  3924. Author: KennT
  3925. ---------------------------------------------------------------------------*/
  3926. STDMETHODIMP RtrMgrProtocolInfo::RtrUnadvise(LONG_PTR ulConnection)
  3927. {
  3928. RtrCriticalSection rtrCritSec(&m_critsec);
  3929. return m_AdviseList.RemoveConnection(ulConnection);
  3930. }
  3931. /*!--------------------------------------------------------------------------
  3932. RtrMgrProtocolInfo::Disconnect
  3933. -
  3934. Author: KennT
  3935. ---------------------------------------------------------------------------*/
  3936. void RtrMgrProtocolInfo::Disconnect()
  3937. {
  3938. }
  3939. /*!--------------------------------------------------------------------------
  3940. RtrMgrProtocolInfo::DoDisconnect
  3941. Implementation of IRtrMgrProtocolInfo::DoDisconnect
  3942. Author: KennT
  3943. ---------------------------------------------------------------------------*/
  3944. STDMETHODIMP RtrMgrProtocolInfo::DoDisconnect()
  3945. {
  3946. HRESULT hr = hrOK;
  3947. COM_PROTECT_TRY
  3948. {
  3949. // Disconnect our data.
  3950. // ------------------------------------------------------------
  3951. Disconnect();
  3952. // Notify the advise sinks of a disconnect.
  3953. // ------------------------------------------------------------
  3954. RtrNotify(ROUTER_DO_DISCONNECT, 0, 0);
  3955. }
  3956. COM_PROTECT_CATCH;
  3957. return hr;
  3958. }
  3959. /*---------------------------------------------------------------------------
  3960. InterfaceInfo Implementation
  3961. ---------------------------------------------------------------------------*/
  3962. TFSCORE_API(HRESULT) CreateInterfaceInfo(IInterfaceInfo **ppInterfaceInfo,
  3963. LPCWSTR pswzInterfaceId,
  3964. DWORD dwInterfaceType)
  3965. {
  3966. Assert(ppInterfaceInfo);
  3967. HRESULT hr = hrOK;
  3968. InterfaceInfo * pInterfaceInfo = NULL;
  3969. USES_CONVERSION;
  3970. COM_PROTECT_TRY
  3971. {
  3972. pInterfaceInfo = new InterfaceInfo(W2CT(pswzInterfaceId),
  3973. dwInterfaceType,
  3974. TRUE,
  3975. InterfaceCB_BindToIp | InterfaceCB_BindToIpx,
  3976. NULL);
  3977. *ppInterfaceInfo = pInterfaceInfo;
  3978. }
  3979. COM_PROTECT_CATCH;
  3980. return hr;
  3981. }
  3982. IMPLEMENT_WEAKREF_ADDREF_RELEASE(InterfaceInfo)
  3983. IMPLEMENT_SIMPLE_QUERYINTERFACE(InterfaceInfo, IInterfaceInfo)
  3984. DEBUG_DECLARE_INSTANCE_COUNTER(InterfaceInfo)
  3985. InterfaceInfo::InterfaceInfo(LPCTSTR pszId,
  3986. DWORD dwIfType,
  3987. BOOL bEnable,
  3988. DWORD dwBindFlags,
  3989. RouterInfo *pRouterInfo)
  3990. : m_hMachineConfig(NULL),
  3991. m_hInterface(NULL),
  3992. m_bDisconnect(FALSE),
  3993. m_dwFlags(0)
  3994. {
  3995. DEBUG_INCREMENT_INSTANCE_COUNTER(InterfaceInfo);
  3996. m_cb.stId = pszId;
  3997. m_cb.dwIfType = dwIfType;
  3998. m_cb.bEnable = bEnable;
  3999. m_cb.dwBindFlags = dwBindFlags;
  4000. m_pRouterInfoParent = pRouterInfo;
  4001. if (m_pRouterInfoParent)
  4002. m_pRouterInfoParent->AddRef();
  4003. InitializeCriticalSection(&m_critsec);
  4004. }
  4005. InterfaceInfo::~InterfaceInfo()
  4006. {
  4007. Assert(m_pRouterInfoParent == NULL);
  4008. Destruct();
  4009. DEBUG_DECREMENT_INSTANCE_COUNTER(InterfaceInfo);
  4010. DeleteCriticalSection(&m_critsec);
  4011. }
  4012. void InterfaceInfo::ReviveStrongRef()
  4013. {
  4014. RtrCriticalSection rtrCritSec(&m_critsec);
  4015. if (m_pRouterInfoParent)
  4016. {
  4017. CONVERT_TO_STRONGREF(m_pRouterInfoParent);
  4018. }
  4019. }
  4020. void InterfaceInfo::OnLastStrongRef()
  4021. {
  4022. RtrCriticalSection rtrCritSec(&m_critsec);
  4023. if (m_pRouterInfoParent)
  4024. {
  4025. CONVERT_TO_WEAKREF(m_pRouterInfoParent);
  4026. }
  4027. if (m_fDestruct)
  4028. Destruct();
  4029. }
  4030. STDMETHODIMP InterfaceInfo::Destruct()
  4031. {
  4032. RtrCriticalSection rtrCritSec(&m_critsec);
  4033. IRouterInfo * pParent;
  4034. m_fDestruct = TRUE;
  4035. if (!m_fStrongRef)
  4036. {
  4037. pParent = m_pRouterInfoParent;
  4038. m_pRouterInfoParent = NULL;
  4039. if (pParent)
  4040. pParent->ReleaseWeakRef();
  4041. // release any data
  4042. Unload();
  4043. }
  4044. return hrOK;
  4045. }
  4046. STDMETHODIMP_(DWORD) InterfaceInfo::GetFlags()
  4047. {
  4048. RtrCriticalSection rtrCritSec(&m_critsec);
  4049. return m_dwFlags;
  4050. }
  4051. STDMETHODIMP InterfaceInfo::SetFlags(DWORD dwFlags)
  4052. {
  4053. RtrCriticalSection rtrCritSec(&m_critsec);
  4054. HRESULT hr = hrOK;
  4055. COM_PROTECT_TRY
  4056. {
  4057. m_dwFlags = dwFlags;
  4058. }
  4059. COM_PROTECT_CATCH;
  4060. return hr;
  4061. }
  4062. /*!--------------------------------------------------------------------------
  4063. InterfaceInfo::Load
  4064. -
  4065. Author: KennT
  4066. ---------------------------------------------------------------------------*/
  4067. STDMETHODIMP InterfaceInfo::Load(LPCOLESTR pszMachine,
  4068. HANDLE hMachine,
  4069. HANDLE hInterface)
  4070. {
  4071. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  4072. RtrCriticalSection rtrCritSec(&m_critsec);
  4073. HRESULT hr = hrOK;
  4074. DWORD dwSize = 0;
  4075. MPR_INTERFACE_0 *pinterface = NULL;
  4076. SPIEnumInterfaceCB spEnumInterfaceCB;
  4077. InterfaceCB ifCB;
  4078. SPSZ spszTitle;
  4079. CString stTitle;
  4080. DWORD dwIfType;
  4081. BOOL bFound = FALSE;
  4082. COM_PROTECT_TRY
  4083. {
  4084. //
  4085. // Discard any existing information
  4086. //
  4087. Unload();
  4088. m_stMachine = OLE2CT(pszMachine ? pszMachine : TEXT(""));
  4089. //
  4090. // If 'hMachine' was not specified, connect to the config
  4091. // on the specified machine
  4092. //
  4093. Assert(m_hMachineConfig == NULL);
  4094. CORg( TryToConnect(OLE2CW(pszMachine), &hMachine) );
  4095. //
  4096. // If 'hInterface' was not specified, connect to the interface
  4097. //
  4098. CORg( TryToGetIfHandle(hMachine, OLE2CW(GetId()), &hInterface) );
  4099. //
  4100. // Get information for the interface
  4101. //
  4102. CWRg( ::MprConfigInterfaceGetInfo(
  4103. hMachine,
  4104. hInterface,
  4105. 0,
  4106. (LPBYTE*)&pinterface,
  4107. &dwSize
  4108. ) );
  4109. // Windows NT Bug ?
  4110. // If this interface is a removed adapter, do not show it.
  4111. // This check needs to be made only for MprConfigInterfacEnum
  4112. // ------------------------------------------------------------
  4113. if ((pinterface->dwConnectionState == ROUTER_IF_STATE_UNREACHABLE) &&
  4114. (pinterface->fUnReachabilityReasons == MPR_INTERFACE_NO_DEVICE))
  4115. {
  4116. CORg( E_INVALIDARG );
  4117. }
  4118. //
  4119. // Save the interface type and enabled/disabled status
  4120. //
  4121. m_cb.dwIfType = (DWORD)pinterface->dwIfType;
  4122. m_cb.bEnable = pinterface->fEnabled;
  4123. ::MprConfigBufferFree(pinterface);
  4124. if (m_pRouterInfoParent)
  4125. {
  4126. //
  4127. // The caller has supplied a list of LAN adapters ('pifcbList'),
  4128. // or this object is contained in a 'CRouterInfo' which will have
  4129. // already loaded the LAN interface control-blocks;
  4130. // search through the list to find our title,
  4131. //
  4132. m_pRouterInfoParent->EnumInterfaceCB(&spEnumInterfaceCB);
  4133. spEnumInterfaceCB->Reset();
  4134. while (spEnumInterfaceCB->Next(1, &ifCB, NULL) == hrOK)
  4135. {
  4136. if (StriCmp(ifCB.szId, OLE2CT(GetId())) == 0)
  4137. {
  4138. m_cb.stTitle = ifCB.szTitle;
  4139. m_cb.stDeviceName = ifCB.szDevice;
  4140. bFound = TRUE;
  4141. break;
  4142. }
  4143. else
  4144. {
  4145. // Windows NT bug 103770
  4146. // Need to check to see if the pcb->sID is a prefix
  4147. // of the Id string (if so it may be the IPX case
  4148. // so use that ID).
  4149. stTitle = GetId();
  4150. if (stTitle.Find((LPCTSTR) ifCB.szId) == 0)
  4151. {
  4152. // Need to check to see that the extension
  4153. // is what we think it is.
  4154. LPCTSTR pszExt = ((LPCTSTR) stTitle +
  4155. lstrlen(ifCB.szId));
  4156. if ((*pszExt == 0) ||
  4157. (lstrcmpi(pszExt, c_szEthernetSNAP) == 0) ||
  4158. (lstrcmpi(pszExt, c_szEthernetII) == 0) ||
  4159. (lstrcmpi(pszExt, c_szEthernet8022) == 0) ||
  4160. (lstrcmpi(pszExt, c_szEthernet8023) == 0))
  4161. {
  4162. m_cb.stTitle = ifCB.szTitle;
  4163. m_cb.stTitle += _T(" (");
  4164. m_cb.stTitle += pszExt + 1; // add 1 to skip over /
  4165. m_cb.stTitle += _T(")");
  4166. bFound = TRUE;
  4167. break;
  4168. }
  4169. }
  4170. }
  4171. }
  4172. }
  4173. if (!bFound)
  4174. {
  4175. //
  4176. // Read the title directly from the registry
  4177. //
  4178. hr = InterfaceInfo::FindInterfaceTitle(OLE2CT(GetMachineName()),
  4179. OLE2CT(GetId()),
  4180. &spszTitle);
  4181. if (FHrOK(hr))
  4182. m_cb.stTitle = spszTitle;
  4183. else
  4184. m_cb.stTitle = OLE2CT(GetId());
  4185. hr = hrOK;
  4186. }
  4187. //
  4188. // Load the list of router-managers on this interface
  4189. //
  4190. CORg( LoadRtrMgrInterfaceList() );
  4191. COM_PROTECT_ERROR_LABEL;
  4192. }
  4193. COM_PROTECT_CATCH;
  4194. if (!FHrSucceeded(hr))
  4195. Unload();
  4196. return hr;
  4197. }
  4198. /*!--------------------------------------------------------------------------
  4199. InterfaceInfo::Save
  4200. -
  4201. Saves the changes to a CInterfaceInfo to the registry.
  4202. Author: KennT
  4203. ---------------------------------------------------------------------------*/
  4204. STDMETHODIMP InterfaceInfo::Save(LPCOLESTR pszMachine,
  4205. HANDLE hMachine,
  4206. HANDLE hInterface)
  4207. {
  4208. RtrCriticalSection rtrCritSec(&m_critsec);
  4209. HRESULT hr = hrOK;
  4210. DWORD dwErr;
  4211. MPR_INTERFACE_0 mprInterface;
  4212. WCHAR wszInterface[MAX_INTERFACE_NAME_LEN+1];
  4213. MPR_SERVER_HANDLE hrouter = NULL;
  4214. #ifdef KSL_IPINIP
  4215. MPR_IPINIP_INTERFACE_0 mprTunnelInterface;
  4216. #endif //KSL_IPINIP
  4217. COM_PROTECT_TRY
  4218. {
  4219. //
  4220. // If already connected, the handle passed in is ignored;
  4221. //
  4222. // Otherwise, if 'hMachine' was not specified, connect to the config
  4223. // on the specified machine
  4224. //
  4225. CORg( TryToConnect(OLE2CW(pszMachine), &hMachine) );
  4226. //
  4227. // Convert the interface name to Unicode
  4228. //
  4229. StrCpyWFromOle(wszInterface, GetId());
  4230. ZeroMemory(&mprInterface, sizeof(mprInterface));
  4231. StrCpyW(mprInterface.wszInterfaceName, wszInterface);
  4232. mprInterface.dwIfType = (ROUTER_INTERFACE_TYPE) GetInterfaceType();
  4233. mprInterface.fEnabled = IsInterfaceEnabled();
  4234. //
  4235. // If already connected, use the existing interface-handle.
  4236. //
  4237. // Otherwise, if the interface-handle wasn't passed in,
  4238. // try to get a handle to the interface; if that fails,
  4239. // create the interface.
  4240. //
  4241. hr = TryToGetIfHandle(hMachine, wszInterface, &hInterface);
  4242. if (!FHrSucceeded(hr))
  4243. {
  4244. #ifdef KSL_IPINIP
  4245. if (GetInterfaceType() == ROUTER_IF_TYPE_TUNNEL1)
  4246. {
  4247. //
  4248. // If we are creating a tunnel, we need to register
  4249. // the GUID-to-friendly name mapping.
  4250. //
  4251. ::ZeroMemory(&mprTunnelInterface,
  4252. sizeof(mprTunnelInterface));
  4253. StrnCpyW(mprTunnelInterface.wszFriendlyName,
  4254. GetTitle(),
  4255. MAX_INTERFACE_NAME_LEN);
  4256. CORg( CLSIDFromString(wszInterface,
  4257. &(mprTunnelInterface.Guid)) );
  4258. CWRg( MprSetupIpInIpInterfaceFriendlyNameCreate(
  4259. (LPOLESTR) GetMachineName(),
  4260. &mprTunnelInterface
  4261. ) );
  4262. // The mapping was created.
  4263. // If we get an error, we need to delete the mapping.
  4264. fIpInIpMapping = TRUE;
  4265. }
  4266. #endif //KSL_IPINIP
  4267. //
  4268. // We couldn't get a handle to the interface,
  4269. // so now attempt to create it.
  4270. //
  4271. CWRg( ::MprConfigInterfaceCreate(
  4272. hMachine,
  4273. 0,
  4274. (LPBYTE)&mprInterface,
  4275. &hInterface
  4276. ) );
  4277. m_hInterface = hInterface;
  4278. }
  4279. //
  4280. // Save the current settings for the interface.
  4281. //
  4282. CWRg( ::MprConfigInterfaceSetInfo(
  4283. hMachine,
  4284. hInterface,
  4285. 0,
  4286. (LPBYTE)&mprInterface
  4287. ) );
  4288. //
  4289. // Now notify the router-service of the new interface
  4290. //
  4291. //
  4292. // Attempt to connect to the router-service
  4293. //
  4294. //$ Review: kennt, what happens if the call to ConnectRouter()
  4295. // fails, we don't have an error code
  4296. if (ConnectRouter(OLE2CT(GetMachineName()), (HANDLE*)&hrouter) == NO_ERROR)
  4297. {
  4298. //
  4299. // The router is running; attempt to get a handle to the interface
  4300. //
  4301. dwErr = ::MprAdminInterfaceGetHandle(hrouter,
  4302. wszInterface,
  4303. &hInterface,
  4304. FALSE
  4305. );
  4306. if (dwErr != NO_ERROR)
  4307. {
  4308. //
  4309. // We couldn't get a handle to the interface,
  4310. // so try creating it.
  4311. //
  4312. dwErr = ::MprAdminInterfaceCreate(
  4313. hrouter,
  4314. 0,
  4315. (BYTE*)&mprInterface,
  4316. &hInterface
  4317. );
  4318. }
  4319. else
  4320. {
  4321. //
  4322. // Save the current settings for the interface.
  4323. //
  4324. dwErr = ::MprAdminInterfaceSetInfo(hrouter,
  4325. hInterface,
  4326. 0,
  4327. (LPBYTE)&mprInterface
  4328. );
  4329. }
  4330. ::MprAdminServerDisconnect(hrouter);
  4331. if ((dwErr == RPC_S_SERVER_UNAVAILABLE) ||
  4332. (dwErr == RPC_S_UNKNOWN_IF))
  4333. dwErr = NO_ERROR;
  4334. if (dwErr != NO_ERROR)
  4335. hr = HRESULT_FROM_WIN32(dwErr);
  4336. }
  4337. COM_PROTECT_ERROR_LABEL;
  4338. }
  4339. COM_PROTECT_CATCH;
  4340. #ifdef KSL_IPINIP
  4341. if (!FHrSucceeded(hr) && fIpInIpMapping)
  4342. {
  4343. // Assume : that the the mprTunnelInterface.Guid was
  4344. // initialized, since to reach there they would have had
  4345. // to gone through the CLSIDFromString() call.
  4346. MprSetupIpInIpInterfaceFriendlyNameDelete((LPOLESTR) GetMachineName(),
  4347. &(mprTunnelInterface.Guid)
  4348. );
  4349. }
  4350. #endif //KSL_IPINIP
  4351. return hr;
  4352. }
  4353. /*!--------------------------------------------------------------------------
  4354. InterfaceInfo::Delete
  4355. -
  4356. Author: KennT
  4357. ---------------------------------------------------------------------------*/
  4358. STDMETHODIMP InterfaceInfo::Delete(LPCOLESTR pszMachine,
  4359. HANDLE hMachine)
  4360. {
  4361. RtrCriticalSection rtrCritSec(&m_critsec);
  4362. HRESULT hr = hrOK;
  4363. DWORD dwErr;
  4364. HANDLE hInterface;
  4365. WCHAR wszInterface[MAX_INTERFACE_NAME_LEN+1];
  4366. MPR_SERVER_HANDLE hrouter = NULL;
  4367. #ifdef KSL_IPINIP
  4368. GUID guidTunnel;
  4369. #endif //KSL_IPINIP
  4370. COM_PROTECT_TRY
  4371. {
  4372. // If already connected, the handle passed in is ignored;
  4373. //
  4374. // Otherwise, if 'hMachine' was not specified, connect to the config
  4375. // on the specified machine
  4376. // ------------------------------------------------------------
  4377. CORg( TryToConnect(OLE2CW(pszMachine), &hMachine) );
  4378. StrCpyWFromOle(wszInterface, GetId());
  4379. // Try to get a handle to the interface
  4380. // ------------------------------------------------------------
  4381. CWRg( ::MprConfigInterfaceGetHandle(hMachine,
  4382. wszInterface,
  4383. &hInterface
  4384. ) );
  4385. // Delete the interface
  4386. // ------------------------------------------------------------
  4387. dwErr = ::MprConfigInterfaceDelete(
  4388. hMachine, hInterface
  4389. );
  4390. m_hInterface = NULL;
  4391. CWRg( dwErr );
  4392. #ifdef KSL_IPINIP
  4393. // If this interface is a tunnel, we need to remove the
  4394. // GUID-to-Friendly name mapping
  4395. // ------------------------------------------------------------
  4396. if (GetInterfaceType() == ROUTER_IF_TYPE_TUNNEL1)
  4397. {
  4398. if (FHrOK(CLSIDFromString((LPTSTR) GetId(),
  4399. &guidTunnel)))
  4400. {
  4401. // If this call fails, we can't do anything about it
  4402. // ----------------------------------------------------
  4403. MprSetupIpInIpInterfaceFriendlyNameDelete((LPTSTR) pszMachine,
  4404. &guidTunnel);
  4405. }
  4406. }
  4407. #endif //KSL_IPINIP
  4408. // Remove the interface from the router if it is running
  4409. // ------------------------------------------------------------
  4410. if (ConnectRouter(OLE2CT(GetMachineName()), (HANDLE*)&hrouter) == NO_ERROR)
  4411. {
  4412. // The router is running; get a handle to the interface
  4413. // --------------------------------------------------------
  4414. dwErr = ::MprAdminInterfaceGetHandle(
  4415. hrouter,
  4416. wszInterface,
  4417. &hInterface,
  4418. FALSE
  4419. );
  4420. if (dwErr == NO_ERROR)
  4421. {
  4422. // Delete the interface
  4423. // ----------------------------------------------------
  4424. dwErr = ::MprAdminInterfaceDelete(
  4425. hrouter,
  4426. hInterface
  4427. );
  4428. }
  4429. ::MprAdminServerDisconnect(hrouter);
  4430. if ((dwErr == RPC_S_SERVER_UNAVAILABLE) ||
  4431. (dwErr == RPC_S_UNKNOWN_IF))
  4432. dwErr = NO_ERROR;
  4433. hr = HRESULT_FROM_WIN32(dwErr);
  4434. }
  4435. // Windows NT Bug: 138738
  4436. // Need to remove the interface from the router managers
  4437. // when deleting the interface.
  4438. // ------------------------------------------------------------
  4439. // Clear out all information for this interface
  4440. // ------------------------------------------------------------
  4441. if (FHrSucceeded(hr))
  4442. {
  4443. SPIEnumRtrMgrInterfaceInfo spEnumRmIf;
  4444. SPIRtrMgrInterfaceInfo spRmIf;
  4445. // Remove the Router Managers from this interface
  4446. // --------------------------------------------------------
  4447. EnumRtrMgrInterface(&spEnumRmIf);
  4448. while (spEnumRmIf->Next(1, &spRmIf, NULL) == hrOK)
  4449. {
  4450. DWORD dwTransportId = spRmIf->GetTransportId();
  4451. spRmIf.Release();
  4452. DeleteRtrMgrInterface(dwTransportId, TRUE);
  4453. }
  4454. }
  4455. COM_PROTECT_ERROR_LABEL;
  4456. }
  4457. COM_PROTECT_CATCH;
  4458. return hr;
  4459. }
  4460. /*!--------------------------------------------------------------------------
  4461. InterfaceInfo::Unload
  4462. -
  4463. Author: KennT
  4464. ---------------------------------------------------------------------------*/
  4465. STDMETHODIMP InterfaceInfo::Unload( )
  4466. {
  4467. RtrCriticalSection rtrCritSec(&m_critsec);
  4468. HRESULT hr = hrOK;
  4469. IRtrMgrInterfaceInfo * pRmIf;
  4470. COM_PROTECT_TRY
  4471. {
  4472. //
  4473. // Free all the contained router-manager structures in our list
  4474. //
  4475. while (!m_RmIfList.IsEmpty())
  4476. {
  4477. pRmIf = m_RmIfList.RemoveHead();
  4478. pRmIf->Destruct();
  4479. pRmIf->ReleaseWeakRef();
  4480. }
  4481. DoDisconnect();
  4482. }
  4483. COM_PROTECT_CATCH;
  4484. return hr;
  4485. }
  4486. /*!--------------------------------------------------------------------------
  4487. InterfaceInfo::Merge
  4488. -
  4489. Author: KennT
  4490. ---------------------------------------------------------------------------*/
  4491. STDMETHODIMP InterfaceInfo::Merge(IInterfaceInfo *pNewIf)
  4492. {
  4493. RtrCriticalSection rtrCritSec(&m_critsec);
  4494. HRESULT hr = hrOK;
  4495. HRESULT hrT;
  4496. SPIEnumRtrMgrInterfaceInfo spEnumRmIf;
  4497. SPIRtrMgrInterfaceInfo spRmIf;
  4498. SPIRtrMgrInfo spRm;
  4499. SPIRtrMgrProtocolInfo spRmProt;
  4500. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  4501. SPIEnumRtrMgrProtocolInterfaceInfo spEnumRmProtIf;
  4502. CDWordArray oldDWArray;
  4503. CDWordArray newDWArray;
  4504. int cOld, cNew;
  4505. int i, j;
  4506. DWORD dwTemp;
  4507. InterfaceCB ifCB;
  4508. Assert(pNewIf);
  4509. Assert(lstrcmpi(pNewIf->GetId(), GetId()) == 0);
  4510. COM_PROTECT_TRY
  4511. {
  4512. // Need to sync up the interface CB Data
  4513. pNewIf->CopyCB(&ifCB);
  4514. m_cb.LoadFrom(&ifCB);
  4515. // Need to sync up the RtrMgrInterface list
  4516. // They are identified by transport ids, so we can
  4517. // use the two array method used by
  4518. // IRtrMgrInterfaceInfo::Merge
  4519. // Get the list of RtrMgrs that are in the new object
  4520. CORg( pNewIf->EnumRtrMgrInterface(&spEnumRmIf) );
  4521. spEnumRmIf->Reset();
  4522. while (spEnumRmIf->Next(1, &spRmIf, NULL) == hrOK)
  4523. {
  4524. newDWArray.Add(spRmIf->GetTransportId());
  4525. spRmIf.Release();
  4526. }
  4527. spEnumRmIf.Release();
  4528. spRmIf.Release();
  4529. // Get the list of interfaces that are in this object
  4530. CORg( this->EnumRtrMgrInterface(&spEnumRmIf) );
  4531. spEnumRmIf->Reset();
  4532. while (spEnumRmIf->Next(1, &spRmIf, NULL) == hrOK)
  4533. {
  4534. oldDWArray.Add(spRmIf->GetTransportId());
  4535. spRmIf.Release();
  4536. }
  4537. spEnumRmIf.Release();
  4538. spRmIf.Release();
  4539. // Ok now go through both lists, removing from the lists
  4540. // interfaces that are in both lists.
  4541. cOld = oldDWArray.GetSize();
  4542. cNew = newDWArray.GetSize();
  4543. for (i=cOld; --i>=0; )
  4544. {
  4545. dwTemp = oldDWArray.GetAt(i);
  4546. for (j=cNew; --j>=0; )
  4547. {
  4548. if (dwTemp == newDWArray.GetAt(j))
  4549. {
  4550. SPIRtrMgrInterfaceInfo spRmIf1;
  4551. SPIRtrMgrInterfaceInfo spRmIf2;
  4552. this->FindRtrMgrInterface(dwTemp, &spRmIf1);
  4553. pNewIf->FindRtrMgrInterface(dwTemp, &spRmIf2);
  4554. Assert(spRmIf1);
  4555. Assert(spRmIf2);
  4556. spRmIf1->Merge(spRmIf2);
  4557. // remove both instances
  4558. newDWArray.RemoveAt(j);
  4559. oldDWArray.RemoveAt(i);
  4560. // Need to update the size of the new array
  4561. cNew--;
  4562. break;
  4563. }
  4564. }
  4565. }
  4566. // oldDWArray now contains the interfaces that should be
  4567. // removed.
  4568. if (oldDWArray.GetSize())
  4569. {
  4570. for (i=oldDWArray.GetSize(); --i>=0; )
  4571. {
  4572. // Windows NT Bug: 132993, if this interface
  4573. // is one that is purely local (mostly because
  4574. // it is a new interface), then we should not
  4575. // delete it.
  4576. SPIRtrMgrInterfaceInfo spRmIfTemp;
  4577. FindRtrMgrInterface(oldDWArray.GetAt(i),
  4578. &spRmIfTemp);
  4579. Assert(spRmIfTemp);
  4580. if (spRmIfTemp->GetFlags() & RouterSnapin_InSyncWithRouter)
  4581. DeleteRtrMgrInterface(oldDWArray.GetAt(i), FALSE);
  4582. }
  4583. }
  4584. // newDWArray contains the interfaces that should be added
  4585. if (newDWArray.GetSize())
  4586. {
  4587. for (i=newDWArray.GetSize(); --i>= 0; )
  4588. {
  4589. hr = pNewIf->FindRtrMgrInterface(
  4590. newDWArray.GetAt(i), &spRmIf);
  4591. Assert(hr == hrOK);
  4592. if (spRmIf)
  4593. {
  4594. AddRtrMgrInterface(spRmIf, NULL);
  4595. // Remove this rmif from its old interface
  4596. // ------------------------------------------------
  4597. pNewIf->ReleaseRtrMgrInterface(spRmIf->GetTransportId());
  4598. // We need to do the notify ourselves (because
  4599. // of the NULL infobase) the notifications won't
  4600. // get sent.
  4601. spRmIf->RtrNotify(ROUTER_CHILD_ADD, ROUTER_OBJ_RmIf, 0);
  4602. if (m_pRouterInfoParent)
  4603. {
  4604. spRm.Release();
  4605. hrT = m_pRouterInfoParent->FindRtrMgr(spRmIf->GetTransportId(), &spRm);
  4606. if (FHrOK(hrT))
  4607. {
  4608. spRm->RtrNotify(ROUTER_CHILD_ADD, ROUTER_OBJ_RmIf, 0);
  4609. // In addition, we will have to let the objects
  4610. // know that the interfaces are also being added
  4611. spEnumRmProtIf.Release();
  4612. spRmProtIf.Release();
  4613. spRmIf->EnumRtrMgrProtocolInterface(&spEnumRmProtIf);
  4614. for(; spEnumRmProtIf->Next(1, &spRmProtIf, NULL) == hrOK; spRmProtIf.Release())
  4615. {
  4616. spRmProt.Release();
  4617. spRm->FindRtrMgrProtocol(spRmProtIf->GetProtocolId(),
  4618. &spRmProt);
  4619. if (spRmProt)
  4620. spRmProt->RtrNotify(ROUTER_CHILD_ADD, ROUTER_OBJ_RmProtIf, 0);
  4621. }
  4622. }
  4623. }
  4624. }
  4625. spRmIf.Release();
  4626. }
  4627. }
  4628. COM_PROTECT_ERROR_LABEL;
  4629. }
  4630. COM_PROTECT_CATCH;
  4631. return hr;
  4632. }
  4633. /*!--------------------------------------------------------------------------
  4634. InterfaceInfo::GetId
  4635. -
  4636. Author: KennT
  4637. ---------------------------------------------------------------------------*/
  4638. STDMETHODIMP_(LPCOLESTR) InterfaceInfo::GetId()
  4639. {
  4640. RtrCriticalSection rtrCritSec(&m_critsec);
  4641. //$UNICODE : kennt, assumes native unicode and OLECHAR==WCHAR
  4642. return m_cb.stId;
  4643. }
  4644. /*!--------------------------------------------------------------------------
  4645. InterfaceInfo::GetInterfaceType
  4646. -
  4647. Author: KennT
  4648. ---------------------------------------------------------------------------*/
  4649. STDMETHODIMP_(DWORD) InterfaceInfo::GetInterfaceType()
  4650. {
  4651. RtrCriticalSection rtrCritSec(&m_critsec);
  4652. return m_cb.dwIfType;
  4653. }
  4654. /*!--------------------------------------------------------------------------
  4655. InterfaceInfo::GetDeviceName
  4656. -
  4657. Author: KennT
  4658. ---------------------------------------------------------------------------*/
  4659. STDMETHODIMP_(LPCOLESTR) InterfaceInfo::GetDeviceName()
  4660. {
  4661. RtrCriticalSection rtrCritSec(&m_critsec);
  4662. return m_cb.stDeviceName;
  4663. }
  4664. /*!--------------------------------------------------------------------------
  4665. InterfaceInfo::GetTitle
  4666. -
  4667. Author: KennT
  4668. ---------------------------------------------------------------------------*/
  4669. STDMETHODIMP_(LPCOLESTR) InterfaceInfo::GetTitle()
  4670. {
  4671. RtrCriticalSection rtrCritSec(&m_critsec);
  4672. //$UNICODE : kennt, assumes native unicode and OLECHAR==WCHAR
  4673. return m_cb.stTitle;
  4674. }
  4675. /*!--------------------------------------------------------------------------
  4676. InterfaceInfo::SetTitle
  4677. -
  4678. Author: KennT
  4679. ---------------------------------------------------------------------------*/
  4680. STDMETHODIMP InterfaceInfo::SetTitle(LPCOLESTR pszTitle)
  4681. {
  4682. RtrCriticalSection rtrCritSec(&m_critsec);
  4683. HRESULT hr = hrOK;
  4684. COM_PROTECT_TRY
  4685. {
  4686. m_cb.stTitle = pszTitle;
  4687. }
  4688. COM_PROTECT_CATCH;
  4689. return hr;
  4690. }
  4691. /*!--------------------------------------------------------------------------
  4692. InterfaceInfo::IsInterfaceEnabled
  4693. -
  4694. Author: KennT
  4695. ---------------------------------------------------------------------------*/
  4696. STDMETHODIMP_(BOOL) InterfaceInfo::IsInterfaceEnabled()
  4697. {
  4698. RtrCriticalSection rtrCritSec(&m_critsec);
  4699. return m_cb.bEnable;
  4700. }
  4701. /*!--------------------------------------------------------------------------
  4702. InterfaceInfo::SetInterfaceEnabledState
  4703. -
  4704. Author: KennT
  4705. ---------------------------------------------------------------------------*/
  4706. STDMETHODIMP InterfaceInfo::SetInterfaceEnabledState( BOOL bEnabled)
  4707. {
  4708. RtrCriticalSection rtrCritSec(&m_critsec);
  4709. m_cb.bEnable = bEnabled;
  4710. return hrOK;
  4711. }
  4712. /*!--------------------------------------------------------------------------
  4713. InterfaceInfo::CopyCB
  4714. -
  4715. Author: KennT
  4716. ---------------------------------------------------------------------------*/
  4717. STDMETHODIMP InterfaceInfo::CopyCB(InterfaceCB *pifcb)
  4718. {
  4719. RtrCriticalSection rtrCritSec(&m_critsec);
  4720. HRESULT hr = hrOK;
  4721. COM_PROTECT_TRY
  4722. {
  4723. m_cb.SaveTo(pifcb);
  4724. }
  4725. COM_PROTECT_CATCH;
  4726. return hr;
  4727. }
  4728. /*!--------------------------------------------------------------------------
  4729. InterfaceInfo::FindInterfaceTitle
  4730. -
  4731. This function retrieves the title of the given interface.
  4732. The argument 'LpszIf' should contain the ID of the interface,
  4733. for instance "EPRO1".
  4734. Author: WeiJiang
  4735. ---------------------------------------------------------------------------*/
  4736. HRESULT InterfaceInfo::FindInterfaceTitle(LPCTSTR pszMachine,
  4737. LPCTSTR pszInterface,
  4738. LPTSTR *ppszTitle)
  4739. {
  4740. HRESULT hr = hrOK;
  4741. DWORD dwErr = ERROR_SUCCESS;
  4742. HKEY hkeyMachine = NULL;
  4743. BOOL fNT4;
  4744. COM_PROTECT_TRY
  4745. {
  4746. //
  4747. // connect to the registry
  4748. //
  4749. CWRg( ConnectRegistry(pszMachine, &hkeyMachine) );
  4750. CWRg( IsNT4Machine(hkeyMachine, &fNT4) );
  4751. if (hkeyMachine)
  4752. DisconnectRegistry(hkeyMachine);
  4753. if(fNT4)
  4754. hr = RegFindInterfaceTitle(pszMachine, pszInterface, ppszTitle);
  4755. else
  4756. {
  4757. //$NT5
  4758. SPMprConfigHandle sphConfig;
  4759. LPWSTR pswz;
  4760. CString stMachineName = pszMachine;
  4761. TCHAR szDesc[1024];
  4762. if (stMachineName.IsEmpty())
  4763. pswz = NULL;
  4764. else
  4765. pswz = (LPTSTR) (LPCTSTR) stMachineName;
  4766. dwErr = ::MprConfigServerConnect(pswz,
  4767. &sphConfig);
  4768. if (dwErr == ERROR_SUCCESS)
  4769. {
  4770. dwErr = ::MprConfigGetFriendlyName(sphConfig,
  4771. (LPTSTR)pszInterface,
  4772. szDesc,
  4773. sizeof(szDesc));
  4774. if(dwErr == ERROR_SUCCESS)
  4775. *ppszTitle = StrDup((LPCTSTR) szDesc);
  4776. }
  4777. hr = HRESULT_FROM_WIN32(dwErr);
  4778. // If we can't find the title by using the Mpr APIS,
  4779. // try to access the registry directly (using the setup APIs)
  4780. // --------------------------------------------------------
  4781. if (dwErr != ERROR_SUCCESS)
  4782. {
  4783. hr = SetupFindInterfaceTitle(pswz, pszInterface,
  4784. ppszTitle);
  4785. }
  4786. }
  4787. COM_PROTECT_ERROR_LABEL;
  4788. }
  4789. COM_PROTECT_CATCH;
  4790. return hr;
  4791. }
  4792. /*!--------------------------------------------------------------------------
  4793. InterfaceInfo::GetMachineName
  4794. -
  4795. Author: KennT
  4796. ---------------------------------------------------------------------------*/
  4797. STDMETHODIMP_(LPCOLESTR) InterfaceInfo::GetMachineName()
  4798. {
  4799. RtrCriticalSection rtrCritSec(&m_critsec);
  4800. //$UNICODE : kennt, assumes native unicode and OLECHAR==WCHAR
  4801. return m_stMachine;
  4802. }
  4803. /*!--------------------------------------------------------------------------
  4804. InterfaceInfo::SetMachineName
  4805. -
  4806. Author: KennT
  4807. ---------------------------------------------------------------------------*/
  4808. STDMETHODIMP InterfaceInfo::SetMachineName(LPCOLESTR pszMachineName)
  4809. {
  4810. RtrCriticalSection rtrCritSec(&m_critsec);
  4811. HRESULT hr = hrOK;
  4812. COM_PROTECT_TRY
  4813. {
  4814. m_stMachine = pszMachineName;
  4815. }
  4816. COM_PROTECT_CATCH;
  4817. return hr;
  4818. }
  4819. /*!--------------------------------------------------------------------------
  4820. InterfaceInfo::GetParentRouterInfo
  4821. -
  4822. Author: KennT
  4823. ---------------------------------------------------------------------------*/
  4824. STDMETHODIMP InterfaceInfo::GetParentRouterInfo(IRouterInfo **ppRouterInfo)
  4825. {
  4826. RtrCriticalSection rtrCritSec(&m_critsec);
  4827. HRESULT hr = hrOK;
  4828. COM_PROTECT_TRY
  4829. {
  4830. *ppRouterInfo = m_pRouterInfoParent;
  4831. if (*ppRouterInfo)
  4832. (*ppRouterInfo)->AddRef();
  4833. }
  4834. COM_PROTECT_CATCH;
  4835. return hr;
  4836. }
  4837. /*!--------------------------------------------------------------------------
  4838. InterfaceInfo::SetParentRouterInfo
  4839. -
  4840. Author: KennT
  4841. ---------------------------------------------------------------------------*/
  4842. HRESULT InterfaceInfo::SetParentRouterInfo(IRouterInfo *pParent)
  4843. {
  4844. RtrCriticalSection rtrCritSec(&m_critsec);
  4845. IRouterInfo * pTemp;
  4846. pTemp = m_pRouterInfoParent;
  4847. m_pRouterInfoParent = NULL;
  4848. if (m_fStrongRef)
  4849. {
  4850. if (pTemp)
  4851. pTemp->Release();
  4852. if (pParent)
  4853. pParent->AddRef();
  4854. }
  4855. else
  4856. {
  4857. if (pTemp)
  4858. pTemp->ReleaseWeakRef();
  4859. if (pParent)
  4860. pParent->AddWeakRef();
  4861. }
  4862. m_pRouterInfoParent = pParent;
  4863. return hrOK;
  4864. }
  4865. /*!--------------------------------------------------------------------------
  4866. InterfaceInfo::EnumRtrMgrInterface
  4867. -
  4868. Author: KennT
  4869. ---------------------------------------------------------------------------*/
  4870. STDMETHODIMP InterfaceInfo::EnumRtrMgrInterface( IEnumRtrMgrInterfaceInfo **ppEnumRmIf)
  4871. {
  4872. RtrCriticalSection rtrCritSec(&m_critsec);
  4873. HRESULT hr = hrOK;
  4874. COM_PROTECT_TRY
  4875. {
  4876. hr = CreateEnumFromRtrMgrInterfaceList(&m_RmIfList, ppEnumRmIf);
  4877. }
  4878. COM_PROTECT_CATCH;
  4879. return hr;
  4880. }
  4881. /*!--------------------------------------------------------------------------
  4882. InterfaceInfo::AddRtrMgrInterface
  4883. -
  4884. Author: KennT
  4885. ---------------------------------------------------------------------------*/
  4886. STDMETHODIMP InterfaceInfo::AddRtrMgrInterface( IRtrMgrInterfaceInfo *pRmIf,
  4887. IInfoBase *pIfInfo)
  4888. {
  4889. Assert(pRmIf);
  4890. RtrCriticalSection rtrCritSec(&m_critsec);
  4891. HRESULT hr = hrOK;
  4892. HRESULT hrT;
  4893. SPIRtrMgrInfo spRm;
  4894. COM_PROTECT_TRY
  4895. {
  4896. //
  4897. // Fail if there is a duplicate
  4898. //
  4899. if (FHrOK(FindRtrMgrInterface(pRmIf->GetTransportId(), NULL)))
  4900. CORg( E_INVALIDARG );
  4901. //
  4902. // Save the new router-manager
  4903. //
  4904. CORg( pRmIf->Save(GetMachineName(),
  4905. m_hMachineConfig, m_hInterface, NULL, pIfInfo, 0) );
  4906. //
  4907. // Add the new router-manager structure to the list
  4908. //
  4909. m_RmIfList.AddTail(pRmIf);
  4910. pRmIf->AddWeakRef();
  4911. pRmIf->SetParentInterfaceInfo(this);
  4912. // We don't notify of a new interface since we haven't
  4913. // actually saved the interface back down to the router
  4914. if (pIfInfo)
  4915. {
  4916. m_AdviseList.NotifyChange(ROUTER_CHILD_ADD, ROUTER_OBJ_RmIf, 0);
  4917. if (m_pRouterInfoParent)
  4918. {
  4919. hrT = m_pRouterInfoParent->FindRtrMgr(pRmIf->GetTransportId(), &spRm);
  4920. if (FHrOK(hrT))
  4921. spRm->RtrNotify(ROUTER_CHILD_ADD, ROUTER_OBJ_RmIf, 0);
  4922. }
  4923. }
  4924. COM_PROTECT_ERROR_LABEL;
  4925. }
  4926. COM_PROTECT_CATCH;
  4927. return hr;
  4928. }
  4929. /*!--------------------------------------------------------------------------
  4930. InterfaceInfo::DeleteRtrMgrInterface
  4931. -
  4932. Author: KennT
  4933. ---------------------------------------------------------------------------*/
  4934. STDMETHODIMP InterfaceInfo::DeleteRtrMgrInterface(DWORD dwTransportId, BOOL fRemove)
  4935. {
  4936. RtrCriticalSection rtrCritSec(&m_critsec);
  4937. HRESULT hr = hrOK, hrT;
  4938. SPIRtrMgrInterfaceInfo spRmIf;
  4939. POSITION pos, posRmIf;
  4940. SPIRtrMgrInfo spRm;
  4941. SPIEnumRtrMgrProtocolInterfaceInfo spEnumRmProtIf;
  4942. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  4943. COM_PROTECT_TRY
  4944. {
  4945. //
  4946. // Find the router-manager to be deleted
  4947. //
  4948. pos = m_RmIfList.GetHeadPosition();
  4949. while (pos)
  4950. {
  4951. posRmIf = pos;
  4952. spRmIf.Set( m_RmIfList.GetNext(pos) );
  4953. if (spRmIf->GetTransportId() == dwTransportId)
  4954. break;
  4955. spRmIf.Release();
  4956. }
  4957. if (!spRmIf)
  4958. CORg( E_INVALIDARG );
  4959. // Delete all RtrMgrProtocolInterfaces from the router manager
  4960. spRmIf->EnumRtrMgrProtocolInterface(&spEnumRmProtIf);
  4961. while (spEnumRmProtIf->Next(1, &spRmProtIf, NULL) == hrOK)
  4962. {
  4963. DWORD dwProtocolId = spRmProtIf->GetProtocolId();
  4964. spRmProtIf.Release();
  4965. spRmIf->DeleteRtrMgrProtocolInterface(dwProtocolId, fRemove);
  4966. }
  4967. //
  4968. // Remove the router-manager from our list
  4969. //
  4970. m_RmIfList.RemoveAt(posRmIf);
  4971. spRmIf->Destruct();
  4972. spRmIf->ReleaseWeakRef();
  4973. //
  4974. // Remove the router-manager from the registry and the router
  4975. //
  4976. if (fRemove)
  4977. spRmIf->Delete(GetMachineName(), NULL, NULL);
  4978. m_AdviseList.NotifyChange(ROUTER_CHILD_DELETE, ROUTER_OBJ_RmIf, 0);
  4979. if (m_pRouterInfoParent)
  4980. {
  4981. hrT = m_pRouterInfoParent->FindRtrMgr(spRmIf->GetTransportId(), &spRm);
  4982. if (FHrOK(hrT))
  4983. spRm->RtrNotify(ROUTER_CHILD_DELETE, ROUTER_OBJ_RmIf, 0);
  4984. }
  4985. spRmIf.Release();
  4986. COM_PROTECT_ERROR_LABEL;
  4987. }
  4988. COM_PROTECT_CATCH;
  4989. return hr;
  4990. }
  4991. /*!--------------------------------------------------------------------------
  4992. InterfaceInfo::ReleaseRtrMgrInterface
  4993. This function will release the AddRef() that this object has
  4994. on the child. This allows us to transfer child objects from
  4995. one router to another.
  4996. Author: KennT
  4997. ---------------------------------------------------------------------------*/
  4998. STDMETHODIMP InterfaceInfo::ReleaseRtrMgrInterface( DWORD dwTransportId )
  4999. {
  5000. HRESULT hr = hrOK;
  5001. POSITION pos, posRmIf;
  5002. SPIRtrMgrInterfaceInfo spRmIf;
  5003. COM_PROTECT_TRY
  5004. {
  5005. pos = m_RmIfList.GetHeadPosition();
  5006. while (pos)
  5007. {
  5008. // Save the position (so that we can delete it)
  5009. posRmIf = pos;
  5010. spRmIf.Set( m_RmIfList.GetNext(pos) );
  5011. if (spRmIf &&
  5012. (spRmIf->GetTransportId() == dwTransportId))
  5013. {
  5014. // When releasing, we need to disconnect (since the
  5015. // main handle is controlled by the router info).
  5016. spRmIf->DoDisconnect();
  5017. spRmIf->ReleaseWeakRef();
  5018. spRmIf.Release();
  5019. // release this node from the list
  5020. m_RmIfList.RemoveAt(posRmIf);
  5021. break;
  5022. }
  5023. spRmIf.Release();
  5024. }
  5025. }
  5026. COM_PROTECT_CATCH;
  5027. return hr;
  5028. }
  5029. /*!--------------------------------------------------------------------------
  5030. InterfaceInfo::FindRtrMgrInterface
  5031. S_OK is returned if a RtrMgrInfo is found.
  5032. S_FALSE is returned if a RtrMgrInfo was NOT found.
  5033. error codes returned otherwise.
  5034. Author: KennT
  5035. ---------------------------------------------------------------------------*/
  5036. STDMETHODIMP InterfaceInfo::FindRtrMgrInterface( DWORD dwTransportId,
  5037. IRtrMgrInterfaceInfo **ppInfo)
  5038. {
  5039. RtrCriticalSection rtrCritSec(&m_critsec);
  5040. HRESULT hr = hrFalse;
  5041. POSITION pos;
  5042. SPIRtrMgrInterfaceInfo spRmIf;
  5043. COM_PROTECT_TRY
  5044. {
  5045. if (ppInfo)
  5046. *ppInfo = NULL;
  5047. pos = m_RmIfList.GetHeadPosition();
  5048. while (pos)
  5049. {
  5050. spRmIf.Set( m_RmIfList.GetNext(pos) );
  5051. if (spRmIf->GetTransportId() == dwTransportId)
  5052. {
  5053. hr = hrOK;
  5054. if (ppInfo)
  5055. *ppInfo = spRmIf.Transfer();
  5056. break;
  5057. }
  5058. }
  5059. }
  5060. COM_PROTECT_CATCH;
  5061. return hr;
  5062. }
  5063. /*!--------------------------------------------------------------------------
  5064. InterfaceInfo::RtrAdvise
  5065. -
  5066. Author: KennT
  5067. ---------------------------------------------------------------------------*/
  5068. STDMETHODIMP InterfaceInfo::RtrAdvise( IRtrAdviseSink *pRtrAdviseSink,
  5069. LONG_PTR *pulConnection, LPARAM lUserParam)
  5070. {
  5071. Assert(pRtrAdviseSink);
  5072. Assert(pulConnection);
  5073. RtrCriticalSection rtrCritSec(&m_critsec);
  5074. LONG_PTR ulConnId;
  5075. HRESULT hr = hrOK;
  5076. COM_PROTECT_TRY
  5077. {
  5078. ulConnId = (LONG_PTR) InterlockedIncrement(&s_cConnections);
  5079. CORg( m_AdviseList.AddConnection(pRtrAdviseSink, ulConnId, lUserParam) );
  5080. *pulConnection = ulConnId;
  5081. COM_PROTECT_ERROR_LABEL;
  5082. }
  5083. COM_PROTECT_CATCH;
  5084. return hr;
  5085. }
  5086. /*!--------------------------------------------------------------------------
  5087. InterfaceInfo::RtrNotify
  5088. -
  5089. Author: KennT
  5090. ---------------------------------------------------------------------------*/
  5091. STDMETHODIMP InterfaceInfo::RtrNotify(DWORD dwChangeType, DWORD dwObjectType,
  5092. LPARAM lParam)
  5093. {
  5094. RtrCriticalSection rtrCritSec(&m_critsec);
  5095. HRESULT hr = hrOK;
  5096. COM_PROTECT_TRY
  5097. {
  5098. m_AdviseList.NotifyChange(dwChangeType, dwObjectType, lParam);
  5099. }
  5100. COM_PROTECT_CATCH;
  5101. return hr;
  5102. }
  5103. /*!--------------------------------------------------------------------------
  5104. InterfaceInfo::RtrUnadvise
  5105. -
  5106. Author: KennT
  5107. ---------------------------------------------------------------------------*/
  5108. STDMETHODIMP InterfaceInfo::RtrUnadvise( LONG_PTR ulConnection)
  5109. {
  5110. RtrCriticalSection rtrCritSec(&m_critsec);
  5111. return m_AdviseList.RemoveConnection(ulConnection);
  5112. }
  5113. /*!--------------------------------------------------------------------------
  5114. InterfaceInfo::LoadRtrMgrInterfaceList
  5115. -
  5116. Author: KennT
  5117. ---------------------------------------------------------------------------*/
  5118. HRESULT InterfaceInfo::LoadRtrMgrInterfaceList()
  5119. {
  5120. RtrCriticalSection rtrCritSec(&m_critsec);
  5121. BOOL bAdd;
  5122. LPBYTE pItemTable = NULL;
  5123. SPIRtrMgrInterfaceInfo spRmIf;
  5124. DWORD dwErr, i, dwEntries, dwTotal;
  5125. HRESULT hr = hrOK;
  5126. MPR_IFTRANSPORT_0 *piftransport;
  5127. TCHAR szTransport[MAX_TRANSPORT_NAME_LEN+1];
  5128. USES_CONVERSION;
  5129. //
  5130. // Now enumerate the transports on this interface
  5131. //
  5132. dwErr = ::MprConfigInterfaceTransportEnum(
  5133. m_hMachineConfig,
  5134. m_hInterface,
  5135. 0,
  5136. &pItemTable,
  5137. (DWORD)-1,
  5138. &dwEntries,
  5139. &dwTotal,
  5140. NULL
  5141. );
  5142. if (dwErr != NO_ERROR && dwErr != ERROR_NO_MORE_ITEMS)
  5143. CWRg( dwErr );
  5144. //
  5145. // Construct a CRmInterfaceInfo for each transport enumerated
  5146. //
  5147. for (i = 0, piftransport = (MPR_IFTRANSPORT_0*)pItemTable;
  5148. i < dwEntries;
  5149. i++, piftransport++)
  5150. {
  5151. #if (WINVER >= 0x0501)
  5152. if (piftransport->dwTransportId == PID_IPX) {continue;}
  5153. #endif
  5154. FindRtrMgrInterface(piftransport->dwTransportId, &spRmIf);
  5155. if (spRmIf)
  5156. bAdd = FALSE;
  5157. else
  5158. {
  5159. bAdd = TRUE;
  5160. StrCpyTFromW(szTransport, piftransport->wszIfTransportName);
  5161. //
  5162. // Construct a CRmInterfaceInfo object for this transport
  5163. //
  5164. spRmIf = new RtrMgrInterfaceInfo(piftransport->dwTransportId,
  5165. szTransport,
  5166. OLE2CT(GetId()),
  5167. GetInterfaceType(),
  5168. this);
  5169. spRmIf->SetFlags(RouterSnapin_InSyncWithRouter);
  5170. }
  5171. //
  5172. // Load the information for this CRmInterfaceInfo,
  5173. // indicating to it that it should load its list of protocols.
  5174. //
  5175. hr = spRmIf->Load(GetMachineName(), m_hMachineConfig, m_hInterface,
  5176. piftransport->hIfTransport );
  5177. if (!FHrSucceeded(hr))
  5178. {
  5179. spRmIf->Destruct();
  5180. spRmIf.Release();
  5181. continue;
  5182. }
  5183. //
  5184. // Add the router-manager interface to our list
  5185. //
  5186. if (bAdd)
  5187. {
  5188. m_RmIfList.AddTail(spRmIf);
  5189. CONVERT_TO_WEAKREF(spRmIf);
  5190. spRmIf.Transfer();
  5191. }
  5192. }
  5193. Error:
  5194. if (pItemTable)
  5195. ::MprConfigBufferFree(pItemTable);
  5196. return hr;
  5197. }
  5198. /*!--------------------------------------------------------------------------
  5199. InterfaceInfo::TryToConnect
  5200. -
  5201. Author: KennT
  5202. ---------------------------------------------------------------------------*/
  5203. HRESULT InterfaceInfo::TryToConnect(LPCWSTR pswzMachine, HANDLE *phMachine)
  5204. {
  5205. RtrCriticalSection rtrCritSec(&m_critsec);
  5206. HRESULT hr = hrOK;
  5207. if (m_hMachineConfig)
  5208. *phMachine = m_hMachineConfig;
  5209. else if (*phMachine)
  5210. {
  5211. m_hMachineConfig = *phMachine;
  5212. m_bDisconnect = FALSE;
  5213. }
  5214. else
  5215. {
  5216. //$ Review: kennt, this function does not take a LPCWSTR,
  5217. // is this a mistake or does it modify the parameters?
  5218. CWRg( ::MprConfigServerConnect((LPWSTR) pswzMachine, phMachine) );
  5219. m_hMachineConfig = *phMachine;
  5220. m_bDisconnect = TRUE;
  5221. }
  5222. Error:
  5223. return hr;
  5224. }
  5225. /*!--------------------------------------------------------------------------
  5226. InterfaceInfo::TryToGetIfHandle
  5227. -
  5228. Author: KennT
  5229. ---------------------------------------------------------------------------*/
  5230. HRESULT InterfaceInfo::TryToGetIfHandle(HANDLE hMachine,
  5231. LPCWSTR pswzInterface,
  5232. HANDLE *phInterface)
  5233. {
  5234. RtrCriticalSection rtrCritSec(&m_critsec);
  5235. HRESULT hr = hrOK;
  5236. if (m_hInterface)
  5237. *phInterface = m_hInterface;
  5238. else if (*phInterface)
  5239. m_hInterface = *phInterface;
  5240. else
  5241. {
  5242. //
  5243. // Get a handle to the interface
  5244. //
  5245. CWRg(::MprConfigInterfaceGetHandle(hMachine,
  5246. (LPWSTR) pswzInterface,
  5247. phInterface
  5248. ) );
  5249. m_hInterface = *phInterface;
  5250. }
  5251. Error:
  5252. return hr;
  5253. }
  5254. /*!--------------------------------------------------------------------------
  5255. InterfaceInfo::Disconnect
  5256. -
  5257. Author: KennT
  5258. ---------------------------------------------------------------------------*/
  5259. void InterfaceInfo::Disconnect()
  5260. {
  5261. if (m_bDisconnect && m_hMachineConfig)
  5262. ::MprConfigServerDisconnect(m_hMachineConfig);
  5263. m_bDisconnect = FALSE;
  5264. m_hMachineConfig = NULL;
  5265. m_hInterface = NULL;
  5266. }
  5267. /*!--------------------------------------------------------------------------
  5268. InterfaceInfo::DoDisconnect
  5269. -
  5270. Author: KennT
  5271. ---------------------------------------------------------------------------*/
  5272. STDMETHODIMP InterfaceInfo::DoDisconnect()
  5273. {
  5274. HRESULT hr = hrOK;
  5275. SPIEnumRtrMgrInterfaceInfo spEnumRmIf;
  5276. SPIRtrMgrInterfaceInfo spRmIf;
  5277. COM_PROTECT_TRY
  5278. {
  5279. // Disconnect our data.
  5280. // ------------------------------------------------------------
  5281. Disconnect();
  5282. // Notify the advise sinks of a disconnect.
  5283. // ------------------------------------------------------------
  5284. RtrNotify(ROUTER_DO_DISCONNECT, 0, 0);
  5285. // Now tell all child objects to disconnect.
  5286. // ------------------------------------------------------------
  5287. HRESULT hrIter = hrOK;
  5288. EnumRtrMgrInterface(&spEnumRmIf);
  5289. spEnumRmIf->Reset();
  5290. while (spEnumRmIf->Next(1, &spRmIf, NULL) == hrOK)
  5291. {
  5292. spRmIf->DoDisconnect();
  5293. spRmIf.Release();
  5294. }
  5295. }
  5296. COM_PROTECT_CATCH;
  5297. return hr;
  5298. }
  5299. /*---------------------------------------------------------------------------
  5300. IRtrMgrInterfaceInfo Implementation
  5301. ---------------------------------------------------------------------------*/
  5302. TFSCORE_API(HRESULT) CreateRtrMgrInterfaceInfo(IRtrMgrInterfaceInfo **ppRmIf,
  5303. LPCWSTR pszId,
  5304. DWORD dwTransportId,
  5305. LPCWSTR pswzInterfaceId,
  5306. DWORD dwIfType)
  5307. {
  5308. Assert(ppRmIf);
  5309. HRESULT hr = hrOK;
  5310. IRtrMgrInterfaceInfo * pRmIf = NULL;
  5311. USES_CONVERSION;
  5312. COM_PROTECT_TRY
  5313. {
  5314. pRmIf = new RtrMgrInterfaceInfo(dwTransportId,
  5315. W2CT(pszId),
  5316. W2CT(pswzInterfaceId),
  5317. dwIfType,
  5318. NULL);
  5319. *ppRmIf = pRmIf;
  5320. }
  5321. COM_PROTECT_CATCH;
  5322. return hr;
  5323. }
  5324. IMPLEMENT_WEAKREF_ADDREF_RELEASE(RtrMgrInterfaceInfo)
  5325. IMPLEMENT_SIMPLE_QUERYINTERFACE(RtrMgrInterfaceInfo, IRtrMgrInterfaceInfo)
  5326. DEBUG_DECLARE_INSTANCE_COUNTER(RtrMgrInterfaceInfo)
  5327. RtrMgrInterfaceInfo::RtrMgrInterfaceInfo(DWORD dwTransportId,
  5328. LPCTSTR pszId,
  5329. LPCTSTR pszIfId,
  5330. DWORD dwIfType,
  5331. InterfaceInfo *pInterfaceInfo)
  5332. : m_hMachineConfig(NULL),
  5333. m_hInterface(NULL),
  5334. m_hIfTransport(NULL),
  5335. m_bDisconnect(FALSE),
  5336. m_dwFlags(0)
  5337. {
  5338. m_cb.dwTransportId = dwTransportId;
  5339. m_cb.stId = pszId;
  5340. m_cb.stInterfaceId = pszIfId;
  5341. m_cb.dwIfType = dwIfType;
  5342. DEBUG_INCREMENT_INSTANCE_COUNTER(RtrMgrInterfaceInfo);
  5343. m_pInterfaceInfoParent = pInterfaceInfo;
  5344. if (m_pInterfaceInfoParent)
  5345. m_pInterfaceInfoParent->AddRef();
  5346. InitializeCriticalSection(&m_critsec);
  5347. }
  5348. RtrMgrInterfaceInfo::~RtrMgrInterfaceInfo()
  5349. {
  5350. Assert(m_pInterfaceInfoParent == NULL);
  5351. Destruct();
  5352. DEBUG_DECREMENT_INSTANCE_COUNTER(RtrMgrInterfaceInfo);
  5353. DeleteCriticalSection(&m_critsec);
  5354. }
  5355. void RtrMgrInterfaceInfo::ReviveStrongRef()
  5356. {
  5357. RtrCriticalSection rtrCritSec(&m_critsec);
  5358. if (m_pInterfaceInfoParent)
  5359. {
  5360. CONVERT_TO_STRONGREF(m_pInterfaceInfoParent);
  5361. }
  5362. }
  5363. void RtrMgrInterfaceInfo::OnLastStrongRef()
  5364. {
  5365. RtrCriticalSection rtrCritSec(&m_critsec);
  5366. if (m_pInterfaceInfoParent)
  5367. {
  5368. CONVERT_TO_WEAKREF(m_pInterfaceInfoParent);
  5369. }
  5370. if (m_fDestruct)
  5371. Destruct();
  5372. }
  5373. STDMETHODIMP RtrMgrInterfaceInfo::Destruct()
  5374. {
  5375. RtrCriticalSection rtrCritSec(&m_critsec);
  5376. IInterfaceInfo * pParent;
  5377. m_fDestruct = TRUE;
  5378. if (!m_fStrongRef)
  5379. {
  5380. pParent = m_pInterfaceInfoParent;
  5381. m_pInterfaceInfoParent = NULL;
  5382. if (pParent)
  5383. pParent->ReleaseWeakRef();
  5384. Unload();
  5385. }
  5386. return hrOK;
  5387. }
  5388. STDMETHODIMP_(DWORD) RtrMgrInterfaceInfo::GetFlags()
  5389. {
  5390. RtrCriticalSection rtrCritSec(&m_critsec);
  5391. return m_dwFlags;
  5392. }
  5393. STDMETHODIMP RtrMgrInterfaceInfo::SetFlags(DWORD dwFlags)
  5394. {
  5395. RtrCriticalSection rtrCritSec(&m_critsec);
  5396. HRESULT hr = hrOK;
  5397. COM_PROTECT_TRY
  5398. {
  5399. m_dwFlags = dwFlags;
  5400. }
  5401. COM_PROTECT_CATCH;
  5402. return hr;
  5403. }
  5404. /*!--------------------------------------------------------------------------
  5405. RtrMgrInterfaceInfo::Load
  5406. -
  5407. Author: KennT
  5408. ---------------------------------------------------------------------------*/
  5409. STDMETHODIMP RtrMgrInterfaceInfo::Load(LPCOLESTR pszMachine,
  5410. HANDLE hMachine,
  5411. HANDLE hInterface,
  5412. HANDLE hIfTransport)
  5413. {
  5414. RtrCriticalSection rtrCritSec(&m_critsec);
  5415. HRESULT hr = hrOK;
  5416. DWORD dwErr;
  5417. DWORD dwSize = 0;
  5418. MPR_INTERFACE_0 *pinterface = NULL;
  5419. SPIInterfaceInfo spIf;
  5420. SPIRouterInfo spRouter;
  5421. SPIEnumInterfaceCB spEnumIfCB;
  5422. InterfaceCB ifCB;
  5423. SPSZ spsz;
  5424. COM_PROTECT_TRY
  5425. {
  5426. //
  5427. // Discard any information already loaded
  5428. //
  5429. Unload();
  5430. m_stMachine = (pszMachine ? pszMachine : TEXT(""));
  5431. //
  5432. // If 'hMachine' was not specified, connect to the config
  5433. // on the specified machine
  5434. //
  5435. Assert(m_hMachineConfig == NULL);
  5436. CORg( TryToGetAllHandles(T2CW((LPTSTR)(LPCTSTR) m_stMachine),
  5437. &hMachine, &hInterface, &hIfTransport) );
  5438. //
  5439. // Get information about the interface
  5440. //
  5441. CWRg(::MprConfigInterfaceGetInfo(
  5442. hMachine,
  5443. hInterface,
  5444. 0,
  5445. (LPBYTE*)&pinterface,
  5446. &dwSize
  5447. ) );
  5448. //
  5449. // Save the interface type
  5450. //
  5451. m_cb.dwIfType = (DWORD)pinterface->dwIfType;
  5452. //
  5453. // If this isn't a LAN card, the interface-ID is the title;
  5454. // otherwise, retrieve the title from the Software key
  5455. //
  5456. if (GetInterfaceType() != (DWORD)ROUTER_IF_TYPE_DEDICATED)
  5457. {
  5458. m_cb.stTitle = OLE2CT(GetInterfaceId());
  5459. }
  5460. else
  5461. {
  5462. // Can we get to the router info object?
  5463. if (m_pInterfaceInfoParent)
  5464. m_pInterfaceInfoParent->GetParentRouterInfo(&spRouter);
  5465. if (spRouter)
  5466. {
  5467. //
  5468. // This object is contained in a 'CRouterInfo',
  5469. // which will have already loaded the LAN interface
  5470. // control-blocks search through that list to find our title,
  5471. //
  5472. BOOL bFound = FALSE;
  5473. CORg( spRouter->EnumInterfaceCB(&spEnumIfCB) );
  5474. spEnumIfCB->Reset();
  5475. while (spEnumIfCB->Next(1, &ifCB, NULL) == hrOK)
  5476. {
  5477. if (StriCmpW(ifCB.szId, GetInterfaceId()) == 0)
  5478. {
  5479. m_cb.stTitle = OLE2CT(ifCB.szId);
  5480. bFound = TRUE;
  5481. break;
  5482. }
  5483. }
  5484. if (!bFound)
  5485. {
  5486. hr = InterfaceInfo::FindInterfaceTitle(OLE2CT(GetMachineName()),
  5487. OLE2CT(GetInterfaceId()),
  5488. &spsz);
  5489. if (FHrOK(hr))
  5490. m_cb.stTitle = spsz;
  5491. else
  5492. m_cb.stTitle = OLE2CT(GetInterfaceId());
  5493. hr = hrOK;
  5494. }
  5495. }
  5496. else
  5497. {
  5498. //
  5499. // Read the title directly from the registry
  5500. //
  5501. hr = InterfaceInfo::FindInterfaceTitle(OLE2CT(GetMachineName()),
  5502. OLE2CT(GetInterfaceId()),
  5503. &spsz);
  5504. if (FHrOK(hr))
  5505. m_cb.stTitle = spsz;
  5506. else
  5507. m_cb.stTitle = OLE2CT(GetInterfaceId());
  5508. hr = hrOK;
  5509. }
  5510. }
  5511. //
  5512. // Load the list of routing-protocols active on this interface
  5513. //
  5514. CORg( LoadRtrMgrInterfaceInfo(hMachine, hInterface, hIfTransport) );
  5515. COM_PROTECT_ERROR_LABEL;
  5516. }
  5517. COM_PROTECT_CATCH;
  5518. if (pinterface)
  5519. ::MprConfigBufferFree(pinterface);
  5520. return hr;
  5521. }
  5522. /*!--------------------------------------------------------------------------
  5523. RtrMgrInterfaceInfo::Save
  5524. -
  5525. Author: KennT
  5526. ---------------------------------------------------------------------------*/
  5527. STDMETHODIMP RtrMgrInterfaceInfo::Save(
  5528. LPCOLESTR pszMachine,
  5529. HANDLE hMachine,
  5530. HANDLE hInterface,
  5531. HANDLE hIfTransport,
  5532. IInfoBase* pInterfaceInfo,
  5533. DWORD dwDeleteProtocolId)
  5534. {
  5535. RtrCriticalSection rtrCritSec(&m_critsec);
  5536. HRESULT hr = hrOK;
  5537. DWORD dwErr;
  5538. COM_PROTECT_TRY
  5539. {
  5540. //$ OPT : We reuse the handles (if they exist), so why
  5541. // do we pass in the machine name? What we should do is
  5542. // to release all the handles first.
  5543. Assert(m_stMachine.CompareNoCase(pszMachine) == 0);
  5544. hr = TryToGetAllHandles(pszMachine,
  5545. &hMachine,
  5546. &hInterface,
  5547. &hIfTransport);
  5548. if (!FHrSucceeded(hr) && (hIfTransport == NULL))
  5549. {
  5550. dwErr = ::MprConfigInterfaceTransportGetHandle(hMachine,
  5551. hInterface, GetTransportId(), &hIfTransport);
  5552. if (dwErr != NO_ERROR)
  5553. {
  5554. //
  5555. // We couldn't connect so try creating the interface-transport;
  5556. // First convert the transport-name to Unicode
  5557. //
  5558. WCHAR wszTransport[MAX_TRANSPORT_NAME_LEN+1];
  5559. StrCpyWFromT(wszTransport, m_cb.stId);
  5560. //
  5561. // Create the interface-transport
  5562. //
  5563. CWRg( ::MprConfigInterfaceTransportAdd(hMachine, hInterface,
  5564. GetTransportId(), wszTransport,
  5565. NULL, 0, &hIfTransport) );
  5566. }
  5567. m_hIfTransport = hIfTransport;
  5568. }
  5569. //
  5570. // Update the registry and our infobase with the current information
  5571. //
  5572. CORg( SaveRtrMgrInterfaceInfo(
  5573. hMachine, hInterface, hIfTransport, pInterfaceInfo,
  5574. dwDeleteProtocolId
  5575. ) );
  5576. COM_PROTECT_ERROR_LABEL;
  5577. }
  5578. COM_PROTECT_CATCH;
  5579. return hr;
  5580. }
  5581. /*!--------------------------------------------------------------------------
  5582. RtrMgrInterfaceInfo::Unload
  5583. -
  5584. Author: KennT
  5585. ---------------------------------------------------------------------------*/
  5586. STDMETHODIMP RtrMgrInterfaceInfo::Unload( )
  5587. {
  5588. RtrCriticalSection rtrCritSec(&m_critsec);
  5589. HRESULT hr = hrOK;
  5590. IRtrMgrProtocolInterfaceInfo * pRmProtIf;
  5591. COM_PROTECT_TRY
  5592. {
  5593. while (!m_RmProtIfList.IsEmpty())
  5594. {
  5595. pRmProtIf = m_RmProtIfList.RemoveHead();
  5596. pRmProtIf->Destruct();
  5597. pRmProtIf->ReleaseWeakRef();
  5598. }
  5599. DoDisconnect();
  5600. }
  5601. COM_PROTECT_CATCH;
  5602. return hr;
  5603. }
  5604. /*!--------------------------------------------------------------------------
  5605. RtrMgrInterfaceInfo::Delete
  5606. -
  5607. Author: KennT
  5608. ---------------------------------------------------------------------------*/
  5609. STDMETHODIMP RtrMgrInterfaceInfo::Delete(LPCOLESTR pszMachine,
  5610. HANDLE hMachine,
  5611. HANDLE hInterface)
  5612. {
  5613. RtrCriticalSection rtrCritSec(&m_critsec);
  5614. MPR_SERVER_HANDLE hrouter = NULL;
  5615. HRESULT hr = hrOK;
  5616. DWORD dwErr;
  5617. HANDLE hIfTransport = NULL;
  5618. WCHAR wszInterface[MAX_INTERFACE_NAME_LEN+1];
  5619. USES_CONVERSION;
  5620. COM_PROTECT_TRY
  5621. {
  5622. //
  5623. //$ OPT, kennt : why is the machine name passed in here?
  5624. //
  5625. CORg( TryToGetAllHandles(pszMachine,
  5626. &hMachine,
  5627. &hInterface,
  5628. NULL) );
  5629. do
  5630. {
  5631. //
  5632. // Get a handle to the interface-transport
  5633. //
  5634. dwErr = ::MprConfigInterfaceTransportGetHandle(
  5635. hMachine,
  5636. hInterface,
  5637. GetTransportId(),
  5638. &hIfTransport
  5639. );
  5640. if (dwErr == NO_ERROR)
  5641. {
  5642. //
  5643. // Remove the interface-transport
  5644. //
  5645. dwErr = ::MprConfigInterfaceTransportRemove(
  5646. hMachine,
  5647. hInterface,
  5648. hIfTransport
  5649. );
  5650. }
  5651. m_hIfTransport = NULL;
  5652. } while(FALSE);
  5653. //
  5654. // Now remove the router-manager from the interface
  5655. // with the currently running router
  5656. //
  5657. if (ConnectRouter(OLE2CT(pszMachine), (HANDLE*)&hrouter) == NO_ERROR)
  5658. {
  5659. //
  5660. // Convert ID into Unicode
  5661. //
  5662. StrnCpyWFromOle(wszInterface, GetInterfaceId(),
  5663. DimensionOf(wszInterface));
  5664. //
  5665. // The router is running; if the interface exists, remove it
  5666. //
  5667. dwErr = ::MprAdminInterfaceGetHandle(
  5668. hrouter,
  5669. wszInterface,
  5670. &hInterface,
  5671. FALSE
  5672. );
  5673. if (dwErr == NO_ERROR)
  5674. {
  5675. //
  5676. // Remove the interface-transport
  5677. //
  5678. dwErr = ::MprAdminInterfaceTransportRemove(
  5679. hrouter,
  5680. hInterface,
  5681. GetTransportId()
  5682. );
  5683. }
  5684. ::MprAdminServerDisconnect(hrouter);
  5685. if ((dwErr == RPC_S_SERVER_UNAVAILABLE) ||
  5686. (dwErr == RPC_S_UNKNOWN_IF))
  5687. dwErr = NO_ERROR;
  5688. CWRg( dwErr );
  5689. }
  5690. COM_PROTECT_ERROR_LABEL;
  5691. }
  5692. COM_PROTECT_CATCH;
  5693. return hr;
  5694. }
  5695. /*!--------------------------------------------------------------------------
  5696. RtrMgrInterfaceInfo::Merge
  5697. -
  5698. Author: KennT
  5699. ---------------------------------------------------------------------------*/
  5700. STDMETHODIMP RtrMgrInterfaceInfo::Merge(IRtrMgrInterfaceInfo *pNewRmIf)
  5701. {
  5702. RtrCriticalSection rtrCritSec(&m_critsec);
  5703. SPIEnumRtrMgrProtocolInterfaceInfo spEnumRmProtIf;
  5704. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  5705. HRESULT hr = hrOK;
  5706. CDWordArray oldDWArray;
  5707. CDWordArray newDWArray;
  5708. int cOld, cNew;
  5709. int i, j;
  5710. DWORD dwTemp;
  5711. RtrMgrInterfaceCB rmIfCB;
  5712. Assert(pNewRmIf);
  5713. Assert(pNewRmIf->GetTransportId() == GetTransportId());
  5714. Assert(lstrcmpi(pNewRmIf->GetId(), GetId()) == 0);
  5715. COM_PROTECT_TRY
  5716. {
  5717. // Need to sync up RtrMgrInterfaceInfo
  5718. pNewRmIf->CopyCB(&rmIfCB);
  5719. m_cb.LoadFrom(&rmIfCB);
  5720. //
  5721. // The general algorithm is to build up two arrays
  5722. // the first array contains the protocol ids for this object
  5723. // the second array contains the ids for the new object
  5724. //
  5725. // We then go through and remove all protocols that are in
  5726. // BOTH lists.
  5727. //
  5728. // This will leave us with the first array containing the
  5729. // ids of the protocols that need to be deleted from this object.
  5730. //
  5731. // The second array will have the list of ids of protocols that
  5732. // have to be added to this object from the second object.
  5733. //
  5734. // Get the list of protocols that are in the new object
  5735. CORg( pNewRmIf->EnumRtrMgrProtocolInterface(&spEnumRmProtIf) );
  5736. spEnumRmProtIf->Reset();
  5737. while (spEnumRmProtIf->Next(1, &spRmProtIf, NULL) == hrOK)
  5738. {
  5739. newDWArray.Add(spRmProtIf->GetProtocolId());
  5740. spRmProtIf.Release();
  5741. }
  5742. spEnumRmProtIf.Release();
  5743. spRmProtIf.Release();
  5744. // Get the list of protocols that are in this object
  5745. CORg( this->EnumRtrMgrProtocolInterface(&spEnumRmProtIf) );
  5746. spEnumRmProtIf->Reset();
  5747. while (spEnumRmProtIf->Next(1, &spRmProtIf, NULL) == hrOK)
  5748. {
  5749. oldDWArray.Add(spRmProtIf->GetProtocolId());
  5750. spRmProtIf.Release();
  5751. }
  5752. spEnumRmProtIf.Release();
  5753. spRmProtIf.Release();
  5754. // Ok now go through both lists, removing from the lists
  5755. // protocols that are in both lists.
  5756. cOld = oldDWArray.GetSize();
  5757. cNew = newDWArray.GetSize();
  5758. for (i=cOld; --i>=0; )
  5759. {
  5760. dwTemp = oldDWArray.GetAt(i);
  5761. for (j=cNew; --j>=0; )
  5762. {
  5763. if (dwTemp == newDWArray.GetAt(j))
  5764. {
  5765. // remove both instances
  5766. newDWArray.RemoveAt(j);
  5767. oldDWArray.RemoveAt(i);
  5768. // Need to update the size of the new array
  5769. cNew--;
  5770. break;
  5771. }
  5772. }
  5773. }
  5774. // oldDWArray now contains the protocols that should be
  5775. // removed.
  5776. if (oldDWArray.GetSize())
  5777. {
  5778. for (i=oldDWArray.GetSize(); --i>=0; )
  5779. {
  5780. // Windows NT Bug: 132993, we need to make sure that
  5781. // we don't delete the local interfaces
  5782. SPIRtrMgrProtocolInterfaceInfo spRmProtIfTemp;
  5783. FindRtrMgrProtocolInterface(oldDWArray.GetAt(i),
  5784. &spRmProtIfTemp);
  5785. Assert(spRmProtIfTemp);
  5786. if (spRmProtIfTemp->GetFlags() & RouterSnapin_InSyncWithRouter)
  5787. DeleteRtrMgrProtocolInterface(oldDWArray.GetAt(i), FALSE);
  5788. }
  5789. }
  5790. // newDWArray contains the protocols that should be added
  5791. if (newDWArray.GetSize())
  5792. {
  5793. for (i=newDWArray.GetSize(); --i>= 0; )
  5794. {
  5795. hr = pNewRmIf->FindRtrMgrProtocolInterface(
  5796. newDWArray.GetAt(i), &spRmProtIf);
  5797. Assert(hr == hrOK);
  5798. if (spRmProtIf)
  5799. {
  5800. AddRtrMgrProtocolInterface(spRmProtIf, NULL);
  5801. // Remove this rmprotif from its old RMinterface
  5802. // ------------------------------------------------
  5803. pNewRmIf->ReleaseRtrMgrProtocolInterface(
  5804. spRmProtIf->GetProtocolId());
  5805. }
  5806. spRmProtIf.Release();
  5807. }
  5808. }
  5809. COM_PROTECT_ERROR_LABEL;
  5810. }
  5811. COM_PROTECT_CATCH;
  5812. return hr;
  5813. }
  5814. /*!--------------------------------------------------------------------------
  5815. RtrMgrInterfaceInfo::SetInfo
  5816. -
  5817. This function updates the information in use by the router-manager
  5818. if it is currently running.
  5819. Author: KennT
  5820. ---------------------------------------------------------------------------*/
  5821. STDMETHODIMP RtrMgrInterfaceInfo::SetInfo(DWORD dwIfInfoSize,
  5822. PBYTE pInterfaceInfoData)
  5823. {
  5824. RtrCriticalSection rtrCritSec(&m_critsec);
  5825. HRESULT hr = hrOK;
  5826. DWORD dwErr;
  5827. MPR_SERVER_HANDLE hrouter = NULL;
  5828. HANDLE hinterface = NULL;
  5829. COM_PROTECT_TRY
  5830. {
  5831. //
  5832. // Connect to the router
  5833. //
  5834. CWRg( ConnectRouter(OLE2CT(GetMachineName()), (HANDLE*)&hrouter) );
  5835. do {
  5836. //
  5837. // Get the handle to the interface
  5838. //
  5839. WCHAR wszInterface[MAX_INTERFACE_NAME_LEN+1];
  5840. StrCpyWFromT(wszInterface, GetInterfaceId());
  5841. dwErr = ::MprAdminInterfaceGetHandle(
  5842. hrouter,
  5843. wszInterface,
  5844. &hinterface,
  5845. FALSE
  5846. );
  5847. if (dwErr != NO_ERROR) { hinterface = NULL; break; }
  5848. //
  5849. // Set the new info for the router-manager
  5850. //
  5851. dwErr = ::MprAdminInterfaceTransportSetInfo(
  5852. hrouter,
  5853. hinterface,
  5854. m_cb.dwTransportId,
  5855. pInterfaceInfoData,
  5856. dwIfInfoSize
  5857. );
  5858. //
  5859. // If that failed, we assume that the router-manager
  5860. // has not been added, and we attempt an add;
  5861. // otherwise, we set the new information
  5862. //
  5863. if (dwErr != NO_ERROR && dwErr != RPC_S_SERVER_UNAVAILABLE)
  5864. {
  5865. //
  5866. // Attempt to add the router-manager on the interface
  5867. //
  5868. DWORD dwErr1 = ::MprAdminInterfaceTransportAdd(
  5869. hrouter,
  5870. hinterface,
  5871. m_cb.dwTransportId,
  5872. pInterfaceInfoData,
  5873. dwIfInfoSize
  5874. );
  5875. if (dwErr1 == NO_ERROR)
  5876. dwErr = dwErr1;
  5877. }
  5878. } while (FALSE);
  5879. if ((dwErr == RPC_S_SERVER_UNAVAILABLE) ||
  5880. (dwErr == RPC_S_UNKNOWN_IF))
  5881. dwErr = NO_ERROR;
  5882. CWRg(dwErr);
  5883. COM_PROTECT_ERROR_LABEL;
  5884. }
  5885. COM_PROTECT_CATCH;
  5886. // If we fail to contact the server, then we will get these
  5887. // errors. The most common occurrence is that the router is
  5888. // not running.
  5889. if ((hr == HResultFromWin32(RPC_S_SERVER_UNAVAILABLE)) ||
  5890. (hr == HResultFromWin32(RPC_S_UNKNOWN_IF)))
  5891. hr = hrOK;
  5892. if (hrouter)
  5893. ::MprAdminServerDisconnect(hrouter);
  5894. return hr;
  5895. }
  5896. /*!--------------------------------------------------------------------------
  5897. RtrMgrInterfaceInfo::SetInfoBase
  5898. -
  5899. Author: KennT
  5900. ---------------------------------------------------------------------------*/
  5901. STDMETHODIMP RtrMgrInterfaceInfo::SetInfoBase(HANDLE hMachine,
  5902. HANDLE hInterface,
  5903. HANDLE hIfTransport,
  5904. IInfoBase *pInfoBase)
  5905. {
  5906. RtrCriticalSection rtrCritSec(&m_critsec);
  5907. HRESULT hr = hrOK;
  5908. LPBYTE pIfBytes = NULL;
  5909. DWORD dwIfBytesSize = 0;
  5910. COM_PROTECT_TRY
  5911. {
  5912. if (pInfoBase)
  5913. {
  5914. //
  5915. // If already loaded, the handles passed in are ignored.
  5916. //
  5917. // Otherwise, if not specified, a connection will be made.
  5918. //
  5919. CORg( TryToGetAllHandles(T2CW((LPTSTR)(LPCTSTR) m_stMachine),
  5920. &hMachine, &hInterface, &hIfTransport) );
  5921. //
  5922. // Convert the CInfoBase to a byte-array
  5923. //
  5924. CWRg( pInfoBase->WriteTo(&pIfBytes, &dwIfBytesSize) );
  5925. //
  5926. // Save the information to the persistent store
  5927. //
  5928. CWRg( ::MprConfigInterfaceTransportSetInfo(
  5929. hMachine,
  5930. hInterface,
  5931. hIfTransport,
  5932. pIfBytes,
  5933. dwIfBytesSize
  5934. ) );
  5935. }
  5936. COM_PROTECT_ERROR_LABEL;
  5937. }
  5938. COM_PROTECT_CATCH;
  5939. CoTaskMemFree( pIfBytes );
  5940. return hr;
  5941. }
  5942. /*!--------------------------------------------------------------------------
  5943. RtrMgrInterfaceInfo::GetInfoBase
  5944. -
  5945. Author: KennT
  5946. ---------------------------------------------------------------------------*/
  5947. STDMETHODIMP RtrMgrInterfaceInfo::GetInfoBase(HANDLE hMachine,
  5948. HANDLE hInterface,
  5949. HANDLE hIfTransport,
  5950. IInfoBase **ppInfoBase)
  5951. {
  5952. Assert(ppInfoBase);
  5953. RtrCriticalSection rtrCritSec(&m_critsec);
  5954. HRESULT hr = hrOK;
  5955. LPBYTE pIfBytes = NULL;
  5956. DWORD dwIfBytesSize;
  5957. SPIInfoBase spInfoBase;
  5958. COM_PROTECT_TRY
  5959. {
  5960. *ppInfoBase = NULL;
  5961. //
  5962. // If already loaded, the handles passed in are ignored.
  5963. //
  5964. // Otherwise, if not specified, a connection will be made.
  5965. //
  5966. CORg( TryToGetAllHandles(T2CW((LPTSTR)(LPCTSTR) m_stMachine),
  5967. &hMachine, &hInterface, &hIfTransport) );
  5968. CORg( CreateInfoBase(&spInfoBase) );
  5969. //
  5970. // Retrieve the info for the interface transport
  5971. //
  5972. CWRg( ::MprConfigInterfaceTransportGetInfo(
  5973. hMachine, hInterface, hIfTransport,
  5974. &pIfBytes,
  5975. &dwIfBytesSize
  5976. ));
  5977. //
  5978. // Parse the interface info for the router-manager
  5979. //
  5980. CORg( spInfoBase->LoadFrom(dwIfBytesSize, pIfBytes) );
  5981. *ppInfoBase = spInfoBase.Transfer();
  5982. COM_PROTECT_ERROR_LABEL;
  5983. }
  5984. COM_PROTECT_CATCH;
  5985. if (pIfBytes) { ::MprConfigBufferFree(pIfBytes); }
  5986. return hr;
  5987. }
  5988. /*!--------------------------------------------------------------------------
  5989. RtrMgrInterfaceInfo::GetId
  5990. -
  5991. Author: KennT
  5992. ---------------------------------------------------------------------------*/
  5993. STDMETHODIMP_(LPCOLESTR) RtrMgrInterfaceInfo::GetId()
  5994. {
  5995. RtrCriticalSection rtrCritSec(&m_critsec);
  5996. return m_cb.stId;
  5997. }
  5998. /*!--------------------------------------------------------------------------
  5999. RtrMgrInterfaceInfo::SetId
  6000. -
  6001. Author: KennT
  6002. ---------------------------------------------------------------------------*/
  6003. STDMETHODIMP RtrMgrInterfaceInfo::SetId(LPCOLESTR pszId)
  6004. {
  6005. RtrCriticalSection rtrCritSec(&m_critsec);
  6006. HRESULT hr = hrOK;
  6007. COM_PROTECT_TRY
  6008. {
  6009. m_cb.stId = pszId;
  6010. }
  6011. COM_PROTECT_CATCH;
  6012. return hr;
  6013. }
  6014. /*!--------------------------------------------------------------------------
  6015. RtrMgrInterfaceInfo::GetTransportId
  6016. -
  6017. Author: KennT
  6018. ---------------------------------------------------------------------------*/
  6019. STDMETHODIMP_(DWORD) RtrMgrInterfaceInfo::GetTransportId()
  6020. {
  6021. RtrCriticalSection rtrCritSec(&m_critsec);
  6022. return m_cb.dwTransportId;
  6023. }
  6024. /*!--------------------------------------------------------------------------
  6025. RtrMgrInterfaceInfo::GetInterfaceId
  6026. -
  6027. Author: KennT
  6028. ---------------------------------------------------------------------------*/
  6029. STDMETHODIMP_(LPCOLESTR) RtrMgrInterfaceInfo::GetInterfaceId()
  6030. {
  6031. RtrCriticalSection rtrCritSec(&m_critsec);
  6032. //$UNICODE : kennt, assumes native unicode and OLECHAR==WCHAR
  6033. return m_cb.stInterfaceId;
  6034. }
  6035. /*!--------------------------------------------------------------------------
  6036. RtrMgrInterfaceInfo::GetInterfaceType
  6037. -
  6038. Author: KennT
  6039. ---------------------------------------------------------------------------*/
  6040. STDMETHODIMP_(DWORD) RtrMgrInterfaceInfo::GetInterfaceType()
  6041. {
  6042. RtrCriticalSection rtrCritSec(&m_critsec);
  6043. return m_cb.dwIfType;
  6044. }
  6045. /*!--------------------------------------------------------------------------
  6046. RtrMgrInterfaceInfo::GetTitle
  6047. -
  6048. Author: KennT
  6049. ---------------------------------------------------------------------------*/
  6050. STDMETHODIMP_(LPCOLESTR) RtrMgrInterfaceInfo::GetTitle()
  6051. {
  6052. RtrCriticalSection rtrCritSec(&m_critsec);
  6053. //$UNICODE : kennt, assumes native unicode and OLECHAR==WCHAR
  6054. return m_cb.stTitle;
  6055. }
  6056. /*!--------------------------------------------------------------------------
  6057. RtrMgrInterfaceInfo::SetTitle
  6058. -
  6059. Author: KennT
  6060. ---------------------------------------------------------------------------*/
  6061. STDMETHODIMP RtrMgrInterfaceInfo::SetTitle(LPCOLESTR pszTitle)
  6062. {
  6063. RtrCriticalSection rtrCritSec(&m_critsec);
  6064. HRESULT hr = hrOK;
  6065. COM_PROTECT_TRY
  6066. {
  6067. m_cb.stTitle = pszTitle;
  6068. }
  6069. COM_PROTECT_CATCH;
  6070. return hr;
  6071. }
  6072. /*!--------------------------------------------------------------------------
  6073. RtrMgrInterfaceInfo::CopyCB
  6074. -
  6075. Author: KennT
  6076. ---------------------------------------------------------------------------*/
  6077. STDMETHODIMP RtrMgrInterfaceInfo::CopyCB(RtrMgrInterfaceCB *pRmIfCB)
  6078. {
  6079. RtrCriticalSection rtrCritSec(&m_critsec);
  6080. HRESULT hr = hrOK;
  6081. COM_PROTECT_TRY
  6082. {
  6083. m_cb.SaveTo(pRmIfCB);
  6084. }
  6085. COM_PROTECT_CATCH;
  6086. return hr;
  6087. }
  6088. /*!--------------------------------------------------------------------------
  6089. RtrMgrInterfaceInfo::GetMachineName
  6090. -
  6091. Author: KennT
  6092. ---------------------------------------------------------------------------*/
  6093. STDMETHODIMP_(LPCOLESTR) RtrMgrInterfaceInfo::GetMachineName()
  6094. {
  6095. RtrCriticalSection rtrCritSec(&m_critsec);
  6096. //$UNICODE : kennt, assumes native unicode and OLECHAR==WCHAR
  6097. return m_stMachine;
  6098. }
  6099. /*!--------------------------------------------------------------------------
  6100. RtrMgrInterfaceInfo::SetMachineName
  6101. -
  6102. Author: KennT
  6103. ---------------------------------------------------------------------------*/
  6104. STDMETHODIMP RtrMgrInterfaceInfo::SetMachineName(LPCOLESTR pszMachineName)
  6105. {
  6106. RtrCriticalSection rtrCritSec(&m_critsec);
  6107. HRESULT hr = hrOK;
  6108. COM_PROTECT_TRY
  6109. {
  6110. m_stMachine = pszMachineName;
  6111. }
  6112. COM_PROTECT_CATCH;
  6113. return hr;
  6114. }
  6115. /*!--------------------------------------------------------------------------
  6116. RtrMgrInterfaceInfo::EnumRtrMgrProtocolInterface
  6117. -
  6118. Author: KennT
  6119. ---------------------------------------------------------------------------*/
  6120. STDMETHODIMP RtrMgrInterfaceInfo::EnumRtrMgrProtocolInterface( IEnumRtrMgrProtocolInterfaceInfo **ppEnumRmProtIf)
  6121. {
  6122. RtrCriticalSection rtrCritSec(&m_critsec);
  6123. HRESULT hr = hrOK;
  6124. COM_PROTECT_TRY
  6125. {
  6126. hr = CreateEnumFromRtrMgrProtocolInterfaceList(&m_RmProtIfList,
  6127. ppEnumRmProtIf);
  6128. }
  6129. COM_PROTECT_CATCH;
  6130. return hr;
  6131. }
  6132. /*!--------------------------------------------------------------------------
  6133. RtrMgrInterfaceInfo::FindRtrMgrProtocolInterface
  6134. -
  6135. Author: KennT
  6136. ---------------------------------------------------------------------------*/
  6137. STDMETHODIMP RtrMgrInterfaceInfo::FindRtrMgrProtocolInterface( DWORD dwProtocolId,
  6138. IRtrMgrProtocolInterfaceInfo **ppInfo)
  6139. {
  6140. RtrCriticalSection rtrCritSec(&m_critsec);
  6141. HRESULT hr = hrFalse;
  6142. POSITION pos;
  6143. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  6144. COM_PROTECT_TRY
  6145. {
  6146. if (ppInfo)
  6147. *ppInfo = NULL;
  6148. // Look through the list of rtr mgrs for the one that matches
  6149. pos = m_RmProtIfList.GetHeadPosition();
  6150. while (pos)
  6151. {
  6152. spRmProtIf.Set(m_RmProtIfList.GetNext(pos));
  6153. Assert(spRmProtIf);
  6154. if (spRmProtIf->GetProtocolId() == dwProtocolId)
  6155. {
  6156. hr = hrOK;
  6157. if (ppInfo)
  6158. *ppInfo = spRmProtIf.Transfer();
  6159. break;
  6160. }
  6161. }
  6162. }
  6163. COM_PROTECT_CATCH;
  6164. return hr;
  6165. }
  6166. /*!--------------------------------------------------------------------------
  6167. RtrMgrInterfaceInfo::AddRtrMgrProtocolInterface
  6168. -
  6169. Author: KennT
  6170. ---------------------------------------------------------------------------*/
  6171. STDMETHODIMP RtrMgrInterfaceInfo::AddRtrMgrProtocolInterface( IRtrMgrProtocolInterfaceInfo *pInfo,
  6172. IInfoBase *pInterfaceInfo)
  6173. {
  6174. Assert(pInfo);
  6175. RtrCriticalSection rtrCritSec(&m_critsec);
  6176. HRESULT hr = hrOK;
  6177. COM_PROTECT_TRY
  6178. {
  6179. //
  6180. // Fail if there is a duplicate
  6181. //
  6182. if (FHrOK(FindRtrMgrProtocolInterface(pInfo->GetProtocolId(), NULL)))
  6183. CORg( E_INVALIDARG );
  6184. //
  6185. // Save the new information if specified
  6186. //
  6187. if (pInterfaceInfo)
  6188. {
  6189. CORg( Save(GetMachineName(),
  6190. m_hMachineConfig,
  6191. m_hInterface,
  6192. m_hIfTransport,
  6193. pInterfaceInfo,
  6194. 0) );
  6195. }
  6196. //
  6197. // Add the new routing-protocol to our list
  6198. //
  6199. m_RmProtIfList.AddTail(pInfo);
  6200. pInfo->AddWeakRef();
  6201. pInfo->SetParentRtrMgrInterfaceInfo(this);
  6202. NotifyOfRmProtIfAdd(pInfo, m_pInterfaceInfoParent);
  6203. COM_PROTECT_ERROR_LABEL;
  6204. }
  6205. COM_PROTECT_CATCH;
  6206. return hr;
  6207. }
  6208. /*!--------------------------------------------------------------------------
  6209. RtrMgrInterfaceInfo::DeleteRtrMgrProtocolInterface
  6210. -
  6211. Author: KennT
  6212. ---------------------------------------------------------------------------*/
  6213. STDMETHODIMP RtrMgrInterfaceInfo::DeleteRtrMgrProtocolInterface( DWORD dwProtocolId, BOOL fRemove)
  6214. {
  6215. RtrCriticalSection rtrCritSec(&m_critsec);
  6216. HRESULT hr = hrOK;
  6217. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  6218. SPIRtrMgrProtocolInfo spRmProt;
  6219. SPIRouterInfo spRouterInfo;
  6220. POSITION pos;
  6221. POSITION posRmProtIf;
  6222. HRESULT hrT;
  6223. COM_PROTECT_TRY
  6224. {
  6225. //
  6226. // Find the routing-protocol to be deleted
  6227. //
  6228. pos = m_RmProtIfList.GetHeadPosition();
  6229. while (pos)
  6230. {
  6231. posRmProtIf = pos;
  6232. spRmProtIf.Set( m_RmProtIfList.GetNext(pos) );
  6233. if (spRmProtIf->GetProtocolId() == dwProtocolId)
  6234. break;
  6235. spRmProtIf.Release();
  6236. }
  6237. if (spRmProtIf == NULL)
  6238. CORg( E_INVALIDARG );
  6239. //
  6240. // Save the updated information, removing the protocol's block
  6241. //
  6242. if (fRemove)
  6243. {
  6244. hr= Save(GetMachineName(),
  6245. m_hMachineConfig,
  6246. m_hInterface,
  6247. m_hIfTransport,
  6248. NULL,
  6249. dwProtocolId) ;
  6250. if (!FHrSucceeded(hr) &&
  6251. (hr != HRESULT_FROM_WIN32(ERROR_NO_SUCH_INTERFACE)))
  6252. CORg(hr);
  6253. }
  6254. //
  6255. // Remove the protocol from our list
  6256. //
  6257. m_RmProtIfList.RemoveAt(posRmProtIf);
  6258. spRmProtIf->Destruct();
  6259. spRmProtIf->ReleaseWeakRef();
  6260. m_AdviseList.NotifyChange(ROUTER_CHILD_DELETE, ROUTER_OBJ_RmProtIf, 0);
  6261. // Also need to advise the RmProt
  6262. if (m_pInterfaceInfoParent)
  6263. {
  6264. hrT = m_pInterfaceInfoParent->GetParentRouterInfo(&spRouterInfo);
  6265. if (FHrOK(hrT))
  6266. hrT = LookupRtrMgrProtocol(spRouterInfo,
  6267. spRmProtIf->GetTransportId(),
  6268. spRmProtIf->GetProtocolId(),
  6269. &spRmProt);
  6270. if (FHrOK(hrT))
  6271. spRmProt->RtrNotify(ROUTER_CHILD_DELETE, ROUTER_OBJ_RmProtIf, 0);
  6272. }
  6273. Assert(FindRtrMgrProtocolInterface(dwProtocolId, NULL) != hrOK);
  6274. COM_PROTECT_ERROR_LABEL;
  6275. }
  6276. COM_PROTECT_CATCH;
  6277. return hr;
  6278. }
  6279. /*!--------------------------------------------------------------------------
  6280. RtrMgrInterfaceInfo::ReleaseRtrMgrProtocolInterface
  6281. This function will release the AddRef() that this object has
  6282. on the child. This allows us to transfer child objects from
  6283. one router to another.
  6284. Author: KennT
  6285. ---------------------------------------------------------------------------*/
  6286. STDMETHODIMP RtrMgrInterfaceInfo::ReleaseRtrMgrProtocolInterface( DWORD dwProtocolId )
  6287. {
  6288. HRESULT hr = hrOK;
  6289. POSITION pos, posRmProtIf;
  6290. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  6291. COM_PROTECT_TRY
  6292. {
  6293. pos = m_RmProtIfList.GetHeadPosition();
  6294. while (pos)
  6295. {
  6296. // Save the position (so that we can delete it)
  6297. posRmProtIf = pos;
  6298. spRmProtIf.Set( m_RmProtIfList.GetNext(pos) );
  6299. if (spRmProtIf &&
  6300. (spRmProtIf->GetProtocolId() == dwProtocolId))
  6301. {
  6302. // When releasing, we need to disconnect (since the
  6303. // main handle is controlled by the router info).
  6304. spRmProtIf->DoDisconnect();
  6305. spRmProtIf->ReleaseWeakRef();
  6306. spRmProtIf.Release();
  6307. // release this node from the list
  6308. m_RmProtIfList.RemoveAt(posRmProtIf);
  6309. break;
  6310. }
  6311. spRmProtIf.Release();
  6312. }
  6313. }
  6314. COM_PROTECT_CATCH;
  6315. return hr;
  6316. }
  6317. /*!--------------------------------------------------------------------------
  6318. RtrMgrInterfaceInfo::RtrAdvise
  6319. -
  6320. Author: KennT
  6321. ---------------------------------------------------------------------------*/
  6322. STDMETHODIMP RtrMgrInterfaceInfo::RtrAdvise( IRtrAdviseSink *pRtrAdviseSink,
  6323. LONG_PTR *pulConnection,
  6324. LPARAM lUserParam)
  6325. {
  6326. Assert(pRtrAdviseSink);
  6327. Assert(pulConnection);
  6328. RtrCriticalSection rtrCritSec(&m_critsec);
  6329. LONG_PTR ulConnId;
  6330. HRESULT hr = hrOK;
  6331. COM_PROTECT_TRY
  6332. {
  6333. ulConnId = (LONG_PTR) InterlockedIncrement(&s_cConnections);
  6334. CORg( m_AdviseList.AddConnection(pRtrAdviseSink, ulConnId, lUserParam) );
  6335. *pulConnection = ulConnId;
  6336. COM_PROTECT_ERROR_LABEL;
  6337. }
  6338. COM_PROTECT_CATCH;
  6339. return hr;
  6340. }
  6341. /*!--------------------------------------------------------------------------
  6342. RtrMgrInterfaceInfo::RtrNotify
  6343. -
  6344. Author: KennT
  6345. ---------------------------------------------------------------------------*/
  6346. STDMETHODIMP RtrMgrInterfaceInfo::RtrNotify(DWORD dwChangeType, DWORD dwObjectType,
  6347. LPARAM lParam)
  6348. {
  6349. RtrCriticalSection rtrCritSec(&m_critsec);
  6350. HRESULT hr = hrOK;
  6351. COM_PROTECT_TRY
  6352. {
  6353. m_AdviseList.NotifyChange(dwChangeType, dwObjectType, lParam);
  6354. }
  6355. COM_PROTECT_CATCH;
  6356. return hr;
  6357. }
  6358. /*!--------------------------------------------------------------------------
  6359. RtrMgrInterfaceInfo::RtrUnadvise
  6360. -
  6361. Author: KennT
  6362. ---------------------------------------------------------------------------*/
  6363. STDMETHODIMP RtrMgrInterfaceInfo::RtrUnadvise( LONG_PTR ulConnection)
  6364. {
  6365. RtrCriticalSection rtrCritSec(&m_critsec);
  6366. return m_AdviseList.RemoveConnection(ulConnection);
  6367. }
  6368. /*!--------------------------------------------------------------------------
  6369. RtrMgrInterfaceInfo::LoadRtrMgrInterfaceInfo
  6370. -
  6371. Author: KennT
  6372. ---------------------------------------------------------------------------*/
  6373. HRESULT RtrMgrInterfaceInfo::LoadRtrMgrInterfaceInfo(HANDLE hMachine,
  6374. HANDLE hInterface,
  6375. HANDLE hIfTransport)
  6376. {
  6377. RtrCriticalSection rtrCritSec(&m_critsec);
  6378. DWORD dwErr;
  6379. SPIInfoBase spInterfaceInfoBase;
  6380. HRESULT hr = hrOK;
  6381. SPIEnumInfoBlock spEnumBlock;
  6382. SPIRouterInfo spRouterInfo;
  6383. SPIEnumRtrMgrProtocolCB spEnumRmProtCB;
  6384. SRtrMgrProtocolCBList SRmProtCBList;
  6385. InfoBlock * pInfoBlock;
  6386. RtrMgrProtocolCB rmprotCB;
  6387. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  6388. //
  6389. // If the caller doesn't want the data for the router-manager,
  6390. // and we need to reload, use the infobase on the stack.
  6391. // Otherwise, create an infobase to be loaded and returned to the caller
  6392. //
  6393. CORg( GetInfoBase(hMachine, hInterface, hIfTransport, &spInterfaceInfoBase) );
  6394. //
  6395. // Now we need to build the list of protocols active on this interface,
  6396. // by examining the blocks in the interface's data.
  6397. //
  6398. // Get a list of the blocks in the interface info
  6399. //
  6400. CORg( spInterfaceInfoBase->QueryBlockList(&spEnumBlock) );
  6401. //
  6402. // Get a list of the routing-protocols installed
  6403. //
  6404. // If possible, we use the routing-protocol control-block list
  6405. // loaded by our containing 'CRouterInfo', to save us from
  6406. // having to load our own in order to interpret the protocols' blocks
  6407. // inside the 'GlobalInfo'.
  6408. //
  6409. // Traverse back through the object hierarchy to get our RouterInfo
  6410. // object
  6411. if (m_pInterfaceInfoParent)
  6412. {
  6413. m_pInterfaceInfoParent->GetParentRouterInfo(&spRouterInfo);
  6414. }
  6415. if (spRouterInfo)
  6416. {
  6417. CORg( spRouterInfo->EnumRtrMgrProtocolCB(&spEnumRmProtCB) );
  6418. }
  6419. else
  6420. {
  6421. CORg( RouterInfo::LoadInstalledRtrMgrProtocolList(GetMachineName(),
  6422. GetTransportId(),
  6423. &SRmProtCBList,
  6424. spRouterInfo) );
  6425. CORg( CreateEnumFromSRmProtCBList(&SRmProtCBList, &spEnumRmProtCB) );
  6426. }
  6427. //
  6428. // Go through the blocks and for each one, see if the block type
  6429. // is the same as the protocol ID for some protocol
  6430. //
  6431. spEnumBlock->Reset();
  6432. while (spEnumBlock->Next(1, &pInfoBlock, NULL) == hrOK)
  6433. {
  6434. //
  6435. // When a routing protocol is removed, its block is left in place,
  6436. // but with zero-length data.
  6437. // We skip such blocks since they don't represent installed protocols.
  6438. //
  6439. if (pInfoBlock->dwSize == 0)
  6440. continue;
  6441. //
  6442. // Look through the installed protocols for a protocol
  6443. // whose ID is the same as this block's type
  6444. //
  6445. spEnumRmProtCB->Reset();
  6446. while (spEnumRmProtCB->Next(1, &rmprotCB, NULL) == hrOK)
  6447. {
  6448. //
  6449. // If this isn't what we're looking for, continue
  6450. //
  6451. if ((pInfoBlock->dwType != rmprotCB.dwProtocolId) ||
  6452. (GetTransportId() != rmprotCB.dwTransportId))
  6453. continue;
  6454. //
  6455. // This is the block we're looking for;
  6456. // construct a CRmProtInterfaceInfo using the control block
  6457. //
  6458. RtrMgrProtocolInterfaceInfo *pRmProtIf = new
  6459. RtrMgrProtocolInterfaceInfo(rmprotCB.dwProtocolId,
  6460. rmprotCB.szId,
  6461. GetTransportId(),
  6462. rmprotCB.szRtrMgrId,
  6463. GetInterfaceId(),
  6464. GetInterfaceType(),
  6465. this);
  6466. spRmProtIf = pRmProtIf;
  6467. spRmProtIf->SetFlags(RouterSnapin_InSyncWithRouter);
  6468. pRmProtIf->m_cb.stTitle = rmprotCB.szTitle;
  6469. //
  6470. // Add the new protocol to our list
  6471. //
  6472. m_RmProtIfList.AddTail(pRmProtIf);
  6473. pRmProtIf->AddWeakRef();
  6474. spRmProtIf.Release();
  6475. NotifyOfRmProtIfAdd(pRmProtIf, m_pInterfaceInfoParent);
  6476. break;
  6477. }
  6478. }
  6479. Error:
  6480. //
  6481. // Empty the list if we got data for it
  6482. //
  6483. if (!SRmProtCBList.IsEmpty())
  6484. {
  6485. while (!SRmProtCBList.IsEmpty())
  6486. delete SRmProtCBList.RemoveHead();
  6487. }
  6488. return hr;
  6489. }
  6490. /*!--------------------------------------------------------------------------
  6491. RtrMgrInterfaceInfo::SaveRtrMgrInterfaceInfo
  6492. -
  6493. This function saves a router-manager's interface information,
  6494. removing blocks for protocols which have been deleted,
  6495. given an infobase derived from CInfoBase.
  6496. Author: KennT
  6497. ---------------------------------------------------------------------------*/
  6498. HRESULT RtrMgrInterfaceInfo::SaveRtrMgrInterfaceInfo(HANDLE hMachine,
  6499. HANDLE hInterface,
  6500. HANDLE hIfTransport,
  6501. IInfoBase *pInterfaceInfoBase,
  6502. DWORD dwDeleteProtocolId)
  6503. {
  6504. RtrCriticalSection rtrCritSec(&m_critsec);
  6505. HRESULT hr = hrOK;
  6506. SPIInfoBase spIfInfoBase;
  6507. LPBYTE pIfBytes = NULL;
  6508. DWORD dwIfBytesSize = 0;
  6509. //
  6510. // If the caller wants a protocol's block to be deleted first,
  6511. // do so before saving the data.
  6512. //
  6513. if (dwDeleteProtocolId)
  6514. {
  6515. //
  6516. // If no data was given but we've been asked to delete a protocol,
  6517. // we need to load the existing data, so that the protocol's block
  6518. // can be removed from the infobase.
  6519. //
  6520. if (pInterfaceInfoBase == NULL)
  6521. {
  6522. CORg( CreateInfoBase(&spIfInfoBase) );
  6523. pInterfaceInfoBase = spIfInfoBase;
  6524. //
  6525. // Retrieve the existing data
  6526. //
  6527. CWRg( ::MprConfigInterfaceTransportGetInfo(
  6528. hMachine,
  6529. hInterface,
  6530. hIfTransport,
  6531. &pIfBytes,
  6532. &dwIfBytesSize
  6533. ) );
  6534. //
  6535. // Parse the data into a list of blocks
  6536. //
  6537. CWRg( pInterfaceInfoBase->LoadFrom(dwIfBytesSize, pIfBytes) );
  6538. }
  6539. //
  6540. // Delete the protocol specified
  6541. //
  6542. pInterfaceInfoBase->SetData(dwDeleteProtocolId, 0, NULL, 0, 0);
  6543. }
  6544. //
  6545. // Convert the CInfoBase to a byte-array
  6546. //
  6547. if (pInterfaceInfoBase)
  6548. CWRg( pInterfaceInfoBase->WriteTo(&pIfBytes, &dwIfBytesSize) );
  6549. //
  6550. // Save the information to the persistent store
  6551. //
  6552. CWRg( ::MprConfigInterfaceTransportSetInfo(
  6553. hMachine,
  6554. hInterface,
  6555. hIfTransport,
  6556. pIfBytes,
  6557. dwIfBytesSize
  6558. ) );
  6559. //
  6560. // Update the info of the running router-manager
  6561. //
  6562. if (pInterfaceInfoBase)
  6563. CWRg( SetInfo(dwIfBytesSize, pIfBytes) );
  6564. // We have now saved the information to the registry and to
  6565. // the running router. We now mark it as such.
  6566. m_dwFlags |= RouterSnapin_InSyncWithRouter;
  6567. Error:
  6568. CoTaskMemFree( pIfBytes );
  6569. return hr;
  6570. }
  6571. /*!--------------------------------------------------------------------------
  6572. RtrMgrInterfaceInfo::TryToConnect
  6573. -
  6574. Author: KennT
  6575. ---------------------------------------------------------------------------*/
  6576. HRESULT RtrMgrInterfaceInfo::TryToConnect(LPCWSTR pswzMachine, HANDLE *phMachine)
  6577. {
  6578. RtrCriticalSection rtrCritSec(&m_critsec);
  6579. HRESULT hr = hrOK;
  6580. if (m_hMachineConfig)
  6581. *phMachine = m_hMachineConfig;
  6582. else if (*phMachine)
  6583. {
  6584. m_hMachineConfig = *phMachine;
  6585. m_bDisconnect = FALSE;
  6586. }
  6587. else
  6588. {
  6589. //$ Review: kennt, this function does not take a LPCWSTR,
  6590. // is this a mistake or does it modify the parameters?
  6591. CWRg( ::MprConfigServerConnect((LPWSTR) pswzMachine, phMachine) );
  6592. m_hMachineConfig = *phMachine;
  6593. m_bDisconnect = TRUE;
  6594. }
  6595. Error:
  6596. return hr;
  6597. }
  6598. /*!--------------------------------------------------------------------------
  6599. RtrMgrInterfaceInfo::NotifyOfRmProtIfAdd
  6600. -
  6601. Author: KennT
  6602. ---------------------------------------------------------------------------*/
  6603. HRESULT RtrMgrInterfaceInfo::NotifyOfRmProtIfAdd(IRtrMgrProtocolInterfaceInfo *pRmProtIf,
  6604. IInterfaceInfo *pParentIf)
  6605. {
  6606. HRESULT hr = hrOK;
  6607. m_AdviseList.NotifyChange(ROUTER_CHILD_ADD, ROUTER_OBJ_RmProtIf, 0);
  6608. // Also notify the RtrMgrProtocol object that interfaces have
  6609. // been added.
  6610. if (pParentIf)
  6611. {
  6612. SPIRouterInfo spRouterInfo;
  6613. SPIRtrMgrProtocolInfo spRmProtInfo;
  6614. HRESULT hrT; // this hr is ignored
  6615. // If these calls fail, it doesn't matter the operation still
  6616. // is considered successful
  6617. hrT = pParentIf->GetParentRouterInfo(&spRouterInfo);
  6618. if (FHrSucceeded(hrT))
  6619. {
  6620. hrT = LookupRtrMgrProtocol(spRouterInfo,
  6621. pRmProtIf->GetTransportId(),
  6622. pRmProtIf->GetProtocolId(),
  6623. &spRmProtInfo);
  6624. }
  6625. if (FHrOK(hrT))
  6626. hrT = spRmProtInfo->RtrNotify(ROUTER_CHILD_ADD,
  6627. ROUTER_OBJ_RmProtIf, 0);
  6628. }
  6629. return hr;
  6630. }
  6631. /*!--------------------------------------------------------------------------
  6632. RtrMgrInterfaceInfo::TryToGetIfHandle
  6633. -
  6634. Author: KennT
  6635. ---------------------------------------------------------------------------*/
  6636. HRESULT RtrMgrInterfaceInfo::TryToGetIfHandle(HANDLE hMachine,
  6637. LPCWSTR pswzInterface,
  6638. HANDLE *phInterface)
  6639. {
  6640. RtrCriticalSection rtrCritSec(&m_critsec);
  6641. HRESULT hr = hrOK;
  6642. if (m_hInterface)
  6643. *phInterface = m_hInterface;
  6644. else if (*phInterface)
  6645. m_hInterface = *phInterface;
  6646. else
  6647. {
  6648. //
  6649. // Get a handle to the interface
  6650. //
  6651. CWRg(::MprConfigInterfaceGetHandle(hMachine,
  6652. (LPWSTR) pswzInterface,
  6653. phInterface
  6654. ) );
  6655. m_hInterface = *phInterface;
  6656. }
  6657. Error:
  6658. return hr;
  6659. }
  6660. /*!--------------------------------------------------------------------------
  6661. RtrMgrInterfaceInfo::GetParentInterfaceInfo
  6662. -
  6663. Author: KennT
  6664. ---------------------------------------------------------------------------*/
  6665. STDMETHODIMP RtrMgrInterfaceInfo::GetParentInterfaceInfo(IInterfaceInfo **ppParent)
  6666. {
  6667. RtrCriticalSection rtrCritSec(&m_critsec);
  6668. *ppParent = m_pInterfaceInfoParent;
  6669. if (*ppParent)
  6670. (*ppParent)->AddRef();
  6671. return hrOK;
  6672. }
  6673. /*!--------------------------------------------------------------------------
  6674. RtrMgrInterfaceInfo::SetParentInterfaceInfo
  6675. -
  6676. Author: KennT
  6677. ---------------------------------------------------------------------------*/
  6678. STDMETHODIMP RtrMgrInterfaceInfo::SetParentInterfaceInfo(IInterfaceInfo *pParent)
  6679. {
  6680. RtrCriticalSection rtrCritSec(&m_critsec);
  6681. IInterfaceInfo * pTemp;
  6682. pTemp = m_pInterfaceInfoParent;
  6683. m_pInterfaceInfoParent = NULL;
  6684. if (m_fStrongRef)
  6685. {
  6686. if (pTemp)
  6687. pTemp->Release();
  6688. if (pParent)
  6689. pParent->AddRef();
  6690. }
  6691. else
  6692. {
  6693. if (pTemp)
  6694. pTemp->ReleaseWeakRef();
  6695. if (pParent)
  6696. pParent->AddWeakRef();
  6697. }
  6698. m_pInterfaceInfoParent = pParent;
  6699. return hrOK;
  6700. }
  6701. /*!--------------------------------------------------------------------------
  6702. RtrMgrInterfaceInfo::Disconnect
  6703. -
  6704. Author: KennT
  6705. ---------------------------------------------------------------------------*/
  6706. void RtrMgrInterfaceInfo::Disconnect()
  6707. {
  6708. if (m_bDisconnect && m_hMachineConfig)
  6709. ::MprConfigServerDisconnect(m_hMachineConfig);
  6710. m_bDisconnect = FALSE;
  6711. m_hMachineConfig = NULL;
  6712. m_hInterface = NULL;
  6713. m_hIfTransport = NULL;
  6714. }
  6715. /*!--------------------------------------------------------------------------
  6716. RtrMgrInterfaceInfo::DoDisconnect
  6717. -
  6718. Author: KennT
  6719. ---------------------------------------------------------------------------*/
  6720. STDMETHODIMP RtrMgrInterfaceInfo::DoDisconnect()
  6721. {
  6722. HRESULT hr = hrOK;
  6723. SPIEnumRtrMgrProtocolInterfaceInfo spEnumRmProtIf;
  6724. SPIRtrMgrProtocolInterfaceInfo spRmProtIf;
  6725. COM_PROTECT_TRY
  6726. {
  6727. // Disconnect our data.
  6728. // ------------------------------------------------------------
  6729. Disconnect();
  6730. // Notify the advise sinks of a disconnect.
  6731. // ------------------------------------------------------------
  6732. RtrNotify(ROUTER_DO_DISCONNECT, 0, 0);
  6733. // Now tell all child objects to disconnect.
  6734. // ------------------------------------------------------------
  6735. HRESULT hrIter = hrOK;
  6736. EnumRtrMgrProtocolInterface(&spEnumRmProtIf);
  6737. spEnumRmProtIf->Reset();
  6738. while (spEnumRmProtIf->Next(1, &spRmProtIf, NULL) == hrOK)
  6739. {
  6740. spRmProtIf->DoDisconnect();
  6741. spRmProtIf.Release();
  6742. }
  6743. }
  6744. COM_PROTECT_CATCH;
  6745. return hr;
  6746. }
  6747. /*!--------------------------------------------------------------------------
  6748. RtrMgrInterfaceInfo::TryToGetAllHandles
  6749. -
  6750. Author: KennT
  6751. ---------------------------------------------------------------------------*/
  6752. HRESULT RtrMgrInterfaceInfo::TryToGetAllHandles(LPCOLESTR pszMachine,
  6753. HANDLE *phMachine,
  6754. HANDLE *phInterface,
  6755. HANDLE *phTransport)
  6756. {
  6757. HRESULT hr = hrOK;
  6758. Assert(phMachine);
  6759. Assert(phInterface);
  6760. //
  6761. // If already loaded, the handle passed in is ignored.
  6762. //
  6763. // Otherwise, if 'hMachine' was not specified, connect to the config
  6764. // on the specified machine
  6765. //
  6766. CORg( TryToConnect(pszMachine, phMachine) );
  6767. //
  6768. // If already loaded, the handle passed in is ignored;
  6769. //
  6770. // Otherwise, if 'hInterface' was not specified,
  6771. // get the interface handle
  6772. //
  6773. CORg( TryToGetIfHandle(*phMachine, GetInterfaceId(), phInterface) );
  6774. //
  6775. // Get a handle to the interface-transport
  6776. //
  6777. //
  6778. // If 'hIfTransport' was not specified, connect
  6779. //
  6780. if (phTransport)
  6781. {
  6782. if (m_hIfTransport)
  6783. *phTransport = m_hIfTransport;
  6784. else if (*phTransport)
  6785. m_hIfTransport = *phTransport;
  6786. else
  6787. {
  6788. //
  6789. // Get a handle to the interface-transport
  6790. //
  6791. CWRg( ::MprConfigInterfaceTransportGetHandle(
  6792. *phMachine,
  6793. *phInterface,
  6794. GetTransportId(),
  6795. phTransport
  6796. ) );
  6797. m_hIfTransport = *phTransport;
  6798. }
  6799. }
  6800. Error:
  6801. return hr;
  6802. }
  6803. /*---------------------------------------------------------------------------
  6804. IRtrMgrProtocolInterfaceInfo Implementation
  6805. ---------------------------------------------------------------------------*/
  6806. TFSCORE_API(HRESULT) CreateRtrMgrProtocolInterfaceInfo(
  6807. IRtrMgrProtocolInterfaceInfo **ppRmProtIfInfo,
  6808. const RtrMgrProtocolInterfaceCB *pRmProtIfCB)
  6809. {
  6810. Assert(ppRmProtIfInfo);
  6811. Assert(pRmProtIfCB);
  6812. HRESULT hr = hrOK;
  6813. IRtrMgrProtocolInterfaceInfo * pRmProtIf = NULL;
  6814. USES_CONVERSION;
  6815. COM_PROTECT_TRY
  6816. {
  6817. *ppRmProtIfInfo = new RtrMgrProtocolInterfaceInfo(
  6818. pRmProtIfCB->dwProtocolId,
  6819. W2CT(pRmProtIfCB->szId),
  6820. pRmProtIfCB->dwTransportId,
  6821. W2CT(pRmProtIfCB->szRtrMgrId),
  6822. W2CT(pRmProtIfCB->szInterfaceId),
  6823. pRmProtIfCB->dwIfType,
  6824. NULL);
  6825. }
  6826. COM_PROTECT_CATCH;
  6827. return hr;
  6828. }
  6829. IMPLEMENT_WEAKREF_ADDREF_RELEASE(RtrMgrProtocolInterfaceInfo)
  6830. IMPLEMENT_SIMPLE_QUERYINTERFACE(RtrMgrProtocolInterfaceInfo, IRtrMgrProtocolInterfaceInfo)
  6831. DEBUG_DECLARE_INSTANCE_COUNTER(RtrMgrProtocolInterfaceInfo)
  6832. RtrMgrProtocolInterfaceInfo::RtrMgrProtocolInterfaceInfo(DWORD dwProtocolId,
  6833. LPCTSTR pszId,
  6834. DWORD dwTransportId,
  6835. LPCTSTR pszRmId,
  6836. LPCTSTR pszIfId,
  6837. DWORD dwIfType,
  6838. RtrMgrInterfaceInfo *pRmIf)
  6839. : m_dwFlags(0)
  6840. {
  6841. m_cb.dwProtocolId = dwProtocolId;
  6842. m_cb.stId = pszId;
  6843. m_cb.dwTransportId = dwTransportId;
  6844. m_cb.stRtrMgrId = pszRmId;
  6845. m_cb.stInterfaceId = pszIfId;
  6846. m_cb.dwIfType = dwIfType;
  6847. DEBUG_INCREMENT_INSTANCE_COUNTER(RtrMgrProtocolInterfaceInfo);
  6848. m_pRtrMgrInterfaceInfoParent = pRmIf;
  6849. if (m_pRtrMgrInterfaceInfoParent)
  6850. m_pRtrMgrInterfaceInfoParent->AddRef();
  6851. InitializeCriticalSection(&m_critsec);
  6852. }
  6853. RtrMgrProtocolInterfaceInfo::~RtrMgrProtocolInterfaceInfo()
  6854. {
  6855. Assert(m_pRtrMgrInterfaceInfoParent == NULL);
  6856. Destruct();
  6857. DEBUG_DECREMENT_INSTANCE_COUNTER(RtrMgrProtocolInterfaceInfo);
  6858. DeleteCriticalSection(&m_critsec);
  6859. }
  6860. void RtrMgrProtocolInterfaceInfo::ReviveStrongRef()
  6861. {
  6862. RtrCriticalSection rtrCritSec(&m_critsec);
  6863. if (m_pRtrMgrInterfaceInfoParent)
  6864. {
  6865. CONVERT_TO_STRONGREF(m_pRtrMgrInterfaceInfoParent);
  6866. }
  6867. }
  6868. void RtrMgrProtocolInterfaceInfo::OnLastStrongRef()
  6869. {
  6870. RtrCriticalSection rtrCritSec(&m_critsec);
  6871. if (m_pRtrMgrInterfaceInfoParent)
  6872. {
  6873. CONVERT_TO_WEAKREF(m_pRtrMgrInterfaceInfoParent);
  6874. }
  6875. if (m_fDestruct)
  6876. Destruct();
  6877. }
  6878. STDMETHODIMP RtrMgrProtocolInterfaceInfo::Destruct()
  6879. {
  6880. RtrCriticalSection rtrCritSec(&m_critsec);
  6881. IRtrMgrInterfaceInfo * pParent;
  6882. m_fDestruct = TRUE;
  6883. if (!m_fStrongRef)
  6884. {
  6885. pParent = m_pRtrMgrInterfaceInfoParent;
  6886. m_pRtrMgrInterfaceInfoParent = NULL;
  6887. if (pParent)
  6888. pParent->ReleaseWeakRef();
  6889. // Unload();
  6890. }
  6891. return hrOK;
  6892. }
  6893. STDMETHODIMP_(DWORD) RtrMgrProtocolInterfaceInfo::GetFlags()
  6894. {
  6895. RtrCriticalSection rtrCritSec(&m_critsec);
  6896. return m_dwFlags;
  6897. }
  6898. STDMETHODIMP RtrMgrProtocolInterfaceInfo::SetFlags(DWORD dwFlags)
  6899. {
  6900. RtrCriticalSection rtrCritSec(&m_critsec);
  6901. HRESULT hr = hrOK;
  6902. COM_PROTECT_TRY
  6903. {
  6904. m_dwFlags = dwFlags;
  6905. }
  6906. COM_PROTECT_CATCH;
  6907. return hr;
  6908. }
  6909. /*!--------------------------------------------------------------------------
  6910. RtrMgrProtocolInterfaceInfo::GetProtocolId
  6911. -
  6912. Author: KennT
  6913. ---------------------------------------------------------------------------*/
  6914. STDMETHODIMP_(DWORD) RtrMgrProtocolInterfaceInfo::GetProtocolId()
  6915. {
  6916. RtrCriticalSection rtrCritSec(&m_critsec);
  6917. return m_cb.dwProtocolId;
  6918. }
  6919. /*!--------------------------------------------------------------------------
  6920. RtrMgrProtocolInterfaceInfo::GetTransportId
  6921. -
  6922. Author: KennT
  6923. ---------------------------------------------------------------------------*/
  6924. STDMETHODIMP_(DWORD) RtrMgrProtocolInterfaceInfo::GetTransportId()
  6925. {
  6926. RtrCriticalSection rtrCritSec(&m_critsec);
  6927. return m_cb.dwTransportId;
  6928. }
  6929. /*!--------------------------------------------------------------------------
  6930. RtrMgrProtocolInterfaceInfo::GetInterfaceId
  6931. -
  6932. Author: KennT
  6933. ---------------------------------------------------------------------------*/
  6934. STDMETHODIMP_(LPCOLESTR) RtrMgrProtocolInterfaceInfo::GetInterfaceId()
  6935. {
  6936. RtrCriticalSection rtrCritSec(&m_critsec);
  6937. return m_cb.stInterfaceId;
  6938. }
  6939. /*!--------------------------------------------------------------------------
  6940. RtrMgrProtocolInterfaceInfo::GetInterfaceType
  6941. -
  6942. Author: KennT
  6943. ---------------------------------------------------------------------------*/
  6944. STDMETHODIMP_(DWORD) RtrMgrProtocolInterfaceInfo::GetInterfaceType()
  6945. {
  6946. RtrCriticalSection rtrCritSec(&m_critsec);
  6947. return m_cb.dwIfType;
  6948. }
  6949. /*!--------------------------------------------------------------------------
  6950. RtrMgrProtocolInterfaceInfo::GetTitle
  6951. -
  6952. Author: KennT
  6953. ---------------------------------------------------------------------------*/
  6954. STDMETHODIMP_(LPCOLESTR) RtrMgrProtocolInterfaceInfo::GetTitle()
  6955. {
  6956. RtrCriticalSection rtrCritSec(&m_critsec);
  6957. return m_cb.stTitle;
  6958. }
  6959. /*!--------------------------------------------------------------------------
  6960. RtrMgrProtocolInterfaceInfo::SetTitle
  6961. -
  6962. Author: KennT
  6963. ---------------------------------------------------------------------------*/
  6964. STDMETHODIMP RtrMgrProtocolInterfaceInfo::SetTitle(LPCOLESTR pszTitle)
  6965. {
  6966. //$UNICODE
  6967. // This assumes that we are native UNICODE
  6968. // and that OLECHAR == WCHAR
  6969. RtrCriticalSection rtrCritSec(&m_critsec);
  6970. HRESULT hr = hrOK;
  6971. COM_PROTECT_TRY
  6972. {
  6973. m_cb.stTitle = pszTitle;
  6974. }
  6975. COM_PROTECT_CATCH;
  6976. return hr;
  6977. }
  6978. /*!--------------------------------------------------------------------------
  6979. RtrMgrProtocolInterfaceInfo::CopyCB
  6980. -
  6981. Author: KennT
  6982. ---------------------------------------------------------------------------*/
  6983. STDMETHODIMP RtrMgrProtocolInterfaceInfo::CopyCB(RtrMgrProtocolInterfaceCB * pRmProtCB)
  6984. {
  6985. RtrCriticalSection rtrCritSec(&m_critsec);
  6986. HRESULT hr = hrOK;
  6987. COM_PROTECT_TRY
  6988. {
  6989. m_cb.SaveTo(pRmProtCB);
  6990. }
  6991. COM_PROTECT_CATCH;
  6992. return hr;
  6993. }
  6994. /*!--------------------------------------------------------------------------
  6995. RtrMgrProtocolInterfaceInfo::RtrAdvise
  6996. -
  6997. Author: KennT
  6998. ---------------------------------------------------------------------------*/
  6999. STDMETHODIMP RtrMgrProtocolInterfaceInfo::RtrAdvise( IRtrAdviseSink *pRtrAdviseSink,
  7000. LONG_PTR *pulConnection, LPARAM lUserParam)
  7001. {
  7002. Assert(pRtrAdviseSink);
  7003. Assert(pulConnection);
  7004. RtrCriticalSection rtrCritSec(&m_critsec);
  7005. LONG_PTR ulConnId;
  7006. HRESULT hr = hrOK;
  7007. COM_PROTECT_TRY
  7008. {
  7009. ulConnId = (LONG_PTR) InterlockedIncrement(&s_cConnections);
  7010. CORg( m_AdviseList.AddConnection(pRtrAdviseSink, ulConnId, lUserParam) );
  7011. *pulConnection = ulConnId;
  7012. COM_PROTECT_ERROR_LABEL;
  7013. }
  7014. COM_PROTECT_CATCH;
  7015. return hr;
  7016. }
  7017. /*!--------------------------------------------------------------------------
  7018. RtrMgrProtocolInterfaceInfo::RtrNotify
  7019. -
  7020. Author: KennT
  7021. ---------------------------------------------------------------------------*/
  7022. STDMETHODIMP RtrMgrProtocolInterfaceInfo::RtrNotify(DWORD dwChangeType, DWORD dwObjectType,
  7023. LPARAM lParam)
  7024. {
  7025. RtrCriticalSection rtrCritSec(&m_critsec);
  7026. HRESULT hr = hrOK;
  7027. COM_PROTECT_TRY
  7028. {
  7029. m_AdviseList.NotifyChange(dwChangeType, dwObjectType, lParam);
  7030. }
  7031. COM_PROTECT_CATCH;
  7032. return hr;
  7033. }
  7034. /*!--------------------------------------------------------------------------
  7035. RtrMgrProtocolInterfaceInfo::RtrUnadvise
  7036. -
  7037. Author: KennT
  7038. ---------------------------------------------------------------------------*/
  7039. STDMETHODIMP RtrMgrProtocolInterfaceInfo::RtrUnadvise( LONG_PTR ulConnection)
  7040. {
  7041. RtrCriticalSection rtrCritSec(&m_critsec);
  7042. return m_AdviseList.RemoveConnection(ulConnection);
  7043. }
  7044. /*!--------------------------------------------------------------------------
  7045. RtrMgrProtocolInterfaceInfo::GetParentRtrMgrInterfaceInfo
  7046. -
  7047. Author: KennT
  7048. ---------------------------------------------------------------------------*/
  7049. STDMETHODIMP RtrMgrProtocolInterfaceInfo::GetParentRtrMgrInterfaceInfo( IRtrMgrInterfaceInfo **ppParent)
  7050. {
  7051. RtrCriticalSection rtrCritSec(&m_critsec);
  7052. HRESULT hr = hrOK;
  7053. COM_PROTECT_TRY
  7054. {
  7055. *ppParent = m_pRtrMgrInterfaceInfoParent;
  7056. if (*ppParent)
  7057. (*ppParent)->AddRef();
  7058. }
  7059. COM_PROTECT_CATCH;
  7060. return hr;
  7061. }
  7062. /*!--------------------------------------------------------------------------
  7063. RtrMgrProtocolInterfaceInfo::SetParentRtrMgrInterfaceInfo
  7064. -
  7065. Author: KennT
  7066. ---------------------------------------------------------------------------*/
  7067. STDMETHODIMP RtrMgrProtocolInterfaceInfo::SetParentRtrMgrInterfaceInfo(IRtrMgrInterfaceInfo *pParent)
  7068. {
  7069. RtrCriticalSection rtrCritSec(&m_critsec);
  7070. IRtrMgrInterfaceInfo * pTemp;
  7071. pTemp = m_pRtrMgrInterfaceInfoParent;
  7072. m_pRtrMgrInterfaceInfoParent = NULL;
  7073. if (m_fStrongRef)
  7074. {
  7075. if (pTemp)
  7076. pTemp->Release();
  7077. if (pParent)
  7078. pParent->AddRef();
  7079. }
  7080. else
  7081. {
  7082. if (pTemp)
  7083. pTemp->ReleaseWeakRef();
  7084. if (pParent)
  7085. pParent->AddWeakRef();
  7086. }
  7087. m_pRtrMgrInterfaceInfoParent = pParent;
  7088. return hrOK;
  7089. }
  7090. void RtrMgrProtocolInterfaceInfo::Disconnect()
  7091. {
  7092. }
  7093. STDMETHODIMP RtrMgrProtocolInterfaceInfo::DoDisconnect()
  7094. {
  7095. HRESULT hr = hrOK;
  7096. COM_PROTECT_TRY
  7097. {
  7098. // Disconnect our data.
  7099. // ------------------------------------------------------------
  7100. Disconnect();
  7101. // Notify the advise sinks of a disconnect.
  7102. // ------------------------------------------------------------
  7103. RtrNotify(ROUTER_DO_DISCONNECT, 0, 0);
  7104. }
  7105. COM_PROTECT_CATCH;
  7106. return hr;
  7107. }
  7108. /*!--------------------------------------------------------------------------
  7109. LoadInfoBase
  7110. -
  7111. Author: KennT
  7112. ---------------------------------------------------------------------------*/
  7113. TFSCORE_API(HRESULT) LoadInfoBase(HANDLE hMachine,
  7114. HANDLE hTransport,
  7115. IInfoBase **ppGlobalInfo,
  7116. IInfoBase **ppClientInfo)
  7117. {
  7118. HRESULT hr = hrOK;
  7119. SPIInfoBase spGlobalInfo;
  7120. SPIInfoBase spClientInfo;
  7121. DWORD dwGlobalBytesSize, dwClientBytesSize;
  7122. BYTE * pGlobalBytes = NULL;
  7123. BYTE * pClientBytes = NULL;
  7124. COM_PROTECT_TRY
  7125. {
  7126. if (ppGlobalInfo)
  7127. CORg( CreateInfoBase(&spGlobalInfo) );
  7128. if (ppClientInfo)
  7129. CORg( CreateInfoBase(&spClientInfo) );
  7130. //
  7131. // Retrieve information for the transport
  7132. //
  7133. CWRg( ::MprConfigTransportGetInfo(
  7134. hMachine,
  7135. hTransport,
  7136. spGlobalInfo ? &pGlobalBytes : NULL,
  7137. spGlobalInfo ? &dwGlobalBytesSize : NULL,
  7138. spClientInfo ? &pClientBytes : NULL,
  7139. spClientInfo ? &dwClientBytesSize : NULL,
  7140. NULL
  7141. ));
  7142. //
  7143. // Load the global info for the router-manager
  7144. //
  7145. if (spGlobalInfo)
  7146. {
  7147. CWRg( spGlobalInfo->LoadFrom(dwGlobalBytesSize, pGlobalBytes) );
  7148. }
  7149. //
  7150. // Load the client info for the router-manager
  7151. //
  7152. if (spClientInfo)
  7153. {
  7154. CWRg( spClientInfo->LoadFrom(dwClientBytesSize, pClientBytes) );
  7155. }
  7156. if (ppGlobalInfo)
  7157. *ppGlobalInfo = spGlobalInfo.Transfer();
  7158. if (ppClientInfo)
  7159. *ppClientInfo = spClientInfo.Transfer();
  7160. COM_PROTECT_ERROR_LABEL;
  7161. }
  7162. COM_PROTECT_CATCH;
  7163. if (pGlobalBytes) { ::MprConfigBufferFree(pGlobalBytes); }
  7164. if (pClientBytes) { ::MprConfigBufferFree(pClientBytes); }
  7165. return hr;
  7166. }