VirtualBox

source: vbox/trunk/src/VBox/Main/ConsoleVRDPServer.cpp@ 4246

Last change on this file since 4246 was 4131, checked in by vboxsync, 17 years ago

Main/Frontends: Added missing IConsoleCallback notifications (onDVDDriveChange, onFloppyDriveChange, onNetworkAdapterChange, onSerialPortChange, onParallelPortChange, onVRDPServerChange, onUSBControllerChange, onSharedFolderChange) to track third party configuration requests in frontends.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 65.5 KB
Line 
1/** @file
2 *
3 * VBox Console VRDP Helper class
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "ConsoleVRDPServer.h"
19#include "ConsoleImpl.h"
20#include "DisplayImpl.h"
21#ifdef VRDP_NO_COM
22#include "KeyboardImpl.h"
23#include "MouseImpl.h"
24#include <VBox/VRDPOrders.h>
25#endif /* VRDP_NO_COM */
26
27#include "Logging.h"
28
29#include <iprt/asm.h>
30#include <iprt/ldr.h>
31
32#include <VBox/err.h>
33
34#ifdef VRDP_NO_COM
35class VRDPConsoleCallback : public IConsoleCallback
36{
37public:
38 VRDPConsoleCallback (ConsoleVRDPServer *server) :
39 m_server(server)
40 {
41#ifndef VBOX_WITH_XPCOM
42 refcnt = 0;
43#endif /* !VBOX_WITH_XPCOM */
44 }
45
46 virtual ~VRDPConsoleCallback() {}
47
48 NS_DECL_ISUPPORTS
49
50#ifndef VBOX_WITH_XPCOM
51 STDMETHOD_(ULONG, AddRef)() {
52 return ::InterlockedIncrement (&refcnt);
53 }
54 STDMETHOD_(ULONG, Release)()
55 {
56 long cnt = ::InterlockedDecrement (&refcnt);
57 if (cnt == 0)
58 delete this;
59 return cnt;
60 }
61 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
62 {
63 if (riid == IID_IUnknown) {
64 *ppObj = this;
65 AddRef();
66 return S_OK;
67 }
68 if (riid == IID_IConsoleCallback) {
69 *ppObj = this;
70 AddRef();
71 return S_OK;
72 }
73 *ppObj = NULL;
74 return E_NOINTERFACE;
75 }
76#endif /* !VBOX_WITH_XPCOM */
77
78
79 STDMETHOD(OnMousePointerShapeChange)(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
80 ULONG width, ULONG height, BYTE *shape);
81
82 STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL needsHostCursor)
83 {
84 if (m_server)
85 {
86 m_server->NotifyAbsoluteMouse(!!supportsAbsolute);
87 }
88 return S_OK;
89 }
90
91 STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
92 {
93 return S_OK;
94 }
95
96 STDMETHOD(OnStateChange)(MachineState_T machineState)
97 {
98 return S_OK;
99 }
100
101 STDMETHOD(OnAdditionsStateChange)()
102 {
103 return S_OK;
104 }
105
106 STDMETHOD(OnDVDDriveChange)()
107 {
108 return S_OK;
109 }
110
111 STDMETHOD(OnFloppyDriveChange)()
112 {
113 return S_OK;
114 }
115
116 STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
117 {
118 return S_OK;
119 }
120
121 STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
122 {
123 return S_OK;
124 }
125
126 STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
127 {
128 return S_OK;
129 }
130
131 STDMETHOD(OnVRDPServerChange)()
132 {
133 return S_OK;
134 }
135
136 STDMETHOD(OnUSBControllerChange)()
137 {
138 return S_OK;
139 }
140
141 STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *aDevice, BOOL aAttached,
142 IVirtualBoxErrorInfo *aError)
143 {
144 return S_OK;
145 }
146
147 STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
148 {
149 return S_OK;
150 }
151
152 STDMETHOD(OnRuntimeError)(BOOL fatal, INPTR BSTR id, INPTR BSTR message)
153 {
154 return S_OK;
155 }
156
157 STDMETHOD(OnCanShowWindow)(BOOL *canShow)
158 {
159 if (!canShow)
160 return E_POINTER;
161 /* we don't manage window activation here: always agree */
162 *canShow = TRUE;
163 return S_OK;
164 }
165
166 STDMETHOD(OnShowWindow) (ULONG64 *winId)
167 {
168 if (!winId)
169 return E_POINTER;
170 /* we don't manage window activation here */
171 *winId = 0;
172 return S_OK;
173 }
174
175private:
176 ConsoleVRDPServer *m_server;
177#ifndef VBOX_WITH_XPCOM
178 long refcnt;
179#endif /* !VBOX_WITH_XPCOM */
180};
181
182#ifdef VBOX_WITH_XPCOM
183#include <nsMemory.h>
184NS_DECL_CLASSINFO(VRDPConsoleCallback)
185NS_IMPL_ISUPPORTS1_CI(VRDPConsoleCallback, IConsoleCallback)
186#endif /* VBOX_WITH_XPCOM */
187
188#ifdef DEBUG_sunlover
189#define LOGDUMPPTR Log
190void dumpPointer (const uint8_t *pu8Shape, uint32_t width, uint32_t height, bool fXorMaskRGB32)
191{
192 unsigned i;
193
194 const uint8_t *pu8And = pu8Shape;
195
196 for (i = 0; i < height; i++)
197 {
198 unsigned j;
199 LOGDUMPPTR(("%p: ", pu8And));
200 for (j = 0; j < (width + 7) / 8; j++)
201 {
202 unsigned k;
203 for (k = 0; k < 8; k++)
204 {
205 LOGDUMPPTR(("%d", ((*pu8And) & (1 << (7 - k)))? 1: 0));
206 }
207
208 pu8And++;
209 }
210 LOGDUMPPTR(("\n"));
211 }
212
213 if (fXorMaskRGB32)
214 {
215 uint32_t *pu32Xor = (uint32_t *)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
216
217 for (i = 0; i < height; i++)
218 {
219 unsigned j;
220 LOGDUMPPTR(("%p: ", pu32Xor));
221 for (j = 0; j < width; j++)
222 {
223 LOGDUMPPTR(("%08X", *pu32Xor++));
224 }
225 LOGDUMPPTR(("\n"));
226 }
227 }
228 else
229 {
230 /* RDP 24 bit RGB mask. */
231 uint8_t *pu8Xor = (uint8_t *)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
232 for (i = 0; i < height; i++)
233 {
234 unsigned j;
235 LOGDUMPPTR(("%p: ", pu8Xor));
236 for (j = 0; j < width; j++)
237 {
238 LOGDUMPPTR(("%02X%02X%02X", pu8Xor[2], pu8Xor[1], pu8Xor[0]));
239 pu8Xor += 3;
240 }
241 LOGDUMPPTR(("\n"));
242 }
243 }
244}
245#else
246#define dumpPointer(a, b, c, d) do {} while (0)
247#endif /* DEBUG_sunlover */
248
249static void findTopLeftBorder (const uint8_t *pu8AndMask, const uint8_t *pu8XorMask, uint32_t width, uint32_t height, uint32_t *pxSkip, uint32_t *pySkip)
250{
251 /*
252 * Find the top border of the AND mask. First assign to special value.
253 */
254 uint32_t ySkipAnd = ~0;
255
256 const uint8_t *pu8And = pu8AndMask;
257 const uint32_t cbAndRow = (width + 7) / 8;
258 const uint8_t maskLastByte = (uint8_t)( 0xFF << (cbAndRow * 8 - width) );
259
260 Assert(cbAndRow > 0);
261
262 unsigned y;
263 unsigned x;
264
265 for (y = 0; y < height && ySkipAnd == ~(uint32_t)0; y++, pu8And += cbAndRow)
266 {
267 /* For each complete byte in the row. */
268 for (x = 0; x < cbAndRow - 1; x++)
269 {
270 if (pu8And[x] != 0xFF)
271 {
272 ySkipAnd = y;
273 break;
274 }
275 }
276
277 if (ySkipAnd == ~(uint32_t)0)
278 {
279 /* Last byte. */
280 if ((pu8And[cbAndRow - 1] & maskLastByte) != maskLastByte)
281 {
282 ySkipAnd = y;
283 }
284 }
285 }
286
287 if (ySkipAnd == ~(uint32_t)0)
288 {
289 ySkipAnd = 0;
290 }
291
292 /*
293 * Find the left border of the AND mask.
294 */
295 uint32_t xSkipAnd = ~0;
296
297 /* For all bit columns. */
298 for (x = 0; x < width && xSkipAnd == ~(uint32_t)0; x++)
299 {
300 pu8And = pu8AndMask + x/8; /* Currently checking byte. */
301 uint8_t mask = 1 << (7 - x%8); /* Currently checking bit in the byte. */
302
303 for (y = ySkipAnd; y < height; y++, pu8And += cbAndRow)
304 {
305 if ((*pu8And & mask) == 0)
306 {
307 xSkipAnd = x;
308 break;
309 }
310 }
311 }
312
313 if (xSkipAnd == ~(uint32_t)0)
314 {
315 xSkipAnd = 0;
316 }
317
318 /*
319 * Find the XOR mask top border.
320 */
321 uint32_t ySkipXor = ~0;
322
323 uint32_t *pu32XorStart = (uint32_t *)pu8XorMask;
324
325 uint32_t *pu32Xor = pu32XorStart;
326
327 for (y = 0; y < height && ySkipXor == ~(uint32_t)0; y++, pu32Xor += width)
328 {
329 for (x = 0; x < width; x++)
330 {
331 if (pu32Xor[x] != 0)
332 {
333 ySkipXor = y;
334 break;
335 }
336 }
337 }
338
339 if (ySkipXor == ~(uint32_t)0)
340 {
341 ySkipXor = 0;
342 }
343
344 /*
345 * Find the left border of the XOR mask.
346 */
347 uint32_t xSkipXor = ~(uint32_t)0;
348
349 /* For all columns. */
350 for (x = 0; x < width && xSkipXor == ~(uint32_t)0; x++)
351 {
352 pu32Xor = pu32XorStart + x; /* Currently checking dword. */
353
354 for (y = ySkipXor; y < height; y++, pu32Xor += width)
355 {
356 if (*pu32Xor != 0)
357 {
358 xSkipXor = x;
359 break;
360 }
361 }
362 }
363
364 if (xSkipXor == ~(uint32_t)0)
365 {
366 xSkipXor = 0;
367 }
368
369 *pxSkip = RT_MIN (xSkipAnd, xSkipXor);
370 *pySkip = RT_MIN (ySkipAnd, ySkipXor);
371}
372
373/* Generate an AND mask for alpha pointers here, because
374 * guest driver does not do that correctly for Vista pointers.
375 * Similar fix, changing the alpha threshold, could be applied
376 * for the guest driver, but then additions reinstall would be
377 * necessary, which we try to avoid.
378 */
379static void mousePointerGenerateANDMask (uint8_t *pu8DstAndMask, int cbDstAndMask, const uint8_t *pu8SrcAlpha, int w, int h)
380{
381 memset (pu8DstAndMask, 0xFF, cbDstAndMask);
382
383 int y;
384 for (y = 0; y < h; y++)
385 {
386 uint8_t bitmask = 0x80;
387
388 int x;
389 for (x = 0; x < w; x++, bitmask >>= 1)
390 {
391 if (bitmask == 0)
392 {
393 bitmask = 0x80;
394 }
395
396 /* Whether alpha channel value is not transparent enough for the pixel to be seen. */
397 if (pu8SrcAlpha[x * 4 + 3] > 0x7f)
398 {
399 pu8DstAndMask[x / 8] &= ~bitmask;
400 }
401 }
402
403 /* Point to next source and dest scans. */
404 pu8SrcAlpha += w * 4;
405 pu8DstAndMask += (w + 7) / 8;
406 }
407}
408
409STDMETHODIMP VRDPConsoleCallback::OnMousePointerShapeChange (BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
410 ULONG width, ULONG height, BYTE *shape)
411{
412 LogSunlover(("VRDPConsoleCallback::OnMousePointerShapeChange: %d, %d, %dx%d, @%d,%d\n", visible, alpha, width, height, xHot, yHot));
413
414 if (m_server)
415 {
416 if (!shape)
417 {
418 if (!visible)
419 {
420 m_server->MousePointerHide ();
421 }
422 }
423 else if (width != 0 && height != 0)
424 {
425 /* Pointer consists of 1 bpp AND and 24 BPP XOR masks.
426 * 'shape' AND mask followed by XOR mask.
427 * XOR mask contains 32 bit (lsb)BGR0(msb) values.
428 *
429 * We convert this to RDP color format which consist of
430 * one bpp AND mask and 24 BPP (BGR) color XOR image.
431 *
432 * RDP clients expect 8 aligned width and height of
433 * pointer (preferably 32x32).
434 *
435 * They even contain bugs which do not appear for
436 * 32x32 pointers but would appear for a 41x32 one.
437 *
438 * So set pointer size to 32x32. This can be done safely
439 * because most pointers are 32x32.
440 */
441
442 dumpPointer (shape, width, height, true);
443
444 int cbDstAndMask = (((width + 7) / 8) * height + 3) & ~3;
445
446 uint8_t *pu8AndMask = shape;
447 uint8_t *pu8XorMask = shape + cbDstAndMask;
448
449 if (alpha)
450 {
451 pu8AndMask = (uint8_t *)alloca (cbDstAndMask);
452
453 mousePointerGenerateANDMask (pu8AndMask, cbDstAndMask, pu8XorMask, width, height);
454 }
455
456 /* Windows guest alpha pointers are wider than 32 pixels.
457 * Try to find out the top-left border of the pointer and
458 * then copy only meaningful bits. All complete top rows
459 * and all complete left columns where (AND == 1 && XOR == 0)
460 * are skipped. Hot spot is adjusted.
461 */
462 uint32_t ySkip = 0; /* How many rows to skip at the top. */
463 uint32_t xSkip = 0; /* How many columns to skip at the left. */
464
465 findTopLeftBorder (pu8AndMask, pu8XorMask, width, height, &xSkip, &ySkip);
466
467 /* Must not skip the hot spot. */
468 xSkip = RT_MIN (xSkip, xHot);
469 ySkip = RT_MIN (ySkip, yHot);
470
471 /*
472 * Compute size and allocate memory for the pointer.
473 */
474 const uint32_t dstwidth = 32;
475 const uint32_t dstheight = 32;
476
477 VRDPCOLORPOINTER *pointer = NULL;
478
479 uint32_t dstmaskwidth = (dstwidth + 7) / 8;
480
481 uint32_t rdpmaskwidth = dstmaskwidth;
482 uint32_t rdpmasklen = dstheight * rdpmaskwidth;
483
484 uint32_t rdpdatawidth = dstwidth * 3;
485 uint32_t rdpdatalen = dstheight * rdpdatawidth;
486
487 pointer = (VRDPCOLORPOINTER *)RTMemTmpAlloc (sizeof (VRDPCOLORPOINTER) + rdpmasklen + rdpdatalen);
488
489 if (pointer)
490 {
491 uint8_t *maskarray = (uint8_t *)pointer + sizeof (VRDPCOLORPOINTER);
492 uint8_t *dataarray = maskarray + rdpmasklen;
493
494 memset (maskarray, 0xFF, rdpmasklen);
495 memset (dataarray, 0x00, rdpdatalen);
496
497 uint32_t srcmaskwidth = (width + 7) / 8;
498 uint32_t srcdatawidth = width * 4;
499
500 /* Copy AND mask. */
501 uint8_t *src = pu8AndMask + ySkip * srcmaskwidth;
502 uint8_t *dst = maskarray + (dstheight - 1) * rdpmaskwidth;
503
504 uint32_t minheight = RT_MIN (height - ySkip, dstheight);
505 uint32_t minwidth = RT_MIN (width - xSkip, dstwidth);
506
507 unsigned x, y;
508
509 for (y = 0; y < minheight; y++)
510 {
511 for (x = 0; x < minwidth; x++)
512 {
513 uint32_t byteIndex = (x + xSkip) / 8;
514 uint32_t bitIndex = (x + xSkip) % 8;
515
516 bool bit = (src[byteIndex] & (1 << (7 - bitIndex))) != 0;
517
518 if (!bit)
519 {
520 byteIndex = x / 8;
521 bitIndex = x % 8;
522
523 dst[byteIndex] &= ~(1 << (7 - bitIndex));
524 }
525 }
526
527 src += srcmaskwidth;
528 dst -= rdpmaskwidth;
529 }
530
531 /* Point src to XOR mask */
532 src = pu8XorMask + ySkip * srcdatawidth;
533 dst = dataarray + (dstheight - 1) * rdpdatawidth;
534
535 for (y = 0; y < minheight ; y++)
536 {
537 for (x = 0; x < minwidth; x++)
538 {
539 memcpy (dst + x * 3, &src[4 * (x + xSkip)], 3);
540 }
541
542 src += srcdatawidth;
543 dst -= rdpdatawidth;
544 }
545
546 pointer->u16HotX = (uint16_t)(xHot - xSkip);
547 pointer->u16HotY = (uint16_t)(yHot - ySkip);
548
549 pointer->u16Width = (uint16_t)dstwidth;
550 pointer->u16Height = (uint16_t)dstheight;
551
552 pointer->u16MaskLen = (uint16_t)rdpmasklen;
553 pointer->u16DataLen = (uint16_t)rdpdatalen;
554
555 dumpPointer ((uint8_t *)pointer + sizeof (*pointer), dstwidth, dstheight, false);
556
557 m_server->MousePointerUpdate (pointer);
558
559 RTMemTmpFree (pointer);
560 }
561 }
562 }
563
564 return S_OK;
565}
566#endif /* VRDP_NO_COM */
567
568
569// ConsoleVRDPServer
570////////////////////////////////////////////////////////////////////////////////
571
572#ifdef VBOX_VRDP
573RTLDRMOD ConsoleVRDPServer::mVRDPLibrary;
574
575#ifdef VRDP_NO_COM
576PFNVRDPCREATESERVER ConsoleVRDPServer::mpfnVRDPCreateServer = NULL;
577
578VRDPENTRYPOINTS_1 *ConsoleVRDPServer::mpEntryPoints = NULL;
579
580VRDPCALLBACKS_1 ConsoleVRDPServer::mCallbacks =
581{
582 { VRDP_INTERFACE_VERSION_1, sizeof (VRDPCALLBACKS_1) },
583 ConsoleVRDPServer::VRDPCallbackQueryProperty,
584 ConsoleVRDPServer::VRDPCallbackClientLogon,
585 ConsoleVRDPServer::VRDPCallbackClientConnect,
586 ConsoleVRDPServer::VRDPCallbackClientDisconnect,
587 ConsoleVRDPServer::VRDPCallbackIntercept,
588 ConsoleVRDPServer::VRDPCallbackUSB,
589 ConsoleVRDPServer::VRDPCallbackClipboard,
590 ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
591 ConsoleVRDPServer::VRDPCallbackFramebufferLock,
592 ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
593 ConsoleVRDPServer::VRDPCallbackInput,
594 ConsoleVRDPServer::VRDPCallbackVideoModeHint
595};
596#else
597int (VBOXCALL *ConsoleVRDPServer::mpfnVRDPStartServer) (IConsole *pConsole, IVRDPServer *pVRDPServer, HVRDPSERVER *phServer);
598int (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSetFramebuffer) (HVRDPSERVER hServer, IFramebuffer *pFramebuffer, uint32_t fFlags);
599void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSetCallback) (HVRDPSERVER hServer, VRDPSERVERCALLBACK *pcallback, void *pvUser);
600void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPShutdownServer) (HVRDPSERVER hServer);
601void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendUpdateBitmap)(HVRDPSERVER hServer, unsigned uScreenId, unsigned x, unsigned y, unsigned w, unsigned h);
602void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendResize) (HVRDPSERVER hServer);
603void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendAudioSamples)(HVRDPSERVER hserver, void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format);
604void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendAudioVolume) (HVRDPSERVER hserver, uint16_t left, uint16_t right);
605void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendUSBRequest) (HVRDPSERVER hserver, uint32_t u32ClientId, void *pvParms, uint32_t cbParms);
606void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendUpdate) (HVRDPSERVER hServer, unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate);
607void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPQueryInfo) (HVRDPSERVER hserver, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
608void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPClipboard) (HVRDPSERVER hserver, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData, uint32_t *pcbActualRead);
609#endif /* VRDP_NO_COM */
610#endif /* VBOX_VRDP */
611
612#ifdef VRDP_NO_COM
613DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut)
614{
615 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
616
617 int rc = VERR_NOT_SUPPORTED;
618
619 switch (index)
620 {
621 case VRDP_QP_NETWORK_PORT:
622 {
623 ULONG port = 0;
624 server->mConsole->getVRDPServer ()->COMGETTER(Port) (&port);
625 if (port == 0)
626 {
627 port = VRDP_DEFAULT_PORT;
628 }
629
630 if (cbBuffer >= sizeof (uint32_t))
631 {
632 *(uint32_t *)pvBuffer = (uint32_t)port;
633 rc = VINF_SUCCESS;
634 }
635 else
636 {
637 rc = VINF_BUFFER_OVERFLOW;
638 }
639
640 *pcbOut = sizeof (uint32_t);
641 } break;
642
643 case VRDP_QP_NETWORK_ADDRESS:
644 {
645 com::Bstr address;
646 server->mConsole->getVRDPServer ()->COMGETTER(NetAddress) (address.asOutParam());
647
648 if (cbBuffer >= address.length ())
649 {
650 if (address.length () > 0)
651 {
652 memcpy (pvBuffer, address.raw(), address.length ());
653 }
654 rc = VINF_SUCCESS;
655 }
656
657 *pcbOut = address.length ();
658 } break;
659
660 case VRDP_QP_NUMBER_MONITORS:
661 {
662 ULONG cMonitors = 1;
663
664 server->mConsole->machine ()->COMGETTER(MonitorCount)(&cMonitors);
665
666 if (cbBuffer >= sizeof (uint32_t))
667 {
668 *(uint32_t *)pvBuffer = (uint32_t)cMonitors;
669 rc = VINF_SUCCESS;
670 }
671 else
672 {
673 rc = VINF_BUFFER_OVERFLOW;
674 }
675
676 *pcbOut = sizeof (uint32_t);
677 } break;
678
679 default:
680 break;
681 }
682
683 return rc;
684}
685
686DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain)
687{
688 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
689
690 return server->mConsole->VRDPClientLogon (u32ClientId, pszUser, pszPassword, pszDomain);
691}
692
693DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId)
694{
695 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
696
697 server->mConsole->VRDPClientConnect (u32ClientId);
698}
699
700DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted)
701{
702 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
703
704 server->mConsole->VRDPClientDisconnect (u32ClientId, fu32Intercepted);
705}
706
707DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept)
708{
709 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
710
711 int rc = VERR_NOT_SUPPORTED;
712
713 switch (fu32Intercept)
714 {
715 case VRDP_CLIENT_INTERCEPT_AUDIO:
716 {
717 server->mConsole->VRDPInterceptAudio (u32ClientId);
718 rc = VINF_SUCCESS;
719 } break;
720
721 case VRDP_CLIENT_INTERCEPT_USB:
722 {
723 server->mConsole->VRDPInterceptUSB (u32ClientId);
724 rc = VINF_SUCCESS;
725 } break;
726
727 case VRDP_CLIENT_INTERCEPT_CLIPBOARD:
728 {
729 server->mConsole->VRDPInterceptClipboard (u32ClientId);
730 rc = VINF_SUCCESS;
731 } break;
732
733 default:
734 break;
735 }
736
737 if (VBOX_SUCCESS (rc))
738 {
739 if (ppvIntercept)
740 {
741 *ppvIntercept = server;
742 }
743 }
744
745 return rc;
746}
747
748DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet)
749{
750 return USBClientResponseCallback (pvIntercept, u32ClientId, u8Code, pvRet, cbRet);
751}
752
753DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData)
754{
755 return ClipboardCallback (pvIntercept, u32ClientId, u32Function, u32Format, pvData, cbData);
756}
757
758DECLCALLBACK(bool) ConsoleVRDPServer::VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDPFRAMEBUFFERINFO *pInfo)
759{
760 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
761
762 bool fAvailable = false;
763
764 IFramebuffer *pfb = NULL;
765 LONG xOrigin = 0;
766 LONG yOrigin = 0;
767
768 server->mConsole->getDisplay ()->GetFramebuffer (uScreenId, &pfb, &xOrigin, &yOrigin);
769
770 if (pfb)
771 {
772 pfb->Lock ();
773
774 /* Query framebuffer parameters. */
775 ULONG lineSize = 0;
776 pfb->COMGETTER(BytesPerLine) (&lineSize);
777
778 ULONG bitsPerPixel = 0;
779 pfb->COMGETTER(BitsPerPixel) (&bitsPerPixel);
780
781 BYTE *address = NULL;
782 pfb->COMGETTER(Address) (&address);
783
784 ULONG height = 0;
785 pfb->COMGETTER(Height) (&height);
786
787 ULONG width = 0;
788 pfb->COMGETTER(Width) (&width);
789
790 /* Now fill the information as requested by the caller. */
791 pInfo->pu8Bits = address;
792 pInfo->xOrigin = xOrigin;
793 pInfo->yOrigin = yOrigin;
794 pInfo->cWidth = width;
795 pInfo->cHeight = height;
796 pInfo->cBitsPerPixel = bitsPerPixel;
797 pInfo->cbLine = lineSize;
798
799 pfb->Unlock ();
800
801 fAvailable = true;
802 }
803
804 if (server->maFramebuffers[uScreenId])
805 {
806 server->maFramebuffers[uScreenId]->Release ();
807 }
808 server->maFramebuffers[uScreenId] = pfb;
809
810 return fAvailable;
811}
812
813DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId)
814{
815 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
816
817 if (server->maFramebuffers[uScreenId])
818 {
819 server->maFramebuffers[uScreenId]->Lock ();
820 }
821}
822
823DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId)
824{
825 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
826
827 if (server->maFramebuffers[uScreenId])
828 {
829 server->maFramebuffers[uScreenId]->Unlock ();
830 }
831}
832
833DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput)
834{
835 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
836 Console *pConsole = server->mConsole;
837
838 switch (type)
839 {
840 case VRDP_INPUT_SCANCODE:
841 {
842 if (cbInput == sizeof (VRDPINPUTSCANCODE))
843 {
844 const VRDPINPUTSCANCODE *pInputScancode = (VRDPINPUTSCANCODE *)pvInput;
845 pConsole->getKeyboard ()->PutScancode((LONG)pInputScancode->uScancode);
846 }
847 } break;
848
849 case VRDP_INPUT_POINT:
850 {
851 if (cbInput == sizeof (VRDPINPUTPOINT))
852 {
853 const VRDPINPUTPOINT *pInputPoint = (VRDPINPUTPOINT *)pvInput;
854
855 int mouseButtons = 0;
856 int iWheel = 0;
857
858 if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON1)
859 {
860 mouseButtons |= MouseButtonState_LeftButton;
861 }
862 if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON2)
863 {
864 mouseButtons |= MouseButtonState_RightButton;
865 }
866 if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON3)
867 {
868 mouseButtons |= MouseButtonState_MiddleButton;
869 }
870 if (pInputPoint->uButtons & VRDP_INPUT_POINT_WHEEL_UP)
871 {
872 mouseButtons |= MouseButtonState_WheelUp;
873 iWheel = -1;
874 }
875 if (pInputPoint->uButtons & VRDP_INPUT_POINT_WHEEL_DOWN)
876 {
877 mouseButtons |= MouseButtonState_WheelDown;
878 iWheel = 1;
879 }
880
881 if (server->m_fGuestWantsAbsolute)
882 {
883 pConsole->getMouse()->PutMouseEventAbsolute (pInputPoint->x + 1, pInputPoint->y + 1, iWheel, mouseButtons);
884 } else
885 {
886 pConsole->getMouse()->PutMouseEvent (pInputPoint->x - server->m_mousex,
887 pInputPoint->y - server->m_mousey,
888 iWheel, mouseButtons);
889 server->m_mousex = pInputPoint->x;
890 server->m_mousey = pInputPoint->y;
891 }
892 }
893 } break;
894
895 case VRDP_INPUT_CAD:
896 {
897 pConsole->getKeyboard ()->PutCAD();
898 } break;
899
900 case VRDP_INPUT_RESET:
901 {
902 pConsole->Reset();
903 } break;
904
905 default:
906 break;
907 }
908}
909
910DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId)
911{
912 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
913
914 server->mConsole->getDisplay ()->SetVideoModeHint(cWidth, cHeight, cBitsPerPixel, uScreenId);
915}
916#endif /* VRDP_NO_COM */
917
918ConsoleVRDPServer::ConsoleVRDPServer (Console *console)
919{
920 mConsole = console;
921
922 int rc = RTCritSectInit (&mCritSect);
923 AssertRC (rc);
924
925 mcClipboardRefs = 0;
926 mpfnClipboardCallback = NULL;
927
928#ifdef VBOX_WITH_USB
929 mUSBBackends.pHead = NULL;
930 mUSBBackends.pTail = NULL;
931
932 mUSBBackends.thread = NIL_RTTHREAD;
933 mUSBBackends.fThreadRunning = false;
934 mUSBBackends.event = 0;
935#endif
936
937#ifdef VBOX_VRDP
938 mhServer = 0;
939
940#ifdef VRDP_NO_COM
941 m_fGuestWantsAbsolute = false;
942 m_mousex = 0;
943 m_mousey = 0;
944
945 memset (maFramebuffers, 0, sizeof (maFramebuffers));
946
947 mConsoleCallback = new VRDPConsoleCallback(this);
948 mConsoleCallback->AddRef();
949 console->RegisterCallback(mConsoleCallback);
950#endif /* VRDP_NO_COM */
951#endif /* VBOX_VRDP */
952
953 mAuthLibrary = 0;
954}
955
956ConsoleVRDPServer::~ConsoleVRDPServer ()
957{
958 Stop ();
959
960#ifdef VRDP_NO_COM
961 if (mConsoleCallback)
962 {
963 mConsole->UnregisterCallback(mConsoleCallback);
964 mConsoleCallback->Release();
965 mConsoleCallback = NULL;
966 }
967
968 unsigned i;
969 for (i = 0; i < ELEMENTS(maFramebuffers); i++)
970 {
971 if (maFramebuffers[i])
972 {
973 maFramebuffers[i]->Release ();
974 maFramebuffers[i] = NULL;
975 }
976 }
977#endif /* VRDP_NO_COM */
978 if (RTCritSectIsInitialized (&mCritSect))
979 {
980 RTCritSectDelete (&mCritSect);
981 memset (&mCritSect, 0, sizeof (mCritSect));
982 }
983}
984
985int ConsoleVRDPServer::Launch (void)
986{
987 LogFlowMember(("ConsoleVRDPServer::Launch\n"));
988#ifdef VBOX_VRDP
989 int rc = VINF_SUCCESS;
990 IVRDPServer *vrdpserver = mConsole->getVRDPServer ();
991 Assert(vrdpserver);
992 BOOL vrdpEnabled = FALSE;
993
994 HRESULT rc2 = vrdpserver->COMGETTER(Enabled) (&vrdpEnabled);
995 AssertComRC(rc2);
996
997 if (SUCCEEDED (rc2)
998 && vrdpEnabled
999 && loadVRDPLibrary ())
1000 {
1001#ifdef VRDP_NO_COM
1002 rc = mpfnVRDPCreateServer (&mCallbacks.header, this, (VRDPINTERFACEHDR **)&mpEntryPoints, &mhServer);
1003#else
1004 rc = mpfnVRDPStartServer(mConsole, vrdpserver, &mhServer);
1005#endif /* VRDP_NO_COM */
1006
1007 if (VBOX_SUCCESS(rc))
1008 {
1009#ifdef VBOX_WITH_USB
1010 remoteUSBThreadStart ();
1011#endif /* VBOX_WITH_USB */
1012 }
1013 else
1014 AssertMsgFailed(("Could not start VRDP server: rc = %Vrc\n", rc));
1015 }
1016#else
1017 int rc = VERR_NOT_SUPPORTED;
1018#endif /* VBOX_VRDP */
1019 return rc;
1020}
1021
1022#ifdef VRDP_NO_COM
1023void ConsoleVRDPServer::EnableConnections (void)
1024{
1025#ifdef VBOX_VRDP
1026 if (mpEntryPoints)
1027 {
1028 mpEntryPoints->VRDPEnableConnections (mhServer, true);
1029 }
1030#endif /* VBOX_VRDP */
1031}
1032
1033void ConsoleVRDPServer::MousePointerUpdate (const VRDPCOLORPOINTER *pPointer)
1034{
1035#ifdef VBOX_VRDP
1036 if (mpEntryPoints)
1037 {
1038 mpEntryPoints->VRDPColorPointer (mhServer, pPointer);
1039 }
1040#endif /* VBOX_VRDP */
1041}
1042
1043void ConsoleVRDPServer::MousePointerHide (void)
1044{
1045#ifdef VBOX_VRDP
1046 if (mpEntryPoints)
1047 {
1048 mpEntryPoints->VRDPHidePointer (mhServer);
1049 }
1050#endif /* VBOX_VRDP */
1051}
1052#else
1053void ConsoleVRDPServer::SetCallback (void)
1054{
1055#ifdef VBOX_VRDP
1056 /* This is called after VM is created and allows the server to accept client connection. */
1057 if (mhServer && mpfnVRDPSetCallback)
1058 {
1059 mpfnVRDPSetCallback (mhServer, mConsole->getVrdpServerCallback (), mConsole);
1060 }
1061#endif /* VBOX_VRDP */
1062}
1063#endif /* VRDP_NO_COM */
1064
1065void ConsoleVRDPServer::Stop (void)
1066{
1067 Assert(VALID_PTR(this)); /** @todo r=bird: there are(/was) some odd cases where this buster was invalid on
1068 * linux. Just remove this when it's 100% sure that problem has been fixed. */
1069#ifdef VBOX_VRDP
1070 if (mhServer)
1071 {
1072#ifdef VRDP_NO_COM
1073#else
1074 HVRDPSERVER hServer = mhServer;
1075#endif /* VRDP_NO_COM */
1076
1077 /* Reset the handle to avoid further calls to the server. */
1078 mhServer = 0;
1079
1080#ifdef VRDP_NO_COM
1081 if (mpEntryPoints)
1082 {
1083 mpEntryPoints->VRDPDestroy (mhServer);
1084 }
1085#else
1086 mpfnVRDPShutdownServer (hServer);
1087#endif /* VRDP_NO_COM */
1088 }
1089#endif /* VBOX_VRDP */
1090
1091#ifdef VBOX_WITH_USB
1092 remoteUSBThreadStop ();
1093#endif /* VBOX_WITH_USB */
1094
1095 mpfnAuthEntry = NULL;
1096 mpfnAuthEntry2 = NULL;
1097
1098 if (mAuthLibrary)
1099 {
1100 RTLdrClose(mAuthLibrary);
1101 mAuthLibrary = 0;
1102 }
1103}
1104
1105/* Worker thread for Remote USB. The thread polls the clients for
1106 * the list of attached USB devices.
1107 * The thread is also responsible for attaching/detaching devices
1108 * to/from the VM.
1109 *
1110 * It is expected that attaching/detaching is not a frequent operation.
1111 *
1112 * The thread is always running when the VRDP server is active.
1113 *
1114 * The thread scans backends and requests the device list every 2 seconds.
1115 *
1116 * When device list is available, the thread calls the Console to process it.
1117 *
1118 */
1119#define VRDP_DEVICE_LIST_PERIOD_MS (2000)
1120
1121#ifdef VBOX_WITH_USB
1122static DECLCALLBACK(int) threadRemoteUSB (RTTHREAD self, void *pvUser)
1123{
1124 ConsoleVRDPServer *pOwner = (ConsoleVRDPServer *)pvUser;
1125
1126 LogFlow(("Console::threadRemoteUSB: start. owner = %p.\n", pOwner));
1127
1128 pOwner->notifyRemoteUSBThreadRunning (self);
1129
1130 while (pOwner->isRemoteUSBThreadRunning ())
1131 {
1132 RemoteUSBBackend *pRemoteUSBBackend = NULL;
1133
1134 while ((pRemoteUSBBackend = pOwner->usbBackendGetNext (pRemoteUSBBackend)) != NULL)
1135 {
1136 pRemoteUSBBackend->PollRemoteDevices ();
1137 }
1138
1139 pOwner->waitRemoteUSBThreadEvent (VRDP_DEVICE_LIST_PERIOD_MS);
1140
1141 LogFlow(("Console::threadRemoteUSB: iteration. owner = %p.\n", pOwner));
1142 }
1143
1144 return VINF_SUCCESS;
1145}
1146
1147void ConsoleVRDPServer::notifyRemoteUSBThreadRunning (RTTHREAD thread)
1148{
1149 mUSBBackends.thread = thread;
1150 mUSBBackends.fThreadRunning = true;
1151 int rc = RTThreadUserSignal (thread);
1152 AssertRC (rc);
1153}
1154
1155bool ConsoleVRDPServer::isRemoteUSBThreadRunning (void)
1156{
1157 return mUSBBackends.fThreadRunning;
1158}
1159
1160void ConsoleVRDPServer::waitRemoteUSBThreadEvent (unsigned cMillies)
1161{
1162 int rc = RTSemEventWait (mUSBBackends.event, cMillies);
1163 Assert (VBOX_SUCCESS(rc) || rc == VERR_TIMEOUT);
1164 NOREF(rc);
1165}
1166
1167void ConsoleVRDPServer::remoteUSBThreadStart (void)
1168{
1169 int rc = RTSemEventCreate (&mUSBBackends.event);
1170
1171 if (VBOX_FAILURE (rc))
1172 {
1173 AssertFailed ();
1174 mUSBBackends.event = 0;
1175 }
1176
1177 if (VBOX_SUCCESS (rc))
1178 {
1179 rc = RTThreadCreate (&mUSBBackends.thread, threadRemoteUSB, this, 65536,
1180 RTTHREADTYPE_VRDP_IO, RTTHREADFLAGS_WAITABLE, "remote usb");
1181 }
1182
1183 if (VBOX_FAILURE (rc))
1184 {
1185 LogRel(("Warning: could not start the remote USB thread, rc = %Vrc!!!\n", rc));
1186 mUSBBackends.thread = NIL_RTTHREAD;
1187 }
1188 else
1189 {
1190 /* Wait until the thread is ready. */
1191 rc = RTThreadUserWait (mUSBBackends.thread, 60000);
1192 AssertRC (rc);
1193 Assert (mUSBBackends.fThreadRunning || VBOX_FAILURE (rc));
1194 }
1195}
1196
1197void ConsoleVRDPServer::remoteUSBThreadStop (void)
1198{
1199 mUSBBackends.fThreadRunning = false;
1200
1201 if (mUSBBackends.thread != NIL_RTTHREAD)
1202 {
1203 Assert (mUSBBackends.event != 0);
1204
1205 RTSemEventSignal (mUSBBackends.event);
1206
1207 int rc = RTThreadWait (mUSBBackends.thread, 60000, NULL);
1208 AssertRC (rc);
1209
1210 mUSBBackends.thread = NIL_RTTHREAD;
1211 }
1212
1213 if (mUSBBackends.event)
1214 {
1215 RTSemEventDestroy (mUSBBackends.event);
1216 mUSBBackends.event = 0;
1217 }
1218}
1219#endif /* VBOX_WITH_USB */
1220
1221VRDPAuthResult ConsoleVRDPServer::Authenticate (const Guid &uuid, VRDPAuthGuestJudgement guestJudgement,
1222 const char *pszUser, const char *pszPassword, const char *pszDomain,
1223 uint32_t u32ClientId)
1224{
1225 VRDPAUTHUUID rawuuid;
1226
1227 memcpy (rawuuid, ((Guid &)uuid).ptr (), sizeof (rawuuid));
1228
1229 LogFlow(("ConsoleVRDPServer::Authenticate: uuid = %Vuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n",
1230 rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId));
1231
1232 /*
1233 * Called only from VRDP input thread. So thread safety is not required.
1234 */
1235
1236 if (!mAuthLibrary)
1237 {
1238 /* Load the external authentication library. */
1239
1240 ComPtr<IMachine> machine;
1241 mConsole->COMGETTER(Machine)(machine.asOutParam());
1242
1243 ComPtr<IVirtualBox> virtualBox;
1244 machine->COMGETTER(Parent)(virtualBox.asOutParam());
1245
1246 ComPtr<ISystemProperties> systemProperties;
1247 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
1248
1249 Bstr authLibrary;
1250 systemProperties->COMGETTER(RemoteDisplayAuthLibrary)(authLibrary.asOutParam());
1251
1252 Utf8Str filename = authLibrary;
1253
1254 LogRel(("VRDPAUTH: ConsoleVRDPServer::Authenticate: loading external authentication library '%ls'\n", authLibrary.raw()));
1255
1256 int rc = RTLdrLoad (filename.raw(), &mAuthLibrary);
1257 if (VBOX_FAILURE (rc))
1258 LogRel(("VRDPAUTH: Failed to load external authentication library. Error code: %Vrc\n", rc));
1259
1260 if (VBOX_SUCCESS (rc))
1261 {
1262 /* Get the entry point. */
1263 mpfnAuthEntry2 = NULL;
1264 int rc2 = RTLdrGetSymbol(mAuthLibrary, "VRDPAuth2", (void**)&mpfnAuthEntry2);
1265 if (VBOX_FAILURE (rc2))
1266 {
1267 LogRel(("VRDPAUTH: Could not resolve import '%s'. Error code: %Vrc\n", "VRDPAuth2", rc2));
1268 rc = rc2;
1269 }
1270
1271 /* Get the entry point. */
1272 mpfnAuthEntry = NULL;
1273 rc2 = RTLdrGetSymbol(mAuthLibrary, "VRDPAuth", (void**)&mpfnAuthEntry);
1274 if (VBOX_FAILURE (rc2))
1275 {
1276 LogRel(("VRDPAUTH: Could not resolve import '%s'. Error code: %Vrc\n", "VRDPAuth", rc2));
1277 rc = rc2;
1278 }
1279
1280 if (mpfnAuthEntry2 || mpfnAuthEntry)
1281 {
1282 LogRel(("VRDPAUTH: Using entry point '%s'.\n", mpfnAuthEntry2? "VRDPAuth2": "VRDPAuth"));
1283 rc = VINF_SUCCESS;
1284 }
1285 }
1286
1287 if (VBOX_FAILURE (rc))
1288 {
1289 mConsole->reportAuthLibraryError (filename.raw(), rc);
1290
1291 mpfnAuthEntry = NULL;
1292 mpfnAuthEntry2 = NULL;
1293
1294 if (mAuthLibrary)
1295 {
1296 RTLdrClose(mAuthLibrary);
1297 mAuthLibrary = 0;
1298 }
1299
1300 return VRDPAuthAccessDenied;
1301 }
1302 }
1303
1304 Assert (mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2));
1305
1306 VRDPAuthResult result = mpfnAuthEntry2?
1307 mpfnAuthEntry2 (&rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, true, u32ClientId):
1308 mpfnAuthEntry (&rawuuid, guestJudgement, pszUser, pszPassword, pszDomain);
1309
1310 switch (result)
1311 {
1312 case VRDPAuthAccessDenied:
1313 LogRel(("VRDPAUTH: external authentication module returned 'access denied'\n"));
1314 break;
1315 case VRDPAuthAccessGranted:
1316 LogRel(("VRDPAUTH: external authentication module returned 'access granted'\n"));
1317 break;
1318 case VRDPAuthDelegateToGuest:
1319 LogRel(("VRDPAUTH: external authentication module returned 'delegate request to guest'\n"));
1320 break;
1321 default:
1322 LogRel(("VRDPAUTH: external authentication module returned incorrect return code %d\n", result));
1323 result = VRDPAuthAccessDenied;
1324 }
1325
1326 LogFlow(("ConsoleVRDPServer::Authenticate: result = %d\n", result));
1327
1328 return result;
1329}
1330
1331void ConsoleVRDPServer::AuthDisconnect (const Guid &uuid, uint32_t u32ClientId)
1332{
1333 VRDPAUTHUUID rawuuid;
1334
1335 memcpy (rawuuid, ((Guid &)uuid).ptr (), sizeof (rawuuid));
1336
1337 LogFlow(("ConsoleVRDPServer::AuthDisconnect: uuid = %Vuuid, u32ClientId = %d\n",
1338 rawuuid, u32ClientId));
1339
1340 Assert (mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2));
1341
1342 if (mpfnAuthEntry2)
1343 mpfnAuthEntry2 (&rawuuid, VRDPAuthGuestNotAsked, NULL, NULL, NULL, false, u32ClientId);
1344}
1345
1346int ConsoleVRDPServer::lockConsoleVRDPServer (void)
1347{
1348 int rc = RTCritSectEnter (&mCritSect);
1349 AssertRC (rc);
1350 return rc;
1351}
1352
1353void ConsoleVRDPServer::unlockConsoleVRDPServer (void)
1354{
1355 RTCritSectLeave (&mCritSect);
1356}
1357
1358DECLCALLBACK(int) ConsoleVRDPServer::ClipboardCallback (void *pvCallback,
1359 uint32_t u32ClientId,
1360 uint32_t u32Function,
1361 uint32_t u32Format,
1362 const void *pvData,
1363 uint32_t cbData)
1364{
1365 LogFlowFunc(("pvCallback = %p, u32ClientId = %d, u32Function = %d, u32Format = 0x%08X, pvData = %p, cbData = %d\n",
1366 pvCallback, u32ClientId, u32Function, u32Format, pvData, cbData));
1367
1368 int rc = VINF_SUCCESS;
1369
1370 ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvCallback);
1371
1372 NOREF(u32ClientId);
1373
1374 switch (u32Function)
1375 {
1376 case VRDP_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE:
1377 {
1378 if (pServer->mpfnClipboardCallback)
1379 {
1380 pServer->mpfnClipboardCallback (VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
1381 u32Format,
1382 (void *)pvData,
1383 cbData);
1384 }
1385 } break;
1386
1387 case VRDP_CLIPBOARD_FUNCTION_DATA_READ:
1388 {
1389 if (pServer->mpfnClipboardCallback)
1390 {
1391 pServer->mpfnClipboardCallback (VBOX_CLIPBOARD_EXT_FN_DATA_READ,
1392 u32Format,
1393 (void *)pvData,
1394 cbData);
1395 }
1396 } break;
1397
1398 default:
1399 rc = VERR_NOT_SUPPORTED;
1400 }
1401
1402 return rc;
1403}
1404
1405DECLCALLBACK(int) ConsoleVRDPServer::ClipboardServiceExtension (void *pvExtension,
1406 uint32_t u32Function,
1407 void *pvParms,
1408 uint32_t cbParms)
1409{
1410 LogFlowFunc(("pvExtension = %p, u32Function = %d, pvParms = %p, cbParms = %d\n",
1411 pvExtension, u32Function, pvParms, cbParms));
1412
1413 int rc = VINF_SUCCESS;
1414
1415#ifdef VBOX_VRDP
1416 ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvExtension);
1417
1418 VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms;
1419
1420 switch (u32Function)
1421 {
1422 case VBOX_CLIPBOARD_EXT_FN_SET_CALLBACK:
1423 {
1424 pServer->mpfnClipboardCallback = (PFNVRDPCLIPBOARDEXTCALLBACK)pParms->pvData;
1425 } break;
1426
1427 case VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE:
1428 {
1429 /* The guest announces clipboard formats. This must be delivered to all clients. */
1430#ifdef VRDP_NO_COM
1431 if (mpEntryPoints)
1432 {
1433 mpEntryPoints->VRDPClipboard (pServer->mhServer,
1434 VRDP_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE,
1435 pParms->u32Format,
1436 NULL,
1437 0,
1438 NULL);
1439 }
1440#else
1441 if (mpfnVRDPClipboard)
1442 {
1443 mpfnVRDPClipboard (pServer->mhServer,
1444 VRDP_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE,
1445 pParms->u32Format,
1446 NULL,
1447 0,
1448 NULL);
1449 }
1450#endif /* VRDP_NO_COM */
1451 } break;
1452
1453 case VBOX_CLIPBOARD_EXT_FN_DATA_READ:
1454 {
1455 /* The clipboard service expects that the pvData buffer will be filled
1456 * with clipboard data. The server returns the data from the client that
1457 * announced the requested format most recently.
1458 */
1459#ifdef VRDP_NO_COM
1460 if (mpEntryPoints)
1461 {
1462 mpEntryPoints->VRDPClipboard (pServer->mhServer,
1463 VRDP_CLIPBOARD_FUNCTION_DATA_READ,
1464 pParms->u32Format,
1465 pParms->pvData,
1466 pParms->cbData,
1467 &pParms->cbData);
1468 }
1469#else
1470 if (mpfnVRDPClipboard)
1471 {
1472 mpfnVRDPClipboard (pServer->mhServer,
1473 VRDP_CLIPBOARD_FUNCTION_DATA_READ,
1474 pParms->u32Format,
1475 pParms->pvData,
1476 pParms->cbData,
1477 &pParms->cbData);
1478 }
1479#endif /* VRDP_NO_COM */
1480 } break;
1481
1482 case VBOX_CLIPBOARD_EXT_FN_DATA_WRITE:
1483 {
1484#ifdef VRDP_NO_COM
1485 if (mpEntryPoints)
1486 {
1487 mpEntryPoints->VRDPClipboard (pServer->mhServer,
1488 VRDP_CLIPBOARD_FUNCTION_DATA_WRITE,
1489 pParms->u32Format,
1490 pParms->pvData,
1491 pParms->cbData,
1492 NULL);
1493 }
1494#else
1495 if (mpfnVRDPClipboard)
1496 {
1497 mpfnVRDPClipboard (pServer->mhServer,
1498 VRDP_CLIPBOARD_FUNCTION_DATA_WRITE,
1499 pParms->u32Format,
1500 pParms->pvData,
1501 pParms->cbData,
1502 NULL);
1503 }
1504#endif /* VRDP_NO_COM */
1505 } break;
1506
1507 default:
1508 rc = VERR_NOT_SUPPORTED;
1509 }
1510#endif /* VBOX_VRDP */
1511
1512 return rc;
1513}
1514
1515#ifdef VRDP_NO_COM
1516void ConsoleVRDPServer::ClipboardCreate (uint32_t u32ClientId)
1517#else
1518void ConsoleVRDPServer::ClipboardCreate (uint32_t u32ClientId, PFNVRDPCLIPBOARDCALLBACK *ppfn, void **ppv)
1519#endif /* VRDP_NO_COM */
1520{
1521 int rc = lockConsoleVRDPServer ();
1522
1523 if (VBOX_SUCCESS (rc))
1524 {
1525 if (mcClipboardRefs == 0)
1526 {
1527 rc = HGCMHostRegisterServiceExtension (&mhClipboard, "VBoxSharedClipboard", ClipboardServiceExtension, this);
1528
1529 if (VBOX_SUCCESS (rc))
1530 {
1531 mcClipboardRefs++;
1532 }
1533 }
1534
1535#ifdef VRDP_NO_COM
1536#else
1537 if (VBOX_SUCCESS (rc))
1538 {
1539 *ppfn = ClipboardCallback;
1540 *ppv = this;
1541 }
1542#endif /* VRDP_NO_COM */
1543
1544 unlockConsoleVRDPServer ();
1545 }
1546}
1547
1548void ConsoleVRDPServer::ClipboardDelete (uint32_t u32ClientId)
1549{
1550 int rc = lockConsoleVRDPServer ();
1551
1552 if (VBOX_SUCCESS (rc))
1553 {
1554 mcClipboardRefs--;
1555
1556 if (mcClipboardRefs == 0)
1557 {
1558 HGCMHostUnregisterServiceExtension (mhClipboard);
1559 }
1560
1561 unlockConsoleVRDPServer ();
1562 }
1563}
1564
1565/* That is called on INPUT thread of the VRDP server.
1566 * The ConsoleVRDPServer keeps a list of created backend instances.
1567 */
1568#ifdef VRDP_NO_COM
1569void ConsoleVRDPServer::USBBackendCreate (uint32_t u32ClientId)
1570#else
1571void ConsoleVRDPServer::USBBackendCreate (uint32_t u32ClientId, PFNVRDPUSBCALLBACK *ppfn, void **ppv)
1572#endif /* VRDP_NO_COM */
1573{
1574#ifdef VBOX_WITH_USB
1575 LogFlow(("ConsoleVRDPServer::USBBackendCreate: u32ClientId = %d\n", u32ClientId));
1576
1577 /* Create a new instance of the USB backend for the new client. */
1578 RemoteUSBBackend *pRemoteUSBBackend = new RemoteUSBBackend (mConsole, this, u32ClientId);
1579
1580 if (pRemoteUSBBackend)
1581 {
1582 pRemoteUSBBackend->AddRef (); /* 'Release' called in USBBackendDelete. */
1583
1584 /* Append the new instance in the list. */
1585 int rc = lockConsoleVRDPServer ();
1586
1587 if (VBOX_SUCCESS (rc))
1588 {
1589 pRemoteUSBBackend->pNext = mUSBBackends.pHead;
1590 if (mUSBBackends.pHead)
1591 {
1592 mUSBBackends.pHead->pPrev = pRemoteUSBBackend;
1593 }
1594 else
1595 {
1596 mUSBBackends.pTail = pRemoteUSBBackend;
1597 }
1598
1599 mUSBBackends.pHead = pRemoteUSBBackend;
1600
1601 unlockConsoleVRDPServer ();
1602
1603#ifdef VRDP_NO_COM
1604#else
1605 pRemoteUSBBackend->QueryVRDPCallbackPointer (ppfn, ppv);
1606#endif /* VRDP_NO_COM */
1607 }
1608
1609 if (VBOX_FAILURE (rc))
1610 {
1611 pRemoteUSBBackend->Release ();
1612 }
1613 }
1614#endif /* VBOX_WITH_USB */
1615}
1616
1617void ConsoleVRDPServer::USBBackendDelete (uint32_t u32ClientId)
1618{
1619#ifdef VBOX_WITH_USB
1620 LogFlow(("ConsoleVRDPServer::USBBackendDelete: u32ClientId = %d\n", u32ClientId));
1621
1622 RemoteUSBBackend *pRemoteUSBBackend = NULL;
1623
1624 /* Find the instance. */
1625 int rc = lockConsoleVRDPServer ();
1626
1627 if (VBOX_SUCCESS (rc))
1628 {
1629 pRemoteUSBBackend = usbBackendFind (u32ClientId);
1630
1631 if (pRemoteUSBBackend)
1632 {
1633 /* Notify that it will be deleted. */
1634 pRemoteUSBBackend->NotifyDelete ();
1635 }
1636
1637 unlockConsoleVRDPServer ();
1638 }
1639
1640 if (pRemoteUSBBackend)
1641 {
1642 /* Here the instance has been excluded from the list and can be dereferenced. */
1643 pRemoteUSBBackend->Release ();
1644 }
1645#endif
1646}
1647
1648void *ConsoleVRDPServer::USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid)
1649{
1650#ifdef VBOX_WITH_USB
1651 RemoteUSBBackend *pRemoteUSBBackend = NULL;
1652
1653 /* Find the instance. */
1654 int rc = lockConsoleVRDPServer ();
1655
1656 if (VBOX_SUCCESS (rc))
1657 {
1658 pRemoteUSBBackend = usbBackendFind (u32ClientId);
1659
1660 if (pRemoteUSBBackend)
1661 {
1662 /* Inform the backend instance that it is referenced by the Guid. */
1663 bool fAdded = pRemoteUSBBackend->addUUID (pGuid);
1664
1665 if (fAdded)
1666 {
1667 /* Reference the instance because its pointer is being taken. */
1668 pRemoteUSBBackend->AddRef (); /* 'Release' is called in USBBackendReleasePointer. */
1669 }
1670 else
1671 {
1672 pRemoteUSBBackend = NULL;
1673 }
1674 }
1675
1676 unlockConsoleVRDPServer ();
1677 }
1678
1679 if (pRemoteUSBBackend)
1680 {
1681 return pRemoteUSBBackend->GetBackendCallbackPointer ();
1682 }
1683
1684#endif
1685 return NULL;
1686}
1687
1688void ConsoleVRDPServer::USBBackendReleasePointer (const Guid *pGuid)
1689{
1690#ifdef VBOX_WITH_USB
1691 RemoteUSBBackend *pRemoteUSBBackend = NULL;
1692
1693 /* Find the instance. */
1694 int rc = lockConsoleVRDPServer ();
1695
1696 if (VBOX_SUCCESS (rc))
1697 {
1698 pRemoteUSBBackend = usbBackendFindByUUID (pGuid);
1699
1700 if (pRemoteUSBBackend)
1701 {
1702 pRemoteUSBBackend->removeUUID (pGuid);
1703 }
1704
1705 unlockConsoleVRDPServer ();
1706
1707 if (pRemoteUSBBackend)
1708 {
1709 pRemoteUSBBackend->Release ();
1710 }
1711 }
1712#endif
1713}
1714
1715RemoteUSBBackend *ConsoleVRDPServer::usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend)
1716{
1717 LogFlow(("ConsoleVRDPServer::usbBackendGetNext: pBackend = %p\n", pRemoteUSBBackend));
1718
1719 RemoteUSBBackend *pNextRemoteUSBBackend = NULL;
1720#ifdef VBOX_WITH_USB
1721
1722 int rc = lockConsoleVRDPServer ();
1723
1724 if (VBOX_SUCCESS (rc))
1725 {
1726 if (pRemoteUSBBackend == NULL)
1727 {
1728 /* The first backend in the list is requested. */
1729 pNextRemoteUSBBackend = mUSBBackends.pHead;
1730 }
1731 else
1732 {
1733 /* Get pointer to the next backend. */
1734 pNextRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
1735 }
1736
1737 if (pNextRemoteUSBBackend)
1738 {
1739 pNextRemoteUSBBackend->AddRef ();
1740 }
1741
1742 unlockConsoleVRDPServer ();
1743
1744 if (pRemoteUSBBackend)
1745 {
1746 pRemoteUSBBackend->Release ();
1747 }
1748 }
1749#endif
1750
1751 return pNextRemoteUSBBackend;
1752}
1753
1754#ifdef VBOX_WITH_USB
1755/* Internal method. Called under the ConsoleVRDPServerLock. */
1756RemoteUSBBackend *ConsoleVRDPServer::usbBackendFind (uint32_t u32ClientId)
1757{
1758 RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
1759
1760 while (pRemoteUSBBackend)
1761 {
1762 if (pRemoteUSBBackend->ClientId () == u32ClientId)
1763 {
1764 break;
1765 }
1766
1767 pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
1768 }
1769
1770 return pRemoteUSBBackend;
1771}
1772
1773/* Internal method. Called under the ConsoleVRDPServerLock. */
1774RemoteUSBBackend *ConsoleVRDPServer::usbBackendFindByUUID (const Guid *pGuid)
1775{
1776 RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
1777
1778 while (pRemoteUSBBackend)
1779 {
1780 if (pRemoteUSBBackend->findUUID (pGuid))
1781 {
1782 break;
1783 }
1784
1785 pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
1786 }
1787
1788 return pRemoteUSBBackend;
1789}
1790#endif
1791
1792/* Internal method. Called by the backend destructor. */
1793void ConsoleVRDPServer::usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend)
1794{
1795#ifdef VBOX_WITH_USB
1796 int rc = lockConsoleVRDPServer ();
1797 AssertRC (rc);
1798
1799 /* Exclude the found instance from the list. */
1800 if (pRemoteUSBBackend->pNext)
1801 {
1802 pRemoteUSBBackend->pNext->pPrev = pRemoteUSBBackend->pPrev;
1803 }
1804 else
1805 {
1806 mUSBBackends.pTail = (RemoteUSBBackend *)pRemoteUSBBackend->pPrev;
1807 }
1808
1809 if (pRemoteUSBBackend->pPrev)
1810 {
1811 pRemoteUSBBackend->pPrev->pNext = pRemoteUSBBackend->pNext;
1812 }
1813 else
1814 {
1815 mUSBBackends.pHead = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
1816 }
1817
1818 pRemoteUSBBackend->pNext = pRemoteUSBBackend->pPrev = NULL;
1819
1820 unlockConsoleVRDPServer ();
1821#endif
1822}
1823
1824
1825void ConsoleVRDPServer::SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const
1826{
1827#ifdef VBOX_VRDP
1828#ifdef VRDP_NO_COM
1829 if (mpEntryPoints)
1830 {
1831 mpEntryPoints->VRDPUpdate (mhServer, uScreenId, pvUpdate, cbUpdate);
1832 }
1833#else
1834 if (mpfnVRDPSendUpdate)
1835 mpfnVRDPSendUpdate (mhServer, uScreenId, pvUpdate, cbUpdate);
1836#endif /* VRDP_NO_COM */
1837#endif
1838}
1839
1840void ConsoleVRDPServer::SendResize (void) const
1841{
1842#ifdef VBOX_VRDP
1843#ifdef VRDP_NO_COM
1844 if (mpEntryPoints)
1845 {
1846 mpEntryPoints->VRDPResize (mhServer);
1847 }
1848#else
1849 if (mpfnVRDPSendResize)
1850 mpfnVRDPSendResize (mhServer);
1851#endif /* VRDP_NO_COM */
1852#endif
1853}
1854
1855void ConsoleVRDPServer::SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const
1856{
1857#ifdef VBOX_VRDP
1858#ifdef VRDP_NO_COM
1859 VRDPORDERHDR update;
1860 update.x = x;
1861 update.y = y;
1862 update.w = w;
1863 update.h = h;
1864 if (mpEntryPoints)
1865 {
1866 mpEntryPoints->VRDPUpdate (mhServer, uScreenId, &update, sizeof (update));
1867 }
1868#else
1869 if (mpfnVRDPSendUpdateBitmap)
1870 mpfnVRDPSendUpdateBitmap (mhServer, uScreenId, x, y, w, h);
1871#endif /* VRDP_NO_COM */
1872#endif
1873}
1874
1875#ifdef VRDP_NO_COM
1876#else
1877void ConsoleVRDPServer::SetFramebuffer (IFramebuffer *framebuffer, uint32_t fFlags) const
1878{
1879#ifdef VBOX_VRDP
1880 if (mpfnVRDPSetFramebuffer)
1881 mpfnVRDPSetFramebuffer (mhServer, framebuffer, fFlags);
1882#endif
1883}
1884#endif /* VRDP_NO_COM */
1885
1886void ConsoleVRDPServer::SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format) const
1887{
1888#ifdef VBOX_VRDP
1889#ifdef VRDP_NO_COM
1890 if (mpEntryPoints)
1891 {
1892 mpEntryPoints->VRDPAudioSamples (mhServer, pvSamples, cSamples, format);
1893 }
1894#else
1895 if (mpfnVRDPSendAudioSamples)
1896 mpfnVRDPSendAudioSamples (mhServer, pvSamples, cSamples, format);
1897#endif /* VRDP_NO_COM */
1898#endif
1899}
1900
1901void ConsoleVRDPServer::SendAudioVolume (uint16_t left, uint16_t right) const
1902{
1903#ifdef VBOX_VRDP
1904#ifdef VRDP_NO_COM
1905 if (mpEntryPoints)
1906 {
1907 mpEntryPoints->VRDPAudioVolume (mhServer, left, right);
1908 }
1909#else
1910 if (mpfnVRDPSendAudioVolume)
1911 mpfnVRDPSendAudioVolume (mhServer, left, right);
1912#endif /* VRDP_NO_COM */
1913#endif
1914}
1915
1916void ConsoleVRDPServer::SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const
1917{
1918#ifdef VBOX_VRDP
1919#ifdef VRDP_NO_COM
1920 if (mpEntryPoints)
1921 {
1922 mpEntryPoints->VRDPUSBRequest (mhServer, u32ClientId, pvParms, cbParms);
1923 }
1924#else
1925 if (mpfnVRDPSendUSBRequest)
1926 mpfnVRDPSendUSBRequest (mhServer, u32ClientId, pvParms, cbParms);
1927#endif /* VRDP_NO_COM */
1928#endif
1929}
1930
1931void ConsoleVRDPServer::QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const
1932{
1933#ifdef VBOX_VRDP
1934#ifdef VRDP_NO_COM
1935 if (mpEntryPoints)
1936 {
1937 mpEntryPoints->VRDPQueryInfo (mhServer, index, pvBuffer, cbBuffer, pcbOut);
1938 }
1939#else
1940 if (mpfnVRDPQueryInfo)
1941 mpfnVRDPQueryInfo (mhServer, index, pvBuffer, cbBuffer, pcbOut);
1942#endif /* VRDP_NO_COM */
1943#endif
1944}
1945
1946#ifdef VBOX_VRDP
1947/* note: static function now! */
1948bool ConsoleVRDPServer::loadVRDPLibrary (void)
1949{
1950 int rc = VINF_SUCCESS;
1951
1952 if (!mVRDPLibrary)
1953 {
1954 rc = RTLdrLoad("VBoxVRDP", &mVRDPLibrary);
1955
1956 if (VBOX_SUCCESS(rc))
1957 {
1958 LogFlow(("VRDPServer::loadLibrary(): successfully loaded VRDP library.\n"));
1959
1960 struct SymbolEntry
1961 {
1962 const char *name;
1963 void **ppfn;
1964 };
1965
1966 #define DEFSYMENTRY(a) { #a, (void**)&mpfn##a }
1967
1968#ifdef VRDP_NO_COM
1969 static const struct SymbolEntry symbols[] =
1970 {
1971 DEFSYMENTRY(VRDPCreateServer)
1972 };
1973#else
1974 static const struct SymbolEntry symbols[] =
1975 {
1976 DEFSYMENTRY(VRDPStartServer),
1977 DEFSYMENTRY(VRDPSetCallback),
1978 DEFSYMENTRY(VRDPShutdownServer),
1979 DEFSYMENTRY(VRDPSendUpdate),
1980 DEFSYMENTRY(VRDPSendUpdateBitmap),
1981 DEFSYMENTRY(VRDPSendResize),
1982 DEFSYMENTRY(VRDPSendAudioSamples),
1983 DEFSYMENTRY(VRDPSendAudioVolume),
1984 DEFSYMENTRY(VRDPSendUSBRequest),
1985 DEFSYMENTRY(VRDPQueryInfo),
1986 DEFSYMENTRY(VRDPClipboard)
1987 };
1988#endif /* VRDP_NO_COM */
1989
1990 #undef DEFSYMENTRY
1991
1992 for (unsigned i = 0; i < ELEMENTS(symbols); i++)
1993 {
1994 rc = RTLdrGetSymbol(mVRDPLibrary, symbols[i].name, symbols[i].ppfn);
1995
1996 AssertMsgRC(rc, ("Error resolving VRDP symbol %s\n", symbols[i].name));
1997
1998 if (VBOX_FAILURE(rc))
1999 {
2000 break;
2001 }
2002 }
2003 }
2004 else
2005 {
2006 LogFlow(("VRDPServer::loadLibrary(): failed to load VRDP library! VRDP not available.\n"));
2007 mVRDPLibrary = NULL;
2008 }
2009 }
2010
2011 // just to be safe
2012 if (VBOX_FAILURE(rc))
2013 {
2014 if (mVRDPLibrary)
2015 {
2016 RTLdrClose (mVRDPLibrary);
2017 mVRDPLibrary = NULL;
2018 }
2019 }
2020
2021 return (mVRDPLibrary != NULL);
2022}
2023#endif /* VBOX_VRDP */
2024
2025/*
2026 * IRemoteDisplayInfo implementation.
2027 */
2028// constructor / destructor
2029/////////////////////////////////////////////////////////////////////////////
2030
2031HRESULT RemoteDisplayInfo::FinalConstruct()
2032{
2033 return S_OK;
2034}
2035
2036void RemoteDisplayInfo::FinalRelease()
2037{
2038 if (isReady())
2039 uninit ();
2040}
2041
2042// public methods only for internal purposes
2043/////////////////////////////////////////////////////////////////////////////
2044
2045/**
2046 * Initializes the guest object.
2047 */
2048HRESULT RemoteDisplayInfo::init (Console *aParent)
2049{
2050 LogFlowMember (("RemoteDisplayInfo::init (%p)\n", aParent));
2051
2052 ComAssertRet (aParent, E_INVALIDARG);
2053
2054 AutoLock alock (this);
2055 ComAssertRet (!isReady(), E_UNEXPECTED);
2056
2057 mParent = aParent;
2058
2059 setReady (true);
2060 return S_OK;
2061}
2062
2063/**
2064 * Uninitializes the instance and sets the ready flag to FALSE.
2065 * Called either from FinalRelease() or by the parent when it gets destroyed.
2066 */
2067void RemoteDisplayInfo::uninit()
2068{
2069 LogFlowMember (("RemoteDisplayInfo::uninit()\n"));
2070
2071 AutoLock alock (this);
2072 AssertReturn (isReady(), (void) 0);
2073
2074 mParent.setNull();
2075
2076 setReady (false);
2077}
2078
2079// IRemoteDisplayInfo properties
2080/////////////////////////////////////////////////////////////////////////////
2081
2082#define IMPL_GETTER_BOOL(_aType, _aName, _aIndex) \
2083 STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
2084 { \
2085 if (!a##_aName) \
2086 return E_POINTER; \
2087 \
2088 AutoLock alock (this); \
2089 CHECK_READY(); \
2090 \
2091 uint32_t value; \
2092 uint32_t cbOut = 0; \
2093 \
2094 mParent->consoleVRDPServer ()->QueryInfo \
2095 (_aIndex, &value, sizeof (value), &cbOut); \
2096 \
2097 *a##_aName = cbOut? !!value: FALSE; \
2098 \
2099 return S_OK; \
2100 }
2101
2102#define IMPL_GETTER_SCALAR(_aType, _aName, _aIndex) \
2103 STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
2104 { \
2105 if (!a##_aName) \
2106 return E_POINTER; \
2107 \
2108 AutoLock alock (this); \
2109 CHECK_READY(); \
2110 \
2111 _aType value; \
2112 uint32_t cbOut = 0; \
2113 \
2114 mParent->consoleVRDPServer ()->QueryInfo \
2115 (_aIndex, &value, sizeof (value), &cbOut); \
2116 \
2117 *a##_aName = cbOut? value: 0; \
2118 \
2119 return S_OK; \
2120 }
2121
2122#define IMPL_GETTER_BSTR(_aType, _aName, _aIndex) \
2123 STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
2124 { \
2125 if (!a##_aName) \
2126 return E_POINTER; \
2127 \
2128 AutoLock alock (this); \
2129 CHECK_READY(); \
2130 \
2131 uint32_t cbOut = 0; \
2132 \
2133 mParent->consoleVRDPServer ()->QueryInfo \
2134 (_aIndex, NULL, 0, &cbOut); \
2135 \
2136 if (cbOut == 0) \
2137 { \
2138 Bstr str(""); \
2139 str.cloneTo (a##_aName); \
2140 return S_OK; \
2141 } \
2142 \
2143 char *pchBuffer = (char *)RTMemTmpAlloc (cbOut); \
2144 \
2145 if (!pchBuffer) \
2146 { \
2147 Log(("RemoteDisplayInfo::" \
2148 #_aName \
2149 ": Failed to allocate memory %d bytes\n", cbOut)); \
2150 return E_OUTOFMEMORY; \
2151 } \
2152 \
2153 mParent->consoleVRDPServer ()->QueryInfo \
2154 (_aIndex, pchBuffer, cbOut, &cbOut); \
2155 \
2156 Bstr str(pchBuffer); \
2157 \
2158 str.cloneTo (a##_aName); \
2159 \
2160 RTMemTmpFree (pchBuffer); \
2161 \
2162 return S_OK; \
2163 }
2164
2165IMPL_GETTER_BOOL (BOOL, Active, VRDP_QI_ACTIVE);
2166IMPL_GETTER_SCALAR (ULONG, NumberOfClients, VRDP_QI_NUMBER_OF_CLIENTS);
2167IMPL_GETTER_SCALAR (LONG64, BeginTime, VRDP_QI_BEGIN_TIME);
2168IMPL_GETTER_SCALAR (LONG64, EndTime, VRDP_QI_END_TIME);
2169IMPL_GETTER_SCALAR (ULONG64, BytesSent, VRDP_QI_BYTES_SENT);
2170IMPL_GETTER_SCALAR (ULONG64, BytesSentTotal, VRDP_QI_BYTES_SENT_TOTAL);
2171IMPL_GETTER_SCALAR (ULONG64, BytesReceived, VRDP_QI_BYTES_RECEIVED);
2172IMPL_GETTER_SCALAR (ULONG64, BytesReceivedTotal, VRDP_QI_BYTES_RECEIVED_TOTAL);
2173IMPL_GETTER_BSTR (BSTR, User, VRDP_QI_USER);
2174IMPL_GETTER_BSTR (BSTR, Domain, VRDP_QI_DOMAIN);
2175IMPL_GETTER_BSTR (BSTR, ClientName, VRDP_QI_CLIENT_NAME);
2176IMPL_GETTER_BSTR (BSTR, ClientIP, VRDP_QI_CLIENT_IP);
2177IMPL_GETTER_SCALAR (ULONG, ClientVersion, VRDP_QI_CLIENT_VERSION);
2178IMPL_GETTER_SCALAR (ULONG, EncryptionStyle, VRDP_QI_ENCRYPTION_STYLE);
2179
2180#undef IMPL_GETTER_BSTR
2181#undef IMPL_GETTER_SCALAR
Note: See TracBrowser for help on using the repository browser.

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