x11.cpp revision 3f279f58d7fa1cfb1ef999f80968cf3aefc0680c
/** @file
*
* Shared Clipboard:
* Linux host.
*/
/*
* Copyright (C) 2006-2007 innotek 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 (GPL) 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.
*/
#define USE_UTF16
#define USE_UTF8
#define USE_CTEXT
#include <vector>
#include <iprt/semaphore.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include "VBoxClipboard.h"
#include "clipboard-helper.h"
#include <X11/Intrinsic.h>
/** The different clipboard formats which we support. */
enum g_eClipboardFormats
{
INVALID = 0,
UTF8,
};
/** The X11 clipboard uses several names for the same format. This structure maps an X11
name to a format. */
typedef struct {
unsigned guestFormat;
/** Does the host or the guest currently own the clipboard? */
typedef struct {
/** BMP file type marker - must always contain 'BM' */
/** The size of the BMP file in bytes (the MS docs say that this is not reliable) */
/** Reserved, must always be zero */
/** Reserved, must always be zero */
/** Offset from the beginning of this header to the actual image bits */
/** Global clipboard context information */
struct _VBOXCLIPBOARDCONTEXT
{
/** The X Toolkit application context structure */
/** We have a separate thread to wait for Window and Clipboard events */
/** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
/** X11 atom refering to the clipboard: CLIPBOARD */
/** X11 atom refering to the clipboard targets: TARGETS */
/** X11 atom refering to the clipboard multiple target: MULTIPLE */
/** X11 atom refering to the clipboard timestamp target: TIMESTAMP */
/** X11 atom refering to the clipboard utf8 text format: UTF8_STRING */
/** X11 atom refering to the clipboard compound text format: COMPOUND_TEXT */
/** A list of the X11 formats which we support, mapped to our identifier for them, in the
order we prefer to have them in. */
/** Does the host or the guest currently own the clipboard? */
volatile enum g_eClipboardOwner eOwner;
/** What is the best text format the host has to offer? INVALID for none. */
/** Atom corresponding to the host text format */
/** What is the best bitmap format the host has to offer? INVALID for none. */
/** Atom corresponding to the host Bitmap format */
/** What formats does the guest have on offer? */
int guestFormats;
/** Windows caches the clipboard data it receives. Since we have no way of knowing whether
that data is still valid, we always send a "data changed" message after a successful
transfer to invalidate the cache. */
bool notifyGuest;
/** Since the clipboard data moves asynchronously, we use an event semaphore to wait for
it. When a function issues a request for clipboard data it must wait for this
semaphore, which is triggered when the data arrives. */
/** And because it would not do for the guest to be waiting for the host while the host
is waiting for the guest, we set a flag and assert horribly if we spot a deadlock. */
/** This mutex is held while an asynchronous operation completes (i.e. the host clipboard is
being queried) to make sure that the clipboard is not disconnected during that time. It
is also grabbed when the clipboard client disconnects. When an asynchronous operation
starts completing, it checks that the same client is still connected immediately after
grabbing the mutex. */
/** Format which we are reading from the host clipboard (valid during a request for the
host clipboard) */
/** The guest buffer to write host clipboard data to (valid during a request for the host
clipboard) */
void *requestBuffer;
/** The size of the guest buffer to write host clipboard data to (valid during a request for
the host clipboard) */
unsigned requestBufferSize;
/** The size of the host clipboard data written to the guest buffer (valid during a request
for the host clipboard) */
/** Pointer to the client data structure */
};
/* Only one client is supported. There seems to be no need for more clients. */
static VBOXCLIPBOARDCONTEXT g_ctx;
/**
* Send a request to the guest to transfer the contents of its clipboard to the host.
*
* @param pCtx Pointer to the host clipboard structure
* @param u32Format The format in which the data should be transfered
*/
{
if (pClient == 0)
{
Log(("vboxClipboardReadDataFromClient: host requested guest clipboard data after guest had disconnected.\n"));
pCtx->guestFormats = 0;
return VERR_TIMEOUT;
}
{
LogRel(("vboxClipboardReadDataFromClient: a guest to host clipboard transfer has been requested, but another is in progress, or has not cleaned up properly.\n"));
AssertMsgFailed(("A guest to host clipboard transfer has been requested, but another is in progress, or has not cleaned up properly.\n"));
}
/* Only one of the guest and the host should be waiting at any one time */
{
LogRel(("vboxClipboardReadDataFromClient: deadlock situation - the host and the guest are both waiting for data from the other."));
return VERR_DEADLOCK;
}
/* Request data from the guest */
/* Which will signal us when it is ready. */
{
LogRel (("vboxClipboardReadDataFromClient: vboxSvcClipboardReportMsg failed to complete within %d milliseconds\n", CLIPBOARDTIMEOUT));
pCtx->guestFormats = 0;
return VERR_TIMEOUT;
}
LogFlowFunc(("wait completed. Returning.\n"));
return VINF_SUCCESS;
}
/**
* Convert the UTF-16 text returned from the X11 clipboard to UTF-16LE with Windows EOLs
* and place it in the global g_pcClipboardText variable. We are reading the host clipboard to
* make it available to the guest.
*
* @param pValue Source UTF-16 text
* @param cwSourceLen Length in 16-bit words of the source text
* @param pv Where to store the converted data
* @param cb Length in bytes of the buffer pointed to by cb
* @param pcbActual Where to store the size of the converted data
* @param pClient Pointer to the client context structure
*/
{
int rc;
LogFlowFunc (("converting Utf-16 to Utf-16LE. cwSrcLen=%d, cb=%d, pu16SrcText+1=%.*ls\n",
/* How long will the converted text be? */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardGetUtf16: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Vrc. Abandoning.\n", rc));
LogFlowFunc (("guest buffer too small: size %d bytes, needed %d. Returning.\n",
}
{
/* Report the amount of buffer space needed for the transfer */
LogFlowFunc (("guest buffer too small: size %d bytes, needed %d. Returning.\n",
return;
}
/* Convert the text. */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardGetUtf16: clipboard conversion failed. vboxClipboardUtf16LinToWin returned %Vrc. Abandoning.\n", rc));
*pcbActual = 0;
return;
}
}
/**
* Convert the UTF-8 text returned from the X11 clipboard to UTF-16LE with Windows EOLS.
* We are reading the host clipboard to make it available to the guest.
*
* @param pValue Source UTF-8 text
* @param cbSourceLen Length in 8-bit bytes of the source text
* @param pv Where to store the converted data
* @param cb Length in bytes of the buffer pointed to by pv
* @param pcbActual Where to store the size of the converted data
* @param pClient Pointer to the client context structure
*/
{
char *pu8SrcText = reinterpret_cast<char *>(pValue);
int rc;
LogFlowFunc (("converting Utf-8 to Utf-16LE. cbSrcLen=%d, cb=%d, pu8SrcText=%.*s\n",
/* First convert the UTF8 to UTF16 */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardGetUtf8: clipboard conversion failed. RTStrToUtf16Ex returned %Vrc. Abandoning.\n", rc));
*pcbActual = 0;
return;
}
/* Check how much longer will the converted text will be. */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardGetUtf8: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Vrc. Abandoning.\n", rc));
LogFlowFunc (("guest buffer too small: size %d bytes, needed %d. Returning.\n",
}
{
/* Report the amount of buffer space needed for the transfer */
LogFlowFunc (("guest buffer too small: size %d bytes, needed %d. Returning.\n",
return;
}
/* Convert the text. */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardGetUtf8: clipboard conversion failed. vboxClipboardUtf16LinToWin returned %Vrc. Abandoning.\n", rc));
*pcbActual = 0;
return;
}
}
/**
* Convert the COMPOUND_TEXT text returned from the X11 clipboard to UTF-16LE with Windows
* EOLS. We are reading the host clipboard to make it available to the guest.
*
* @param pValue Source COMPOUND_TEXT text
* @param cbSourceLen Length in 8-bit bytes of the source text
* @param pv Where to store the converted data
* @param cb Length in bytes of the buffer pointed to by pv
* @param pcbActual Where to store the size of the converted data
* @param pClient Pointer to the client context structure
*/
{
char **ppu8SrcText;
LogFlowFunc (("converting COMPOUND TEXT to Utf-16LE. cbSrcLen=%d, cb=%d, pu8SrcText=%.*s\n",
/* First convert the compound text to Utf8 */
#ifdef RT_OS_SOLARIS
#else
#endif
if (rc < 0)
{
const char *pcReason;
switch(rc)
{
case XNoMemory:
pcReason = "out of memory";
break;
case XLocaleNotSupported:
pcReason = "locale (Utf8) not supported";
break;
case XConverterNotFound:
pcReason = "converter not found";
break;
default:
pcReason = "unknown error";
}
LogRel(("vboxClipboardGetCText: Xutf8TextPropertyToTextList failed. Reason: %s\n",
pcReason));
*pcbActual = 0;
return;
}
/* Now convert the UTF8 to UTF16 */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardGetCText: clipboard conversion failed. RTStrToUtf16Ex returned %Vrc. Abandoning.\n", rc));
*pcbActual = 0;
return;
}
/* Check how much longer will the converted text will be. */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardGetCText: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Vrc. Abandoning.\n", rc));
LogFlowFunc (("guest buffer too small: size %d bytes, needed %d. Returning.\n",
}
{
/* Report the amount of buffer space needed for the transfer */
LogFlowFunc (("guest buffer too small: size %d bytes, needed %d. Returning.\n",
return;
}
/* Convert the text. */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardGetCText: clipboard conversion failed. vboxClipboardUtf16LinToWin returned %Vrc. Abandoning.\n", rc));
*pcbActual = 0;
return;
}
}
/**
* Convert the Latin1 text returned from the X11 clipboard to UTF-16LE with Windows EOLS
* and place it in the global g_pcClipboardText variable. We are reading the host clipboard to
* make it available to the guest.
*
* @param pValue Source Latin1 text
* @param cbSourceLen Length in 8-bit bytes of the source text
* @param pv Where to store the converted data
* @param cb Length in bytes of the buffer pointed to by cb
* @param pcbActual Where to store the size of the converted data
* @param pClient Pointer to the client context structure
*/
{
char *pu8SourceText = reinterpret_cast<char *>(pValue);
LogFlow (("vboxClipboardGetLatin1: converting Latin1 to Utf-16LE. Original is %.*s\n",
for (unsigned i = 0; i < cbSourceLen; i++)
if (pu8SourceText[i] == LINEFEED)
++cwDestLen;
{
/* Report the amount of buffer space needed for the transfer */
return;
}
for (unsigned i = 0, j = 0; i < cbSourceLen; ++i, ++j)
if (pu8SourceText[i] != LINEFEED)
else
{
pu16DestText[j] = CARRIAGERETURN;
++j;
pu16DestText[j] = LINEFEED;
}
}
/** Convert the clipboard text from the current format to Utf-16 with Windows line breaks.
We are reading the host clipboard to make it available to the guest. */
int *piFormat)
{
LogFlowFunc(("g_ctx.requestHostFormat=%d, g_ctx.requestBufferSize=%d\n",
/* The X Toolkit may have failed to get the clipboard selection for us. */
if (*atomType == XT_CONVERT_FAIL)
return;
/* The clipboard selection may have changed before we could get it. */
return;
/* We grab this mutex whenever an asynchronous clipboard operation completes and while
disconnecting a client from the clipboard to stop these operations colliding. */
{
/* If the client is no longer connected, just return. */
LogFlowFunc(("client is no longer connected, returning\n"));
return;
}
/* In which format did we request the clipboard data? */
switch (g_ctx.requestHostFormat)
{
case UTF16:
break;
case CTEXT:
break;
case UTF8:
{
/* If we are given broken Utf-8, we treat it as Latin1. Is this acceptable? */
char *pu8SourceText = reinterpret_cast<char *>(pValue);
{
break;
}
else
{
break;
}
}
default:
Log (("vboxClipboardGetProc: bad target format\n"));
return;
}
g_ctx.notifyGuest = true;
}
/** Callback to handle a reply to a request for the targets the current clipboard holder can
handle. We are reading the host clipboard to make it available to the guest. */
int *piFormat)
{
Log3 (("vboxClipboardTargetsProc called\n"));
if (*atomType == XT_CONVERT_FAIL)
{
Log (("vboxClipboardTargetsProc: reading clipboard from host, X toolkit failed to convert the selection\n"));
return;
}
/* We grab this mutex whenever an asynchronous clipboard operation completes and while
disconnecting a client from the clipboard to stop these operations colliding. */
{
/* If the client is no longer connected, just return. */
LogFlowFunc(("client is no longer connected, returning\n"));
return;
}
for (unsigned i = 0; i < cAtoms; ++i)
{
{
{
}
break;
}
#ifdef DEBUG
if (szAtomName != 0)
{
}
#endif
}
{
uint32_t u32Formats = 0;
#ifdef DEBUG
if (atomBestTarget != None)
{
Log2 (("vboxClipboardTargetsProc: switching to host text target %s. Available targets are:\n",
szAtomName));
}
else
{
Log2(("vboxClipboardTargetsProc: no supported host text target found. Available targets are:\n"));
}
for (unsigned i = 0; i < cAtoms; ++i)
{
if (szAtomName != 0)
{
}
}
#endif
if (eBestTarget != INVALID)
g_ctx.notifyGuest = false;
}
}
/**
* This callback is called every 200ms to check the contents of the host clipboard.
*/
{
Log3 (("vboxClipboardTimerProc called\n"));
/* Get the current clipboard contents */
{
Log3 (("vboxClipboardTimerProc: requesting the targets that the host clipboard offers\n"));
}
/* Re-arm our timer */
}
/** We store information about the target formats we can handle in a global vector for internal
use. */
unsigned guestFormat)
{
/* Get an atom from the X server for that target format */
}
/**
* The main loop of our clipboard reader.
*/
{
/* Create a window and make it a clipboard viewer. */
int cArgc = 0;
char *pcArgv = 0;
int rc = VINF_SUCCESS;
LogRel (("vboxClipboardThread: starting clipboard thread\n"));
/* Make sure we are thread safe */
/* Set up the Clipbard application context and main window. We call all these functions
directly instead of calling XtOpenApplication() so that we can fail gracefully if we
can't get an X11 display. */
if (pDisplay == 0)
{
LogRel(("vboxClipboardThread: failed to connect to the host clipboard - the window system may not be running.\n"));
return VERR_NOT_SUPPORTED;
}
0, 0);
{
LogRel(("vboxClipboardThread: failed to construct the X11 window for the clipboard manager.\n"));
}
/* Get hold of the atoms which we need */
g_ctx.atomClipboard = XInternAtom(XtDisplay(g_ctx.widget), "CLIPBOARD", false /* only_if_exists */);
/* And build up the vector of supported formats */
/* And build up the vector of supported formats */
#ifdef USE_UTF16
#endif
#ifdef USE_UTF8
#endif
#ifdef USE_CTEXT
#endif
/* Set up a timer to poll the host clipboard */
LogRel (("vboxClipboardThread: clipboard thread terminated successfully with return code %Vrc\n", rc));
return rc;
}
/** Initialise the host side of the shared clipboard - called by the hgcm layer. */
int vboxClipboardInit (void)
{
int rc;
LogRel(("vboxClipboardInit: initializing host clipboard\n"));
RTTHREADFLAGS_WAITABLE, "SHCLIP");
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardInit: failed to create the clipboard thread.\n"));
}
}
/** Terminate the host side of the shared clipboard - called by the hgcm layer. */
void vboxClipboardDestroy (void)
{
LogRel(("vboxClipboardDestroy: shutting down host clipboard\n"));
/* Set the termination flag. */
/* Wake up the event loop */
LogFlowFunc(("returning.\n"));
}
/**
* Enable the shared clipboard - called by the hgcm clipboard subsystem.
*
* @param pClient Structure containing context information about the guest system
* @returns RT status code
*/
{
LogFlow(("vboxClipboardConnect\n"));
/* Only one client is supported for now */
{
LogRel(("vboxClipboardConnect: attempted to connect, but a client appears to be already running.\n"));
}
g_ctx.notifyGuest = true;
return VINF_SUCCESS;
}
/**
* Synchronise the contents of the host clipboard with the guest, called by the HGCM layer
* after a save and restore of the guest.
*/
{
/* On a Linux host, the guest should never synchronise/cache its clipboard contents, as
we have no way of reliably telling when the host clipboard data changes. So instead
of synchronising, we tell the guest to empty its clipboard, and we set the cached
flag so that we report formats to the guest next time we poll for them. */
g_ctx.notifyGuest = true;
return VINF_SUCCESS;
}
/**
* Shut down the shared clipboard subsystem and "disconnect" the guest.
*/
{
LogFlow(("vboxClipboardDisconnect\n"));
}
/**
* Satisfy a request from the host for available clipboard targets.
*
* @returns true if we successfully convert the data to the format requested, false otherwise.
*
* @param atomTypeReturn The type of the data we are returning
* @param pValReturn A pointer to the data we are returning. This should be to memory
* allocated by XtMalloc, which will be freed by the toolkit later
* @param pcLenReturn The length of the data we are returning
* @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
*/
unsigned long *pcLenReturn, int *piFormatReturn)
{
unsigned cTargets = 0;
LogFlow (("vboxClipboardConvertTargets called\n"));
for (unsigned i = 0; i < uListSize; ++i)
{
{
++cTargets;
}
}
#ifdef DEBUG
for (unsigned i = 0; i < cTargets + 3; i++)
{
if (szAtomName != 0)
{
}
else
{
}
}
#endif
*piFormatReturn = 32;
return true;
}
/**
* Reset the contents of the buffer used to pass clipboard data from the guest to the host.
* This must be done after every clipboard transfer.
*/
static void vboxClipboardEmptyGuestBuffer(void)
{
}
/**
* Satisfy a request from the host to convert the clipboard text to Utf16. We return non-zero
* terminated text.
*
* @returns true if we successfully convert the data to the format requested, false otherwise.
*
* @retval atomTypeReturn The type of the data we are returning
* @retval pValReturn A pointer to the data we are returning. This should be to memory
* allocated by XtMalloc, which will be freed by the toolkit later
* @retval pcLenReturn The length of the data we are returning
* @retval piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
*/
unsigned long *pcLenReturn, int *piFormatReturn)
{
int rc;
LogFlowFunc (("called\n"));
{
/* If vboxClipboardReadDataFromClient fails then pClient may be invalid */
return false;
}
/* How long will the converted text be? */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardConvertUtf16: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Vrc. Abandoning.\n", rc));
AssertRCReturn(rc, false);
}
if (cwDestLen == 0)
{
LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));
return false;
}
if (pu16DestText == 0)
{
return false;
}
/* Convert the text. */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardConvertUtf16: clipboard conversion failed. vboxClipboardUtf16WinToLin returned %Vrc. Abandoning.\n", rc));
XtFree(reinterpret_cast<char *>(pu16DestText));
return false;
}
*pcLenReturn = cwDestLen;
*piFormatReturn = 16;
return true;
}
/**
* Satisfy a request from the host to convert the clipboard text to Utf8.
*
* @returns true if we successfully convert the data to the format requested, false otherwise.
*
* @param atomTypeReturn The type of the data we are returning
* @param pValReturn A pointer to the data we are returning. This should be to memory
* allocated by XtMalloc, which will be freed by the toolkit later
* @param pcLenReturn The length of the data we are returning
* @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
*/
unsigned long *pcLenReturn, int *piFormatReturn)
{
char *pu8DestText;
int rc;
LogFlowFunc (("called\n"));
/* Read the clipboard data from the guest. */
{
/* If vboxClipboardReadDataFromClient fails then pClient may be invalid */
return false;
}
/* How long will the converted text be? */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardConvertUtf8: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Vrc. Abandoning.\n", rc));
AssertRCReturn(rc, false);
}
if (cwDestLen == 0)
{
LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));
return false;
}
if (pu16DestText == 0)
{
return false;
}
/* Convert the text. */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardConvertUtf8: clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Vrc. Abandoning.\n", rc));
RTMemFree(reinterpret_cast<void *>(pu16DestText));
return false;
}
/* Allocate enough space, as RTUtf16ToUtf8Ex may fail if the
space is too tightly calculated. */
if (pu8DestText == 0)
{
RTMemFree(reinterpret_cast<void *>(pu16DestText));
return false;
}
/* Convert the Utf16 string to Utf8. */
&cbDestLen);
RTMemFree(reinterpret_cast<void *>(pu16DestText));
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardConvertUtf8: clipboard conversion failed. RTUtf16ToUtf8Ex() returned %Vrc. Abandoning.\n", rc));
return false;
}
*pcLenReturn = cbDestLen;
*piFormatReturn = 8;
return true;
}
/**
* Satisfy a request from the host to convert the clipboard text to COMPOUND_TEXT.
*
* @returns true if we successfully convert the data to the format requested, false otherwise.
*
* @param atomTypeReturn The type of the data we are returning
* @param pValReturn A pointer to the data we are returning. This should be to memory
* allocated by XtMalloc, which will be freed by the toolkit later
* @param pcLenReturn The length of the data we are returning
* @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
*/
unsigned long *pcLenReturn, int *piFormatReturn)
{
char *pu8DestText = 0;
int rc;
LogFlowFunc (("called\n"));
/* Read the clipboard data from the guest. */
{
/* If vboxClipboardReadDataFromClient fails then pClient may be invalid */
return false;
}
/* How long will the converted text be? */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardConvertCText: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Vrc. Abandoning.\n", rc));
AssertRCReturn(rc, false);
}
if (cwDestLen == 0)
{
LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));
return false;
}
if (pu16DestText == 0)
{
return false;
}
/* Convert the text. */
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardConvertCText: clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Vrc. Abandoning.\n", rc));
RTMemFree(reinterpret_cast<void *>(pu16DestText));
return false;
}
/* Convert the Utf16 string to Utf8. */
RTMemFree(reinterpret_cast<void *>(pu16DestText));
if (RT_FAILURE(rc))
{
LogRel(("vboxClipboardConvertCText: clipboard conversion failed. RTUtf16ToUtf8Ex() returned %Vrc. Abandoning.\n", rc));
return false;
}
/* And finally (!) convert the Utf8 text to compound text. */
#ifdef RT_OS_SOLARIS
#else
#endif
if (rc < 0)
{
const char *pcReason;
switch(rc)
{
case XNoMemory:
pcReason = "out of memory";
break;
case XLocaleNotSupported:
pcReason = "locale (Utf8) not supported";
break;
case XConverterNotFound:
pcReason = "converter not found";
break;
default:
pcReason = "unknown error";
}
LogRel(("vboxClipboardConvertCText: Xutf8TextListToTextProperty failed. Reason: %s\n",
pcReason));
return false;
}
return true;
}
/**
* Callback to convert the guests clipboard data for an application on the host. Called by the
* X Toolkit.
* @returns true if we successfully convert the data to the format requested, false otherwise.
*
* @param atomSelection The selection which is being requested. We only handle the clipboard.
* @param atomTarget The format we should convert the data to
* @param atomTypeReturn The type of the data we are returning
* @param pValReturn A pointer to the data we are returning. This should be to memory
* allocated by XtMalloc, which will be freed by the toolkit later
* @param pcLenReturn The length of the data we are returning
* @param piFormatReturn The format (8bit, 16bit, 32bit) of the data we are returning
*/
unsigned long *pcLenReturn, int *piFormatReturn)
{
LogFlowFunc(("\n"));
{
LogFlowFunc(("rc = false\n"));
return false;
}
#ifdef DEBUG
if (szAtomName != 0)
{
}
else
{
}
#endif
{
}
else
{
{
{
break;
}
}
}
switch (eFormat)
{
case TARGETS:
case UTF16:
case UTF8:
case CTEXT:
default:
Log(("vboxClipboardConvertProc: bad format\n"));
return false;
}
}
{
LogFlow (("vboxClipboardLoseProc: called, giving the host clipboard ownership\n"));
g_ctx.notifyGuest = true;
}
/**
* The guest is taking possession of the shared clipboard. Called by the HGCM clipboard
* subsystem.
*
* @param pClient Context data for the guest system
* @param u32Formats Clipboard formats the the guest is offering
*/
{
if (u32Formats == 0)
{
/* This is just an automatism, not a genuine anouncement */
LogFlowFunc(("returning\n"));
return;
}
{
/* We already own the clipboard, so no need to grab it, especially as that can lead
to races due to the asynchronous nature of the X11 clipboard. This event may also
have been sent out by the guest to invalidate the Windows clipboard cache. */
LogFlowFunc(("returning\n"));
return;
}
Log2 (("vboxClipboardFormatAnnounce: giving the guest clipboard ownership\n"));
vboxClipboardLoseProc, 0) != True)
{
Log2 (("vboxClipboardFormatAnnounce: returning clipboard ownership to the host\n"));
/* We set this so that the guest gets notified when we take the clipboard, even if no
guest formats are found which we understand. */
g_ctx.notifyGuest = true;
}
LogFlowFunc(("returning\n"));
}
/**
* Called by the HGCM clipboard subsystem when the guest wants to read the host clipboard.
*
* @param pClient Context information about the guest VM
* @param u32Format The format that the guest would like to receive the data in
* @param pv Where to write the data to
* @param cb The size of the buffer to write the data to
* @param pcbActual Where to write the actual size of the written data
*/
{
/*
* The guest wants to read data in the given format.
*/
{
{
/* No data available. */
*pcbActual = 0;
return VINF_SUCCESS;
}
/* Only one of the host and the guest should ever be waiting. */
{
LogRel(("vboxClipboardReadData: detected a deadlock situation - the host and the guest are waiting for each other.\n"));
return VERR_DEADLOCK;
}
/* Send out a request for the data to the current clipboard owner */
/* When the data arrives, the vboxClipboardGetProc callback will be called. The
callback will signal the event semaphore when it has processed the data for us. */
{
LogRel (("vboxClipboardReadDataFromClient: XtGetSelectionValue failed to complete within %d milliseconds\n", CLIPBOARDTIMEOUT));
return VERR_TIMEOUT;
}
}
else
{
return VERR_NOT_IMPLEMENTED;
}
return VINF_SUCCESS;
}
/**
* Called by the HGCM clipboard subsystem when we have requested data and that data arrives.
*
* @param pClient Context information about the guest VM
* @param pv Buffer to which the data was written
* @param cb The size of the data written
* @param u32Format The format of the data written
*/
void vboxClipboardWriteData (VBOXCLIPBOARDCLIENTDATA *pClient, void *pv, uint32_t cb, uint32_t u32Format)
{
LogFlow(("vboxClipboardWriteData\n"));
/*
* The guest returns data that was requested in the WM_RENDERFORMAT handler.
*/
{
LogRel(("vboxClipboardWriteData: clipboard data has arrived from the guest, but another transfer is in process or has not cleaned up properly.\n"));
AssertMsgFailed(("vboxClipboardWriteData: clipboard data has arrived from the guest, but another transfer is in process or has not cleaned up properly.\n"));
}
if (cb > 0)
{
{
}
}
}