VirtualBox

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

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

Do not call the VRDP server when it is being terminated.

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