From 46e908c06eae26d419f72bd3bd071287ca4c02f6 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Fri, 23 Feb 2018 22:14:11 -0500 Subject: [PATCH] GUACAMOLE-269: Allow backspace key to be configured. --- src/protocols/ssh/settings.c | 13 +++++++++++++ src/protocols/ssh/settings.h | 5 +++++ src/protocols/ssh/ssh.c | 2 +- src/protocols/telnet/settings.c | 11 +++++++++++ src/protocols/telnet/settings.h | 7 +++++++ src/protocols/telnet/telnet.c | 2 +- src/terminal/terminal.c | 9 +++++++-- src/terminal/terminal/terminal.h | 12 +++++++++++- 8 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/protocols/ssh/settings.c b/src/protocols/ssh/settings.c index 7c803eaa..89b6e82b 100644 --- a/src/protocols/ssh/settings.c +++ b/src/protocols/ssh/settings.c @@ -56,6 +56,7 @@ const char* GUAC_SSH_CLIENT_ARGS[] = { "create-recording-path", "read-only", "server-alive-interval", + "backspace", NULL }; @@ -209,6 +210,13 @@ enum SSH_ARGS_IDX { */ IDX_SERVER_ALIVE_INTERVAL, + /** + * The ASCII code, in decimal, to send for the backspace key, as configured + * by the SSH connection from the client. By default this will be 0x7f, + * the ASCII DELETE code. + */ + IDX_BACKSPACE, + SSH_ARGS_COUNT }; @@ -348,6 +356,11 @@ guac_ssh_settings* guac_ssh_parse_args(guac_user* user, guac_user_parse_args_int(user, GUAC_SSH_CLIENT_ARGS, argv, IDX_SERVER_ALIVE_INTERVAL, 0); + /* Parse backspace key setting */ + settings->backspace = + guac_user_parse_args_int(user, GUAC_SSH_CLIENT_ARGS, argv, + IDX_BACKSPACE, 127); + /* Parsing was successful */ return settings; diff --git a/src/protocols/ssh/settings.h b/src/protocols/ssh/settings.h index 689d4258..65f60fa8 100644 --- a/src/protocols/ssh/settings.h +++ b/src/protocols/ssh/settings.h @@ -223,6 +223,11 @@ typedef struct guac_ssh_settings { */ int server_alive_interval; + /** + * The decismal ASCII code of the command to send for backspace. + */ + int backspace; + } guac_ssh_settings; /** diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 62bfbb25..86ebddbc 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -207,7 +207,7 @@ void* ssh_client_thread(void* data) { ssh_client->term = guac_terminal_create(client, settings->font_name, settings->font_size, settings->resolution, settings->width, settings->height, - settings->color_scheme); + settings->color_scheme, settings->backspace); /* Fail if terminal init failed */ if (ssh_client->term == NULL) { diff --git a/src/protocols/telnet/settings.c b/src/protocols/telnet/settings.c index 082cff48..acb1f905 100644 --- a/src/protocols/telnet/settings.c +++ b/src/protocols/telnet/settings.c @@ -50,6 +50,7 @@ const char* GUAC_TELNET_CLIENT_ARGS[] = { "recording-include-keys", "create-recording-path", "read-only", + "backspace", NULL }; @@ -174,6 +175,11 @@ enum TELNET_ARGS_IDX { */ IDX_READ_ONLY, + /** + * ASCII code to use for the backspace key, or 127 if not specified. + */ + IDX_BACKSPACE, + TELNET_ARGS_COUNT }; @@ -328,6 +334,11 @@ guac_telnet_settings* guac_telnet_parse_args(guac_user* user, guac_user_parse_args_boolean(user, GUAC_TELNET_CLIENT_ARGS, argv, IDX_CREATE_RECORDING_PATH, false); + /* Parse backspae key code */ + settings->backspace = + guac_user_parse_args_int(user, GUAC_TELNET_CLIENT_ARGS, argv, + IDX_BACKSPACE, 127); + /* Parsing was successful */ return settings; diff --git a/src/protocols/telnet/settings.h b/src/protocols/telnet/settings.h index 11761c63..71c807a3 100644 --- a/src/protocols/telnet/settings.h +++ b/src/protocols/telnet/settings.h @@ -207,6 +207,13 @@ typedef struct guac_telnet_settings { */ bool recording_include_keys; + /** + * The ASCII code, in decimal, that the telnet client will use when the + * backspace key is pressed. By default, this is 0x7f, ASCII delete, + * but can be configured in the client settings. + */ + int backspace; + } guac_telnet_settings; /** diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index 2a4000d8..040d10be 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -480,7 +480,7 @@ void* guac_telnet_client_thread(void* data) { telnet_client->term = guac_terminal_create(client, settings->font_name, settings->font_size, settings->resolution, settings->width, settings->height, - settings->color_scheme); + settings->color_scheme, settings->backspace); /* Fail if terminal init failed */ if (telnet_client->term == NULL) { diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 4d2171a0..0dae5ccd 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -257,7 +257,8 @@ void* guac_terminal_thread(void* data) { guac_terminal* guac_terminal_create(guac_client* client, const char* font_name, int font_size, int dpi, - int width, int height, const char* color_scheme) { + int width, int height, const char* color_scheme, + const int backspace) { int default_foreground; int default_background; @@ -406,6 +407,10 @@ guac_terminal* guac_terminal_create(guac_client* client, return NULL; } + /* Configure backspace */ + term->backspace = backspace; + guac_client_log(client, GUAC_LOG_DEBUG, "Backspace has been set to %d", term->backspace); + return term; } @@ -1594,7 +1599,7 @@ static int __guac_terminal_send_key(guac_terminal* term, int keysym, int pressed /* Non-printable keys */ else { - if (keysym == 0xFF08) return guac_terminal_send_string(term, "\x7F"); /* Backspace */ + if (keysym == 0xFF08) return guac_terminal_send_string(term, &term->backspace); /* Backspace */ if (keysym == 0xFF09 || keysym == 0xFF89) return guac_terminal_send_string(term, "\x09"); /* Tab */ if (keysym == 0xFF0D || keysym == 0xFF8D) return guac_terminal_send_string(term, "\x0D"); /* Enter */ if (keysym == 0xFF1B) return guac_terminal_send_string(term, "\x1B"); /* Esc */ diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index 37b07484..90cf06ac 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -432,6 +432,11 @@ struct guac_terminal { */ guac_common_clipboard* clipboard; + /** + * Hexidecimal ASCII code sent when backspace is pressed. + */ + char backspace; + }; /** @@ -464,13 +469,18 @@ struct guac_terminal { * invalid, a warning will be logged, and the terminal will fall back on * GUAC_TERMINAL_SCHEME_GRAY_BLACK. * + * @param backspace + * The decimal ASCII code to send when backspace is pressed in + * this terminal. + * * @return * 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_client* client, const char* font_name, int font_size, int dpi, - int width, int height, const char* color_scheme); + int width, int height, const char* color_scheme, + const int backspace); /** * Frees all resources associated with the given terminal.