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,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, void guac_rdp_process_cb_data_response(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 */ /* Convert to UTF-8 based on format */
if (event->data[event->size - 1] == '\0') { switch (client_data->requested_clipboard_format) {
/* Convert to UTF-8 based on format */ /* Non-Unicode */
switch (client_data->requested_clipboard_format) { case CB_FORMAT_TEXT:
guac_client_log_info(client, "STUB: Copy non-unicode");
__guac_rdp_clipboard_send_iso8859_1(client, event);
break;
/* Non-Unicode */ /* Unicode (UTF-16) */
case CB_FORMAT_TEXT: case CB_FORMAT_UNICODETEXT:
guac_client_log_info(client, "STUB: Copy non-unicode"); guac_client_log_info(client, "STUB: Copy unicode");
break; __guac_rdp_clipboard_send_utf16(client, event);
break;
/* Unicode (UTF-16) */ default:
case CB_FORMAT_UNICODETEXT: guac_client_log_error(client, "Requested clipboard data in "
guac_client_log_info(client, "STUB: Copy unicode"); "unsupported format %i",
break; client_data->requested_clipboard_format);
return;
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);
} }
else
guac_client_log_error(client,
"Clipboard data missing null terminator");
} }