VirtualBox

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

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

VRDP server: fixed error handling if the VRDP library could not be loaded

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