VirtualBox

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

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

The Giant CDDL Dual-License Header Change.

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