VirtualBox

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

Last change on this file since 4122 was 4093, checked in by vboxsync, 18 years ago

Fixed missing black edge for Windows Vista alpha pointers over RDP.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette