From 4fc7794ae998fe53fc04f51aea0e897240447cb7 Mon Sep 17 00:00:00 2001 From: Vic Lee Date: Tue, 12 Jul 2011 23:06:39 +0800 Subject: [PATCH] cliprdr: add format list ui event. --- channels/cliprdr/CMakeLists.txt | 4 ++ channels/cliprdr/cliprdr_format.c | 76 +++++++++++++++++++++++++++++++ channels/cliprdr/cliprdr_format.h | 26 +++++++++++ channels/cliprdr/cliprdr_main.c | 12 +++++ cunit/test_cliprdr.c | 25 ++++++++++ 5 files changed, 143 insertions(+) create mode 100644 channels/cliprdr/cliprdr_format.c create mode 100644 channels/cliprdr/cliprdr_format.h diff --git a/channels/cliprdr/CMakeLists.txt b/channels/cliprdr/CMakeLists.txt index c15ce6dda..d74f823f2 100644 --- a/channels/cliprdr/CMakeLists.txt +++ b/channels/cliprdr/CMakeLists.txt @@ -18,7 +18,11 @@ # limitations under the License. set(CLIPRDR_SRCS + cliprdr_constants.h + cliprdr_format.c + cliprdr_format.h cliprdr_main.c + cliprdr_main.h ) add_library(cliprdr SHARED ${CLIPRDR_SRCS}) diff --git a/channels/cliprdr/cliprdr_format.c b/channels/cliprdr/cliprdr_format.c new file mode 100644 index 000000000..82213b81a --- /dev/null +++ b/channels/cliprdr/cliprdr_format.c @@ -0,0 +1,76 @@ +/** + * 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 +#include +#include +#include +#include +#include +#include + +#include "cliprdr_constants.h" +#include "cliprdr_main.h" +#include "cliprdr_format.h" + +#define CFSTR_HTML "HTML Format" +#define CFSTR_PNG "PNG" +#define CFSTR_JPEG "JFIF" +#define CFSTR_GIF "GIF" + +static void cliprdr_copy_format_name(char* dest, const char* src) +{ + while (*src) + { + *dest = *src++; + dest += 2; + } +} + +void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, FRDP_CB_FORMAT_LIST_EVENT* cb_event) +{ + STREAM* data_out; + int i; + + data_out = cliprdr_packet_new(CB_FORMAT_LIST, 0, 36 * cb_event->num_formats); + + for (i = 0; i < cb_event->num_formats; i++) + { + stream_write_uint32(data_out, cb_event->formats[i]); + switch (cb_event->formats[i]) + { + case CB_FORMAT_HTML: + cliprdr_copy_format_name(stream_get_tail(data_out), CFSTR_HTML); + break; + case CB_FORMAT_PNG: + cliprdr_copy_format_name(stream_get_tail(data_out), CFSTR_PNG); + break; + case CB_FORMAT_JPEG: + cliprdr_copy_format_name(stream_get_tail(data_out), CFSTR_JPEG); + break; + case CB_FORMAT_GIF: + cliprdr_copy_format_name(stream_get_tail(data_out), CFSTR_GIF); + break; + } + stream_seek(data_out, 32); + } + + cliprdr_packet_send(cliprdr, data_out); +} diff --git a/channels/cliprdr/cliprdr_format.h b/channels/cliprdr/cliprdr_format.h new file mode 100644 index 000000000..894e12d73 --- /dev/null +++ b/channels/cliprdr/cliprdr_format.h @@ -0,0 +1,26 @@ +/** + * 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. + */ + +#ifndef __CLIPRDR_FORMAT_H +#define __CLIPRDR_FORMAT_H + +void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, FRDP_CB_FORMAT_LIST_EVENT* cb_event); + +#endif /* __CLIPRDR_FORMAT_H */ diff --git a/channels/cliprdr/cliprdr_main.c b/channels/cliprdr/cliprdr_main.c index a46e0849b..f0e2819b1 100644 --- a/channels/cliprdr/cliprdr_main.c +++ b/channels/cliprdr/cliprdr_main.c @@ -28,6 +28,7 @@ #include "cliprdr_constants.h" #include "cliprdr_main.h" +#include "cliprdr_format.h" STREAM* cliprdr_packet_new(uint16 msgType, uint16 msgFlags, uint32 dataLen) { @@ -128,6 +129,17 @@ static void cliprdr_process_receive(rdpSvcPlugin* plugin, STREAM* data_in) static void cliprdr_process_event(rdpSvcPlugin* plugin, FRDP_EVENT* event) { + switch (event->event_type) + { + case FRDP_EVENT_TYPE_CB_FORMAT_LIST: + cliprdr_process_format_list_event((cliprdrPlugin*)plugin, (FRDP_CB_FORMAT_LIST_EVENT*)event); + break; + + default: + DEBUG_WARN("unknown event type %d", event->event_type); + break; + } + freerdp_event_free(event); } static void cliprdr_process_terminate(rdpSvcPlugin* plugin) diff --git a/cunit/test_cliprdr.c b/cunit/test_cliprdr.c index 4504cfbdf..5836dbd77 100644 --- a/cunit/test_cliprdr.c +++ b/cunit/test_cliprdr.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "test_cliprdr.h" @@ -62,6 +63,15 @@ static const uint8 test_monitor_ready_data[] = static int test_rdp_channel_data(rdpInst* inst, int chan_id, char* data, int data_size) { printf("chan_id %d data_size %d\n", chan_id, data_size); + freerdp_hexdump(data, data_size); +} + +static int event_processed; + +static void event_process_callback(FRDP_EVENT* event) +{ + printf("Event %d processed.\n", event->event_type); + event_processed = 1; } void test_cliprdr(void) @@ -70,6 +80,7 @@ void test_cliprdr(void) rdpSettings settings = { 0 }; rdpInst inst = { 0 }; FRDP_EVENT* event; + FRDP_CB_FORMAT_LIST_EVENT* format_list_event; settings.hostname = "testhost"; inst.settings = &settings; @@ -95,6 +106,20 @@ void test_cliprdr(void) CU_ASSERT(event->event_type == FRDP_EVENT_TYPE_CB_SYNC); freerdp_event_free(event); + event = freerdp_event_new(FRDP_EVENT_TYPE_CB_FORMAT_LIST, event_process_callback, NULL); + format_list_event = (FRDP_CB_FORMAT_LIST_EVENT*)event; + format_list_event->num_formats = 2; + format_list_event->formats = (uint32*)xmalloc(sizeof(uint32) * 2); + format_list_event->formats[0] = CB_FORMAT_TEXT; + format_list_event->formats[1] = CB_FORMAT_HTML; + + event_processed = 0; + freerdp_chanman_send_event(chan_man, "cliprdr", event); + while (!event_processed) + { + freerdp_chanman_check_fds(chan_man, &inst); + } + freerdp_chanman_close(chan_man, &inst); freerdp_chanman_free(chan_man); }