From 7c08593b83b8a1c1218eb123ccf242b1c88fe495 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 6 May 2014 17:14:40 -0700 Subject: [PATCH] GUAC-653: Restore file upload for SSH. --- src/protocols/ssh/ssh_client.c | 4 ++++ src/terminal/terminal.c | 2 ++ src/terminal/terminal.h | 22 ++++++++++++++++++++++ src/terminal/terminal_handlers.c | 6 ++++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/protocols/ssh/ssh_client.c b/src/protocols/ssh/ssh_client.c index 6cb6bb1e..e6b23def 100644 --- a/src/protocols/ssh/ssh_client.c +++ b/src/protocols/ssh/ssh_client.c @@ -309,6 +309,10 @@ void* ssh_client_thread(void* data) { /* Start SFTP session as well, if enabled */ if (client_data->enable_sftp) { + /* Init handlers for Guacamole-specific console codes */ + client_data->term->upload_path_handler = guac_sftp_set_upload_path; + client_data->term->file_download_handler = guac_sftp_download_file; + /* Create SSH session specific for SFTP */ guac_client_log_info(client, "Reconnecting for SFTP..."); client_data->sftp_ssh_session = __guac_ssh_create_session(client, NULL); diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index b5a4e21f..a4d44fa2 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -100,6 +100,8 @@ guac_terminal* guac_terminal_create(guac_client* client, guac_terminal* term = malloc(sizeof(guac_terminal)); term->client = client; + term->upload_path_handler = NULL; + term->file_download_handler = NULL; /* Init buffer */ term->buffer = guac_terminal_buffer_alloc(1000, &default_char); diff --git a/src/terminal/terminal.h b/src/terminal/terminal.h index f4ed3793..59c6c654 100644 --- a/src/terminal/terminal.h +++ b/src/terminal/terminal.h @@ -61,6 +61,16 @@ typedef struct guac_terminal guac_terminal; */ typedef int guac_terminal_char_handler(guac_terminal* term, unsigned char c); +/** + * Handler for setting the destination path for file uploads. + */ +typedef void guac_terminal_upload_path_handler(guac_client* client, char* path); + +/** + * Handler for creating an outbound file download stream for a specified file. + */ +typedef guac_stream* guac_terminal_file_download_handler(guac_client* client, char* filename); + /** * Represents a terminal emulator which uses a given Guacamole client to * render itself. @@ -72,6 +82,18 @@ struct guac_terminal { */ guac_client* client; + /** + * Called whenever the necessary terminal codes are sent to change + * the path for future file uploads. + */ + guac_terminal_upload_path_handler* upload_path_handler; + + /** + * Called whenever the necessary terminal codes are sent to initiate + * a download of a given remote file. + */ + guac_terminal_file_download_handler* file_download_handler; + /** * Lock which restricts simultaneous access to this terminal via the root * guac_terminal_* functions. diff --git a/src/terminal/terminal_handlers.c b/src/terminal/terminal_handlers.c index 5a4a0122..fd723676 100644 --- a/src/terminal/terminal_handlers.c +++ b/src/terminal/terminal_handlers.c @@ -884,7 +884,8 @@ int guac_terminal_set_directory(guac_terminal* term, unsigned char c) { if (c == 0x9C || c == 0x5C || c == 0x07) { filename[length++] = '\0'; term->char_handler = guac_terminal_echo; - /*guac_sftp_set_upload_path(term->client, filename);*/ + if (term->upload_path_handler) + term->upload_path_handler(term->client, filename); length = 0; } @@ -905,7 +906,8 @@ int guac_terminal_download(guac_terminal* term, unsigned char c) { if (c == 0x9C || c == 0x5C || c == 0x07) { filename[length++] = '\0'; term->char_handler = guac_terminal_echo; - /*guac_sftp_download_file(term->client, filename);*/ + if (term->file_download_handler) + term->file_download_handler(term->client, filename); length = 0; }