GUAC-608: Migrate RDP to common clipboard code for outbound data.

This commit is contained in:
Michael Jumper 2014-04-08 15:06:48 -07:00
parent 855e32c7a5
commit 3cf644009f
4 changed files with 12 additions and 39 deletions

View File

@ -655,6 +655,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
guac_client_data->bounded = FALSE; guac_client_data->bounded = FALSE;
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 = guac_common_clipboard_alloc(GUAC_RDP_CLIPBOARD_MAX_LENGTH);
guac_client_data->requested_clipboard_format = CB_FORMAT_TEXT; 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;

View File

@ -26,6 +26,7 @@
#include "config.h" #include "config.h"
#include "guac_clipboard.h"
#include "guac_list.h" #include "guac_list.h"
#include "rdp_fs.h" #include "rdp_fs.h"
#include "rdp_keymap.h" #include "rdp_keymap.h"
@ -171,9 +172,9 @@ typedef struct rdp_guac_client_data {
guac_rdp_keysym_state_map keysym_state; 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 * The format of the clipboard which was requested. Data received from

View File

@ -90,6 +90,7 @@ int rdp_guac_client_free_handler(guac_client* client) {
guac_common_list_free(guac_client_data->available_svc); guac_common_list_free(guac_client_data->available_svc);
/* Free client data */ /* 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->opaque_glyph_surface);
cairo_surface_destroy(guac_client_data->trans_glyph_surface); cairo_surface_destroy(guac_client_data->trans_glyph_surface);
free(guac_client_data); free(guac_client_data);

View File

@ -219,10 +219,11 @@ 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;
char received_data[GUAC_RDP_CLIPBOARD_MAX_LENGTH];
guac_iconv_read* reader; guac_iconv_read* reader;
char* input = (char*) event->data; char* input = (char*) event->data;
char* output = client_data->clipboard; char* output = received_data;
/* Find correct source encoding */ /* Find correct source encoding */
switch (client_data->requested_clipboard_format) { switch (client_data->requested_clipboard_format) {
@ -247,43 +248,12 @@ void guac_rdp_process_cb_data_response(guac_client* client,
/* Convert send clipboard data */ /* Convert send clipboard data */
if (guac_iconv(reader, &input, event->size, 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 length = strnlen(received_data, sizeof(received_data));
int remaining = GUAC_RDP_CLIPBOARD_MAX_LENGTH; guac_common_clipboard_reset(client_data->clipboard, "text/plain");
guac_common_clipboard_append(client_data->clipboard, received_data, length);
/* Begin stream */ guac_common_clipboard_send(client_data->clipboard, client);
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);
} }