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.

476 lines
18 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) 1993-1996 Microsoft Corporation. All Rights Reserved.
  3. //
  4. // MODULE: conman.h
  5. //
  6. // PURPOSE: Defines the CConnectionManager object for Athena.
  7. //
  8. #ifndef __CONMAN_H__
  9. #define __CONMAN_H__
  10. #ifndef WIN16 // No RAS support in Win16
  11. #include <ras.h>
  12. #include <raserror.h>
  13. #include <rasdlg.h>
  14. #include <sensapi.h>
  15. #include "imnact.h"
  16. // Forward Reference
  17. class CConnectionManager;
  18. typedef enum {
  19. CONNNOTIFY_CONNECTED = 0,
  20. CONNNOTIFY_DISCONNECTING, // pvData is the name of the connection comming down
  21. CONNNOTIFY_DISCONNECTED,
  22. CONNNOTIFY_RASACCOUNTSCHANGED,
  23. CONNNOTIFY_WORKOFFLINE,
  24. CONNNOTIFY_USER_CANCELLED
  25. } CONNNOTIFY;
  26. typedef enum CONNINFOSTATE {
  27. CIS_REFRESH,
  28. CIS_CLEAN
  29. } CONNINFOSTATE;
  30. typedef struct CONNINFO {
  31. CONNINFOSTATE state;
  32. HRASCONN hRasConn;
  33. TCHAR szCurrentConnectionName[RAS_MaxEntryName + 1];
  34. BOOL fConnected;
  35. BOOL fIStartedRas;
  36. BOOL fAutoDial;
  37. } CONNINFO, *LPCONNINFO;
  38. typedef struct TagConnListNode
  39. {
  40. TagConnListNode *pNext;
  41. TCHAR pszRasConn[RAS_MaxEntryName + 1];
  42. }ConnListNode;
  43. // This interface is implemented by clients of the connection manager that
  44. // care when a new RAS connection is established or an existing connection
  45. // is destroyed.
  46. DECLARE_INTERFACE_(IConnectionNotify, IUnknown)
  47. {
  48. // *** IUnknown Methods ***
  49. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  50. STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  51. STDMETHOD_(ULONG, Release)(THIS) PURE;
  52. // *** IConnectionNotify ***
  53. // OnConnectionNotify
  54. //
  55. // <in> nCode - Tells the function which event happened
  56. // <in> pvData - Pointer to extra data for the notification
  57. // <in> pConMan - Pointer to the CConnectionManager object that sent the
  58. // notification. The recipient can use this to find out
  59. // if they can connect to a server based on the new state
  60. // of the RAS connection.
  61. STDMETHOD(OnConnectionNotify) (THIS_
  62. CONNNOTIFY nCode,
  63. LPVOID pvData,
  64. CConnectionManager *pConMan) PURE;
  65. };
  66. /////////////////////////////////////////////////////////////////////////////
  67. // API Typedefs
  68. //
  69. typedef DWORD (APIENTRY *RASDIALPROC)(LPRASDIALEXTENSIONS, LPTSTR, LPRASDIALPARAMS, DWORD, LPVOID, LPHRASCONN);
  70. typedef DWORD (APIENTRY *RASENUMCONNECTIONSPROC)(LPRASCONN, LPDWORD, LPDWORD);
  71. typedef DWORD (APIENTRY *RASENUMENTRIESPROC)(LPTSTR, LPTSTR, LPRASENTRYNAME, LPDWORD, LPDWORD);
  72. typedef DWORD (APIENTRY *RASGETCONNECTSTATUSPROC)(HRASCONN, LPRASCONNSTATUS);
  73. typedef DWORD (APIENTRY *RASGETERRORSTRINGPROC)(UINT, LPTSTR, DWORD);
  74. typedef DWORD (APIENTRY *RASHANGUPPROC)(HRASCONN);
  75. typedef DWORD (APIENTRY *RASSETENTRYDIALPARAMSPROC)(LPTSTR, LPRASDIALPARAMS, BOOL);
  76. typedef DWORD (APIENTRY *RASGETENTRYDIALPARAMSPROC)(LPTSTR, LPRASDIALPARAMS, BOOL*);
  77. typedef DWORD (APIENTRY *RASEDITPHONEBOOKENTRYPROC)(HWND, LPTSTR, LPTSTR);
  78. typedef BOOL (APIENTRY *RASDIALDLGPROC)(LPSTR, LPSTR, LPSTR, LPRASDIALDLG);
  79. typedef BOOL (APIENTRY *RASENTRYDLGPROC)(LPSTR, LPSTR, LPRASENTRYDLG);
  80. typedef DWORD (APIENTRY *RASGETENTRYPROPERTIES)(LPTSTR, LPTSTR, LPRASENTRY, LPDWORD, LPBYTE, LPDWORD);
  81. //Mobility Pack
  82. typedef BOOLEAN (APIENTRY *ISDESTINATIONREACHABLE)(LPCSTR lpwstrDestination, LPQOCINFO lpqocinfo);
  83. typedef BOOLEAN (APIENTRY *ISNETWORKALIVE)(LPDWORD lpdwflags);
  84. #define CONNECTION_RAS 0x00000001
  85. #define CONNECTION_LAN 0x00000002
  86. #define CONNECTION_MANUAL 0x00000004
  87. #define MAX_RAS_ERROR 256
  88. #define NOTIFY_PROP _T("NotifyInfoProp")
  89. #define NOTIFY_HWND _T("ConnectionNotify")
  90. // This is the name of our mutex that we use to make sure just one
  91. // instance of this object ever get's created.
  92. const TCHAR c_szConManMutex[] = _T("ConnectionManager");
  93. typedef struct tagNOTIFYHWND
  94. {
  95. DWORD dwThreadId;
  96. HWND hwnd;
  97. struct tagNOTIFYHWND *pNext;
  98. } NOTIFYHWND;
  99. typedef struct tagNOTIFYLIST
  100. {
  101. IConnectionNotify *pNotify;
  102. struct tagNOTIFYLIST *pNext;
  103. } NOTIFYLIST;
  104. class CConnectionManager : public IImnAdviseAccount
  105. {
  106. public:
  107. /////////////////////////////////////////////////////////////////////////
  108. // Constructor, Destructor
  109. //
  110. CConnectionManager();
  111. ~CConnectionManager();
  112. /////////////////////////////////////////////////////////////////////////
  113. // Initialization
  114. //
  115. HRESULT HrInit(IImnAccountManager *pAcctMan);
  116. /////////////////////////////////////////////////////////////////////////
  117. // IUnknown
  118. //
  119. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
  120. ULONG STDMETHODCALLTYPE AddRef(void);
  121. ULONG STDMETHODCALLTYPE Release(void);
  122. /////////////////////////////////////////////////////////////////////////
  123. // IImnAdviseAccount
  124. //
  125. HRESULT STDMETHODCALLTYPE AdviseAccount(DWORD dwAdviseType,
  126. ACTX *pactx);
  127. /////////////////////////////////////////////////////////////////////////
  128. // Connection APIs
  129. // CanConnect
  130. //
  131. // Allows the caller to determine if they can talk to the specified
  132. // account using the current connection.
  133. //
  134. // Return Values:
  135. // S_OK - The caller can connect using the existing connection
  136. // S_FALSE - There is no existing connection. The caller must first
  137. // connect.
  138. // E_FAIL - There is a connection that is active, but it is not the
  139. // connection for this account.
  140. //
  141. HRESULT CanConnect(IImnAccount *pAccount);
  142. HRESULT CanConnect(LPTSTR pszAccount);
  143. BOOL IsAccountDisabled(LPTSTR pszAccount);
  144. // Connect
  145. //
  146. // If the specified account requires a RAS connection, then connect
  147. // attempts to establish that connection. Otherwise, we simply
  148. // return success for manual or LAN connections.
  149. //
  150. // <in> pAccount / pszAccount - Name or pointer to the account to connect
  151. // <in> fShowUI - TRUE if the connection manager is allowed to display
  152. // UI while trying to connect.
  153. //
  154. HRESULT Connect(IImnAccount *pAccount, HWND hwnd, BOOL fShowUI);
  155. HRESULT Connect(LPTSTR pszAccount, HWND hwnd, BOOL fShowUI);
  156. HRESULT Connect(HMENU hMenu, DWORD cmd, HWND hwnd);
  157. HRESULT ConnectDefault(HWND hwnd, BOOL fShowUI);
  158. // Disconnect
  159. //
  160. // If there is a RAS connection in effect and we established that
  161. // connection, then we bring the connection down without asking any
  162. // questions. If we didn't establish the connection, then we explain
  163. // the conundrum to the user and ask if they still want to. If it's
  164. // a LAN connection, then we just return success.
  165. //
  166. HRESULT Disconnect(HWND hwnd, BOOL fShowUI, BOOL fForce, BOOL fShutdown);
  167. // IsConnected
  168. //
  169. // The client can call this to determine if there is currently an active
  170. // connection.
  171. //
  172. BOOL IsConnected(void);
  173. // IsRasLoaded
  174. //
  175. // In our shutdown code we call this before calling IsConnected since
  176. // IsConnected causes RAS to be loaded. We don't want to load RAS on
  177. // shutdown.
  178. //
  179. BOOL IsRasLoaded(void) {
  180. EnterCriticalSection(&m_cs);
  181. BOOL f = (NULL == m_hInstRas) ? FALSE : TRUE;
  182. LeaveCriticalSection(&m_cs);
  183. return f;
  184. }
  185. // IsGlobalOffline
  186. //
  187. // Checks the state of the global WININET offline option
  188. //
  189. BOOL IsGlobalOffline(void);
  190. // SetGlobalOffline
  191. //
  192. // Sets the global offline state for Athena and IE
  193. //
  194. void SetGlobalOffline(BOOL fOffline, HWND hwndParent = NULL);
  195. // Notifications
  196. //
  197. // A client can call Advise() to register itself to receive
  198. // notifications of connection changes.
  199. //
  200. HRESULT Advise(IConnectionNotify *pNotify);
  201. HRESULT Unadvise(IConnectionNotify *pNotify);
  202. /////////////////////////////////////////////////////////////////////////
  203. // UI Related APIs
  204. //
  205. // RasAccountsExist
  206. //
  207. // A client can call this to determine if there are any configured
  208. // accounts that exist that require a RAS connection.
  209. //
  210. // Returns:
  211. // S_OK - At least one account exists that uses RAS
  212. // S_FALSE - No accounts exist that use RAS
  213. //
  214. HRESULT RasAccountsExist(void);
  215. // GetConnectMenu
  216. //
  217. // A client can call this to retrieve the current list of items that
  218. // we can currently connect to. The client must call DestroyMenu() to
  219. // free the menu when the client is done.
  220. //
  221. HRESULT GetConnectMenu(HMENU *phMenu);
  222. // FreeConnectMenu
  223. //
  224. // After the client is done with the menu returned from GetConnectMenu(),
  225. // they need to call FreeConnectMenu() to free item data stored in the
  226. // menu and to destroy the menu resource.
  227. void FreeConnectMenu(HMENU hMenu);
  228. // OnActivate
  229. //
  230. // This should be called by the browser whenever our window receives an
  231. // WM_ACTIVATE message. When we receive the message, we check to see
  232. // what the current state of the RAS Connection is.
  233. void OnActivate(BOOL fActive);
  234. // FillRasCombo
  235. //
  236. // This function takes a handle to a combo box and inserts the list of
  237. // RAS connections used by accounts in Athena.
  238. BOOL FillRasCombo(HWND hwndCombo, BOOL fIncludeNone);
  239. // DoStartupDial
  240. //
  241. // This function checks to see what the user's startup options are with
  242. // respect to RAS and performs the actions required (dial, dialog, nada)
  243. void DoStartupDial(HWND hwndParent);
  244. // RefreshConnInfo - Defer checking of current connection information
  245. HRESULT RefreshConnInfo(BOOL fSendAdvise = TRUE);
  246. // HRESULT HandleConnStuff(BOOLEAN fShowUI, LPSTR pszAccountName, HWND hwnd);
  247. void DoOfflineTransactions(void);
  248. private:
  249. /////////////////////////////////////////////////////////////////////////
  250. // These are private. Stop looking at them you pervert.
  251. //
  252. HRESULT VerifyRasLoaded(void);
  253. HRESULT EnumerateConnections(LPRASCONN *ppRasConn, ULONG *pcConnections);
  254. HRESULT StartRasDial(HWND hwndParent, LPTSTR pszConnection);
  255. HRESULT RasLogon(HWND hwnd, LPTSTR pszConnection, BOOL fForcePrompt);
  256. HRESULT GetDefaultConnection(IImnAccount *pAccout, IImnAccount **ppDefault);
  257. HRESULT ConnectActual(LPTSTR pszRasConn, HWND hwnd, BOOL fShowUI);
  258. HRESULT CanConnectActual(LPTSTR pszRasConn);
  259. void DisplayRasError(HWND hwnd, HRESULT hrRasError, DWORD dwRasError);
  260. void CombinedRasError(HWND hwnd, UINT unids, LPTSTR pszRasError,
  261. DWORD dwRasError);
  262. UINT PromptCloseConnection(HWND hwnd);
  263. HRESULT PromptCloseConnection(LPTSTR pszRasConn, BOOL fShowUI, HWND hwndParent);
  264. static INT_PTR CALLBACK RasCloseConnDlgProc(HWND hwnd, UINT uMsg,
  265. WPARAM wParam, LPARAM lParam);
  266. static INT_PTR CALLBACK RasLogonDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
  267. LPARAM lParam);
  268. static INT_PTR CALLBACK RasProgressDlgProc(HWND hwnd, UINT uMsg,
  269. WPARAM wParam, LPARAM lParam);
  270. static INT_PTR CALLBACK RasStartupDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
  271. LPARAM lParam);
  272. BOOL RasHangupAndWait(HRASCONN hRasConn, DWORD dwMaxWaitSeconds);
  273. DWORD InternetHangUpAndWait(DWORD_PTR hRasConn, DWORD dwMaxWaitSeconds);
  274. BOOL LogonRetry(HWND hwnd, LPTSTR pszCancel);
  275. void FailedRasDial(HWND hwnd, HRESULT hrRasError, DWORD dwRasError);
  276. DWORD EditPhonebookEntry(HWND hwnd, LPTSTR pszEntryName);
  277. void SendAdvise(CONNNOTIFY nCode, LPVOID pvData);
  278. void FreeNotifyList(void);
  279. static LRESULT CALLBACK NotifyWndProc(HWND, UINT, WPARAM, LPARAM);
  280. BOOL IsConnectionUsed(LPTSTR pszConn);
  281. // Autodialer functions
  282. HRESULT DoAutoDial(HWND hwndParent, LPTSTR pszConnectoid, BOOL fDial);
  283. HRESULT LookupAutoDialHandler(LPTSTR pszConnectoid, LPTSTR pszAutodialDllName,
  284. LPTSTR pszAutodialFcnName);
  285. BOOL ConnectionManagerVoodoo(LPTSTR pszConnection);
  286. HRESULT AddToConnList(LPTSTR pszRasConn);
  287. void RemoveFromConnList(LPTSTR pszRasConn);
  288. void EmptyConnList();
  289. HRESULT SearchConnList(LPTSTR pszRasConn);
  290. HRESULT OEIsDestinationReachable(IImnAccount *pAccount, DWORD dwConnType);
  291. BOOLEAN IsSameDestination(LPSTR pszConnectionName, LPSTR pszServerName);
  292. HRESULT GetServerName(IImnAccount *pAcct, LPSTR pServerName, DWORD size);
  293. HRESULT IsInternetReachable(IImnAccount*, DWORD);
  294. HRESULT IsInternetReachable(LPTSTR pszRasConn);
  295. HRESULT VerifyMobilityPackLoaded();
  296. HRESULT ConnectUsingIESettings(HWND hwndParent, BOOL fShowUI);
  297. void SetTryAgain(BOOL bval);
  298. static INT_PTR CALLBACK OfferOfflineDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  299. HRESULT GetDefConnectoid(LPTSTR szConn, DWORD dwSize);
  300. private:
  301. /////////////////////////////////////////////////////////////////////////
  302. // Private Class Data
  303. ULONG m_cRef; // Ref count
  304. CRITICAL_SECTION m_cs;
  305. HANDLE m_hMutexDial;
  306. IImnAccountManager *m_pAcctMan;
  307. /////////////////////////////////////////////////////////////////////////////
  308. // State
  309. BOOL m_fSavePassword;
  310. BOOL m_fRASLoadFailed;
  311. BOOL m_fOffline;
  312. /////////////////////////////////////////////////////////////////////////////
  313. // Current Connection Information
  314. DWORD_PTR m_dwConnId;
  315. CONNINFO m_rConnInfo;
  316. TCHAR m_szConnectName[RAS_MaxEntryName + 1];
  317. RASDIALPARAMS m_rdp;
  318. /////////////////////////////////////////////////////////////////////////////
  319. // RAS DLL Handles
  320. //
  321. HINSTANCE m_hInstRas;
  322. HINSTANCE m_hInstRasDlg;
  323. //For Mobility Pack
  324. HINSTANCE m_hInstSensDll;
  325. BOOL m_fMobilityPackFailed;
  326. /////////////////////////////////////////////////////////////////////////////
  327. // Notifications
  328. NOTIFYHWND *m_pNotifyList;
  329. /////////////////////////////////////////////////////////////////////////////
  330. // Ras Dial Function Pointers
  331. //
  332. RASDIALPROC m_pRasDial;
  333. RASENUMCONNECTIONSPROC m_pRasEnumConnections;
  334. RASENUMENTRIESPROC m_pRasEnumEntries;
  335. RASGETCONNECTSTATUSPROC m_pRasGetConnectStatus;
  336. RASGETERRORSTRINGPROC m_pRasGetErrorString;
  337. RASHANGUPPROC m_pRasHangup;
  338. RASSETENTRYDIALPARAMSPROC m_pRasSetEntryDialParams;
  339. RASGETENTRYDIALPARAMSPROC m_pRasGetEntryDialParams;
  340. RASEDITPHONEBOOKENTRYPROC m_pRasEditPhonebookEntry;
  341. RASDIALDLGPROC m_pRasDialDlg;
  342. RASENTRYDLGPROC m_pRasEntryDlg;
  343. RASGETENTRYPROPERTIES m_pRasGetEntryProperties;
  344. //Mobility Pack
  345. ISDESTINATIONREACHABLE m_pIsDestinationReachable;
  346. ISNETWORKALIVE m_pIsNetworkAlive;
  347. ConnListNode *m_pConnListHead;
  348. BOOL m_fTryAgain;
  349. BOOL m_fDialerUI;
  350. };
  351. /////////////////////////////////////////////////////////////////////////////
  352. // Make our code look prettier
  353. //
  354. #undef RasDial
  355. #undef RasEnumConnections
  356. #undef RasEnumEntries
  357. #undef RasGetConnectStatus
  358. #undef RasGetErrorString
  359. #undef RasHangup
  360. #undef RasSetEntryDialParams
  361. #undef RasGetEntryDialParams
  362. #undef RasEditPhonebookEntry
  363. #undef RasDialDlg
  364. #undef RasGetEntryProperties
  365. #define RasDial (*m_pRasDial)
  366. #define RasEnumConnections (*m_pRasEnumConnections)
  367. #define RasEnumEntries (*m_pRasEnumEntries)
  368. #define RasGetConnectStatus (*m_pRasGetConnectStatus)
  369. #define RasGetErrorString (*m_pRasGetErrorString)
  370. #define RasHangup (*m_pRasHangup)
  371. #define RasSetEntryDialParams (*m_pRasSetEntryDialParams)
  372. #define RasGetEntryDialParams (*m_pRasGetEntryDialParams)
  373. #define RasEditPhonebookEntry (*m_pRasEditPhonebookEntry)
  374. #define RasDialDlg (*m_pRasDialDlg)
  375. #define RasGetEntryProperties (*m_pRasGetEntryProperties)
  376. //Mobility Pack
  377. #undef IsDestinationReachable
  378. #define IsDestinationReachable (*m_pIsDestinationReachable)
  379. #undef IsNetworkAlive
  380. #define IsNetworkAlive (*m_pIsNetworkAlive)
  381. // Dialog Control IDs
  382. #define idbDet 1000
  383. #define idlbDetails 1001
  384. #define ideProgress 1002
  385. #define idcSplitter 1003
  386. #define idchSavePassword 1004
  387. #define ideUserName 1005
  388. #define idePassword 1006
  389. #define idePhone 1007
  390. #define idbEditConnection 1009
  391. #define idrgUseCurrent 1010
  392. #define idrgDialNew 1011
  393. #define idcCurrentMsg 1012
  394. #define idcDialupCombo 1013
  395. #define idcDefaultCheck 1014
  396. #define idcDontWarnCheck 1015
  397. #endif // !WIN16
  398. #endif // __CONMAN_H__