From 4a7e5609f543c9363b3fba713d147123d3cf5c61 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 7 May 2014 15:30:48 -0700 Subject: [PATCH] GUAC-654: Implement local echo. --- src/protocols/telnet/client.c | 1 + src/protocols/telnet/client.h | 6 ++++++ src/protocols/telnet/telnet_client.c | 21 ++++++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/protocols/telnet/client.c b/src/protocols/telnet/client.c index 21ffe039..fce5cb82 100644 --- a/src/protocols/telnet/client.c +++ b/src/protocols/telnet/client.c @@ -85,6 +85,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { client_data->telnet = NULL; client_data->socket_fd = -1; client_data->naws_enabled = 0; + client_data->echo_enabled = 1; if (argc != TELNET_ARGS_COUNT) { guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Wrong number of arguments"); diff --git a/src/protocols/telnet/client.h b/src/protocols/telnet/client.h index da2455cf..227d0e56 100644 --- a/src/protocols/telnet/client.h +++ b/src/protocols/telnet/client.h @@ -75,6 +75,12 @@ typedef struct guac_telnet_client_data { */ int naws_enabled; + /** + * Whether all user input should be automatically echoed to the + * terminal. + */ + int echo_enabled; + /** * The terminal which will render all output from the telnet client. */ diff --git a/src/protocols/telnet/telnet_client.c b/src/protocols/telnet/telnet_client.c index a0933129..9ceff036 100644 --- a/src/protocols/telnet/telnet_client.c +++ b/src/protocols/telnet/telnet_client.c @@ -42,7 +42,7 @@ #include static const telnet_telopt_t __telnet_options[] = { - { TELNET_TELOPT_ECHO, TELNET_WONT, TELNET_DONT }, + { TELNET_TELOPT_ECHO, TELNET_WONT, TELNET_DO }, { TELNET_TELOPT_TTYPE, TELNET_WILL, TELNET_DONT }, { TELNET_TELOPT_COMPRESS2, TELNET_WONT, TELNET_DO }, { TELNET_TELOPT_MSSP, TELNET_WONT, TELNET_DO }, @@ -89,7 +89,19 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event, guac_client_stop(client); break; - /* Feature enable */ + /* Remote feature enabled */ + case TELNET_EV_WILL: + if (event->neg.telopt == TELNET_TELOPT_ECHO) + client_data->echo_enabled = 0; /* Disable local echo, as remote will echo */ + break; + + /* Remote feature disabled */ + case TELNET_EV_WONT: + if (event->neg.telopt == TELNET_TELOPT_ECHO) + client_data->echo_enabled = 1; /* Enable local echo, as remote won't echo */ + break; + + /* Local feature enable */ case TELNET_EV_DO: if (event->neg.telopt == TELNET_TELOPT_NAWS) { client_data->naws_enabled = 1; @@ -131,8 +143,11 @@ static void* __guac_telnet_input_thread(void* data) { int bytes_read; /* Write all data read */ - while ((bytes_read = guac_terminal_read_stdin(client_data->term, buffer, sizeof(buffer))) > 0) + while ((bytes_read = guac_terminal_read_stdin(client_data->term, buffer, sizeof(buffer))) > 0) { telnet_send(client_data->telnet, buffer, bytes_read); + if (client_data->echo_enabled) + guac_terminal_write_stdout(client_data->term, buffer, bytes_read); + } return NULL;