GUAC-608: Change semantics of clipboard instruction within libguac.

This commit is contained in:
Michael Jumper 2014-04-07 17:08:16 -07:00
parent e5c34f8661
commit 85cde821a4
4 changed files with 45 additions and 12 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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.

View File

@ -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);