VirtualBox

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

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

More release logging for the VRDP server startup failures.

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