Move download-specific logic to rdpdr.

This commit is contained in:
Michael Jumper 2013-11-12 11:25:04 -08:00
parent f4ff04ab30
commit b262440ba5
2 changed files with 56 additions and 19 deletions

View File

@ -53,6 +53,7 @@
#include "rdpdr_messages.h" #include "rdpdr_messages.h"
#include "rdpdr_service.h" #include "rdpdr_service.h"
#include "client.h" #include "client.h"
#include "debug.h"
#include "unicode.h" #include "unicode.h"
#include <freerdp/utils/svc_plugin.h> #include <freerdp/utils/svc_plugin.h>
@ -101,10 +102,27 @@ void guac_rdpdr_fs_process_create(guac_rdpdr_device* device,
/* Otherwise, open succeeded */ /* Otherwise, open succeeded */
else { else {
guac_rdp_fs_file* file;
output_stream = guac_rdpdr_new_io_completion(device, completion_id, output_stream = guac_rdpdr_new_io_completion(device, completion_id,
STATUS_SUCCESS, 5); STATUS_SUCCESS, 5);
Stream_Write_UINT32(output_stream, file_id); /* fileId */ Stream_Write_UINT32(output_stream, file_id); /* fileId */
Stream_Write_UINT8(output_stream, 0); /* information */ Stream_Write_UINT8(output_stream, 0); /* information */
/* Create \Download if it doesn't exist */
file = guac_rdp_fs_get_file((guac_rdp_fs*) device->data, file_id);
if (file != NULL && strcmp(file->absolute_path, "\\") == 0) {
int download_id =
guac_rdp_fs_open((guac_rdp_fs*) device->data, "\\Download",
ACCESS_GENERIC_READ, 0,
DISP_FILE_OPEN_IF, FILE_DIRECTORY_FILE);
if (download_id >= 0)
guac_rdp_fs_close((guac_rdp_fs*) device->data, download_id);
}
} }
svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream); svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream);
@ -194,6 +212,44 @@ void guac_rdpdr_fs_process_close(guac_rdpdr_device* device,
wStream* input_stream, int file_id, int completion_id) { wStream* input_stream, int file_id, int completion_id) {
wStream* output_stream; wStream* output_stream;
guac_rdp_fs_file* file;
/* Get file */
file = guac_rdp_fs_get_file((guac_rdp_fs*) device->data, file_id);
if (file == NULL)
return;
/* 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) {
int i;
char c;
/* Get client */
guac_client* client = device->rdpdr->client;
/* Allocate stream */
guac_stream* stream = guac_client_alloc_stream(client);
/* Get basename from absolute path */
char* 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);
guac_protocol_send_file(client->socket, stream,
"application/octet-stream", basename);
guac_socket_flush(client->socket);
}
/* 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);

View File

@ -215,19 +215,6 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path,
GUAC_RDP_DEBUG(2, "Normalized path \"%s\" to \"%s\".", GUAC_RDP_DEBUG(2, "Normalized path \"%s\" to \"%s\".",
path, normalized_path); path, normalized_path);
/* Create \Download if it doesn't exist */
if (strcmp(normalized_path, "\\") == 0) {
int download_id = guac_rdp_fs_open(fs, "\\Download",
ACCESS_GENERIC_READ, 0,
DISP_FILE_OPEN_IF, FILE_DIRECTORY_FILE);
if (download_id < 0)
return download_id;
guac_rdp_fs_close(fs, download_id);
}
/* Translate normalized path to real path */ /* Translate normalized path to real path */
__guac_rdp_fs_translate_path(fs, normalized_path, real_path); __guac_rdp_fs_translate_path(fs, normalized_path, real_path);
@ -477,12 +464,6 @@ void guac_rdp_fs_close(guac_rdp_fs* fs, int file_id) {
file = &(fs->files[file_id]); file = &(fs->files[file_id]);
/* 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) {
GUAC_RDP_DEBUG(2, "Will download \"%s\"", file->absolute_path);
}
GUAC_RDP_DEBUG(2, "Closed \"%s\" (file_id=%i)", GUAC_RDP_DEBUG(2, "Closed \"%s\" (file_id=%i)",
file->absolute_path, file_id); file->absolute_path, file_id);