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