cliprdr: add format list ui event.
authorVic Lee <llyzs@163.com>
Tue, 12 Jul 2011 15:06:39 +0000 (23:06 +0800)
committerVic Lee <llyzs@163.com>
Tue, 12 Jul 2011 15:06:39 +0000 (23:06 +0800)
channels/cliprdr/CMakeLists.txt
channels/cliprdr/cliprdr_format.c [new file with mode: 0644]
channels/cliprdr/cliprdr_format.h [new file with mode: 0644]
channels/cliprdr/cliprdr_main.c
cunit/test_cliprdr.c

index c15ce6d..d74f823 100644 (file)
 # 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 (file)
index 0000000..82213b8
--- /dev/null
@@ -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 <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>
+
+#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 (file)
index 0000000..894e12d
--- /dev/null
@@ -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 */
index a46e084..f0e2819 100644 (file)
@@ -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)
index 4504cfb..5836dbd 100644 (file)
@@ -24,6 +24,7 @@
 #include <freerdp/constants.h>
 #include <freerdp/chanman.h>
 #include <freerdp/utils/event.h>
+#include <freerdp/utils/hexdump.h>
 
 #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);
 }