diff --git a/src/protocols/vnc/Makefile.am b/src/protocols/vnc/Makefile.am index 27f69d86..44743f81 100644 --- a/src/protocols/vnc/Makefile.am +++ b/src/protocols/vnc/Makefile.am @@ -31,12 +31,14 @@ lib_LTLIBRARIES = libguac-client-vnc.la libguac_client_vnc_la_SOURCES = \ client.c \ + clipboard.c \ convert.c \ guac_handlers.c \ vnc_handlers.c noinst_HEADERS = \ client.h \ + clipboard.h \ convert.h \ guac_handlers.h \ vnc_handlers.h diff --git a/src/protocols/vnc/client.c b/src/protocols/vnc/client.c index 0cf2461a..35d080b8 100644 --- a/src/protocols/vnc/client.c +++ b/src/protocols/vnc/client.c @@ -23,6 +23,7 @@ #include "config.h" #include "client.h" +#include "guac_clipboard.h" #include "guac_dot_cursor.h" #include "guac_handlers.h" #include "guac_pointer_cursor.h" @@ -266,6 +267,9 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_client_data->listen_timeout = 5000; #endif + /* Init clipboard */ + guac_client_data->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH); + /* Ensure connection is kept alive during lengthy connects */ guac_socket_require_keep_alive(client->socket); diff --git a/src/protocols/vnc/client.h b/src/protocols/vnc/client.h index 9f89893e..e6c4b231 100644 --- a/src/protocols/vnc/client.h +++ b/src/protocols/vnc/client.h @@ -25,6 +25,7 @@ #define __GUAC_VNC_CLIENT_H #include "config.h" +#include "guac_clipboard.h" #include #include @@ -51,6 +52,11 @@ */ #define GUAC_VNC_CONNECT_INTERVAL 1000 +/** + * The maximum number of bytes to allow within the clipboard. + */ +#define GUAC_VNC_CLIPBOARD_MAX_LENGTH 262144 + extern char* __GUAC_CLIENT; /** @@ -168,7 +174,12 @@ typedef struct vnc_guac_client_data { */ pa_threaded_mainloop* pa_mainloop; #endif - + + /** + * Internal clipboard. + */ + guac_common_clipboard* clipboard; + } vnc_guac_client_data; #endif diff --git a/src/protocols/vnc/clipboard.c b/src/protocols/vnc/clipboard.c new file mode 100644 index 00000000..6a195749 --- /dev/null +++ b/src/protocols/vnc/clipboard.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" +#include "clipboard.h" + +int guac_vnc_clipboard_handler(guac_client* client, guac_stream* stream, + char* mimetype) { + /* STUB */ + return 0; +} + +int guac_vnc_clipboard_blob_handler(guac_client* client, guac_stream* stream, + void* data, int length) { + /* STUB */ + return 0; +} + +int guac_vnc_clipboard_end_handler(guac_client* client, guac_stream* stream) { + /* STUB */ + return 0; +} + diff --git a/src/protocols/vnc/clipboard.h b/src/protocols/vnc/clipboard.h new file mode 100644 index 00000000..5ff2ef79 --- /dev/null +++ b/src/protocols/vnc/clipboard.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _GUAC_VNC_CLIPBOARD_H +#define _GUAC_VNC_CLIPBOARD_H + +#include "config.h" + +#include +#include + +/** + * Handler for inbound clipboard data. + */ +int guac_vnc_clipboard_handler(guac_client* client, guac_stream* stream, + char* mimetype); + +/** + * Handler for stream data related to clipboard. + */ +int guac_vnc_clipboard_blob_handler(guac_client* client, guac_stream* stream, + void* data, int length); + +/** + * Handler for end-of-stream related to clipboard. + */ +int guac_vnc_clipboard_end_handler(guac_client* client, guac_stream* stream); + +#endif + diff --git a/src/protocols/vnc/guac_handlers.c b/src/protocols/vnc/guac_handlers.c index 846b5b2f..e9ab0140 100644 --- a/src/protocols/vnc/guac_handlers.c +++ b/src/protocols/vnc/guac_handlers.c @@ -24,6 +24,7 @@ #include "client.h" #include "convert.h" +#include "guac_clipboard.h" #include #include @@ -96,8 +97,8 @@ int vnc_guac_client_key_handler(guac_client* client, int keysym, int pressed) { return 0; } -int vnc_guac_client_clipboard_handler(guac_client* client, char* data) { - +int vnc_guac_client_clipboard_handler(guac_client* client, guac_stream* stream, char* mimetype) { +#if 0 rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; /* Convert UTF-8 character data to ISO_8859-1 */ @@ -115,7 +116,7 @@ int vnc_guac_client_clipboard_handler(guac_client* client, char* data) { } else SendClientCutText(rfb_client, "", 0); - +#endif return 0; } @@ -134,6 +135,9 @@ int vnc_guac_client_free_handler(guac_client* client) { if (guac_client_data->encodings != NULL) free(guac_client_data->encodings); + /* Free clipboard */ + guac_common_clipboard_free(guac_client_data->clipboard); + /* Free generic data struct */ free(client->data); diff --git a/src/protocols/vnc/guac_handlers.h b/src/protocols/vnc/guac_handlers.h index 8ad1e2f1..753cce0b 100644 --- a/src/protocols/vnc/guac_handlers.h +++ b/src/protocols/vnc/guac_handlers.h @@ -31,7 +31,7 @@ int vnc_guac_client_handle_messages(guac_client* client); int vnc_guac_client_mouse_handler(guac_client* client, int x, int y, int mask); int vnc_guac_client_key_handler(guac_client* client, int keysym, int pressed); -int vnc_guac_client_clipboard_handler(guac_client* client, char* data); +int vnc_guac_client_clipboard_handler(guac_client* client, guac_stream* stream, char* mimetype); int vnc_guac_client_free_handler(guac_client* client); #endif diff --git a/src/protocols/vnc/vnc_handlers.c b/src/protocols/vnc/vnc_handlers.c index f0573a3a..d202a261 100644 --- a/src/protocols/vnc/vnc_handlers.c +++ b/src/protocols/vnc/vnc_handlers.c @@ -23,9 +23,8 @@ #include "config.h" #include "client.h" -#include "convert.h" +#include "guac_iconv.h" -#include #include #include #include @@ -298,14 +297,21 @@ rfbBool guac_vnc_malloc_framebuffer(rfbClient* rfb_client) { void guac_vnc_cut_text(rfbClient* client, const char* text, int textlen) { guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT); - guac_socket* socket = gc->socket; + vnc_guac_client_data* client_data = (vnc_guac_client_data*) gc->data; - /* Convert ASCII character data to UTF-8 */ - char* utf8_text = convert("ISO_8859-1", "UTF-8", text); + char received_data[GUAC_VNC_CLIPBOARD_MAX_LENGTH]; - guac_protocol_send_clipboard(socket, utf8_text); + const char* input = text; + char* output = received_data; - free(utf8_text); + /* Convert clipboard contents */ + guac_iconv(GUAC_READ_ISO8859_1, &input, textlen, + GUAC_WRITE_UTF8, &output, sizeof(received_data)); + + /* Send converted data */ + guac_common_clipboard_reset(client_data->clipboard, "text/plain"); + guac_common_clipboard_append(client_data->clipboard, received_data, output - received_data); + guac_common_clipboard_send(client_data->clipboard, gc); }