From 11303e0813025660e8fe3465ec2402acc111ae59 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 29 Apr 2012 23:28:29 -0700 Subject: [PATCH] Write support in clipboard. --- protocols/rdp/include/guac_handlers.h | 1 + protocols/rdp/include/rdp_cliprdr.h | 4 ++- protocols/rdp/src/client.c | 1 + protocols/rdp/src/guac_handlers.c | 25 +++++++++++++++++ protocols/rdp/src/rdp_cliprdr.c | 40 ++++++++++++++++++++++++--- 5 files changed, 66 insertions(+), 5 deletions(-) diff --git a/protocols/rdp/include/guac_handlers.h b/protocols/rdp/include/guac_handlers.h index e7914fac..5e9ccee3 100644 --- a/protocols/rdp/include/guac_handlers.h +++ b/protocols/rdp/include/guac_handlers.h @@ -44,6 +44,7 @@ int rdp_guac_client_free_handler(guac_client* client); int rdp_guac_client_handle_messages(guac_client* client); int rdp_guac_client_mouse_handler(guac_client* client, int x, int y, int mask); int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed); +int rdp_guac_client_clipboard_handler(guac_client* client, char* data); #endif diff --git a/protocols/rdp/include/rdp_cliprdr.h b/protocols/rdp/include/rdp_cliprdr.h index f86dd093..be838c4a 100644 --- a/protocols/rdp/include/rdp_cliprdr.h +++ b/protocols/rdp/include/rdp_cliprdr.h @@ -46,7 +46,9 @@ void guac_rdp_process_cb_monitor_ready(guac_client* client, RDP_EVENT* event); void guac_rdp_process_cb_format_list(guac_client* client, RDP_CB_FORMAT_LIST_EVENT* event); -void guac_rdp_process_cb_data_request(guac_client* client, RDP_EVENT* event); +void guac_rdp_process_cb_data_request(guac_client* client, + RDP_CB_DATA_REQUEST_EVENT* event); + void guac_rdp_process_cb_data_response(guac_client* client, RDP_CB_DATA_RESPONSE_EVENT* event); diff --git a/protocols/rdp/src/client.c b/protocols/rdp/src/client.c index 930f55cb..e8c511f4 100644 --- a/protocols/rdp/src/client.c +++ b/protocols/rdp/src/client.c @@ -199,6 +199,7 @@ boolean rdp_freerdp_post_connect(freerdp* instance) { client->handle_messages = rdp_guac_client_handle_messages; client->mouse_handler = rdp_guac_client_mouse_handler; client->key_handler = rdp_guac_client_key_handler; + client->clipboard_handler = rdp_guac_client_clipboard_handler; return true; diff --git a/protocols/rdp/src/guac_handlers.c b/protocols/rdp/src/guac_handlers.c index 671fd8f2..e5977f2c 100644 --- a/protocols/rdp/src/guac_handlers.c +++ b/protocols/rdp/src/guac_handlers.c @@ -409,3 +409,28 @@ int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) { } +int rdp_guac_client_clipboard_handler(guac_client* client, char* data) { + + rdpChannels* channels = + ((rdp_guac_client_data*) client->data)->rdp_inst->context->channels; + + RDP_CB_FORMAT_LIST_EVENT* format_list = + (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new( + RDP_EVENT_CLASS_CLIPRDR, + RDP_EVENT_TYPE_CB_FORMAT_LIST, + NULL, NULL); + + /* Store data in client */ + ((rdp_guac_client_data*) client->data)->clipboard = strdup(data); + + /* Notify server that text data is now available */ + format_list->formats = (uint32*) malloc(sizeof(uint32)); + format_list->formats[0] = CB_FORMAT_TEXT; + format_list->num_formats = 1; + + freerdp_channels_send_event(channels, (RDP_EVENT*) format_list); + + return 0; + +} + diff --git a/protocols/rdp/src/rdp_cliprdr.c b/protocols/rdp/src/rdp_cliprdr.c index 44318bbd..7770ef9f 100644 --- a/protocols/rdp/src/rdp_cliprdr.c +++ b/protocols/rdp/src/rdp_cliprdr.c @@ -60,7 +60,8 @@ void guac_rdp_process_cliprdr_event(guac_client* client, RDP_EVENT* event) { break; case RDP_EVENT_TYPE_CB_DATA_REQUEST: - guac_rdp_process_cb_data_request(client, event); + guac_rdp_process_cb_data_request(client, + (RDP_CB_DATA_REQUEST_EVENT*) event); break; case RDP_EVENT_TYPE_CB_DATA_RESPONSE: @@ -135,9 +136,40 @@ void guac_rdp_process_cb_format_list(guac_client* client, } -void guac_rdp_process_cb_data_request(guac_client* client, RDP_EVENT* event) { - /* STUB */ - guac_client_log_info(client, "data_request"); +void guac_rdp_process_cb_data_request(guac_client* client, + RDP_CB_DATA_REQUEST_EVENT* event) { + + rdpChannels* channels = + ((rdp_guac_client_data*) client->data)->rdp_inst->context->channels; + + /* If text requested, send clipboard text contents */ + if (event->format == CB_FORMAT_TEXT) { + + /* Get clipboard data */ + const char* clipboard = + ((rdp_guac_client_data*) client->data)->clipboard; + + /* Create new data response */ + RDP_CB_DATA_RESPONSE_EVENT* data_response = + (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new( + RDP_EVENT_CLASS_CLIPRDR, + RDP_EVENT_TYPE_CB_DATA_RESPONSE, + NULL, NULL); + + /* Set data and length */ + data_response->data = (uint8*) strdup(clipboard); + data_response->size = strlen(clipboard) + 1; + + /* Send response */ + freerdp_channels_send_event(channels, (RDP_EVENT*) data_response); + + } + + /* Otherwise ... failure */ + else + guac_client_log_error(client, + "Server requested unsupported clipboard data type"); + } void guac_rdp_process_cb_data_response(guac_client* client,