Move download logic into own function.
This commit is contained in:
parent
a1d4e2d2e6
commit
88f9f883b4
@ -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 was written to, and it's in the \Download folder, start stream */
|
||||||
if (file->bytes_written > 0 &&
|
if (file->bytes_written > 0 &&
|
||||||
strncmp(file->absolute_path, "\\Download\\", 10) == 0) {
|
strncmp(file->absolute_path, "\\Download\\", 10) == 0) {
|
||||||
|
guac_rdpdr_start_download(device, file->absolute_path);
|
||||||
/* 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);
|
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 */
|
|
||||||
|
|
||||||
/* Close file */
|
/* Close file */
|
||||||
guac_rdp_fs_close((guac_rdp_fs*) device->data, file_id);
|
guac_rdp_fs_close((guac_rdp_fs*) device->data, file_id);
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
#include "rdpdr_fs_service.h"
|
#include "rdpdr_fs_service.h"
|
||||||
|
|
||||||
#include "client.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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -179,5 +179,10 @@ void guac_rdpdr_process_event(rdpSvcPlugin* plugin, wMessage* event);
|
|||||||
wStream* guac_rdpdr_new_io_completion(guac_rdpdr_device* device,
|
wStream* guac_rdpdr_new_io_completion(guac_rdpdr_device* device,
|
||||||
int completion_id, int status, int size);
|
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
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user