diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages.c index 04afb353..c06fe840 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages.c @@ -239,59 +239,9 @@ void guac_rdpdr_fs_process_close(guac_rdpdr_device* device, /* If file was written to, and it's in the \Download folder, start stream */ if (file->bytes_written > 0 && strncmp(file->absolute_path, "\\Download\\", 10) == 0) { - - /* Get client and stream */ - guac_client* client = device->rdpdr->client; - - int file_id = guac_rdp_fs_open((guac_rdp_fs*) device->data, - file->absolute_path, ACCESS_FILE_READ_DATA, 0, - DISP_FILE_OPEN, 0); - - /* If file opened successfully, start stream */ - if (file_id >= 0) { - - guac_rdp_download_status* status; - char* basename; - - int i; - char c; - - /* Associate stream with transfer status */ - guac_stream* stream = guac_client_alloc_stream(client); - stream->data = status = malloc(sizeof(guac_rdp_download_status)); - status->file_id = file_id; - status->offset = 0; - - /* Delete file after opened */ - guac_rdp_fs_delete((guac_rdp_fs*) device->data, file_id); - - /* Get basename from absolute path */ - i=0; - basename = file->absolute_path; - do { - - c = file->absolute_path[i]; - if (c == '/' || c == '\\') - basename = &(file->absolute_path[i+1]); - - i++; - - } while (c != '\0'); - - GUAC_RDP_DEBUG(2, "Initiating download of \"%s\"", - file->absolute_path); - - /* Begin stream */ - guac_protocol_send_file(client->socket, stream, - "application/octet-stream", basename); - guac_socket_flush(client->socket); - - } - else - guac_client_log_error(client, "Unable to download \"%s\"", - file->absolute_path); - - } /* end if download */ + guac_rdpdr_start_download(device, file->absolute_path); + guac_rdp_fs_delete((guac_rdp_fs*) device->data, file_id); + } /* Close file */ guac_rdp_fs_close((guac_rdp_fs*) device->data, file_id); diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_service.c b/src/protocols/rdp/guac_rdpdr/rdpdr_service.c index d9ac12ce..c6f84ebf 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_service.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_service.c @@ -57,6 +57,7 @@ #include "rdpdr_fs_service.h" #include "client.h" +#include "debug.h" /** @@ -234,3 +235,52 @@ wStream* guac_rdpdr_new_io_completion(guac_rdpdr_device* device, } +void guac_rdpdr_start_download(guac_rdpdr_device* device, const char* path) { + + /* Get client and stream */ + guac_client* client = device->rdpdr->client; + + int file_id = guac_rdp_fs_open((guac_rdp_fs*) device->data, path, + ACCESS_FILE_READ_DATA, 0, DISP_FILE_OPEN, 0); + + /* If file opened successfully, start stream */ + if (file_id >= 0) { + + guac_rdp_download_status* status; + const char* basename; + + int i; + char c; + + /* Associate stream with transfer status */ + guac_stream* stream = guac_client_alloc_stream(client); + stream->data = status = malloc(sizeof(guac_rdp_download_status)); + status->file_id = file_id; + status->offset = 0; + + /* Get basename from absolute path */ + i=0; + basename = path; + do { + + c = path[i]; + if (c == '/' || c == '\\') + basename = &(path[i+1]); + + i++; + + } while (c != '\0'); + + GUAC_RDP_DEBUG(2, "Initiating download of \"%s\"", path); + + /* Begin stream */ + guac_protocol_send_file(client->socket, stream, + "application/octet-stream", basename); + guac_socket_flush(client->socket); + + } + else + guac_client_log_error(client, "Unable to download \"%s\"", path); + +} + diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_service.h b/src/protocols/rdp/guac_rdpdr/rdpdr_service.h index f7ca5c25..ae97e33b 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_service.h +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_service.h @@ -179,5 +179,10 @@ void guac_rdpdr_process_event(rdpSvcPlugin* plugin, wMessage* event); wStream* guac_rdpdr_new_io_completion(guac_rdpdr_device* device, int completion_id, int status, int size); +/** + * Begins streaming the given file to the user via a Guacamole file stream. + */ +void guac_rdpdr_start_download(guac_rdpdr_device* device, const char* path); + #endif