VirtualBox

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

Last change on this file since 87093 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.5 KB
Line 
1/* $Id: ConsoleVRDPServer.h 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VBox Console VRDE Server Helper class and implementation of IVRDEServerInfo
4 */
5
6/*
7 * Copyright (C) 2006-2020 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
142 void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
143
144 int SendAudioInputBegin(void **ppvUserCtx,
145 void *pvContext,
146 uint32_t cSamples,
147 uint32_t iSampleHz,
148 uint32_t cChannels,
149 uint32_t cBits);
150
151 void SendAudioInputEnd(void *pvUserCtx);
152
153 int SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData);
154
155 int VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx);
156 int VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
157 int VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle);
158 int VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
159 const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq);
160
161 Console *getConsole(void) { return mConsole; }
162
163 void onMousePointerShapeChange(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
164 ULONG width, ULONG height, ComSafeArrayIn(BYTE,shape));
165
166private:
167 /* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
168 * is actually just a part of the Console.
169 */
170 Console *mConsole;
171
172 HVRDESERVER mhServer;
173 int mServerInterfaceVersion;
174
175 int32_t volatile mcInResize; /* Do not Stop the server if this is not 0. */
176
177 static int loadVRDPLibrary (const char *pszLibraryName);
178
179 /** Static because will never load this more than once! */
180 static RTLDRMOD mVRDPLibrary;
181
182 static PFNVRDECREATESERVER mpfnVRDECreateServer;
183
184 static VRDEENTRYPOINTS_4 mEntryPoints;
185 static VRDEENTRYPOINTS_4 *mpEntryPoints;
186 static VRDECALLBACKS_4 mCallbacks;
187
188 static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
189 static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
190 static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
191 static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
192 static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
193 static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
194 static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
195 static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDEFRAMEBUFFERINFO *pInfo);
196 static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
197 static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
198 static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
199 static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
200 static DECLCALLBACK(void) VRDECallbackAudioIn (void *pvCallback, void *pvCtx, uint32_t u32ClientId, uint32_t u32Event, const void *pvData, uint32_t cbData);
201
202 void fetchCurrentState(void);
203
204 bool m_fGuestWantsAbsolute;
205 int m_mousex;
206 int m_mousey;
207
208 ComPtr<IDisplaySourceBitmap> maSourceBitmaps[SchemaDefs::MaxGuestMonitors];
209
210 ComPtr<IEventListener> mConsoleListener;
211
212 VRDPInputSynch m_InputSynch;
213
214 int32_t mVRDPBindPort;
215
216 RTCRITSECT mCritSect;
217
218 int lockConsoleVRDPServer (void);
219 void unlockConsoleVRDPServer (void);
220
221 int mcClipboardRefs;
222 HGCMSVCEXTHANDLE mhClipboard;
223 PFNVRDPCLIPBOARDEXTCALLBACK mpfnClipboardCallback;
224
225 static DECLCALLBACK(int) ClipboardCallback (void *pvCallback, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
226 static DECLCALLBACK(int) ClipboardServiceExtension(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
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#if 0 /** @todo Chromium got removed (see @bugref{9529}) and this is not available for VMSVGA yet. */
262 static DECLCALLBACK(void) H3DORBegin(const void *pvContext, void **ppvInstance,
263 const char *pszFormat);
264 static DECLCALLBACK(void) H3DORGeometry(void *pvInstance,
265 int32_t x, int32_t y, uint32_t w, uint32_t h);
266 static DECLCALLBACK(void) H3DORVisibleRegion(void *pvInstance,
267 uint32_t cRects, const RTRECT *paRects);
268 static DECLCALLBACK(void) H3DORFrame(void *pvInstance,
269 void *pvData, uint32_t cbData);
270 static DECLCALLBACK(void) H3DOREnd(void *pvInstance);
271 static DECLCALLBACK(int) H3DORContextProperty(const void *pvContext, uint32_t index,
272 void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
273#endif
274
275 void remote3DRedirect(bool fEnable);
276
277 /*
278 * VRDE server optional interfaces.
279 */
280
281 /* Image update interface. */
282 bool m_fInterfaceImage;
283 VRDEIMAGECALLBACKS m_interfaceCallbacksImage;
284 VRDEIMAGEINTERFACE m_interfaceImage;
285 static DECLCALLBACK(int) VRDEImageCbNotify (void *pvContext,
286 void *pvUser,
287 HVRDEIMAGE hVideo,
288 uint32_t u32Id,
289 void *pvData,
290 uint32_t cbData);
291 /* Mouse pointer interface. */
292 VRDEMOUSEPTRINTERFACE m_interfaceMousePtr;
293
294 /* Smartcard interface. */
295 VRDESCARDINTERFACE m_interfaceSCard;
296 VRDESCARDCALLBACKS m_interfaceCallbacksSCard;
297 static DECLCALLBACK(int) VRDESCardCbNotify(void *pvContext,
298 uint32_t u32Id,
299 void *pvData,
300 uint32_t cbData);
301 static DECLCALLBACK(int) VRDESCardCbResponse(void *pvContext,
302 int rcRequest,
303 void *pvUser,
304 uint32_t u32Function,
305 void *pvData,
306 uint32_t cbData);
307
308 /* TSMF interface. */
309 VRDETSMFINTERFACE m_interfaceTSMF;
310 VRDETSMFCALLBACKS m_interfaceCallbacksTSMF;
311 static DECLCALLBACK(void) VRDETSMFCbNotify(void *pvContext,
312 uint32_t u32Notification,
313 void *pvChannel,
314 const void *pvParm,
315 uint32_t cbParm);
316 void setupTSMF(void);
317
318 static DECLCALLBACK(int) tsmfHostChannelAttach(void *pvProvider, void **ppvInstance, uint32_t u32Flags,
319 VBOXHOSTCHANNELCALLBACKS *pCallbacks, void *pvCallbacks);
320 static DECLCALLBACK(void) tsmfHostChannelDetach(void *pvInstance);
321 static DECLCALLBACK(int) tsmfHostChannelSend(void *pvInstance, const void *pvData, uint32_t cbData);
322 static DECLCALLBACK(int) tsmfHostChannelRecv(void *pvInstance, void *pvData, uint32_t cbData,
323 uint32_t *pcbReturned, uint32_t *pcbRemaining);
324 static DECLCALLBACK(int) tsmfHostChannelControl(void *pvInstance, uint32_t u32Code,
325 const void *pvParm, uint32_t cbParm,
326 const void *pvData, uint32_t cbData, uint32_t *pcbDataReturned);
327 int tsmfLock(void);
328 void tsmfUnlock(void);
329 RTCRITSECT mTSMFLock;
330
331 /* Video input interface. */
332 VRDEVIDEOININTERFACE m_interfaceVideoIn;
333 VRDEVIDEOINCALLBACKS m_interfaceCallbacksVideoIn;
334 static DECLCALLBACK(void) VRDECallbackVideoInNotify(void *pvCallback,
335 uint32_t u32Id,
336 const void *pvData,
337 uint32_t cbData);
338 static DECLCALLBACK(void) VRDECallbackVideoInDeviceDesc(void *pvCallback,
339 int rcRequest,
340 void *pDeviceCtx,
341 void *pvUser,
342 const VRDEVIDEOINDEVICEDESC *pDeviceDesc,
343 uint32_t cbDevice);
344 static DECLCALLBACK(void) VRDECallbackVideoInControl(void *pvCallback,
345 int rcRequest,
346 void *pDeviceCtx,
347 void *pvUser,
348 const VRDEVIDEOINCTRLHDR *pControl,
349 uint32_t cbControl);
350 static DECLCALLBACK(void) VRDECallbackVideoInFrame(void *pvCallback,
351 int rcRequest,
352 void *pDeviceCtx,
353 const VRDEVIDEOINPAYLOADHDR *pFrame,
354 uint32_t cbFrame);
355 EmWebcam *mEmWebcam;
356
357 /* Input interface. */
358 VRDEINPUTINTERFACE m_interfaceInput;
359 VRDEINPUTCALLBACKS m_interfaceCallbacksInput;
360 static DECLCALLBACK(void) VRDECallbackInputSetup(void *pvCallback,
361 int rcRequest,
362 uint32_t u32Method,
363 const void *pvResult,
364 uint32_t cbResult);
365 static DECLCALLBACK(void) VRDECallbackInputEvent(void *pvCallback,
366 uint32_t u32Method,
367 const void *pvEvent,
368 uint32_t cbEvent);
369 uint64_t mu64TouchInputTimestampMCS;
370};
371
372
373class Console;
374
375class ATL_NO_VTABLE VRDEServerInfo :
376 public VRDEServerInfoWrap
377{
378public:
379 DECLARE_NOT_AGGREGATABLE(VRDEServerInfo)
380
381 DECLARE_EMPTY_CTOR_DTOR(VRDEServerInfo)
382
383 HRESULT FinalConstruct();
384 void FinalRelease();
385
386 /* Public initializer/uninitializer for internal purposes only. */
387 HRESULT init(Console *aParent);
388 void uninit();
389
390private:
391 // wrapped IVRDEServerInfo properties
392#define DECL_GETTER(_aType, _aName) virtual HRESULT get##_aName(_aType *a##_aName)
393#define DECL_GETTER_REF(_aType, _aName) virtual HRESULT get##_aName(_aType &a##_aName)
394 DECL_GETTER(BOOL, Active);
395 DECL_GETTER(LONG, Port);
396 DECL_GETTER(ULONG, NumberOfClients);
397 DECL_GETTER(LONG64, BeginTime);
398 DECL_GETTER(LONG64, EndTime);
399 DECL_GETTER(LONG64, BytesSent);
400 DECL_GETTER(LONG64, BytesSentTotal);
401 DECL_GETTER(LONG64, BytesReceived);
402 DECL_GETTER(LONG64, BytesReceivedTotal);
403 DECL_GETTER_REF(com::Utf8Str, User);
404 DECL_GETTER_REF(com::Utf8Str, Domain);
405 DECL_GETTER_REF(com::Utf8Str, ClientName);
406 DECL_GETTER_REF(com::Utf8Str, ClientIP);
407 DECL_GETTER(ULONG, ClientVersion);
408 DECL_GETTER(ULONG, EncryptionStyle);
409#undef DECL_GETTER_REF
410#undef DECL_GETTER
411
412 Console * const mParent;
413};
414
415#endif /* !MAIN_INCLUDED_ConsoleVRDPServer_h */
416/* 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