diff --git a/src/common/clipboard.c b/src/common/clipboard.c index 227623e1..f9bf1acb 100644 --- a/src/common/clipboard.c +++ b/src/common/clipboard.c @@ -29,15 +29,15 @@ #include #include -guac_common_clipboard* guac_common_clipboard_alloc(int size) { +guac_common_clipboard* guac_common_clipboard_alloc() { guac_common_clipboard* clipboard = malloc(sizeof(guac_common_clipboard)); /* Init clipboard */ clipboard->mimetype[0] = '\0'; - clipboard->buffer = malloc(size); + clipboard->buffer = malloc(GUAC_COMMON_CLIPBOARD_MAX_LENGTH); + clipboard->available = GUAC_COMMON_CLIPBOARD_MAX_LENGTH; clipboard->length = 0; - clipboard->available = size; pthread_mutex_init(&(clipboard->lock), NULL); diff --git a/src/common/common/clipboard.h b/src/common/common/clipboard.h index c129a7c3..308c6674 100644 --- a/src/common/common/clipboard.h +++ b/src/common/common/clipboard.h @@ -31,6 +31,11 @@ */ #define GUAC_COMMON_CLIPBOARD_BLOCK_SIZE 4096 +/** + * The maximum number of bytes to allow within the clipboard. + */ +#define GUAC_COMMON_CLIPBOARD_MAX_LENGTH 262144 + /** * Generic clipboard structure. */ @@ -66,12 +71,9 @@ typedef struct guac_common_clipboard { } guac_common_clipboard; /** - * Creates a new clipboard having the given initial size. - * - * @param size The maximum number of bytes to allow within the clipboard. - * @return A newly-allocated clipboard. + * Creates a new clipboard. */ -guac_common_clipboard* guac_common_clipboard_alloc(int size); +guac_common_clipboard* guac_common_clipboard_alloc(); /** * Frees the given clipboard. diff --git a/src/protocols/kubernetes/argv.c b/src/protocols/kubernetes/argv.c index aab158c8..fa949f7e 100644 --- a/src/protocols/kubernetes/argv.c +++ b/src/protocols/kubernetes/argv.c @@ -21,6 +21,7 @@ #include "argv.h" #include "kubernetes.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include diff --git a/src/protocols/kubernetes/client.c b/src/protocols/kubernetes/client.c index 040d35a3..42a18286 100644 --- a/src/protocols/kubernetes/client.c +++ b/src/protocols/kubernetes/client.c @@ -19,7 +19,6 @@ #include "argv.h" #include "client.h" -#include "common/clipboard.h" #include "kubernetes.h" #include "settings.h" #include "user.h" @@ -95,9 +94,6 @@ int guac_client_init(guac_client* client) { guac_kubernetes_client* kubernetes_client = calloc(1, sizeof(guac_kubernetes_client)); client->data = kubernetes_client; - /* Init clipboard */ - kubernetes_client->clipboard = guac_common_clipboard_alloc(GUAC_KUBERNETES_CLIPBOARD_MAX_LENGTH); - /* Set handlers */ client->join_handler = guac_kubernetes_user_join_handler; client->free_handler = guac_kubernetes_client_free_handler; @@ -133,7 +129,6 @@ int guac_kubernetes_client_free_handler(guac_client* client) { if (kubernetes_client->settings != NULL) guac_kubernetes_settings_free(kubernetes_client->settings); - guac_common_clipboard_free(kubernetes_client->clipboard); free(kubernetes_client); return 0; diff --git a/src/protocols/kubernetes/client.h b/src/protocols/kubernetes/client.h index ec4ba326..0d6f96b5 100644 --- a/src/protocols/kubernetes/client.h +++ b/src/protocols/kubernetes/client.h @@ -22,11 +22,6 @@ #include -/** - * The maximum number of bytes to allow within the clipboard. - */ -#define GUAC_KUBERNETES_CLIPBOARD_MAX_LENGTH 262144 - /** * Static reference to the guac_client associated with the active Kubernetes * connection. While libwebsockets provides some means of storing and diff --git a/src/protocols/kubernetes/clipboard.c b/src/protocols/kubernetes/clipboard.c index f1682066..8e9085b6 100644 --- a/src/protocols/kubernetes/clipboard.c +++ b/src/protocols/kubernetes/clipboard.c @@ -20,6 +20,7 @@ #include "clipboard.h" #include "common/clipboard.h" #include "kubernetes.h" +#include "terminal/terminal_priv.h" #include #include @@ -33,7 +34,7 @@ int guac_kubernetes_clipboard_handler(guac_user* user, guac_stream* stream, (guac_kubernetes_client*) client->data; /* Clear clipboard and prepare for new data */ - guac_common_clipboard_reset(kubernetes_client->clipboard, mimetype); + guac_common_clipboard_reset(kubernetes_client->term->clipboard, mimetype); /* Set handlers for clipboard stream */ stream->blob_handler = guac_kubernetes_clipboard_blob_handler; @@ -50,7 +51,7 @@ int guac_kubernetes_clipboard_blob_handler(guac_user* user, (guac_kubernetes_client*) client->data; /* Append new data */ - guac_common_clipboard_append(kubernetes_client->clipboard, data, length); + guac_common_clipboard_append(kubernetes_client->term->clipboard, data, length); return 0; } diff --git a/src/protocols/kubernetes/input.c b/src/protocols/kubernetes/input.c index 814578ef..88e73887 100644 --- a/src/protocols/kubernetes/input.c +++ b/src/protocols/kubernetes/input.c @@ -21,6 +21,7 @@ #include "input.h" #include "kubernetes.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include diff --git a/src/protocols/kubernetes/kubernetes.c b/src/protocols/kubernetes/kubernetes.c index d77c6473..5e17eb8a 100644 --- a/src/protocols/kubernetes/kubernetes.c +++ b/src/protocols/kubernetes/kubernetes.c @@ -26,6 +26,7 @@ #include "kubernetes.h" #include "ssl.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include "url.h" #include @@ -241,8 +242,7 @@ void* guac_kubernetes_client_thread(void* data) { /* Create terminal options with required parameters */ guac_terminal_options* options = guac_terminal_options_create( - client, kubernetes_client->clipboard, - settings->width, settings->height, settings->resolution); + client, settings->width, settings->height, settings->resolution); /* Set optional parameters */ options->disable_copy = settings->disable_copy; diff --git a/src/protocols/kubernetes/kubernetes.h b/src/protocols/kubernetes/kubernetes.h index c37ca4cf..42d95670 100644 --- a/src/protocols/kubernetes/kubernetes.h +++ b/src/protocols/kubernetes/kubernetes.h @@ -102,11 +102,6 @@ typedef struct guac_kubernetes_client { */ pthread_t client_thread; - /** - * The current clipboard contents. - */ - guac_common_clipboard* clipboard; - /** * The terminal which will render all output from the Kubernetes pod. */ diff --git a/src/protocols/kubernetes/user.c b/src/protocols/kubernetes/user.c index b09d837e..f1eb4de5 100644 --- a/src/protocols/kubernetes/user.c +++ b/src/protocols/kubernetes/user.c @@ -25,6 +25,7 @@ #include "pipe.h" #include "settings.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include "user.h" #include diff --git a/src/protocols/rdp/channels/cliprdr.c b/src/protocols/rdp/channels/cliprdr.c index 8f9d92a5..4845577e 100644 --- a/src/protocols/rdp/channels/cliprdr.c +++ b/src/protocols/rdp/channels/cliprdr.c @@ -358,7 +358,7 @@ static UINT guac_rdp_cliprdr_format_data_request(CliprdrClientContext* cliprdr, guac_iconv_write* remote_writer; const char* input = clipboard->clipboard->buffer; - char* output = malloc(GUAC_RDP_CLIPBOARD_MAX_LENGTH); + char* output = malloc(GUAC_COMMON_CLIPBOARD_MAX_LENGTH); /* Map requested clipboard format to a guac_iconv writer */ switch (format_data_request->requestedFormatId) { @@ -389,7 +389,7 @@ static UINT guac_rdp_cliprdr_format_data_request(CliprdrClientContext* cliprdr, BYTE* start = (BYTE*) output; guac_iconv_read* local_reader = settings->normalize_clipboard ? GUAC_READ_UTF8_NORMALIZED : GUAC_READ_UTF8; guac_iconv(local_reader, &input, clipboard->clipboard->length, - remote_writer, &output, GUAC_RDP_CLIPBOARD_MAX_LENGTH); + remote_writer, &output, GUAC_COMMON_CLIPBOARD_MAX_LENGTH); CLIPRDR_FORMAT_DATA_RESPONSE data_response = { .requestedFormatData = (BYTE*) start, @@ -449,7 +449,7 @@ static UINT guac_rdp_cliprdr_format_data_response(CliprdrClientContext* cliprdr, return CHANNEL_RC_OK; } - char received_data[GUAC_RDP_CLIPBOARD_MAX_LENGTH]; + char received_data[GUAC_COMMON_CLIPBOARD_MAX_LENGTH]; guac_iconv_read* remote_reader; const char* input = (char*) format_data_response->requestedFormatData; @@ -595,7 +595,7 @@ guac_rdp_clipboard* guac_rdp_clipboard_alloc(guac_client* client) { /* Allocate clipboard and underlying storage */ guac_rdp_clipboard* clipboard = calloc(1, sizeof(guac_rdp_clipboard)); clipboard->client = client; - clipboard->clipboard = guac_common_clipboard_alloc(GUAC_RDP_CLIPBOARD_MAX_LENGTH); + clipboard->clipboard = guac_common_clipboard_alloc(); clipboard->requested_format = CF_TEXT; return clipboard; diff --git a/src/protocols/rdp/client.h b/src/protocols/rdp/client.h index 9acd33ab..943d39ab 100644 --- a/src/protocols/rdp/client.h +++ b/src/protocols/rdp/client.h @@ -62,11 +62,6 @@ */ #define GUAC_RDP_REASONABLE_AREA (800*600) -/** - * The maximum number of bytes to allow within the clipboard. - */ -#define GUAC_RDP_CLIPBOARD_MAX_LENGTH 262144 - /** * Initial rate of audio to stream, in Hz. If the RDP server uses a different * value, the Guacamole audio stream will simply be reset appropriately. diff --git a/src/protocols/ssh/argv.c b/src/protocols/ssh/argv.c index 9b3cf653..040c4909 100644 --- a/src/protocols/ssh/argv.c +++ b/src/protocols/ssh/argv.c @@ -21,6 +21,7 @@ #include "argv.h" #include "ssh.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include diff --git a/src/protocols/ssh/client.c b/src/protocols/ssh/client.c index 1d0a1157..8f8f3f75 100644 --- a/src/protocols/ssh/client.c +++ b/src/protocols/ssh/client.c @@ -21,7 +21,6 @@ #include "argv.h" #include "client.h" -#include "common/clipboard.h" #include "common/recording.h" #include "common-ssh/sftp.h" #include "ssh.h" @@ -45,9 +44,6 @@ int guac_client_init(guac_client* client) { guac_ssh_client* ssh_client = calloc(1, sizeof(guac_ssh_client)); client->data = ssh_client; - /* Init clipboard */ - ssh_client->clipboard = guac_common_clipboard_alloc(GUAC_SSH_CLIPBOARD_MAX_LENGTH); - /* Set handlers */ client->join_handler = guac_ssh_user_join_handler; client->free_handler = guac_ssh_client_free_handler; @@ -118,7 +114,6 @@ int guac_ssh_client_free_handler(guac_client* client) { guac_ssh_settings_free(ssh_client->settings); /* Free client structure */ - guac_common_clipboard_free(ssh_client->clipboard); free(ssh_client); guac_common_ssh_uninit(); diff --git a/src/protocols/ssh/client.h b/src/protocols/ssh/client.h index 551cb7a5..a759e817 100644 --- a/src/protocols/ssh/client.h +++ b/src/protocols/ssh/client.h @@ -22,11 +22,6 @@ #include -/** - * The maximum number of bytes to allow within the clipboard. - */ -#define GUAC_SSH_CLIPBOARD_MAX_LENGTH 262144 - /** * Handler which is invoked when the SSH client needs to be disconnected (if * connected) and freed. This can happen if initialization fails, or all users diff --git a/src/protocols/ssh/clipboard.c b/src/protocols/ssh/clipboard.c index 72e1ca01..64370b1d 100644 --- a/src/protocols/ssh/clipboard.c +++ b/src/protocols/ssh/clipboard.c @@ -22,6 +22,7 @@ #include "common/clipboard.h" #include "ssh.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include @@ -33,7 +34,7 @@ int guac_ssh_clipboard_handler(guac_user* user, guac_stream* stream, /* Clear clipboard and prepare for new data */ guac_client* client = user->client; guac_ssh_client* ssh_client = (guac_ssh_client*) client->data; - guac_common_clipboard_reset(ssh_client->clipboard, mimetype); + guac_common_clipboard_reset(ssh_client->term->clipboard, mimetype); /* Set handlers for clipboard stream */ stream->blob_handler = guac_ssh_clipboard_blob_handler; @@ -48,7 +49,7 @@ int guac_ssh_clipboard_blob_handler(guac_user* user, guac_stream* stream, /* Append new data */ guac_client* client = user->client; guac_ssh_client* ssh_client = (guac_ssh_client*) client->data; - guac_common_clipboard_append(ssh_client->clipboard, data, length); + guac_common_clipboard_append(ssh_client->term->clipboard, data, length); return 0; } diff --git a/src/protocols/ssh/input.c b/src/protocols/ssh/input.c index 4ad54199..5b849a09 100644 --- a/src/protocols/ssh/input.c +++ b/src/protocols/ssh/input.c @@ -24,6 +24,7 @@ #include "common/recording.h" #include "ssh.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 7cc7e995..c946e268 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -27,6 +27,7 @@ #include "sftp.h" #include "ssh.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include "ttymode.h" #ifdef ENABLE_SSH_AGENT @@ -240,8 +241,7 @@ void* ssh_client_thread(void* data) { /* Create terminal options with required parameters */ guac_terminal_options* options = guac_terminal_options_create( - client, ssh_client->clipboard, - settings->width, settings->height, settings->resolution); + client, settings->width, settings->height, settings->resolution); /* Set optional parameters */ options->disable_copy = settings->disable_copy; diff --git a/src/protocols/ssh/ssh.h b/src/protocols/ssh/ssh.h index cb5d8bc5..e623e4e6 100644 --- a/src/protocols/ssh/ssh.h +++ b/src/protocols/ssh/ssh.h @@ -90,11 +90,6 @@ typedef struct guac_ssh_client { */ pthread_mutex_t term_channel_lock; - /** - * The current clipboard contents. - */ - guac_common_clipboard* clipboard; - /** * The terminal which will render all output from the SSH client. */ diff --git a/src/protocols/ssh/user.c b/src/protocols/ssh/user.c index ea520b9e..6d598f4b 100644 --- a/src/protocols/ssh/user.c +++ b/src/protocols/ssh/user.c @@ -25,6 +25,7 @@ #include "input.h" #include "user.h" #include "pipe.h" +#include "terminal/terminal_priv.h" #include "sftp.h" #include "ssh.h" #include "settings.h" diff --git a/src/protocols/telnet/argv.c b/src/protocols/telnet/argv.c index cf8df05e..5604b9a7 100644 --- a/src/protocols/telnet/argv.c +++ b/src/protocols/telnet/argv.c @@ -21,6 +21,7 @@ #include "argv.h" #include "telnet.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include diff --git a/src/protocols/telnet/client.c b/src/protocols/telnet/client.c index c0c30e5c..fcb7e7a2 100644 --- a/src/protocols/telnet/client.c +++ b/src/protocols/telnet/client.c @@ -23,7 +23,6 @@ #include "common/recording.h" #include "settings.h" #include "telnet.h" -#include "terminal/terminal.h" #include "user.h" #include @@ -44,9 +43,6 @@ int guac_client_init(guac_client* client) { guac_telnet_client* telnet_client = calloc(1, sizeof(guac_telnet_client)); client->data = telnet_client; - /* Init clipboard */ - telnet_client->clipboard = guac_common_clipboard_alloc(GUAC_TELNET_CLIPBOARD_MAX_LENGTH); - /* Init telnet client */ telnet_client->socket_fd = -1; telnet_client->naws_enabled = 0; @@ -100,7 +96,6 @@ int guac_telnet_client_free_handler(guac_client* client) { if (telnet_client->settings != NULL) guac_telnet_settings_free(telnet_client->settings); - guac_common_clipboard_free(telnet_client->clipboard); free(telnet_client); return 0; diff --git a/src/protocols/telnet/client.h b/src/protocols/telnet/client.h index 47d21f28..8921a9f4 100644 --- a/src/protocols/telnet/client.h +++ b/src/protocols/telnet/client.h @@ -29,11 +29,6 @@ #include -/** - * The maximum number of bytes to allow within the clipboard. - */ -#define GUAC_TELNET_CLIPBOARD_MAX_LENGTH 262144 - /** * Free handler. Required by libguac and called when the guac_client is * disconnected and must be cleaned up. diff --git a/src/protocols/telnet/clipboard.c b/src/protocols/telnet/clipboard.c index b663b2c3..fa032640 100644 --- a/src/protocols/telnet/clipboard.c +++ b/src/protocols/telnet/clipboard.c @@ -22,6 +22,7 @@ #include "common/clipboard.h" #include "telnet.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include @@ -33,7 +34,7 @@ int guac_telnet_clipboard_handler(guac_user* user, guac_stream* stream, /* Clear clipboard and prepare for new data */ guac_client* client = user->client; guac_telnet_client* telnet_client = (guac_telnet_client*) client->data; - guac_common_clipboard_reset(telnet_client->clipboard, mimetype); + guac_common_clipboard_reset(telnet_client->term->clipboard, mimetype); /* Set handlers for clipboard stream */ stream->blob_handler = guac_telnet_clipboard_blob_handler; @@ -48,7 +49,7 @@ int guac_telnet_clipboard_blob_handler(guac_user* user, guac_stream* stream, /* Append new data */ guac_client* client = user->client; guac_telnet_client* telnet_client = (guac_telnet_client*) client->data; - guac_common_clipboard_append(telnet_client->clipboard, data, length); + guac_common_clipboard_append(telnet_client->term->clipboard, data, length); return 0; } diff --git a/src/protocols/telnet/input.c b/src/protocols/telnet/input.c index 9a63da40..a8431cc6 100644 --- a/src/protocols/telnet/input.c +++ b/src/protocols/telnet/input.c @@ -21,6 +21,7 @@ #include "common/recording.h" #include "input.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include "telnet.h" #include diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index 400b4c8b..d2ffdfd3 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -23,6 +23,7 @@ #include "common/recording.h" #include "telnet.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include @@ -587,8 +588,7 @@ void* guac_telnet_client_thread(void* data) { /* Create terminal options with required parameters */ guac_terminal_options* options = guac_terminal_options_create( - client, telnet_client->clipboard, - settings->width, settings->height, settings->resolution); + client, settings->width, settings->height, settings->resolution); /* Set optional parameters */ options->disable_copy = settings->disable_copy; diff --git a/src/protocols/telnet/telnet.h b/src/protocols/telnet/telnet.h index b68470fe..24ad4a8f 100644 --- a/src/protocols/telnet/telnet.h +++ b/src/protocols/telnet/telnet.h @@ -21,7 +21,6 @@ #define GUAC_TELNET_H #include "config.h" -#include "common/clipboard.h" #include "common/recording.h" #include "settings.h" #include "terminal/terminal.h" @@ -67,11 +66,6 @@ typedef struct guac_telnet_client { */ int echo_enabled; - /** - * The current clipboard contents. - */ - guac_common_clipboard* clipboard; - /** * The terminal which will render all output from the telnet client. */ diff --git a/src/protocols/telnet/user.c b/src/protocols/telnet/user.c index ba19eb44..d709a01c 100644 --- a/src/protocols/telnet/user.c +++ b/src/protocols/telnet/user.c @@ -26,6 +26,7 @@ #include "settings.h" #include "telnet.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include "user.h" #include diff --git a/src/protocols/vnc/client.c b/src/protocols/vnc/client.c index 6efe0058..581edf8f 100644 --- a/src/protocols/vnc/client.c +++ b/src/protocols/vnc/client.c @@ -55,7 +55,7 @@ int guac_client_init(guac_client* client) { #endif /* Init clipboard */ - vnc_client->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH); + vnc_client->clipboard = guac_common_clipboard_alloc(); /* Set handlers */ client->join_handler = guac_vnc_user_join_handler; diff --git a/src/protocols/vnc/client.h b/src/protocols/vnc/client.h index 32a26894..abaf7ba8 100644 --- a/src/protocols/vnc/client.h +++ b/src/protocols/vnc/client.h @@ -49,11 +49,6 @@ */ #define GUAC_VNC_CONNECT_INTERVAL 1000 -/** - * The maximum number of bytes to allow within the clipboard. - */ -#define GUAC_VNC_CLIPBOARD_MAX_LENGTH 262144 - /** * Handler which frees all data associated with the guac_client. */ diff --git a/src/protocols/vnc/clipboard.c b/src/protocols/vnc/clipboard.c index c3b1bd1f..319ca95f 100644 --- a/src/protocols/vnc/clipboard.c +++ b/src/protocols/vnc/clipboard.c @@ -103,7 +103,7 @@ int guac_vnc_clipboard_end_handler(guac_user* user, guac_stream* stream) { guac_vnc_client* vnc_client = (guac_vnc_client*) user->client->data; rfbClient* rfb_client = vnc_client->rfb_client; - char output_data[GUAC_VNC_CLIPBOARD_MAX_LENGTH]; + char output_data[GUAC_COMMON_CLIPBOARD_MAX_LENGTH]; const char* input = vnc_client->clipboard->buffer; char* output = output_data; @@ -129,7 +129,7 @@ void guac_vnc_cut_text(rfbClient* client, const char* text, int textlen) { if (vnc_client->settings->disable_copy) return; - char received_data[GUAC_VNC_CLIPBOARD_MAX_LENGTH]; + char received_data[GUAC_COMMON_CLIPBOARD_MAX_LENGTH]; const char* input = text; char* output = received_data; diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index 1b20f704..1219e968 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -30,6 +30,9 @@ lib_LTLIBRARIES = libguac-terminal.la libguac_terminalincdir = $(includedir)/guacamole/terminal +noinst_HEADERS = \ + terminal/terminal_priv.h + libguac_terminalinc_HEADERS = \ terminal/buffer.h \ terminal/char_mappings.h \ diff --git a/src/terminal/select.c b/src/terminal/select.c index 0a075ebd..a10687c5 100644 --- a/src/terminal/select.c +++ b/src/terminal/select.c @@ -24,6 +24,7 @@ #include "terminal/display.h" #include "terminal/select.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include "terminal/types.h" #include diff --git a/src/terminal/terminal-stdin-stream.c b/src/terminal/terminal-stdin-stream.c index 02f5b943..f9a2d617 100644 --- a/src/terminal/terminal-stdin-stream.c +++ b/src/terminal/terminal-stdin-stream.c @@ -20,6 +20,7 @@ #include "config.h" #include "terminal/common.h" #include "terminal/terminal.h" +#include "terminal/terminal_priv.h" #include #include diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 13a98d00..d76c00f5 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -29,6 +29,7 @@ #include "terminal/select.h" #include "terminal/terminal.h" #include "terminal/terminal_handlers.h" +#include "terminal/terminal_priv.h" #include "terminal/types.h" #include "terminal/typescript.h" @@ -307,14 +308,13 @@ void* guac_terminal_thread(void* data) { } guac_terminal_options* guac_terminal_options_create(guac_client* client, - guac_common_clipboard* clipboard, int width, int height, int dpi) { + int width, int height, int dpi) { guac_terminal_options* options = malloc(sizeof(guac_terminal_options)); /* Set all required parameters */ options->client = client; - options->clipboard = clipboard; options->width = width; options->height = height; options->dpi = dpi; @@ -416,7 +416,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) { /* Init terminal state */ term->current_attributes = default_char.attributes; term->default_char = default_char; - term->clipboard = options->clipboard; + term->clipboard = guac_common_clipboard_alloc(); term->disable_copy = options->disable_copy; /* Calculate character size */ @@ -546,6 +546,9 @@ void guac_terminal_free(guac_terminal* term) { free((char*) term->color_scheme); free((char*) term->font_name); + /* Free clipboard */ + guac_common_clipboard_free(term->clipboard); + /* Free the terminal itself */ free(term); diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index 11fd268f..3596580d 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -24,7 +24,6 @@ #include "config.h" #include "buffer.h" -#include "common/clipboard.h" #include "common/cursor.h" #include "display.h" #include "scrollbar.h" @@ -156,428 +155,6 @@ typedef void guac_terminal_upload_path_handler(guac_client* client, char* path); */ typedef guac_stream* guac_terminal_file_download_handler(guac_client* client, char* filename); -/** - * Represents a terminal emulator which uses a given Guacamole client to - * render itself. - */ -struct guac_terminal { - - /** - * The Guacamole client associated with this terminal emulator. - */ - guac_client* client; - - /** - * Whether user input should be handled and this terminal should render - * frames. Initially, this will be false, user input will be ignored, and - * rendering of frames will be withheld until guac_terminal_start() has - * been invoked. The data within frames will still be rendered, and text - * data received will still be handled, however actual frame boundaries - * will not be sent. - */ - bool started; - - /** - * The terminal render thread. - */ - pthread_t thread; - - /** - * Called whenever the necessary terminal codes are sent to change - * the path for future file uploads. - */ - guac_terminal_upload_path_handler* upload_path_handler; - - /** - * Called whenever the necessary terminal codes are sent to initiate - * a download of a given remote file. - */ - guac_terminal_file_download_handler* file_download_handler; - - /** - * Lock which restricts simultaneous access to this terminal via the root - * guac_terminal_* functions. - */ - pthread_mutex_t lock; - - /** - * The mutex associated with the modified condition and flag, locked - * whenever a thread is waiting on the modified condition, the modified - * condition is being signalled, or the modified flag is being changed. - */ - pthread_mutex_t modified_lock; - - /** - * Flag set whenever an operation has affected the terminal in a way that - * will require a frame flush. When this flag is set, the modified_cond - * condition will be signalled. The modified_lock will always be - * acquired before this flag is altered. - */ - int modified; - - /** - * Condition which is signalled when the modified flag has been set - */ - pthread_cond_t modified_cond; - - /** - * Pipe which will be the source of user input. When a terminal code - * generates synthesized user input, that data will be written to - * this pipe. - */ - int stdin_pipe_fd[2]; - - /** - * The currently-open pipe stream from which all terminal input should be - * read, if any. If no pipe stream is open, terminal input will be received - * through keyboard, clipboard, and mouse events, and this value will be - * NULL. - */ - guac_stream* input_stream; - - /** - * The currently-open pipe stream to which all terminal output should be - * written, if any. If no pipe stream is open, terminal output will be - * written to the terminal display, and this value will be NULL. - */ - guac_stream* pipe_stream; - - /** - * Bitwise OR of all flags which apply to the currently-open pipe stream. - * If no pipe stream is open, this value has no meaning, and its contents - * are undefined. - * - * @see GUAC_TERMINAL_PIPE_INTERPRET_OUTPUT - * @see GUAC_TERMINAL_PIPE_AUTOFLUSH - */ - int pipe_stream_flags; - - /** - * Buffer of data pending write to the pipe_stream. Data within this buffer - * will be flushed to the pipe_stream when either (1) the buffer is full - * and another character needs to be written or (2) the pipe_stream is - * closed. - */ - char pipe_buffer[6048]; - - /** - * The number of bytes currently stored within the pipe_buffer. - */ - int pipe_buffer_length; - - /** - * The currently-active typescript recording all terminal output, or NULL - * if no typescript is being used for the terminal session. - */ - guac_terminal_typescript* typescript; - - /** - * Terminal-wide mouse cursor, synchronized across all users. - */ - guac_common_cursor* cursor; - - /** - * Graphical representation of the current scroll state. - */ - guac_terminal_scrollbar* scrollbar; - - /** - * The relative offset of the display. A positive value indicates that - * many rows have been scrolled into view, zero indicates that no - * scrolling has occurred. Negative values are illegal. - */ - int scroll_offset; - - /** - * The maximum number of rows to allow within the terminal buffer. Note - * that while this value is traditionally referred to as the scrollback - * size, it actually encompasses both the display and the off-screen - * region. The terminal will ensure enough buffer space is allocated for - * the on-screen rows, even if this exceeds the defined maximum, however - * additional rows for off-screen data will only be available if the - * display is smaller than this value. - */ - int max_scrollback; - - /** - * The number of rows that the user has requested be avalable within the - * terminal buffer. This value may be adjusted by the user while the - * terminal is running through console codes, and will adjust the number - * of rows available within the terminal buffer, subject to the maximum - * defined at terminal creation and stored within max_scrollback. - */ - int requested_scrollback; - - /** - * The width of the space available to all components of the terminal, in - * pixels. This may include space which will not actually be used for - * character rendering. - */ - int outer_width; - - /** - * The height of the space available to all components of the terminal, in - * pixels. This may include space which will not actually be used for - * character rendering. - */ - int outer_height; - - /** - * The width of the terminal, in pixels. - */ - int width; - - /** - * The height of the terminal, in pixels. - */ - int height; - - /** - * The width of the terminal, in characters. - */ - int term_width; - - /** - * The height of the terminal, in characters. - */ - int term_height; - - /** - * The index of the first row in the scrolling region. - */ - int scroll_start; - - /** - * The index of the last row in the scrolling region. - */ - int scroll_end; - - /** - * The current row location of the cursor. Note that while most terminal - * operations will clip the cursor location within the bounds of the - * terminal, this is not guaranteed. - */ - int cursor_row; - - /** - * The current column location of the cursor. Note that while most - * terminal operations will clip the cursor location within the bounds - * of the terminal, this is not guaranteed. There are times when the - * cursor is legitimately outside the terminal bounds (such as when the - * end of a line is reached, but it is not yet necessary to scroll up). - */ - int cursor_col; - - /** - * The desired visibility state of the cursor. - */ - bool cursor_visible; - - /** - * The row of the rendered cursor. - * Will be set to -1 if the cursor is not visible. - */ - int visible_cursor_row; - - /** - * The column of the rendered cursor. - * Will be set to -1 if the cursor is not visible. - */ - int visible_cursor_col; - - /** - * The row of the saved cursor (ESC 7). - */ - int saved_cursor_row; - - /** - * The column of the saved cursor (ESC 7). - */ - int saved_cursor_col; - - /** - * The attributes which will be applied to future characters. - */ - guac_terminal_attributes current_attributes; - - /** - * The character whose attributes dictate the default attributes - * of all characters. When new screen space is allocated, this - * character fills the gaps. - */ - guac_terminal_char default_char; - - /** - * Handler which will receive all printed characters, updating the terminal - * accordingly. - */ - guac_terminal_char_handler* char_handler; - - /** - * The difference between the currently-rendered screen and the current - * state of the terminal, and the contextual information necessary to - * interpret and render those differences. - */ - guac_terminal_display* display; - - /** - * Current terminal display state. All characters present on the screen - * are within this buffer. This has nothing to do with the display, which - * facilitates transfer of a set of changes to the remote display. - */ - guac_terminal_buffer* buffer; - - /** - * Automatically place a tabstop every N characters. If zero, then no - * tabstops exist automatically. - */ - int tab_interval; - - /** - * Array of all tabs set. Each entry is the column number of a tab + 1, - * or 0 if that tab cell is unset. - */ - int custom_tabs[GUAC_TERMINAL_MAX_TABS]; - - /** - * Array of arrays of mapped characters, where the character N is located at the N-32 - * position within the array. Each element in a contained array is the corresponding Unicode - * codepoint. If NULL, a direct mapping from Unicode is used. The entries of the main array - * correspond to the character set in use (G0, G1, etc.) - */ - const int* char_mapping[2]; - - /** - * The active character set. For example, 0 for G0, 1 for G1, etc. - */ - int active_char_set; - - /** - * Whether text is currently selected. - */ - bool text_selected; - - /** - * Whether the selection is finished, and will no longer be modified. A - * committed selection remains highlighted for reference, but the - * highlight will be removed if characters within the selected region are - * modified. - */ - bool selection_committed; - - /** - * The row that the selection starts at. - */ - int selection_start_row; - - /** - * The column that the selection starts at. - */ - int selection_start_column; - - /** - * The width of the character at selection start. - */ - int selection_start_width; - - /** - * The row that the selection ends at. - */ - int selection_end_row; - - /** - * The column that the selection ends at. - */ - int selection_end_column; - - /** - * The width of the character at selection end. - */ - int selection_end_width; - - /** - * Whether the cursor (arrow) keys should send cursor sequences - * or application sequences (DECCKM). - */ - bool application_cursor_keys; - - /** - * Whether a CR should automatically follow a LF, VT, or FF. - */ - bool automatic_carriage_return; - - /** - * Whether insert mode is enabled (DECIM). - */ - bool insert_mode; - - /** - * Whether the alt key is currently being held down. - */ - int mod_alt; - - /** - * Whether the control key is currently being held down. - */ - int mod_ctrl; - - /** - * Whether the shift key is currently being held down. - */ - int mod_shift; - - /** - * The current mouse button state. - */ - int mouse_mask; - - /** - * The current mouse cursor, to avoid re-setting the cursor image. - */ - guac_terminal_cursor_type current_cursor; - - /** - * The current contents of the clipboard. This clipboard instance is - * maintained externally (will not be freed when this terminal is freed) - * and will be updated both internally by the terminal and externally - * through received clipboard instructions. - */ - guac_common_clipboard* clipboard; - - /** - * The name of the font to use when rendering glyphs, as requested at - * creation time or via guac_terminal_apply_font(). - */ - const char* font_name; - - /** - * The size of each glyph, in points, as requested at creation time or via - * guac_terminal_apply_font(). - */ - int font_size; - - /** - * The name of the color scheme to use, as requested at creation time or - * via guac_terminal_apply_color_scheme(). This string must be in the - * format accepted by guac_terminal_parse_color_scheme(). - */ - const char* color_scheme; - - /** - * ASCII character to send when backspace is pressed. - */ - char backspace; - - /** - * Whether copying from the terminal clipboard should be blocked. If set, - * the contents of the terminal can still be copied, but will be usable - * only within the terminal itself. The clipboard contents will not be - * automatically streamed to the client. - */ - bool disable_copy; - -}; - /** * Configuration options that may be passed when creating a new guac_terminal. * @@ -591,15 +168,6 @@ typedef struct guac_terminal_options { */ guac_client* client; - /** - * The guac_common_clipboard which will contain the current clipboard - * state. It is expected that this clipboard instance will be updated - * both internally by the terminal and externally through received - * clipboard instructions. This clipboard will not be automatically - * freed when this terminal is freed. - */ - guac_common_clipboard* clipboard; - /** * Whether copying from the terminal clipboard should be blocked. If set, * the contents of the terminal can still be copied, but will be usable @@ -691,10 +259,6 @@ guac_terminal* guac_terminal_create(guac_terminal_options* terminal_options); * @param guac_client * The client to which the terminal will be rendered. * - * @param clipboard - * The guac_common_clipboard which will contain the current clipboard - * state. - * * @param width * The width of the terminal, in pixels. * @@ -710,7 +274,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* terminal_options); * ready to have any defaults overriden as needed. */ guac_terminal_options* guac_terminal_options_create(guac_client* client, - guac_common_clipboard* clipboard, int width, int height, int dpi); + int width, int height, int dpi); /** * Frees all resources associated with the given terminal. diff --git a/src/terminal/terminal/terminal_priv.h b/src/terminal/terminal/terminal_priv.h new file mode 100644 index 00000000..0b26c834 --- /dev/null +++ b/src/terminal/terminal/terminal_priv.h @@ -0,0 +1,450 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +#ifndef _GUAC_TERMINAL_PRIV_H +#define _GUAC_TERMINAL_PRIV_H + +#include "common/clipboard.h" +#include "terminal/terminal.h" + +/** + * Represents a terminal emulator which uses a given Guacamole client to + * render itself. + */ +struct guac_terminal { + + /** + * The Guacamole client associated with this terminal emulator. + */ + guac_client* client; + + /** + * Whether user input should be handled and this terminal should render + * frames. Initially, this will be false, user input will be ignored, and + * rendering of frames will be withheld until guac_terminal_start() has + * been invoked. The data within frames will still be rendered, and text + * data received will still be handled, however actual frame boundaries + * will not be sent. + */ + bool started; + + /** + * The terminal render thread. + */ + pthread_t thread; + + /** + * Called whenever the necessary terminal codes are sent to change + * the path for future file uploads. + */ + guac_terminal_upload_path_handler* upload_path_handler; + + /** + * Called whenever the necessary terminal codes are sent to initiate + * a download of a given remote file. + */ + guac_terminal_file_download_handler* file_download_handler; + + /** + * Lock which restricts simultaneous access to this terminal via the root + * guac_terminal_* functions. + */ + pthread_mutex_t lock; + + /** + * The mutex associated with the modified condition and flag, locked + * whenever a thread is waiting on the modified condition, the modified + * condition is being signalled, or the modified flag is being changed. + */ + pthread_mutex_t modified_lock; + + /** + * Flag set whenever an operation has affected the terminal in a way that + * will require a frame flush. When this flag is set, the modified_cond + * condition will be signalled. The modified_lock will always be + * acquired before this flag is altered. + */ + int modified; + + /** + * Condition which is signalled when the modified flag has been set + */ + pthread_cond_t modified_cond; + + /** + * Pipe which will be the source of user input. When a terminal code + * generates synthesized user input, that data will be written to + * this pipe. + */ + int stdin_pipe_fd[2]; + + /** + * The currently-open pipe stream from which all terminal input should be + * read, if any. If no pipe stream is open, terminal input will be received + * through keyboard, clipboard, and mouse events, and this value will be + * NULL. + */ + guac_stream* input_stream; + + /** + * The currently-open pipe stream to which all terminal output should be + * written, if any. If no pipe stream is open, terminal output will be + * written to the terminal display, and this value will be NULL. + */ + guac_stream* pipe_stream; + + /** + * Bitwise OR of all flags which apply to the currently-open pipe stream. + * If no pipe stream is open, this value has no meaning, and its contents + * are undefined. + * + * @see GUAC_TERMINAL_PIPE_INTERPRET_OUTPUT + * @see GUAC_TERMINAL_PIPE_AUTOFLUSH + */ + int pipe_stream_flags; + + /** + * Buffer of data pending write to the pipe_stream. Data within this buffer + * will be flushed to the pipe_stream when either (1) the buffer is full + * and another character needs to be written or (2) the pipe_stream is + * closed. + */ + char pipe_buffer[6048]; + + /** + * The number of bytes currently stored within the pipe_buffer. + */ + int pipe_buffer_length; + + /** + * The currently-active typescript recording all terminal output, or NULL + * if no typescript is being used for the terminal session. + */ + guac_terminal_typescript* typescript; + + /** + * Terminal-wide mouse cursor, synchronized across all users. + */ + guac_common_cursor* cursor; + + /** + * Graphical representation of the current scroll state. + */ + guac_terminal_scrollbar* scrollbar; + + /** + * The relative offset of the display. A positive value indicates that + * many rows have been scrolled into view, zero indicates that no + * scrolling has occurred. Negative values are illegal. + */ + int scroll_offset; + + /** + * The maximum number of rows to allow within the terminal buffer. Note + * that while this value is traditionally referred to as the scrollback + * size, it actually encompasses both the display and the off-screen + * region. The terminal will ensure enough buffer space is allocated for + * the on-screen rows, even if this exceeds the defined maximum, however + * additional rows for off-screen data will only be available if the + * display is smaller than this value. + */ + int max_scrollback; + + /** + * The number of rows that the user has requested be avalable within the + * terminal buffer. This value may be adjusted by the user while the + * terminal is running through console codes, and will adjust the number + * of rows available within the terminal buffer, subject to the maximum + * defined at terminal creation and stored within max_scrollback. + */ + int requested_scrollback; + + /** + * The width of the space available to all components of the terminal, in + * pixels. This may include space which will not actually be used for + * character rendering. + */ + int outer_width; + + /** + * The height of the space available to all components of the terminal, in + * pixels. This may include space which will not actually be used for + * character rendering. + */ + int outer_height; + + /** + * The width of the terminal, in pixels. + */ + int width; + + /** + * The height of the terminal, in pixels. + */ + int height; + + /** + * The width of the terminal, in characters. + */ + int term_width; + + /** + * The height of the terminal, in characters. + */ + int term_height; + + /** + * The index of the first row in the scrolling region. + */ + int scroll_start; + + /** + * The index of the last row in the scrolling region. + */ + int scroll_end; + + /** + * The current row location of the cursor. Note that while most terminal + * operations will clip the cursor location within the bounds of the + * terminal, this is not guaranteed. + */ + int cursor_row; + + /** + * The current column location of the cursor. Note that while most + * terminal operations will clip the cursor location within the bounds + * of the terminal, this is not guaranteed. There are times when the + * cursor is legitimately outside the terminal bounds (such as when the + * end of a line is reached, but it is not yet necessary to scroll up). + */ + int cursor_col; + + /** + * The desired visibility state of the cursor. + */ + bool cursor_visible; + + /** + * The row of the rendered cursor. + * Will be set to -1 if the cursor is not visible. + */ + int visible_cursor_row; + + /** + * The column of the rendered cursor. + * Will be set to -1 if the cursor is not visible. + */ + int visible_cursor_col; + + /** + * The row of the saved cursor (ESC 7). + */ + int saved_cursor_row; + + /** + * The column of the saved cursor (ESC 7). + */ + int saved_cursor_col; + + /** + * The attributes which will be applied to future characters. + */ + guac_terminal_attributes current_attributes; + + /** + * The character whose attributes dictate the default attributes + * of all characters. When new screen space is allocated, this + * character fills the gaps. + */ + guac_terminal_char default_char; + + /** + * Handler which will receive all printed characters, updating the terminal + * accordingly. + */ + guac_terminal_char_handler* char_handler; + + /** + * The difference between the currently-rendered screen and the current + * state of the terminal, and the contextual information necessary to + * interpret and render those differences. + */ + guac_terminal_display* display; + + /** + * Current terminal display state. All characters present on the screen + * are within this buffer. This has nothing to do with the display, which + * facilitates transfer of a set of changes to the remote display. + */ + guac_terminal_buffer* buffer; + + /** + * Automatically place a tabstop every N characters. If zero, then no + * tabstops exist automatically. + */ + int tab_interval; + + /** + * Array of all tabs set. Each entry is the column number of a tab + 1, + * or 0 if that tab cell is unset. + */ + int custom_tabs[GUAC_TERMINAL_MAX_TABS]; + + /** + * Array of arrays of mapped characters, where the character N is located at the N-32 + * position within the array. Each element in a contained array is the corresponding Unicode + * codepoint. If NULL, a direct mapping from Unicode is used. The entries of the main array + * correspond to the character set in use (G0, G1, etc.) + */ + const int* char_mapping[2]; + + /** + * The active character set. For example, 0 for G0, 1 for G1, etc. + */ + int active_char_set; + + /** + * Whether text is currently selected. + */ + bool text_selected; + + /** + * Whether the selection is finished, and will no longer be modified. A + * committed selection remains highlighted for reference, but the + * highlight will be removed if characters within the selected region are + * modified. + */ + bool selection_committed; + + /** + * The row that the selection starts at. + */ + int selection_start_row; + + /** + * The column that the selection starts at. + */ + int selection_start_column; + + /** + * The width of the character at selection start. + */ + int selection_start_width; + + /** + * The row that the selection ends at. + */ + int selection_end_row; + + /** + * The column that the selection ends at. + */ + int selection_end_column; + + /** + * The width of the character at selection end. + */ + int selection_end_width; + + /** + * Whether the cursor (arrow) keys should send cursor sequences + * or application sequences (DECCKM). + */ + bool application_cursor_keys; + + /** + * Whether a CR should automatically follow a LF, VT, or FF. + */ + bool automatic_carriage_return; + + /** + * Whether insert mode is enabled (DECIM). + */ + bool insert_mode; + + /** + * Whether the alt key is currently being held down. + */ + int mod_alt; + + /** + * Whether the control key is currently being held down. + */ + int mod_ctrl; + + /** + * Whether the shift key is currently being held down. + */ + int mod_shift; + + /** + * The current mouse button state. + */ + int mouse_mask; + + /** + * The current mouse cursor, to avoid re-setting the cursor image. + */ + guac_terminal_cursor_type current_cursor; + + /** + * The current contents of the clipboard. This clipboard instance is + * maintained externally (will not be freed when this terminal is freed) + * and will be updated both internally by the terminal and externally + * through received clipboard instructions. + */ + guac_common_clipboard* clipboard; + + /** + * The name of the font to use when rendering glyphs, as requested at + * creation time or via guac_terminal_apply_font(). + */ + const char* font_name; + + /** + * The size of each glyph, in points, as requested at creation time or via + * guac_terminal_apply_font(). + */ + int font_size; + + /** + * The name of the color scheme to use, as requested at creation time or + * via guac_terminal_apply_color_scheme(). This string must be in the + * format accepted by guac_terminal_parse_color_scheme(). + */ + const char* color_scheme; + + /** + * ASCII character to send when backspace is pressed. + */ + char backspace; + + /** + * Whether copying from the terminal clipboard should be blocked. If set, + * the contents of the terminal can still be copied, but will be usable + * only within the terminal itself. The clipboard contents will not be + * automatically streamed to the client. + */ + bool disable_copy; + +}; + +#endif + diff --git a/src/terminal/terminal_handlers.c b/src/terminal/terminal_handlers.c index d406c486..a4079fca 100644 --- a/src/terminal/terminal_handlers.c +++ b/src/terminal/terminal_handlers.c @@ -23,6 +23,7 @@ #include "terminal/palette.h" #include "terminal/terminal.h" #include "terminal/terminal_handlers.h" +#include "terminal/terminal_priv.h" #include "terminal/types.h" #include "terminal/xparsecolor.h"