diff --git a/CMakeLists.txt b/CMakeLists.txt index 774eca6..f3ab04e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/example/provider/static_filesystem.c b/example/provider/static_filesystem.c new file mode 100644 index 0000000..03801f8 --- /dev/null +++ b/example/provider/static_filesystem.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include + +#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 \n" + "Example of webfuse static filesystem provider\n" + "\n" + "Usage: static-filesystem-provider \n" + "\n" + "Arguments:\n" + "\t 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; +} diff --git a/include/webfuse/provider/static_filesystem.h b/include/webfuse/provider/static_filesystem.h new file mode 100644 index 0000000..b2bdbfc --- /dev/null +++ b/include/webfuse/provider/static_filesystem.h @@ -0,0 +1,76 @@ +#ifndef WFP_STATIC_FILESYSTEM_H +#define WFP_STATIC_FILESYSTEM_H + +#ifndef __cplusplus +#include +#else +#include +using ::std::size_t; +#endif + +#include + +#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 diff --git a/include/webfuse_provider.h b/include/webfuse_provider.h index 26398ff..e37fd68 100644 --- a/include/webfuse_provider.h +++ b/include/webfuse_provider.h @@ -17,4 +17,6 @@ #include #include +#include + #endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 1384d20..0d9a96b 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -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); +} diff --git a/lib/webfuse/provider/impl/static_filesystem.c b/lib/webfuse/provider/impl/static_filesystem.c new file mode 100644 index 0000000..9639c2a --- /dev/null +++ b/lib/webfuse/provider/impl/static_filesystem.c @@ -0,0 +1,91 @@ +#include "webfuse/provider/impl/static_filesystem.h" +#include + +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 +} diff --git a/lib/webfuse/provider/impl/static_filesystem.h b/lib/webfuse/provider/impl/static_filesystem.h new file mode 100644 index 0000000..a18835d --- /dev/null +++ b/lib/webfuse/provider/impl/static_filesystem.h @@ -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