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.

242 lines
7.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: connection.h
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Header for the CCmConnection class.
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: quintinb Created Header 08/16/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #ifndef CONNECTION_H
  15. #define CONNECTION_H
  16. #include "cm_misc.h"
  17. #include "ras.h"
  18. #include "ConnStat.h"
  19. #include "Idlestat.h"
  20. #include "WatchProcess.h"
  21. #include "StatusDlg.h"
  22. #include "ReconnectDlg.h"
  23. #include "cm_def.h"
  24. #include "resource.h"
  25. #include "TrayIcon.h"
  26. #include <rasdlg.h>
  27. #include "cmdial.h"
  28. #include "RasApiDll.h"
  29. #include "cmlog.h"
  30. struct tagCmConnectedInfo; // CM_CONNECTED_INFO
  31. struct Cm_Connection; // CM_CONNECTION
  32. class CCmConnection
  33. {
  34. public:
  35. // Called by main thread
  36. // Post a hangup message to itself
  37. // The connection is already hangup,
  38. void PostHangupMsg() const;
  39. CCmConnection(const tagCmConnectedInfo * pConnectedInfo,
  40. const Cm_Connection* pConnectionEntry);
  41. ~CCmConnection();
  42. const TCHAR* GetServiceName() const {return m_szServiceName;}
  43. enum {
  44. // Tray icon message send to status window
  45. WM_TRAYICON = WM_USER + 1,
  46. WM_CONN_EVENT, // Internal message posted to the thread, wParam in below
  47. };
  48. // Connection events, wParam for WM_CONN_EVENT
  49. enum CONN_EVENT
  50. {
  51. EVENT_LOST_CONNECTION, // The connection is lost
  52. EVENT_IDLE, // No-traffic/No watching-process
  53. EVENT_COUNTDOWN_ZERO, // Disconnect Countdown down to 0
  54. EVENT_USER_DISCONNECT, // user choose to disconnect
  55. EVENT_CMDIAL_HANGUP, // cmdial send cmmon a hangup request
  56. EVENT_RECONNECT, // User clicked OK for the reconnect dialog
  57. EVENT_NONE, // No event happened
  58. };
  59. // wParam for WM_COMMAND
  60. enum {IDM_TRAYMENU = IDC_DISCONNECT + 1000}; // addition tray icon menu id start from here
  61. void ReInstateTrayIcon(); // re-add the trayicon to the tray
  62. DWORD OnTrayIcon(WPARAM wParam, LPARAM lParam); // WM_TRAYICON
  63. void OnStatusDetails(); // "Detail" button clicked
  64. void OnStayOnLine(); // "Stay Online" clicked
  65. void OnAdditionalTrayMenu(WORD nCmd); // Additinal command from tray menu selected
  66. BOOL OnEndSession(BOOL fEndSession, BOOL fLogOff); // WM_ENDSESSION
  67. // Logging class
  68. CmLogFile m_Log;
  69. // Is this a "global" user (i.e. an all-user connectoid) with global creds?
  70. // That's the only type of connectoid that will survive a Fast User Switch
  71. BOOL m_fGlobalGlobal;
  72. protected:
  73. enum CONN_STATE
  74. {
  75. STATE_CONNECTED, // the connection is connected, this is the initial state
  76. STATE_COUNTDOWN, // displaying disconnect count down dialog box
  77. STATE_PROMPT_RECONNECT, // Displaying prompt reconnect dialog
  78. STATE_RECONNECTING, // Calling cmdial to reconnect
  79. STATE_TERMINATED, // connection no longer exist
  80. };
  81. // Internal state
  82. CONN_STATE m_dwState;
  83. // The connection thread ID
  84. DWORD m_dwThreadId;
  85. // Dial-up RAS connection handle
  86. HRASCONN m_hRasDial;
  87. // Tunnel RAS connection handle
  88. HRASCONN m_hRasTunnel;
  89. // Connection statistics for Win9x
  90. CConnStatistics m_ConnStatistics;
  91. // Disconnect count down timer is 30 seconds
  92. enum{IDLE_DLG_WAIT_TIMEOUT = 30 * 1000};
  93. // Manage idle disconnect for Win9x
  94. CIdleStatistics m_IdleStatistics;
  95. // The tray icon on the task bar
  96. CTrayIcon m_TrayIcon;
  97. // The big and small CM icon,
  98. // the icon for status dialog and reconnect dialog
  99. HICON m_hBigIcon;
  100. HICON m_hSmallIcon;
  101. // Manage watch process list
  102. CWatchProcessList m_WatchProcess;
  103. // the start time when connected
  104. DWORD m_dwConnectStartTime;
  105. // The start time of disconnect count down
  106. DWORD m_dwCountDownStartTime;
  107. // Status and disconnect count down dialog
  108. CStatusDlg m_StatusDlg;
  109. // the prompt reconnect dialog
  110. CReconnectDlg m_ReconnectDlg;
  111. //
  112. // Information for reconnect only, except dwCmFlags
  113. //
  114. CMDIALINFO m_ReconnectInfo;
  115. // the long service name
  116. TCHAR m_szServiceName[RAS_MaxEntryName + 1];
  117. TCHAR m_szRasPhoneBook[MAX_PATH];
  118. CIni m_IniProfile; // .cmp file
  119. CIni m_IniService; // .cms file
  120. CIni m_IniBoth; // Both .cmp and .cms file
  121. // Write to .cmp file
  122. // Read from .cmp file, if not found try .cms file
  123. // The help file name
  124. TCHAR m_szHelpFile[128];
  125. // An event for RAS to be signaled whe connection is lost
  126. // If NULL, we have to check the connection by RasGetConnectionStatus in our timer
  127. HANDLE m_hEventRasNotify;
  128. // The link to rasapi32
  129. CRasApiDll m_RasApiDll;
  130. // Whether to minimize the working set before MsgWaitForMultipleObject
  131. BOOL m_fToMinimizeWorkingSet;
  132. // hide the trayicon?
  133. BOOL m_fHideTrayIcon;
  134. // Used to cascade the window, increased by 1 for each connection
  135. static DWORD m_dwCurPositionId;
  136. // The position id of this connection, use this id to position the window
  137. DWORD m_dwPositionId;
  138. public:
  139. BOOL StartConnectionThread(); // Create a thread for this connection
  140. CONN_EVENT StateConnectedOnTimer();
  141. BOOL IsTrayIconHidden() const;
  142. protected:
  143. static DWORD WINAPI ConnectionThread(LPVOID pConnection); // Thread entry point
  144. DWORD ConnectionThread(); // Non static function of the entry point
  145. void InitIniFiles(const TCHAR* pszProfileName);
  146. void StateConnectedInit();
  147. void StateConnectedCleanup(BOOL fEndSession = FALSE);
  148. void StateConnected(); // The life time of state STATE_CONNECTED/COUNTDOWN
  149. CONN_EVENT StateConnectedGetEvent();
  150. CONN_STATE StateConnectedProcessEvent(CONN_EVENT wEvent);
  151. BOOL CmCustomHangup(BOOL fPromptReconnect, BOOL fEndSession = FALSE);
  152. BOOL CheckRasConnection(OUT BOOL& fLostConnection);
  153. LPTSTR LoadHelpFileName() ;
  154. void LoadConnectionIcons();
  155. BOOL IsPromptReconnectEnabled() const;
  156. BOOL IsAutoReconnectEnabled() const;
  157. HANDLE CallRasConnectionNotification(HRASCONN hRasDial, HRASCONN hRasTunnel);
  158. static DWORD WINAPI RasMonitorDlgThread(LPVOID lParam);
  159. CONN_STATE StatePrompt();
  160. BOOL Reconnect();
  161. //
  162. // Utility functions
  163. //
  164. BOOL ExecCmdLine(const TCHAR* pszCmdLine, const TCHAR* pszCmsFile);
  165. HANDLE RunAsUser(WCHAR *pszProgram, WCHAR *pszParams, WCHAR *pszDesktop);
  166. DWORD GetProcessId(WCHAR *pszModule);
  167. static void PositionWindow(HWND hWnd, DWORD dwPositionId);
  168. public:
  169. #ifdef DEBUG
  170. void AssertValid() const; //assert this is valid, for debugging
  171. #endif
  172. };
  173. //
  174. // Inline functions
  175. //
  176. inline BOOL CCmConnection::IsTrayIconHidden() const
  177. {
  178. return m_fHideTrayIcon;
  179. }
  180. inline void CCmConnection::ReInstateTrayIcon()
  181. {
  182. //
  183. // we need to re-add the trayicon
  184. //
  185. m_TrayIcon.SetIcon(NULL, m_StatusDlg.GetHwnd(), WM_TRAYICON, 0, m_szServiceName);
  186. }
  187. #endif