2011-07-12 13:06:14 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-12 13:06:14 +04:00
|
|
|
* Clipboard Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2009-2011 Jay Sorg
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-04-06 22:55:22 +04:00
|
|
|
#include "config.h"
|
2012-08-15 01:09:01 +04:00
|
|
|
#endif
|
|
|
|
|
2012-10-09 04:26:11 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-08-18 23:39:28 +04:00
|
|
|
#include <winpr/print.h>
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2011-07-12 13:06:14 +04:00
|
|
|
#include <freerdp/types.h>
|
2011-11-01 09:09:38 +04:00
|
|
|
#include <freerdp/constants.h>
|
2012-10-09 04:33:58 +04:00
|
|
|
#include <freerdp/client/cliprdr.h>
|
2011-07-12 13:06:14 +04:00
|
|
|
|
|
|
|
#include "cliprdr_main.h"
|
2011-07-12 19:06:39 +04:00
|
|
|
#include "cliprdr_format.h"
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
const char* const CB_MSG_TYPE_STRINGS[] =
|
2011-11-01 03:15:27 +04:00
|
|
|
{
|
|
|
|
"",
|
|
|
|
"CB_MONITOR_READY",
|
|
|
|
"CB_FORMAT_LIST",
|
|
|
|
"CB_FORMAT_LIST_RESPONSE",
|
|
|
|
"CB_FORMAT_DATA_REQUEST",
|
|
|
|
"CB_FORMAT_DATA_RESPONSE",
|
|
|
|
"CB_TEMP_DIRECTORY",
|
|
|
|
"CB_CLIP_CAPS",
|
|
|
|
"CB_FILECONTENTS_REQUEST",
|
|
|
|
"CB_FILECONTENTS_RESPONSE",
|
|
|
|
"CB_LOCK_CLIPDATA"
|
|
|
|
"CB_UNLOCK_CLIPDATA"
|
|
|
|
};
|
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr)
|
|
|
|
{
|
|
|
|
CliprdrClientContext* pInterface;
|
2014-11-12 20:56:03 +03:00
|
|
|
pInterface = (CliprdrClientContext*) cliprdr->channelEntryPoints.pInterface;
|
2013-11-24 06:35:44 +04:00
|
|
|
return pInterface;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, dataLen + 8);
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, msgType);
|
|
|
|
Stream_Write_UINT16(s, msgFlags);
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2011-07-12 13:06:14 +04:00
|
|
|
/* Write actual length after the entire packet has been constructed. */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 4);
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
return s;
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* s)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
|
|
|
int pos;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dataLen;
|
2014-11-12 20:56:03 +03:00
|
|
|
UINT32 status = 0;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(s);
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2011-07-12 13:06:14 +04:00
|
|
|
dataLen = pos - 8;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 4);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, dataLen);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, pos);
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2013-08-18 23:39:28 +04:00
|
|
|
#ifdef WITH_DEBUG_CLIPRDR
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "Cliprdr Sending (%d bytes)", dataLen + 8);
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), dataLen + 8);
|
2013-08-18 23:39:28 +04:00
|
|
|
#endif
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2014-11-12 20:56:03 +03:00
|
|
|
if (!cliprdr)
|
|
|
|
{
|
|
|
|
status = CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = cliprdr->channelEntryPoints.pVirtualChannelWrite(cliprdr->OpenHandle,
|
|
|
|
Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2015-01-20 13:45:36 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
|
|
|
|
WTSErrorToString(status), status);
|
2014-11-12 20:56:03 +03:00
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void cliprdr_print_general_capability_flags(UINT32 flags)
|
2011-11-01 03:15:27 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_INFO(TAG, "generalFlags (0x%08X) {", flags);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
|
|
|
if (flags & CB_USE_LONG_FORMAT_NAMES)
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_INFO(TAG, "\tCB_USE_LONG_FORMAT_NAMES");
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
if (flags & CB_STREAM_FILECLIP_ENABLED)
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_INFO(TAG, "\tCB_STREAM_FILECLIP_ENABLED");
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
if (flags & CB_FILECLIP_NO_FILE_PATHS)
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_INFO(TAG, "\tCB_FILECLIP_NO_FILE_PATHS");
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
if (flags & CB_CAN_LOCK_CLIPDATA)
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_INFO(TAG, "\tCB_CAN_LOCK_CLIPDATA");
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_INFO(TAG, "}");
|
2011-11-01 03:15:27 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
static int cliprdr_process_general_capability(cliprdrPlugin* cliprdr, wStream* s)
|
2011-11-01 03:15:27 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 version;
|
|
|
|
UINT32 generalFlags;
|
2014-11-20 22:28:05 +03:00
|
|
|
CLIPRDR_CAPABILITIES capabilities;
|
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
|
|
|
|
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, version); /* version (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, generalFlags); /* generalFlags (4 bytes) */
|
2014-11-20 22:28:05 +03:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
DEBUG_CLIPRDR("Version: %d", version);
|
|
|
|
#ifdef WITH_DEBUG_CLIPRDR
|
|
|
|
cliprdr_print_general_capability_flags(generalFlags);
|
|
|
|
#endif
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (cliprdr->useLongFormatNames)
|
|
|
|
cliprdr->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (cliprdr->streamFileClipEnabled)
|
|
|
|
cliprdr->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (cliprdr->fileClipNoFilePaths)
|
|
|
|
cliprdr->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (cliprdr->canLockClipData)
|
|
|
|
cliprdr->canLockClipData = (generalFlags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
cliprdr->capabilitiesReceived = TRUE;
|
2011-11-18 04:51:30 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (!context->custom)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
capabilities.cCapabilitiesSets = 1;
|
|
|
|
capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &(generalCapabilitySet);
|
|
|
|
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
|
|
|
|
generalCapabilitySet.capabilitySetLength = 12;
|
|
|
|
generalCapabilitySet.version = version;
|
|
|
|
generalCapabilitySet.generalFlags = generalFlags;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (context->ServerCapabilities)
|
|
|
|
context->ServerCapabilities(context, &capabilities);
|
2014-10-24 02:17:53 +04:00
|
|
|
|
|
|
|
return 1;
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
static int cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, wStream* s, UINT16 length, UINT16 flags)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
UINT16 index;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 lengthCapability;
|
|
|
|
UINT16 cCapabilitiesSets;
|
|
|
|
UINT16 capabilitySetType;
|
2014-11-20 22:28:05 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, cCapabilitiesSets); /* cCapabilitiesSets (2 bytes) */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT16(s); /* pad1 (2 bytes) */
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerCapabilities");
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
for (index = 0; index < cCapabilitiesSets; index++)
|
2011-11-01 03:15:27 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, capabilitySetType); /* capabilitySetType (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, lengthCapability); /* lengthCapability (2 bytes) */
|
2011-11-01 03:15:27 +04:00
|
|
|
|
|
|
|
switch (capabilitySetType)
|
|
|
|
{
|
|
|
|
case CB_CAPSTYPE_GENERAL:
|
|
|
|
cliprdr_process_general_capability(cliprdr, s);
|
|
|
|
break;
|
2014-11-20 22:28:05 +03:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
default:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "unknown cliprdr capability set: %d", capabilitySetType);
|
2011-11-01 03:15:27 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-24 02:17:53 +04:00
|
|
|
|
|
|
|
return 1;
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
static int cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, wStream* s, UINT16 length, UINT16 flags)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
CLIPRDR_MONITOR_READY monitorReady;
|
2013-11-24 06:35:44 +04:00
|
|
|
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
|
|
|
|
2014-10-16 06:48:18 +04:00
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "MonitorReady");
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (!context->custom)
|
|
|
|
return -1;
|
2011-07-12 18:09:56 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (!cliprdr->capabilitiesReceived)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The clipboard capabilities pdu from server to client is optional,
|
|
|
|
* but a server using it must send it before sending the monitor ready pdu.
|
|
|
|
* When the server capabilities pdu is not used, default capabilities
|
|
|
|
* corresponding to a generalFlags field set to zero are assumed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
cliprdr->useLongFormatNames = FALSE;
|
|
|
|
cliprdr->streamFileClipEnabled = FALSE;
|
|
|
|
cliprdr->fileClipNoFilePaths = TRUE;
|
|
|
|
cliprdr->canLockClipData = FALSE;
|
2013-11-24 06:35:44 +04:00
|
|
|
}
|
2014-11-20 22:28:05 +03:00
|
|
|
|
|
|
|
monitorReady.msgType = CB_MONITOR_READY;
|
|
|
|
monitorReady.msgFlags = flags;
|
|
|
|
monitorReady.dataLen = length;
|
|
|
|
|
|
|
|
if (context->MonitorReady)
|
|
|
|
context->MonitorReady(context, &monitorReady);
|
2014-10-24 02:17:53 +04:00
|
|
|
|
|
|
|
return 1;
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
static int cliprdr_process_filecontents_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, UINT16 flags)
|
2014-03-03 06:56:04 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
CLIPRDR_FILE_CONTENTS_REQUEST request;
|
2014-10-24 02:17:53 +04:00
|
|
|
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsRequest");
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (!context->custom)
|
|
|
|
return -1;
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 28)
|
|
|
|
return -1;
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
request.msgType = CB_FILECONTENTS_REQUEST;
|
|
|
|
request.msgFlags = flags;
|
|
|
|
request.dataLen = length;
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
Stream_Read_UINT32(s, request.streamId); /* streamId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, request.listIndex); /* listIndex (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, request.dwFlags); /* dwFlags (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, request.nPositionLow); /* nPositionLow (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, request.nPositionHigh); /* nPositionHigh (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, request.cbRequested); /* cbRequested (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, request.clipDataId); /* clipDataId (4 bytes) */
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (context->ServerFileContentsRequest)
|
|
|
|
context->ServerFileContentsRequest(context, &request);
|
2014-10-24 02:17:53 +04:00
|
|
|
|
|
|
|
return 1;
|
2014-03-03 06:56:04 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
static int cliprdr_process_filecontents_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, UINT16 flags)
|
2014-03-03 06:56:04 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
CLIPRDR_FILE_CONTENTS_RESPONSE response;
|
2014-10-24 02:17:53 +04:00
|
|
|
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsResponse");
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (!context->custom)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
return -1;
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
response.msgType = CB_FILECONTENTS_RESPONSE;
|
|
|
|
response.msgFlags = flags;
|
|
|
|
response.dataLen = length;
|
2014-03-03 06:56:04 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
Stream_Read_UINT32(s, response.streamId); /* streamId (4 bytes) */
|
|
|
|
|
|
|
|
response.cbRequested = length - 4;
|
|
|
|
response.requestedData = Stream_Pointer(s); /* requestedFileContentsData */
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (context->ServerFileContentsResponse)
|
|
|
|
context->ServerFileContentsResponse(context, &response);
|
2014-03-10 10:20:53 +04:00
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
return 1;
|
2014-03-03 06:56:04 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
static int cliprdr_process_lock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, UINT16 flags)
|
2014-03-03 06:56:04 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData;
|
2014-10-24 02:17:53 +04:00
|
|
|
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "LockClipData");
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (!context->custom)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
return -1;
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
lockClipboardData.msgType = CB_LOCK_CLIPDATA;
|
|
|
|
lockClipboardData.msgFlags = flags;
|
|
|
|
lockClipboardData.dataLen = length;
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
Stream_Read_UINT32(s, lockClipboardData.clipDataId); /* clipDataId (4 bytes) */
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (context->ServerLockClipboardData)
|
|
|
|
context->ServerLockClipboardData(context, &lockClipboardData);
|
2014-10-24 02:17:53 +04:00
|
|
|
|
|
|
|
return 1;
|
2014-03-10 10:20:53 +04:00
|
|
|
}
|
2014-03-03 06:56:04 +04:00
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
static int cliprdr_process_unlock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, UINT16 flags)
|
2014-03-03 06:56:04 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData;
|
2014-10-24 02:17:53 +04:00
|
|
|
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "UnlockClipData");
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (!context->custom)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
return -1;
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
unlockClipboardData.msgType = CB_UNLOCK_CLIPDATA;
|
|
|
|
unlockClipboardData.msgFlags = flags;
|
|
|
|
unlockClipboardData.dataLen = length;
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
Stream_Read_UINT32(s, unlockClipboardData.clipDataId); /* clipDataId (4 bytes) */
|
2014-10-24 02:17:53 +04:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (context->ServerUnlockClipboardData)
|
|
|
|
context->ServerUnlockClipboardData(context, &unlockClipboardData);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
return 1;
|
2014-03-03 06:56:04 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:56:03 +03:00
|
|
|
static void cliprdr_order_recv(cliprdrPlugin* cliprdr, wStream* s)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 msgType;
|
|
|
|
UINT16 msgFlags;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dataLen;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
Stream_Read_UINT16(s, msgType); /* msgType (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, msgFlags); /* msgFlags (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, dataLen); /* dataLen (4 bytes) */
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
DEBUG_CLIPRDR("msgType: %s (%d), msgFlags: %d dataLen: %d",
|
2014-08-19 20:26:39 +04:00
|
|
|
CB_MSG_TYPE_STRINGS[msgType], msgType, msgFlags, dataLen);
|
2013-08-18 23:39:28 +04:00
|
|
|
#ifdef WITH_DEBUG_CLIPRDR
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), dataLen + 8);
|
2013-08-18 23:39:28 +04:00
|
|
|
#endif
|
|
|
|
|
2011-07-12 13:06:14 +04:00
|
|
|
switch (msgType)
|
|
|
|
{
|
|
|
|
case CB_CLIP_CAPS:
|
2011-11-23 19:58:13 +04:00
|
|
|
cliprdr_process_clip_caps(cliprdr, s, dataLen, msgFlags);
|
2011-07-12 13:06:14 +04:00
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2011-07-12 13:06:14 +04:00
|
|
|
case CB_MONITOR_READY:
|
2011-11-23 19:58:13 +04:00
|
|
|
cliprdr_process_monitor_ready(cliprdr, s, dataLen, msgFlags);
|
2011-07-12 13:06:14 +04:00
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2011-07-12 19:53:54 +04:00
|
|
|
case CB_FORMAT_LIST:
|
2011-11-01 09:09:38 +04:00
|
|
|
cliprdr_process_format_list(cliprdr, s, dataLen, msgFlags);
|
2011-07-12 19:53:54 +04:00
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2011-07-12 20:01:50 +04:00
|
|
|
case CB_FORMAT_LIST_RESPONSE:
|
2011-11-23 19:58:13 +04:00
|
|
|
cliprdr_process_format_list_response(cliprdr, s, dataLen, msgFlags);
|
2011-07-12 20:01:50 +04:00
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2011-07-12 20:30:25 +04:00
|
|
|
case CB_FORMAT_DATA_REQUEST:
|
2011-11-23 19:58:13 +04:00
|
|
|
cliprdr_process_format_data_request(cliprdr, s, dataLen, msgFlags);
|
2011-07-12 20:30:25 +04:00
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2011-07-12 20:50:00 +04:00
|
|
|
case CB_FORMAT_DATA_RESPONSE:
|
2011-11-23 19:58:13 +04:00
|
|
|
cliprdr_process_format_data_response(cliprdr, s, dataLen, msgFlags);
|
2011-07-12 20:50:00 +04:00
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2014-03-03 06:56:04 +04:00
|
|
|
case CB_FILECONTENTS_REQUEST:
|
|
|
|
cliprdr_process_filecontents_request(cliprdr, s, dataLen, msgFlags);
|
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2014-03-03 06:56:04 +04:00
|
|
|
case CB_FILECONTENTS_RESPONSE:
|
|
|
|
cliprdr_process_filecontents_response(cliprdr, s, dataLen, msgFlags);
|
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2014-03-03 06:56:04 +04:00
|
|
|
case CB_LOCK_CLIPDATA:
|
|
|
|
cliprdr_process_lock_clipdata(cliprdr, s, dataLen, msgFlags);
|
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2014-03-03 06:56:04 +04:00
|
|
|
case CB_UNLOCK_CLIPDATA:
|
|
|
|
cliprdr_process_unlock_clipdata(cliprdr, s, dataLen, msgFlags);
|
|
|
|
break;
|
|
|
|
|
2011-07-12 19:06:39 +04:00
|
|
|
default:
|
2014-11-12 20:56:03 +03:00
|
|
|
WLog_ERR(TAG, "unknown msgType %d", msgType);
|
2011-07-12 19:06:39 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-12-03 22:17:27 +03:00
|
|
|
|
|
|
|
Stream_Free(s, TRUE);
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-29 22:49:09 +04:00
|
|
|
/**
|
|
|
|
* Callback Interface
|
|
|
|
*/
|
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
int cliprdr_client_capabilities(CliprdrClientContext* context, CLIPRDR_CAPABILITIES* capabilities)
|
2013-03-29 22:49:09 +04:00
|
|
|
{
|
2013-11-24 06:35:44 +04:00
|
|
|
wStream* s;
|
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
2014-11-21 00:05:13 +03:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
Stream_Write_UINT16(s, 1); /* cCapabilitiesSets */
|
|
|
|
Stream_Write_UINT16(s, 0); /* pad1 */
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
generalCapabilitySet = (CLIPRDR_GENERAL_CAPABILITY_SET*) capabilities->capabilitySets;
|
|
|
|
Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetType); /* capabilitySetType */
|
|
|
|
Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetLength); /* lengthCapability */
|
|
|
|
Stream_Write_UINT32(s, generalCapabilitySet->version); /* version */
|
|
|
|
Stream_Write_UINT32(s, generalCapabilitySet->generalFlags); /* generalFlags */
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientCapabilities");
|
2013-11-24 06:35:44 +04:00
|
|
|
cliprdr_packet_send(cliprdr, s);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-03-29 22:49:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
int cliprdr_temp_directory(CliprdrClientContext* context, CLIPRDR_TEMP_DIRECTORY* tempDirectory)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
wStream* s;
|
|
|
|
WCHAR* wszTempDir = NULL;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, 520 * 2);
|
|
|
|
|
|
|
|
length = ConvertToUnicode(CP_UTF8, 0, tempDirectory->szTempDir, -1, &wszTempDir, 0);
|
|
|
|
|
|
|
|
if (length < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (length > 520)
|
|
|
|
length = 520;
|
|
|
|
|
|
|
|
Stream_Write(s, tempDirectory->szTempDir, length * 2);
|
|
|
|
Stream_Zero(s, (520 - length) * 2);
|
|
|
|
|
|
|
|
free(wszTempDir);
|
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "TempDirectory: %s",
|
|
|
|
tempDirectory->szTempDir);
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
int cliprdr_client_format_list(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST* formatList)
|
2013-03-29 22:49:09 +04:00
|
|
|
{
|
2013-11-24 06:35:44 +04:00
|
|
|
wStream* s;
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 index;
|
2013-11-24 06:35:44 +04:00
|
|
|
int length = 0;
|
2014-11-20 22:28:05 +03:00
|
|
|
int cchWideChar;
|
|
|
|
LPWSTR lpWideCharStr;
|
2013-11-24 06:35:44 +04:00
|
|
|
int formatNameSize;
|
2014-11-20 22:28:05 +03:00
|
|
|
int formatNameLength;
|
|
|
|
char* szFormatName;
|
|
|
|
WCHAR* wszFormatName;
|
|
|
|
BOOL asciiNames = FALSE;
|
2013-11-24 06:35:44 +04:00
|
|
|
CLIPRDR_FORMAT* format;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
if (!cliprdr->useLongFormatNames)
|
2013-11-24 06:35:44 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
length = formatList->numFormats * 36;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_FORMAT_LIST, 0, length);
|
|
|
|
|
|
|
|
for (index = 0; index < formatList->numFormats; index++)
|
|
|
|
{
|
|
|
|
format = (CLIPRDR_FORMAT*) &(formatList->formats[index]);
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */
|
|
|
|
|
|
|
|
formatNameSize = 0;
|
|
|
|
formatNameLength = 0;
|
|
|
|
|
|
|
|
szFormatName = format->formatName;
|
|
|
|
|
|
|
|
if (asciiNames)
|
|
|
|
{
|
|
|
|
if (szFormatName)
|
|
|
|
formatNameLength = strlen(szFormatName);
|
|
|
|
|
|
|
|
if (formatNameLength > 31)
|
|
|
|
formatNameLength = 31;
|
|
|
|
|
|
|
|
Stream_Write(s, szFormatName, formatNameLength);
|
|
|
|
Stream_Zero(s, 32 - formatNameLength);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wszFormatName = NULL;
|
|
|
|
|
|
|
|
if (szFormatName)
|
|
|
|
formatNameSize = ConvertToUnicode(CP_UTF8, 0, szFormatName, -1, &wszFormatName, 0);
|
|
|
|
|
|
|
|
if (formatNameSize > 15)
|
|
|
|
formatNameSize = 15;
|
2014-12-07 02:33:37 +03:00
|
|
|
|
|
|
|
if (wszFormatName)
|
|
|
|
Stream_Write(s, wszFormatName, formatNameSize * 2);
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
Stream_Zero(s, 32 - (formatNameSize * 2));
|
2014-11-21 00:05:13 +03:00
|
|
|
|
|
|
|
free(wszFormatName);
|
2014-11-20 22:28:05 +03:00
|
|
|
}
|
|
|
|
}
|
2013-11-24 06:35:44 +04:00
|
|
|
}
|
2014-11-20 22:28:05 +03:00
|
|
|
else
|
2013-11-24 06:35:44 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
for (index = 0; index < formatList->numFormats; index++)
|
2013-11-24 06:35:44 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
format = (CLIPRDR_FORMAT*) &(formatList->formats[index]);
|
|
|
|
length += 4;
|
|
|
|
formatNameSize = 2;
|
|
|
|
|
|
|
|
if (format->formatName)
|
|
|
|
formatNameSize = MultiByteToWideChar(CP_UTF8, 0, format->formatName, -1, NULL, 0) * 2;
|
|
|
|
|
|
|
|
length += formatNameSize;
|
2013-11-24 06:35:44 +04:00
|
|
|
}
|
2014-11-20 22:28:05 +03:00
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_FORMAT_LIST, 0, length);
|
|
|
|
|
|
|
|
for (index = 0; index < formatList->numFormats; index++)
|
2013-11-24 06:35:44 +04:00
|
|
|
{
|
2014-11-20 22:28:05 +03:00
|
|
|
format = (CLIPRDR_FORMAT*) &(formatList->formats[index]);
|
|
|
|
Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */
|
|
|
|
|
|
|
|
if (format->formatName)
|
|
|
|
{
|
|
|
|
lpWideCharStr = (LPWSTR) Stream_Pointer(s);
|
|
|
|
cchWideChar = (Stream_Capacity(s) - Stream_GetPosition(s)) / 2;
|
|
|
|
formatNameSize = MultiByteToWideChar(CP_UTF8, 0,
|
|
|
|
format->formatName, -1, lpWideCharStr, cchWideChar) * 2;
|
|
|
|
Stream_Seek(s, formatNameSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Stream_Write_UINT16(s, 0);
|
|
|
|
}
|
2013-11-24 06:35:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-16 06:48:18 +04:00
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatList: numFormats: %d",
|
2014-10-17 05:45:47 +04:00
|
|
|
formatList->numFormats);
|
2014-11-20 22:28:05 +03:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
cliprdr_packet_send(cliprdr, s);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cliprdr_client_format_list_response(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
formatListResponse->msgType = CB_FORMAT_LIST_RESPONSE;
|
|
|
|
formatListResponse->dataLen = 0;
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
s = cliprdr_packet_new(formatListResponse->msgType, formatListResponse->msgFlags, formatListResponse->dataLen);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatListResponse");
|
2013-11-24 06:35:44 +04:00
|
|
|
cliprdr_packet_send(cliprdr, s);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-03-29 22:49:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
int cliprdr_client_lock_clipboard_data(CliprdrClientContext* context, CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_LOCK_CLIPDATA, 0, 4);
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, lockClipboardData->clipDataId); /* clipDataId (4 bytes) */
|
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientLockClipboardData: clipDataId: 0x%04X",
|
|
|
|
lockClipboardData->clipDataId);
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_UNLOCK_CLIPDATA, 0, 4);
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, unlockClipboardData->clipDataId); /* clipDataId (4 bytes) */
|
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientUnlockClipboardData: clipDataId: 0x%04X",
|
|
|
|
unlockClipboardData->clipDataId);
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-24 08:45:31 +04:00
|
|
|
int cliprdr_client_format_data_request(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
|
2013-03-29 22:49:09 +04:00
|
|
|
{
|
2013-11-24 08:45:31 +04:00
|
|
|
wStream* s;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 08:45:31 +04:00
|
|
|
formatDataRequest->msgType = CB_FORMAT_DATA_REQUEST;
|
2013-11-25 09:25:16 +04:00
|
|
|
formatDataRequest->msgFlags = 0;
|
2013-11-24 08:45:31 +04:00
|
|
|
formatDataRequest->dataLen = 4;
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 08:45:31 +04:00
|
|
|
s = cliprdr_packet_new(formatDataRequest->msgType, formatDataRequest->msgFlags, formatDataRequest->dataLen);
|
|
|
|
Stream_Write_UINT32(s, formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataRequest");
|
2013-11-24 08:45:31 +04:00
|
|
|
cliprdr_packet_send(cliprdr, s);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-03-29 22:49:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-24 08:45:31 +04:00
|
|
|
int cliprdr_client_format_data_response(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
|
2013-03-29 22:49:09 +04:00
|
|
|
{
|
2013-11-24 08:45:31 +04:00
|
|
|
wStream* s;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 08:45:31 +04:00
|
|
|
formatDataResponse->msgType = CB_FORMAT_DATA_RESPONSE;
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 08:45:31 +04:00
|
|
|
s = cliprdr_packet_new(formatDataResponse->msgType, formatDataResponse->msgFlags, formatDataResponse->dataLen);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-11-24 08:45:31 +04:00
|
|
|
Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->dataLen);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataResponse");
|
2013-11-24 08:45:31 +04:00
|
|
|
cliprdr_packet_send(cliprdr, s);
|
2014-10-16 06:48:18 +04:00
|
|
|
|
2013-03-29 22:49:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 02:17:53 +04:00
|
|
|
int cliprdr_client_file_contents_request(CliprdrClientContext* context, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_FILECONTENTS_REQUEST, 0, 28);
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, fileContentsRequest->streamId); /* streamId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, fileContentsRequest->listIndex); /* listIndex (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, fileContentsRequest->dwFlags); /* dwFlags (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, fileContentsRequest->nPositionLow); /* nPositionLow (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, fileContentsRequest->nPositionHigh); /* nPositionHigh (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, fileContentsRequest->cbRequested); /* cbRequested (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, fileContentsRequest->clipDataId); /* clipDataId (4 bytes) */
|
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFileContentsRequest: streamId: 0x%04X",
|
|
|
|
fileContentsRequest->streamId);
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cliprdr_client_file_contents_response(CliprdrClientContext* context, CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
|
|
|
|
|
|
|
if (fileContentsResponse->dwFlags & FILECONTENTS_SIZE)
|
|
|
|
fileContentsResponse->cbRequested = sizeof(UINT64);
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_FILECONTENTS_REQUEST, 0,
|
|
|
|
4 + fileContentsResponse->cbRequested);
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, fileContentsResponse->streamId); /* streamId (4 bytes) */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* requestedFileContentsData:
|
|
|
|
* FILECONTENTS_SIZE: file size as UINT64
|
|
|
|
* FILECONTENTS_RANGE: file data from requested range
|
|
|
|
*/
|
|
|
|
|
|
|
|
Stream_Write(s, fileContentsResponse->requestedData, fileContentsResponse->cbRequested);
|
|
|
|
|
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFileContentsResponse: streamId: 0x%04X",
|
|
|
|
fileContentsResponse->streamId);
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:56:03 +03:00
|
|
|
/****************************************************************************************/
|
|
|
|
|
2015-01-20 14:31:43 +03:00
|
|
|
static wListDictionary* g_InitHandles = NULL;
|
|
|
|
static wListDictionary* g_OpenHandles = NULL;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
|
|
|
void cliprdr_add_init_handle_data(void* pInitHandle, void* pUserData)
|
|
|
|
{
|
|
|
|
if (!g_InitHandles)
|
|
|
|
g_InitHandles = ListDictionary_New(TRUE);
|
|
|
|
|
|
|
|
ListDictionary_Add(g_InitHandles, pInitHandle, pUserData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* cliprdr_get_init_handle_data(void* pInitHandle)
|
|
|
|
{
|
|
|
|
void* pUserData = NULL;
|
|
|
|
pUserData = ListDictionary_GetItemValue(g_InitHandles, pInitHandle);
|
|
|
|
return pUserData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cliprdr_remove_init_handle_data(void* pInitHandle)
|
|
|
|
{
|
|
|
|
ListDictionary_Remove(g_InitHandles, pInitHandle);
|
2015-01-20 13:45:36 +03:00
|
|
|
if (ListDictionary_Count(g_InitHandles) < 1)
|
|
|
|
{
|
|
|
|
ListDictionary_Free(g_InitHandles);
|
|
|
|
g_InitHandles = NULL;
|
|
|
|
}
|
2014-11-12 20:56:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cliprdr_add_open_handle_data(DWORD openHandle, void* pUserData)
|
|
|
|
{
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
|
|
|
|
if (!g_OpenHandles)
|
|
|
|
g_OpenHandles = ListDictionary_New(TRUE);
|
|
|
|
|
|
|
|
ListDictionary_Add(g_OpenHandles, pOpenHandle, pUserData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* cliprdr_get_open_handle_data(DWORD openHandle)
|
|
|
|
{
|
|
|
|
void* pUserData = NULL;
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
pUserData = ListDictionary_GetItemValue(g_OpenHandles, pOpenHandle);
|
|
|
|
return pUserData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cliprdr_remove_open_handle_data(DWORD openHandle)
|
|
|
|
{
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
ListDictionary_Remove(g_OpenHandles, pOpenHandle);
|
2015-01-20 13:45:36 +03:00
|
|
|
|
|
|
|
if (ListDictionary_Count(g_OpenHandles) < 1)
|
|
|
|
{
|
|
|
|
ListDictionary_Free(g_OpenHandles);
|
|
|
|
g_OpenHandles = NULL;
|
|
|
|
}
|
2014-11-12 20:56:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cliprdr_virtual_channel_event_data_received(cliprdrPlugin* cliprdr,
|
|
|
|
void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
|
|
|
{
|
|
|
|
wStream* data_in;
|
|
|
|
|
|
|
|
if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_FIRST)
|
|
|
|
{
|
|
|
|
if (cliprdr->data_in)
|
|
|
|
Stream_Free(cliprdr->data_in, TRUE);
|
|
|
|
|
|
|
|
cliprdr->data_in = Stream_New(NULL, totalLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
data_in = cliprdr->data_in;
|
|
|
|
Stream_EnsureRemainingCapacity(data_in, (int) dataLength);
|
|
|
|
Stream_Write(data_in, pData, dataLength);
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_LAST)
|
|
|
|
{
|
|
|
|
if (Stream_Capacity(data_in) != Stream_GetPosition(data_in))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "cliprdr_plugin_process_received: read error");
|
|
|
|
}
|
|
|
|
|
|
|
|
cliprdr->data_in = NULL;
|
|
|
|
Stream_SealLength(data_in);
|
|
|
|
Stream_SetPosition(data_in, 0);
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
MessageQueue_Post(cliprdr->queue, NULL, 0, (void*) data_in, NULL);
|
2014-11-12 20:56:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID VCAPITYPE cliprdr_virtual_channel_open_event(DWORD openHandle, UINT event,
|
|
|
|
LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
|
|
|
{
|
|
|
|
cliprdrPlugin* cliprdr;
|
|
|
|
|
|
|
|
cliprdr = (cliprdrPlugin*) cliprdr_get_open_handle_data(openHandle);
|
|
|
|
|
|
|
|
if (!cliprdr)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "cliprdr_virtual_channel_open_event: error no match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_DATA_RECEIVED:
|
|
|
|
cliprdr_virtual_channel_event_data_received(cliprdr, pData, dataLength, totalLength, dataFlags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_WRITE_COMPLETE:
|
|
|
|
Stream_Free((wStream*) pData, TRUE);
|
|
|
|
break;
|
2015-01-20 13:45:36 +03:00
|
|
|
|
|
|
|
case CHANNEL_EVENT_USER:
|
|
|
|
break;
|
2014-11-12 20:56:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* cliprdr_virtual_channel_client_thread(void* arg)
|
|
|
|
{
|
|
|
|
wStream* data;
|
|
|
|
wMessage message;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) arg;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2014-12-27 23:20:29 +03:00
|
|
|
if (!MessageQueue_Wait(cliprdr->queue))
|
2014-11-12 20:56:03 +03:00
|
|
|
break;
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
if (MessageQueue_Peek(cliprdr->queue, &message, TRUE))
|
2014-11-12 20:56:03 +03:00
|
|
|
{
|
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (message.id == 0)
|
|
|
|
{
|
|
|
|
data = (wStream*) message.wParam;
|
|
|
|
cliprdr_order_recv(cliprdr, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitThread(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr, LPVOID pData, UINT32 dataLength)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
|
|
|
status = cliprdr->channelEntryPoints.pVirtualChannelOpen(cliprdr->InitHandle,
|
|
|
|
&cliprdr->OpenHandle, cliprdr->channelDef.name, cliprdr_virtual_channel_open_event);
|
|
|
|
|
|
|
|
cliprdr_add_open_handle_data(cliprdr->OpenHandle, cliprdr);
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
2015-01-20 13:45:36 +03:00
|
|
|
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
|
|
|
|
WTSErrorToString(status), status);
|
2014-11-12 20:56:03 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
cliprdr->queue = MessageQueue_New(NULL);
|
2014-11-12 20:56:03 +03:00
|
|
|
|
|
|
|
cliprdr->thread = CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) cliprdr_virtual_channel_client_thread, (void*) cliprdr, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2015-01-20 13:45:36 +03:00
|
|
|
static void cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* cliprdr)
|
2014-11-12 20:56:03 +03:00
|
|
|
{
|
2015-01-20 13:45:36 +03:00
|
|
|
UINT rc;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2015-01-20 13:45:36 +03:00
|
|
|
MessageQueue_PostQuit(cliprdr->queue, 0);
|
|
|
|
WaitForSingleObject(cliprdr->thread, INFINITE);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2015-01-20 13:45:36 +03:00
|
|
|
MessageQueue_Free(cliprdr->queue);
|
|
|
|
CloseHandle(cliprdr->thread);
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2015-01-20 13:45:36 +03:00
|
|
|
rc = cliprdr->channelEntryPoints.pVirtualChannelClose(cliprdr->OpenHandle);
|
|
|
|
if (CHANNEL_RC_OK != rc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
|
|
|
|
WTSErrorToString(rc), rc);
|
|
|
|
}
|
2014-11-12 20:56:03 +03:00
|
|
|
|
|
|
|
if (cliprdr->data_in)
|
|
|
|
{
|
|
|
|
Stream_Free(cliprdr->data_in, TRUE);
|
|
|
|
cliprdr->data_in = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cliprdr_remove_open_handle_data(cliprdr->OpenHandle);
|
2015-01-20 13:45:36 +03:00
|
|
|
}
|
2014-12-03 22:17:27 +03:00
|
|
|
|
2015-01-20 13:45:36 +03:00
|
|
|
static void cliprdr_virtual_channel_event_terminated(cliprdrPlugin* cliprdr)
|
|
|
|
{
|
|
|
|
cliprdr_remove_init_handle_data(cliprdr->InitHandle);
|
2014-12-27 23:20:29 +03:00
|
|
|
|
2014-12-03 22:17:27 +03:00
|
|
|
free(cliprdr);
|
2014-11-12 20:56:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VOID VCAPITYPE cliprdr_virtual_channel_init_event(LPVOID pInitHandle, UINT event, LPVOID pData, UINT dataLength)
|
|
|
|
{
|
|
|
|
cliprdrPlugin* cliprdr;
|
|
|
|
|
|
|
|
cliprdr = (cliprdrPlugin*) cliprdr_get_init_handle_data(pInitHandle);
|
|
|
|
|
|
|
|
if (!cliprdr)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "cliprdr_virtual_channel_init_event: error no match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_CONNECTED:
|
|
|
|
cliprdr_virtual_channel_event_connected(cliprdr, pData, dataLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_DISCONNECTED:
|
2015-01-20 13:45:36 +03:00
|
|
|
cliprdr_virtual_channel_event_disconnected(cliprdr);
|
2014-11-12 20:56:03 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_TERMINATED:
|
|
|
|
cliprdr_virtual_channel_event_terminated(cliprdr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 06:48:17 +04:00
|
|
|
/* cliprdr is always built-in */
|
2012-10-09 04:26:11 +04:00
|
|
|
#define VirtualChannelEntry cliprdr_VirtualChannelEntry
|
|
|
|
|
2014-03-04 03:28:31 +04:00
|
|
|
BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
|
2012-10-09 04:26:11 +04:00
|
|
|
{
|
2015-01-20 13:45:36 +03:00
|
|
|
UINT rc;
|
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
cliprdrPlugin* cliprdr;
|
2013-03-29 22:49:09 +04:00
|
|
|
CliprdrClientContext* context;
|
2014-02-17 02:38:59 +04:00
|
|
|
CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx;
|
2014-10-16 05:30:11 +04:00
|
|
|
|
2014-02-17 02:27:36 +04:00
|
|
|
cliprdr = (cliprdrPlugin*) calloc(1, sizeof(cliprdrPlugin));
|
2014-10-16 05:30:11 +04:00
|
|
|
|
2014-11-12 20:56:03 +03:00
|
|
|
cliprdr->channelDef.options =
|
2014-08-19 20:26:39 +04:00
|
|
|
CHANNEL_OPTION_INITIALIZED |
|
|
|
|
CHANNEL_OPTION_ENCRYPT_RDP |
|
|
|
|
CHANNEL_OPTION_COMPRESS_RDP |
|
|
|
|
CHANNEL_OPTION_SHOW_PROTOCOL;
|
2014-10-16 05:30:11 +04:00
|
|
|
|
2014-11-12 20:56:03 +03:00
|
|
|
strcpy(cliprdr->channelDef.name, "cliprdr");
|
2014-10-16 05:30:11 +04:00
|
|
|
|
2014-02-17 02:38:59 +04:00
|
|
|
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP*) pEntryPoints;
|
2013-03-29 22:49:09 +04:00
|
|
|
|
2014-02-17 02:38:59 +04:00
|
|
|
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP)) &&
|
2013-05-13 05:23:12 +04:00
|
|
|
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
|
|
|
|
{
|
2014-02-17 02:27:36 +04:00
|
|
|
context = (CliprdrClientContext*) calloc(1, sizeof(CliprdrClientContext));
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
context->handle = (void*) cliprdr;
|
2014-11-12 20:56:03 +03:00
|
|
|
context->custom = NULL;
|
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
context->ClientCapabilities = cliprdr_client_capabilities;
|
2014-10-24 02:17:53 +04:00
|
|
|
context->TempDirectory = cliprdr_temp_directory;
|
2013-11-24 06:35:44 +04:00
|
|
|
context->ClientFormatList = cliprdr_client_format_list;
|
|
|
|
context->ClientFormatListResponse = cliprdr_client_format_list_response;
|
2014-10-24 02:17:53 +04:00
|
|
|
context->ClientLockClipboardData = cliprdr_client_lock_clipboard_data;
|
|
|
|
context->ClientUnlockClipboardData = cliprdr_client_unlock_clipboard_data;
|
2013-11-24 08:45:31 +04:00
|
|
|
context->ClientFormatDataRequest = cliprdr_client_format_data_request;
|
|
|
|
context->ClientFormatDataResponse = cliprdr_client_format_data_response;
|
2014-10-24 02:17:53 +04:00
|
|
|
context->ClientFileContentsRequest = cliprdr_client_file_contents_request;
|
|
|
|
context->ClientFileContentsResponse = cliprdr_client_file_contents_response;
|
2014-11-12 20:56:03 +03:00
|
|
|
|
2013-05-13 05:23:12 +04:00
|
|
|
*(pEntryPointsEx->ppInterface) = (void*) context;
|
2014-12-27 23:20:29 +03:00
|
|
|
cliprdr->context = context;
|
2013-05-13 05:23:12 +04:00
|
|
|
}
|
2013-03-29 22:49:09 +04:00
|
|
|
|
2014-11-12 20:56:03 +03:00
|
|
|
cliprdr->log = WLog_Get("com.freerdp.channels.cliprdr.client");
|
|
|
|
|
2014-11-20 22:28:05 +03:00
|
|
|
cliprdr->useLongFormatNames = TRUE;
|
|
|
|
cliprdr->streamFileClipEnabled = FALSE;
|
|
|
|
cliprdr->fileClipNoFilePaths = TRUE;
|
|
|
|
cliprdr->canLockClipData = FALSE;
|
|
|
|
|
2014-11-12 20:56:03 +03:00
|
|
|
WLog_Print(cliprdr->log, WLOG_DEBUG, "VirtualChannelEntry");
|
|
|
|
|
|
|
|
CopyMemory(&(cliprdr->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
|
|
|
|
|
2015-01-20 13:45:36 +03:00
|
|
|
rc = cliprdr->channelEntryPoints.pVirtualChannelInit(&cliprdr->InitHandle,
|
2014-11-12 20:56:03 +03:00
|
|
|
&cliprdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, cliprdr_virtual_channel_init_event);
|
2015-01-20 13:45:36 +03:00
|
|
|
if (CHANNEL_RC_OK != rc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
|
|
|
|
WTSErrorToString(rc), rc);
|
|
|
|
free(cliprdr);
|
|
|
|
return -1;
|
|
|
|
}
|
2014-11-12 20:56:03 +03:00
|
|
|
|
|
|
|
cliprdr->channelEntryPoints.pInterface = *(cliprdr->channelEntryPoints.ppInterface);
|
|
|
|
cliprdr->channelEntryPoints.ppInterface = &(cliprdr->channelEntryPoints.pInterface);
|
|
|
|
|
|
|
|
cliprdr_add_init_handle_data(cliprdr->InitHandle, (void*) cliprdr);
|
|
|
|
|
2012-10-09 04:26:11 +04:00
|
|
|
return 1;
|
|
|
|
}
|