VirtualBox

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

Last change on this file since 100612 was 100612, checked in by vboxsync, 11 months ago

Shared Clipboard/Main: Made SHCLEXTPARMS a little more flexible (only was used by the VRDP console stuff before). bugref:9437

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

© 2023 Oracle
ContactPrivacy policyTerms of Use