VirtualBox

source: vbox/trunk/src/VBox/Main/include/ConsoleVRDPServer.h@ 78897

Last change on this file since 78897 was 78897, checked in by vboxsync, 6 years ago

Shared Clipboard/URI: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 KB
Line 
1/* $Id: ConsoleVRDPServer.h 78897 2019-05-31 15:23:14Z vboxsync $ */
2/** @file
3 * VBox Console VRDE Server Helper class and implementation of IVRDEServerInfo
4 */
5
6/*
7 * Copyright (C) 2006-2019 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 MAIN_INCLUDED_ConsoleVRDPServer_h
19#define MAIN_INCLUDED_ConsoleVRDPServer_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "VRDEServerInfoWrap.h"
25#include "RemoteUSBBackend.h"
26#include "HGCM.h"
27
28#include "AuthLibrary.h"
29
30#include <VBox/RemoteDesktop/VRDEImage.h>
31#include <VBox/RemoteDesktop/VRDEMousePtr.h>
32#include <VBox/RemoteDesktop/VRDESCard.h>
33#include <VBox/RemoteDesktop/VRDETSMF.h>
34#define VRDE_VIDEOIN_WITH_VRDEINTERFACE /* Get the VRDE interface definitions. */
35#include <VBox/RemoteDesktop/VRDEVideoIn.h>
36#include <VBox/RemoteDesktop/VRDEInput.h>
37
38#include <VBox/HostServices/VBoxClipboardExt.h>
39#include <VBox/HostServices/VBoxHostChannel.h>
40
41#include "SchemaDefs.h"
42
43// ConsoleVRDPServer
44///////////////////////////////////////////////////////////////////////////////
45
46class EmWebcam;
47
48typedef struct _VRDPInputSynch
49{
50 int cGuestNumLockAdaptions;
51 int cGuestCapsLockAdaptions;
52
53 bool fGuestNumLock;
54 bool fGuestCapsLock;
55 bool fGuestScrollLock;
56
57 bool fClientNumLock;
58 bool fClientCapsLock;
59 bool fClientScrollLock;
60} VRDPInputSynch;
61
62/* Member of Console. Helper class for VRDP server management. Not a COM class. */
63class ConsoleVRDPServer
64{
65public:
66 ConsoleVRDPServer (Console *console);
67 ~ConsoleVRDPServer ();
68
69 int Launch (void);
70
71 void NotifyAbsoluteMouse (bool fGuestWantsAbsolute)
72 {
73 m_fGuestWantsAbsolute = fGuestWantsAbsolute;
74 }
75
76 void NotifyKeyboardLedsChange (BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
77 {
78 bool fGuestNumLock = (fNumLock != FALSE);
79 bool fGuestCapsLock = (fCapsLock != FALSE);
80 bool fGuestScrollLock = (fScrollLock != FALSE);
81
82 /* Might need to resync in case the guest itself changed the LED status. */
83 if (m_InputSynch.fClientNumLock != fGuestNumLock)
84 {
85 m_InputSynch.cGuestNumLockAdaptions = 2;
86 }
87
88 if (m_InputSynch.fClientCapsLock != fGuestCapsLock)
89 {
90 m_InputSynch.cGuestCapsLockAdaptions = 2;
91 }
92
93 m_InputSynch.fGuestNumLock = fGuestNumLock;
94 m_InputSynch.fGuestCapsLock = fGuestCapsLock;
95 m_InputSynch.fGuestScrollLock = fGuestScrollLock;
96 }
97
98 void EnableConnections (void);
99 void DisconnectClient (uint32_t u32ClientId, bool fReconnect);
100 int MousePointer(BOOL alpha, ULONG xHot, ULONG yHot, ULONG width, ULONG height, const uint8_t *pu8Shape);
101 void MousePointerUpdate (const VRDECOLORPOINTER *pPointer);
102 void MousePointerHide (void);
103
104 void Stop (void);
105
106 AuthResult Authenticate (const Guid &uuid, AuthGuestJudgement guestJudgement,
107 const char *pszUser, const char *pszPassword, const char *pszDomain,
108 uint32_t u32ClientId);
109
110 void AuthDisconnect (const Guid &uuid, uint32_t u32ClientId);
111
112 void USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept);
113 void USBBackendDelete (uint32_t u32ClientId);
114
115 void *USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid);
116 void USBBackendReleasePointer (const Guid *pGuid);
117
118 /* Private interface for the RemoteUSBBackend destructor. */
119 void usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend);
120
121 /* Private methods for the Remote USB thread. */
122 RemoteUSBBackend *usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend);
123
124 void notifyRemoteUSBThreadRunning (RTTHREAD thread);
125 bool isRemoteUSBThreadRunning (void);
126 void waitRemoteUSBThreadEvent (RTMSINTERVAL cMillies);
127
128 void ClipboardCreate (uint32_t u32ClientId);
129 void ClipboardDelete (uint32_t u32ClientId);
130
131 /*
132 * Forwarders to VRDP server library.
133 */
134 void SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const;
135 void SendResize (void);
136 void SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const;
137
138 void SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const;
139 void SendAudioVolume (uint16_t left, uint16_t right) const;
140 void SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const;
141 void SendClipboard (uint32_t u32Function, uint32_t u32Format,
142 void *pvData, uint32_t cbData, uint32_t *pcbActualRead) const;
143
144 void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
145
146 int SendAudioInputBegin(void **ppvUserCtx,
147 void *pvContext,
148 uint32_t cSamples,
149 uint32_t iSampleHz,
150 uint32_t cChannels,
151 uint32_t cBits);
152
153 void SendAudioInputEnd(void *pvUserCtx);
154
155 int SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData);
156
157 int VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx);
158 int VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
159 int VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
160 int VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
161 const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq);
162
163 Console *getConsole(void) { return mConsole; }
164
165 void onMousePointerShapeChange(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
166 ULONG width, ULONG height, ComSafeArrayIn(BYTE,shape));
167
168private:
169 /* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
170 * is actually just a part of the Console.
171 */
172 Console *mConsole;
173
174 HVRDESERVER mhServer;
175 int mServerInterfaceVersion;
176
177 int32_t volatile mcInResize; /* Do not Stop the server if this is not 0. */
178
179 static int loadVRDPLibrary (const char *pszLibraryName);
180
181 /** Static because will never load this more than once! */
182 static RTLDRMOD mVRDPLibrary;
183
184 static PFNVRDECREATESERVER mpfnVRDECreateServer;
185
186 static VRDEENTRYPOINTS_4 mEntryPoints;
187 static VRDEENTRYPOINTS_4 *mpEntryPoints;
188 static VRDECALLBACKS_4 mCallbacks;
189
190 static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
191 static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
192 static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
193 static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
194 static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
195 static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
196 static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
197 static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDEFRAMEBUFFERINFO *pInfo);
198 static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
199 static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
200 static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
201 static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
202 static DECLCALLBACK(void) VRDECallbackAudioIn (void *pvCallback, void *pvCtx, uint32_t u32ClientId, uint32_t u32Event, const void *pvData, uint32_t cbData);
203
204 void fetchCurrentState(void);
205
206 bool m_fGuestWantsAbsolute;
207 int m_mousex;
208 int m_mousey;
209
210 ComPtr<IDisplaySourceBitmap> maSourceBitmaps[SchemaDefs::MaxGuestMonitors];
211
212 ComPtr<IEventListener> mConsoleListener;
213
214 VRDPInputSynch m_InputSynch;
215
216 int32_t mVRDPBindPort;
217
218 RTCRITSECT mCritSect;
219
220 int lockConsoleVRDPServer (void);
221 void unlockConsoleVRDPServer (void);
222
223 int mcClipboardRefs;
224 PFNVRDPCLIPBOARDEXTCALLBACK mpfnClipboardCallback;
225
226 static DECLCALLBACK(int) ClipboardCallback (void *pvCallback, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
227
228#ifdef VBOX_WITH_USB
229 RemoteUSBBackend *usbBackendFindByUUID (const Guid *pGuid);
230 RemoteUSBBackend *usbBackendFind (uint32_t u32ClientId);
231
232 typedef struct _USBBackends
233 {
234 RemoteUSBBackend *pHead;
235 RemoteUSBBackend *pTail;
236
237 RTTHREAD thread;
238
239 bool fThreadRunning;
240
241 RTSEMEVENT event;
242 } USBBackends;
243
244 USBBackends mUSBBackends;
245
246 void remoteUSBThreadStart (void);
247 void remoteUSBThreadStop (void);
248#endif /* VBOX_WITH_USB */
249
250#ifndef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
251 /* External authentication library context. The library is loaded in the
252 * Authenticate method and unloaded at the object destructor.
253 */
254 AUTHLIBRARYCONTEXT mAuthLibCtx;
255#endif
256
257 uint32_t volatile mu32AudioInputClientId;
258
259 int32_t volatile mcClients;
260
261 static DECLCALLBACK(void) H3DORBegin(const void *pvContext, void **ppvInstance,
262 const char *pszFormat);
263 static DECLCALLBACK(void) H3DORGeometry(void *pvInstance,
264 int32_t x, int32_t y, uint32_t w, uint32_t h);
265 static DECLCALLBACK(void) H3DORVisibleRegion(void *pvInstance,
266 uint32_t cRects, const RTRECT *paRects);
267 static DECLCALLBACK(void) H3DORFrame(void *pvInstance,
268 void *pvData, uint32_t cbData);
269 static DECLCALLBACK(void) H3DOREnd(void *pvInstance);
270 static DECLCALLBACK(int) H3DORContextProperty(const void *pvContext, uint32_t index,
271 void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
272
273 void remote3DRedirect(bool fEnable);
274
275 /*
276 * VRDE server optional interfaces.
277 */
278
279 /* Image update interface. */
280 bool m_fInterfaceImage;
281 VRDEIMAGECALLBACKS m_interfaceCallbacksImage;
282 VRDEIMAGEINTERFACE m_interfaceImage;
283 static DECLCALLBACK(int) VRDEImageCbNotify (void *pvContext,
284 void *pvUser,
285 HVRDEIMAGE hVideo,
286 uint32_t u32Id,
287 void *pvData,
288 uint32_t cbData);
289 /* Mouse pointer interface. */
290 VRDEMOUSEPTRINTERFACE m_interfaceMousePtr;
291
292 /* Smartcard interface. */
293 VRDESCARDINTERFACE m_interfaceSCard;
294 VRDESCARDCALLBACKS m_interfaceCallbacksSCard;
295 static DECLCALLBACK(int) VRDESCardCbNotify(void *pvContext,
296 uint32_t u32Id,
297 void *pvData,
298 uint32_t cbData);
299 static DECLCALLBACK(int) VRDESCardCbResponse(void *pvContext,
300 int rcRequest,
301 void *pvUser,
302 uint32_t u32Function,
303 void *pvData,
304 uint32_t cbData);
305
306 /* TSMF interface. */
307 VRDETSMFINTERFACE m_interfaceTSMF;
308 VRDETSMFCALLBACKS m_interfaceCallbacksTSMF;
309 static DECLCALLBACK(void) VRDETSMFCbNotify(void *pvContext,
310 uint32_t u32Notification,
311 void *pvChannel,
312 const void *pvParm,
313 uint32_t cbParm);
314 void setupTSMF(void);
315
316 static DECLCALLBACK(int) tsmfHostChannelAttach(void *pvProvider, void **ppvInstance, uint32_t u32Flags,
317 VBOXHOSTCHANNELCALLBACKS *pCallbacks, void *pvCallbacks);
318 static DECLCALLBACK(void) tsmfHostChannelDetach(void *pvInstance);
319 static DECLCALLBACK(int) tsmfHostChannelSend(void *pvInstance, const void *pvData, uint32_t cbData);
320 static DECLCALLBACK(int) tsmfHostChannelRecv(void *pvInstance, void *pvData, uint32_t cbData,
321 uint32_t *pcbReturned, uint32_t *pcbRemaining);
322 static DECLCALLBACK(int) tsmfHostChannelControl(void *pvInstance, uint32_t u32Code,
323 const void *pvParm, uint32_t cbParm,
324 const void *pvData, uint32_t cbData, uint32_t *pcbDataReturned);
325 int tsmfLock(void);
326 void tsmfUnlock(void);
327 RTCRITSECT mTSMFLock;
328
329 /* Video input interface. */
330 VRDEVIDEOININTERFACE m_interfaceVideoIn;
331 VRDEVIDEOINCALLBACKS m_interfaceCallbacksVideoIn;
332 static DECLCALLBACK(void) VRDECallbackVideoInNotify(void *pvCallback,
333 uint32_t u32Id,
334 const void *pvData,
335 uint32_t cbData);
336 static DECLCALLBACK(void) VRDECallbackVideoInDeviceDesc(void *pvCallback,
337 int rcRequest,
338 void *pDeviceCtx,
339 void *pvUser,
340 const VRDEVIDEOINDEVICEDESC *pDeviceDesc,
341 uint32_t cbDevice);
342 static DECLCALLBACK(void) VRDECallbackVideoInControl(void *pvCallback,
343 int rcRequest,
344 void *pDeviceCtx,
345 void *pvUser,
346 const VRDEVIDEOINCTRLHDR *pControl,
347 uint32_t cbControl);
348 static DECLCALLBACK(void) VRDECallbackVideoInFrame(void *pvCallback,
349 int rcRequest,
350 void *pDeviceCtx,
351 const VRDEVIDEOINPAYLOADHDR *pFrame,
352 uint32_t cbFrame);
353 EmWebcam *mEmWebcam;
354
355 /* Input interface. */
356 VRDEINPUTINTERFACE m_interfaceInput;
357 VRDEINPUTCALLBACKS m_interfaceCallbacksInput;
358 static DECLCALLBACK(void) VRDECallbackInputSetup(void *pvCallback,
359 int rcRequest,
360 uint32_t u32Method,
361 const void *pvResult,
362 uint32_t cbResult);
363 static DECLCALLBACK(void) VRDECallbackInputEvent(void *pvCallback,
364 uint32_t u32Method,
365 const void *pvEvent,
366 uint32_t cbEvent);
367 uint64_t mu64TouchInputTimestampMCS;
368};
369
370
371class Console;
372
373class ATL_NO_VTABLE VRDEServerInfo :
374 public VRDEServerInfoWrap
375{
376public:
377 DECLARE_NOT_AGGREGATABLE(VRDEServerInfo)
378
379 DECLARE_EMPTY_CTOR_DTOR(VRDEServerInfo)
380
381 HRESULT FinalConstruct();
382 void FinalRelease();
383
384 /* Public initializer/uninitializer for internal purposes only. */
385 HRESULT init(Console *aParent);
386 void uninit();
387
388private:
389 // wrapped IVRDEServerInfo properties
390#define DECL_GETTER(_aType, _aName) virtual HRESULT get##_aName(_aType *a##_aName)
391#define DECL_GETTER_REF(_aType, _aName) virtual HRESULT get##_aName(_aType &a##_aName)
392 DECL_GETTER(BOOL, Active);
393 DECL_GETTER(LONG, Port);
394 DECL_GETTER(ULONG, NumberOfClients);
395 DECL_GETTER(LONG64, BeginTime);
396 DECL_GETTER(LONG64, EndTime);
397 DECL_GETTER(LONG64, BytesSent);
398 DECL_GETTER(LONG64, BytesSentTotal);
399 DECL_GETTER(LONG64, BytesReceived);
400 DECL_GETTER(LONG64, BytesReceivedTotal);
401 DECL_GETTER_REF(com::Utf8Str, User);
402 DECL_GETTER_REF(com::Utf8Str, Domain);
403 DECL_GETTER_REF(com::Utf8Str, ClientName);
404 DECL_GETTER_REF(com::Utf8Str, ClientIP);
405 DECL_GETTER(ULONG, ClientVersion);
406 DECL_GETTER(ULONG, EncryptionStyle);
407#undef DECL_GETTER_REF
408#undef DECL_GETTER
409
410 Console * const mParent;
411};
412
413#endif /* !MAIN_INCLUDED_ConsoleVRDPServer_h */
414/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette