ConsoleVRDPServer.cpp revision 7258e84ec2fa7ecaf94e1a244bd6d2cf6b3a40a4
/** @file
*
* VBox Console VRDP Helper class
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#include "ConsoleVRDPServer.h"
#include "ConsoleImpl.h"
#include "DisplayImpl.h"
#include "Logging.h"
// ConsoleVRDPServer
////////////////////////////////////////////////////////////////////////////////
#ifdef VBOX_VRDP
int (VBOXCALL *ConsoleVRDPServer::mpfnVRDPStartServer) (IConsole *pConsole, IVRDPServer *pVRDPServer, HVRDPSERVER *phServer);
int (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSetFramebuffer) (HVRDPSERVER hServer, IFramebuffer *pFramebuffer, uint32_t fFlags);
void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSetCallback) (HVRDPSERVER hServer, VRDPSERVERCALLBACK *pcallback, void *pvUser);
void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendUpdateBitmap)(HVRDPSERVER hServer, unsigned x, unsigned y, unsigned w, unsigned h);
void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendAudioSamples)(HVRDPSERVER hserver, void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format);
void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendAudioVolume) (HVRDPSERVER hserver, uint16_t left, uint16_t right);
#ifdef VRDP_MC
void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendUSBRequest) (HVRDPSERVER hserver, uint32_t u32ClientId, void *pvParms, uint32_t cbParms);
#else
void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendUSBRequest) (HVRDPSERVER hserver, void *pvParms, uint32_t cbParms);
#endif /* VRDP_MC */
void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPSendUpdate) (HVRDPSERVER hServer, void *pvUpdate, uint32_t cbUpdate);
void (VBOXCALL *ConsoleVRDPServer::mpfnVRDPQueryInfo) (HVRDPSERVER hserver, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut);
#endif
{
#ifdef VRDP_MC
#ifdef VBOX_WITH_USB
mUSBBackends.fThreadRunning = false;
mUSBBackends.event = 0;
#endif
#else
#ifdef VBOX_WITH_USB
#endif
#endif /* VRDP_MC */
#ifdef VBOX_VRDP
mhServer = 0;
#endif
mAuthLibrary = 0;
}
{
#ifdef VRDP_MC
Stop ();
if (RTCritSectIsInitialized (&mCritSect))
{
}
#else
#ifdef VBOX_VRDP
Stop ();
/* No unloading of anything because we might still have live object around. */
#endif
#endif /* VRDP_MC */
}
int ConsoleVRDPServer::Launch (void)
{
LogFlowMember(("ConsoleVRDPServer::Launch\n"));
#ifdef VBOX_VRDP
int rc = VINF_SUCCESS;
&& vrdpEnabled
&& loadVRDPLibrary ())
{
if (VBOX_SUCCESS(rc))
{
#ifdef VBOX_WITH_USB
#ifdef VRDP_MC
#endif /* VRDP_MC */
#endif /* VBOX_WITH_USB */
}
else
}
#else
int rc = VERR_NOT_SUPPORTED;
#endif
return rc;
}
void ConsoleVRDPServer::SetCallback (void)
{
#ifdef VBOX_VRDP
/* This is called after VM is created and allows the server to accept client connection. */
if (mhServer && mpfnVRDPSetCallback)
{
}
#endif
}
void ConsoleVRDPServer::Stop (void)
{
Assert(VALID_PTR(this)); /** @todo r=bird: there are(/was) some odd cases where this buster was invalid on
* linux. Just remove this when it's 100% sure that problem has been fixed. */
#ifdef VBOX_VRDP
if (mhServer)
{
/* Reset the handle to avoid further calls to the server. */
mhServer = 0;
}
#endif
#ifdef VBOX_WITH_USB
#ifdef VRDP_MC
#else
/* Delete the USB backend object if it was not deleted properly. */
if (mRemoteUSBBackend)
{
Log(("ConsoleVRDPServer::Stop: deleting USB backend\n"));
delete mRemoteUSBBackend;
}
#endif /* VRDP_MC */
#endif /* VBOX_WITH_USB */
if (mAuthLibrary)
{
mAuthLibrary = 0;
}
}
#ifdef VRDP_MC
/* Worker thread for Remote USB. The thread polls the clients for
* the list of attached USB devices.
*
*
* The thread is always running when the VRDP server is active.
*
* The thread scans backends and requests the device list every 2 seconds.
*
* When device list is available, the thread calls the Console to process it.
*
*/
#define VRDP_DEVICE_LIST_PERIOD_MS (2000)
#ifdef VBOX_WITH_USB
{
while (pOwner->isRemoteUSBThreadRunning ())
{
{
}
}
return VINF_SUCCESS;
}
{
#ifdef VBOX_WITH_USB
mUSBBackends.fThreadRunning = true;
#endif
}
bool ConsoleVRDPServer::isRemoteUSBThreadRunning (void)
{
return mUSBBackends.fThreadRunning;
}
{
}
void ConsoleVRDPServer::remoteUSBThreadStart (void)
{
if (VBOX_FAILURE (rc))
{
AssertFailed ();
mUSBBackends.event = 0;
}
if (VBOX_SUCCESS (rc))
{
}
if (VBOX_FAILURE (rc))
{
}
else
{
/* Wait until the thread is ready. */
}
}
void ConsoleVRDPServer::remoteUSBThreadStop (void)
{
mUSBBackends.fThreadRunning = false;
{
}
if (mUSBBackends.event)
{
mUSBBackends.event = 0;
}
}
#endif /* VBOX_WITH_USB */
#endif /* VRDP_MC */
VRDPAuthResult ConsoleVRDPServer::Authenticate (const Guid &uuid, VRDPAuthGuestJudgement guestJudgement,
{
LogFlow(("ConsoleVRDPServer::Authenticate: uuid = %Vuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s\n",
/*
* Called only from VRDP input thread. So thread safety is not required.
*/
if (!mAuthLibrary)
{
/* Load the external authentication library. */
LogRel(("VRDPAUTH: ConsoleVRDPServer::Authenticate: loading external authentication library '%ls'\n", authLibrary.raw()));
if (VBOX_FAILURE (rc))
if (VBOX_SUCCESS (rc))
{
/* Get the entry point. */
if (VBOX_FAILURE (rc))
}
if (VBOX_FAILURE (rc))
{
if (mAuthLibrary)
{
mAuthLibrary = 0;
}
return VRDPAuthAccessDenied;
}
}
switch (result)
{
case VRDPAuthAccessDenied:
LogRel(("VRDPAUTH: external authentication module returned 'access denied'\n"));
break;
case VRDPAuthAccessGranted:
LogRel(("VRDPAUTH: external authentication module returned 'access granted'\n"));
break;
case VRDPAuthDelegateToGuest:
LogRel(("VRDPAUTH: external authentication module returned 'delegate request to guest'\n"));
break;
default:
}
return result;
}
#ifdef VRDP_MC
int ConsoleVRDPServer::lockConsoleVRDPServer (void)
{
return rc;
}
void ConsoleVRDPServer::unlockConsoleVRDPServer (void)
{
}
/* That is called on INPUT thread of the VRDP server.
* The ConsoleVRDPServer keeps a list of created backend instances.
*/
void ConsoleVRDPServer::USBBackendCreate (uint32_t u32ClientId, PFNVRDPUSBCALLBACK *ppfn, void **ppv)
{
#ifdef VBOX_WITH_USB
/* Create a new instance of the USB backend for the new client. */
if (pRemoteUSBBackend)
{
/* Append the new instance in the list. */
int rc = lockConsoleVRDPServer ();
if (VBOX_SUCCESS (rc))
{
if (mUSBBackends.pHead)
{
}
else
{
}
}
if (VBOX_FAILURE (rc))
{
pRemoteUSBBackend->Release ();
}
}
#endif
}
{
#ifdef VBOX_WITH_USB
/* Find the instance. */
int rc = lockConsoleVRDPServer ();
if (VBOX_SUCCESS (rc))
{
if (pRemoteUSBBackend)
{
/* Notify that it will be deleted. */
}
}
if (pRemoteUSBBackend)
{
/* Here the instance has been excluded from the list and can be dereferenced. */
pRemoteUSBBackend->Release ();
}
#endif
}
{
#ifdef VBOX_WITH_USB
/* Find the instance. */
int rc = lockConsoleVRDPServer ();
if (VBOX_SUCCESS (rc))
{
if (pRemoteUSBBackend)
{
/* Inform the backend instance that it is referenced by the Guid. */
if (fAdded)
{
/* Reference the instance because its pointer is being taken. */
}
else
{
}
}
}
if (pRemoteUSBBackend)
{
return pRemoteUSBBackend->GetBackendCallbackPointer ();
}
#endif
return NULL;
}
{
#ifdef VBOX_WITH_USB
/* Find the instance. */
int rc = lockConsoleVRDPServer ();
if (VBOX_SUCCESS (rc))
{
if (pRemoteUSBBackend)
{
}
if (pRemoteUSBBackend)
{
pRemoteUSBBackend->Release ();
}
}
#endif
}
{
#ifdef VBOX_WITH_USB
int rc = lockConsoleVRDPServer ();
if (VBOX_SUCCESS (rc))
{
if (pRemoteUSBBackend == NULL)
{
/* The first backend in the list is requested. */
}
else
{
/* Get pointer to the next backend. */
}
{
}
if (pRemoteUSBBackend)
{
pRemoteUSBBackend->Release ();
}
}
#endif
return pNextRemoteUSBBackend;
}
#ifdef VBOX_WITH_USB
/* Internal method. Called under the ConsoleVRDPServerLock. */
{
while (pRemoteUSBBackend)
{
{
break;
}
}
return pRemoteUSBBackend;
}
/* Internal method. Called under the ConsoleVRDPServerLock. */
{
while (pRemoteUSBBackend)
{
{
break;
}
}
return pRemoteUSBBackend;
}
#endif
/* Internal method. Called by the backend destructor. */
{
#ifdef VBOX_WITH_USB
int rc = lockConsoleVRDPServer ();
/* Exclude the found instance from the list. */
if (pRemoteUSBBackend->pNext)
{
}
else
{
}
if (pRemoteUSBBackend->pPrev)
{
}
else
{
}
#endif
}
#else // VRDP_MC
{
#ifdef VBOX_WITH_USB
if (mRemoteUSBBackend)
{
if (VBOX_FAILURE (rc))
{
delete mRemoteUSBBackend;
}
}
#endif /* VBOX_WITH_USB */
}
void ConsoleVRDPServer::DeleteUSBBackend (void)
{
#ifdef VBOX_WITH_USB
if (mRemoteUSBBackend)
{
delete mRemoteUSBBackend;
}
#endif /* VBOX_WITH_USB */
}
void *ConsoleVRDPServer::GetUSBBackendPointer (void)
{
#ifdef VBOX_WITH_USB
return mRemoteUSBBackend->GetRemoteBackendCallback ();
#else
return NULL;
#endif
}
#endif /* VRDP_MC */
{
#ifdef VBOX_VRDP
if (mpfnVRDPSendUpdate)
#endif
}
void ConsoleVRDPServer::SendResize (void) const
{
#ifdef VBOX_VRDP
if (mpfnVRDPSendResize)
#endif
}
{
#ifdef VBOX_VRDP
mpfnVRDPSendUpdateBitmap (mhServer, x, y, w, h);
#endif
}
{
#ifdef VBOX_VRDP
#endif
}
void ConsoleVRDPServer::SendAudioSamples (void *pvSamples, uint32_t cSamples, VRDPAUDIOFORMAT format) const
{
#ifdef VBOX_VRDP
#endif
}
{
#ifdef VBOX_VRDP
#endif
}
#ifdef VRDP_MC
void ConsoleVRDPServer::SendUSBRequest (uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const
{
#ifdef VBOX_VRDP
#endif
}
#else
{
#ifdef VBOX_VRDP
#endif
}
#endif /* VRDP_MC */
void ConsoleVRDPServer::QueryInfo (uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const
{
#ifdef VBOX_VRDP
if (mpfnVRDPQueryInfo)
#endif
}
#ifdef VBOX_VRDP
/* note: static function now! */
bool ConsoleVRDPServer::loadVRDPLibrary (void)
{
int rc = VINF_SUCCESS;
if (!mVRDPLibrary)
{
if (VBOX_SUCCESS(rc))
{
LogFlow(("VRDPServer::loadLibrary(): successfully loaded VRDP library.\n"));
struct SymbolEntry
{
const char *name;
void **ppfn;
};
#define DEFSYMENTRY(a) { #a, (void**)&mpfn##a }
static const struct SymbolEntry symbols[] =
{
};
{
if (VBOX_FAILURE(rc))
{
break;
}
}
}
else
{
LogFlow(("VRDPServer::loadLibrary(): failed to load VRDP library! VRDP not available.\n"));
mVRDPLibrary = NULL;
}
}
// just to be safe
if (VBOX_FAILURE(rc))
{
if (mVRDPLibrary)
{
mVRDPLibrary = NULL;
}
}
return (mVRDPLibrary != NULL);
}
#endif /* VBOX_VRDP */
/*
* IRemoteDisplayInfo implementation.
*/
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void RemoteDisplayInfo::FinalRelease()
{
if (isReady())
uninit ();
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the guest object.
*/
{
setReady (true);
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void RemoteDisplayInfo::uninit()
{
LogFlowMember (("RemoteDisplayInfo::uninit()\n"));
AssertReturn (isReady(), (void) 0);
setReady (false);
}
// IRemoteDisplayInfo properties
/////////////////////////////////////////////////////////////////////////////
{ \
if (!a##_aName) \
return E_POINTER; \
\
CHECK_READY(); \
\
\
\
\
return S_OK; \
}
{ \
if (!a##_aName) \
return E_POINTER; \
\
CHECK_READY(); \
\
\
\
\
return S_OK; \
}
{ \
if (!a##_aName) \
return E_POINTER; \
\
CHECK_READY(); \
\
\
\
if (cbOut == 0) \
{ \
return S_OK; \
} \
\
\
if (!pchBuffer) \
{ \
Log(("RemoteDisplayInfo::" \
#_aName \
": Failed to allocate memory %d bytes\n", cbOut)); \
return E_OUTOFMEMORY; \
} \
\
\
\
\
RTMemTmpFree (pchBuffer); \
\
return S_OK; \
}