mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
added unit tests for read operation (adapter); did some hardening
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
#include "webfuse/adapter/impl/operation/open.h"
|
||||
#include "webfuse/adapter/impl/operation/close.h"
|
||||
#include "webfuse/adapter/impl/operation/read.h"
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "webfuse/adapter/impl/operation/read.h"
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <errno.h>
|
||||
@@ -11,8 +12,9 @@
|
||||
|
||||
#define WF_MAX_READ_LENGTH 4096
|
||||
|
||||
static char * wf_impl_fill_buffer(
|
||||
char * wf_impl_fill_buffer(
|
||||
char const * data,
|
||||
size_t data_size,
|
||||
char const * format,
|
||||
size_t count,
|
||||
wf_status * status)
|
||||
@@ -24,11 +26,22 @@ static char * wf_impl_fill_buffer(
|
||||
{
|
||||
if (0 == strcmp("identity", format))
|
||||
{
|
||||
memcpy(buffer, data, count);
|
||||
if (count == data_size)
|
||||
{
|
||||
memcpy(buffer, data, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
*status = WF_BAD;
|
||||
}
|
||||
}
|
||||
else if (0 == strcmp("base64", format))
|
||||
{
|
||||
wf_base64_decode(data, strlen(data), (uint8_t *) buffer, count);
|
||||
size_t result = wf_base64_decode(data, data_size, (uint8_t *) buffer, count);
|
||||
if (result != count)
|
||||
{
|
||||
*status = WF_BAD;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -36,10 +49,16 @@ static char * wf_impl_fill_buffer(
|
||||
}
|
||||
}
|
||||
|
||||
if (WF_GOOD != *status)
|
||||
{
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void wf_impl_operation_read_finished(
|
||||
void wf_impl_operation_read_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
@@ -60,10 +79,11 @@ static void wf_impl_operation_read_finished(
|
||||
json_is_integer(count_holder))
|
||||
{
|
||||
char const * const data = json_string_value(data_holder);
|
||||
size_t const data_size = json_string_length(data_holder);
|
||||
char const * const format = json_string_value(format_holder);
|
||||
length = (size_t) json_integer_value(count_holder);
|
||||
|
||||
buffer = wf_impl_fill_buffer(data, format, length, &status);
|
||||
buffer = wf_impl_fill_buffer(data, data_size, format, length, &status);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
36
lib/webfuse/adapter/impl/operation/read.h
Normal file
36
lib/webfuse/adapter/impl/operation/read.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATION_READ_H
|
||||
#define WF_ADAPTER_IMPL_OPERATION_READ_H
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wf_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t ino, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
extern char * wf_impl_fill_buffer(
|
||||
char const * data,
|
||||
size_t data_size,
|
||||
char const * format,
|
||||
size_t count,
|
||||
wf_status * status);
|
||||
|
||||
extern void wf_impl_operation_read_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -34,11 +34,6 @@ extern void wf_impl_operation_readdir (
|
||||
off_t offset,
|
||||
struct fuse_file_info *file_info);
|
||||
|
||||
extern void wf_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t ino, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct wf_impl_operations_context * context);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user