1 | /* $Id: ConsoleVRDPServer.h 43350 2012-09-18 14:39:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Console VRDE Server Helper class and implementation of IVRDEServerInfo
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ____H_CONSOLEVRDPSERVER
|
---|
19 | #define ____H_CONSOLEVRDPSERVER
|
---|
20 |
|
---|
21 | #include "RemoteUSBBackend.h"
|
---|
22 | #include "HGCM.h"
|
---|
23 |
|
---|
24 | #include <VBox/VBoxAuth.h>
|
---|
25 |
|
---|
26 | #include <VBox/RemoteDesktop/VRDEImage.h>
|
---|
27 | #include <VBox/RemoteDesktop/VRDEMousePtr.h>
|
---|
28 | #include <VBox/RemoteDesktop/VRDESCard.h>
|
---|
29 | #include <VBox/RemoteDesktop/VRDETSMF.h>
|
---|
30 |
|
---|
31 | #include <VBox/HostServices/VBoxClipboardExt.h>
|
---|
32 | #include <VBox/HostServices/VBoxHostChannel.h>
|
---|
33 |
|
---|
34 | #include "SchemaDefs.h"
|
---|
35 |
|
---|
36 | // ConsoleVRDPServer
|
---|
37 | ///////////////////////////////////////////////////////////////////////////////
|
---|
38 |
|
---|
39 | typedef struct _VRDPInputSynch
|
---|
40 | {
|
---|
41 | int cGuestNumLockAdaptions;
|
---|
42 | int cGuestCapsLockAdaptions;
|
---|
43 |
|
---|
44 | bool fGuestNumLock;
|
---|
45 | bool fGuestCapsLock;
|
---|
46 | bool fGuestScrollLock;
|
---|
47 |
|
---|
48 | bool fClientNumLock;
|
---|
49 | bool fClientCapsLock;
|
---|
50 | bool fClientScrollLock;
|
---|
51 | } VRDPInputSynch;
|
---|
52 |
|
---|
53 | /* Member of Console. Helper class for VRDP server management. Not a COM class. */
|
---|
54 | class ConsoleVRDPServer
|
---|
55 | {
|
---|
56 | public:
|
---|
57 | ConsoleVRDPServer (Console *console);
|
---|
58 | ~ConsoleVRDPServer ();
|
---|
59 |
|
---|
60 | int Launch (void);
|
---|
61 |
|
---|
62 | void NotifyAbsoluteMouse (bool fGuestWantsAbsolute)
|
---|
63 | {
|
---|
64 | m_fGuestWantsAbsolute = fGuestWantsAbsolute;
|
---|
65 | }
|
---|
66 |
|
---|
67 | void NotifyKeyboardLedsChange (BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
|
---|
68 | {
|
---|
69 | bool fGuestNumLock = (fNumLock != FALSE);
|
---|
70 | bool fGuestCapsLock = (fCapsLock != FALSE);
|
---|
71 | bool fGuestScrollLock = (fScrollLock != FALSE);
|
---|
72 |
|
---|
73 | /* Might need to resync in case the guest itself changed the LED status. */
|
---|
74 | if (m_InputSynch.fClientNumLock != fGuestNumLock)
|
---|
75 | {
|
---|
76 | m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
77 | }
|
---|
78 |
|
---|
79 | if (m_InputSynch.fClientCapsLock != fGuestCapsLock)
|
---|
80 | {
|
---|
81 | m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
82 | }
|
---|
83 |
|
---|
84 | m_InputSynch.fGuestNumLock = fGuestNumLock;
|
---|
85 | m_InputSynch.fGuestCapsLock = fGuestCapsLock;
|
---|
86 | m_InputSynch.fGuestScrollLock = fGuestScrollLock;
|
---|
87 | }
|
---|
88 |
|
---|
89 | void EnableConnections (void);
|
---|
90 | void DisconnectClient (uint32_t u32ClientId, bool fReconnect);
|
---|
91 | int MousePointer(BOOL alpha, ULONG xHot, ULONG yHot, ULONG width, ULONG height, const uint8_t *pu8Shape);
|
---|
92 | void MousePointerUpdate (const VRDECOLORPOINTER *pPointer);
|
---|
93 | void MousePointerHide (void);
|
---|
94 |
|
---|
95 | void Stop (void);
|
---|
96 |
|
---|
97 | AuthResult Authenticate (const Guid &uuid, AuthGuestJudgement guestJudgement,
|
---|
98 | const char *pszUser, const char *pszPassword, const char *pszDomain,
|
---|
99 | uint32_t u32ClientId);
|
---|
100 |
|
---|
101 | void AuthDisconnect (const Guid &uuid, uint32_t u32ClientId);
|
---|
102 |
|
---|
103 | void USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept);
|
---|
104 | void USBBackendDelete (uint32_t u32ClientId);
|
---|
105 |
|
---|
106 | void *USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid);
|
---|
107 | void USBBackendReleasePointer (const Guid *pGuid);
|
---|
108 |
|
---|
109 | /* Private interface for the RemoteUSBBackend destructor. */
|
---|
110 | void usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend);
|
---|
111 |
|
---|
112 | /* Private methods for the Remote USB thread. */
|
---|
113 | RemoteUSBBackend *usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend);
|
---|
114 |
|
---|
115 | void notifyRemoteUSBThreadRunning (RTTHREAD thread);
|
---|
116 | bool isRemoteUSBThreadRunning (void);
|
---|
117 | void waitRemoteUSBThreadEvent (RTMSINTERVAL cMillies);
|
---|
118 |
|
---|
119 | void ClipboardCreate (uint32_t u32ClientId);
|
---|
120 | void ClipboardDelete (uint32_t u32ClientId);
|
---|
121 |
|
---|
122 | /*
|
---|
123 | * Forwarders to VRDP server library.
|
---|
124 | */
|
---|
125 | void SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const;
|
---|
126 | void SendResize (void) const;
|
---|
127 | void SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const;
|
---|
128 |
|
---|
129 | void SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const;
|
---|
130 | void SendAudioVolume (uint16_t left, uint16_t right) const;
|
---|
131 | void SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const;
|
---|
132 |
|
---|
133 | void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
|
---|
134 |
|
---|
135 | int SendAudioInputBegin(void **ppvUserCtx,
|
---|
136 | void *pvContext,
|
---|
137 | uint32_t cSamples,
|
---|
138 | uint32_t iSampleHz,
|
---|
139 | uint32_t cChannels,
|
---|
140 | uint32_t cBits);
|
---|
141 |
|
---|
142 | void SendAudioInputEnd(void *pvUserCtx);
|
---|
143 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
144 | int GetVideoFrameDimensions(uint16_t *pu16Heigh, uint16_t *pu16Width);
|
---|
145 | int SendVideoSreamOn(bool fFetch);
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | int SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData);
|
---|
149 |
|
---|
150 | private:
|
---|
151 | /* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
|
---|
152 | * is actually just a part of the Console.
|
---|
153 | */
|
---|
154 | Console *mConsole;
|
---|
155 |
|
---|
156 | HVRDESERVER mhServer;
|
---|
157 | int mServerInterfaceVersion;
|
---|
158 |
|
---|
159 | static int loadVRDPLibrary (const char *pszLibraryName);
|
---|
160 |
|
---|
161 | /** Static because will never load this more than once! */
|
---|
162 | static RTLDRMOD mVRDPLibrary;
|
---|
163 |
|
---|
164 | static PFNVRDECREATESERVER mpfnVRDECreateServer;
|
---|
165 |
|
---|
166 | static VRDEENTRYPOINTS_4 mEntryPoints;
|
---|
167 | static VRDEENTRYPOINTS_4 *mpEntryPoints;
|
---|
168 | static VRDECALLBACKS_4 mCallbacks;
|
---|
169 |
|
---|
170 | static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
|
---|
171 | static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
|
---|
172 | static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
|
---|
173 | static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
|
---|
174 | static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
|
---|
175 | static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
|
---|
176 | static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
|
---|
177 | static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDEFRAMEBUFFERINFO *pInfo);
|
---|
178 | static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
|
---|
179 | static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
|
---|
180 | static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
|
---|
181 | static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
|
---|
182 | static DECLCALLBACK(void) VRDECallbackAudioIn (void *pvCallback, void *pvCtx, uint32_t u32ClientId, uint32_t u32Event, const void *pvData, uint32_t cbData);
|
---|
183 |
|
---|
184 | bool m_fGuestWantsAbsolute;
|
---|
185 | int m_mousex;
|
---|
186 | int m_mousey;
|
---|
187 |
|
---|
188 | IFramebuffer *maFramebuffers[SchemaDefs::MaxGuestMonitors];
|
---|
189 |
|
---|
190 | ComPtr<IEventListener> mConsoleListener;
|
---|
191 |
|
---|
192 | VRDPInputSynch m_InputSynch;
|
---|
193 |
|
---|
194 | int32_t mVRDPBindPort;
|
---|
195 |
|
---|
196 | RTCRITSECT mCritSect;
|
---|
197 |
|
---|
198 | int lockConsoleVRDPServer (void);
|
---|
199 | void unlockConsoleVRDPServer (void);
|
---|
200 |
|
---|
201 | int mcClipboardRefs;
|
---|
202 | HGCMSVCEXTHANDLE mhClipboard;
|
---|
203 | PFNVRDPCLIPBOARDEXTCALLBACK mpfnClipboardCallback;
|
---|
204 |
|
---|
205 | static DECLCALLBACK(int) ClipboardCallback (void *pvCallback, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
|
---|
206 | static DECLCALLBACK(int) ClipboardServiceExtension (void *pvExtension, uint32_t u32Function, void *pvParm, uint32_t cbParms);
|
---|
207 |
|
---|
208 | #ifdef VBOX_WITH_USB
|
---|
209 | RemoteUSBBackend *usbBackendFindByUUID (const Guid *pGuid);
|
---|
210 | RemoteUSBBackend *usbBackendFind (uint32_t u32ClientId);
|
---|
211 |
|
---|
212 | typedef struct _USBBackends
|
---|
213 | {
|
---|
214 | RemoteUSBBackend *pHead;
|
---|
215 | RemoteUSBBackend *pTail;
|
---|
216 |
|
---|
217 | RTTHREAD thread;
|
---|
218 |
|
---|
219 | bool fThreadRunning;
|
---|
220 |
|
---|
221 | RTSEMEVENT event;
|
---|
222 | } USBBackends;
|
---|
223 |
|
---|
224 | USBBackends mUSBBackends;
|
---|
225 |
|
---|
226 | void remoteUSBThreadStart (void);
|
---|
227 | void remoteUSBThreadStop (void);
|
---|
228 | #endif /* VBOX_WITH_USB */
|
---|
229 |
|
---|
230 | /* External authentication library handle. The library is loaded in the
|
---|
231 | * Authenticate method and unloaded at the object destructor.
|
---|
232 | */
|
---|
233 | RTLDRMOD mAuthLibrary;
|
---|
234 | PAUTHENTRY mpfnAuthEntry;
|
---|
235 | PAUTHENTRY2 mpfnAuthEntry2;
|
---|
236 | PAUTHENTRY3 mpfnAuthEntry3;
|
---|
237 |
|
---|
238 | uint32_t volatile mu32AudioInputClientId;
|
---|
239 |
|
---|
240 | static DECLCALLBACK(void) H3DORBegin(const void *pvContext, void **ppvInstance,
|
---|
241 | const char *pszFormat);
|
---|
242 | static DECLCALLBACK(void) H3DORGeometry(void *pvInstance,
|
---|
243 | int32_t x, int32_t y, uint32_t w, uint32_t h);
|
---|
244 | static DECLCALLBACK(void) H3DORVisibleRegion(void *pvInstance,
|
---|
245 | uint32_t cRects, RTRECT *paRects);
|
---|
246 | static DECLCALLBACK(void) H3DORFrame(void *pvInstance,
|
---|
247 | void *pvData, uint32_t cbData);
|
---|
248 | static DECLCALLBACK(void) H3DOREnd(void *pvInstance);
|
---|
249 | static DECLCALLBACK(int) H3DORContextProperty(const void *pvContext, uint32_t index,
|
---|
250 | void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
|
---|
251 |
|
---|
252 | void remote3DRedirect(void);
|
---|
253 |
|
---|
254 | /*
|
---|
255 | * VRDE server optional interfaces.
|
---|
256 | */
|
---|
257 |
|
---|
258 | /* Image update interface. */
|
---|
259 | bool m_fInterfaceImage;
|
---|
260 | VRDEIMAGECALLBACKS m_interfaceCallbacksImage;
|
---|
261 | VRDEIMAGEINTERFACE m_interfaceImage;
|
---|
262 | static DECLCALLBACK(int) VRDEImageCbNotify (void *pvContext,
|
---|
263 | void *pvUser,
|
---|
264 | HVRDEIMAGE hVideo,
|
---|
265 | uint32_t u32Id,
|
---|
266 | void *pvData,
|
---|
267 | uint32_t cbData);
|
---|
268 | /* Mouse pointer interface. */
|
---|
269 | VRDEMOUSEPTRINTERFACE m_interfaceMousePtr;
|
---|
270 |
|
---|
271 | /* Smartcard interface. */
|
---|
272 | VRDESCARDINTERFACE m_interfaceSCard;
|
---|
273 | VRDESCARDCALLBACKS m_interfaceCallbacksSCard;
|
---|
274 | static DECLCALLBACK(int) VRDESCardCbNotify(void *pvContext,
|
---|
275 | uint32_t u32Id,
|
---|
276 | void *pvData,
|
---|
277 | uint32_t cbData);
|
---|
278 | static DECLCALLBACK(int) VRDESCardCbResponse(void *pvContext,
|
---|
279 | int rcRequest,
|
---|
280 | void *pvUser,
|
---|
281 | uint32_t u32Function,
|
---|
282 | void *pvData,
|
---|
283 | uint32_t cbData);
|
---|
284 |
|
---|
285 | /* TSMF interface. */
|
---|
286 | VRDETSMFINTERFACE m_interfaceTSMF;
|
---|
287 | VRDETSMFCALLBACKS m_interfaceCallbacksTSMF;
|
---|
288 | static DECLCALLBACK(void) VRDETSMFCbNotify(void *pvContext,
|
---|
289 | uint32_t u32Notification,
|
---|
290 | void *pvChannel,
|
---|
291 | const void *pvParm,
|
---|
292 | uint32_t cbParm);
|
---|
293 | void setupTSMF(void);
|
---|
294 |
|
---|
295 | static DECLCALLBACK(int) tsmfHostChannelAttach(void *pvProvider, void **ppvInstance, uint32_t u32Flags,
|
---|
296 | VBOXHOSTCHANNELCALLBACKS *pCallbacks, void *pvCallbacks);
|
---|
297 | static DECLCALLBACK(void) tsmfHostChannelDetach(void *pvInstance);
|
---|
298 | static DECLCALLBACK(int) tsmfHostChannelSend(void *pvInstance, const void *pvData, uint32_t cbData);
|
---|
299 | static DECLCALLBACK(int) tsmfHostChannelRecv(void *pvInstance, void *pvData, uint32_t cbData,
|
---|
300 | uint32_t *pcbReturned, uint32_t *pcbRemaining);
|
---|
301 | static DECLCALLBACK(int) tsmfHostChannelControl(void *pvInstance, uint32_t u32Code,
|
---|
302 | const void *pvParm, uint32_t cbParm,
|
---|
303 | const void *pvData, uint32_t cbData, uint32_t *pcbDataReturned);
|
---|
304 | };
|
---|
305 |
|
---|
306 |
|
---|
307 | class Console;
|
---|
308 |
|
---|
309 | class ATL_NO_VTABLE VRDEServerInfo :
|
---|
310 | public VirtualBoxBase,
|
---|
311 | VBOX_SCRIPTABLE_IMPL(IVRDEServerInfo)
|
---|
312 | {
|
---|
313 | public:
|
---|
314 |
|
---|
315 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VRDEServerInfo, IVRDEServerInfo)
|
---|
316 |
|
---|
317 | DECLARE_NOT_AGGREGATABLE(VRDEServerInfo)
|
---|
318 |
|
---|
319 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
320 |
|
---|
321 | BEGIN_COM_MAP(VRDEServerInfo)
|
---|
322 | VBOX_DEFAULT_INTERFACE_ENTRIES(IVRDEServerInfo)
|
---|
323 | END_COM_MAP()
|
---|
324 |
|
---|
325 | DECLARE_EMPTY_CTOR_DTOR (VRDEServerInfo)
|
---|
326 |
|
---|
327 | HRESULT FinalConstruct();
|
---|
328 | void FinalRelease();
|
---|
329 |
|
---|
330 | /* Public initializer/uninitializer for internal purposes only. */
|
---|
331 | HRESULT init (Console *aParent);
|
---|
332 | void uninit();
|
---|
333 |
|
---|
334 | /* IVRDEServerInfo properties */
|
---|
335 | #define DECL_GETTER(_aType, _aName) STDMETHOD(COMGETTER(_aName)) (_aType *a##_aName)
|
---|
336 | DECL_GETTER (BOOL, Active);
|
---|
337 | DECL_GETTER (LONG, Port);
|
---|
338 | DECL_GETTER (ULONG, NumberOfClients);
|
---|
339 | DECL_GETTER (LONG64, BeginTime);
|
---|
340 | DECL_GETTER (LONG64, EndTime);
|
---|
341 | DECL_GETTER (LONG64, BytesSent);
|
---|
342 | DECL_GETTER (LONG64, BytesSentTotal);
|
---|
343 | DECL_GETTER (LONG64, BytesReceived);
|
---|
344 | DECL_GETTER (LONG64, BytesReceivedTotal);
|
---|
345 | DECL_GETTER (BSTR, User);
|
---|
346 | DECL_GETTER (BSTR, Domain);
|
---|
347 | DECL_GETTER (BSTR, ClientName);
|
---|
348 | DECL_GETTER (BSTR, ClientIP);
|
---|
349 | DECL_GETTER (ULONG, ClientVersion);
|
---|
350 | DECL_GETTER (ULONG, EncryptionStyle);
|
---|
351 | #undef DECL_GETTER
|
---|
352 |
|
---|
353 | private:
|
---|
354 |
|
---|
355 | Console * const mParent;
|
---|
356 | };
|
---|
357 |
|
---|
358 | #endif // ____H_CONSOLEVRDPSERVER
|
---|
359 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|