1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

made static_filesystem private (used for test purposes only)

This commit is contained in:
Falk Werner 2020-02-20 18:54:29 +01:00
parent a27e68f5a6
commit 17fa84bc38
14 changed files with 133 additions and 402 deletions

View File

@ -12,13 +12,14 @@ add_executable(alltests
test/webfuse/utils/msleep.cc test/webfuse/utils/msleep.cc
test/webfuse/utils/die_if.cc test/webfuse/utils/die_if.cc
test/webfuse/utils/timeout_watcher.cc test/webfuse/utils/timeout_watcher.cc
test/webfuse/utils/path.c
test/webfuse/utils/static_filesystem.c
test/webfuse/fakes/fake_adapter_server.cc test/webfuse/fakes/fake_adapter_server.cc
test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_authenticator.cc
test/webfuse/mocks/mock_request.cc test/webfuse/mocks/mock_request.cc
test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_container_of.cc
test/webfuse/tests/core/test_string.cc test/webfuse/tests/core/test_string.cc
test/webfuse/tests/core/test_slist.cc test/webfuse/tests/core/test_slist.cc
test/webfuse/tests/core/test_path.cc
test/webfuse/tests/core/test_base64.cc test/webfuse/tests/core/test_base64.cc
test/webfuse/tests/core/test_status.cc test/webfuse/tests/core/test_status.cc
test/webfuse/tests/core/test_message.cc test/webfuse/tests/core/test_message.cc
@ -43,7 +44,6 @@ add_executable(alltests
test/webfuse/tests/adapter/jsonrpc/test_server.cc test/webfuse/tests/adapter/jsonrpc/test_server.cc
test/webfuse/tests/adapter/jsonrpc/test_proxy.cc test/webfuse/tests/adapter/jsonrpc/test_proxy.cc
test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_url.cc
test/webfuse/tests/provider/test_static_filesystem.cc
test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/test_client_protocol.cc
test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/test_integration.cc
test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/server.cc

View File

@ -6,7 +6,6 @@ add_library(webfuse-core STATIC
lib/webfuse/core/message_queue.c lib/webfuse/core/message_queue.c
lib/webfuse/core/status.c lib/webfuse/core/status.c
lib/webfuse/core/string.c lib/webfuse/core/string.c
lib/webfuse/core/path.c
lib/webfuse/core/base64.c lib/webfuse/core/base64.c
lib/webfuse/core/lws_log.c lib/webfuse/core/lws_log.c
) )

View File

@ -15,7 +15,6 @@ add_library(webfuse-provider-static STATIC
lib/webfuse/provider/impl/operation/open.c lib/webfuse/provider/impl/operation/open.c
lib/webfuse/provider/impl/operation/close.c lib/webfuse/provider/impl/operation/close.c
lib/webfuse/provider/impl/operation/read.c lib/webfuse/provider/impl/operation/read.c
lib/webfuse/provider/impl/static_filesystem.c
) )
set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider) set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider)

View File

