VBoxClientClipboardHostToGuest.cpp revision 2e79616cdb94a9f801a368bc0b31a6a7dc7f20dd
/** $Id$ */
/** @file
* VBoxClient - Shared Clipboard Host -> Guest copying, Darwin.
*/
/*
* Copyright (C) 2007-2013 Oracle Corporation
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <signal.h>
#include <stdlib.h>
#include <iprt/initterm.h>
#include <VBox/VBoxGuestLib.h>
#include "VBoxClientInternal.h"
/**
* Allocate memory for host buffer and receive it.
*
* @param u32ClientId Host connection.
* @param fFormat Buffer data format.
* @param pData Where to store received data.
* @param cbDataSize The size of the received data.
* @param cbMemSize The actual size of memory occupied by *pData.
*
* @returns IPRT status code.
*/
static int vbclClipboardReadHostData(uint32_t u32ClientId, uint32_t fFormat, void **pData, uint32_t *cbDataSize, uint32_t *cbMemSize)
{
int rc;
if (!pDataInternal)
return VERR_NO_MEMORY;
rc = VbglR3ClipboardReadData(u32ClientId, fFormat, pDataInternal, cbMemSizeInternal, &cbDataSizeInternal);
if (rc == VINF_BUFFER_OVERFLOW)
{
/* Reallocate bigger buffer and receive all the data */
if (!pDataInternal)
return VERR_NO_MEMORY;
rc = VbglR3ClipboardReadData(u32ClientId, fFormat, pDataInternal, cbMemSizeInternal, &cbDataSizeInternal);
}
/* Error occurred of zero-sized buffer */
if (RT_FAILURE(rc))
{
return VERR_NO_MEMORY;
}
*pData = pDataInternal;
return rc;
}
/**
* Release memory occupied by host buffer.
*
* @param pData Pointer to memory occupied by host buffer.
* @param cbMemSize The actual size of memory occupied by *pData.
*/
{
}
/**
* Paste buffer into guest clipboard.
*
* @param pPasteboard Guest PasteBoard reference.
* @param pData Data to be pasted.
* @param cbDataSize The size of *pData.
* @param fFormat Buffer data format.
* @param fClear Whether or not clear guest clipboard before insert data.
*
* @returns IPRT status code.
*/
static int vbclClipboardGuestPasteData(PasteboardRef pPasteboard, UInt8 *pData, CFIndex cbDataSize, CFStringRef sFormat, bool fClear)
{
/* Ignoring sunchronization flags here */
if (fClear)
{
}
/* Create a CData object which we could pass to the pasteboard */
{
/* Put the Utf-8 version to the pasteboard */
{
return VERR_GENERAL_FAILURE;
}
}
else
return VERR_NO_MEMORY;
/* Synchronize updated content */
return VINF_SUCCESS;
}
/**
* Paste text data into guest clipboard.
*
* @param pPasteboard Guest PasteBoard reference.
* @param pData Data to be pasted.
* @param cbDataSize Size of *pData.
*/
{
int rc;
char *pszUtf8Buf;
/* Skip zero-sized buffer */
/* If buffer content is Unicode text, then deliver
it in both formats UTF16 (original) and UTF8. */
/* Convert END-OF-LINE */
/* Do actual paste */
if (RT_SUCCESS(rc))
{
/* Paste UTF16 */
rc = vbclClipboardGuestPasteData(pPasteboard, (UInt8 *)pDataInternal, cbActualLen * 2, kUTTypeUTF16PlainText, true);
if (RT_SUCCESS(rc))
{
/* Paste UTF8 */
if (RT_SUCCESS(rc))
{
rc = vbclClipboardGuestPasteData(pPasteboard, (UInt8 *)pszUtf8Buf, strlen(pszUtf8Buf), kUTTypeUTF8PlainText, false);
}
}
}
return rc;
}
/**
* Paste picture data into guest clipboard.
*
* @param pPasteboard Guest PasteBoard reference.
* @param pData Data to be pasted.
* @param cbDataSize The size of *pData.
*
* @returns IPRT status code.
*/
static int vbclClipboardGuestPastePicture(PasteboardRef pPasteboard, void *pData, uint32_t cbDataSize)
{
int rc;
void *pBmp;
/* Skip zero-sized buffer */
return rc;
}
/**
* Read host's clipboard buffer and put its content to guest clipboard.
*
* @param u32ClientId Host connection.
* @param pPasteboard Guest PasteBoard reference.
* @param fFormats List of data formats (bit field) received from host.
*
* @returns IPRT status code.
*/
{
int rc = VERR_INVALID_PARAMETER;
void *pData;
/* Walk across all item(s) formats */
while (fFormatsInternal)
{
{
rc = vbclClipboardReadHostData(u32ClientId, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pData, &cbDataSize, &cbMemSize);
if (RT_SUCCESS(rc))
{
/* Store data in guest buffer */
/* Release occupied resources */
}
}
else if (fFormatsInternal & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
{
rc = vbclClipboardReadHostData(u32ClientId, VBOX_SHARED_CLIPBOARD_FMT_BITMAP, &pData, &cbDataSize, &cbMemSize);
if (RT_SUCCESS(rc))
{
/* Store data in guest buffer */
/* Release occupied resources */
}
}
else if (fFormatsInternal & VBOX_SHARED_CLIPBOARD_FMT_HTML)
{
rc = vbclClipboardReadHostData(u32ClientId, VBOX_SHARED_CLIPBOARD_FMT_HTML, &pData, &cbDataSize, &cbMemSize);
if (RT_SUCCESS(rc))
{
/* Store data in guest buffer */
/* Release occupied resources */
}
}
else
{
break;
}
}
return rc;
}