2013-04-26 16:59:16 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Android Clipboard Redirection
|
|
|
|
*
|
|
|
|
* Copyright 2013 Felix Long
|
2015-06-02 14:05:10 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2013-04-26 16:59:16 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/stream.h>
|
|
|
|
|
|
|
|
#include <freerdp/client/channels.h>
|
|
|
|
#include <freerdp/client/cliprdr.h>
|
|
|
|
|
|
|
|
#include "android_cliprdr.h"
|
|
|
|
#include "android_jni_utils.h"
|
|
|
|
#include "android_jni_callback.h"
|
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
UINT android_cliprdr_send_client_format_list(CliprdrClientContext* cliprdr)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
UINT rc = ERROR_INTERNAL_ERROR;
|
2014-11-12 20:25:12 +03:00
|
|
|
UINT32 index;
|
|
|
|
UINT32 formatId;
|
|
|
|
UINT32 numFormats;
|
|
|
|
UINT32* pFormatIds;
|
|
|
|
const char* formatName;
|
|
|
|
CLIPRDR_FORMAT* formats;
|
|
|
|
CLIPRDR_FORMAT_LIST formatList;
|
2016-08-04 14:25:52 +03:00
|
|
|
|
|
|
|
if (!cliprdr)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
androidContext* afc = (androidContext*) cliprdr->custom;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!afc || !afc->cliprdr)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST));
|
2014-11-12 20:25:12 +03:00
|
|
|
pFormatIds = NULL;
|
|
|
|
numFormats = ClipboardGetFormatIds(afc->clipboard, &pFormatIds);
|
|
|
|
formats = (CLIPRDR_FORMAT*) calloc(numFormats, sizeof(CLIPRDR_FORMAT));
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if (!formats)
|
2016-08-04 14:25:52 +03:00
|
|
|
goto fail;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
for (index = 0; index < numFormats; index++)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
formatId = pFormatIds[index];
|
|
|
|
formatName = ClipboardGetFormatName(afc->clipboard, formatId);
|
|
|
|
formats[index].formatId = formatId;
|
|
|
|
formats[index].formatName = NULL;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if ((formatId > CF_MAX) && formatName)
|
2016-10-04 09:54:42 +03:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
formats[index].formatName = _strdup(formatName);
|
2016-10-04 09:54:42 +03:00
|
|
|
|
|
|
|
if (!formats[index].formatName)
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
formatList.msgFlags = CB_RESPONSE_OK;
|
|
|
|
formatList.numFormats = numFormats;
|
|
|
|
formatList.formats = formats;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!afc->cliprdr->ClientFormatList)
|
|
|
|
goto fail;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
rc = afc->cliprdr->ClientFormatList(afc->cliprdr, &formatList);
|
|
|
|
fail:
|
2014-11-12 20:25:12 +03:00
|
|
|
free(pFormatIds);
|
|
|
|
free(formats);
|
2016-08-04 14:25:52 +03:00
|
|
|
return rc;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_send_client_format_data_request(
|
|
|
|
CliprdrClientContext* cliprdr, UINT32 formatId)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
UINT rc = ERROR_INVALID_PARAMETER;
|
2014-11-12 20:25:12 +03:00
|
|
|
CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest;
|
2016-08-04 14:25:52 +03:00
|
|
|
androidContext* afc;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
afc = (androidContext*) cliprdr->custom;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!afc || !afc->clipboardRequestEvent || !cliprdr->ClientFormatDataRequest)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ZeroMemory(&formatDataRequest, sizeof(CLIPRDR_FORMAT_DATA_REQUEST));
|
2014-11-12 20:25:12 +03:00
|
|
|
formatDataRequest.msgType = CB_FORMAT_DATA_REQUEST;
|
|
|
|
formatDataRequest.msgFlags = 0;
|
|
|
|
formatDataRequest.requestedFormatId = formatId;
|
|
|
|
afc->requestedFormatId = formatId;
|
|
|
|
ResetEvent(afc->clipboardRequestEvent);
|
2016-08-04 14:25:52 +03:00
|
|
|
rc = cliprdr->ClientFormatDataRequest(cliprdr, &formatDataRequest);
|
|
|
|
fail:
|
|
|
|
return rc;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_send_client_capabilities(CliprdrClientContext*
|
|
|
|
cliprdr)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
CLIPRDR_CAPABILITIES capabilities;
|
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr || !cliprdr->ClientCapabilities)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
capabilities.cCapabilitiesSets = 1;
|
|
|
|
capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &
|
|
|
|
(generalCapabilitySet);
|
2014-11-12 20:25:12 +03:00
|
|
|
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
|
|
|
|
generalCapabilitySet.capabilitySetLength = 12;
|
|
|
|
generalCapabilitySet.version = CB_CAPS_VERSION_2;
|
|
|
|
generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES;
|
2016-08-04 14:25:52 +03:00
|
|
|
return cliprdr->ClientCapabilities(cliprdr, &capabilities);
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_monitor_ready(CliprdrClientContext* cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_MONITOR_READY* monitorReady)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
UINT rc;
|
|
|
|
androidContext* afc;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr || !monitorReady)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
afc = (androidContext*) cliprdr->custom;
|
|
|
|
|
|
|
|
if (!afc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if ((rc = android_cliprdr_send_client_capabilities(cliprdr)) != CHANNEL_RC_OK)
|
|
|
|
return rc;
|
2014-11-12 20:25:12 +03:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if ((rc = android_cliprdr_send_client_format_list(cliprdr)) != CHANNEL_RC_OK)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
afc->clipboardSync = TRUE;
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_capabilities(CliprdrClientContext* cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_CAPABILITIES* capabilities)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
UINT32 index;
|
|
|
|
CLIPRDR_CAPABILITY_SET* capabilitySet;
|
2016-08-04 14:25:52 +03:00
|
|
|
androidContext* afc;
|
|
|
|
|
|
|
|
if (!cliprdr || !capabilities)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
afc = (androidContext*) cliprdr->custom;
|
|
|
|
|
|
|
|
if (!afc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
for (index = 0; index < capabilities->cCapabilitiesSets; index++)
|
|
|
|
{
|
|
|
|
capabilitySet = &(capabilities->capabilitySets[index]);
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if ((capabilitySet->capabilitySetType == CB_CAPSTYPE_GENERAL) &&
|
|
|
|
(capabilitySet->capabilitySetLength >= CB_CAPSTYPE_GENERAL_LEN))
|
|
|
|
{
|
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet
|
2016-08-04 14:25:52 +03:00
|
|
|
= (CLIPRDR_GENERAL_CAPABILITY_SET*) capabilitySet;
|
2014-11-12 20:25:12 +03:00
|
|
|
afc->clipboardCapabilities = generalCapabilitySet->generalFlags;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_format_list(CliprdrClientContext* cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_FORMAT_LIST* formatList)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
UINT rc;
|
2014-11-12 20:25:12 +03:00
|
|
|
UINT32 index;
|
|
|
|
CLIPRDR_FORMAT* format;
|
2016-08-04 14:25:52 +03:00
|
|
|
androidContext* afc;
|
|
|
|
|
|
|
|
if (!cliprdr || !formatList)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
afc = (androidContext*) cliprdr->custom;
|
|
|
|
|
|
|
|
if (!afc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if (afc->serverFormats)
|
|
|
|
{
|
|
|
|
for (index = 0; index < afc->numServerFormats; index++)
|
|
|
|
free(afc->serverFormats[index].formatName);
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
free(afc->serverFormats);
|
|
|
|
afc->serverFormats = NULL;
|
|
|
|
afc->numServerFormats = 0;
|
|
|
|
}
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if (formatList->numFormats < 1)
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
afc->numServerFormats = formatList->numFormats;
|
2016-08-04 14:25:52 +03:00
|
|
|
afc->serverFormats = (CLIPRDR_FORMAT*) calloc(afc->numServerFormats,
|
|
|
|
sizeof(CLIPRDR_FORMAT));
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if (!afc->serverFormats)
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
for (index = 0; index < afc->numServerFormats; index++)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
afc->serverFormats[index].formatId = formatList->formats[index].formatId;
|
|
|
|
afc->serverFormats[index].formatName = NULL;
|
|
|
|
|
|
|
|
if (formatList->formats[index].formatName)
|
2016-10-04 09:54:42 +03:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
afc->serverFormats[index].formatName = _strdup(
|
|
|
|
formatList->formats[index].formatName);
|
2016-10-04 09:54:42 +03:00
|
|
|
|
|
|
|
if (!afc->serverFormats[index].formatName)
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
2014-11-12 20:25:12 +03:00
|
|
|
|
|
|
|
for (index = 0; index < afc->numServerFormats; index++)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
format = &(afc->serverFormats[index]);
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if (format->formatId == CF_UNICODETEXT)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
if ((rc = android_cliprdr_send_client_format_data_request(cliprdr,
|
|
|
|
CF_UNICODETEXT)) != CHANNEL_RC_OK)
|
|
|
|
return rc;
|
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (format->formatId == CF_TEXT)
|
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
if ((rc = android_cliprdr_send_client_format_data_request(cliprdr,
|
|
|
|
CF_TEXT)) != CHANNEL_RC_OK)
|
|
|
|
return rc;
|
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
break;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-12 20:25:12 +03:00
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_format_list_response(
|
|
|
|
CliprdrClientContext* cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr || !formatListResponse)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 20:25:12 +03:00
|
|
|
}
|
2014-11-12 19:14:10 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_lock_clipboard_data(CliprdrClientContext*
|
|
|
|
cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
|
2014-11-12 20:25:12 +03:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr || !lockClipboardData)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 20:25:12 +03:00
|
|
|
}
|
2014-11-12 19:14:10 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_unlock_clipboard_data(
|
|
|
|
CliprdrClientContext* cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
|
2014-11-12 20:25:12 +03:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr || !unlockClipboardData)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_format_data_request(CliprdrClientContext*
|
|
|
|
cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
UINT rc;
|
2014-11-12 20:25:12 +03:00
|
|
|
BYTE* data;
|
|
|
|
UINT32 size;
|
|
|
|
UINT32 formatId;
|
|
|
|
CLIPRDR_FORMAT_DATA_RESPONSE response;
|
2016-08-04 14:25:52 +03:00
|
|
|
androidContext* afc;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr || !formatDataRequest || !cliprdr->ClientFormatDataResponse)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
afc = (androidContext*) cliprdr->custom;
|
|
|
|
|
|
|
|
if (!afc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
ZeroMemory(&response, sizeof(CLIPRDR_FORMAT_DATA_RESPONSE));
|
2014-11-12 20:25:12 +03:00
|
|
|
formatId = formatDataRequest->requestedFormatId;
|
|
|
|
data = (BYTE*) ClipboardGetData(afc->clipboard, formatId, &size);
|
|
|
|
response.msgFlags = CB_RESPONSE_OK;
|
|
|
|
response.dataLen = size;
|
|
|
|
response.requestedFormatData = data;
|
|
|
|
|
|
|
|
if (!data)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
response.msgFlags = CB_RESPONSE_FAIL;
|
|
|
|
response.dataLen = 0;
|
|
|
|
response.requestedFormatData = NULL;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
2014-11-12 20:25:12 +03:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
rc = cliprdr->ClientFormatDataResponse(cliprdr, &response);
|
2014-11-12 20:25:12 +03:00
|
|
|
free(data);
|
2016-08-04 14:25:52 +03:00
|
|
|
return rc;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_format_data_response(
|
|
|
|
CliprdrClientContext* cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
BYTE* data;
|
|
|
|
UINT32 size;
|
|
|
|
UINT32 index;
|
|
|
|
UINT32 formatId;
|
|
|
|
CLIPRDR_FORMAT* format = NULL;
|
2016-08-04 14:25:52 +03:00
|
|
|
androidContext* afc;
|
|
|
|
freerdp* instance;
|
|
|
|
|
|
|
|
if (!cliprdr || !formatDataResponse)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
afc = (androidContext*) cliprdr->custom;
|
|
|
|
|
|
|
|
if (!afc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
instance = ((rdpContext*) afc)->instance;
|
|
|
|
|
|
|
|
if (!instance)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2014-11-12 20:25:12 +03:00
|
|
|
|
|
|
|
for (index = 0; index < afc->numServerFormats; index++)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
if (afc->requestedFormatId == afc->serverFormats[index].formatId)
|
|
|
|
format = &(afc->serverFormats[index]);
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if (!format)
|
|
|
|
{
|
|
|
|
SetEvent(afc->clipboardRequestEvent);
|
2015-06-02 14:05:10 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-12 20:25:12 +03:00
|
|
|
}
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if (format->formatName)
|
|
|
|
formatId = ClipboardRegisterFormat(afc->clipboard, format->formatName);
|
|
|
|
else
|
|
|
|
formatId = format->formatId;
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
size = formatDataResponse->dataLen;
|
2016-08-04 14:25:52 +03:00
|
|
|
|
2016-10-06 14:31:25 +03:00
|
|
|
if (!ClipboardSetData(afc->clipboard, formatId,
|
|
|
|
formatDataResponse->requestedFormatData, size))
|
2016-08-04 14:25:52 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-12 20:25:12 +03:00
|
|
|
|
|
|
|
SetEvent(afc->clipboardRequestEvent);
|
|
|
|
|
|
|
|
if ((formatId == CF_TEXT) || (formatId == CF_UNICODETEXT))
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2014-11-12 20:25:12 +03:00
|
|
|
JNIEnv* env;
|
|
|
|
jstring jdata;
|
|
|
|
jboolean attached;
|
|
|
|
formatId = ClipboardRegisterFormat(afc->clipboard, "UTF8_STRING");
|
|
|
|
data = (void*) ClipboardGetData(afc->clipboard, formatId, &size);
|
|
|
|
attached = jni_attach_thread(&env);
|
2018-02-01 11:34:07 +03:00
|
|
|
size = strnlen(data, size);
|
2014-11-12 20:25:12 +03:00
|
|
|
jdata = jniNewStringUTF(env, data, size);
|
2017-01-11 01:17:44 +03:00
|
|
|
freerdp_callback("OnRemoteClipboardChanged", "(JLjava/lang/String;)V", (jlong)instance,
|
2016-08-04 14:25:52 +03:00
|
|
|
jdata);
|
2014-11-12 20:25:12 +03:00
|
|
|
(*env)->DeleteLocalRef(env, jdata);
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
if (attached == JNI_TRUE)
|
|
|
|
jni_detach_thread();
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
2014-11-12 20:25:12 +03:00
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_file_contents_request(
|
|
|
|
CliprdrClientContext* cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr || !fileContentsRequest)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 20:25:12 +03:00
|
|
|
}
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-04 14:25:52 +03:00
|
|
|
static UINT android_cliprdr_server_file_contents_response(
|
|
|
|
CliprdrClientContext* cliprdr,
|
2019-01-23 18:22:29 +03:00
|
|
|
const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
|
2014-11-12 20:25:12 +03:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!cliprdr || !fileContentsResponse)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2015-06-02 14:05:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-11-12 20:25:12 +03:00
|
|
|
}
|
2013-04-26 16:59:16 +04:00
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
BOOL android_cliprdr_init(androidContext* afc, CliprdrClientContext* cliprdr)
|
2014-11-12 20:25:12 +03:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
wClipboard* clipboard;
|
|
|
|
HANDLE hevent;
|
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!afc || !cliprdr)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(hevent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
2016-08-04 14:25:52 +03:00
|
|
|
return FALSE;
|
2015-04-28 18:00:41 +03:00
|
|
|
|
|
|
|
if (!(clipboard = ClipboardCreate()))
|
|
|
|
{
|
|
|
|
CloseHandle(hevent);
|
2016-08-04 14:25:52 +03:00
|
|
|
return FALSE;
|
2015-04-28 18:00:41 +03:00
|
|
|
}
|
2014-11-12 20:25:12 +03:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
afc->cliprdr = cliprdr;
|
|
|
|
afc->clipboard = clipboard;
|
|
|
|
afc->clipboardRequestEvent = hevent;
|
|
|
|
cliprdr->custom = (void*) afc;
|
2014-11-12 20:25:12 +03:00
|
|
|
cliprdr->MonitorReady = android_cliprdr_monitor_ready;
|
|
|
|
cliprdr->ServerCapabilities = android_cliprdr_server_capabilities;
|
|
|
|
cliprdr->ServerFormatList = android_cliprdr_server_format_list;
|
|
|
|
cliprdr->ServerFormatListResponse = android_cliprdr_server_format_list_response;
|
|
|
|
cliprdr->ServerLockClipboardData = android_cliprdr_server_lock_clipboard_data;
|
2016-08-04 14:25:52 +03:00
|
|
|
cliprdr->ServerUnlockClipboardData =
|
|
|
|
android_cliprdr_server_unlock_clipboard_data;
|
2014-11-12 20:25:12 +03:00
|
|
|
cliprdr->ServerFormatDataRequest = android_cliprdr_server_format_data_request;
|
|
|
|
cliprdr->ServerFormatDataResponse = android_cliprdr_server_format_data_response;
|
2016-08-04 14:25:52 +03:00
|
|
|
cliprdr->ServerFileContentsRequest =
|
|
|
|
android_cliprdr_server_file_contents_request;
|
|
|
|
cliprdr->ServerFileContentsResponse =
|
|
|
|
android_cliprdr_server_file_contents_response;
|
|
|
|
return TRUE;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|
|
|
|
|
2016-08-04 14:25:52 +03:00
|
|
|
BOOL android_cliprdr_uninit(androidContext* afc, CliprdrClientContext* cliprdr)
|
2013-04-26 16:59:16 +04:00
|
|
|
{
|
2016-08-04 14:25:52 +03:00
|
|
|
if (!afc || !cliprdr)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-11-12 20:25:12 +03:00
|
|
|
cliprdr->custom = NULL;
|
|
|
|
afc->cliprdr = NULL;
|
|
|
|
ClipboardDestroy(afc->clipboard);
|
|
|
|
CloseHandle(afc->clipboardRequestEvent);
|
2016-08-04 14:25:52 +03:00
|
|
|
return TRUE;
|
2013-04-26 16:59:16 +04:00
|
|
|
}
|