VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/ConsoleVRDPServer.cpp@ 73768

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

Main,SharedOpenGL: VRDP cleanup. bugref:9225

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 133.7 KB
RevLine 
[13607]1/* $Id: ConsoleVRDPServer.cpp 73624 2018-08-10 17:46:50Z vboxsync $ */
[1]2/** @file
[54230]3 * VBox Console VRDP helper class.
[1]4 */
5
6/*
[70496]7 * Copyright (C) 2006-2018 Oracle Corporation
[1]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
[5999]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.
[1]16 */
17
[67914]18#define LOG_GROUP LOG_GROUP_MAIN_CONSOLE
19#include "LoggingNew.h"
20
[1]21#include "ConsoleVRDPServer.h"
22#include "ConsoleImpl.h"
23#include "DisplayImpl.h"
[3720]24#include "KeyboardImpl.h"
25#include "MouseImpl.h"
[70496]26#ifdef VBOX_WITH_AUDIO_VRDE
[50686]27#include "DrvAudioVRDE.h"
[65164]28#endif
[34244]29#ifdef VBOX_WITH_EXTPACK
30# include "ExtPackManagerImpl.h"
31#endif
[36843]32#include "VMMDev.h"
[41352]33#ifdef VBOX_WITH_USB_CARDREADER
34# include "UsbCardReader.h"
35#endif
[48406]36#include "UsbWebcamInterface.h"
[1]37
[34244]38#include "Global.h"
[25860]39#include "AutoCaller.h"
[1]40
[2386]41#include <iprt/asm.h>
[34244]42#include <iprt/alloca.h>
[1]43#include <iprt/ldr.h>
[7257]44#include <iprt/param.h>
45#include <iprt/path.h>
[30681]46#include <iprt/cpp/utils.h>
[1]47
48#include <VBox/err.h>
[33004]49#include <VBox/RemoteDesktop/VRDEOrders.h>
[33963]50#include <VBox/com/listeners.h>
[36843]51#include <VBox/HostServices/VBoxCrOpenGLSvc.h>
[1]52
[67914]53
[33959]54class VRDPConsoleListener
[3720]55{
56public:
[35722]57 VRDPConsoleListener()
[3720]58 {
59 }
[1]60
[62157]61 virtual ~VRDPConsoleListener()
62 {
63 }
64
[35722]65 HRESULT init(ConsoleVRDPServer *server)
66 {
67 m_server = server;
68 return S_OK;
69 }
70
71 void uninit()
72 {
73 }
74
[33959]75 STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
[3720]76 {
[30627]77 switch (aType)
[5782]78 {
[30871]79 case VBoxEventType_OnMousePointerShapeChanged:
[30627]80 {
[30825]81 ComPtr<IMousePointerShapeChangedEvent> mpscev = aEvent;
[30627]82 Assert(mpscev);
83 BOOL visible, alpha;
84 ULONG xHot, yHot, width, height;
85 com::SafeArray <BYTE> shape;
[4131]86
[30627]87 mpscev->COMGETTER(Visible)(&visible);
88 mpscev->COMGETTER(Alpha)(&alpha);
89 mpscev->COMGETTER(Xhot)(&xHot);
90 mpscev->COMGETTER(Yhot)(&yHot);
91 mpscev->COMGETTER(Width)(&width);
92 mpscev->COMGETTER(Height)(&height);
93 mpscev->COMGETTER(Shape)(ComSafeArrayAsOutParam(shape));
[3720]94
[52923]95 m_server->onMousePointerShapeChange(visible, alpha, xHot, yHot, width, height, ComSafeArrayAsInParam(shape));
[30627]96 break;
97 }
[30871]98 case VBoxEventType_OnMouseCapabilityChanged:
[30627]99 {
[30825]100 ComPtr<IMouseCapabilityChangedEvent> mccev = aEvent;
[30627]101 Assert(mccev);
102 if (m_server)
103 {
104 BOOL fAbsoluteMouse;
105 mccev->COMGETTER(SupportsAbsolute)(&fAbsoluteMouse);
106 m_server->NotifyAbsoluteMouse(!!fAbsoluteMouse);
107 }
108 break;
109 }
[30871]110 case VBoxEventType_OnKeyboardLedsChanged:
[30627]111 {
[30825]112 ComPtr<IKeyboardLedsChangedEvent> klcev = aEvent;
[30627]113 Assert(klcev);
[3720]114
[30627]115 if (m_server)
116 {
117 BOOL fNumLock, fCapsLock, fScrollLock;
118 klcev->COMGETTER(NumLock)(&fNumLock);
119 klcev->COMGETTER(CapsLock)(&fCapsLock);
120 klcev->COMGETTER(ScrollLock)(&fScrollLock);
121 m_server->NotifyKeyboardLedsChange(fNumLock, fCapsLock, fScrollLock);
122 }
123 break;
124 }
[3720]125
[30627]126 default:
127 AssertFailed();
128 }
[25901]129
[4131]130 return S_OK;
131 }
132
[3720]133private:
134 ConsoleVRDPServer *m_server;
135};
136
[33959]137typedef ListenerImpl<VRDPConsoleListener, ConsoleVRDPServer*> VRDPConsoleListenerImpl;
[3720]138
[33959]139VBOX_LISTENER_DECLARE(VRDPConsoleListenerImpl)
140
[4093]141#ifdef DEBUG_sunlover
142#define LOGDUMPPTR Log
[26186]143void dumpPointer(const uint8_t *pu8Shape, uint32_t width, uint32_t height, bool fXorMaskRGB32)
[3720]144{
[4093]145 unsigned i;
146
147 const uint8_t *pu8And = pu8Shape;
148
149 for (i = 0; i < height; i++)
150 {
151 unsigned j;
152 LOGDUMPPTR(("%p: ", pu8And));
153 for (j = 0; j < (width + 7) / 8; j++)
154 {
155 unsigned k;
156 for (k = 0; k < 8; k++)
157 {
158 LOGDUMPPTR(("%d", ((*pu8And) & (1 << (7 - k)))? 1: 0));
159 }
160
161 pu8And++;
162 }
163 LOGDUMPPTR(("\n"));
164 }
165
166 if (fXorMaskRGB32)
167 {
[26186]168 uint32_t *pu32Xor = (uint32_t*)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
[4093]169
170 for (i = 0; i < height; i++)
171 {
172 unsigned j;
173 LOGDUMPPTR(("%p: ", pu32Xor));
174 for (j = 0; j < width; j++)
175 {
176 LOGDUMPPTR(("%08X", *pu32Xor++));
177 }
178 LOGDUMPPTR(("\n"));
179 }
180 }
181 else
182 {
183 /* RDP 24 bit RGB mask. */
[26186]184 uint8_t *pu8Xor = (uint8_t*)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
[4093]185 for (i = 0; i < height; i++)
186 {
187 unsigned j;
188 LOGDUMPPTR(("%p: ", pu8Xor));
189 for (j = 0; j < width; j++)
190 {
191 LOGDUMPPTR(("%02X%02X%02X", pu8Xor[2], pu8Xor[1], pu8Xor[0]));
192 pu8Xor += 3;
193 }
194 LOGDUMPPTR(("\n"));
195 }
196 }
197}
198#else
199#define dumpPointer(a, b, c, d) do {} while (0)
200#endif /* DEBUG_sunlover */
201
[51092]202static void findTopLeftBorder(const uint8_t *pu8AndMask, const uint8_t *pu8XorMask, uint32_t width,
203 uint32_t height, uint32_t *pxSkip, uint32_t *pySkip)
[4093]204{
[3720]205 /*
206 * Find the top border of the AND mask. First assign to special value.
207 */
[63147]208 uint32_t ySkipAnd = UINT32_MAX;
[3720]209
[4093]210 const uint8_t *pu8And = pu8AndMask;
[3720]211 const uint32_t cbAndRow = (width + 7) / 8;
212 const uint8_t maskLastByte = (uint8_t)( 0xFF << (cbAndRow * 8 - width) );
213
214 Assert(cbAndRow > 0);
215
216 unsigned y;
217 unsigned x;
218
219 for (y = 0; y < height && ySkipAnd == ~(uint32_t)0; y++, pu8And += cbAndRow)
220 {
221 /* For each complete byte in the row. */
222 for (x = 0; x < cbAndRow - 1; x++)
223 {
224 if (pu8And[x] != 0xFF)
225 {
226 ySkipAnd = y;
227 break;
228 }
229 }
230
231 if (ySkipAnd == ~(uint32_t)0)
232 {
233 /* Last byte. */
234 if ((pu8And[cbAndRow - 1] & maskLastByte) != maskLastByte)
235 {
236 ySkipAnd = y;
237 }
238 }
239 }
240
241 if (ySkipAnd == ~(uint32_t)0)
242 {
243 ySkipAnd = 0;
244 }
245
246 /*
247 * Find the left border of the AND mask.
248 */
[63147]249 uint32_t xSkipAnd = UINT32_MAX;
[3720]250
251 /* For all bit columns. */
252 for (x = 0; x < width && xSkipAnd == ~(uint32_t)0; x++)
253 {
[4093]254 pu8And = pu8AndMask + x/8; /* Currently checking byte. */
[3720]255 uint8_t mask = 1 << (7 - x%8); /* Currently checking bit in the byte. */
256
257 for (y = ySkipAnd; y < height; y++, pu8And += cbAndRow)
258 {
259 if ((*pu8And & mask) == 0)
260 {
261 xSkipAnd = x;
262 break;
263 }
264 }
265 }
266
267 if (xSkipAnd == ~(uint32_t)0)
268 {
269 xSkipAnd = 0;
270 }
271
272 /*
273 * Find the XOR mask top border.
274 */
[63147]275 uint32_t ySkipXor = UINT32_MAX;
[3720]276
[4093]277 uint32_t *pu32XorStart = (uint32_t *)pu8XorMask;
[3720]278
279 uint32_t *pu32Xor = pu32XorStart;
280
281 for (y = 0; y < height && ySkipXor == ~(uint32_t)0; y++, pu32Xor += width)
282 {
283 for (x = 0; x < width; x++)
284 {
285 if (pu32Xor[x] != 0)
286 {
287 ySkipXor = y;
288 break;
289 }
290 }
291 }
292
293 if (ySkipXor == ~(uint32_t)0)
294 {
295 ySkipXor = 0;
296 }
297
298 /*
299 * Find the left border of the XOR mask.
300 */
301 uint32_t xSkipXor = ~(uint32_t)0;
302
303 /* For all columns. */
304 for (x = 0; x < width && xSkipXor == ~(uint32_t)0; x++)
305 {
306 pu32Xor = pu32XorStart + x; /* Currently checking dword. */
307
308 for (y = ySkipXor; y < height; y++, pu32Xor += width)
309 {
310 if (*pu32Xor != 0)
311 {
312 xSkipXor = x;
313 break;
314 }
315 }
316 }
317
318 if (xSkipXor == ~(uint32_t)0)
319 {
320 xSkipXor = 0;
321 }
322
[26186]323 *pxSkip = RT_MIN(xSkipAnd, xSkipXor);
324 *pySkip = RT_MIN(ySkipAnd, ySkipXor);
[3720]325}
326
[4093]327/* Generate an AND mask for alpha pointers here, because
328 * guest driver does not do that correctly for Vista pointers.
329 * Similar fix, changing the alpha threshold, could be applied
330 * for the guest driver, but then additions reinstall would be
331 * necessary, which we try to avoid.
332 */
[26186]333static void mousePointerGenerateANDMask(uint8_t *pu8DstAndMask, int cbDstAndMask, const uint8_t *pu8SrcAlpha, int w, int h)
[4093]334{
[26186]335 memset(pu8DstAndMask, 0xFF, cbDstAndMask);
[4876]336
[4093]337 int y;
338 for (y = 0; y < h; y++)
339 {
340 uint8_t bitmask = 0x80;
[4876]341
[4093]342 int x;
343 for (x = 0; x < w; x++, bitmask >>= 1)
344 {
345 if (bitmask == 0)
346 {
347 bitmask = 0x80;
348 }
[4876]349
[4093]350 /* Whether alpha channel value is not transparent enough for the pixel to be seen. */
351 if (pu8SrcAlpha[x * 4 + 3] > 0x7f)
352 {
353 pu8DstAndMask[x / 8] &= ~bitmask;
354 }
355 }
[4876]356
[4093]357 /* Point to next source and dest scans. */
358 pu8SrcAlpha += w * 4;
359 pu8DstAndMask += (w + 7) / 8;
360 }
361}
[3720]362
[52923]363void ConsoleVRDPServer::onMousePointerShapeChange(BOOL visible,
364 BOOL alpha,
365 ULONG xHot,
366 ULONG yHot,
367 ULONG width,
368 ULONG height,
369 ComSafeArrayIn(BYTE,inShape))
[3720]370{
[55988]371 Log9(("VRDPConsoleListener::OnMousePointerShapeChange: %d, %d, %lux%lu, @%lu,%lu\n",
372 visible, alpha, width, height, xHot, yHot));
[3720]373
[52923]374 com::SafeArray <BYTE> aShape(ComSafeArrayInArg(inShape));
375 if (aShape.size() == 0)
[3720]376 {
[52923]377 if (!visible)
[3720]378 {
[52923]379 MousePointerHide();
[3720]380 }
[52923]381 }
382 else if (width != 0 && height != 0)
383 {
384 uint8_t* shape = aShape.raw();
385
386 dumpPointer(shape, width, height, true);
387
388 /* Try the new interface. */
389 if (MousePointer(alpha, xHot, yHot, width, height, shape) == VINF_SUCCESS)
[3720]390 {
[52923]391 return;
392 }
[40626]393
[52923]394 /* Continue with the old interface. */
[40626]395
[52923]396 /* Pointer consists of 1 bpp AND and 24 BPP XOR masks.
397 * 'shape' AND mask followed by XOR mask.
398 * XOR mask contains 32 bit (lsb)BGR0(msb) values.
399 *
400 * We convert this to RDP color format which consist of
401 * one bpp AND mask and 24 BPP (BGR) color XOR image.
402 *
403 * RDP clients expect 8 aligned width and height of
404 * pointer (preferably 32x32).
405 *
406 * They even contain bugs which do not appear for
407 * 32x32 pointers but would appear for a 41x32 one.
408 *
409 * So set pointer size to 32x32. This can be done safely
410 * because most pointers are 32x32.
411 */
[40626]412
[52923]413 int cbDstAndMask = (((width + 7) / 8) * height + 3) & ~3;
[3720]414
[52923]415 uint8_t *pu8AndMask = shape;
416 uint8_t *pu8XorMask = shape + cbDstAndMask;
[4093]417
[52923]418 if (alpha)
419 {
420 pu8AndMask = (uint8_t*)alloca(cbDstAndMask);
[4093]421
[52923]422 mousePointerGenerateANDMask(pu8AndMask, cbDstAndMask, pu8XorMask, width, height);
423 }
[4093]424
[52923]425 /* Windows guest alpha pointers are wider than 32 pixels.
426 * Try to find out the top-left border of the pointer and
427 * then copy only meaningful bits. All complete top rows
428 * and all complete left columns where (AND == 1 && XOR == 0)
429 * are skipped. Hot spot is adjusted.
430 */
431 uint32_t ySkip = 0; /* How many rows to skip at the top. */
432 uint32_t xSkip = 0; /* How many columns to skip at the left. */
[4093]433
[52923]434 findTopLeftBorder(pu8AndMask, pu8XorMask, width, height, &xSkip, &ySkip);
[3720]435
[52923]436 /* Must not skip the hot spot. */
437 xSkip = RT_MIN(xSkip, xHot);
438 ySkip = RT_MIN(ySkip, yHot);
[3720]439
[52923]440 /*
441 * Compute size and allocate memory for the pointer.
442 */
443 const uint32_t dstwidth = 32;
444 const uint32_t dstheight = 32;
[3720]445
[52923]446 VRDECOLORPOINTER *pointer = NULL;
[3720]447
[52923]448 uint32_t dstmaskwidth = (dstwidth + 7) / 8;
[3720]449
[52923]450 uint32_t rdpmaskwidth = dstmaskwidth;
451 uint32_t rdpmasklen = dstheight * rdpmaskwidth;
[3720]452
[52923]453 uint32_t rdpdatawidth = dstwidth * 3;
454 uint32_t rdpdatalen = dstheight * rdpdatawidth;
[3720]455
[52923]456 pointer = (VRDECOLORPOINTER *)RTMemTmpAlloc(sizeof(VRDECOLORPOINTER) + rdpmasklen + rdpdatalen);
[3720]457
[52923]458 if (pointer)
459 {
460 uint8_t *maskarray = (uint8_t*)pointer + sizeof(VRDECOLORPOINTER);
461 uint8_t *dataarray = maskarray + rdpmasklen;
[3720]462
[52923]463 memset(maskarray, 0xFF, rdpmasklen);
464 memset(dataarray, 0x00, rdpdatalen);
[3720]465
[52923]466 uint32_t srcmaskwidth = (width + 7) / 8;
467 uint32_t srcdatawidth = width * 4;
[3720]468
[52923]469 /* Copy AND mask. */
470 uint8_t *src = pu8AndMask + ySkip * srcmaskwidth;
471 uint8_t *dst = maskarray + (dstheight - 1) * rdpmaskwidth;
[3720]472
[52923]473 uint32_t minheight = RT_MIN(height - ySkip, dstheight);
474 uint32_t minwidth = RT_MIN(width - xSkip, dstwidth);
[3720]475
[52923]476 unsigned x, y;
[3720]477
[52923]478 for (y = 0; y < minheight; y++)
479 {
480 for (x = 0; x < minwidth; x++)
[3720]481 {
[52923]482 uint32_t byteIndex = (x + xSkip) / 8;
483 uint32_t bitIndex = (x + xSkip) % 8;
[3720]484
[52923]485 bool bit = (src[byteIndex] & (1 << (7 - bitIndex))) != 0;
[3720]486
[52923]487 if (!bit)
488 {
489 byteIndex = x / 8;
490 bitIndex = x % 8;
[3720]491
[52923]492 dst[byteIndex] &= ~(1 << (7 - bitIndex));
[3720]493 }
494 }
495
[52923]496 src += srcmaskwidth;
497 dst -= rdpmaskwidth;
498 }
[3720]499
[52923]500 /* Point src to XOR mask */
501 src = pu8XorMask + ySkip * srcdatawidth;
502 dst = dataarray + (dstheight - 1) * rdpdatawidth;
503
504 for (y = 0; y < minheight ; y++)
505 {
506 for (x = 0; x < minwidth; x++)
[3720]507 {
[52923]508 memcpy(dst + x * 3, &src[4 * (x + xSkip)], 3);
[3720]509 }
510
[52923]511 src += srcdatawidth;
512 dst -= rdpdatawidth;
513 }
[3720]514
[52923]515 pointer->u16HotX = (uint16_t)(xHot - xSkip);
516 pointer->u16HotY = (uint16_t)(yHot - ySkip);
[3720]517
[52923]518 pointer->u16Width = (uint16_t)dstwidth;
519 pointer->u16Height = (uint16_t)dstheight;
[3720]520
[52923]521 pointer->u16MaskLen = (uint16_t)rdpmasklen;
522 pointer->u16DataLen = (uint16_t)rdpdatalen;
[4093]523
[52923]524 dumpPointer((uint8_t*)pointer + sizeof(*pointer), dstwidth, dstheight, false);
[3720]525
[52923]526 MousePointerUpdate(pointer);
527
528 RTMemTmpFree(pointer);
[3720]529 }
530 }
531}
532
533
[1]534// ConsoleVRDPServer
535////////////////////////////////////////////////////////////////////////////////
536
[34244]537RTLDRMOD ConsoleVRDPServer::mVRDPLibrary = NIL_RTLDRMOD;
[3720]538
[33005]539PFNVRDECREATESERVER ConsoleVRDPServer::mpfnVRDECreateServer = NULL;
[3720]540
[36843]541VRDEENTRYPOINTS_4 ConsoleVRDPServer::mEntryPoints; /* A copy of the server entry points. */
542VRDEENTRYPOINTS_4 *ConsoleVRDPServer::mpEntryPoints = NULL;
[3720]543
[36843]544VRDECALLBACKS_4 ConsoleVRDPServer::mCallbacks =
[3720]545{
[36843]546 { VRDE_INTERFACE_VERSION_4, sizeof(VRDECALLBACKS_4) },
[3720]547 ConsoleVRDPServer::VRDPCallbackQueryProperty,
548 ConsoleVRDPServer::VRDPCallbackClientLogon,
549 ConsoleVRDPServer::VRDPCallbackClientConnect,
550 ConsoleVRDPServer::VRDPCallbackClientDisconnect,
551 ConsoleVRDPServer::VRDPCallbackIntercept,
552 ConsoleVRDPServer::VRDPCallbackUSB,
553 ConsoleVRDPServer::VRDPCallbackClipboard,
554 ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
555 ConsoleVRDPServer::VRDPCallbackFramebufferLock,
556 ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
557 ConsoleVRDPServer::VRDPCallbackInput,
[34906]558 ConsoleVRDPServer::VRDPCallbackVideoModeHint,
559 ConsoleVRDPServer::VRDECallbackAudioIn
[3720]560};
[1]561
[51092]562DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackQueryProperty(void *pvCallback, uint32_t index, void *pvBuffer,
563 uint32_t cbBuffer, uint32_t *pcbOut)
[3720]564{
[26186]565 ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
[3720]566
567 int rc = VERR_NOT_SUPPORTED;
568
569 switch (index)
570 {
[33004]571 case VRDE_QP_NETWORK_PORT:
[3720]572 {
[33386]573 /* This is obsolete, the VRDE server uses VRDE_QP_NETWORK_PORT_RANGE instead. */
[3720]574 ULONG port = 0;
575
[26186]576 if (cbBuffer >= sizeof(uint32_t))
[3720]577 {
578 *(uint32_t *)pvBuffer = (uint32_t)port;
579 rc = VINF_SUCCESS;
580 }
581 else
582 {
583 rc = VINF_BUFFER_OVERFLOW;
584 }
585
[26186]586 *pcbOut = sizeof(uint32_t);
[3720]587 } break;
588
[33004]589 case VRDE_QP_NETWORK_ADDRESS:
[3720]590 {
[5611]591 com::Bstr bstr;
[51612]592 server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("TCP/Address").raw(), bstr.asOutParam());
[8083]593
[5611]594 /* The server expects UTF8. */
595 com::Utf8Str address = bstr;
[4876]596
[26186]597 size_t cbAddress = address.length() + 1;
[8083]598
[5611]599 if (cbAddress >= 0x10000)
[3720]600 {
[5611]601 /* More than 64K seems to be an invalid address. */
602 rc = VERR_TOO_MUCH_DATA;
603 break;
604 }
[8083]605
[5611]606 if ((size_t)cbBuffer >= cbAddress)
607 {
[31539]608 memcpy(pvBuffer, address.c_str(), cbAddress);
[3720]609 rc = VINF_SUCCESS;
610 }
[5611]611 else
612 {
613 rc = VINF_BUFFER_OVERFLOW;
614 }
[4876]615
[5611]616 *pcbOut = (uint32_t)cbAddress;
[3720]617 } break;
618
[33004]619 case VRDE_QP_NUMBER_MONITORS:
[3720]620 {
621 ULONG cMonitors = 1;
622
[51612]623 server->mConsole->i_machine()->COMGETTER(MonitorCount)(&cMonitors);
[4876]624
[26186]625 if (cbBuffer >= sizeof(uint32_t))
[3720]626 {
627 *(uint32_t *)pvBuffer = (uint32_t)cMonitors;
628 rc = VINF_SUCCESS;
629 }
630 else
631 {
632 rc = VINF_BUFFER_OVERFLOW;
633 }
634
[26186]635 *pcbOut = sizeof(uint32_t);
[3720]636 } break;
637
[33004]638 case VRDE_QP_NETWORK_PORT_RANGE:
[22663]639 {
640 com::Bstr bstr;
[51612]641 HRESULT hrc = server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("TCP/Ports").raw(), bstr.asOutParam());
[25030]642
[22663]643 if (hrc != S_OK)
644 {
645 bstr = "";
646 }
647
[23643]648 if (bstr == "0")
649 {
650 bstr = "3389";
651 }
652
[22663]653 /* The server expects UTF8. */
654 com::Utf8Str portRange = bstr;
655
[32718]656 size_t cbPortRange = portRange.length() + 1;
[22663]657
[54230]658 if (cbPortRange >= _64K)
[22663]659 {
[54230]660 /* More than 64K seems to be an invalid port range string. */
[22663]661 rc = VERR_TOO_MUCH_DATA;
662 break;
663 }
664
665 if ((size_t)cbBuffer >= cbPortRange)
666 {
[31539]667 memcpy(pvBuffer, portRange.c_str(), cbPortRange);
[22663]668 rc = VINF_SUCCESS;
669 }
670 else
671 {
672 rc = VINF_BUFFER_OVERFLOW;
673 }
674
675 *pcbOut = (uint32_t)cbPortRange;
676 } break;
677
[33004]678 case VRDE_QP_VIDEO_CHANNEL:
[28802]679 {
[35146]680 com::Bstr bstr;
[51612]681 HRESULT hrc = server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("VideoChannel/Enabled").raw(),
[51092]682 bstr.asOutParam());
[28802]683
[35146]684 if (hrc != S_OK)
685 {
686 bstr = "";
687 }
[28802]688
[35146]689 com::Utf8Str value = bstr;
690
691 BOOL fVideoEnabled = RTStrICmp(value.c_str(), "true") == 0
692 || RTStrICmp(value.c_str(), "1") == 0;
693
[28802]694 if (cbBuffer >= sizeof(uint32_t))
695 {
696 *(uint32_t *)pvBuffer = (uint32_t)fVideoEnabled;
697 rc = VINF_SUCCESS;
698 }
699 else
700 {
701 rc = VINF_BUFFER_OVERFLOW;
702 }
703
704 *pcbOut = sizeof(uint32_t);
705 } break;
706
[33004]707 case VRDE_QP_VIDEO_CHANNEL_QUALITY:
[28802]708 {
[35146]709 com::Bstr bstr;
[51612]710 HRESULT hrc = server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("VideoChannel/Quality").raw(),
[51092]711 bstr.asOutParam());
[28802]712
[35146]713 if (hrc != S_OK)
714 {
715 bstr = "";
716 }
[28802]717
[35146]718 com::Utf8Str value = bstr;
719
720 ULONG ulQuality = RTStrToUInt32(value.c_str()); /* This returns 0 on invalid string which is ok. */
721
[28802]722 if (cbBuffer >= sizeof(uint32_t))
723 {
724 *(uint32_t *)pvBuffer = (uint32_t)ulQuality;
725 rc = VINF_SUCCESS;
726 }
727 else
728 {
729 rc = VINF_BUFFER_OVERFLOW;
730 }
731
732 *pcbOut = sizeof(uint32_t);
733 } break;
[30245]734
[33004]735 case VRDE_QP_VIDEO_CHANNEL_SUNFLSH:
[30245]736 {
[30335]737 ULONG ulSunFlsh = 1;
[30245]738
739 com::Bstr bstr;
[51612]740 HRESULT hrc = server->mConsole->i_machine()->GetExtraData(Bstr("VRDP/SunFlsh").raw(),
[32718]741 bstr.asOutParam());
[30245]742 if (hrc == S_OK && !bstr.isEmpty())
743 {
744 com::Utf8Str sunFlsh = bstr;
745 if (!sunFlsh.isEmpty())
746 {
747 ulSunFlsh = sunFlsh.toUInt32();
748 }
749 }
750
751 if (cbBuffer >= sizeof(uint32_t))
752 {
753 *(uint32_t *)pvBuffer = (uint32_t)ulSunFlsh;
754 rc = VINF_SUCCESS;
755 }
756 else
757 {
758 rc = VINF_BUFFER_OVERFLOW;
759 }
760
761 *pcbOut = sizeof(uint32_t);
762 } break;
[28802]763
[33004]764 case VRDE_QP_FEATURE:
[31957]765 {
[33004]766 if (cbBuffer < sizeof(VRDEFEATURE))
[31957]767 {
768 rc = VERR_INVALID_PARAMETER;
769 break;
770 }
771
[73097]772 size_t cbInfo = cbBuffer - RT_UOFFSETOF(VRDEFEATURE, achInfo);
[31957]773
[33004]774 VRDEFEATURE *pFeature = (VRDEFEATURE *)pvBuffer;
[31957]775
776 size_t cchInfo = 0;
777 rc = RTStrNLenEx(pFeature->achInfo, cbInfo, &cchInfo);
778
779 if (RT_FAILURE(rc))
780 {
781 rc = VERR_INVALID_PARAMETER;
782 break;
783 }
784
[33556]785 Log(("VRDE_QP_FEATURE [%s]\n", pFeature->achInfo));
[31957]786
787 com::Bstr bstrValue;
788
789 if ( RTStrICmp(pFeature->achInfo, "Client/DisableDisplay") == 0
790 || RTStrICmp(pFeature->achInfo, "Client/DisableInput") == 0
791 || RTStrICmp(pFeature->achInfo, "Client/DisableAudio") == 0
792 || RTStrICmp(pFeature->achInfo, "Client/DisableUSB") == 0
793 || RTStrICmp(pFeature->achInfo, "Client/DisableClipboard") == 0
794 )
795 {
[63563]796 /** @todo these features should be per client. */
[33556]797 NOREF(pFeature->u32ClientId);
798
799 /* These features are mapped to "VRDE/Feature/NAME" extra data. */
800 com::Utf8Str extraData("VRDE/Feature/");
801 extraData += pFeature->achInfo;
802
[51612]803 HRESULT hrc = server->mConsole->i_machine()->GetExtraData(com::Bstr(extraData).raw(),
[54230]804 bstrValue.asOutParam());
[33556]805 if (FAILED(hrc) || bstrValue.isEmpty())
[31957]806 {
[33556]807 /* Also try the old "VRDP/Feature/NAME" */
808 extraData = "VRDP/Feature/";
809 extraData += pFeature->achInfo;
810
[51612]811 hrc = server->mConsole->i_machine()->GetExtraData(com::Bstr(extraData).raw(),
[54230]812 bstrValue.asOutParam());
[34121]813 if (FAILED(hrc))
[33556]814 {
815 rc = VERR_NOT_SUPPORTED;
816 }
[31957]817 }
818 }
[33556]819 else if (RTStrNCmp(pFeature->achInfo, "Property/", 9) == 0)
820 {
821 /* Generic properties. */
822 const char *pszPropertyName = &pFeature->achInfo[9];
[51612]823 HRESULT hrc = server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr(pszPropertyName).raw(),
[54230]824 bstrValue.asOutParam());
[33556]825 if (FAILED(hrc))
826 {
827 rc = VERR_NOT_SUPPORTED;
828 }
829 }
[31957]830 else
831 {
832 rc = VERR_NOT_SUPPORTED;
833 }
834
835 /* Copy the value string to the callers buffer. */
836 if (rc == VINF_SUCCESS)
837 {
838 com::Utf8Str value = bstrValue;
839
840 size_t cb = value.length() + 1;
841
842 if ((size_t)cbInfo >= cb)
843 {
844 memcpy(pFeature->achInfo, value.c_str(), cb);
845 }
846 else
847 {
848 rc = VINF_BUFFER_OVERFLOW;
849 }
850
851 *pcbOut = (uint32_t)cb;
852 }
853 } break;
854
[33004]855 case VRDE_SP_NETWORK_BIND_PORT:
[22663]856 {
[26186]857 if (cbBuffer != sizeof(uint32_t))
[22663]858 {
859 rc = VERR_INVALID_PARAMETER;
860 break;
861 }
862
863 ULONG port = *(uint32_t *)pvBuffer;
[25149]864
[23643]865 server->mVRDPBindPort = port;
[22663]866
867 rc = VINF_SUCCESS;
868
869 if (pcbOut)
870 {
[26186]871 *pcbOut = sizeof(uint32_t);
[22663]872 }
[23643]873
[51612]874 server->mConsole->i_onVRDEServerInfoChange();
[22663]875 } break;
876
[39493]877 case VRDE_SP_CLIENT_STATUS:
[39435]878 {
[39493]879 if (cbBuffer < sizeof(VRDECLIENTSTATUS))
[39435]880 {
881 rc = VERR_INVALID_PARAMETER;
882 break;
883 }
884
[39493]885 size_t cbStatus = cbBuffer - RT_UOFFSETOF(VRDECLIENTSTATUS, achStatus);
[39435]886
[39493]887 VRDECLIENTSTATUS *pStatus = (VRDECLIENTSTATUS *)pvBuffer;
[39435]888
[39493]889 if (cbBuffer < RT_UOFFSETOF(VRDECLIENTSTATUS, achStatus) + pStatus->cbStatus)
890 {
891 rc = VERR_INVALID_PARAMETER;
892 break;
893 }
[39435]894
[39493]895 size_t cchStatus = 0;
896 rc = RTStrNLenEx(pStatus->achStatus, cbStatus, &cchStatus);
897
[39435]898 if (RT_FAILURE(rc))
899 {
900 rc = VERR_INVALID_PARAMETER;
901 break;
902 }
903
[39493]904 Log(("VRDE_SP_CLIENT_STATUS [%s]\n", pStatus->achStatus));
[39435]905
[51612]906 server->mConsole->i_VRDPClientStatusChange(pStatus->u32ClientId, pStatus->achStatus);
[39435]907
908 rc = VINF_SUCCESS;
909
910 if (pcbOut)
911 {
912 *pcbOut = cbBuffer;
913 }
914
[51612]915 server->mConsole->i_onVRDEServerInfoChange();
[39435]916 } break;
917
[3720]918 default:
919 break;
920 }
921
922 return rc;
923}
924
[51092]925DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClientLogon(void *pvCallback, uint32_t u32ClientId, const char *pszUser,
926 const char *pszPassword, const char *pszDomain)
[3720]927{
[26186]928 ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
[4876]929
[51612]930 return server->mConsole->i_VRDPClientLogon(u32ClientId, pszUser, pszPassword, pszDomain);
[3720]931}
932
[32718]933DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientConnect(void *pvCallback, uint32_t u32ClientId)
[3720]934{
[73370]935 ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvCallback);
[4876]936
[73370]937 pServer->mConsole->i_VRDPClientConnect(u32ClientId);
[47158]938
939 /* Should the server report usage of an interface for each client?
940 * Similar to Intercept.
941 */
[73370]942 int c = ASMAtomicIncS32(&pServer->mcClients);
[47158]943 if (c == 1)
944 {
945 /* Features which should be enabled only if there is a client. */
[73370]946 pServer->remote3DRedirect(true);
[47158]947 }
[73370]948
949#ifdef VBOX_WITH_AUDIO_VRDE
950 AudioVRDE *pVRDE = pServer->mConsole->i_getAudioVRDE();
951 if (pVRDE)
952 pVRDE->onVRDEClientConnect(u32ClientId);
953#endif
[3720]954}
955
[51092]956DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientDisconnect(void *pvCallback, uint32_t u32ClientId,
957 uint32_t fu32Intercepted)
[3720]958{
[53442]959 ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvCallback);
960 AssertPtrReturnVoid(pServer);
[4876]961
[53442]962 pServer->mConsole->i_VRDPClientDisconnect(u32ClientId, fu32Intercepted);
[34906]963
[53442]964 if (ASMAtomicReadU32(&pServer->mu32AudioInputClientId) == u32ClientId)
[34906]965 {
[53442]966 LogFunc(("Disconnected client %u\n", u32ClientId));
967 ASMAtomicWriteU32(&pServer->mu32AudioInputClientId, 0);
[34906]968
[70496]969#ifdef VBOX_WITH_AUDIO_VRDE
[54230]970 AudioVRDE *pVRDE = pServer->mConsole->i_getAudioVRDE();
971 if (pVRDE)
[73370]972 {
[54230]973 pVRDE->onVRDEInputIntercept(false /* fIntercept */);
[73370]974 pVRDE->onVRDEClientDisconnect(u32ClientId);
975 }
[65164]976#endif
[34906]977 }
[47158]978
[53442]979 int32_t cClients = ASMAtomicDecS32(&pServer->mcClients);
980 if (cClients == 0)
[47158]981 {
982 /* Features which should be enabled only if there is a client. */
[53442]983 pServer->remote3DRedirect(false);
[47158]984 }
[3720]985}
986
[51092]987DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackIntercept(void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept,
988 void **ppvIntercept)
[3720]989{
[53442]990 ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvCallback);
[54230]991 AssertPtrReturn(pServer, VERR_INVALID_POINTER);
[4876]992
[4404]993 LogFlowFunc(("%x\n", fu32Intercept));
[3720]994
995 int rc = VERR_NOT_SUPPORTED;
996
997 switch (fu32Intercept)
998 {
[33004]999 case VRDE_CLIENT_INTERCEPT_AUDIO:
[3720]1000 {
[53442]1001 pServer->mConsole->i_VRDPInterceptAudio(u32ClientId);
[4404]1002 if (ppvIntercept)
1003 {
[53442]1004 *ppvIntercept = pServer;
[4404]1005 }
[3720]1006 rc = VINF_SUCCESS;
1007 } break;
1008
[33004]1009 case VRDE_CLIENT_INTERCEPT_USB:
[3720]1010 {
[53442]1011 pServer->mConsole->i_VRDPInterceptUSB(u32ClientId, ppvIntercept);
[3720]1012 rc = VINF_SUCCESS;
1013 } break;
1014
[33004]1015 case VRDE_CLIENT_INTERCEPT_CLIPBOARD:
[3720]1016 {
[53442]1017 pServer->mConsole->i_VRDPInterceptClipboard(u32ClientId);
[4404]1018 if (ppvIntercept)
1019 {
[53442]1020 *ppvIntercept = pServer;
[4404]1021 }
[3720]1022 rc = VINF_SUCCESS;
1023 } break;
1024
[34906]1025 case VRDE_CLIENT_INTERCEPT_AUDIO_INPUT:
1026 {
[54230]1027 /*
1028 * This request is processed internally by the ConsoleVRDPServer.
[34906]1029 * Only one client is allowed to intercept audio input.
1030 */
[53442]1031 if (ASMAtomicCmpXchgU32(&pServer->mu32AudioInputClientId, u32ClientId, 0) == true)
[34906]1032 {
[54230]1033 LogFunc(("Intercepting audio input by client %RU32\n", u32ClientId));
[56085]1034
[70496]1035#ifdef VBOX_WITH_AUDIO_VRDE
[54230]1036 AudioVRDE *pVRDE = pServer->mConsole->i_getAudioVRDE();
1037 if (pVRDE)
1038 pVRDE->onVRDEInputIntercept(true /* fIntercept */);
[65164]1039#endif
[34906]1040 }
1041 else
1042 {
[54230]1043 Log(("AUDIOIN: ignored client %RU32, active client %RU32\n", u32ClientId, pServer->mu32AudioInputClientId));
[34906]1044 rc = VERR_NOT_SUPPORTED;
1045 }
1046 } break;
1047
[3720]1048 default:
1049 break;
1050 }
1051
1052 return rc;
1053}
1054
[51092]1055DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackUSB(void *pvCallback, void *pvIntercept, uint32_t u32ClientId,
1056 uint8_t u8Code, const void *pvRet, uint32_t cbRet)
[3720]1057{
[63240]1058 RT_NOREF(pvCallback);
[4632]1059#ifdef VBOX_WITH_USB
[32718]1060 return USBClientResponseCallback(pvIntercept, u32ClientId, u8Code, pvRet, cbRet);
[4632]1061#else
1062 return VERR_NOT_SUPPORTED;
[4876]1063#endif
[3720]1064}
1065
[51092]1066DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClipboard(void *pvCallback, void *pvIntercept, uint32_t u32ClientId,
1067 uint32_t u32Function, uint32_t u32Format,
1068 const void *pvData, uint32_t cbData)
[3720]1069{
[63240]1070 RT_NOREF(pvCallback);
[32718]1071 return ClipboardCallback(pvIntercept, u32ClientId, u32Function, u32Format, pvData, cbData);
[3720]1072}
1073
[51092]1074DECLCALLBACK(bool) ConsoleVRDPServer::VRDPCallbackFramebufferQuery(void *pvCallback, unsigned uScreenId,
1075 VRDEFRAMEBUFFERINFO *pInfo)
[3720]1076{
[26186]1077 ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
[3720]1078
1079 bool fAvailable = false;
1080
[51436]1081 /* Obtain the new screen bitmap. */
[51612]1082 HRESULT hr = server->mConsole->i_getDisplay()->QuerySourceBitmap(uScreenId, server->maSourceBitmaps[uScreenId].asOutParam());
[51436]1083 if (SUCCEEDED(hr))
[3720]1084 {
[51436]1085 LONG xOrigin = 0;
1086 LONG yOrigin = 0;
1087 BYTE *pAddress = NULL;
1088 ULONG ulWidth = 0;
1089 ULONG ulHeight = 0;
1090 ULONG ulBitsPerPixel = 0;
1091 ULONG ulBytesPerLine = 0;
[54828]1092 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
[3720]1093
[51436]1094 hr = server->maSourceBitmaps[uScreenId]->QueryBitmapInfo(&pAddress,
1095 &ulWidth,
1096 &ulHeight,
1097 &ulBitsPerPixel,
1098 &ulBytesPerLine,
[54828]1099 &bitmapFormat);
[3720]1100
[51436]1101 if (SUCCEEDED(hr))
1102 {
[52064]1103 ULONG dummy;
[52978]1104 GuestMonitorStatus_T monitorStatus;
[52064]1105 hr = server->mConsole->i_getDisplay()->GetScreenResolution(uScreenId, &dummy, &dummy, &dummy,
[52978]1106 &xOrigin, &yOrigin, &monitorStatus);
[3720]1107
[51436]1108 if (SUCCEEDED(hr))
1109 {
1110 /* Now fill the information as requested by the caller. */
1111 pInfo->pu8Bits = pAddress;
1112 pInfo->xOrigin = xOrigin;
1113 pInfo->yOrigin = yOrigin;
1114 pInfo->cWidth = ulWidth;
1115 pInfo->cHeight = ulHeight;
1116 pInfo->cBitsPerPixel = ulBitsPerPixel;
1117 pInfo->cbLine = ulBytesPerLine;
[3720]1118
[51436]1119 fAvailable = true;
1120 }
1121 }
[3720]1122 }
1123
1124 return fAvailable;
1125}
1126
[32718]1127DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferLock(void *pvCallback, unsigned uScreenId)
[3720]1128{
[51436]1129 NOREF(pvCallback);
1130 NOREF(uScreenId);
1131 /* Do nothing */
[3720]1132}
1133
[32718]1134DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferUnlock(void *pvCallback, unsigned uScreenId)
[3720]1135{
[51436]1136 NOREF(pvCallback);
1137 NOREF(uScreenId);
1138 /* Do nothing */
[3720]1139}
1140
[32718]1141static void fixKbdLockStatus(VRDPInputSynch *pInputSynch, IKeyboard *pKeyboard)
[5782]1142{
1143 if ( pInputSynch->cGuestNumLockAdaptions
1144 && (pInputSynch->fGuestNumLock != pInputSynch->fClientNumLock))
1145 {
1146 pInputSynch->cGuestNumLockAdaptions--;
1147 pKeyboard->PutScancode(0x45);
1148 pKeyboard->PutScancode(0x45 | 0x80);
1149 }
1150 if ( pInputSynch->cGuestCapsLockAdaptions
1151 && (pInputSynch->fGuestCapsLock != pInputSynch->fClientCapsLock))
1152 {
1153 pInputSynch->cGuestCapsLockAdaptions--;
1154 pKeyboard->PutScancode(0x3a);
1155 pKeyboard->PutScancode(0x3a | 0x80);
1156 }
1157}
1158
[32718]1159DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackInput(void *pvCallback, int type, const void *pvInput, unsigned cbInput)
[3720]1160{
[26186]1161 ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
[3720]1162 Console *pConsole = server->mConsole;
1163
1164 switch (type)
1165 {
[33004]1166 case VRDE_INPUT_SCANCODE:
[3720]1167 {
[33004]1168 if (cbInput == sizeof(VRDEINPUTSCANCODE))
[3720]1169 {
[51612]1170 IKeyboard *pKeyboard = pConsole->i_getKeyboard();
[5782]1171
[33004]1172 const VRDEINPUTSCANCODE *pInputScancode = (VRDEINPUTSCANCODE *)pvInput;
[5782]1173
1174 /* Track lock keys. */
1175 if (pInputScancode->uScancode == 0x45)
1176 {
1177 server->m_InputSynch.fClientNumLock = !server->m_InputSynch.fClientNumLock;
1178 }
1179 else if (pInputScancode->uScancode == 0x3a)
1180 {
1181 server->m_InputSynch.fClientCapsLock = !server->m_InputSynch.fClientCapsLock;
1182 }
1183 else if (pInputScancode->uScancode == 0x46)
1184 {
1185 server->m_InputSynch.fClientScrollLock = !server->m_InputSynch.fClientScrollLock;
1186 }
1187 else if ((pInputScancode->uScancode & 0x80) == 0)
1188 {
1189 /* Key pressed. */
[32718]1190 fixKbdLockStatus(&server->m_InputSynch, pKeyboard);
[5782]1191 }
1192
1193 pKeyboard->PutScancode((LONG)pInputScancode->uScancode);
[3720]1194 }
1195 } break;
1196
[33004]1197 case VRDE_INPUT_POINT:
[3720]1198 {
[33004]1199 if (cbInput == sizeof(VRDEINPUTPOINT))
[3720]1200 {
[33004]1201 const VRDEINPUTPOINT *pInputPoint = (VRDEINPUTPOINT *)pvInput;
[3720]1202
1203 int mouseButtons = 0;
1204 int iWheel = 0;
1205
[33004]1206 if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON1)
[3720]1207 {
1208 mouseButtons |= MouseButtonState_LeftButton;
1209 }
[33004]1210 if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON2)
[3720]1211 {
1212 mouseButtons |= MouseButtonState_RightButton;
1213 }
[33004]1214 if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON3)
[3720]1215 {
1216 mouseButtons |= MouseButtonState_MiddleButton;
1217 }
[33004]1218 if (pInputPoint->uButtons & VRDE_INPUT_POINT_WHEEL_UP)
[3720]1219 {
1220 mouseButtons |= MouseButtonState_WheelUp;
1221 iWheel = -1;
1222 }
[33004]1223 if (pInputPoint->uButtons & VRDE_INPUT_POINT_WHEEL_DOWN)
[3720]1224 {
1225 mouseButtons |= MouseButtonState_WheelDown;
1226 iWheel = 1;
1227 }
1228
1229 if (server->m_fGuestWantsAbsolute)
1230 {
[51612]1231 pConsole->i_getMouse()->PutMouseEventAbsolute(pInputPoint->x + 1, pInputPoint->y + 1, iWheel,
1232 0 /* Horizontal wheel */, mouseButtons);
[3720]1233 } else
1234 {
[51612]1235 pConsole->i_getMouse()->PutMouseEvent(pInputPoint->x - server->m_mousex,
1236 pInputPoint->y - server->m_mousey,
1237 iWheel, 0 /* Horizontal wheel */, mouseButtons);
[3720]1238 server->m_mousex = pInputPoint->x;
1239 server->m_mousey = pInputPoint->y;
1240 }
1241 }
1242 } break;
1243
[33004]1244 case VRDE_INPUT_CAD:
[3720]1245 {
[51612]1246 pConsole->i_getKeyboard()->PutCAD();
[3720]1247 } break;
1248
[33004]1249 case VRDE_INPUT_RESET:
[3720]1250 {
1251 pConsole->Reset();
1252 } break;
1253
[33004]1254 case VRDE_INPUT_SYNCH:
[5782]1255 {
[33004]1256 if (cbInput == sizeof(VRDEINPUTSYNCH))
[5782]1257 {
[51612]1258 IKeyboard *pKeyboard = pConsole->i_getKeyboard();
[5782]1259
[33004]1260 const VRDEINPUTSYNCH *pInputSynch = (VRDEINPUTSYNCH *)pvInput;
[5782]1261
[33004]1262 server->m_InputSynch.fClientNumLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_NUMLOCK) != 0;
1263 server->m_InputSynch.fClientCapsLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_CAPITAL) != 0;
1264 server->m_InputSynch.fClientScrollLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_SCROLL) != 0;
[5782]1265
[8083]1266 /* The client initiated synchronization. Always make the guest to reflect the client state.
[5782]1267 * Than means, when the guest changes the state itself, it is forced to return to the client
1268 * state.
1269 */
1270 if (server->m_InputSynch.fClientNumLock != server->m_InputSynch.fGuestNumLock)
1271 {
1272 server->m_InputSynch.cGuestNumLockAdaptions = 2;
1273 }
1274
1275 if (server->m_InputSynch.fClientCapsLock != server->m_InputSynch.fGuestCapsLock)
1276 {
1277 server->m_InputSynch.cGuestCapsLockAdaptions = 2;
1278 }
1279
[32718]1280 fixKbdLockStatus(&server->m_InputSynch, pKeyboard);
[5782]1281 }
1282 } break;
1283
[3720]1284 default:
1285 break;
1286 }
1287}
1288
[51092]1289DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackVideoModeHint(void *pvCallback, unsigned cWidth, unsigned cHeight,
1290 unsigned cBitsPerPixel, unsigned uScreenId)
[3720]1291{
[26186]1292 ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
[3720]1293
[51612]1294 server->mConsole->i_getDisplay()->SetVideoModeHint(uScreenId, TRUE /*=enabled*/,
1295 FALSE /*=changeOrigin*/, 0/*=OriginX*/, 0/*=OriginY*/,
1296 cWidth, cHeight, cBitsPerPixel);
[3720]1297}
1298
[34906]1299DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackAudioIn(void *pvCallback,
1300 void *pvCtx,
1301 uint32_t u32ClientId,
1302 uint32_t u32Event,
1303 const void *pvData,
1304 uint32_t cbData)
1305{
[63240]1306 RT_NOREF(u32ClientId);
[53442]1307 ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvCallback);
1308 AssertPtrReturnVoid(pServer);
[56085]1309
[70496]1310#ifdef VBOX_WITH_AUDIO_VRDE
[54230]1311 AudioVRDE *pVRDE = pServer->mConsole->i_getAudioVRDE();
1312 if (!pVRDE) /* Nothing to do, bail out early. */
1313 return;
1314
[34906]1315 switch (u32Event)
1316 {
1317 case VRDE_AUDIOIN_BEGIN:
1318 {
[54230]1319 pVRDE->onVRDEInputBegin(pvCtx, (PVRDEAUDIOINBEGIN)pvData);
[53442]1320 break;
1321 }
[34906]1322
1323 case VRDE_AUDIOIN_DATA:
[54230]1324 pVRDE->onVRDEInputData(pvCtx, pvData, cbData);
[53442]1325 break;
[34906]1326
1327 case VRDE_AUDIOIN_END:
[54230]1328 pVRDE->onVRDEInputEnd(pvCtx);
[53442]1329 break;
[34906]1330
1331 default:
[53442]1332 break;
[34906]1333 }
[65164]1334#else
1335 RT_NOREF(pvCtx, u32Event, pvData, cbData);
[70496]1336#endif /* VBOX_WITH_AUDIO_VRDE */
[34906]1337}
1338
[32718]1339ConsoleVRDPServer::ConsoleVRDPServer(Console *console)
[1]1340{
1341 mConsole = console;
1342
[26186]1343 int rc = RTCritSectInit(&mCritSect);
1344 AssertRC(rc);
[4876]1345
[2386]1346 mcClipboardRefs = 0;
1347 mpfnClipboardCallback = NULL;
[1]1348#ifdef VBOX_WITH_USB
1349 mUSBBackends.pHead = NULL;
1350 mUSBBackends.pTail = NULL;
[4876]1351
[1]1352 mUSBBackends.thread = NIL_RTTHREAD;
1353 mUSBBackends.fThreadRunning = false;
1354 mUSBBackends.event = 0;
1355#endif
1356
1357 mhServer = 0;
[34906]1358 mServerInterfaceVersion = 0;
[4876]1359
[46097]1360 mcInResize = 0;
1361
[3720]1362 m_fGuestWantsAbsolute = false;
1363 m_mousex = 0;
1364 m_mousey = 0;
[4876]1365
[5782]1366 m_InputSynch.cGuestNumLockAdaptions = 2;
1367 m_InputSynch.cGuestCapsLockAdaptions = 2;
1368
1369 m_InputSynch.fGuestNumLock = false;
1370 m_InputSynch.fGuestCapsLock = false;
1371 m_InputSynch.fGuestScrollLock = false;
[8083]1372
[5782]1373 m_InputSynch.fClientNumLock = false;
1374 m_InputSynch.fClientCapsLock = false;
1375 m_InputSynch.fClientScrollLock = false;
[8083]1376
[30627]1377 {
1378 ComPtr<IEventSource> es;
1379 console->COMGETTER(EventSource)(es.asOutParam());
[35722]1380 ComObjPtr<VRDPConsoleListenerImpl> aConsoleListener;
1381 aConsoleListener.createObject();
1382 aConsoleListener->init(new VRDPConsoleListener(), this);
1383 mConsoleListener = aConsoleListener;
[30628]1384 com::SafeArray <VBoxEventType_T> eventTypes;
[30871]1385 eventTypes.push_back(VBoxEventType_OnMousePointerShapeChanged);
1386 eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged);
1387 eventTypes.push_back(VBoxEventType_OnKeyboardLedsChanged);
[30627]1388 es->RegisterListener(mConsoleListener, ComSafeArrayAsInParam(eventTypes), true);
1389 }
[22864]1390
[23643]1391 mVRDPBindPort = -1;
[1]1392
[58383]1393#ifndef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
[58368]1394 RT_ZERO(mAuthLibCtx);
[58383]1395#endif
[34906]1396
1397 mu32AudioInputClientId = 0;
[47158]1398 mcClients = 0;
[36843]1399
1400 /*
1401 * Optional interfaces.
1402 */
1403 m_fInterfaceImage = false;
[47117]1404 RT_ZERO(m_interfaceImage);
1405 RT_ZERO(m_interfaceCallbacksImage);
[40626]1406 RT_ZERO(m_interfaceMousePtr);
[41352]1407 RT_ZERO(m_interfaceSCard);
1408 RT_ZERO(m_interfaceCallbacksSCard);
[43350]1409 RT_ZERO(m_interfaceTSMF);
1410 RT_ZERO(m_interfaceCallbacksTSMF);
[43929]1411 RT_ZERO(m_interfaceVideoIn);
1412 RT_ZERO(m_interfaceCallbacksVideoIn);
[47464]1413 RT_ZERO(m_interfaceInput);
1414 RT_ZERO(m_interfaceCallbacksInput);
[43892]1415
1416 rc = RTCritSectInit(&mTSMFLock);
1417 AssertRC(rc);
[49120]1418
1419 mEmWebcam = new EmWebcam(this);
1420 AssertPtr(mEmWebcam);
[1]1421}
1422
[32718]1423ConsoleVRDPServer::~ConsoleVRDPServer()
[1]1424{
[32718]1425 Stop();
[1]1426
[30627]1427 if (mConsoleListener)
[3720]1428 {
[30627]1429 ComPtr<IEventSource> es;
1430 mConsole->COMGETTER(EventSource)(es.asOutParam());
1431 es->UnregisterListener(mConsoleListener);
[35722]1432 mConsoleListener.setNull();
[3720]1433 }
1434
[3823]1435 unsigned i;
[51436]1436 for (i = 0; i < RT_ELEMENTS(maSourceBitmaps); i++)
[3720]1437 {
[51436]1438 maSourceBitmaps[i].setNull();
[3720]1439 }
[5982]1440
[49120]1441 if (mEmWebcam)
1442 {
1443 delete mEmWebcam;
1444 mEmWebcam = NULL;
1445 }
1446
[32718]1447 if (RTCritSectIsInitialized(&mCritSect))
[1]1448 {
[32718]1449 RTCritSectDelete(&mCritSect);
[47117]1450 RT_ZERO(mCritSect);
[1]1451 }
[43892]1452
1453 if (RTCritSectIsInitialized(&mTSMFLock))
1454 {
1455 RTCritSectDelete(&mTSMFLock);
[47117]1456 RT_ZERO(mTSMFLock);
[43892]1457 }
[1]1458}
1459
[32718]1460int ConsoleVRDPServer::Launch(void)
[1]1461{
[28302]1462 LogFlowThisFunc(("\n"));
[33590]1463
[51612]1464 IVRDEServer *server = mConsole->i_getVRDEServer();
[34244]1465 AssertReturn(server, VERR_INTERNAL_ERROR_2);
[1]1466
[33676]1467 /*
[34244]1468 * Check if VRDE is enabled.
[33386]1469 */
[34244]1470 BOOL fEnabled;
[45680]1471 HRESULT hrc = server->COMGETTER(Enabled)(&fEnabled);
[34244]1472 AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc));
1473 if (!fEnabled)
1474 return VINF_SUCCESS;
[1]1475
[34244]1476 /*
1477 * Check that a VRDE extension pack name is set and resolve it into a
1478 * library path.
1479 */
1480 Bstr bstrExtPack;
1481 hrc = server->COMGETTER(VRDEExtPack)(bstrExtPack.asOutParam());
1482 if (FAILED(hrc))
1483 return Global::vboxStatusCodeFromCOM(hrc);
1484 if (bstrExtPack.isEmpty())
1485 return VINF_NOT_SUPPORTED;
[33386]1486
[34244]1487 Utf8Str strExtPack(bstrExtPack);
1488 Utf8Str strVrdeLibrary;
1489 int vrc = VINF_SUCCESS;
1490 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
1491 strVrdeLibrary = "VBoxVRDP";
1492 else
[1]1493 {
[34244]1494#ifdef VBOX_WITH_EXTPACK
[51612]1495 ExtPackManager *pExtPackMgr = mConsole->i_getExtPackManager();
[50914]1496 vrc = pExtPackMgr->i_getVrdeLibraryPathForExtPack(&strExtPack, &strVrdeLibrary);
[34244]1497#else
1498 vrc = VERR_FILE_NOT_FOUND;
1499#endif
[33386]1500 }
[34244]1501 if (RT_SUCCESS(vrc))
[33386]1502 {
[34244]1503 /*
1504 * Load the VRDE library and start the server, if it is enabled.
1505 */
1506 vrc = loadVRDPLibrary(strVrdeLibrary.c_str());
1507 if (RT_SUCCESS(vrc))
[33386]1508 {
[36843]1509 VRDEENTRYPOINTS_4 *pEntryPoints4;
1510 vrc = mpfnVRDECreateServer(&mCallbacks.header, this, (VRDEINTERFACEHDR **)&pEntryPoints4, &mhServer);
[34906]1511
[34244]1512 if (RT_SUCCESS(vrc))
[6658]1513 {
[36843]1514 mServerInterfaceVersion = 4;
1515 mEntryPoints = *pEntryPoints4;
[34906]1516 mpEntryPoints = &mEntryPoints;
1517 }
1518 else if (vrc == VERR_VERSION_MISMATCH)
1519 {
[36843]1520 /* An older version of VRDE is installed, try version 3. */
1521 VRDEENTRYPOINTS_3 *pEntryPoints3;
[34906]1522
[36843]1523 static VRDECALLBACKS_3 sCallbacks3 =
[34906]1524 {
[36843]1525 { VRDE_INTERFACE_VERSION_3, sizeof(VRDECALLBACKS_3) },
[34906]1526 ConsoleVRDPServer::VRDPCallbackQueryProperty,
1527 ConsoleVRDPServer::VRDPCallbackClientLogon,
1528 ConsoleVRDPServer::VRDPCallbackClientConnect,
1529 ConsoleVRDPServer::VRDPCallbackClientDisconnect,
1530 ConsoleVRDPServer::VRDPCallbackIntercept,
1531 ConsoleVRDPServer::VRDPCallbackUSB,
1532 ConsoleVRDPServer::VRDPCallbackClipboard,
1533 ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
1534 ConsoleVRDPServer::VRDPCallbackFramebufferLock,
1535 ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
1536 ConsoleVRDPServer::VRDPCallbackInput,
[36843]1537 ConsoleVRDPServer::VRDPCallbackVideoModeHint,
1538 ConsoleVRDPServer::VRDECallbackAudioIn
[34906]1539 };
1540
[36843]1541 vrc = mpfnVRDECreateServer(&sCallbacks3.header, this, (VRDEINTERFACEHDR **)&pEntryPoints3, &mhServer);
[34906]1542 if (RT_SUCCESS(vrc))
1543 {
1544 mServerInterfaceVersion = 3;
[36843]1545 mEntryPoints.header = pEntryPoints3->header;
1546 mEntryPoints.VRDEDestroy = pEntryPoints3->VRDEDestroy;
1547 mEntryPoints.VRDEEnableConnections = pEntryPoints3->VRDEEnableConnections;
1548 mEntryPoints.VRDEDisconnect = pEntryPoints3->VRDEDisconnect;
1549 mEntryPoints.VRDEResize = pEntryPoints3->VRDEResize;
1550 mEntryPoints.VRDEUpdate = pEntryPoints3->VRDEUpdate;
1551 mEntryPoints.VRDEColorPointer = pEntryPoints3->VRDEColorPointer;
1552 mEntryPoints.VRDEHidePointer = pEntryPoints3->VRDEHidePointer;
1553 mEntryPoints.VRDEAudioSamples = pEntryPoints3->VRDEAudioSamples;
1554 mEntryPoints.VRDEAudioVolume = pEntryPoints3->VRDEAudioVolume;
1555 mEntryPoints.VRDEUSBRequest = pEntryPoints3->VRDEUSBRequest;
1556 mEntryPoints.VRDEClipboard = pEntryPoints3->VRDEClipboard;
1557 mEntryPoints.VRDEQueryInfo = pEntryPoints3->VRDEQueryInfo;
1558 mEntryPoints.VRDERedirect = pEntryPoints3->VRDERedirect;
1559 mEntryPoints.VRDEAudioInOpen = pEntryPoints3->VRDEAudioInOpen;
1560 mEntryPoints.VRDEAudioInClose = pEntryPoints3->VRDEAudioInClose;
1561 mEntryPoints.VRDEGetInterface = NULL;
[34906]1562 mpEntryPoints = &mEntryPoints;
1563 }
[36843]1564 else if (vrc == VERR_VERSION_MISMATCH)
1565 {
1566 /* An older version of VRDE is installed, try version 1. */
1567 VRDEENTRYPOINTS_1 *pEntryPoints1;
1568
1569 static VRDECALLBACKS_1 sCallbacks1 =
1570 {
1571 { VRDE_INTERFACE_VERSION_1, sizeof(VRDECALLBACKS_1) },
1572 ConsoleVRDPServer::VRDPCallbackQueryProperty,
1573 ConsoleVRDPServer::VRDPCallbackClientLogon,
1574 ConsoleVRDPServer::VRDPCallbackClientConnect,
1575 ConsoleVRDPServer::VRDPCallbackClientDisconnect,
1576 ConsoleVRDPServer::VRDPCallbackIntercept,
1577 ConsoleVRDPServer::VRDPCallbackUSB,
1578 ConsoleVRDPServer::VRDPCallbackClipboard,
1579 ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
1580 ConsoleVRDPServer::VRDPCallbackFramebufferLock,
1581 ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
1582 ConsoleVRDPServer::VRDPCallbackInput,
1583 ConsoleVRDPServer::VRDPCallbackVideoModeHint
1584 };
1585
1586 vrc = mpfnVRDECreateServer(&sCallbacks1.header, this, (VRDEINTERFACEHDR **)&pEntryPoints1, &mhServer);
1587 if (RT_SUCCESS(vrc))
1588 {
1589 mServerInterfaceVersion = 1;
1590 mEntryPoints.header = pEntryPoints1->header;
1591 mEntryPoints.VRDEDestroy = pEntryPoints1->VRDEDestroy;
1592 mEntryPoints.VRDEEnableConnections = pEntryPoints1->VRDEEnableConnections;
1593 mEntryPoints.VRDEDisconnect = pEntryPoints1->VRDEDisconnect;
1594 mEntryPoints.VRDEResize = pEntryPoints1->VRDEResize;
1595 mEntryPoints.VRDEUpdate = pEntryPoints1->VRDEUpdate;
1596 mEntryPoints.VRDEColorPointer = pEntryPoints1->VRDEColorPointer;
1597 mEntryPoints.VRDEHidePointer = pEntryPoints1->VRDEHidePointer;
1598 mEntryPoints.VRDEAudioSamples = pEntryPoints1->VRDEAudioSamples;
1599 mEntryPoints.VRDEAudioVolume = pEntryPoints1->VRDEAudioVolume;
1600 mEntryPoints.VRDEUSBRequest = pEntryPoints1->VRDEUSBRequest;
1601 mEntryPoints.VRDEClipboard = pEntryPoints1->VRDEClipboard;
1602 mEntryPoints.VRDEQueryInfo = pEntryPoints1->VRDEQueryInfo;
1603 mEntryPoints.VRDERedirect = NULL;
1604 mEntryPoints.VRDEAudioInOpen = NULL;
1605 mEntryPoints.VRDEAudioInClose = NULL;
1606 mEntryPoints.VRDEGetInterface = NULL;
1607 mpEntryPoints = &mEntryPoints;
1608 }
1609 }
[34906]1610 }
1611
1612 if (RT_SUCCESS(vrc))
1613 {
[36843]1614 LogRel(("VRDE: loaded version %d of the server.\n", mServerInterfaceVersion));
1615
1616 if (mServerInterfaceVersion >= 4)
1617 {
1618 /* The server supports optional interfaces. */
1619 Assert(mpEntryPoints->VRDEGetInterface != NULL);
1620
1621 /* Image interface. */
1622 m_interfaceImage.header.u64Version = 1;
1623 m_interfaceImage.header.u64Size = sizeof(m_interfaceImage);
1624
1625 m_interfaceCallbacksImage.header.u64Version = 1;
1626 m_interfaceCallbacksImage.header.u64Size = sizeof(m_interfaceCallbacksImage);
1627 m_interfaceCallbacksImage.VRDEImageCbNotify = VRDEImageCbNotify;
1628
1629 vrc = mpEntryPoints->VRDEGetInterface(mhServer,
1630 VRDE_IMAGE_INTERFACE_NAME,
1631 &m_interfaceImage.header,
1632 &m_interfaceCallbacksImage.header,
1633 this);
1634 if (RT_SUCCESS(vrc))
1635 {
[40626]1636 LogRel(("VRDE: [%s]\n", VRDE_IMAGE_INTERFACE_NAME));
[36843]1637 m_fInterfaceImage = true;
1638 }
1639
[40626]1640 /* Mouse pointer interface. */
1641 m_interfaceMousePtr.header.u64Version = 1;
1642 m_interfaceMousePtr.header.u64Size = sizeof(m_interfaceMousePtr);
1643
1644 vrc = mpEntryPoints->VRDEGetInterface(mhServer,
1645 VRDE_MOUSEPTR_INTERFACE_NAME,
1646 &m_interfaceMousePtr.header,
1647 NULL,
1648 this);
1649 if (RT_SUCCESS(vrc))
1650 {
1651 LogRel(("VRDE: [%s]\n", VRDE_MOUSEPTR_INTERFACE_NAME));
1652 }
1653 else
1654 {
1655 RT_ZERO(m_interfaceMousePtr);
1656 }
1657
[41352]1658 /* Smartcard interface. */
1659 m_interfaceSCard.header.u64Version = 1;
1660 m_interfaceSCard.header.u64Size = sizeof(m_interfaceSCard);
1661
1662 m_interfaceCallbacksSCard.header.u64Version = 1;
1663 m_interfaceCallbacksSCard.header.u64Size = sizeof(m_interfaceCallbacksSCard);
1664 m_interfaceCallbacksSCard.VRDESCardCbNotify = VRDESCardCbNotify;
1665 m_interfaceCallbacksSCard.VRDESCardCbResponse = VRDESCardCbResponse;
1666
1667 vrc = mpEntryPoints->VRDEGetInterface(mhServer,
1668 VRDE_SCARD_INTERFACE_NAME,
1669 &m_interfaceSCard.header,
1670 &m_interfaceCallbacksSCard.header,
1671 this);
1672 if (RT_SUCCESS(vrc))
1673 {
1674 LogRel(("VRDE: [%s]\n", VRDE_SCARD_INTERFACE_NAME));
1675 }
1676 else
1677 {
1678 RT_ZERO(m_interfaceSCard);
1679 }
1680
[43350]1681 /* Raw TSMF interface. */
1682 m_interfaceTSMF.header.u64Version = 1;
1683 m_interfaceTSMF.header.u64Size = sizeof(m_interfaceTSMF);
1684
1685 m_interfaceCallbacksTSMF.header.u64Version = 1;
1686 m_interfaceCallbacksTSMF.header.u64Size = sizeof(m_interfaceCallbacksTSMF);
1687 m_interfaceCallbacksTSMF.VRDETSMFCbNotify = VRDETSMFCbNotify;
1688
1689 vrc = mpEntryPoints->VRDEGetInterface(mhServer,
1690 VRDE_TSMF_INTERFACE_NAME,
1691 &m_interfaceTSMF.header,
1692 &m_interfaceCallbacksTSMF.header,
1693 this);
1694 if (RT_SUCCESS(vrc))
1695 {
1696 LogRel(("VRDE: [%s]\n", VRDE_TSMF_INTERFACE_NAME));
1697 }
1698 else
1699 {
1700 RT_ZERO(m_interfaceTSMF);
1701 }
1702
[43929]1703 /* VideoIn interface. */
1704 m_interfaceVideoIn.header.u64Version = 1;
1705 m_interfaceVideoIn.header.u64Size = sizeof(m_interfaceVideoIn);
1706
1707 m_interfaceCallbacksVideoIn.header.u64Version = 1;
1708 m_interfaceCallbacksVideoIn.header.u64Size = sizeof(m_interfaceCallbacksVideoIn);
1709 m_interfaceCallbacksVideoIn.VRDECallbackVideoInNotify = VRDECallbackVideoInNotify;
1710 m_interfaceCallbacksVideoIn.VRDECallbackVideoInDeviceDesc = VRDECallbackVideoInDeviceDesc;
1711 m_interfaceCallbacksVideoIn.VRDECallbackVideoInControl = VRDECallbackVideoInControl;
1712 m_interfaceCallbacksVideoIn.VRDECallbackVideoInFrame = VRDECallbackVideoInFrame;
1713
1714 vrc = mpEntryPoints->VRDEGetInterface(mhServer,
1715 VRDE_VIDEOIN_INTERFACE_NAME,
1716 &m_interfaceVideoIn.header,
1717 &m_interfaceCallbacksVideoIn.header,
1718 this);
1719 if (RT_SUCCESS(vrc))
1720 {
1721 LogRel(("VRDE: [%s]\n", VRDE_VIDEOIN_INTERFACE_NAME));
1722 }
1723 else
1724 {
1725 RT_ZERO(m_interfaceVideoIn);
1726 }
1727
[47464]1728 /* Input interface. */
1729 m_interfaceInput.header.u64Version = 1;
1730 m_interfaceInput.header.u64Size = sizeof(m_interfaceInput);
1731
1732 m_interfaceCallbacksInput.header.u64Version = 1;
1733 m_interfaceCallbacksInput.header.u64Size = sizeof(m_interfaceCallbacksInput);
1734 m_interfaceCallbacksInput.VRDECallbackInputSetup = VRDECallbackInputSetup;
1735 m_interfaceCallbacksInput.VRDECallbackInputEvent = VRDECallbackInputEvent;
1736
1737 vrc = mpEntryPoints->VRDEGetInterface(mhServer,
1738 VRDE_INPUT_INTERFACE_NAME,
1739 &m_interfaceInput.header,
1740 &m_interfaceCallbacksInput.header,
1741 this);
1742 if (RT_SUCCESS(vrc))
1743 {
1744 LogRel(("VRDE: [%s]\n", VRDE_INPUT_INTERFACE_NAME));
1745 }
1746 else
1747 {
1748 RT_ZERO(m_interfaceInput);
1749 }
1750
[36843]1751 /* Since these interfaces are optional, it is always a success here. */
1752 vrc = VINF_SUCCESS;
1753 }
[1]1754#ifdef VBOX_WITH_USB
[32718]1755 remoteUSBThreadStart();
[34244]1756#endif
[52923]1757
1758 /*
1759 * Re-init the server current state, which is usually obtained from events.
1760 */
1761 fetchCurrentState();
[6658]1762 }
[34244]1763 else
[33386]1764 {
[34244]1765 if (vrc != VERR_NET_ADDRESS_IN_USE)
[34906]1766 LogRel(("VRDE: Could not start the server rc = %Rrc\n", vrc));
[34244]1767 /* Don't unload the lib, because it prevents us trying again or
1768 because there may be other users? */
[33386]1769 }
[1]1770 }
1771 }
[33590]1772
[34244]1773 return vrc;
[1]1774}
1775
[52923]1776void ConsoleVRDPServer::fetchCurrentState(void)
1777{
1778 ComPtr<IMousePointerShape> mps;
1779 mConsole->i_getMouse()->COMGETTER(PointerShape)(mps.asOutParam());
1780 if (!mps.isNull())
1781 {
1782 BOOL visible, alpha;
1783 ULONG hotX, hotY, width, height;
1784 com::SafeArray <BYTE> shape;
1785
1786 mps->COMGETTER(Visible)(&visible);
1787 mps->COMGETTER(Alpha)(&alpha);
1788 mps->COMGETTER(HotX)(&hotX);
1789 mps->COMGETTER(HotY)(&hotY);
1790 mps->COMGETTER(Width)(&width);
1791 mps->COMGETTER(Height)(&height);
1792 mps->COMGETTER(Shape)(ComSafeArrayAsOutParam(shape));
1793
1794 onMousePointerShapeChange(visible, alpha, hotX, hotY, width, height, ComSafeArrayAsInParam(shape));
1795 }
1796}
1797
[36843]1798typedef struct H3DORInstance
1799{
1800 ConsoleVRDPServer *pThis;
1801 HVRDEIMAGE hImageBitmap;
1802 int32_t x;
1803 int32_t y;
1804 uint32_t w;
1805 uint32_t h;
1806 bool fCreated;
[46291]1807 bool fFallback;
[50319]1808 bool fTopDown;
[36843]1809} H3DORInstance;
1810
[46291]1811#define H3DORLOG Log
1812
[36843]1813/* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORBegin(const void *pvContext, void **ppvInstance,
1814 const char *pszFormat)
1815{
[46291]1816 H3DORLOG(("H3DORBegin: ctx %p [%s]\n", pvContext, pszFormat));
[36843]1817
[46291]1818 H3DORInstance *p = (H3DORInstance *)RTMemAlloc(sizeof(H3DORInstance));
[36843]1819
1820 if (p)
1821 {
1822 p->pThis = (ConsoleVRDPServer *)pvContext;
1823 p->hImageBitmap = NULL;
1824 p->x = 0;
1825 p->y = 0;
1826 p->w = 0;
1827 p->h = 0;
1828 p->fCreated = false;
[46291]1829 p->fFallback = false;
[36843]1830
1831 /* Host 3D service passes the actual format of data in this redirect instance.
1832 * That is what will be in the H3DORFrame's parameters pvData and cbData.
1833 */
1834 if (RTStrICmp(pszFormat, H3DOR_FMT_RGBA_TOPDOWN) == 0)
1835 {
1836 /* Accept it. */
[50319]1837 p->fTopDown = true;
[36843]1838 }
[50319]1839 else if (RTStrICmp(pszFormat, H3DOR_FMT_RGBA) == 0)
1840 {
1841 /* Accept it. */
1842 p->fTopDown = false;
1843 }
[36843]1844 else
1845 {
1846 RTMemFree(p);
1847 p = NULL;
1848 }
1849 }
1850
[46291]1851 H3DORLOG(("H3DORBegin: ins %p\n", p));
1852
1853 /* Caller checks this for NULL. */
[36843]1854 *ppvInstance = p;
1855}
1856
1857/* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORGeometry(void *pvInstance,
1858 int32_t x, int32_t y, uint32_t w, uint32_t h)
1859{
[46291]1860 H3DORLOG(("H3DORGeometry: ins %p %d,%d %dx%d\n", pvInstance, x, y, w, h));
[36843]1861
1862 H3DORInstance *p = (H3DORInstance *)pvInstance;
[73624]1863 AssertPtrReturnVoid(p);
1864 AssertPtrReturnVoid(p->pThis);
[36843]1865
[63563]1866 /** @todo find out what to do if size changes to 0x0 from non zero */
[36843]1867 if (w == 0 || h == 0)
1868 {
1869 /* Do nothing. */
1870 return;
1871 }
1872
1873 RTRECT rect;
1874 rect.xLeft = x;
1875 rect.yTop = y;
1876 rect.xRight = x + w;
1877 rect.yBottom = y + h;
1878
1879 if (p->hImageBitmap)
1880 {
1881 /* An image handle has been already created,
1882 * check if it has the same size as the reported geometry.
1883 */
1884 if ( p->x == x
1885 && p->y == y
1886 && p->w == w
1887 && p->h == h)
1888 {
[46291]1889 H3DORLOG(("H3DORGeometry: geometry not changed\n"));
[36843]1890 /* Do nothing. Continue using the existing handle. */
1891 }
1892 else
1893 {
[46291]1894 int rc = p->fFallback?
[46295]1895 VERR_NOT_SUPPORTED: /* Try to go out of fallback mode. */
[46291]1896 p->pThis->m_interfaceImage.VRDEImageGeometrySet(p->hImageBitmap, &rect);
[36843]1897 if (RT_SUCCESS(rc))
1898 {
1899 p->x = x;
1900 p->y = y;
1901 p->w = w;
1902 p->h = h;
1903 }
1904 else
1905 {
1906 /* The handle must be recreated. Delete existing handle here. */
1907 p->pThis->m_interfaceImage.VRDEImageHandleClose(p->hImageBitmap);
1908 p->hImageBitmap = NULL;
1909 }
1910 }
1911 }
1912
1913 if (!p->hImageBitmap)
1914 {
1915 /* Create a new bitmap handle. */
[63563]1916 uint32_t u32ScreenId = 0; /** @todo clip to corresponding screens.
[36843]1917 * Clipping can be done here or in VRDP server.
1918 * If VRDP does clipping, then uScreenId parameter
1919 * is not necessary and coords must be global.
1920 * (have to check which coords are used in opengl service).
1921 * Since all VRDE API uses a ScreenId,
1922 * the clipping must be done here in ConsoleVRDPServer
1923 */
1924 uint32_t fu32CompletionFlags = 0;
[46291]1925 p->fFallback = false;
[36843]1926 int rc = p->pThis->m_interfaceImage.VRDEImageHandleCreate(p->pThis->mhServer,
1927 &p->hImageBitmap,
1928 p,
1929 u32ScreenId,
1930 VRDE_IMAGE_F_CREATE_CONTENT_3D
1931 | VRDE_IMAGE_F_CREATE_WINDOW,
1932 &rect,
1933 VRDE_IMAGE_FMT_ID_BITMAP_BGRA8,
1934 NULL,
1935 0,
1936 &fu32CompletionFlags);
[43446]1937 if (RT_FAILURE(rc))
1938 {
1939 /* No support for a 3D + WINDOW. Try bitmap updates. */
[46291]1940 H3DORLOG(("H3DORGeometry: Fallback to bitmaps\n"));
[43446]1941 fu32CompletionFlags = 0;
[46291]1942 p->fFallback = true;
[43446]1943 rc = p->pThis->m_interfaceImage.VRDEImageHandleCreate(p->pThis->mhServer,
1944 &p->hImageBitmap,
1945 p,
1946 u32ScreenId,
1947 0,
1948 &rect,
1949 VRDE_IMAGE_FMT_ID_BITMAP_BGRA8,
1950 NULL,
1951 0,
1952 &fu32CompletionFlags);
1953 }
1954
[46291]1955 H3DORLOG(("H3DORGeometry: Image handle create %Rrc, flags 0x%RX32\n", rc, fu32CompletionFlags));
1956
[36843]1957 if (RT_SUCCESS(rc))
1958 {
1959 p->x = x;
1960 p->y = y;
1961 p->w = w;
1962 p->h = h;
1963
1964 if ((fu32CompletionFlags & VRDE_IMAGE_F_COMPLETE_ASYNC) == 0)
1965 {
1966 p->fCreated = true;
1967 }
1968 }
1969 else
1970 {
1971 p->hImageBitmap = NULL;
1972 p->w = 0;
1973 p->h = 0;
1974 }
1975 }
[46291]1976
1977 H3DORLOG(("H3DORGeometry: ins %p completed\n", pvInstance));
[36843]1978}
1979
1980/* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORVisibleRegion(void *pvInstance,
[43888]1981 uint32_t cRects, const RTRECT *paRects)
[36843]1982{
[46291]1983 H3DORLOG(("H3DORVisibleRegion: ins %p %d\n", pvInstance, cRects));
[36843]1984
1985 H3DORInstance *p = (H3DORInstance *)pvInstance;
[73624]1986 AssertPtrReturnVoid(p);
1987 AssertPtrReturnVoid(p->pThis);
[36843]1988
1989 if (cRects == 0)
1990 {
1991 /* Complete image is visible. */
1992 RTRECT rect;
1993 rect.xLeft = p->x;
1994 rect.yTop = p->y;
1995 rect.xRight = p->x + p->w;
1996 rect.yBottom = p->y + p->h;
1997 p->pThis->m_interfaceImage.VRDEImageRegionSet (p->hImageBitmap,
1998 1,
1999 &rect);
2000 }
2001 else
2002 {
2003 p->pThis->m_interfaceImage.VRDEImageRegionSet (p->hImageBitmap,
2004 cRects,
2005 paRects);
2006 }
[46291]2007
2008 H3DORLOG(("H3DORVisibleRegion: ins %p completed\n", pvInstance));
[36843]2009}
2010
2011/* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORFrame(void *pvInstance,
2012 void *pvData, uint32_t cbData)
2013{
[46291]2014 H3DORLOG(("H3DORFrame: ins %p %p %d\n", pvInstance, pvData, cbData));
[36843]2015
2016 H3DORInstance *p = (H3DORInstance *)pvInstance;
[73624]2017 AssertPtrReturnVoid(p);
2018 AssertPtrReturnVoid(p->pThis);
[36843]2019
2020 /* Currently only a topdown BGR0 bitmap format is supported. */
2021 VRDEIMAGEBITMAP image;
2022
2023 image.cWidth = p->w;
2024 image.cHeight = p->h;
2025 image.pvData = pvData;
2026 image.cbData = cbData;
2027 image.pvScanLine0 = (uint8_t *)pvData + (p->h - 1) * p->w * 4;
[50319]2028 image.iScanDelta = 4 * p->w;
2029 if (p->fTopDown)
2030 {
2031 image.iScanDelta = -image.iScanDelta;
2032 }
[36843]2033
2034 p->pThis->m_interfaceImage.VRDEImageUpdate (p->hImageBitmap,
2035 p->x,
2036 p->y,
2037 p->w,
2038 p->h,
2039 &image,
2040 sizeof(VRDEIMAGEBITMAP));
[46291]2041
2042 H3DORLOG(("H3DORFrame: ins %p completed\n", pvInstance));
[36843]2043}
2044
2045/* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DOREnd(void *pvInstance)
2046{
[46291]2047 H3DORLOG(("H3DOREnd: ins %p\n", pvInstance));
[36843]2048
2049 H3DORInstance *p = (H3DORInstance *)pvInstance;
[73624]2050 AssertPtrReturnVoid(p);
2051 AssertPtrReturnVoid(p->pThis);
[36843]2052
2053 p->pThis->m_interfaceImage.VRDEImageHandleClose(p->hImageBitmap);
2054
[73624]2055 RT_ZERO(*p);
[36843]2056 RTMemFree(p);
[46291]2057
2058 H3DORLOG(("H3DOREnd: ins %p completed\n", pvInstance));
[36843]2059}
2060
2061/* static */ DECLCALLBACK(int) ConsoleVRDPServer::H3DORContextProperty(const void *pvContext, uint32_t index,
2062 void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut)
2063{
[63240]2064 RT_NOREF(pvContext, pvBuffer);
[36843]2065 int rc = VINF_SUCCESS;
2066
[46291]2067 H3DORLOG(("H3DORContextProperty: index %d\n", index));
2068
[36843]2069 if (index == H3DOR_PROP_FORMATS)
2070 {
2071 /* Return a comma separated list of supported formats. */
[50319]2072 uint32_t cbOut = (uint32_t)strlen(H3DOR_FMT_RGBA_TOPDOWN) + 1
2073 + (uint32_t)strlen(H3DOR_FMT_RGBA) + 1;
[36843]2074 if (cbOut <= cbBuffer)
2075 {
[50319]2076 char *pch = (char *)pvBuffer;
2077 memcpy(pch, H3DOR_FMT_RGBA_TOPDOWN, strlen(H3DOR_FMT_RGBA_TOPDOWN));
2078 pch += strlen(H3DOR_FMT_RGBA_TOPDOWN);
2079 *pch++ = ',';
2080 memcpy(pch, H3DOR_FMT_RGBA, strlen(H3DOR_FMT_RGBA));
2081 pch += strlen(H3DOR_FMT_RGBA);
2082 *pch++ = '\0';
[36843]2083 }
2084 else
2085 {
2086 rc = VERR_BUFFER_OVERFLOW;
2087 }
2088 *pcbOut = cbOut;
2089 }
2090 else
2091 {
2092 rc = VERR_NOT_SUPPORTED;
2093 }
2094
[46291]2095 H3DORLOG(("H3DORContextProperty: %Rrc\n", rc));
[36843]2096 return rc;
2097}
2098
[47158]2099void ConsoleVRDPServer::remote3DRedirect(bool fEnable)
[36843]2100{
2101 if (!m_fInterfaceImage)
2102 {
2103 /* No redirect without corresponding interface. */
2104 return;
2105 }
2106
[47158]2107 /* Check if 3D redirection has been enabled. It is enabled by default. */
[36843]2108 com::Bstr bstr;
[51612]2109 HRESULT hrc = mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("H3DRedirect/Enabled").raw(), bstr.asOutParam());
[36843]2110
[47158]2111 com::Utf8Str value = hrc == S_OK? bstr: "";
[36843]2112
[47158]2113 bool fAllowed = RTStrICmp(value.c_str(), "true") == 0
2114 || RTStrICmp(value.c_str(), "1") == 0
2115 || value.c_str()[0] == 0;
[36843]2116
[47158]2117 if (!fAllowed && fEnable)
[36843]2118 {
2119 return;
2120 }
2121
2122 /* Tell the host 3D service to redirect output using the ConsoleVRDPServer callbacks. */
2123 H3DOUTPUTREDIRECT outputRedirect =
2124 {
2125 this,
2126 H3DORBegin,
2127 H3DORGeometry,
2128 H3DORVisibleRegion,
2129 H3DORFrame,
2130 H3DOREnd,
2131 H3DORContextProperty
2132 };
2133
[47158]2134 if (!fEnable)
2135 {
2136 /* This will tell the service to disable rediection. */
2137 RT_ZERO(outputRedirect);
2138 }
2139
[50940]2140#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
[50848]2141 VBOXCRCMDCTL_HGCM data;
2142 data.Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
2143 data.Hdr.u32Function = SHCRGL_HOST_FN_SET_OUTPUT_REDIRECT;
[36843]2144
[50848]2145 data.aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2146 data.aParms[0].u.pointer.addr = &outputRedirect;
2147 data.aParms[0].u.pointer.size = sizeof(outputRedirect);
[36843]2148
[52064]2149 int rc = mConsole->i_getDisplay()->i_crCtlSubmitSync(&data.Hdr, sizeof (data));
[36843]2150 if (!RT_SUCCESS(rc))
2151 {
[47251]2152 Log(("SHCRGL_HOST_FN_SET_CONSOLE failed with %Rrc\n", rc));
[36843]2153 return;
2154 }
2155
[47158]2156 LogRel(("VRDE: %s 3D redirect.\n", fEnable? "Enabled": "Disabled"));
[50940]2157# ifdef DEBUG_misha
[50848]2158 AssertFailed();
[50940]2159# endif
[50848]2160#endif
[36843]2161
2162 return;
2163}
2164
2165/* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDEImageCbNotify (void *pvContext,
2166 void *pvUser,
2167 HVRDEIMAGE hVideo,
2168 uint32_t u32Id,
2169 void *pvData,
2170 uint32_t cbData)
2171{
[63240]2172 RT_NOREF(hVideo);
[46291]2173 H3DORLOG(("H3DOR: VRDEImageCbNotify: pvContext %p, pvUser %p, hVideo %p, u32Id %u, pvData %p, cbData %d\n",
2174 pvContext, pvUser, hVideo, u32Id, pvData, cbData));
[36843]2175
[62379]2176 ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvContext); NOREF(pServer);
[36843]2177 H3DORInstance *p = (H3DORInstance *)pvUser;
2178 Assert(p);
2179 Assert(p->pThis);
2180 Assert(p->pThis == pServer);
2181
[36925]2182 if (u32Id == VRDE_IMAGE_NOTIFY_HANDLE_CREATE)
2183 {
2184 if (cbData != sizeof(uint32_t))
2185 {
2186 AssertFailed();
2187 return VERR_INVALID_PARAMETER;
2188 }
[36843]2189
[36925]2190 uint32_t u32StreamId = *(uint32_t *)pvData;
[46291]2191 H3DORLOG(("H3DOR: VRDE_IMAGE_NOTIFY_HANDLE_CREATE u32StreamId %d\n",
2192 u32StreamId));
[36843]2193
[36925]2194 if (u32StreamId != 0)
2195 {
[63563]2196 p->fCreated = true; /// @todo not needed?
[36925]2197 }
2198 else
2199 {
2200 /* The stream has not been created. */
2201 }
2202 }
2203
[36843]2204 return VINF_SUCCESS;
2205}
2206
[46291]2207#undef H3DORLOG
2208
[41352]2209/* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDESCardCbNotify(void *pvContext,
2210 uint32_t u32Id,
2211 void *pvData,
2212 uint32_t cbData)
2213{
2214#ifdef VBOX_WITH_USB_CARDREADER
2215 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
[51612]2216 UsbCardReader *pReader = pThis->mConsole->i_getUsbCardReader();
[41352]2217 return pReader->VRDENotify(u32Id, pvData, cbData);
2218#else
2219 NOREF(pvContext);
2220 NOREF(u32Id);
2221 NOREF(pvData);
2222 NOREF(cbData);
2223 return VERR_NOT_SUPPORTED;
2224#endif
2225}
2226
2227/* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDESCardCbResponse(void *pvContext,
2228 int rcRequest,
2229 void *pvUser,
2230 uint32_t u32Function,
2231 void *pvData,
2232 uint32_t cbData)
2233{
2234#ifdef VBOX_WITH_USB_CARDREADER
2235 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
[51612]2236 UsbCardReader *pReader = pThis->mConsole->i_getUsbCardReader();
[41352]2237 return pReader->VRDEResponse(rcRequest, pvUser, u32Function, pvData, cbData);
2238#else
2239 NOREF(pvContext);
2240 NOREF(rcRequest);
2241 NOREF(pvUser);
2242 NOREF(u32Function);
2243 NOREF(pvData);
2244 NOREF(cbData);
2245 return VERR_NOT_SUPPORTED;
2246#endif
2247}
2248
2249int ConsoleVRDPServer::SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData)
2250{
2251 int rc = VINF_SUCCESS;
2252
2253 if (mhServer && mpEntryPoints && m_interfaceSCard.VRDESCardRequest)
2254 {
2255 rc = m_interfaceSCard.VRDESCardRequest(mhServer, pvUser, u32Function, pvData, cbData);
2256 }
2257 else
2258 {
2259 rc = VERR_NOT_SUPPORTED;
2260 }
2261
2262 return rc;
2263}
2264
[43892]2265
2266struct TSMFHOSTCHCTX;
2267struct TSMFVRDPCTX;
2268
2269typedef struct TSMFHOSTCHCTX
[43350]2270{
2271 ConsoleVRDPServer *pThis;
2272
[43892]2273 struct TSMFVRDPCTX *pVRDPCtx; /* NULL if no corresponding host channel context. */
2274
2275 void *pvDataReceived;
2276 uint32_t cbDataReceived;
2277 uint32_t cbDataAllocated;
2278} TSMFHOSTCHCTX;
2279
2280typedef struct TSMFVRDPCTX
2281{
2282 ConsoleVRDPServer *pThis;
2283
[43350]2284 VBOXHOSTCHANNELCALLBACKS *pCallbacks;
2285 void *pvCallbacks;
2286
[43892]2287 TSMFHOSTCHCTX *pHostChCtx; /* NULL if no corresponding host channel context. */
2288
[43350]2289 uint32_t u32ChannelHandle;
[43892]2290} TSMFVRDPCTX;
[43350]2291
[43892]2292static int tsmfContextsAlloc(TSMFHOSTCHCTX **ppHostChCtx, TSMFVRDPCTX **ppVRDPCtx)
2293{
2294 TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)RTMemAllocZ(sizeof(TSMFHOSTCHCTX));
2295 if (!pHostChCtx)
2296 {
2297 return VERR_NO_MEMORY;
2298 }
[43350]2299
[43892]2300 TSMFVRDPCTX *pVRDPCtx = (TSMFVRDPCTX *)RTMemAllocZ(sizeof(TSMFVRDPCTX));
2301 if (!pVRDPCtx)
2302 {
2303 RTMemFree(pHostChCtx);
2304 return VERR_NO_MEMORY;
2305 }
2306
2307 *ppHostChCtx = pHostChCtx;
2308 *ppVRDPCtx = pVRDPCtx;
2309 return VINF_SUCCESS;
2310}
2311
2312int ConsoleVRDPServer::tsmfLock(void)
2313{
2314 int rc = RTCritSectEnter(&mTSMFLock);
2315 AssertRC(rc);
2316 return rc;
2317}
2318
2319void ConsoleVRDPServer::tsmfUnlock(void)
2320{
2321 RTCritSectLeave(&mTSMFLock);
2322}
2323
[43350]2324/* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelAttach(void *pvProvider,
2325 void **ppvChannel,
2326 uint32_t u32Flags,
2327 VBOXHOSTCHANNELCALLBACKS *pCallbacks,
2328 void *pvCallbacks)
2329{
2330 LogFlowFunc(("\n"));
2331
2332 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvProvider);
2333
[43892]2334 /* Create 2 context structures: for the VRDP server and for the host service. */
2335 TSMFHOSTCHCTX *pHostChCtx = NULL;
2336 TSMFVRDPCTX *pVRDPCtx = NULL;
2337
2338 int rc = tsmfContextsAlloc(&pHostChCtx, &pVRDPCtx);
2339 if (RT_FAILURE(rc))
[43350]2340 {
[43892]2341 return rc;
[43350]2342 }
2343
[43892]2344 pHostChCtx->pThis = pThis;
2345 pHostChCtx->pVRDPCtx = pVRDPCtx;
[43350]2346
[43892]2347 pVRDPCtx->pThis = pThis;
2348 pVRDPCtx->pCallbacks = pCallbacks;
2349 pVRDPCtx->pvCallbacks = pvCallbacks;
2350 pVRDPCtx->pHostChCtx = pHostChCtx;
[43350]2351
[43892]2352 rc = pThis->m_interfaceTSMF.VRDETSMFChannelCreate(pThis->mhServer, pVRDPCtx, u32Flags);
2353
[43350]2354 if (RT_SUCCESS(rc))
2355 {
[63563]2356 /** @todo contexts should be in a list for accounting. */
[43892]2357 *ppvChannel = pHostChCtx;
[43350]2358 }
2359 else
2360 {
[43892]2361 RTMemFree(pHostChCtx);
2362 RTMemFree(pVRDPCtx);
[43350]2363 }
2364
2365 return rc;
2366}
2367
2368/* static */ DECLCALLBACK(void) ConsoleVRDPServer::tsmfHostChannelDetach(void *pvChannel)
2369{
2370 LogFlowFunc(("\n"));
2371
[43892]2372 TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
2373 ConsoleVRDPServer *pThis = pHostChCtx->pThis;
[43388]2374
[43892]2375 int rc = pThis->tsmfLock();
2376 if (RT_SUCCESS(rc))
2377 {
2378 bool fClose = false;
2379 uint32_t u32ChannelHandle = 0;
2380
2381 if (pHostChCtx->pVRDPCtx)
2382 {
2383 /* There is still a VRDP context for this channel. */
2384 pHostChCtx->pVRDPCtx->pHostChCtx = NULL;
2385 u32ChannelHandle = pHostChCtx->pVRDPCtx->u32ChannelHandle;
2386 fClose = true;
2387 }
2388
2389 pThis->tsmfUnlock();
2390
2391 RTMemFree(pHostChCtx);
2392
2393 if (fClose)
2394 {
2395 LogFlowFunc(("Closing VRDE channel %d.\n", u32ChannelHandle));
2396 pThis->m_interfaceTSMF.VRDETSMFChannelClose(pThis->mhServer, u32ChannelHandle);
2397 }
2398 else
2399 {
2400 LogFlowFunc(("No VRDE channel.\n"));
2401 }
2402 }
[43350]2403}
2404
2405/* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelSend(void *pvChannel,
2406 const void *pvData,
2407 uint32_t cbData)
2408{
[43892]2409 LogFlowFunc(("cbData %d\n", cbData));
[43350]2410
[43892]2411 TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
2412 ConsoleVRDPServer *pThis = pHostChCtx->pThis;
[43350]2413
[43892]2414 int rc = pThis->tsmfLock();
2415 if (RT_SUCCESS(rc))
2416 {
2417 bool fSend = false;
2418 uint32_t u32ChannelHandle = 0;
2419
2420 if (pHostChCtx->pVRDPCtx)
2421 {
2422 u32ChannelHandle = pHostChCtx->pVRDPCtx->u32ChannelHandle;
2423 fSend = true;
2424 }
2425
2426 pThis->tsmfUnlock();
2427
2428 if (fSend)
2429 {
2430 LogFlowFunc(("Send to VRDE channel %d.\n", u32ChannelHandle));
2431 rc = pThis->m_interfaceTSMF.VRDETSMFChannelSend(pThis->mhServer, u32ChannelHandle,
2432 pvData, cbData);
2433 }
2434 }
2435
[43350]2436 return rc;
2437}
2438
2439/* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelRecv(void *pvChannel,
2440 void *pvData,
2441 uint32_t cbData,
2442 uint32_t *pcbReceived,
2443 uint32_t *pcbRemaining)
2444{
[43892]2445 LogFlowFunc(("cbData %d\n", cbData));
[43350]2446
[43892]2447 TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
2448 ConsoleVRDPServer *pThis = pHostChCtx->pThis;
[43350]2449
[43892]2450 int rc = pThis->tsmfLock();
2451 if (RT_SUCCESS(rc))
2452 {
2453 uint32_t cbToCopy = RT_MIN(cbData, pHostChCtx->cbDataReceived);
2454 uint32_t cbRemaining = pHostChCtx->cbDataReceived - cbToCopy;
[43350]2455
[43892]2456 LogFlowFunc(("cbToCopy %d, cbRemaining %d\n", cbToCopy, cbRemaining));
[43350]2457
[43892]2458 if (cbToCopy != 0)
2459 {
2460 memcpy(pvData, pHostChCtx->pvDataReceived, cbToCopy);
[43350]2461
[43892]2462 if (cbRemaining != 0)
2463 {
2464 memmove(pHostChCtx->pvDataReceived, (uint8_t *)pHostChCtx->pvDataReceived + cbToCopy, cbRemaining);
2465 }
2466
2467 pHostChCtx->cbDataReceived = cbRemaining;
[43350]2468 }
2469
[43892]2470 pThis->tsmfUnlock();
2471
2472 *pcbRemaining = cbRemaining;
2473 *pcbReceived = cbToCopy;
[43350]2474 }
2475
[43892]2476 return rc;
[43350]2477}
2478
2479/* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelControl(void *pvChannel,
2480 uint32_t u32Code,
2481 const void *pvParm,
2482 uint32_t cbParm,
2483 const void *pvData,
2484 uint32_t cbData,
2485 uint32_t *pcbDataReturned)
2486{
[63240]2487 RT_NOREF(pvParm, cbParm, pvData, cbData);
[43892]2488 LogFlowFunc(("u32Code %u\n", u32Code));
2489
[43462]2490 if (!pvChannel)
2491 {
2492 /* Special case, the provider must answer rather than a channel instance. */
2493 if (u32Code == VBOX_HOST_CHANNEL_CTRL_EXISTS)
2494 {
2495 *pcbDataReturned = 0;
2496 return VINF_SUCCESS;
2497 }
2498
2499 return VERR_NOT_IMPLEMENTED;
2500 }
2501
2502 /* Channels do not support this. */
[43350]2503 return VERR_NOT_IMPLEMENTED;
2504}
2505
2506
2507void ConsoleVRDPServer::setupTSMF(void)
2508{
2509 if (m_interfaceTSMF.header.u64Size == 0)
2510 {
2511 return;
2512 }
2513
2514 /* Register with the host channel service. */
2515 VBOXHOSTCHANNELINTERFACE hostChannelInterface =
2516 {
2517 this,
2518 tsmfHostChannelAttach,
2519 tsmfHostChannelDetach,
2520 tsmfHostChannelSend,
2521 tsmfHostChannelRecv,
2522 tsmfHostChannelControl
2523 };
2524
2525 VBoxHostChannelHostRegister parms;
2526
2527 static char szProviderName[] = "/vrde/tsmf";
2528
2529 parms.name.type = VBOX_HGCM_SVC_PARM_PTR;
2530 parms.name.u.pointer.addr = &szProviderName[0];
2531 parms.name.u.pointer.size = sizeof(szProviderName);
2532
2533 parms.iface.type = VBOX_HGCM_SVC_PARM_PTR;
2534 parms.iface.u.pointer.addr = &hostChannelInterface;
2535 parms.iface.u.pointer.size = sizeof(hostChannelInterface);
2536
[51612]2537 VMMDev *pVMMDev = mConsole->i_getVMMDev();
[43350]2538
2539 if (!pVMMDev)
2540 {
2541 AssertMsgFailed(("setupTSMF no vmmdev\n"));
2542 return;
2543 }
2544
2545 int rc = pVMMDev->hgcmHostCall("VBoxHostChannel",
2546 VBOX_HOST_CHANNEL_HOST_FN_REGISTER,
2547 2,
2548 &parms.name);
2549
2550 if (!RT_SUCCESS(rc))
2551 {
2552 Log(("VBOX_HOST_CHANNEL_HOST_FN_REGISTER failed with %Rrc\n", rc));
2553 return;
2554 }
2555
2556 LogRel(("VRDE: Enabled TSMF channel.\n"));
2557
2558 return;
2559}
2560
[63563]2561/** @todo these defines must be in a header, which is used by guest component as well. */
[43350]2562#define VBOX_TSMF_HCH_CREATE_ACCEPTED (VBOX_HOST_CHANNEL_EVENT_USER + 0)
2563#define VBOX_TSMF_HCH_CREATE_DECLINED (VBOX_HOST_CHANNEL_EVENT_USER + 1)
2564#define VBOX_TSMF_HCH_DISCONNECTED (VBOX_HOST_CHANNEL_EVENT_USER + 2)
2565
2566/* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDETSMFCbNotify(void *pvContext,
2567 uint32_t u32Notification,
2568 void *pvChannel,
2569 const void *pvParm,
2570 uint32_t cbParm)
2571{
[63240]2572 RT_NOREF(cbParm);
[43892]2573 int rc = VINF_SUCCESS;
2574
[43350]2575 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
2576
[43892]2577 TSMFVRDPCTX *pVRDPCtx = (TSMFVRDPCTX *)pvChannel;
[43350]2578
[43892]2579 Assert(pVRDPCtx->pThis == pThis);
[43350]2580
[43892]2581 if (pVRDPCtx->pCallbacks == NULL)
[43350]2582 {
[43892]2583 LogFlowFunc(("tsmfHostChannel: Channel disconnected. Skipping.\n"));
2584 return;
2585 }
2586
2587 switch (u32Notification)
2588 {
[43350]2589 case VRDE_TSMF_N_CREATE_ACCEPTED:
2590 {
2591 VRDETSMFNOTIFYCREATEACCEPTED *p = (VRDETSMFNOTIFYCREATEACCEPTED *)pvParm;
2592 Assert(cbParm == sizeof(VRDETSMFNOTIFYCREATEACCEPTED));
2593
[43892]2594 LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_CREATE_ACCEPTED(%p): p->u32ChannelHandle %d\n",
2595 pVRDPCtx, p->u32ChannelHandle));
[43350]2596
[43892]2597 pVRDPCtx->u32ChannelHandle = p->u32ChannelHandle;
[43350]2598
[43892]2599 pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
2600 VBOX_TSMF_HCH_CREATE_ACCEPTED,
2601 NULL, 0);
[43350]2602 } break;
2603
2604 case VRDE_TSMF_N_CREATE_DECLINED:
2605 {
[43892]2606 LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_CREATE_DECLINED(%p)\n", pVRDPCtx));
2607
2608 pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
2609 VBOX_TSMF_HCH_CREATE_DECLINED,
2610 NULL, 0);
[43350]2611 } break;
2612
2613 case VRDE_TSMF_N_DATA:
2614 {
2615 /* Save the data in the intermediate buffer and send the event. */
2616 VRDETSMFNOTIFYDATA *p = (VRDETSMFNOTIFYDATA *)pvParm;
2617 Assert(cbParm == sizeof(VRDETSMFNOTIFYDATA));
2618
[43892]2619 LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DATA(%p): p->cbData %d\n", pVRDPCtx, p->cbData));
[43350]2620
[43892]2621 VBOXHOSTCHANNELEVENTRECV ev;
2622 ev.u32SizeAvailable = 0;
[43350]2623
[43892]2624 rc = pThis->tsmfLock();
2625
2626 if (RT_SUCCESS(rc))
[43350]2627 {
[43892]2628 TSMFHOSTCHCTX *pHostChCtx = pVRDPCtx->pHostChCtx;
[43350]2629
[43892]2630 if (pHostChCtx)
2631 {
2632 if (pHostChCtx->pvDataReceived)
2633 {
2634 uint32_t cbAlloc = p->cbData + pHostChCtx->cbDataReceived;
2635 pHostChCtx->pvDataReceived = RTMemRealloc(pHostChCtx->pvDataReceived, cbAlloc);
2636 memcpy((uint8_t *)pHostChCtx->pvDataReceived + pHostChCtx->cbDataReceived, p->pvData, p->cbData);
2637
2638 pHostChCtx->cbDataReceived += p->cbData;
2639 pHostChCtx->cbDataAllocated = cbAlloc;
2640 }
2641 else
2642 {
2643 pHostChCtx->pvDataReceived = RTMemAlloc(p->cbData);
2644 memcpy(pHostChCtx->pvDataReceived, p->pvData, p->cbData);
2645
2646 pHostChCtx->cbDataReceived = p->cbData;
2647 pHostChCtx->cbDataAllocated = p->cbData;
2648 }
2649
2650 ev.u32SizeAvailable = p->cbData;
2651 }
2652 else
2653 {
2654 LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DATA: no host channel. Skipping\n"));
2655 }
2656
2657 pThis->tsmfUnlock();
[43350]2658 }
2659
[43892]2660 pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
2661 VBOX_HOST_CHANNEL_EVENT_RECV,
2662 &ev, sizeof(ev));
[43350]2663 } break;
2664
2665 case VRDE_TSMF_N_DISCONNECTED:
2666 {
[43892]2667 LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DISCONNECTED(%p)\n", pVRDPCtx));
2668
2669 pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
2670 VBOX_TSMF_HCH_DISCONNECTED,
2671 NULL, 0);
2672
2673 /* The callback context will not be used anymore. */
2674 pVRDPCtx->pCallbacks->HostChannelCallbackDeleted(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx);
2675 pVRDPCtx->pCallbacks = NULL;
2676 pVRDPCtx->pvCallbacks = NULL;
2677
2678 rc = pThis->tsmfLock();
2679 if (RT_SUCCESS(rc))
2680 {
2681 if (pVRDPCtx->pHostChCtx)
2682 {
2683 /* There is still a host channel context for this channel. */
2684 pVRDPCtx->pHostChCtx->pVRDPCtx = NULL;
2685 }
2686
2687 pThis->tsmfUnlock();
2688
[47117]2689 RT_ZERO(*pVRDPCtx);
[43892]2690 RTMemFree(pVRDPCtx);
2691 }
[43350]2692 } break;
2693
2694 default:
2695 {
2696 AssertFailed();
2697 } break;
2698 }
2699}
2700
[43929]2701/* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInNotify(void *pvCallback,
2702 uint32_t u32Id,
2703 const void *pvData,
2704 uint32_t cbData)
2705{
2706 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
[49120]2707 if (pThis->mEmWebcam)
2708 {
2709 pThis->mEmWebcam->EmWebcamCbNotify(u32Id, pvData, cbData);
2710 }
[43929]2711}
2712
2713/* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInDeviceDesc(void *pvCallback,
2714 int rcRequest,
2715 void *pDeviceCtx,
2716 void *pvUser,
2717 const VRDEVIDEOINDEVICEDESC *pDeviceDesc,
2718 uint32_t cbDevice)
2719{
2720 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
[49120]2721 if (pThis->mEmWebcam)
2722 {
2723 pThis->mEmWebcam->EmWebcamCbDeviceDesc(rcRequest, pDeviceCtx, pvUser, pDeviceDesc, cbDevice);
2724 }
[43929]2725}
2726
2727/* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInControl(void *pvCallback,
2728 int rcRequest,
2729 void *pDeviceCtx,
2730 void *pvUser,
2731 const VRDEVIDEOINCTRLHDR *pControl,
2732 uint32_t cbControl)
2733{
2734 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
[49120]2735 if (pThis->mEmWebcam)
2736 {
2737 pThis->mEmWebcam->EmWebcamCbControl(rcRequest, pDeviceCtx, pvUser, pControl, cbControl);
2738 }
[43929]2739}
2740
2741/* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInFrame(void *pvCallback,
2742 int rcRequest,
2743 void *pDeviceCtx,
2744 const VRDEVIDEOINPAYLOADHDR *pFrame,
2745 uint32_t cbFrame)
2746{
2747 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
[49120]2748 if (pThis->mEmWebcam)
2749 {
2750 pThis->mEmWebcam->EmWebcamCbFrame(rcRequest, pDeviceCtx, pFrame, cbFrame);
2751 }
[43929]2752}
2753
2754int ConsoleVRDPServer::VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx)
2755{
2756 int rc;
2757
2758 if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInDeviceAttach)
2759 {
2760 rc = m_interfaceVideoIn.VRDEVideoInDeviceAttach(mhServer, pDeviceHandle, pvDeviceCtx);
2761 }
2762 else
2763 {
2764 rc = VERR_NOT_SUPPORTED;
2765 }
2766
2767 return rc;
2768}
2769
2770int ConsoleVRDPServer::VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle)
2771{
2772 int rc;
2773
2774 if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInDeviceDetach)
2775 {
2776 rc = m_interfaceVideoIn.VRDEVideoInDeviceDetach(mhServer, pDeviceHandle);
2777 }
2778 else
2779 {
2780 rc = VERR_NOT_SUPPORTED;
2781 }
2782
2783 return rc;
2784}
2785
2786int ConsoleVRDPServer::VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle)
2787{
2788 int rc;
2789
2790 if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInGetDeviceDesc)
2791 {
2792 rc = m_interfaceVideoIn.VRDEVideoInGetDeviceDesc(mhServer, pvUser, pDeviceHandle);
2793 }
2794 else
2795 {
2796 rc = VERR_NOT_SUPPORTED;
2797 }
2798
2799 return rc;
2800}
2801
2802int ConsoleVRDPServer::VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
[44191]2803 const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq)
[43929]2804{
2805 int rc;
2806
2807 if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInControl)
2808 {
2809 rc = m_interfaceVideoIn.VRDEVideoInControl(mhServer, pvUser, pDeviceHandle, pReq, cbReq);
2810 }
2811 else
2812 {
2813 rc = VERR_NOT_SUPPORTED;
2814 }
2815
2816 return rc;
2817}
2818
[47464]2819
2820/* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackInputSetup(void *pvCallback,
2821 int rcRequest,
2822 uint32_t u32Method,
2823 const void *pvResult,
2824 uint32_t cbResult)
2825{
2826 NOREF(pvCallback);
2827 NOREF(rcRequest);
2828 NOREF(u32Method);
2829 NOREF(pvResult);
2830 NOREF(cbResult);
2831}
2832
2833/* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackInputEvent(void *pvCallback,
2834 uint32_t u32Method,
2835 const void *pvEvent,
2836 uint32_t cbEvent)
2837{
2838 ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
2839
2840 if (u32Method == VRDE_INPUT_METHOD_TOUCH)
2841 {
2842 if (cbEvent >= sizeof(VRDEINPUTHEADER))
2843 {
2844 VRDEINPUTHEADER *pHeader = (VRDEINPUTHEADER *)pvEvent;
2845
2846 if (pHeader->u16EventId == VRDEINPUT_EVENTID_TOUCH)
2847 {
[51612]2848 IMouse *pMouse = pThis->mConsole->i_getMouse();
[47571]2849
[47464]2850 VRDEINPUT_TOUCH_EVENT_PDU *p = (VRDEINPUT_TOUCH_EVENT_PDU *)pHeader;
2851
2852 uint16_t iFrame;
2853 for (iFrame = 0; iFrame < p->u16FrameCount; iFrame++)
2854 {
2855 VRDEINPUT_TOUCH_FRAME *pFrame = &p->aFrames[iFrame];
2856
[47571]2857 com::SafeArray<LONG64> aContacts(pFrame->u16ContactCount);
2858
[47464]2859 uint16_t iContact;
2860 for (iContact = 0; iContact < pFrame->u16ContactCount; iContact++)
2861 {
2862 VRDEINPUT_CONTACT_DATA *pContact = &pFrame->aContacts[iContact];
2863
[47571]2864 int16_t x = (int16_t)(pContact->i32X + 1);
2865 int16_t y = (int16_t)(pContact->i32Y + 1);
2866 uint8_t contactId = pContact->u8ContactId;
2867 uint8_t contactState = TouchContactState_None;
[47464]2868
2869 if (pContact->u32ContactFlags & VRDEINPUT_CONTACT_FLAG_INRANGE)
2870 {
2871 contactState |= TouchContactState_InRange;
2872 }
2873 if (pContact->u32ContactFlags & VRDEINPUT_CONTACT_FLAG_INCONTACT)
2874 {
2875 contactState |= TouchContactState_InContact;
2876 }
[47571]2877
2878 aContacts[iContact] = RT_MAKE_U64_FROM_U16((uint16_t)x,
2879 (uint16_t)y,
2880 RT_MAKE_U16(contactId, contactState),
2881 0);
[47464]2882 }
[47571]2883
2884 if (pFrame->u64FrameOffset == 0)
2885 {
2886 pThis->mu64TouchInputTimestampMCS = 0;
2887 }
2888 else
2889 {
2890 pThis->mu64TouchInputTimestampMCS += pFrame->u64FrameOffset;
2891 }
2892
2893 pMouse->PutEventMultiTouch(pFrame->u16ContactCount,
2894 ComSafeArrayAsInParam(aContacts),
2895 (ULONG)(pThis->mu64TouchInputTimestampMCS / 1000)); /* Micro->milliseconds. */
[47464]2896 }
2897 }
2898 else if (pHeader->u16EventId == VRDEINPUT_EVENTID_DISMISS_HOVERING_CONTACT)
2899 {
[63563]2900 /** @todo */
[47464]2901 }
2902 else
2903 {
2904 AssertMsgFailed(("EventId %d\n", pHeader->u16EventId));
2905 }
2906 }
2907 }
2908}
2909
2910
[32718]2911void ConsoleVRDPServer::EnableConnections(void)
[3720]2912{
[4363]2913 if (mpEntryPoints && mhServer)
[3720]2914 {
[33004]2915 mpEntryPoints->VRDEEnableConnections(mhServer, true);
[36843]2916
[43350]2917 /* Setup the generic TSMF channel. */
2918 setupTSMF();
[3720]2919 }
2920}
2921
[32718]2922void ConsoleVRDPServer::DisconnectClient(uint32_t u32ClientId, bool fReconnect)
[12127]2923{
2924 if (mpEntryPoints && mhServer)
2925 {
[33004]2926 mpEntryPoints->VRDEDisconnect(mhServer, u32ClientId, fReconnect);
[12127]2927 }
2928}
2929
[40626]2930int ConsoleVRDPServer::MousePointer(BOOL alpha,
2931 ULONG xHot,
2932 ULONG yHot,
2933 ULONG width,
2934 ULONG height,
2935 const uint8_t *pu8Shape)
2936{
2937 int rc = VINF_SUCCESS;
2938
2939 if (mhServer && mpEntryPoints && m_interfaceMousePtr.VRDEMousePtr)
2940 {
2941 size_t cbMask = (((width + 7) / 8) * height + 3) & ~3;
2942 size_t cbData = width * height * 4;
2943
2944 size_t cbDstMask = alpha? 0: cbMask;
2945
2946 size_t cbPointer = sizeof(VRDEMOUSEPTRDATA) + cbDstMask + cbData;
2947 uint8_t *pu8Pointer = (uint8_t *)RTMemAlloc(cbPointer);
2948 if (pu8Pointer != NULL)
2949 {
2950 VRDEMOUSEPTRDATA *pPointer = (VRDEMOUSEPTRDATA *)pu8Pointer;
2951
2952 pPointer->u16HotX = (uint16_t)xHot;
2953 pPointer->u16HotY = (uint16_t)yHot;
2954 pPointer->u16Width = (uint16_t)width;
2955 pPointer->u16Height = (uint16_t)height;
2956 pPointer->u16MaskLen = (uint16_t)cbDstMask;
2957 pPointer->u32DataLen = (uint32_t)cbData;
2958
2959 /* AND mask. */
2960 uint8_t *pu8Mask = pu8Pointer + sizeof(VRDEMOUSEPTRDATA);
2961 if (cbDstMask)
2962 {
2963 memcpy(pu8Mask, pu8Shape, cbDstMask);
2964 }
2965
2966 /* XOR mask */
2967 uint8_t *pu8Data = pu8Mask + pPointer->u16MaskLen;
2968 memcpy(pu8Data, pu8Shape + cbMask, cbData);
2969
2970 m_interfaceMousePtr.VRDEMousePtr(mhServer, pPointer);
2971
2972 RTMemFree(pu8Pointer);
2973 }
2974 else
2975 {
2976 rc = VERR_NO_MEMORY;
2977 }
2978 }
2979 else
2980 {
2981 rc = VERR_NOT_SUPPORTED;
2982 }
2983
2984 return rc;
2985}
2986
[33004]2987void ConsoleVRDPServer::MousePointerUpdate(const VRDECOLORPOINTER *pPointer)
[3720]2988{
[4363]2989 if (mpEntryPoints && mhServer)
[3720]2990 {
[33004]2991 mpEntryPoints->VRDEColorPointer(mhServer, pPointer);
[3720]2992 }
2993}
2994
[32718]2995void ConsoleVRDPServer::MousePointerHide(void)
[3720]2996{
[4363]2997 if (mpEntryPoints && mhServer)
[3720]2998 {
[33004]2999 mpEntryPoints->VRDEHidePointer(mhServer);
[3720]3000 }
3001}
[300]3002
[32718]3003void ConsoleVRDPServer::Stop(void)
[1]3004{
3005 Assert(VALID_PTR(this)); /** @todo r=bird: there are(/was) some odd cases where this buster was invalid on
3006 * linux. Just remove this when it's 100% sure that problem has been fixed. */
[47113]3007
3008#ifdef VBOX_WITH_USB
3009 remoteUSBThreadStop();
3010#endif /* VBOX_WITH_USB */
3011
[1]3012 if (mhServer)
3013 {
[33004]3014 HVRDESERVER hServer = mhServer;
[1]3015
3016 /* Reset the handle to avoid further calls to the server. */
3017 mhServer = 0;
3018
[46097]3019 /* Workaround for VM process hangs on termination.
3020 *
3021 * Make sure that the server is not currently processing a resize.
3022 * mhServer 0 will not allow to enter the server again.
3023 * Wait until any current resize returns from the server.
3024 */
3025 if (mcInResize)
3026 {
3027 LogRel(("VRDP: waiting for resize %d\n", mcInResize));
3028
3029 int i = 0;
3030 while (mcInResize && ++i < 100)
3031 {
3032 RTThreadSleep(10);
3033 }
3034 }
3035
[4363]3036 if (mpEntryPoints && hServer)
[3720]3037 {
[33004]3038 mpEntryPoints->VRDEDestroy(hServer);
[3720]3039 }
[1]3040 }
3041
[58383]3042#ifndef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
[58368]3043 AuthLibUnload(&mAuthLibCtx);
[58383]3044#endif
[1]3045}
3046
3047/* Worker thread for Remote USB. The thread polls the clients for
3048 * the list of attached USB devices.
3049 * The thread is also responsible for attaching/detaching devices
3050 * to/from the VM.
3051 *
3052 * It is expected that attaching/detaching is not a frequent operation.
3053 *
3054 * The thread is always running when the VRDP server is active.
3055 *
3056 * The thread scans backends and requests the device list every 2 seconds.
3057 *
3058 * When device list is available, the thread calls the Console to process it.
3059 *
3060 */
3061#define VRDP_DEVICE_LIST_PERIOD_MS (2000)
3062
[1928]3063#ifdef VBOX_WITH_USB
[32718]3064static DECLCALLBACK(int) threadRemoteUSB(RTTHREAD self, void *pvUser)
[1]3065{
3066 ConsoleVRDPServer *pOwner = (ConsoleVRDPServer *)pvUser;
3067
3068 LogFlow(("Console::threadRemoteUSB: start. owner = %p.\n", pOwner));
[4876]3069
[32718]3070 pOwner->notifyRemoteUSBThreadRunning(self);
[1]3071
[32718]3072 while (pOwner->isRemoteUSBThreadRunning())
[1]3073 {
3074 RemoteUSBBackend *pRemoteUSBBackend = NULL;
[4876]3075
[32718]3076 while ((pRemoteUSBBackend = pOwner->usbBackendGetNext(pRemoteUSBBackend)) != NULL)
[1]3077 {
[32718]3078 pRemoteUSBBackend->PollRemoteDevices();
[1]3079 }
3080
[32718]3081 pOwner->waitRemoteUSBThreadEvent(VRDP_DEVICE_LIST_PERIOD_MS);
[1]3082
3083 LogFlow(("Console::threadRemoteUSB: iteration. owner = %p.\n", pOwner));
3084 }
3085
3086 return VINF_SUCCESS;
3087}
3088
[32718]3089void ConsoleVRDPServer::notifyRemoteUSBThreadRunning(RTTHREAD thread)
[1]3090{
3091 mUSBBackends.thread = thread;
3092 mUSBBackends.fThreadRunning = true;
[32718]3093 int rc = RTThreadUserSignal(thread);
[26186]3094 AssertRC(rc);
[1]3095}
[4876]3096
[32718]3097bool ConsoleVRDPServer::isRemoteUSBThreadRunning(void)
[1]3098{
3099 return mUSBBackends.fThreadRunning;
3100}
[4876]3101
[32718]3102void ConsoleVRDPServer::waitRemoteUSBThreadEvent(RTMSINTERVAL cMillies)
[1]3103{
[32718]3104 int rc = RTSemEventWait(mUSBBackends.event, cMillies);
3105 Assert(RT_SUCCESS(rc) || rc == VERR_TIMEOUT);
[1928]3106 NOREF(rc);
[1]3107}
3108
[32718]3109void ConsoleVRDPServer::remoteUSBThreadStart(void)
[1]3110{
[32718]3111 int rc = RTSemEventCreate(&mUSBBackends.event);
[1]3112
[21878]3113 if (RT_FAILURE(rc))
[1]3114 {
[32718]3115 AssertFailed();
[1]3116 mUSBBackends.event = 0;
3117 }
[4876]3118
[21878]3119 if (RT_SUCCESS(rc))
[1]3120 {
[32718]3121 rc = RTThreadCreate(&mUSBBackends.thread, threadRemoteUSB, this, 65536,
[1]3122 RTTHREADTYPE_VRDP_IO, RTTHREADFLAGS_WAITABLE, "remote usb");
3123 }
[4876]3124
[21878]3125 if (RT_FAILURE(rc))
[1]3126 {
[13837]3127 LogRel(("Warning: could not start the remote USB thread, rc = %Rrc!!!\n", rc));
[1]3128 mUSBBackends.thread = NIL_RTTHREAD;
3129 }
3130 else
3131 {
3132 /* Wait until the thread is ready. */
[32718]3133 rc = RTThreadUserWait(mUSBBackends.thread, 60000);
[26186]3134 AssertRC(rc);
[21878]3135 Assert (mUSBBackends.fThreadRunning || RT_FAILURE(rc));
[1]3136 }
3137}
3138
[32718]3139void ConsoleVRDPServer::remoteUSBThreadStop(void)
[1]3140{
3141 mUSBBackends.fThreadRunning = false;
[4876]3142
[1]3143 if (mUSBBackends.thread != NIL_RTTHREAD)
3144 {
3145 Assert (mUSBBackends.event != 0);
[4876]3146
[32718]3147 RTSemEventSignal(mUSBBackends.event);
[4876]3148
[32718]3149 int rc = RTThreadWait(mUSBBackends.thread, 60000, NULL);
[26186]3150 AssertRC(rc);
[4876]3151
[1]3152 mUSBBackends.thread = NIL_RTTHREAD;
3153 }
[4876]3154
[1]3155 if (mUSBBackends.event)
3156 {
[32718]3157 RTSemEventDestroy(mUSBBackends.event);
[1]3158 mUSBBackends.event = 0;
3159 }
3160}
[1928]3161#endif /* VBOX_WITH_USB */
[1]3162
[34558]3163AuthResult ConsoleVRDPServer::Authenticate(const Guid &uuid, AuthGuestJudgement guestJudgement,
[58383]3164 const char *pszUser, const char *pszPassword, const char *pszDomain,
3165 uint32_t u32ClientId)
[1]3166{
[58368]3167 LogFlowFunc(("uuid = %RTuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n",
3168 uuid.raw(), guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId));
[1]3169
[58383]3170 AuthResult result = AuthResultAccessDenied;
3171
3172#ifdef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
3173 try
3174 {
3175 /* Init auth parameters. Order is important. */
3176 SafeArray<BSTR> authParams;
3177 Bstr("VRDEAUTH" ).detachTo(authParams.appendedRaw());
3178 Bstr(uuid.toUtf16() ).detachTo(authParams.appendedRaw());
3179 BstrFmt("%u", guestJudgement).detachTo(authParams.appendedRaw());
3180 Bstr(pszUser ).detachTo(authParams.appendedRaw());
3181 Bstr(pszPassword ).detachTo(authParams.appendedRaw());
3182 Bstr(pszDomain ).detachTo(authParams.appendedRaw());
3183 BstrFmt("%u", u32ClientId).detachTo(authParams.appendedRaw());
3184
3185 Bstr authResult;
3186 HRESULT hr = mConsole->mControl->AuthenticateExternal(ComSafeArrayAsInParam(authParams),
3187 authResult.asOutParam());
3188 LogFlowFunc(("%Rhrc [%ls]\n", hr, authResult.raw()));
3189
3190 size_t cbPassword = RTUtf16Len((PRTUTF16)authParams[4]) * sizeof(RTUTF16);
3191 if (cbPassword)
3192 RTMemWipeThoroughly(authParams[4], cbPassword, 10 /* cPasses */);
3193
3194 if (SUCCEEDED(hr) && authResult == "granted")
3195 result = AuthResultAccessGranted;
3196 }
[73505]3197 catch (std::bad_alloc &)
[58383]3198 {
3199 }
3200#else
[1]3201 /*
3202 * Called only from VRDP input thread. So thread safety is not required.
3203 */
3204
[58368]3205 if (!mAuthLibCtx.hAuthLibrary)
[1]3206 {
3207 /* Load the external authentication library. */
3208 Bstr authLibrary;
[51612]3209 mConsole->i_getVRDEServer()->COMGETTER(AuthLibrary)(authLibrary.asOutParam());
[1]3210
3211 Utf8Str filename = authLibrary;
3212
[73003]3213 int vrc = AuthLibLoad(&mAuthLibCtx, filename.c_str());
3214 if (RT_FAILURE(vrc))
[1]3215 {
[73003]3216 mConsole->setErrorBoth(E_FAIL, vrc, mConsole->tr("Could not load the external authentication library '%s' (%Rrc)"),
3217 filename.c_str(), vrc);
[34558]3218 return AuthResultAccessDenied;
[1]3219 }
3220 }
3221
[58383]3222 result = AuthLibAuthenticate(&mAuthLibCtx,
3223 uuid.raw(), guestJudgement,
3224 pszUser, pszPassword, pszDomain,
3225 u32ClientId);
3226#endif /* !VBOX_WITH_VRDEAUTH_IN_VBOXSVC */
[1]3227
3228 switch (result)
3229 {
[34558]3230 case AuthResultAccessDenied:
3231 LogRel(("AUTH: external authentication module returned 'access denied'\n"));
[1]3232 break;
[34558]3233 case AuthResultAccessGranted:
3234 LogRel(("AUTH: external authentication module returned 'access granted'\n"));
[1]3235 break;
[34558]3236 case AuthResultDelegateToGuest:
3237 LogRel(("AUTH: external authentication module returned 'delegate request to guest'\n"));
[1]3238 break;
3239 default:
[34558]3240 LogRel(("AUTH: external authentication module returned incorrect return code %d\n", result));
3241 result = AuthResultAccessDenied;
[1]3242 }
3243
[58368]3244 LogFlowFunc(("result = %d\n", result));
[1]3245
3246 return result;
3247}
3248
[32718]3249void ConsoleVRDPServer::AuthDisconnect(const Guid &uuid, uint32_t u32ClientId)
[2527]3250{
[13842]3251 LogFlow(("ConsoleVRDPServer::AuthDisconnect: uuid = %RTuuid, u32ClientId = %d\n",
[58368]3252 uuid.raw(), u32ClientId));
[2527]3253
[58383]3254#ifdef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
3255 try
3256 {
3257 /* Init auth parameters. Order is important. */
3258 SafeArray<BSTR> authParams;
3259 Bstr("VRDEAUTHDISCONNECT").detachTo(authParams.appendedRaw());
3260 Bstr(uuid.toUtf16() ).detachTo(authParams.appendedRaw());
3261 BstrFmt("%u", u32ClientId).detachTo(authParams.appendedRaw());
3262
3263 Bstr authResult;
3264 HRESULT hr = mConsole->mControl->AuthenticateExternal(ComSafeArrayAsInParam(authParams),
3265 authResult.asOutParam());
3266 LogFlowFunc(("%Rhrc [%ls]\n", hr, authResult.raw())); NOREF(hr);
3267 }
[73505]3268 catch (std::bad_alloc &)
[58383]3269 {
3270 }
3271#else
[58368]3272 AuthLibDisconnect(&mAuthLibCtx, uuid.raw(), u32ClientId);
[58383]3273#endif /* !VBOX_WITH_VRDEAUTH_IN_VBOXSVC */
[2527]3274}
3275
[32718]3276int ConsoleVRDPServer::lockConsoleVRDPServer(void)
[1]3277{
[32718]3278 int rc = RTCritSectEnter(&mCritSect);
[26186]3279 AssertRC(rc);
[1]3280 return rc;
3281}
3282
[32718]3283void ConsoleVRDPServer::unlockConsoleVRDPServer(void)
[1]3284{
[32718]3285 RTCritSectLeave(&mCritSect);
[1]3286}
3287
[32718]3288DECLCALLBACK(int) ConsoleVRDPServer::ClipboardCallback(void *pvCallback,
3289 uint32_t u32ClientId,
3290 uint32_t u32Function,
3291 uint32_t u32Format,
3292 const void *pvData,
3293 uint32_t cbData)
[2386]3294{
3295 LogFlowFunc(("pvCallback = %p, u32ClientId = %d, u32Function = %d, u32Format = 0x%08X, pvData = %p, cbData = %d\n",
3296 pvCallback, u32ClientId, u32Function, u32Format, pvData, cbData));
3297
3298 int rc = VINF_SUCCESS;
[4876]3299
[2386]3300 ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvCallback);
[4876]3301
[2386]3302 NOREF(u32ClientId);
[4876]3303
[2386]3304 switch (u32Function)
3305 {
[33004]3306 case VRDE_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE:
[2386]3307 {
3308 if (pServer->mpfnClipboardCallback)
3309 {
[32718]3310 pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
3311 u32Format,
3312 (void *)pvData,
3313 cbData);
[2386]3314 }
[4876]3315 } break;
3316
[33004]3317 case VRDE_CLIPBOARD_FUNCTION_DATA_READ:
[2386]3318 {
3319 if (pServer->mpfnClipboardCallback)
3320 {
[32718]3321 pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_DATA_READ,
3322 u32Format,
3323 (void *)pvData,
3324 cbData);
[2386]3325 }
[4876]3326 } break;
[2386]3327
[4876]3328 default:
[2386]3329 rc = VERR_NOT_SUPPORTED;
3330 }
[4876]3331
[2386]3332 return rc;
3333}
3334
[32718]3335DECLCALLBACK(int) ConsoleVRDPServer::ClipboardServiceExtension(void *pvExtension,
3336 uint32_t u32Function,
3337 void *pvParms,
3338 uint32_t cbParms)
[2386]3339{
[63240]3340 RT_NOREF(cbParms);
[2386]3341 LogFlowFunc(("pvExtension = %p, u32Function = %d, pvParms = %p, cbParms = %d\n",
3342 pvExtension, u32Function, pvParms, cbParms));
[4876]3343
[2386]3344 int rc = VINF_SUCCESS;
[4876]3345
[2386]3346 ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvExtension);
[4876]3347
[2386]3348 VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms;
[4876]3349
[2386]3350 switch (u32Function)
3351 {
3352 case VBOX_CLIPBOARD_EXT_FN_SET_CALLBACK:
3353 {
[13860]3354 pServer->mpfnClipboardCallback = pParms->u.pfnCallback;
[2386]3355 } break;
3356
3357 case VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE:
3358 {
[2522]3359 /* The guest announces clipboard formats. This must be delivered to all clients. */
[4363]3360 if (mpEntryPoints && pServer->mhServer)
[3720]3361 {
[33004]3362 mpEntryPoints->VRDEClipboard(pServer->mhServer,
3363 VRDE_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE,
[32718]3364 pParms->u32Format,
3365 NULL,
3366 0,
3367 NULL);
[3720]3368 }
[2386]3369 } break;
3370
3371 case VBOX_CLIPBOARD_EXT_FN_DATA_READ:
3372 {
[2522]3373 /* The clipboard service expects that the pvData buffer will be filled
3374 * with clipboard data. The server returns the data from the client that
3375 * announced the requested format most recently.
3376 */
[4363]3377 if (mpEntryPoints && pServer->mhServer)
[3720]3378 {
[33004]3379 mpEntryPoints->VRDEClipboard(pServer->mhServer,
3380 VRDE_CLIPBOARD_FUNCTION_DATA_READ,
[32718]3381 pParms->u32Format,
3382 pParms->u.pvData,
3383 pParms->cbData,
3384 &pParms->cbData);
[3720]3385 }
[2386]3386 } break;
3387
3388 case VBOX_CLIPBOARD_EXT_FN_DATA_WRITE:
3389 {
[4363]3390 if (mpEntryPoints && pServer->mhServer)
[3720]3391 {
[33004]3392 mpEntryPoints->VRDEClipboard(pServer->mhServer,
3393 VRDE_CLIPBOARD_FUNCTION_DATA_WRITE,
[32718]3394 pParms->u32Format,
3395 pParms->u.pvData,
3396 pParms->cbData,
3397 NULL);
[3720]3398 }
[2386]3399 } break;
[4876]3400
3401 default:
[2386]3402 rc = VERR_NOT_SUPPORTED;
3403 }
[2393]3404
[2386]3405 return rc;
3406}
3407
[32718]3408void ConsoleVRDPServer::ClipboardCreate(uint32_t u32ClientId)
[2386]3409{
[63240]3410 RT_NOREF(u32ClientId);
[32718]3411 int rc = lockConsoleVRDPServer();
[4876]3412
[21878]3413 if (RT_SUCCESS(rc))
[2386]3414 {
3415 if (mcClipboardRefs == 0)
3416 {
[32718]3417 rc = HGCMHostRegisterServiceExtension(&mhClipboard, "VBoxSharedClipboard", ClipboardServiceExtension, this);
[4876]3418
[21878]3419 if (RT_SUCCESS(rc))
[2386]3420 {
3421 mcClipboardRefs++;
3422 }
3423 }
[4876]3424
[32718]3425 unlockConsoleVRDPServer();
[2386]3426 }
3427}
3428
[32718]3429void ConsoleVRDPServer::ClipboardDelete(uint32_t u32ClientId)
[2386]3430{
[63240]3431 RT_NOREF(u32ClientId);
[32718]3432 int rc = lockConsoleVRDPServer();
[4876]3433
[21878]3434 if (RT_SUCCESS(rc))
[2386]3435 {
3436 mcClipboardRefs--;
[4876]3437
[2386]3438 if (mcClipboardRefs == 0)
3439 {
[32718]3440 HGCMHostUnregisterServiceExtension(mhClipboard);
[2386]3441 }
3442
[32718]3443 unlockConsoleVRDPServer();
[2386]3444 }
3445}
3446
[1]3447/* That is called on INPUT thread of the VRDP server.
3448 * The ConsoleVRDPServer keeps a list of created backend instances.
3449 */
[32718]3450void ConsoleVRDPServer::USBBackendCreate(uint32_t u32ClientId, void **ppvIntercept)
[1]3451{
[1928]3452#ifdef VBOX_WITH_USB
[1]3453 LogFlow(("ConsoleVRDPServer::USBBackendCreate: u32ClientId = %d\n", u32ClientId));
[4876]3454
[1]3455 /* Create a new instance of the USB backend for the new client. */
[32718]3456 RemoteUSBBackend *pRemoteUSBBackend = new RemoteUSBBackend(mConsole, this, u32ClientId);
[1]3457
3458 if (pRemoteUSBBackend)
3459 {
[32718]3460 pRemoteUSBBackend->AddRef(); /* 'Release' called in USBBackendDelete. */
[4876]3461
[1]3462 /* Append the new instance in the list. */
[32718]3463 int rc = lockConsoleVRDPServer();
[4876]3464
[21878]3465 if (RT_SUCCESS(rc))
[1]3466 {
3467 pRemoteUSBBackend->pNext = mUSBBackends.pHead;
3468 if (mUSBBackends.pHead)
3469 {
3470 mUSBBackends.pHead->pPrev = pRemoteUSBBackend;
3471 }
3472 else
3473 {
3474 mUSBBackends.pTail = pRemoteUSBBackend;
3475 }
[4876]3476
[1]3477 mUSBBackends.pHead = pRemoteUSBBackend;
[4876]3478
[32718]3479 unlockConsoleVRDPServer();
[4876]3480
[4404]3481 if (ppvIntercept)
3482 {
3483 *ppvIntercept = pRemoteUSBBackend;
3484 }
[1]3485 }
3486
[21878]3487 if (RT_FAILURE(rc))
[1]3488 {
[32718]3489 pRemoteUSBBackend->Release();
[1]3490 }
3491 }
[3720]3492#endif /* VBOX_WITH_USB */
[1]3493}
3494
[32718]3495void ConsoleVRDPServer::USBBackendDelete(uint32_t u32ClientId)
[1]3496{
[1928]3497#ifdef VBOX_WITH_USB
[1]3498 LogFlow(("ConsoleVRDPServer::USBBackendDelete: u32ClientId = %d\n", u32ClientId));
3499
3500 RemoteUSBBackend *pRemoteUSBBackend = NULL;
[4876]3501
[1]3502 /* Find the instance. */
[32718]3503 int rc = lockConsoleVRDPServer();
[4876]3504
[21878]3505 if (RT_SUCCESS(rc))
[1]3506 {
[32718]3507 pRemoteUSBBackend = usbBackendFind(u32ClientId);
[4876]3508
[1]3509 if (pRemoteUSBBackend)
3510 {
3511 /* Notify that it will be deleted. */
[32718]3512 pRemoteUSBBackend->NotifyDelete();
[1]3513 }
[4876]3514
[32718]3515 unlockConsoleVRDPServer();
[1]3516 }
[4876]3517
[1]3518 if (pRemoteUSBBackend)
3519 {
3520 /* Here the instance has been excluded from the list and can be dereferenced. */
[32718]3521 pRemoteUSBBackend->Release();
[1]3522 }
[1928]3523#endif
[1]3524}
3525
[32718]3526void *ConsoleVRDPServer::USBBackendRequestPointer(uint32_t u32ClientId, const Guid *pGuid)
[1]3527{
[1928]3528#ifdef VBOX_WITH_USB
[1]3529 RemoteUSBBackend *pRemoteUSBBackend = NULL;
[4876]3530
[1]3531 /* Find the instance. */
[32718]3532 int rc = lockConsoleVRDPServer();
[4876]3533
[21878]3534 if (RT_SUCCESS(rc))
[1]3535 {
[32718]3536 pRemoteUSBBackend = usbBackendFind(u32ClientId);
[4876]3537
[1]3538 if (pRemoteUSBBackend)
3539 {
3540 /* Inform the backend instance that it is referenced by the Guid. */
[32718]3541 bool fAdded = pRemoteUSBBackend->addUUID(pGuid);
[4876]3542
[1]3543 if (fAdded)
3544 {
3545 /* Reference the instance because its pointer is being taken. */
[32718]3546 pRemoteUSBBackend->AddRef(); /* 'Release' is called in USBBackendReleasePointer. */
[1]3547 }
3548 else
3549 {
3550 pRemoteUSBBackend = NULL;
3551 }
3552 }
[4876]3553
[32718]3554 unlockConsoleVRDPServer();
[1]3555 }
[4876]3556
[1]3557 if (pRemoteUSBBackend)
3558 {
[32718]3559 return pRemoteUSBBackend->GetBackendCallbackPointer();
[1]3560 }
[4876]3561
[1928]3562#endif
[1]3563 return NULL;
3564}
3565
[32718]3566void ConsoleVRDPServer::USBBackendReleasePointer(const Guid *pGuid)
[1]3567{
[1928]3568#ifdef VBOX_WITH_USB
[1]3569 RemoteUSBBackend *pRemoteUSBBackend = NULL;
[4876]3570
[1]3571 /* Find the instance. */
[32718]3572 int rc = lockConsoleVRDPServer();
[4876]3573
[21878]3574 if (RT_SUCCESS(rc))
[1]3575 {
[32718]3576 pRemoteUSBBackend = usbBackendFindByUUID(pGuid);
[4876]3577
[1]3578 if (pRemoteUSBBackend)
3579 {
[32718]3580 pRemoteUSBBackend->removeUUID(pGuid);
[1]3581 }
[4876]3582
[32718]3583 unlockConsoleVRDPServer();
[4876]3584
[1]3585 if (pRemoteUSBBackend)
3586 {
[32718]3587 pRemoteUSBBackend->Release();
[1]3588 }
3589 }
[1928]3590#endif
[1]3591}
3592
[32718]3593RemoteUSBBackend *ConsoleVRDPServer::usbBackendGetNext(RemoteUSBBackend *pRemoteUSBBackend)
[1]3594{
3595 LogFlow(("ConsoleVRDPServer::usbBackendGetNext: pBackend = %p\n", pRemoteUSBBackend));
3596
3597 RemoteUSBBackend *pNextRemoteUSBBackend = NULL;
[1928]3598#ifdef VBOX_WITH_USB
[4876]3599
[32718]3600 int rc = lockConsoleVRDPServer();
[4876]3601
[21878]3602 if (RT_SUCCESS(rc))
[1]3603 {
3604 if (pRemoteUSBBackend == NULL)
3605 {
3606 /* The first backend in the list is requested. */
3607 pNextRemoteUSBBackend = mUSBBackends.pHead;
3608 }
3609 else
3610 {
3611 /* Get pointer to the next backend. */
3612 pNextRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
3613 }
[4876]3614
[1]3615 if (pNextRemoteUSBBackend)
3616 {
[32718]3617 pNextRemoteUSBBackend->AddRef();
[1]3618 }
[4876]3619
[32718]3620 unlockConsoleVRDPServer();
[4876]3621
[1]3622 if (pRemoteUSBBackend)
3623 {
[32718]3624 pRemoteUSBBackend->Release();
[1]3625 }
3626 }
[1928]3627#endif
[4876]3628
[1]3629 return pNextRemoteUSBBackend;
3630}
3631
[1928]3632#ifdef VBOX_WITH_USB
[1]3633/* Internal method. Called under the ConsoleVRDPServerLock. */
[32718]3634RemoteUSBBackend *ConsoleVRDPServer::usbBackendFind(uint32_t u32ClientId)
[1]3635{
3636 RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
[4876]3637
[1]3638 while (pRemoteUSBBackend)
3639 {
[32718]3640 if (pRemoteUSBBackend->ClientId() == u32ClientId)
[1]3641 {
3642 break;
3643 }
[4876]3644
[1]3645 pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
3646 }
[4876]3647
[1]3648 return pRemoteUSBBackend;
3649}
3650
3651/* Internal method. Called under the ConsoleVRDPServerLock. */
[32718]3652RemoteUSBBackend *ConsoleVRDPServer::usbBackendFindByUUID(const Guid *pGuid)
[1]3653{
3654 RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
[4876]3655
[1]3656 while (pRemoteUSBBackend)
3657 {
[32718]3658 if (pRemoteUSBBackend->findUUID(pGuid))
[1]3659 {
3660 break;
3661 }
[4876]3662
[1]3663 pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
3664 }
[4876]3665
[1]3666 return pRemoteUSBBackend;
3667}
[1928]3668#endif
[1]3669
3670/* Internal method. Called by the backend destructor. */
[32718]3671void ConsoleVRDPServer::usbBackendRemoveFromList(RemoteUSBBackend *pRemoteUSBBackend)
[1]3672{
[1928]3673#ifdef VBOX_WITH_USB
[32718]3674 int rc = lockConsoleVRDPServer();
[26186]3675 AssertRC(rc);
[4876]3676
[1]3677 /* Exclude the found instance from the list. */
3678 if (pRemoteUSBBackend->pNext)
3679 {
3680 pRemoteUSBBackend->pNext->pPrev = pRemoteUSBBackend->pPrev;
3681 }
3682 else
3683 {
3684 mUSBBackends.pTail = (RemoteUSBBackend *)pRemoteUSBBackend->pPrev;
3685 }
[4876]3686
[1]3687 if (pRemoteUSBBackend->pPrev)
3688 {
3689 pRemoteUSBBackend->pPrev->pNext = pRemoteUSBBackend->pNext;
3690 }
3691 else
3692 {
3693 mUSBBackends.pHead = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
3694 }
[4876]3695
[1]3696 pRemoteUSBBackend->pNext = pRemoteUSBBackend->pPrev = NULL;
[4876]3697
[32718]3698 unlockConsoleVRDPServer();
[1928]3699#endif
[1]3700}
3701
3702
[32718]3703void ConsoleVRDPServer::SendUpdate(unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const
[1]3704{
[4363]3705 if (mpEntryPoints && mhServer)
[3720]3706 {
[33004]3707 mpEntryPoints->VRDEUpdate(mhServer, uScreenId, pvUpdate, cbUpdate);
[3720]3708 }
[1]3709}
3710
[46097]3711void ConsoleVRDPServer::SendResize(void)
[1]3712{
[4363]3713 if (mpEntryPoints && mhServer)
[3720]3714 {
[46097]3715 ++mcInResize;
[33004]3716 mpEntryPoints->VRDEResize(mhServer);
[46097]3717 --mcInResize;
[3720]3718 }
[1]3719}
3720
[32718]3721void ConsoleVRDPServer::SendUpdateBitmap(unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const
[1]3722{
[33004]3723 VRDEORDERHDR update;
[62379]3724 update.x = (uint16_t)x;
3725 update.y = (uint16_t)y;
3726 update.w = (uint16_t)w;
3727 update.h = (uint16_t)h;
[4363]3728 if (mpEntryPoints && mhServer)
[3720]3729 {
[33004]3730 mpEntryPoints->VRDEUpdate(mhServer, uScreenId, &update, sizeof(update));
[3720]3731 }
[1]3732}
3733
[33004]3734void ConsoleVRDPServer::SendAudioSamples(void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const
[1]3735{
[4363]3736 if (mpEntryPoints && mhServer)
[3720]3737 {
[33004]3738 mpEntryPoints->VRDEAudioSamples(mhServer, pvSamples, cSamples, format);
[3720]3739 }
[1]3740}
3741
[32718]3742void ConsoleVRDPServer::SendAudioVolume(uint16_t left, uint16_t right) const
[1]3743{
[4363]3744 if (mpEntryPoints && mhServer)
[3720]3745 {
[33004]3746 mpEntryPoints->VRDEAudioVolume(mhServer, left, right);
[3720]3747 }
[1]3748}
3749
[32718]3750void ConsoleVRDPServer::SendUSBRequest(uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const
[1]3751{
[4363]3752 if (mpEntryPoints && mhServer)
[3720]3753 {
[33004]3754 mpEntryPoints->VRDEUSBRequest(mhServer, u32ClientId, pvParms, cbParms);
[3720]3755 }
[1]3756}
3757
[34906]3758int ConsoleVRDPServer::SendAudioInputBegin(void **ppvUserCtx,
3759 void *pvContext,
3760 uint32_t cSamples,
3761 uint32_t iSampleHz,
3762 uint32_t cChannels,
3763 uint32_t cBits)
3764{
[53442]3765 if ( mhServer
3766 && mpEntryPoints && mpEntryPoints->VRDEAudioInOpen)
[34906]3767 {
3768 uint32_t u32ClientId = ASMAtomicReadU32(&mu32AudioInputClientId);
3769 if (u32ClientId != 0) /* 0 would mean broadcast to all clients. */
3770 {
3771 VRDEAUDIOFORMAT audioFormat = VRDE_AUDIO_FMT_MAKE(iSampleHz, cChannels, cBits, 0);
[53442]3772 mpEntryPoints->VRDEAudioInOpen(mhServer,
3773 pvContext,
3774 u32ClientId,
3775 audioFormat,
3776 cSamples);
3777 if (ppvUserCtx)
3778 *ppvUserCtx = NULL; /* This is the ConsoleVRDPServer context.
3779 * Currently not used because only one client is allowed to
3780 * do audio input and the client ID is saved by the ConsoleVRDPServer.
3781 */
[34906]3782 return VINF_SUCCESS;
3783 }
3784 }
[53442]3785
3786 /*
3787 * Not supported or no client connected.
3788 */
[34906]3789 return VERR_NOT_SUPPORTED;
3790}
3791
3792void ConsoleVRDPServer::SendAudioInputEnd(void *pvUserCtx)
3793{
[63240]3794 RT_NOREF(pvUserCtx);
[34906]3795 if (mpEntryPoints && mhServer && mpEntryPoints->VRDEAudioInClose)
3796 {
3797 uint32_t u32ClientId = ASMAtomicReadU32(&mu32AudioInputClientId);
3798 if (u32ClientId != 0) /* 0 would mean broadcast to all clients. */
3799 {
3800 mpEntryPoints->VRDEAudioInClose(mhServer, u32ClientId);
3801 }
3802 }
3803}
3804
[32718]3805void ConsoleVRDPServer::QueryInfo(uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const
[1]3806{
[33004]3807 if (index == VRDE_QI_PORT)
[3720]3808 {
[32718]3809 uint32_t cbOut = sizeof(int32_t);
[23643]3810
3811 if (cbBuffer >= cbOut)
3812 {
3813 *pcbOut = cbOut;
3814 *(int32_t *)pvBuffer = (int32_t)mVRDPBindPort;
3815 }
3816 }
3817 else if (mpEntryPoints && mhServer)
3818 {
[33004]3819 mpEntryPoints->VRDEQueryInfo(mhServer, index, pvBuffer, cbBuffer, pcbOut);
[3720]3820 }
[1]3821}
3822
[33386]3823/* static */ int ConsoleVRDPServer::loadVRDPLibrary(const char *pszLibraryName)
[1]3824{
3825 int rc = VINF_SUCCESS;
3826
[34244]3827 if (mVRDPLibrary == NIL_RTLDRMOD)
[1]3828 {
[35188]3829 RTERRINFOSTATIC ErrInfo;
3830 RTErrInfoInitStatic(&ErrInfo);
3831
[34244]3832 if (RTPathHavePath(pszLibraryName))
[35188]3833 rc = SUPR3HardenedLdrLoadPlugIn(pszLibraryName, &mVRDPLibrary, &ErrInfo.Core);
[34244]3834 else
[35191]3835 rc = SUPR3HardenedLdrLoadAppPriv(pszLibraryName, &mVRDPLibrary, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
[13835]3836 if (RT_SUCCESS(rc))
[1]3837 {
3838 struct SymbolEntry
3839 {
[2333]3840 const char *name;
[1]3841 void **ppfn;
3842 };
3843
3844 #define DEFSYMENTRY(a) { #a, (void**)&mpfn##a }
3845
[34244]3846 static const struct SymbolEntry s_aSymbols[] =
[1]3847 {
[33005]3848 DEFSYMENTRY(VRDECreateServer)
[3720]3849 };
[1]3850
3851 #undef DEFSYMENTRY
3852
[34244]3853 for (unsigned i = 0; i < RT_ELEMENTS(s_aSymbols); i++)
[1]3854 {
[34244]3855 rc = RTLdrGetSymbol(mVRDPLibrary, s_aSymbols[i].name, s_aSymbols[i].ppfn);
[1]3856
[13835]3857 if (RT_FAILURE(rc))
[1]3858 {
[34244]3859 LogRel(("VRDE: Error resolving symbol '%s', rc %Rrc.\n", s_aSymbols[i].name, rc));
[1]3860 break;
3861 }
3862 }
3863 }
3864 else
3865 {
[35188]3866 if (RTErrInfoIsSet(&ErrInfo.Core))
3867 LogRel(("VRDE: Error loading the library '%s': %s (%Rrc)\n", pszLibraryName, ErrInfo.Core.pszMsg, rc));
[34244]3868 else
[33386]3869 LogRel(("VRDE: Error loading the library '%s' rc = %Rrc.\n", pszLibraryName, rc));
3870
[34244]3871 mVRDPLibrary = NIL_RTLDRMOD;
[1]3872 }
3873 }
3874
[13835]3875 if (RT_FAILURE(rc))
[1]3876 {
[34244]3877 if (mVRDPLibrary != NIL_RTLDRMOD)
[1]3878 {
[32718]3879 RTLdrClose(mVRDPLibrary);
[34244]3880 mVRDPLibrary = NIL_RTLDRMOD;
[1]3881 }
3882 }
3883
[33386]3884 return rc;
[1]3885}
3886
3887/*
[33386]3888 * IVRDEServerInfo implementation.
[1]3889 */
3890// constructor / destructor
3891/////////////////////////////////////////////////////////////////////////////
3892
[33386]3893VRDEServerInfo::VRDEServerInfo()
[27608]3894 : mParent(NULL)
3895{
3896}
[13606]3897
[33386]3898VRDEServerInfo::~VRDEServerInfo()
[27608]3899{
3900}
3901
3902
[33386]3903HRESULT VRDEServerInfo::FinalConstruct()
[1]3904{
[35638]3905 return BaseFinalConstruct();
[1]3906}
3907
[33386]3908void VRDEServerInfo::FinalRelease()
[1]3909{
[32718]3910 uninit();
[35638]3911 BaseFinalRelease();
[1]3912}
3913
3914// public methods only for internal purposes
3915/////////////////////////////////////////////////////////////////////////////
3916
3917/**
3918 * Initializes the guest object.
3919 */
[33386]3920HRESULT VRDEServerInfo::init(Console *aParent)
[1]3921{
[21878]3922 LogFlowThisFunc(("aParent=%p\n", aParent));
[1]3923
[26235]3924 ComAssertRet(aParent, E_INVALIDARG);
[1]3925
[13606]3926 /* Enclose the state transition NotReady->InInit->Ready */
[21878]3927 AutoInitSpan autoInitSpan(this);
3928 AssertReturn(autoInitSpan.isOk(), E_FAIL);
[1]3929
[21878]3930 unconst(mParent) = aParent;
[1]3931
[15916]3932 /* Confirm a successful initialization */
3933 autoInitSpan.setSucceeded();
3934
[1]3935 return S_OK;
3936}
3937
3938/**
3939 * Uninitializes the instance and sets the ready flag to FALSE.
3940 * Called either from FinalRelease() or by the parent when it gets destroyed.
3941 */
[33386]3942void VRDEServerInfo::uninit()
[1]3943{
[21878]3944 LogFlowThisFunc(("\n"));
[1]3945
[13606]3946 /* Enclose the state transition Ready->InUninit->NotReady */
[21878]3947 AutoUninitSpan autoUninitSpan(this);
[13606]3948 if (autoUninitSpan.uninitDone())
3949 return;
[1]3950
[27607]3951 unconst(mParent) = NULL;
[1]3952}
3953
[33386]3954// IVRDEServerInfo properties
[1]3955/////////////////////////////////////////////////////////////////////////////
3956
3957#define IMPL_GETTER_BOOL(_aType, _aName, _aIndex) \
[52442]3958 HRESULT VRDEServerInfo::get##_aName(_aType *a##_aName) \
[1]3959 { \
[63563]3960 /** @todo Not sure if a AutoReadLock would be sufficient. */ \
[29385]3961 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
[13606]3962 \
[1]3963 uint32_t value; \
3964 uint32_t cbOut = 0; \
3965 \
[52442]3966 mParent->i_consoleVRDPServer()->QueryInfo \
[32718]3967 (_aIndex, &value, sizeof(value), &cbOut); \
[1]3968 \
3969 *a##_aName = cbOut? !!value: FALSE; \
3970 \
3971 return S_OK; \
[29385]3972 } \
3973 extern void IMPL_GETTER_BOOL_DUMMY(void)
[1]3974
[31747]3975#define IMPL_GETTER_SCALAR(_aType, _aName, _aIndex, _aValueMask) \
[52442]3976 HRESULT VRDEServerInfo::get##_aName(_aType *a##_aName) \
[1]3977 { \
[63563]3978 /** @todo Not sure if a AutoReadLock would be sufficient. */ \
[29385]3979 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
[13606]3980 \
[1]3981 _aType value; \
3982 uint32_t cbOut = 0; \
3983 \
[52442]3984 mParent->i_consoleVRDPServer()->QueryInfo \
[32718]3985 (_aIndex, &value, sizeof(value), &cbOut); \
[1]3986 \
[31747]3987 if (_aValueMask) value &= (_aValueMask); \
[1]3988 *a##_aName = cbOut? value: 0; \
3989 \
3990 return S_OK; \
[29385]3991 } \
3992 extern void IMPL_GETTER_SCALAR_DUMMY(void)
[1]3993
[52442]3994#define IMPL_GETTER_UTF8STR(_aType, _aName, _aIndex) \
3995 HRESULT VRDEServerInfo::get##_aName(_aType &a##_aName) \
[1]3996 { \
[63563]3997 /** @todo Not sure if a AutoReadLock would be sufficient. */ \
[29385]3998 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
[13606]3999 \
[1]4000 uint32_t cbOut = 0; \
4001 \
[52442]4002 mParent->i_consoleVRDPServer()->QueryInfo \
[1]4003 (_aIndex, NULL, 0, &cbOut); \
4004 \
4005 if (cbOut == 0) \
4006 { \
[52442]4007 a##_aName = Utf8Str::Empty; \
[1]4008 return S_OK; \
4009 } \
4010 \
[32718]4011 char *pchBuffer = (char *)RTMemTmpAlloc(cbOut); \
[1]4012 \
4013 if (!pchBuffer) \
4014 { \
[33386]4015 Log(("VRDEServerInfo::" \
[1]4016 #_aName \
4017 ": Failed to allocate memory %d bytes\n", cbOut)); \
4018 return E_OUTOFMEMORY; \
4019 } \
4020 \
[52442]4021 mParent->i_consoleVRDPServer()->QueryInfo \
[1]4022 (_aIndex, pchBuffer, cbOut, &cbOut); \
4023 \
[52442]4024 a##_aName = pchBuffer; \
[1]4025 \
[32718]4026 RTMemTmpFree(pchBuffer); \
[1]4027 \
4028 return S_OK; \
[29385]4029 } \
4030 extern void IMPL_GETTER_BSTR_DUMMY(void)
[1]4031
[33004]4032IMPL_GETTER_BOOL (BOOL, Active, VRDE_QI_ACTIVE);
4033IMPL_GETTER_SCALAR (LONG, Port, VRDE_QI_PORT, 0);
4034IMPL_GETTER_SCALAR (ULONG, NumberOfClients, VRDE_QI_NUMBER_OF_CLIENTS, 0);
4035IMPL_GETTER_SCALAR (LONG64, BeginTime, VRDE_QI_BEGIN_TIME, 0);
4036IMPL_GETTER_SCALAR (LONG64, EndTime, VRDE_QI_END_TIME, 0);
4037IMPL_GETTER_SCALAR (LONG64, BytesSent, VRDE_QI_BYTES_SENT, INT64_MAX);
4038IMPL_GETTER_SCALAR (LONG64, BytesSentTotal, VRDE_QI_BYTES_SENT_TOTAL, INT64_MAX);
4039IMPL_GETTER_SCALAR (LONG64, BytesReceived, VRDE_QI_BYTES_RECEIVED, INT64_MAX);
4040IMPL_GETTER_SCALAR (LONG64, BytesReceivedTotal, VRDE_QI_BYTES_RECEIVED_TOTAL, INT64_MAX);
[52442]4041IMPL_GETTER_UTF8STR(Utf8Str, User, VRDE_QI_USER);
4042IMPL_GETTER_UTF8STR(Utf8Str, Domain, VRDE_QI_DOMAIN);
4043IMPL_GETTER_UTF8STR(Utf8Str, ClientName, VRDE_QI_CLIENT_NAME);
4044IMPL_GETTER_UTF8STR(Utf8Str, ClientIP, VRDE_QI_CLIENT_IP);
[33004]4045IMPL_GETTER_SCALAR (ULONG, ClientVersion, VRDE_QI_CLIENT_VERSION, 0);
4046IMPL_GETTER_SCALAR (ULONG, EncryptionStyle, VRDE_QI_ENCRYPTION_STYLE, 0);
[1]4047
[52442]4048#undef IMPL_GETTER_UTF8STR
[1]4049#undef IMPL_GETTER_SCALAR
[29385]4050#undef IMPL_GETTER_BOOL
[14772]4051/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use