From bbf451a552c76260518c7893a2f6fe55e89837f4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 31 Mar 2014 16:33:23 -0700 Subject: [PATCH] GUAC-584: Handle Unicode data (STUB). Need real conversion code with actual length calculations. --- src/protocols/rdp/rdp_cliprdr.c | 103 ++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 33 deletions(-) diff --git a/src/protocols/rdp/rdp_cliprdr.c b/src/protocols/rdp/rdp_cliprdr.c index 95916c9c..4f98c17a 100644 --- a/src/protocols/rdp/rdp_cliprdr.c +++ b/src/protocols/rdp/rdp_cliprdr.c @@ -24,6 +24,7 @@ #include "client.h" #include "rdp_cliprdr.h" +#include "unicode.h" #include #include @@ -211,49 +212,85 @@ void guac_rdp_process_cb_data_request(guac_client* client, } +static void __guac_rdp_clipboard_send_iso8859_1(guac_client* client, + RDP_CB_DATA_RESPONSE_EVENT* event) { + + rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data; + + /* Ensure data is large enough and has null terminator */ + if (event->size < 1 || event->data[event->size - 1] != '\0') { + guac_client_log_error(client, + "Clipboard data missing null terminator"); + return; + } + + /* Free existing data */ + free(client_data->clipboard); + + /* Store clipboard data */ + client_data->clipboard = strdup((char*) event->data); + + /* Send clipboard data */ + guac_protocol_send_clipboard(client->socket, client_data->clipboard); + +} + +static void __guac_rdp_clipboard_send_utf16(guac_client* client, + RDP_CB_DATA_RESPONSE_EVENT* event) { + + rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data; + int output_length; + + /* Ensure data is large enough and has null terminator */ + if (event->size < 2 + || event->data[event->size - 2] != '\0' + || event->data[event->size - 1] != '\0') { + guac_client_log_error(client, + "Clipboard data missing null terminator"); + return; + } + + /* Free existing data */ + free(client_data->clipboard); + + /* Store clipboard data */ + output_length = event->size * 3; + client_data->clipboard = malloc(output_length); + guac_rdp_utf16_to_utf8(event->data, event->size/2, + client_data->clipboard, output_length); + + /* Send clipboard data */ + guac_protocol_send_clipboard(client->socket, client_data->clipboard); + +} + 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; - /* Received clipboard data */ - if (event->data[event->size - 1] == '\0') { + /* Convert to UTF-8 based on format */ + switch (client_data->requested_clipboard_format) { - /* Convert to UTF-8 based on format */ - switch (client_data->requested_clipboard_format) { + /* Non-Unicode */ + case CB_FORMAT_TEXT: + guac_client_log_info(client, "STUB: Copy non-unicode"); + __guac_rdp_clipboard_send_iso8859_1(client, event); + break; - /* Non-Unicode */ - case CB_FORMAT_TEXT: - guac_client_log_info(client, "STUB: Copy non-unicode"); - break; + /* Unicode (UTF-16) */ + case CB_FORMAT_UNICODETEXT: + guac_client_log_info(client, "STUB: Copy unicode"); + __guac_rdp_clipboard_send_utf16(client, event); + break; - /* Unicode (UTF-16) */ - case CB_FORMAT_UNICODETEXT: - guac_client_log_info(client, "STUB: Copy unicode"); - break; - - default: - guac_client_log_error(client, "Requested clipboard data in " - "unsupported format %i", - client_data->requested_clipboard_format); - return; - - } - - /* Free existing data */ - free(((rdp_guac_client_data*) client->data)->clipboard); - - /* Store clipboard data */ - ((rdp_guac_client_data*) client->data)->clipboard = - strdup((char*) event->data); - - /* Send clipboard data */ - guac_protocol_send_clipboard(client->socket, (char*) event->data); + default: + guac_client_log_error(client, "Requested clipboard data in " + "unsupported format %i", + client_data->requested_clipboard_format); + return; } - else - guac_client_log_error(client, - "Clipboard data missing null terminator"); }