GUAC-584: Handle Unicode data (STUB). Need real conversion code with actual length calculations.

This commit is contained in:
Michael Jumper 2014-03-31 16:33:23 -07:00
parent 0b414ed9b5
commit bbf451a552

View File

@ -24,6 +24,7 @@
#include "client.h" #include "client.h"
#include "rdp_cliprdr.h" #include "rdp_cliprdr.h"
#include "unicode.h"
#include <freerdp/channels/channels.h> #include <freerdp/channels/channels.h>
#include <freerdp/freerdp.h> #include <freerdp/freerdp.h>
@ -211,13 +212,62 @@ void guac_rdp_process_cb_data_request(guac_client* client,
} }
void guac_rdp_process_cb_data_response(guac_client* client, static void __guac_rdp_clipboard_send_iso8859_1(guac_client* client,
RDP_CB_DATA_RESPONSE_EVENT* event) { RDP_CB_DATA_RESPONSE_EVENT* event) {
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data; rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
/* Received clipboard data */ /* Ensure data is large enough and has null terminator */
if (event->data[event->size - 1] == '\0') { 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;
/* Convert to UTF-8 based on format */ /* Convert to UTF-8 based on format */
switch (client_data->requested_clipboard_format) { switch (client_data->requested_clipboard_format) {
@ -225,11 +275,13 @@ void guac_rdp_process_cb_data_response(guac_client* client,
/* Non-Unicode */ /* Non-Unicode */
case CB_FORMAT_TEXT: case CB_FORMAT_TEXT:
guac_client_log_info(client, "STUB: Copy non-unicode"); guac_client_log_info(client, "STUB: Copy non-unicode");
__guac_rdp_clipboard_send_iso8859_1(client, event);
break; break;
/* Unicode (UTF-16) */ /* Unicode (UTF-16) */
case CB_FORMAT_UNICODETEXT: case CB_FORMAT_UNICODETEXT:
guac_client_log_info(client, "STUB: Copy unicode"); guac_client_log_info(client, "STUB: Copy unicode");
__guac_rdp_clipboard_send_utf16(client, event);
break; break;
default: default:
@ -240,20 +292,5 @@ void guac_rdp_process_cb_data_response(guac_client* client,
} }
/* 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);
}
else
guac_client_log_error(client,
"Clipboard data missing null terminator");
} }