ConsoleVRDPServer.h revision f6adf1a86574758258baa232172c965aed0d848d
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* $Id$ */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/** @file
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VBox Console VRDP Helper class and implementation of IRemoteDisplayInfo
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/*
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (C) 2006-2008 Sun Microsystems, Inc.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * available from http://www.virtualbox.org. This file is free software;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * General Public License (GPL) as published by the Free Software
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * additional information or have any questions.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef ____H_CONSOLEVRDPSERVER
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#define ____H_CONSOLEVRDPSERVER
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include "RemoteUSBBackend.h"
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <hgcm/HGCM.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include <VBox/VRDPAuth.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include <VBox/HostServices/VBoxClipboardExt.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include "SchemaDefs.h"
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync// ConsoleVRDPServer
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync///////////////////////////////////////////////////////////////////////////////
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#ifdef VBOX_WITH_VRDP
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsynctypedef struct _VRDPInputSynch
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync int cGuestNumLockAdaptions;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync int cGuestCapsLockAdaptions;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fGuestNumLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fGuestCapsLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fGuestScrollLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fClientNumLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fClientCapsLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fClientScrollLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync} VRDPInputSynch;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#endif /* VBOX_WITH_VRDP */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* Member of Console. Helper class for VRDP server management. Not a COM class. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncclass ConsoleVRDPServer
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncpublic:
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync ConsoleVRDPServer (Console *console);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync ~ConsoleVRDPServer ();
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync int Launch (void);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void NotifyAbsoluteMouse (bool fGuestWantsAbsolute)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#ifdef VBOX_WITH_VRDP
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m_fGuestWantsAbsolute = fGuestWantsAbsolute;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#else
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync NOREF(fGuestWantsAbsolute);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#endif /* VBOX_WITH_VRDP */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void NotifyKeyboardLedsChange (BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#ifdef VBOX_WITH_VRDP
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fGuestNumLock = (fNumLock != FALSE);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fGuestCapsLock = (fCapsLock != FALSE);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fGuestScrollLock = (fScrollLock != FALSE);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Might need to resynch in case the guest itself changed the LED status. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (m_InputSynch.fClientNumLock != fGuestNumLock)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m_InputSynch.cGuestNumLockAdaptions = 2;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (m_InputSynch.fClientCapsLock != fGuestCapsLock)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m_InputSynch.cGuestCapsLockAdaptions = 2;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m_InputSynch.fGuestNumLock = fGuestNumLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m_InputSynch.fGuestCapsLock = fGuestCapsLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync m_InputSynch.fGuestScrollLock = fGuestScrollLock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#else
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync NOREF(fNumLock);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync NOREF(fCapsLock);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync NOREF(fScrollLock);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#endif /* VBOX_WITH_VRDP */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void EnableConnections (void);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void DisconnectClient (uint32_t u32ClientId, bool fReconnect);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void MousePointerUpdate (const VRDPCOLORPOINTER *pPointer);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void MousePointerHide (void);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void Stop (void);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync VRDPAuthResult Authenticate (const Guid &uuid, VRDPAuthGuestJudgement guestJudgement,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync const char *pszUser, const char *pszPassword, const char *pszDomain,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync uint32_t u32ClientId);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void AuthDisconnect (const Guid &uuid, uint32_t u32ClientId);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void USBBackendCreate (uint32_t u32ClientId, void **ppvIntercept);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void USBBackendDelete (uint32_t u32ClientId);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void *USBBackendRequestPointer (uint32_t u32ClientId, const Guid *pGuid);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void USBBackendReleasePointer (const Guid *pGuid);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Private interface for the RemoteUSBBackend destructor. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void usbBackendRemoveFromList (RemoteUSBBackend *pRemoteUSBBackend);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Private methods for the Remote USB thread. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RemoteUSBBackend *usbBackendGetNext (RemoteUSBBackend *pRemoteUSBBackend);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void notifyRemoteUSBThreadRunning (RTTHREAD thread);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool isRemoteUSBThreadRunning (void);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void waitRemoteUSBThreadEvent (unsigned cMillies);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void ClipboardCreate (uint32_t u32ClientId);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void ClipboardDelete (uint32_t u32ClientId);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /*
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Forwarders to VRDP server library.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void SendUpdate (unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void SendResize (void) const;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void SendUpdateBitmap (unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format) const;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void SendAudioVolume (uint16_t left, uint16_t right) const;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const;
void QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const;
private:
/* Note: This is not a ComObjPtr here, because the ConsoleVRDPServer object
* is actually just a part of the Console.
*/
Console *mConsole;
#ifdef VBOX_WITH_VRDP
HVRDPSERVER mhServer;
static bool loadVRDPLibrary (void);
/** Static because will never load this more than once! */
static RTLDRMOD mVRDPLibrary;
static PFNVRDPCREATESERVER mpfnVRDPCreateServer;
static VRDPENTRYPOINTS_1 *mpEntryPoints;
static VRDPCALLBACKS_1 mCallbacks;
static DECLCALLBACK(int) VRDPCallbackQueryProperty (void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
static DECLCALLBACK(int) VRDPCallbackClientLogon (void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
static DECLCALLBACK(void) VRDPCallbackClientConnect (void *pvCallback, uint32_t u32ClientId);
static DECLCALLBACK(void) VRDPCallbackClientDisconnect (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted);
static DECLCALLBACK(int) VRDPCallbackIntercept (void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept);
static DECLCALLBACK(int) VRDPCallbackUSB (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet);
static DECLCALLBACK(int) VRDPCallbackClipboard (void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
static DECLCALLBACK(bool) VRDPCallbackFramebufferQuery (void *pvCallback, unsigned uScreenId, VRDPFRAMEBUFFERINFO *pInfo);
static DECLCALLBACK(void) VRDPCallbackFramebufferLock (void *pvCallback, unsigned uScreenId);
static DECLCALLBACK(void) VRDPCallbackFramebufferUnlock (void *pvCallback, unsigned uScreenId);
static DECLCALLBACK(void) VRDPCallbackInput (void *pvCallback, int type, const void *pvInput, unsigned cbInput);
static DECLCALLBACK(void) VRDPCallbackVideoModeHint (void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId);
bool m_fGuestWantsAbsolute;
int m_mousex;
int m_mousey;
IFramebuffer *maFramebuffers[SchemaDefs::MaxGuestMonitors];
IConsoleCallback *mConsoleCallback;
VRDPInputSynch m_InputSynch;
#endif /* VBOX_WITH_VRDP */
RTCRITSECT mCritSect;
int lockConsoleVRDPServer (void);
void unlockConsoleVRDPServer (void);
int mcClipboardRefs;
HGCMSVCEXTHANDLE mhClipboard;
PFNVRDPCLIPBOARDEXTCALLBACK mpfnClipboardCallback;
static DECLCALLBACK(int) ClipboardCallback (void *pvCallback, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData);
static DECLCALLBACK(int) ClipboardServiceExtension (void *pvExtension, uint32_t u32Function, void *pvParm, uint32_t cbParms);
#ifdef VBOX_WITH_USB
RemoteUSBBackend *usbBackendFindByUUID (const Guid *pGuid);
RemoteUSBBackend *usbBackendFind (uint32_t u32ClientId);
typedef struct _USBBackends
{
RemoteUSBBackend *pHead;
RemoteUSBBackend *pTail;
RTTHREAD thread;
bool fThreadRunning;
RTSEMEVENT event;
} USBBackends;
USBBackends mUSBBackends;
void remoteUSBThreadStart (void);
void remoteUSBThreadStop (void);
#endif /* VBOX_WITH_USB */
/* External authentication library handle. The library is loaded in the
* Authenticate method and unloaded at the object destructor.
*/
RTLDRMOD mAuthLibrary;
PVRDPAUTHENTRY mpfnAuthEntry;
PVRDPAUTHENTRY2 mpfnAuthEntry2;
};
class Console;
class ATL_NO_VTABLE RemoteDisplayInfo :
public VirtualBoxBaseNEXT,
public VirtualBoxSupportErrorInfoImpl <RemoteDisplayInfo, IRemoteDisplayInfo>,
public VirtualBoxSupportTranslation <RemoteDisplayInfo>,
public IRemoteDisplayInfo
{
public:
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (RemoteDisplayInfo)
DECLARE_NOT_AGGREGATABLE(RemoteDisplayInfo)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(RemoteDisplayInfo)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(IRemoteDisplayInfo)
END_COM_MAP()
NS_DECL_ISUPPORTS
DECLARE_EMPTY_CTOR_DTOR (RemoteDisplayInfo)
HRESULT FinalConstruct();
void FinalRelease();
/* Public initializer/uninitializer for internal purposes only. */
HRESULT init (Console *aParent);
void uninit();
/* IRemoteDisplayInfo properties */
#define DECL_GETTER(_aType, _aName) STDMETHOD(COMGETTER(_aName)) (_aType *a##_aName)
DECL_GETTER (BOOL, Active);
DECL_GETTER (ULONG, NumberOfClients);
DECL_GETTER (LONG64, BeginTime);
DECL_GETTER (LONG64, EndTime);
DECL_GETTER (ULONG64, BytesSent);
DECL_GETTER (ULONG64, BytesSentTotal);
DECL_GETTER (ULONG64, BytesReceived);
DECL_GETTER (ULONG64, BytesReceivedTotal);
DECL_GETTER (BSTR, User);
DECL_GETTER (BSTR, Domain);
DECL_GETTER (BSTR, ClientName);
DECL_GETTER (BSTR, ClientIP);
DECL_GETTER (ULONG, ClientVersion);
DECL_GETTER (ULONG, EncryptionStyle);
#undef DECL_GETTER
/* For VirtualBoxSupportErrorInfoImpl. */
static const wchar_t *getComponentName() { return L"RemoteDisplayInfo"; }
private:
const ComObjPtr <Console, ComWeakRef> mParent;
};
#endif // ____H_CONSOLEVRDPSERVER
/* vi: set tabstop=4 shiftwidth=4 expandtab: */