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
|
|
|
|
|
2011-07-12 13:06:14 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
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>
|
2011-07-12 13:06:14 +04:00
|
|
|
#include <freerdp/utils/svc_plugin.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
|
|
|
|
2011-12-01 04:11:27 +04:00
|
|
|
static 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;
|
|
|
|
rdpSvcPlugin* plugin = (rdpSvcPlugin*) cliprdr;
|
|
|
|
pInterface = (CliprdrClientContext*) *(plugin->channel_entry_points.ppInterface);
|
|
|
|
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;
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, dataLen + 8);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, msgType);
|
|
|
|
Stream_Write_UINT16(s, msgFlags);
|
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);
|
2011-07-12 13:06:14 +04: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;
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(s);
|
2011-07-12 13:06:14 +04:00
|
|
|
dataLen = pos - 8;
|
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);
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2013-08-18 23:39:28 +04:00
|
|
|
#ifdef WITH_DEBUG_CLIPRDR
|
|
|
|
printf("Cliprdr Sending (%d bytes)\n", dataLen + 8);
|
|
|
|
winpr_HexDump(Stream_Buffer(s), dataLen + 8);
|
|
|
|
#endif
|
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
svc_plugin_send((rdpSvcPlugin*) cliprdr, s);
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cliprdr_process_connect(rdpSvcPlugin* plugin)
|
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
DEBUG_CLIPRDR("connecting");
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void cliprdr_print_general_capability_flags(UINT32 flags)
|
2011-11-01 03:15:27 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "generalFlags (0x%08X) {\n", flags);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
|
|
|
if (flags & CB_USE_LONG_FORMAT_NAMES)
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "\tCB_USE_LONG_FORMAT_NAMES\n");
|
2011-11-01 03:15:27 +04:00
|
|
|
if (flags & CB_STREAM_FILECLIP_ENABLED)
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "\tCB_STREAM_FILECLIP_ENABLED\n");
|
2011-11-01 03:15:27 +04:00
|
|
|
if (flags & CB_FILECLIP_NO_FILE_PATHS)
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "\tCB_FILECLIP_NO_FILE_PATHS\n");
|
2011-11-01 03:15:27 +04:00
|
|
|
if (flags & CB_CAN_LOCK_CLIPDATA)
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "\tCB_CAN_LOCK_CLIPDATA\n");
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "}\n");
|
2011-11-01 03:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void 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;
|
2013-11-24 06:35:44 +04:00
|
|
|
CliprdrClientContext* context;
|
|
|
|
|
|
|
|
context = cliprdr_get_client_interface(cliprdr);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, version); /* version (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, generalFlags); /* generalFlags (4 bytes) */
|
2011-11-01 03:15:27 +04:00
|
|
|
|
|
|
|
DEBUG_CLIPRDR("Version: %d", version);
|
|
|
|
|
|
|
|
#ifdef WITH_DEBUG_CLIPRDR
|
|
|
|
cliprdr_print_general_capability_flags(generalFlags);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (generalFlags & CB_USE_LONG_FORMAT_NAMES)
|
2012-10-09 10:31:28 +04:00
|
|
|
cliprdr->use_long_format_names = TRUE;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
|
|
|
if (generalFlags & CB_STREAM_FILECLIP_ENABLED)
|
2012-10-09 10:31:28 +04:00
|
|
|
cliprdr->stream_fileclip_enabled = TRUE;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
|
|
|
if (generalFlags & CB_FILECLIP_NO_FILE_PATHS)
|
2012-10-09 10:31:28 +04:00
|
|
|
cliprdr->fileclip_no_file_paths = TRUE;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
|
|
|
if (generalFlags & CB_CAN_LOCK_CLIPDATA)
|
2012-10-09 10:31:28 +04:00
|
|
|
cliprdr->can_lock_clipdata = TRUE;
|
2011-11-18 04:51:30 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
cliprdr->received_caps = TRUE;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
if (context->custom)
|
|
|
|
{
|
|
|
|
CLIPRDR_CAPABILITIES capabilities;
|
|
|
|
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
|
|
|
|
|
|
|
|
capabilities.cCapabilitiesSets = 1;
|
|
|
|
capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &(generalCapabilitySet);
|
|
|
|
|
|
|
|
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
|
|
|
|
generalCapabilitySet.capabilitySetLength = 12;
|
2013-11-05 06:52:17 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
generalCapabilitySet.version = version;
|
|
|
|
generalCapabilitySet.generalFlags = generalFlags;
|
|
|
|
|
|
|
|
if (context->ServerCapabilities)
|
|
|
|
context->ServerCapabilities(context, &capabilities);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RDP_CB_CLIP_CAPS* caps_event;
|
|
|
|
|
|
|
|
caps_event = (RDP_CB_CLIP_CAPS*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_ClipCaps, NULL, NULL);
|
|
|
|
caps_event->capabilities = generalFlags;
|
|
|
|
|
|
|
|
svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (wMessage*) caps_event);
|
|
|
|
}
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, wStream* s, UINT16 length, UINT16 flags)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
int i;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 lengthCapability;
|
|
|
|
UINT16 cCapabilitiesSets;
|
|
|
|
UINT16 capabilitySetType;
|
2011-11-01 03:15:27 +04: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) */
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
DEBUG_CLIPRDR("cCapabilitiesSets %d", cCapabilitiesSets);
|
|
|
|
|
|
|
|
for (i = 0; i < cCapabilitiesSets; i++)
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_WARN("unknown cliprdr capability set: %d", capabilitySetType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cliprdr_send_clip_caps(cliprdrPlugin* cliprdr)
|
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 flags;
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-11-18 04:51:30 +04:00
|
|
|
DEBUG_CLIPRDR("Sending Capabilities");
|
|
|
|
|
|
|
|
flags = CB_USE_LONG_FORMAT_NAMES;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, 1); /* cCapabilitiesSets */
|
|
|
|
Stream_Write_UINT16(s, 0); /* pad1 */
|
|
|
|
Stream_Write_UINT16(s, CB_CAPSTYPE_GENERAL); /* capabilitySetType */
|
|
|
|
Stream_Write_UINT16(s, CB_CAPSTYPE_GENERAL_LEN); /* lengthCapability */
|
|
|
|
Stream_Write_UINT32(s, CB_CAPS_VERSION_2); /* version */
|
|
|
|
Stream_Write_UINT32(s, flags); /* generalFlags */
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
cliprdr_packet_send(cliprdr, s);
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, wStream* s, UINT16 length, UINT16 flags)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
2013-11-24 06:35:44 +04:00
|
|
|
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
|
|
|
|
|
|
|
|
if (context->custom)
|
|
|
|
{
|
|
|
|
CLIPRDR_MONITOR_READY monitorReady;
|
2011-07-12 18:09:56 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
monitorReady.msgType = CB_MONITOR_READY;
|
|
|
|
monitorReady.msgFlags = flags;
|
|
|
|
monitorReady.dataLen = length;
|
2011-07-12 18:09:56 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
if (context->MonitorReady)
|
|
|
|
context->MonitorReady(context, &monitorReady);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RDP_CB_MONITOR_READY_EVENT* event;
|
|
|
|
|
|
|
|
if (cliprdr->received_caps)
|
|
|
|
cliprdr_send_clip_caps(cliprdr);
|
2013-03-29 02:29:57 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
event = (RDP_CB_MONITOR_READY_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_MonitorReady, NULL, NULL);
|
|
|
|
|
|
|
|
svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (wMessage*) event);
|
|
|
|
}
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void cliprdr_process_receive(rdpSvcPlugin* plugin, 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;
|
2011-11-01 03:15:27 +04:00
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) plugin;
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, msgType);
|
|
|
|
Stream_Read_UINT16(s, msgFlags);
|
|
|
|
Stream_Read_UINT32(s, dataLen);
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
DEBUG_CLIPRDR("msgType: %s (%d), msgFlags: %d dataLen: %d",
|
2011-11-18 04:51:30 +04:00
|
|
|
CB_MSG_TYPE_STRINGS[msgType], msgType, msgFlags, dataLen);
|
2013-11-25 05:46:56 +04:00
|
|
|
|
2013-08-18 23:39:28 +04:00
|
|
|
#ifdef WITH_DEBUG_CLIPRDR
|
|
|
|
winpr_HexDump(Stream_Buffer(s), dataLen + 8);
|
|
|
|
#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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
2011-07-12 13:06:14 +04:00
|
|
|
default:
|
|
|
|
DEBUG_WARN("unknown msgType %d", msgType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
static void cliprdr_process_event(rdpSvcPlugin* plugin, wMessage* event)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
2013-03-29 04:23:16 +04:00
|
|
|
switch (GetMessageType(event->id))
|
2011-07-12 19:06:39 +04:00
|
|
|
{
|
2013-03-29 02:29:57 +04:00
|
|
|
case CliprdrChannel_FormatList:
|
2011-11-18 04:51:30 +04:00
|
|
|
cliprdr_process_format_list_event((cliprdrPlugin*) plugin, (RDP_CB_FORMAT_LIST_EVENT*) event);
|
2011-07-12 19:06:39 +04:00
|
|
|
break;
|
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
case CliprdrChannel_DataRequest:
|
2011-11-18 04:51:30 +04:00
|
|
|
cliprdr_process_format_data_request_event((cliprdrPlugin*) plugin, (RDP_CB_DATA_REQUEST_EVENT*) event);
|
2011-07-12 20:50:00 +04:00
|
|
|
break;
|
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
case CliprdrChannel_DataResponse:
|
2011-11-18 04:51:30 +04:00
|
|
|
cliprdr_process_format_data_response_event((cliprdrPlugin*) plugin, (RDP_CB_DATA_RESPONSE_EVENT*) event);
|
2011-07-12 20:30:25 +04:00
|
|
|
break;
|
|
|
|
|
2011-07-12 19:06:39 +04:00
|
|
|
default:
|
2013-03-29 04:23:16 +04:00
|
|
|
DEBUG_WARN("unknown event type %d", GetMessageType(event->id));
|
2011-07-12 19:06:39 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-11-18 04:51:30 +04:00
|
|
|
|
2011-07-12 19:06:39 +04:00
|
|
|
freerdp_event_free(event);
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cliprdr_process_terminate(rdpSvcPlugin* plugin)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(plugin);
|
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;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, 1); /* cCapabilitiesSets */
|
|
|
|
Stream_Write_UINT16(s, 0); /* pad1 */
|
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
2013-03-29 22:49:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
int index;
|
|
|
|
wStream* s;
|
|
|
|
int length = 0;
|
|
|
|
int formatNameSize;
|
|
|
|
CLIPRDR_FORMAT* format;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
|
|
|
|
|
|
|
for (index = 0; index < formatList->cFormats; index++)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(CB_FORMAT_LIST, 0, length);
|
|
|
|
|
|
|
|
for (index = 0; index < formatList->cFormats; index++)
|
|
|
|
{
|
|
|
|
format = (CLIPRDR_FORMAT*) &(formatList->formats[index]);
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */
|
|
|
|
|
|
|
|
if (format->formatName)
|
|
|
|
{
|
|
|
|
int cchWideChar;
|
|
|
|
LPWSTR lpWideCharStr;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cliprdr_client_format_list_response(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
|
|
|
|
|
|
|
|
formatListResponse->msgType = CB_FORMAT_LIST_RESPONSE;
|
|
|
|
formatListResponse->dataLen = 0;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(formatListResponse->msgType, formatListResponse->msgFlags, formatListResponse->dataLen);
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
2013-03-29 22:49:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(formatDataRequest->msgType, formatDataRequest->msgFlags, formatDataRequest->dataLen);
|
|
|
|
Stream_Write_UINT32(s, formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
formatDataResponse->msgType = CB_FORMAT_DATA_RESPONSE;
|
|
|
|
|
|
|
|
s = cliprdr_packet_new(formatDataResponse->msgType, formatDataResponse->msgFlags, formatDataResponse->dataLen);
|
|
|
|
Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->dataLen);
|
|
|
|
|
|
|
|
cliprdr_packet_send(cliprdr, s);
|
|
|
|
|
2013-03-29 22:49:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2012-11-01 07:04:31 +04:00
|
|
|
int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
|
2012-10-09 04:26:11 +04:00
|
|
|
{
|
2013-11-24 06:35:44 +04:00
|
|
|
cliprdrPlugin* cliprdr;
|
2013-03-29 22:49:09 +04:00
|
|
|
CliprdrClientContext* context;
|
2013-05-13 05:23:12 +04:00
|
|
|
CHANNEL_ENTRY_POINTS_EX* pEntryPointsEx;
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
cliprdr = (cliprdrPlugin*) malloc(sizeof(cliprdrPlugin));
|
|
|
|
ZeroMemory(cliprdr, sizeof(cliprdrPlugin));
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
cliprdr->plugin.channel_def.options =
|
2012-10-09 04:26:11 +04:00
|
|
|
CHANNEL_OPTION_INITIALIZED |
|
|
|
|
CHANNEL_OPTION_ENCRYPT_RDP |
|
|
|
|
CHANNEL_OPTION_COMPRESS_RDP |
|
|
|
|
CHANNEL_OPTION_SHOW_PROTOCOL;
|
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
strcpy(cliprdr->plugin.channel_def.name, "cliprdr");
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
cliprdr->plugin.connect_callback = cliprdr_process_connect;
|
|
|
|
cliprdr->plugin.receive_callback = cliprdr_process_receive;
|
|
|
|
cliprdr->plugin.event_callback = cliprdr_process_event;
|
|
|
|
cliprdr->plugin.terminate_callback = cliprdr_process_terminate;
|
2012-10-09 04:26:11 +04:00
|
|
|
|
2013-05-13 05:23:12 +04:00
|
|
|
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_EX*) pEntryPoints;
|
2013-03-29 22:49:09 +04:00
|
|
|
|
2013-05-13 05:23:12 +04:00
|
|
|
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_EX)) &&
|
|
|
|
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
|
|
|
|
{
|
|
|
|
context = (CliprdrClientContext*) malloc(sizeof(CliprdrClientContext));
|
2013-11-24 06:35:44 +04:00
|
|
|
ZeroMemory(context, sizeof(CliprdrClientContext));
|
|
|
|
|
|
|
|
context->handle = (void*) cliprdr;
|
2013-05-13 05:23:12 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
context->ClientCapabilities = cliprdr_client_capabilities;
|
|
|
|
context->ClientFormatList = cliprdr_client_format_list;
|
|
|
|
context->ClientFormatListResponse = cliprdr_client_format_list_response;
|
2013-11-24 08:45:31 +04:00
|
|
|
context->ClientFormatDataRequest = cliprdr_client_format_data_request;
|
|
|
|
context->ClientFormatDataResponse = cliprdr_client_format_data_response;
|
2013-03-29 22:49:09 +04:00
|
|
|
|
2013-05-13 05:23:12 +04:00
|
|
|
*(pEntryPointsEx->ppInterface) = (void*) context;
|
|
|
|
}
|
2013-03-29 22:49:09 +04:00
|
|
|
|
2013-11-24 06:35:44 +04:00
|
|
|
svc_plugin_init((rdpSvcPlugin*) cliprdr, pEntryPoints);
|
2012-10-09 04:26:11 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|