1 | /* $Id: ConsoleVRDPServer.h 33004 2010-10-08 10:23:59Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VBox Console VRDP Helper class and implementation of IRemoteDisplayInfo
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2008 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef ____H_CONSOLEVRDPSERVER
|
---|
21 | #define ____H_CONSOLEVRDPSERVER
|
---|
22 |
|
---|
23 | #include "RemoteUSBBackend.h"
|
---|
24 | #include <hgcm/HGCM.h>
|
---|
25 |
|
---|
26 | #include <VBox/VRDPAuth.h>
|
---|
27 |
|
---|
28 | #include <VBox/HostServices/VBoxClipboardExt.h>
|
---|
29 |
|
---|
30 | #include "SchemaDefs.h"
|
---|
31 |
|
---|
32 | // ConsoleVRDPServer
|
---|
33 | ///////////////////////////////////////////////////////////////////////////////
|
---|
34 |
|
---|
35 | #ifdef VBOX_WITH_VRDP
|
---|
36 | typedef struct _VRDPInputSynch
|
---|
37 | {
|
---|
38 | int cGuestNumLockAdaptions;
|
---|
39 | int cGuestCapsLockAdaptions;
|
---|
40 |
|
---|
41 | bool fGuestNumLock;
|
---|
42 | bool fGuestCapsLock;
|
---|
43 | bool fGuestScrollLock;
|
---|
44 |
|
---|
45 | bool fClientNumLock;
|
---|
46 | bool fClientCapsLock;
|
---|
47 | bool fClientScrollLock;
|
---|
48 | } VRDPInputSynch;
|
---|
49 | #endif /* VBOX_WITH_VRDP */
|
---|
50 |
|
---|
51 | /* Member of Console. Helper class for VRDP server management. Not a COM class. */
|
---|
52 | class ConsoleVRDPServer
|
---|
53 | {
|
---|
54 | public:
|
---|
55 | ConsoleVRDPServer (Console *console);
|
---|
56 | ~ConsoleVRDPServer ();
|
---|
57 |
|
---|
58 | int Launch (void);
|
---|
59 |
|
---|
60 | void NotifyAbsoluteMouse (bool fGuestWantsAbsolute)
|
---|
61 | {
|
---|
62 | #ifdef VBOX_WITH_VRDP
|
---|
63 | m_fGuestWantsAbsolute = fGuestWantsAbsolute;
|
---|
64 | #else
|
---|
65 | NOREF(fGuestWantsAbsolute);
|
---|
66 | #endif /* VBOX_WITH_VRDP */
|
---|
67 | }
|
---|
68 |
|
---|
69 | void NotifyKeyboardLedsChange (BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
|
---|
70 | {
|
---|
71 | #ifdef VBOX_WITH_VRDP
|
---|
72 | bool fGuestNumLock = (fNumLock != FALSE);
|
---|
73 | bool fGuestCapsLock = (fCapsLock != FALSE);
|
---|
74 | bool fGuestScrollLock = (fScrollLock != FALSE);
|
---|
75 |
|
---|
76 | /* Might need to resynch in case the guest itself changed the LED status. */
|
---|
77 | if (m_InputSynch.fClientNumLock != fGuestNumLock)
|
---|
78 | {
|
---|
79 | m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
80 | }
|
---|
81 |
|
---|
82 | if (m_InputSynch.fClientCapsLock != fGuestCapsLock)
|
---|
83 | {
|
---|
84 | m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
85 | }
|
---|
86 |
|
---|
87 | m_InputSynch.fGuestNumLock = fGuestNumLock;
|
---|
88 | m_InputSynch.fGuestCapsLock = fGuestCapsLock;
|
---|
89 | m_InputSynch.fGuestScrollLock = fGuestScrollLock;
|
---|
90 | #else
|
---|
91 | NOREF(fNumLock);
|
---|
92 | NOREF(fCapsLock);
|
---|
93 | NOREF(fScrollLock);
|
---|
94 | #endif /* VBOX_WITH_VRDP */
|
---|
95 | }
|
---|
96 |
|
---|
97 | void EnableConnections (void);
|
---|
98 | void DisconnectClient (uint32_t u32ClientId, bool fReconnect);
|
---|
99 | void MousePointerUpdate (const VRDECOLORPOINTER *pPointer);
|
---|
100 | void MousePointerHide (void);
|
---|
101 |
|
---|
102 | void Stop (void);
|
---|
103 |
|
---|
104 | VRDPAuthResult Authenticate (const Guid &uuid, VRDPAuthGuestJudgement guestJudgement,
|
---|
105 | const char *pszUser, const char *pszPassword, const char *pszDomain,
|
---|
106 | uint32_t u32ClientId);
|
---|
107 |
|
---|
108 | void AuthDisconnect (const Guid &uuid, uint32_t u32ClientId);
|
---|
109 |
|
---|
110 | void USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept);
|
---|
111 | void USBBackendDelete (uint32_t u32ClientId);
|
---|
112 |
|
---|
113 | void *USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid);
|
---|
114 | void USBBackendReleasePointer (const Guid *pGuid);
|
---|
115 |
|
---|
116 | /* Private interface for the RemoteUSBBackend destructor. */
|
---|
117 | void usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend);
|
---|
118 |
|
---|
119 | /* Private methods for the Remote USB thread. */
|
---|
120 | RemoteUSBBackend *usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend);
|
---|
121 |
|
---|
122 | void notifyRemoteUSBThreadRunning (RTTHREAD thread);
|
---|
123 | bool isRemoteUSBThreadRunning (void);
|
---|
124 | void waitRemoteUSBThreadEvent (RTMSINTERVAL cMillies);
|
---|
125 |
|
---|
126 | void ClipboardCreate (uint32_t u32ClientId);
|
---|
127 | void ClipboardDelete (uint32_t u32ClientId);
|
---|
128 |
|
---|
129 | /*
|
---|
130 | * Forwarders to VRDP server library.
|
---|
131 | */
|
---|
132 | void SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const;
|
---|
133 | void SendResize (void) const;
|
---|
134 | void SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const;
|
---|
135 |
|
---|
136 | void SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const;
|
---|
137 | void SendAudioVolume (uint16_t left, uint16_t right) const;
|
---|
138 | void SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const;
|
---|
139 |
|
---|
140 | void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
|
---|
141 |
|
---|
142 | private:
|
---|
143 | /* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
|
---|
144 | * is actually just a part of the Console.
|
---|
145 | */
|
---|
146 | Console *mConsole;
|
---|
147 |
|
---|
148 | #ifdef VBOX_WITH_VRDP
|
---|
149 | HVRDESERVER mhServer;
|
---|
150 |
|
---|
151 | static bool loadVRDPLibrary (void);
|
---|
152 |
|
---|
153 | /** Static because will never load this more than once! */
|
---|
154 | static RTLDRMOD mVRDPLibrary;
|
---|
155 |
|
---|
156 | static PFNVRDECREATESERVER mpfnVRDPCreateServer;
|
---|
157 |
|
---|
158 | static VRDEENTRYPOINTS_1 *mpEntryPoints;
|
---|
159 | static VRDECALLBACKS_1 mCallbacks;
|
---|
160 |
|
---|
161 | static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
|
---|
162 | static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
|
---|
163 | static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
|
---|
164 | static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
|
---|
165 | static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
|
---|
166 | static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
|
---|
167 | static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
|
---|
168 | static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDEFRAMEBUFFERINFO *pInfo);
|
---|
169 | static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
|
---|
170 | static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
|
---|
171 | static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
|
---|
172 | static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
|
---|
173 |
|
---|
174 | bool m_fGuestWantsAbsolute;
|
---|
175 | int m_mousex;
|
---|
176 | int m_mousey;
|
---|
177 |
|
---|
178 | IFramebuffer *maFramebuffers[SchemaDefs::MaxGuestMonitors];
|
---|
179 |
|
---|
180 | IEventListener *mConsoleListener;
|
---|
181 |
|
---|
182 | VRDPInputSynch m_InputSynch;
|
---|
183 |
|
---|
184 | int32_t mVRDPBindPort;
|
---|
185 | #endif /* VBOX_WITH_VRDP */
|
---|
186 |
|
---|
187 | RTCRITSECT mCritSect;
|
---|
188 |
|
---|
189 | int lockConsoleVRDPServer (void);
|
---|
190 | void unlockConsoleVRDPServer (void);
|
---|
191 |
|
---|
192 | int mcClipboardRefs;
|
---|
193 | HGCMSVCEXTHANDLE mhClipboard;
|
---|
194 | PFNVRDPCLIPBOARDEXTCALLBACK mpfnClipboardCallback;
|
---|
195 |
|
---|
196 | static DECLCALLBACK(int) ClipboardCallback (void *pvCallback, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
|
---|
197 | static DECLCALLBACK(int) ClipboardServiceExtension (void *pvExtension, uint32_t u32Function, void *pvParm, uint32_t cbParms);
|
---|
198 |
|
---|
199 | #ifdef VBOX_WITH_USB
|
---|
200 | RemoteUSBBackend *usbBackendFindByUUID (const Guid *pGuid);
|
---|
201 | RemoteUSBBackend *usbBackendFind (uint32_t u32ClientId);
|
---|
202 |
|
---|
203 | typedef struct _USBBackends
|
---|
204 | {
|
---|
205 | RemoteUSBBackend *pHead;
|
---|
206 | RemoteUSBBackend *pTail;
|
---|
207 |
|
---|
208 | RTTHREAD thread;
|
---|
209 |
|
---|
210 | bool fThreadRunning;
|
---|
211 |
|
---|
212 | RTSEMEVENT event;
|
---|
213 | } USBBackends;
|
---|
214 |
|
---|
215 | USBBackends mUSBBackends;
|
---|
216 |
|
---|
217 | void remoteUSBThreadStart (void);
|
---|
218 | void remoteUSBThreadStop (void);
|
---|
219 | #endif /* VBOX_WITH_USB */
|
---|
220 |
|
---|
221 | /* External authentication library handle. The library is loaded in the
|
---|
222 | * Authenticate method and unloaded at the object destructor.
|
---|
223 | */
|
---|
224 | RTLDRMOD mAuthLibrary;
|
---|
225 | PVRDPAUTHENTRY mpfnAuthEntry;
|
---|
226 | PVRDPAUTHENTRY2 mpfnAuthEntry2;
|
---|
227 | };
|
---|
228 |
|
---|
229 |
|
---|
230 | class Console;
|
---|
231 |
|
---|
232 | class ATL_NO_VTABLE RemoteDisplayInfo :
|
---|
233 | public VirtualBoxBase,
|
---|
234 | VBOX_SCRIPTABLE_IMPL(IRemoteDisplayInfo)
|
---|
235 | {
|
---|
236 | public:
|
---|
237 |
|
---|
238 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(RemoteDisplayInfo, IRemoteDisplayInfo)
|
---|
239 |
|
---|
240 | DECLARE_NOT_AGGREGATABLE(RemoteDisplayInfo)
|
---|
241 |
|
---|
242 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
243 |
|
---|
244 | BEGIN_COM_MAP(RemoteDisplayInfo)
|
---|
245 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
246 | COM_INTERFACE_ENTRY(IRemoteDisplayInfo)
|
---|
247 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
248 | END_COM_MAP()
|
---|
249 |
|
---|
250 | DECLARE_EMPTY_CTOR_DTOR (RemoteDisplayInfo)
|
---|
251 |
|
---|
252 | HRESULT FinalConstruct();
|
---|
253 | void FinalRelease();
|
---|
254 |
|
---|
255 | /* Public initializer/uninitializer for internal purposes only. */
|
---|
256 | HRESULT init (Console *aParent);
|
---|
257 | void uninit();
|
---|
258 |
|
---|
259 | /* IRemoteDisplayInfo properties */
|
---|
260 | #define DECL_GETTER(_aType, _aName) STDMETHOD(COMGETTER(_aName)) (_aType *a##_aName)
|
---|
261 | DECL_GETTER (BOOL, Active);
|
---|
262 | DECL_GETTER (LONG, Port);
|
---|
263 | DECL_GETTER (ULONG, NumberOfClients);
|
---|
264 | DECL_GETTER (LONG64, BeginTime);
|
---|
265 | DECL_GETTER (LONG64, EndTime);
|
---|
266 | DECL_GETTER (LONG64, BytesSent);
|
---|
267 | DECL_GETTER (LONG64, BytesSentTotal);
|
---|
268 | DECL_GETTER (LONG64, BytesReceived);
|
---|
269 | DECL_GETTER (LONG64, BytesReceivedTotal);
|
---|
270 | DECL_GETTER (BSTR, User);
|
---|
271 | DECL_GETTER (BSTR, Domain);
|
---|
272 | DECL_GETTER (BSTR, ClientName);
|
---|
273 | DECL_GETTER (BSTR, ClientIP);
|
---|
274 | DECL_GETTER (ULONG, ClientVersion);
|
---|
275 | DECL_GETTER (ULONG, EncryptionStyle);
|
---|
276 | #undef DECL_GETTER
|
---|
277 |
|
---|
278 | private:
|
---|
279 |
|
---|
280 | Console * const mParent;
|
---|
281 | };
|
---|
282 |
|
---|
283 | #endif // ____H_CONSOLEVRDPSERVER
|
---|
284 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|