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