FreeRDP/channels/cliprdr/cliprdr_main.c

178 lines
4.5 KiB
C
Raw Normal View History

2011-07-12 13:06:14 +04:00
/**
* FreeRDP: A Remote Desktop Protocol client.
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <freerdp/constants.h>
#include <freerdp/types.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/svc_plugin.h>
2011-08-11 07:07:03 +04:00
#include <freerdp/plugins/cliprdr.h>
2011-07-12 13:06:14 +04:00
#include "cliprdr_constants.h"
#include "cliprdr_main.h"
2011-07-12 19:06:39 +04:00
#include "cliprdr_format.h"
2011-07-12 13:06:14 +04:00
STREAM* cliprdr_packet_new(uint16 msgType, uint16 msgFlags, uint32 dataLen)
{
2011-09-23 07:37:17 +04:00
STREAM* s;
2011-07-12 13:06:14 +04:00
2011-09-23 07:37:17 +04:00
s = stream_new(dataLen + 8);
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. */
2011-09-23 07:37:17 +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
}
2011-09-23 07:37:17 +04:00
void cliprdr_packet_send(cliprdrPlugin* cliprdr, STREAM* s)
2011-07-12 13:06:14 +04:00
{
int pos;
uint32 dataLen;
2011-09-23 07:37:17 +04:00
pos = stream_get_pos(s);
2011-07-12 13:06:14 +04:00
dataLen = pos - 8;
2011-09-23 07:37:17 +04:00
stream_set_pos(s, 4);
stream_write_uint32(s, dataLen);
stream_set_pos(s, pos);
2011-07-12 13:06:14 +04:00
2011-09-23 07:37:17 +04:00
svc_plugin_send((rdpSvcPlugin*)cliprdr, s);
2011-07-12 13:06:14 +04:00
}
static void cliprdr_process_connect(rdpSvcPlugin* plugin)
{
DEBUG_SVC("connecting");
}
2011-09-23 07:37:17 +04:00
static void cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, STREAM* s)
2011-07-12 13:06:14 +04:00
{
uint16 cCapabilitiesSets;
2011-09-23 07:37:17 +04:00
stream_read_uint16(s, cCapabilitiesSets);
2011-07-12 13:06:14 +04:00
DEBUG_SVC("cCapabilitiesSets %d", cCapabilitiesSets);
}
static void cliprdr_send_clip_caps(cliprdrPlugin* cliprdr)
{
2011-09-23 07:37:17 +04:00
STREAM* s;
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-09-23 07:37:17 +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, 0); /* 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
}
static void cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr)
{
2011-08-18 01:28:26 +04:00
RDP_EVENT* event;
2011-07-12 18:09:56 +04:00
2011-07-12 13:06:14 +04:00
cliprdr_send_clip_caps(cliprdr);
2011-07-12 18:09:56 +04:00
2011-08-18 01:28:26 +04:00
event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_SYNC, NULL, NULL);
2011-07-12 18:09:56 +04:00
svc_plugin_send_event((rdpSvcPlugin*)cliprdr, event);
2011-07-12 13:06:14 +04:00
}
2011-09-23 07:37:17 +04:00
static void cliprdr_process_receive(rdpSvcPlugin* plugin, STREAM* s)
2011-07-12 13:06:14 +04:00
{
cliprdrPlugin* cliprdr = (cliprdrPlugin*)plugin;
uint16 msgType;
uint16 msgFlags;
uint32 dataLen;
2011-09-23 07:37:17 +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
DEBUG_SVC("msgType %d msgFlags %d dataLen %d", msgType, msgFlags, dataLen);
switch (msgType)
{
case CB_CLIP_CAPS:
2011-09-23 07:37:17 +04:00
cliprdr_process_clip_caps(cliprdr, s);
2011-07-12 13:06:14 +04:00
break;
case CB_MONITOR_READY:
cliprdr_process_monitor_ready(cliprdr);
break;
2011-07-12 19:53:54 +04:00
case CB_FORMAT_LIST:
2011-09-23 07:37:17 +04:00
cliprdr_process_format_list(cliprdr, s, dataLen);
2011-07-12 19:53:54 +04:00
break;
case CB_FORMAT_LIST_RESPONSE:
2011-09-23 07:37:17 +04:00
cliprdr_process_format_list_response(cliprdr, msgFlags);
break;
case CB_FORMAT_DATA_REQUEST:
2011-09-23 07:37:17 +04:00
cliprdr_process_format_data_request(cliprdr, s);
break;
case CB_FORMAT_DATA_RESPONSE:
2011-09-23 07:37:17 +04:00
cliprdr_process_format_data_response(cliprdr, s, dataLen);
break;
2011-07-12 13:06:14 +04:00
default:
DEBUG_WARN("unknown msgType %d", msgType);
break;
}
2011-09-23 07:37:17 +04:00
stream_free(s);
2011-07-12 13:06:14 +04:00
}
2011-08-18 01:28:26 +04:00
static void cliprdr_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event)
2011-07-12 13:06:14 +04:00
{
2011-07-12 19:06:39 +04:00
switch (event->event_type)
{
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_CB_FORMAT_LIST:
cliprdr_process_format_list_event((cliprdrPlugin*)plugin, (RDP_CB_FORMAT_LIST_EVENT*)event);
2011-07-12 19:06:39 +04:00
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_CB_DATA_REQUEST:
cliprdr_process_format_data_request_event((cliprdrPlugin*)plugin, (RDP_CB_DATA_REQUEST_EVENT*)event);
break;
2011-08-18 01:28:26 +04:00
case RDP_EVENT_TYPE_CB_DATA_RESPONSE:
cliprdr_process_format_data_response_event((cliprdrPlugin*)plugin, (RDP_CB_DATA_RESPONSE_EVENT*)event);
break;
2011-07-12 19:06:39 +04:00
default:
DEBUG_WARN("unknown event type %d", event->event_type);
break;
}
freerdp_event_free(event);
2011-07-12 13:06:14 +04:00
}
static void cliprdr_process_terminate(rdpSvcPlugin* plugin)
{
xfree(plugin);
}
DEFINE_SVC_PLUGIN(cliprdr, "cliprdr",
CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL)