From 63bf5b329cc2821e814f5f00fc1158aa5cc6919c Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Mon, 21 Feb 2022 13:34:54 -0800 Subject: [PATCH 1/9] GUACAMOLE-1538: Rename library to match conventions. --- configure.ac | 2 +- src/terminal/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index be8ab5ca..54a958bc 100644 --- a/configure.ac +++ b/configure.ac @@ -194,7 +194,7 @@ AC_SUBST([LIBGUAC_CLIENT_RDP_LTLIB], '$(top_builddir)/src/protocols/rdp/libgua AC_SUBST([LIBGUAC_CLIENT_RDP_INCLUDE], '-I$(top_srcdir)/src/protocols/rdp') # Terminal emulator -AC_SUBST([TERMINAL_LTLIB], '$(top_builddir)/src/terminal/libguac_terminal.la') +AC_SUBST([TERMINAL_LTLIB], '$(top_builddir)/src/terminal/libguac-terminal.la') AC_SUBST([TERMINAL_INCLUDE], '-I$(top_srcdir)/src/terminal $(PANGO_CFLAGS) $(PANGOCAIRO_CFLAGS) $(COMMON_INCLUDE)') # Init directory diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index fa87412d..d7302b46 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -26,7 +26,7 @@ AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I m4 -lib_LTLIBRARIES = libguac_terminal.la +lib_LTLIBRARIES = libguac-terminal.la libguac_terminalincdir = $(includedir)/guacamole/terminal From 037045a054a6de2b5524152779286a8fd74361d5 Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Tue, 22 Feb 2022 11:07:24 -0800 Subject: [PATCH 2/9] GUACAMOLE-1538: Explicitly include the common lib; ensure no undefined symbols. --- src/terminal/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index d7302b46..1b20f704 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -70,6 +70,7 @@ libguac_terminal_la_CFLAGS = \ @PANGOCAIRO_CFLAGS@ libguac_terminal_la_LIBADD = \ + @COMMON_LTLIB@ \ @LIBGUAC_LTLIB@ libguac_terminal_la_LDFLAGS = \ From 589e0ecd037b3fc658058b1c13b99011b9073bfc Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Tue, 22 Feb 2022 12:45:35 -0800 Subject: [PATCH 3/9] GUACAMOLE-1538 - Consolidate clipboard handling; opaque clipboard struct to avoid exposing internal guac_common_clipboard. --- src/common/clipboard.c | 6 +- src/common/common/clipboard.h | 12 +- src/protocols/kubernetes/argv.c | 1 + src/protocols/kubernetes/client.c | 5 - src/protocols/kubernetes/client.h | 5 - src/protocols/kubernetes/clipboard.c | 5 +- src/protocols/kubernetes/input.c | 1 + src/protocols/kubernetes/kubernetes.c | 4 +- src/protocols/kubernetes/kubernetes.h | 5 - src/protocols/kubernetes/user.c | 1 + src/protocols/rdp/channels/cliprdr.c | 8 +- src/protocols/rdp/client.h | 5 - src/protocols/ssh/argv.c | 1 + src/protocols/ssh/client.c | 5 - src/protocols/ssh/client.h | 5 - src/protocols/ssh/clipboard.c | 5 +- src/protocols/ssh/input.c | 1 + src/protocols/ssh/ssh.c | 4 +- src/protocols/ssh/ssh.h | 5 - src/protocols/ssh/user.c | 1 + src/protocols/telnet/argv.c | 1 + src/protocols/telnet/client.c | 5 - src/protocols/telnet/client.h | 5 - src/protocols/telnet/clipboard.c | 5 +- src/protocols/telnet/input.c | 1 + src/protocols/telnet/telnet.c | 4 +- src/protocols/telnet/telnet.h | 6 - src/protocols/telnet/user.c | 1 + src/protocols/vnc/client.c | 2 +- src/protocols/vnc/client.h | 5 - src/protocols/vnc/clipboard.c | 4 +- src/terminal/Makefile.am | 3 + src/terminal/select.c | 1 + src/terminal/terminal-stdin-stream.c | 1 + src/terminal/terminal.c | 9 +- src/terminal/terminal/terminal.h | 438 +------------------------ src/terminal/terminal/terminal_priv.h | 450 ++++++++++++++++++++++++++ src/terminal/terminal_handlers.c | 1 + 38 files changed, 504 insertions(+), 523 deletions(-) create mode 100644 src/terminal/terminal/terminal_priv.h 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" From 6dd33a8d90907b93a29bc482e888e4a972a0be4d Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Tue, 22 Feb 2022 16:06:48 -0800 Subject: [PATCH 4/9] GUACAMOLE-1538: Do not use terminal internals outside of terminal code. --- src/protocols/kubernetes/argv.c | 16 +-- src/protocols/kubernetes/clipboard.c | 7 +- src/protocols/kubernetes/input.c | 6 +- src/protocols/kubernetes/kubernetes.c | 5 +- src/protocols/kubernetes/user.c | 5 +- src/protocols/ssh/argv.c | 13 ++- src/protocols/ssh/clipboard.c | 6 +- src/protocols/ssh/input.c | 4 +- src/protocols/ssh/ssh.c | 12 +- src/protocols/ssh/user.c | 6 +- src/protocols/telnet/argv.c | 14 ++- src/protocols/telnet/clipboard.c | 6 +- src/protocols/telnet/input.c | 11 +- src/protocols/telnet/telnet.c | 5 +- src/protocols/telnet/user.c | 5 +- src/terminal/terminal.c | 49 ++++++++ src/terminal/terminal/terminal.h | 159 +++++++++++++++++++++++--- src/terminal/terminal/terminal_priv.h | 4 - 18 files changed, 254 insertions(+), 79 deletions(-) diff --git a/src/protocols/kubernetes/argv.c b/src/protocols/kubernetes/argv.c index fa949f7e..5301855a 100644 --- a/src/protocols/kubernetes/argv.c +++ b/src/protocols/kubernetes/argv.c @@ -21,7 +21,6 @@ #include "argv.h" #include "kubernetes.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include #include @@ -54,8 +53,9 @@ int guac_kubernetes_argv_callback(guac_user* user, const char* mimetype, } /* Update Kubernetes terminal size */ - guac_kubernetes_resize(client, terminal->term_height, - terminal->term_width); + guac_kubernetes_resize(client, + guac_terminal_term_height(terminal), + guac_terminal_term_width(terminal)); return 0; @@ -68,20 +68,20 @@ void* guac_kubernetes_send_current_argv(guac_user* user, void* data) { /* Send current color scheme */ guac_user_stream_argv(user, user->socket, "text/plain", - GUAC_KUBERNETES_ARGV_COLOR_SCHEME, terminal->color_scheme); + GUAC_KUBERNETES_ARGV_COLOR_SCHEME, + guac_terminal_color_scheme(terminal)); /* Send current font name */ guac_user_stream_argv(user, user->socket, "text/plain", - GUAC_KUBERNETES_ARGV_FONT_NAME, terminal->font_name); + GUAC_KUBERNETES_ARGV_FONT_NAME, + guac_terminal_font_name(terminal)); /* Send current font size */ char font_size[64]; - sprintf(font_size, "%i", terminal->font_size); + sprintf(font_size, "%i", guac_terminal_font_size(terminal)); guac_user_stream_argv(user, user->socket, "text/plain", GUAC_KUBERNETES_ARGV_FONT_SIZE, font_size); return NULL; - } - diff --git a/src/protocols/kubernetes/clipboard.c b/src/protocols/kubernetes/clipboard.c index 8e9085b6..f031f11e 100644 --- a/src/protocols/kubernetes/clipboard.c +++ b/src/protocols/kubernetes/clipboard.c @@ -18,9 +18,8 @@ */ #include "clipboard.h" -#include "common/clipboard.h" #include "kubernetes.h" -#include "terminal/terminal_priv.h" +#include "terminal/terminal.h" #include #include @@ -34,7 +33,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->term->clipboard, mimetype); + guac_terminal_clipboard_reset(kubernetes_client->term, mimetype); /* Set handlers for clipboard stream */ stream->blob_handler = guac_kubernetes_clipboard_blob_handler; @@ -51,7 +50,7 @@ int guac_kubernetes_clipboard_blob_handler(guac_user* user, (guac_kubernetes_client*) client->data; /* Append new data */ - guac_common_clipboard_append(kubernetes_client->term->clipboard, data, length); + guac_terminal_clipboard_append(kubernetes_client->term, data, length); return 0; } diff --git a/src/protocols/kubernetes/input.c b/src/protocols/kubernetes/input.c index 88e73887..b3f5d259 100644 --- a/src/protocols/kubernetes/input.c +++ b/src/protocols/kubernetes/input.c @@ -21,7 +21,6 @@ #include "input.h" #include "kubernetes.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include #include @@ -87,8 +86,9 @@ int guac_kubernetes_user_size_handler(guac_user* user, int width, int height) { guac_terminal_resize(terminal, width, height); /* Update Kubernetes terminal window size if connected */ - guac_kubernetes_resize(client, terminal->term_height, - terminal->term_width); + guac_kubernetes_resize(client, + guac_terminal_term_height(terminal), + guac_terminal_term_width(terminal)); return 0; } diff --git a/src/protocols/kubernetes/kubernetes.c b/src/protocols/kubernetes/kubernetes.c index 5e17eb8a..f7142975 100644 --- a/src/protocols/kubernetes/kubernetes.c +++ b/src/protocols/kubernetes/kubernetes.c @@ -26,7 +26,6 @@ #include "kubernetes.h" #include "ssl.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include "url.h" #include @@ -414,8 +413,8 @@ void guac_kubernetes_force_redraw(guac_client* client) { /* Get current terminal dimensions */ guac_terminal* term = kubernetes_client->term; - int rows = term->term_height; - int columns = term->term_width; + int rows = guac_terminal_term_height(term); + int columns = guac_terminal_term_width(term); /* Force a redraw by increasing the terminal size by one character in * each dimension and then resizing it back to normal (the same technique diff --git a/src/protocols/kubernetes/user.c b/src/protocols/kubernetes/user.c index f1eb4de5..a1c067df 100644 --- a/src/protocols/kubernetes/user.c +++ b/src/protocols/kubernetes/user.c @@ -25,7 +25,6 @@ #include "pipe.h" #include "settings.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include "user.h" #include @@ -110,8 +109,8 @@ int guac_kubernetes_user_leave_handler(guac_user* user) { guac_kubernetes_client* kubernetes_client = (guac_kubernetes_client*) user->client->data; - /* Update shared cursor state */ - guac_common_cursor_remove_user(kubernetes_client->term->cursor, user); + /* Remove the user from the terminal */ + guac_terminal_remove_user(kubernetes_client->term, user); /* Free settings if not owner (owner settings will be freed with client) */ if (!user->owner) { diff --git a/src/protocols/ssh/argv.c b/src/protocols/ssh/argv.c index 040c4909..f1a03834 100644 --- a/src/protocols/ssh/argv.c +++ b/src/protocols/ssh/argv.c @@ -21,7 +21,6 @@ #include "argv.h" #include "ssh.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include #include @@ -55,10 +54,12 @@ int guac_ssh_argv_callback(guac_user* user, const char* mimetype, } /* Update SSH pty size if connected */ + int term_width = guac_terminal_term_width(terminal); + int term_height = guac_terminal_term_height(terminal); if (ssh_client->term_channel != NULL) { pthread_mutex_lock(&(ssh_client->term_channel_lock)); libssh2_channel_request_pty_size(ssh_client->term_channel, - terminal->term_width, terminal->term_height); + term_width, term_height); pthread_mutex_unlock(&(ssh_client->term_channel_lock)); } @@ -73,15 +74,17 @@ void* guac_ssh_send_current_argv(guac_user* user, void* data) { /* Send current color scheme */ guac_user_stream_argv(user, user->socket, "text/plain", - GUAC_SSH_ARGV_COLOR_SCHEME, terminal->color_scheme); + GUAC_SSH_ARGV_COLOR_SCHEME, + guac_terminal_color_scheme(terminal)); /* Send current font name */ guac_user_stream_argv(user, user->socket, "text/plain", - GUAC_SSH_ARGV_FONT_NAME, terminal->font_name); + GUAC_SSH_ARGV_FONT_NAME, + guac_terminal_font_name(terminal)); /* Send current font size */ char font_size[64]; - sprintf(font_size, "%i", terminal->font_size); + sprintf(font_size, "%i", guac_terminal_font_size(terminal)); guac_user_stream_argv(user, user->socket, "text/plain", GUAC_SSH_ARGV_FONT_SIZE, font_size); diff --git a/src/protocols/ssh/clipboard.c b/src/protocols/ssh/clipboard.c index 64370b1d..0e236325 100644 --- a/src/protocols/ssh/clipboard.c +++ b/src/protocols/ssh/clipboard.c @@ -19,10 +19,8 @@ #include "config.h" #include "clipboard.h" -#include "common/clipboard.h" #include "ssh.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include #include @@ -34,7 +32,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->term->clipboard, mimetype); + guac_terminal_clipboard_reset(ssh_client->term, mimetype); /* Set handlers for clipboard stream */ stream->blob_handler = guac_ssh_clipboard_blob_handler; @@ -49,7 +47,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->term->clipboard, data, length); + guac_terminal_clipboard_append(ssh_client->term, data, length); return 0; } diff --git a/src/protocols/ssh/input.c b/src/protocols/ssh/input.c index 5b849a09..f5826127 100644 --- a/src/protocols/ssh/input.c +++ b/src/protocols/ssh/input.c @@ -24,7 +24,6 @@ #include "common/recording.h" #include "ssh.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include #include @@ -89,7 +88,8 @@ int guac_ssh_user_size_handler(guac_user* user, int width, int height) { if (ssh_client->term_channel != NULL) { pthread_mutex_lock(&(ssh_client->term_channel_lock)); libssh2_channel_request_pty_size(ssh_client->term_channel, - terminal->term_width, terminal->term_height); + guac_terminal_term_width(terminal), + guac_terminal_term_height(terminal)); pthread_mutex_unlock(&(ssh_client->term_channel_lock)); } diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index c946e268..8249ac07 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -27,7 +27,6 @@ #include "sftp.h" #include "ssh.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include "ttymode.h" #ifdef ENABLE_SSH_AGENT @@ -359,10 +358,12 @@ void* ssh_client_thread(void* data) { /* Init handlers for Guacamole-specific console codes */ if (!settings->sftp_disable_upload) - ssh_client->term->upload_path_handler = guac_sftp_set_upload_path; + guac_terminal_set_upload_path_handler(ssh_client->term, + guac_sftp_set_upload_path); if (!settings->sftp_disable_download) - ssh_client->term->file_download_handler = guac_sftp_download_file; + guac_terminal_set_file_download_handler(ssh_client->term, + guac_sftp_download_file); guac_client_log(client, GUAC_LOG_DEBUG, "SFTP session initialized"); @@ -376,10 +377,11 @@ void* ssh_client_thread(void* data) { " Backspace may not work as expected."); /* Request PTY */ + int term_height = guac_terminal_term_height(ssh_client->term); + int term_width = guac_terminal_term_width(ssh_client->term); if (libssh2_channel_request_pty_ex(ssh_client->term_channel, settings->terminal_type, strlen(settings->terminal_type), - ssh_ttymodes, ttymodeBytes, ssh_client->term->term_width, - ssh_client->term->term_height, 0, 0)) { + ssh_ttymodes, ttymodeBytes, term_width, term_height, 0, 0)) { guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR, "Unable to allocate PTY."); return NULL; } diff --git a/src/protocols/ssh/user.c b/src/protocols/ssh/user.c index 6d598f4b..12488402 100644 --- a/src/protocols/ssh/user.c +++ b/src/protocols/ssh/user.c @@ -25,7 +25,7 @@ #include "input.h" #include "user.h" #include "pipe.h" -#include "terminal/terminal_priv.h" +#include "terminal/terminal.h" #include "sftp.h" #include "ssh.h" #include "settings.h" @@ -114,8 +114,8 @@ int guac_ssh_user_leave_handler(guac_user* user) { guac_ssh_client* ssh_client = (guac_ssh_client*) user->client->data; - /* Update shared cursor state */ - guac_common_cursor_remove_user(ssh_client->term->cursor, user); + /* Remove the user from the terminal */ + guac_terminal_remove_user(ssh_client->term, user); /* Free settings if not owner (owner settings will be freed with client) */ if (!user->owner) { diff --git a/src/protocols/telnet/argv.c b/src/protocols/telnet/argv.c index 5604b9a7..25b1dbe1 100644 --- a/src/protocols/telnet/argv.c +++ b/src/protocols/telnet/argv.c @@ -21,7 +21,6 @@ #include "argv.h" #include "telnet.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include #include @@ -55,8 +54,9 @@ int guac_telnet_argv_callback(guac_user* user, const char* mimetype, /* Update terminal window size if connected */ if (telnet_client->telnet != NULL && telnet_client->naws_enabled) - guac_telnet_send_naws(telnet_client->telnet, terminal->term_width, - terminal->term_height); + guac_telnet_send_naws(telnet_client->telnet, + guac_terminal_term_width(terminal), + guac_terminal_term_height(terminal)); return 0; @@ -69,15 +69,17 @@ void* guac_telnet_send_current_argv(guac_user* user, void* data) { /* Send current color scheme */ guac_user_stream_argv(user, user->socket, "text/plain", - GUAC_TELNET_ARGV_COLOR_SCHEME, terminal->color_scheme); + GUAC_TELNET_ARGV_COLOR_SCHEME, + guac_terminal_color_scheme(terminal)); /* Send current font name */ guac_user_stream_argv(user, user->socket, "text/plain", - GUAC_TELNET_ARGV_FONT_NAME, terminal->font_name); + GUAC_TELNET_ARGV_FONT_NAME, + guac_terminal_font_name(terminal)); /* Send current font size */ char font_size[64]; - sprintf(font_size, "%i", terminal->font_size); + sprintf(font_size, "%i", guac_terminal_font_size(terminal)); guac_user_stream_argv(user, user->socket, "text/plain", GUAC_TELNET_ARGV_FONT_SIZE, font_size); diff --git a/src/protocols/telnet/clipboard.c b/src/protocols/telnet/clipboard.c index fa032640..08d28b11 100644 --- a/src/protocols/telnet/clipboard.c +++ b/src/protocols/telnet/clipboard.c @@ -19,10 +19,8 @@ #include "config.h" #include "clipboard.h" -#include "common/clipboard.h" #include "telnet.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include #include @@ -34,7 +32,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->term->clipboard, mimetype); + guac_terminal_clipboard_reset(telnet_client->term, mimetype); /* Set handlers for clipboard stream */ stream->blob_handler = guac_telnet_clipboard_blob_handler; @@ -49,7 +47,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->term->clipboard, data, length); + guac_terminal_clipboard_append(telnet_client->term, data, length); return 0; } diff --git a/src/protocols/telnet/input.c b/src/protocols/telnet/input.c index a8431cc6..9ecfbaba 100644 --- a/src/protocols/telnet/input.c +++ b/src/protocols/telnet/input.c @@ -21,7 +21,6 @@ #include "common/recording.h" #include "input.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include "telnet.h" #include @@ -101,7 +100,10 @@ int guac_telnet_user_key_handler(guac_user* user, int keysym, int pressed) { if (pressed && ( keysym == 0xFF13 /* Pause */ || keysym == 0xFF6B /* Break */ - || (term->mod_ctrl && keysym == '0') /* Ctrl + 0 */ + || ( + guac_terminal_mod_ctrl(term) + && keysym == '0' + ) /* Ctrl + 0 */ )) { /* Send IAC BRK */ @@ -133,8 +135,9 @@ int guac_telnet_user_size_handler(guac_user* user, int width, int height) { /* Update terminal window size if connected */ if (telnet_client->telnet != NULL && telnet_client->naws_enabled) - guac_telnet_send_naws(telnet_client->telnet, terminal->term_width, - terminal->term_height); + guac_telnet_send_naws(telnet_client->telnet, + guac_terminal_term_width(terminal), + guac_terminal_term_height(terminal)); return 0; } diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index d2ffdfd3..61417854 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -23,7 +23,6 @@ #include "common/recording.h" #include "telnet.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include #include @@ -303,7 +302,9 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event, case TELNET_EV_DO: if (event->neg.telopt == TELNET_TELOPT_NAWS) { telnet_client->naws_enabled = 1; - guac_telnet_send_naws(telnet, telnet_client->term->term_width, telnet_client->term->term_height); + guac_telnet_send_naws(telnet, + guac_terminal_term_width(telnet_client->term), + guac_terminal_term_height(telnet_client->term)); } break; diff --git a/src/protocols/telnet/user.c b/src/protocols/telnet/user.c index d709a01c..2c0e1c61 100644 --- a/src/protocols/telnet/user.c +++ b/src/protocols/telnet/user.c @@ -26,7 +26,6 @@ #include "settings.h" #include "telnet.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" #include "user.h" #include @@ -109,8 +108,8 @@ int guac_telnet_user_leave_handler(guac_user* user) { guac_telnet_client* telnet_client = (guac_telnet_client*) user->client->data; - /* Update shared cursor state */ - guac_common_cursor_remove_user(telnet_client->term->cursor, user); + /* Remove the user from the terminal */ + guac_terminal_remove_user(telnet_client->term, user); /* Free settings if not owner (owner settings will be freed with client) */ if (!user->owner) { diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index d76c00f5..ace2056a 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -190,6 +190,14 @@ int guac_terminal_available_scroll(guac_terminal* term) { return guac_terminal_effective_buffer_length(term) - term->term_height; } +int guac_terminal_term_height(guac_terminal* term) { + return term->term_height; +} + +int guac_terminal_term_width(guac_terminal* term) { + return term->term_width; +} + void guac_terminal_reset(guac_terminal* term) { int row; @@ -2020,6 +2028,10 @@ void guac_terminal_apply_color_scheme(guac_terminal* terminal, } +const char* guac_terminal_color_scheme(guac_terminal* terminal) { + return terminal->color_scheme; +} + void guac_terminal_apply_font(guac_terminal* terminal, const char* font_name, int font_size, int dpi) { @@ -2058,3 +2070,40 @@ void guac_terminal_apply_font(guac_terminal* terminal, const char* font_name, } +void guac_terminal_set_upload_path_handler(guac_terminal* terminal, + guac_terminal_upload_path_handler* upload_path_handler) { + terminal->upload_path_handler = upload_path_handler; +} + +void guac_terminal_set_file_download_handler(guac_terminal* terminal, + guac_terminal_file_download_handler* file_download_handler) { + terminal->file_download_handler = file_download_handler; +} + +const char* guac_terminal_font_name(guac_terminal* terminal) { + return terminal->font_name; +} + +int guac_terminal_font_size(guac_terminal* terminal) { + return terminal->font_size; +} + +int guac_terminal_mod_ctrl(guac_terminal* terminal) { + return terminal->mod_ctrl; +} + +void guac_terminal_clipboard_reset(guac_terminal* terminal, + const char* mimetype) { + guac_common_clipboard_reset(terminal->clipboard, mimetype); +} + +void guac_terminal_clipboard_append(guac_terminal* terminal, + const char* data, int length) { + guac_common_clipboard_append(terminal->clipboard, data, length); +} + +void guac_terminal_remove_user(guac_terminal* terminal, guac_user* user) { + + /* Remove the user from the terminal cursor */ + guac_common_cursor_remove_user(terminal->cursor, user); +} \ No newline at end of file diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index 3596580d..3c7c8e15 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -114,6 +114,10 @@ */ #define GUAC_TERMINAL_PIPE_AUTOFLUSH 2 +/** + * Represents a terminal emulator which uses a given Guacamole client to + * render itself. + */ typedef struct guac_terminal guac_terminal; /** @@ -281,6 +285,32 @@ guac_terminal_options* guac_terminal_options_create(guac_client* client, */ void guac_terminal_free(guac_terminal* term); +/** + * Set the upload path handler for the given terminal. + * + * @param terminal + * The terminal to set the upload path handler for. + * + * @param upload_path_handler + * The handler to be called whenever the necessary terminal codes are sent + * to the given terminal to change the path for future file uploads. + */ +void guac_terminal_set_upload_path_handler(guac_terminal* terminal, + guac_terminal_upload_path_handler* upload_path_handler); + +/** + * Set the file download handler for the given terminal. + * + * @param terminal + * The terminal to set the file download handler for. + * + * @param upload_path_handler + * The handler to be called whenever the necessary terminal codes are sent to + * the given terminal to initiate a download of a given remote file. + */ +void guac_terminal_set_file_download_handler(guac_terminal* terminal, + guac_terminal_file_download_handler* file_download_handler); + /** * Renders a single frame of terminal data. If data is not yet available, * this function will block until data is written. @@ -479,6 +509,75 @@ void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value) void guac_terminal_dup(guac_terminal* term, guac_user* user, guac_socket* socket); +/** + * Returns the number of rows within the buffer of the given terminal which are + * not currently displayed on screen. Adjustments to the desired scrollback + * size are taken into account, and rows which are within the buffer but + * unavailable due to being outside the desired scrollback range are ignored. + * + * @param term + * The terminal whose off-screen row count should be determined. + * + * @return + * The number of rows within the buffer which are not currently displayed + * on screen. + */ +int guac_terminal_available_scroll(guac_terminal* term); + +/** + * Returns the height of the given terminal, in characters. + * + * @param term + * The terminal whose height should be determined. + * + * @return + * The height of the terminal, in characters. + */ +int guac_terminal_term_height(guac_terminal* term); + +/** + * Returns the width of the given terminal, in characters. + * + * @param term + * The terminal whose width should be determined. + * + * @return + * The width of the terminal, in characters. + */ +int guac_terminal_term_width(guac_terminal* term); + +/** + * Clears the clipboard contents for a given terminal, and assigns a new + * mimetype for future data. + * + * @param terminal The terminal whose clipboard is being reset. + * @param mimetype The mimetype of future data. + */ +void guac_terminal_clipboard_reset(guac_terminal* terminal, + const char* mimetype); + +/** + * Appends the given data to the contents of the clipboard for the given + * terminal. The data must match the mimetype chosen for the clipboard data by + * guac_terminal_clipboard_reset(). + * + * @param terminal The terminal whose clipboard is being appended to. + * @param data The data to append. + * @param length The number of bytes to append from the data given. + */ +void guac_terminal_clipboard_append(guac_terminal* terminal, + const char* data, int length); + +/** + * Removes the given user from any user-specific resources internal to the + * given terminal. This function must be called whenever a user leaves a + * terminal connection. + * + * @param terminal The terminal that the given user is leaving. + * @param user The user who is disconnecting. + */ +void guac_terminal_remove_user(guac_terminal* terminal, guac_user* user); + /* INTERNAL FUNCTIONS */ @@ -767,21 +866,6 @@ void guac_terminal_pipe_stream_close(guac_terminal* term); int guac_terminal_create_typescript(guac_terminal* term, const char* path, const char* name, int create_path); -/** - * Returns the number of rows within the buffer of the given terminal which are - * not currently displayed on screen. Adjustments to the desired scrollback - * size are taken into account, and rows which are within the buffer but - * unavailable due to being outside the desired scrollback range are ignored. - * - * @param term - * The terminal whose off-screen row count should be determined. - * - * @return - * The number of rows within the buffer which are not currently displayed - * on screen. - */ -int guac_terminal_available_scroll(guac_terminal* term); - /** * Immediately applies the given color scheme to the given terminal, overriding * the color scheme provided when the terminal was created. Valid color schemes @@ -796,6 +880,17 @@ int guac_terminal_available_scroll(guac_terminal* term); void guac_terminal_apply_color_scheme(guac_terminal* terminal, const char* color_scheme); +/** + * Returns name of the color scheme currently in use by the given terminal. + * + * @param terminal + * The terminal whose color scheme should be returned. + * + * @return + * The name of the color scheme currently in use by the given terminal. + */ +const char* guac_terminal_color_scheme(guac_terminal* terminal); + /** * Alters the font of the terminal. The terminal will automatically be redrawn * and resized as necessary. If the terminal size changes, the remote side of @@ -820,5 +915,37 @@ void guac_terminal_apply_color_scheme(guac_terminal* terminal, void guac_terminal_apply_font(guac_terminal* terminal, const char* font_name, int font_size, int dpi); -#endif +/** + * Returns the font name currently in use by the given terminal. + * + * @param terminal + * The terminal whose font name is being retrieved. + * + * @return + * The name of the font in use by the given terminal. + */ +const char* guac_terminal_font_name(guac_terminal* terminal); +/** + * Returns the font size currently in use by the given terminal. + * + * @param terminal + * The terminal whose font size is being retrieved. + * + * @return + * The size of the font in use by the given terminal. + */ +int guac_terminal_font_size(guac_terminal* terminal); + +/** + * Returns the current state of the mod_ctrl flag in the given terminal. + * + * @param terminal + * The terminal for which the mod_ctrl state is being checked. + * + * @return + * The current state of the mod_ctrl flag. + */ +int guac_terminal_mod_ctrl(guac_terminal* terminal); + +#endif diff --git a/src/terminal/terminal/terminal_priv.h b/src/terminal/terminal/terminal_priv.h index 0b26c834..6b165444 100644 --- a/src/terminal/terminal/terminal_priv.h +++ b/src/terminal/terminal/terminal_priv.h @@ -24,10 +24,6 @@ #include "common/clipboard.h" #include "terminal/terminal.h" -/** - * Represents a terminal emulator which uses a given Guacamole client to - * render itself. - */ struct guac_terminal { /** From ce2ffdf75ffbb3c65cd68eedc8d2855088568e5e Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Tue, 22 Feb 2022 20:37:42 -0800 Subject: [PATCH 5/9] GUACAMOLE-1538: Improve code style and cleanliness. --- src/protocols/kubernetes/argv.c | 4 +-- src/protocols/kubernetes/input.c | 4 +-- src/protocols/kubernetes/kubernetes.c | 8 +++--- src/protocols/ssh/argv.c | 4 +-- src/protocols/ssh/input.c | 4 +-- src/protocols/ssh/ssh.c | 8 +++--- src/protocols/telnet/argv.c | 4 +-- src/protocols/telnet/input.c | 4 +-- src/protocols/telnet/telnet.c | 8 +++--- src/terminal/terminal.c | 21 +++++++------- src/terminal/terminal/terminal.h | 41 ++++++++++++++------------- src/terminal/terminal/terminal_priv.h | 4 +-- 12 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/protocols/kubernetes/argv.c b/src/protocols/kubernetes/argv.c index 5301855a..009e2480 100644 --- a/src/protocols/kubernetes/argv.c +++ b/src/protocols/kubernetes/argv.c @@ -54,8 +54,8 @@ int guac_kubernetes_argv_callback(guac_user* user, const char* mimetype, /* Update Kubernetes terminal size */ guac_kubernetes_resize(client, - guac_terminal_term_height(terminal), - guac_terminal_term_width(terminal)); + guac_terminal_get_rows(terminal), + guac_terminal_get_columns(terminal)); return 0; diff --git a/src/protocols/kubernetes/input.c b/src/protocols/kubernetes/input.c index b3f5d259..a24f4645 100644 --- a/src/protocols/kubernetes/input.c +++ b/src/protocols/kubernetes/input.c @@ -87,8 +87,8 @@ int guac_kubernetes_user_size_handler(guac_user* user, int width, int height) { /* Update Kubernetes terminal window size if connected */ guac_kubernetes_resize(client, - guac_terminal_term_height(terminal), - guac_terminal_term_width(terminal)); + guac_terminal_get_rows(terminal), + guac_terminal_get_columns(terminal)); return 0; } diff --git a/src/protocols/kubernetes/kubernetes.c b/src/protocols/kubernetes/kubernetes.c index f7142975..4acaa4d8 100644 --- a/src/protocols/kubernetes/kubernetes.c +++ b/src/protocols/kubernetes/kubernetes.c @@ -241,7 +241,7 @@ void* guac_kubernetes_client_thread(void* data) { /* Create terminal options with required parameters */ guac_terminal_options* options = guac_terminal_options_create( - client, settings->width, settings->height, settings->resolution); + settings->width, settings->height, settings->resolution); /* Set optional parameters */ options->disable_copy = settings->disable_copy; @@ -252,7 +252,7 @@ void* guac_kubernetes_client_thread(void* data) { options->backspace = settings->backspace; /* Create terminal */ - kubernetes_client->term = guac_terminal_create(options); + kubernetes_client->term = guac_terminal_create(client, options); /* Free options struct now that it's been used */ free(options); @@ -413,8 +413,8 @@ void guac_kubernetes_force_redraw(guac_client* client) { /* Get current terminal dimensions */ guac_terminal* term = kubernetes_client->term; - int rows = guac_terminal_term_height(term); - int columns = guac_terminal_term_width(term); + int rows = guac_terminal_get_rows(term); + int columns = guac_terminal_get_columns(term); /* Force a redraw by increasing the terminal size by one character in * each dimension and then resizing it back to normal (the same technique diff --git a/src/protocols/ssh/argv.c b/src/protocols/ssh/argv.c index f1a03834..af191f4e 100644 --- a/src/protocols/ssh/argv.c +++ b/src/protocols/ssh/argv.c @@ -54,8 +54,8 @@ int guac_ssh_argv_callback(guac_user* user, const char* mimetype, } /* Update SSH pty size if connected */ - int term_width = guac_terminal_term_width(terminal); - int term_height = guac_terminal_term_height(terminal); + int term_width = guac_terminal_get_columns(terminal); + int term_height = guac_terminal_get_rows(terminal); if (ssh_client->term_channel != NULL) { pthread_mutex_lock(&(ssh_client->term_channel_lock)); libssh2_channel_request_pty_size(ssh_client->term_channel, diff --git a/src/protocols/ssh/input.c b/src/protocols/ssh/input.c index f5826127..73f45fce 100644 --- a/src/protocols/ssh/input.c +++ b/src/protocols/ssh/input.c @@ -88,8 +88,8 @@ int guac_ssh_user_size_handler(guac_user* user, int width, int height) { if (ssh_client->term_channel != NULL) { pthread_mutex_lock(&(ssh_client->term_channel_lock)); libssh2_channel_request_pty_size(ssh_client->term_channel, - guac_terminal_term_width(terminal), - guac_terminal_term_height(terminal)); + guac_terminal_get_columns(terminal), + guac_terminal_get_rows(terminal)); pthread_mutex_unlock(&(ssh_client->term_channel_lock)); } diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 8249ac07..e1a16541 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -240,7 +240,7 @@ void* ssh_client_thread(void* data) { /* Create terminal options with required parameters */ guac_terminal_options* options = guac_terminal_options_create( - client, settings->width, settings->height, settings->resolution); + settings->width, settings->height, settings->resolution); /* Set optional parameters */ options->disable_copy = settings->disable_copy; @@ -251,7 +251,7 @@ void* ssh_client_thread(void* data) { options->backspace = settings->backspace; /* Create terminal */ - ssh_client->term = guac_terminal_create(options); + ssh_client->term = guac_terminal_create(client, options); /* Free options struct now that it's been used */ free(options); @@ -377,8 +377,8 @@ void* ssh_client_thread(void* data) { " Backspace may not work as expected."); /* Request PTY */ - int term_height = guac_terminal_term_height(ssh_client->term); - int term_width = guac_terminal_term_width(ssh_client->term); + int term_height = guac_terminal_get_rows(ssh_client->term); + int term_width = guac_terminal_get_columns(ssh_client->term); if (libssh2_channel_request_pty_ex(ssh_client->term_channel, settings->terminal_type, strlen(settings->terminal_type), ssh_ttymodes, ttymodeBytes, term_width, term_height, 0, 0)) { diff --git a/src/protocols/telnet/argv.c b/src/protocols/telnet/argv.c index 25b1dbe1..59814a71 100644 --- a/src/protocols/telnet/argv.c +++ b/src/protocols/telnet/argv.c @@ -55,8 +55,8 @@ int guac_telnet_argv_callback(guac_user* user, const char* mimetype, /* Update terminal window size if connected */ if (telnet_client->telnet != NULL && telnet_client->naws_enabled) guac_telnet_send_naws(telnet_client->telnet, - guac_terminal_term_width(terminal), - guac_terminal_term_height(terminal)); + guac_terminal_get_columns(terminal), + guac_terminal_get_rows(terminal)); return 0; diff --git a/src/protocols/telnet/input.c b/src/protocols/telnet/input.c index 9ecfbaba..dbd2e5f8 100644 --- a/src/protocols/telnet/input.c +++ b/src/protocols/telnet/input.c @@ -136,8 +136,8 @@ int guac_telnet_user_size_handler(guac_user* user, int width, int height) { /* Update terminal window size if connected */ if (telnet_client->telnet != NULL && telnet_client->naws_enabled) guac_telnet_send_naws(telnet_client->telnet, - guac_terminal_term_width(terminal), - guac_terminal_term_height(terminal)); + guac_terminal_get_columns(terminal), + guac_terminal_get_rows(terminal)); return 0; } diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index 61417854..242542e2 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -303,8 +303,8 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event, if (event->neg.telopt == TELNET_TELOPT_NAWS) { telnet_client->naws_enabled = 1; guac_telnet_send_naws(telnet, - guac_terminal_term_width(telnet_client->term), - guac_terminal_term_height(telnet_client->term)); + guac_terminal_get_columns(telnet_client->term), + guac_terminal_get_rows(telnet_client->term)); } break; @@ -589,7 +589,7 @@ void* guac_telnet_client_thread(void* data) { /* Create terminal options with required parameters */ guac_terminal_options* options = guac_terminal_options_create( - client, settings->width, settings->height, settings->resolution); + settings->width, settings->height, settings->resolution); /* Set optional parameters */ options->disable_copy = settings->disable_copy; @@ -600,7 +600,7 @@ void* guac_telnet_client_thread(void* data) { options->backspace = settings->backspace; /* Create terminal */ - telnet_client->term = guac_terminal_create(options); + telnet_client->term = guac_terminal_create(client, options); /* Free options struct now that it's been used */ free(options); diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index ace2056a..c67998cc 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -190,11 +190,11 @@ int guac_terminal_available_scroll(guac_terminal* term) { return guac_terminal_effective_buffer_length(term) - term->term_height; } -int guac_terminal_term_height(guac_terminal* term) { +int guac_terminal_get_rows(guac_terminal* term) { return term->term_height; } -int guac_terminal_term_width(guac_terminal* term) { +int guac_terminal_get_columns(guac_terminal* term) { return term->term_width; } @@ -315,14 +315,12 @@ void* guac_terminal_thread(void* data) { } -guac_terminal_options* guac_terminal_options_create(guac_client* client, +guac_terminal_options* guac_terminal_options_create( int width, int height, int dpi) { - guac_terminal_options* options = malloc(sizeof(guac_terminal_options)); /* Set all required parameters */ - options->client = client; options->width = width; options->height = height; options->dpi = dpi; @@ -338,7 +336,8 @@ guac_terminal_options* guac_terminal_options_create(guac_client* client, return options; } -guac_terminal* guac_terminal_create(guac_terminal_options* options) { +guac_terminal* guac_terminal_create(guac_client* client, + guac_terminal_options* options) { /* The width and height may need to be changed from what's requested */ int width = options->width; @@ -360,7 +359,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) { guac_terminal_color (*default_palette)[256] = (guac_terminal_color(*)[256]) malloc(sizeof(guac_terminal_color[256])); - guac_terminal_parse_color_scheme(options->client, options->color_scheme, + guac_terminal_parse_color_scheme(client, options->color_scheme, &default_char.attributes.foreground, &default_char.attributes.background, default_palette); @@ -372,7 +371,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) { guac_terminal* term = malloc(sizeof(guac_terminal)); term->started = false; - term->client = options->client; + term->client = client; term->upload_path_handler = NULL; term->file_download_handler = NULL; @@ -405,7 +404,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) { &default_char); /* Init display */ - term->display = guac_terminal_display_alloc(options->client, + term->display = guac_terminal_display_alloc(client, options->font_name, options->font_size, options->dpi, &default_char.attributes.foreground, &default_char.attributes.background, @@ -413,13 +412,13 @@ guac_terminal* guac_terminal_create(guac_terminal_options* options) { /* Fail if display init failed */ if (term->display == NULL) { - guac_client_log(options->client, GUAC_LOG_DEBUG, "Display initialization failed"); + guac_client_log(client, GUAC_LOG_DEBUG, "Display initialization failed"); free(term); return NULL; } /* Init common cursor */ - term->cursor = guac_common_cursor_alloc(options->client); + term->cursor = guac_common_cursor_alloc(client); /* Init terminal state */ term->current_attributes = default_char.attributes; diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index 3c7c8e15..c78f61f4 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -167,11 +167,6 @@ typedef guac_stream* guac_terminal_file_download_handler(guac_client* client, ch */ typedef struct guac_terminal_options { - /** - * The client to which the terminal will be rendered. - */ - guac_client* client; - /** * Whether copying from the terminal clipboard should be blocked. If set, * the contents of the terminal can still be copied, but will be usable @@ -242,6 +237,9 @@ typedef struct guac_terminal_options { * either the underlying connection has truly succeeded, or until visible * terminal output or user input is required. * + * @param client + * The client to which the terminal will be rendered. + * * @param terminal_options * The configuration used for instantiating the terminal. For information * about the options, see the guac_terminal_options definition. @@ -250,7 +248,8 @@ typedef struct guac_terminal_options { * A new guac_terminal having the given font, dimensions, and attributes * which renders all text to the given client. */ -guac_terminal* guac_terminal_create(guac_terminal_options* terminal_options); +guac_terminal* guac_terminal_create(guac_client* client, + guac_terminal_options* terminal_options); /** * Create a new guac_terminal_options struct. All parameters are required. @@ -260,9 +259,6 @@ guac_terminal* guac_terminal_create(guac_terminal_options* terminal_options); * The guac_terminal_options struct should only be created using this * constructor. * - * @param guac_client - * The client to which the terminal will be rendered. - * * @param width * The width of the terminal, in pixels. * @@ -277,7 +273,7 @@ guac_terminal* guac_terminal_create(guac_terminal_options* terminal_options); * A new terminal options struct with all required options populated, * ready to have any defaults overriden as needed. */ -guac_terminal_options* guac_terminal_options_create(guac_client* client, +guac_terminal_options* guac_terminal_options_create( int width, int height, int dpi); /** @@ -533,7 +529,7 @@ int guac_terminal_available_scroll(guac_terminal* term); * @return * The height of the terminal, in characters. */ -int guac_terminal_term_height(guac_terminal* term); +int guac_terminal_get_rows(guac_terminal* term); /** * Returns the width of the given terminal, in characters. @@ -544,14 +540,16 @@ int guac_terminal_term_height(guac_terminal* term); * @return * The width of the terminal, in characters. */ -int guac_terminal_term_width(guac_terminal* term); +int guac_terminal_get_columns(guac_terminal* term); /** * Clears the clipboard contents for a given terminal, and assigns a new * mimetype for future data. * - * @param terminal The terminal whose clipboard is being reset. - * @param mimetype The mimetype of future data. + * @param terminal + * The terminal whose clipboard is being reset. + * @param mimetype + * The mimetype of future data. */ void guac_terminal_clipboard_reset(guac_terminal* terminal, const char* mimetype); @@ -561,9 +559,12 @@ void guac_terminal_clipboard_reset(guac_terminal* terminal, * terminal. The data must match the mimetype chosen for the clipboard data by * guac_terminal_clipboard_reset(). * - * @param terminal The terminal whose clipboard is being appended to. - * @param data The data to append. - * @param length The number of bytes to append from the data given. + * @param terminal + * The terminal whose clipboard is being appended to. + * @param data + * The data to append. + * @param length + * The number of bytes to append from the data given. */ void guac_terminal_clipboard_append(guac_terminal* terminal, const char* data, int length); @@ -573,8 +574,10 @@ void guac_terminal_clipboard_append(guac_terminal* terminal, * given terminal. This function must be called whenever a user leaves a * terminal connection. * - * @param terminal The terminal that the given user is leaving. - * @param user The user who is disconnecting. + * @param terminal + * The terminal that the given user is leaving. + * @param user + * The user who is disconnecting. */ void guac_terminal_remove_user(guac_terminal* terminal, guac_user* user); diff --git a/src/terminal/terminal/terminal_priv.h b/src/terminal/terminal/terminal_priv.h index 6b165444..b4da851a 100644 --- a/src/terminal/terminal/terminal_priv.h +++ b/src/terminal/terminal/terminal_priv.h @@ -18,8 +18,8 @@ */ -#ifndef _GUAC_TERMINAL_PRIV_H -#define _GUAC_TERMINAL_PRIV_H +#ifndef GUAC_TERMINAL_PRIV_H +#define GUAC_TERMINAL_PRIV_H #include "common/clipboard.h" #include "terminal/terminal.h" From 1c97cdb115ea3b339b334135d1e1de1fab6e47aa Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Wed, 23 Feb 2022 11:16:43 -0800 Subject: [PATCH 6/9] GUACAMOLE-1538: Autogenerate docs for new library. --- .dockerignore | 2 +- .gitignore | 2 +- Makefile.am | 19 +++--- configure.ac | 3 +- doc/libguac-terminal/Doxyfile.in | 59 +++++++++++++++++++ doc/{ => libguac}/Doxyfile.in | 4 +- src/terminal/Makefile.am | 10 ++-- .../{color-scheme.c => color_scheme.c} | 2 +- .../{named-colors.c => named_colors.c} | 0 src/terminal/terminal.c | 2 +- src/terminal/terminal/buffer.h | 7 +++ src/terminal/terminal/char_mappings.h | 6 ++ .../{color-scheme.h => color_scheme.h} | 6 ++ src/terminal/terminal/common.h | 6 ++ src/terminal/terminal/display.h | 6 ++ .../{named-colors.h => named_colors.h} | 6 ++ src/terminal/terminal/palette.h | 6 ++ src/terminal/terminal/scrollbar.h | 6 ++ src/terminal/terminal/select.h | 6 ++ src/terminal/terminal/terminal.h | 7 +++ src/terminal/terminal/terminal_handlers.h | 6 ++ src/terminal/terminal/types.h | 7 +++ src/terminal/terminal/typescript.h | 7 +++ src/terminal/terminal/xparsecolor.h | 6 ++ ...stdin-stream.c => terminal_stdin_stream.c} | 0 src/terminal/xparsecolor.c | 2 +- 26 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 doc/libguac-terminal/Doxyfile.in rename doc/{ => libguac}/Doxyfile.in (94%) rename src/terminal/{color-scheme.c => color_scheme.c} (99%) rename src/terminal/{named-colors.c => named_colors.c} (100%) rename src/terminal/terminal/{color-scheme.h => color_scheme.h} (96%) rename src/terminal/terminal/{named-colors.h => named_colors.h} (93%) rename src/terminal/{terminal-stdin-stream.c => terminal_stdin_stream.c} (100%) diff --git a/.dockerignore b/.dockerignore index 6e106436..fcfe87b0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -56,5 +56,5 @@ tests/test_* !tests/test_*.[ch] # Generated docs -doc/doxygen-output +doc/*/doxygen-output diff --git a/.gitignore b/.gitignore index 8b8022ad..e72000d8 100644 --- a/.gitignore +++ b/.gitignore @@ -44,7 +44,7 @@ configure stamp-h1 # Generated docs -doc/doxygen-output +doc/*/doxygen-output # IDE metadata nbproject/ diff --git a/Makefile.am b/Makefile.am index c75735c1..6ce3814a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -89,14 +89,15 @@ if ENABLE_GUACLOG SUBDIRS += src/guaclog endif -EXTRA_DIST = \ - .dockerignore \ - CONTRIBUTING \ - Dockerfile \ - LICENSE \ - NOTICE \ - bin/guacctl \ - doc/Doxyfile.in \ - src/guacd-docker \ +EXTRA_DIST = \ + .dockerignore \ + CONTRIBUTING \ + Dockerfile \ + LICENSE \ + NOTICE \ + bin/guacctl \ + doc/libguac/Doxyfile.in \ + doc/libguac-terminal/Doxyfile.in \ + src/guacd-docker \ util/generate-test-runner.pl diff --git a/configure.ac b/configure.ac index 54a958bc..624aae13 100644 --- a/configure.ac +++ b/configure.ac @@ -1167,7 +1167,8 @@ AM_CONDITIONAL([ENABLE_GUACLOG], [test "x${enable_guaclog}" = "xyes"]) # AC_CONFIG_FILES([Makefile - doc/Doxyfile + doc/libguac/Doxyfile + doc/libguac-terminal/Doxyfile src/common/Makefile src/common/tests/Makefile src/common-ssh/Makefile diff --git a/doc/libguac-terminal/Doxyfile.in b/doc/libguac-terminal/Doxyfile.in new file mode 100644 index 00000000..640ab48a --- /dev/null +++ b/doc/libguac-terminal/Doxyfile.in @@ -0,0 +1,59 @@ +# +# 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. +# + +# +# Project name / version +# + +PROJECT_NAME = libguac-terminal +PROJECT_NUMBER = @PACKAGE_VERSION@ + +# +# Warn about undocumented parameters and return values, but do not fill output +# with verbose progress info. +# + +QUIET = YES +WARN_NO_PARAMDOC = YES + +# +# Output format +# + +ALPHABETICAL_INDEX = YES +GENERATE_HTML = YES +GENERATE_LATEX = NO +OPTIMIZE_OUTPUT_FOR_C = YES +OUTPUT_DIRECTORY = doxygen-output +RECURSIVE = YES +SHOW_INCLUDE_FILES = NO + +# +# Input format +# + +CASE_SENSE_NAMES = YES +FILE_PATTERNS = *.h +STRIP_FROM_PATH = ../../src/terminal +INPUT = ../../src/terminal/terminal/ +EXCLUDE = ../../src/terminal/terminal/terminal_priv.h +JAVADOC_AUTOBRIEF = YES +TAB_SIZE = 4 +TYPEDEF_HIDES_STRUCT = YES + diff --git a/doc/Doxyfile.in b/doc/libguac/Doxyfile.in similarity index 94% rename from doc/Doxyfile.in rename to doc/libguac/Doxyfile.in index 83d54df7..5a0ae6bc 100644 --- a/doc/Doxyfile.in +++ b/doc/libguac/Doxyfile.in @@ -52,9 +52,9 @@ SHOW_INCLUDE_FILES = NO CASE_SENSE_NAMES = YES EXCLUDE_SYMBOLS = __* guac_palette* FILE_PATTERNS = *.h -INPUT = ../src/libguac/guacamole +INPUT = ../../src/libguac/guacamole JAVADOC_AUTOBRIEF = YES -STRIP_FROM_PATH = ../src/libguac +STRIP_FROM_PATH = ../../src/libguac TAB_SIZE = 4 TYPEDEF_HIDES_STRUCT = YES diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index 1219e968..52cc13dd 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -37,9 +37,9 @@ libguac_terminalinc_HEADERS = \ terminal/buffer.h \ terminal/char_mappings.h \ terminal/common.h \ - terminal/color-scheme.h \ + terminal/color_scheme.h \ terminal/display.h \ - terminal/named-colors.h \ + terminal/named_colors.h \ terminal/palette.h \ terminal/scrollbar.h \ terminal/select.h \ @@ -52,16 +52,16 @@ libguac_terminalinc_HEADERS = \ libguac_terminal_la_SOURCES = \ buffer.c \ char_mappings.c \ - color-scheme.c \ + color_scheme.c \ common.c \ display.c \ - named-colors.c \ + named_colors.c \ palette.c \ scrollbar.c \ select.c \ terminal.c \ terminal_handlers.c \ - terminal-stdin-stream.c \ + terminal_stdin_stream.c \ typescript.c \ xparsecolor.c diff --git a/src/terminal/color-scheme.c b/src/terminal/color_scheme.c similarity index 99% rename from src/terminal/color-scheme.c rename to src/terminal/color_scheme.c index 5df181fa..ec602e12 100644 --- a/src/terminal/color-scheme.c +++ b/src/terminal/color_scheme.c @@ -19,7 +19,7 @@ #include "config.h" -#include "terminal/color-scheme.h" +#include "terminal/color_scheme.h" #include "terminal/palette.h" #include "terminal/xparsecolor.h" diff --git a/src/terminal/named-colors.c b/src/terminal/named_colors.c similarity index 100% rename from src/terminal/named-colors.c rename to src/terminal/named_colors.c diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index c67998cc..4378a304 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -22,7 +22,7 @@ #include "common/clipboard.h" #include "common/cursor.h" #include "terminal/buffer.h" -#include "terminal/color-scheme.h" +#include "terminal/color_scheme.h" #include "terminal/common.h" #include "terminal/display.h" #include "terminal/palette.h" diff --git a/src/terminal/terminal/buffer.h b/src/terminal/terminal/buffer.h index 0e08226a..fb5c77f8 100644 --- a/src/terminal/terminal/buffer.h +++ b/src/terminal/terminal/buffer.h @@ -21,6 +21,13 @@ #ifndef _GUAC_TERMINAL_BUFFER_H #define _GUAC_TERMINAL_BUFFER_H +/** + * Data structures and functions related to the terminal buffer. + * + * @file buffer.h + */ + + #include "config.h" #include "types.h" diff --git a/src/terminal/terminal/char_mappings.h b/src/terminal/terminal/char_mappings.h index 5e0e4742..937c4147 100644 --- a/src/terminal/terminal/char_mappings.h +++ b/src/terminal/terminal/char_mappings.h @@ -21,6 +21,12 @@ #ifndef _GUAC_TERMINAL_CHAR_MAPPINGS_H #define _GUAC_TERMINAL_CHAR_MAPPINGS_H +/** + * Graphics character mapping definitions. + * + * @file char_mappings.h + */ + #include "config.h" /** diff --git a/src/terminal/terminal/color-scheme.h b/src/terminal/terminal/color_scheme.h similarity index 96% rename from src/terminal/terminal/color-scheme.h rename to src/terminal/terminal/color_scheme.h index 5417ce1c..446b9eed 100644 --- a/src/terminal/terminal/color-scheme.h +++ b/src/terminal/terminal/color_scheme.h @@ -20,6 +20,12 @@ #ifndef GUAC_TERMINAL_COLOR_SCHEME_H #define GUAC_TERMINAL_COLOR_SCHEME_H +/** + * Definitions and functions related to color scheme handling. + * + * @file color_scheme.h + */ + #include "config.h" #include "terminal/palette.h" diff --git a/src/terminal/terminal/common.h b/src/terminal/terminal/common.h index ad059a87..5ca8f37b 100644 --- a/src/terminal/terminal/common.h +++ b/src/terminal/terminal/common.h @@ -21,6 +21,12 @@ #ifndef _GUAC_TERMINAL_COMMON_H #define _GUAC_TERMINAL_COMMON_H +/** + * Miscellaneous terminal function definitions. + * + * @file common.h + */ + #include "config.h" #include "types.h" diff --git a/src/terminal/terminal/display.h b/src/terminal/terminal/display.h index 5377cb14..456343da 100644 --- a/src/terminal/terminal/display.h +++ b/src/terminal/terminal/display.h @@ -21,6 +21,12 @@ #ifndef _GUAC_TERMINAL_DISPLAY_H #define _GUAC_TERMINAL_DISPLAY_H +/** + * Structures and function definitions related to the graphical display. + * + * @file display.h + */ + #include "config.h" #include "common/surface.h" diff --git a/src/terminal/terminal/named-colors.h b/src/terminal/terminal/named_colors.h similarity index 93% rename from src/terminal/terminal/named-colors.h rename to src/terminal/terminal/named_colors.h index 675bf124..615d6978 100644 --- a/src/terminal/terminal/named-colors.h +++ b/src/terminal/terminal/named_colors.h @@ -20,6 +20,12 @@ #ifndef GUAC_TERMINAL_NAMED_COLORS_H #define GUAC_TERMINAL_NAMED_COLORS_H +/** + * Function definitions for operating on individual terminal colors. + * + * @file named_colors.h + */ + #include "config.h" #include "terminal/palette.h" diff --git a/src/terminal/terminal/palette.h b/src/terminal/terminal/palette.h index b1524b5a..88a6b923 100644 --- a/src/terminal/terminal/palette.h +++ b/src/terminal/terminal/palette.h @@ -20,6 +20,12 @@ #ifndef GUAC_TERMINAL_PALETTE_H #define GUAC_TERMINAL_PALETTE_H +/** + * Constants, structures, and function definitions related to the terminal color pallate. + * + * @file palette.h + */ + #include "config.h" #include diff --git a/src/terminal/terminal/scrollbar.h b/src/terminal/terminal/scrollbar.h index bf0da873..9e6c5ebc 100644 --- a/src/terminal/terminal/scrollbar.h +++ b/src/terminal/terminal/scrollbar.h @@ -20,6 +20,12 @@ #ifndef GUAC_TERMINAL_SCROLLBAR_H #define GUAC_TERMINAL_SCROLLBAR_H +/** + * Constants, structures, and function definitions related to the terminal scrollbar. + * + * @file scrollbar.h + */ + #include "config.h" #include diff --git a/src/terminal/terminal/select.h b/src/terminal/terminal/select.h index 1ae7d3d2..8abdd019 100644 --- a/src/terminal/terminal/select.h +++ b/src/terminal/terminal/select.h @@ -21,6 +21,12 @@ #ifndef GUAC_TERMINAL_SELECT_H #define GUAC_TERMINAL_SELECT_H +/** + * Function definitions related to selecting text withing a terminal. + * + * @file select.h + */ + #include "config.h" #include "terminal.h" diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index c78f61f4..dba68e32 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -21,6 +21,13 @@ #ifndef _GUAC_TERMINAL_H #define _GUAC_TERMINAL_H +/** + * Constants, structures, and function definitions defining the core + * functionality for the terminal library. + * + * @file terminal.h + */ + #include "config.h" #include "buffer.h" diff --git a/src/terminal/terminal/terminal_handlers.h b/src/terminal/terminal/terminal_handlers.h index 0869b19d..e293c581 100644 --- a/src/terminal/terminal/terminal_handlers.h +++ b/src/terminal/terminal/terminal_handlers.h @@ -21,6 +21,12 @@ #ifndef _GUAC_TERMINAL_HANDLERS #define _GUAC_TERMINAL_HANDLERS +/** + * Function definitions for terminal event handlers. + * + * @file terminal_handlers.h + */ + #include "config.h" #include "terminal.h" diff --git a/src/terminal/terminal/types.h b/src/terminal/terminal/types.h index 0d054f8f..fbf9c646 100644 --- a/src/terminal/terminal/types.h +++ b/src/terminal/terminal/types.h @@ -21,6 +21,13 @@ #ifndef _GUAC_TERMINAL_TYPES_H #define _GUAC_TERMINAL_TYPES_H +/** + * Structures and function definitions related to individual characters + * within the terminal. + * + * @file types.h + */ + #include "config.h" #include "palette.h" diff --git a/src/terminal/terminal/typescript.h b/src/terminal/terminal/typescript.h index 9fce9e54..9f8dff2d 100644 --- a/src/terminal/terminal/typescript.h +++ b/src/terminal/terminal/typescript.h @@ -21,6 +21,13 @@ #ifndef GUAC_TERMINAL_TYPESCRIPT_H #define GUAC_TERMINAL_TYPESCRIPT_H +/** + * Constants, structures, and function definitions related to terminal + * typescripts. + * + * @file typescript.h + */ + #include "config.h" #include diff --git a/src/terminal/terminal/xparsecolor.h b/src/terminal/terminal/xparsecolor.h index 7cb2fcaa..398de758 100644 --- a/src/terminal/terminal/xparsecolor.h +++ b/src/terminal/terminal/xparsecolor.h @@ -20,6 +20,12 @@ #ifndef GUAC_TERMINAL_XPARSECOLOR_H #define GUAC_TERMINAL_XPARSECOLOR_H +/** + * Function definitions related to handling X11 color specs. + * + * @file xparsecolor.h + */ + #include "config.h" #include "terminal/palette.h" diff --git a/src/terminal/terminal-stdin-stream.c b/src/terminal/terminal_stdin_stream.c similarity index 100% rename from src/terminal/terminal-stdin-stream.c rename to src/terminal/terminal_stdin_stream.c diff --git a/src/terminal/xparsecolor.c b/src/terminal/xparsecolor.c index 779374d8..f5432476 100644 --- a/src/terminal/xparsecolor.c +++ b/src/terminal/xparsecolor.c @@ -19,7 +19,7 @@ #include "config.h" -#include "terminal/named-colors.h" +#include "terminal/named_colors.h" #include "terminal/palette.h" #include From 0856e94ece57d63991f0b5828d73c43b10491d5b Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Thu, 24 Feb 2022 11:12:05 -0800 Subject: [PATCH 7/9] GUACAMOLE-1538 Use dashes instead of underscores in filenames for consistency with libguac public API. --- src/terminal/Makefile.am | 20 +++++++++---------- .../{char_mappings.c => char-mappings.c} | 0 .../{color_scheme.c => color-scheme.c} | 2 +- .../{named_colors.c => named-colors.c} | 0 src/terminal/select.c | 2 +- ...erminal_handlers.c => terminal-handlers.c} | 6 +++--- ...stdin_stream.c => terminal-stdin-stream.c} | 2 +- src/terminal/terminal.c | 6 +++--- .../{char_mappings.h => char-mappings.h} | 2 +- .../{color_scheme.h => color-scheme.h} | 2 +- .../{named_colors.h => named-colors.h} | 2 +- ...erminal_handlers.h => terminal-handlers.h} | 2 +- .../{terminal_priv.h => terminal-priv.h} | 0 src/terminal/xparsecolor.c | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) rename src/terminal/{char_mappings.c => char-mappings.c} (100%) rename src/terminal/{color_scheme.c => color-scheme.c} (99%) rename src/terminal/{named_colors.c => named-colors.c} (100%) rename src/terminal/{terminal_handlers.c => terminal-handlers.c} (99%) rename src/terminal/{terminal_stdin_stream.c => terminal-stdin-stream.c} (99%) rename src/terminal/terminal/{char_mappings.h => char-mappings.h} (98%) rename src/terminal/terminal/{color_scheme.h => color-scheme.h} (99%) rename src/terminal/terminal/{named_colors.h => named-colors.h} (98%) rename src/terminal/terminal/{terminal_handlers.h => terminal-handlers.h} (99%) rename src/terminal/terminal/{terminal_priv.h => terminal-priv.h} (100%) diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index 52cc13dd..4d704e7b 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -31,37 +31,37 @@ lib_LTLIBRARIES = libguac-terminal.la libguac_terminalincdir = $(includedir)/guacamole/terminal noinst_HEADERS = \ - terminal/terminal_priv.h + terminal/terminal-priv.h libguac_terminalinc_HEADERS = \ terminal/buffer.h \ - terminal/char_mappings.h \ + terminal/char-mappings.h \ terminal/common.h \ - terminal/color_scheme.h \ + terminal/color-scheme.h \ terminal/display.h \ - terminal/named_colors.h \ + terminal/named-colors.h \ terminal/palette.h \ terminal/scrollbar.h \ terminal/select.h \ terminal/terminal.h \ - terminal/terminal_handlers.h \ + terminal/terminal-handlers.h \ terminal/types.h \ terminal/typescript.h \ terminal/xparsecolor.h libguac_terminal_la_SOURCES = \ buffer.c \ - char_mappings.c \ - color_scheme.c \ + char-mappings.c \ + color-scheme.c \ common.c \ display.c \ - named_colors.c \ + named-colors.c \ palette.c \ scrollbar.c \ select.c \ terminal.c \ - terminal_handlers.c \ - terminal_stdin_stream.c \ + terminal-handlers.c \ + terminal-stdin-stream.c \ typescript.c \ xparsecolor.c diff --git a/src/terminal/char_mappings.c b/src/terminal/char-mappings.c similarity index 100% rename from src/terminal/char_mappings.c rename to src/terminal/char-mappings.c diff --git a/src/terminal/color_scheme.c b/src/terminal/color-scheme.c similarity index 99% rename from src/terminal/color_scheme.c rename to src/terminal/color-scheme.c index ec602e12..5df181fa 100644 --- a/src/terminal/color_scheme.c +++ b/src/terminal/color-scheme.c @@ -19,7 +19,7 @@ #include "config.h" -#include "terminal/color_scheme.h" +#include "terminal/color-scheme.h" #include "terminal/palette.h" #include "terminal/xparsecolor.h" diff --git a/src/terminal/named_colors.c b/src/terminal/named-colors.c similarity index 100% rename from src/terminal/named_colors.c rename to src/terminal/named-colors.c diff --git a/src/terminal/select.c b/src/terminal/select.c index a10687c5..e2622e4d 100644 --- a/src/terminal/select.c +++ b/src/terminal/select.c @@ -24,7 +24,7 @@ #include "terminal/display.h" #include "terminal/select.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" +#include "terminal/terminal-priv.h" #include "terminal/types.h" #include diff --git a/src/terminal/terminal_handlers.c b/src/terminal/terminal-handlers.c similarity index 99% rename from src/terminal/terminal_handlers.c rename to src/terminal/terminal-handlers.c index a4079fca..1603d4f5 100644 --- a/src/terminal/terminal_handlers.c +++ b/src/terminal/terminal-handlers.c @@ -19,11 +19,11 @@ #include "config.h" -#include "terminal/char_mappings.h" +#include "terminal/char-mappings.h" #include "terminal/palette.h" #include "terminal/terminal.h" -#include "terminal/terminal_handlers.h" -#include "terminal/terminal_priv.h" +#include "terminal/terminal-handlers.h" +#include "terminal/terminal-priv.h" #include "terminal/types.h" #include "terminal/xparsecolor.h" diff --git a/src/terminal/terminal_stdin_stream.c b/src/terminal/terminal-stdin-stream.c similarity index 99% rename from src/terminal/terminal_stdin_stream.c rename to src/terminal/terminal-stdin-stream.c index f9a2d617..8498a161 100644 --- a/src/terminal/terminal_stdin_stream.c +++ b/src/terminal/terminal-stdin-stream.c @@ -20,7 +20,7 @@ #include "config.h" #include "terminal/common.h" #include "terminal/terminal.h" -#include "terminal/terminal_priv.h" +#include "terminal/terminal-priv.h" #include #include diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 4378a304..cd469703 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -22,14 +22,14 @@ #include "common/clipboard.h" #include "common/cursor.h" #include "terminal/buffer.h" -#include "terminal/color_scheme.h" +#include "terminal/color-scheme.h" #include "terminal/common.h" #include "terminal/display.h" #include "terminal/palette.h" #include "terminal/select.h" #include "terminal/terminal.h" -#include "terminal/terminal_handlers.h" -#include "terminal/terminal_priv.h" +#include "terminal/terminal-handlers.h" +#include "terminal/terminal-priv.h" #include "terminal/types.h" #include "terminal/typescript.h" diff --git a/src/terminal/terminal/char_mappings.h b/src/terminal/terminal/char-mappings.h similarity index 98% rename from src/terminal/terminal/char_mappings.h rename to src/terminal/terminal/char-mappings.h index 937c4147..9af99a94 100644 --- a/src/terminal/terminal/char_mappings.h +++ b/src/terminal/terminal/char-mappings.h @@ -24,7 +24,7 @@ /** * Graphics character mapping definitions. * - * @file char_mappings.h + * @file char-mappings.h */ #include "config.h" diff --git a/src/terminal/terminal/color_scheme.h b/src/terminal/terminal/color-scheme.h similarity index 99% rename from src/terminal/terminal/color_scheme.h rename to src/terminal/terminal/color-scheme.h index 446b9eed..51d27be7 100644 --- a/src/terminal/terminal/color_scheme.h +++ b/src/terminal/terminal/color-scheme.h @@ -23,7 +23,7 @@ /** * Definitions and functions related to color scheme handling. * - * @file color_scheme.h + * @file color-scheme.h */ #include "config.h" diff --git a/src/terminal/terminal/named_colors.h b/src/terminal/terminal/named-colors.h similarity index 98% rename from src/terminal/terminal/named_colors.h rename to src/terminal/terminal/named-colors.h index 615d6978..ef51f8c0 100644 --- a/src/terminal/terminal/named_colors.h +++ b/src/terminal/terminal/named-colors.h @@ -23,7 +23,7 @@ /** * Function definitions for operating on individual terminal colors. * - * @file named_colors.h + * @file named-colors.h */ #include "config.h" diff --git a/src/terminal/terminal/terminal_handlers.h b/src/terminal/terminal/terminal-handlers.h similarity index 99% rename from src/terminal/terminal/terminal_handlers.h rename to src/terminal/terminal/terminal-handlers.h index e293c581..7a5551d5 100644 --- a/src/terminal/terminal/terminal_handlers.h +++ b/src/terminal/terminal/terminal-handlers.h @@ -24,7 +24,7 @@ /** * Function definitions for terminal event handlers. * - * @file terminal_handlers.h + * @file terminal-handlers.h */ #include "config.h" diff --git a/src/terminal/terminal/terminal_priv.h b/src/terminal/terminal/terminal-priv.h similarity index 100% rename from src/terminal/terminal/terminal_priv.h rename to src/terminal/terminal/terminal-priv.h diff --git a/src/terminal/xparsecolor.c b/src/terminal/xparsecolor.c index f5432476..779374d8 100644 --- a/src/terminal/xparsecolor.c +++ b/src/terminal/xparsecolor.c @@ -19,7 +19,7 @@ #include "config.h" -#include "terminal/named_colors.h" +#include "terminal/named-colors.h" #include "terminal/palette.h" #include From ad0155b5f5b0d0ae16469e66af97ec1e0f2ade87 Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Thu, 24 Feb 2022 11:22:12 -0800 Subject: [PATCH 8/9] GUACAMOLE-1538: Make it clear which functions are getters by adding _get_ to the name of each. --- src/protocols/kubernetes/argv.c | 6 +++--- src/protocols/ssh/argv.c | 6 +++--- src/protocols/telnet/argv.c | 6 +++--- src/protocols/telnet/input.c | 2 +- src/terminal/terminal-handlers.c | 2 +- src/terminal/terminal.c | 18 +++++++++--------- src/terminal/terminal/color-scheme.h | 4 ++-- src/terminal/terminal/terminal.h | 10 +++++----- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/protocols/kubernetes/argv.c b/src/protocols/kubernetes/argv.c index 009e2480..0cbc7160 100644 --- a/src/protocols/kubernetes/argv.c +++ b/src/protocols/kubernetes/argv.c @@ -69,16 +69,16 @@ void* guac_kubernetes_send_current_argv(guac_user* user, void* data) { /* Send current color scheme */ guac_user_stream_argv(user, user->socket, "text/plain", GUAC_KUBERNETES_ARGV_COLOR_SCHEME, - guac_terminal_color_scheme(terminal)); + guac_terminal_get_color_scheme(terminal)); /* Send current font name */ guac_user_stream_argv(user, user->socket, "text/plain", GUAC_KUBERNETES_ARGV_FONT_NAME, - guac_terminal_font_name(terminal)); + guac_terminal_get_font_name(terminal)); /* Send current font size */ char font_size[64]; - sprintf(font_size, "%i", guac_terminal_font_size(terminal)); + sprintf(font_size, "%i", guac_terminal_get_font_size(terminal)); guac_user_stream_argv(user, user->socket, "text/plain", GUAC_KUBERNETES_ARGV_FONT_SIZE, font_size); diff --git a/src/protocols/ssh/argv.c b/src/protocols/ssh/argv.c index af191f4e..446d0169 100644 --- a/src/protocols/ssh/argv.c +++ b/src/protocols/ssh/argv.c @@ -75,16 +75,16 @@ void* guac_ssh_send_current_argv(guac_user* user, void* data) { /* Send current color scheme */ guac_user_stream_argv(user, user->socket, "text/plain", GUAC_SSH_ARGV_COLOR_SCHEME, - guac_terminal_color_scheme(terminal)); + guac_terminal_get_color_scheme(terminal)); /* Send current font name */ guac_user_stream_argv(user, user->socket, "text/plain", GUAC_SSH_ARGV_FONT_NAME, - guac_terminal_font_name(terminal)); + guac_terminal_get_font_name(terminal)); /* Send current font size */ char font_size[64]; - sprintf(font_size, "%i", guac_terminal_font_size(terminal)); + sprintf(font_size, "%i", guac_terminal_get_font_size(terminal)); guac_user_stream_argv(user, user->socket, "text/plain", GUAC_SSH_ARGV_FONT_SIZE, font_size); diff --git a/src/protocols/telnet/argv.c b/src/protocols/telnet/argv.c index 59814a71..966584c6 100644 --- a/src/protocols/telnet/argv.c +++ b/src/protocols/telnet/argv.c @@ -70,16 +70,16 @@ void* guac_telnet_send_current_argv(guac_user* user, void* data) { /* Send current color scheme */ guac_user_stream_argv(user, user->socket, "text/plain", GUAC_TELNET_ARGV_COLOR_SCHEME, - guac_terminal_color_scheme(terminal)); + guac_terminal_get_color_scheme(terminal)); /* Send current font name */ guac_user_stream_argv(user, user->socket, "text/plain", GUAC_TELNET_ARGV_FONT_NAME, - guac_terminal_font_name(terminal)); + guac_terminal_get_font_name(terminal)); /* Send current font size */ char font_size[64]; - sprintf(font_size, "%i", guac_terminal_font_size(terminal)); + sprintf(font_size, "%i", guac_terminal_get_font_size(terminal)); guac_user_stream_argv(user, user->socket, "text/plain", GUAC_TELNET_ARGV_FONT_SIZE, font_size); diff --git a/src/protocols/telnet/input.c b/src/protocols/telnet/input.c index dbd2e5f8..3c3a5890 100644 --- a/src/protocols/telnet/input.c +++ b/src/protocols/telnet/input.c @@ -101,7 +101,7 @@ int guac_telnet_user_key_handler(guac_user* user, int keysym, int pressed) { keysym == 0xFF13 /* Pause */ || keysym == 0xFF6B /* Break */ || ( - guac_terminal_mod_ctrl(term) + guac_terminal_get_mod_ctrl(term) && keysym == '0' ) /* Ctrl + 0 */ )) { diff --git a/src/terminal/terminal-handlers.c b/src/terminal/terminal-handlers.c index 1603d4f5..f5b10beb 100644 --- a/src/terminal/terminal-handlers.c +++ b/src/terminal/terminal-handlers.c @@ -1227,7 +1227,7 @@ int guac_terminal_set_scrollback(guac_terminal* term, unsigned char c) { /* Update scrollbar bounds */ guac_terminal_scrollbar_set_bounds(term->scrollbar, - -guac_terminal_available_scroll(term), 0); + -guac_terminal_get_available_scroll(term), 0); /* Return to echo mode */ term->char_handler = guac_terminal_echo; diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index cd469703..bfe8936a 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -186,7 +186,7 @@ static int guac_terminal_effective_buffer_length(guac_terminal* term) { } -int guac_terminal_available_scroll(guac_terminal* term) { +int guac_terminal_get_available_scroll(guac_terminal* term) { return guac_terminal_effective_buffer_length(term) - term->term_height; } @@ -897,7 +897,7 @@ int guac_terminal_scroll_up(guac_terminal* term, /* Reset scrollbar bounds */ guac_terminal_scrollbar_set_bounds(term->scrollbar, - -guac_terminal_available_scroll(term), 0); + -guac_terminal_get_available_scroll(term), 0); /* Update cursor location if within region */ if (term->visible_cursor_row >= start_row && @@ -1107,7 +1107,7 @@ void guac_terminal_scroll_display_up(guac_terminal* terminal, int row, column; /* Limit scroll amount by size of scrollback buffer */ - int available_scroll = guac_terminal_available_scroll(terminal); + int available_scroll = guac_terminal_get_available_scroll(terminal); if (terminal->scroll_offset + scroll_amount > available_scroll) scroll_amount = available_scroll - terminal->scroll_offset; @@ -1308,7 +1308,7 @@ static void __guac_terminal_resize(guac_terminal* term, int width, int height) { if (height > term->term_height) { /* If undisplayed rows exist in the buffer, shift them into view */ - int available_scroll = guac_terminal_available_scroll(term); + int available_scroll = guac_terminal_get_available_scroll(term); if (available_scroll > 0) { /* If the new terminal bottom reveals N rows, shift down N rows */ @@ -1433,7 +1433,7 @@ int guac_terminal_resize(guac_terminal* terminal, int width, int height) { /* Notify scrollbar of resize */ guac_terminal_scrollbar_parent_resized(terminal->scrollbar, width, height, rows); guac_terminal_scrollbar_set_bounds(terminal->scrollbar, - -guac_terminal_available_scroll(terminal), 0); + -guac_terminal_get_available_scroll(terminal), 0); /* Release terminal */ @@ -2027,7 +2027,7 @@ void guac_terminal_apply_color_scheme(guac_terminal* terminal, } -const char* guac_terminal_color_scheme(guac_terminal* terminal) { +const char* guac_terminal_get_color_scheme(guac_terminal* terminal) { return terminal->color_scheme; } @@ -2079,15 +2079,15 @@ void guac_terminal_set_file_download_handler(guac_terminal* terminal, terminal->file_download_handler = file_download_handler; } -const char* guac_terminal_font_name(guac_terminal* terminal) { +const char* guac_terminal_get_font_name(guac_terminal* terminal) { return terminal->font_name; } -int guac_terminal_font_size(guac_terminal* terminal) { +int guac_terminal_get_font_size(guac_terminal* terminal) { return terminal->font_size; } -int guac_terminal_mod_ctrl(guac_terminal* terminal) { +int guac_terminal_get_mod_ctrl(guac_terminal* terminal) { return terminal->mod_ctrl; } diff --git a/src/terminal/terminal/color-scheme.h b/src/terminal/terminal/color-scheme.h index 51d27be7..5b9a93db 100644 --- a/src/terminal/terminal/color-scheme.h +++ b/src/terminal/terminal/color-scheme.h @@ -17,8 +17,8 @@ * under the License. */ -#ifndef GUAC_TERMINAL_COLOR_SCHEME_H -#define GUAC_TERMINAL_COLOR_SCHEME_H +#ifndef GUAC_TERMINAL_GET_COLOR_SCHEME_H +#define GUAC_TERMINAL_GET_COLOR_SCHEME_H /** * Definitions and functions related to color scheme handling. diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index dba68e32..50aa27dd 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -525,7 +525,7 @@ void guac_terminal_dup(guac_terminal* term, guac_user* user, * The number of rows within the buffer which are not currently displayed * on screen. */ -int guac_terminal_available_scroll(guac_terminal* term); +int guac_terminal_get_available_scroll(guac_terminal* term); /** * Returns the height of the given terminal, in characters. @@ -899,7 +899,7 @@ void guac_terminal_apply_color_scheme(guac_terminal* terminal, * @return * The name of the color scheme currently in use by the given terminal. */ -const char* guac_terminal_color_scheme(guac_terminal* terminal); +const char* guac_terminal_get_color_scheme(guac_terminal* terminal); /** * Alters the font of the terminal. The terminal will automatically be redrawn @@ -934,7 +934,7 @@ void guac_terminal_apply_font(guac_terminal* terminal, const char* font_name, * @return * The name of the font in use by the given terminal. */ -const char* guac_terminal_font_name(guac_terminal* terminal); +const char* guac_terminal_get_font_name(guac_terminal* terminal); /** * Returns the font size currently in use by the given terminal. @@ -945,7 +945,7 @@ const char* guac_terminal_font_name(guac_terminal* terminal); * @return * The size of the font in use by the given terminal. */ -int guac_terminal_font_size(guac_terminal* terminal); +int guac_terminal_get_font_size(guac_terminal* terminal); /** * Returns the current state of the mod_ctrl flag in the given terminal. @@ -956,6 +956,6 @@ int guac_terminal_font_size(guac_terminal* terminal); * @return * The current state of the mod_ctrl flag. */ -int guac_terminal_mod_ctrl(guac_terminal* terminal); +int guac_terminal_get_mod_ctrl(guac_terminal* terminal); #endif From 46e813343e4a6896d96a671533a343712a1bda7f Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Sat, 26 Feb 2022 02:13:22 +0000 Subject: [PATCH 9/9] GUACAMOLE-1538: Only the core functionality of the terminal lib should be public. --- doc/libguac-terminal/Doxyfile.in | 3 +- src/protocols/ssh/argv.c | 1 + src/protocols/ssh/ssh.c | 22 +- src/protocols/telnet/argv.c | 1 + src/protocols/telnet/client.c | 1 + src/protocols/telnet/telnet.c | 7 +- src/terminal/Makefile.am | 12 +- src/terminal/buffer.c | 1 - src/terminal/char-mappings.c | 1 - src/terminal/color-scheme.c | 1 - src/terminal/common.c | 1 - src/terminal/display.c | 3 +- src/terminal/named-colors.c | 1 - src/terminal/palette.c | 1 - src/terminal/scrollbar.c | 1 - src/terminal/select.c | 1 - src/terminal/terminal-stdin-stream.c | 1 - src/terminal/terminal.c | 1 - src/terminal/terminal/buffer.h | 1 - src/terminal/terminal/char-mappings.h | 1 - src/terminal/terminal/color-scheme.h | 7 +- src/terminal/terminal/common.h | 1 - src/terminal/terminal/display.h | 1 - src/terminal/terminal/named-colors.h | 3 +- src/terminal/terminal/palette.h | 1 - src/terminal/terminal/scrollbar.h | 1 - src/terminal/terminal/select.h | 1 - src/terminal/terminal/terminal-handlers.h | 1 + src/terminal/terminal/terminal-priv.h | 196 ++++++++++++- src/terminal/terminal/terminal.h | 342 +++++----------------- src/terminal/terminal/types.h | 1 - src/terminal/terminal/typescript.h | 1 - src/terminal/terminal/xparsecolor.h | 3 +- src/terminal/typescript.c | 1 - src/terminal/xparsecolor.c | 1 - 35 files changed, 298 insertions(+), 325 deletions(-) diff --git a/doc/libguac-terminal/Doxyfile.in b/doc/libguac-terminal/Doxyfile.in index 640ab48a..aab06575 100644 --- a/doc/libguac-terminal/Doxyfile.in +++ b/doc/libguac-terminal/Doxyfile.in @@ -51,8 +51,7 @@ SHOW_INCLUDE_FILES = NO CASE_SENSE_NAMES = YES FILE_PATTERNS = *.h STRIP_FROM_PATH = ../../src/terminal -INPUT = ../../src/terminal/terminal/ -EXCLUDE = ../../src/terminal/terminal/terminal_priv.h +INPUT = ../../src/terminal/terminal/terminal.h JAVADOC_AUTOBRIEF = YES TAB_SIZE = 4 TYPEDEF_HIDES_STRUCT = YES diff --git a/src/protocols/ssh/argv.c b/src/protocols/ssh/argv.c index 446d0169..a8f31f2e 100644 --- a/src/protocols/ssh/argv.c +++ b/src/protocols/ssh/argv.c @@ -27,6 +27,7 @@ #include #include +#include #include #include diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index e1a16541..847f4730 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include #include #include @@ -98,7 +100,7 @@ static guac_common_ssh_user* guac_ssh_get_user(guac_client* client) { guac_client_log(client, GUAC_LOG_DEBUG, "Initial import failed: %s", guac_common_ssh_key_error()); - + guac_client_log(client, GUAC_LOG_DEBUG, "Re-attempting private key import (WITH passphrase)"); @@ -148,23 +150,23 @@ static guac_common_ssh_user* guac_ssh_get_user(guac_client* client) { * A function used to generate a terminal prompt to gather additional * credentials from the guac_client during a connection, and using * the specified string to generate the prompt for the user. - * + * * @param client * The guac_client object associated with the current connection * where additional credentials are required. - * + * * @param cred_name * The prompt text to display to the screen when prompting for the * additional credentials. - * - * @return + * + * @return * The string of credentials gathered from the user. */ static char* guac_ssh_get_credential(guac_client *client, char* cred_name) { guac_ssh_client* ssh_client = (guac_ssh_client*) client->data; return guac_terminal_prompt(ssh_client->term, cred_name, false); - + } void* ssh_input_thread(void* data) { @@ -206,17 +208,17 @@ void* ssh_client_thread(void* data) { if (settings->wol_send_packet) { guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, " "and pausing for %d seconds.", settings->wol_wait_time); - + /* Send the Wake-on-LAN request. */ if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr, settings->wol_udp_port)) return NULL; - + /* If wait time is specified, sleep for that amount of time. */ if (settings->wol_wait_time > 0) guac_timestamp_msleep(settings->wol_wait_time * 1000); } - + /* Init SSH base libraries */ if (guac_common_ssh_init(client)) { guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, @@ -360,7 +362,7 @@ void* ssh_client_thread(void* data) { if (!settings->sftp_disable_upload) guac_terminal_set_upload_path_handler(ssh_client->term, guac_sftp_set_upload_path); - + if (!settings->sftp_disable_download) guac_terminal_set_file_download_handler(ssh_client->term, guac_sftp_download_file); diff --git a/src/protocols/telnet/argv.c b/src/protocols/telnet/argv.c index 966584c6..3ea3095e 100644 --- a/src/protocols/telnet/argv.c +++ b/src/protocols/telnet/argv.c @@ -26,6 +26,7 @@ #include #include +#include #include #include diff --git a/src/protocols/telnet/client.c b/src/protocols/telnet/client.c index fcb7e7a2..752234b4 100644 --- a/src/protocols/telnet/client.c +++ b/src/protocols/telnet/client.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index 242542e2..ced9df05 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -559,17 +560,17 @@ void* guac_telnet_client_thread(void* data) { pthread_t input_thread; char buffer[8192]; int wait_result; - + /* If Wake-on-LAN is enabled, attempt to wake. */ if (settings->wol_send_packet) { guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, " "and pausing for %d seconds.", settings->wol_wait_time); - + /* Send the Wake-on-LAN request. */ if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr, settings->wol_udp_port)) return NULL; - + /* If wait time is specified, sleep for that amount of time. */ if (settings->wol_wait_time > 0) guac_timestamp_msleep(settings->wol_wait_time * 1000); diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index 4d704e7b..b2c93d64 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -23,17 +23,14 @@ # to you by the ASF under the Apache License, Version 2.0, as described above. # -AUTOMAKE_OPTIONS = foreign +AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libguac-terminal.la libguac_terminalincdir = $(includedir)/guacamole/terminal -noinst_HEADERS = \ - terminal/terminal-priv.h - -libguac_terminalinc_HEADERS = \ +noinst_HEADERS = \ terminal/buffer.h \ terminal/char-mappings.h \ terminal/common.h \ @@ -43,12 +40,15 @@ libguac_terminalinc_HEADERS = \ terminal/palette.h \ terminal/scrollbar.h \ terminal/select.h \ - terminal/terminal.h \ + terminal/terminal-priv.h \ terminal/terminal-handlers.h \ terminal/types.h \ terminal/typescript.h \ terminal/xparsecolor.h +libguac_terminalinc_HEADERS = \ + terminal/terminal.h + libguac_terminal_la_SOURCES = \ buffer.c \ char-mappings.c \ diff --git a/src/terminal/buffer.c b/src/terminal/buffer.c index 4ecc5ba5..e8ad4b3c 100644 --- a/src/terminal/buffer.c +++ b/src/terminal/buffer.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "terminal/buffer.h" #include "terminal/common.h" diff --git a/src/terminal/char-mappings.c b/src/terminal/char-mappings.c index 9b9bebcd..421bc388 100644 --- a/src/terminal/char-mappings.c +++ b/src/terminal/char-mappings.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" const int vt100_map[] = { ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', diff --git a/src/terminal/color-scheme.c b/src/terminal/color-scheme.c index 5df181fa..c1a9e3ff 100644 --- a/src/terminal/color-scheme.c +++ b/src/terminal/color-scheme.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "terminal/color-scheme.h" #include "terminal/palette.h" diff --git a/src/terminal/common.c b/src/terminal/common.c index 99137534..36675f31 100644 --- a/src/terminal/common.c +++ b/src/terminal/common.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "terminal/types.h" #include diff --git a/src/terminal/display.c b/src/terminal/display.c index e35b8a74..a9d671f6 100644 --- a/src/terminal/display.c +++ b/src/terminal/display.c @@ -17,12 +17,13 @@ * under the License. */ -#include "config.h" #include "common/surface.h" #include "terminal/common.h" #include "terminal/display.h" #include "terminal/palette.h" +#include "terminal/terminal.h" +#include "terminal/terminal-priv.h" #include "terminal/types.h" #include diff --git a/src/terminal/named-colors.c b/src/terminal/named-colors.c index ab94153e..948982af 100644 --- a/src/terminal/named-colors.c +++ b/src/terminal/named-colors.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "terminal/palette.h" #include diff --git a/src/terminal/palette.c b/src/terminal/palette.c index a6b2d5ae..d4975665 100644 --- a/src/terminal/palette.c +++ b/src/terminal/palette.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "terminal/palette.h" const guac_terminal_color GUAC_TERMINAL_INITIAL_PALETTE[256] = { diff --git a/src/terminal/scrollbar.c b/src/terminal/scrollbar.c index ddff2997..a0eec8ec 100644 --- a/src/terminal/scrollbar.c +++ b/src/terminal/scrollbar.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "terminal/scrollbar.h" #include diff --git a/src/terminal/select.c b/src/terminal/select.c index e2622e4d..1698e381 100644 --- a/src/terminal/select.c +++ b/src/terminal/select.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "common/clipboard.h" #include "terminal/buffer.h" diff --git a/src/terminal/terminal-stdin-stream.c b/src/terminal/terminal-stdin-stream.c index 8498a161..9c1e9446 100644 --- a/src/terminal/terminal-stdin-stream.c +++ b/src/terminal/terminal-stdin-stream.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "terminal/common.h" #include "terminal/terminal.h" #include "terminal/terminal-priv.h" diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index bfe8936a..cb21e93f 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "common/clipboard.h" #include "common/cursor.h" diff --git a/src/terminal/terminal/buffer.h b/src/terminal/terminal/buffer.h index fb5c77f8..00277cb9 100644 --- a/src/terminal/terminal/buffer.h +++ b/src/terminal/terminal/buffer.h @@ -28,7 +28,6 @@ */ -#include "config.h" #include "types.h" diff --git a/src/terminal/terminal/char-mappings.h b/src/terminal/terminal/char-mappings.h index 9af99a94..6d1dab0b 100644 --- a/src/terminal/terminal/char-mappings.h +++ b/src/terminal/terminal/char-mappings.h @@ -27,7 +27,6 @@ * @file char-mappings.h */ -#include "config.h" /** * VT100 graphics mapping. Each entry is the corresponding Unicode codepoint diff --git a/src/terminal/terminal/color-scheme.h b/src/terminal/terminal/color-scheme.h index 5b9a93db..02e24046 100644 --- a/src/terminal/terminal/color-scheme.h +++ b/src/terminal/terminal/color-scheme.h @@ -17,8 +17,8 @@ * under the License. */ -#ifndef GUAC_TERMINAL_GET_COLOR_SCHEME_H -#define GUAC_TERMINAL_GET_COLOR_SCHEME_H +#ifndef GUAC_TERMINAL_COLOR_SCHEME_H +#define GUAC_TERMINAL_COLOR_SCHEME_H /** * Definitions and functions related to color scheme handling. @@ -26,9 +26,8 @@ * @file color-scheme.h */ -#include "config.h" -#include "terminal/palette.h" +#include "palette.h" #include diff --git a/src/terminal/terminal/common.h b/src/terminal/terminal/common.h index 5ca8f37b..e50b702e 100644 --- a/src/terminal/terminal/common.h +++ b/src/terminal/terminal/common.h @@ -27,7 +27,6 @@ * @file common.h */ -#include "config.h" #include "types.h" #include diff --git a/src/terminal/terminal/display.h b/src/terminal/terminal/display.h index 456343da..db85b2ac 100644 --- a/src/terminal/terminal/display.h +++ b/src/terminal/terminal/display.h @@ -27,7 +27,6 @@ * @file display.h */ -#include "config.h" #include "common/surface.h" #include "palette.h" diff --git a/src/terminal/terminal/named-colors.h b/src/terminal/terminal/named-colors.h index ef51f8c0..4571e6e3 100644 --- a/src/terminal/terminal/named-colors.h +++ b/src/terminal/terminal/named-colors.h @@ -26,8 +26,7 @@ * @file named-colors.h */ -#include "config.h" -#include "terminal/palette.h" +#include "palette.h" /** * Searches for the color having the given name, storing that color within the diff --git a/src/terminal/terminal/palette.h b/src/terminal/terminal/palette.h index 88a6b923..b7dc1118 100644 --- a/src/terminal/terminal/palette.h +++ b/src/terminal/terminal/palette.h @@ -26,7 +26,6 @@ * @file palette.h */ -#include "config.h" #include diff --git a/src/terminal/terminal/scrollbar.h b/src/terminal/terminal/scrollbar.h index 9e6c5ebc..c3083377 100644 --- a/src/terminal/terminal/scrollbar.h +++ b/src/terminal/terminal/scrollbar.h @@ -26,7 +26,6 @@ * @file scrollbar.h */ -#include "config.h" #include #include diff --git a/src/terminal/terminal/select.h b/src/terminal/terminal/select.h index 8abdd019..f85eef3a 100644 --- a/src/terminal/terminal/select.h +++ b/src/terminal/terminal/select.h @@ -27,7 +27,6 @@ * @file select.h */ -#include "config.h" #include "terminal.h" #include diff --git a/src/terminal/terminal/terminal-handlers.h b/src/terminal/terminal/terminal-handlers.h index 7a5551d5..d983ae3e 100644 --- a/src/terminal/terminal/terminal-handlers.h +++ b/src/terminal/terminal/terminal-handlers.h @@ -29,6 +29,7 @@ #include "config.h" +#include "display.h" #include "terminal.h" /** diff --git a/src/terminal/terminal/terminal-priv.h b/src/terminal/terminal/terminal-priv.h index b4da851a..4fe85500 100644 --- a/src/terminal/terminal/terminal-priv.h +++ b/src/terminal/terminal/terminal-priv.h @@ -22,7 +22,12 @@ #define GUAC_TERMINAL_PRIV_H #include "common/clipboard.h" -#include "terminal/terminal.h" +#include "common/cursor.h" +#include "buffer.h" +#include "display.h" +#include "scrollbar.h" +#include "terminal.h" +#include "typescript.h" struct guac_terminal { @@ -442,5 +447,194 @@ struct guac_terminal { }; +/** + * Handles a scroll event received from the scrollbar associated with a + * terminal. + * + * @param scrollbar + * The scrollbar that has been scrolled. + * + * @param value + * The new value that should be stored within the scrollbar, and + * represented within the terminal display. + */ +void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value); + +/** + * Sets the given range of columns within the given row to the given + * character. + */ +void guac_terminal_set_columns(guac_terminal* terminal, int row, + int start_column, int end_column, guac_terminal_char* character); + +/** + * Acquires exclusive access to the terminal. Note that enforcing this + * exclusive access requires that ALL users of the terminal call this + * function before making further calls to the terminal. + */ +void guac_terminal_lock(guac_terminal* terminal); + +/** + * Releases exclusive access to the terminal. + */ +void guac_terminal_unlock(guac_terminal* terminal); + +/** + * Resets the state of the given terminal, as if it were just allocated. + */ +void guac_terminal_reset(guac_terminal* term); + +/** + * Sets the character at the given row and column to the specified value. + */ +int guac_terminal_set(guac_terminal* term, int row, int col, int codepoint); + +/** + * Clears the given region within a single row. + */ +int guac_terminal_clear_columns(guac_terminal* term, + int row, int start_col, int end_col); + +/** + * Clears the given region from right-to-left, top-to-bottom, replacing + * all characters with the current background color and attributes. + */ +int guac_terminal_clear_range(guac_terminal* term, + int start_row, int start_col, + int end_row, int end_col); + +/** + * Scrolls the terminal's current scroll region up by one row. + */ +int guac_terminal_scroll_up(guac_terminal* term, + int start_row, int end_row, int amount); + +/** + * Scrolls the terminal's current scroll region down by one row. + */ +int guac_terminal_scroll_down(guac_terminal* term, + int start_row, int end_row, int amount); + +/** + * Commits the current cursor location, updating the visible cursor + * on the screen. + */ +void guac_terminal_commit_cursor(guac_terminal* term); + +/** + * Scroll down the display by the given amount, replacing the new space with + * data from the buffer. If not enough data is available, the maximum + * amount will be scrolled. + */ +void guac_terminal_scroll_display_down(guac_terminal* terminal, int amount); + +/** + * Scroll up the display by the given amount, replacing the new space with data + * from either the buffer or the terminal buffer. If not enough data is + * available, the maximum amount will be scrolled. + */ +void guac_terminal_scroll_display_up(guac_terminal* terminal, int amount); + +/** + * Opens a new pipe stream, redirecting all output from the given terminal to + * that pipe stream. If a pipe stream is already open, that pipe stream will + * be flushed and closed prior to opening the new pipe stream. + * + * @param term + * The terminal which should redirect output to a new pipe stream having + * the given name. + * + * @param name + * The name of the pipe stream to open. + * + * @param flags + * A bitwise OR of all integer flags which should apply to the new pipe + * stream. + * + * @see GUAC_TERMINAL_PIPE_INTERPRET_OUTPUT + * @see GUAC_TERMINAL_PIPE_AUTOFLUSH + */ +void guac_terminal_pipe_stream_open(guac_terminal* term, const char* name, + int flags); + +/** + * Writes a single byte of data to the pipe stream currently open and + * associated with the given terminal. The pipe stream must already have been + * opened via guac_terminal_pipe_stream_open(). If no pipe stream is currently + * open, this function has no effect. Data written through this function may + * be buffered. + * + * @param term + * The terminal whose currently-open pipe stream should be written to. + * + * @param c + * The byte of data to write to the pipe stream. + */ +void guac_terminal_pipe_stream_write(guac_terminal* term, char c); + +/** + * Flushes any data currently buffered for the currently-open pipe stream + * associated with the given terminal. The pipe stream must already have been + * opened via guac_terminal_pipe_stream_open(). If no pipe stream is currently + * open or no data is in the buffer, this function has no effect. + * + * @param term + * The terminal whose pipe stream buffer should be flushed. + */ +void guac_terminal_pipe_stream_flush(guac_terminal* term); + +/** + * Closes the currently-open pipe stream associated with the given terminal, + * redirecting all output back to the terminal display. Any data currently + * buffered for output to the pipe stream will be flushed prior to closure. The + * pipe stream must already have been opened via + * guac_terminal_pipe_stream_open(). If no pipe stream is currently open, this + * function has no effect. + * + * @param term + * The terminal whose currently-open pipe stream should be closed. + */ +void guac_terminal_pipe_stream_close(guac_terminal* term); + +/** + * Sets a tabstop in the given column. + */ +void guac_terminal_set_tab(guac_terminal* term, int column); + +/** + * Removes the tabstop at the given column. + */ +void guac_terminal_unset_tab(guac_terminal* term, int column); + +/** + * Removes all tabstops. + */ +void guac_terminal_clear_tabs(guac_terminal* term); + +/** + * Given a column within the given terminal, returns the location of the + * next tabstop (or the rightmost character, if no more tabstops exist). + */ +int guac_terminal_next_tab(guac_terminal* term, int column); + +/** + * Copies the given range of columns to a new location, offset from + * the original by the given number of columns. + */ +void guac_terminal_copy_columns(guac_terminal* terminal, int row, + int start_column, int end_column, int offset); + +/** + * Copies the given range of rows to a new location, offset from the + * original by the given number of rows. + */ +void guac_terminal_copy_rows(guac_terminal* terminal, + int start_row, int end_row, int offset); + +/** + * Flushes all pending operations within the given guac_terminal. + */ +void guac_terminal_flush(guac_terminal* terminal); + #endif diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index 50aa27dd..47f4d623 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -28,15 +28,6 @@ * @file terminal.h */ -#include "config.h" - -#include "buffer.h" -#include "common/cursor.h" -#include "display.h" -#include "scrollbar.h" -#include "types.h" -#include "typescript.h" - #include #include @@ -453,6 +444,52 @@ int guac_terminal_send_key(guac_terminal* term, int keysym, int pressed); int guac_terminal_send_mouse(guac_terminal* term, guac_user* user, int x, int y, int mask); +/** + * Sends the given string as if typed by the user. If terminal input is + * currently coming from a stream due to a prior call to + * guac_terminal_send_stream(), any input which would normally result from + * invoking this function is dropped. + * + * @param term + * The terminal which should receive the given data on STDIN. + * + * @param data + * The data the terminal should receive on STDIN. + * + * @param length + * The size of the given data, in bytes. + * + * @return + * The number of bytes written to STDIN, or a negative value if an error + * occurs preventing the data from being written. This should always be + * the size of the data given unless data is intentionally dropped. + */ +int guac_terminal_send_data(guac_terminal* term, const char* data, int length); + +/** + * Sends the given string as if typed by the user. If terminal input is + * currently coming from a stream due to a prior call to + * guac_terminal_send_stream(), any input which would normally result from + * invoking this function is dropped. + * + * @param term + * The terminal which should receive the given data on STDIN. + * + * @param data + * The data the terminal should receive on STDIN. + * + * @return + * The number of bytes written to STDIN, or a negative value if an error + * occurs preventing the data from being written. This should always be + * the size of the data given unless data is intentionally dropped. + */ +int guac_terminal_send_string(guac_terminal* term, const char* data); + +/** + * Writes the given string of characters to the terminal. + */ +int guac_terminal_write(guac_terminal* term, const char* c, int size); + /** * Initializes the handlers of the given guac_stream such that it serves as the * source of input to the terminal. Other input sources will be temporarily @@ -482,17 +519,27 @@ int guac_terminal_send_stream(guac_terminal* term, guac_user* user, guac_stream* stream); /** - * Handles a scroll event received from the scrollbar associated with a - * terminal. + * Sends data through STDIN as if typed by the user, using the format string + * given and any args (similar to printf). If terminal input is currently + * coming from a stream due to a prior call to guac_terminal_send_stream(), any + * input which would normally result from invoking this function is dropped. * - * @param scrollbar - * The scrollbar that has been scrolled. + * @param term + * The terminal which should receive the given data on STDIN. * - * @param value - * The new value that should be stored within the scrollbar, and - * represented within the terminal display. + * @param format + * A printf-style format string describing the data to be received on + * STDIN. + * + * @param ... + * Any srguments to use when filling the format string. + * + * @return + * The number of bytes written to STDIN, or a negative value if an error + * occurs preventing the data from being written. This should always be + * the size of the data given unless data is intentionally dropped. */ -void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value); +int guac_terminal_sendf(guac_terminal* term, const char* format, ...); /** * Replicates the current display state to a user that has just joined the @@ -512,6 +559,11 @@ void guac_terminal_scroll_handler(guac_terminal_scrollbar* scrollbar, int value) void guac_terminal_dup(guac_terminal* term, guac_user* user, guac_socket* socket); +/** + * Resize the terminal to the given dimensions. + */ +int guac_terminal_resize(guac_terminal* term, int width, int height); + /** * Returns the number of rows within the buffer of the given terminal which are * not currently displayed on screen. Adjustments to the desired scrollback @@ -588,262 +640,6 @@ void guac_terminal_clipboard_append(guac_terminal* terminal, */ void guac_terminal_remove_user(guac_terminal* terminal, guac_user* user); -/* INTERNAL FUNCTIONS */ - - -/** - * Acquires exclusive access to the terminal. Note that enforcing this - * exclusive access requires that ALL users of the terminal call this - * function before making further calls to the terminal. - */ -void guac_terminal_lock(guac_terminal* terminal); - -/** - * Releases exclusive access to the terminal. - */ -void guac_terminal_unlock(guac_terminal* terminal); - -/** - * Resets the state of the given terminal, as if it were just allocated. - */ -void guac_terminal_reset(guac_terminal* term); - -/** - * Writes the given string of characters to the terminal. - */ -int guac_terminal_write(guac_terminal* term, const char* c, int size); - -/** - * Sets the character at the given row and column to the specified value. - */ -int guac_terminal_set(guac_terminal* term, int row, int col, int codepoint); - -/** - * Clears the given region within a single row. - */ -int guac_terminal_clear_columns(guac_terminal* term, - int row, int start_col, int end_col); - -/** - * Clears the given region from right-to-left, top-to-bottom, replacing - * all characters with the current background color and attributes. - */ -int guac_terminal_clear_range(guac_terminal* term, - int start_row, int start_col, - int end_row, int end_col); - -/** - * Scrolls the terminal's current scroll region up by one row. - */ -int guac_terminal_scroll_up(guac_terminal* term, - int start_row, int end_row, int amount); - -/** - * Scrolls the terminal's current scroll region down by one row. - */ -int guac_terminal_scroll_down(guac_terminal* term, - int start_row, int end_row, int amount); - -/** - * Commits the current cursor location, updating the visible cursor - * on the screen. - */ -void guac_terminal_commit_cursor(guac_terminal* term); - -/** - * Scroll down the display by the given amount, replacing the new space with - * data from the buffer. If not enough data is available, the maximum - * amount will be scrolled. - */ -void guac_terminal_scroll_display_down(guac_terminal* terminal, int amount); - -/** - * Scroll up the display by the given amount, replacing the new space with data - * from either the buffer or the terminal buffer. If not enough data is - * available, the maximum amount will be scrolled. - */ -void guac_terminal_scroll_display_up(guac_terminal* terminal, int amount); - -/* LOW-LEVEL TERMINAL OPERATIONS */ - - -/** - * Copies the given range of columns to a new location, offset from - * the original by the given number of columns. - */ -void guac_terminal_copy_columns(guac_terminal* terminal, int row, - int start_column, int end_column, int offset); - -/** - * Copies the given range of rows to a new location, offset from the - * original by the given number of rows. - */ -void guac_terminal_copy_rows(guac_terminal* terminal, - int start_row, int end_row, int offset); - -/** - * Sets the given range of columns within the given row to the given - * character. - */ -void guac_terminal_set_columns(guac_terminal* terminal, int row, - int start_column, int end_column, guac_terminal_char* character); - -/** - * Resize the terminal to the given dimensions. - */ -int guac_terminal_resize(guac_terminal* term, int width, int height); - -/** - * Flushes all pending operations within the given guac_terminal. - */ -void guac_terminal_flush(guac_terminal* terminal); - -/** - * Sends the given string as if typed by the user. If terminal input is - * currently coming from a stream due to a prior call to - * guac_terminal_send_stream(), any input which would normally result from - * invoking this function is dropped. - * - * @param term - * The terminal which should receive the given data on STDIN. - * - * @param data - * The data the terminal should receive on STDIN. - * - * @param length - * The size of the given data, in bytes. - * - * @return - * The number of bytes written to STDIN, or a negative value if an error - * occurs preventing the data from being written. This should always be - * the size of the data given unless data is intentionally dropped. - */ -int guac_terminal_send_data(guac_terminal* term, const char* data, int length); - -/** - * Sends the given string as if typed by the user. If terminal input is - * currently coming from a stream due to a prior call to - * guac_terminal_send_stream(), any input which would normally result from - * invoking this function is dropped. - * - * @param term - * The terminal which should receive the given data on STDIN. - * - * @param data - * The data the terminal should receive on STDIN. - * - * @return - * The number of bytes written to STDIN, or a negative value if an error - * occurs preventing the data from being written. This should always be - * the size of the data given unless data is intentionally dropped. - */ -int guac_terminal_send_string(guac_terminal* term, const char* data); - -/** - * Sends data through STDIN as if typed by the user, using the format string - * given and any args (similar to printf). If terminal input is currently - * coming from a stream due to a prior call to guac_terminal_send_stream(), any - * input which would normally result from invoking this function is dropped. - * - * @param term - * The terminal which should receive the given data on STDIN. - * - * @param format - * A printf-style format string describing the data to be received on - * STDIN. - * - * @param ... - * Any srguments to use when filling the format string. - * - * @return - * The number of bytes written to STDIN, or a negative value if an error - * occurs preventing the data from being written. This should always be - * the size of the data given unless data is intentionally dropped. - */ -int guac_terminal_sendf(guac_terminal* term, const char* format, ...); - -/** - * Sets a tabstop in the given column. - */ -void guac_terminal_set_tab(guac_terminal* term, int column); - -/** - * Removes the tabstop at the given column. - */ -void guac_terminal_unset_tab(guac_terminal* term, int column); - -/** - * Removes all tabstops. - */ -void guac_terminal_clear_tabs(guac_terminal* term); - -/** - * Given a column within the given terminal, returns the location of the - * next tabstop (or the rightmost character, if no more tabstops exist). - */ -int guac_terminal_next_tab(guac_terminal* term, int column); - -/** - * Opens a new pipe stream, redirecting all output from the given terminal to - * that pipe stream. If a pipe stream is already open, that pipe stream will - * be flushed and closed prior to opening the new pipe stream. - * - * @param term - * The terminal which should redirect output to a new pipe stream having - * the given name. - * - * @param name - * The name of the pipe stream to open. - * - * @param flags - * A bitwise OR of all integer flags which should apply to the new pipe - * stream. - * - * @see GUAC_TERMINAL_PIPE_INTERPRET_OUTPUT - * @see GUAC_TERMINAL_PIPE_AUTOFLUSH - */ -void guac_terminal_pipe_stream_open(guac_terminal* term, const char* name, - int flags); - -/** - * Writes a single byte of data to the pipe stream currently open and - * associated with the given terminal. The pipe stream must already have been - * opened via guac_terminal_pipe_stream_open(). If no pipe stream is currently - * open, this function has no effect. Data written through this function may - * be buffered. - * - * @param term - * The terminal whose currently-open pipe stream should be written to. - * - * @param c - * The byte of data to write to the pipe stream. - */ -void guac_terminal_pipe_stream_write(guac_terminal* term, char c); - -/** - * Flushes any data currently buffered for the currently-open pipe stream - * associated with the given terminal. The pipe stream must already have been - * opened via guac_terminal_pipe_stream_open(). If no pipe stream is currently - * open or no data is in the buffer, this function has no effect. - * - * @param term - * The terminal whose pipe stream buffer should be flushed. - */ -void guac_terminal_pipe_stream_flush(guac_terminal* term); - -/** - * Closes the currently-open pipe stream associated with the given terminal, - * redirecting all output back to the terminal display. Any data currently - * buffered for output to the pipe stream will be flushed prior to closure. The - * pipe stream must already have been opened via - * guac_terminal_pipe_stream_open(). If no pipe stream is currently open, this - * function has no effect. - * - * @param term - * The terminal whose currently-open pipe stream should be closed. - */ -void guac_terminal_pipe_stream_close(guac_terminal* term); - /** * Requests that the terminal write all output to a new pair of typescript * files within the given path and using the given base name. Terminal output diff --git a/src/terminal/terminal/types.h b/src/terminal/terminal/types.h index fbf9c646..24cf7723 100644 --- a/src/terminal/terminal/types.h +++ b/src/terminal/terminal/types.h @@ -28,7 +28,6 @@ * @file types.h */ -#include "config.h" #include "palette.h" #include diff --git a/src/terminal/terminal/typescript.h b/src/terminal/terminal/typescript.h index 9f8dff2d..5edf178f 100644 --- a/src/terminal/terminal/typescript.h +++ b/src/terminal/terminal/typescript.h @@ -28,7 +28,6 @@ * @file typescript.h */ -#include "config.h" #include diff --git a/src/terminal/terminal/xparsecolor.h b/src/terminal/terminal/xparsecolor.h index 398de758..4550ac3c 100644 --- a/src/terminal/terminal/xparsecolor.h +++ b/src/terminal/terminal/xparsecolor.h @@ -26,9 +26,8 @@ * @file xparsecolor.h */ -#include "config.h" -#include "terminal/palette.h" +#include "palette.h" /** * Parses an X11 color spec, as defined by Xlib's XParseColor(), storing the diff --git a/src/terminal/typescript.c b/src/terminal/typescript.c index 5dd0df80..180547c6 100644 --- a/src/terminal/typescript.c +++ b/src/terminal/typescript.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "common/io.h" #include "terminal/typescript.h" diff --git a/src/terminal/xparsecolor.c b/src/terminal/xparsecolor.c index 779374d8..cb589f23 100644 --- a/src/terminal/xparsecolor.c +++ b/src/terminal/xparsecolor.c @@ -17,7 +17,6 @@ * under the License. */ -#include "config.h" #include "terminal/named-colors.h" #include "terminal/palette.h"