GUAC-584: Add basic handling for Unicode text - just stubs, no converting to UTF-8 yet.

This commit is contained in:
Michael Jumper 2014-03-31 15:46:49 -07:00
parent 16757aebec
commit 0b414ed9b5
4 changed files with 97 additions and 24 deletions

View File

@ -57,6 +57,12 @@
#include <guacamole/protocol.h> #include <guacamole/protocol.h>
#include <guacamole/socket.h> #include <guacamole/socket.h>
#ifdef HAVE_FREERDP_CLIENT_CLIPRDR_H
#include <freerdp/client/cliprdr.h>
#else
#include "compat/client-cliprdr.h"
#endif
#ifdef ENABLE_WINPR #ifdef ENABLE_WINPR
#include <winpr/wtypes.h> #include <winpr/wtypes.h>
#else #else
@ -650,6 +656,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
guac_client_data->mouse_button_mask = 0; guac_client_data->mouse_button_mask = 0;
guac_client_data->current_surface = GUAC_DEFAULT_LAYER; guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
guac_client_data->clipboard = NULL; guac_client_data->clipboard = NULL;
guac_client_data->requested_clipboard_format = CB_FORMAT_TEXT;
guac_client_data->audio = NULL; guac_client_data->audio = NULL;
guac_client_data->filesystem = NULL; guac_client_data->filesystem = NULL;
guac_client_data->available_svc = guac_common_list_alloc(); guac_client_data->available_svc = guac_common_list_alloc();

View File

@ -170,6 +170,14 @@ typedef struct rdp_guac_client_data {
*/ */
char* clipboard; char* clipboard;
/**
* The format of the clipboard which was requested. Data received from
* the RDP server should conform to this format. This will be one of
* several legal clipboard format values defined within FreeRDP, such as
* CB_FORMAT_TEXT.
*/
int requested_clipboard_format;
/** /**
* Audio output, if any. * Audio output, if any.
*/ */

View File

@ -99,27 +99,22 @@ void guac_rdp_process_cb_monitor_ready(guac_client* client, wMessage* event) {
/* Received notification of clipboard support. */ /* Received notification of clipboard support. */
/* Respond with supported format list */ /* Respond with supported format list */
format_list->formats = (UINT32*) malloc(sizeof(UINT32)); format_list->formats = (UINT32*) malloc(sizeof(UINT32)*2);
format_list->formats[0] = CB_FORMAT_TEXT; format_list->formats[0] = CB_FORMAT_TEXT;
format_list->num_formats = 1; format_list->formats[1] = CB_FORMAT_UNICODETEXT;
format_list->num_formats = 2;
freerdp_channels_send_event(channels, (wMessage*) format_list); freerdp_channels_send_event(channels, (wMessage*) format_list);
} }
void guac_rdp_process_cb_format_list(guac_client* client, /**
RDP_CB_FORMAT_LIST_EVENT* event) { * Sends a clipboard data request for the given format.
*/
static void __guac_rdp_cb_request_format(guac_client* client, int format) {
rdpChannels* channels = rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
((rdp_guac_client_data*) client->data)->rdp_inst->context->channels; rdpChannels* channels = client_data->rdp_inst->context->channels;
/* Received notification of available data */
int i;
for (i=0; i<event->num_formats; i++) {
/* If plain text available, request it */
if (event->formats[i] == CB_FORMAT_TEXT) {
/* Create new data request */ /* Create new data request */
RDP_CB_DATA_REQUEST_EVENT* data_request = RDP_CB_DATA_REQUEST_EVENT* data_request =
@ -128,18 +123,48 @@ void guac_rdp_process_cb_format_list(guac_client* client,
CliprdrChannel_DataRequest, CliprdrChannel_DataRequest,
NULL, NULL); NULL, NULL);
/* We want plain text */ /* Set to requested format */
data_request->format = CB_FORMAT_TEXT; client_data->requested_clipboard_format = format;
data_request->format = format;
/* Send request */ /* Send request */
freerdp_channels_send_event(channels, (wMessage*) data_request); freerdp_channels_send_event(channels, (wMessage*) data_request);
}
void guac_rdp_process_cb_format_list(guac_client* client,
RDP_CB_FORMAT_LIST_EVENT* event) {
int formats = 0;
/* Received notification of available data */
int i;
for (i=0; i<event->num_formats; i++) {
/* If plain text available, request it */
if (event->formats[i] == CB_FORMAT_TEXT)
formats |= GUAC_RDP_CLIPBOARD_FORMAT_ISO8859_1;
else if (event->formats[i] == CB_FORMAT_UNICODETEXT)
formats |= GUAC_RDP_CLIPBOARD_FORMAT_UTF16;
}
/* Prefer Unicode to plain text */
if (formats & GUAC_RDP_CLIPBOARD_FORMAT_UTF16) {
guac_client_log_info(client, "Requesting unicode text");
__guac_rdp_cb_request_format(client, CB_FORMAT_UNICODETEXT);
return; return;
} }
/* Use plain text if Unicode unavailable */
if (formats & GUAC_RDP_CLIPBOARD_FORMAT_ISO8859_1) {
guac_client_log_info(client, "Requesting plain text");
__guac_rdp_cb_request_format(client, CB_FORMAT_TEXT);
return;
} }
/* Otherwise, no supported data available */ /* Ignore if no supported format available */
guac_client_log_info(client, "Ignoring unsupported clipboard data"); guac_client_log_info(client, "Ignoring unsupported clipboard data");
} }
@ -147,8 +172,8 @@ void guac_rdp_process_cb_format_list(guac_client* client,
void guac_rdp_process_cb_data_request(guac_client* client, void guac_rdp_process_cb_data_request(guac_client* client,
RDP_CB_DATA_REQUEST_EVENT* event) { RDP_CB_DATA_REQUEST_EVENT* event) {
rdpChannels* channels = rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
((rdp_guac_client_data*) client->data)->rdp_inst->context->channels; rdpChannels* channels = client_data->rdp_inst->context->channels;
/* If text requested, send clipboard text contents */ /* If text requested, send clipboard text contents */
if (event->format == CB_FORMAT_TEXT) { if (event->format == CB_FORMAT_TEXT) {
@ -189,9 +214,32 @@ void guac_rdp_process_cb_data_request(guac_client* client,
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;
/* Received clipboard data */ /* Received clipboard data */
if (event->data[event->size - 1] == '\0') { if (event->data[event->size - 1] == '\0') {
/* 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");
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 existing data */
free(((rdp_guac_client_data*) client->data)->clipboard); free(((rdp_guac_client_data*) client->data)->clipboard);

View File

@ -40,6 +40,16 @@
#include "compat/client-cliprdr.h" #include "compat/client-cliprdr.h"
#endif #endif
/**
* Clipboard format for text encoded in ISO-8859-1.
*/
#define GUAC_RDP_CLIPBOARD_FORMAT_ISO8859_1 1
/**
* Clipboard format for text encoded in UTF-16.
*/
#define GUAC_RDP_CLIPBOARD_FORMAT_UTF16 2
void guac_rdp_process_cliprdr_event(guac_client* client, wMessage* event); void guac_rdp_process_cliprdr_event(guac_client* client, wMessage* event);
void guac_rdp_process_cb_monitor_ready(guac_client* client, wMessage* event); void guac_rdp_process_cb_monitor_ready(guac_client* client, wMessage* event);