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.

621 lines
18 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. ports.h
  7. Interface administration
  8. FILE HISTORY:
  9. */
  10. #ifndef _PORTS_H_
  11. #define _PORTS_H_
  12. #ifndef _BASEHAND_H
  13. #include "basehand.h"
  14. #endif
  15. #ifndef _HANDLERS_H_
  16. #include "handlers.h"
  17. #endif
  18. #ifndef _ROUTER_H
  19. #include "router.h"
  20. #endif
  21. #ifndef _INFO_H
  22. #include "info.h"
  23. #endif
  24. #ifndef _BASECON_H
  25. #include "basecon.h"
  26. #endif
  27. #ifndef _RTRUTIL_H_
  28. #include "rtrutil.h"
  29. #endif
  30. #ifndef _RTRSHEET_H_
  31. #include "rtrsheet.h"
  32. #endif
  33. #ifndef _DIALOG_H_
  34. #include "dialog.h"
  35. #endif
  36. #ifndef _LISTCTRL_H_
  37. #include "listctrl.h"
  38. #endif
  39. #include "rasdlg.h"
  40. extern "C"
  41. {
  42. #ifndef _RASMAN_
  43. #include "rasman.h"
  44. #endif
  45. };
  46. // forward declarations
  47. class RouterAdminConfigStream;
  48. interface IRouterInfo;
  49. struct ColumnData;
  50. struct SPortsNodeMenu;
  51. class PortsProperties;
  52. /*---------------------------------------------------------------------------
  53. Struct: PortsNodeData
  54. This is information related to the set of interfaces (not per-interface),
  55. this is intended for SHARED data.
  56. Put data in here that needs to be accessed by the child nodes. All other
  57. private data should go in the handler.
  58. ---------------------------------------------------------------------------*/
  59. struct PortsNodeData
  60. {
  61. PortsNodeData();
  62. ~PortsNodeData();
  63. #ifdef DEBUG
  64. char m_szDebug[32]; // for iding structures
  65. #endif
  66. static HRESULT InitAdminNodeData(ITFSNode *pNode, RouterAdminConfigStream *pConfigStream);
  67. static HRESULT FreeAdminNodeData(ITFSNode *pNode);
  68. HRESULT LoadHandle(LPCTSTR pszMachineName);
  69. HANDLE GetHandle();
  70. void ReleaseHandles();
  71. CString m_stMachineName;
  72. protected:
  73. SPMprServerHandle m_sphDdmHandle;
  74. };
  75. #define GET_PORTSNODEDATA(pNode) \
  76. ((PortsNodeData *) pNode->GetData(TFS_DATA_USER))
  77. #define SET_PORTSNODEDATA(pNode, pData) \
  78. pNode->SetData(TFS_DATA_USER, (LONG_PTR) pData)
  79. /*---------------------------------------------------------------------------
  80. This is the list of columns available for the Interfaces node
  81. - Name, "COM1: USR Sportster Modem"
  82. - Device, "modem"
  83. - Comment, "stuff"
  84. - Status, "active"
  85. ---------------------------------------------------------------------------*/
  86. enum
  87. {
  88. PORTS_SI_NAME = 0,
  89. PORTS_SI_DEVICE = 1,
  90. PORTS_SI_USAGE = 2,
  91. PORTS_SI_STATUS = 3,
  92. PORTS_SI_COMMENT = 4,
  93. PORTS_MAX_COLUMNS,
  94. // Entries after this are not visible to the user
  95. PORTS_SI_PORT = PORTS_MAX_COLUMNS,
  96. PORTS_SI_MAX,
  97. };
  98. /*---------------------------------------------------------------------------
  99. Struct: PortsListEntry
  100. ---------------------------------------------------------------------------*/
  101. struct PortsListEntry
  102. {
  103. RAS_PORT_0 m_rp0;
  104. BOOL m_fActiveDialOut; // TRUE if used as a dial-out port
  105. // fix b32887 -- add more information to the result pane -- ras / routing enabled ports
  106. DWORD m_dwEnableRas; // = 1 if RAS is enabled on this device
  107. DWORD m_dwEnableRouting; // = 1 if Routing is enabled on this device
  108. DWORD m_dwEnableOutboundRouting; // = 1 if outbound Routing is
  109. // enabled on this device
  110. };
  111. typedef CList<PortsListEntry, PortsListEntry &> PortsList;
  112. /*---------------------------------------------------------------------------
  113. Struct: PortsDeviceEntry
  114. Data kept by the property page on a per-device basis, rather than a
  115. per-port basis.
  116. ---------------------------------------------------------------------------*/
  117. struct PortsDeviceEntry
  118. {
  119. PortsDeviceEntry();
  120. ~PortsDeviceEntry();
  121. BOOL m_fRegistry; // TRUE if read in from the registry
  122. BOOL m_fModified; // TRUE if struct has been modifed, FALSE otherwise
  123. DWORD m_dwPorts; // Number of ports available
  124. DWORD m_dwOldPorts; // Number of ports avail. (old value)
  125. BOOL m_fWriteable; // Is the number of ports modifiable.
  126. DWORD m_dwMinPorts; // these values only matter if m_fWriteable is TRUE
  127. DWORD m_dwMaxPorts;
  128. //$PPTP
  129. // This value is added explicitly for PPTP. For PPTP the maximum
  130. // may be adjusted above the value of m_dwMaxPorts. (In this case
  131. // we prompt for a reboot). This is the maximum value that m_dwMaxPorts
  132. // may take.
  133. DWORD m_dwMaxMaxPorts;
  134. HKEY m_hKey; // registry key for this device (if router is off)
  135. DWORD m_dwEnableRas; // = 1 if RAS is enabled on this device
  136. DWORD m_dwEnableRouting; // = 1 if Routing is enabled on this device
  137. DWORD m_dwEnableOutboundRouting; // = 1 if outbound only routing
  138. // is enabled on this device.
  139. // from RAS_DEVICE_INFO - set for PPTP/L2TP only
  140. RASDEVICETYPE m_eDeviceType;
  141. CString m_stDisplayName;
  142. // We store a copy of this struct for the case where the router is live.
  143. // We copy the info here into the variables above which are used as
  144. // temporary storage. When the user hits OK, we copy the information
  145. // back to the RAS_DEVICE_INFO structure and write that out. (Thus we
  146. // only write over what we use).
  147. RAS_DEVICE_INFO m_RasDeviceInfo;
  148. // Store a copy of the calledid info
  149. // This will get saved only when we exit out of the ports
  150. // property sheet. It gets loaded only if needed.
  151. BOOL m_fSaveCalledIdInfo; // TRUE if it needs to be written back
  152. BOOL m_fCalledIdInfoLoaded; // TRUE if the data has been loaded
  153. RAS_CALLEDID_INFO *m_pCalledIdInfo;
  154. };
  155. typedef CList<PortsDeviceEntry *, PortsDeviceEntry *> PortsDeviceList;
  156. /*---------------------------------------------------------------------------
  157. Class: PortsDataEntry
  158. This class is used to abstract the data gathering. There are two
  159. ways of getting the data, the first is through the registry (when the
  160. router is not running) and the second is go through the Ras APIs.
  161. ---------------------------------------------------------------------------*/
  162. class PortsDataEntry
  163. {
  164. public:
  165. PortsDataEntry();
  166. ~PortsDataEntry();
  167. // Initializes the class for the machine.
  168. HRESULT Initialize(LPCTSTR pszMachineName);
  169. // Loads the data into the PortsDeviceList. If the router is
  170. // running then the Ras APIs will be used else we go through the
  171. // registry.
  172. HRESULT LoadDevices(PortsDeviceList *pList);
  173. HRESULT LoadDevicesFromRegistry(PortsDeviceList *pList);
  174. HRESULT LoadDevicesFromRouter(PortsDeviceList *pList);
  175. // Saves the data into the PortsDeviceList. If the router is
  176. // running then the Ras APIs will be used else we go through the
  177. // registry.
  178. HRESULT SaveDevices(PortsDeviceList *pList);
  179. HRESULT SaveDevicesToRegistry(PortsDeviceList *pList);
  180. HRESULT SaveDevicesToRouter(PortsDeviceList *pList);
  181. protected:
  182. CString m_stMachine;
  183. RegKey m_regkeyMachine;
  184. BOOL m_fReadFromRegistry;
  185. };
  186. /*---------------------------------------------------------------------------
  187. Class: PortsNodeHandler
  188. ---------------------------------------------------------------------------*/
  189. class PortsNodeHandler :
  190. public BaseContainerHandler
  191. {
  192. public:
  193. PortsNodeHandler(ITFSComponentData *pCompData);
  194. HRESULT Init(IRouterInfo *pInfo, RouterAdminConfigStream *pConfigStream);
  195. // Override QI to handle embedded interface
  196. STDMETHOD(QueryInterface)(REFIID iid, LPVOID *ppv);
  197. // Embedded interface to deal with refresh callbacks
  198. DeclareEmbeddedInterface(IRtrAdviseSink, IUnknown)
  199. // base handler functionality we override
  200. OVERRIDE_NodeHandler_DestroyHandler();
  201. OVERRIDE_NodeHandler_GetString();
  202. OVERRIDE_NodeHandler_HasPropertyPages();
  203. OVERRIDE_NodeHandler_CreatePropertyPages();
  204. OVERRIDE_NodeHandler_OnAddMenuItems();
  205. OVERRIDE_NodeHandler_OnCreateDataObject();
  206. OVERRIDE_ResultHandler_CompareItems();
  207. // override handler notifications
  208. OVERRIDE_BaseHandlerNotify_OnExpand();
  209. OVERRIDE_BaseResultHandlerNotify_OnResultShow();
  210. // Initializes the node
  211. HRESULT ConstructNode(ITFSNode *pNode);
  212. // User-initiated commands
  213. // Helper function to add interfaces to the UI
  214. HRESULT AddPortsUserNode(ITFSNode *pParent, const PortsListEntry &PortsEntry);
  215. // Causes a sync action (synchronizes data not the structure)
  216. HRESULT SynchronizeNodeData(ITFSNode *pNode);
  217. HRESULT UnmarkAllNodes(ITFSNode *pNode, ITFSNodeEnum *pEnum);
  218. HRESULT RemoveAllUnmarkedNodes(ITFSNode *pNode, ITFSNodeEnum *pEnum);
  219. HRESULT GenerateListOfPorts(ITFSNode *pNode, PortsList *pList);
  220. HRESULT SetUserData(ITFSNode *pNode, const PortsListEntry& Ports);
  221. // Structure used to pass data to callbacks - used as a way of
  222. // avoiding recomputation
  223. struct SMenuData
  224. {
  225. ULONG m_ulMenuId;
  226. SPITFSNode m_spNode;
  227. };
  228. DWORD GetActivePorts() { return m_dwActivePorts;};
  229. protected:
  230. SPIDataObject m_spDataObject; // cachecd data object
  231. CString m_stTitle; // holds the title of the node
  232. LONG_PTR m_ulConnId; // notification id for router info
  233. LONG_PTR m_ulRefreshConnId; // id for refresh notifications
  234. BOOL m_bExpanded; // is the node expanded?
  235. MMC_COOKIE m_cookie; // cookie for the node
  236. DWORD m_dwActivePorts; // number of active ports
  237. RouterAdminConfigStream * m_pConfigStream;
  238. };
  239. /*---------------------------------------------------------------------------
  240. Class: PortsUserHandler
  241. ---------------------------------------------------------------------------*/
  242. class PortsUserHandler :
  243. public BaseRouterHandler
  244. {
  245. public:
  246. PortsUserHandler(ITFSComponentData *pCompData);
  247. ~PortsUserHandler()
  248. { DEBUG_DECREMENT_INSTANCE_COUNTER(PortsUserHandler); }
  249. HRESULT Init(IRouterInfo *pInfo, ITFSNode *pParent);
  250. // Override QI to handle embedded interface
  251. DeclareIUnknownMembers(IMPL)
  252. // STDMETHOD(QueryInterface)(REFIID iid, LPVOID *ppv);
  253. OVERRIDE_ResultHandler_GetString();
  254. OVERRIDE_ResultHandler_HasPropertyPages();
  255. OVERRIDE_ResultHandler_CompareItems();
  256. OVERRIDE_ResultHandler_AddMenuItems();
  257. OVERRIDE_ResultHandler_Command();
  258. OVERRIDE_ResultHandler_OnCreateDataObject();
  259. OVERRIDE_ResultHandler_DestroyResultHandler();
  260. OVERRIDE_BaseResultHandlerNotify_OnResultItemClkOrDblClk();
  261. // Initializes the node
  262. HRESULT ConstructNode(ITFSNode *pNode,
  263. IInterfaceInfo *pIfInfo,
  264. const PortsListEntry *pEntry);
  265. // Refresh the data for this node
  266. void RefreshInterface(MMC_COOKIE cookie);
  267. public:
  268. // Structure used to pass data to callbacks - used as a way of
  269. // avoiding recomputation
  270. struct SMenuData
  271. {
  272. SPITFSNode m_spNode;
  273. };
  274. static ULONG GetDisconnectMenuState(const SRouterNodeMenu *pMenuData,
  275. INT_PTR pUserData);
  276. protected:
  277. CString m_stTitle; // holds the title of the node
  278. DWORD m_ulConnId;
  279. PortsListEntry m_entry;
  280. // It is assumed that this will be valid for the lifetime of this node!
  281. DeclareEmbeddedInterface(IRtrAdviseSink, IUnknown)
  282. };
  283. /*---------------------------------------------------------------------------
  284. Class: PortsPageGeneral
  285. This class handles the General page of the Ports sheet.
  286. ---------------------------------------------------------------------------*/
  287. class PortsPageGeneral :
  288. public RtrPropertyPage
  289. {
  290. friend class PortsDeviceConfigDlg;
  291. public:
  292. PortsPageGeneral(UINT nIDTemplate, UINT nIDCaption = 0)
  293. : RtrPropertyPage(nIDTemplate, nIDCaption), m_bShowContent(TRUE)
  294. {};
  295. ~PortsPageGeneral();
  296. HRESULT Init(PortsProperties * pIPPropSheet, IRouterInfo *pRouter);
  297. protected:
  298. // Override the OnApply() so that we can grab our data from the
  299. // controls in the dialog.
  300. virtual BOOL OnApply();
  301. PortsProperties * m_pPortsPropSheet;
  302. //{{AFX_VIRTUAL(PortsPageGeneral)
  303. protected:
  304. virtual VOID DoDataExchange(CDataExchange *pDX);
  305. //}}AFX_VIRTUAL
  306. //{{AFX_MSG(PortsPageGeneral)
  307. virtual BOOL OnInitDialog();
  308. afx_msg void OnConfigure();
  309. afx_msg void OnListDblClk(NMHDR *pNMHdr, LRESULT *);
  310. afx_msg void OnNotifyListItemChanged(NMHDR *, LRESULT *);
  311. //}}AFX_MSG
  312. // Use CListCtrlEx to get the checkboxes
  313. CListCtrlEx m_listCtrl;
  314. SPIRouterInfo m_spRouter;
  315. BOOL m_bShowContent; // only show content of the page on NT5 servers
  316. PortsDeviceList m_deviceList;
  317. PortsDataEntry m_deviceDataEntry;
  318. DECLARE_MESSAGE_MAP()
  319. };
  320. /*---------------------------------------------------------------------------
  321. Class: PortsProperties
  322. This is the property sheet support class for the properties page of
  323. the Ports node.
  324. ---------------------------------------------------------------------------*/
  325. class PortsProperties :
  326. public RtrPropertySheet
  327. {
  328. public:
  329. PortsProperties(ITFSNode *pNode,
  330. IComponentData *pComponentData,
  331. ITFSComponentData *pTFSCompData,
  332. LPCTSTR pszSheetName,
  333. CWnd *pParent = NULL,
  334. UINT iPage=0,
  335. BOOL fScopePane = TRUE);
  336. ~PortsProperties();
  337. HRESULT Init(IRouterInfo *pRouter, PortsNodeHandler* pPortNodeHandler);
  338. void SetThreadInfo(DWORD dwThreadId);
  339. PortsNodeHandler* m_pPortsNodeHandle;
  340. protected:
  341. SPIRouterInfo m_spRouter;
  342. PortsPageGeneral m_pageGeneral;
  343. DWORD m_dwThreadId;
  344. };
  345. /*---------------------------------------------------------------------------
  346. Class : PortsDeviceConfigDlg
  347. ---------------------------------------------------------------------------*/
  348. class PortsDeviceConfigDlg : public CBaseDialog
  349. {
  350. public:
  351. PortsDeviceConfigDlg(PortsPageGeneral *pageGeneral,
  352. LPCTSTR pszMachine,
  353. CWnd *pParent = NULL)
  354. : CBaseDialog(PortsDeviceConfigDlg::IDD, pParent),
  355. m_pEntry(NULL) ,
  356. m_dwTotalActivePorts(0),
  357. m_pageGeneral(pageGeneral),
  358. m_stMachine(pszMachine)
  359. {};
  360. enum { IDD = IDD_PORTS_DEVICE_CONFIG };
  361. void SetDevice(PortsDeviceEntry *pEntry, DWORD dwTotalActivePorts);
  362. protected:
  363. // total number of active ports
  364. DWORD m_dwTotalActivePorts;
  365. virtual void DoDataExchange(CDataExchange *pDX);
  366. HRESULT LoadCalledIdInfo();
  367. HRESULT AllocateCalledId(DWORD dwSize, RAS_CALLEDID_INFO **ppCalledIdInfo);
  368. HRESULT CalledIdInfoToString(CString *pst);
  369. HRESULT StringToCalledIdInfo(LPCTSTR psz);
  370. CSpinButtonCtrl m_spinPorts;
  371. PortsDeviceEntry * m_pEntry;
  372. CString m_stMachine;
  373. virtual BOOL OnInitDialog();
  374. virtual void OnOK();
  375. PortsPageGeneral *m_pageGeneral;
  376. DECLARE_MESSAGE_MAP()
  377. };
  378. /*---------------------------------------------------------------------------
  379. Class : PortsSimpleDeviceConfigDlg
  380. This is a simplified version of PortsDeviceConfigDlg. We allow
  381. setting of the RAS/Routing flag only.
  382. ---------------------------------------------------------------------------*/
  383. class PortsSimpleDeviceConfigDlg : public CBaseDialog
  384. {
  385. public:
  386. PortsSimpleDeviceConfigDlg(UINT uIDD = PortsSimpleDeviceConfigDlg::IDD,
  387. CWnd *pParent = NULL)
  388. : CBaseDialog(uIDD, pParent),
  389. m_dwEnableRas(0), m_dwEnableRouting(0),
  390. m_dwEnableOutboundRouting(0)
  391. {};
  392. enum { IDD = IDD_PORTS_DEVICE_CONFIG };
  393. DWORD m_dwEnableRas;
  394. DWORD m_dwEnableRouting;
  395. DWORD m_dwEnableOutboundRouting;
  396. protected:
  397. virtual void DoDataExchange(CDataExchange *pDX);
  398. virtual BOOL OnInitDialog();
  399. virtual void OnOK();
  400. DECLARE_MESSAGE_MAP()
  401. };
  402. /*---------------------------------------------------------------------------
  403. Utility functions
  404. ---------------------------------------------------------------------------*/
  405. /*!--------------------------------------------------------------------------
  406. OnConfigurePorts
  407. This will bring up the ports dialog for the specified machine.
  408. The total number of active ports is used to determine if a
  409. warning should be displayed when we reduce the number of ports
  410. on a device.
  411. This returns TRUE if something has been changed (and the dirty
  412. flag should be set). FALSE is returned if nothing has been
  413. changed.
  414. If pPage is NULL, then it is assumed that this function is NOT
  415. being called from the property page (and thus is being called from
  416. the wizard). In the case that pPage is non-NULL, we will reboot
  417. the machine if the PPTP ports are changed.
  418. Author: KennT
  419. ---------------------------------------------------------------------------*/
  420. BOOL OnConfigurePorts(LPCTSTR pszMachineName,
  421. DWORD dwTotalActivePorts,
  422. PortsPageGeneral *pPage,
  423. CListCtrlEx *pListCtrl);
  424. // List box columns (in the Ports General page), for the wizard and
  425. // the properties.
  426. // --------------------------------------------------------------------
  427. #define PORTS_COL_DEVICE (0)
  428. #define PORTS_COL_USAGE (1)
  429. #define PORTS_COL_TYPE (2)
  430. #define PORTS_COL_NUMBER (3)
  431. // To make it easier to find the dialout ports, create a
  432. // special case (with the port name as the hash key).
  433. //
  434. // Note: we store a pointer to the port in the CStringMapToPtr.
  435. // We do not access this pointer (except in debug to verify that we
  436. // actually found the right port). If we do not think a port is
  437. // dialout active, we do not add it to our list.
  438. // --------------------------------------------------------------------
  439. class RasmanPortMap
  440. {
  441. public:
  442. ~RasmanPortMap();
  443. HRESULT Init(HANDLE hRasHandle,
  444. RASMAN_PORT *pPort,
  445. DWORD dwEntries);
  446. BOOL FIsDialoutActive(LPCWSTR pswzPortName);
  447. protected:
  448. CMapStringToPtr m_map;
  449. };
  450. #endif _PORTS_H_