@ -1,114 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/static_filesystem.h
/// \brief Reference implementation of static filesystem.
///
/// This header is used by integration tests. It may be removed from the
/// library.
///
/// \todo Remove this header from library
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_STATIC_FILESYSTEM_H
#define WFP_STATIC_FILESYSTEM_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
using ::std::size_t;
#endif
#include <webfuse/provider/api.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_client_config;
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
struct wfp_static_filesystem;
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
typedef size_t
wfp_static_filesystem_read_fn(
size_t offset,
char * buffer,
size_t buffer_size,
void * user_data);
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
typedef void
wfp_static_filesystem_get_info_fn(
void * user_data,
int * result_mode,
size_t * result_size);
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
extern WFP_API struct wfp_static_filesystem *
wfp_static_filesystem_create(
struct wfp_client_config * config);
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
extern WFP_API void
wfp_static_filesystem_dispose(
struct wfp_static_filesystem * filesystem);
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
extern WFP_API void
wfp_static_filesystem_add(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content,
size_t length);
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
extern WFP_API void
wfp_static_filesystem_add_text(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content);
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
extern WFP_API void
wfp_static_filesystem_add_file(
struct wfp_static_filesystem * filesystem,
char const * path,
char const * filename);
//------------------------------------------------------------------------------
/// \deprecated This will be removed. Dont use it.
//------------------------------------------------------------------------------
extern WFP_API void
wfp_static_filesystem_add_generic(
struct wfp_static_filesystem * filesystem,
char const * path,
wfp_static_filesystem_read_fn * read,
wfp_static_filesystem_get_info_fn * get_info,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -22,6 +22,4 @@
#include <webfuse/provider/operation/close.h> #include <webfuse/provider/operation/close.h>
#include <webfuse/provider/operation/read.h> #include <webfuse/provider/operation/read.h>
#include <webfuse/provider/static_filesystem.h>
#endif #endif

View File

@ -11,7 +11,6 @@
#include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/client_config.h"
#include "webfuse/provider/impl/client.h" #include "webfuse/provider/impl/client.h"
#include "webfuse/provider/impl/dirbuffer.h" #include "webfuse/provider/impl/dirbuffer.h"
#include "webfuse/provider/impl/static_filesystem.h"
// respond // respond
@ -241,60 +240,3 @@ void wfp_dirbuffer_add(
{ {
wfp_impl_dirbuffer_add(buffer, name, inode); wfp_impl_dirbuffer_add(buffer, name, inode);
} }
// static_filesystem
struct wfp_static_filesystem *
wfp_static_filesystem_create(
struct wfp_client_config * config)
{
return wfp_impl_static_filesystem_create(config);
}
void
wfp_static_filesystem_dispose(
struct wfp_static_filesystem * filesystem)
{
wfp_impl_static_filesystem_dispose(filesystem);
}
void
wfp_static_filesystem_add(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content,
size_t length)
{
wfp_impl_static_filesystem_add(filesystem, path, mode, content, length);
}
void
wfp_static_filesystem_add_text(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content)
{
wfp_impl_static_filesystem_add_text(filesystem, path, mode, content);
}
void
wfp_static_filesystem_add_file(
struct wfp_static_filesystem * filesystem,
char const * path,
char const * filename)
{
wfp_impl_static_filesystem_add_file(filesystem, path, filename);
}
void
wfp_static_filesystem_add_generic(
struct wfp_static_filesystem * filesystem,
char const * path,
wfp_static_filesystem_read_fn * read,
wfp_static_filesystem_get_info_fn * get_info,
void * user_data)
{
wfp_impl_static_filesystem_add_generic(filesystem, path, read, get_info, user_data);
}

View File

@ -1,52 +0,0 @@
#ifndef WFP_IMPL_STATIC_FILESYSTEM_H
#define WFP_IMPL_STATIC_FILESYSTEM_H
#include "webfuse/provider/static_filesystem.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern struct wfp_static_filesystem *
wfp_impl_static_filesystem_create(
struct wfp_client_config * config);
extern void
wfp_impl_static_filesystem_dispose(
struct wfp_static_filesystem * filesystem);
extern void
wfp_impl_static_filesystem_add(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content,
size_t length);
extern void
wfp_impl_static_filesystem_add_text(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content);
extern void
wfp_impl_static_filesystem_add_file(
struct wfp_static_filesystem * filesystem,
char const * path,
char const * filename);
extern void
wfp_impl_static_filesystem_add_generic(
struct wfp_static_filesystem * filesystem,
char const * path,
wfp_static_filesystem_read_fn * read,
wfp_static_filesystem_get_info_fn * get_info,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,58 +0,0 @@
#include <gtest/gtest.h>
#include "webfuse/core/path.h"
TEST(wf_path, empty)
{
struct wf_path * path = wf_path_create("");
ASSERT_EQ(0, wf_path_element_count(path));
ASSERT_EQ(nullptr, wf_path_get_element(path, 0));
wf_path_dispose(path);
}
TEST(wf_path, relative_file)
{
struct wf_path * path = wf_path_create("some.file");
ASSERT_EQ(1, wf_path_element_count(path));
ASSERT_STREQ("some.file", wf_path_get_element(path, 0));
wf_path_dispose(path);
}
TEST(wf_path, absolute_file)
{
struct wf_path * path = wf_path_create("/absolute.file");
ASSERT_EQ(1, wf_path_element_count(path));
ASSERT_STREQ("absolute.file", wf_path_get_element(path, 0));
wf_path_dispose(path);
}
TEST(wf_path, nested_path)
{
struct wf_path * path = wf_path_create("/a/nested/path");
ASSERT_EQ(3, wf_path_element_count(path));
ASSERT_STREQ("a", wf_path_get_element(path, 0));
ASSERT_STREQ("nested", wf_path_get_element(path, 1));
ASSERT_STREQ("path", wf_path_get_element(path, 2));
wf_path_dispose(path);
}
TEST(wf_path, deep_nested_path)
{
struct wf_path * path = wf_path_create("/this/is/a/very/deep/nested/path/to/some/file");
ASSERT_EQ(10, wf_path_element_count(path));
ASSERT_STREQ("this", wf_path_get_element(path, 0));
ASSERT_STREQ("is", wf_path_get_element(path, 1));
ASSERT_STREQ("a", wf_path_get_element(path, 2));
ASSERT_STREQ("very", wf_path_get_element(path, 3));
ASSERT_STREQ("deep", wf_path_get_element(path, 4));
ASSERT_STREQ("nested", wf_path_get_element(path, 5));
ASSERT_STREQ("path", wf_path_get_element(path, 6));
ASSERT_STREQ("to", wf_path_get_element(path, 7));
ASSERT_STREQ("some", wf_path_get_element(path, 8));
ASSERT_STREQ("file", wf_path_get_element(path, 9));
wf_path_dispose(path);
}

View File

@ -5,6 +5,7 @@
#include <mutex> #include <mutex>
#include <string> #include <string>
#include "webfuse/utils/msleep.hpp" #include "webfuse/utils/msleep.hpp"
#include "webfuse/utils/static_filesystem.h"
namespace webfuse_test namespace webfuse_test
{ {

View File

@ -1,61 +0,0 @@
#include <gtest/gtest.h>
#include "webfuse/provider/impl/static_filesystem.h"
#include "webfuse/provider/client_config.h"
#include "webfuse/provider/impl/client_config.h"
#include "webfuse/mocks/mock_request.hpp"
using webfuse_test::request_create;
using webfuse_test::MockRequest;
using webfuse_test::GetAttrMatcher;
using webfuse_test::ReaddirMatcher;
using testing::_;
TEST(wfp_static_filesystem, has_root_dir)
{
struct wfp_client_config * config = wfp_client_config_create();
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
MockRequest mock;
struct wfp_request * request = request_create(&mock, 42);
EXPECT_CALL(mock, respond(GetAttrMatcher(1, 0555, "dir"), 42)).Times(1);
config->provider.getattr(request, 1, config->user_data);
wfp_impl_static_filesystem_dispose(filesystem);
wfp_client_config_dispose(config);
}
TEST(wfp_static_filesystem, contains_default_dirs)
{
struct wfp_client_config * config = wfp_client_config_create();
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
MockRequest mock;
struct wfp_request * request = request_create(&mock, 23);
char const * default_dirs[] = {".", "..", nullptr};
EXPECT_CALL(mock, respond(ReaddirMatcher(default_dirs), 23)).Times(1);
config->provider.readdir(request, 1, config->user_data);
wfp_impl_static_filesystem_dispose(filesystem);
wfp_client_config_dispose(config);
}
TEST(wfp_static_filesystem, add_text)
{
struct wfp_client_config * config = wfp_client_config_create();
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
wfp_impl_static_filesystem_add_text(filesystem, "text.file", 666, "some text");
MockRequest mock;
struct wfp_request * request = request_create(&mock, 23);
char const * contained_elements[] = {"text.file", nullptr};
EXPECT_CALL(mock, respond(ReaddirMatcher(contained_elements), 23)).Times(1);
config->provider.readdir(request, 1, config->user_data);
wfp_impl_static_filesystem_dispose(filesystem);
wfp_client_config_dispose(config);
}

View File

@ -1,4 +1,4 @@
#include "webfuse/core/path.h" #include "webfuse/utils/path.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -1,9 +1,9 @@
#include "webfuse/provider/impl/static_filesystem.h" #include "webfuse/utils/static_filesystem.h"
#include "webfuse/provider/client_config.h" #include "webfuse/provider/client_config.h"
#include "webfuse/provider/dirbuffer.h" #include "webfuse/provider/dirbuffer.h"
#include "webfuse/provider/operation/error.h" #include "webfuse/provider/operation/error.h"
#include "webfuse/core/path.h" #include "webfuse/utils/path.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"
#include <sys/stat.h> #include <sys/stat.h>
@ -41,7 +41,7 @@ struct wfp_static_filesystem
}; };
static struct wfp_static_filesystem_entry * static struct wfp_static_filesystem_entry *
wfp_impl_static_filesystem_get_entry( wfp_static_filesystem_get_entry(
struct wfp_static_filesystem * filesystem, struct wfp_static_filesystem * filesystem,
size_t inode) size_t inode)
{ {
@ -56,7 +56,7 @@ wfp_impl_static_filesystem_get_entry(
} }
static struct wfp_static_filesystem_entry * static struct wfp_static_filesystem_entry *
wfp_impl_static_filesystem_get_entry_by_name( wfp_static_filesystem_get_entry_by_name(
struct wfp_static_filesystem * filesystem, struct wfp_static_filesystem * filesystem,
size_t parent, size_t parent,
char const * name) char const * name)
@ -76,7 +76,7 @@ wfp_impl_static_filesystem_get_entry_by_name(
} }
static struct wfp_static_filesystem_entry * static struct wfp_static_filesystem_entry *
wfp_impl_static_filesystem_add_entry( wfp_static_filesystem_add_entry(
struct wfp_static_filesystem * filesystem) struct wfp_static_filesystem * filesystem)
{ {
struct wfp_static_filesystem_entry * entry = NULL; struct wfp_static_filesystem_entry * entry = NULL;
@ -107,7 +107,7 @@ wfp_impl_static_filesystem_add_entry(
} }
static size_t static size_t
wfp_impl_static_filesystem_entry_read( wfp_static_filesystem_entry_read(
size_t offset, size_t offset,
char * buffer, char * buffer,
size_t buffer_size, size_t buffer_size,
@ -126,7 +126,7 @@ wfp_impl_static_filesystem_entry_read(
} }
static void static void
wfp_impl_static_filesystem_entry_get_info( wfp_static_filesystem_entry_get_info(
void * user_data, void * user_data,
int * result_mode, int * result_mode,
size_t * result_size) size_t * result_size)
@ -137,7 +137,7 @@ wfp_impl_static_filesystem_entry_get_info(
} }
static size_t static size_t
wfp_impl_static_filesystem_file_read( wfp_static_filesystem_file_read(
size_t offset, size_t offset,
char * buffer, char * buffer,
size_t buffer_size, size_t buffer_size,
@ -159,7 +159,7 @@ wfp_impl_static_filesystem_file_read(
} }
static void static void
wfp_impl_static_filesystem_file_get_info( wfp_static_filesystem_file_get_info(
void * user_data, void * user_data,
int * result_mode, int * result_mode,
size_t * result_size) size_t * result_size)
@ -176,23 +176,23 @@ wfp_impl_static_filesystem_file_get_info(
static size_t static size_t
wfp_impl_static_filesystem_add_dir( wfp_static_filesystem_add_dir(
struct wfp_static_filesystem * filesystem, struct wfp_static_filesystem * filesystem,
size_t parent, size_t parent,
char const * name char const * name
) )
{ {
struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry_by_name(filesystem, parent, name); struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name);
if (NULL == entry) if (NULL == entry)
{ {
entry = wfp_impl_static_filesystem_add_entry(filesystem); entry = wfp_static_filesystem_add_entry(filesystem);
entry->parent = parent; entry->parent = parent;
entry->is_file = false; entry->is_file = false;
entry->mode = 0555; entry->mode = 0555;
entry->name = strdup(name); entry->name = strdup(name);
entry->user_data = entry; entry->user_data = entry;
entry->read = &wfp_impl_static_filesystem_entry_read; entry->read = &wfp_static_filesystem_entry_read;
entry->get_info = &wfp_impl_static_filesystem_entry_get_info; entry->get_info = &wfp_static_filesystem_entry_get_info;
entry->size = 0; entry->size = 0;
entry->content = NULL; entry->content = NULL;
} }
@ -201,7 +201,7 @@ wfp_impl_static_filesystem_add_dir(
} }
static size_t static size_t
wfp_impl_static_filesystem_make_parent( wfp_static_filesystem_make_parent(
struct wfp_static_filesystem * filesystem, struct wfp_static_filesystem * filesystem,
struct wf_path * path) struct wf_path * path)
{ {
@ -213,7 +213,7 @@ wfp_impl_static_filesystem_make_parent(
for(size_t i = 0; i < (count - 1); i++) for(size_t i = 0; i < (count - 1); i++)
{ {
char const * name = wf_path_get_element(path, i); char const * name = wf_path_get_element(path, i);
result = wfp_impl_static_filesystem_add_dir(filesystem, result, name); result = wfp_static_filesystem_add_dir(filesystem, result, name);
} }
} }
@ -221,7 +221,7 @@ wfp_impl_static_filesystem_make_parent(
} }
static void static void
wfp_impl_static_filesystem_stat( wfp_static_filesystem_stat(
struct wfp_static_filesystem_entry * entry, struct wfp_static_filesystem_entry * entry,
struct stat * stat struct stat * stat
) )
@ -238,19 +238,19 @@ wfp_impl_static_filesystem_stat(
stat->st_mode |= (entry->is_file) ? S_IFREG: S_IFDIR; stat->st_mode |= (entry->is_file) ? S_IFREG: S_IFDIR;
} }
static void wfp_impl_static_filesystem_lookup( static void wfp_static_filesystem_lookup(
struct wfp_request * request, struct wfp_request * request,
ino_t parent, ino_t parent,
char const * name, char const * name,
void * user_data) void * user_data)
{ {
struct wfp_static_filesystem * filesystem = user_data; struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry_by_name(filesystem, parent, name); struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name);
if (NULL != entry) if (NULL != entry)
{ {
struct stat stat; struct stat stat;
wfp_impl_static_filesystem_stat(entry, &stat); wfp_static_filesystem_stat(entry, &stat);
wfp_respond_lookup(request, &stat); wfp_respond_lookup(request, &stat);
} }
else else
@ -260,18 +260,18 @@ static void wfp_impl_static_filesystem_lookup(
} }
static void wfp_impl_static_filesystem_getattr( static void wfp_static_filesystem_getattr(
struct wfp_request * request, struct wfp_request * request,
ino_t inode, ino_t inode,
void * user_data) void * user_data)
{ {
struct wfp_static_filesystem * filesystem = user_data; struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode);
if (NULL != entry) if (NULL != entry)
{ {
struct stat stat; struct stat stat;
wfp_impl_static_filesystem_stat(entry, &stat); wfp_static_filesystem_stat(entry, &stat);
wfp_respond_getattr(request, &stat); wfp_respond_getattr(request, &stat);
} }
else else
@ -280,13 +280,13 @@ static void wfp_impl_static_filesystem_getattr(
} }
} }
static void wfp_impl_static_filesystem_readdir( static void wfp_static_filesystem_readdir(
struct wfp_request * request, struct wfp_request * request,
ino_t directory, ino_t directory,
void * user_data) void * user_data)
{ {
struct wfp_static_filesystem * filesystem = user_data; struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * dir = wfp_impl_static_filesystem_get_entry(filesystem, directory); struct wfp_static_filesystem_entry * dir = wfp_static_filesystem_get_entry(filesystem, directory);
if ((NULL != dir) && (!dir->is_file)) if ((NULL != dir) && (!dir->is_file))
{ {
@ -312,14 +312,14 @@ static void wfp_impl_static_filesystem_readdir(
} }
} }
static void wfp_impl_static_filesystem_open( static void wfp_static_filesystem_open(
struct wfp_request * request, struct wfp_request * request,
ino_t inode, ino_t inode,
int flags, int flags,
void * user_data) void * user_data)
{ {
struct wfp_static_filesystem * filesystem = user_data; struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode);
if ((NULL != entry) && (entry->is_file)) if ((NULL != entry) && (entry->is_file))
{ {
@ -338,7 +338,7 @@ static void wfp_impl_static_filesystem_open(
} }
} }
static void wfp_impl_static_filesystem_read( static void wfp_static_filesystem_read(
struct wfp_request * request, struct wfp_request * request,
ino_t inode, ino_t inode,
uint32_t WF_UNUSED_PARAM(handle), uint32_t WF_UNUSED_PARAM(handle),
@ -347,7 +347,7 @@ static void wfp_impl_static_filesystem_read(
void * user_data) void * user_data)
{ {
struct wfp_static_filesystem * filesystem = user_data; struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode);
if ((NULL != entry) && (entry->is_file)) if ((NULL != entry) && (entry->is_file))
{ {
@ -365,7 +365,7 @@ static void wfp_impl_static_filesystem_read(
struct wfp_static_filesystem * struct wfp_static_filesystem *
wfp_impl_static_filesystem_create( wfp_static_filesystem_create(
struct wfp_client_config * config) struct wfp_client_config * config)
{ {
(void) config; (void) config;
@ -377,21 +377,21 @@ wfp_impl_static_filesystem_create(
filesystem->size = 0; filesystem->size = 0;
filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY; filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY;
wfp_impl_static_filesystem_add_dir(filesystem, 0, "<root>"); wfp_static_filesystem_add_dir(filesystem, 0, "<root>");
wfp_client_config_set_userdata(config, filesystem); wfp_client_config_set_userdata(config, filesystem);
wfp_client_config_set_onlookup(config, &wfp_impl_static_filesystem_lookup); wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup);
wfp_client_config_set_ongetattr(config, &wfp_impl_static_filesystem_getattr); wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr);
wfp_client_config_set_onreaddir(config, &wfp_impl_static_filesystem_readdir); wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir);
wfp_client_config_set_onopen(config, &wfp_impl_static_filesystem_open); wfp_client_config_set_onopen(config, &wfp_static_filesystem_open);
wfp_client_config_set_onread(config, &wfp_impl_static_filesystem_read); wfp_client_config_set_onread(config, &wfp_static_filesystem_read);
} }
return filesystem; return filesystem;
} }
void void
wfp_impl_static_filesystem_dispose( wfp_static_filesystem_dispose(
struct wfp_static_filesystem * filesystem) struct wfp_static_filesystem * filesystem)
{ {
for(size_t i = 0; i < filesystem->size; i++) for(size_t i = 0; i < filesystem->size; i++)
@ -406,7 +406,7 @@ wfp_impl_static_filesystem_dispose(
} }
void void
wfp_impl_static_filesystem_add( wfp_static_filesystem_add(
struct wfp_static_filesystem * filesystem, struct wfp_static_filesystem * filesystem,
char const * path, char const * path,
int mode, int mode,
@ -416,15 +416,15 @@ wfp_impl_static_filesystem_add(
struct wf_path * path_ = wf_path_create(path); struct wf_path * path_ = wf_path_create(path);
if (NULL != path_) if (NULL != path_)
{ {
size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); size_t parent = wfp_static_filesystem_make_parent(filesystem, path_);
struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem);
entry->parent = parent; entry->parent = parent;
entry->is_file = true; entry->is_file = true;
entry->name = strdup(wf_path_get_filename(path_)); entry->name = strdup(wf_path_get_filename(path_));
entry->mode = mode; entry->mode = mode;
entry->size = length; entry->size = length;
entry->get_info = &wfp_impl_static_filesystem_entry_get_info; entry->get_info = &wfp_static_filesystem_entry_get_info;
entry->read = &wfp_impl_static_filesystem_entry_read; entry->read = &wfp_static_filesystem_entry_read;
entry->user_data = entry; entry->user_data = entry;
entry->content = malloc(length); entry->content = malloc(length);
@ -435,18 +435,18 @@ wfp_impl_static_filesystem_add(
} }
void void
wfp_impl_static_filesystem_add_text( wfp_static_filesystem_add_text(
struct wfp_static_filesystem * filesystem, struct wfp_static_filesystem * filesystem,
char const * path, char const * path,
int mode, int mode,
char const * content) char const * content)
{ {
size_t length = strlen(content); size_t length = strlen(content);
wfp_impl_static_filesystem_add(filesystem, path, mode, content, length); wfp_static_filesystem_add(filesystem, path, mode, content, length);
} }
void void
wfp_impl_static_filesystem_add_file( wfp_static_filesystem_add_file(
struct wfp_static_filesystem * filesystem, struct wfp_static_filesystem * filesystem,
char const * path, char const * path,
char const * filename) char const * filename)
@ -454,16 +454,16 @@ wfp_impl_static_filesystem_add_file(
struct wf_path * path_ = wf_path_create(path); struct wf_path * path_ = wf_path_create(path);
if (NULL != path_) if (NULL != path_)
{ {
size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); size_t parent = wfp_static_filesystem_make_parent(filesystem, path_);
struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem);
entry->parent = parent; entry->parent = parent;
entry->is_file = true; entry->is_file = true;
entry->mode = 0; entry->mode = 0;
entry->content = strdup(filename); entry->content = strdup(filename);
entry->size = 0; entry->size = 0;
entry->name = strdup(wf_path_get_filename(path_)); entry->name = strdup(wf_path_get_filename(path_));
entry->get_info = &wfp_impl_static_filesystem_file_get_info; entry->get_info = &wfp_static_filesystem_file_get_info;
entry->read = &wfp_impl_static_filesystem_file_read; entry->read = &wfp_static_filesystem_file_read;
entry->user_data = entry; entry->user_data = entry;
wf_path_dispose(path_); wf_path_dispose(path_);
@ -471,7 +471,7 @@ wfp_impl_static_filesystem_add_file(
} }
void void
wfp_impl_static_filesystem_add_generic( wfp_static_filesystem_add_generic(
struct wfp_static_filesystem * filesystem, struct wfp_static_filesystem * filesystem,
char const * path, char const * path,
wfp_static_filesystem_read_fn * read, wfp_static_filesystem_read_fn * read,
@ -481,8 +481,8 @@ wfp_impl_static_filesystem_add_generic(
struct wf_path * path_ = wf_path_create(path); struct wf_path * path_ = wf_path_create(path);
if (NULL != path_) if (NULL != path_)
{ {
size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); size_t parent = wfp_static_filesystem_make_parent(filesystem, path_);
struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem);
entry->parent = parent; entry->parent = parent;
entry->is_file = true; entry->is_file = true;
entry->mode = 0; entry->mode = 0;

View File

@ -0,0 +1,77 @@
#ifndef WFP_STATIC_FILESYSTEM_H
#define WFP_STATIC_FILESYSTEM_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
using ::std::size_t;
#endif
#include <webfuse/provider/api.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_client_config;
struct wfp_static_filesystem;
typedef size_t
wfp_static_filesystem_read_fn(
size_t offset,
char * buffer,
size_t buffer_size,
void * user_data);
typedef void
wfp_static_filesystem_get_info_fn(
void * user_data,
int * result_mode,
size_t * result_size);
extern WFP_API struct wfp_static_filesystem *
wfp_static_filesystem_create(
struct wfp_client_config * config);
extern WFP_API void
wfp_static_filesystem_dispose(
struct wfp_static_filesystem * filesystem);
extern WFP_API void
wfp_static_filesystem_add(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content,
size_t length);
extern WFP_API void
wfp_static_filesystem_add_text(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content);
extern WFP_API void
wfp_static_filesystem_add_file(
struct wfp_static_filesystem * filesystem,
char const * path,
char const * filename);
extern WFP_API void
wfp_static_filesystem_add_generic(
struct wfp_static_filesystem * filesystem,
char const * path,
wfp_static_filesystem_read_fn * read,
wfp_static_filesystem_get_info_fn * get_info,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif