VirtualBox

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

Last change on this file since 98102 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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