Add guac_rdpdr_fs_read_dir(). Bump _POSIX_C_SOURCE value as necessary for fdopendir().

This commit is contained in:
Michael Jumper 2013-08-01 17:44:39 -07:00
parent 9773f348e2
commit 52f9bac805
3 changed files with 76 additions and 18 deletions

View File

@ -37,6 +37,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef ENABLE_WINPR #ifdef ENABLE_WINPR
@ -251,11 +252,13 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path,
void guac_rdpdr_fs_close(guac_rdpdr_device* device, int file_id) { void guac_rdpdr_fs_close(guac_rdpdr_device* device, int file_id) {
guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data; guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data;
guac_rdpdr_fs_file* file;
/* Only close if file ID is valid */ /* Only close if file ID is valid */
if (file_id >= 0 && file_id <= GUAC_RDPDR_FS_MAX_FILES-1) { if (file_id < 0 || file_id >= GUAC_RDPDR_FS_MAX_FILES)
return;
guac_rdpdr_fs_file* file = &(data->files[file_id]); file = &(data->files[file_id]);
/* Close directory, if open */ /* Close directory, if open */
if (file->dir != NULL) if (file->dir != NULL)
@ -270,5 +273,32 @@ void guac_rdpdr_fs_close(guac_rdpdr_device* device, int file_id) {
} }
const char* guac_rdpdr_fs_read_dir(guac_rdpdr_device* device, int file_id) {
guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data;
guac_rdpdr_fs_file* file;
struct dirent* result;
/* Only read if file ID is valid */
if (file_id < 0 || file_id >= GUAC_RDPDR_FS_MAX_FILES)
return NULL;
file = &(data->files[file_id]);
/* Open directory if not yet open, stop if error */
if (file->dir == NULL) {
file->dir = fdopendir(file->fd);
if (file->dir == NULL)
return NULL;
}
/* Read next entry, stop if error */
if (readdir_r(file->dir, &(file->__dirent), &result))
return NULL;
/* Return filename */
return file->__dirent.d_name;
} }

View File

@ -176,6 +176,12 @@ typedef struct guac_rdpdr_fs_file {
*/ */
DIR* dir; DIR* dir;
/**
* The last read dirent structure. This is used if traversing the contents
* of a directory.
*/
struct dirent __dirent;
/** /**
* The size of this file, in bytes. * The size of this file, in bytes.
*/ */
@ -238,5 +244,11 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path,
*/ */
void guac_rdpdr_fs_close(guac_rdpdr_device* device, int file_id); void guac_rdpdr_fs_close(guac_rdpdr_device* device, int file_id);
/**
* Returns the next filename within the directory having the given file ID,
* or NULL if no more files.
*/
const char* guac_rdpdr_fs_read_dir(guac_rdpdr_device* device, int file_id);
#endif #endif

View File

@ -275,6 +275,9 @@ void guac_rdpdr_fs_process_notify_change_directory(guac_rdpdr_device* device,
void guac_rdpdr_fs_process_query_directory(guac_rdpdr_device* device, wStream* input_stream, void guac_rdpdr_fs_process_query_directory(guac_rdpdr_device* device, wStream* input_stream,
int file_id, int completion_id) { int file_id, int completion_id) {
/*guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data;
guac_rdpdr_fs_file* file = &(data->files[file_id]);*/
int fs_information_class, initial_query; int fs_information_class, initial_query;
int path_length; int path_length;
@ -285,13 +288,26 @@ void guac_rdpdr_fs_process_query_directory(guac_rdpdr_device* device, wStream* i
/* If this is the first query, the path is included after padding */ /* If this is the first query, the path is included after padding */
if (initial_query) { if (initial_query) {
unsigned char* path;
Stream_Seek(input_stream, 23); /* Padding */ Stream_Seek(input_stream, 23); /* Padding */
/* Path here */ path = Stream_Pointer(input_stream); /* Path */
}
guac_client_log_info(device->rdpdr->client, guac_client_log_info(device->rdpdr->client,
"Received dir query - class=0x%x, path_length=%i", "Received initial dir query - class=0x%x, path_length=%i, path=%s",
fs_information_class, path_length); fs_information_class, path_length, path);
/* Open directory */
/*file->dir = fdopendir(file->fd);*/
/* FIXME: Handle error */
}
else
guac_client_log_info(device->rdpdr->client,
"Received continued dir query - class=0x%x",
fs_information_class);
/* Dispatch to appropriate class-specific handler */ /* Dispatch to appropriate class-specific handler */
switch (fs_information_class) { switch (fs_information_class) {