From 85cde821a4c73bb74f48f2d40aa4444272c3c920 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 7 Apr 2014 17:08:16 -0700 Subject: [PATCH] GUAC-608: Change semantics of clipboard instruction within libguac. --- src/libguac/client-handlers.c | 30 +++++++++++++++++++++++++++++- src/libguac/guacamole/client.h | 14 +++++++------- src/libguac/guacamole/protocol.h | 6 ++++-- src/libguac/protocol.c | 7 +++++-- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/libguac/client-handlers.c b/src/libguac/client-handlers.c index 3028fa8c..dc418329 100644 --- a/src/libguac/client-handlers.c +++ b/src/libguac/client-handlers.c @@ -99,12 +99,40 @@ int __guac_handle_key(guac_client* client, guac_instruction* instruction) { } int __guac_handle_clipboard(guac_client* client, guac_instruction* instruction) { + + /* Pull corresponding stream */ + int stream_index = atoi(instruction->argv[0]); + guac_stream* stream; + + /* Validate stream index */ + if (stream_index < 0 || stream_index >= GUAC_CLIENT_MAX_STREAMS) { + + guac_stream dummy_stream; + dummy_stream.index = stream_index; + + guac_protocol_send_ack(client->socket, &dummy_stream, + "Invalid stream index", GUAC_PROTOCOL_STATUS_CLIENT_BAD_REQUEST); + return 0; + } + + /* Initialize stream */ + stream = &(client->__input_streams[stream_index]); + stream->index = stream_index; + stream->data = NULL; + + /* If supported, call handler */ if (client->clipboard_handler) return client->clipboard_handler( client, - instruction->argv[0] /* data */ + stream, + instruction->argv[1] /* mimetype */ ); + + /* Otherwise, abort */ + guac_protocol_send_ack(client->socket, stream, + "Clipboard unsupported", GUAC_PROTOCOL_STATUS_UNSUPPORTED); return 0; + } int __guac_handle_size(guac_client* client, guac_instruction* instruction) { diff --git a/src/libguac/guacamole/client.h b/src/libguac/guacamole/client.h index 6a1abee4..d3f5383e 100644 --- a/src/libguac/guacamole/client.h +++ b/src/libguac/guacamole/client.h @@ -71,8 +71,8 @@ typedef int guac_client_key_handler(guac_client* client, int keysym, int pressed /** * Handler for Guacamole clipboard events. */ -typedef int guac_client_clipboard_handler(guac_client* client, char* copied); - +typedef int guac_client_clipboard_handler(guac_client* client, guac_stream* stream, + char* mimetype); /** * Handler for Guacamole screen size events. */ @@ -356,14 +356,14 @@ struct guac_client { * handler will be called whenever the web-client sets the data of the * clipboard. * - * This handler takes a single string which contains the text which - * has been set in the clipboard. This text is already unescaped from - * the Guacamole escaped version sent within the clipboard message - * in the protocol. + * The handler takes a guac_stream, which contains the stream index and + * will persist through the duration of the transfer, and the mimetype + * of the data being transferred. * * Example: * @code - * int clipboard_handler(guac_client* client, char* copied); + * int clipboard_handler(guac_client* client, guac_stream* stream, + * char* mimetype); * * int guac_client_init(guac_client* client, int argc, char** argv) { * client->clipboard_handler = clipboard_handler; diff --git a/src/libguac/guacamole/protocol.h b/src/libguac/guacamole/protocol.h index 6b944f75..eb2b094c 100644 --- a/src/libguac/guacamole/protocol.h +++ b/src/libguac/guacamole/protocol.h @@ -950,10 +950,12 @@ int guac_protocol_send_size(guac_socket* socket, const guac_layer* layer, * returned, and guac_error is set appropriately. * * @param socket The guac_socket connection to use. - * @param data The clipboard data to send. + * @param stream The stream to use. + * @param mimetype The mimetype of the clipboard data being sent. * @return Zero on success, non-zero on error. */ -int guac_protocol_send_clipboard(guac_socket* socket, const char* data); +int guac_protocol_send_clipboard(guac_socket* socket, const guac_stream* stream, + const char* mimetype); /** * Sends a name instruction over the given guac_socket connection. diff --git a/src/libguac/protocol.c b/src/libguac/protocol.c index a8c144de..6c19d24d 100644 --- a/src/libguac/protocol.c +++ b/src/libguac/protocol.c @@ -551,14 +551,17 @@ int guac_protocol_send_clip(guac_socket* socket, const guac_layer* layer) { } -int guac_protocol_send_clipboard(guac_socket* socket, const char* data) { +int guac_protocol_send_clipboard(guac_socket* socket, const guac_stream* stream, + const char* mimetype) { int ret_val; guac_socket_instruction_begin(socket); ret_val = guac_socket_write_string(socket, "9.clipboard,") - || __guac_socket_write_length_string(socket, data) + || __guac_socket_write_length_int(socket, stream->index) + || guac_socket_write_string(socket, ",") + || __guac_socket_write_length_string(socket, mimetype) || guac_socket_write_string(socket, ";"); guac_socket_instruction_end(socket);