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

1540 lines
40 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. DialIn
  7. Interface node information
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "dialin.h"
  12. #include "ifadmin.h"
  13. #include "rtrstrm.h" // for RouterAdminConfigStream
  14. #include "rtrlib.h" // ContainerColumnInfo
  15. #include "coldlg.h" // ColumnDlg
  16. #include "column.h" // ComponentConfigStream
  17. #include "refresh.h" // IRouterRefresh
  18. #include "iface.h" // for interfacenode data
  19. #include "conndlg.h" // CConnDlg - connection dialog
  20. #include "msgdlg.h" // CMessageDlg
  21. #include "dmvcomp.h"
  22. DialInNodeData::DialInNodeData()
  23. {
  24. #ifdef DEBUG
  25. StrCpyA(m_szDebug, "DialInNodeData");
  26. #endif
  27. }
  28. DialInNodeData::~DialInNodeData()
  29. {
  30. }
  31. /*!--------------------------------------------------------------------------
  32. DialInNodeData::InitAdminNodeData
  33. -
  34. Author: KennT
  35. ---------------------------------------------------------------------------*/
  36. HRESULT DialInNodeData::InitAdminNodeData(ITFSNode *pNode, RouterAdminConfigStream *pConfigStream)
  37. {
  38. HRESULT hr = hrOK;
  39. DialInNodeData * pData = NULL;
  40. pData = new DialInNodeData;
  41. SET_DIALINNODEDATA(pNode, pData);
  42. // Need to connect to the router to get this data
  43. return hr;
  44. }
  45. /*!--------------------------------------------------------------------------
  46. DialInNodeData::FreeAdminNodeData
  47. -
  48. Author: KennT
  49. ---------------------------------------------------------------------------*/
  50. HRESULT DialInNodeData::FreeAdminNodeData(ITFSNode *pNode)
  51. {
  52. DialInNodeData * pData = GET_DIALINNODEDATA(pNode);
  53. delete pData;
  54. SET_DIALINNODEDATA(pNode, NULL);
  55. return hrOK;
  56. }
  57. HRESULT DialInNodeData::LoadHandle(LPCTSTR pszMachineName)
  58. {
  59. m_stMachineName = pszMachineName;
  60. return HResultFromWin32(::MprAdminServerConnect((LPTSTR) pszMachineName,
  61. &m_sphDdmHandle));
  62. }
  63. HANDLE DialInNodeData::GetHandle()
  64. {
  65. if (!m_sphDdmHandle)
  66. {
  67. LoadHandle(m_stMachineName);
  68. }
  69. return m_sphDdmHandle;
  70. }
  71. void DialInNodeData::ReleaseHandles()
  72. {
  73. m_sphDdmHandle.Release();
  74. }
  75. STDMETHODIMP DialInNodeHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  76. {
  77. // Is the pointer bad?
  78. if (ppv == NULL)
  79. return E_INVALIDARG;
  80. // Place NULL in *ppv in case of failure
  81. *ppv = NULL;
  82. // This is the non-delegating IUnknown implementation
  83. if (riid == IID_IUnknown)
  84. *ppv = (LPVOID) this;
  85. else if (riid == IID_IRtrAdviseSink)
  86. *ppv = &m_IRtrAdviseSink;
  87. else
  88. return CHandler::QueryInterface(riid, ppv);
  89. // If we're going to return an interface, AddRef it first
  90. if (*ppv)
  91. {
  92. ((LPUNKNOWN) *ppv)->AddRef();
  93. return hrOK;
  94. }
  95. else
  96. return E_NOINTERFACE;
  97. }
  98. /*---------------------------------------------------------------------------
  99. NodeHandler implementation
  100. ---------------------------------------------------------------------------*/
  101. extern const ContainerColumnInfo s_rgDialInColumnInfo[];
  102. const ContainerColumnInfo s_rgDialInColumnInfo[] =
  103. {
  104. { IDS_DIALIN_COL_USERNAME, CON_SORT_BY_STRING, TRUE, COL_STRING},
  105. { IDS_DIALIN_COL_DURATION, CON_SORT_BY_DWORD, TRUE, COL_DURATION},
  106. { IDS_DIALIN_COL_NUMBEROFPORTS, CON_SORT_BY_DWORD, TRUE, COL_SMALL_NUM},
  107. };
  108. #define NUM_FOLDERS 1
  109. DialInNodeHandler::DialInNodeHandler(ITFSComponentData *pCompData)
  110. : BaseContainerHandler(pCompData, DM_COLUMNS_DIALIN, s_rgDialInColumnInfo),
  111. m_bExpanded(FALSE),
  112. m_pConfigStream(NULL),
  113. m_ulConnId(0),
  114. m_ulRefreshConnId(0),
  115. m_ulPartialRefreshConnId(0)
  116. {
  117. // Setup the verb states for this node
  118. m_rgButtonState[MMC_VERB_REFRESH_INDEX] = ENABLED;
  119. m_bState[MMC_VERB_REFRESH_INDEX] = TRUE;
  120. }
  121. /*!--------------------------------------------------------------------------
  122. DialInNodeHandler::Init
  123. -
  124. Author: KennT
  125. ---------------------------------------------------------------------------*/
  126. HRESULT DialInNodeHandler::Init(IRouterInfo *pRouterInfo, RouterAdminConfigStream *pConfigStream)
  127. {
  128. HRESULT hr = hrOK;
  129. SPIRouterRefresh spRefresh;
  130. // If we don't have a router info then we probably failed to load
  131. // or failed to connect. Bail out of this.
  132. if (!pRouterInfo)
  133. CORg( E_FAIL );
  134. m_spRouterInfo.Set(pRouterInfo);
  135. // Also need to register for change notifications
  136. m_spRouterInfo->RtrAdvise(&m_IRtrAdviseSink, &m_ulConnId, 0);
  137. m_pConfigStream = pConfigStream;
  138. // register the partial refhersh notifications
  139. if( 0 == m_ulPartialRefreshConnId )
  140. {
  141. m_spRouterInfo->GetRefreshObject(&spRefresh);
  142. if(spRefresh)
  143. spRefresh->AdviseRefresh(&m_IRtrAdviseSink, &m_ulPartialRefreshConnId, 0);
  144. }
  145. Error:
  146. return hrOK;
  147. }
  148. /*!--------------------------------------------------------------------------
  149. DialInNodeHandler::DestroyHandler
  150. Implementation of ITFSNodeHandler::DestroyHandler
  151. Author: KennT
  152. ---------------------------------------------------------------------------*/
  153. STDMETHODIMP DialInNodeHandler::DestroyHandler(ITFSNode *pNode)
  154. {
  155. DialInNodeData::FreeAdminNodeData(pNode);
  156. m_spDataObject.Release();
  157. if (m_ulRefreshConnId || m_ulPartialRefreshConnId)
  158. {
  159. SPIRouterRefresh spRefresh;
  160. if (m_spRouterInfo)
  161. m_spRouterInfo->GetRefreshObject(&spRefresh);
  162. if (spRefresh)
  163. {
  164. if(m_ulRefreshConnId)
  165. spRefresh->UnadviseRefresh(m_ulRefreshConnId);
  166. if(m_ulPartialRefreshConnId)
  167. spRefresh->UnadviseRefresh(m_ulPartialRefreshConnId);
  168. }
  169. }
  170. m_ulRefreshConnId = 0;
  171. m_ulPartialRefreshConnId = 0;
  172. if (m_spRouterInfo)
  173. {
  174. m_spRouterInfo->RtrUnadvise(m_ulConnId);
  175. m_spRouterInfo.Release();
  176. }
  177. return hrOK;
  178. }
  179. /*!--------------------------------------------------------------------------
  180. DialInNodeHandler::HasPropertyPages
  181. Implementation of ITFSNodeHandler::HasPropertyPages
  182. ---------------------------------------------------------------------------*/
  183. STDMETHODIMP
  184. DialInNodeHandler::HasPropertyPages
  185. (
  186. ITFSNode * pNode,
  187. LPDATAOBJECT pDataObject,
  188. DATA_OBJECT_TYPES type,
  189. DWORD dwType
  190. )
  191. {
  192. // we have no property pages in the normal case
  193. return hrFalse;
  194. }
  195. /*---------------------------------------------------------------------------
  196. Menu data structure for our menus
  197. ---------------------------------------------------------------------------*/
  198. static const SRouterNodeMenu s_rgDialInNodeMenu[] =
  199. {
  200. // Add items that are primary go here
  201. { IDS_MENU_DIALIN_SENDALL, DialInNodeHandler::GetSendAllMenuFlags,
  202. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  203. // Add items that go on the "Create new" menu here
  204. // Add items that go on the "Task" menu here
  205. };
  206. ULONG DialInNodeHandler::GetSendAllMenuFlags(const SRouterNodeMenu *pMenuData,
  207. INT_PTR pUserData)
  208. {
  209. ULONG ulFlags = 0;
  210. SMenuData * pData = reinterpret_cast<SMenuData *>(pUserData);
  211. if (pData)
  212. {
  213. int iVis, iTotal;
  214. pData->m_spNode->GetChildCount(&iVis, &iTotal);
  215. if (iTotal == 0)
  216. ulFlags = MF_GRAYED;
  217. }
  218. return ulFlags;
  219. }
  220. /*!--------------------------------------------------------------------------
  221. DialInNodeHandler::OnAddMenuItems
  222. Implementation of ITFSNodeHandler::OnAddMenuItems
  223. Author: KennT
  224. ---------------------------------------------------------------------------*/
  225. STDMETHODIMP DialInNodeHandler::OnAddMenuItems(
  226. ITFSNode *pNode,
  227. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  228. LPDATAOBJECT lpDataObject,
  229. DATA_OBJECT_TYPES type,
  230. DWORD dwType,
  231. long *pInsertionAllowed)
  232. {
  233. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  234. HRESULT hr = S_OK;
  235. DialInNodeHandler::SMenuData menuData;
  236. COM_PROTECT_TRY
  237. {
  238. menuData.m_spNode.Set(pNode);
  239. hr = AddArrayOfMenuItems(pNode, s_rgDialInNodeMenu,
  240. DimensionOf(s_rgDialInNodeMenu),
  241. pContextMenuCallback,
  242. *pInsertionAllowed,
  243. reinterpret_cast<INT_PTR>(&menuData));
  244. }
  245. COM_PROTECT_CATCH;
  246. return hr;
  247. }
  248. /*!--------------------------------------------------------------------------
  249. DialInNodeHandler::OnCommand
  250. Implementation of ITFSNodeHandler::OnCommand
  251. Author: KennT
  252. ---------------------------------------------------------------------------*/
  253. STDMETHODIMP DialInNodeHandler::OnCommand(ITFSNode *pNode, long nCommandId,
  254. DATA_OBJECT_TYPES type,
  255. LPDATAOBJECT pDataObject,
  256. DWORD dwType)
  257. {
  258. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  259. if (nCommandId == IDS_MENU_DIALIN_SENDALL)
  260. {
  261. WCHAR * pswzComputerName;
  262. // Get the machine name out of the data object
  263. pswzComputerName = ExtractComputerName(pDataObject);
  264. CMessageDlg dlg(m_spRouterInfo->GetMachineName(), W2CT(pswzComputerName), NULL);
  265. dlg.DoModal();
  266. }
  267. return hrOK;
  268. }
  269. /*!--------------------------------------------------------------------------
  270. DialInNodeHandler::GetString
  271. Implementation of ITFSNodeHandler::GetString
  272. Author: KennT
  273. ---------------------------------------------------------------------------*/
  274. STDMETHODIMP_(LPCTSTR) DialInNodeHandler::GetString(ITFSNode *pNode, int nCol)
  275. {
  276. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  277. HRESULT hr = hrOK;
  278. COM_PROTECT_TRY
  279. {
  280. if (m_stTitle.IsEmpty())
  281. m_stTitle.LoadString(IDS_DIALIN_USERS);
  282. }
  283. COM_PROTECT_CATCH;
  284. return m_stTitle;
  285. }
  286. /*!--------------------------------------------------------------------------
  287. DialInNodeHandler::OnCreateDataObject
  288. Implementation of ITFSNodeHandler::OnCreateDataObject
  289. Author: KennT
  290. ---------------------------------------------------------------------------*/
  291. STDMETHODIMP DialInNodeHandler::OnCreateDataObject(MMC_COOKIE cookie,
  292. DATA_OBJECT_TYPES type,
  293. IDataObject **ppDataObject)
  294. {
  295. HRESULT hr = hrOK;
  296. COM_PROTECT_TRY
  297. {
  298. if (!m_spDataObject)
  299. {
  300. CORg( CreateDataObjectFromRouterInfo(m_spRouterInfo,
  301. m_spRouterInfo->GetMachineName(),
  302. type, cookie, m_spTFSCompData,
  303. &m_spDataObject, NULL, FALSE) );
  304. Assert(m_spDataObject);
  305. }
  306. *ppDataObject = m_spDataObject;
  307. (*ppDataObject)->AddRef();
  308. COM_PROTECT_ERROR_LABEL;
  309. }
  310. COM_PROTECT_CATCH;
  311. return hr;
  312. }
  313. /*!--------------------------------------------------------------------------
  314. DialInNodeHandler::OnExpand
  315. -
  316. Author: KennT
  317. ---------------------------------------------------------------------------*/
  318. HRESULT DialInNodeHandler::OnExpand(ITFSNode *pNode,
  319. LPDATAOBJECT pDataObject,
  320. DWORD dwType,
  321. LPARAM arg,
  322. LPARAM lParam)
  323. {
  324. HRESULT hr = hrOK;
  325. SPIEnumInterfaceInfo spEnumIf;
  326. SPIInterfaceInfo spIf;
  327. // If we don't have a router object, then we don't have any info, don't
  328. // try to expand.
  329. if (!m_spRouterInfo)
  330. return hrOK;
  331. if (m_bExpanded)
  332. return hrOK;
  333. COM_PROTECT_TRY
  334. {
  335. SynchronizeNodeData(pNode);
  336. m_bExpanded = TRUE;
  337. }
  338. COM_PROTECT_CATCH;
  339. return hr;
  340. }
  341. /*!--------------------------------------------------------------------------
  342. DialInNodeHandler::OnResultShow
  343. -
  344. Author: KennT
  345. ---------------------------------------------------------------------------*/
  346. HRESULT DialInNodeHandler::OnResultShow(ITFSComponent *pTFSComponent,
  347. MMC_COOKIE cookie,
  348. LPARAM arg,
  349. LPARAM lParam)
  350. {
  351. BOOL bSelect = (BOOL) arg;
  352. HRESULT hr = hrOK;
  353. SPIRouterRefresh spRefresh;
  354. SPITFSNode spNode;
  355. BaseContainerHandler::OnResultShow(pTFSComponent, cookie, arg, lParam);
  356. if (bSelect)
  357. {
  358. // Call synchronize on this node
  359. m_spNodeMgr->FindNode(cookie, &spNode);
  360. if (spNode)
  361. SynchronizeNodeData(spNode);
  362. }
  363. // Un/Register for refresh advises
  364. if (m_spRouterInfo)
  365. m_spRouterInfo->GetRefreshObject(&spRefresh);
  366. if (spRefresh)
  367. {
  368. if (bSelect)
  369. {
  370. if (m_ulRefreshConnId == 0)
  371. spRefresh->AdviseRefresh(&m_IRtrAdviseSink, &m_ulRefreshConnId, 0);
  372. if (m_ulPartialRefreshConnId)
  373. {
  374. spRefresh->UnadviseRefresh(m_ulPartialRefreshConnId);
  375. m_ulPartialRefreshConnId = 0;
  376. }
  377. }
  378. else
  379. {
  380. if (m_ulRefreshConnId)
  381. spRefresh->UnadviseRefresh(m_ulRefreshConnId);
  382. m_ulRefreshConnId = 0;
  383. if (m_ulPartialRefreshConnId == 0)
  384. spRefresh->AdviseRefresh(&m_IRtrAdviseSink, &m_ulPartialRefreshConnId, 0);
  385. }
  386. }
  387. return hr;
  388. }
  389. /*!--------------------------------------------------------------------------
  390. DialInNodeHandler::ConstructNode
  391. Initializes the Domain node (sets it up).
  392. Author: KennT
  393. ---------------------------------------------------------------------------*/
  394. HRESULT DialInNodeHandler::ConstructNode(ITFSNode *pNode)
  395. {
  396. HRESULT hr = hrOK;
  397. DialInNodeData * pNodeData;
  398. if (pNode == NULL)
  399. return hrOK;
  400. COM_PROTECT_TRY
  401. {
  402. // Need to initialize the data for the Domain node
  403. pNode->SetData(TFS_DATA_IMAGEINDEX, IMAGE_IDX_INTERFACES);
  404. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, IMAGE_IDX_INTERFACES);
  405. pNode->SetData(TFS_DATA_SCOPEID, 0);
  406. // This is a leaf node in the scope pane
  407. pNode->SetData(TFS_DATA_SCOPE_LEAF_NODE, TRUE);
  408. m_cookie = reinterpret_cast<MMC_COOKIE>(pNode);
  409. pNode->SetData(TFS_DATA_COOKIE, m_cookie);
  410. pNode->SetNodeType(&GUID_RouterDialInNodeType);
  411. DialInNodeData::InitAdminNodeData(pNode, m_pConfigStream);
  412. pNodeData = GET_DIALINNODEDATA(pNode);
  413. Assert(pNodeData);
  414. // Ignore the error, we should be able to deal with the
  415. // case of a stopped router.
  416. pNodeData->LoadHandle(m_spRouterInfo->GetMachineName());
  417. PartialSynchronizeNodeData(pNode);
  418. }
  419. COM_PROTECT_CATCH
  420. return hr;
  421. }
  422. /*!--------------------------------------------------------------------------
  423. DialInNodeHandler::SynchronizeNodeData
  424. -
  425. Author: KennT
  426. ---------------------------------------------------------------------------*/
  427. HRESULT DialInNodeHandler::SynchronizeNodeData(ITFSNode *pThisNode)
  428. {
  429. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  430. Assert(pThisNode);
  431. SPITFSNodeEnum spEnum;
  432. int i;
  433. HRESULT hr = hrOK;
  434. DWORD dwTotalCount = 0;
  435. DialInNodeData * pNodeData;
  436. DialInList dialinList;
  437. DialInList newDialInList;
  438. DialInListEntry * pDialIn;
  439. BOOL fFound;
  440. POSITION pos;
  441. SPITFSNode spChildNode;
  442. InterfaceNodeData * pChildData;
  443. int nChildCount;
  444. COM_PROTECT_TRY
  445. {
  446. // Get the status data from the running router
  447. pNodeData = GET_DIALINNODEDATA(pThisNode);
  448. if (pNodeData == NULL)
  449. {
  450. // Remove all of the nodes, we can't connect so we can't
  451. // get any running data.
  452. UnmarkAllNodes(pThisNode, spEnum);
  453. RemoveAllUnmarkedNodes(pThisNode, spEnum);
  454. m_stTitle.LoadString(IDS_DIALIN_USERS);
  455. pThisNode->ChangeNode(SCOPE_PANE_CHANGE_ITEM_DATA);
  456. return hrOK;
  457. }
  458. // Unmark all of the nodes
  459. pThisNode->GetEnum(&spEnum);
  460. UnmarkAllNodes(pThisNode, spEnum);
  461. // Go out and grab the data, merge the the new data in with
  462. // the old data.
  463. CORg( GenerateListOfUsers(pThisNode, &dialinList, &dwTotalCount) );
  464. pos = dialinList.GetHeadPosition();
  465. while (pos)
  466. {
  467. pDialIn = & dialinList.GetNext(pos);
  468. // Look for this entry in our current list of nodes
  469. spEnum->Reset();
  470. spChildNode.Release();
  471. fFound = FALSE;
  472. for (;spEnum->Next(1, &spChildNode, NULL) == hrOK; spChildNode.Release())
  473. {
  474. pChildData = GET_INTERFACENODEDATA(spChildNode);
  475. Assert(pChildData);
  476. if (pChildData->m_rgData[DIALIN_SI_CONNECTION].m_ulData ==
  477. reinterpret_cast<LONG_PTR>(pDialIn->m_rc0.hConnection))
  478. {
  479. // Ok, this user already exists, update the metric
  480. // and mark it
  481. Assert(pChildData->dwMark == FALSE);
  482. pChildData->dwMark = TRUE;
  483. fFound = TRUE;
  484. SetUserData(spChildNode, *pDialIn);
  485. // Force MMC to redraw the node
  486. spChildNode->ChangeNode(RESULT_PANE_CHANGE_ITEM_DATA);
  487. break;
  488. }
  489. }
  490. if (!fFound)
  491. newDialInList.AddTail(*pDialIn);
  492. }
  493. // In case of an error (such as we cannot contact the server)
  494. // we want to remove the unmarked nodes.
  495. COM_PROTECT_ERROR_LABEL;
  496. // Remove all nodes that were not marked
  497. RemoveAllUnmarkedNodes(pThisNode, spEnum);
  498. // Now iterate through the list of new users, adding them all in.
  499. pos = newDialInList.GetHeadPosition();
  500. while (pos)
  501. {
  502. pDialIn = & newDialInList.GetNext(pos);
  503. AddDialInUserNode(pThisNode, *pDialIn);
  504. }
  505. // NT BUG #163162, put the connected client count into the
  506. // title of the node
  507. if (FHrSucceeded(hr))
  508. m_stTitle.Format(IDS_DIALIN_USERS_NUM, dwTotalCount);
  509. else
  510. m_stTitle.Format(IDS_DIALIN_USERS);
  511. pThisNode->ChangeNode(SCOPE_PANE_CHANGE_ITEM_DATA);
  512. }
  513. COM_PROTECT_CATCH;
  514. return hr;
  515. }
  516. /*!--------------------------------------------------------------------------
  517. DialInNodeHandler::PartialSynchronizeNodeData
  518. -
  519. Description: For Bug #163162 Only refresh dialin user count on the the node title
  520. Author: NSun
  521. ---------------------------------------------------------------------------*/
  522. HRESULT DialInNodeHandler::PartialSynchronizeNodeData(ITFSNode *pThisNode)
  523. {
  524. Assert(pThisNode);
  525. SPITFSNodeEnum spEnum;
  526. int i;
  527. HRESULT hr = hrOK;
  528. DWORD dwCount = 0;
  529. DialInNodeData * pNodeData;
  530. int iFormat;
  531. COM_PROTECT_TRY
  532. {
  533. // Get the status data from the running router
  534. pNodeData = GET_DIALINNODEDATA(pThisNode);
  535. if (pNodeData == NULL)
  536. {
  537. // Remove all of the nodes, we can't connect so we can't
  538. // get any running data.
  539. iFormat = IDS_DIALIN_USERS;
  540. }
  541. else
  542. {
  543. // Get the count of dial-in clients and put the number
  544. // in the node title
  545. hr = GenerateListOfUsers(pThisNode, NULL, &dwCount);
  546. if (FHrSucceeded(hr))
  547. iFormat = IDS_DIALIN_USERS_NUM;
  548. else
  549. iFormat = IDS_DIALIN_USERS;
  550. }
  551. m_stTitle.Format(iFormat, dwCount);
  552. pThisNode->ChangeNode(SCOPE_PANE_CHANGE_ITEM_DATA);
  553. }
  554. COM_PROTECT_CATCH;
  555. return hr;
  556. }
  557. /*!--------------------------------------------------------------------------
  558. DialInNodeHandler::SetUserData
  559. -
  560. Author: KennT
  561. ---------------------------------------------------------------------------*/
  562. HRESULT DialInNodeHandler::SetUserData(ITFSNode *pNode, const DialInListEntry& entry)
  563. {
  564. HRESULT hr = hrOK;
  565. InterfaceNodeData * pData;
  566. TCHAR szNumber[32];
  567. CString st;
  568. pData = GET_INTERFACENODEDATA(pNode);
  569. Assert(pData);
  570. if (entry.m_rc0.dwInterfaceType != ROUTER_IF_TYPE_CLIENT)
  571. {
  572. pData->m_rgData[DIALIN_SI_USERNAME].m_stData =
  573. entry.m_rc0.wszInterfaceName;
  574. }
  575. else
  576. {
  577. if (StrLenW(entry.m_rc0.wszLogonDomain))
  578. {
  579. if (StrLenW(entry.m_rc0.wszUserName))
  580. st.Format(IDS_DIALINUSR_DOMAIN_AND_NAME,
  581. entry.m_rc0.wszLogonDomain,
  582. entry.m_rc0.wszUserName);
  583. else
  584. st.Format(IDS_DIALINUSR_DOMAIN_ONLY,
  585. entry.m_rc0.wszLogonDomain);
  586. }
  587. else
  588. st = entry.m_rc0.wszUserName;
  589. pData->m_rgData[DIALIN_SI_USERNAME].m_stData = st;
  590. }
  591. pData->m_rgData[DIALIN_SI_DOMAIN].m_stData = entry.m_rc0.wszLogonDomain;
  592. pData->m_rgData[DIALIN_SI_CONNECTION].m_ulData = reinterpret_cast<LONG_PTR>(entry.m_rc0.hConnection);
  593. FormatDuration(entry.m_rc0.dwConnectDuration,
  594. pData->m_rgData[DIALIN_SI_DURATION].m_stData, UNIT_SECONDS);
  595. pData->m_rgData[DIALIN_SI_DURATION].m_dwData = entry.m_rc0.dwConnectDuration;
  596. FormatNumber(entry.m_cPorts, szNumber, DimensionOf(szNumber), FALSE);
  597. pData->m_rgData[DIALIN_SI_NUMBEROFPORTS].m_dwData = entry.m_cPorts;
  598. pData->m_rgData[DIALIN_SI_NUMBEROFPORTS].m_stData = szNumber;
  599. return hr;
  600. }
  601. /*!--------------------------------------------------------------------------
  602. DialInNodeHandler::GenerateListOfUsers
  603. -
  604. Author: KennT
  605. Note: If pList is NULL, then only the count of items is returned
  606. ---------------------------------------------------------------------------*/
  607. HRESULT DialInNodeHandler::GenerateListOfUsers(ITFSNode *pNode, DialInList *pList, DWORD *pdwCount)
  608. {
  609. DialInListEntry entry;
  610. DialInNodeData * pDialInData;
  611. DWORD dwTotal;
  612. DWORD rc0Count;
  613. RAS_CONNECTION_0 *rc0Table;
  614. HRESULT hr = hrOK;
  615. DWORD i;
  616. RAS_PORT_0 * rp0Table;
  617. DWORD rp0Count;
  618. SPMprAdminBuffer spMpr;
  619. POSITION pos;
  620. DialInListEntry * pEntry;
  621. DWORD dwClientCount;
  622. pDialInData = GET_DIALINNODEDATA(pNode);
  623. Assert(pDialInData);
  624. // Fill in the list with all of the current connections
  625. CWRg( ::MprAdminConnectionEnum(pDialInData->GetHandle(),
  626. 0,
  627. (BYTE **) &rc0Table,
  628. (DWORD) -1,
  629. &rc0Count,
  630. &dwTotal,
  631. NULL
  632. ));
  633. Assert(rc0Table);
  634. spMpr = (LPBYTE) rc0Table;
  635. dwClientCount = 0;
  636. // Add a new DialInListEntry for each connection
  637. for (i=0; i<rc0Count; i++)
  638. {
  639. // Windows NT Bug : 124371
  640. // Need to filter out non-client connections
  641. // ------------------------------------------------------------
  642. if (rc0Table[i].dwInterfaceType != ROUTER_IF_TYPE_CLIENT)
  643. continue;
  644. dwClientCount++;
  645. if( pList != NULL )
  646. {
  647. ::ZeroMemory(&entry, sizeof(entry));
  648. entry.m_rc0 = rc0Table[i];
  649. entry.m_cPorts = 0;
  650. pList->AddTail(entry);
  651. }
  652. }
  653. spMpr.Free();
  654. if( pdwCount != NULL )
  655. *pdwCount = dwClientCount;
  656. //if pList is NULL, we are only intereted in the count
  657. if( NULL == pList )
  658. goto Error;
  659. // If the list is empty, there is no need to enumerate the ports
  660. // to match them up to the connections.
  661. // ----------------------------------------------------------------
  662. if (!pList->IsEmpty())
  663. {
  664. // Now go through the ports, matching them up against the connections
  665. CWRg( ::MprAdminPortEnum( pDialInData->GetHandle(),
  666. 0,
  667. INVALID_HANDLE_VALUE,
  668. (BYTE **) &rp0Table,
  669. (DWORD) -1,
  670. &rp0Count,
  671. &dwTotal,
  672. NULL) );
  673. spMpr = (LPBYTE) rp0Table;
  674. for (i=0; i<rp0Count; i++)
  675. {
  676. // Look through the list of connections for one that
  677. // matches
  678. pos = pList->GetHeadPosition();
  679. while (pos)
  680. {
  681. pEntry = & pList->GetNext(pos);
  682. if (pEntry->m_rc0.hConnection == rp0Table[i].hConnection)
  683. {
  684. pEntry->m_cPorts++;
  685. break;
  686. }
  687. }
  688. }
  689. }
  690. Error:
  691. return hr;
  692. }
  693. ImplementEmbeddedUnknown(DialInNodeHandler, IRtrAdviseSink)
  694. STDMETHODIMP DialInNodeHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  695. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  696. {
  697. InitPThis(DialInNodeHandler, IRtrAdviseSink);
  698. SPITFSNode spThisNode;
  699. HRESULT hr = hrOK;
  700. COM_PROTECT_TRY
  701. {
  702. pThis->m_spNodeMgr->FindNode(pThis->m_cookie, &spThisNode);
  703. if (dwChangeType == ROUTER_REFRESH)
  704. {
  705. //(nsun) Bug 163162, We have two Refresh Connection ID for this node and we only
  706. // partially refresh (just refresh the node title) if this node is not at focus
  707. if( ulConn == pThis->m_ulRefreshConnId )
  708. {
  709. // Ok, just call the synchronize on this node
  710. pThis->SynchronizeNodeData(spThisNode);
  711. }
  712. else if( ulConn == pThis->m_ulPartialRefreshConnId )
  713. {
  714. pThis->PartialSynchronizeNodeData(spThisNode);
  715. }
  716. }
  717. else if (dwChangeType == ROUTER_DO_DISCONNECT)
  718. {
  719. DialInNodeData * pNodeData;
  720. pNodeData = GET_DIALINNODEDATA(spThisNode);
  721. Assert(pNodeData);
  722. // Release the handle
  723. pNodeData->ReleaseHandles();
  724. }
  725. }
  726. COM_PROTECT_CATCH;
  727. return hr;
  728. }
  729. /*!--------------------------------------------------------------------------
  730. DialInNodeHandler::CompareItems
  731. Implementation of ITFSResultHandler::CompareItems
  732. Author: KennT
  733. ---------------------------------------------------------------------------*/
  734. STDMETHODIMP_(int) DialInNodeHandler::CompareItems(
  735. ITFSComponent * pComponent,
  736. MMC_COOKIE cookieA,
  737. MMC_COOKIE cookieB,
  738. int nCol)
  739. {
  740. // Get the strings from the nodes and use that as a basis for
  741. // comparison.
  742. SPITFSNode spNode;
  743. SPITFSResultHandler spResult;
  744. m_spNodeMgr->FindNode(cookieA, &spNode);
  745. spNode->GetResultHandler(&spResult);
  746. return spResult->CompareItems(pComponent, cookieA, cookieB, nCol);
  747. }
  748. /*---------------------------------------------------------------------------
  749. This is the set of menus that will appear when a right-click is
  750. done on the blank area of the result pane.
  751. ---------------------------------------------------------------------------*/
  752. static const SRouterNodeMenu s_rgDialInResultNodeMenu[] =
  753. {
  754. // Add items that go on the "Create New" menu here
  755. { IDS_MENU_DIALIN_SENDALL, DialInNodeHandler::GetSendAllMenuFlags,
  756. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  757. };
  758. /*!--------------------------------------------------------------------------
  759. DialInNodeHandler::AddMenuItems
  760. Implementation of ITFSResultHandler::AddMenuItems
  761. Use this to add commands to the context menu of the blank areas
  762. of the result pane.
  763. Author: KennT
  764. ---------------------------------------------------------------------------*/
  765. STDMETHODIMP DialInNodeHandler::AddMenuItems(ITFSComponent *pComponent,
  766. MMC_COOKIE cookie,
  767. LPDATAOBJECT pDataObject,
  768. LPCONTEXTMENUCALLBACK pCallback,
  769. long *pInsertionAllowed)
  770. {
  771. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  772. HRESULT hr = hrOK;
  773. SPITFSNode spNode;
  774. DialInNodeHandler::SMenuData menuData;
  775. COM_PROTECT_TRY
  776. {
  777. m_spNodeMgr->FindNode(cookie, &spNode);
  778. menuData.m_spNode.Set(spNode);
  779. hr = AddArrayOfMenuItems(spNode,
  780. s_rgDialInResultNodeMenu,
  781. DimensionOf(s_rgDialInResultNodeMenu),
  782. pCallback,
  783. *pInsertionAllowed,
  784. reinterpret_cast<INT_PTR>(&menuData));
  785. }
  786. COM_PROTECT_CATCH;
  787. return hr;
  788. }
  789. /*!--------------------------------------------------------------------------
  790. DialInNodeHandler::Command
  791. -
  792. Author: KennT
  793. ---------------------------------------------------------------------------*/
  794. STDMETHODIMP DialInNodeHandler::Command(ITFSComponent *pComponent,
  795. MMC_COOKIE cookie,
  796. int nCommandID,
  797. LPDATAOBJECT pDataObject)
  798. {
  799. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  800. SPITFSNode spNode;
  801. HRESULT hr = hrOK;
  802. m_spNodeMgr->FindNode(cookie, &spNode);
  803. hr = OnCommand(spNode,
  804. nCommandID,
  805. CCT_RESULT,
  806. pDataObject,
  807. TFS_COMPDATA_CHILD_CONTEXTMENU);
  808. return hr;
  809. }
  810. /*!--------------------------------------------------------------------------
  811. DialInNodeHandler::AddDialInUserNode
  812. Adds a user to the UI. This will create a new result item
  813. node for each interface.
  814. Author: KennT
  815. ---------------------------------------------------------------------------*/
  816. HRESULT DialInNodeHandler::AddDialInUserNode(ITFSNode *pParent, const DialInListEntry& dialinEntry)
  817. {
  818. DialInUserHandler * pHandler;
  819. SPITFSResultHandler spHandler;
  820. SPITFSNode spNode;
  821. HRESULT hr = hrOK;
  822. pHandler = new DialInUserHandler(m_spTFSCompData);
  823. spHandler = pHandler;
  824. CORg( pHandler->Init(m_spRouterInfo, pParent) );
  825. CORg( CreateLeafTFSNode(&spNode,
  826. NULL,
  827. static_cast<ITFSNodeHandler *>(pHandler),
  828. static_cast<ITFSResultHandler *>(pHandler),
  829. m_spNodeMgr) );
  830. CORg( pHandler->ConstructNode(spNode, NULL, &dialinEntry) );
  831. SetUserData(spNode, dialinEntry);
  832. // Make the node immediately visible
  833. CORg( spNode->SetVisibilityState(TFS_VIS_SHOW) );
  834. CORg( pParent->AddChild(spNode) );
  835. Error:
  836. return hr;
  837. }
  838. /*!--------------------------------------------------------------------------
  839. DialInNodeHandler::UnmarkAllNodes
  840. -
  841. Author: KennT
  842. ---------------------------------------------------------------------------*/
  843. HRESULT DialInNodeHandler::UnmarkAllNodes(ITFSNode *pNode, ITFSNodeEnum *pEnum)
  844. {
  845. SPITFSNode spChildNode;
  846. InterfaceNodeData * pNodeData;
  847. pEnum->Reset();
  848. for ( ;pEnum->Next(1, &spChildNode, NULL) == hrOK; spChildNode.Release())
  849. {
  850. pNodeData = GET_INTERFACENODEDATA(spChildNode);
  851. Assert(pNodeData);
  852. pNodeData->dwMark = FALSE;
  853. }
  854. return hrOK;
  855. }
  856. /*!--------------------------------------------------------------------------
  857. DialInNodeHandler::RemoveAllUnmarkedNodes
  858. -
  859. Author: KennT
  860. ---------------------------------------------------------------------------*/
  861. HRESULT DialInNodeHandler::RemoveAllUnmarkedNodes(ITFSNode *pNode, ITFSNodeEnum *pEnum)
  862. {
  863. HRESULT hr = hrOK;
  864. SPITFSNode spChildNode;
  865. InterfaceNodeData * pNodeData;
  866. pEnum->Reset();
  867. for ( ;pEnum->Next(1, &spChildNode, NULL) == hrOK; spChildNode.Release())
  868. {
  869. pNodeData = GET_INTERFACENODEDATA(spChildNode);
  870. Assert(pNodeData);
  871. if (pNodeData->dwMark == FALSE)
  872. {
  873. pNode->RemoveChild(spChildNode);
  874. spChildNode->Destroy();
  875. }
  876. }
  877. return hr;
  878. }
  879. /*---------------------------------------------------------------------------
  880. DialInUserHandler implementation
  881. ---------------------------------------------------------------------------*/
  882. DEBUG_DECLARE_INSTANCE_COUNTER(DialInUserHandler)
  883. IMPLEMENT_ADDREF_RELEASE(DialInUserHandler)
  884. STDMETHODIMP DialInUserHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  885. {
  886. // Is the pointer bad?
  887. if (ppv == NULL)
  888. return E_INVALIDARG;
  889. // Place NULL in *ppv in case of failure
  890. *ppv = NULL;
  891. // This is the non-delegating IUnknown implementation
  892. if (riid == IID_IUnknown)
  893. *ppv = (LPVOID) this;
  894. else if (riid == IID_IRtrAdviseSink)
  895. *ppv = &m_IRtrAdviseSink;
  896. else
  897. return CBaseResultHandler::QueryInterface(riid, ppv);
  898. // If we're going to return an interface, AddRef it first
  899. if (*ppv)
  900. {
  901. ((LPUNKNOWN) *ppv)->AddRef();
  902. return hrOK;
  903. }
  904. else
  905. return E_NOINTERFACE;
  906. }
  907. /*---------------------------------------------------------------------------
  908. NodeHandler implementation
  909. ---------------------------------------------------------------------------*/
  910. DialInUserHandler::DialInUserHandler(ITFSComponentData *pCompData)
  911. : BaseRouterHandler(pCompData),
  912. m_ulConnId(0)
  913. {
  914. DEBUG_INCREMENT_INSTANCE_COUNTER(DialInUserHandler);
  915. // Setup the verb states for this node
  916. // ----------------------------------------------------------------
  917. m_rgButtonState[MMC_VERB_REFRESH_INDEX] = ENABLED;
  918. m_bState[MMC_VERB_REFRESH_INDEX] = TRUE;
  919. }
  920. /*!--------------------------------------------------------------------------
  921. DialInUserHandler::Init
  922. -
  923. Author: KennT
  924. ---------------------------------------------------------------------------*/
  925. HRESULT DialInUserHandler::Init(IRouterInfo *pInfo, ITFSNode *pParent)
  926. {
  927. m_spRouterInfo.Set(pInfo);
  928. return hrOK;
  929. }
  930. /*!--------------------------------------------------------------------------
  931. DialInUserHandler::DestroyResultHandler
  932. -
  933. Author: KennT
  934. ---------------------------------------------------------------------------*/
  935. STDMETHODIMP DialInUserHandler::DestroyResultHandler(MMC_COOKIE cookie)
  936. {
  937. SPITFSNode spNode;
  938. m_spNodeMgr->FindNode(cookie, &spNode);
  939. InterfaceNodeData::Free(spNode);
  940. CHandler::DestroyResultHandler(cookie);
  941. return hrOK;
  942. }
  943. static DWORD s_rgInterfaceImageMap[] =
  944. {
  945. ROUTER_IF_TYPE_HOME_ROUTER, IMAGE_IDX_WAN_CARD,
  946. ROUTER_IF_TYPE_FULL_ROUTER, IMAGE_IDX_WAN_CARD,
  947. ROUTER_IF_TYPE_CLIENT, IMAGE_IDX_WAN_CARD,
  948. ROUTER_IF_TYPE_DEDICATED, IMAGE_IDX_LAN_CARD,
  949. ROUTER_IF_TYPE_INTERNAL, IMAGE_IDX_LAN_CARD,
  950. ROUTER_IF_TYPE_LOOPBACK, IMAGE_IDX_LAN_CARD,
  951. -1, IMAGE_IDX_WAN_CARD, // sentinel value
  952. };
  953. /*!--------------------------------------------------------------------------
  954. DialInUserHandler::ConstructNode
  955. Initializes the Domain node (sets it up).
  956. Author: KennT
  957. ---------------------------------------------------------------------------*/
  958. HRESULT DialInUserHandler::ConstructNode(ITFSNode *pNode,
  959. IInterfaceInfo *pIfInfo,
  960. const DialInListEntry *pEntry)
  961. {
  962. HRESULT hr = hrOK;
  963. int i;
  964. Assert(pEntry);
  965. if (pNode == NULL)
  966. return hrOK;
  967. COM_PROTECT_TRY
  968. {
  969. // Need to initialize the data for the Domain node
  970. pNode->SetData(TFS_DATA_IMAGEINDEX, IMAGE_IDX_INTERFACES);
  971. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, IMAGE_IDX_INTERFACES);
  972. pNode->SetData(TFS_DATA_SCOPEID, 0);
  973. pNode->SetData(TFS_DATA_COOKIE, reinterpret_cast<LONG_PTR>(pNode));
  974. //$ Review: kennt, what are the different type of interfaces
  975. // do we distinguish based on the same list as above? (i.e. the
  976. // one for image indexes).
  977. pNode->SetNodeType(&GUID_RouterDialInResultNodeType);
  978. m_entry = *pEntry;
  979. InterfaceNodeData::Init(pNode, pIfInfo);
  980. }
  981. COM_PROTECT_CATCH
  982. return hr;
  983. }
  984. /*!--------------------------------------------------------------------------
  985. DialInUserHandler::GetString
  986. -
  987. Author: KennT
  988. ---------------------------------------------------------------------------*/
  989. STDMETHODIMP_(LPCTSTR) DialInUserHandler::GetString(ITFSComponent * pComponent,
  990. MMC_COOKIE cookie,
  991. int nCol)
  992. {
  993. Assert(m_spNodeMgr);
  994. SPITFSNode spNode;
  995. InterfaceNodeData * pData;
  996. ConfigStream * pConfig;
  997. m_spNodeMgr->FindNode(cookie, &spNode);
  998. Assert(spNode);
  999. pData = GET_INTERFACENODEDATA(spNode);
  1000. Assert(pData);
  1001. pComponent->GetUserData((LONG_PTR *) &pConfig);
  1002. Assert(pConfig);
  1003. return pData->m_rgData[pConfig->MapColumnToSubitem(DM_COLUMNS_DIALIN, nCol)].m_stData;
  1004. }
  1005. /*!--------------------------------------------------------------------------
  1006. DialInUserHandler::CompareItems
  1007. -
  1008. Author: KennT
  1009. ---------------------------------------------------------------------------*/
  1010. STDMETHODIMP_(int) DialInUserHandler::CompareItems(ITFSComponent * pComponent,
  1011. MMC_COOKIE cookieA,
  1012. MMC_COOKIE cookieB,
  1013. int nCol)
  1014. {
  1015. ConfigStream * pConfig;
  1016. pComponent->GetUserData((LONG_PTR *) &pConfig);
  1017. Assert(pConfig);
  1018. int nSubItem = pConfig->MapColumnToSubitem(DM_COLUMNS_DIALIN, nCol);
  1019. if (pConfig->GetSortCriteria(DM_COLUMNS_DIALIN, nCol) == CON_SORT_BY_DWORD)
  1020. {
  1021. SPITFSNode spNodeA, spNodeB;
  1022. InterfaceNodeData * pNodeDataA = NULL;
  1023. InterfaceNodeData * pNodeDataB = NULL;
  1024. m_spNodeMgr->FindNode(cookieA, &spNodeA);
  1025. m_spNodeMgr->FindNode(cookieB, &spNodeB);
  1026. pNodeDataA = GET_INTERFACENODEDATA(spNodeA);
  1027. Assert(pNodeDataA);
  1028. pNodeDataB = GET_INTERFACENODEDATA(spNodeB);
  1029. Assert(pNodeDataB);
  1030. // Note: if the values are both zero, we need to do
  1031. // a string comparison (to distinuguish true zero
  1032. // from a NULL data).
  1033. // e.g. "0" vs. "-"
  1034. if ((pNodeDataA->m_rgData[nSubItem].m_dwData == 0 ) &&
  1035. (pNodeDataB->m_rgData[nSubItem].m_dwData == 0))
  1036. {
  1037. return StriCmpW(GetString(pComponent, cookieA, nCol),
  1038. GetString(pComponent, cookieB, nCol));
  1039. }
  1040. else
  1041. return pNodeDataA->m_rgData[nSubItem].m_dwData -
  1042. pNodeDataB->m_rgData[nSubItem].m_dwData;
  1043. }
  1044. else
  1045. return StriCmpW(GetString(pComponent, cookieA, nCol),
  1046. GetString(pComponent, cookieB, nCol));
  1047. }
  1048. static const SRouterNodeMenu s_rgIfNodeMenu[] =
  1049. {
  1050. { IDS_MENU_DIALIN_STATUS, 0,
  1051. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  1052. { IDS_MENU_DIALIN_DISCONNECT, 0,
  1053. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  1054. { IDS_MENU_DIALIN_SENDMSG, DialInUserHandler::GetSendMsgMenuFlags,
  1055. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  1056. { IDS_MENU_DIALIN_SENDALL, 0,
  1057. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  1058. };
  1059. ULONG DialInUserHandler::GetSendMsgMenuFlags(const SRouterNodeMenu *,
  1060. INT_PTR pUserData)
  1061. {
  1062. SMenuData * pData = reinterpret_cast<SMenuData *>(pUserData);
  1063. if (pData->m_pDialin->m_entry.m_rc0.dwInterfaceType == ROUTER_IF_TYPE_CLIENT)
  1064. return 0;
  1065. else
  1066. return MF_GRAYED;
  1067. }
  1068. /*!--------------------------------------------------------------------------
  1069. DialInUserHandler::AddMenuItems
  1070. Implementation of ITFSResultHandler::OnAddMenuItems
  1071. Author: KennT
  1072. ---------------------------------------------------------------------------*/
  1073. STDMETHODIMP DialInUserHandler::AddMenuItems(ITFSComponent *pComponent,
  1074. MMC_COOKIE cookie,
  1075. LPDATAOBJECT lpDataObject,
  1076. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1077. long *pInsertionAllowed)
  1078. {
  1079. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1080. HRESULT hr = S_OK;
  1081. SPITFSNode spNode;
  1082. DialInUserHandler::SMenuData menuData;
  1083. COM_PROTECT_TRY
  1084. {
  1085. m_spNodeMgr->FindNode(cookie, &spNode);
  1086. // Now go through and add our menu items
  1087. menuData.m_spNode.Set(spNode);
  1088. menuData.m_pDialin = this;
  1089. hr = AddArrayOfMenuItems(spNode, s_rgIfNodeMenu,
  1090. DimensionOf(s_rgIfNodeMenu),
  1091. pContextMenuCallback,
  1092. *pInsertionAllowed,
  1093. reinterpret_cast<INT_PTR>(&menuData));
  1094. }
  1095. COM_PROTECT_CATCH;
  1096. return hr;
  1097. }
  1098. /*!--------------------------------------------------------------------------
  1099. DialInUserHandler::Command
  1100. -
  1101. Author: KennT
  1102. ---------------------------------------------------------------------------*/
  1103. STDMETHODIMP DialInUserHandler::Command(ITFSComponent *pComponent,
  1104. MMC_COOKIE cookie,
  1105. int nCommandId,
  1106. LPDATAOBJECT pDataObject)
  1107. {
  1108. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1109. HRESULT hr = S_OK;
  1110. SPITFSNode spNode;
  1111. SPITFSNode spNodeParent;
  1112. SPITFSNodeHandler spParentHandler;
  1113. DialInNodeData * pData;
  1114. LPCWSTR pswzComputerName;
  1115. USES_CONVERSION;
  1116. COM_PROTECT_TRY
  1117. {
  1118. switch (nCommandId)
  1119. {
  1120. case IDS_MENU_DIALIN_STATUS:
  1121. {
  1122. // Get the hServer and hPort
  1123. m_spNodeMgr->FindNode(cookie, &spNode);
  1124. spNode->GetParent(&spNodeParent);
  1125. pData = GET_DIALINNODEDATA(spNodeParent);
  1126. CConnDlg conndlg(pData->GetHandle(),
  1127. m_entry.m_rc0.hConnection,
  1128. spNodeParent);
  1129. conndlg.DoModal();
  1130. // if (conndlg.m_bChanged)
  1131. RefreshInterface(cookie);
  1132. }
  1133. break;
  1134. case IDS_MENU_DIALIN_DISCONNECT:
  1135. {
  1136. // Get the hServer and hPort
  1137. m_spNodeMgr->FindNode(cookie, &spNode);
  1138. spNode->GetParent(&spNodeParent);
  1139. pData = GET_DIALINNODEDATA(spNodeParent);
  1140. ::MprAdminInterfaceDisconnect(
  1141. pData->GetHandle(),
  1142. m_entry.m_rc0.hInterface);
  1143. // Refresh this node
  1144. RefreshInterface(cookie);
  1145. }
  1146. break;
  1147. case IDS_MENU_DIALIN_SENDMSG:
  1148. {
  1149. // If this is a client inteface, don't allow sending
  1150. // to this.
  1151. if (m_entry.m_rc0.dwInterfaceType != ROUTER_IF_TYPE_CLIENT)
  1152. break;
  1153. // If the messenger flags are set, then don't bother
  1154. // trying to send the message to this client
  1155. if (!(m_entry.m_rc0.dwConnectionFlags & RAS_FLAGS_MESSENGER_PRESENT))
  1156. {
  1157. AfxMessageBox(IDS_ERR_NO_MESSENGER, MB_OK | MB_ICONINFORMATION);
  1158. break;
  1159. }
  1160. // Send a message to a single user
  1161. // ------------------------------------------------
  1162. CMessageDlg dlg(m_spRouterInfo->GetMachineName(),
  1163. W2CT(m_entry.m_rc0.wszUserName),
  1164. W2CT(m_entry.m_rc0.wszRemoteComputer),
  1165. m_entry.m_rc0.hConnection,
  1166. NULL);
  1167. dlg.DoModal();
  1168. }
  1169. break;
  1170. case IDS_MENU_DIALIN_SENDALL:
  1171. {
  1172. // Get the hServer and hPort
  1173. m_spNodeMgr->FindNode(cookie, &spNode);
  1174. ForwardCommandToParent(spNode,
  1175. IDS_MENU_DIALIN_SENDALL,
  1176. CCT_RESULT, pDataObject, 0);
  1177. }
  1178. break;
  1179. default:
  1180. Panic0("DialInUserHandler: Unknown menu command!");
  1181. break;
  1182. }
  1183. }
  1184. COM_PROTECT_CATCH;
  1185. return hr;
  1186. }
  1187. ImplementEmbeddedUnknown(DialInUserHandler, IRtrAdviseSink)
  1188. STDMETHODIMP DialInUserHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  1189. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  1190. {
  1191. InitPThis(DialInUserHandler, IRtrAdviseSink);
  1192. HRESULT hr = hrOK;
  1193. return hr;
  1194. }
  1195. /*!--------------------------------------------------------------------------
  1196. DialInUserHandler::OnCreateDataObject
  1197. Implementation of ITFSResultHandler::OnCreateDataObject
  1198. Author: KennT
  1199. ---------------------------------------------------------------------------*/
  1200. STDMETHODIMP DialInUserHandler::OnCreateDataObject(ITFSComponent *pComp,
  1201. MMC_COOKIE cookie,
  1202. DATA_OBJECT_TYPES type,
  1203. IDataObject **ppDataObject)
  1204. {
  1205. HRESULT hr = hrOK;
  1206. COM_PROTECT_TRY
  1207. {
  1208. CORg( CreateDataObjectFromRouterInfo(m_spRouterInfo,
  1209. m_spRouterInfo->GetMachineName(),
  1210. type, cookie, m_spTFSCompData,
  1211. ppDataObject, NULL, FALSE) );
  1212. COM_PROTECT_ERROR_LABEL;
  1213. }
  1214. COM_PROTECT_CATCH;
  1215. return hr;
  1216. }
  1217. STDMETHODIMP DialInUserHandler::HasPropertyPages (
  1218. ITFSComponent *pComp,
  1219. MMC_COOKIE cookie,
  1220. LPDATAOBJECT pDataObject)
  1221. {
  1222. return hrFalse;
  1223. }
  1224. /*!--------------------------------------------------------------------------
  1225. DialInUserHandler::RefreshInterface
  1226. -
  1227. Author: KennT
  1228. ---------------------------------------------------------------------------*/
  1229. void DialInUserHandler::RefreshInterface(MMC_COOKIE cookie)
  1230. {
  1231. ForceGlobalRefresh(m_spRouterInfo);
  1232. }
  1233. /*!--------------------------------------------------------------------------
  1234. DialInUserHandler::OnResultItemClkOrDblClk
  1235. -
  1236. Author: KennT
  1237. ---------------------------------------------------------------------------*/
  1238. HRESULT DialInUserHandler::OnResultItemClkOrDblClk(ITFSComponent *pComponent,
  1239. MMC_COOKIE cookie,
  1240. LPARAM arg,
  1241. LPARAM lParam,
  1242. BOOL bDoubleClick)
  1243. {
  1244. HRESULT hr = hrOK;
  1245. if (bDoubleClick)
  1246. {
  1247. // Bring up the status dialog on this port
  1248. CORg( Command(pComponent, cookie, IDS_MENU_DIALIN_STATUS,
  1249. NULL) );
  1250. }
  1251. Error:
  1252. return hr;
  1253. }