VirtualBox

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

Last change on this file since 17698 was 17669, checked in by vboxsync, 16 years ago

Main: Rework storage controller handling to allow an arbitrary number of different storage controllers and remove code duplication:

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