From 4b7c679808c7c299f6750802af923d5908e03f5b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 23 Apr 2017 15:13:37 -0700 Subject: [PATCH] GUACAMOLE-265: Set connection name when terminal window title is changed. --- src/terminal/terminal/terminal_handlers.h | 13 +++++++++ src/terminal/terminal_handlers.c | 34 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/terminal/terminal/terminal_handlers.h b/src/terminal/terminal/terminal_handlers.h index 0a8fdcef..0b2f9bb3 100644 --- a/src/terminal/terminal/terminal_handlers.h +++ b/src/terminal/terminal/terminal_handlers.h @@ -138,6 +138,19 @@ int guac_terminal_open_pipe_stream(guac_terminal* term, unsigned char c); */ int guac_terminal_close_pipe_stream(guac_terminal* term, unsigned char c); +/** + * Parses the remainder of an OSC sequence setting the window title. The + * window title is everything after the window title sequence begins, up to + * the end of the OSC sequence itself. + * + * @param term + * The terminal that received the given character of data. + * + * @param c + * The character that was received by the given terminal. + */ +int guac_terminal_window_title(guac_terminal* term, unsigned char c); + /** * Parses the remainder of xterm's OSC sequence for redefining the terminal * emulator's palette. diff --git a/src/terminal/terminal_handlers.c b/src/terminal/terminal_handlers.c index 8e83fb11..633798b1 100644 --- a/src/terminal/terminal_handlers.c +++ b/src/terminal/terminal_handlers.c @@ -1156,6 +1156,36 @@ int guac_terminal_close_pipe_stream(guac_terminal* term, unsigned char c) { } +int guac_terminal_window_title(guac_terminal* term, unsigned char c) { + + static int position = 0; + static char title[4096]; + + guac_socket* socket = term->client->socket; + + /* Stop on ECMA-48 ST (String Terminator */ + if (c == 0x9C || c == 0x5C || c == 0x07) { + + /* Terminate and reset stored title */ + title[position] = '\0'; + position = 0; + + /* Send title as connection name */ + guac_protocol_send_name(socket, title); + guac_socket_flush(socket); + + term->char_handler = guac_terminal_echo; + + } + + /* Store all other characters within title, space permitting */ + else if (position < sizeof(title) - 1) + title[position++] = (char) c; + + return 0; + +} + int guac_terminal_xterm_palette(guac_terminal* term, unsigned char c) { /* NOTE: Currently unimplemented. Attempts to set the 256-color palette @@ -1196,6 +1226,10 @@ int guac_terminal_osc(guac_terminal* term, unsigned char c) { else if (operation == 482203) term->char_handler = guac_terminal_close_pipe_stream; + /* Set window title OSC */ + else if (operation == 0 || operation == 2) + term->char_handler = guac_terminal_window_title; + /* xterm 256-color palette redefinition */ else if (operation == 4) term->char_handler = guac_terminal_xterm_palette;