GUACAMOLE-597: Additionally parse integer flags which may affect pipe stream contents.

This commit is contained in:
Michael Jumper 2018-07-01 22:25:09 -07:00
parent 79ce5ad8b0
commit e02df8d550
3 changed files with 43 additions and 12 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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;