Add guac_rdpdr_fs_read_dir(). Bump _POSIX_C_SOURCE value as necessary for fdopendir().
This commit is contained in:
parent
9773f348e2
commit
52f9bac805
@ -37,6 +37,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#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) {
|
||||
|
||||
guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data;
|
||||
guac_rdpdr_fs_file* file;
|
||||
|
||||
/* 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 */
|
||||
if (file->dir != NULL)
|
||||
@ -268,7 +271,34 @@ void guac_rdpdr_fs_close(guac_rdpdr_device* device, int file_id) {
|
||||
guac_pool_free_int(data->file_id_pool, file_id);
|
||||
data->open_files--;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
@ -176,6 +176,12 @@ typedef struct guac_rdpdr_fs_file {
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -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);
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
|
@ -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,
|
||||
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 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 (initial_query) {
|
||||
|
||||
unsigned char* path;
|
||||
|
||||
Stream_Seek(input_stream, 23); /* Padding */
|
||||
/* Path here */
|
||||
}
|
||||
path = Stream_Pointer(input_stream); /* Path */
|
||||
|
||||
guac_client_log_info(device->rdpdr->client,
|
||||
"Received dir query - class=0x%x, path_length=%i",
|
||||
fs_information_class, path_length);
|
||||
"Received initial dir query - class=0x%x, path_length=%i, path=%s",
|
||||
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 */
|
||||
switch (fs_information_class) {
|
||||
|
Loading…
Reference in New Issue
Block a user