From 3cf644009f96500362953732cb5d9b0c96c03d6f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 8 Apr 2014 15:06:48 -0700 Subject: [PATCH] GUAC-608: Migrate RDP to common clipboard code for outbound data. --- src/protocols/rdp/client.c | 1 + src/protocols/rdp/client.h | 5 ++-- src/protocols/rdp/guac_handlers.c | 1 + src/protocols/rdp/rdp_cliprdr.c | 44 +++++-------------------------- 4 files changed, 12 insertions(+), 39 deletions(-) diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index 0e7fa873..9fc24de7 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -655,6 +655,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_client_data->bounded = FALSE; guac_client_data->mouse_button_mask = 0; guac_client_data->current_surface = GUAC_DEFAULT_LAYER; + guac_client_data->clipboard = guac_common_clipboard_alloc(GUAC_RDP_CLIPBOARD_MAX_LENGTH); guac_client_data->requested_clipboard_format = CB_FORMAT_TEXT; guac_client_data->audio = NULL; guac_client_data->filesystem = NULL; diff --git a/src/protocols/rdp/client.h b/src/protocols/rdp/client.h index c6d242cb..4ffc0515 100644 --- a/src/protocols/rdp/client.h +++ b/src/protocols/rdp/client.h @@ -26,6 +26,7 @@ #include "config.h" +#include "guac_clipboard.h" #include "guac_list.h" #include "rdp_fs.h" #include "rdp_keymap.h" @@ -171,9 +172,9 @@ typedef struct rdp_guac_client_data { guac_rdp_keysym_state_map keysym_state; /** - * The current clipboard contents, in UTF-8. + * The current clipboard contents. */ - char clipboard[GUAC_RDP_CLIPBOARD_MAX_LENGTH]; + guac_common_clipboard* clipboard; /** * The format of the clipboard which was requested. Data received from diff --git a/src/protocols/rdp/guac_handlers.c b/src/protocols/rdp/guac_handlers.c index 5052a8d5..4453d461 100644 --- a/src/protocols/rdp/guac_handlers.c +++ b/src/protocols/rdp/guac_handlers.c @@ -90,6 +90,7 @@ int rdp_guac_client_free_handler(guac_client* client) { guac_common_list_free(guac_client_data->available_svc); /* Free client data */ + guac_common_clipboard_free(guac_client_data->clipboard); cairo_surface_destroy(guac_client_data->opaque_glyph_surface); cairo_surface_destroy(guac_client_data->trans_glyph_surface); free(guac_client_data); diff --git a/src/protocols/rdp/rdp_cliprdr.c b/src/protocols/rdp/rdp_cliprdr.c index 7489267c..a5a7d613 100644 --- a/src/protocols/rdp/rdp_cliprdr.c +++ b/src/protocols/rdp/rdp_cliprdr.c @@ -219,10 +219,11 @@ void guac_rdp_process_cb_data_response(guac_client* client, RDP_CB_DATA_RESPONSE_EVENT* event) { rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data; + char received_data[GUAC_RDP_CLIPBOARD_MAX_LENGTH]; guac_iconv_read* reader; char* input = (char*) event->data; - char* output = client_data->clipboard; + char* output = received_data; /* Find correct source encoding */ switch (client_data->requested_clipboard_format) { @@ -247,43 +248,12 @@ void guac_rdp_process_cb_data_response(guac_client* client, /* Convert send clipboard data */ if (guac_iconv(reader, &input, event->size, - GUAC_WRITE_UTF8, &output, GUAC_RDP_CLIPBOARD_MAX_LENGTH)) { + GUAC_WRITE_UTF8, &output, sizeof(received_data))) { - char* current = client_data->clipboard; - int remaining = GUAC_RDP_CLIPBOARD_MAX_LENGTH; - - /* Begin stream */ - guac_stream* stream = guac_client_alloc_stream(client); - guac_protocol_send_clipboard(client->socket, stream, "text/plain"); - - /* Split clipboard into chunks */ - while (remaining > 0) { - - /* Calculate size of next block */ - int block_size = 4096; - if (remaining < block_size) - block_size = remaining; - - /* If at end of string, send final blob */ - int length = strnlen(current, block_size); - if (length < block_size) { - guac_protocol_send_blob(client->socket, stream, current, length+1); - break; - } - - /* Otherwise, send current blob and continue */ - else - guac_protocol_send_blob(client->socket, stream, current, length); - - /* Next block */ - remaining -= length; - current += length; - - } - - /* End stream */ - guac_protocol_send_end(client->socket, stream); - guac_client_free_stream(client, stream); + int length = strnlen(received_data, sizeof(received_data)); + guac_common_clipboard_reset(client_data->clipboard, "text/plain"); + guac_common_clipboard_append(client_data->clipboard, received_data, length); + guac_common_clipboard_send(client_data->clipboard, client); }