1 | /* $Id: ConsoleVRDPServer.h 34563 2010-12-01 11:39:52Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VBox Console VRDE Server Helper class and implementation of IVRDEServerInfo
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef ____H_CONSOLEVRDPSERVER
|
---|
21 | #define ____H_CONSOLEVRDPSERVER
|
---|
22 |
|
---|
23 | #include "RemoteUSBBackend.h"
|
---|
24 | #include <hgcm/HGCM.h>
|
---|
25 |
|
---|
26 | #include <VBox/VBoxAuth.h>
|
---|
27 |
|
---|
28 | #include <VBox/HostServices/VBoxClipboardExt.h>
|
---|
29 |
|
---|
30 | #include "SchemaDefs.h"
|
---|
31 |
|
---|
32 | // ConsoleVRDPServer
|
---|
33 | ///////////////////////////////////////////////////////////////////////////////
|
---|
34 |
|
---|
35 | typedef struct _VRDPInputSynch
|
---|
36 | {
|
---|
37 | int cGuestNumLockAdaptions;
|
---|
38 | int cGuestCapsLockAdaptions;
|
---|
39 |
|
---|
40 | bool fGuestNumLock;
|
---|
41 | bool fGuestCapsLock;
|
---|
42 | bool fGuestScrollLock;
|
---|
43 |
|
---|
44 | bool fClientNumLock;
|
---|
45 | bool fClientCapsLock;
|
---|
46 | bool fClientScrollLock;
|
---|
47 | } VRDPInputSynch;
|
---|
48 |
|
---|
49 | /* Member of Console. Helper class for VRDP server management. Not a COM class. */
|
---|
50 | class ConsoleVRDPServer
|
---|
51 | {
|
---|
52 | public:
|
---|
53 | ConsoleVRDPServer (Console *console);
|
---|
54 | ~ConsoleVRDPServer ();
|
---|
55 |
|
---|
56 | int Launch (void);
|
---|
57 |
|
---|
58 | void NotifyAbsoluteMouse (bool fGuestWantsAbsolute)
|
---|
59 | {
|
---|
60 | m_fGuestWantsAbsolute = fGuestWantsAbsolute;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void NotifyKeyboardLedsChange (BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
|
---|
64 | {
|
---|
65 | bool fGuestNumLock = (fNumLock != FALSE);
|
---|
66 | bool fGuestCapsLock = (fCapsLock != FALSE);
|
---|
67 | bool fGuestScrollLock = (fScrollLock != FALSE);
|
---|
68 |
|
---|
69 | /* Might need to resync in case the guest itself changed the LED status. */
|
---|
70 | if (m_InputSynch.fClientNumLock != fGuestNumLock)
|
---|
71 | {
|
---|
72 | m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
73 | }
|
---|
74 |
|
---|
75 | if (m_InputSynch.fClientCapsLock != fGuestCapsLock)
|
---|
76 | {
|
---|
77 | m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
78 | }
|
---|
79 |
|
---|
80 | m_InputSynch.fGuestNumLock = fGuestNumLock;
|
---|
81 | m_InputSynch.fGuestCapsLock = fGuestCapsLock;
|
---|
82 | m_InputSynch.fGuestScrollLock = fGuestScrollLock;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void EnableConnections (void);
|
---|
86 | void DisconnectClient (uint32_t u32ClientId, bool fReconnect);
|
---|
87 | void MousePointerUpdate (const VRDECOLORPOINTER *pPointer);
|
---|
88 | void MousePointerHide (void);
|
---|
89 |
|
---|
90 | void Stop (void);
|
---|
91 |
|
---|
92 | AuthResult Authenticate (const Guid &uuid, AuthGuestJudgement guestJudgement,
|
---|
93 | const char *pszUser, const char *pszPassword, const char *pszDomain,
|
---|
94 | uint32_t u32ClientId);
|
---|
95 |
|
---|
96 | void AuthDisconnect (const Guid &uuid, uint32_t u32ClientId);
|
---|
97 |
|
---|
98 | void USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept);
|
---|
99 | void USBBackendDelete (uint32_t u32ClientId);
|
---|
100 |
|
---|
101 | void *USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid);
|
---|
102 | void USBBackendReleasePointer (const Guid *pGuid);
|
---|
103 |
|
---|
104 | /* Private interface for the RemoteUSBBackend destructor. */
|
---|
105 | void usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend);
|
---|
106 |
|
---|
107 | /* Private methods for the Remote USB thread. */
|
---|
108 | RemoteUSBBackend *usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend);
|
---|
109 |
|
---|
110 | void notifyRemoteUSBThreadRunning (RTTHREAD thread);
|
---|
111 | bool isRemoteUSBThreadRunning (void);
|
---|
112 | void waitRemoteUSBThreadEvent (RTMSINTERVAL cMillies);
|
---|
113 |
|
---|
114 | void ClipboardCreate (uint32_t u32ClientId);
|
---|
115 | void ClipboardDelete (uint32_t u32ClientId);
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * Forwarders to VRDP server library.
|
---|
119 | */
|
---|
120 | void SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const;
|
---|
121 | void SendResize (void) const;
|
---|
122 | void SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const;
|
---|
123 |
|
---|
124 | void SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const;
|
---|
125 | void SendAudioVolume (uint16_t left, uint16_t right) const;
|
---|
126 | void SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const;
|
---|
127 |
|
---|
128 | void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
|
---|
129 |
|
---|
130 | private:
|
---|
131 | /* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
|
---|
132 | * is actually just a part of the Console.
|
---|
133 | */
|
---|
134 | Console *mConsole;
|
---|
135 |
|
---|
136 | HVRDESERVER mhServer;
|
---|
137 |
|
---|
138 | static int loadVRDPLibrary (const char *pszLibraryName);
|
---|
139 |
|
---|
140 | /** Static because will never load this more than once! */
|
---|
141 | static RTLDRMOD mVRDPLibrary;
|
---|
142 |
|
---|
143 | static PFNVRDECREATESERVER mpfnVRDECreateServer;
|
---|
144 |
|
---|
145 | static VRDEENTRYPOINTS_1 *mpEntryPoints;
|
---|
146 | static VRDECALLBACKS_1 mCallbacks;
|
---|
147 |
|
---|
148 | static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
|
---|
149 | static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
|
---|
150 | static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
|
---|
151 | static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
|
---|
152 | static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
|
---|
153 | static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
|
---|
154 | static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
|
---|
155 | static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDEFRAMEBUFFERINFO *pInfo);
|
---|
156 | static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
|
---|
157 | static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
|
---|
158 | static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
|
---|
159 | static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
|
---|
160 |
|
---|
161 | bool m_fGuestWantsAbsolute;
|
---|
162 | int m_mousex;
|
---|
163 | int m_mousey;
|
---|
164 |
|
---|
165 | IFramebuffer *maFramebuffers[SchemaDefs::MaxGuestMonitors];
|
---|
166 |
|
---|
167 | IEventListener *mConsoleListener;
|
---|
168 |
|
---|
169 | VRDPInputSynch m_InputSynch;
|
---|
170 |
|
---|
171 | int32_t mVRDPBindPort;
|
---|
172 |
|
---|
173 | RTCRITSECT mCritSect;
|
---|
174 |
|
---|
175 | int lockConsoleVRDPServer (void);
|
---|
176 | void unlockConsoleVRDPServer (void);
|
---|
177 |
|
---|
178 | int mcClipboardRefs;
|
---|
179 | HGCMSVCEXTHANDLE mhClipboard;
|
---|
180 | PFNVRDPCLIPBOARDEXTCALLBACK mpfnClipboardCallback;
|
---|
181 |
|
---|
182 | static DECLCALLBACK(int) ClipboardCallback (void *pvCallback, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
|
---|
183 | static DECLCALLBACK(int) ClipboardServiceExtension (void *pvExtension, uint32_t u32Function, void *pvParm, uint32_t cbParms);
|
---|
184 |
|
---|
185 | #ifdef VBOX_WITH_USB
|
---|
186 | RemoteUSBBackend *usbBackendFindByUUID (const Guid *pGuid);
|
---|
187 | RemoteUSBBackend *usbBackendFind (uint32_t u32ClientId);
|
---|
188 |
|
---|
189 | typedef struct _USBBackends
|
---|
190 | {
|
---|
191 | RemoteUSBBackend *pHead;
|
---|
192 | RemoteUSBBackend *pTail;
|
---|
193 |
|
---|
194 | RTTHREAD thread;
|
---|
195 |
|
---|
196 | bool fThreadRunning;
|
---|
197 |
|
---|
198 | RTSEMEVENT event;
|
---|
199 | } USBBackends;
|
---|
200 |
|
---|
201 | USBBackends mUSBBackends;
|
---|
202 |
|
---|
203 | void remoteUSBThreadStart (void);
|
---|
204 | void remoteUSBThreadStop (void);
|
---|
205 | #endif /* VBOX_WITH_USB */
|
---|
206 |
|
---|
207 | /* External authentication library handle. The library is loaded in the
|
---|
208 | * Authenticate method and unloaded at the object destructor.
|
---|
209 | */
|
---|
210 | RTLDRMOD mAuthLibrary;
|
---|
211 | PAUTHENTRY mpfnAuthEntry;
|
---|
212 | PAUTHENTRY2 mpfnAuthEntry2;
|
---|
213 | PAUTHENTRY3 mpfnAuthEntry3;
|
---|
214 | };
|
---|
215 |
|
---|
216 |
|
---|
217 | class Console;
|
---|
218 |
|
---|
219 | class ATL_NO_VTABLE VRDEServerInfo :
|
---|
220 | public VirtualBoxBase,
|
---|
221 | VBOX_SCRIPTABLE_IMPL(IVRDEServerInfo)
|
---|
222 | {
|
---|
223 | public:
|
---|
224 |
|
---|
225 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VRDEServerInfo, IVRDEServerInfo)
|
---|
226 |
|
---|
227 | DECLARE_NOT_AGGREGATABLE(VRDEServerInfo)
|
---|
228 |
|
---|
229 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
230 |
|
---|
231 | BEGIN_COM_MAP(VRDEServerInfo)
|
---|
232 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
233 | COM_INTERFACE_ENTRY(IVRDEServerInfo)
|
---|
234 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
235 | END_COM_MAP()
|
---|
236 |
|
---|
237 | DECLARE_EMPTY_CTOR_DTOR (VRDEServerInfo)
|
---|
238 |
|
---|
239 | HRESULT FinalConstruct();
|
---|
240 | void FinalRelease();
|
---|
241 |
|
---|
242 | /* Public initializer/uninitializer for internal purposes only. */
|
---|
243 | HRESULT init (Console *aParent);
|
---|
244 | void uninit();
|
---|
245 |
|
---|
246 | /* IVRDEServerInfo properties */
|
---|
247 | #define DECL_GETTER(_aType, _aName) STDMETHOD(COMGETTER(_aName)) (_aType *a##_aName)
|
---|
248 | DECL_GETTER (BOOL, Active);
|
---|
249 | DECL_GETTER (LONG, Port);
|
---|
250 | DECL_GETTER (ULONG, NumberOfClients);
|
---|
251 | DECL_GETTER (LONG64, BeginTime);
|
---|
252 | DECL_GETTER (LONG64, EndTime);
|
---|
253 | DECL_GETTER (LONG64, BytesSent);
|
---|
254 | DECL_GETTER (LONG64, BytesSentTotal);
|
---|
255 | DECL_GETTER (LONG64, BytesReceived);
|
---|
256 | DECL_GETTER (LONG64, BytesReceivedTotal);
|
---|
257 | DECL_GETTER (BSTR, User);
|
---|
258 | DECL_GETTER (BSTR, Domain);
|
---|
259 | DECL_GETTER (BSTR, ClientName);
|
---|
260 | DECL_GETTER (BSTR, ClientIP);
|
---|
261 | DECL_GETTER (ULONG, ClientVersion);
|
---|
262 | DECL_GETTER (ULONG, EncryptionStyle);
|
---|
263 | #undef DECL_GETTER
|
---|
264 |
|
---|
265 | private:
|
---|
266 |
|
---|
267 | Console * const mParent;
|
---|
268 | };
|
---|
269 |
|
---|
270 | #endif // ____H_CONSOLEVRDPSERVER
|
---|
271 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|