From e02df8d5504214acf3b01cc55e124754ce0b4bcf Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 1 Jul 2018 22:25:09 -0700 Subject: [PATCH] GUACAMOLE-597: Additionally parse integer flags which may affect pipe stream contents. --- src/terminal/terminal.c | 8 +++++--- src/terminal/terminal/terminal.h | 14 +++++++++++++- src/terminal/terminal_handlers.c | 33 ++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index b24ec8ea..5a106ad1 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -1961,7 +1961,8 @@ int guac_terminal_next_tab(guac_terminal* term, int column) { return tabstop; } -void guac_terminal_pipe_stream_open(guac_terminal* term, const char* name) { +void guac_terminal_pipe_stream_open(guac_terminal* term, const char* name, + int flags) { guac_client* client = term->client; guac_socket* socket = client->socket; @@ -1972,13 +1973,14 @@ void guac_terminal_pipe_stream_open(guac_terminal* term, const char* name) { /* Allocate and assign new pipe stream */ term->pipe_stream = guac_client_alloc_stream(client); term->pipe_buffer_length = 0; + term->pipe_stream_flags = flags; /* Open new pipe stream */ guac_protocol_send_pipe(socket, term->pipe_stream, "text/plain", name); /* Log redirect at debug level */ - guac_client_log(client, GUAC_LOG_DEBUG, - "Terminal output now redirected to pipe '%s'.", name); + guac_client_log(client, GUAC_LOG_DEBUG, "Terminal output now directed to " + "pipe \"%s\" (flags=%i).", name, flags); } diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index adadc4fe..e0863922 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -215,6 +215,13 @@ struct guac_terminal { */ 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. + */ + 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 @@ -920,8 +927,13 @@ int guac_terminal_next_tab(guac_terminal* term, int column); * * @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. */ -void guac_terminal_pipe_stream_open(guac_terminal* term, const char* name); +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 diff --git a/src/terminal/terminal_handlers.c b/src/terminal/terminal_handlers.c index afbf20e6..1437307a 100644 --- a/src/terminal/terminal_handlers.c +++ b/src/terminal/terminal_handlers.c @@ -1141,27 +1141,44 @@ int guac_terminal_download(guac_terminal* term, unsigned char c) { int guac_terminal_open_pipe_stream(guac_terminal* term, unsigned char c) { - static char stream_name[2048]; + static char param[2048]; static int length = 0; + static int flags = 0; /* Open pipe on ECMA-48 ST (String Terminator) */ if (c == 0x9C || c == 0x5C || c == 0x07) { - /* End stream name string */ - stream_name[length++] = '\0'; + /* End parameter string */ + param[length++] = '\0'; length = 0; - /* Open new pipe stream */ - guac_terminal_pipe_stream_open(term, stream_name); + /* Open new pipe stream using final parameter as name */ + guac_terminal_pipe_stream_open(term, param, flags); /* Return to echo mode */ term->char_handler = guac_terminal_echo; + /* Reset tracked flags for sake of any future pipe streams */ + flags = 0; + } - /* Otherwise, store character within stream name */ - else if (length < sizeof(stream_name)-1) - stream_name[length++] = c; + /* Interpret all parameters prior to the final parameter as integer + * flags which should affect the pipe stream when opened */ + else if (c == ';') { + + /* End parameter string */ + param[length++] = '\0'; + length = 0; + + /* Parse parameter string as integer flags */ + flags |= atoi(param); + + } + + /* Otherwise, store character within parameter */ + else if (length < sizeof(param)-1) + param[length++] = c; return 0;