1 | /* $Id: ConsoleVRDPServer.cpp 80377 2019-08-21 17:50:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Console VRDP helper class.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
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 | #define LOG_GROUP LOG_GROUP_MAIN_CONSOLE
|
---|
19 | #include "LoggingNew.h"
|
---|
20 |
|
---|
21 | #include "ConsoleVRDPServer.h"
|
---|
22 | #include "ConsoleImpl.h"
|
---|
23 | #include "DisplayImpl.h"
|
---|
24 | #include "KeyboardImpl.h"
|
---|
25 | #include "MouseImpl.h"
|
---|
26 | #ifdef VBOX_WITH_AUDIO_VRDE
|
---|
27 | #include "DrvAudioVRDE.h"
|
---|
28 | #endif
|
---|
29 | #ifdef VBOX_WITH_EXTPACK
|
---|
30 | # include "ExtPackManagerImpl.h"
|
---|
31 | #endif
|
---|
32 | #include "VMMDev.h"
|
---|
33 | #ifdef VBOX_WITH_USB_CARDREADER
|
---|
34 | # include "UsbCardReader.h"
|
---|
35 | #endif
|
---|
36 | #include "UsbWebcamInterface.h"
|
---|
37 |
|
---|
38 | #include "Global.h"
|
---|
39 | #include "AutoCaller.h"
|
---|
40 |
|
---|
41 | #include <iprt/asm.h>
|
---|
42 | #include <iprt/alloca.h>
|
---|
43 | #include <iprt/ldr.h>
|
---|
44 | #include <iprt/param.h>
|
---|
45 | #include <iprt/path.h>
|
---|
46 | #include <iprt/cpp/utils.h>
|
---|
47 |
|
---|
48 | #include <VBox/err.h>
|
---|
49 | #include <VBox/RemoteDesktop/VRDEOrders.h>
|
---|
50 | #include <VBox/com/listeners.h>
|
---|
51 |
|
---|
52 |
|
---|
53 | class VRDPConsoleListener
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | VRDPConsoleListener()
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | virtual ~VRDPConsoleListener()
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 | HRESULT init(ConsoleVRDPServer *server)
|
---|
65 | {
|
---|
66 | m_server = server;
|
---|
67 | return S_OK;
|
---|
68 | }
|
---|
69 |
|
---|
70 | void uninit()
|
---|
71 | {
|
---|
72 | }
|
---|
73 |
|
---|
74 | STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
|
---|
75 | {
|
---|
76 | switch (aType)
|
---|
77 | {
|
---|
78 | case VBoxEventType_OnMousePointerShapeChanged:
|
---|
79 | {
|
---|
80 | ComPtr<IMousePointerShapeChangedEvent> mpscev = aEvent;
|
---|
81 | Assert(mpscev);
|
---|
82 | BOOL visible, alpha;
|
---|
83 | ULONG xHot, yHot, width, height;
|
---|
84 | com::SafeArray <BYTE> shape;
|
---|
85 |
|
---|
86 | mpscev->COMGETTER(Visible)(&visible);
|
---|
87 | mpscev->COMGETTER(Alpha)(&alpha);
|
---|
88 | mpscev->COMGETTER(Xhot)(&xHot);
|
---|
89 | mpscev->COMGETTER(Yhot)(&yHot);
|
---|
90 | mpscev->COMGETTER(Width)(&width);
|
---|
91 | mpscev->COMGETTER(Height)(&height);
|
---|
92 | mpscev->COMGETTER(Shape)(ComSafeArrayAsOutParam(shape));
|
---|
93 |
|
---|
94 | m_server->onMousePointerShapeChange(visible, alpha, xHot, yHot, width, height, ComSafeArrayAsInParam(shape));
|
---|
95 | break;
|
---|
96 | }
|
---|
97 | case VBoxEventType_OnMouseCapabilityChanged:
|
---|
98 | {
|
---|
99 | ComPtr<IMouseCapabilityChangedEvent> mccev = aEvent;
|
---|
100 | Assert(mccev);
|
---|
101 | if (m_server)
|
---|
102 | {
|
---|
103 | BOOL fAbsoluteMouse;
|
---|
104 | mccev->COMGETTER(SupportsAbsolute)(&fAbsoluteMouse);
|
---|
105 | m_server->NotifyAbsoluteMouse(!!fAbsoluteMouse);
|
---|
106 | }
|
---|
107 | break;
|
---|
108 | }
|
---|
109 | case VBoxEventType_OnKeyboardLedsChanged:
|
---|
110 | {
|
---|
111 | ComPtr<IKeyboardLedsChangedEvent> klcev = aEvent;
|
---|
112 | Assert(klcev);
|
---|
113 |
|
---|
114 | if (m_server)
|
---|
115 | {
|
---|
116 | BOOL fNumLock, fCapsLock, fScrollLock;
|
---|
117 | klcev->COMGETTER(NumLock)(&fNumLock);
|
---|
118 | klcev->COMGETTER(CapsLock)(&fCapsLock);
|
---|
119 | klcev->COMGETTER(ScrollLock)(&fScrollLock);
|
---|
120 | m_server->NotifyKeyboardLedsChange(fNumLock, fCapsLock, fScrollLock);
|
---|
121 | }
|
---|
122 | break;
|
---|
123 | }
|
---|
124 |
|
---|
125 | default:
|
---|
126 | AssertFailed();
|
---|
127 | }
|
---|
128 |
|
---|
129 | return S_OK;
|
---|
130 | }
|
---|
131 |
|
---|
132 | private:
|
---|
133 | ConsoleVRDPServer *m_server;
|
---|
134 | };
|
---|
135 |
|
---|
136 | typedef ListenerImpl<VRDPConsoleListener, ConsoleVRDPServer*> VRDPConsoleListenerImpl;
|
---|
137 |
|
---|
138 | VBOX_LISTENER_DECLARE(VRDPConsoleListenerImpl)
|
---|
139 |
|
---|
140 | #ifdef DEBUG_sunlover
|
---|
141 | #define LOGDUMPPTR Log
|
---|
142 | void dumpPointer(const uint8_t *pu8Shape, uint32_t width, uint32_t height, bool fXorMaskRGB32)
|
---|
143 | {
|
---|
144 | unsigned i;
|
---|
145 |
|
---|
146 | const uint8_t *pu8And = pu8Shape;
|
---|
147 |
|
---|
148 | for (i = 0; i < height; i++)
|
---|
149 | {
|
---|
150 | unsigned j;
|
---|
151 | LOGDUMPPTR(("%p: ", pu8And));
|
---|
152 | for (j = 0; j < (width + 7) / 8; j++)
|
---|
153 | {
|
---|
154 | unsigned k;
|
---|
155 | for (k = 0; k < 8; k++)
|
---|
156 | {
|
---|
157 | LOGDUMPPTR(("%d", ((*pu8And) & (1 << (7 - k)))? 1: 0));
|
---|
158 | }
|
---|
159 |
|
---|
160 | pu8And++;
|
---|
161 | }
|
---|
162 | LOGDUMPPTR(("\n"));
|
---|
163 | }
|
---|
164 |
|
---|
165 | if (fXorMaskRGB32)
|
---|
166 | {
|
---|
167 | uint32_t *pu32Xor = (uint32_t*)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
|
---|
168 |
|
---|
169 | for (i = 0; i < height; i++)
|
---|
170 | {
|
---|
171 | unsigned j;
|
---|
172 | LOGDUMPPTR(("%p: ", pu32Xor));
|
---|
173 | for (j = 0; j < width; j++)
|
---|
174 | {
|
---|
175 | LOGDUMPPTR(("%08X", *pu32Xor++));
|
---|
176 | }
|
---|
177 | LOGDUMPPTR(("\n"));
|
---|
178 | }
|
---|
179 | }
|
---|
180 | else
|
---|
181 | {
|
---|
182 | /* RDP 24 bit RGB mask. */
|
---|
183 | uint8_t *pu8Xor = (uint8_t*)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
|
---|
184 | for (i = 0; i < height; i++)
|
---|
185 | {
|
---|
186 | unsigned j;
|
---|
187 | LOGDUMPPTR(("%p: ", pu8Xor));
|
---|
188 | for (j = 0; j < width; j++)
|
---|
189 | {
|
---|
190 | LOGDUMPPTR(("%02X%02X%02X", pu8Xor[2], pu8Xor[1], pu8Xor[0]));
|
---|
191 | pu8Xor += 3;
|
---|
192 | }
|
---|
193 | LOGDUMPPTR(("\n"));
|
---|
194 | }
|
---|
195 | }
|
---|
196 | }
|
---|
197 | #else
|
---|
198 | #define dumpPointer(a, b, c, d) do {} while (0)
|
---|
199 | #endif /* DEBUG_sunlover */
|
---|
200 |
|
---|
201 | static void findTopLeftBorder(const uint8_t *pu8AndMask, const uint8_t *pu8XorMask, uint32_t width,
|
---|
202 | uint32_t height, uint32_t *pxSkip, uint32_t *pySkip)
|
---|
203 | {
|
---|
204 | /*
|
---|
205 | * Find the top border of the AND mask. First assign to special value.
|
---|
206 | */
|
---|
207 | uint32_t ySkipAnd = UINT32_MAX;
|
---|
208 |
|
---|
209 | const uint8_t *pu8And = pu8AndMask;
|
---|
210 | const uint32_t cbAndRow = (width + 7) / 8;
|
---|
211 | const uint8_t maskLastByte = (uint8_t)( 0xFF << (cbAndRow * 8 - width) );
|
---|
212 |
|
---|
213 | Assert(cbAndRow > 0);
|
---|
214 |
|
---|
215 | unsigned y;
|
---|
216 | unsigned x;
|
---|
217 |
|
---|
218 | for (y = 0; y < height && ySkipAnd == ~(uint32_t)0; y++, pu8And += cbAndRow)
|
---|
219 | {
|
---|
220 | /* For each complete byte in the row. */
|
---|
221 | for (x = 0; x < cbAndRow - 1; x++)
|
---|
222 | {
|
---|
223 | if (pu8And[x] != 0xFF)
|
---|
224 | {
|
---|
225 | ySkipAnd = y;
|
---|
226 | break;
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | if (ySkipAnd == ~(uint32_t)0)
|
---|
231 | {
|
---|
232 | /* Last byte. */
|
---|
233 | if ((pu8And[cbAndRow - 1] & maskLastByte) != maskLastByte)
|
---|
234 | {
|
---|
235 | ySkipAnd = y;
|
---|
236 | }
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 | if (ySkipAnd == ~(uint32_t)0)
|
---|
241 | {
|
---|
242 | ySkipAnd = 0;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /*
|
---|
246 | * Find the left border of the AND mask.
|
---|
247 | */
|
---|
248 | uint32_t xSkipAnd = UINT32_MAX;
|
---|
249 |
|
---|
250 | /* For all bit columns. */
|
---|
251 | for (x = 0; x < width && xSkipAnd == ~(uint32_t)0; x++)
|
---|
252 | {
|
---|
253 | pu8And = pu8AndMask + x/8; /* Currently checking byte. */
|
---|
254 | uint8_t mask = 1 << (7 - x%8); /* Currently checking bit in the byte. */
|
---|
255 |
|
---|
256 | for (y = ySkipAnd; y < height; y++, pu8And += cbAndRow)
|
---|
257 | {
|
---|
258 | if ((*pu8And & mask) == 0)
|
---|
259 | {
|
---|
260 | xSkipAnd = x;
|
---|
261 | break;
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 |
|
---|
266 | if (xSkipAnd == ~(uint32_t)0)
|
---|
267 | {
|
---|
268 | xSkipAnd = 0;
|
---|
269 | }
|
---|
270 |
|
---|
271 | /*
|
---|
272 | * Find the XOR mask top border.
|
---|
273 | */
|
---|
274 | uint32_t ySkipXor = UINT32_MAX;
|
---|
275 |
|
---|
276 | uint32_t *pu32XorStart = (uint32_t *)pu8XorMask;
|
---|
277 |
|
---|
278 | uint32_t *pu32Xor = pu32XorStart;
|
---|
279 |
|
---|
280 | for (y = 0; y < height && ySkipXor == ~(uint32_t)0; y++, pu32Xor += width)
|
---|
281 | {
|
---|
282 | for (x = 0; x < width; x++)
|
---|
283 | {
|
---|
284 | if (pu32Xor[x] != 0)
|
---|
285 | {
|
---|
286 | ySkipXor = y;
|
---|
287 | break;
|
---|
288 | }
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | if (ySkipXor == ~(uint32_t)0)
|
---|
293 | {
|
---|
294 | ySkipXor = 0;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /*
|
---|
298 | * Find the left border of the XOR mask.
|
---|
299 | */
|
---|
300 | uint32_t xSkipXor = ~(uint32_t)0;
|
---|
301 |
|
---|
302 | /* For all columns. */
|
---|
303 | for (x = 0; x < width && xSkipXor == ~(uint32_t)0; x++)
|
---|
304 | {
|
---|
305 | pu32Xor = pu32XorStart + x; /* Currently checking dword. */
|
---|
306 |
|
---|
307 | for (y = ySkipXor; y < height; y++, pu32Xor += width)
|
---|
308 | {
|
---|
309 | if (*pu32Xor != 0)
|
---|
310 | {
|
---|
311 | xSkipXor = x;
|
---|
312 | break;
|
---|
313 | }
|
---|
314 | }
|
---|
315 | }
|
---|
316 |
|
---|
317 | if (xSkipXor == ~(uint32_t)0)
|
---|
318 | {
|
---|
319 | xSkipXor = 0;
|
---|
320 | }
|
---|
321 |
|
---|
322 | *pxSkip = RT_MIN(xSkipAnd, xSkipXor);
|
---|
323 | *pySkip = RT_MIN(ySkipAnd, ySkipXor);
|
---|
324 | }
|
---|
325 |
|
---|
326 | /* Generate an AND mask for alpha pointers here, because
|
---|
327 | * guest driver does not do that correctly for Vista pointers.
|
---|
328 | * Similar fix, changing the alpha threshold, could be applied
|
---|
329 | * for the guest driver, but then additions reinstall would be
|
---|
330 | * necessary, which we try to avoid.
|
---|
331 | */
|
---|
332 | static void mousePointerGenerateANDMask(uint8_t *pu8DstAndMask, int cbDstAndMask, const uint8_t *pu8SrcAlpha, int w, int h)
|
---|
333 | {
|
---|
334 | memset(pu8DstAndMask, 0xFF, cbDstAndMask);
|
---|
335 |
|
---|
336 | int y;
|
---|
337 | for (y = 0; y < h; y++)
|
---|
338 | {
|
---|
339 | uint8_t bitmask = 0x80;
|
---|
340 |
|
---|
341 | int x;
|
---|
342 | for (x = 0; x < w; x++, bitmask >>= 1)
|
---|
343 | {
|
---|
344 | if (bitmask == 0)
|
---|
345 | {
|
---|
346 | bitmask = 0x80;
|
---|
347 | }
|
---|
348 |
|
---|
349 | /* Whether alpha channel value is not transparent enough for the pixel to be seen. */
|
---|
350 | if (pu8SrcAlpha[x * 4 + 3] > 0x7f)
|
---|
351 | {
|
---|
352 | pu8DstAndMask[x / 8] &= ~bitmask;
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | /* Point to next source and dest scans. */
|
---|
357 | pu8SrcAlpha += w * 4;
|
---|
358 | pu8DstAndMask += (w + 7) / 8;
|
---|
359 | }
|
---|
360 | }
|
---|
361 |
|
---|
362 | void ConsoleVRDPServer::onMousePointerShapeChange(BOOL visible,
|
---|
363 | BOOL alpha,
|
---|
364 | ULONG xHot,
|
---|
365 | ULONG yHot,
|
---|
366 | ULONG width,
|
---|
367 | ULONG height,
|
---|
368 | ComSafeArrayIn(BYTE,inShape))
|
---|
369 | {
|
---|
370 | Log9(("VRDPConsoleListener::OnMousePointerShapeChange: %d, %d, %lux%lu, @%lu,%lu\n",
|
---|
371 | visible, alpha, width, height, xHot, yHot));
|
---|
372 |
|
---|
373 | com::SafeArray <BYTE> aShape(ComSafeArrayInArg(inShape));
|
---|
374 | if (aShape.size() == 0)
|
---|
375 | {
|
---|
376 | if (!visible)
|
---|
377 | {
|
---|
378 | MousePointerHide();
|
---|
379 | }
|
---|
380 | }
|
---|
381 | else if (width != 0 && height != 0)
|
---|
382 | {
|
---|
383 | uint8_t* shape = aShape.raw();
|
---|
384 |
|
---|
385 | dumpPointer(shape, width, height, true);
|
---|
386 |
|
---|
387 | /* Try the new interface. */
|
---|
388 | if (MousePointer(alpha, xHot, yHot, width, height, shape) == VINF_SUCCESS)
|
---|
389 | {
|
---|
390 | return;
|
---|
391 | }
|
---|
392 |
|
---|
393 | /* Continue with the old interface. */
|
---|
394 |
|
---|
395 | /* Pointer consists of 1 bpp AND and 24 BPP XOR masks.
|
---|
396 | * 'shape' AND mask followed by XOR mask.
|
---|
397 | * XOR mask contains 32 bit (lsb)BGR0(msb) values.
|
---|
398 | *
|
---|
399 | * We convert this to RDP color format which consist of
|
---|
400 | * one bpp AND mask and 24 BPP (BGR) color XOR image.
|
---|
401 | *
|
---|
402 | * RDP clients expect 8 aligned width and height of
|
---|
403 | * pointer (preferably 32x32).
|
---|
404 | *
|
---|
405 | * They even contain bugs which do not appear for
|
---|
406 | * 32x32 pointers but would appear for a 41x32 one.
|
---|
407 | *
|
---|
408 | * So set pointer size to 32x32. This can be done safely
|
---|
409 | * because most pointers are 32x32.
|
---|
410 | */
|
---|
411 |
|
---|
412 | int cbDstAndMask = (((width + 7) / 8) * height + 3) & ~3;
|
---|
413 |
|
---|
414 | uint8_t *pu8AndMask = shape;
|
---|
415 | uint8_t *pu8XorMask = shape + cbDstAndMask;
|
---|
416 |
|
---|
417 | if (alpha)
|
---|
418 | {
|
---|
419 | pu8AndMask = (uint8_t*)alloca(cbDstAndMask);
|
---|
420 |
|
---|
421 | mousePointerGenerateANDMask(pu8AndMask, cbDstAndMask, pu8XorMask, width, height);
|
---|
422 | }
|
---|
423 |
|
---|
424 | /* Windows guest alpha pointers are wider than 32 pixels.
|
---|
425 | * Try to find out the top-left border of the pointer and
|
---|
426 | * then copy only meaningful bits. All complete top rows
|
---|
427 | * and all complete left columns where (AND == 1 && XOR == 0)
|
---|
428 | * are skipped. Hot spot is adjusted.
|
---|
429 | */
|
---|
430 | uint32_t ySkip = 0; /* How many rows to skip at the top. */
|
---|
431 | uint32_t xSkip = 0; /* How many columns to skip at the left. */
|
---|
432 |
|
---|
433 | findTopLeftBorder(pu8AndMask, pu8XorMask, width, height, &xSkip, &ySkip);
|
---|
434 |
|
---|
435 | /* Must not skip the hot spot. */
|
---|
436 | xSkip = RT_MIN(xSkip, xHot);
|
---|
437 | ySkip = RT_MIN(ySkip, yHot);
|
---|
438 |
|
---|
439 | /*
|
---|
440 | * Compute size and allocate memory for the pointer.
|
---|
441 | */
|
---|
442 | const uint32_t dstwidth = 32;
|
---|
443 | const uint32_t dstheight = 32;
|
---|
444 |
|
---|
445 | VRDECOLORPOINTER *pointer = NULL;
|
---|
446 |
|
---|
447 | uint32_t dstmaskwidth = (dstwidth + 7) / 8;
|
---|
448 |
|
---|
449 | uint32_t rdpmaskwidth = dstmaskwidth;
|
---|
450 | uint32_t rdpmasklen = dstheight * rdpmaskwidth;
|
---|
451 |
|
---|
452 | uint32_t rdpdatawidth = dstwidth * 3;
|
---|
453 | uint32_t rdpdatalen = dstheight * rdpdatawidth;
|
---|
454 |
|
---|
455 | pointer = (VRDECOLORPOINTER *)RTMemTmpAlloc(sizeof(VRDECOLORPOINTER) + rdpmasklen + rdpdatalen);
|
---|
456 |
|
---|
457 | if (pointer)
|
---|
458 | {
|
---|
459 | uint8_t *maskarray = (uint8_t*)pointer + sizeof(VRDECOLORPOINTER);
|
---|
460 | uint8_t *dataarray = maskarray + rdpmasklen;
|
---|
461 |
|
---|
462 | memset(maskarray, 0xFF, rdpmasklen);
|
---|
463 | memset(dataarray, 0x00, rdpdatalen);
|
---|
464 |
|
---|
465 | uint32_t srcmaskwidth = (width + 7) / 8;
|
---|
466 | uint32_t srcdatawidth = width * 4;
|
---|
467 |
|
---|
468 | /* Copy AND mask. */
|
---|
469 | uint8_t *src = pu8AndMask + ySkip * srcmaskwidth;
|
---|
470 | uint8_t *dst = maskarray + (dstheight - 1) * rdpmaskwidth;
|
---|
471 |
|
---|
472 | uint32_t minheight = RT_MIN(height - ySkip, dstheight);
|
---|
473 | uint32_t minwidth = RT_MIN(width - xSkip, dstwidth);
|
---|
474 |
|
---|
475 | unsigned x, y;
|
---|
476 |
|
---|
477 | for (y = 0; y < minheight; y++)
|
---|
478 | {
|
---|
479 | for (x = 0; x < minwidth; x++)
|
---|
480 | {
|
---|
481 | uint32_t byteIndex = (x + xSkip) / 8;
|
---|
482 | uint32_t bitIndex = (x + xSkip) % 8;
|
---|
483 |
|
---|
484 | bool bit = (src[byteIndex] & (1 << (7 - bitIndex))) != 0;
|
---|
485 |
|
---|
486 | if (!bit)
|
---|
487 | {
|
---|
488 | byteIndex = x / 8;
|
---|
489 | bitIndex = x % 8;
|
---|
490 |
|
---|
491 | dst[byteIndex] &= ~(1 << (7 - bitIndex));
|
---|
492 | }
|
---|
493 | }
|
---|
494 |
|
---|
495 | src += srcmaskwidth;
|
---|
496 | dst -= rdpmaskwidth;
|
---|
497 | }
|
---|
498 |
|
---|
499 | /* Point src to XOR mask */
|
---|
500 | src = pu8XorMask + ySkip * srcdatawidth;
|
---|
501 | dst = dataarray + (dstheight - 1) * rdpdatawidth;
|
---|
502 |
|
---|
503 | for (y = 0; y < minheight ; y++)
|
---|
504 | {
|
---|
505 | for (x = 0; x < minwidth; x++)
|
---|
506 | {
|
---|
507 | memcpy(dst + x * 3, &src[4 * (x + xSkip)], 3);
|
---|
508 | }
|
---|
509 |
|
---|
510 | src += srcdatawidth;
|
---|
511 | dst -= rdpdatawidth;
|
---|
512 | }
|
---|
513 |
|
---|
514 | pointer->u16HotX = (uint16_t)(xHot - xSkip);
|
---|
515 | pointer->u16HotY = (uint16_t)(yHot - ySkip);
|
---|
516 |
|
---|
517 | pointer->u16Width = (uint16_t)dstwidth;
|
---|
518 | pointer->u16Height = (uint16_t)dstheight;
|
---|
519 |
|
---|
520 | pointer->u16MaskLen = (uint16_t)rdpmasklen;
|
---|
521 | pointer->u16DataLen = (uint16_t)rdpdatalen;
|
---|
522 |
|
---|
523 | dumpPointer((uint8_t*)pointer + sizeof(*pointer), dstwidth, dstheight, false);
|
---|
524 |
|
---|
525 | MousePointerUpdate(pointer);
|
---|
526 |
|
---|
527 | RTMemTmpFree(pointer);
|
---|
528 | }
|
---|
529 | }
|
---|
530 | }
|
---|
531 |
|
---|
532 |
|
---|
533 | // ConsoleVRDPServer
|
---|
534 | ////////////////////////////////////////////////////////////////////////////////
|
---|
535 |
|
---|
536 | RTLDRMOD ConsoleVRDPServer::mVRDPLibrary = NIL_RTLDRMOD;
|
---|
537 |
|
---|
538 | PFNVRDECREATESERVER ConsoleVRDPServer::mpfnVRDECreateServer = NULL;
|
---|
539 |
|
---|
540 | VRDEENTRYPOINTS_4 ConsoleVRDPServer::mEntryPoints; /* A copy of the server entry points. */
|
---|
541 | VRDEENTRYPOINTS_4 *ConsoleVRDPServer::mpEntryPoints = NULL;
|
---|
542 |
|
---|
543 | VRDECALLBACKS_4 ConsoleVRDPServer::mCallbacks =
|
---|
544 | {
|
---|
545 | { VRDE_INTERFACE_VERSION_4, sizeof(VRDECALLBACKS_4) },
|
---|
546 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
547 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
548 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
549 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
550 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
551 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
552 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
553 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
554 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
555 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
556 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
557 | ConsoleVRDPServer::VRDPCallbackVideoModeHint,
|
---|
558 | ConsoleVRDPServer::VRDECallbackAudioIn
|
---|
559 | };
|
---|
560 |
|
---|
561 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackQueryProperty(void *pvCallback, uint32_t index, void *pvBuffer,
|
---|
562 | uint32_t cbBuffer, uint32_t *pcbOut)
|
---|
563 | {
|
---|
564 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
565 |
|
---|
566 | int rc = VERR_NOT_SUPPORTED;
|
---|
567 |
|
---|
568 | switch (index)
|
---|
569 | {
|
---|
570 | case VRDE_QP_NETWORK_PORT:
|
---|
571 | {
|
---|
572 | /* This is obsolete, the VRDE server uses VRDE_QP_NETWORK_PORT_RANGE instead. */
|
---|
573 | ULONG port = 0;
|
---|
574 |
|
---|
575 | if (cbBuffer >= sizeof(uint32_t))
|
---|
576 | {
|
---|
577 | *(uint32_t *)pvBuffer = (uint32_t)port;
|
---|
578 | rc = VINF_SUCCESS;
|
---|
579 | }
|
---|
580 | else
|
---|
581 | {
|
---|
582 | rc = VINF_BUFFER_OVERFLOW;
|
---|
583 | }
|
---|
584 |
|
---|
585 | *pcbOut = sizeof(uint32_t);
|
---|
586 | } break;
|
---|
587 |
|
---|
588 | case VRDE_QP_NETWORK_ADDRESS:
|
---|
589 | {
|
---|
590 | com::Bstr bstr;
|
---|
591 | server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("TCP/Address").raw(), bstr.asOutParam());
|
---|
592 |
|
---|
593 | /* The server expects UTF8. */
|
---|
594 | com::Utf8Str address = bstr;
|
---|
595 |
|
---|
596 | size_t cbAddress = address.length() + 1;
|
---|
597 |
|
---|
598 | if (cbAddress >= 0x10000)
|
---|
599 | {
|
---|
600 | /* More than 64K seems to be an invalid address. */
|
---|
601 | rc = VERR_TOO_MUCH_DATA;
|
---|
602 | break;
|
---|
603 | }
|
---|
604 |
|
---|
605 | if ((size_t)cbBuffer >= cbAddress)
|
---|
606 | {
|
---|
607 | memcpy(pvBuffer, address.c_str(), cbAddress);
|
---|
608 | rc = VINF_SUCCESS;
|
---|
609 | }
|
---|
610 | else
|
---|
611 | {
|
---|
612 | rc = VINF_BUFFER_OVERFLOW;
|
---|
613 | }
|
---|
614 |
|
---|
615 | *pcbOut = (uint32_t)cbAddress;
|
---|
616 | } break;
|
---|
617 |
|
---|
618 | case VRDE_QP_NUMBER_MONITORS:
|
---|
619 | {
|
---|
620 | ULONG cMonitors = 1;
|
---|
621 |
|
---|
622 | server->mConsole->i_machine()->COMGETTER(MonitorCount)(&cMonitors);
|
---|
623 |
|
---|
624 | if (cbBuffer >= sizeof(uint32_t))
|
---|
625 | {
|
---|
626 | *(uint32_t *)pvBuffer = (uint32_t)cMonitors;
|
---|
627 | rc = VINF_SUCCESS;
|
---|
628 | }
|
---|
629 | else
|
---|
630 | {
|
---|
631 | rc = VINF_BUFFER_OVERFLOW;
|
---|
632 | }
|
---|
633 |
|
---|
634 | *pcbOut = sizeof(uint32_t);
|
---|
635 | } break;
|
---|
636 |
|
---|
637 | case VRDE_QP_NETWORK_PORT_RANGE:
|
---|
638 | {
|
---|
639 | com::Bstr bstr;
|
---|
640 | HRESULT hrc = server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("TCP/Ports").raw(), bstr.asOutParam());
|
---|
641 |
|
---|
642 | if (hrc != S_OK)
|
---|
643 | {
|
---|
644 | bstr = "";
|
---|
645 | }
|
---|
646 |
|
---|
647 | if (bstr == "0")
|
---|
648 | {
|
---|
649 | bstr = "3389";
|
---|
650 | }
|
---|
651 |
|
---|
652 | /* The server expects UTF8. */
|
---|
653 | com::Utf8Str portRange = bstr;
|
---|
654 |
|
---|
655 | size_t cbPortRange = portRange.length() + 1;
|
---|
656 |
|
---|
657 | if (cbPortRange >= _64K)
|
---|
658 | {
|
---|
659 | /* More than 64K seems to be an invalid port range string. */
|
---|
660 | rc = VERR_TOO_MUCH_DATA;
|
---|
661 | break;
|
---|
662 | }
|
---|
663 |
|
---|
664 | if ((size_t)cbBuffer >= cbPortRange)
|
---|
665 | {
|
---|
666 | memcpy(pvBuffer, portRange.c_str(), cbPortRange);
|
---|
667 | rc = VINF_SUCCESS;
|
---|
668 | }
|
---|
669 | else
|
---|
670 | {
|
---|
671 | rc = VINF_BUFFER_OVERFLOW;
|
---|
672 | }
|
---|
673 |
|
---|
674 | *pcbOut = (uint32_t)cbPortRange;
|
---|
675 | } break;
|
---|
676 |
|
---|
677 | case VRDE_QP_VIDEO_CHANNEL:
|
---|
678 | {
|
---|
679 | com::Bstr bstr;
|
---|
680 | HRESULT hrc = server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("VideoChannel/Enabled").raw(),
|
---|
681 | bstr.asOutParam());
|
---|
682 |
|
---|
683 | if (hrc != S_OK)
|
---|
684 | {
|
---|
685 | bstr = "";
|
---|
686 | }
|
---|
687 |
|
---|
688 | com::Utf8Str value = bstr;
|
---|
689 |
|
---|
690 | BOOL fVideoEnabled = RTStrICmp(value.c_str(), "true") == 0
|
---|
691 | || RTStrICmp(value.c_str(), "1") == 0;
|
---|
692 |
|
---|
693 | if (cbBuffer >= sizeof(uint32_t))
|
---|
694 | {
|
---|
695 | *(uint32_t *)pvBuffer = (uint32_t)fVideoEnabled;
|
---|
696 | rc = VINF_SUCCESS;
|
---|
697 | }
|
---|
698 | else
|
---|
699 | {
|
---|
700 | rc = VINF_BUFFER_OVERFLOW;
|
---|
701 | }
|
---|
702 |
|
---|
703 | *pcbOut = sizeof(uint32_t);
|
---|
704 | } break;
|
---|
705 |
|
---|
706 | case VRDE_QP_VIDEO_CHANNEL_QUALITY:
|
---|
707 | {
|
---|
708 | com::Bstr bstr;
|
---|
709 | HRESULT hrc = server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("VideoChannel/Quality").raw(),
|
---|
710 | bstr.asOutParam());
|
---|
711 |
|
---|
712 | if (hrc != S_OK)
|
---|
713 | {
|
---|
714 | bstr = "";
|
---|
715 | }
|
---|
716 |
|
---|
717 | com::Utf8Str value = bstr;
|
---|
718 |
|
---|
719 | ULONG ulQuality = RTStrToUInt32(value.c_str()); /* This returns 0 on invalid string which is ok. */
|
---|
720 |
|
---|
721 | if (cbBuffer >= sizeof(uint32_t))
|
---|
722 | {
|
---|
723 | *(uint32_t *)pvBuffer = (uint32_t)ulQuality;
|
---|
724 | rc = VINF_SUCCESS;
|
---|
725 | }
|
---|
726 | else
|
---|
727 | {
|
---|
728 | rc = VINF_BUFFER_OVERFLOW;
|
---|
729 | }
|
---|
730 |
|
---|
731 | *pcbOut = sizeof(uint32_t);
|
---|
732 | } break;
|
---|
733 |
|
---|
734 | case VRDE_QP_VIDEO_CHANNEL_SUNFLSH:
|
---|
735 | {
|
---|
736 | ULONG ulSunFlsh = 1;
|
---|
737 |
|
---|
738 | com::Bstr bstr;
|
---|
739 | HRESULT hrc = server->mConsole->i_machine()->GetExtraData(Bstr("VRDP/SunFlsh").raw(),
|
---|
740 | bstr.asOutParam());
|
---|
741 | if (hrc == S_OK && !bstr.isEmpty())
|
---|
742 | {
|
---|
743 | com::Utf8Str sunFlsh = bstr;
|
---|
744 | if (!sunFlsh.isEmpty())
|
---|
745 | {
|
---|
746 | ulSunFlsh = sunFlsh.toUInt32();
|
---|
747 | }
|
---|
748 | }
|
---|
749 |
|
---|
750 | if (cbBuffer >= sizeof(uint32_t))
|
---|
751 | {
|
---|
752 | *(uint32_t *)pvBuffer = (uint32_t)ulSunFlsh;
|
---|
753 | rc = VINF_SUCCESS;
|
---|
754 | }
|
---|
755 | else
|
---|
756 | {
|
---|
757 | rc = VINF_BUFFER_OVERFLOW;
|
---|
758 | }
|
---|
759 |
|
---|
760 | *pcbOut = sizeof(uint32_t);
|
---|
761 | } break;
|
---|
762 |
|
---|
763 | case VRDE_QP_FEATURE:
|
---|
764 | {
|
---|
765 | if (cbBuffer < sizeof(VRDEFEATURE))
|
---|
766 | {
|
---|
767 | rc = VERR_INVALID_PARAMETER;
|
---|
768 | break;
|
---|
769 | }
|
---|
770 |
|
---|
771 | size_t cbInfo = cbBuffer - RT_UOFFSETOF(VRDEFEATURE, achInfo);
|
---|
772 |
|
---|
773 | VRDEFEATURE *pFeature = (VRDEFEATURE *)pvBuffer;
|
---|
774 |
|
---|
775 | size_t cchInfo = 0;
|
---|
776 | rc = RTStrNLenEx(pFeature->achInfo, cbInfo, &cchInfo);
|
---|
777 |
|
---|
778 | if (RT_FAILURE(rc))
|
---|
779 | {
|
---|
780 | rc = VERR_INVALID_PARAMETER;
|
---|
781 | break;
|
---|
782 | }
|
---|
783 |
|
---|
784 | Log(("VRDE_QP_FEATURE [%s]\n", pFeature->achInfo));
|
---|
785 |
|
---|
786 | com::Bstr bstrValue;
|
---|
787 |
|
---|
788 | if ( RTStrICmp(pFeature->achInfo, "Client/DisableDisplay") == 0
|
---|
789 | || RTStrICmp(pFeature->achInfo, "Client/DisableInput") == 0
|
---|
790 | || RTStrICmp(pFeature->achInfo, "Client/DisableAudio") == 0
|
---|
791 | || RTStrICmp(pFeature->achInfo, "Client/DisableUSB") == 0
|
---|
792 | || RTStrICmp(pFeature->achInfo, "Client/DisableClipboard") == 0
|
---|
793 | )
|
---|
794 | {
|
---|
795 | /** @todo these features should be per client. */
|
---|
796 | NOREF(pFeature->u32ClientId);
|
---|
797 |
|
---|
798 | /* These features are mapped to "VRDE/Feature/NAME" extra data. */
|
---|
799 | com::Utf8Str extraData("VRDE/Feature/");
|
---|
800 | extraData += pFeature->achInfo;
|
---|
801 |
|
---|
802 | HRESULT hrc = server->mConsole->i_machine()->GetExtraData(com::Bstr(extraData).raw(),
|
---|
803 | bstrValue.asOutParam());
|
---|
804 | if (FAILED(hrc) || bstrValue.isEmpty())
|
---|
805 | {
|
---|
806 | /* Also try the old "VRDP/Feature/NAME" */
|
---|
807 | extraData = "VRDP/Feature/";
|
---|
808 | extraData += pFeature->achInfo;
|
---|
809 |
|
---|
810 | hrc = server->mConsole->i_machine()->GetExtraData(com::Bstr(extraData).raw(),
|
---|
811 | bstrValue.asOutParam());
|
---|
812 | if (FAILED(hrc))
|
---|
813 | {
|
---|
814 | rc = VERR_NOT_SUPPORTED;
|
---|
815 | }
|
---|
816 | }
|
---|
817 | }
|
---|
818 | else if (RTStrNCmp(pFeature->achInfo, "Property/", 9) == 0)
|
---|
819 | {
|
---|
820 | /* Generic properties. */
|
---|
821 | const char *pszPropertyName = &pFeature->achInfo[9];
|
---|
822 | HRESULT hrc = server->mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr(pszPropertyName).raw(),
|
---|
823 | bstrValue.asOutParam());
|
---|
824 | if (FAILED(hrc))
|
---|
825 | {
|
---|
826 | rc = VERR_NOT_SUPPORTED;
|
---|
827 | }
|
---|
828 | }
|
---|
829 | else
|
---|
830 | {
|
---|
831 | rc = VERR_NOT_SUPPORTED;
|
---|
832 | }
|
---|
833 |
|
---|
834 | /* Copy the value string to the callers buffer. */
|
---|
835 | if (rc == VINF_SUCCESS)
|
---|
836 | {
|
---|
837 | com::Utf8Str value = bstrValue;
|
---|
838 |
|
---|
839 | size_t cb = value.length() + 1;
|
---|
840 |
|
---|
841 | if ((size_t)cbInfo >= cb)
|
---|
842 | {
|
---|
843 | memcpy(pFeature->achInfo, value.c_str(), cb);
|
---|
844 | }
|
---|
845 | else
|
---|
846 | {
|
---|
847 | rc = VINF_BUFFER_OVERFLOW;
|
---|
848 | }
|
---|
849 |
|
---|
850 | *pcbOut = (uint32_t)cb;
|
---|
851 | }
|
---|
852 | } break;
|
---|
853 |
|
---|
854 | case VRDE_SP_NETWORK_BIND_PORT:
|
---|
855 | {
|
---|
856 | if (cbBuffer != sizeof(uint32_t))
|
---|
857 | {
|
---|
858 | rc = VERR_INVALID_PARAMETER;
|
---|
859 | break;
|
---|
860 | }
|
---|
861 |
|
---|
862 | ULONG port = *(uint32_t *)pvBuffer;
|
---|
863 |
|
---|
864 | server->mVRDPBindPort = port;
|
---|
865 |
|
---|
866 | rc = VINF_SUCCESS;
|
---|
867 |
|
---|
868 | if (pcbOut)
|
---|
869 | {
|
---|
870 | *pcbOut = sizeof(uint32_t);
|
---|
871 | }
|
---|
872 |
|
---|
873 | server->mConsole->i_onVRDEServerInfoChange();
|
---|
874 | } break;
|
---|
875 |
|
---|
876 | case VRDE_SP_CLIENT_STATUS:
|
---|
877 | {
|
---|
878 | if (cbBuffer < sizeof(VRDECLIENTSTATUS))
|
---|
879 | {
|
---|
880 | rc = VERR_INVALID_PARAMETER;
|
---|
881 | break;
|
---|
882 | }
|
---|
883 |
|
---|
884 | size_t cbStatus = cbBuffer - RT_UOFFSETOF(VRDECLIENTSTATUS, achStatus);
|
---|
885 |
|
---|
886 | VRDECLIENTSTATUS *pStatus = (VRDECLIENTSTATUS *)pvBuffer;
|
---|
887 |
|
---|
888 | if (cbBuffer < RT_UOFFSETOF(VRDECLIENTSTATUS, achStatus) + pStatus->cbStatus)
|
---|
889 | {
|
---|
890 | rc = VERR_INVALID_PARAMETER;
|
---|
891 | break;
|
---|
892 | }
|
---|
893 |
|
---|
894 | size_t cchStatus = 0;
|
---|
895 | rc = RTStrNLenEx(pStatus->achStatus, cbStatus, &cchStatus);
|
---|
896 |
|
---|
897 | if (RT_FAILURE(rc))
|
---|
898 | {
|
---|
899 | rc = VERR_INVALID_PARAMETER;
|
---|
900 | break;
|
---|
901 | }
|
---|
902 |
|
---|
903 | Log(("VRDE_SP_CLIENT_STATUS [%s]\n", pStatus->achStatus));
|
---|
904 |
|
---|
905 | server->mConsole->i_VRDPClientStatusChange(pStatus->u32ClientId, pStatus->achStatus);
|
---|
906 |
|
---|
907 | rc = VINF_SUCCESS;
|
---|
908 |
|
---|
909 | if (pcbOut)
|
---|
910 | {
|
---|
911 | *pcbOut = cbBuffer;
|
---|
912 | }
|
---|
913 |
|
---|
914 | server->mConsole->i_onVRDEServerInfoChange();
|
---|
915 | } break;
|
---|
916 |
|
---|
917 | default:
|
---|
918 | break;
|
---|
919 | }
|
---|
920 |
|
---|
921 | return rc;
|
---|
922 | }
|
---|
923 |
|
---|
924 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClientLogon(void *pvCallback, uint32_t u32ClientId, const char *pszUser,
|
---|
925 | const char *pszPassword, const char *pszDomain)
|
---|
926 | {
|
---|
927 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
928 |
|
---|
929 | return server->mConsole->i_VRDPClientLogon(u32ClientId, pszUser, pszPassword, pszDomain);
|
---|
930 | }
|
---|
931 |
|
---|
932 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientConnect(void *pvCallback, uint32_t u32ClientId)
|
---|
933 | {
|
---|
934 | ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
935 |
|
---|
936 | pServer->mConsole->i_VRDPClientConnect(u32ClientId);
|
---|
937 |
|
---|
938 | /* Should the server report usage of an interface for each client?
|
---|
939 | * Similar to Intercept.
|
---|
940 | */
|
---|
941 | int c = ASMAtomicIncS32(&pServer->mcClients);
|
---|
942 | if (c == 1)
|
---|
943 | {
|
---|
944 | /* Features which should be enabled only if there is a client. */
|
---|
945 | pServer->remote3DRedirect(true);
|
---|
946 | }
|
---|
947 |
|
---|
948 | #ifdef VBOX_WITH_AUDIO_VRDE
|
---|
949 | AudioVRDE *pVRDE = pServer->mConsole->i_getAudioVRDE();
|
---|
950 | if (pVRDE)
|
---|
951 | pVRDE->onVRDEClientConnect(u32ClientId);
|
---|
952 | #endif
|
---|
953 | }
|
---|
954 |
|
---|
955 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientDisconnect(void *pvCallback, uint32_t u32ClientId,
|
---|
956 | uint32_t fu32Intercepted)
|
---|
957 | {
|
---|
958 | ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
959 | AssertPtrReturnVoid(pServer);
|
---|
960 |
|
---|
961 | pServer->mConsole->i_VRDPClientDisconnect(u32ClientId, fu32Intercepted);
|
---|
962 |
|
---|
963 | if (ASMAtomicReadU32(&pServer->mu32AudioInputClientId) == u32ClientId)
|
---|
964 | {
|
---|
965 | LogFunc(("Disconnected client %u\n", u32ClientId));
|
---|
966 | ASMAtomicWriteU32(&pServer->mu32AudioInputClientId, 0);
|
---|
967 |
|
---|
968 | #ifdef VBOX_WITH_AUDIO_VRDE
|
---|
969 | AudioVRDE *pVRDE = pServer->mConsole->i_getAudioVRDE();
|
---|
970 | if (pVRDE)
|
---|
971 | {
|
---|
972 | pVRDE->onVRDEInputIntercept(false /* fIntercept */);
|
---|
973 | pVRDE->onVRDEClientDisconnect(u32ClientId);
|
---|
974 | }
|
---|
975 | #endif
|
---|
976 | }
|
---|
977 |
|
---|
978 | int32_t cClients = ASMAtomicDecS32(&pServer->mcClients);
|
---|
979 | if (cClients == 0)
|
---|
980 | {
|
---|
981 | /* Features which should be enabled only if there is a client. */
|
---|
982 | pServer->remote3DRedirect(false);
|
---|
983 | }
|
---|
984 | }
|
---|
985 |
|
---|
986 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackIntercept(void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept,
|
---|
987 | void **ppvIntercept)
|
---|
988 | {
|
---|
989 | ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
990 | AssertPtrReturn(pServer, VERR_INVALID_POINTER);
|
---|
991 |
|
---|
992 | LogFlowFunc(("%x\n", fu32Intercept));
|
---|
993 |
|
---|
994 | int rc = VERR_NOT_SUPPORTED;
|
---|
995 |
|
---|
996 | switch (fu32Intercept)
|
---|
997 | {
|
---|
998 | case VRDE_CLIENT_INTERCEPT_AUDIO:
|
---|
999 | {
|
---|
1000 | pServer->mConsole->i_VRDPInterceptAudio(u32ClientId);
|
---|
1001 | if (ppvIntercept)
|
---|
1002 | {
|
---|
1003 | *ppvIntercept = pServer;
|
---|
1004 | }
|
---|
1005 | rc = VINF_SUCCESS;
|
---|
1006 | } break;
|
---|
1007 |
|
---|
1008 | case VRDE_CLIENT_INTERCEPT_USB:
|
---|
1009 | {
|
---|
1010 | pServer->mConsole->i_VRDPInterceptUSB(u32ClientId, ppvIntercept);
|
---|
1011 | rc = VINF_SUCCESS;
|
---|
1012 | } break;
|
---|
1013 |
|
---|
1014 | case VRDE_CLIENT_INTERCEPT_CLIPBOARD:
|
---|
1015 | {
|
---|
1016 | pServer->mConsole->i_VRDPInterceptClipboard(u32ClientId);
|
---|
1017 | if (ppvIntercept)
|
---|
1018 | {
|
---|
1019 | *ppvIntercept = pServer;
|
---|
1020 | }
|
---|
1021 | rc = VINF_SUCCESS;
|
---|
1022 | } break;
|
---|
1023 |
|
---|
1024 | case VRDE_CLIENT_INTERCEPT_AUDIO_INPUT:
|
---|
1025 | {
|
---|
1026 | /*
|
---|
1027 | * This request is processed internally by the ConsoleVRDPServer.
|
---|
1028 | * Only one client is allowed to intercept audio input.
|
---|
1029 | */
|
---|
1030 | if (ASMAtomicCmpXchgU32(&pServer->mu32AudioInputClientId, u32ClientId, 0) == true)
|
---|
1031 | {
|
---|
1032 | LogFunc(("Intercepting audio input by client %RU32\n", u32ClientId));
|
---|
1033 |
|
---|
1034 | #ifdef VBOX_WITH_AUDIO_VRDE
|
---|
1035 | AudioVRDE *pVRDE = pServer->mConsole->i_getAudioVRDE();
|
---|
1036 | if (pVRDE)
|
---|
1037 | pVRDE->onVRDEInputIntercept(true /* fIntercept */);
|
---|
1038 | #endif
|
---|
1039 | }
|
---|
1040 | else
|
---|
1041 | {
|
---|
1042 | Log(("AUDIOIN: ignored client %RU32, active client %RU32\n", u32ClientId, pServer->mu32AudioInputClientId));
|
---|
1043 | rc = VERR_NOT_SUPPORTED;
|
---|
1044 | }
|
---|
1045 | } break;
|
---|
1046 |
|
---|
1047 | default:
|
---|
1048 | break;
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | return rc;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackUSB(void *pvCallback, void *pvIntercept, uint32_t u32ClientId,
|
---|
1055 | uint8_t u8Code, const void *pvRet, uint32_t cbRet)
|
---|
1056 | {
|
---|
1057 | RT_NOREF(pvCallback);
|
---|
1058 | #ifdef VBOX_WITH_USB
|
---|
1059 | return USBClientResponseCallback(pvIntercept, u32ClientId, u8Code, pvRet, cbRet);
|
---|
1060 | #else
|
---|
1061 | return VERR_NOT_SUPPORTED;
|
---|
1062 | #endif
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClipboard(void *pvCallback, void *pvIntercept, uint32_t u32ClientId,
|
---|
1066 | uint32_t u32Function, uint32_t u32Format,
|
---|
1067 | const void *pvData, uint32_t cbData)
|
---|
1068 | {
|
---|
1069 | RT_NOREF(pvCallback);
|
---|
1070 | return ClipboardCallback(pvIntercept, u32ClientId, u32Function, u32Format, pvData, cbData);
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | DECLCALLBACK(bool) ConsoleVRDPServer::VRDPCallbackFramebufferQuery(void *pvCallback, unsigned uScreenId,
|
---|
1074 | VRDEFRAMEBUFFERINFO *pInfo)
|
---|
1075 | {
|
---|
1076 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1077 |
|
---|
1078 | bool fAvailable = false;
|
---|
1079 |
|
---|
1080 | /* Obtain the new screen bitmap. */
|
---|
1081 | HRESULT hr = server->mConsole->i_getDisplay()->QuerySourceBitmap(uScreenId, server->maSourceBitmaps[uScreenId].asOutParam());
|
---|
1082 | if (SUCCEEDED(hr))
|
---|
1083 | {
|
---|
1084 | LONG xOrigin = 0;
|
---|
1085 | LONG yOrigin = 0;
|
---|
1086 | BYTE *pAddress = NULL;
|
---|
1087 | ULONG ulWidth = 0;
|
---|
1088 | ULONG ulHeight = 0;
|
---|
1089 | ULONG ulBitsPerPixel = 0;
|
---|
1090 | ULONG ulBytesPerLine = 0;
|
---|
1091 | BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
|
---|
1092 |
|
---|
1093 | hr = server->maSourceBitmaps[uScreenId]->QueryBitmapInfo(&pAddress,
|
---|
1094 | &ulWidth,
|
---|
1095 | &ulHeight,
|
---|
1096 | &ulBitsPerPixel,
|
---|
1097 | &ulBytesPerLine,
|
---|
1098 | &bitmapFormat);
|
---|
1099 |
|
---|
1100 | if (SUCCEEDED(hr))
|
---|
1101 | {
|
---|
1102 | ULONG dummy;
|
---|
1103 | GuestMonitorStatus_T monitorStatus;
|
---|
1104 | hr = server->mConsole->i_getDisplay()->GetScreenResolution(uScreenId, &dummy, &dummy, &dummy,
|
---|
1105 | &xOrigin, &yOrigin, &monitorStatus);
|
---|
1106 |
|
---|
1107 | if (SUCCEEDED(hr))
|
---|
1108 | {
|
---|
1109 | /* Now fill the information as requested by the caller. */
|
---|
1110 | pInfo->pu8Bits = pAddress;
|
---|
1111 | pInfo->xOrigin = xOrigin;
|
---|
1112 | pInfo->yOrigin = yOrigin;
|
---|
1113 | pInfo->cWidth = ulWidth;
|
---|
1114 | pInfo->cHeight = ulHeight;
|
---|
1115 | pInfo->cBitsPerPixel = ulBitsPerPixel;
|
---|
1116 | pInfo->cbLine = ulBytesPerLine;
|
---|
1117 |
|
---|
1118 | fAvailable = true;
|
---|
1119 | }
|
---|
1120 | }
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | return fAvailable;
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferLock(void *pvCallback, unsigned uScreenId)
|
---|
1127 | {
|
---|
1128 | NOREF(pvCallback);
|
---|
1129 | NOREF(uScreenId);
|
---|
1130 | /* Do nothing */
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferUnlock(void *pvCallback, unsigned uScreenId)
|
---|
1134 | {
|
---|
1135 | NOREF(pvCallback);
|
---|
1136 | NOREF(uScreenId);
|
---|
1137 | /* Do nothing */
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | static void fixKbdLockStatus(VRDPInputSynch *pInputSynch, IKeyboard *pKeyboard)
|
---|
1141 | {
|
---|
1142 | if ( pInputSynch->cGuestNumLockAdaptions
|
---|
1143 | && (pInputSynch->fGuestNumLock != pInputSynch->fClientNumLock))
|
---|
1144 | {
|
---|
1145 | pInputSynch->cGuestNumLockAdaptions--;
|
---|
1146 | pKeyboard->PutScancode(0x45);
|
---|
1147 | pKeyboard->PutScancode(0x45 | 0x80);
|
---|
1148 | }
|
---|
1149 | if ( pInputSynch->cGuestCapsLockAdaptions
|
---|
1150 | && (pInputSynch->fGuestCapsLock != pInputSynch->fClientCapsLock))
|
---|
1151 | {
|
---|
1152 | pInputSynch->cGuestCapsLockAdaptions--;
|
---|
1153 | pKeyboard->PutScancode(0x3a);
|
---|
1154 | pKeyboard->PutScancode(0x3a | 0x80);
|
---|
1155 | }
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackInput(void *pvCallback, int type, const void *pvInput, unsigned cbInput)
|
---|
1159 | {
|
---|
1160 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1161 | Console *pConsole = server->mConsole;
|
---|
1162 |
|
---|
1163 | switch (type)
|
---|
1164 | {
|
---|
1165 | case VRDE_INPUT_SCANCODE:
|
---|
1166 | {
|
---|
1167 | if (cbInput == sizeof(VRDEINPUTSCANCODE))
|
---|
1168 | {
|
---|
1169 | IKeyboard *pKeyboard = pConsole->i_getKeyboard();
|
---|
1170 |
|
---|
1171 | const VRDEINPUTSCANCODE *pInputScancode = (VRDEINPUTSCANCODE *)pvInput;
|
---|
1172 |
|
---|
1173 | /* Track lock keys. */
|
---|
1174 | if (pInputScancode->uScancode == 0x45)
|
---|
1175 | {
|
---|
1176 | server->m_InputSynch.fClientNumLock = !server->m_InputSynch.fClientNumLock;
|
---|
1177 | }
|
---|
1178 | else if (pInputScancode->uScancode == 0x3a)
|
---|
1179 | {
|
---|
1180 | server->m_InputSynch.fClientCapsLock = !server->m_InputSynch.fClientCapsLock;
|
---|
1181 | }
|
---|
1182 | else if (pInputScancode->uScancode == 0x46)
|
---|
1183 | {
|
---|
1184 | server->m_InputSynch.fClientScrollLock = !server->m_InputSynch.fClientScrollLock;
|
---|
1185 | }
|
---|
1186 | else if ((pInputScancode->uScancode & 0x80) == 0)
|
---|
1187 | {
|
---|
1188 | /* Key pressed. */
|
---|
1189 | fixKbdLockStatus(&server->m_InputSynch, pKeyboard);
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | pKeyboard->PutScancode((LONG)pInputScancode->uScancode);
|
---|
1193 | }
|
---|
1194 | } break;
|
---|
1195 |
|
---|
1196 | case VRDE_INPUT_POINT:
|
---|
1197 | {
|
---|
1198 | if (cbInput == sizeof(VRDEINPUTPOINT))
|
---|
1199 | {
|
---|
1200 | const VRDEINPUTPOINT *pInputPoint = (VRDEINPUTPOINT *)pvInput;
|
---|
1201 |
|
---|
1202 | int mouseButtons = 0;
|
---|
1203 | int iWheel = 0;
|
---|
1204 |
|
---|
1205 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON1)
|
---|
1206 | {
|
---|
1207 | mouseButtons |= MouseButtonState_LeftButton;
|
---|
1208 | }
|
---|
1209 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON2)
|
---|
1210 | {
|
---|
1211 | mouseButtons |= MouseButtonState_RightButton;
|
---|
1212 | }
|
---|
1213 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON3)
|
---|
1214 | {
|
---|
1215 | mouseButtons |= MouseButtonState_MiddleButton;
|
---|
1216 | }
|
---|
1217 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_WHEEL_UP)
|
---|
1218 | {
|
---|
1219 | mouseButtons |= MouseButtonState_WheelUp;
|
---|
1220 | iWheel = -1;
|
---|
1221 | }
|
---|
1222 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_WHEEL_DOWN)
|
---|
1223 | {
|
---|
1224 | mouseButtons |= MouseButtonState_WheelDown;
|
---|
1225 | iWheel = 1;
|
---|
1226 | }
|
---|
1227 |
|
---|
1228 | if (server->m_fGuestWantsAbsolute)
|
---|
1229 | {
|
---|
1230 | pConsole->i_getMouse()->PutMouseEventAbsolute(pInputPoint->x + 1, pInputPoint->y + 1, iWheel,
|
---|
1231 | 0 /* Horizontal wheel */, mouseButtons);
|
---|
1232 | } else
|
---|
1233 | {
|
---|
1234 | pConsole->i_getMouse()->PutMouseEvent(pInputPoint->x - server->m_mousex,
|
---|
1235 | pInputPoint->y - server->m_mousey,
|
---|
1236 | iWheel, 0 /* Horizontal wheel */, mouseButtons);
|
---|
1237 | server->m_mousex = pInputPoint->x;
|
---|
1238 | server->m_mousey = pInputPoint->y;
|
---|
1239 | }
|
---|
1240 | }
|
---|
1241 | } break;
|
---|
1242 |
|
---|
1243 | case VRDE_INPUT_CAD:
|
---|
1244 | {
|
---|
1245 | pConsole->i_getKeyboard()->PutCAD();
|
---|
1246 | } break;
|
---|
1247 |
|
---|
1248 | case VRDE_INPUT_RESET:
|
---|
1249 | {
|
---|
1250 | pConsole->Reset();
|
---|
1251 | } break;
|
---|
1252 |
|
---|
1253 | case VRDE_INPUT_SYNCH:
|
---|
1254 | {
|
---|
1255 | if (cbInput == sizeof(VRDEINPUTSYNCH))
|
---|
1256 | {
|
---|
1257 | IKeyboard *pKeyboard = pConsole->i_getKeyboard();
|
---|
1258 |
|
---|
1259 | const VRDEINPUTSYNCH *pInputSynch = (VRDEINPUTSYNCH *)pvInput;
|
---|
1260 |
|
---|
1261 | server->m_InputSynch.fClientNumLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_NUMLOCK) != 0;
|
---|
1262 | server->m_InputSynch.fClientCapsLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_CAPITAL) != 0;
|
---|
1263 | server->m_InputSynch.fClientScrollLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_SCROLL) != 0;
|
---|
1264 |
|
---|
1265 | /* The client initiated synchronization. Always make the guest to reflect the client state.
|
---|
1266 | * Than means, when the guest changes the state itself, it is forced to return to the client
|
---|
1267 | * state.
|
---|
1268 | */
|
---|
1269 | if (server->m_InputSynch.fClientNumLock != server->m_InputSynch.fGuestNumLock)
|
---|
1270 | {
|
---|
1271 | server->m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 | if (server->m_InputSynch.fClientCapsLock != server->m_InputSynch.fGuestCapsLock)
|
---|
1275 | {
|
---|
1276 | server->m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | fixKbdLockStatus(&server->m_InputSynch, pKeyboard);
|
---|
1280 | }
|
---|
1281 | } break;
|
---|
1282 |
|
---|
1283 | default:
|
---|
1284 | break;
|
---|
1285 | }
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackVideoModeHint(void *pvCallback, unsigned cWidth, unsigned cHeight,
|
---|
1289 | unsigned cBitsPerPixel, unsigned uScreenId)
|
---|
1290 | {
|
---|
1291 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1292 |
|
---|
1293 | server->mConsole->i_getDisplay()->SetVideoModeHint(uScreenId, TRUE /*=enabled*/,
|
---|
1294 | FALSE /*=changeOrigin*/, 0/*=OriginX*/, 0/*=OriginY*/,
|
---|
1295 | cWidth, cHeight, cBitsPerPixel, TRUE /*=notify*/);
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackAudioIn(void *pvCallback,
|
---|
1299 | void *pvCtx,
|
---|
1300 | uint32_t u32ClientId,
|
---|
1301 | uint32_t u32Event,
|
---|
1302 | const void *pvData,
|
---|
1303 | uint32_t cbData)
|
---|
1304 | {
|
---|
1305 | RT_NOREF(u32ClientId);
|
---|
1306 | ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1307 | AssertPtrReturnVoid(pServer);
|
---|
1308 |
|
---|
1309 | #ifdef VBOX_WITH_AUDIO_VRDE
|
---|
1310 | AudioVRDE *pVRDE = pServer->mConsole->i_getAudioVRDE();
|
---|
1311 | if (!pVRDE) /* Nothing to do, bail out early. */
|
---|
1312 | return;
|
---|
1313 |
|
---|
1314 | switch (u32Event)
|
---|
1315 | {
|
---|
1316 | case VRDE_AUDIOIN_BEGIN:
|
---|
1317 | {
|
---|
1318 | pVRDE->onVRDEInputBegin(pvCtx, (PVRDEAUDIOINBEGIN)pvData);
|
---|
1319 | break;
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | case VRDE_AUDIOIN_DATA:
|
---|
1323 | pVRDE->onVRDEInputData(pvCtx, pvData, cbData);
|
---|
1324 | break;
|
---|
1325 |
|
---|
1326 | case VRDE_AUDIOIN_END:
|
---|
1327 | pVRDE->onVRDEInputEnd(pvCtx);
|
---|
1328 | break;
|
---|
1329 |
|
---|
1330 | default:
|
---|
1331 | break;
|
---|
1332 | }
|
---|
1333 | #else
|
---|
1334 | RT_NOREF(pvCtx, u32Event, pvData, cbData);
|
---|
1335 | #endif /* VBOX_WITH_AUDIO_VRDE */
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | ConsoleVRDPServer::ConsoleVRDPServer(Console *console)
|
---|
1339 | {
|
---|
1340 | mConsole = console;
|
---|
1341 |
|
---|
1342 | int rc = RTCritSectInit(&mCritSect);
|
---|
1343 | AssertRC(rc);
|
---|
1344 |
|
---|
1345 | mcClipboardRefs = 0;
|
---|
1346 | mpfnClipboardCallback = NULL;
|
---|
1347 | #ifdef VBOX_WITH_USB
|
---|
1348 | mUSBBackends.pHead = NULL;
|
---|
1349 | mUSBBackends.pTail = NULL;
|
---|
1350 |
|
---|
1351 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
1352 | mUSBBackends.fThreadRunning = false;
|
---|
1353 | mUSBBackends.event = 0;
|
---|
1354 | #endif
|
---|
1355 |
|
---|
1356 | mhServer = 0;
|
---|
1357 | mServerInterfaceVersion = 0;
|
---|
1358 |
|
---|
1359 | mcInResize = 0;
|
---|
1360 |
|
---|
1361 | m_fGuestWantsAbsolute = false;
|
---|
1362 | m_mousex = 0;
|
---|
1363 | m_mousey = 0;
|
---|
1364 |
|
---|
1365 | m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
1366 | m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
1367 |
|
---|
1368 | m_InputSynch.fGuestNumLock = false;
|
---|
1369 | m_InputSynch.fGuestCapsLock = false;
|
---|
1370 | m_InputSynch.fGuestScrollLock = false;
|
---|
1371 |
|
---|
1372 | m_InputSynch.fClientNumLock = false;
|
---|
1373 | m_InputSynch.fClientCapsLock = false;
|
---|
1374 | m_InputSynch.fClientScrollLock = false;
|
---|
1375 |
|
---|
1376 | {
|
---|
1377 | ComPtr<IEventSource> es;
|
---|
1378 | console->COMGETTER(EventSource)(es.asOutParam());
|
---|
1379 | ComObjPtr<VRDPConsoleListenerImpl> aConsoleListener;
|
---|
1380 | aConsoleListener.createObject();
|
---|
1381 | aConsoleListener->init(new VRDPConsoleListener(), this);
|
---|
1382 | mConsoleListener = aConsoleListener;
|
---|
1383 | com::SafeArray <VBoxEventType_T> eventTypes;
|
---|
1384 | eventTypes.push_back(VBoxEventType_OnMousePointerShapeChanged);
|
---|
1385 | eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged);
|
---|
1386 | eventTypes.push_back(VBoxEventType_OnKeyboardLedsChanged);
|
---|
1387 | es->RegisterListener(mConsoleListener, ComSafeArrayAsInParam(eventTypes), true);
|
---|
1388 | }
|
---|
1389 |
|
---|
1390 | mVRDPBindPort = -1;
|
---|
1391 |
|
---|
1392 | #ifndef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
|
---|
1393 | RT_ZERO(mAuthLibCtx);
|
---|
1394 | #endif
|
---|
1395 |
|
---|
1396 | mu32AudioInputClientId = 0;
|
---|
1397 | mcClients = 0;
|
---|
1398 |
|
---|
1399 | /*
|
---|
1400 | * Optional interfaces.
|
---|
1401 | */
|
---|
1402 | m_fInterfaceImage = false;
|
---|
1403 | RT_ZERO(m_interfaceImage);
|
---|
1404 | RT_ZERO(m_interfaceCallbacksImage);
|
---|
1405 | RT_ZERO(m_interfaceMousePtr);
|
---|
1406 | RT_ZERO(m_interfaceSCard);
|
---|
1407 | RT_ZERO(m_interfaceCallbacksSCard);
|
---|
1408 | RT_ZERO(m_interfaceTSMF);
|
---|
1409 | RT_ZERO(m_interfaceCallbacksTSMF);
|
---|
1410 | RT_ZERO(m_interfaceVideoIn);
|
---|
1411 | RT_ZERO(m_interfaceCallbacksVideoIn);
|
---|
1412 | RT_ZERO(m_interfaceInput);
|
---|
1413 | RT_ZERO(m_interfaceCallbacksInput);
|
---|
1414 |
|
---|
1415 | rc = RTCritSectInit(&mTSMFLock);
|
---|
1416 | AssertRC(rc);
|
---|
1417 |
|
---|
1418 | mEmWebcam = new EmWebcam(this);
|
---|
1419 | AssertPtr(mEmWebcam);
|
---|
1420 | }
|
---|
1421 |
|
---|
1422 | ConsoleVRDPServer::~ConsoleVRDPServer()
|
---|
1423 | {
|
---|
1424 | Stop();
|
---|
1425 |
|
---|
1426 | if (mConsoleListener)
|
---|
1427 | {
|
---|
1428 | ComPtr<IEventSource> es;
|
---|
1429 | mConsole->COMGETTER(EventSource)(es.asOutParam());
|
---|
1430 | es->UnregisterListener(mConsoleListener);
|
---|
1431 | mConsoleListener.setNull();
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 | unsigned i;
|
---|
1435 | for (i = 0; i < RT_ELEMENTS(maSourceBitmaps); i++)
|
---|
1436 | {
|
---|
1437 | maSourceBitmaps[i].setNull();
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | if (mEmWebcam)
|
---|
1441 | {
|
---|
1442 | delete mEmWebcam;
|
---|
1443 | mEmWebcam = NULL;
|
---|
1444 | }
|
---|
1445 |
|
---|
1446 | if (RTCritSectIsInitialized(&mCritSect))
|
---|
1447 | {
|
---|
1448 | RTCritSectDelete(&mCritSect);
|
---|
1449 | RT_ZERO(mCritSect);
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | if (RTCritSectIsInitialized(&mTSMFLock))
|
---|
1453 | {
|
---|
1454 | RTCritSectDelete(&mTSMFLock);
|
---|
1455 | RT_ZERO(mTSMFLock);
|
---|
1456 | }
|
---|
1457 | }
|
---|
1458 |
|
---|
1459 | int ConsoleVRDPServer::Launch(void)
|
---|
1460 | {
|
---|
1461 | LogFlowThisFunc(("\n"));
|
---|
1462 |
|
---|
1463 | IVRDEServer *server = mConsole->i_getVRDEServer();
|
---|
1464 | AssertReturn(server, VERR_INTERNAL_ERROR_2);
|
---|
1465 |
|
---|
1466 | /*
|
---|
1467 | * Check if VRDE is enabled.
|
---|
1468 | */
|
---|
1469 | BOOL fEnabled;
|
---|
1470 | HRESULT hrc = server->COMGETTER(Enabled)(&fEnabled);
|
---|
1471 | AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc));
|
---|
1472 | if (!fEnabled)
|
---|
1473 | return VINF_SUCCESS;
|
---|
1474 |
|
---|
1475 | /*
|
---|
1476 | * Check that a VRDE extension pack name is set and resolve it into a
|
---|
1477 | * library path.
|
---|
1478 | */
|
---|
1479 | Bstr bstrExtPack;
|
---|
1480 | hrc = server->COMGETTER(VRDEExtPack)(bstrExtPack.asOutParam());
|
---|
1481 | if (FAILED(hrc))
|
---|
1482 | return Global::vboxStatusCodeFromCOM(hrc);
|
---|
1483 | if (bstrExtPack.isEmpty())
|
---|
1484 | return VINF_NOT_SUPPORTED;
|
---|
1485 |
|
---|
1486 | Utf8Str strExtPack(bstrExtPack);
|
---|
1487 | Utf8Str strVrdeLibrary;
|
---|
1488 | int vrc = VINF_SUCCESS;
|
---|
1489 | if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
|
---|
1490 | strVrdeLibrary = "VBoxVRDP";
|
---|
1491 | else
|
---|
1492 | {
|
---|
1493 | #ifdef VBOX_WITH_EXTPACK
|
---|
1494 | ExtPackManager *pExtPackMgr = mConsole->i_getExtPackManager();
|
---|
1495 | vrc = pExtPackMgr->i_getVrdeLibraryPathForExtPack(&strExtPack, &strVrdeLibrary);
|
---|
1496 | #else
|
---|
1497 | vrc = VERR_FILE_NOT_FOUND;
|
---|
1498 | #endif
|
---|
1499 | }
|
---|
1500 | if (RT_SUCCESS(vrc))
|
---|
1501 | {
|
---|
1502 | /*
|
---|
1503 | * Load the VRDE library and start the server, if it is enabled.
|
---|
1504 | */
|
---|
1505 | vrc = loadVRDPLibrary(strVrdeLibrary.c_str());
|
---|
1506 | if (RT_SUCCESS(vrc))
|
---|
1507 | {
|
---|
1508 | VRDEENTRYPOINTS_4 *pEntryPoints4;
|
---|
1509 | vrc = mpfnVRDECreateServer(&mCallbacks.header, this, (VRDEINTERFACEHDR **)&pEntryPoints4, &mhServer);
|
---|
1510 |
|
---|
1511 | if (RT_SUCCESS(vrc))
|
---|
1512 | {
|
---|
1513 | mServerInterfaceVersion = 4;
|
---|
1514 | mEntryPoints = *pEntryPoints4;
|
---|
1515 | mpEntryPoints = &mEntryPoints;
|
---|
1516 | }
|
---|
1517 | else if (vrc == VERR_VERSION_MISMATCH)
|
---|
1518 | {
|
---|
1519 | /* An older version of VRDE is installed, try version 3. */
|
---|
1520 | VRDEENTRYPOINTS_3 *pEntryPoints3;
|
---|
1521 |
|
---|
1522 | static VRDECALLBACKS_3 sCallbacks3 =
|
---|
1523 | {
|
---|
1524 | { VRDE_INTERFACE_VERSION_3, sizeof(VRDECALLBACKS_3) },
|
---|
1525 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
1526 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
1527 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
1528 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
1529 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
1530 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
1531 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
1532 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
1533 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
1534 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
1535 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
1536 | ConsoleVRDPServer::VRDPCallbackVideoModeHint,
|
---|
1537 | ConsoleVRDPServer::VRDECallbackAudioIn
|
---|
1538 | };
|
---|
1539 |
|
---|
1540 | vrc = mpfnVRDECreateServer(&sCallbacks3.header, this, (VRDEINTERFACEHDR **)&pEntryPoints3, &mhServer);
|
---|
1541 | if (RT_SUCCESS(vrc))
|
---|
1542 | {
|
---|
1543 | mServerInterfaceVersion = 3;
|
---|
1544 | mEntryPoints.header = pEntryPoints3->header;
|
---|
1545 | mEntryPoints.VRDEDestroy = pEntryPoints3->VRDEDestroy;
|
---|
1546 | mEntryPoints.VRDEEnableConnections = pEntryPoints3->VRDEEnableConnections;
|
---|
1547 | mEntryPoints.VRDEDisconnect = pEntryPoints3->VRDEDisconnect;
|
---|
1548 | mEntryPoints.VRDEResize = pEntryPoints3->VRDEResize;
|
---|
1549 | mEntryPoints.VRDEUpdate = pEntryPoints3->VRDEUpdate;
|
---|
1550 | mEntryPoints.VRDEColorPointer = pEntryPoints3->VRDEColorPointer;
|
---|
1551 | mEntryPoints.VRDEHidePointer = pEntryPoints3->VRDEHidePointer;
|
---|
1552 | mEntryPoints.VRDEAudioSamples = pEntryPoints3->VRDEAudioSamples;
|
---|
1553 | mEntryPoints.VRDEAudioVolume = pEntryPoints3->VRDEAudioVolume;
|
---|
1554 | mEntryPoints.VRDEUSBRequest = pEntryPoints3->VRDEUSBRequest;
|
---|
1555 | mEntryPoints.VRDEClipboard = pEntryPoints3->VRDEClipboard;
|
---|
1556 | mEntryPoints.VRDEQueryInfo = pEntryPoints3->VRDEQueryInfo;
|
---|
1557 | mEntryPoints.VRDERedirect = pEntryPoints3->VRDERedirect;
|
---|
1558 | mEntryPoints.VRDEAudioInOpen = pEntryPoints3->VRDEAudioInOpen;
|
---|
1559 | mEntryPoints.VRDEAudioInClose = pEntryPoints3->VRDEAudioInClose;
|
---|
1560 | mEntryPoints.VRDEGetInterface = NULL;
|
---|
1561 | mpEntryPoints = &mEntryPoints;
|
---|
1562 | }
|
---|
1563 | else if (vrc == VERR_VERSION_MISMATCH)
|
---|
1564 | {
|
---|
1565 | /* An older version of VRDE is installed, try version 1. */
|
---|
1566 | VRDEENTRYPOINTS_1 *pEntryPoints1;
|
---|
1567 |
|
---|
1568 | static VRDECALLBACKS_1 sCallbacks1 =
|
---|
1569 | {
|
---|
1570 | { VRDE_INTERFACE_VERSION_1, sizeof(VRDECALLBACKS_1) },
|
---|
1571 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
1572 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
1573 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
1574 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
1575 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
1576 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
1577 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
1578 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
1579 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
1580 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
1581 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
1582 | ConsoleVRDPServer::VRDPCallbackVideoModeHint
|
---|
1583 | };
|
---|
1584 |
|
---|
1585 | vrc = mpfnVRDECreateServer(&sCallbacks1.header, this, (VRDEINTERFACEHDR **)&pEntryPoints1, &mhServer);
|
---|
1586 | if (RT_SUCCESS(vrc))
|
---|
1587 | {
|
---|
1588 | mServerInterfaceVersion = 1;
|
---|
1589 | mEntryPoints.header = pEntryPoints1->header;
|
---|
1590 | mEntryPoints.VRDEDestroy = pEntryPoints1->VRDEDestroy;
|
---|
1591 | mEntryPoints.VRDEEnableConnections = pEntryPoints1->VRDEEnableConnections;
|
---|
1592 | mEntryPoints.VRDEDisconnect = pEntryPoints1->VRDEDisconnect;
|
---|
1593 | mEntryPoints.VRDEResize = pEntryPoints1->VRDEResize;
|
---|
1594 | mEntryPoints.VRDEUpdate = pEntryPoints1->VRDEUpdate;
|
---|
1595 | mEntryPoints.VRDEColorPointer = pEntryPoints1->VRDEColorPointer;
|
---|
1596 | mEntryPoints.VRDEHidePointer = pEntryPoints1->VRDEHidePointer;
|
---|
1597 | mEntryPoints.VRDEAudioSamples = pEntryPoints1->VRDEAudioSamples;
|
---|
1598 | mEntryPoints.VRDEAudioVolume = pEntryPoints1->VRDEAudioVolume;
|
---|
1599 | mEntryPoints.VRDEUSBRequest = pEntryPoints1->VRDEUSBRequest;
|
---|
1600 | mEntryPoints.VRDEClipboard = pEntryPoints1->VRDEClipboard;
|
---|
1601 | mEntryPoints.VRDEQueryInfo = pEntryPoints1->VRDEQueryInfo;
|
---|
1602 | mEntryPoints.VRDERedirect = NULL;
|
---|
1603 | mEntryPoints.VRDEAudioInOpen = NULL;
|
---|
1604 | mEntryPoints.VRDEAudioInClose = NULL;
|
---|
1605 | mEntryPoints.VRDEGetInterface = NULL;
|
---|
1606 | mpEntryPoints = &mEntryPoints;
|
---|
1607 | }
|
---|
1608 | }
|
---|
1609 | }
|
---|
1610 |
|
---|
1611 | if (RT_SUCCESS(vrc))
|
---|
1612 | {
|
---|
1613 | LogRel(("VRDE: loaded version %d of the server.\n", mServerInterfaceVersion));
|
---|
1614 |
|
---|
1615 | if (mServerInterfaceVersion >= 4)
|
---|
1616 | {
|
---|
1617 | /* The server supports optional interfaces. */
|
---|
1618 | Assert(mpEntryPoints->VRDEGetInterface != NULL);
|
---|
1619 |
|
---|
1620 | /* Image interface. */
|
---|
1621 | m_interfaceImage.header.u64Version = 1;
|
---|
1622 | m_interfaceImage.header.u64Size = sizeof(m_interfaceImage);
|
---|
1623 |
|
---|
1624 | m_interfaceCallbacksImage.header.u64Version = 1;
|
---|
1625 | m_interfaceCallbacksImage.header.u64Size = sizeof(m_interfaceCallbacksImage);
|
---|
1626 | m_interfaceCallbacksImage.VRDEImageCbNotify = VRDEImageCbNotify;
|
---|
1627 |
|
---|
1628 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1629 | VRDE_IMAGE_INTERFACE_NAME,
|
---|
1630 | &m_interfaceImage.header,
|
---|
1631 | &m_interfaceCallbacksImage.header,
|
---|
1632 | this);
|
---|
1633 | if (RT_SUCCESS(vrc))
|
---|
1634 | {
|
---|
1635 | LogRel(("VRDE: [%s]\n", VRDE_IMAGE_INTERFACE_NAME));
|
---|
1636 | m_fInterfaceImage = true;
|
---|
1637 | }
|
---|
1638 |
|
---|
1639 | /* Mouse pointer interface. */
|
---|
1640 | m_interfaceMousePtr.header.u64Version = 1;
|
---|
1641 | m_interfaceMousePtr.header.u64Size = sizeof(m_interfaceMousePtr);
|
---|
1642 |
|
---|
1643 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1644 | VRDE_MOUSEPTR_INTERFACE_NAME,
|
---|
1645 | &m_interfaceMousePtr.header,
|
---|
1646 | NULL,
|
---|
1647 | this);
|
---|
1648 | if (RT_SUCCESS(vrc))
|
---|
1649 | {
|
---|
1650 | LogRel(("VRDE: [%s]\n", VRDE_MOUSEPTR_INTERFACE_NAME));
|
---|
1651 | }
|
---|
1652 | else
|
---|
1653 | {
|
---|
1654 | RT_ZERO(m_interfaceMousePtr);
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | /* Smartcard interface. */
|
---|
1658 | m_interfaceSCard.header.u64Version = 1;
|
---|
1659 | m_interfaceSCard.header.u64Size = sizeof(m_interfaceSCard);
|
---|
1660 |
|
---|
1661 | m_interfaceCallbacksSCard.header.u64Version = 1;
|
---|
1662 | m_interfaceCallbacksSCard.header.u64Size = sizeof(m_interfaceCallbacksSCard);
|
---|
1663 | m_interfaceCallbacksSCard.VRDESCardCbNotify = VRDESCardCbNotify;
|
---|
1664 | m_interfaceCallbacksSCard.VRDESCardCbResponse = VRDESCardCbResponse;
|
---|
1665 |
|
---|
1666 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1667 | VRDE_SCARD_INTERFACE_NAME,
|
---|
1668 | &m_interfaceSCard.header,
|
---|
1669 | &m_interfaceCallbacksSCard.header,
|
---|
1670 | this);
|
---|
1671 | if (RT_SUCCESS(vrc))
|
---|
1672 | {
|
---|
1673 | LogRel(("VRDE: [%s]\n", VRDE_SCARD_INTERFACE_NAME));
|
---|
1674 | }
|
---|
1675 | else
|
---|
1676 | {
|
---|
1677 | RT_ZERO(m_interfaceSCard);
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 | /* Raw TSMF interface. */
|
---|
1681 | m_interfaceTSMF.header.u64Version = 1;
|
---|
1682 | m_interfaceTSMF.header.u64Size = sizeof(m_interfaceTSMF);
|
---|
1683 |
|
---|
1684 | m_interfaceCallbacksTSMF.header.u64Version = 1;
|
---|
1685 | m_interfaceCallbacksTSMF.header.u64Size = sizeof(m_interfaceCallbacksTSMF);
|
---|
1686 | m_interfaceCallbacksTSMF.VRDETSMFCbNotify = VRDETSMFCbNotify;
|
---|
1687 |
|
---|
1688 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1689 | VRDE_TSMF_INTERFACE_NAME,
|
---|
1690 | &m_interfaceTSMF.header,
|
---|
1691 | &m_interfaceCallbacksTSMF.header,
|
---|
1692 | this);
|
---|
1693 | if (RT_SUCCESS(vrc))
|
---|
1694 | {
|
---|
1695 | LogRel(("VRDE: [%s]\n", VRDE_TSMF_INTERFACE_NAME));
|
---|
1696 | }
|
---|
1697 | else
|
---|
1698 | {
|
---|
1699 | RT_ZERO(m_interfaceTSMF);
|
---|
1700 | }
|
---|
1701 |
|
---|
1702 | /* VideoIn interface. */
|
---|
1703 | m_interfaceVideoIn.header.u64Version = 1;
|
---|
1704 | m_interfaceVideoIn.header.u64Size = sizeof(m_interfaceVideoIn);
|
---|
1705 |
|
---|
1706 | m_interfaceCallbacksVideoIn.header.u64Version = 1;
|
---|
1707 | m_interfaceCallbacksVideoIn.header.u64Size = sizeof(m_interfaceCallbacksVideoIn);
|
---|
1708 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInNotify = VRDECallbackVideoInNotify;
|
---|
1709 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInDeviceDesc = VRDECallbackVideoInDeviceDesc;
|
---|
1710 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInControl = VRDECallbackVideoInControl;
|
---|
1711 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInFrame = VRDECallbackVideoInFrame;
|
---|
1712 |
|
---|
1713 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1714 | VRDE_VIDEOIN_INTERFACE_NAME,
|
---|
1715 | &m_interfaceVideoIn.header,
|
---|
1716 | &m_interfaceCallbacksVideoIn.header,
|
---|
1717 | this);
|
---|
1718 | if (RT_SUCCESS(vrc))
|
---|
1719 | {
|
---|
1720 | LogRel(("VRDE: [%s]\n", VRDE_VIDEOIN_INTERFACE_NAME));
|
---|
1721 | }
|
---|
1722 | else
|
---|
1723 | {
|
---|
1724 | RT_ZERO(m_interfaceVideoIn);
|
---|
1725 | }
|
---|
1726 |
|
---|
1727 | /* Input interface. */
|
---|
1728 | m_interfaceInput.header.u64Version = 1;
|
---|
1729 | m_interfaceInput.header.u64Size = sizeof(m_interfaceInput);
|
---|
1730 |
|
---|
1731 | m_interfaceCallbacksInput.header.u64Version = 1;
|
---|
1732 | m_interfaceCallbacksInput.header.u64Size = sizeof(m_interfaceCallbacksInput);
|
---|
1733 | m_interfaceCallbacksInput.VRDECallbackInputSetup = VRDECallbackInputSetup;
|
---|
1734 | m_interfaceCallbacksInput.VRDECallbackInputEvent = VRDECallbackInputEvent;
|
---|
1735 |
|
---|
1736 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1737 | VRDE_INPUT_INTERFACE_NAME,
|
---|
1738 | &m_interfaceInput.header,
|
---|
1739 | &m_interfaceCallbacksInput.header,
|
---|
1740 | this);
|
---|
1741 | if (RT_SUCCESS(vrc))
|
---|
1742 | {
|
---|
1743 | LogRel(("VRDE: [%s]\n", VRDE_INPUT_INTERFACE_NAME));
|
---|
1744 | }
|
---|
1745 | else
|
---|
1746 | {
|
---|
1747 | RT_ZERO(m_interfaceInput);
|
---|
1748 | }
|
---|
1749 |
|
---|
1750 | /* Since these interfaces are optional, it is always a success here. */
|
---|
1751 | vrc = VINF_SUCCESS;
|
---|
1752 | }
|
---|
1753 | #ifdef VBOX_WITH_USB
|
---|
1754 | remoteUSBThreadStart();
|
---|
1755 | #endif
|
---|
1756 |
|
---|
1757 | /*
|
---|
1758 | * Re-init the server current state, which is usually obtained from events.
|
---|
1759 | */
|
---|
1760 | fetchCurrentState();
|
---|
1761 | }
|
---|
1762 | else
|
---|
1763 | {
|
---|
1764 | if (vrc != VERR_NET_ADDRESS_IN_USE)
|
---|
1765 | LogRel(("VRDE: Could not start the server rc = %Rrc\n", vrc));
|
---|
1766 | /* Don't unload the lib, because it prevents us trying again or
|
---|
1767 | because there may be other users? */
|
---|
1768 | }
|
---|
1769 | }
|
---|
1770 | }
|
---|
1771 |
|
---|
1772 | return vrc;
|
---|
1773 | }
|
---|
1774 |
|
---|
1775 | void ConsoleVRDPServer::fetchCurrentState(void)
|
---|
1776 | {
|
---|
1777 | ComPtr<IMousePointerShape> mps;
|
---|
1778 | mConsole->i_getMouse()->COMGETTER(PointerShape)(mps.asOutParam());
|
---|
1779 | if (!mps.isNull())
|
---|
1780 | {
|
---|
1781 | BOOL visible, alpha;
|
---|
1782 | ULONG hotX, hotY, width, height;
|
---|
1783 | com::SafeArray <BYTE> shape;
|
---|
1784 |
|
---|
1785 | mps->COMGETTER(Visible)(&visible);
|
---|
1786 | mps->COMGETTER(Alpha)(&alpha);
|
---|
1787 | mps->COMGETTER(HotX)(&hotX);
|
---|
1788 | mps->COMGETTER(HotY)(&hotY);
|
---|
1789 | mps->COMGETTER(Width)(&width);
|
---|
1790 | mps->COMGETTER(Height)(&height);
|
---|
1791 | mps->COMGETTER(Shape)(ComSafeArrayAsOutParam(shape));
|
---|
1792 |
|
---|
1793 | onMousePointerShapeChange(visible, alpha, hotX, hotY, width, height, ComSafeArrayAsInParam(shape));
|
---|
1794 | }
|
---|
1795 | }
|
---|
1796 |
|
---|
1797 | #if 0 /** @todo Chromium got removed (see @bugref{9529}) and this is not available for VMSVGA yet. */
|
---|
1798 | typedef struct H3DORInstance
|
---|
1799 | {
|
---|
1800 | ConsoleVRDPServer *pThis;
|
---|
1801 | HVRDEIMAGE hImageBitmap;
|
---|
1802 | int32_t x;
|
---|
1803 | int32_t y;
|
---|
1804 | uint32_t w;
|
---|
1805 | uint32_t h;
|
---|
1806 | bool fCreated;
|
---|
1807 | bool fFallback;
|
---|
1808 | bool fTopDown;
|
---|
1809 | } H3DORInstance;
|
---|
1810 |
|
---|
1811 | #define H3DORLOG Log
|
---|
1812 |
|
---|
1813 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORBegin(const void *pvContext, void **ppvInstance,
|
---|
1814 | const char *pszFormat)
|
---|
1815 | {
|
---|
1816 | H3DORLOG(("H3DORBegin: ctx %p [%s]\n", pvContext, pszFormat));
|
---|
1817 |
|
---|
1818 | H3DORInstance *p = (H3DORInstance *)RTMemAlloc(sizeof(H3DORInstance));
|
---|
1819 |
|
---|
1820 | if (p)
|
---|
1821 | {
|
---|
1822 | p->pThis = (ConsoleVRDPServer *)pvContext;
|
---|
1823 | p->hImageBitmap = NULL;
|
---|
1824 | p->x = 0;
|
---|
1825 | p->y = 0;
|
---|
1826 | p->w = 0;
|
---|
1827 | p->h = 0;
|
---|
1828 | p->fCreated = false;
|
---|
1829 | p->fFallback = false;
|
---|
1830 |
|
---|
1831 | /* Host 3D service passes the actual format of data in this redirect instance.
|
---|
1832 | * That is what will be in the H3DORFrame's parameters pvData and cbData.
|
---|
1833 | */
|
---|
1834 | if (RTStrICmp(pszFormat, H3DOR_FMT_RGBA_TOPDOWN) == 0)
|
---|
1835 | {
|
---|
1836 | /* Accept it. */
|
---|
1837 | p->fTopDown = true;
|
---|
1838 | }
|
---|
1839 | else if (RTStrICmp(pszFormat, H3DOR_FMT_RGBA) == 0)
|
---|
1840 | {
|
---|
1841 | /* Accept it. */
|
---|
1842 | p->fTopDown = false;
|
---|
1843 | }
|
---|
1844 | else
|
---|
1845 | {
|
---|
1846 | RTMemFree(p);
|
---|
1847 | p = NULL;
|
---|
1848 | }
|
---|
1849 | }
|
---|
1850 |
|
---|
1851 | H3DORLOG(("H3DORBegin: ins %p\n", p));
|
---|
1852 |
|
---|
1853 | /* Caller checks this for NULL. */
|
---|
1854 | *ppvInstance = p;
|
---|
1855 | }
|
---|
1856 |
|
---|
1857 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORGeometry(void *pvInstance,
|
---|
1858 | int32_t x, int32_t y, uint32_t w, uint32_t h)
|
---|
1859 | {
|
---|
1860 | H3DORLOG(("H3DORGeometry: ins %p %d,%d %dx%d\n", pvInstance, x, y, w, h));
|
---|
1861 |
|
---|
1862 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1863 | AssertPtrReturnVoid(p);
|
---|
1864 | AssertPtrReturnVoid(p->pThis);
|
---|
1865 |
|
---|
1866 | /** @todo find out what to do if size changes to 0x0 from non zero */
|
---|
1867 | if (w == 0 || h == 0)
|
---|
1868 | {
|
---|
1869 | /* Do nothing. */
|
---|
1870 | return;
|
---|
1871 | }
|
---|
1872 |
|
---|
1873 | RTRECT rect;
|
---|
1874 | rect.xLeft = x;
|
---|
1875 | rect.yTop = y;
|
---|
1876 | rect.xRight = x + w;
|
---|
1877 | rect.yBottom = y + h;
|
---|
1878 |
|
---|
1879 | if (p->hImageBitmap)
|
---|
1880 | {
|
---|
1881 | /* An image handle has been already created,
|
---|
1882 | * check if it has the same size as the reported geometry.
|
---|
1883 | */
|
---|
1884 | if ( p->x == x
|
---|
1885 | && p->y == y
|
---|
1886 | && p->w == w
|
---|
1887 | && p->h == h)
|
---|
1888 | {
|
---|
1889 | H3DORLOG(("H3DORGeometry: geometry not changed\n"));
|
---|
1890 | /* Do nothing. Continue using the existing handle. */
|
---|
1891 | }
|
---|
1892 | else
|
---|
1893 | {
|
---|
1894 | int rc = p->fFallback?
|
---|
1895 | VERR_NOT_SUPPORTED: /* Try to go out of fallback mode. */
|
---|
1896 | p->pThis->m_interfaceImage.VRDEImageGeometrySet(p->hImageBitmap, &rect);
|
---|
1897 | if (RT_SUCCESS(rc))
|
---|
1898 | {
|
---|
1899 | p->x = x;
|
---|
1900 | p->y = y;
|
---|
1901 | p->w = w;
|
---|
1902 | p->h = h;
|
---|
1903 | }
|
---|
1904 | else
|
---|
1905 | {
|
---|
1906 | /* The handle must be recreated. Delete existing handle here. */
|
---|
1907 | p->pThis->m_interfaceImage.VRDEImageHandleClose(p->hImageBitmap);
|
---|
1908 | p->hImageBitmap = NULL;
|
---|
1909 | }
|
---|
1910 | }
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | if (!p->hImageBitmap)
|
---|
1914 | {
|
---|
1915 | /* Create a new bitmap handle. */
|
---|
1916 | uint32_t u32ScreenId = 0; /** @todo clip to corresponding screens.
|
---|
1917 | * Clipping can be done here or in VRDP server.
|
---|
1918 | * If VRDP does clipping, then uScreenId parameter
|
---|
1919 | * is not necessary and coords must be global.
|
---|
1920 | * (have to check which coords are used in opengl service).
|
---|
1921 | * Since all VRDE API uses a ScreenId,
|
---|
1922 | * the clipping must be done here in ConsoleVRDPServer
|
---|
1923 | */
|
---|
1924 | uint32_t fu32CompletionFlags = 0;
|
---|
1925 | p->fFallback = false;
|
---|
1926 | int rc = p->pThis->m_interfaceImage.VRDEImageHandleCreate(p->pThis->mhServer,
|
---|
1927 | &p->hImageBitmap,
|
---|
1928 | p,
|
---|
1929 | u32ScreenId,
|
---|
1930 | VRDE_IMAGE_F_CREATE_CONTENT_3D
|
---|
1931 | | VRDE_IMAGE_F_CREATE_WINDOW,
|
---|
1932 | &rect,
|
---|
1933 | VRDE_IMAGE_FMT_ID_BITMAP_BGRA8,
|
---|
1934 | NULL,
|
---|
1935 | 0,
|
---|
1936 | &fu32CompletionFlags);
|
---|
1937 | if (RT_FAILURE(rc))
|
---|
1938 | {
|
---|
1939 | /* No support for a 3D + WINDOW. Try bitmap updates. */
|
---|
1940 | H3DORLOG(("H3DORGeometry: Fallback to bitmaps\n"));
|
---|
1941 | fu32CompletionFlags = 0;
|
---|
1942 | p->fFallback = true;
|
---|
1943 | rc = p->pThis->m_interfaceImage.VRDEImageHandleCreate(p->pThis->mhServer,
|
---|
1944 | &p->hImageBitmap,
|
---|
1945 | p,
|
---|
1946 | u32ScreenId,
|
---|
1947 | 0,
|
---|
1948 | &rect,
|
---|
1949 | VRDE_IMAGE_FMT_ID_BITMAP_BGRA8,
|
---|
1950 | NULL,
|
---|
1951 | 0,
|
---|
1952 | &fu32CompletionFlags);
|
---|
1953 | }
|
---|
1954 |
|
---|
1955 | H3DORLOG(("H3DORGeometry: Image handle create %Rrc, flags 0x%RX32\n", rc, fu32CompletionFlags));
|
---|
1956 |
|
---|
1957 | if (RT_SUCCESS(rc))
|
---|
1958 | {
|
---|
1959 | p->x = x;
|
---|
1960 | p->y = y;
|
---|
1961 | p->w = w;
|
---|
1962 | p->h = h;
|
---|
1963 |
|
---|
1964 | if ((fu32CompletionFlags & VRDE_IMAGE_F_COMPLETE_ASYNC) == 0)
|
---|
1965 | {
|
---|
1966 | p->fCreated = true;
|
---|
1967 | }
|
---|
1968 | }
|
---|
1969 | else
|
---|
1970 | {
|
---|
1971 | p->hImageBitmap = NULL;
|
---|
1972 | p->w = 0;
|
---|
1973 | p->h = 0;
|
---|
1974 | }
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 | H3DORLOG(("H3DORGeometry: ins %p completed\n", pvInstance));
|
---|
1978 | }
|
---|
1979 |
|
---|
1980 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORVisibleRegion(void *pvInstance,
|
---|
1981 | uint32_t cRects, const RTRECT *paRects)
|
---|
1982 | {
|
---|
1983 | H3DORLOG(("H3DORVisibleRegion: ins %p %d\n", pvInstance, cRects));
|
---|
1984 |
|
---|
1985 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1986 | AssertPtrReturnVoid(p);
|
---|
1987 | AssertPtrReturnVoid(p->pThis);
|
---|
1988 |
|
---|
1989 | if (cRects == 0)
|
---|
1990 | {
|
---|
1991 | /* Complete image is visible. */
|
---|
1992 | RTRECT rect;
|
---|
1993 | rect.xLeft = p->x;
|
---|
1994 | rect.yTop = p->y;
|
---|
1995 | rect.xRight = p->x + p->w;
|
---|
1996 | rect.yBottom = p->y + p->h;
|
---|
1997 | p->pThis->m_interfaceImage.VRDEImageRegionSet (p->hImageBitmap,
|
---|
1998 | 1,
|
---|
1999 | &rect);
|
---|
2000 | }
|
---|
2001 | else
|
---|
2002 | {
|
---|
2003 | p->pThis->m_interfaceImage.VRDEImageRegionSet (p->hImageBitmap,
|
---|
2004 | cRects,
|
---|
2005 | paRects);
|
---|
2006 | }
|
---|
2007 |
|
---|
2008 | H3DORLOG(("H3DORVisibleRegion: ins %p completed\n", pvInstance));
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORFrame(void *pvInstance,
|
---|
2012 | void *pvData, uint32_t cbData)
|
---|
2013 | {
|
---|
2014 | H3DORLOG(("H3DORFrame: ins %p %p %d\n", pvInstance, pvData, cbData));
|
---|
2015 |
|
---|
2016 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
2017 | AssertPtrReturnVoid(p);
|
---|
2018 | AssertPtrReturnVoid(p->pThis);
|
---|
2019 |
|
---|
2020 | /* Currently only a topdown BGR0 bitmap format is supported. */
|
---|
2021 | VRDEIMAGEBITMAP image;
|
---|
2022 |
|
---|
2023 | image.cWidth = p->w;
|
---|
2024 | image.cHeight = p->h;
|
---|
2025 | image.pvData = pvData;
|
---|
2026 | image.cbData = cbData;
|
---|
2027 | image.pvScanLine0 = (uint8_t *)pvData + (p->h - 1) * p->w * 4;
|
---|
2028 | image.iScanDelta = 4 * p->w;
|
---|
2029 | if (p->fTopDown)
|
---|
2030 | {
|
---|
2031 | image.iScanDelta = -image.iScanDelta;
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 | p->pThis->m_interfaceImage.VRDEImageUpdate (p->hImageBitmap,
|
---|
2035 | p->x,
|
---|
2036 | p->y,
|
---|
2037 | p->w,
|
---|
2038 | p->h,
|
---|
2039 | &image,
|
---|
2040 | sizeof(VRDEIMAGEBITMAP));
|
---|
2041 |
|
---|
2042 | H3DORLOG(("H3DORFrame: ins %p completed\n", pvInstance));
|
---|
2043 | }
|
---|
2044 |
|
---|
2045 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DOREnd(void *pvInstance)
|
---|
2046 | {
|
---|
2047 | H3DORLOG(("H3DOREnd: ins %p\n", pvInstance));
|
---|
2048 |
|
---|
2049 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
2050 | AssertPtrReturnVoid(p);
|
---|
2051 | AssertPtrReturnVoid(p->pThis);
|
---|
2052 |
|
---|
2053 | p->pThis->m_interfaceImage.VRDEImageHandleClose(p->hImageBitmap);
|
---|
2054 |
|
---|
2055 | RT_ZERO(*p);
|
---|
2056 | RTMemFree(p);
|
---|
2057 |
|
---|
2058 | H3DORLOG(("H3DOREnd: ins %p completed\n", pvInstance));
|
---|
2059 | }
|
---|
2060 |
|
---|
2061 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::H3DORContextProperty(const void *pvContext, uint32_t index,
|
---|
2062 | void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut)
|
---|
2063 | {
|
---|
2064 | RT_NOREF(pvContext, pvBuffer);
|
---|
2065 | int rc = VINF_SUCCESS;
|
---|
2066 |
|
---|
2067 | H3DORLOG(("H3DORContextProperty: index %d\n", index));
|
---|
2068 |
|
---|
2069 | if (index == H3DOR_PROP_FORMATS)
|
---|
2070 | {
|
---|
2071 | /* Return a comma separated list of supported formats. */
|
---|
2072 | uint32_t cbOut = (uint32_t)strlen(H3DOR_FMT_RGBA_TOPDOWN) + 1
|
---|
2073 | + (uint32_t)strlen(H3DOR_FMT_RGBA) + 1;
|
---|
2074 | if (cbOut <= cbBuffer)
|
---|
2075 | {
|
---|
2076 | char *pch = (char *)pvBuffer;
|
---|
2077 | memcpy(pch, H3DOR_FMT_RGBA_TOPDOWN, strlen(H3DOR_FMT_RGBA_TOPDOWN));
|
---|
2078 | pch += strlen(H3DOR_FMT_RGBA_TOPDOWN);
|
---|
2079 | *pch++ = ',';
|
---|
2080 | memcpy(pch, H3DOR_FMT_RGBA, strlen(H3DOR_FMT_RGBA));
|
---|
2081 | pch += strlen(H3DOR_FMT_RGBA);
|
---|
2082 | *pch++ = '\0';
|
---|
2083 | }
|
---|
2084 | else
|
---|
2085 | {
|
---|
2086 | rc = VERR_BUFFER_OVERFLOW;
|
---|
2087 | }
|
---|
2088 | *pcbOut = cbOut;
|
---|
2089 | }
|
---|
2090 | else
|
---|
2091 | {
|
---|
2092 | rc = VERR_NOT_SUPPORTED;
|
---|
2093 | }
|
---|
2094 |
|
---|
2095 | H3DORLOG(("H3DORContextProperty: %Rrc\n", rc));
|
---|
2096 | return rc;
|
---|
2097 | }
|
---|
2098 | #endif
|
---|
2099 |
|
---|
2100 | void ConsoleVRDPServer::remote3DRedirect(bool fEnable)
|
---|
2101 | {
|
---|
2102 | if (!m_fInterfaceImage)
|
---|
2103 | {
|
---|
2104 | /* No redirect without corresponding interface. */
|
---|
2105 | return;
|
---|
2106 | }
|
---|
2107 |
|
---|
2108 | /* Check if 3D redirection has been enabled. It is enabled by default. */
|
---|
2109 | com::Bstr bstr;
|
---|
2110 | HRESULT hrc = mConsole->i_getVRDEServer()->GetVRDEProperty(Bstr("H3DRedirect/Enabled").raw(), bstr.asOutParam());
|
---|
2111 |
|
---|
2112 | com::Utf8Str value = hrc == S_OK? bstr: "";
|
---|
2113 |
|
---|
2114 | bool fAllowed = RTStrICmp(value.c_str(), "true") == 0
|
---|
2115 | || RTStrICmp(value.c_str(), "1") == 0
|
---|
2116 | || value.c_str()[0] == 0;
|
---|
2117 |
|
---|
2118 | if (!fAllowed && fEnable)
|
---|
2119 | {
|
---|
2120 | return;
|
---|
2121 | }
|
---|
2122 |
|
---|
2123 | #if 0 /** @todo Implement again for VMSVGA. */
|
---|
2124 | /* Tell the host 3D service to redirect output using the ConsoleVRDPServer callbacks. */
|
---|
2125 | H3DOUTPUTREDIRECT outputRedirect =
|
---|
2126 | {
|
---|
2127 | this,
|
---|
2128 | H3DORBegin,
|
---|
2129 | H3DORGeometry,
|
---|
2130 | H3DORVisibleRegion,
|
---|
2131 | H3DORFrame,
|
---|
2132 | H3DOREnd,
|
---|
2133 | H3DORContextProperty
|
---|
2134 | };
|
---|
2135 |
|
---|
2136 | if (!fEnable)
|
---|
2137 | {
|
---|
2138 | /* This will tell the service to disable rediection. */
|
---|
2139 | RT_ZERO(outputRedirect);
|
---|
2140 | }
|
---|
2141 | #endif
|
---|
2142 |
|
---|
2143 | return;
|
---|
2144 | }
|
---|
2145 |
|
---|
2146 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDEImageCbNotify (void *pvContext,
|
---|
2147 | void *pvUser,
|
---|
2148 | HVRDEIMAGE hVideo,
|
---|
2149 | uint32_t u32Id,
|
---|
2150 | void *pvData,
|
---|
2151 | uint32_t cbData)
|
---|
2152 | {
|
---|
2153 | RT_NOREF(hVideo);
|
---|
2154 | Log(("H3DOR: VRDEImageCbNotify: pvContext %p, pvUser %p, hVideo %p, u32Id %u, pvData %p, cbData %d\n",
|
---|
2155 | pvContext, pvUser, hVideo, u32Id, pvData, cbData));
|
---|
2156 |
|
---|
2157 | ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvContext); NOREF(pServer);
|
---|
2158 |
|
---|
2159 | #if 0 /** @todo Implement again for VMSVGA. */
|
---|
2160 | H3DORInstance *p = (H3DORInstance *)pvUser;
|
---|
2161 | Assert(p);
|
---|
2162 | Assert(p->pThis);
|
---|
2163 | Assert(p->pThis == pServer);
|
---|
2164 |
|
---|
2165 | if (u32Id == VRDE_IMAGE_NOTIFY_HANDLE_CREATE)
|
---|
2166 | {
|
---|
2167 | if (cbData != sizeof(uint32_t))
|
---|
2168 | {
|
---|
2169 | AssertFailed();
|
---|
2170 | return VERR_INVALID_PARAMETER;
|
---|
2171 | }
|
---|
2172 |
|
---|
2173 | uint32_t u32StreamId = *(uint32_t *)pvData;
|
---|
2174 | Log(("H3DOR: VRDE_IMAGE_NOTIFY_HANDLE_CREATE u32StreamId %d\n",
|
---|
2175 | u32StreamId));
|
---|
2176 |
|
---|
2177 | if (u32StreamId != 0)
|
---|
2178 | {
|
---|
2179 | p->fCreated = true; /// @todo not needed?
|
---|
2180 | }
|
---|
2181 | else
|
---|
2182 | {
|
---|
2183 | /* The stream has not been created. */
|
---|
2184 | }
|
---|
2185 | }
|
---|
2186 | #else
|
---|
2187 | RT_NOREF(pvUser, u32Id, pvData, cbData);
|
---|
2188 | #endif
|
---|
2189 |
|
---|
2190 | return VINF_SUCCESS;
|
---|
2191 | }
|
---|
2192 |
|
---|
2193 | #undef H3DORLOG
|
---|
2194 |
|
---|
2195 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDESCardCbNotify(void *pvContext,
|
---|
2196 | uint32_t u32Id,
|
---|
2197 | void *pvData,
|
---|
2198 | uint32_t cbData)
|
---|
2199 | {
|
---|
2200 | #ifdef VBOX_WITH_USB_CARDREADER
|
---|
2201 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2202 | UsbCardReader *pReader = pThis->mConsole->i_getUsbCardReader();
|
---|
2203 | return pReader->VRDENotify(u32Id, pvData, cbData);
|
---|
2204 | #else
|
---|
2205 | NOREF(pvContext);
|
---|
2206 | NOREF(u32Id);
|
---|
2207 | NOREF(pvData);
|
---|
2208 | NOREF(cbData);
|
---|
2209 | return VERR_NOT_SUPPORTED;
|
---|
2210 | #endif
|
---|
2211 | }
|
---|
2212 |
|
---|
2213 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDESCardCbResponse(void *pvContext,
|
---|
2214 | int rcRequest,
|
---|
2215 | void *pvUser,
|
---|
2216 | uint32_t u32Function,
|
---|
2217 | void *pvData,
|
---|
2218 | uint32_t cbData)
|
---|
2219 | {
|
---|
2220 | #ifdef VBOX_WITH_USB_CARDREADER
|
---|
2221 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2222 | UsbCardReader *pReader = pThis->mConsole->i_getUsbCardReader();
|
---|
2223 | return pReader->VRDEResponse(rcRequest, pvUser, u32Function, pvData, cbData);
|
---|
2224 | #else
|
---|
2225 | NOREF(pvContext);
|
---|
2226 | NOREF(rcRequest);
|
---|
2227 | NOREF(pvUser);
|
---|
2228 | NOREF(u32Function);
|
---|
2229 | NOREF(pvData);
|
---|
2230 | NOREF(cbData);
|
---|
2231 | return VERR_NOT_SUPPORTED;
|
---|
2232 | #endif
|
---|
2233 | }
|
---|
2234 |
|
---|
2235 | int ConsoleVRDPServer::SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData)
|
---|
2236 | {
|
---|
2237 | int rc = VINF_SUCCESS;
|
---|
2238 |
|
---|
2239 | if (mhServer && mpEntryPoints && m_interfaceSCard.VRDESCardRequest)
|
---|
2240 | {
|
---|
2241 | rc = m_interfaceSCard.VRDESCardRequest(mhServer, pvUser, u32Function, pvData, cbData);
|
---|
2242 | }
|
---|
2243 | else
|
---|
2244 | {
|
---|
2245 | rc = VERR_NOT_SUPPORTED;
|
---|
2246 | }
|
---|
2247 |
|
---|
2248 | return rc;
|
---|
2249 | }
|
---|
2250 |
|
---|
2251 |
|
---|
2252 | struct TSMFHOSTCHCTX;
|
---|
2253 | struct TSMFVRDPCTX;
|
---|
2254 |
|
---|
2255 | typedef struct TSMFHOSTCHCTX
|
---|
2256 | {
|
---|
2257 | ConsoleVRDPServer *pThis;
|
---|
2258 |
|
---|
2259 | struct TSMFVRDPCTX *pVRDPCtx; /* NULL if no corresponding host channel context. */
|
---|
2260 |
|
---|
2261 | void *pvDataReceived;
|
---|
2262 | uint32_t cbDataReceived;
|
---|
2263 | uint32_t cbDataAllocated;
|
---|
2264 | } TSMFHOSTCHCTX;
|
---|
2265 |
|
---|
2266 | typedef struct TSMFVRDPCTX
|
---|
2267 | {
|
---|
2268 | ConsoleVRDPServer *pThis;
|
---|
2269 |
|
---|
2270 | VBOXHOSTCHANNELCALLBACKS *pCallbacks;
|
---|
2271 | void *pvCallbacks;
|
---|
2272 |
|
---|
2273 | TSMFHOSTCHCTX *pHostChCtx; /* NULL if no corresponding host channel context. */
|
---|
2274 |
|
---|
2275 | uint32_t u32ChannelHandle;
|
---|
2276 | } TSMFVRDPCTX;
|
---|
2277 |
|
---|
2278 | static int tsmfContextsAlloc(TSMFHOSTCHCTX **ppHostChCtx, TSMFVRDPCTX **ppVRDPCtx)
|
---|
2279 | {
|
---|
2280 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)RTMemAllocZ(sizeof(TSMFHOSTCHCTX));
|
---|
2281 | if (!pHostChCtx)
|
---|
2282 | {
|
---|
2283 | return VERR_NO_MEMORY;
|
---|
2284 | }
|
---|
2285 |
|
---|
2286 | TSMFVRDPCTX *pVRDPCtx = (TSMFVRDPCTX *)RTMemAllocZ(sizeof(TSMFVRDPCTX));
|
---|
2287 | if (!pVRDPCtx)
|
---|
2288 | {
|
---|
2289 | RTMemFree(pHostChCtx);
|
---|
2290 | return VERR_NO_MEMORY;
|
---|
2291 | }
|
---|
2292 |
|
---|
2293 | *ppHostChCtx = pHostChCtx;
|
---|
2294 | *ppVRDPCtx = pVRDPCtx;
|
---|
2295 | return VINF_SUCCESS;
|
---|
2296 | }
|
---|
2297 |
|
---|
2298 | int ConsoleVRDPServer::tsmfLock(void)
|
---|
2299 | {
|
---|
2300 | int rc = RTCritSectEnter(&mTSMFLock);
|
---|
2301 | AssertRC(rc);
|
---|
2302 | return rc;
|
---|
2303 | }
|
---|
2304 |
|
---|
2305 | void ConsoleVRDPServer::tsmfUnlock(void)
|
---|
2306 | {
|
---|
2307 | RTCritSectLeave(&mTSMFLock);
|
---|
2308 | }
|
---|
2309 |
|
---|
2310 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelAttach(void *pvProvider,
|
---|
2311 | void **ppvChannel,
|
---|
2312 | uint32_t u32Flags,
|
---|
2313 | VBOXHOSTCHANNELCALLBACKS *pCallbacks,
|
---|
2314 | void *pvCallbacks)
|
---|
2315 | {
|
---|
2316 | LogFlowFunc(("\n"));
|
---|
2317 |
|
---|
2318 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvProvider);
|
---|
2319 |
|
---|
2320 | /* Create 2 context structures: for the VRDP server and for the host service. */
|
---|
2321 | TSMFHOSTCHCTX *pHostChCtx = NULL;
|
---|
2322 | TSMFVRDPCTX *pVRDPCtx = NULL;
|
---|
2323 |
|
---|
2324 | int rc = tsmfContextsAlloc(&pHostChCtx, &pVRDPCtx);
|
---|
2325 | if (RT_FAILURE(rc))
|
---|
2326 | {
|
---|
2327 | return rc;
|
---|
2328 | }
|
---|
2329 |
|
---|
2330 | pHostChCtx->pThis = pThis;
|
---|
2331 | pHostChCtx->pVRDPCtx = pVRDPCtx;
|
---|
2332 |
|
---|
2333 | pVRDPCtx->pThis = pThis;
|
---|
2334 | pVRDPCtx->pCallbacks = pCallbacks;
|
---|
2335 | pVRDPCtx->pvCallbacks = pvCallbacks;
|
---|
2336 | pVRDPCtx->pHostChCtx = pHostChCtx;
|
---|
2337 |
|
---|
2338 | rc = pThis->m_interfaceTSMF.VRDETSMFChannelCreate(pThis->mhServer, pVRDPCtx, u32Flags);
|
---|
2339 |
|
---|
2340 | if (RT_SUCCESS(rc))
|
---|
2341 | {
|
---|
2342 | /** @todo contexts should be in a list for accounting. */
|
---|
2343 | *ppvChannel = pHostChCtx;
|
---|
2344 | }
|
---|
2345 | else
|
---|
2346 | {
|
---|
2347 | RTMemFree(pHostChCtx);
|
---|
2348 | RTMemFree(pVRDPCtx);
|
---|
2349 | }
|
---|
2350 |
|
---|
2351 | return rc;
|
---|
2352 | }
|
---|
2353 |
|
---|
2354 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::tsmfHostChannelDetach(void *pvChannel)
|
---|
2355 | {
|
---|
2356 | LogFlowFunc(("\n"));
|
---|
2357 |
|
---|
2358 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2359 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2360 |
|
---|
2361 | int rc = pThis->tsmfLock();
|
---|
2362 | if (RT_SUCCESS(rc))
|
---|
2363 | {
|
---|
2364 | bool fClose = false;
|
---|
2365 | uint32_t u32ChannelHandle = 0;
|
---|
2366 |
|
---|
2367 | if (pHostChCtx->pVRDPCtx)
|
---|
2368 | {
|
---|
2369 | /* There is still a VRDP context for this channel. */
|
---|
2370 | pHostChCtx->pVRDPCtx->pHostChCtx = NULL;
|
---|
2371 | u32ChannelHandle = pHostChCtx->pVRDPCtx->u32ChannelHandle;
|
---|
2372 | fClose = true;
|
---|
2373 | }
|
---|
2374 |
|
---|
2375 | pThis->tsmfUnlock();
|
---|
2376 |
|
---|
2377 | RTMemFree(pHostChCtx);
|
---|
2378 |
|
---|
2379 | if (fClose)
|
---|
2380 | {
|
---|
2381 | LogFlowFunc(("Closing VRDE channel %d.\n", u32ChannelHandle));
|
---|
2382 | pThis->m_interfaceTSMF.VRDETSMFChannelClose(pThis->mhServer, u32ChannelHandle);
|
---|
2383 | }
|
---|
2384 | else
|
---|
2385 | {
|
---|
2386 | LogFlowFunc(("No VRDE channel.\n"));
|
---|
2387 | }
|
---|
2388 | }
|
---|
2389 | }
|
---|
2390 |
|
---|
2391 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelSend(void *pvChannel,
|
---|
2392 | const void *pvData,
|
---|
2393 | uint32_t cbData)
|
---|
2394 | {
|
---|
2395 | LogFlowFunc(("cbData %d\n", cbData));
|
---|
2396 |
|
---|
2397 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2398 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2399 |
|
---|
2400 | int rc = pThis->tsmfLock();
|
---|
2401 | if (RT_SUCCESS(rc))
|
---|
2402 | {
|
---|
2403 | bool fSend = false;
|
---|
2404 | uint32_t u32ChannelHandle = 0;
|
---|
2405 |
|
---|
2406 | if (pHostChCtx->pVRDPCtx)
|
---|
2407 | {
|
---|
2408 | u32ChannelHandle = pHostChCtx->pVRDPCtx->u32ChannelHandle;
|
---|
2409 | fSend = true;
|
---|
2410 | }
|
---|
2411 |
|
---|
2412 | pThis->tsmfUnlock();
|
---|
2413 |
|
---|
2414 | if (fSend)
|
---|
2415 | {
|
---|
2416 | LogFlowFunc(("Send to VRDE channel %d.\n", u32ChannelHandle));
|
---|
2417 | rc = pThis->m_interfaceTSMF.VRDETSMFChannelSend(pThis->mhServer, u32ChannelHandle,
|
---|
2418 | pvData, cbData);
|
---|
2419 | }
|
---|
2420 | }
|
---|
2421 |
|
---|
2422 | return rc;
|
---|
2423 | }
|
---|
2424 |
|
---|
2425 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelRecv(void *pvChannel,
|
---|
2426 | void *pvData,
|
---|
2427 | uint32_t cbData,
|
---|
2428 | uint32_t *pcbReceived,
|
---|
2429 | uint32_t *pcbRemaining)
|
---|
2430 | {
|
---|
2431 | LogFlowFunc(("cbData %d\n", cbData));
|
---|
2432 |
|
---|
2433 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2434 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2435 |
|
---|
2436 | int rc = pThis->tsmfLock();
|
---|
2437 | if (RT_SUCCESS(rc))
|
---|
2438 | {
|
---|
2439 | uint32_t cbToCopy = RT_MIN(cbData, pHostChCtx->cbDataReceived);
|
---|
2440 | uint32_t cbRemaining = pHostChCtx->cbDataReceived - cbToCopy;
|
---|
2441 |
|
---|
2442 | LogFlowFunc(("cbToCopy %d, cbRemaining %d\n", cbToCopy, cbRemaining));
|
---|
2443 |
|
---|
2444 | if (cbToCopy != 0)
|
---|
2445 | {
|
---|
2446 | memcpy(pvData, pHostChCtx->pvDataReceived, cbToCopy);
|
---|
2447 |
|
---|
2448 | if (cbRemaining != 0)
|
---|
2449 | {
|
---|
2450 | memmove(pHostChCtx->pvDataReceived, (uint8_t *)pHostChCtx->pvDataReceived + cbToCopy, cbRemaining);
|
---|
2451 | }
|
---|
2452 |
|
---|
2453 | pHostChCtx->cbDataReceived = cbRemaining;
|
---|
2454 | }
|
---|
2455 |
|
---|
2456 | pThis->tsmfUnlock();
|
---|
2457 |
|
---|
2458 | *pcbRemaining = cbRemaining;
|
---|
2459 | *pcbReceived = cbToCopy;
|
---|
2460 | }
|
---|
2461 |
|
---|
2462 | return rc;
|
---|
2463 | }
|
---|
2464 |
|
---|
2465 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelControl(void *pvChannel,
|
---|
2466 | uint32_t u32Code,
|
---|
2467 | const void *pvParm,
|
---|
2468 | uint32_t cbParm,
|
---|
2469 | const void *pvData,
|
---|
2470 | uint32_t cbData,
|
---|
2471 | uint32_t *pcbDataReturned)
|
---|
2472 | {
|
---|
2473 | RT_NOREF(pvParm, cbParm, pvData, cbData);
|
---|
2474 | LogFlowFunc(("u32Code %u\n", u32Code));
|
---|
2475 |
|
---|
2476 | if (!pvChannel)
|
---|
2477 | {
|
---|
2478 | /* Special case, the provider must answer rather than a channel instance. */
|
---|
2479 | if (u32Code == VBOX_HOST_CHANNEL_CTRL_EXISTS)
|
---|
2480 | {
|
---|
2481 | *pcbDataReturned = 0;
|
---|
2482 | return VINF_SUCCESS;
|
---|
2483 | }
|
---|
2484 |
|
---|
2485 | return VERR_NOT_IMPLEMENTED;
|
---|
2486 | }
|
---|
2487 |
|
---|
2488 | /* Channels do not support this. */
|
---|
2489 | return VERR_NOT_IMPLEMENTED;
|
---|
2490 | }
|
---|
2491 |
|
---|
2492 |
|
---|
2493 | void ConsoleVRDPServer::setupTSMF(void)
|
---|
2494 | {
|
---|
2495 | if (m_interfaceTSMF.header.u64Size == 0)
|
---|
2496 | {
|
---|
2497 | return;
|
---|
2498 | }
|
---|
2499 |
|
---|
2500 | /* Register with the host channel service. */
|
---|
2501 | VBOXHOSTCHANNELINTERFACE hostChannelInterface =
|
---|
2502 | {
|
---|
2503 | this,
|
---|
2504 | tsmfHostChannelAttach,
|
---|
2505 | tsmfHostChannelDetach,
|
---|
2506 | tsmfHostChannelSend,
|
---|
2507 | tsmfHostChannelRecv,
|
---|
2508 | tsmfHostChannelControl
|
---|
2509 | };
|
---|
2510 |
|
---|
2511 | VBoxHostChannelHostRegister parms;
|
---|
2512 |
|
---|
2513 | static char szProviderName[] = "/vrde/tsmf";
|
---|
2514 |
|
---|
2515 | parms.name.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2516 | parms.name.u.pointer.addr = &szProviderName[0];
|
---|
2517 | parms.name.u.pointer.size = sizeof(szProviderName);
|
---|
2518 |
|
---|
2519 | parms.iface.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2520 | parms.iface.u.pointer.addr = &hostChannelInterface;
|
---|
2521 | parms.iface.u.pointer.size = sizeof(hostChannelInterface);
|
---|
2522 |
|
---|
2523 | VMMDev *pVMMDev = mConsole->i_getVMMDev();
|
---|
2524 |
|
---|
2525 | if (!pVMMDev)
|
---|
2526 | {
|
---|
2527 | AssertMsgFailed(("setupTSMF no vmmdev\n"));
|
---|
2528 | return;
|
---|
2529 | }
|
---|
2530 |
|
---|
2531 | int rc = pVMMDev->hgcmHostCall("VBoxHostChannel",
|
---|
2532 | VBOX_HOST_CHANNEL_HOST_FN_REGISTER,
|
---|
2533 | 2,
|
---|
2534 | &parms.name);
|
---|
2535 |
|
---|
2536 | if (!RT_SUCCESS(rc))
|
---|
2537 | {
|
---|
2538 | Log(("VBOX_HOST_CHANNEL_HOST_FN_REGISTER failed with %Rrc\n", rc));
|
---|
2539 | return;
|
---|
2540 | }
|
---|
2541 |
|
---|
2542 | LogRel(("VRDE: Enabled TSMF channel.\n"));
|
---|
2543 |
|
---|
2544 | return;
|
---|
2545 | }
|
---|
2546 |
|
---|
2547 | /** @todo these defines must be in a header, which is used by guest component as well. */
|
---|
2548 | #define VBOX_TSMF_HCH_CREATE_ACCEPTED (VBOX_HOST_CHANNEL_EVENT_USER + 0)
|
---|
2549 | #define VBOX_TSMF_HCH_CREATE_DECLINED (VBOX_HOST_CHANNEL_EVENT_USER + 1)
|
---|
2550 | #define VBOX_TSMF_HCH_DISCONNECTED (VBOX_HOST_CHANNEL_EVENT_USER + 2)
|
---|
2551 |
|
---|
2552 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDETSMFCbNotify(void *pvContext,
|
---|
2553 | uint32_t u32Notification,
|
---|
2554 | void *pvChannel,
|
---|
2555 | const void *pvParm,
|
---|
2556 | uint32_t cbParm)
|
---|
2557 | {
|
---|
2558 | RT_NOREF(cbParm);
|
---|
2559 | int rc = VINF_SUCCESS;
|
---|
2560 |
|
---|
2561 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2562 |
|
---|
2563 | TSMFVRDPCTX *pVRDPCtx = (TSMFVRDPCTX *)pvChannel;
|
---|
2564 |
|
---|
2565 | Assert(pVRDPCtx->pThis == pThis);
|
---|
2566 |
|
---|
2567 | if (pVRDPCtx->pCallbacks == NULL)
|
---|
2568 | {
|
---|
2569 | LogFlowFunc(("tsmfHostChannel: Channel disconnected. Skipping.\n"));
|
---|
2570 | return;
|
---|
2571 | }
|
---|
2572 |
|
---|
2573 | switch (u32Notification)
|
---|
2574 | {
|
---|
2575 | case VRDE_TSMF_N_CREATE_ACCEPTED:
|
---|
2576 | {
|
---|
2577 | VRDETSMFNOTIFYCREATEACCEPTED *p = (VRDETSMFNOTIFYCREATEACCEPTED *)pvParm;
|
---|
2578 | Assert(cbParm == sizeof(VRDETSMFNOTIFYCREATEACCEPTED));
|
---|
2579 |
|
---|
2580 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_CREATE_ACCEPTED(%p): p->u32ChannelHandle %d\n",
|
---|
2581 | pVRDPCtx, p->u32ChannelHandle));
|
---|
2582 |
|
---|
2583 | pVRDPCtx->u32ChannelHandle = p->u32ChannelHandle;
|
---|
2584 |
|
---|
2585 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2586 | VBOX_TSMF_HCH_CREATE_ACCEPTED,
|
---|
2587 | NULL, 0);
|
---|
2588 | } break;
|
---|
2589 |
|
---|
2590 | case VRDE_TSMF_N_CREATE_DECLINED:
|
---|
2591 | {
|
---|
2592 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_CREATE_DECLINED(%p)\n", pVRDPCtx));
|
---|
2593 |
|
---|
2594 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2595 | VBOX_TSMF_HCH_CREATE_DECLINED,
|
---|
2596 | NULL, 0);
|
---|
2597 | } break;
|
---|
2598 |
|
---|
2599 | case VRDE_TSMF_N_DATA:
|
---|
2600 | {
|
---|
2601 | /* Save the data in the intermediate buffer and send the event. */
|
---|
2602 | VRDETSMFNOTIFYDATA *p = (VRDETSMFNOTIFYDATA *)pvParm;
|
---|
2603 | Assert(cbParm == sizeof(VRDETSMFNOTIFYDATA));
|
---|
2604 |
|
---|
2605 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DATA(%p): p->cbData %d\n", pVRDPCtx, p->cbData));
|
---|
2606 |
|
---|
2607 | VBOXHOSTCHANNELEVENTRECV ev;
|
---|
2608 | ev.u32SizeAvailable = 0;
|
---|
2609 |
|
---|
2610 | rc = pThis->tsmfLock();
|
---|
2611 |
|
---|
2612 | if (RT_SUCCESS(rc))
|
---|
2613 | {
|
---|
2614 | TSMFHOSTCHCTX *pHostChCtx = pVRDPCtx->pHostChCtx;
|
---|
2615 |
|
---|
2616 | if (pHostChCtx)
|
---|
2617 | {
|
---|
2618 | if (pHostChCtx->pvDataReceived)
|
---|
2619 | {
|
---|
2620 | uint32_t cbAlloc = p->cbData + pHostChCtx->cbDataReceived;
|
---|
2621 | pHostChCtx->pvDataReceived = RTMemRealloc(pHostChCtx->pvDataReceived, cbAlloc);
|
---|
2622 | memcpy((uint8_t *)pHostChCtx->pvDataReceived + pHostChCtx->cbDataReceived, p->pvData, p->cbData);
|
---|
2623 |
|
---|
2624 | pHostChCtx->cbDataReceived += p->cbData;
|
---|
2625 | pHostChCtx->cbDataAllocated = cbAlloc;
|
---|
2626 | }
|
---|
2627 | else
|
---|
2628 | {
|
---|
2629 | pHostChCtx->pvDataReceived = RTMemAlloc(p->cbData);
|
---|
2630 | memcpy(pHostChCtx->pvDataReceived, p->pvData, p->cbData);
|
---|
2631 |
|
---|
2632 | pHostChCtx->cbDataReceived = p->cbData;
|
---|
2633 | pHostChCtx->cbDataAllocated = p->cbData;
|
---|
2634 | }
|
---|
2635 |
|
---|
2636 | ev.u32SizeAvailable = p->cbData;
|
---|
2637 | }
|
---|
2638 | else
|
---|
2639 | {
|
---|
2640 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DATA: no host channel. Skipping\n"));
|
---|
2641 | }
|
---|
2642 |
|
---|
2643 | pThis->tsmfUnlock();
|
---|
2644 | }
|
---|
2645 |
|
---|
2646 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2647 | VBOX_HOST_CHANNEL_EVENT_RECV,
|
---|
2648 | &ev, sizeof(ev));
|
---|
2649 | } break;
|
---|
2650 |
|
---|
2651 | case VRDE_TSMF_N_DISCONNECTED:
|
---|
2652 | {
|
---|
2653 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DISCONNECTED(%p)\n", pVRDPCtx));
|
---|
2654 |
|
---|
2655 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2656 | VBOX_TSMF_HCH_DISCONNECTED,
|
---|
2657 | NULL, 0);
|
---|
2658 |
|
---|
2659 | /* The callback context will not be used anymore. */
|
---|
2660 | pVRDPCtx->pCallbacks->HostChannelCallbackDeleted(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx);
|
---|
2661 | pVRDPCtx->pCallbacks = NULL;
|
---|
2662 | pVRDPCtx->pvCallbacks = NULL;
|
---|
2663 |
|
---|
2664 | rc = pThis->tsmfLock();
|
---|
2665 | if (RT_SUCCESS(rc))
|
---|
2666 | {
|
---|
2667 | if (pVRDPCtx->pHostChCtx)
|
---|
2668 | {
|
---|
2669 | /* There is still a host channel context for this channel. */
|
---|
2670 | pVRDPCtx->pHostChCtx->pVRDPCtx = NULL;
|
---|
2671 | }
|
---|
2672 |
|
---|
2673 | pThis->tsmfUnlock();
|
---|
2674 |
|
---|
2675 | RT_ZERO(*pVRDPCtx);
|
---|
2676 | RTMemFree(pVRDPCtx);
|
---|
2677 | }
|
---|
2678 | } break;
|
---|
2679 |
|
---|
2680 | default:
|
---|
2681 | {
|
---|
2682 | AssertFailed();
|
---|
2683 | } break;
|
---|
2684 | }
|
---|
2685 | }
|
---|
2686 |
|
---|
2687 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInNotify(void *pvCallback,
|
---|
2688 | uint32_t u32Id,
|
---|
2689 | const void *pvData,
|
---|
2690 | uint32_t cbData)
|
---|
2691 | {
|
---|
2692 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2693 | if (pThis->mEmWebcam)
|
---|
2694 | {
|
---|
2695 | pThis->mEmWebcam->EmWebcamCbNotify(u32Id, pvData, cbData);
|
---|
2696 | }
|
---|
2697 | }
|
---|
2698 |
|
---|
2699 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInDeviceDesc(void *pvCallback,
|
---|
2700 | int rcRequest,
|
---|
2701 | void *pDeviceCtx,
|
---|
2702 | void *pvUser,
|
---|
2703 | const VRDEVIDEOINDEVICEDESC *pDeviceDesc,
|
---|
2704 | uint32_t cbDevice)
|
---|
2705 | {
|
---|
2706 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2707 | if (pThis->mEmWebcam)
|
---|
2708 | {
|
---|
2709 | pThis->mEmWebcam->EmWebcamCbDeviceDesc(rcRequest, pDeviceCtx, pvUser, pDeviceDesc, cbDevice);
|
---|
2710 | }
|
---|
2711 | }
|
---|
2712 |
|
---|
2713 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInControl(void *pvCallback,
|
---|
2714 | int rcRequest,
|
---|
2715 | void *pDeviceCtx,
|
---|
2716 | void *pvUser,
|
---|
2717 | const VRDEVIDEOINCTRLHDR *pControl,
|
---|
2718 | uint32_t cbControl)
|
---|
2719 | {
|
---|
2720 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2721 | if (pThis->mEmWebcam)
|
---|
2722 | {
|
---|
2723 | pThis->mEmWebcam->EmWebcamCbControl(rcRequest, pDeviceCtx, pvUser, pControl, cbControl);
|
---|
2724 | }
|
---|
2725 | }
|
---|
2726 |
|
---|
2727 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInFrame(void *pvCallback,
|
---|
2728 | int rcRequest,
|
---|
2729 | void *pDeviceCtx,
|
---|
2730 | const VRDEVIDEOINPAYLOADHDR *pFrame,
|
---|
2731 | uint32_t cbFrame)
|
---|
2732 | {
|
---|
2733 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2734 | if (pThis->mEmWebcam)
|
---|
2735 | {
|
---|
2736 | pThis->mEmWebcam->EmWebcamCbFrame(rcRequest, pDeviceCtx, pFrame, cbFrame);
|
---|
2737 | }
|
---|
2738 | }
|
---|
2739 |
|
---|
2740 | int ConsoleVRDPServer::VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx)
|
---|
2741 | {
|
---|
2742 | int rc;
|
---|
2743 |
|
---|
2744 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInDeviceAttach)
|
---|
2745 | {
|
---|
2746 | rc = m_interfaceVideoIn.VRDEVideoInDeviceAttach(mhServer, pDeviceHandle, pvDeviceCtx);
|
---|
2747 | }
|
---|
2748 | else
|
---|
2749 | {
|
---|
2750 | rc = VERR_NOT_SUPPORTED;
|
---|
2751 | }
|
---|
2752 |
|
---|
2753 | return rc;
|
---|
2754 | }
|
---|
2755 |
|
---|
2756 | int ConsoleVRDPServer::VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle)
|
---|
2757 | {
|
---|
2758 | int rc;
|
---|
2759 |
|
---|
2760 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInDeviceDetach)
|
---|
2761 | {
|
---|
2762 | rc = m_interfaceVideoIn.VRDEVideoInDeviceDetach(mhServer, pDeviceHandle);
|
---|
2763 | }
|
---|
2764 | else
|
---|
2765 | {
|
---|
2766 | rc = VERR_NOT_SUPPORTED;
|
---|
2767 | }
|
---|
2768 |
|
---|
2769 | return rc;
|
---|
2770 | }
|
---|
2771 |
|
---|
2772 | int ConsoleVRDPServer::VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle)
|
---|
2773 | {
|
---|
2774 | int rc;
|
---|
2775 |
|
---|
2776 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInGetDeviceDesc)
|
---|
2777 | {
|
---|
2778 | rc = m_interfaceVideoIn.VRDEVideoInGetDeviceDesc(mhServer, pvUser, pDeviceHandle);
|
---|
2779 | }
|
---|
2780 | else
|
---|
2781 | {
|
---|
2782 | rc = VERR_NOT_SUPPORTED;
|
---|
2783 | }
|
---|
2784 |
|
---|
2785 | return rc;
|
---|
2786 | }
|
---|
2787 |
|
---|
2788 | int ConsoleVRDPServer::VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
|
---|
2789 | const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq)
|
---|
2790 | {
|
---|
2791 | int rc;
|
---|
2792 |
|
---|
2793 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInControl)
|
---|
2794 | {
|
---|
2795 | rc = m_interfaceVideoIn.VRDEVideoInControl(mhServer, pvUser, pDeviceHandle, pReq, cbReq);
|
---|
2796 | }
|
---|
2797 | else
|
---|
2798 | {
|
---|
2799 | rc = VERR_NOT_SUPPORTED;
|
---|
2800 | }
|
---|
2801 |
|
---|
2802 | return rc;
|
---|
2803 | }
|
---|
2804 |
|
---|
2805 |
|
---|
2806 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackInputSetup(void *pvCallback,
|
---|
2807 | int rcRequest,
|
---|
2808 | uint32_t u32Method,
|
---|
2809 | const void *pvResult,
|
---|
2810 | uint32_t cbResult)
|
---|
2811 | {
|
---|
2812 | NOREF(pvCallback);
|
---|
2813 | NOREF(rcRequest);
|
---|
2814 | NOREF(u32Method);
|
---|
2815 | NOREF(pvResult);
|
---|
2816 | NOREF(cbResult);
|
---|
2817 | }
|
---|
2818 |
|
---|
2819 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackInputEvent(void *pvCallback,
|
---|
2820 | uint32_t u32Method,
|
---|
2821 | const void *pvEvent,
|
---|
2822 | uint32_t cbEvent)
|
---|
2823 | {
|
---|
2824 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2825 |
|
---|
2826 | if (u32Method == VRDE_INPUT_METHOD_TOUCH)
|
---|
2827 | {
|
---|
2828 | if (cbEvent >= sizeof(VRDEINPUTHEADER))
|
---|
2829 | {
|
---|
2830 | VRDEINPUTHEADER *pHeader = (VRDEINPUTHEADER *)pvEvent;
|
---|
2831 |
|
---|
2832 | if (pHeader->u16EventId == VRDEINPUT_EVENTID_TOUCH)
|
---|
2833 | {
|
---|
2834 | IMouse *pMouse = pThis->mConsole->i_getMouse();
|
---|
2835 |
|
---|
2836 | VRDEINPUT_TOUCH_EVENT_PDU *p = (VRDEINPUT_TOUCH_EVENT_PDU *)pHeader;
|
---|
2837 |
|
---|
2838 | uint16_t iFrame;
|
---|
2839 | for (iFrame = 0; iFrame < p->u16FrameCount; iFrame++)
|
---|
2840 | {
|
---|
2841 | VRDEINPUT_TOUCH_FRAME *pFrame = &p->aFrames[iFrame];
|
---|
2842 |
|
---|
2843 | com::SafeArray<LONG64> aContacts(pFrame->u16ContactCount);
|
---|
2844 |
|
---|
2845 | uint16_t iContact;
|
---|
2846 | for (iContact = 0; iContact < pFrame->u16ContactCount; iContact++)
|
---|
2847 | {
|
---|
2848 | VRDEINPUT_CONTACT_DATA *pContact = &pFrame->aContacts[iContact];
|
---|
2849 |
|
---|
2850 | int16_t x = (int16_t)(pContact->i32X + 1);
|
---|
2851 | int16_t y = (int16_t)(pContact->i32Y + 1);
|
---|
2852 | uint8_t contactId = pContact->u8ContactId;
|
---|
2853 | uint8_t contactState = TouchContactState_None;
|
---|
2854 |
|
---|
2855 | if (pContact->u32ContactFlags & VRDEINPUT_CONTACT_FLAG_INRANGE)
|
---|
2856 | {
|
---|
2857 | contactState |= TouchContactState_InRange;
|
---|
2858 | }
|
---|
2859 | if (pContact->u32ContactFlags & VRDEINPUT_CONTACT_FLAG_INCONTACT)
|
---|
2860 | {
|
---|
2861 | contactState |= TouchContactState_InContact;
|
---|
2862 | }
|
---|
2863 |
|
---|
2864 | aContacts[iContact] = RT_MAKE_U64_FROM_U16((uint16_t)x,
|
---|
2865 | (uint16_t)y,
|
---|
2866 | RT_MAKE_U16(contactId, contactState),
|
---|
2867 | 0);
|
---|
2868 | }
|
---|
2869 |
|
---|
2870 | if (pFrame->u64FrameOffset == 0)
|
---|
2871 | {
|
---|
2872 | pThis->mu64TouchInputTimestampMCS = 0;
|
---|
2873 | }
|
---|
2874 | else
|
---|
2875 | {
|
---|
2876 | pThis->mu64TouchInputTimestampMCS += pFrame->u64FrameOffset;
|
---|
2877 | }
|
---|
2878 |
|
---|
2879 | pMouse->PutEventMultiTouch(pFrame->u16ContactCount,
|
---|
2880 | ComSafeArrayAsInParam(aContacts),
|
---|
2881 | (ULONG)(pThis->mu64TouchInputTimestampMCS / 1000)); /* Micro->milliseconds. */
|
---|
2882 | }
|
---|
2883 | }
|
---|
2884 | else if (pHeader->u16EventId == VRDEINPUT_EVENTID_DISMISS_HOVERING_CONTACT)
|
---|
2885 | {
|
---|
2886 | /** @todo */
|
---|
2887 | }
|
---|
2888 | else
|
---|
2889 | {
|
---|
2890 | AssertMsgFailed(("EventId %d\n", pHeader->u16EventId));
|
---|
2891 | }
|
---|
2892 | }
|
---|
2893 | }
|
---|
2894 | }
|
---|
2895 |
|
---|
2896 |
|
---|
2897 | void ConsoleVRDPServer::EnableConnections(void)
|
---|
2898 | {
|
---|
2899 | if (mpEntryPoints && mhServer)
|
---|
2900 | {
|
---|
2901 | mpEntryPoints->VRDEEnableConnections(mhServer, true);
|
---|
2902 |
|
---|
2903 | /* Setup the generic TSMF channel. */
|
---|
2904 | setupTSMF();
|
---|
2905 | }
|
---|
2906 | }
|
---|
2907 |
|
---|
2908 | void ConsoleVRDPServer::DisconnectClient(uint32_t u32ClientId, bool fReconnect)
|
---|
2909 | {
|
---|
2910 | if (mpEntryPoints && mhServer)
|
---|
2911 | {
|
---|
2912 | mpEntryPoints->VRDEDisconnect(mhServer, u32ClientId, fReconnect);
|
---|
2913 | }
|
---|
2914 | }
|
---|
2915 |
|
---|
2916 | int ConsoleVRDPServer::MousePointer(BOOL alpha,
|
---|
2917 | ULONG xHot,
|
---|
2918 | ULONG yHot,
|
---|
2919 | ULONG width,
|
---|
2920 | ULONG height,
|
---|
2921 | const uint8_t *pu8Shape)
|
---|
2922 | {
|
---|
2923 | int rc = VINF_SUCCESS;
|
---|
2924 |
|
---|
2925 | if (mhServer && mpEntryPoints && m_interfaceMousePtr.VRDEMousePtr)
|
---|
2926 | {
|
---|
2927 | size_t cbMask = (((width + 7) / 8) * height + 3) & ~3;
|
---|
2928 | size_t cbData = width * height * 4;
|
---|
2929 |
|
---|
2930 | size_t cbDstMask = alpha? 0: cbMask;
|
---|
2931 |
|
---|
2932 | size_t cbPointer = sizeof(VRDEMOUSEPTRDATA) + cbDstMask + cbData;
|
---|
2933 | uint8_t *pu8Pointer = (uint8_t *)RTMemAlloc(cbPointer);
|
---|
2934 | if (pu8Pointer != NULL)
|
---|
2935 | {
|
---|
2936 | VRDEMOUSEPTRDATA *pPointer = (VRDEMOUSEPTRDATA *)pu8Pointer;
|
---|
2937 |
|
---|
2938 | pPointer->u16HotX = (uint16_t)xHot;
|
---|
2939 | pPointer->u16HotY = (uint16_t)yHot;
|
---|
2940 | pPointer->u16Width = (uint16_t)width;
|
---|
2941 | pPointer->u16Height = (uint16_t)height;
|
---|
2942 | pPointer->u16MaskLen = (uint16_t)cbDstMask;
|
---|
2943 | pPointer->u32DataLen = (uint32_t)cbData;
|
---|
2944 |
|
---|
2945 | /* AND mask. */
|
---|
2946 | uint8_t *pu8Mask = pu8Pointer + sizeof(VRDEMOUSEPTRDATA);
|
---|
2947 | if (cbDstMask)
|
---|
2948 | {
|
---|
2949 | memcpy(pu8Mask, pu8Shape, cbDstMask);
|
---|
2950 | }
|
---|
2951 |
|
---|
2952 | /* XOR mask */
|
---|
2953 | uint8_t *pu8Data = pu8Mask + pPointer->u16MaskLen;
|
---|
2954 | memcpy(pu8Data, pu8Shape + cbMask, cbData);
|
---|
2955 |
|
---|
2956 | m_interfaceMousePtr.VRDEMousePtr(mhServer, pPointer);
|
---|
2957 |
|
---|
2958 | RTMemFree(pu8Pointer);
|
---|
2959 | }
|
---|
2960 | else
|
---|
2961 | {
|
---|
2962 | rc = VERR_NO_MEMORY;
|
---|
2963 | }
|
---|
2964 | }
|
---|
2965 | else
|
---|
2966 | {
|
---|
2967 | rc = VERR_NOT_SUPPORTED;
|
---|
2968 | }
|
---|
2969 |
|
---|
2970 | return rc;
|
---|
2971 | }
|
---|
2972 |
|
---|
2973 | void ConsoleVRDPServer::MousePointerUpdate(const VRDECOLORPOINTER *pPointer)
|
---|
2974 | {
|
---|
2975 | if (mpEntryPoints && mhServer)
|
---|
2976 | {
|
---|
2977 | mpEntryPoints->VRDEColorPointer(mhServer, pPointer);
|
---|
2978 | }
|
---|
2979 | }
|
---|
2980 |
|
---|
2981 | void ConsoleVRDPServer::MousePointerHide(void)
|
---|
2982 | {
|
---|
2983 | if (mpEntryPoints && mhServer)
|
---|
2984 | {
|
---|
2985 | mpEntryPoints->VRDEHidePointer(mhServer);
|
---|
2986 | }
|
---|
2987 | }
|
---|
2988 |
|
---|
2989 | void ConsoleVRDPServer::Stop(void)
|
---|
2990 | {
|
---|
2991 | Assert(VALID_PTR(this)); /** @todo r=bird: there are(/was) some odd cases where this buster was invalid on
|
---|
2992 | * linux. Just remove this when it's 100% sure that problem has been fixed. */
|
---|
2993 |
|
---|
2994 | #ifdef VBOX_WITH_USB
|
---|
2995 | remoteUSBThreadStop();
|
---|
2996 | #endif /* VBOX_WITH_USB */
|
---|
2997 |
|
---|
2998 | if (mhServer)
|
---|
2999 | {
|
---|
3000 | HVRDESERVER hServer = mhServer;
|
---|
3001 |
|
---|
3002 | /* Reset the handle to avoid further calls to the server. */
|
---|
3003 | mhServer = 0;
|
---|
3004 |
|
---|
3005 | /* Workaround for VM process hangs on termination.
|
---|
3006 | *
|
---|
3007 | * Make sure that the server is not currently processing a resize.
|
---|
3008 | * mhServer 0 will not allow to enter the server again.
|
---|
3009 | * Wait until any current resize returns from the server.
|
---|
3010 | */
|
---|
3011 | if (mcInResize)
|
---|
3012 | {
|
---|
3013 | LogRel(("VRDP: waiting for resize %d\n", mcInResize));
|
---|
3014 |
|
---|
3015 | int i = 0;
|
---|
3016 | while (mcInResize && ++i < 100)
|
---|
3017 | {
|
---|
3018 | RTThreadSleep(10);
|
---|
3019 | }
|
---|
3020 | }
|
---|
3021 |
|
---|
3022 | if (mpEntryPoints && hServer)
|
---|
3023 | {
|
---|
3024 | mpEntryPoints->VRDEDestroy(hServer);
|
---|
3025 | }
|
---|
3026 | }
|
---|
3027 |
|
---|
3028 | #ifndef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
|
---|
3029 | AuthLibUnload(&mAuthLibCtx);
|
---|
3030 | #endif
|
---|
3031 | }
|
---|
3032 |
|
---|
3033 | /* Worker thread for Remote USB. The thread polls the clients for
|
---|
3034 | * the list of attached USB devices.
|
---|
3035 | * The thread is also responsible for attaching/detaching devices
|
---|
3036 | * to/from the VM.
|
---|
3037 | *
|
---|
3038 | * It is expected that attaching/detaching is not a frequent operation.
|
---|
3039 | *
|
---|
3040 | * The thread is always running when the VRDP server is active.
|
---|
3041 | *
|
---|
3042 | * The thread scans backends and requests the device list every 2 seconds.
|
---|
3043 | *
|
---|
3044 | * When device list is available, the thread calls the Console to process it.
|
---|
3045 | *
|
---|
3046 | */
|
---|
3047 | #define VRDP_DEVICE_LIST_PERIOD_MS (2000)
|
---|
3048 |
|
---|
3049 | #ifdef VBOX_WITH_USB
|
---|
3050 | static DECLCALLBACK(int) threadRemoteUSB(RTTHREAD self, void *pvUser)
|
---|
3051 | {
|
---|
3052 | ConsoleVRDPServer *pOwner = (ConsoleVRDPServer *)pvUser;
|
---|
3053 |
|
---|
3054 | LogFlow(("Console::threadRemoteUSB: start. owner = %p.\n", pOwner));
|
---|
3055 |
|
---|
3056 | pOwner->notifyRemoteUSBThreadRunning(self);
|
---|
3057 |
|
---|
3058 | while (pOwner->isRemoteUSBThreadRunning())
|
---|
3059 | {
|
---|
3060 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3061 |
|
---|
3062 | while ((pRemoteUSBBackend = pOwner->usbBackendGetNext(pRemoteUSBBackend)) != NULL)
|
---|
3063 | {
|
---|
3064 | pRemoteUSBBackend->PollRemoteDevices();
|
---|
3065 | }
|
---|
3066 |
|
---|
3067 | pOwner->waitRemoteUSBThreadEvent(VRDP_DEVICE_LIST_PERIOD_MS);
|
---|
3068 |
|
---|
3069 | LogFlow(("Console::threadRemoteUSB: iteration. owner = %p.\n", pOwner));
|
---|
3070 | }
|
---|
3071 |
|
---|
3072 | return VINF_SUCCESS;
|
---|
3073 | }
|
---|
3074 |
|
---|
3075 | void ConsoleVRDPServer::notifyRemoteUSBThreadRunning(RTTHREAD thread)
|
---|
3076 | {
|
---|
3077 | mUSBBackends.thread = thread;
|
---|
3078 | mUSBBackends.fThreadRunning = true;
|
---|
3079 | int rc = RTThreadUserSignal(thread);
|
---|
3080 | AssertRC(rc);
|
---|
3081 | }
|
---|
3082 |
|
---|
3083 | bool ConsoleVRDPServer::isRemoteUSBThreadRunning(void)
|
---|
3084 | {
|
---|
3085 | return mUSBBackends.fThreadRunning;
|
---|
3086 | }
|
---|
3087 |
|
---|
3088 | void ConsoleVRDPServer::waitRemoteUSBThreadEvent(RTMSINTERVAL cMillies)
|
---|
3089 | {
|
---|
3090 | int rc = RTSemEventWait(mUSBBackends.event, cMillies);
|
---|
3091 | Assert(RT_SUCCESS(rc) || rc == VERR_TIMEOUT);
|
---|
3092 | NOREF(rc);
|
---|
3093 | }
|
---|
3094 |
|
---|
3095 | void ConsoleVRDPServer::remoteUSBThreadStart(void)
|
---|
3096 | {
|
---|
3097 | int rc = RTSemEventCreate(&mUSBBackends.event);
|
---|
3098 |
|
---|
3099 | if (RT_FAILURE(rc))
|
---|
3100 | {
|
---|
3101 | AssertFailed();
|
---|
3102 | mUSBBackends.event = 0;
|
---|
3103 | }
|
---|
3104 |
|
---|
3105 | if (RT_SUCCESS(rc))
|
---|
3106 | {
|
---|
3107 | rc = RTThreadCreate(&mUSBBackends.thread, threadRemoteUSB, this, 65536,
|
---|
3108 | RTTHREADTYPE_VRDP_IO, RTTHREADFLAGS_WAITABLE, "remote usb");
|
---|
3109 | }
|
---|
3110 |
|
---|
3111 | if (RT_FAILURE(rc))
|
---|
3112 | {
|
---|
3113 | LogRel(("Warning: could not start the remote USB thread, rc = %Rrc!!!\n", rc));
|
---|
3114 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
3115 | }
|
---|
3116 | else
|
---|
3117 | {
|
---|
3118 | /* Wait until the thread is ready. */
|
---|
3119 | rc = RTThreadUserWait(mUSBBackends.thread, 60000);
|
---|
3120 | AssertRC(rc);
|
---|
3121 | Assert (mUSBBackends.fThreadRunning || RT_FAILURE(rc));
|
---|
3122 | }
|
---|
3123 | }
|
---|
3124 |
|
---|
3125 | void ConsoleVRDPServer::remoteUSBThreadStop(void)
|
---|
3126 | {
|
---|
3127 | mUSBBackends.fThreadRunning = false;
|
---|
3128 |
|
---|
3129 | if (mUSBBackends.thread != NIL_RTTHREAD)
|
---|
3130 | {
|
---|
3131 | Assert (mUSBBackends.event != 0);
|
---|
3132 |
|
---|
3133 | RTSemEventSignal(mUSBBackends.event);
|
---|
3134 |
|
---|
3135 | int rc = RTThreadWait(mUSBBackends.thread, 60000, NULL);
|
---|
3136 | AssertRC(rc);
|
---|
3137 |
|
---|
3138 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
3139 | }
|
---|
3140 |
|
---|
3141 | if (mUSBBackends.event)
|
---|
3142 | {
|
---|
3143 | RTSemEventDestroy(mUSBBackends.event);
|
---|
3144 | mUSBBackends.event = 0;
|
---|
3145 | }
|
---|
3146 | }
|
---|
3147 | #endif /* VBOX_WITH_USB */
|
---|
3148 |
|
---|
3149 | AuthResult ConsoleVRDPServer::Authenticate(const Guid &uuid, AuthGuestJudgement guestJudgement,
|
---|
3150 | const char *pszUser, const char *pszPassword, const char *pszDomain,
|
---|
3151 | uint32_t u32ClientId)
|
---|
3152 | {
|
---|
3153 | LogFlowFunc(("uuid = %RTuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n",
|
---|
3154 | uuid.raw(), guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId));
|
---|
3155 |
|
---|
3156 | AuthResult result = AuthResultAccessDenied;
|
---|
3157 |
|
---|
3158 | #ifdef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
|
---|
3159 | try
|
---|
3160 | {
|
---|
3161 | /* Init auth parameters. Order is important. */
|
---|
3162 | SafeArray<BSTR> authParams;
|
---|
3163 | Bstr("VRDEAUTH" ).detachTo(authParams.appendedRaw());
|
---|
3164 | Bstr(uuid.toUtf16() ).detachTo(authParams.appendedRaw());
|
---|
3165 | BstrFmt("%u", guestJudgement).detachTo(authParams.appendedRaw());
|
---|
3166 | Bstr(pszUser ).detachTo(authParams.appendedRaw());
|
---|
3167 | Bstr(pszPassword ).detachTo(authParams.appendedRaw());
|
---|
3168 | Bstr(pszDomain ).detachTo(authParams.appendedRaw());
|
---|
3169 | BstrFmt("%u", u32ClientId).detachTo(authParams.appendedRaw());
|
---|
3170 |
|
---|
3171 | Bstr authResult;
|
---|
3172 | HRESULT hr = mConsole->mControl->AuthenticateExternal(ComSafeArrayAsInParam(authParams),
|
---|
3173 | authResult.asOutParam());
|
---|
3174 | LogFlowFunc(("%Rhrc [%ls]\n", hr, authResult.raw()));
|
---|
3175 |
|
---|
3176 | size_t cbPassword = RTUtf16Len((PRTUTF16)authParams[4]) * sizeof(RTUTF16);
|
---|
3177 | if (cbPassword)
|
---|
3178 | RTMemWipeThoroughly(authParams[4], cbPassword, 10 /* cPasses */);
|
---|
3179 |
|
---|
3180 | if (SUCCEEDED(hr) && authResult == "granted")
|
---|
3181 | result = AuthResultAccessGranted;
|
---|
3182 | }
|
---|
3183 | catch (std::bad_alloc &)
|
---|
3184 | {
|
---|
3185 | }
|
---|
3186 | #else
|
---|
3187 | /*
|
---|
3188 | * Called only from VRDP input thread. So thread safety is not required.
|
---|
3189 | */
|
---|
3190 |
|
---|
3191 | if (!mAuthLibCtx.hAuthLibrary)
|
---|
3192 | {
|
---|
3193 | /* Load the external authentication library. */
|
---|
3194 | Bstr authLibrary;
|
---|
3195 | mConsole->i_getVRDEServer()->COMGETTER(AuthLibrary)(authLibrary.asOutParam());
|
---|
3196 |
|
---|
3197 | Utf8Str filename = authLibrary;
|
---|
3198 |
|
---|
3199 | int vrc = AuthLibLoad(&mAuthLibCtx, filename.c_str());
|
---|
3200 | if (RT_FAILURE(vrc))
|
---|
3201 | {
|
---|
3202 | mConsole->setErrorBoth(E_FAIL, vrc, mConsole->tr("Could not load the external authentication library '%s' (%Rrc)"),
|
---|
3203 | filename.c_str(), vrc);
|
---|
3204 | return AuthResultAccessDenied;
|
---|
3205 | }
|
---|
3206 | }
|
---|
3207 |
|
---|
3208 | result = AuthLibAuthenticate(&mAuthLibCtx,
|
---|
3209 | uuid.raw(), guestJudgement,
|
---|
3210 | pszUser, pszPassword, pszDomain,
|
---|
3211 | u32ClientId);
|
---|
3212 | #endif /* !VBOX_WITH_VRDEAUTH_IN_VBOXSVC */
|
---|
3213 |
|
---|
3214 | switch (result)
|
---|
3215 | {
|
---|
3216 | case AuthResultAccessDenied:
|
---|
3217 | LogRel(("AUTH: external authentication module returned 'access denied'\n"));
|
---|
3218 | break;
|
---|
3219 | case AuthResultAccessGranted:
|
---|
3220 | LogRel(("AUTH: external authentication module returned 'access granted'\n"));
|
---|
3221 | break;
|
---|
3222 | case AuthResultDelegateToGuest:
|
---|
3223 | LogRel(("AUTH: external authentication module returned 'delegate request to guest'\n"));
|
---|
3224 | break;
|
---|
3225 | default:
|
---|
3226 | LogRel(("AUTH: external authentication module returned incorrect return code %d\n", result));
|
---|
3227 | result = AuthResultAccessDenied;
|
---|
3228 | }
|
---|
3229 |
|
---|
3230 | LogFlowFunc(("result = %d\n", result));
|
---|
3231 |
|
---|
3232 | return result;
|
---|
3233 | }
|
---|
3234 |
|
---|
3235 | void ConsoleVRDPServer::AuthDisconnect(const Guid &uuid, uint32_t u32ClientId)
|
---|
3236 | {
|
---|
3237 | LogFlow(("ConsoleVRDPServer::AuthDisconnect: uuid = %RTuuid, u32ClientId = %d\n",
|
---|
3238 | uuid.raw(), u32ClientId));
|
---|
3239 |
|
---|
3240 | #ifdef VBOX_WITH_VRDEAUTH_IN_VBOXSVC
|
---|
3241 | try
|
---|
3242 | {
|
---|
3243 | /* Init auth parameters. Order is important. */
|
---|
3244 | SafeArray<BSTR> authParams;
|
---|
3245 | Bstr("VRDEAUTHDISCONNECT").detachTo(authParams.appendedRaw());
|
---|
3246 | Bstr(uuid.toUtf16() ).detachTo(authParams.appendedRaw());
|
---|
3247 | BstrFmt("%u", u32ClientId).detachTo(authParams.appendedRaw());
|
---|
3248 |
|
---|
3249 | Bstr authResult;
|
---|
3250 | HRESULT hr = mConsole->mControl->AuthenticateExternal(ComSafeArrayAsInParam(authParams),
|
---|
3251 | authResult.asOutParam());
|
---|
3252 | LogFlowFunc(("%Rhrc [%ls]\n", hr, authResult.raw())); NOREF(hr);
|
---|
3253 | }
|
---|
3254 | catch (std::bad_alloc &)
|
---|
3255 | {
|
---|
3256 | }
|
---|
3257 | #else
|
---|
3258 | AuthLibDisconnect(&mAuthLibCtx, uuid.raw(), u32ClientId);
|
---|
3259 | #endif /* !VBOX_WITH_VRDEAUTH_IN_VBOXSVC */
|
---|
3260 | }
|
---|
3261 |
|
---|
3262 | int ConsoleVRDPServer::lockConsoleVRDPServer(void)
|
---|
3263 | {
|
---|
3264 | int rc = RTCritSectEnter(&mCritSect);
|
---|
3265 | AssertRC(rc);
|
---|
3266 | return rc;
|
---|
3267 | }
|
---|
3268 |
|
---|
3269 | void ConsoleVRDPServer::unlockConsoleVRDPServer(void)
|
---|
3270 | {
|
---|
3271 | RTCritSectLeave(&mCritSect);
|
---|
3272 | }
|
---|
3273 |
|
---|
3274 | DECLCALLBACK(int) ConsoleVRDPServer::ClipboardCallback(void *pvCallback,
|
---|
3275 | uint32_t u32ClientId,
|
---|
3276 | uint32_t u32Function,
|
---|
3277 | uint32_t u32Format,
|
---|
3278 | const void *pvData,
|
---|
3279 | uint32_t cbData)
|
---|
3280 | {
|
---|
3281 | LogFlowFunc(("pvCallback = %p, u32ClientId = %d, u32Function = %d, u32Format = 0x%08X, pvData = %p, cbData = %d\n",
|
---|
3282 | pvCallback, u32ClientId, u32Function, u32Format, pvData, cbData));
|
---|
3283 |
|
---|
3284 | int rc = VINF_SUCCESS;
|
---|
3285 |
|
---|
3286 | ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvCallback);
|
---|
3287 |
|
---|
3288 | RT_NOREF(u32ClientId);
|
---|
3289 |
|
---|
3290 | switch (u32Function)
|
---|
3291 | {
|
---|
3292 | case VRDE_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE:
|
---|
3293 | {
|
---|
3294 | if (pServer->mpfnClipboardCallback)
|
---|
3295 | {
|
---|
3296 | pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
|
---|
3297 | u32Format,
|
---|
3298 | (void *)pvData,
|
---|
3299 | cbData);
|
---|
3300 | }
|
---|
3301 | } break;
|
---|
3302 |
|
---|
3303 | case VRDE_CLIPBOARD_FUNCTION_DATA_READ:
|
---|
3304 | {
|
---|
3305 | if (pServer->mpfnClipboardCallback)
|
---|
3306 | {
|
---|
3307 | pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_DATA_READ,
|
---|
3308 | u32Format,
|
---|
3309 | (void *)pvData,
|
---|
3310 | cbData);
|
---|
3311 | }
|
---|
3312 | } break;
|
---|
3313 |
|
---|
3314 | default:
|
---|
3315 | {
|
---|
3316 | rc = VERR_NOT_SUPPORTED;
|
---|
3317 | } break;
|
---|
3318 | }
|
---|
3319 |
|
---|
3320 | return rc;
|
---|
3321 | }
|
---|
3322 |
|
---|
3323 | void ConsoleVRDPServer::ClipboardCreate(uint32_t u32ClientId)
|
---|
3324 | {
|
---|
3325 | RT_NOREF(u32ClientId);
|
---|
3326 |
|
---|
3327 | int rc = lockConsoleVRDPServer();
|
---|
3328 | if (RT_SUCCESS(rc))
|
---|
3329 | {
|
---|
3330 | if (mcClipboardRefs == 0)
|
---|
3331 | mcClipboardRefs++;
|
---|
3332 |
|
---|
3333 | unlockConsoleVRDPServer();
|
---|
3334 | }
|
---|
3335 | }
|
---|
3336 |
|
---|
3337 | void ConsoleVRDPServer::ClipboardDelete(uint32_t u32ClientId)
|
---|
3338 | {
|
---|
3339 | RT_NOREF(u32ClientId);
|
---|
3340 |
|
---|
3341 | int rc = lockConsoleVRDPServer();
|
---|
3342 | if (RT_SUCCESS(rc))
|
---|
3343 | {
|
---|
3344 | Assert(mcClipboardRefs);
|
---|
3345 | mcClipboardRefs--;
|
---|
3346 |
|
---|
3347 | unlockConsoleVRDPServer();
|
---|
3348 | }
|
---|
3349 | }
|
---|
3350 |
|
---|
3351 | /* That is called on INPUT thread of the VRDP server.
|
---|
3352 | * The ConsoleVRDPServer keeps a list of created backend instances.
|
---|
3353 | */
|
---|
3354 | void ConsoleVRDPServer::USBBackendCreate(uint32_t u32ClientId, void **ppvIntercept)
|
---|
3355 | {
|
---|
3356 | #ifdef VBOX_WITH_USB
|
---|
3357 | LogFlow(("ConsoleVRDPServer::USBBackendCreate: u32ClientId = %d\n", u32ClientId));
|
---|
3358 |
|
---|
3359 | /* Create a new instance of the USB backend for the new client. */
|
---|
3360 | RemoteUSBBackend *pRemoteUSBBackend = new RemoteUSBBackend(mConsole, this, u32ClientId);
|
---|
3361 |
|
---|
3362 | if (pRemoteUSBBackend)
|
---|
3363 | {
|
---|
3364 | pRemoteUSBBackend->AddRef(); /* 'Release' called in USBBackendDelete. */
|
---|
3365 |
|
---|
3366 | /* Append the new instance in the list. */
|
---|
3367 | int rc = lockConsoleVRDPServer();
|
---|
3368 |
|
---|
3369 | if (RT_SUCCESS(rc))
|
---|
3370 | {
|
---|
3371 | pRemoteUSBBackend->pNext = mUSBBackends.pHead;
|
---|
3372 | if (mUSBBackends.pHead)
|
---|
3373 | {
|
---|
3374 | mUSBBackends.pHead->pPrev = pRemoteUSBBackend;
|
---|
3375 | }
|
---|
3376 | else
|
---|
3377 | {
|
---|
3378 | mUSBBackends.pTail = pRemoteUSBBackend;
|
---|
3379 | }
|
---|
3380 |
|
---|
3381 | mUSBBackends.pHead = pRemoteUSBBackend;
|
---|
3382 |
|
---|
3383 | unlockConsoleVRDPServer();
|
---|
3384 |
|
---|
3385 | if (ppvIntercept)
|
---|
3386 | {
|
---|
3387 | *ppvIntercept = pRemoteUSBBackend;
|
---|
3388 | }
|
---|
3389 | }
|
---|
3390 |
|
---|
3391 | if (RT_FAILURE(rc))
|
---|
3392 | {
|
---|
3393 | pRemoteUSBBackend->Release();
|
---|
3394 | }
|
---|
3395 | }
|
---|
3396 | #endif /* VBOX_WITH_USB */
|
---|
3397 | }
|
---|
3398 |
|
---|
3399 | void ConsoleVRDPServer::USBBackendDelete(uint32_t u32ClientId)
|
---|
3400 | {
|
---|
3401 | #ifdef VBOX_WITH_USB
|
---|
3402 | LogFlow(("ConsoleVRDPServer::USBBackendDelete: u32ClientId = %d\n", u32ClientId));
|
---|
3403 |
|
---|
3404 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3405 |
|
---|
3406 | /* Find the instance. */
|
---|
3407 | int rc = lockConsoleVRDPServer();
|
---|
3408 |
|
---|
3409 | if (RT_SUCCESS(rc))
|
---|
3410 | {
|
---|
3411 | pRemoteUSBBackend = usbBackendFind(u32ClientId);
|
---|
3412 |
|
---|
3413 | if (pRemoteUSBBackend)
|
---|
3414 | {
|
---|
3415 | /* Notify that it will be deleted. */
|
---|
3416 | pRemoteUSBBackend->NotifyDelete();
|
---|
3417 | }
|
---|
3418 |
|
---|
3419 | unlockConsoleVRDPServer();
|
---|
3420 | }
|
---|
3421 |
|
---|
3422 | if (pRemoteUSBBackend)
|
---|
3423 | {
|
---|
3424 | /* Here the instance has been excluded from the list and can be dereferenced. */
|
---|
3425 | pRemoteUSBBackend->Release();
|
---|
3426 | }
|
---|
3427 | #endif
|
---|
3428 | }
|
---|
3429 |
|
---|
3430 | void *ConsoleVRDPServer::USBBackendRequestPointer(uint32_t u32ClientId, const Guid *pGuid)
|
---|
3431 | {
|
---|
3432 | #ifdef VBOX_WITH_USB
|
---|
3433 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3434 |
|
---|
3435 | /* Find the instance. */
|
---|
3436 | int rc = lockConsoleVRDPServer();
|
---|
3437 |
|
---|
3438 | if (RT_SUCCESS(rc))
|
---|
3439 | {
|
---|
3440 | pRemoteUSBBackend = usbBackendFind(u32ClientId);
|
---|
3441 |
|
---|
3442 | if (pRemoteUSBBackend)
|
---|
3443 | {
|
---|
3444 | /* Inform the backend instance that it is referenced by the Guid. */
|
---|
3445 | bool fAdded = pRemoteUSBBackend->addUUID(pGuid);
|
---|
3446 |
|
---|
3447 | if (fAdded)
|
---|
3448 | {
|
---|
3449 | /* Reference the instance because its pointer is being taken. */
|
---|
3450 | pRemoteUSBBackend->AddRef(); /* 'Release' is called in USBBackendReleasePointer. */
|
---|
3451 | }
|
---|
3452 | else
|
---|
3453 | {
|
---|
3454 | pRemoteUSBBackend = NULL;
|
---|
3455 | }
|
---|
3456 | }
|
---|
3457 |
|
---|
3458 | unlockConsoleVRDPServer();
|
---|
3459 | }
|
---|
3460 |
|
---|
3461 | if (pRemoteUSBBackend)
|
---|
3462 | {
|
---|
3463 | return pRemoteUSBBackend->GetBackendCallbackPointer();
|
---|
3464 | }
|
---|
3465 |
|
---|
3466 | #endif
|
---|
3467 | return NULL;
|
---|
3468 | }
|
---|
3469 |
|
---|
3470 | void ConsoleVRDPServer::USBBackendReleasePointer(const Guid *pGuid)
|
---|
3471 | {
|
---|
3472 | #ifdef VBOX_WITH_USB
|
---|
3473 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3474 |
|
---|
3475 | /* Find the instance. */
|
---|
3476 | int rc = lockConsoleVRDPServer();
|
---|
3477 |
|
---|
3478 | if (RT_SUCCESS(rc))
|
---|
3479 | {
|
---|
3480 | pRemoteUSBBackend = usbBackendFindByUUID(pGuid);
|
---|
3481 |
|
---|
3482 | if (pRemoteUSBBackend)
|
---|
3483 | {
|
---|
3484 | pRemoteUSBBackend->removeUUID(pGuid);
|
---|
3485 | }
|
---|
3486 |
|
---|
3487 | unlockConsoleVRDPServer();
|
---|
3488 |
|
---|
3489 | if (pRemoteUSBBackend)
|
---|
3490 | {
|
---|
3491 | pRemoteUSBBackend->Release();
|
---|
3492 | }
|
---|
3493 | }
|
---|
3494 | #endif
|
---|
3495 | }
|
---|
3496 |
|
---|
3497 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendGetNext(RemoteUSBBackend *pRemoteUSBBackend)
|
---|
3498 | {
|
---|
3499 | LogFlow(("ConsoleVRDPServer::usbBackendGetNext: pBackend = %p\n", pRemoteUSBBackend));
|
---|
3500 |
|
---|
3501 | RemoteUSBBackend *pNextRemoteUSBBackend = NULL;
|
---|
3502 | #ifdef VBOX_WITH_USB
|
---|
3503 |
|
---|
3504 | int rc = lockConsoleVRDPServer();
|
---|
3505 |
|
---|
3506 | if (RT_SUCCESS(rc))
|
---|
3507 | {
|
---|
3508 | if (pRemoteUSBBackend == NULL)
|
---|
3509 | {
|
---|
3510 | /* The first backend in the list is requested. */
|
---|
3511 | pNextRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3512 | }
|
---|
3513 | else
|
---|
3514 | {
|
---|
3515 | /* Get pointer to the next backend. */
|
---|
3516 | pNextRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3517 | }
|
---|
3518 |
|
---|
3519 | if (pNextRemoteUSBBackend)
|
---|
3520 | {
|
---|
3521 | pNextRemoteUSBBackend->AddRef();
|
---|
3522 | }
|
---|
3523 |
|
---|
3524 | unlockConsoleVRDPServer();
|
---|
3525 |
|
---|
3526 | if (pRemoteUSBBackend)
|
---|
3527 | {
|
---|
3528 | pRemoteUSBBackend->Release();
|
---|
3529 | }
|
---|
3530 | }
|
---|
3531 | #endif
|
---|
3532 |
|
---|
3533 | return pNextRemoteUSBBackend;
|
---|
3534 | }
|
---|
3535 |
|
---|
3536 | #ifdef VBOX_WITH_USB
|
---|
3537 | /* Internal method. Called under the ConsoleVRDPServerLock. */
|
---|
3538 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendFind(uint32_t u32ClientId)
|
---|
3539 | {
|
---|
3540 | RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3541 |
|
---|
3542 | while (pRemoteUSBBackend)
|
---|
3543 | {
|
---|
3544 | if (pRemoteUSBBackend->ClientId() == u32ClientId)
|
---|
3545 | {
|
---|
3546 | break;
|
---|
3547 | }
|
---|
3548 |
|
---|
3549 | pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3550 | }
|
---|
3551 |
|
---|
3552 | return pRemoteUSBBackend;
|
---|
3553 | }
|
---|
3554 |
|
---|
3555 | /* Internal method. Called under the ConsoleVRDPServerLock. */
|
---|
3556 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendFindByUUID(const Guid *pGuid)
|
---|
3557 | {
|
---|
3558 | RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3559 |
|
---|
3560 | while (pRemoteUSBBackend)
|
---|
3561 | {
|
---|
3562 | if (pRemoteUSBBackend->findUUID(pGuid))
|
---|
3563 | {
|
---|
3564 | break;
|
---|
3565 | }
|
---|
3566 |
|
---|
3567 | pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3568 | }
|
---|
3569 |
|
---|
3570 | return pRemoteUSBBackend;
|
---|
3571 | }
|
---|
3572 | #endif
|
---|
3573 |
|
---|
3574 | /* Internal method. Called by the backend destructor. */
|
---|
3575 | void ConsoleVRDPServer::usbBackendRemoveFromList(RemoteUSBBackend *pRemoteUSBBackend)
|
---|
3576 | {
|
---|
3577 | #ifdef VBOX_WITH_USB
|
---|
3578 | int rc = lockConsoleVRDPServer();
|
---|
3579 | AssertRC(rc);
|
---|
3580 |
|
---|
3581 | /* Exclude the found instance from the list. */
|
---|
3582 | if (pRemoteUSBBackend->pNext)
|
---|
3583 | {
|
---|
3584 | pRemoteUSBBackend->pNext->pPrev = pRemoteUSBBackend->pPrev;
|
---|
3585 | }
|
---|
3586 | else
|
---|
3587 | {
|
---|
3588 | mUSBBackends.pTail = (RemoteUSBBackend *)pRemoteUSBBackend->pPrev;
|
---|
3589 | }
|
---|
3590 |
|
---|
3591 | if (pRemoteUSBBackend->pPrev)
|
---|
3592 | {
|
---|
3593 | pRemoteUSBBackend->pPrev->pNext = pRemoteUSBBackend->pNext;
|
---|
3594 | }
|
---|
3595 | else
|
---|
3596 | {
|
---|
3597 | mUSBBackends.pHead = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3598 | }
|
---|
3599 |
|
---|
3600 | pRemoteUSBBackend->pNext = pRemoteUSBBackend->pPrev = NULL;
|
---|
3601 |
|
---|
3602 | unlockConsoleVRDPServer();
|
---|
3603 | #endif
|
---|
3604 | }
|
---|
3605 |
|
---|
3606 |
|
---|
3607 | void ConsoleVRDPServer::SendUpdate(unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const
|
---|
3608 | {
|
---|
3609 | if (mpEntryPoints && mhServer)
|
---|
3610 | {
|
---|
3611 | mpEntryPoints->VRDEUpdate(mhServer, uScreenId, pvUpdate, cbUpdate);
|
---|
3612 | }
|
---|
3613 | }
|
---|
3614 |
|
---|
3615 | void ConsoleVRDPServer::SendResize(void)
|
---|
3616 | {
|
---|
3617 | if (mpEntryPoints && mhServer)
|
---|
3618 | {
|
---|
3619 | ++mcInResize;
|
---|
3620 | mpEntryPoints->VRDEResize(mhServer);
|
---|
3621 | --mcInResize;
|
---|
3622 | }
|
---|
3623 | }
|
---|
3624 |
|
---|
3625 | void ConsoleVRDPServer::SendUpdateBitmap(unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const
|
---|
3626 | {
|
---|
3627 | VRDEORDERHDR update;
|
---|
3628 | update.x = (uint16_t)x;
|
---|
3629 | update.y = (uint16_t)y;
|
---|
3630 | update.w = (uint16_t)w;
|
---|
3631 | update.h = (uint16_t)h;
|
---|
3632 | if (mpEntryPoints && mhServer)
|
---|
3633 | {
|
---|
3634 | mpEntryPoints->VRDEUpdate(mhServer, uScreenId, &update, sizeof(update));
|
---|
3635 | }
|
---|
3636 | }
|
---|
3637 |
|
---|
3638 | void ConsoleVRDPServer::SendAudioSamples(void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const
|
---|
3639 | {
|
---|
3640 | if (mpEntryPoints && mhServer)
|
---|
3641 | {
|
---|
3642 | mpEntryPoints->VRDEAudioSamples(mhServer, pvSamples, cSamples, format);
|
---|
3643 | }
|
---|
3644 | }
|
---|
3645 |
|
---|
3646 | void ConsoleVRDPServer::SendAudioVolume(uint16_t left, uint16_t right) const
|
---|
3647 | {
|
---|
3648 | if (mpEntryPoints && mhServer)
|
---|
3649 | {
|
---|
3650 | mpEntryPoints->VRDEAudioVolume(mhServer, left, right);
|
---|
3651 | }
|
---|
3652 | }
|
---|
3653 |
|
---|
3654 | void ConsoleVRDPServer::SendUSBRequest(uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const
|
---|
3655 | {
|
---|
3656 | if (mpEntryPoints && mhServer)
|
---|
3657 | {
|
---|
3658 | mpEntryPoints->VRDEUSBRequest(mhServer, u32ClientId, pvParms, cbParms);
|
---|
3659 | }
|
---|
3660 | }
|
---|
3661 |
|
---|
3662 | void ConsoleVRDPServer::SendClipboard(uint32_t u32Function, uint32_t u32Format,
|
---|
3663 | void *pvData, uint32_t cbData, uint32_t *pcbActualRead) const
|
---|
3664 | {
|
---|
3665 | if (mpEntryPoints && mhServer)
|
---|
3666 | {
|
---|
3667 | mpEntryPoints->VRDEClipboard(mhServer, u32Function, u32Format, pvData, cbData, pcbActualRead);
|
---|
3668 | }
|
---|
3669 | }
|
---|
3670 |
|
---|
3671 | int ConsoleVRDPServer::SendAudioInputBegin(void **ppvUserCtx,
|
---|
3672 | void *pvContext,
|
---|
3673 | uint32_t cSamples,
|
---|
3674 | uint32_t iSampleHz,
|
---|
3675 | uint32_t cChannels,
|
---|
3676 | uint32_t cBits)
|
---|
3677 | {
|
---|
3678 | if ( mhServer
|
---|
3679 | && mpEntryPoints && mpEntryPoints->VRDEAudioInOpen)
|
---|
3680 | {
|
---|
3681 | uint32_t u32ClientId = ASMAtomicReadU32(&mu32AudioInputClientId);
|
---|
3682 | if (u32ClientId != 0) /* 0 would mean broadcast to all clients. */
|
---|
3683 | {
|
---|
3684 | VRDEAUDIOFORMAT audioFormat = VRDE_AUDIO_FMT_MAKE(iSampleHz, cChannels, cBits, 0);
|
---|
3685 | mpEntryPoints->VRDEAudioInOpen(mhServer,
|
---|
3686 | pvContext,
|
---|
3687 | u32ClientId,
|
---|
3688 | audioFormat,
|
---|
3689 | cSamples);
|
---|
3690 | if (ppvUserCtx)
|
---|
3691 | *ppvUserCtx = NULL; /* This is the ConsoleVRDPServer context.
|
---|
3692 | * Currently not used because only one client is allowed to
|
---|
3693 | * do audio input and the client ID is saved by the ConsoleVRDPServer.
|
---|
3694 | */
|
---|
3695 | return VINF_SUCCESS;
|
---|
3696 | }
|
---|
3697 | }
|
---|
3698 |
|
---|
3699 | /*
|
---|
3700 | * Not supported or no client connected.
|
---|
3701 | */
|
---|
3702 | return VERR_NOT_SUPPORTED;
|
---|
3703 | }
|
---|
3704 |
|
---|
3705 | void ConsoleVRDPServer::SendAudioInputEnd(void *pvUserCtx)
|
---|
3706 | {
|
---|
3707 | RT_NOREF(pvUserCtx);
|
---|
3708 | if (mpEntryPoints && mhServer && mpEntryPoints->VRDEAudioInClose)
|
---|
3709 | {
|
---|
3710 | uint32_t u32ClientId = ASMAtomicReadU32(&mu32AudioInputClientId);
|
---|
3711 | if (u32ClientId != 0) /* 0 would mean broadcast to all clients. */
|
---|
3712 | {
|
---|
3713 | mpEntryPoints->VRDEAudioInClose(mhServer, u32ClientId);
|
---|
3714 | }
|
---|
3715 | }
|
---|
3716 | }
|
---|
3717 |
|
---|
3718 | void ConsoleVRDPServer::QueryInfo(uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const
|
---|
3719 | {
|
---|
3720 | if (index == VRDE_QI_PORT)
|
---|
3721 | {
|
---|
3722 | uint32_t cbOut = sizeof(int32_t);
|
---|
3723 |
|
---|
3724 | if (cbBuffer >= cbOut)
|
---|
3725 | {
|
---|
3726 | *pcbOut = cbOut;
|
---|
3727 | *(int32_t *)pvBuffer = (int32_t)mVRDPBindPort;
|
---|
3728 | }
|
---|
3729 | }
|
---|
3730 | else if (mpEntryPoints && mhServer)
|
---|
3731 | {
|
---|
3732 | mpEntryPoints->VRDEQueryInfo(mhServer, index, pvBuffer, cbBuffer, pcbOut);
|
---|
3733 | }
|
---|
3734 | }
|
---|
3735 |
|
---|
3736 | /* static */ int ConsoleVRDPServer::loadVRDPLibrary(const char *pszLibraryName)
|
---|
3737 | {
|
---|
3738 | int rc = VINF_SUCCESS;
|
---|
3739 |
|
---|
3740 | if (mVRDPLibrary == NIL_RTLDRMOD)
|
---|
3741 | {
|
---|
3742 | RTERRINFOSTATIC ErrInfo;
|
---|
3743 | RTErrInfoInitStatic(&ErrInfo);
|
---|
3744 |
|
---|
3745 | if (RTPathHavePath(pszLibraryName))
|
---|
3746 | rc = SUPR3HardenedLdrLoadPlugIn(pszLibraryName, &mVRDPLibrary, &ErrInfo.Core);
|
---|
3747 | else
|
---|
3748 | rc = SUPR3HardenedLdrLoadAppPriv(pszLibraryName, &mVRDPLibrary, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
|
---|
3749 | if (RT_SUCCESS(rc))
|
---|
3750 | {
|
---|
3751 | struct SymbolEntry
|
---|
3752 | {
|
---|
3753 | const char *name;
|
---|
3754 | void **ppfn;
|
---|
3755 | };
|
---|
3756 |
|
---|
3757 | #define DEFSYMENTRY(a) { #a, (void**)&mpfn##a }
|
---|
3758 |
|
---|
3759 | static const struct SymbolEntry s_aSymbols[] =
|
---|
3760 | {
|
---|
3761 | DEFSYMENTRY(VRDECreateServer)
|
---|
3762 | };
|
---|
3763 |
|
---|
3764 | #undef DEFSYMENTRY
|
---|
3765 |
|
---|
3766 | for (unsigned i = 0; i < RT_ELEMENTS(s_aSymbols); i++)
|
---|
3767 | {
|
---|
3768 | rc = RTLdrGetSymbol(mVRDPLibrary, s_aSymbols[i].name, s_aSymbols[i].ppfn);
|
---|
3769 |
|
---|
3770 | if (RT_FAILURE(rc))
|
---|
3771 | {
|
---|
3772 | LogRel(("VRDE: Error resolving symbol '%s', rc %Rrc.\n", s_aSymbols[i].name, rc));
|
---|
3773 | break;
|
---|
3774 | }
|
---|
3775 | }
|
---|
3776 | }
|
---|
3777 | else
|
---|
3778 | {
|
---|
3779 | if (RTErrInfoIsSet(&ErrInfo.Core))
|
---|
3780 | LogRel(("VRDE: Error loading the library '%s': %s (%Rrc)\n", pszLibraryName, ErrInfo.Core.pszMsg, rc));
|
---|
3781 | else
|
---|
3782 | LogRel(("VRDE: Error loading the library '%s' rc = %Rrc.\n", pszLibraryName, rc));
|
---|
3783 |
|
---|
3784 | mVRDPLibrary = NIL_RTLDRMOD;
|
---|
3785 | }
|
---|
3786 | }
|
---|
3787 |
|
---|
3788 | if (RT_FAILURE(rc))
|
---|
3789 | {
|
---|
3790 | if (mVRDPLibrary != NIL_RTLDRMOD)
|
---|
3791 | {
|
---|
3792 | RTLdrClose(mVRDPLibrary);
|
---|
3793 | mVRDPLibrary = NIL_RTLDRMOD;
|
---|
3794 | }
|
---|
3795 | }
|
---|
3796 |
|
---|
3797 | return rc;
|
---|
3798 | }
|
---|
3799 |
|
---|
3800 | /*
|
---|
3801 | * IVRDEServerInfo implementation.
|
---|
3802 | */
|
---|
3803 | // constructor / destructor
|
---|
3804 | /////////////////////////////////////////////////////////////////////////////
|
---|
3805 |
|
---|
3806 | VRDEServerInfo::VRDEServerInfo()
|
---|
3807 | : mParent(NULL)
|
---|
3808 | {
|
---|
3809 | }
|
---|
3810 |
|
---|
3811 | VRDEServerInfo::~VRDEServerInfo()
|
---|
3812 | {
|
---|
3813 | }
|
---|
3814 |
|
---|
3815 |
|
---|
3816 | HRESULT VRDEServerInfo::FinalConstruct()
|
---|
3817 | {
|
---|
3818 | return BaseFinalConstruct();
|
---|
3819 | }
|
---|
3820 |
|
---|
3821 | void VRDEServerInfo::FinalRelease()
|
---|
3822 | {
|
---|
3823 | uninit();
|
---|
3824 | BaseFinalRelease();
|
---|
3825 | }
|
---|
3826 |
|
---|
3827 | // public methods only for internal purposes
|
---|
3828 | /////////////////////////////////////////////////////////////////////////////
|
---|
3829 |
|
---|
3830 | /**
|
---|
3831 | * Initializes the guest object.
|
---|
3832 | */
|
---|
3833 | HRESULT VRDEServerInfo::init(Console *aParent)
|
---|
3834 | {
|
---|
3835 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
3836 |
|
---|
3837 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
3838 |
|
---|
3839 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
3840 | AutoInitSpan autoInitSpan(this);
|
---|
3841 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
3842 |
|
---|
3843 | unconst(mParent) = aParent;
|
---|
3844 |
|
---|
3845 | /* Confirm a successful initialization */
|
---|
3846 | autoInitSpan.setSucceeded();
|
---|
3847 |
|
---|
3848 | return S_OK;
|
---|
3849 | }
|
---|
3850 |
|
---|
3851 | /**
|
---|
3852 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
3853 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
3854 | */
|
---|
3855 | void VRDEServerInfo::uninit()
|
---|
3856 | {
|
---|
3857 | LogFlowThisFunc(("\n"));
|
---|
3858 |
|
---|
3859 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
3860 | AutoUninitSpan autoUninitSpan(this);
|
---|
3861 | if (autoUninitSpan.uninitDone())
|
---|
3862 | return;
|
---|
3863 |
|
---|
3864 | unconst(mParent) = NULL;
|
---|
3865 | }
|
---|
3866 |
|
---|
3867 | // IVRDEServerInfo properties
|
---|
3868 | /////////////////////////////////////////////////////////////////////////////
|
---|
3869 |
|
---|
3870 | #define IMPL_GETTER_BOOL(_aType, _aName, _aIndex) \
|
---|
3871 | HRESULT VRDEServerInfo::get##_aName(_aType *a##_aName) \
|
---|
3872 | { \
|
---|
3873 | /** @todo Not sure if a AutoReadLock would be sufficient. */ \
|
---|
3874 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
3875 | \
|
---|
3876 | uint32_t value; \
|
---|
3877 | uint32_t cbOut = 0; \
|
---|
3878 | \
|
---|
3879 | mParent->i_consoleVRDPServer()->QueryInfo \
|
---|
3880 | (_aIndex, &value, sizeof(value), &cbOut); \
|
---|
3881 | \
|
---|
3882 | *a##_aName = cbOut? !!value: FALSE; \
|
---|
3883 | \
|
---|
3884 | return S_OK; \
|
---|
3885 | } \
|
---|
3886 | extern void IMPL_GETTER_BOOL_DUMMY(void)
|
---|
3887 |
|
---|
3888 | #define IMPL_GETTER_SCALAR(_aType, _aName, _aIndex, _aValueMask) \
|
---|
3889 | HRESULT VRDEServerInfo::get##_aName(_aType *a##_aName) \
|
---|
3890 | { \
|
---|
3891 | /** @todo Not sure if a AutoReadLock would be sufficient. */ \
|
---|
3892 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
3893 | \
|
---|
3894 | _aType value; \
|
---|
3895 | uint32_t cbOut = 0; \
|
---|
3896 | \
|
---|
3897 | mParent->i_consoleVRDPServer()->QueryInfo \
|
---|
3898 | (_aIndex, &value, sizeof(value), &cbOut); \
|
---|
3899 | \
|
---|
3900 | if (_aValueMask) value &= (_aValueMask); \
|
---|
3901 | *a##_aName = cbOut? value: 0; \
|
---|
3902 | \
|
---|
3903 | return S_OK; \
|
---|
3904 | } \
|
---|
3905 | extern void IMPL_GETTER_SCALAR_DUMMY(void)
|
---|
3906 |
|
---|
3907 | #define IMPL_GETTER_UTF8STR(_aType, _aName, _aIndex) \
|
---|
3908 | HRESULT VRDEServerInfo::get##_aName(_aType &a##_aName) \
|
---|
3909 | { \
|
---|
3910 | /** @todo Not sure if a AutoReadLock would be sufficient. */ \
|
---|
3911 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
3912 | \
|
---|
3913 | uint32_t cbOut = 0; \
|
---|
3914 | \
|
---|
3915 | mParent->i_consoleVRDPServer()->QueryInfo \
|
---|
3916 | (_aIndex, NULL, 0, &cbOut); \
|
---|
3917 | \
|
---|
3918 | if (cbOut == 0) \
|
---|
3919 | { \
|
---|
3920 | a##_aName = Utf8Str::Empty; \
|
---|
3921 | return S_OK; \
|
---|
3922 | } \
|
---|
3923 | \
|
---|
3924 | char *pchBuffer = (char *)RTMemTmpAlloc(cbOut); \
|
---|
3925 | \
|
---|
3926 | if (!pchBuffer) \
|
---|
3927 | { \
|
---|
3928 | Log(("VRDEServerInfo::" \
|
---|
3929 | #_aName \
|
---|
3930 | ": Failed to allocate memory %d bytes\n", cbOut)); \
|
---|
3931 | return E_OUTOFMEMORY; \
|
---|
3932 | } \
|
---|
3933 | \
|
---|
3934 | mParent->i_consoleVRDPServer()->QueryInfo \
|
---|
3935 | (_aIndex, pchBuffer, cbOut, &cbOut); \
|
---|
3936 | \
|
---|
3937 | a##_aName = pchBuffer; \
|
---|
3938 | \
|
---|
3939 | RTMemTmpFree(pchBuffer); \
|
---|
3940 | \
|
---|
3941 | return S_OK; \
|
---|
3942 | } \
|
---|
3943 | extern void IMPL_GETTER_BSTR_DUMMY(void)
|
---|
3944 |
|
---|
3945 | IMPL_GETTER_BOOL (BOOL, Active, VRDE_QI_ACTIVE);
|
---|
3946 | IMPL_GETTER_SCALAR (LONG, Port, VRDE_QI_PORT, 0);
|
---|
3947 | IMPL_GETTER_SCALAR (ULONG, NumberOfClients, VRDE_QI_NUMBER_OF_CLIENTS, 0);
|
---|
3948 | IMPL_GETTER_SCALAR (LONG64, BeginTime, VRDE_QI_BEGIN_TIME, 0);
|
---|
3949 | IMPL_GETTER_SCALAR (LONG64, EndTime, VRDE_QI_END_TIME, 0);
|
---|
3950 | IMPL_GETTER_SCALAR (LONG64, BytesSent, VRDE_QI_BYTES_SENT, INT64_MAX);
|
---|
3951 | IMPL_GETTER_SCALAR (LONG64, BytesSentTotal, VRDE_QI_BYTES_SENT_TOTAL, INT64_MAX);
|
---|
3952 | IMPL_GETTER_SCALAR (LONG64, BytesReceived, VRDE_QI_BYTES_RECEIVED, INT64_MAX);
|
---|
3953 | IMPL_GETTER_SCALAR (LONG64, BytesReceivedTotal, VRDE_QI_BYTES_RECEIVED_TOTAL, INT64_MAX);
|
---|
3954 | IMPL_GETTER_UTF8STR(Utf8Str, User, VRDE_QI_USER);
|
---|
3955 | IMPL_GETTER_UTF8STR(Utf8Str, Domain, VRDE_QI_DOMAIN);
|
---|
3956 | IMPL_GETTER_UTF8STR(Utf8Str, ClientName, VRDE_QI_CLIENT_NAME);
|
---|
3957 | IMPL_GETTER_UTF8STR(Utf8Str, ClientIP, VRDE_QI_CLIENT_IP);
|
---|
3958 | IMPL_GETTER_SCALAR (ULONG, ClientVersion, VRDE_QI_CLIENT_VERSION, 0);
|
---|
3959 | IMPL_GETTER_SCALAR (ULONG, EncryptionStyle, VRDE_QI_ENCRYPTION_STYLE, 0);
|
---|
3960 |
|
---|
3961 | #undef IMPL_GETTER_UTF8STR
|
---|
3962 | #undef IMPL_GETTER_SCALAR
|
---|
3963 | #undef IMPL_GETTER_BOOL
|
---|
3964 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|