GUAC-608: Convert VNC outbound clipboard to common code. Stub inbound clipboard.

This commit is contained in:
Michael Jumper 2014-04-08 16:42:10 -07:00
parent d5fa14c0c7
commit c9b077af4c
8 changed files with 130 additions and 12 deletions

View File

@ -31,12 +31,14 @@ lib_LTLIBRARIES = libguac-client-vnc.la
libguac_client_vnc_la_SOURCES = \ libguac_client_vnc_la_SOURCES = \
client.c \ client.c \
clipboard.c \
convert.c \ convert.c \
guac_handlers.c \ guac_handlers.c \
vnc_handlers.c vnc_handlers.c
noinst_HEADERS = \ noinst_HEADERS = \
client.h \ client.h \
clipboard.h \
convert.h \ convert.h \
guac_handlers.h \ guac_handlers.h \
vnc_handlers.h vnc_handlers.h

View File

@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include "client.h" #include "client.h"
#include "guac_clipboard.h"
#include "guac_dot_cursor.h" #include "guac_dot_cursor.h"
#include "guac_handlers.h" #include "guac_handlers.h"
#include "guac_pointer_cursor.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; guac_client_data->listen_timeout = 5000;
#endif #endif
/* Init clipboard */
guac_client_data->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH);
/* Ensure connection is kept alive during lengthy connects */ /* Ensure connection is kept alive during lengthy connects */
guac_socket_require_keep_alive(client->socket); guac_socket_require_keep_alive(client->socket);

View File

@ -25,6 +25,7 @@
#define __GUAC_VNC_CLIENT_H #define __GUAC_VNC_CLIENT_H
#include "config.h" #include "config.h"
#include "guac_clipboard.h"
#include <guacamole/audio.h> #include <guacamole/audio.h>
#include <guacamole/client.h> #include <guacamole/client.h>
@ -51,6 +52,11 @@
*/ */
#define GUAC_VNC_CONNECT_INTERVAL 1000 #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; extern char* __GUAC_CLIENT;
/** /**
@ -168,7 +174,12 @@ typedef struct vnc_guac_client_data {
*/ */
pa_threaded_mainloop* pa_mainloop; pa_threaded_mainloop* pa_mainloop;
#endif #endif
/**
* Internal clipboard.
*/
guac_common_clipboard* clipboard;
} vnc_guac_client_data; } vnc_guac_client_data;
#endif #endif

View File

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

View File

@ -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 <guacamole/client.h>
#include <guacamole/stream.h>
/**
* 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

View File

@ -24,6 +24,7 @@
#include "client.h" #include "client.h"
#include "convert.h" #include "convert.h"
#include "guac_clipboard.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -96,8 +97,8 @@ int vnc_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
return 0; 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; rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client;
/* Convert UTF-8 character data to ISO_8859-1 */ /* 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 else
SendClientCutText(rfb_client, "", 0); SendClientCutText(rfb_client, "", 0);
#endif
return 0; return 0;
} }
@ -134,6 +135,9 @@ int vnc_guac_client_free_handler(guac_client* client) {
if (guac_client_data->encodings != NULL) if (guac_client_data->encodings != NULL)
free(guac_client_data->encodings); free(guac_client_data->encodings);
/* Free clipboard */
guac_common_clipboard_free(guac_client_data->clipboard);
/* Free generic data struct */ /* Free generic data struct */
free(client->data); free(client->data);

View File

@ -31,7 +31,7 @@
int vnc_guac_client_handle_messages(guac_client* client); 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_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_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); int vnc_guac_client_free_handler(guac_client* client);
#endif #endif

View File

@ -23,9 +23,8 @@
#include "config.h" #include "config.h"
#include "client.h" #include "client.h"
#include "convert.h" #include "guac_iconv.h"
#include <iconv.h>
#include <stdlib.h> #include <stdlib.h>
#include <syslog.h> #include <syslog.h>
#include <time.h> #include <time.h>
@ -298,14 +297,21 @@ rfbBool guac_vnc_malloc_framebuffer(rfbClient* rfb_client) {
void guac_vnc_cut_text(rfbClient* client, const char* text, int textlen) { void guac_vnc_cut_text(rfbClient* client, const char* text, int textlen) {
guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT); 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 received_data[GUAC_VNC_CLIPBOARD_MAX_LENGTH];
char* utf8_text = convert("ISO_8859-1", "UTF-8", text);
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);
} }