VirtualBox

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

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

don't try call USBClientResponseCallback unless we're building with USB support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 66.0 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_THREADSAFE_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 LogFlowFunc(("%x\n", fu32Intercept));
712
713 int rc = VERR_NOT_SUPPORTED;
714
715 switch (fu32Intercept)
716 {
717 case VRDP_CLIENT_INTERCEPT_AUDIO:
718 {
719 server->mConsole->VRDPInterceptAudio (u32ClientId);
720 if (ppvIntercept)
721 {
722 *ppvIntercept = server;
723 }
724 rc = VINF_SUCCESS;
725 } break;
726
727 case VRDP_CLIENT_INTERCEPT_USB:
728 {
729 server->mConsole->VRDPInterceptUSB (u32ClientId, ppvIntercept);
730 rc = VINF_SUCCESS;
731 } break;
732
733 case VRDP_CLIENT_INTERCEPT_CLIPBOARD:
734 {
735 server->mConsole->VRDPInterceptClipboard (u32ClientId);
736 if (ppvIntercept)
737 {
738 *ppvIntercept = server;
739 }
740 rc = VINF_SUCCESS;
741 } break;
742
743 default:
744 break;
745 }
746
747 return rc;
748}
749
750DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet)
751{
752#ifdef VBOX_WITH_USB
753 return USBClientResponseCallback (pvIntercept, u32ClientId, u8Code, pvRet, cbRet);
754#else
755 return VERR_NOT_SUPPORTED;
756#endif
757}
758
759DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData)
760{
761 return ClipboardCallback (pvIntercept, u32ClientId, u32Function, u32Format, pvData, cbData);
762}
763
764DECLCALLBACK(bool) ConsoleVRDPServer::VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDPFRAMEBUFFERINFO *pInfo)
765{
766 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
767
768 bool fAvailable = false;
769
770 IFramebuffer *pfb = NULL;
771 LONG xOrigin = 0;
772 LONG yOrigin = 0;
773
774 server->mConsole->getDisplay ()->GetFramebuffer (uScreenId, &pfb, &xOrigin, &yOrigin);
775
776 if (pfb)
777 {
778 pfb->Lock ();
779
780 /* Query framebuffer parameters. */
781 ULONG lineSize = 0;
782 pfb->COMGETTER(BytesPerLine) (&lineSize);
783
784 ULONG bitsPerPixel = 0;
785 pfb->COMGETTER(BitsPerPixel) (&bitsPerPixel);
786
787 BYTE *address = NULL;
788 pfb->COMGETTER(Address) (&address);
789
790 ULONG height = 0;
791 pfb->COMGETTER(Height) (&height);
792
793 ULONG width = 0;
794 pfb->COMGETTER(Width) (&width);
795
796 /* Now fill the information as requested by the caller. */
797 pInfo->pu8Bits = address;
798 pInfo->xOrigin = xOrigin;
799 pInfo->yOrigin = yOrigin;
800 pInfo->cWidth = width;
801 pInfo->cHeight = height;
802 pInfo->cBitsPerPixel = bitsPerPixel;
803 pInfo->cbLine = lineSize;
804
805 pfb->Unlock ();
806
807 fAvailable = true;
808 }
809
810 if (server->maFramebuffers[uScreenId])
811 {
812 server->maFramebuffers[uScreenId]->Release ();
813 }
814 server->maFramebuffers[uScreenId] = pfb;
815
816 return fAvailable;
817}
818
819DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId)
820{
821 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
822
823 if (server->maFramebuffers[uScreenId])
824 {
825 server->maFramebuffers[uScreenId]->Lock ();
826 }
827}
828
829DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId)
830{
831 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
832
833 if (server->maFramebuffers[uScreenId])
834 {
835 server->maFramebuffers[uScreenId]->Unlock ();
836 }
837}
838
839DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput)
840{
841 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
842 Console *pConsole = server->mConsole;
843
844 switch (type)
845 {
846 case VRDP_INPUT_SCANCODE:
847 {
848 if (cbInput == sizeof (VRDPINPUTSCANCODE))
849 {
850 const VRDPINPUTSCANCODE *pInputScancode = (VRDPINPUTSCANCODE *)pvInput;
851 pConsole->getKeyboard ()->PutScancode((LONG)pInputScancode->uScancode);
852 }
853 } break;
854
855 case VRDP_INPUT_POINT:
856 {
857 if (cbInput == sizeof (VRDPINPUTPOINT))
858 {
859 const VRDPINPUTPOINT *pInputPoint = (VRDPINPUTPOINT *)pvInput;
860
861 int mouseButtons = 0;
862 int iWheel = 0;
863
864 if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON1)
865 {
866 mouseButtons |= MouseButtonState_LeftButton;
867 }
868 if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON2)
869 {
870 mouseButtons |= MouseButtonState_RightButton;
871 }
872 if (pInputPoint->uButtons & VRDP_INPUT_POINT_BUTTON3)
873 {
874 mouseButtons |= MouseButtonState_MiddleButton;
875 }
876 if (pInputPoint->uButtons & VRDP_INPUT_POINT_WHEEL_UP)
877 {
878 mouseButtons |= MouseButtonState_WheelUp;
879 iWheel = -1;
880 }
881 if (pInputPoint->uButtons & VRDP_INPUT_POINT_WHEEL_DOWN)
882 {
883 mouseButtons |= MouseButtonState_WheelDown;
884 iWheel = 1;
885 }
886
887 if (server->m_fGuestWantsAbsolute)
888 {
889 pConsole->getMouse()->PutMouseEventAbsolute (pInputPoint->x + 1, pInputPoint->y + 1, iWheel, mouseButtons);
890 } else
891 {
892 pConsole->getMouse()->PutMouseEvent (pInputPoint->x - server->m_mousex,
893 pInputPoint->y - server->m_mousey,
894 iWheel, mouseButtons);
895 server->m_mousex = pInputPoint->x;
896 server->m_mousey = pInputPoint->y;
897 }
898 }
899 } break;
900
901 case VRDP_INPUT_CAD:
902 {
903 pConsole->getKeyboard ()->PutCAD();
904 } break;
905
906 case VRDP_INPUT_RESET:
907 {
908 pConsole->Reset();
909 } break;
910
911 default:
912 break;
913 }
914}
915
916DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId)
917{
918 ConsoleVRDPServer *server = static_cast <ConsoleVRDPServer *> (pvCallback);
919
920 server->mConsole->getDisplay ()->SetVideoModeHint(cWidth, cHeight, cBitsPerPixel, uScreenId);
921}
922#endif /* VRDP_NO_COM */
923
924ConsoleVRDPServer::ConsoleVRDPServer (Console *console)
925{
926 mConsole = console;
927
928 int rc = RTCritSectInit (&mCritSect);
929 AssertRC (rc);
930
931 mcClipboardRefs = 0;
932 mpfnClipboardCallback = NULL;
933
934#ifdef VBOX_WITH_USB
935 mUSBBackends.pHead = NULL;
936 mUSBBackends.pTail = NULL;
937
938 mUSBBackends.thread = NIL_RTTHREAD;
939 mUSBBackends.fThreadRunning = false;
940 mUSBBackends.event = 0;
941#endif
942
943#ifdef VBOX_VRDP
944 mhServer = 0;
945
946#ifdef VRDP_NO_COM
947 m_fGuestWantsAbsolute = false;
948 m_mousex = 0;
949 m_mousey = 0;
950
951 memset (maFramebuffers, 0, sizeof (maFramebuffers));
952
953 mConsoleCallback = new VRDPConsoleCallback(this);
954 mConsoleCallback->AddRef();
955 console->RegisterCallback(mConsoleCallback);
956#endif /* VRDP_NO_COM */
957#endif /* VBOX_VRDP */
958
959 mAuthLibrary = 0;
960}
961
962ConsoleVRDPServer::~ConsoleVRDPServer ()
963{
964 Stop ();
965
966#ifdef VRDP_NO_COM
967 if (mConsoleCallback)
968 {
969 mConsole->UnregisterCallback(mConsoleCallback);
970 mConsoleCallback->Release();
971 mConsoleCallback = NULL;
972 }
973
974 unsigned i;
975 for (i = 0; i < ELEMENTS(maFramebuffers); i++)
976 {
977 if (maFramebuffers[i])
978 {
979 maFramebuffers[i]->Release ();
980 maFramebuffers[i] = NULL;
981 }
982 }
983#endif /* VRDP_NO_COM */
984 if (RTCritSectIsInitialized (&mCritSect))
985 {
986 RTCritSectDelete (&mCritSect);
987 memset (&mCritSect, 0, sizeof (mCritSect));
988 }
989}
990
991int ConsoleVRDPServer::Launch (void)
992{
993 LogFlowMember(("ConsoleVRDPServer::Launch\n"));
994#ifdef VBOX_VRDP
995 int rc = VINF_SUCCESS;
996 IVRDPServer *vrdpserver = mConsole->getVRDPServer ();
997 Assert(vrdpserver);
998 BOOL vrdpEnabled = FALSE;
999
1000 HRESULT rc2 = vrdpserver->COMGETTER(Enabled) (&vrdpEnabled);
1001 AssertComRC(rc2);
1002
1003 if (SUCCEEDED (rc2)
1004 && vrdpEnabled
1005 && loadVRDPLibrary ())
1006 {
1007#ifdef VRDP_NO_COM
1008 rc = mpfnVRDPCreateServer (&mCallbacks.header, this, (VRDPINTERFACEHDR **)&mpEntryPoints, &mhServer);
1009#else
1010 rc = mpfnVRDPStartServer(mConsole, vrdpserver, &mhServer);
1011#endif /* VRDP_NO_COM */
1012
1013 if (VBOX_SUCCESS(rc))
1014 {
1015#ifdef VBOX_WITH_USB
1016 remoteUSBThreadStart ();
1017#endif /* VBOX_WITH_USB */
1018 }
1019 else
1020 AssertMsgFailed(("Could not start VRDP server: rc = %Vrc\n", rc));
1021 }
1022#else
1023 int rc = VERR_NOT_SUPPORTED;
1024#endif /* VBOX_VRDP */
1025 return rc;
1026}
1027
1028#ifdef VRDP_NO_COM
1029void ConsoleVRDPServer::EnableConnections (void)
1030{
1031#ifdef VBOX_VRDP
1032 if (mpEntryPoints && mhServer)
1033 {
1034 mpEntryPoints->VRDPEnableConnections (mhServer, true);
1035 }
1036#endif /* VBOX_VRDP */
1037}
1038
1039void ConsoleVRDPServer::MousePointerUpdate (const VRDPCOLORPOINTER *pPointer)
1040{
1041#ifdef VBOX_VRDP
1042 if (mpEntryPoints && mhServer)
1043 {
1044 mpEntryPoints->VRDPColorPointer (mhServer, pPointer);
1045 }
1046#endif /* VBOX_VRDP */
1047}
1048
1049void ConsoleVRDPServer::MousePointerHide (void)
1050{
1051#ifdef VBOX_VRDP
1052 if (mpEntryPoints && mhServer)
1053 {
1054 mpEntryPoints->VRDPHidePointer (mhServer);
1055 }
1056#endif /* VBOX_VRDP */
1057}
1058#else
1059void ConsoleVRDPServer::SetCallback (void)
1060{
1061#ifdef VBOX_VRDP
1062 /* This is called after VM is created and allows the server to accept client connection. */
1063 if (mhServer && mpfnVRDPSetCallback)
1064 {
1065 mpfnVRDPSetCallback (mhServer, mConsole->getVrdpServerCallback (), mConsole);
1066 }
1067#endif /* VBOX_VRDP */
1068}
1069#endif /* VRDP_NO_COM */
1070
1071void ConsoleVRDPServer::Stop (void)
1072{
1073 Assert(VALID_PTR(this)); /** @todo r=bird: there are(/was) some odd cases where this buster was invalid on
1074 * linux. Just remove this when it's 100% sure that problem has been fixed. */
1075#ifdef VBOX_VRDP
1076 if (mhServer)
1077 {
1078 HVRDPSERVER hServer = mhServer;
1079
1080 /* Reset the handle to avoid further calls to the server. */
1081 mhServer = 0;
1082
1083#ifdef VRDP_NO_COM
1084 if (mpEntryPoints && hServer)
1085 {
1086 mpEntryPoints->VRDPDestroy (hServer);
1087 }
1088#else
1089 mpfnVRDPShutdownServer (hServer);
1090#endif /* VRDP_NO_COM */
1091 }
1092#endif /* VBOX_VRDP */
1093
1094#ifdef VBOX_WITH_USB
1095 remoteUSBThreadStop ();
1096#endif /* VBOX_WITH_USB */
1097
1098 mpfnAuthEntry = NULL;
1099 mpfnAuthEntry2 = NULL;
1100
1101 if (mAuthLibrary)
1102 {
1103 RTLdrClose(mAuthLibrary);
1104 mAuthLibrary = 0;
1105 }
1106}
1107
1108/* Worker thread for Remote USB. The thread polls the clients for
1109 * the list of attached USB devices.
1110 * The thread is also responsible for attaching/detaching devices
1111 * to/from the VM.
1112 *
1113 * It is expected that attaching/detaching is not a frequent operation.
1114 *
1115 * The thread is always running when the VRDP server is active.
1116 *
1117 * The thread scans backends and requests the device list every 2 seconds.
1118 *
1119 * When device list is available, the thread calls the Console to process it.
1120 *
1121 */
1122#define VRDP_DEVICE_LIST_PERIOD_MS (2000)
1123
1124#ifdef VBOX_WITH_USB
1125static DECLCALLBACK(int) threadRemoteUSB (RTTHREAD self, void *pvUser)
1126{
1127 ConsoleVRDPServer *pOwner = (ConsoleVRDPServer *)pvUser;
1128
1129 LogFlow(("Console::threadRemoteUSB: start. owner = %p.\n", pOwner));
1130
1131 pOwner->notifyRemoteUSBThreadRunning (self);
1132
1133 while (pOwner->isRemoteUSBThreadRunning ())
1134 {
1135 RemoteUSBBackend *pRemoteUSBBackend = NULL;
1136
1137 while ((pRemoteUSBBackend = pOwner->usbBackendGetNext (pRemoteUSBBackend)) != NULL)
1138 {
1139 pRemoteUSBBackend->PollRemoteDevices ();
1140 }
1141
1142 pOwner->waitRemoteUSBThreadEvent (VRDP_DEVICE_LIST_PERIOD_MS);
1143
1144 LogFlow(("Console::threadRemoteUSB: iteration. owner = %p.\n", pOwner));
1145 }
1146
1147 return VINF_SUCCESS;
1148}
1149
1150void ConsoleVRDPServer::notifyRemoteUSBThreadRunning (RTTHREAD thread)
1151{
1152 mUSBBackends.thread = thread;
1153 mUSBBackends.fThreadRunning = true;
1154 int rc = RTThreadUserSignal (thread);
1155 AssertRC (rc);
1156}
1157
1158bool ConsoleVRDPServer::isRemoteUSBThreadRunning (void)
1159{
1160 return mUSBBackends.fThreadRunning;
1161}
1162
1163void ConsoleVRDPServer::waitRemoteUSBThreadEvent (unsigned cMillies)
1164{
1165 int rc = RTSemEventWait (mUSBBackends.event, cMillies);
1166 Assert (VBOX_SUCCESS(rc) || rc == VERR_TIMEOUT);
1167 NOREF(rc);
1168}
1169
1170void ConsoleVRDPServer::remoteUSBThreadStart (void)
1171{
1172 int rc = RTSemEventCreate (&mUSBBackends.event);
1173
1174 if (VBOX_FAILURE (rc))
1175 {
1176 AssertFailed ();
1177 mUSBBackends.event = 0;
1178 }
1179
1180 if (VBOX_SUCCESS (rc))
1181 {
1182 rc = RTThreadCreate (&mUSBBackends.thread, threadRemoteUSB, this, 65536,
1183 RTTHREADTYPE_VRDP_IO, RTTHREADFLAGS_WAITABLE, "remote usb");
1184 }
1185
1186 if (VBOX_FAILURE (rc))
1187 {
1188 LogRel(("Warning: could not start the remote USB thread, rc = %Vrc!!!\n", rc));
1189 mUSBBackends.thread = NIL_RTTHREAD;
1190 }
1191 else
1192 {
1193 /* Wait until the thread is ready. */
1194 rc = RTThreadUserWait (mUSBBackends.thread, 60000);
1195 AssertRC (rc);
1196 Assert (mUSBBackends.fThreadRunning || VBOX_FAILURE (rc));
1197 }
1198}
1199
1200void ConsoleVRDPServer::remoteUSBThreadStop (void)
1201{
1202 mUSBBackends.fThreadRunning = false;
1203
1204 if (mUSBBackends.thread != NIL_RTTHREAD)
1205 {
1206 Assert (mUSBBackends.event != 0);
1207
1208 RTSemEventSignal (mUSBBackends.event);
1209
1210 int rc = RTThreadWait (mUSBBackends.thread, 60000, NULL);
1211 AssertRC (rc);
1212
1213 mUSBBackends.thread = NIL_RTTHREAD;
1214 }
1215
1216 if (mUSBBackends.event)
1217 {
1218 RTSemEventDestroy (mUSBBackends.event);
1219 mUSBBackends.event = 0;
1220 }
1221}
1222#endif /* VBOX_WITH_USB */
1223
1224VRDPAuthResult ConsoleVRDPServer::Authenticate (const Guid &uuid, VRDPAuthGuestJudgement guestJudgement,
1225 const char *pszUser, const char *pszPassword, const char *pszDomain,
1226 uint32_t u32ClientId)
1227{
1228 VRDPAUTHUUID rawuuid;
1229
1230 memcpy (rawuuid, ((Guid &)uuid).ptr (), sizeof (rawuuid));
1231
1232 LogFlow(("ConsoleVRDPServer::Authenticate: uuid = %Vuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n",
1233 rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId));
1234
1235 /*
1236 * Called only from VRDP input thread. So thread safety is not required.
1237 */
1238
1239 if (!mAuthLibrary)
1240 {
1241 /* Load the external authentication library. */
1242
1243 ComPtr<IMachine> machine;
1244 mConsole->COMGETTER(Machine)(machine.asOutParam());
1245
1246 ComPtr<IVirtualBox> virtualBox;
1247 machine->COMGETTER(Parent)(virtualBox.asOutParam());
1248
1249 ComPtr<ISystemProperties> systemProperties;
1250 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
1251
1252 Bstr authLibrary;
1253 systemProperties->COMGETTER(RemoteDisplayAuthLibrary)(authLibrary.asOutParam());
1254
1255 Utf8Str filename = authLibrary;
1256
1257 LogRel(("VRDPAUTH: ConsoleVRDPServer::Authenticate: loading external authentication library '%ls'\n", authLibrary.raw()));
1258
1259 int rc = RTLdrLoad (filename.raw(), &mAuthLibrary);
1260 if (VBOX_FAILURE (rc))
1261 LogRel(("VRDPAUTH: Failed to load external authentication library. Error code: %Vrc\n", rc));
1262
1263 if (VBOX_SUCCESS (rc))
1264 {
1265 /* Get the entry point. */
1266 mpfnAuthEntry2 = NULL;
1267 int rc2 = RTLdrGetSymbol(mAuthLibrary, "VRDPAuth2", (void**)&mpfnAuthEntry2);
1268 if (VBOX_FAILURE (rc2))
1269 {
1270 LogRel(("VRDPAUTH: Could not resolve import '%s'. Error code: %Vrc\n", "VRDPAuth2", rc2));
1271 rc = rc2;
1272 }
1273
1274 /* Get the entry point. */
1275 mpfnAuthEntry = NULL;
1276 rc2 = RTLdrGetSymbol(mAuthLibrary, "VRDPAuth", (void**)&mpfnAuthEntry);
1277 if (VBOX_FAILURE (rc2))
1278 {
1279 LogRel(("VRDPAUTH: Could not resolve import '%s'. Error code: %Vrc\n", "VRDPAuth", rc2));
1280 rc = rc2;
1281 }
1282
1283 if (mpfnAuthEntry2 || mpfnAuthEntry)
1284 {
1285 LogRel(("VRDPAUTH: Using entry point '%s'.\n", mpfnAuthEntry2? "VRDPAuth2": "VRDPAuth"));
1286 rc = VINF_SUCCESS;
1287 }
1288 }
1289
1290 if (VBOX_FAILURE (rc))
1291 {
1292 mConsole->reportAuthLibraryError (filename.raw(), rc);
1293
1294 mpfnAuthEntry = NULL;
1295 mpfnAuthEntry2 = NULL;
1296
1297 if (mAuthLibrary)
1298 {
1299 RTLdrClose(mAuthLibrary);
1300 mAuthLibrary = 0;
1301 }
1302
1303 return VRDPAuthAccessDenied;
1304 }
1305 }
1306
1307 Assert (mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2));
1308
1309 VRDPAuthResult result = mpfnAuthEntry2?
1310 mpfnAuthEntry2 (&rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, true, u32ClientId):
1311 mpfnAuthEntry (&rawuuid, guestJudgement, pszUser, pszPassword, pszDomain);
1312
1313 switch (result)
1314 {
1315 case VRDPAuthAccessDenied:
1316 LogRel(("VRDPAUTH: external authentication module returned 'access denied'\n"));
1317 break;
1318 case VRDPAuthAccessGranted:
1319 LogRel(("VRDPAUTH: external authentication module returned 'access granted'\n"));
1320 break;
1321 case VRDPAuthDelegateToGuest:
1322 LogRel(("VRDPAUTH: external authentication module returned 'delegate request to guest'\n"));
1323 break;
1324 default:
1325 LogRel(("VRDPAUTH: external authentication module returned incorrect return code %d\n", result));
1326 result = VRDPAuthAccessDenied;
1327 }
1328
1329 LogFlow(("ConsoleVRDPServer::Authenticate: result = %d\n", result));
1330
1331 return result;
1332}
1333
1334void ConsoleVRDPServer::AuthDisconnect (const Guid &uuid, uint32_t u32ClientId)
1335{
1336 VRDPAUTHUUID rawuuid;
1337
1338 memcpy (rawuuid, ((Guid &)uuid).ptr (), sizeof (rawuuid));
1339
1340 LogFlow(("ConsoleVRDPServer::AuthDisconnect: uuid = %Vuuid, u32ClientId = %d\n",
1341 rawuuid, u32ClientId));
1342
1343 Assert (mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2));
1344
1345 if (mpfnAuthEntry2)
1346 mpfnAuthEntry2 (&rawuuid, VRDPAuthGuestNotAsked, NULL, NULL, NULL, false, u32ClientId);
1347}
1348
1349int ConsoleVRDPServer::lockConsoleVRDPServer (void)
1350{
1351 int rc = RTCritSectEnter (&mCritSect);
1352 AssertRC (rc);
1353 return rc;
1354}
1355
1356void ConsoleVRDPServer::unlockConsoleVRDPServer (void)
1357{
1358 RTCritSectLeave (&mCritSect);
1359}
1360
1361DECLCALLBACK(int) ConsoleVRDPServer::ClipboardCallback (void *pvCallback,
1362 uint32_t u32ClientId,
1363 uint32_t u32Function,
1364 uint32_t u32Format,
1365 const void *pvData,
1366 uint32_t cbData)
1367{
1368 LogFlowFunc(("pvCallback = %p, u32ClientId = %d, u32Function = %d, u32Format = 0x%08X, pvData = %p, cbData = %d\n",
1369 pvCallback, u32ClientId, u32Function, u32Format, pvData, cbData));
1370
1371 int rc = VINF_SUCCESS;
1372
1373 ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvCallback);
1374
1375 NOREF(u32ClientId);
1376
1377 switch (u32Function)
1378 {
1379 case VRDP_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE:
1380 {
1381 if (pServer->mpfnClipboardCallback)
1382 {
1383 pServer->mpfnClipboardCallback (VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
1384 u32Format,
1385 (void *)pvData,
1386 cbData);
1387 }
1388 } break;
1389
1390 case VRDP_CLIPBOARD_FUNCTION_DATA_READ:
1391 {
1392 if (pServer->mpfnClipboardCallback)
1393 {
1394 pServer->mpfnClipboardCallback (VBOX_CLIPBOARD_EXT_FN_DATA_READ,
1395 u32Format,
1396 (void *)pvData,
1397 cbData);
1398 }
1399 } break;
1400
1401 default:
1402 rc = VERR_NOT_SUPPORTED;
1403 }
1404
1405 return rc;
1406}
1407
1408DECLCALLBACK(int) ConsoleVRDPServer::ClipboardServiceExtension (void *pvExtension,
1409 uint32_t u32Function,
1410 void *pvParms,
1411 uint32_t cbParms)
1412{
1413 LogFlowFunc(("pvExtension = %p, u32Function = %d, pvParms = %p, cbParms = %d\n",
1414 pvExtension, u32Function, pvParms, cbParms));
1415
1416 int rc = VINF_SUCCESS;
1417
1418#ifdef VBOX_VRDP
1419 ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvExtension);
1420
1421 VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms;
1422
1423 switch (u32Function)
1424 {
1425 case VBOX_CLIPBOARD_EXT_FN_SET_CALLBACK:
1426 {
1427 pServer->mpfnClipboardCallback = (PFNVRDPCLIPBOARDEXTCALLBACK)pParms->pvData;
1428 } break;
1429
1430 case VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE:
1431 {
1432 /* The guest announces clipboard formats. This must be delivered to all clients. */
1433#ifdef VRDP_NO_COM
1434 if (mpEntryPoints && pServer->mhServer)
1435 {
1436 mpEntryPoints->VRDPClipboard (pServer->mhServer,
1437 VRDP_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE,
1438 pParms->u32Format,
1439 NULL,
1440 0,
1441 NULL);
1442 }
1443#else
1444 if (mpfnVRDPClipboard)
1445 {
1446 mpfnVRDPClipboard (pServer->mhServer,
1447 VRDP_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE,
1448 pParms->u32Format,
1449 NULL,
1450 0,
1451 NULL);
1452 }
1453#endif /* VRDP_NO_COM */
1454 } break;
1455
1456 case VBOX_CLIPBOARD_EXT_FN_DATA_READ:
1457 {
1458 /* The clipboard service expects that the pvData buffer will be filled
1459 * with clipboard data. The server returns the data from the client that
1460 * announced the requested format most recently.
1461 */
1462#ifdef VRDP_NO_COM
1463 if (mpEntryPoints && pServer->mhServer)
1464 {
1465 mpEntryPoints->VRDPClipboard (pServer->mhServer,
1466 VRDP_CLIPBOARD_FUNCTION_DATA_READ,
1467 pParms->u32Format,
1468 pParms->pvData,
1469 pParms->cbData,
1470 &pParms->cbData);
1471 }
1472#else
1473 if (mpfnVRDPClipboard)
1474 {
1475 mpfnVRDPClipboard (pServer->mhServer,
1476 VRDP_CLIPBOARD_FUNCTION_DATA_READ,
1477 pParms->u32Format,
1478 pParms->pvData,
1479 pParms->cbData,
1480 &pParms->cbData);
1481 }
1482#endif /* VRDP_NO_COM */
1483 } break;
1484
1485 case VBOX_CLIPBOARD_EXT_FN_DATA_WRITE:
1486 {
1487#ifdef VRDP_NO_COM
1488 if (mpEntryPoints && pServer->mhServer)
1489 {
1490 mpEntryPoints->VRDPClipboard (pServer->mhServer,
1491 VRDP_CLIPBOARD_FUNCTION_DATA_WRITE,
1492 pParms->u32Format,
1493 pParms->pvData,
1494 pParms->cbData,
1495 NULL);
1496 }
1497#else
1498 if (mpfnVRDPClipboard)
1499 {
1500 mpfnVRDPClipboard (pServer->mhServer,
1501 VRDP_CLIPBOARD_FUNCTION_DATA_WRITE,
1502 pParms->u32Format,
1503 pParms->pvData,
1504 pParms->cbData,
1505 NULL);
1506 }
1507#endif /* VRDP_NO_COM */
1508 } break;
1509
1510 default:
1511 rc = VERR_NOT_SUPPORTED;
1512 }
1513#endif /* VBOX_VRDP */
1514
1515 return rc;
1516}
1517
1518#ifdef VRDP_NO_COM
1519void ConsoleVRDPServer::ClipboardCreate (uint32_t u32ClientId)
1520#else
1521void ConsoleVRDPServer::ClipboardCreate (uint32_t u32ClientId, PFNVRDPCLIPBOARDCALLBACK *ppfn, void **ppv)
1522#endif /* VRDP_NO_COM */
1523{
1524 int rc = lockConsoleVRDPServer ();
1525
1526 if (VBOX_SUCCESS (rc))
1527 {
1528 if (mcClipboardRefs == 0)
1529 {
1530 rc = HGCMHostRegisterServiceExtension (&mhClipboard, "VBoxSharedClipboard", ClipboardServiceExtension, this);
1531
1532 if (VBOX_SUCCESS (rc))
1533 {
1534 mcClipboardRefs++;
1535 }
1536 }
1537
1538#ifdef VRDP_NO_COM
1539#else
1540 if (VBOX_SUCCESS (rc))
1541 {
1542 *ppfn = ClipboardCallback;
1543 *ppv = this;
1544 }
1545#endif /* VRDP_NO_COM */
1546
1547 unlockConsoleVRDPServer ();
1548 }
1549}
1550
1551void ConsoleVRDPServer::ClipboardDelete (uint32_t u32ClientId)
1552{
1553 int rc = lockConsoleVRDPServer ();
1554
1555 if (VBOX_SUCCESS (rc))
1556 {
1557 mcClipboardRefs--;
1558
1559 if (mcClipboardRefs == 0)
1560 {
1561 HGCMHostUnregisterServiceExtension (mhClipboard);
1562 }
1563
1564 unlockConsoleVRDPServer ();
1565 }
1566}
1567
1568/* That is called on INPUT thread of the VRDP server.
1569 * The ConsoleVRDPServer keeps a list of created backend instances.
1570 */
1571#ifdef VRDP_NO_COM
1572void ConsoleVRDPServer::USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept)
1573#else
1574void ConsoleVRDPServer::USBBackendCreate (uint32_t u32ClientId, PFNVRDPUSBCALLBACK *ppfn, void **ppv)
1575#endif /* VRDP_NO_COM */
1576{
1577#ifdef VBOX_WITH_USB
1578 LogFlow(("ConsoleVRDPServer::USBBackendCreate: u32ClientId = %d\n", u32ClientId));
1579
1580 /* Create a new instance of the USB backend for the new client. */
1581 RemoteUSBBackend *pRemoteUSBBackend = new RemoteUSBBackend (mConsole, this, u32ClientId);
1582
1583 if (pRemoteUSBBackend)
1584 {
1585 pRemoteUSBBackend->AddRef (); /* 'Release' called in USBBackendDelete. */
1586
1587 /* Append the new instance in the list. */
1588 int rc = lockConsoleVRDPServer ();
1589
1590 if (VBOX_SUCCESS (rc))
1591 {
1592 pRemoteUSBBackend->pNext = mUSBBackends.pHead;
1593 if (mUSBBackends.pHead)
1594 {
1595 mUSBBackends.pHead->pPrev = pRemoteUSBBackend;
1596 }
1597 else
1598 {
1599 mUSBBackends.pTail = pRemoteUSBBackend;
1600 }
1601
1602 mUSBBackends.pHead = pRemoteUSBBackend;
1603
1604 unlockConsoleVRDPServer ();
1605
1606#ifdef VRDP_NO_COM
1607 if (ppvIntercept)
1608 {
1609 *ppvIntercept = pRemoteUSBBackend;
1610 }
1611#else
1612 pRemoteUSBBackend->QueryVRDPCallbackPointer (ppfn, ppv);
1613#endif /* VRDP_NO_COM */
1614 }
1615
1616 if (VBOX_FAILURE (rc))
1617 {
1618 pRemoteUSBBackend->Release ();
1619 }
1620 }
1621#endif /* VBOX_WITH_USB */
1622}
1623
1624void ConsoleVRDPServer::USBBackendDelete (uint32_t u32ClientId)
1625{
1626#ifdef VBOX_WITH_USB
1627 LogFlow(("ConsoleVRDPServer::USBBackendDelete: u32ClientId = %d\n", u32ClientId));
1628
1629 RemoteUSBBackend *pRemoteUSBBackend = NULL;
1630
1631 /* Find the instance. */
1632 int rc = lockConsoleVRDPServer ();
1633
1634 if (VBOX_SUCCESS (rc))
1635 {
1636 pRemoteUSBBackend = usbBackendFind (u32ClientId);
1637
1638 if (pRemoteUSBBackend)
1639 {
1640 /* Notify that it will be deleted. */
1641 pRemoteUSBBackend->NotifyDelete ();
1642 }
1643
1644 unlockConsoleVRDPServer ();
1645 }
1646
1647 if (pRemoteUSBBackend)
1648 {
1649 /* Here the instance has been excluded from the list and can be dereferenced. */
1650 pRemoteUSBBackend->Release ();
1651 }
1652#endif
1653}
1654
1655void *ConsoleVRDPServer::USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid)
1656{
1657#ifdef VBOX_WITH_USB
1658 RemoteUSBBackend *pRemoteUSBBackend = NULL;
1659
1660 /* Find the instance. */
1661 int rc = lockConsoleVRDPServer ();
1662
1663 if (VBOX_SUCCESS (rc))
1664 {
1665 pRemoteUSBBackend = usbBackendFind (u32ClientId);
1666
1667 if (pRemoteUSBBackend)
1668 {
1669 /* Inform the backend instance that it is referenced by the Guid. */
1670 bool fAdded = pRemoteUSBBackend->addUUID (pGuid);
1671
1672 if (fAdded)
1673 {
1674 /* Reference the instance because its pointer is being taken. */
1675 pRemoteUSBBackend->AddRef (); /* 'Release' is called in USBBackendReleasePointer. */
1676 }
1677 else
1678 {
1679 pRemoteUSBBackend = NULL;
1680 }
1681 }
1682
1683 unlockConsoleVRDPServer ();
1684 }
1685
1686 if (pRemoteUSBBackend)
1687 {
1688 return pRemoteUSBBackend->GetBackendCallbackPointer ();
1689 }
1690
1691#endif
1692 return NULL;
1693}
1694
1695void ConsoleVRDPServer::USBBackendReleasePointer (const Guid *pGuid)
1696{
1697#ifdef VBOX_WITH_USB
1698 RemoteUSBBackend *pRemoteUSBBackend = NULL;
1699
1700 /* Find the instance. */
1701 int rc = lockConsoleVRDPServer ();
1702
1703 if (VBOX_SUCCESS (rc))
1704 {
1705 pRemoteUSBBackend = usbBackendFindByUUID (pGuid);
1706
1707 if (pRemoteUSBBackend)
1708 {
1709 pRemoteUSBBackend->removeUUID (pGuid);
1710 }
1711
1712 unlockConsoleVRDPServer ();
1713
1714 if (pRemoteUSBBackend)
1715 {
1716 pRemoteUSBBackend->Release ();
1717 }
1718 }
1719#endif
1720}
1721
1722RemoteUSBBackend *ConsoleVRDPServer::usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend)
1723{
1724 LogFlow(("ConsoleVRDPServer::usbBackendGetNext: pBackend = %p\n", pRemoteUSBBackend));
1725
1726 RemoteUSBBackend *pNextRemoteUSBBackend = NULL;
1727#ifdef VBOX_WITH_USB
1728
1729 int rc = lockConsoleVRDPServer ();
1730
1731 if (VBOX_SUCCESS (rc))
1732 {
1733 if (pRemoteUSBBackend == NULL)
1734 {
1735 /* The first backend in the list is requested. */
1736 pNextRemoteUSBBackend = mUSBBackends.pHead;
1737 }
1738 else
1739 {
1740 /* Get pointer to the next backend. */
1741 pNextRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
1742 }
1743
1744 if (pNextRemoteUSBBackend)
1745 {
1746 pNextRemoteUSBBackend->AddRef ();
1747 }
1748
1749 unlockConsoleVRDPServer ();
1750
1751 if (pRemoteUSBBackend)
1752 {
1753 pRemoteUSBBackend->Release ();
1754 }
1755 }
1756#endif
1757
1758 return pNextRemoteUSBBackend;
1759}
1760
1761#ifdef VBOX_WITH_USB
1762/* Internal method. Called under the ConsoleVRDPServerLock. */
1763RemoteUSBBackend *ConsoleVRDPServer::usbBackendFind (uint32_t u32ClientId)
1764{
1765 RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
1766
1767 while (pRemoteUSBBackend)
1768 {
1769 if (pRemoteUSBBackend->ClientId () == u32ClientId)
1770 {
1771 break;
1772 }
1773
1774 pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
1775 }
1776
1777 return pRemoteUSBBackend;
1778}
1779
1780/* Internal method. Called under the ConsoleVRDPServerLock. */
1781RemoteUSBBackend *ConsoleVRDPServer::usbBackendFindByUUID (const Guid *pGuid)
1782{
1783 RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
1784
1785 while (pRemoteUSBBackend)
1786 {
1787 if (pRemoteUSBBackend->findUUID (pGuid))
1788 {
1789 break;
1790 }
1791
1792 pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
1793 }
1794
1795 return pRemoteUSBBackend;
1796}
1797#endif
1798
1799/* Internal method. Called by the backend destructor. */
1800void ConsoleVRDPServer::usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend)
1801{
1802#ifdef VBOX_WITH_USB
1803 int rc = lockConsoleVRDPServer ();
1804 AssertRC (rc);
1805
1806 /* Exclude the found instance from the list. */
1807 if (pRemoteUSBBackend->pNext)
1808 {
1809 pRemoteUSBBackend->pNext->pPrev = pRemoteUSBBackend->pPrev;
1810 }
1811 else
1812 {
1813 mUSBBackends.pTail = (RemoteUSBBackend *)pRemoteUSBBackend->pPrev;
1814 }
1815
1816 if (pRemoteUSBBackend->pPrev)
1817 {
1818 pRemoteUSBBackend->pPrev->pNext = pRemoteUSBBackend->pNext;
1819 }
1820 else
1821 {
1822 mUSBBackends.pHead = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
1823 }
1824
1825 pRemoteUSBBackend->pNext = pRemoteUSBBackend->pPrev = NULL;
1826
1827 unlockConsoleVRDPServer ();
1828#endif
1829}
1830
1831
1832void ConsoleVRDPServer::SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const
1833{
1834#ifdef VBOX_VRDP
1835#ifdef VRDP_NO_COM
1836 if (mpEntryPoints && mhServer)
1837 {
1838 mpEntryPoints->VRDPUpdate (mhServer, uScreenId, pvUpdate, cbUpdate);
1839 }
1840#else
1841 if (mpfnVRDPSendUpdate)
1842 mpfnVRDPSendUpdate (mhServer, uScreenId, pvUpdate, cbUpdate);
1843#endif /* VRDP_NO_COM */
1844#endif
1845}
1846
1847void ConsoleVRDPServer::SendResize (void) const
1848{
1849#ifdef VBOX_VRDP
1850#ifdef VRDP_NO_COM
1851 if (mpEntryPoints && mhServer)
1852 {
1853 mpEntryPoints->VRDPResize (mhServer);
1854 }
1855#else
1856 if (mpfnVRDPSendResize)
1857 mpfnVRDPSendResize (mhServer);
1858#endif /* VRDP_NO_COM */
1859#endif
1860}
1861
1862void ConsoleVRDPServer::SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const
1863{
1864#ifdef VBOX_VRDP
1865#ifdef VRDP_NO_COM
1866 VRDPORDERHDR update;
1867 update.x = x;
1868 update.y = y;
1869 update.w = w;
1870 update.h = h;
1871 if (mpEntryPoints && mhServer)
1872 {
1873 mpEntryPoints->VRDPUpdate (mhServer, uScreenId, &update, sizeof (update));
1874 }
1875#else
1876 if (mpfnVRDPSendUpdateBitmap)
1877 mpfnVRDPSendUpdateBitmap (mhServer, uScreenId, x, y, w, h);
1878#endif /* VRDP_NO_COM */
1879#endif
1880}
1881
1882#ifdef VRDP_NO_COM
1883#else
1884void ConsoleVRDPServer::SetFramebuffer (IFramebuffer *framebuffer, uint32_t fFlags) const
1885{
1886#ifdef VBOX_VRDP
1887 if (mpfnVRDPSetFramebuffer)
1888 mpfnVRDPSetFramebuffer (mhServer, framebuffer, fFlags);
1889#endif
1890}
1891#endif /* VRDP_NO_COM */
1892
1893void ConsoleVRDPServer::SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format) const
1894{
1895#ifdef VBOX_VRDP
1896#ifdef VRDP_NO_COM
1897 if (mpEntryPoints && mhServer)
1898 {
1899 mpEntryPoints->VRDPAudioSamples (mhServer, pvSamples, cSamples, format);
1900 }
1901#else
1902 if (mpfnVRDPSendAudioSamples)
1903 mpfnVRDPSendAudioSamples (mhServer, pvSamples, cSamples, format);
1904#endif /* VRDP_NO_COM */
1905#endif
1906}
1907
1908void ConsoleVRDPServer::SendAudioVolume (uint16_t left, uint16_t right) const
1909{
1910#ifdef VBOX_VRDP
1911#ifdef VRDP_NO_COM
1912 if (mpEntryPoints && mhServer)
1913 {
1914 mpEntryPoints->VRDPAudioVolume (mhServer, left, right);
1915 }
1916#else
1917 if (mpfnVRDPSendAudioVolume)
1918 mpfnVRDPSendAudioVolume (mhServer, left, right);
1919#endif /* VRDP_NO_COM */
1920#endif
1921}
1922
1923void ConsoleVRDPServer::SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const
1924{
1925#ifdef VBOX_VRDP
1926#ifdef VRDP_NO_COM
1927 if (mpEntryPoints && mhServer)
1928 {
1929 mpEntryPoints->VRDPUSBRequest (mhServer, u32ClientId, pvParms, cbParms);
1930 }
1931#else
1932 if (mpfnVRDPSendUSBRequest)
1933 mpfnVRDPSendUSBRequest (mhServer, u32ClientId, pvParms, cbParms);
1934#endif /* VRDP_NO_COM */
1935#endif
1936}
1937
1938void ConsoleVRDPServer::QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const
1939{
1940#ifdef VBOX_VRDP
1941#ifdef VRDP_NO_COM
1942 if (mpEntryPoints && mhServer)
1943 {
1944 mpEntryPoints->VRDPQueryInfo (mhServer, index, pvBuffer, cbBuffer, pcbOut);
1945 }
1946#else
1947 if (mpfnVRDPQueryInfo)
1948 mpfnVRDPQueryInfo (mhServer, index, pvBuffer, cbBuffer, pcbOut);
1949#endif /* VRDP_NO_COM */
1950#endif
1951}
1952
1953#ifdef VBOX_VRDP
1954/* note: static function now! */
1955bool ConsoleVRDPServer::loadVRDPLibrary (void)
1956{
1957 int rc = VINF_SUCCESS;
1958
1959 if (!mVRDPLibrary)
1960 {
1961 rc = RTLdrLoad("VBoxVRDP", &mVRDPLibrary);
1962
1963 if (VBOX_SUCCESS(rc))
1964 {
1965 LogFlow(("VRDPServer::loadLibrary(): successfully loaded VRDP library.\n"));
1966
1967 struct SymbolEntry
1968 {
1969 const char *name;
1970 void **ppfn;
1971 };
1972
1973 #define DEFSYMENTRY(a) { #a, (void**)&mpfn##a }
1974
1975#ifdef VRDP_NO_COM
1976 static const struct SymbolEntry symbols[] =
1977 {
1978 DEFSYMENTRY(VRDPCreateServer)
1979 };
1980#else
1981 static const struct SymbolEntry symbols[] =
1982 {
1983 DEFSYMENTRY(VRDPStartServer),
1984 DEFSYMENTRY(VRDPSetCallback),
1985 DEFSYMENTRY(VRDPShutdownServer),
1986 DEFSYMENTRY(VRDPSendUpdate),
1987 DEFSYMENTRY(VRDPSendUpdateBitmap),
1988 DEFSYMENTRY(VRDPSendResize),
1989 DEFSYMENTRY(VRDPSendAudioSamples),
1990 DEFSYMENTRY(VRDPSendAudioVolume),
1991 DEFSYMENTRY(VRDPSendUSBRequest),
1992 DEFSYMENTRY(VRDPQueryInfo),
1993 DEFSYMENTRY(VRDPClipboard)
1994 };
1995#endif /* VRDP_NO_COM */
1996
1997 #undef DEFSYMENTRY
1998
1999 for (unsigned i = 0; i < ELEMENTS(symbols); i++)
2000 {
2001 rc = RTLdrGetSymbol(mVRDPLibrary, symbols[i].name, symbols[i].ppfn);
2002
2003 AssertMsgRC(rc, ("Error resolving VRDP symbol %s\n", symbols[i].name));
2004
2005 if (VBOX_FAILURE(rc))
2006 {
2007 break;
2008 }
2009 }
2010 }
2011 else
2012 {
2013 LogFlow(("VRDPServer::loadLibrary(): failed to load VRDP library! VRDP not available.\n"));
2014 mVRDPLibrary = NULL;
2015 }
2016 }
2017
2018 // just to be safe
2019 if (VBOX_FAILURE(rc))
2020 {
2021 if (mVRDPLibrary)
2022 {
2023 RTLdrClose (mVRDPLibrary);
2024 mVRDPLibrary = NULL;
2025 }
2026 }
2027
2028 return (mVRDPLibrary != NULL);
2029}
2030#endif /* VBOX_VRDP */
2031
2032/*
2033 * IRemoteDisplayInfo implementation.
2034 */
2035// constructor / destructor
2036/////////////////////////////////////////////////////////////////////////////
2037
2038HRESULT RemoteDisplayInfo::FinalConstruct()
2039{
2040 return S_OK;
2041}
2042
2043void RemoteDisplayInfo::FinalRelease()
2044{
2045 if (isReady())
2046 uninit ();
2047}
2048
2049// public methods only for internal purposes
2050/////////////////////////////////////////////////////////////////////////////
2051
2052/**
2053 * Initializes the guest object.
2054 */
2055HRESULT RemoteDisplayInfo::init (Console *aParent)
2056{
2057 LogFlowMember (("RemoteDisplayInfo::init (%p)\n", aParent));
2058
2059 ComAssertRet (aParent, E_INVALIDARG);
2060
2061 AutoLock alock (this);
2062 ComAssertRet (!isReady(), E_UNEXPECTED);
2063
2064 mParent = aParent;
2065
2066 setReady (true);
2067 return S_OK;
2068}
2069
2070/**
2071 * Uninitializes the instance and sets the ready flag to FALSE.
2072 * Called either from FinalRelease() or by the parent when it gets destroyed.
2073 */
2074void RemoteDisplayInfo::uninit()
2075{
2076 LogFlowMember (("RemoteDisplayInfo::uninit()\n"));
2077
2078 AutoLock alock (this);
2079 AssertReturn (isReady(), (void) 0);
2080
2081 mParent.setNull();
2082
2083 setReady (false);
2084}
2085
2086// IRemoteDisplayInfo properties
2087/////////////////////////////////////////////////////////////////////////////
2088
2089#define IMPL_GETTER_BOOL(_aType, _aName, _aIndex) \
2090 STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
2091 { \
2092 if (!a##_aName) \
2093 return E_POINTER; \
2094 \
2095 AutoLock alock (this); \
2096 CHECK_READY(); \
2097 \
2098 uint32_t value; \
2099 uint32_t cbOut = 0; \
2100 \
2101 mParent->consoleVRDPServer ()->QueryInfo \
2102 (_aIndex, &value, sizeof (value), &cbOut); \
2103 \
2104 *a##_aName = cbOut? !!value: FALSE; \
2105 \
2106 return S_OK; \
2107 }
2108
2109#define IMPL_GETTER_SCALAR(_aType, _aName, _aIndex) \
2110 STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
2111 { \
2112 if (!a##_aName) \
2113 return E_POINTER; \
2114 \
2115 AutoLock alock (this); \
2116 CHECK_READY(); \
2117 \
2118 _aType value; \
2119 uint32_t cbOut = 0; \
2120 \
2121 mParent->consoleVRDPServer ()->QueryInfo \
2122 (_aIndex, &value, sizeof (value), &cbOut); \
2123 \
2124 *a##_aName = cbOut? value: 0; \
2125 \
2126 return S_OK; \
2127 }
2128
2129#define IMPL_GETTER_BSTR(_aType, _aName, _aIndex) \
2130 STDMETHODIMP RemoteDisplayInfo::COMGETTER(_aName) (_aType *a##_aName) \
2131 { \
2132 if (!a##_aName) \
2133 return E_POINTER; \
2134 \
2135 AutoLock alock (this); \
2136 CHECK_READY(); \
2137 \
2138 uint32_t cbOut = 0; \
2139 \
2140 mParent->consoleVRDPServer ()->QueryInfo \
2141 (_aIndex, NULL, 0, &cbOut); \
2142 \
2143 if (cbOut == 0) \
2144 { \
2145 Bstr str(""); \
2146 str.cloneTo (a##_aName); \
2147 return S_OK; \
2148 } \
2149 \
2150 char *pchBuffer = (char *)RTMemTmpAlloc (cbOut); \
2151 \
2152 if (!pchBuffer) \
2153 { \
2154 Log(("RemoteDisplayInfo::" \
2155 #_aName \
2156 ": Failed to allocate memory %d bytes\n", cbOut)); \
2157 return E_OUTOFMEMORY; \
2158 } \
2159 \
2160 mParent->consoleVRDPServer ()->QueryInfo \
2161 (_aIndex, pchBuffer, cbOut, &cbOut); \
2162 \
2163 Bstr str(pchBuffer); \
2164 \
2165 str.cloneTo (a##_aName); \
2166 \
2167 RTMemTmpFree (pchBuffer); \
2168 \
2169 return S_OK; \
2170 }
2171
2172IMPL_GETTER_BOOL (BOOL, Active, VRDP_QI_ACTIVE);
2173IMPL_GETTER_SCALAR (ULONG, NumberOfClients, VRDP_QI_NUMBER_OF_CLIENTS);
2174IMPL_GETTER_SCALAR (LONG64, BeginTime, VRDP_QI_BEGIN_TIME);
2175IMPL_GETTER_SCALAR (LONG64, EndTime, VRDP_QI_END_TIME);
2176IMPL_GETTER_SCALAR (ULONG64, BytesSent, VRDP_QI_BYTES_SENT);
2177IMPL_GETTER_SCALAR (ULONG64, BytesSentTotal, VRDP_QI_BYTES_SENT_TOTAL);
2178IMPL_GETTER_SCALAR (ULONG64, BytesReceived, VRDP_QI_BYTES_RECEIVED);
2179IMPL_GETTER_SCALAR (ULONG64, BytesReceivedTotal, VRDP_QI_BYTES_RECEIVED_TOTAL);
2180IMPL_GETTER_BSTR (BSTR, User, VRDP_QI_USER);
2181IMPL_GETTER_BSTR (BSTR, Domain, VRDP_QI_DOMAIN);
2182IMPL_GETTER_BSTR (BSTR, ClientName, VRDP_QI_CLIENT_NAME);
2183IMPL_GETTER_BSTR (BSTR, ClientIP, VRDP_QI_CLIENT_IP);
2184IMPL_GETTER_SCALAR (ULONG, ClientVersion, VRDP_QI_CLIENT_VERSION);
2185IMPL_GETTER_SCALAR (ULONG, EncryptionStyle, VRDP_QI_ENCRYPTION_STYLE);
2186
2187#undef IMPL_GETTER_BSTR
2188#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