mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-13 12:54:15 +00:00
added API stub of static_filesystem
This commit is contained in:
parent
3a7c064af7
commit
bbc5271491
@ -152,6 +152,7 @@ add_library(webfuse-provider-static STATIC
|
||||
lib/webfuse/provider/impl/operation/open.c
|
||||
lib/webfuse/provider/impl/operation/close.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)
|
||||
@ -237,6 +238,16 @@ target_link_libraries(webfuse-provider-app PUBLIC webfuse-provider ${EXTRA_LIBS}
|
||||
target_include_directories(webfuse-provider-app PUBLIC ${EXTRA_INCLUDE_DIRS})
|
||||
target_compile_options(webfuse-provider-app PUBLIC ${EXTRA_CFLAGS})
|
||||
|
||||
# static-filesystem-provider
|
||||
|
||||
add_executable(static-filesystem-provider
|
||||
example/provider/static_filesystem.c
|
||||
)
|
||||
|
||||
target_link_libraries(static-filesystem-provider PUBLIC webfuse-provider ${EXTRA_LIBS})
|
||||
target_include_directories(static-filesystem-provider PUBLIC ${EXTRA_INCLUDE_DIRS})
|
||||
target_compile_options(static-filesystem-provider PUBLIC ${EXTRA_CFLAGS})
|
||||
|
||||
# webfuse-passwd
|
||||
|
||||
add_executable(webfuse-passwd
|
||||
|
99
example/provider/static_filesystem.c
Normal file
99
example/provider/static_filesystem.c
Normal file
@ -0,0 +1,99 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "webfuse_provider.h"
|
||||
|
||||
struct args
|
||||
{
|
||||
char const * url;
|
||||
bool show_help;
|
||||
};
|
||||
|
||||
static int
|
||||
parse_args(
|
||||
struct args * args,
|
||||
int argc,
|
||||
char * argv[])
|
||||
{
|
||||
int result = EXIT_FAILURE;
|
||||
args->show_help = true;
|
||||
args->url = NULL;
|
||||
|
||||
if (2 == argc)
|
||||
{
|
||||
result = EXIT_SUCCESS;
|
||||
|
||||
char const * url = argv[1];
|
||||
if ((0 != strcmp(url, "-h")) && (0 != strcmp(url, "--help")))
|
||||
{
|
||||
args->show_help = false;
|
||||
args->url = url;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "error: missing argument\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static struct wfp_client * client = NULL;
|
||||
|
||||
static void on_interrupt(int signal_id)
|
||||
{
|
||||
(void) signal_id;
|
||||
|
||||
wfp_client_shutdown(client);
|
||||
}
|
||||
|
||||
static void print_usage()
|
||||
{
|
||||
printf(
|
||||
"static-filesystem-provider Copyright (c) 2019, webfuse authors <https://github.com/falk-werner/webfuse>\n"
|
||||
"Example of webfuse static filesystem provider\n"
|
||||
"\n"
|
||||
"Usage: static-filesystem-provider <url>\n"
|
||||
"\n"
|
||||
"Arguments:\n"
|
||||
"\t<url> URL of webfuse server (required)\n"
|
||||
"\t-h, --help prints this message\n"
|
||||
"\n"
|
||||
"Example:\n"
|
||||
"\tstatic-filesystem-provider ws://localhost:8080/\n"
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
signal(SIGINT, &on_interrupt);
|
||||
|
||||
struct args args;
|
||||
int result = parse_args(&args, argc, argv);
|
||||
if (EXIT_SUCCESS == result)
|
||||
{
|
||||
struct wfp_client_config * config = wfp_client_config_create();
|
||||
|
||||
struct wfp_static_filesystem * fs = wfp_static_filesystem_create(config);
|
||||
wfp_static_filesystem_add_text(fs, "hello.txt", 0444, "Hello, World!");
|
||||
|
||||
client = wfp_client_create(config);
|
||||
wfp_client_connect(client, args.url);
|
||||
wfp_client_run(client);
|
||||
|
||||
wfp_client_dispose(client);
|
||||
wfp_static_filesystem_dispose(fs);
|
||||
wfp_client_config_dispose(config);
|
||||
}
|
||||
|
||||
if (args.show_help)
|
||||
{
|
||||
print_usage();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
76
include/webfuse/provider/static_filesystem.h
Normal file
76
include/webfuse/provider/static_filesystem.h
Normal file
@ -0,0 +1,76 @@
|
||||
#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
|
@ -17,4 +17,6 @@
|
||||
#include <webfuse/provider/operation/close.h>
|
||||
#include <webfuse/provider/operation/read.h>
|
||||
|
||||
#include <webfuse/provider/static_filesystem.h>
|
||||
|
||||
#endif
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "webfuse/provider/impl/client_config.h"
|
||||
#include "webfuse/provider/impl/client.h"
|
||||
#include "webfuse/provider/impl/dirbuffer.h"
|
||||
#include "webfuse/provider/impl/static_filesystem.h"
|
||||
|
||||
// respond
|
||||
|
||||
@ -238,3 +239,59 @@ void wfp_dirbuffer_add(
|
||||
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);
|
||||
}
|
||||
|
91
lib/webfuse/provider/impl/static_filesystem.c
Normal file
91
lib/webfuse/provider/impl/static_filesystem.c
Normal file
@ -0,0 +1,91 @@
|
||||
#include "webfuse/provider/impl/static_filesystem.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct wfp_static_filesystem
|
||||
{
|
||||
int dummy;
|
||||
};
|
||||
|
||||
struct wfp_static_filesystem *
|
||||
wfp_impl_static_filesystem_create(
|
||||
struct wfp_client_config * config)
|
||||
{
|
||||
(void) config;
|
||||
|
||||
struct wfp_static_filesystem * filesystem = malloc(sizeof(struct wfp_static_filesystem));
|
||||
if (NULL != filesystem)
|
||||
{
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
return filesystem;
|
||||
}
|
||||
|
||||
void
|
||||
wfp_impl_static_filesystem_dispose(
|
||||
struct wfp_static_filesystem * filesystem)
|
||||
{
|
||||
free(filesystem);
|
||||
}
|
||||
|
||||
void
|
||||
wfp_impl_static_filesystem_add(
|
||||
struct wfp_static_filesystem * filesystem,
|
||||
char const * path,
|
||||
int mode,
|
||||
char const * content,
|
||||
size_t length)
|
||||
{
|
||||
(void) filesystem;
|
||||
(void) path;
|
||||
(void) mode;
|
||||
(void) content;
|
||||
(void) length;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void
|
||||
wfp_impl_static_filesystem_add_text(
|
||||
struct wfp_static_filesystem * filesystem,
|
||||
char const * path,
|
||||
int mode,
|
||||
char const * content)
|
||||
{
|
||||
(void) filesystem;
|
||||
(void) path;
|
||||
(void) mode;
|
||||
(void) content;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void
|
||||
wfp_impl_static_filesystem_add_file(
|
||||
struct wfp_static_filesystem * filesystem,
|
||||
char const * path,
|
||||
char const * filename)
|
||||
{
|
||||
(void) filesystem;
|
||||
(void) path;
|
||||
(void) filename;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
(void) filesystem;
|
||||
(void) path;
|
||||
(void) read;
|
||||
(void) get_info;
|
||||
(void) user_data;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
52
lib/webfuse/provider/impl/static_filesystem.h
Normal file
52
lib/webfuse/provider/impl/static_filesystem.h
Normal file
@ -0,0 +1,52 @@
|
||||
#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
|
Loading…
Reference in New Issue
Block a user