diff --git a/AUTHORS b/AUTHORS index 01e215c..2cf3f05 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,4 +1,4 @@ -# This is the list of fuse-wsfs authors for copyright purposes. +# This is the list of webfuse authors for copyright purposes. # # This does not necessarily list everyone who has contributed code, since in # some cases, their employer may be the copyright holder. To see the full list diff --git a/CMakeLists.txt b/CMakeLists.txt index 96b0ef2..08cc332 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 3.10) -project(fuse-wsfs VERSION 0.1.0 DESCRIPTION "Websocket filesystem based on libfuse") +project(webfuse VERSION 0.1.0 DESCRIPTION "Websocket filesystem based on libfuse") option(WITHOUT_TESTS "disable unit tests" OFF) option(WITHOUT_EXAMPLE "disable example" OFF) @@ -45,142 +45,142 @@ set(EXTRA_CFLAGS ) -# libwsfs-core +# libwebfuse-core -add_library(wsfs-core STATIC - lib/wsfs/core/message.c - lib/wsfs/core/message_queue.c - lib/wsfs/core/status.c +add_library(webfuse-core STATIC + lib/webfuse/core/message.c + lib/webfuse/core/message_queue.c + lib/webfuse/core/status.c ) -set_target_properties(wsfs-core PROPERTIES OUTPUT_NAME wsfs-core) -target_include_directories(wsfs-core PUBLIC lib ${EXTRA_INCLUDE_DIRS}) -target_compile_options(wsfs-core PUBLIC ${EXTRA_CFLAGS}) -set_target_properties(wsfs-core PROPERTIES C_VISIBILITY_PRESET hidden) - -install(DIRECTORY include/wsfs/core DESTINATION include/wsfs) - - -# libwsfs-adapter - -add_library(wsfs-adapter-static STATIC - lib/wsfs/adapter/api.c - lib/wsfs/adapter/impl/filesystem.c - lib/wsfs/adapter/impl/server.c - lib/wsfs/adapter/impl/server_config.c - lib/wsfs/adapter/impl/server_protocol.c - lib/wsfs/adapter/impl/session.c - lib/wsfs/adapter/impl/session_manager.c - lib/wsfs/adapter/impl/authenticator.c - lib/wsfs/adapter/impl/authenticators.c - lib/wsfs/adapter/impl/credentials.c - lib/wsfs/adapter/impl/time/timepoint.c - lib/wsfs/adapter/impl/time/timer.c - lib/wsfs/adapter/impl/time/timeout_manager.c - lib/wsfs/adapter/impl/operation/lookup.c - lib/wsfs/adapter/impl/operation/getattr.c - lib/wsfs/adapter/impl/operation/readdir.c - lib/wsfs/adapter/impl/operation/open.c - lib/wsfs/adapter/impl/operation/close.c - lib/wsfs/adapter/impl/operation/read.c - lib/wsfs/adapter/impl/jsonrpc/server.c - lib/wsfs/adapter/impl/jsonrpc/method.c - lib/wsfs/adapter/impl/jsonrpc/request.c - lib/wsfs/adapter/impl/jsonrpc/response.c - lib/wsfs/adapter/impl/jsonrpc/util.c +set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) +target_include_directories(webfuse-core PUBLIC lib ${EXTRA_INCLUDE_DIRS}) +target_compile_options(webfuse-core PUBLIC ${EXTRA_CFLAGS}) +set_target_properties(webfuse-core PROPERTIES C_VISIBILITY_PRESET hidden) + +install(DIRECTORY include/webfuse/core DESTINATION include/webfuse) + + +# libwebfuse-adapter + +add_library(webfuse-adapter-static STATIC + lib/webfuse/adapter/api.c + lib/webfuse/adapter/impl/filesystem.c + lib/webfuse/adapter/impl/server.c + lib/webfuse/adapter/impl/server_config.c + lib/webfuse/adapter/impl/server_protocol.c + lib/webfuse/adapter/impl/session.c + lib/webfuse/adapter/impl/session_manager.c + lib/webfuse/adapter/impl/authenticator.c + lib/webfuse/adapter/impl/authenticators.c + lib/webfuse/adapter/impl/credentials.c + lib/webfuse/adapter/impl/time/timepoint.c + lib/webfuse/adapter/impl/time/timer.c + lib/webfuse/adapter/impl/time/timeout_manager.c + lib/webfuse/adapter/impl/operation/lookup.c + lib/webfuse/adapter/impl/operation/getattr.c + lib/webfuse/adapter/impl/operation/readdir.c + lib/webfuse/adapter/impl/operation/open.c + lib/webfuse/adapter/impl/operation/close.c + lib/webfuse/adapter/impl/operation/read.c + lib/webfuse/adapter/impl/jsonrpc/server.c + lib/webfuse/adapter/impl/jsonrpc/method.c + lib/webfuse/adapter/impl/jsonrpc/request.c + lib/webfuse/adapter/impl/jsonrpc/response.c + lib/webfuse/adapter/impl/jsonrpc/util.c ) -set_target_properties(wsfs-adapter-static PROPERTIES OUTPUT_NAME wsfs-adapter) -target_include_directories(wsfs-adapter-static PUBLIC lib ${EXTRA_INCLUDE_DIRS}) -target_compile_options(wsfs-adapter-static PUBLIC ${EXTRA_CFLAGS}) -set_target_properties(wsfs-adapter-static PROPERTIES C_VISIBILITY_PRESET hidden) +set_target_properties(webfuse-adapter-static PROPERTIES OUTPUT_NAME webfuse-adapter) +target_include_directories(webfuse-adapter-static PUBLIC lib ${EXTRA_INCLUDE_DIRS}) +target_compile_options(webfuse-adapter-static PUBLIC ${EXTRA_CFLAGS}) +set_target_properties(webfuse-adapter-static PROPERTIES C_VISIBILITY_PRESET hidden) -add_library(wsfs-adapter SHARED - lib/wsfs/adapter/api.c +add_library(webfuse-adapter SHARED + lib/webfuse/adapter/api.c ) -set_target_properties(wsfs-adapter PROPERTIES VERSION ${PROJECT_VERSION}) -set_target_properties(wsfs-adapter PROPERTIES SOVERSION 0) -set_target_properties(wsfs-adapter PROPERTIES C_VISIBILITY_PRESET hidden) -set_target_properties(wsfs-adapter PROPERTIES COMPILE_DEFINITIONS "WSFSA_API=WSFSA_EXPORT") +set_target_properties(webfuse-adapter PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(webfuse-adapter PROPERTIES SOVERSION 0) +set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden) +set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT") -target_include_directories(wsfs-adapter PUBLIC lib ${EXTRA_INCLUDE_DIRS}) -target_compile_options(wsfs-adapter PUBLIC ${EXTRA_CFLAGS}) -target_link_libraries(wsfs-adapter PRIVATE wsfs-adapter-static wsfs-core) +target_include_directories(webfuse-adapter PUBLIC lib ${EXTRA_INCLUDE_DIRS}) +target_compile_options(webfuse-adapter PUBLIC ${EXTRA_CFLAGS}) +target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core) -file(WRITE "${PROJECT_BINARY_DIR}/libwsfs-adapter.pc" +file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" exec_prefix=\${prefix} libdir=\${exec_prefix}/lib${LIB_SUFFIX} includedir=\${prefix}/include -Name: libwsfs +Name: libwebfuse Description: Websockets filesystem server library Version: ${PROJECT_VERSION} -Libs: -L\${libdir} -lwsfs-adapter -l${FUSE3_LIBRARIES} -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} +Libs: -L\${libdir} -lwebfuse-adapter -l${FUSE3_LIBRARIES} -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} Cflags: -I\${includedir}" ) -install(TARGETS wsfs-adapter DESTINATION lib${LIB_SUFFIX}) -install(FILES include/wsfs_adapter.h DESTINATION include) -install(DIRECTORY include/wsfs/adapter DESTINATION include/wsfs) -install(FILES "${PROJECT_BINARY_DIR}/libwsfs-adapter.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) - -#libwsfs-provider - -add_library(wsfs-provider-static STATIC - lib/wsfs/provider/api.c - lib/wsfs/provider/impl/url.c - lib/wsfs/provider/impl/client.c - lib/wsfs/provider/impl/client_config.c - lib/wsfs/provider/impl/client_protocol.c - lib/wsfs/provider/impl/provider.c - lib/wsfs/provider/impl/request.c - lib/wsfs/provider/impl/dirbuffer.c - lib/wsfs/provider/impl/operation/lookup.c - lib/wsfs/provider/impl/operation/getattr.c - lib/wsfs/provider/impl/operation/readdir.c - lib/wsfs/provider/impl/operation/open.c - lib/wsfs/provider/impl/operation/close.c - lib/wsfs/provider/impl/operation/read.c +install(TARGETS webfuse-adapter DESTINATION lib${LIB_SUFFIX}) +install(FILES include/webfuse_adapter.h DESTINATION include) +install(DIRECTORY include/webfuse/adapter DESTINATION include/webfuse) +install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) + +#libwebfuse-provider + +add_library(webfuse-provider-static STATIC + lib/webfuse/provider/api.c + lib/webfuse/provider/impl/url.c + lib/webfuse/provider/impl/client.c + lib/webfuse/provider/impl/client_config.c + lib/webfuse/provider/impl/client_protocol.c + lib/webfuse/provider/impl/provider.c + lib/webfuse/provider/impl/request.c + lib/webfuse/provider/impl/dirbuffer.c + lib/webfuse/provider/impl/operation/lookup.c + lib/webfuse/provider/impl/operation/getattr.c + lib/webfuse/provider/impl/operation/readdir.c + lib/webfuse/provider/impl/operation/open.c + lib/webfuse/provider/impl/operation/close.c + lib/webfuse/provider/impl/operation/read.c ) -set_target_properties(wsfs-provider-static PROPERTIES OUTPUT_NAME wsfs-provider) -target_include_directories(wsfs-provider-static PUBLIC lib ${EXTRA_INCLUDE_DIRS}) -target_compile_options(wsfs-provider-static PUBLIC ${EXTRA_CFLAGS}) -set_target_properties(wsfs-provider-static PROPERTIES C_VISIBILITY_PRESET hidden) +set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider) +target_include_directories(webfuse-provider-static PUBLIC lib ${EXTRA_INCLUDE_DIRS}) +target_compile_options(webfuse-provider-static PUBLIC ${EXTRA_CFLAGS}) +set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden) -add_library(wsfs-provider SHARED - lib/wsfs/provider/api.c +add_library(webfuse-provider SHARED + lib/webfuse/provider/api.c ) -set_target_properties(wsfs-provider PROPERTIES VERSION ${PROJECT_VERSION}) -set_target_properties(wsfs-provider PROPERTIES SOVERSION 0) -set_target_properties(wsfs-provider PROPERTIES C_VISIBILITY_PRESET hidden) -set_target_properties(wsfs-provider PROPERTIES COMPILE_DEFINITIONS "WSFSP_API=WSFSP_EXPORT") +set_target_properties(webfuse-provider PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(webfuse-provider PROPERTIES SOVERSION 0) +set_target_properties(webfuse-provider PROPERTIES C_VISIBILITY_PRESET hidden) +set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT") -target_include_directories(wsfs-provider PUBLIC lib ${EXTRA_INCLUDE_DIRS}) -target_compile_options(wsfs-provider PUBLIC ${EXTRA_CFLAGS}) -target_link_libraries(wsfs-provider PRIVATE wsfs-provider-static wsfs-core) +target_include_directories(webfuse-provider PUBLIC lib ${EXTRA_INCLUDE_DIRS}) +target_compile_options(webfuse-provider PUBLIC ${EXTRA_CFLAGS}) +target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core) -file(WRITE "${PROJECT_BINARY_DIR}/libwsfs-provider.pc" +file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" exec_prefix=\${prefix} libdir=\${exec_prefix}/lib${LIB_SUFFIX} includedir=\${prefix}/include -Name: libwsfs-provider +Name: libwebfuse-provider Description: Provider library for websockets filesystem Version: ${PROJECT_VERSION} -Libs: -L\${libdir} -lwsfs-provider -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} +Libs: -L\${libdir} -lwebfuse-provider -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} Cflags: -I\${includedir}" ) -install(TARGETS wsfs-provider DESTINATION lib${LIB_SUFFIX}) -install(FILES include/wsfs_provider.h DESTINATION include) -install(DIRECTORY include/wsfs/provider DESTINATION include/wsfs) -install(FILES "${PROJECT_BINARY_DIR}/libwsfs-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) +install(TARGETS webfuse-provider DESTINATION lib${LIB_SUFFIX}) +install(FILES include/webfuse_provider.h DESTINATION include) +install(DIRECTORY include/webfuse/provider DESTINATION include/webfuse) +install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) # examples @@ -207,49 +207,49 @@ target_compile_options(userdb PUBLIC # daemon -add_executable(wsfsd +add_executable(webfused example/daemon/main.c ) -target_link_libraries(wsfsd PUBLIC wsfs-adapter ${EXTRA_LIBS}) -target_include_directories(wsfsd PUBLIC ${EXTRA_INCLUDE_DIRS}) -target_compile_options(wsfsd PUBLIC ${EXTRA_CFLAGS}) +target_link_libraries(webfused PUBLIC webfuse-adapter ${EXTRA_LIBS}) +target_include_directories(webfused PUBLIC ${EXTRA_INCLUDE_DIRS}) +target_compile_options(webfused PUBLIC ${EXTRA_CFLAGS}) # provider -add_executable(wsfs-provider-app +add_executable(webfuse-provider-app example/provider/main.c ) -set_target_properties(wsfs-provider-app PROPERTIES OUTPUT_NAME wsfs-provider) +set_target_properties(webfuse-provider-app PROPERTIES OUTPUT_NAME webfuse-provider) -target_link_libraries(wsfs-provider-app PUBLIC wsfs-provider ${EXTRA_LIBS}) -target_include_directories(wsfs-provider-app PUBLIC ${EXTRA_INCLUDE_DIRS}) -target_compile_options(wsfs-provider-app PUBLIC ${EXTRA_CFLAGS}) +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}) -# wsfs-passwd +# webfuse-passwd pkg_check_modules(OPENSSL REQUIRED openssl) -add_executable(wsfs-passwd +add_executable(webfuse-passwd example/passwd/main.c ) -target_link_libraries(wsfs-passwd PUBLIC +target_link_libraries(webfuse-passwd PUBLIC userdb ${OPENSSL_LIBRARIES} ${JANSSON_LIBRARIES} ) -target_include_directories(wsfs-passwd PUBLIC +target_include_directories(webfuse-passwd PUBLIC example/passwd example/lib/userdb/include ${OPENSSL_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS} ) -target_compile_options(wsfs-passwd PUBLIC +target_compile_options(webfuse-passwd PUBLIC ${C_WARNINGS} ${OPENSSL_CFLAGS_OTHER} ${JANSSON_CFLAGS_OTHER} @@ -281,7 +281,7 @@ add_executable(alltests test/test_authenticators.cc ) -target_link_libraries(alltests PUBLIC wsfs-adapter-static wsfs-provider-static wsfs-core ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES}) +target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES}) target_include_directories(alltests PUBLIC lib ${EXTRA_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) target_compile_options(alltests PUBLIC ${EXTRA_CFLAGS} ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) diff --git a/Makefile b/Makefile index 3afe7b9..c1a6f2c 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ export BUILDTIME ?= $(shell date -u -d '@$(SOURCE_DATE_EPOCH)' --rfc-3339 ns 2>/ VERBOSE ?= MARCH ?= -PROJECT_NAME ?= webfs +PROJECT_NAME ?= webfuse PROJECT_ROOT ?= . VERSION ?= $(shell cat $(PROJECT_ROOT)/VERSION) OUT ?= $(PROJECT_ROOT)/.build diff --git a/README.md b/README.md index 4badc14..b5e8dde 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -[![Build Status](https://travis-ci.org/falk-werner/fuse-wsfs.svg?branch=master)](https://travis-ci.org/falk-werner/fuse-wsfs) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d6c20d37bb3a456a9c0ee224001081b2)](https://www.codacy.com/app/falk.werner/fuse-wsfs?utm_source=github.com&utm_medium=referral&utm_content=falk-werner/fuse-wsfs&utm_campaign=Badge_Grade) +[![Build Status](https://travis-ci.org/falk-werner/webfuse.svg?branch=master)](https://travis-ci.org/falk-werner/webfuse) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d6c20d37bb3a456a9c0ee224001081b2)](https://www.codacy.com/app/falk.werner/webfuse?utm_source=github.com&utm_medium=referral&utm_content=falk-werner/webfuse&utm_campaign=Badge_Grade) -# fuse-wsfs +# webfuse -fuse-wsfs combines libwebsockets and libfuse. It allows ot attach a remote filesystem via websockets. +webfuse combines libwebsockets and libfuse. It allows ot attach a remote filesystem via websockets. ## Contents @@ -29,13 +29,13 @@ However at least one (unecessary) copy of the upload file is needed on the devic To avoid Steps 1 and 2, it would be great to keep the update file entirely in web server, just like [NFS](https://en.wikipedia.org/wiki/Network_File_System) or [WebDAV](https://wiki.archlinux.org/index.php/WebDAV). Unfortunately, NFS is not based on any protocol, natively usable by a web application. WebDAV is based on HTTP, but it needs a server providing the update file. -fuse-wsfs solves this problem by using the [WebSocket](https://en.wikipedia.org/wiki/WebSocket) protocol. The emdedded device runs a service, known as WSFS adapter, awaiting incoming connections, e.g. from a web browser. The browser acts as a file system provider, providing the update file to the device. +webfuse solves this problem by using the [WebSocket](https://en.wikipedia.org/wiki/WebSocket) protocol. The emdedded device runs a service, known as webfuse adapter, awaiting incoming connections, e.g. from a web browser. The browser acts as a file system provider, providing the update file to the device. ## Concecpt +---------------------+ +-------------+ +------+ - | Filesystem Provider | | wsfs daemon | | user | - | (e.g. Webbrowser) | | | | | + | Filesystem Provider | | webfuse | | user | + | (e.g. Webbrowser) | | daemon | | | +----------+----------+ +------+------+ +---+--+ | | | | +-+-+ | @@ -62,18 +62,18 @@ fuse-wsfs solves this problem by using the [WebSocket](https://en.wikipedia.org/ | +-+-+ +-+-+ | | | -With fuse-wsfs it is possible to implement remote filesystems based on websockets. +With webfuse it is possible to implement remote filesystems based on websockets. A reference implementation of such a daemon is provided within the examples. The picture above describes the workflow: -- The websocket filesystem daemon (*wsfs daemon*) mounts a filesystem on startup. +- The websocket filesystem daemon (*webfuse daemon*) mounts a filesystem on startup. It starts the websocket server and waits for incoming connections. -- A remote filesystem provider connects to wsfs daemon via websocket protocol. +- A remote filesystem provider connects to webfuse daemon via websocket protocol. The example includes such a provider implemented in HTML and JavaScript. -- Whenever the user makes filesystem requests, such as *ls*, the request is redirected via wsfs daemon to the connected filesystem provider +- Whenever the user makes filesystem requests, such as *ls*, the request is redirected via webfuse daemon to the connected filesystem provider -Currently all requests are initiated by wsfs daemon and responded by filesystem provider. This may change in future, e.g. when authentication is supported. +Currently all requests are initiated by webfuse daemon and responded by filesystem provider. This may change in future, e.g. when authentication is supported. ## Similar Projects @@ -81,13 +81,13 @@ Currently all requests are initiated by wsfs daemon and responded by filesystem [davfs2](http://savannah.nongnu.org/projects/davfs2) is a Linux file system driver that allows to mount a [WebDAV](https://wiki.archlinux.org/index.php/WebDAV) resource. WebDAV is an extension to HTTP/1.1 that allows remote collaborative authoring of Web resources. -Unlike fuse-wsfs, davfs2 mounts a remote filesystem locally, that is provided by a WebDAV server. In contrast, fuse-wsfs starts a server awaiting client connections to attach the remote file system. +Unlike webfuse, davfs2 mounts a remote filesystem locally, that is provided by a WebDAV server. In contrast, webfuse starts a server awaiting client connections to attach the remote file system. ## API ### Requests, responses and notifications -There are three types of messages, used for communication between wsfs daemon and filesystem provider. All message types are encoded in [JSON](https://www.json.org/) and strongly inspired by [JSON-RPC](https://www.jsonrpc.org/). +There are three types of messages, used for communication between webfuse daemon and filesystem provider. All message types are encoded in [JSON](https://www.json.org/) and strongly inspired by [JSON-RPC](https://www.jsonrpc.org/). #### Request @@ -168,7 +168,7 @@ Notfications are used to inform a receiver about something. Unlike requests, not Retrieve information about a filesystem entry by name. - wsfs daemon: {"method": "lookup", "params": [, ], "id": } + webfuse daemon: {"method": "lookup", "params": [, ], "id": } fs provider: {"result": { "inode": , "mode" : , @@ -195,7 +195,7 @@ Retrieve information about a filesystem entry by name. Get file attributes. - wsfs daemon: {"method": "getattr", "params": [], "id": } + webfuse daemon: {"method": "getattr", "params": [], "id": } fs provider: {"result": { "mode" : , "type" : , @@ -221,7 +221,7 @@ Read directory contents. Result is an array of name-inode pairs for each entry. The generic entries "." and ".." should also be provided. - wsfs daemon: {"method": "readdir", "params": [], "id": } + webfuse daemon: {"method": "readdir", "params": [], "id": } fs provider: {"result": [ {"name": , "inode": }, ... @@ -237,7 +237,7 @@ Result is an array of name-inode pairs for each entry. The generic entries Open a file. - wsfs daemon: {"method": "readdir", "params": [, ], "id": } + webfuse daemon: {"method": "readdir", "params": [, ], "id": } fs provider: {"result": {"handle": }, "id": } | Item | Data type | Description | @@ -264,7 +264,7 @@ Open a file. Informs filesystem provider, that a file is closed. Since `close` is a notification, it cannot fail. - wsfs daemon: {"method": "close", "params": [, , ], "id": } + webfuse daemon: {"method": "close", "params": [, , ], "id": } | Item | Data type | Description | | ----------- | ----------| ---------------------------- | @@ -276,7 +276,7 @@ Since `close` is a notification, it cannot fail. Read from an open file. - wsfs daemon: {"method": "close", "params": [, , , ], "id": } + webfuse daemon: {"method": "close", "params": [, , , ], "id": } fs provider: {"result": { "data": , "format": , @@ -304,12 +304,12 @@ Read from an open file. To install dependencies, see below. - cd fuse-wsfs + cd webfuse mkdir .build cd .build cmake .. mkdir test - ./wsfsd -m test --document_root=../exmaple/daemon/www --port=4711 + ./webfused -m test --document_root=../exmaple/daemon/www --port=4711 ### Build options @@ -364,7 +364,7 @@ By default, unit tests and example application are enabled. You can disable them #### GoogleTest -Installation of GoogleTest is optional fuse-wsfs library, but required to compile tests. +Installation of GoogleTest is optional webfuse library, but required to compile tests. wget -O gtest-1.8.1.tar.gz https://github.com/google/googletest/archive/release-1.8.1.tar.gz tar -xf gtest-1.8.1.tar.gz diff --git a/example/daemon/main.c b/example/daemon/main.c index 0614970..f9b4798 100644 --- a/example/daemon/main.c +++ b/example/daemon/main.c @@ -9,25 +9,25 @@ #include #include -#include +#include struct args { - struct wsfs_server_config * config; + struct wf_server_config * config; char * passwd_path; bool show_help; }; -static struct wsfs_server * server; +static struct wf_server * server; static void show_help(void) { printf( - "wsfsd, Copyright (c) 2019, Falk Werner\n" + "webfused, Copyright (c) 2019, webfuse authors \n" "Websocket file system daemon\n" "\n" - "Usage: wsfsd [m ] [-d ] [-p ]\n" + "Usage: webfused [m ] [-d ] [-p ]\n" " [-c ] [-k ] [-P ]\n" "\n" "Options:\n" @@ -41,13 +41,13 @@ static void show_help(void) "\n"); } -static bool authenticate(struct wsfs_credentials * creds, void * user_data) +static bool authenticate(struct wf_credentials * creds, void * user_data) { bool result = false; struct args * args = user_data; - char const * username = wsfs_credentials_get(creds, "username"); - char const * password = wsfs_credentials_get(creds, "password"); + char const * username = wf_credentials_get(creds, "username"); + char const * password = wf_credentials_get(creds, "password"); if ((NULL != username) && (NULL != password)) { json_t * passwd = json_load_file(args->passwd_path, 0, NULL); @@ -103,28 +103,28 @@ static int parse_arguments(int argc, char * argv[], struct args * args) finished = true; break; case 'm': - wsfs_server_config_set_mountpoint(args->config, optarg); + wf_server_config_set_mountpoint(args->config, optarg); has_mountpoint = true; break; case 'd': - wsfs_server_config_set_documentroot(args->config, optarg); + wf_server_config_set_documentroot(args->config, optarg); break; case 'c': - wsfs_server_config_set_certpath(args->config, optarg); + wf_server_config_set_certpath(args->config, optarg); break; case 'k': - wsfs_server_config_set_keypath(args->config, optarg); + wf_server_config_set_keypath(args->config, optarg); break; case 'n': - wsfs_server_config_set_vhostname(args->config, optarg); + wf_server_config_set_vhostname(args->config, optarg); break; case 'p': - wsfs_server_config_set_port(args->config, atoi(optarg)); + wf_server_config_set_port(args->config, atoi(optarg)); break; case 'P': free(args->passwd_path); args->passwd_path = strdup(optarg); - wsfs_server_config_add_authenticator(args->config, + wf_server_config_add_authenticator(args->config, "username", &authenticate, args); @@ -157,15 +157,15 @@ static void on_interrupt(int signal_id) { (void) signal_id; - wsfs_server_shutdown(server); + wf_server_shutdown(server); } int main(int argc, char * argv[]) { struct args args; - args.config = wsfs_server_config_create(); - wsfs_server_config_set_vhostname(args.config, "localhost"); - wsfs_server_config_set_port(args.config, 8080); + args.config = wf_server_config_create(); + wf_server_config_set_vhostname(args.config, "localhost"); + wf_server_config_set_port(args.config, 8080); args.passwd_path = NULL; args.show_help = false; @@ -174,11 +174,11 @@ int main(int argc, char * argv[]) if (!args.show_help) { signal(SIGINT, on_interrupt); - server = wsfs_server_create(args.config); + server = wf_server_create(args.config); if (NULL != server) { - wsfs_server_run(server); - wsfs_server_dispose(server); + wf_server_run(server); + wf_server_dispose(server); } else { @@ -192,7 +192,7 @@ int main(int argc, char * argv[]) } free(args.passwd_path); - wsfs_server_config_dispose(args.config); + wf_server_config_dispose(args.config); return result; } diff --git a/example/daemon/www/js/filesystem_provider.js b/example/daemon/www/js/filesystem_provider.js index c2f9fbe..85ad287 100644 --- a/example/daemon/www/js/filesystem_provider.js +++ b/example/daemon/www/js/filesystem_provider.js @@ -1,8 +1,8 @@ /* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */ -import { BadState } from "./wsfs/bad_state.js"; -import { FileMode } from "./wsfs/file_mode.js"; -import { Provider } from "./wsfs/provider.js"; +import { BadState } from "./webfuse/bad_state.js"; +import { FileMode } from "./webfuse/file_mode.js"; +import { Provider } from "./webfuse/provider.js"; export class FileSystemProvider extends Provider { constructor(root) { diff --git a/example/daemon/www/js/package.json b/example/daemon/www/js/package.json index 276764e..6c7a7cd 100644 --- a/example/daemon/www/js/package.json +++ b/example/daemon/www/js/package.json @@ -1,7 +1,7 @@ { - "name": "wsfs-provider", + "name": "webfuse-provider", "version": "0.1.0", - "description": "Provider for websocket filesystem (wsfs)", + "description": "Provider for websocket filesystem (webfuse)", "main": "startup.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/example/daemon/www/js/startup.js b/example/daemon/www/js/startup.js index fa164f0..cdc0796 100644 --- a/example/daemon/www/js/startup.js +++ b/example/daemon/www/js/startup.js @@ -1,4 +1,4 @@ -import { Client } from "./wsfs/client.js"; +import { Client } from "./webfuse/client.js"; import { ConnectionView } from "./connection_view.js"; import { FileSystemProvider } from "./filesystem_provider.js"; diff --git a/example/daemon/www/js/wsfs/bad_state.js b/example/daemon/www/js/webfuse/bad_state.js similarity index 100% rename from example/daemon/www/js/wsfs/bad_state.js rename to example/daemon/www/js/webfuse/bad_state.js diff --git a/example/daemon/www/js/wsfs/client.js b/example/daemon/www/js/webfuse/client.js similarity index 100% rename from example/daemon/www/js/wsfs/client.js rename to example/daemon/www/js/webfuse/client.js diff --git a/example/daemon/www/js/wsfs/file_mode.js b/example/daemon/www/js/webfuse/file_mode.js similarity index 100% rename from example/daemon/www/js/wsfs/file_mode.js rename to example/daemon/www/js/webfuse/file_mode.js diff --git a/example/daemon/www/js/wsfs/provider.js b/example/daemon/www/js/webfuse/provider.js similarity index 100% rename from example/daemon/www/js/wsfs/provider.js rename to example/daemon/www/js/webfuse/provider.js diff --git a/example/lib/userdb/src/userdb.c b/example/lib/userdb/src/userdb.c index f25c42b..172742a 100644 --- a/example/lib/userdb/src/userdb.c +++ b/example/lib/userdb/src/userdb.c @@ -33,7 +33,7 @@ static bool is_compatible(json_t * meta) result = ( json_is_string(type) && - (0 == strcmp(json_string_value(type), "wsfs-userdb")) && + (0 == strcmp(json_string_value(type), "wf-userdb")) && json_is_integer(major) && (USERDB_MAJOR == json_integer_value(major)) && json_is_integer(minor) && @@ -170,7 +170,7 @@ bool userdb_save( json_t * container = json_object(); json_t * meta = json_object(); - json_object_set_new(meta, "type", json_string("wsfs-userdb")); + json_object_set_new(meta, "type", json_string("wf-userdb")); json_object_set_new(meta, "major", json_integer(USERDB_MAJOR)); json_object_set_new(meta, "minor", json_integer(USERDB_MINOR)); json_object_set_new(meta, "hash_algorithm", json_string(db->hash_algorithm)); diff --git a/example/passwd/main.c b/example/passwd/main.c index 83ec16e..83862cc 100644 --- a/example/passwd/main.c +++ b/example/passwd/main.c @@ -36,13 +36,13 @@ struct command static void print_usage(void) { printf( - "wsfs-passwd, Copyright (c) 2019 authors \n" - "Manage wsfs passwd file\n" + "webfuse-passwd, Copyright (c) 2019, webfuse authors \n" + "Manage webfuse passwd file\n" "\n" - "Usage: wsfs-passwd -f -c [-u ] [-p ] [-P ]\n" + "Usage: webfuse-passwd -f -c [-u ] [-p ] [-P ]\n" "\n" "Options:\n" - "\t-f, --file Path of wsfs passwd file\n" + "\t-f, --file Path of wf passwd file\n" "\t-c, --command Command to execute\n" "\t-u, --username Name of user\n" "\t-p, --password Password of user\n" @@ -51,13 +51,13 @@ static void print_usage(void) "\n" "Commands:\n" "\tcreate Creates an empty passwd file (or cleans an existing)\n" - "\t Example: wsfs-passwd -f passwd.json -c create\n" + "\t Example: webfuse-passwd -f passwd.json -c create\n" "\tadd Adds or replaces a user\n" - "\t Example: wsfs-passwd -f passwd.json -c add -u bob -p secret\n" + "\t Example: webfuse-passwd -f passwd.json -c add -u bob -p secret\n" "\tremove Removes a user\n" - "\t Example: wsfs-passwd -f passwd.json -c remove -u bob\n" + "\t Example: webfuse-passwd -f passwd.json -c remove -u bob\n" "\tcheck Checks password of a user\n" - "\t Example: wsfs-passwd -f passwd.json -c check -u bob -p secret\n" + "\t Example: webfuse-passwd -f passwd.json -c check -u bob -p secret\n" "\n" ); } diff --git a/example/provider/main.c b/example/provider/main.c index 07c62fb..a3d6adb 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -9,12 +9,12 @@ #include #include -#include "wsfs_provider.h" +#include "webfuse_provider.h" struct config { char * url; - struct wsfsp_client_config * client_config; + struct wfp_client_config * client_config; bool show_help; }; @@ -43,19 +43,19 @@ struct fs static void show_help() { printf( - "wsfs-provider, Copyright (c) 2019 fuse-wsfs authors \n" + "webfuse-provider, Copyright (c) 2019, webfuse authors \n" "Example for websocket file system provider\n" "\n" - "Usage: wsfs-provider -u [-k ] [-c ]\n" + "Usage: webfuse-provider -u [-k ] [-c ]\n" "\n" "Options:\n" - "\t-u, --url URL of WSFS server (required)\n" + "\t-u, --url URL of webfuse server (required)\n" "\t-k, --key_path Path to private key of provider (default: not set, TLS disabled)\n" "\t-c, --cert_path Path to certificate of provider (defautl: not set, TLS disabled)\n" "\t-h, --help prints this message\n" "\n" "Example:\n" - "\twsfs-provider -u ws://localhost:8080/\n" + "\twebfuse-provider -u ws://localhost:8080/\n" "\n" ); } @@ -95,10 +95,10 @@ static int parse_arguments( config->url = strdup(optarg); break; case 'k': - wsfsp_client_config_set_keypath(config->client_config, optarg); + wfp_client_config_set_keypath(config->client_config, optarg); break; case 'c': - wsfsp_client_config_set_certpath(config->client_config, optarg); + wfp_client_config_set_certpath(config->client_config, optarg); break; default: fprintf(stderr, "error: unknown argument\n"); @@ -177,7 +177,7 @@ static void fs_stat( } static void fs_lookup( - struct wsfsp_request * request, + struct wfp_request * request, ino_t parent, char const * name, void * user_data) @@ -189,17 +189,17 @@ static void fs_lookup( struct stat stat; fs_stat(entry, &stat); - wsfsp_respond_lookup(request, &stat); + wfp_respond_lookup(request, &stat); } else { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wfp_respond_error(request, WF_BAD_NOENTRY); } } static void fs_getattr( - struct wsfsp_request * request, + struct wfp_request * request, ino_t inode, void * user_data) { @@ -211,16 +211,16 @@ static void fs_getattr( struct stat stat; fs_stat(entry, &stat); - wsfsp_respond_getattr(request, &stat); + wfp_respond_getattr(request, &stat); } else { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wfp_respond_error(request, WF_BAD_NOENTRY); } } static void fs_readdir( - struct wsfsp_request * request, + struct wfp_request * request, ino_t directory, void * user_data) { @@ -229,30 +229,30 @@ static void fs_readdir( struct fs_entry const * dir = fs_getentry(fs, directory); if ((NULL != dir) && (FS_DIR == dir->type)) { - struct wsfsp_dirbuffer * buffer = wsfsp_dirbuffer_create(); - wsfsp_dirbuffer_add(buffer, ".", dir->inode); - wsfsp_dirbuffer_add(buffer, "..", dir->inode); + struct wfp_dirbuffer * buffer = wfp_dirbuffer_create(); + wfp_dirbuffer_add(buffer, ".", dir->inode); + wfp_dirbuffer_add(buffer, "..", dir->inode); for(size_t i = 0; 0 != fs->entries[i].inode; i++) { struct fs_entry const * entry = &fs->entries[i]; if (directory == entry->parent) { - wsfsp_dirbuffer_add(buffer, entry->name, entry->inode); + wfp_dirbuffer_add(buffer, entry->name, entry->inode); } } - wsfsp_respond_readdir(request, buffer); - wsfsp_dirbuffer_dispose(buffer); + wfp_respond_readdir(request, buffer); + wfp_dirbuffer_dispose(buffer); } else { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wfp_respond_error(request, WF_BAD_NOENTRY); } } static void fs_open( - struct wsfsp_request * request, + struct wfp_request * request, ino_t inode, int flags, void * user_data) @@ -264,16 +264,16 @@ static void fs_open( { if (O_RDONLY == (flags & O_ACCMODE)) { - wsfsp_respond_open(request, 0U); + wfp_respond_open(request, 0U); } else { - wsfsp_respond_error(request, WSFS_BAD_NOACCESS); + wfp_respond_error(request, WF_BAD_NOACCESS); } } else { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wfp_respond_error(request, WF_BAD_NOENTRY); } } @@ -283,7 +283,7 @@ static size_t min(size_t const a, size_t const b) } static void fs_read( - struct wsfsp_request * request, + struct wfp_request * request, ino_t inode, uint32_t handle, size_t offset, @@ -301,26 +301,26 @@ static void fs_read( size_t const remaining = entry->content_length - offset; size_t const count = min(remaining, length); - wsfsp_respond_read(request, &entry->content[offset], count); + wfp_respond_read(request, &entry->content[offset], count); } else { - wsfsp_respond_error(request, WSFS_BAD); + wfp_respond_error(request, WF_BAD); } } else { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wfp_respond_error(request, WF_BAD_NOENTRY); } } -static struct wsfsp_client * client; +static struct wfp_client * client; static void on_interrupt(int signal_id) { (void) signal_id; - wsfsp_client_shutdown(client); + wfp_client_shutdown(client); } int main(int argc, char* argv[]) @@ -328,7 +328,7 @@ int main(int argc, char* argv[]) struct config config; config.url = NULL; config.show_help = false; - config.client_config = wsfsp_client_config_create(); + config.client_config = wfp_client_config_create(); int result = parse_arguments(argc, argv, &config); if (EXIT_SUCCESS == result) @@ -355,19 +355,19 @@ int main(int argc, char* argv[]) signal(SIGINT, &on_interrupt); - wsfsp_client_config_set_userdata(config.client_config, &fs); - wsfsp_client_config_set_onlookup(config.client_config, &fs_lookup); - wsfsp_client_config_set_ongetattr(config.client_config, &fs_getattr); - wsfsp_client_config_set_onreaddir(config.client_config, &fs_readdir); - wsfsp_client_config_set_onopen(config.client_config, &fs_open); - wsfsp_client_config_set_onread(config.client_config, &fs_read); + wfp_client_config_set_userdata(config.client_config, &fs); + wfp_client_config_set_onlookup(config.client_config, &fs_lookup); + wfp_client_config_set_ongetattr(config.client_config, &fs_getattr); + wfp_client_config_set_onreaddir(config.client_config, &fs_readdir); + wfp_client_config_set_onopen(config.client_config, &fs_open); + wfp_client_config_set_onread(config.client_config, &fs_read); - client = wsfsp_client_create(config.client_config); - wsfsp_client_connect(client, config.url); + client = wfp_client_create(config.client_config); + wfp_client_connect(client, config.url); - wsfsp_client_run(client); + wfp_client_run(client); - wsfsp_client_dispose(client); + wfp_client_dispose(client); } if (config.show_help) @@ -376,6 +376,6 @@ int main(int argc, char* argv[]) } free(config.url); - wsfsp_client_config_dispose(config.client_config); + wfp_client_config_dispose(config.client_config); return result; } \ No newline at end of file diff --git a/include/webfuse/adapter/api.h b/include/webfuse/adapter/api.h new file mode 100644 index 0000000..5d00900 --- /dev/null +++ b/include/webfuse/adapter/api.h @@ -0,0 +1,16 @@ +#ifndef WF_ADAPTER_API_H +#define WF_ADAPTER_API_H + +#ifndef WF_API +#define WF_API +#endif + +#ifndef WF_EXPORT +#ifdef __GNUC__ +#define WF_EXPORT __attribute__ ((visibility ("default"))) +#else +#define WF_EXPORT +#endif +#endif + +#endif diff --git a/include/webfuse/adapter/authenticate.h b/include/webfuse/adapter/authenticate.h new file mode 100644 index 0000000..e9113a6 --- /dev/null +++ b/include/webfuse/adapter/authenticate.h @@ -0,0 +1,23 @@ +#ifndef WF_ADAPTER_AUTHENTICATE_H +#define WF_ADAPTER_AUTHENTICATE_H + +#ifndef __cplusplus +#include +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_credentials; + +typedef bool wf_authenticate_fn( + struct wf_credentials * credentials, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/webfuse/adapter/credentials.h b/include/webfuse/adapter/credentials.h new file mode 100644 index 0000000..82a8094 --- /dev/null +++ b/include/webfuse/adapter/credentials.h @@ -0,0 +1,25 @@ +#ifndef WF_ADAPTER_CREDENTIALS_H +#define WF_ADAPTER_CREDENTIALS_H + +#include "webfuse/adapter/api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_credentials; + +extern WF_API char const * wf_credentials_type( + struct wf_credentials const * credentials); + +extern WF_API char const * wf_credentials_get( + struct wf_credentials const * credentials, + char const * key); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/webfuse/adapter/server.h b/include/webfuse/adapter/server.h new file mode 100644 index 0000000..2b4bfe9 --- /dev/null +++ b/include/webfuse/adapter/server.h @@ -0,0 +1,31 @@ +#ifndef WF_ADAPTER_SERVER_H +#define WF_ADAPTER_SERVER_H + +#include "webfuse/adapter/api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_server; +struct wf_server_config; + +extern WF_API struct wf_server * wf_server_create( + struct wf_server_config * config); + +extern WF_API void wf_server_dispose( + struct wf_server * server); + +extern WF_API void wf_server_run( + struct wf_server * server); + +extern WF_API void wf_server_shutdown( + struct wf_server * server); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/webfuse/adapter/server_config.h b/include/webfuse/adapter/server_config.h new file mode 100644 index 0000000..cc1b6d3 --- /dev/null +++ b/include/webfuse/adapter/server_config.h @@ -0,0 +1,55 @@ +#ifndef WF_ADAPTER_SERVER_CONFIG_H +#define WF_ADAPTER_SERVER_CONFIG_H + +#include "webfuse/adapter/api.h" +#include "webfuse/adapter/authenticate.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_server_config; + +extern WF_API struct wf_server_config * wf_server_config_create(void); + +extern WF_API void wf_server_config_dispose( + struct wf_server_config * config); + + +extern WF_API void wf_server_config_set_mountpoint( + struct wf_server_config * config, + char const * mount_point); + +extern WF_API void wf_server_config_set_documentroot( + struct wf_server_config * config, + char const * document_root); + +extern WF_API void wf_server_config_set_keypath( + struct wf_server_config * config, + char const * key_path); + +extern WF_API void wf_server_config_set_certpath( + struct wf_server_config * config, + char const * cert_path); + +extern WF_API void wf_server_config_set_vhostname( + struct wf_server_config * config, + char const * vhost_name); + +extern WF_API void wf_server_config_set_port( + struct wf_server_config * config, + int port); + +extern WF_API void wf_server_config_add_authenticator( + struct wf_server_config * config, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data +); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/webfuse/adapter/server_protocol.h b/include/webfuse/adapter/server_protocol.h new file mode 100644 index 0000000..d77cbc3 --- /dev/null +++ b/include/webfuse/adapter/server_protocol.h @@ -0,0 +1,35 @@ +#ifndef WF_ADAPTER_SERVER_PROTOCOL_H +#define WF_ADAPTER_SERVER_PROTOCOL_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_server_protocol; +struct lws_protocols; + +extern WF_API struct wf_server_protocol * wf_server_protocol_create( + char * mount_point); + +extern WF_API void wf_server_protocol_dispose( + struct wf_server_protocol * protocol); + +extern WF_API void wf_server_protocol_init_lws( + struct wf_server_protocol * protocol, + struct lws_protocols * lws_protocol); + +extern WF_API void wf_server_protocol_add_authenticator( + struct wf_server_protocol * protocol, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/webfuse/core/status.h b/include/webfuse/core/status.h new file mode 100644 index 0000000..9ce425d --- /dev/null +++ b/include/webfuse/core/status.h @@ -0,0 +1,17 @@ +#ifndef WF_STATUS_H +#define WF_STATUS_H + +#define WF_GOOD 0 +#define WF_BAD 1 + +#define WF_BAD_NOTIMPLEMENTED 2 +#define WF_BAD_TIMEOUT 3 +#define WF_BAD_BUSY 4 +#define WF_BAD_FORMAT 5 + +#define WF_BAD_NOENTRY 101 +#define WF_BAD_NOACCESS 102 + +typedef int wf_status; + +#endif diff --git a/include/webfuse/provider/api.h b/include/webfuse/provider/api.h new file mode 100644 index 0000000..5b3c572 --- /dev/null +++ b/include/webfuse/provider/api.h @@ -0,0 +1,16 @@ +#ifndef WFP_PROVIDER_API_H +#define WFP_PROVIDER_API_H + +#ifndef WFP_API +#define WFP_API +#endif + +#ifndef WFP_EXPORT +#ifdef __GNUC__ +#define WFP_EXPORT __attribute__ ((visibility ("default"))) +#else +#define WFP_EXPORT +#endif +#endif + +#endif diff --git a/include/webfuse/provider/client.h b/include/webfuse/provider/client.h new file mode 100644 index 0000000..8fa6326 --- /dev/null +++ b/include/webfuse/provider/client.h @@ -0,0 +1,39 @@ +#ifndef WF_PROVIDER_CLIENT_H +#define WF_PROVIDER_CLIENT_H + +#include "webfuse/provider/api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_client; +struct wfp_client_config; + +extern WFP_API struct wfp_client * wfp_client_create( + struct wfp_client_config * config); + +extern WFP_API void wfp_client_connect( + struct wfp_client * client, + char const * url); + +extern WFP_API void wfp_client_disconnect( + struct wfp_client * client); + +extern WFP_API void wfp_client_dispose( + struct wfp_client * client); + +extern WFP_API void wfp_client_run( + struct wfp_client * client); + +extern WFP_API void wfp_client_shutdown( + struct wfp_client * client); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/webfuse/provider/client_config.h b/include/webfuse/provider/client_config.h new file mode 100644 index 0000000..4a9cebc --- /dev/null +++ b/include/webfuse/provider/client_config.h @@ -0,0 +1,88 @@ +#ifndef WF_PROVIDER_CLIENT_CONFIG_H +#define WF_PROVIDER_CLIENT_CONFIG_H + +#include + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_client_config; + +typedef void wfp_connected_fn( + void * user_data); + +typedef void wfp_disconnected_fn( + void * user_data); + +typedef void wfp_ontimer_fn( + void * user_data); + +extern WFP_API struct wfp_client_config * wfp_client_config_create(void); + +extern WFP_API void wfp_client_config_dispose( + struct wfp_client_config * config); + +extern WFP_API void wfp_client_config_set_userdata( + struct wfp_client_config * config, + void * user_data); + +extern WFP_API void wfp_client_config_set_keypath( + struct wfp_client_config * config, + char const * key_path); + +extern WFP_API void wfp_client_config_set_certpath( + struct wfp_client_config * config, + char const * cert_path); + +extern WFP_API void wfp_client_config_set_onconnected( + struct wfp_client_config * config, + wfp_connected_fn * handler); + +extern WFP_API void wfp_client_config_set_ondisconnected( + struct wfp_client_config * config, + wfp_disconnected_fn * handler); + +extern WFP_API void wfp_client_config_set_ontimer( + struct wfp_client_config * config, + wfp_ontimer_fn * handler); + + +extern WFP_API void wfp_client_config_set_onlookup( + struct wfp_client_config * config, + wfp_lookup_fn * handler); + +extern WFP_API void wfp_client_config_set_ongetattr( + struct wfp_client_config * config, + wfp_getattr_fn * handler); + +extern WFP_API void wfp_client_config_set_onreaddir( + struct wfp_client_config * config, + wfp_readdir_fn * handler); + +extern WFP_API void wfp_client_config_set_onopen( + struct wfp_client_config * config, + wfp_open_fn * handler); + +extern WFP_API void wfp_client_config_set_onclose( + struct wfp_client_config * config, + wfp_close_fn * handler); + +extern WFP_API void wfp_client_config_set_onread( + struct wfp_client_config * config, + wfp_read_fn * handler); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/webfuse/provider/client_protocol.h b/include/webfuse/provider/client_protocol.h new file mode 100644 index 0000000..8bda896 --- /dev/null +++ b/include/webfuse/provider/client_protocol.h @@ -0,0 +1,32 @@ +#ifndef WF_PROVIDER_CLIENT_PROTOCOL_H +#define WF_PROVIDER_CLIENT_PROTOCOL_H + +#include "webfuse/provider/api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_client_protocol; +struct wfp_provider; +struct lws_protocols; + +extern WFP_API struct wfp_client_protocol * wfp_client_protocol_create( + struct wfp_provider const * provider, + void * user_data); + +extern WFP_API void wfp_client_protocol_dispose( + struct wfp_client_protocol * protocol); + +extern WFP_API void wfp_client_protocol_init_lws( + struct wfp_client_protocol * protocol, + struct lws_protocols * lws_protocol); + +#ifdef __cplusplus +} +#endif + + + +#endif diff --git a/include/webfuse/provider/dirbuffer.h b/include/webfuse/provider/dirbuffer.h new file mode 100644 index 0000000..d0770e5 --- /dev/null +++ b/include/webfuse/provider/dirbuffer.h @@ -0,0 +1,32 @@ +#ifndef WF_PROVIDER_DIRBUFFER_H +#define WF_PROVIDER_DIRBUFFER_H + +#include +#include +#include + +#include "webfuse/provider/api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_dirbuffer; + +extern WFP_API struct wfp_dirbuffer * wfp_dirbuffer_create(void); + +extern WFP_API void wfp_dirbuffer_dispose( + struct wfp_dirbuffer * buffer); + +extern WFP_API void wfp_dirbuffer_add( + struct wfp_dirbuffer * buffer, + char const * name, + ino_t inode); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/wsfs/provider/operation/close.h b/include/webfuse/provider/operation/close.h similarity index 70% rename from include/wsfs/provider/operation/close.h rename to include/webfuse/provider/operation/close.h index 63851c7..bb1eef1 100644 --- a/include/wsfs/provider/operation/close.h +++ b/include/webfuse/provider/operation/close.h @@ -1,5 +1,5 @@ -#ifndef WSFSP_OPERATION_CLOSE_H -#define WSFSP_OPERATION_CLOSE_H +#ifndef WFP_OPERATION_CLOSE_H +#define WFP_OPERATION_CLOSE_H #ifndef __cplusplus #include @@ -11,14 +11,14 @@ #include #include -#include "wsfs/provider/api.h" +#include "webfuse/provider/api.h" #ifdef __cplusplus extern "C" { #endif -typedef void wsfsp_close_fn( +typedef void wfp_close_fn( ino_t inode, uint32_t handle, int flags, diff --git a/include/webfuse/provider/operation/error.h b/include/webfuse/provider/operation/error.h new file mode 100644 index 0000000..4e8e1fe --- /dev/null +++ b/include/webfuse/provider/operation/error.h @@ -0,0 +1,22 @@ +#ifndef WFP_OPERATION_ERROR_H +#define WFP_OPERATION_ERROR_H + +#include "webfuse/provider/api.h" +#include "webfuse/core/status.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_request; + +extern WFP_API void wfp_respond_error( + struct wfp_request * request, + wf_status status); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/webfuse/provider/operation/getattr.h b/include/webfuse/provider/operation/getattr.h new file mode 100644 index 0000000..14af3dc --- /dev/null +++ b/include/webfuse/provider/operation/getattr.h @@ -0,0 +1,31 @@ +#ifndef WFP_OPERATION_GETATTR_H +#define WFP_OPERATION_GETATTR_H + +#include +#include +#include + +#include "webfuse/provider/api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_request; + +typedef void wfp_getattr_fn( + struct wfp_request * request, + ino_t inode, + void * user_data); + +extern WFP_API void wfp_respond_getattr( + struct wfp_request * request, + struct stat const * stat); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/webfuse/provider/operation/lookup.h b/include/webfuse/provider/operation/lookup.h new file mode 100644 index 0000000..5e177d7 --- /dev/null +++ b/include/webfuse/provider/operation/lookup.h @@ -0,0 +1,32 @@ +#ifndef WFP_OPERATION_LOOKUP_H +#define WFP_OPERATION_LOOKUP_H + +#include +#include +#include + +#include "webfuse/provider/api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_request; + +typedef void wfp_lookup_fn( + struct wfp_request * request, + ino_t parent, + char const * name, + void * user_data); + +extern WFP_API void wfp_respond_lookup( + struct wfp_request * request, + struct stat const * stat); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/wsfs/provider/operation/open.h b/include/webfuse/provider/operation/open.h similarity index 54% rename from include/wsfs/provider/operation/open.h rename to include/webfuse/provider/operation/open.h index 3ef7693..9114828 100644 --- a/include/wsfs/provider/operation/open.h +++ b/include/webfuse/provider/operation/open.h @@ -1,5 +1,5 @@ -#ifndef WSFSP_OPERATION_OPEN_H -#define WSFSP_OPERATION_OPEN_H +#ifndef WFP_OPERATION_OPEN_H +#define WFP_OPERATION_OPEN_H #ifndef __cplusplus #include @@ -11,23 +11,23 @@ #include #include -#include "wsfs/provider/api.h" +#include "webfuse/provider/api.h" #ifdef __cplusplus extern "C" { #endif -struct wsfsp_request; +struct wfp_request; -typedef void wsfsp_open_fn( - struct wsfsp_request * request, +typedef void wfp_open_fn( + struct wfp_request * request, ino_t inode, int flags, void * user_data); -extern WSFSP_API void wsfsp_respond_open( - struct wsfsp_request * request, +extern WFP_API void wfp_respond_open( + struct wfp_request * request, uint32_t handle); diff --git a/include/wsfs/provider/operation/read.h b/include/webfuse/provider/operation/read.h similarity index 62% rename from include/wsfs/provider/operation/read.h rename to include/webfuse/provider/operation/read.h index 9440977..570c310 100644 --- a/include/wsfs/provider/operation/read.h +++ b/include/webfuse/provider/operation/read.h @@ -1,5 +1,5 @@ -#ifndef WSFSP_OPERATION_READ_H -#define WSFSP_OPERATION_READ_H +#ifndef WFP_OPERATION_READ_H +#define WFP_OPERATION_READ_H #ifndef __cplusplus #include @@ -14,25 +14,25 @@ using std::size_t; #include #include -#include "wsfs/provider/api.h" +#include "webfuse/provider/api.h" #ifdef __cplusplus extern "C" { #endif -struct wsfsp_request; +struct wfp_request; -typedef void wsfsp_read_fn( - struct wsfsp_request * request, +typedef void wfp_read_fn( + struct wfp_request * request, ino_t inode, uint32_t handle, size_t offset, size_t length, void * user_data); -extern WSFSP_API void wsfsp_respond_read( - struct wsfsp_request * request, +extern WFP_API void wfp_respond_read( + struct wfp_request * request, char const * data, size_t length); diff --git a/include/webfuse/provider/operation/readdir.h b/include/webfuse/provider/operation/readdir.h new file mode 100644 index 0000000..968b7f3 --- /dev/null +++ b/include/webfuse/provider/operation/readdir.h @@ -0,0 +1,31 @@ +#ifndef WFP_OPERATION_READDIR_H +#define WFP_OPERATION_READDIR_H + +#include +#include +#include + +#include "webfuse/provider/api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_dirbuffer; +struct wfp_request; + +typedef void wfp_readdir_fn( + struct wfp_request * request, + ino_t directory, + void * user_data); + +extern WFP_API void wfp_respond_readdir( + struct wfp_request * request, + struct wfp_dirbuffer * dirbuffer); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/webfuse_adapter.h b/include/webfuse_adapter.h new file mode 100644 index 0000000..8edad51 --- /dev/null +++ b/include/webfuse_adapter.h @@ -0,0 +1,13 @@ +#ifndef WF_ADAPTER_H +#define WF_ADAPTER_H + +#include + +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/webfuse_provider.h b/include/webfuse_provider.h new file mode 100644 index 0000000..26398ff --- /dev/null +++ b/include/webfuse_provider.h @@ -0,0 +1,20 @@ +#ifndef WF_PROVIDER_H +#define WF_PROVIDER_H + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/wsfs/adapter/api.h b/include/wsfs/adapter/api.h deleted file mode 100644 index 6cd6a32..0000000 --- a/include/wsfs/adapter/api.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef WSFS_ADAPTER_API_H -#define WSFS_ADAPTER_API_H - -#ifndef WSFSA_API -#define WSFSA_API -#endif - -#ifndef WSFSA_EXPORT -#ifdef __GNUC__ -#define WSFSA_EXPORT __attribute__ ((visibility ("default"))) -#else -#define WSFSA_EXPORT -#endif -#endif - -#endif diff --git a/include/wsfs/adapter/authenticate.h b/include/wsfs/adapter/authenticate.h deleted file mode 100644 index c34d402..0000000 --- a/include/wsfs/adapter/authenticate.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef WSFS_ADAPTER_AUTHENTICATE_H -#define WSFS_ADAPTER_AUTHENTICATE_H - -#ifndef __cplusplus -#include -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_credentials; - -typedef bool wsfs_authenticate_fn( - struct wsfs_credentials * credentials, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/wsfs/adapter/credentials.h b/include/wsfs/adapter/credentials.h deleted file mode 100644 index 9e77113..0000000 --- a/include/wsfs/adapter/credentials.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef WSFS_ADAPTER_CREDENTIALS_H -#define WSFS_ADAPTER_CREDENTIALS_H - -#include "wsfs/adapter/api.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_credentials; - -extern WSFSA_API char const * wsfs_credentials_type( - struct wsfs_credentials const * credentials); - -extern WSFSA_API char const * wsfs_credentials_get( - struct wsfs_credentials const * credentials, - char const * key); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/include/wsfs/adapter/server.h b/include/wsfs/adapter/server.h deleted file mode 100644 index 3a27bdc..0000000 --- a/include/wsfs/adapter/server.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WSFS_ADAPTER_SERVER_H -#define WSFS_ADAPTER_SERVER_H - -#include "wsfs/adapter/api.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_server; -struct wsfs_server_config; - -extern WSFSA_API struct wsfs_server * wsfs_server_create( - struct wsfs_server_config * config); - -extern WSFSA_API void wsfs_server_dispose( - struct wsfs_server * server); - -extern WSFSA_API void wsfs_server_run( - struct wsfs_server * server); - -extern WSFSA_API void wsfs_server_shutdown( - struct wsfs_server * server); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/include/wsfs/adapter/server_config.h b/include/wsfs/adapter/server_config.h deleted file mode 100644 index 8983693..0000000 --- a/include/wsfs/adapter/server_config.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef WSFS_ADAPTER_SERVER_CONFIG_H -#define WSFS_ADAPTER_SERVER_CONFIG_H - -#include "wsfs/adapter/api.h" -#include "wsfs/adapter/authenticate.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_server_config; - -extern WSFSA_API struct wsfs_server_config * wsfs_server_config_create(void); - -extern WSFSA_API void wsfs_server_config_dispose( - struct wsfs_server_config * config); - - -extern WSFSA_API void wsfs_server_config_set_mountpoint( - struct wsfs_server_config * config, - char const * mount_point); - -extern WSFSA_API void wsfs_server_config_set_documentroot( - struct wsfs_server_config * config, - char const * document_root); - -extern WSFSA_API void wsfs_server_config_set_keypath( - struct wsfs_server_config * config, - char const * key_path); - -extern WSFSA_API void wsfs_server_config_set_certpath( - struct wsfs_server_config * config, - char const * cert_path); - -extern WSFSA_API void wsfs_server_config_set_vhostname( - struct wsfs_server_config * config, - char const * vhost_name); - -extern WSFSA_API void wsfs_server_config_set_port( - struct wsfs_server_config * config, - int port); - -extern WSFSA_API void wsfs_server_config_add_authenticator( - struct wsfs_server_config * config, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data -); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/wsfs/adapter/server_protocol.h b/include/wsfs/adapter/server_protocol.h deleted file mode 100644 index bfa33ee..0000000 --- a/include/wsfs/adapter/server_protocol.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef WSFS_ADAPTER_SERVER_PROTOCOL_H -#define WSFS_ADAPTER_SERVER_PROTOCOL_H - -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_server_protocol; -struct lws_protocols; - -extern WSFSA_API struct wsfs_server_protocol * wsfs_server_protocol_create( - char * mount_point); - -extern WSFSA_API void wsfs_server_protocol_dispose( - struct wsfs_server_protocol * protocol); - -extern WSFSA_API void wsfs_server_protocol_init_lws( - struct wsfs_server_protocol * protocol, - struct lws_protocols * lws_protocol); - -extern WSFSA_API void wsfs_server_protocol_add_authenticator( - struct wsfs_server_protocol * protocol, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/wsfs/core/status.h b/include/wsfs/core/status.h deleted file mode 100644 index 7740f7f..0000000 --- a/include/wsfs/core/status.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WSFS_STATUS_H -#define WSFS_STATUS_H - -#define WSFS_GOOD 0 -#define WSFS_BAD 1 - -#define WSFS_BAD_NOTIMPLEMENTED 2 -#define WSFS_BAD_TIMEOUT 3 -#define WSFS_BAD_BUSY 4 -#define WSFS_BAD_FORMAT 5 - -#define WSFS_BAD_NOENTRY 101 -#define WSFS_BAD_NOACCESS 102 - -typedef int wsfs_status; - -#endif diff --git a/include/wsfs/provider/api.h b/include/wsfs/provider/api.h deleted file mode 100644 index 4935bf2..0000000 --- a/include/wsfs/provider/api.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef WSFSP_PROVIDER_API_H -#define WSFSP_PROVIDER_API_H - -#ifndef WSFSP_API -#define WSFSP_API -#endif - -#ifndef WSFSP_EXPORT -#ifdef __GNUC__ -#define WSFSP_EXPORT __attribute__ ((visibility ("default"))) -#else -#define WSFSP_EXPORT -#endif -#endif - -#endif diff --git a/include/wsfs/provider/client.h b/include/wsfs/provider/client.h deleted file mode 100644 index 397b03a..0000000 --- a/include/wsfs/provider/client.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef WSFS_PROVIDER_CLIENT_H -#define WSFS_PROVIDER_CLIENT_H - -#include "wsfs/provider/api.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_client; -struct wsfsp_client_config; - -extern WSFSP_API struct wsfsp_client * wsfsp_client_create( - struct wsfsp_client_config * config); - -extern WSFSP_API void wsfsp_client_connect( - struct wsfsp_client * client, - char const * url); - -extern WSFSP_API void wsfsp_client_disconnect( - struct wsfsp_client * client); - -extern WSFSP_API void wsfsp_client_dispose( - struct wsfsp_client * client); - -extern WSFSP_API void wsfsp_client_run( - struct wsfsp_client * client); - -extern WSFSP_API void wsfsp_client_shutdown( - struct wsfsp_client * client); - - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/include/wsfs/provider/client_config.h b/include/wsfs/provider/client_config.h deleted file mode 100644 index 2396a3d..0000000 --- a/include/wsfs/provider/client_config.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef WSFS_PROVIDER_CLIENT_CONFIG_H -#define WSFS_PROVIDER_CLIENT_CONFIG_H - -#include - -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_client_config; - -typedef void wsfsp_connected_fn( - void * user_data); - -typedef void wsfsp_disconnected_fn( - void * user_data); - -typedef void wsfsp_ontimer_fn( - void * user_data); - -extern WSFSP_API struct wsfsp_client_config * wsfsp_client_config_create(void); - -extern WSFSP_API void wsfsp_client_config_dispose( - struct wsfsp_client_config * config); - -extern WSFSP_API void wsfsp_client_config_set_userdata( - struct wsfsp_client_config * config, - void * user_data); - -extern WSFSP_API void wsfsp_client_config_set_keypath( - struct wsfsp_client_config * config, - char const * key_path); - -extern WSFSP_API void wsfsp_client_config_set_certpath( - struct wsfsp_client_config * config, - char const * cert_path); - -extern WSFSP_API void wsfsp_client_config_set_onconnected( - struct wsfsp_client_config * config, - wsfsp_connected_fn * handler); - -extern WSFSP_API void wsfsp_client_config_set_ondisconnected( - struct wsfsp_client_config * config, - wsfsp_disconnected_fn * handler); - -extern WSFSP_API void wsfsp_client_config_set_ontimer( - struct wsfsp_client_config * config, - wsfsp_ontimer_fn * handler); - - -extern WSFSP_API void wsfsp_client_config_set_onlookup( - struct wsfsp_client_config * config, - wsfsp_lookup_fn * handler); - -extern WSFSP_API void wsfsp_client_config_set_ongetattr( - struct wsfsp_client_config * config, - wsfsp_getattr_fn * handler); - -extern WSFSP_API void wsfsp_client_config_set_onreaddir( - struct wsfsp_client_config * config, - wsfsp_readdir_fn * handler); - -extern WSFSP_API void wsfsp_client_config_set_onopen( - struct wsfsp_client_config * config, - wsfsp_open_fn * handler); - -extern WSFSP_API void wsfsp_client_config_set_onclose( - struct wsfsp_client_config * config, - wsfsp_close_fn * handler); - -extern WSFSP_API void wsfsp_client_config_set_onread( - struct wsfsp_client_config * config, - wsfsp_read_fn * handler); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/include/wsfs/provider/client_protocol.h b/include/wsfs/provider/client_protocol.h deleted file mode 100644 index 23e1620..0000000 --- a/include/wsfs/provider/client_protocol.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef WSFS_PROVIDER_CLIENT_PROTOCOL_H -#define WSFS_PROVIDER_CLIENT_PROTOCOL_H - -#include "wsfs/provider/api.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_client_protocol; -struct wsfsp_provider; -struct lws_protocols; - -extern WSFSP_API struct wsfsp_client_protocol * wsfsp_client_protocol_create( - struct wsfsp_provider const * provider, - void * user_data); - -extern WSFSP_API void wsfsp_client_protocol_dispose( - struct wsfsp_client_protocol * protocol); - -extern WSFSP_API void wsfsp_client_protocol_init_lws( - struct wsfsp_client_protocol * protocol, - struct lws_protocols * lws_protocol); - -#ifdef __cplusplus -} -#endif - - - -#endif diff --git a/include/wsfs/provider/dirbuffer.h b/include/wsfs/provider/dirbuffer.h deleted file mode 100644 index 0c53157..0000000 --- a/include/wsfs/provider/dirbuffer.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef WSFS_PROVIDER_DIRBUFFER_H -#define WSFS_PROVIDER_DIRBUFFER_H - -#include -#include -#include - -#include "wsfs/provider/api.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_dirbuffer; - -extern WSFSP_API struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void); - -extern WSFSP_API void wsfsp_dirbuffer_dispose( - struct wsfsp_dirbuffer * buffer); - -extern WSFSP_API void wsfsp_dirbuffer_add( - struct wsfsp_dirbuffer * buffer, - char const * name, - ino_t inode); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/include/wsfs/provider/operation/error.h b/include/wsfs/provider/operation/error.h deleted file mode 100644 index 077963d..0000000 --- a/include/wsfs/provider/operation/error.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef WSFSP_OPERATION_ERROR_H -#define WSFSP_OPERATION_ERROR_H - -#include "wsfs/provider/api.h" -#include "wsfs/core/status.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_request; - -extern WSFSP_API void wsfsp_respond_error( - struct wsfsp_request * request, - wsfs_status status); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/wsfs/provider/operation/getattr.h b/include/wsfs/provider/operation/getattr.h deleted file mode 100644 index a88b2af..0000000 --- a/include/wsfs/provider/operation/getattr.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WSFSP_OPERATION_GETATTR_H -#define WSFSP_OPERATION_GETATTR_H - -#include -#include -#include - -#include "wsfs/provider/api.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_request; - -typedef void wsfsp_getattr_fn( - struct wsfsp_request * request, - ino_t inode, - void * user_data); - -extern WSFSP_API void wsfsp_respond_getattr( - struct wsfsp_request * request, - struct stat const * stat); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/wsfs/provider/operation/lookup.h b/include/wsfs/provider/operation/lookup.h deleted file mode 100644 index 0cb2875..0000000 --- a/include/wsfs/provider/operation/lookup.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef WSFSP_OPERATION_LOOKUP_H -#define WSFSP_OPERATION_LOOKUP_H - -#include -#include -#include - -#include "wsfs/provider/api.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_request; - -typedef void wsfsp_lookup_fn( - struct wsfsp_request * request, - ino_t parent, - char const * name, - void * user_data); - -extern WSFSP_API void wsfsp_respond_lookup( - struct wsfsp_request * request, - struct stat const * stat); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/wsfs/provider/operation/readdir.h b/include/wsfs/provider/operation/readdir.h deleted file mode 100644 index e887ebf..0000000 --- a/include/wsfs/provider/operation/readdir.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WSFSP_OPERATION_READDIR_H -#define WSFSP_OPERATION_READDIR_H - -#include -#include -#include - -#include "wsfs/provider/api.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_dirbuffer; -struct wsfsp_request; - -typedef void wsfsp_readdir_fn( - struct wsfsp_request * request, - ino_t directory, - void * user_data); - -extern WSFSP_API void wsfsp_respond_readdir( - struct wsfsp_request * request, - struct wsfsp_dirbuffer * dirbuffer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/wsfs_adapter.h b/include/wsfs_adapter.h deleted file mode 100644 index 076267f..0000000 --- a/include/wsfs_adapter.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef WSFS_ADAPTER_H -#define WSFS_ADAPTER_H - -#include - -#include -#include -#include -#include -#include -#include - -#endif diff --git a/include/wsfs_provider.h b/include/wsfs_provider.h deleted file mode 100644 index 1251212..0000000 --- a/include/wsfs_provider.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef WSFS_PROVIDER_H -#define WSFS_PROVIDER_H - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c new file mode 100644 index 0000000..ecfd136 --- /dev/null +++ b/lib/webfuse/adapter/api.c @@ -0,0 +1,141 @@ +#include "webfuse_adapter.h" + +#include "webfuse/adapter/impl/server.h" +#include "webfuse/adapter/impl/server_protocol.h" +#include "webfuse/adapter/impl/server_config.h" +#include "webfuse/adapter/impl/credentials.h" + +// server + +struct wf_server * wf_server_create( + struct wf_server_config * config) +{ + return wf_impl_server_create(config); +} + +void wf_server_dispose( + struct wf_server * server) +{ + wf_impl_server_dispose(server); +} + +void wf_server_run( + struct wf_server * server) +{ + wf_impl_server_run(server); +} + +void wf_server_shutdown( + struct wf_server * server) +{ + wf_impl_server_shutdown(server); +} + +// server protocol + +struct wf_server_protocol * wf_server_protocol_create( + char * mount_point) +{ + return wf_impl_server_protocol_create(mount_point); +} + +void wf_server_protocol_dispose( + struct wf_server_protocol * protocol) +{ + wf_impl_server_protocol_dispose(protocol); +} + +void wf_server_protocol_init_lws( + struct wf_server_protocol * protocol, + struct lws_protocols * lws_protocol) +{ + wf_impl_server_protocol_init_lws(protocol, lws_protocol); +} + +void wf_server_protocol_add_authenticator( + struct wf_server_protocol * protocol, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data) +{ + wf_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data); +} + +// server_config + +struct wf_server_config * wf_server_config_create(void) +{ + return wf_impl_server_config_create(); +} + +void wf_server_config_dispose( + struct wf_server_config * config) +{ + wf_impl_server_config_dispose(config); +} + +void wf_server_config_set_mountpoint( + struct wf_server_config * config, + char const * mount_point) +{ + wf_impl_server_config_set_mountpoint(config, mount_point); +} + +void wf_server_config_set_documentroot( + struct wf_server_config * config, + char const * document_root) +{ + wf_impl_server_config_set_documentroot(config, document_root); +} + +void wf_server_config_set_keypath( + struct wf_server_config * config, + char const * key_path) +{ + wf_impl_server_config_set_keypath(config, key_path); +} + +void wf_server_config_set_certpath( + struct wf_server_config * config, + char const * cert_path) +{ + wf_impl_server_config_set_certpath(config, cert_path); +} + +void wf_server_config_set_vhostname( + struct wf_server_config * config, + char const * vhost_name) +{ + wf_impl_server_config_set_vhostname(config, vhost_name); +} + +void wf_server_config_set_port( + struct wf_server_config * config, + int port) +{ + wf_impl_server_config_set_port(config, port); +} + +void wf_server_config_add_authenticator( + struct wf_server_config * config, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data) +{ + wf_impl_server_config_add_authenticator(config, type, authenticate, user_data); +} + +// credentials + +char const * wf_credentials_type( + struct wf_credentials const * credentials) +{ + return wf_impl_credentials_type(credentials); +} + +char const * wf_credentials_get( + struct wf_credentials const * credentials, + char const * key) +{ + return wf_impl_credentials_get(credentials, key); +} diff --git a/lib/wsfs/adapter/impl/authenticator.c b/lib/webfuse/adapter/impl/authenticator.c similarity index 55% rename from lib/wsfs/adapter/impl/authenticator.c rename to lib/webfuse/adapter/impl/authenticator.c index a4c8c34..0be4b62 100644 --- a/lib/wsfs/adapter/impl/authenticator.c +++ b/lib/webfuse/adapter/impl/authenticator.c @@ -1,16 +1,16 @@ -#include "wsfs/adapter/impl/authenticator.h" +#include "webfuse/adapter/impl/authenticator.h" #include #include -#include "wsfs/adapter/impl/credentials.h" +#include "webfuse/adapter/impl/credentials.h" -struct wsfs_impl_authenticator * wsfs_impl_authenticator_create( +struct wf_impl_authenticator * wf_impl_authenticator_create( char const * type, - wsfs_authenticate_fn * authenticate, + wf_authenticate_fn * authenticate, void * user_data) { - struct wsfs_impl_authenticator * authenticator = malloc(sizeof(struct wsfs_impl_authenticator)); + struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator)); if (NULL != authenticator) { authenticator->type = strdup(type); @@ -22,16 +22,16 @@ struct wsfs_impl_authenticator * wsfs_impl_authenticator_create( return authenticator; } -void wsfs_impl_authenticator_dispose( - struct wsfs_impl_authenticator * authenticator) +void wf_impl_authenticator_dispose( + struct wf_impl_authenticator * authenticator) { free(authenticator->type); free(authenticator); } -bool wsfs_impl_authenticator_autenticate( - struct wsfs_impl_authenticator * authenticator, - struct wsfs_credentials * credentials) +bool wf_impl_authenticator_autenticate( + struct wf_impl_authenticator * authenticator, + struct wf_credentials * credentials) { bool result; diff --git a/lib/webfuse/adapter/impl/authenticator.h b/lib/webfuse/adapter/impl/authenticator.h new file mode 100644 index 0000000..2d92e2f --- /dev/null +++ b/lib/webfuse/adapter/impl/authenticator.h @@ -0,0 +1,42 @@ +#ifndef WF_ADAPTER_IMPL_AUTHENTICATOR_H +#define WF_ADAPTER_IMPL_AUTHENTICATOR_H + +#ifndef __cplusplus +#include +#endif + +#include "webfuse/adapter/authenticate.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_credentials; + +struct wf_impl_authenticator +{ + char * type; + wf_authenticate_fn * authenticate; + void * user_data; + struct wf_impl_authenticator * next; +}; + +extern struct wf_impl_authenticator * wf_impl_authenticator_create( + char const * type, + wf_authenticate_fn * authenticate, + void * user_data); + +extern void wf_impl_authenticator_dispose( + struct wf_impl_authenticator * authenticator); + +extern bool wf_impl_authenticator_autenticate( + struct wf_impl_authenticator * authenticator, + struct wf_credentials * credentials); + + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/webfuse/adapter/impl/authenticators.c b/lib/webfuse/adapter/impl/authenticators.c new file mode 100644 index 0000000..57d1e20 --- /dev/null +++ b/lib/webfuse/adapter/impl/authenticators.c @@ -0,0 +1,101 @@ +#include "webfuse/adapter/impl/authenticators.h" +#include +#include + +#include "webfuse/adapter/impl/authenticator.h" +#include "webfuse/adapter/impl/credentials.h" + +static struct wf_impl_authenticator * wf_impl_authenticators_find( + struct wf_impl_authenticators * authenticators, + char const * type) +{ + struct wf_impl_authenticator * result = NULL; + + struct wf_impl_authenticator * actual = authenticators->first; + while ((NULL == result) && (NULL != actual)) + { + struct wf_impl_authenticator * next = actual->next; + if (0 == strcmp(type, actual->type)) + { + result = actual; + } + + actual = next; + } + + return result; +} + +void wf_impl_authenticators_init( + struct wf_impl_authenticators * authenticators) +{ + authenticators->first = NULL; +} + +void wf_impl_authenticators_cleanup( + struct wf_impl_authenticators * authenticators) +{ + struct wf_impl_authenticator * actual = authenticators->first; + while (NULL != actual) + { + struct wf_impl_authenticator * next = actual->next; + wf_impl_authenticator_dispose(actual); + actual = next; + } + + authenticators->first = NULL; +} + +void wf_impl_authenticators_clone( + struct wf_impl_authenticators * authenticators, + struct wf_impl_authenticators * other) +{ + wf_impl_authenticators_init(other); + + struct wf_impl_authenticator * actual = authenticators->first; + while (NULL != actual) + { + struct wf_impl_authenticator * next = actual->next; + wf_impl_authenticators_add(other, + actual->type, actual->authenticate, actual->user_data); + actual = next; + } + +} + +extern void wf_impl_authenticators_move( + struct wf_impl_authenticators * authenticators, + struct wf_impl_authenticators * other) +{ + other->first = authenticators->first; + authenticators->first = NULL; +} + +void wf_impl_authenticators_add( + struct wf_impl_authenticators * authenticators, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data) +{ + struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(type, authenticate, user_data); + authenticator->next = authenticators->first; + authenticators->first = authenticator; +} + +bool wf_impl_authenticators_authenticate( + struct wf_impl_authenticators * authenticators, + struct wf_credentials * credentials) +{ + bool result = (NULL == authenticators->first); + + if (NULL != credentials) + { + struct wf_impl_authenticator * authenticator = wf_impl_authenticators_find(authenticators, credentials->type); + if (NULL != authenticator) + { + result = wf_impl_authenticator_autenticate(authenticator, credentials); + } + } + + return result; +} \ No newline at end of file diff --git a/lib/webfuse/adapter/impl/authenticators.h b/lib/webfuse/adapter/impl/authenticators.h new file mode 100644 index 0000000..bf2c72d --- /dev/null +++ b/lib/webfuse/adapter/impl/authenticators.h @@ -0,0 +1,51 @@ +#ifndef WF_ADAPTER_IMPL_AUTHENTICATORS_H +#define WF_ADAPTER_IMPL_AUTHENTICATORS_H + +#ifndef __cplusplus +#include +#endif + +#include "webfuse/adapter/authenticate.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_impl_authenticator; +struct wf_credentials; + +struct wf_impl_authenticators +{ + struct wf_impl_authenticator * first; +}; + +extern void wf_impl_authenticators_init( + struct wf_impl_authenticators * authenticators); + +extern void wf_impl_authenticators_cleanup( + struct wf_impl_authenticators * authenticators); + +extern void wf_impl_authenticators_clone( + struct wf_impl_authenticators * authenticators, + struct wf_impl_authenticators * other); + +extern void wf_impl_authenticators_move( + struct wf_impl_authenticators * authenticators, + struct wf_impl_authenticators * other); + +extern void wf_impl_authenticators_add( + struct wf_impl_authenticators * authenticators, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data); + +extern bool wf_impl_authenticators_authenticate( + struct wf_impl_authenticators * authenticators, + struct wf_credentials * credentials); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsfs/adapter/impl/credentials.c b/lib/webfuse/adapter/impl/credentials.c similarity index 58% rename from lib/wsfs/adapter/impl/credentials.c rename to lib/webfuse/adapter/impl/credentials.c index 2c4619c..040638a 100644 --- a/lib/wsfs/adapter/impl/credentials.c +++ b/lib/webfuse/adapter/impl/credentials.c @@ -1,8 +1,8 @@ -#include "wsfs/adapter/impl/credentials.h" +#include "webfuse/adapter/impl/credentials.h" #include -void wsfs_impl_credentials_init( - struct wsfs_credentials * credentials, +void wf_impl_credentials_init( + struct wf_credentials * credentials, char const * type, json_t * data) { @@ -11,21 +11,21 @@ void wsfs_impl_credentials_init( json_incref(credentials->data); } -void wsfs_impl_credentials_cleanup( - struct wsfs_credentials * credentials) +void wf_impl_credentials_cleanup( + struct wf_credentials * credentials) { free(credentials->type); json_decref(credentials->data); } -char const * wsfs_impl_credentials_type( - struct wsfs_credentials const * credentials) +char const * wf_impl_credentials_type( + struct wf_credentials const * credentials) { return credentials->type; } -char const * wsfs_impl_credentials_get( - struct wsfs_credentials const * credentials, +char const * wf_impl_credentials_get( + struct wf_credentials const * credentials, char const * key) { char const * result = NULL; diff --git a/lib/webfuse/adapter/impl/credentials.h b/lib/webfuse/adapter/impl/credentials.h new file mode 100644 index 0000000..a2cd647 --- /dev/null +++ b/lib/webfuse/adapter/impl/credentials.h @@ -0,0 +1,36 @@ +#ifndef WF_ADAPTER_IMPL_CREDENTIALS_H +#define WF_ADAPTER_IMPL_CREDENTIALS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_credentials +{ + char * type; + json_t * data; +}; + +extern void wf_impl_credentials_init( + struct wf_credentials * credentials, + char const * type, + json_t * data); + +extern void wf_impl_credentials_cleanup( + struct wf_credentials * credentials); + +extern char const * wf_impl_credentials_type( + struct wf_credentials const * credentials); + +extern char const * wf_impl_credentials_get( + struct wf_credentials const * credentials, + char const * key); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfs/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c similarity index 64% rename from lib/wsfs/adapter/impl/filesystem.c rename to lib/webfuse/adapter/impl/filesystem.c index 25f1ba8..2e9cce9 100644 --- a/lib/wsfs/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -1,6 +1,6 @@ -#include "wsfs/adapter/impl/filesystem.h" -#include "wsfs/adapter/impl/operations.h" -#include "wsfs/adapter/impl/jsonrpc/server.h" +#include "webfuse/adapter/impl/filesystem.h" +#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/jsonrpc/server.h" #include #include @@ -8,18 +8,18 @@ static struct fuse_lowlevel_ops const filesystem_operations = { - .lookup = &wsfs_impl_operation_lookup, - .getattr = &wsfs_impl_operation_getattr, - .readdir = &wsfs_impl_operation_readdir, - .open = &wsfs_impl_operation_open, - .release = &wsfs_impl_operation_close, - .read = &wsfs_impl_operation_read + .lookup = &wf_impl_operation_lookup, + .getattr = &wf_impl_operation_getattr, + .readdir = &wf_impl_operation_readdir, + .open = &wf_impl_operation_open, + .release = &wf_impl_operation_close, + .read = &wf_impl_operation_read }; -bool wsfs_impl_filesystem_init( - struct wsfs_impl_filesystem * filesystem, - struct wsfs_impl_jsonrpc_server * rpc, +bool wf_impl_filesystem_init( + struct wf_impl_filesystem * filesystem, + struct wf_impl_jsonrpc_server * rpc, char * mount_point) { bool result = false; @@ -46,8 +46,8 @@ bool wsfs_impl_filesystem_init( return result; } -void wsfs_impl_filesystem_cleanup( - struct wsfs_impl_filesystem * filesystem) +void wf_impl_filesystem_cleanup( + struct wf_impl_filesystem * filesystem) { if (NULL != filesystem->session) { @@ -61,14 +61,14 @@ void wsfs_impl_filesystem_cleanup( fuse_opt_free_args(&filesystem->args); } -int wsfs_impl_filesystem_get_fd( - struct wsfs_impl_filesystem * filesystem) +int wf_impl_filesystem_get_fd( + struct wf_impl_filesystem * filesystem) { return fuse_session_fd(filesystem->session); } -void wsfs_impl_filesystem_process_request( - struct wsfs_impl_filesystem * filesystem) +void wf_impl_filesystem_process_request( + struct wf_impl_filesystem * filesystem) { int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer); if (0 < result) diff --git a/lib/webfuse/adapter/impl/filesystem.h b/lib/webfuse/adapter/impl/filesystem.h new file mode 100644 index 0000000..0a3adad --- /dev/null +++ b/lib/webfuse/adapter/impl/filesystem.h @@ -0,0 +1,45 @@ +#ifndef WF_ADAPTER_IMPL_FILESYSTEM_H +#define WF_ADAPTER_IMPL_FILESYSTEM_H + +#ifndef __cplusplus +#include +#endif + +#include "webfuse/adapter/impl/fuse_wrapper.h" +#include "webfuse/adapter/impl/operations.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_impl_jsonrpc_server; + +struct wf_impl_filesystem +{ + struct fuse_args args; + struct fuse_session * session; + struct fuse_buf buffer; + struct wf_impl_operations_context user_data; +}; + +extern bool wf_impl_filesystem_init( + struct wf_impl_filesystem * filesystem, + struct wf_impl_jsonrpc_server * rpc, + char * mount_point); + +extern void wf_impl_filesystem_cleanup( + struct wf_impl_filesystem * filesystem); + +extern int wf_impl_filesystem_get_fd( + struct wf_impl_filesystem * filesystem); + +extern void wf_impl_filesystem_process_request( + struct wf_impl_filesystem * filesystem); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/wsfs/adapter/impl/fuse_wrapper.h b/lib/webfuse/adapter/impl/fuse_wrapper.h similarity index 67% rename from lib/wsfs/adapter/impl/fuse_wrapper.h rename to lib/webfuse/adapter/impl/fuse_wrapper.h index 0cba5c2..719d758 100644 --- a/lib/wsfs/adapter/impl/fuse_wrapper.h +++ b/lib/webfuse/adapter/impl/fuse_wrapper.h @@ -1,5 +1,5 @@ -#ifndef WSFS_ADAPTER_IMPL_FUSE_H -#define WSFS_ADAPTER_IMPL_FUSE_H +#ifndef WF_ADAPTER_IMPL_FUSE_H +#define WF_ADAPTER_IMPL_FUSE_H #ifdef __cplusplus extern "C" { diff --git a/lib/webfuse/adapter/impl/jsonrpc/method.c b/lib/webfuse/adapter/impl/jsonrpc/method.c new file mode 100644 index 0000000..ddc7df5 --- /dev/null +++ b/lib/webfuse/adapter/impl/jsonrpc/method.c @@ -0,0 +1,28 @@ +#include "webfuse/adapter/impl/jsonrpc/method_intern.h" + +#include +#include + +struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create( + char const * name, + wf_impl_jsonrpc_method_invoke_fn * invoke, + void * user_data) +{ + struct wf_impl_jsonrpc_method * method = malloc(sizeof(struct wf_impl_jsonrpc_method)); + if (NULL != method) + { + method->next = NULL; + method->name = strdup(name); + method->invoke = invoke; + method->user_data = user_data; + } + + return method; +} + +void wf_impl_jsonrpc_method_dispose( + struct wf_impl_jsonrpc_method * method) +{ + free(method->name); + free(method); +} diff --git a/lib/wsfs/adapter/impl/jsonrpc/method.h b/lib/webfuse/adapter/impl/jsonrpc/method.h similarity index 52% rename from lib/wsfs/adapter/impl/jsonrpc/method.h rename to lib/webfuse/adapter/impl/jsonrpc/method.h index fe3db02..f102f60 100644 --- a/lib/wsfs/adapter/impl/jsonrpc/method.h +++ b/lib/webfuse/adapter/impl/jsonrpc/method.h @@ -1,25 +1,25 @@ -#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H -#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H +#ifndef WF_ADAPTER_IMPL_JSONRPC_METHOD_H +#define WF_ADAPTER_IMPL_JSONRPC_METHOD_H #ifndef __cplusplus #include #endif #include -#include "wsfs/core/status.h" +#include "webfuse/core/status.h" #ifdef __cplusplus extern "C" { #endif -typedef bool wsfs_impl_jsonrpc_method_invoke_fn( +typedef bool wf_impl_jsonrpc_method_invoke_fn( void * user_data, struct json_t const * method_call); -typedef void wsfs_impl_jsonrpc_method_finished_fn( +typedef void wf_impl_jsonrpc_method_finished_fn( void * user_data, - wsfs_status status, + wf_status status, struct json_t const * result); #ifdef __cplusplus diff --git a/lib/webfuse/adapter/impl/jsonrpc/method_intern.h b/lib/webfuse/adapter/impl/jsonrpc/method_intern.h new file mode 100644 index 0000000..0a1190d --- /dev/null +++ b/lib/webfuse/adapter/impl/jsonrpc/method_intern.h @@ -0,0 +1,31 @@ +#ifndef WF_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H +#define WF_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H + +#include "webfuse/adapter/impl/jsonrpc/method.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_impl_jsonrpc_method +{ + struct wf_impl_jsonrpc_method * next; + char * name; + wf_impl_jsonrpc_method_invoke_fn * invoke; + void * user_data; +}; + +extern struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create( + char const * name, + wf_impl_jsonrpc_method_invoke_fn * invoke, + void * user_data); + +extern void wf_impl_jsonrpc_method_dispose( + struct wf_impl_jsonrpc_method * method); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsfs/adapter/impl/jsonrpc/request.c b/lib/webfuse/adapter/impl/jsonrpc/request.c similarity index 90% rename from lib/wsfs/adapter/impl/jsonrpc/request.c rename to lib/webfuse/adapter/impl/jsonrpc/request.c index 4894d41..710db11 100644 --- a/lib/wsfs/adapter/impl/jsonrpc/request.c +++ b/lib/webfuse/adapter/impl/jsonrpc/request.c @@ -1,6 +1,6 @@ -#include "wsfs/adapter/impl/jsonrpc/request.h" +#include "webfuse/adapter/impl/jsonrpc/request.h" -json_t * wsfs_impl_jsonrpc_request_create( +json_t * wf_impl_jsonrpc_request_create( char const * method, int id, char const * param_info, diff --git a/lib/wsfs/adapter/impl/jsonrpc/request.h b/lib/webfuse/adapter/impl/jsonrpc/request.h similarity index 70% rename from lib/wsfs/adapter/impl/jsonrpc/request.h rename to lib/webfuse/adapter/impl/jsonrpc/request.h index 69a888d..28c9f3d 100644 --- a/lib/wsfs/adapter/impl/jsonrpc/request.h +++ b/lib/webfuse/adapter/impl/jsonrpc/request.h @@ -1,5 +1,5 @@ -#ifndef WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H -#define WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H +#ifndef WF_ADAPTER_IMPL_JSONRPC_REQUEST_H +#define WF_ADAPTER_IMPL_JSONRPC_REQUEST_H #ifndef __cplusplus #include @@ -18,7 +18,7 @@ extern "C" { #endif -extern json_t * wsfs_impl_jsonrpc_request_create( +extern json_t * wf_impl_jsonrpc_request_create( char const * method, int id, char const * param_info, diff --git a/lib/wsfs/adapter/impl/jsonrpc/response.c b/lib/webfuse/adapter/impl/jsonrpc/response.c similarity index 70% rename from lib/wsfs/adapter/impl/jsonrpc/response.c rename to lib/webfuse/adapter/impl/jsonrpc/response.c index f0969d9..74f230f 100644 --- a/lib/wsfs/adapter/impl/jsonrpc/response.c +++ b/lib/webfuse/adapter/impl/jsonrpc/response.c @@ -1,30 +1,30 @@ -#include "wsfs/adapter/impl/jsonrpc/response.h" +#include "webfuse/adapter/impl/jsonrpc/response.h" -void wsfs_impl_jsonrpc_response_init( - struct wsfs_impl_jsonrpc_response * result, +void wf_impl_jsonrpc_response_init( + struct wf_impl_jsonrpc_response * result, char const * buffer, size_t length) { - result->status = WSFS_BAD; + result->status = WF_BAD; result->id = -1; result->result = NULL; json_t * response = json_loadb(buffer, length, 0, NULL); if (NULL == response) { - result->status = WSFS_BAD_FORMAT; + result->status = WF_BAD_FORMAT; return; } json_t * id_holder = json_object_get(response, "id"); if ((NULL == id_holder) || (!json_is_integer(id_holder))) { - result->status = WSFS_BAD_FORMAT; + result->status = WF_BAD_FORMAT; json_decref(response); return; } - result->status = WSFS_GOOD; + result->status = WF_GOOD; result->id = json_integer_value(id_holder); result->result = json_object_get(response, "result"); if (NULL != result->result) @@ -33,7 +33,7 @@ void wsfs_impl_jsonrpc_response_init( } else { - result->status = WSFS_BAD_FORMAT; + result->status = WF_BAD_FORMAT; json_t * error = json_object_get(response, "error"); if (NULL != error) @@ -49,8 +49,8 @@ void wsfs_impl_jsonrpc_response_init( json_decref(response); } -void wsfs_impl_jsonrpc_response_cleanup( - struct wsfs_impl_jsonrpc_response * response) +void wf_impl_jsonrpc_response_cleanup( + struct wf_impl_jsonrpc_response * response) { if (NULL != response->result) { diff --git a/lib/webfuse/adapter/impl/jsonrpc/response.h b/lib/webfuse/adapter/impl/jsonrpc/response.h new file mode 100644 index 0000000..b537994 --- /dev/null +++ b/lib/webfuse/adapter/impl/jsonrpc/response.h @@ -0,0 +1,38 @@ +#ifndef WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H +#define WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H + +#ifndef __cplusplus +#include +#else +#include +using std::size_t; +#endif + +#include +#include "webfuse/core/status.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wf_impl_jsonrpc_response +{ + wf_status status; + int id; + json_t * result; +}; + +extern void wf_impl_jsonrpc_response_init( + struct wf_impl_jsonrpc_response * response, + char const * buffer, + size_t buffer_length); + +extern void wf_impl_jsonrpc_response_cleanup( + struct wf_impl_jsonrpc_response * response); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/lib/webfuse/adapter/impl/jsonrpc/server.c b/lib/webfuse/adapter/impl/jsonrpc/server.c new file mode 100644 index 0000000..613e27d --- /dev/null +++ b/lib/webfuse/adapter/impl/jsonrpc/server.c @@ -0,0 +1,186 @@ +#include "webfuse/adapter/impl/jsonrpc/server.h" +#include + +#include "webfuse/adapter/impl/jsonrpc/method_intern.h" +#include "webfuse/adapter/impl/jsonrpc/request.h" +#include "webfuse/adapter/impl/jsonrpc/response.h" + +#define WF_DEFAULT_TIMEOUT (10 * 1000) + +static struct wf_impl_jsonrpc_method const * wf_impl_jsonrpc_server_getmethod( + struct wf_impl_jsonrpc_server * server, + char const * name) +{ + struct wf_impl_jsonrpc_method * method = server->methods; + while ((NULL != method) && (0 == strcmp(name, method->name))) + { + method = method->next; + } + + return method; +} + +static void wf_impl_jsonrpc_server_timeout( + struct wf_impl_timer * timer) +{ + struct wf_impl_jsonrpc_server * server = timer->user_data; + + if (server->request.is_pending) + { + wf_impl_jsonrpc_method_finished_fn * finished = server->request.finished; + void * user_data = server->request.user_data; + + server->request.is_pending = false; + server->request.id = 0; + server->request.user_data = NULL; + server->request.finished = NULL; + wf_impl_timer_cancel(&server->request.timer); + + finished(user_data, WF_BAD_TIMEOUT, NULL); + } +} + +void wf_impl_jsonrpc_server_init( + struct wf_impl_jsonrpc_server * server, + struct wf_impl_timeout_manager * timeout_manager) +{ + server->methods = NULL; + server->request.is_pending = false; + + wf_impl_timer_init(&server->request.timer, timeout_manager); +} + +void wf_impl_jsonrpc_server_cleanup( + struct wf_impl_jsonrpc_server * server) +{ + wf_impl_timer_cleanup(&server->request.timer); + + if (server->request.is_pending) + { + server->request.finished(server->request.user_data, WF_BAD, NULL); + server->request.is_pending = false; + } + + struct wf_impl_jsonrpc_method * method = server->methods; + while (NULL != method) + { + struct wf_impl_jsonrpc_method * next = method->next; + method->next = NULL; + wf_impl_jsonrpc_method_dispose(method); + method = next; + } + server->methods = NULL; +} + +void wf_impl_jsonrpc_server_add( + struct wf_impl_jsonrpc_server * server, + char const * name, + wf_impl_jsonrpc_method_invoke_fn * invoke, + void * user_data) +{ + struct wf_impl_jsonrpc_method * method = wf_impl_jsonrpc_method_create(name, invoke, user_data); + method->next = server->methods; + server->methods = method; +} + +void wf_impl_jsonrpc_server_invoke( + struct wf_impl_jsonrpc_server * server, + wf_impl_jsonrpc_method_finished_fn * finished, + void * user_data, + char const * method_name, + char const * param_info, + ... +) +{ + if (!server->request.is_pending) + { + struct wf_impl_jsonrpc_method const * method = wf_impl_jsonrpc_server_getmethod(server, method_name); + if (NULL != method) + { + server->request.is_pending = true; + server->request.finished = finished; + server->request.user_data = user_data; + server->request.id = 42; + wf_impl_timer_start(&server->request.timer, wf_impl_timepoint_in_msec(WF_DEFAULT_TIMEOUT), + &wf_impl_jsonrpc_server_timeout, server); + + va_list args; + va_start(args, param_info); + json_t * request = wf_impl_jsonrpc_request_create(method_name, server->request.id, param_info, args); + va_end(args); + if (NULL != request) + { + if (!method->invoke(method->user_data, request)) + { + server->request.is_pending = false; + server->request.finished = NULL; + server->request.user_data = NULL; + server->request.id = 0; + wf_impl_timer_cancel(&server->request.timer); + + finished(user_data, WF_BAD, NULL); + } + json_decref(request); + } + } + else + { + finished(user_data, WF_BAD_NOTIMPLEMENTED, NULL); + } + } + else + { + finished(user_data, WF_BAD_BUSY, NULL); + } +} + +extern void wf_impl_jsonrpc_server_notify( + struct wf_impl_jsonrpc_server * server, + char const * method_name, + char const * param_info, + ... +) +{ + struct wf_impl_jsonrpc_method const * method = wf_impl_jsonrpc_server_getmethod(server, method_name); + if (NULL != method) + { + + va_list args; + va_start(args, param_info); + json_t * request = wf_impl_jsonrpc_request_create(method_name, 0, param_info, args); + va_end(args); + if (NULL != request) + { + method->invoke(method->user_data, request); + json_decref(request); + } + } + +} + + +void wf_impl_jsonrpc_server_onresult( + struct wf_impl_jsonrpc_server * server, + char const * message, + size_t length) +{ + struct wf_impl_jsonrpc_response response; + wf_impl_jsonrpc_response_init(&response, message, length); + + if ((server->request.is_pending) && (response.id == server->request.id)) + { + wf_impl_jsonrpc_method_finished_fn * finished = server->request.finished; + void * user_data = server->request.user_data; + + server->request.is_pending = false; + server->request.id = 0; + server->request.user_data = NULL; + server->request.finished = NULL; + wf_impl_timer_cancel(&server->request.timer); + + finished(user_data, response.status, response.result); + } + + wf_impl_jsonrpc_response_cleanup(&response); +} + diff --git a/lib/webfuse/adapter/impl/jsonrpc/server.h b/lib/webfuse/adapter/impl/jsonrpc/server.h new file mode 100644 index 0000000..e5e53cb --- /dev/null +++ b/lib/webfuse/adapter/impl/jsonrpc/server.h @@ -0,0 +1,77 @@ +#ifndef WF_ADAPTER_IMPL_JSONRPC_SERVER_H +#define WF_ADAPTER_IMPL_JSONRPC_SERVER_H + +#ifndef __cplusplus +#include +#include +#include +#else +#include +#include +using std::size_t; +#endif + +#include +#include "webfuse/adapter/impl/jsonrpc/method.h" +#include "webfuse/adapter/impl/time/timeout_manager.h" +#include "webfuse/adapter/impl/time/timer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wf_impl_jsonrpc_request +{ + bool is_pending; + wf_impl_jsonrpc_method_finished_fn * finished; + void * user_data; + int id; + struct wf_impl_timer timer; +}; + +struct wf_impl_jsonrpc_server +{ + struct wf_impl_jsonrpc_method * methods; + struct wf_impl_jsonrpc_request request; +}; + +extern void wf_impl_jsonrpc_server_init( + struct wf_impl_jsonrpc_server * server, + struct wf_impl_timeout_manager * manager); + +extern void wf_impl_jsonrpc_server_cleanup( + struct wf_impl_jsonrpc_server * server); + +extern void wf_impl_jsonrpc_server_add( + struct wf_impl_jsonrpc_server * server, + char const * name, + wf_impl_jsonrpc_method_invoke_fn * invoke, + void * user_data ); + +extern void wf_impl_jsonrpc_server_invoke( + struct wf_impl_jsonrpc_server * server, + wf_impl_jsonrpc_method_finished_fn * finished, + void * user_data, + char const * method_name, + char const * param_info, + ... +); + +extern void wf_impl_jsonrpc_server_notify( + struct wf_impl_jsonrpc_server * server, + char const * method_name, + char const * param_info, + ... +); + +extern void wf_impl_jsonrpc_server_onresult( + struct wf_impl_jsonrpc_server * server, + char const * message, + size_t length); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/wsfs/adapter/impl/jsonrpc/util.c b/lib/webfuse/adapter/impl/jsonrpc/util.c similarity index 59% rename from lib/wsfs/adapter/impl/jsonrpc/util.c rename to lib/webfuse/adapter/impl/jsonrpc/util.c index fa00633..439eddb 100644 --- a/lib/wsfs/adapter/impl/jsonrpc/util.c +++ b/lib/webfuse/adapter/impl/jsonrpc/util.c @@ -1,6 +1,6 @@ -#include "wsfs/adapter/impl/jsonrpc/util.h" +#include "webfuse/adapter/impl/jsonrpc/util.h" -int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value) +int wf_impl_json_get_int(json_t const * object, char const * key, int default_value) { int result = default_value; diff --git a/lib/webfuse/adapter/impl/jsonrpc/util.h b/lib/webfuse/adapter/impl/jsonrpc/util.h new file mode 100644 index 0000000..0d5c6ab --- /dev/null +++ b/lib/webfuse/adapter/impl/jsonrpc/util.h @@ -0,0 +1,17 @@ +#ifndef WF_ADAPTER_IMPL_JSON_UTIL_H +#define WF_ADAPTER_IMPL_JSON_UTIL_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern int wf_impl_json_get_int(json_t const * object, char const * key, int default_value); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c new file mode 100644 index 0000000..fcf0645 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -0,0 +1,21 @@ +#include "webfuse/adapter/impl/operations.h" + +#include +#include +#include + +#include "webfuse/adapter/impl/jsonrpc/server.h" +#include "webfuse/core/util.h" + +void wf_impl_operation_close( + fuse_req_t request, + fuse_ino_t inode, + struct fuse_file_info * file_info) +{ + struct wf_impl_operations_context * user_data = fuse_req_userdata(request); + struct wf_impl_jsonrpc_server * rpc = user_data->rpc; + + int handle = (int) (file_info->fh & INT_MAX); + wf_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags); + fuse_reply_err(request, 0); +} diff --git a/lib/wsfs/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c similarity index 55% rename from lib/wsfs/adapter/impl/operation/getattr.c rename to lib/webfuse/adapter/impl/operation/getattr.c index a8c6b47..6a3c359 100644 --- a/lib/wsfs/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operations.h" #include #include @@ -7,11 +7,11 @@ #include #include -#include "wsfs/adapter/impl/jsonrpc/server.h" -#include "wsfs/adapter/impl/jsonrpc/util.h" -#include "wsfs/core/util.h" +#include "webfuse/adapter/impl/jsonrpc/server.h" +#include "webfuse/adapter/impl/jsonrpc/util.h" +#include "webfuse/core/util.h" -struct wsfs_impl_operation_getattr_context +struct wf_impl_operation_getattr_context { fuse_req_t request; double timeout; @@ -19,12 +19,12 @@ struct wsfs_impl_operation_getattr_context gid_t gid; }; -static void wsfs_impl_operation_getattr_finished( +static void wf_impl_operation_getattr_finished( void * user_data, - wsfs_status status, + wf_status status, json_t const * data) { - struct wsfs_impl_operation_getattr_context * context = user_data; + struct wf_impl_operation_getattr_context * context = user_data; struct stat buffer; if (NULL != data) @@ -50,19 +50,19 @@ static void wsfs_impl_operation_getattr_finished( buffer.st_uid = context->uid; buffer.st_gid = context->gid; buffer.st_nlink = 1; - buffer.st_size = wsfs_impl_json_get_int(data, "size", 0); - buffer.st_atime = wsfs_impl_json_get_int(data, "atime", 0); - buffer.st_mtime = wsfs_impl_json_get_int(data, "mtime", 0); - buffer.st_ctime = wsfs_impl_json_get_int(data, "ctime", 0); + buffer.st_size = wf_impl_json_get_int(data, "size", 0); + buffer.st_atime = wf_impl_json_get_int(data, "atime", 0); + buffer.st_mtime = wf_impl_json_get_int(data, "mtime", 0); + buffer.st_ctime = wf_impl_json_get_int(data, "ctime", 0); } else { - status = WSFS_BAD_FORMAT; + status = WF_BAD_FORMAT; } } - if (WSFS_GOOD == status) + if (WF_GOOD == status) { fuse_reply_attr(context->request, &buffer, context->timeout); } @@ -74,20 +74,20 @@ static void wsfs_impl_operation_getattr_finished( free(context); } -void wsfs_impl_operation_getattr ( +void wf_impl_operation_getattr ( fuse_req_t request, fuse_ino_t inode, - struct fuse_file_info * WSFS_UNUSED_PARAM(file_info)) + struct fuse_file_info * WF_UNUSED_PARAM(file_info)) { struct fuse_ctx const * context = fuse_req_ctx(request); - struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; + struct wf_impl_operations_context * user_data = fuse_req_userdata(request); + struct wf_impl_jsonrpc_server * rpc = user_data->rpc; - struct wsfs_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wsfs_impl_operation_getattr_context)); + struct wf_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wf_impl_operation_getattr_context)); getattr_context->request = request; getattr_context->uid = context->uid; getattr_context->gid = context->gid; getattr_context->timeout = user_data->timeout; - wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_getattr_finished, getattr_context, "getattr", "i", inode); + wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "i", inode); } diff --git a/lib/wsfs/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c similarity index 61% rename from lib/wsfs/adapter/impl/operation/lookup.c rename to lib/webfuse/adapter/impl/operation/lookup.c index c1e06d9..321be8a 100644 --- a/lib/wsfs/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operations.h" #include #include @@ -10,11 +10,11 @@ #include -#include "wsfs/adapter/impl/jsonrpc/server.h" -#include "wsfs/adapter/impl/jsonrpc/util.h" -#include "wsfs/core/util.h" +#include "webfuse/adapter/impl/jsonrpc/server.h" +#include "webfuse/adapter/impl/jsonrpc/util.h" +#include "webfuse/core/util.h" -struct wsfs_impl_operation_lookup_context +struct wf_impl_operation_lookup_context { fuse_req_t request; double timeout; @@ -22,13 +22,13 @@ struct wsfs_impl_operation_lookup_context gid_t gid; }; -static void wsfs_impl_operation_lookup_finished( +static void wf_impl_operation_lookup_finished( void * user_data, - wsfs_status status, + wf_status status, json_t const * data ) { - struct wsfs_impl_operation_lookup_context * context = user_data; + struct wf_impl_operation_lookup_context * context = user_data; struct fuse_entry_param buffer; if (NULL != data) @@ -60,18 +60,18 @@ static void wsfs_impl_operation_lookup_finished( buffer.attr.st_uid = context->uid; buffer.attr.st_gid = context->gid; buffer.attr.st_nlink = 1; - buffer.attr.st_size = wsfs_impl_json_get_int(data, "size", 0); - buffer.attr.st_atime = wsfs_impl_json_get_int(data, "atime", 0); - buffer.attr.st_mtime = wsfs_impl_json_get_int(data, "mtime", 0); - buffer.attr.st_ctime = wsfs_impl_json_get_int(data, "ctime", 0); + buffer.attr.st_size = wf_impl_json_get_int(data, "size", 0); + buffer.attr.st_atime = wf_impl_json_get_int(data, "atime", 0); + buffer.attr.st_mtime = wf_impl_json_get_int(data, "mtime", 0); + buffer.attr.st_ctime = wf_impl_json_get_int(data, "ctime", 0); } else { - status = WSFS_BAD_FORMAT; + status = WF_BAD_FORMAT; } } - if (WSFS_GOOD == status) + if (WF_GOOD == status) { fuse_reply_entry(context->request, &buffer); } @@ -83,20 +83,20 @@ static void wsfs_impl_operation_lookup_finished( free(context); } -void wsfs_impl_operation_lookup ( +void wf_impl_operation_lookup ( fuse_req_t request, fuse_ino_t parent, char const * name) { struct fuse_ctx const * context = fuse_req_ctx(request); - struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; + struct wf_impl_operations_context * user_data = fuse_req_userdata(request); + struct wf_impl_jsonrpc_server * rpc = user_data->rpc; - struct wsfs_impl_operation_lookup_context * lookup_context = malloc(sizeof(struct wsfs_impl_operation_lookup_context)); + struct wf_impl_operation_lookup_context * lookup_context = malloc(sizeof(struct wf_impl_operation_lookup_context)); lookup_context->request = request; lookup_context->uid = context->uid; lookup_context->gid = context->gid; lookup_context->timeout = user_data->timeout; - wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name); + wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name); } diff --git a/lib/wsfs/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c similarity index 55% rename from lib/wsfs/adapter/impl/operation/open.c rename to lib/webfuse/adapter/impl/operation/open.c index 63c8e91..b9e78d4 100644 --- a/lib/wsfs/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -1,16 +1,16 @@ -#include "wsfs/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operations.h" #include #include #include -#include "wsfs/adapter/impl/jsonrpc/server.h" -#include "wsfs/core/util.h" -#include "wsfs/core/status.h" +#include "webfuse/adapter/impl/jsonrpc/server.h" +#include "webfuse/core/util.h" +#include "webfuse/core/status.h" -static void wsfs_impl_operation_open_finished( +static void wf_impl_operation_open_finished( void * user_data, - wsfs_status status, + wf_status status, json_t const * result) { fuse_req_t request = user_data; @@ -26,11 +26,11 @@ static void wsfs_impl_operation_open_finished( } else { - status = WSFS_BAD_FORMAT; + status = WF_BAD_FORMAT; } } - if (WSFS_GOOD == status) + if (WF_GOOD == status) { fuse_reply_open(request, &file_info); } @@ -41,13 +41,13 @@ static void wsfs_impl_operation_open_finished( } -void wsfs_impl_operation_open( +void wf_impl_operation_open( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info * file_info) { - struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; + struct wf_impl_operations_context * user_data = fuse_req_userdata(request); + struct wf_impl_jsonrpc_server * rpc = user_data->rpc; - wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags); + wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags); } diff --git a/lib/wsfs/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c similarity index 61% rename from lib/wsfs/adapter/impl/operation/read.c rename to lib/webfuse/adapter/impl/operation/read.c index d92bf40..7be1b01 100644 --- a/lib/wsfs/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operations.h" #include #include @@ -6,17 +6,17 @@ #include #include -#include "wsfs/adapter/impl/jsonrpc/server.h" +#include "webfuse/adapter/impl/jsonrpc/server.h" -#define WSFS_MAX_READ_LENGTH 4096 +#define WF_MAX_READ_LENGTH 4096 -static char * wsfs_impl_fill_buffer( +static char * wf_impl_fill_buffer( char const * data, char const * format, size_t count, - wsfs_status * status) + wf_status * status) { - *status = WSFS_GOOD; + *status = WF_GOOD; char * buffer = malloc(count + 1); if ((NULL != buffer) && (0 < count)) @@ -31,14 +31,14 @@ static char * wsfs_impl_fill_buffer( } else { - *status = WSFS_BAD; + *status = WF_BAD; } } return buffer; } -static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status status, json_t const * data) +static void wf_impl_operation_read_finished(void * user_data, wf_status status, json_t const * data) { fuse_req_t request = user_data; @@ -58,15 +58,15 @@ static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status stat char const * const format = json_string_value(format_holder); length = (size_t) json_integer_value(count_holder); - buffer = wsfs_impl_fill_buffer(data, format, length, &status); + buffer = wf_impl_fill_buffer(data, format, length, &status); } else { - status = WSFS_BAD_FORMAT; + status = WF_BAD_FORMAT; } } - if (WSFS_GOOD == status) + if (WF_GOOD == status) { fuse_reply_buf(request, buffer, length); } @@ -79,17 +79,17 @@ static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status stat } -void wsfs_impl_operation_read( +void wf_impl_operation_read( fuse_req_t request, fuse_ino_t inode, size_t size, off_t offset, struct fuse_file_info * file_info) { - struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; + struct wf_impl_operations_context * user_data = fuse_req_userdata(request); + struct wf_impl_jsonrpc_server * rpc = user_data->rpc; - int const length = (size <= WSFS_MAX_READ_LENGTH) ? (int) size : WSFS_MAX_READ_LENGTH; + int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH; int handle = (file_info->fh & INT_MAX); - wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length); + wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length); } diff --git a/lib/wsfs/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c similarity index 58% rename from lib/wsfs/adapter/impl/operation/readdir.c rename to lib/webfuse/adapter/impl/operation/readdir.c index 16c6640..8c027ee 100644 --- a/lib/wsfs/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operations.h" #include #include @@ -8,43 +8,43 @@ #include #include -#include "wsfs/adapter/impl/jsonrpc/server.h" -#include "wsfs/core/util.h" +#include "webfuse/adapter/impl/jsonrpc/server.h" +#include "webfuse/core/util.h" -#define WSFS_DIRBUFFER_INITIAL_SIZE 1024 +#define WF_DIRBUFFER_INITIAL_SIZE 1024 -struct wsfs_impl_operation_readdir_context +struct wf_impl_operation_readdir_context { fuse_req_t request; size_t size; off_t offset; }; -struct wsfs_impl_dirbuffer +struct wf_impl_dirbuffer { char * data; size_t position; size_t capacity; }; -static void wsfs_impl_dirbuffer_init( - struct wsfs_impl_dirbuffer * buffer) +static void wf_impl_dirbuffer_init( + struct wf_impl_dirbuffer * buffer) { - buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE); + buffer->data = malloc(WF_DIRBUFFER_INITIAL_SIZE); buffer->position = 0; - buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE; + buffer->capacity = WF_DIRBUFFER_INITIAL_SIZE; } -static void wsfs_impl_dirbuffer_dispose( - struct wsfs_impl_dirbuffer * buffer) +static void wf_impl_dirbuffer_dispose( + struct wf_impl_dirbuffer * buffer) { free(buffer->data); } -static void wsfs_impl_dirbuffer_add( +static void wf_impl_dirbuffer_add( fuse_req_t request, - struct wsfs_impl_dirbuffer * buffer, + struct wf_impl_dirbuffer * buffer, char const * name, fuse_ino_t inode) { @@ -66,20 +66,20 @@ static void wsfs_impl_dirbuffer_add( buffer->position += size; } -static size_t wsfs_impl_min(size_t a, size_t b) +static size_t wf_impl_min(size_t a, size_t b) { return (a < b) ? a : b; } -static void wsfs_impl_operation_readdir_finished( +static void wf_impl_operation_readdir_finished( void * user_data, - wsfs_status status, + wf_status status, json_t const * result) { - struct wsfs_impl_operation_readdir_context * context = user_data; + struct wf_impl_operation_readdir_context * context = user_data; - struct wsfs_impl_dirbuffer buffer; - wsfs_impl_dirbuffer_init(&buffer); + struct wf_impl_dirbuffer buffer; + wf_impl_dirbuffer_init(&buffer); if (NULL != result) { @@ -100,19 +100,19 @@ static void wsfs_impl_operation_readdir_finished( { char const * name = json_string_value(name_holder); fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder); - wsfs_impl_dirbuffer_add(context->request, &buffer, name, entry_inode); + wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode); } } } } } - if (WSFS_GOOD == status) + if (WF_GOOD == status) { if (((size_t) context->offset) < buffer.position) { fuse_reply_buf(context->request, &buffer.data[context->offset], - wsfs_impl_min(buffer.position - context->offset, context->size)); + wf_impl_min(buffer.position - context->offset, context->size)); } else { @@ -125,23 +125,23 @@ static void wsfs_impl_operation_readdir_finished( fuse_reply_err(context->request, ENOENT); } - wsfs_impl_dirbuffer_dispose(&buffer); + wf_impl_dirbuffer_dispose(&buffer); free(context); } -void wsfs_impl_operation_readdir ( +void wf_impl_operation_readdir ( fuse_req_t request, fuse_ino_t inode, size_t size, off_t offset, - struct fuse_file_info * WSFS_UNUSED_PARAM(file_info)) + struct fuse_file_info * WF_UNUSED_PARAM(file_info)) { - struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; - struct wsfs_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_impl_operation_readdir_context)); + struct wf_impl_operations_context * user_data = fuse_req_userdata(request); + struct wf_impl_jsonrpc_server * rpc = user_data->rpc; + struct wf_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wf_impl_operation_readdir_context)); readdir_context->request = request; readdir_context->size = size; readdir_context->offset = offset; - wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode); + wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode); } diff --git a/lib/wsfs/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h similarity index 56% rename from lib/wsfs/adapter/impl/operations.h rename to lib/webfuse/adapter/impl/operations.h index b2eef91..74875ae 100644 --- a/lib/wsfs/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -1,48 +1,48 @@ -#ifndef WSFS_ADAPTER_IMPL_OPERATIONS_H -#define WSFS_ADAPTER_IMPL_OPERATIONS_H +#ifndef WF_ADAPTER_IMPL_OPERATIONS_H +#define WF_ADAPTER_IMPL_OPERATIONS_H -#include "wsfs/adapter/impl/fuse_wrapper.h" +#include "webfuse/adapter/impl/fuse_wrapper.h" #ifdef __cplusplus extern "C" { #endif -struct wsfs_impl_jsonrpc_server; +struct wf_impl_jsonrpc_server; -struct wsfs_impl_operations_context +struct wf_impl_operations_context { - struct wsfs_impl_jsonrpc_server * rpc; + struct wf_impl_jsonrpc_server * rpc; double timeout; }; -extern void wsfs_impl_operation_lookup ( +extern void wf_impl_operation_lookup ( fuse_req_t req, fuse_ino_t parent, char const * name); -extern void wsfs_impl_operation_getattr ( +extern void wf_impl_operation_getattr ( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info *file_info); -extern void wsfs_impl_operation_readdir ( +extern void wf_impl_operation_readdir ( fuse_req_t request, fuse_ino_t inode, size_t size, off_t offset, struct fuse_file_info *file_info); -extern void wsfs_impl_operation_open( +extern void wf_impl_operation_open( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info * file_info); -extern void wsfs_impl_operation_close( +extern void wf_impl_operation_close( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info * file_info); -extern void wsfs_impl_operation_read( +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); diff --git a/lib/wsfs/adapter/impl/server.c b/lib/webfuse/adapter/impl/server.c similarity index 57% rename from lib/wsfs/adapter/impl/server.c rename to lib/webfuse/adapter/impl/server.c index 3777bbc..5bddb10 100644 --- a/lib/wsfs/adapter/impl/server.c +++ b/lib/webfuse/adapter/impl/server.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/server.h" +#include "webfuse/adapter/server.h" #include #include @@ -8,40 +8,40 @@ #include #include -#include "wsfs/adapter/impl/server_config.h" -#include "wsfs/adapter/impl/server_protocol.h" +#include "webfuse/adapter/impl/server_config.h" +#include "webfuse/adapter/impl/server_protocol.h" -#define WSFS_DISABLE_LWS_LOG 0 -#define WSFS_SERVER_PROTOCOL_COUNT 3 -#define WSFS_SERVER_TIMEOUT (1 * 1000) +#define WF_DISABLE_LWS_LOG 0 +#define WF_SERVER_PROTOCOL_COUNT 3 +#define WF_SERVER_TIMEOUT (1 * 1000) -struct wsfs_server +struct wf_server { - struct wsfs_server_config config; - struct wsfs_server_protocol protocol; - struct lws_protocols ws_protocols[WSFS_SERVER_PROTOCOL_COUNT]; + struct wf_server_config config; + struct wf_server_protocol protocol; + struct lws_protocols ws_protocols[WF_SERVER_PROTOCOL_COUNT]; struct lws_context * context; volatile bool shutdown_requested; struct lws_http_mount mount; struct lws_context_creation_info info; }; -static bool wsfs_impl_server_tls_enabled( - struct wsfs_server * server) +static bool wf_impl_server_tls_enabled( + struct wf_server * server) { return ((server->config.key_path != NULL) && (server->config.cert_path != NULL)); } -static struct lws_context * wsfs_impl_server_context_create( - struct wsfs_server * server) +static struct lws_context * wf_impl_server_context_create( + struct wf_server * server) { - lws_set_log_level(WSFS_DISABLE_LWS_LOG, NULL); + lws_set_log_level(WF_DISABLE_LWS_LOG, NULL); - memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WSFS_SERVER_PROTOCOL_COUNT); + memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT); server->ws_protocols[0].name = "http"; server->ws_protocols[0].callback = lws_callback_http_dummy; server->ws_protocols[1].name = "fs"; - wsfs_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]); + wf_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]); memset(&server->mount, 0, sizeof(struct lws_http_mount)); server->mount.mount_next = NULL, @@ -66,7 +66,7 @@ static struct lws_context * wsfs_impl_server_context_create( server->info.mounts = NULL; } - if (wsfs_impl_server_tls_enabled(server)) + if (wf_impl_server_tls_enabled(server)) { server->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; server->info.ssl_cert_filepath = server->config.cert_path; @@ -78,8 +78,8 @@ static struct lws_context * wsfs_impl_server_context_create( } -static bool wsfs_impl_server_check_mountpoint( - struct wsfs_server_config * config) +static bool wf_impl_server_check_mountpoint( + struct wf_server_config * config) { bool result = false; @@ -98,22 +98,22 @@ static bool wsfs_impl_server_check_mountpoint( return result; } -struct wsfs_server * wsfs_impl_server_create( - struct wsfs_server_config * config) +struct wf_server * wf_impl_server_create( + struct wf_server_config * config) { - struct wsfs_server * server = NULL; + struct wf_server * server = NULL; - if (wsfs_impl_server_check_mountpoint(config)) + if (wf_impl_server_check_mountpoint(config)) { - server = malloc(sizeof(struct wsfs_server)); + server = malloc(sizeof(struct wf_server)); if (NULL != server) { - if (wsfs_impl_server_protocol_init(&server->protocol, config->mount_point)) + if (wf_impl_server_protocol_init(&server->protocol, config->mount_point)) { server->shutdown_requested = false; - wsfs_impl_server_config_clone(config, &server->config); - wsfs_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); - server->context = wsfs_impl_server_context_create(server); + wf_impl_server_config_clone(config, &server->config); + wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); + server->context = wf_impl_server_context_create(server); } else { @@ -126,27 +126,27 @@ struct wsfs_server * wsfs_impl_server_create( return server; } -void wsfs_impl_server_dispose( - struct wsfs_server * server) +void wf_impl_server_dispose( + struct wf_server * server) { lws_context_destroy(server->context); - wsfs_impl_server_protocol_cleanup(&server->protocol); - wsfs_impl_server_config_cleanup(&server->config); + wf_impl_server_protocol_cleanup(&server->protocol); + wf_impl_server_config_cleanup(&server->config); free(server); } -void wsfs_impl_server_run( - struct wsfs_server * server) +void wf_impl_server_run( + struct wf_server * server) { int n = 0; while ((0 <= n) && (!server->shutdown_requested)) { - n = lws_service(server->context, WSFS_SERVER_TIMEOUT); + n = lws_service(server->context, WF_SERVER_TIMEOUT); } } -void wsfs_impl_server_shutdown( - struct wsfs_server * server) +void wf_impl_server_shutdown( + struct wf_server * server) { server->shutdown_requested = true; } diff --git a/lib/webfuse/adapter/impl/server.h b/lib/webfuse/adapter/impl/server.h new file mode 100644 index 0000000..57f6d4a --- /dev/null +++ b/lib/webfuse/adapter/impl/server.h @@ -0,0 +1,29 @@ +#ifndef WF_ADAPTER_IMPL_SERVER_H +#define WF_ADAPTER_IMPL_SERVER_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_server; +struct wf_server_config; + +extern struct wf_server * wf_impl_server_create( + struct wf_server_config * config); + +extern void wf_impl_server_dispose( + struct wf_server * server); + +extern void wf_impl_server_run( + struct wf_server * server); + +extern void wf_impl_server_shutdown( + struct wf_server * server); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/webfuse/adapter/impl/server_config.c b/lib/webfuse/adapter/impl/server_config.c new file mode 100644 index 0000000..7098dac --- /dev/null +++ b/lib/webfuse/adapter/impl/server_config.c @@ -0,0 +1,127 @@ +#include "webfuse/adapter/impl/server_config.h" + +#include +#include + +static char * wf_impl_server_config_strdup(char const * value) +{ + char * result = NULL; + if (NULL != value) + { + result = strdup(value); + } + + return result; +} + +void wf_impl_server_config_init( + struct wf_server_config * config) +{ + memset(config, 0, sizeof(struct wf_server_config)); + + wf_impl_authenticators_init(&config->authenticators); +} + +void wf_impl_server_config_cleanup( + struct wf_server_config * config) +{ + wf_impl_authenticators_cleanup(&config->authenticators); + + free(config->mount_point); + free(config->document_root); + free(config->key_path); + free(config->cert_path); + free(config->vhost_name); + + wf_impl_server_config_init(config); +} + +void wf_impl_server_config_clone( + struct wf_server_config * config, + struct wf_server_config * clone) +{ + clone->mount_point = wf_impl_server_config_strdup(config->mount_point); + clone->document_root = wf_impl_server_config_strdup(config->document_root); + clone->key_path = wf_impl_server_config_strdup(config->key_path); + clone->cert_path = wf_impl_server_config_strdup(config->cert_path); + clone->vhost_name = wf_impl_server_config_strdup(config->vhost_name); + clone->port = config->port; + + wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators); +} + +struct wf_server_config * wf_impl_server_config_create(void) +{ + struct wf_server_config * config = malloc(sizeof(struct wf_server_config)); + if (NULL != config) + { + wf_impl_server_config_init(config); + } + + return config; +} + +void wf_impl_server_config_dispose( + struct wf_server_config * config) +{ + wf_impl_server_config_cleanup(config); + free(config); +} + +void wf_impl_server_config_set_mountpoint( + struct wf_server_config * config, + char const * mount_point) +{ + free(config->mount_point); + config->mount_point = strdup(mount_point); +} + +void wf_impl_server_config_set_documentroot( + struct wf_server_config * config, + char const * document_root) +{ + free(config->document_root); + config->document_root = strdup(document_root); +} + +void wf_impl_server_config_set_keypath( + struct wf_server_config * config, + char const * key_path) +{ + free(config->key_path); + config->key_path = strdup(key_path); +} + +void wf_impl_server_config_set_certpath( + struct wf_server_config * config, + char const * cert_path) +{ + free(config->cert_path); + config->cert_path = strdup(cert_path); +} + +void wf_impl_server_config_set_vhostname( + struct wf_server_config * config, + char const * vhost_name) +{ + free(config->vhost_name); + config->vhost_name = strdup(vhost_name); +} + +void wf_impl_server_config_set_port( + struct wf_server_config * config, + int port) +{ + config->port = port; +} + +void wf_impl_server_config_add_authenticator( + struct wf_server_config * config, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data +) +{ + wf_impl_authenticators_add(&config->authenticators, type, authenticate, user_data); +} + diff --git a/lib/webfuse/adapter/impl/server_config.h b/lib/webfuse/adapter/impl/server_config.h new file mode 100644 index 0000000..734c83a --- /dev/null +++ b/lib/webfuse/adapter/impl/server_config.h @@ -0,0 +1,72 @@ +#ifndef WF_ADAPTER_IMPL_SERVER_CONFIG_H +#define WF_ADAPTER_IMPL_SERVER_CONFIG_H + +#include "webfuse/adapter/impl/authenticators.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wf_server_config +{ + char * mount_point; + char * document_root; + char * key_path; + char * cert_path; + char * vhost_name; + int port; + struct wf_impl_authenticators authenticators; +}; + +extern struct wf_server_config * wf_impl_server_config_create(void); + +extern void wf_impl_server_config_dispose( + struct wf_server_config * config); + +extern void wf_impl_server_config_init( + struct wf_server_config * config); + +extern void wf_impl_server_config_cleanup( + struct wf_server_config * config); + +extern void wf_impl_server_config_clone( + struct wf_server_config * config, + struct wf_server_config * clone); + +extern void wf_impl_server_config_set_mountpoint( + struct wf_server_config * config, + char const * mount_point); + +extern void wf_impl_server_config_set_documentroot( + struct wf_server_config * config, + char const * document_root); + +extern void wf_impl_server_config_set_keypath( + struct wf_server_config * config, + char const * key_path); + +extern void wf_impl_server_config_set_certpath( + struct wf_server_config * config, + char const * cert_path); + +extern void wf_impl_server_config_set_vhostname( + struct wf_server_config * config, + char const * vhost_name); + +extern void wf_impl_server_config_set_port( + struct wf_server_config * config, + int port); + +extern void wf_impl_server_config_add_authenticator( + struct wf_server_config * config, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data +); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c new file mode 100644 index 0000000..2d817ab --- /dev/null +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -0,0 +1,166 @@ +#include "webfuse/adapter/impl/server_protocol.h" + +#include +#include + +#include "webfuse/core/message.h" +#include "webfuse/core/util.h" + +#include "webfuse/adapter/impl/filesystem.h" + +static int wf_impl_server_protocol_callback( + struct lws * wsi, + enum lws_callback_reasons reason, + void * WF_UNUSED_PARAM(user), + void * in, + size_t len) +{ + struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); + struct wf_server_protocol * protocol = ws_protocol->user; + + wf_impl_timeout_manager_check(&protocol->timeout_manager); + struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi); + + switch (reason) + { + case LWS_CALLBACK_PROTOCOL_INIT: + { + lws_sock_file_fd_type fd; + fd.filefd = wf_impl_filesystem_get_fd(&protocol->filesystem); + if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL)) + { + fprintf(stderr, "error: unable to adopt fd"); + } + } + break; + case LWS_CALLBACK_ESTABLISHED: + session = wf_impl_session_manager_add( + &protocol->session_manager, + wsi, + &protocol->authenticators, + &protocol->rpc); + + if (NULL != session) + { + wf_impl_session_authenticate(session, NULL); + } + break; + case LWS_CALLBACK_CLOSED: + wf_impl_session_manager_remove(&protocol->session_manager, wsi); + break; + case LWS_CALLBACK_SERVER_WRITEABLE: + if (NULL != session) + { + wf_impl_session_onwritable(session); + } + break; + case LWS_CALLBACK_RECEIVE: + if (NULL != session) + { + wf_impl_session_receive(session, in, len); + } + break; + case LWS_CALLBACK_RAW_RX_FILE: + wf_impl_filesystem_process_request(&protocol->filesystem); + break; + default: + break; + } + + return 0; +} + +static bool wf_impl_server_protocol_invoke( + void * user_data, + json_t const * request) +{ + struct wf_server_protocol * protocol = user_data; + struct wf_impl_session * session = &protocol->session_manager.session; + struct wf_message * message = wf_message_create(request); + + bool const result = wf_impl_session_send(session, message); + + return result; +} + + +struct wf_server_protocol * wf_impl_server_protocol_create( + char * mount_point) +{ + struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol)); + if (NULL != protocol) + { + if (!wf_impl_server_protocol_init(protocol, mount_point)) + { + free(protocol); + protocol = NULL; + } + } + + return protocol; +} + +void wf_impl_server_protocol_dispose( + struct wf_server_protocol * protocol) +{ + wf_impl_server_protocol_cleanup(protocol); + free(protocol); +} + +void wf_impl_server_protocol_init_lws( + struct wf_server_protocol * protocol, + struct lws_protocols * lws_protocol) +{ + lws_protocol->callback = &wf_impl_server_protocol_callback; + lws_protocol->per_session_data_size = 0; + lws_protocol->user = protocol; +} + +bool wf_impl_server_protocol_init( + struct wf_server_protocol * protocol, + char * mount_point) +{ + wf_impl_timeout_manager_init(&protocol->timeout_manager); + wf_impl_session_manager_init(&protocol->session_manager); + wf_impl_authenticators_init(&protocol->authenticators); + + wf_impl_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager); + wf_impl_jsonrpc_server_add(&protocol->rpc, "lookup", &wf_impl_server_protocol_invoke, protocol); + wf_impl_jsonrpc_server_add(&protocol->rpc, "getattr", &wf_impl_server_protocol_invoke, protocol); + wf_impl_jsonrpc_server_add(&protocol->rpc, "readdir", &wf_impl_server_protocol_invoke, protocol); + wf_impl_jsonrpc_server_add(&protocol->rpc, "open", &wf_impl_server_protocol_invoke, protocol); + wf_impl_jsonrpc_server_add(&protocol->rpc, "close", &wf_impl_server_protocol_invoke, protocol); + wf_impl_jsonrpc_server_add(&protocol->rpc, "read", &wf_impl_server_protocol_invoke, protocol); + + bool const success = wf_impl_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point); + + // cleanup on error + if (!success) + { + wf_impl_jsonrpc_server_cleanup(&protocol->rpc); + wf_impl_authenticators_cleanup(&protocol->authenticators); + wf_impl_timeout_manager_cleanup(&protocol->timeout_manager); + wf_impl_session_manager_cleanup(&protocol->session_manager); + } + + return success; +} + +void wf_impl_server_protocol_cleanup( + struct wf_server_protocol * protocol) +{ + wf_impl_filesystem_cleanup(&protocol->filesystem); + wf_impl_jsonrpc_server_cleanup(&protocol->rpc); + wf_impl_timeout_manager_cleanup(&protocol->timeout_manager); + wf_impl_authenticators_cleanup(&protocol->authenticators); + wf_impl_session_manager_cleanup(&protocol->session_manager); +} + +void wf_impl_server_protocol_add_authenticator( + struct wf_server_protocol * protocol, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data) +{ + wf_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data); +} diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h new file mode 100644 index 0000000..599f9a5 --- /dev/null +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -0,0 +1,53 @@ +#ifndef WF_ADAPTER_IMPL_SERVER_PROTOCOL_H +#define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H + +#include "webfuse/adapter/impl/filesystem.h" +#include "webfuse/adapter/impl/jsonrpc/server.h" +#include "webfuse/adapter/impl/time/timeout_manager.h" +#include "webfuse/adapter/impl/authenticators.h" +#include "webfuse/adapter/impl/session_manager.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct lws_protocols; + +struct wf_server_protocol +{ + struct wf_impl_timeout_manager timeout_manager; + struct wf_impl_filesystem filesystem; + struct wf_impl_jsonrpc_server rpc; + struct wf_impl_authenticators authenticators; + struct wf_impl_session_manager session_manager; +}; + +extern bool wf_impl_server_protocol_init( + struct wf_server_protocol * protocol, + char * mount_point); + +extern void wf_impl_server_protocol_cleanup( + struct wf_server_protocol * protocol); + +extern struct wf_server_protocol * wf_impl_server_protocol_create( + char * mount_point); + +extern void wf_impl_server_protocol_dispose( + struct wf_server_protocol * protocol); + +extern void wf_impl_server_protocol_init_lws( + struct wf_server_protocol * protocol, + struct lws_protocols * lws_protocol); + +extern void wf_impl_server_protocol_add_authenticator( + struct wf_server_protocol * protocol, + char const * type, + wf_authenticate_fn * authenticate, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c new file mode 100644 index 0000000..101a950 --- /dev/null +++ b/lib/webfuse/adapter/impl/session.c @@ -0,0 +1,84 @@ +#include "webfuse/adapter/impl/session.h" +#include "webfuse/adapter/impl/authenticators.h" +#include "webfuse/core/message_queue.h" +#include "webfuse/core/message.h" +#include "webfuse/adapter/impl/jsonrpc/server.h" + +#include +#include + +void wf_impl_session_init( + struct wf_impl_session * session, + struct lws * wsi, + struct wf_impl_authenticators * authenticators, + struct wf_impl_jsonrpc_server * rpc) + { + session->wsi = wsi; + session->is_authenticated = false; + session->authenticators = authenticators; + session->rpc = rpc; + wf_message_queue_init(&session->queue); + } + +void wf_impl_session_cleanup( + struct wf_impl_session * session) +{ + wf_message_queue_cleanup(&session->queue); + session->is_authenticated = false; + session->wsi = NULL; + session->authenticators = NULL; + session->rpc = NULL; +} + +void wf_impl_session_authenticate( + struct wf_impl_session * session, + struct wf_credentials * creds) +{ + session->is_authenticated = wf_impl_authenticators_authenticate(session->authenticators, creds); +} + +bool wf_impl_session_send( + struct wf_impl_session * session, + struct wf_message * message) +{ + bool result = (session->is_authenticated) && (NULL != session->wsi); + + if (result) + { + wf_message_queue_push(&session->queue, message); + lws_callback_on_writable(session->wsi); + + result = true; + } + else + { + wf_message_dispose(message); + } + + return result; +} + +void wf_impl_session_onwritable( + struct wf_impl_session * session) +{ + if (!wf_message_queue_empty(&session->queue)) + { + struct wf_message * message = wf_message_queue_pop(&session->queue); + lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT); + wf_message_dispose(message); + + if (!wf_message_queue_empty(&session->queue)) + { + lws_callback_on_writable(session->wsi); + } + } +} + + +void wf_impl_session_receive( + struct wf_impl_session * session, + char const * data, + size_t length) +{ + wf_impl_jsonrpc_server_onresult(session->rpc, data, length); +} \ No newline at end of file diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h new file mode 100644 index 0000000..598c551 --- /dev/null +++ b/lib/webfuse/adapter/impl/session.h @@ -0,0 +1,64 @@ +#ifndef WF_ADAPTER_IMPL_SESSION_H +#define WF_ADAPTER_IMPL_SESSION_H + +#ifndef __cplusplus +#include +#include +#else +#include +using std::size_t; +#endif + +#include "webfuse/core/message_queue.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct lws; +struct wf_message; +struct wf_credentials; +struct wf_impl_authenticators; +struct wf_impl_jsonrpc_server; + +struct wf_impl_session +{ + struct lws * wsi; + bool is_authenticated; + struct wf_message_queue queue; + struct wf_impl_authenticators * authenticators; + struct wf_impl_jsonrpc_server * rpc; +}; + +extern void wf_impl_session_init( + struct wf_impl_session * session, + struct lws * wsi, + struct wf_impl_authenticators * authenticators, + struct wf_impl_jsonrpc_server * rpc); + +extern void wf_impl_session_authenticate( + struct wf_impl_session * session, + struct wf_credentials * creds); + +extern bool wf_impl_session_send( + struct wf_impl_session * session, + struct wf_message * message); + +extern void wf_impl_session_receive( + struct wf_impl_session * session, + char const * data, + size_t length); + +extern void wf_impl_session_onwritable( + struct wf_impl_session * session); + +extern void wf_impl_session_cleanup( + struct wf_impl_session * session); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/webfuse/adapter/impl/session_manager.c b/lib/webfuse/adapter/impl/session_manager.c new file mode 100644 index 0000000..e1f61c2 --- /dev/null +++ b/lib/webfuse/adapter/impl/session_manager.c @@ -0,0 +1,54 @@ +#include "webfuse/adapter/impl/session_manager.h" +#include + +void wf_impl_session_manager_init( + struct wf_impl_session_manager * manager) +{ + wf_impl_session_init(&manager->session, NULL, NULL, NULL); +} + +void wf_impl_session_manager_cleanup( + struct wf_impl_session_manager * manager) +{ + wf_impl_session_cleanup(&manager->session); +} + +struct wf_impl_session * wf_impl_session_manager_add( + struct wf_impl_session_manager * manager, + struct lws * wsi, + struct wf_impl_authenticators * authenticators, + struct wf_impl_jsonrpc_server * rpc) +{ + struct wf_impl_session * session = NULL; + if (NULL == manager->session.wsi) + { + session = &manager->session; + wf_impl_session_init(&manager->session, wsi, authenticators, rpc); + } + + return session; +} + +struct wf_impl_session * wf_impl_session_manager_get( + struct wf_impl_session_manager * manager, + struct lws * wsi) +{ + struct wf_impl_session * session = NULL; + if (wsi == manager->session.wsi) + { + session = &manager->session; + } + + return session; +} + +void wf_impl_session_manager_remove( + struct wf_impl_session_manager * manager, + struct lws * wsi) +{ + if (wsi == manager->session.wsi) + { + wf_impl_session_cleanup(&manager->session); + manager->session.wsi = NULL; + } +} diff --git a/lib/webfuse/adapter/impl/session_manager.h b/lib/webfuse/adapter/impl/session_manager.h new file mode 100644 index 0000000..562d078 --- /dev/null +++ b/lib/webfuse/adapter/impl/session_manager.h @@ -0,0 +1,46 @@ +#ifndef WF_ADAPTER_IMPL_SESSION_MANAGER_H +#define WF_ADAPTER_IMPL_SESSION_MANAGER_H + +#ifndef __cplusplus +#include +#endif + +#include "webfuse/adapter/impl/session.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct lws; + +struct wf_impl_session_manager +{ + struct wf_impl_session session; +}; + +extern void wf_impl_session_manager_init( + struct wf_impl_session_manager * manager); + +extern void wf_impl_session_manager_cleanup( + struct wf_impl_session_manager * manager); + +extern struct wf_impl_session * wf_impl_session_manager_add( + struct wf_impl_session_manager * manager, + struct lws * wsi, + struct wf_impl_authenticators * authenticators, + struct wf_impl_jsonrpc_server * rpc); + +extern struct wf_impl_session * wf_impl_session_manager_get( + struct wf_impl_session_manager * manager, + struct lws * wsi); + +extern void wf_impl_session_manager_remove( + struct wf_impl_session_manager * manager, + struct lws * wsi); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/webfuse/adapter/impl/time/timeout_manager.c b/lib/webfuse/adapter/impl/time/timeout_manager.c new file mode 100644 index 0000000..155ffe6 --- /dev/null +++ b/lib/webfuse/adapter/impl/time/timeout_manager.c @@ -0,0 +1,84 @@ +#include "webfuse/adapter/impl/time/timeout_manager_intern.h" + +#include +#include "webfuse/adapter/impl/time/timer_intern.h" +#include "webfuse/adapter/impl/time/timepoint.h" + +void wf_impl_timeout_manager_init( + struct wf_impl_timeout_manager * manager) +{ + manager->timers = NULL; +} + +void wf_impl_timeout_manager_cleanup( + struct wf_impl_timeout_manager * manager) +{ + struct wf_impl_timer * timer = manager->timers; + while (NULL != timer) + { + struct wf_impl_timer * next = timer->next; + + wf_impl_timer_trigger(timer); + + timer = next; + } + + manager->timers = NULL; + +} + +void wf_impl_timeout_manager_check( + struct wf_impl_timeout_manager * manager) +{ + struct wf_impl_timer * timer = manager->timers; + while (NULL != timer) + { + struct wf_impl_timer * next = timer->next; + + if (wf_impl_timer_is_timeout(timer)) + { + wf_impl_timeout_manager_removetimer(manager, timer); + wf_impl_timer_trigger(timer); + } + + timer = next; + } +} + +void wf_impl_timeout_manager_addtimer( + struct wf_impl_timeout_manager * manager, + struct wf_impl_timer * timer) +{ + if (NULL != manager->timers) + { + manager->timers->prev = timer; + } + + timer->next = manager->timers; + timer->prev = NULL; + manager->timers = timer; +} + +void wf_impl_timeout_manager_removetimer( + struct wf_impl_timeout_manager * manager, + struct wf_impl_timer * timer) +{ + struct wf_impl_timer * prev = timer->prev; + struct wf_impl_timer * next = timer->next; + + if (NULL != prev) + { + prev->next = next; + } + + if (NULL != next) + { + next->prev = prev; + } + + if (manager->timers == timer) + { + manager->timers = next; + } +} + diff --git a/lib/webfuse/adapter/impl/time/timeout_manager.h b/lib/webfuse/adapter/impl/time/timeout_manager.h new file mode 100644 index 0000000..0e33c1b --- /dev/null +++ b/lib/webfuse/adapter/impl/time/timeout_manager.h @@ -0,0 +1,29 @@ +#ifndef WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H +#define WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_impl_timer; +struct wf_impl_timeout_manager +{ + struct wf_impl_timer * timers; +}; + +extern void wf_impl_timeout_manager_init( + struct wf_impl_timeout_manager * manager); + +extern void wf_impl_timeout_manager_cleanup( + struct wf_impl_timeout_manager * manager); + +extern void wf_impl_timeout_manager_check( + struct wf_impl_timeout_manager * manager); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/time/timeout_manager_intern.h b/lib/webfuse/adapter/impl/time/timeout_manager_intern.h new file mode 100644 index 0000000..67ee0f8 --- /dev/null +++ b/lib/webfuse/adapter/impl/time/timeout_manager_intern.h @@ -0,0 +1,24 @@ +#ifndef WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H +#define WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H + +#include "webfuse/adapter/impl/time/timeout_manager.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wf_impl_timeout_manager_addtimer( + struct wf_impl_timeout_manager * manager, + struct wf_impl_timer * timer); + +extern void wf_impl_timeout_manager_removetimer( + struct wf_impl_timeout_manager * manager, + struct wf_impl_timer * timer); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/webfuse/adapter/impl/time/timepoint.c b/lib/webfuse/adapter/impl/time/timepoint.c new file mode 100644 index 0000000..8425000 --- /dev/null +++ b/lib/webfuse/adapter/impl/time/timepoint.c @@ -0,0 +1,31 @@ +#include "webfuse/adapter/impl/time/timepoint.h" + +#include + +#define WF_MSEC_PER_SEC ((wf_impl_timepoint) 1000) +#define WF_NSEC_PER_MSEC ((wf_impl_timepoint) 1000 * 1000) + +wf_impl_timepoint wf_impl_timepoint_now(void) +{ + struct timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + + wf_impl_timepoint const now = (tp.tv_sec * WF_MSEC_PER_SEC) + (tp.tv_nsec / WF_NSEC_PER_MSEC); + return now; +} + +wf_impl_timepoint wf_impl_timepoint_in_msec(wf_impl_timediff value) +{ + wf_impl_timepoint const now = wf_impl_timepoint_now(); + wf_impl_timepoint result = now + ((wf_impl_timepoint) value); + + return result; +} + +bool wf_impl_timepoint_is_elapsed(wf_impl_timepoint tp) +{ + wf_impl_timepoint const now = wf_impl_timepoint_now(); + wf_impl_timediff const diff = (wf_impl_timediff) (tp - now); + + return (0 > diff); +} diff --git a/lib/webfuse/adapter/impl/time/timepoint.h b/lib/webfuse/adapter/impl/time/timepoint.h new file mode 100644 index 0000000..c9f6560 --- /dev/null +++ b/lib/webfuse/adapter/impl/time/timepoint.h @@ -0,0 +1,31 @@ +#ifndef WF_ADAPTER_IMPL_TIME_TIMEPOINT_H +#define WF_ADAPTER_IMPL_TIME_TIMEPOINT_H + +#ifndef __cplusplus +#include +#include +#else +#include +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef uint64_t wf_impl_timepoint; +typedef int64_t wf_impl_timediff; + +extern wf_impl_timepoint wf_impl_timepoint_now(void); + +extern wf_impl_timepoint wf_impl_timepoint_in_msec( + wf_impl_timediff value); + +extern bool wf_impl_timepoint_is_elapsed( + wf_impl_timepoint timepoint); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/time/timer.c b/lib/webfuse/adapter/impl/time/timer.c new file mode 100644 index 0000000..9d1da17 --- /dev/null +++ b/lib/webfuse/adapter/impl/time/timer.c @@ -0,0 +1,65 @@ +#include "webfuse/adapter/impl/time/timer_intern.h" +#include "webfuse/adapter/impl/time/timeout_manager_intern.h" + +#include +#include + +void wf_impl_timer_init( + struct wf_impl_timer * timer, + struct wf_impl_timeout_manager * manager) +{ + timer->manager = manager; + timer->timeout = 0; + timer->timeout_handler = NULL; + timer->user_data = NULL; + timer->prev = NULL; + timer->next = NULL; +} + +void wf_impl_timer_cleanup( + struct wf_impl_timer * timer) +{ + memset(timer, 0, sizeof(struct wf_impl_timer)); +} + +void wf_impl_timer_start( + struct wf_impl_timer * timer, + wf_impl_timepoint absolute_timeout, + wf_impl_timer_timeout_fn * handler, + void * user_data) +{ + timer->timeout = absolute_timeout; + timer->timeout_handler = handler; + timer->user_data = user_data; + + wf_impl_timeout_manager_addtimer(timer->manager, timer); +} + +void wf_impl_timer_cancel( + struct wf_impl_timer * timer) +{ + wf_impl_timeout_manager_removetimer(timer->manager, timer); + + timer->timeout = 0; + timer->timeout_handler = NULL; + timer->user_data = NULL; +} + +bool wf_impl_timer_is_timeout( + struct wf_impl_timer * timer) +{ + return wf_impl_timepoint_is_elapsed(timer->timeout); +} + + +void wf_impl_timer_trigger( + struct wf_impl_timer * timer) +{ + if (NULL != timer->timeout_handler) + { + timer->prev = NULL; + timer->next = NULL; + + timer->timeout_handler(timer); + } +} diff --git a/lib/webfuse/adapter/impl/time/timer.h b/lib/webfuse/adapter/impl/time/timer.h new file mode 100644 index 0000000..bbc840d --- /dev/null +++ b/lib/webfuse/adapter/impl/time/timer.h @@ -0,0 +1,48 @@ +#ifndef WF_ADAPTER_IMPL_TIME_TIMER_H +#define WF_ADAPTER_IMPL_TIME_TIMER_H + +#include "webfuse/adapter/impl/time/timepoint.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_impl_timer; +struct wf_impl_timeout_manager; + +typedef void wf_impl_timer_timeout_fn(struct wf_impl_timer * timer); + +struct wf_impl_timer +{ + struct wf_impl_timeout_manager * manager; + wf_impl_timepoint timeout; + wf_impl_timer_timeout_fn * timeout_handler; + void * user_data; + struct wf_impl_timer * next; + struct wf_impl_timer * prev; +}; + +extern void wf_impl_timer_init( + struct wf_impl_timer * timer, + struct wf_impl_timeout_manager * manager); + +extern void wf_impl_timer_cleanup( + struct wf_impl_timer * timer); + +extern void wf_impl_timer_start( + struct wf_impl_timer * timer, + wf_impl_timepoint absolute_timeout, + wf_impl_timer_timeout_fn * handler, + void * user_data); + +extern void wf_impl_timer_cancel( + struct wf_impl_timer * timer); + +#ifdef __cplusplus +} +#endif + + + +#endif diff --git a/lib/webfuse/adapter/impl/time/timer_intern.h b/lib/webfuse/adapter/impl/time/timer_intern.h new file mode 100644 index 0000000..6f1f19f --- /dev/null +++ b/lib/webfuse/adapter/impl/time/timer_intern.h @@ -0,0 +1,25 @@ +#ifndef WF_ADAPTER_IMPL_TIME_TIMER_INTERN_H +#define WF_ADAPTER_IMPL_TIME_TIMER_INTERN_H + +#ifndef __cplusplus +#include +#endif + +#include "webfuse/adapter/impl/time/timer.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern bool wf_impl_timer_is_timeout( + struct wf_impl_timer * timer); + +extern void wf_impl_timer_trigger( + struct wf_impl_timer * timer); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/core/message.c b/lib/webfuse/core/message.c new file mode 100644 index 0000000..bc19248 --- /dev/null +++ b/lib/webfuse/core/message.c @@ -0,0 +1,32 @@ +#include "webfuse/core/message.h" + +#include +#include + +extern struct wf_message * wf_message_create(json_t const * value) +{ + struct wf_message * message = NULL; + size_t const length = json_dumpb(value, NULL, 0, JSON_COMPACT); + + if (0 < length) + { + char * data = malloc(sizeof(struct wf_message) + LWS_PRE + length); + message = (struct wf_message *) data; + if (NULL != message) + { + message->data = &data[sizeof(struct wf_message) + LWS_PRE]; + message->length = length; + message->next = NULL; + + json_dumpb(value, message->data, length, JSON_COMPACT); + } + } + + return message; +} + +void wf_message_dispose( + struct wf_message * message) +{ + free(message); +} diff --git a/lib/webfuse/core/message.h b/lib/webfuse/core/message.h new file mode 100644 index 0000000..ea73e5f --- /dev/null +++ b/lib/webfuse/core/message.h @@ -0,0 +1,34 @@ +#ifndef WF_MESSAGE_H +#define WF_MESSAGE_H + +#ifndef __cplusplus +#include +#else +#include +using std::size_t; +#endif + +#include + +struct wf_message +{ + struct wf_message * next; + char * data; + size_t length; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern struct wf_message * wf_message_create(json_t const * value); + +extern void wf_message_dispose( + struct wf_message * message); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/core/message_queue.c b/lib/webfuse/core/message_queue.c new file mode 100644 index 0000000..b601215 --- /dev/null +++ b/lib/webfuse/core/message_queue.c @@ -0,0 +1,63 @@ +#include "webfuse/core/message_queue.h" +#include "webfuse/core/message.h" + +void wf_message_queue_init( + struct wf_message_queue * queue) +{ + queue->first = NULL; + queue->last = NULL; + +} + +void wf_message_queue_cleanup( + struct wf_message_queue * queue) +{ + struct wf_message * message = queue->first; + while (NULL != message) + { + struct wf_message * next = message->next; + wf_message_dispose(message); + message = next; + } + wf_message_queue_init(queue); +} + +bool wf_message_queue_empty( + struct wf_message_queue * queue) +{ + return (NULL == queue->first); +} + +void wf_message_queue_push( + struct wf_message_queue * queue, + struct wf_message * message) +{ + message->next = NULL; + + if (NULL != queue->last) + { + queue->last->next = message; + queue->last = message; + } + else + { + queue->first = message; + queue->last = message; + } +} + +struct wf_message * wf_message_queue_pop( + struct wf_message_queue * queue) +{ + struct wf_message * const result = queue->first; + if (NULL != result) + { + queue->first = queue->first->next; + if (NULL == queue->first) + { + queue->last = NULL; + } + } + + return result; +} diff --git a/lib/webfuse/core/message_queue.h b/lib/webfuse/core/message_queue.h new file mode 100644 index 0000000..48fdfad --- /dev/null +++ b/lib/webfuse/core/message_queue.h @@ -0,0 +1,42 @@ +#ifndef WF_MESSAGE_QUEUE_H +#define WF_MESSAGE_QUEUE_H + +#ifndef __cplusplus +#include +#endif + +struct wf_message_queue; +struct wf_message; + +struct wf_message_queue +{ + struct wf_message * first; + struct wf_message * last; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wf_message_queue_init( + struct wf_message_queue * queue); + +extern void wf_message_queue_cleanup( + struct wf_message_queue * queue); + +extern bool wf_message_queue_empty( + struct wf_message_queue * queue); + +extern void wf_message_queue_push( + struct wf_message_queue * queue, + struct wf_message * message); + +extern struct wf_message * wf_message_queue_pop( + struct wf_message_queue * queue); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/core/status.c b/lib/webfuse/core/status.c new file mode 100644 index 0000000..c7ea0de --- /dev/null +++ b/lib/webfuse/core/status.c @@ -0,0 +1,34 @@ +#include "webfuse/core/status_intern.h" + +#include + + int wf_status_to_rc(wf_status status) +{ + switch(status) + { + case WF_GOOD: return 0; + case WF_BAD_NOTIMPLEMENTED: return -ENOSYS; + case WF_BAD_TIMEOUT: return -ETIMEDOUT; + case WF_BAD_BUSY: return -ENOENT; + case WF_BAD_FORMAT: return -ENOENT; + case WF_BAD_NOENTRY: return -ENOENT; + case WF_BAD_NOACCESS: return -EACCES; + default: return -ENOENT; + } +} + +char const * wf_status_tostring(wf_status status) +{ + switch(status) + { + case WF_GOOD: return "Good"; + case WF_BAD: return "Bad"; + case WF_BAD_NOTIMPLEMENTED: return "Bad (not implelemted)"; + case WF_BAD_TIMEOUT: return "Bad (timeout)"; + case WF_BAD_BUSY: return "Bad (busy)"; + case WF_BAD_FORMAT: return "Bad (format)"; + case WF_BAD_NOENTRY: return "Bad (no entry)"; + case WF_BAD_NOACCESS: return "Bad (no access)"; + default: return "Bad (unknown)"; + } +} diff --git a/lib/webfuse/core/status_intern.h b/lib/webfuse/core/status_intern.h new file mode 100644 index 0000000..fad0e0c --- /dev/null +++ b/lib/webfuse/core/status_intern.h @@ -0,0 +1,19 @@ +#ifndef WF_STATUS_INTERN_H +#define WF_STATUS_INTERN_H + +#include "webfuse/core/status.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern int wf_status_to_rc(wf_status status); + +extern char const * wf_status_tostring(wf_status status); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/lib/webfuse/core/util.h b/lib/webfuse/core/util.h new file mode 100644 index 0000000..b0169b8 --- /dev/null +++ b/lib/webfuse/core/util.h @@ -0,0 +1,10 @@ +#ifndef WF_UTIL_H +#define WF_UTIL_H + +#ifdef __GNUC__ +#define WF_UNUSED_PARAM(param) param __attribute__((unused)) +#else +#define WF_UNUSED_PARAM(param) +#endif + +#endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c new file mode 100644 index 0000000..1384d20 --- /dev/null +++ b/lib/webfuse/provider/api.c @@ -0,0 +1,240 @@ +#include "webfuse_provider.h" + +#include "webfuse/provider/impl/request.h" +#include "webfuse/provider/impl/operation/getattr.h" +#include "webfuse/provider/impl/operation/lookup.h" +#include "webfuse/provider/impl/operation/readdir.h" +#include "webfuse/provider/impl/operation/open.h" +#include "webfuse/provider/impl/operation/close.h" +#include "webfuse/provider/impl/operation/read.h" +#include "webfuse/provider/impl/client_protocol.h" +#include "webfuse/provider/impl/client_config.h" +#include "webfuse/provider/impl/client.h" +#include "webfuse/provider/impl/dirbuffer.h" + +// respond + +void wfp_respond_error( + struct wfp_request * request, + wf_status status) +{ + wfp_impl_respond_error(request, status); +} + +void wfp_respond_getattr( + struct wfp_request * request, + struct stat const * stat) +{ + wfp_impl_respond_getattr(request, stat); +} + +void wfp_respond_lookup( + struct wfp_request * request, + struct stat const * stat) +{ + wfp_impl_respond_lookup(request, stat); +} + +void wfp_respond_open( + struct wfp_request * request, + uint32_t handle) +{ + wfp_impl_respond_open(request, handle); +} + +void wfp_respond_read( + struct wfp_request * request, + char const * data, + size_t length) +{ + wfp_impl_respond_read(request, data, length); +} + +void wfp_respond_readdir( + struct wfp_request * request, + struct wfp_dirbuffer * dirbuffer) +{ + wfp_impl_respond_readdir(request, dirbuffer); +} + +// config + + +struct wfp_client_config * wfp_client_config_create(void) +{ + return wfp_impl_client_config_create(); +} + +void wfp_client_config_dispose( + struct wfp_client_config * config) +{ + wfp_impl_client_config_dispose(config); +} + +void wfp_client_config_set_userdata( + struct wfp_client_config * config, + void * user_data) +{ + wfp_impl_client_config_set_userdata(config, user_data); +} + +void wfp_client_config_set_keypath( + struct wfp_client_config * config, + char const * key_path) +{ + wfp_impl_client_config_set_keypath(config, key_path); +} + +void wfp_client_config_set_certpath( + struct wfp_client_config * config, + char const * cert_path) +{ + wfp_impl_client_config_set_certpath(config, cert_path); +} + +void wfp_client_config_set_onconnected( + struct wfp_client_config * config, + wfp_connected_fn * handler) +{ + wfp_impl_client_config_set_onconnected(config, handler); +} + +void wfp_client_config_set_ondisconnected( + struct wfp_client_config * config, + wfp_disconnected_fn * handler) +{ + wfp_impl_client_config_set_ondisconnected(config, handler); +} + +void wfp_client_config_set_ontimer( + struct wfp_client_config * config, + wfp_ontimer_fn * handler) +{ + wfp_impl_client_config_set_ontimer(config, handler); +} + +void wfp_client_config_set_onlookup( + struct wfp_client_config * config, + wfp_lookup_fn * handler) +{ + wfp_impl_client_config_set_onlookup(config, handler); +} + +void wfp_client_config_set_ongetattr( + struct wfp_client_config * config, + wfp_getattr_fn * handler) +{ + wfp_impl_client_config_set_ongetattr(config, handler); +} + +void wfp_client_config_set_onreaddir( + struct wfp_client_config * config, + wfp_readdir_fn * handler) +{ + wfp_impl_client_config_set_onreaddir(config, handler); +} + +void wfp_client_config_set_onopen( + struct wfp_client_config * config, + wfp_open_fn * handler) +{ + wfp_impl_client_config_set_onopen(config, handler); +} + +void wfp_client_config_set_onclose( + struct wfp_client_config * config, + wfp_close_fn * handler) +{ + wfp_impl_client_config_set_onclose(config, handler); +} + +void wfp_client_config_set_onread( + struct wfp_client_config * config, + wfp_read_fn * handler) +{ + wfp_impl_client_config_set_onread(config, handler); +} + +// protocol + + +struct wfp_client_protocol * wfp_client_protocol_create( + struct wfp_provider const * provider, + void * user_data) +{ + return wfp_impl_client_protocol_create(provider, user_data); +} + +void wfp_client_protocol_dispose( + struct wfp_client_protocol * protocol) +{ + wfp_impl_client_protocol_dispose(protocol); +} + +void wfp_client_protocol_init_lws( + struct wfp_client_protocol * protocol, + struct lws_protocols * lws_protocol) +{ + wfp_impl_client_protocol_init_lws(protocol, lws_protocol); +} + +// client + +struct wfp_client * wfp_client_create( + struct wfp_client_config * config) +{ + return wfp_impl_client_create(config); +} + +void wfp_client_connect( + struct wfp_client * client, + char const * url) +{ + wfp_impl_client_connect(client, url); +} + +void wfp_client_disconnect( + struct wfp_client * client) +{ + wfp_impl_client_disconnect(client); +} + +void wfp_client_dispose( + struct wfp_client * client) +{ + wfp_impl_client_dispose(client); +} + +void wfp_client_run( + struct wfp_client * client) +{ + wfp_impl_client_run(client); +} + +void wfp_client_shutdown( + struct wfp_client * client) +{ + wfp_impl_client_shutdown(client); +} + +// dirbuffer + +struct wfp_dirbuffer * wfp_dirbuffer_create(void) +{ + return wfp_impl_dirbuffer_create(); +} + +void wfp_dirbuffer_dispose( + struct wfp_dirbuffer * buffer) +{ + wfp_impl_dirbuffer_dispose(buffer); +} + +void wfp_dirbuffer_add( + struct wfp_dirbuffer * buffer, + char const * name, + ino_t inode) +{ + wfp_impl_dirbuffer_add(buffer, name, inode); +} + diff --git a/lib/wsfs/provider/impl/client.c b/lib/webfuse/provider/impl/client.c similarity index 51% rename from lib/wsfs/provider/impl/client.c rename to lib/webfuse/provider/impl/client.c index 6ea28f1..aee5757 100644 --- a/lib/wsfs/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -1,4 +1,4 @@ -#include "wsfs/provider/impl/client.h" +#include "webfuse/provider/impl/client.h" #include #include @@ -6,42 +6,42 @@ #include -#include "wsfs/provider/impl/provider.h" -#include "wsfs/provider/impl/client_protocol.h" -#include "wsfs/provider/impl/client_config.h" -#include "wsfs/provider/impl/url.h" +#include "webfuse/provider/impl/provider.h" +#include "webfuse/provider/impl/client_protocol.h" +#include "webfuse/provider/impl/client_config.h" +#include "webfuse/provider/impl/url.h" -#define WSFSP_PROTOCOL ("fs") -#define WSFSP_DISABLE_LWS_LOG 0 -#define WSFSP_CLIENT_PROTOCOL_COUNT 2 -#define WSFSP_CLIENT_TIMEOUT (1 * 1000) +#define WFP_PROTOCOL ("fs") +#define WFP_DISABLE_LWS_LOG 0 +#define WFP_CLIENT_PROTOCOL_COUNT 2 +#define WFP_CLIENT_TIMEOUT (1 * 1000) -struct wsfsp_client +struct wfp_client { volatile bool is_running; - struct wsfsp_client_protocol protocol; + struct wfp_client_protocol protocol; struct lws_context_creation_info info; - struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT]; + struct lws_protocols protocols[WFP_CLIENT_PROTOCOL_COUNT]; struct lws_context * context; char * key_path; char * cert_path; }; -struct wsfsp_client * wsfsp_impl_client_create( - struct wsfsp_client_config * config) +struct wfp_client * wfp_impl_client_create( + struct wfp_client_config * config) { - lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL); + lws_set_log_level(WFP_DISABLE_LWS_LOG, NULL); - struct wsfsp_client * client = malloc(sizeof(struct wsfsp_client)); + struct wfp_client * client = malloc(sizeof(struct wfp_client)); if (NULL != client) { client->is_running = true; - wsfsp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); + wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); - memset(client->protocols, 0, sizeof(struct lws_protocols) * WSFSP_CLIENT_PROTOCOL_COUNT); + memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT); client->protocols[0].name = "fs"; - wsfsp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]); + wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]); memset(&client->info, 0, sizeof(struct lws_context_creation_info)); client->info.port = CONTEXT_PORT_NO_LISTEN; @@ -60,20 +60,20 @@ struct wsfsp_client * wsfsp_impl_client_create( return client; } -void wsfsp_impl_client_dispose( - struct wsfsp_client * client) +void wfp_impl_client_dispose( + struct wfp_client * client) { lws_context_destroy(client->context); - wsfsp_impl_client_protocol_cleanup(&client->protocol); + wfp_impl_client_protocol_cleanup(&client->protocol); free(client); } -void wsfsp_impl_client_connect( - struct wsfsp_client * client, +void wfp_impl_client_connect( + struct wfp_client * client, char const * url) { - struct wsfsp_impl_url url_data; - bool const success = wsfsp_impl_url_init(&url_data, url); + struct wfp_impl_url url_data; + bool const success = wfp_impl_url_init(&url_data, url); if (success) { struct lws_client_connect_info info; @@ -85,34 +85,34 @@ void wsfsp_impl_client_connect( info.host = info.address; info.origin = info.address; info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0; - info.protocol = WSFSP_PROTOCOL; + info.protocol = WFP_PROTOCOL; info.pwsi = &client->protocol.wsi; lws_client_connect_via_info(&info); - wsfsp_impl_url_cleanup(&url_data); + wfp_impl_url_cleanup(&url_data); } } -void wsfsp_impl_client_disconnect( - struct wsfsp_client * client) +void wfp_impl_client_disconnect( + struct wfp_client * client) { (void) client; // ToDo: implement me } -void wsfsp_impl_client_run( - struct wsfsp_client * client) +void wfp_impl_client_run( + struct wfp_client * client) { while (client->is_running) { - lws_service(client->context, WSFSP_CLIENT_TIMEOUT); + lws_service(client->context, WFP_CLIENT_TIMEOUT); } } -void wsfsp_impl_client_shutdown( - struct wsfsp_client * client) +void wfp_impl_client_shutdown( + struct wfp_client * client) { client->is_running = false; } diff --git a/lib/webfuse/provider/impl/client.h b/lib/webfuse/provider/impl/client.h new file mode 100644 index 0000000..68cc892 --- /dev/null +++ b/lib/webfuse/provider/impl/client.h @@ -0,0 +1,49 @@ +#ifndef WF_PROVIDER_IMPL_CLIENT_H +#define WF_PROVIDER_IMPL_CLIENT_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_client; +struct wfp_client_config; + +extern struct wfp_client * wfp_impl_client_create( + struct wfp_client_config * config); + +extern void wfp_impl_client_set_keypath( + struct wfp_client * client, + char * key_path); + +extern void wfp_impl_client_set_certpath( + struct wfp_client * client, + char * cert_path); + +extern void wfp_impl_client_connect( + struct wfp_client * client, + char const * url); + +extern void wfp_impl_client_disconnect( + struct wfp_client * client); + +extern void wfp_impl_client_settimeout( + struct wfp_client * client, + unsigned int timepoint); + +extern void wfp_impl_client_dispose( + struct wfp_client * client); + +extern void wfp_impl_client_run( + struct wfp_client * client); + +extern void wfp_impl_client_shutdown( + struct wfp_client * client); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c new file mode 100644 index 0000000..7d121da --- /dev/null +++ b/lib/webfuse/provider/impl/client_config.c @@ -0,0 +1,112 @@ +#include "webfuse/provider/impl/client_config.h" +#include "webfuse/provider/impl/provider.h" +#include +#include + +struct wfp_client_config * wfp_impl_client_config_create(void) +{ + struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config)); + if (NULL != config) + { + wfp_impl_provider_init(&config->provider); + config->user_data = NULL; + config->key_path = NULL; + config->cert_path = NULL; + } + + return config; +} + +void wfp_impl_client_config_dispose( + struct wfp_client_config * config) +{ + free(config->key_path); + free(config->cert_path); + free(config); +} + +void wfp_impl_client_config_set_userdata( + struct wfp_client_config * config, + void * user_data) +{ + config->user_data = user_data; +} + +void wfp_impl_client_config_set_keypath( + struct wfp_client_config * config, + char const * key_path) +{ + free(config->key_path); + config->key_path = strdup(key_path); +} + +void wfp_impl_client_config_set_certpath( + struct wfp_client_config * config, + char const * cert_path) +{ + free(config->cert_path); + config->cert_path = strdup(cert_path); +} + +void wfp_impl_client_config_set_onconnected( + struct wfp_client_config * config, + wfp_connected_fn * handler) +{ + config->provider.connected = handler; +} + +void wfp_impl_client_config_set_ondisconnected( + struct wfp_client_config * config, + wfp_disconnected_fn * handler) +{ + config->provider.disconnected = handler; +} + +void wfp_impl_client_config_set_ontimer( + struct wfp_client_config * config, + wfp_ontimer_fn * handler) +{ + config->provider.ontimer = handler; +} + +void wfp_impl_client_config_set_onlookup( + struct wfp_client_config * config, + wfp_lookup_fn * handler) +{ + config->provider.lookup = handler; +} + +void wfp_impl_client_config_set_ongetattr( + struct wfp_client_config * config, + wfp_getattr_fn * handler) +{ + config->provider.getattr = handler; +} + +void wfp_impl_client_config_set_onreaddir( + struct wfp_client_config * config, + wfp_readdir_fn * handler) +{ + config->provider.readdir = handler; +} + +void wfp_impl_client_config_set_onopen( + struct wfp_client_config * config, + wfp_open_fn * handler) +{ + config->provider.open = handler; +} + +void wfp_impl_client_config_set_onclose( + struct wfp_client_config * config, + wfp_close_fn * handler) +{ + config->provider.close = handler; +} + +void wfp_impl_client_config_set_onread( + struct wfp_client_config * config, + wfp_read_fn * handler) +{ + config->provider.read = handler; +} diff --git a/lib/webfuse/provider/impl/client_config.h b/lib/webfuse/provider/impl/client_config.h new file mode 100644 index 0000000..190a3cb --- /dev/null +++ b/lib/webfuse/provider/impl/client_config.h @@ -0,0 +1,77 @@ +#ifndef WF_PROVIDER_IMPL_CLIENT_CONFIG_H +#define WF_PROVIDER_IMPL_CLIENT_CONFIG_H + +#include "webfuse/provider/client_config.h" +#include "webfuse/provider/impl/provider.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_client_config +{ + struct wfp_provider provider; + void * user_data; + char * key_path; + char * cert_path; +}; + +extern struct wfp_client_config * wfp_impl_client_config_create(void); + +extern void wfp_impl_client_config_dispose( + struct wfp_client_config * config); + +extern void wfp_impl_client_config_set_userdata( + struct wfp_client_config * config, + void * user_data); + +extern void wfp_impl_client_config_set_keypath( + struct wfp_client_config * config, + char const * key_path); + +extern void wfp_impl_client_config_set_certpath( + struct wfp_client_config * config, + char const * cert_path); + +extern void wfp_impl_client_config_set_onconnected( + struct wfp_client_config * config, + wfp_connected_fn * handler); + +extern void wfp_impl_client_config_set_ondisconnected( + struct wfp_client_config * config, + wfp_disconnected_fn * handler); + +extern void wfp_impl_client_config_set_ontimer( + struct wfp_client_config * config, + wfp_ontimer_fn * handler); + +extern void wfp_impl_client_config_set_onlookup( + struct wfp_client_config * config, + wfp_lookup_fn * handler); + +extern void wfp_impl_client_config_set_ongetattr( + struct wfp_client_config * config, + wfp_getattr_fn * handler); + +extern void wfp_impl_client_config_set_onreaddir( + struct wfp_client_config * config, + wfp_readdir_fn * handler); + +extern void wfp_impl_client_config_set_onopen( + struct wfp_client_config * config, + wfp_open_fn * handler); + +extern void wfp_impl_client_config_set_onclose( + struct wfp_client_config * config, + wfp_close_fn * handler); + +extern void wfp_impl_client_config_set_onread( + struct wfp_client_config * config, + wfp_read_fn * handler); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c new file mode 100644 index 0000000..f6c34be --- /dev/null +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -0,0 +1,149 @@ +#include "webfuse/provider/impl/client_protocol.h" + +#include +#include + +#include +#include + + +#include "webfuse/provider/impl/provider.h" +#include "webfuse/core/util.h" +#include "webfuse/core/message.h" + +static void wfp_impl_client_protocol_respond( + json_t * response, + void * user_data) +{ + struct wfp_client_protocol * protocol = (struct wfp_client_protocol *) user_data; + + struct wf_message * message = wf_message_create(response); + if (NULL != message) + { + wf_message_queue_push(&protocol->queue, message); + lws_callback_on_writable(protocol->wsi); + } +} + +static void wfp_impl_client_protocol_process_request( + struct wfp_client_protocol * protocol, + char const * message, + size_t length) +{ + json_t * request = json_loadb(message, length, 0, NULL); + if (NULL != request) + { + struct wfp_impl_invokation_context context = + { + .provider = &protocol->provider, + .user_data = protocol->user_data, + .request = &protocol->request + }; + + wfp_impl_provider_invoke(&context, request); + json_decref(request); + } +} + + +static int wfp_impl_client_protocol_callback( + struct lws * wsi, + enum lws_callback_reasons reason, + void * WF_UNUSED_PARAM(user), + void * in, + size_t len) +{ + struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); + struct wfp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL; + + if (NULL != protocol) + { + switch (reason) + { + case LWS_CALLBACK_CLIENT_ESTABLISHED: + protocol->provider.connected(protocol->user_data); + break; + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + protocol->provider.disconnected(protocol->user_data); + break; + case LWS_CALLBACK_CLIENT_CLOSED: + protocol->provider.connected(protocol->user_data); + break; + case LWS_CALLBACK_CLIENT_RECEIVE: + wfp_impl_client_protocol_process_request(protocol, in, len); + break; + case LWS_CALLBACK_SERVER_WRITEABLE: + // fall-through + case LWS_CALLBACK_CLIENT_WRITEABLE: + if ((wsi == protocol->wsi) && (!wf_message_queue_empty(&protocol->queue))) + { + struct wf_message * message = wf_message_queue_pop(&protocol->queue); + lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT); + wf_message_dispose(message); + + if (!wf_message_queue_empty(&protocol->queue)) + { + lws_callback_on_writable(wsi); + + } + } + break; + default: + break; + } + } + + return 0; +} + + +void wfp_impl_client_protocol_init( + struct wfp_client_protocol * protocol, + struct wfp_provider const * provider, + void * user_data) +{ + wf_message_queue_init(&protocol->queue); + + protocol->wsi = NULL; + + protocol->request.respond = &wfp_impl_client_protocol_respond; + protocol->request.user_data = protocol; + + protocol->user_data = user_data; + wfp_impl_provider_init_from_prototype(&protocol->provider, provider); +} + +void wfp_impl_client_protocol_cleanup( + struct wfp_client_protocol * protocol) +{ + wf_message_queue_cleanup(&protocol->queue); +} + +struct wfp_client_protocol * wfp_impl_client_protocol_create( + struct wfp_provider const * provider, + void * user_data) +{ + struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol)); + if (NULL != protocol) + { + wfp_impl_client_protocol_init(protocol, provider, user_data); + } + + return protocol; +} + +void wfp_impl_client_protocol_dispose( + struct wfp_client_protocol * protocol) +{ + wfp_impl_client_protocol_cleanup(protocol); + free(protocol); +} + +void wfp_impl_client_protocol_init_lws( + struct wfp_client_protocol * protocol, + struct lws_protocols * lws_protocol) +{ + lws_protocol->callback = &wfp_impl_client_protocol_callback; + lws_protocol->per_session_data_size = 0; + lws_protocol->user = protocol; +} diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h new file mode 100644 index 0000000..c4181fe --- /dev/null +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -0,0 +1,49 @@ +#ifndef WF_PROVIDER_IMPL_CLIENT_PROTOCOL_H +#define WF_PROVIDER_IMPL_CLIENT_PROTOCOL_H + +#include "webfuse/provider/impl/provider.h" +#include "webfuse/provider/impl/request.h" + +#include "webfuse/core/message_queue.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_provider; +struct lws_protocols; + +struct wfp_client_protocol +{ + struct wfp_request request; + struct wfp_provider provider; + void * user_data; + struct lws * wsi; + struct wf_message_queue queue; +}; + +extern void wfp_impl_client_protocol_init( + struct wfp_client_protocol * protocol, + struct wfp_provider const * provider, + void * user_data); + +extern void wfp_impl_client_protocol_cleanup( + struct wfp_client_protocol * protocol); + +extern struct wfp_client_protocol * wfp_impl_client_protocol_create( + struct wfp_provider const * provider, + void * user_data); + +extern void wfp_impl_client_protocol_dispose( + struct wfp_client_protocol * protocol); + +extern void wfp_impl_client_protocol_init_lws( + struct wfp_client_protocol * protocol, + struct lws_protocols * lws_protocol); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsfs/provider/impl/dirbuffer.c b/lib/webfuse/provider/impl/dirbuffer.c similarity index 59% rename from lib/wsfs/provider/impl/dirbuffer.c rename to lib/webfuse/provider/impl/dirbuffer.c index 70c9e52..db401ef 100644 --- a/lib/wsfs/provider/impl/dirbuffer.c +++ b/lib/webfuse/provider/impl/dirbuffer.c @@ -1,9 +1,9 @@ -#include "wsfs/provider/impl/dirbuffer.h" +#include "webfuse/provider/impl/dirbuffer.h" #include -struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void) +struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void) { - struct wsfsp_dirbuffer * buffer = malloc(sizeof(struct wsfsp_dirbuffer)); + struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer)); if (NULL != buffer) { buffer->entries = json_array(); @@ -12,8 +12,8 @@ struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void) return buffer; } -void wsfsp_impl_dirbuffer_dispose( - struct wsfsp_dirbuffer * buffer) +void wfp_impl_dirbuffer_dispose( + struct wfp_dirbuffer * buffer) { if (NULL != buffer->entries) { @@ -23,8 +23,8 @@ void wsfsp_impl_dirbuffer_dispose( free(buffer); } -void wsfsp_impl_dirbuffer_add( - struct wsfsp_dirbuffer * buffer, +void wfp_impl_dirbuffer_add( + struct wfp_dirbuffer * buffer, char const * name, ino_t inode) { @@ -35,8 +35,8 @@ void wsfsp_impl_dirbuffer_add( json_array_append_new(buffer->entries, entry); } -json_t * wsfsp_impl_dirbuffer_take( - struct wsfsp_dirbuffer * buffer) +json_t * wfp_impl_dirbuffer_take( + struct wfp_dirbuffer * buffer) { json_t * entries = buffer->entries; diff --git a/lib/webfuse/provider/impl/dirbuffer.h b/lib/webfuse/provider/impl/dirbuffer.h new file mode 100644 index 0000000..8118ed1 --- /dev/null +++ b/lib/webfuse/provider/impl/dirbuffer.h @@ -0,0 +1,37 @@ +#ifndef WF_PROVIDER_IMPL_DIRBUFFER_H +#define WF_PROVIDER_IMPL_DIRBUFFER_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_dirbuffer +{ + json_t * entries; +}; + +extern struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void); + +extern void wfp_impl_dirbuffer_dispose( + struct wfp_dirbuffer * buffer); + +extern void wfp_impl_dirbuffer_add( + struct wfp_dirbuffer * buffer, + char const * name, + ino_t inode); + +extern json_t * wfp_impl_dirbuffer_take( + struct wfp_dirbuffer * buffer); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsfs/provider/impl/operation/close.c b/lib/webfuse/provider/impl/operation/close.c similarity index 68% rename from lib/wsfs/provider/impl/operation/close.c rename to lib/webfuse/provider/impl/operation/close.c index c62381a..2dfaf9f 100644 --- a/lib/wsfs/provider/impl/operation/close.c +++ b/lib/webfuse/provider/impl/operation/close.c @@ -1,11 +1,11 @@ -#include "wsfs/provider/impl/operation/close.h" +#include "webfuse/provider/impl/operation/close.h" #include -#include "wsfs/core/util.h" +#include "webfuse/core/util.h" -void wsfsp_impl_close( - struct wsfsp_impl_invokation_context * context, +void wfp_impl_close( + struct wfp_impl_invokation_context * context, json_t * params, - int WSFS_UNUSED_PARAM(id)) + int WF_UNUSED_PARAM(id)) { size_t const param_count = json_array_size(params); if (3 == param_count) @@ -28,11 +28,11 @@ void wsfsp_impl_close( } -void wsfsp_impl_close_default( - ino_t WSFS_UNUSED_PARAM(inode), - uint32_t WSFS_UNUSED_PARAM(handle), - int WSFS_UNUSED_PARAM(flags), - void * WSFS_UNUSED_PARAM(user_data)) +void wfp_impl_close_default( + ino_t WF_UNUSED_PARAM(inode), + uint32_t WF_UNUSED_PARAM(handle), + int WF_UNUSED_PARAM(flags), + void * WF_UNUSED_PARAM(user_data)) { // empty } \ No newline at end of file diff --git a/lib/webfuse/provider/impl/operation/close.h b/lib/webfuse/provider/impl/operation/close.h new file mode 100644 index 0000000..da1548b --- /dev/null +++ b/lib/webfuse/provider/impl/operation/close.h @@ -0,0 +1,26 @@ +#ifndef WF_PROVIDER_IMPL_OPERATION_CLOSE_H +#define WF_PROVIDER_IMPL_OPERATION_CLOSE_H + +#include "webfuse/provider/impl/provider.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wfp_impl_close( + struct wfp_impl_invokation_context * context, + json_t * params, + int id); + +extern void wfp_impl_close_default( + ino_t inode, + uint32_t handle, + int flags, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/webfuse/provider/impl/operation/error.h b/lib/webfuse/provider/impl/operation/error.h new file mode 100644 index 0000000..5594ac1 --- /dev/null +++ b/lib/webfuse/provider/impl/operation/error.h @@ -0,0 +1,22 @@ +#ifndef WFP_OPERATION_IMPL_ERROR_H +#define WFP_OPERATION_IMPL_ERROR_H + +#include "webfuse/provider/api.h" +#include "webfuse/core/status.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_request; + +extern WFP_API void wfp_impl_respond_error( + struct wfp_request * request, + wf_status status); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsfs/provider/impl/operation/getattr.c b/lib/webfuse/provider/impl/operation/getattr.c similarity index 65% rename from lib/wsfs/provider/impl/operation/getattr.c rename to lib/webfuse/provider/impl/operation/getattr.c index eb49063..f83c851 100644 --- a/lib/wsfs/provider/impl/operation/getattr.c +++ b/lib/webfuse/provider/impl/operation/getattr.c @@ -1,14 +1,14 @@ -#include "wsfs/provider/impl/operation/getattr.h" +#include "webfuse/provider/impl/operation/getattr.h" #include -#include "wsfs/provider/impl/operation/error.h" -#include "wsfs/provider/impl/request.h" -#include "wsfs/core/util.h" +#include "webfuse/provider/impl/operation/error.h" +#include "webfuse/provider/impl/request.h" +#include "webfuse/core/util.h" -void wsfsp_impl_getattr( - struct wsfsp_impl_invokation_context * context, +void wfp_impl_getattr( + struct wfp_impl_invokation_context * context, json_t * params, int id) { @@ -20,23 +20,23 @@ void wsfsp_impl_getattr( if (json_is_integer(inode_holder)) { ino_t inode = (ino_t) json_integer_value(inode_holder); - struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); + struct wfp_request * request = wfp_impl_request_create(context->request, id); context->provider->getattr(request, inode, context->user_data); } } } -void wsfsp_impl_getattr_default( - struct wsfsp_request * request, - ino_t WSFS_UNUSED_PARAM(inode), - void * WSFS_UNUSED_PARAM(user_data)) +void wfp_impl_getattr_default( + struct wfp_request * request, + ino_t WF_UNUSED_PARAM(inode), + void * WF_UNUSED_PARAM(user_data)) { - wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); + wfp_impl_respond_error(request, WF_BAD_NOENTRY); } -void wsfsp_impl_respond_getattr( - struct wsfsp_request * request, +void wfp_impl_respond_getattr( + struct wfp_request * request, struct stat const * stat) { bool const is_file = (0 != (stat->st_mode & S_IFREG)); @@ -60,5 +60,5 @@ void wsfsp_impl_respond_getattr( json_object_set_new(result, "type", json_string("dir")); } - wsfsp_impl_respond(request, result); + wfp_impl_respond(request, result); } diff --git a/lib/webfuse/provider/impl/operation/getattr.h b/lib/webfuse/provider/impl/operation/getattr.h new file mode 100644 index 0000000..40f3b1c --- /dev/null +++ b/lib/webfuse/provider/impl/operation/getattr.h @@ -0,0 +1,29 @@ +#ifndef WF_PROVIDER_IMPL_OPERATION_GETATTR_H +#define WF_PROVIDER_IMPL_OPERATION_GETATTR_H + +#include "webfuse/provider/impl/provider.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wfp_impl_respond_getattr( + struct wfp_request * request, + struct stat const * stat); + +extern void wfp_impl_getattr( + struct wfp_impl_invokation_context * context, + json_t * params, + int id); + +extern void wfp_impl_getattr_default( + struct wfp_request * request, + ino_t inode, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/lookup.c b/lib/webfuse/provider/impl/operation/lookup.c similarity index 69% rename from lib/wsfs/provider/impl/operation/lookup.c rename to lib/webfuse/provider/impl/operation/lookup.c index 9b55a04..17dc2c1 100644 --- a/lib/wsfs/provider/impl/operation/lookup.c +++ b/lib/webfuse/provider/impl/operation/lookup.c @@ -1,13 +1,13 @@ -#include "wsfs/provider/impl/operation/lookup.h" +#include "webfuse/provider/impl/operation/lookup.h" #include -#include "wsfs/provider/impl/operation/error.h" -#include "wsfs/provider/impl/request.h" -#include "wsfs/core/util.h" +#include "webfuse/provider/impl/operation/error.h" +#include "webfuse/provider/impl/request.h" +#include "webfuse/core/util.h" -void wsfsp_impl_lookup( - struct wsfsp_impl_invokation_context * context, +void wfp_impl_lookup( + struct wfp_impl_invokation_context * context, json_t * params, int id) { @@ -23,14 +23,14 @@ void wsfsp_impl_lookup( ino_t inode = json_integer_value(inode_holder); char const * name = json_string_value(name_holder); - struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); + struct wfp_request * request = wfp_impl_request_create(context->request, id); context->provider->lookup(request, inode, name, context->user_data); } } } -void wsfsp_impl_respond_lookup( - struct wsfsp_request * request, +void wfp_impl_respond_lookup( + struct wfp_request * request, struct stat const * stat) { bool const is_file = (0 != (stat->st_mode & S_IFREG)); @@ -54,15 +54,15 @@ void wsfsp_impl_respond_lookup( json_object_set_new(result, "type", json_string("dir")); } - wsfsp_impl_respond(request, result); + wfp_impl_respond(request, result); } -void wsfsp_impl_lookup_default( - struct wsfsp_request * request, - ino_t WSFS_UNUSED_PARAM(parent), - char const * WSFS_UNUSED_PARAM(name), - void * WSFS_UNUSED_PARAM(user_data)) +void wfp_impl_lookup_default( + struct wfp_request * request, + ino_t WF_UNUSED_PARAM(parent), + char const * WF_UNUSED_PARAM(name), + void * WF_UNUSED_PARAM(user_data)) { - wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); + wfp_impl_respond_error(request, WF_BAD_NOENTRY); } diff --git a/lib/webfuse/provider/impl/operation/lookup.h b/lib/webfuse/provider/impl/operation/lookup.h new file mode 100644 index 0000000..e0fca6f --- /dev/null +++ b/lib/webfuse/provider/impl/operation/lookup.h @@ -0,0 +1,30 @@ +#ifndef WF_PROVIDER_IMPL_OPERATION_LOOKUP_H +#define WF_PROVIDER_IMPL_OPERATION_LOOKUP_H + +#include "webfuse/provider/impl/provider.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wfp_impl_respond_lookup( + struct wfp_request * request, + struct stat const * stat); + +extern void wfp_impl_lookup( + struct wfp_impl_invokation_context * context, + json_t * params, + int id); + +extern void wfp_impl_lookup_default( + struct wfp_request * request, + ino_t parent, + char const * name, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/open.c b/lib/webfuse/provider/impl/operation/open.c similarity index 52% rename from lib/wsfs/provider/impl/operation/open.c rename to lib/webfuse/provider/impl/operation/open.c index ea28a93..6beb974 100644 --- a/lib/wsfs/provider/impl/operation/open.c +++ b/lib/webfuse/provider/impl/operation/open.c @@ -1,10 +1,10 @@ -#include "wsfs/provider/impl/operation/open.h" -#include "wsfs/provider/impl/operation/error.h" -#include "wsfs/provider/impl/request.h" -#include "wsfs/core/util.h" +#include "webfuse/provider/impl/operation/open.h" +#include "webfuse/provider/impl/operation/error.h" +#include "webfuse/provider/impl/request.h" +#include "webfuse/core/util.h" -void wsfsp_impl_open( - struct wsfsp_impl_invokation_context * context, +void wfp_impl_open( + struct wfp_impl_invokation_context * context, json_t * params, int id) { @@ -20,28 +20,28 @@ void wsfsp_impl_open( ino_t inode = (ino_t) json_integer_value(inode_holder); int flags = (ino_t) json_integer_value(flags_holder); - struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); + struct wfp_request * request = wfp_impl_request_create(context->request, id); context->provider->open(request, inode, flags, context->user_data); /* Flawfinder: ignore */ } } } -void wsfsp_impl_open_default( - struct wsfsp_request * request, - ino_t WSFS_UNUSED_PARAM(inode), - int WSFS_UNUSED_PARAM(flags), - void * WSFS_UNUSED_PARAM(user_data)) +void wfp_impl_open_default( + struct wfp_request * request, + ino_t WF_UNUSED_PARAM(inode), + int WF_UNUSED_PARAM(flags), + void * WF_UNUSED_PARAM(user_data)) { - wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); + wfp_impl_respond_error(request, WF_BAD_NOENTRY); } -void wsfsp_impl_respond_open( - struct wsfsp_request * request, +void wfp_impl_respond_open( + struct wfp_request * request, uint32_t handle) { json_t * result = json_object(); json_object_set_new(result, "handle", json_integer((int) handle)); - wsfsp_impl_respond(request, result); + wfp_impl_respond(request, result); } diff --git a/lib/webfuse/provider/impl/operation/open.h b/lib/webfuse/provider/impl/operation/open.h new file mode 100644 index 0000000..22d74c8 --- /dev/null +++ b/lib/webfuse/provider/impl/operation/open.h @@ -0,0 +1,30 @@ +#ifndef WF_PROVIDER_IMPL_OPERATION_OPEN_H +#define WF_PROVIDER_IMPL_OPERATION_OPEN_H + +#include "webfuse/provider/impl/provider.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wfp_impl_respond_open( + struct wfp_request * request, + uint32_t handle); + +extern void wfp_impl_open( + struct wfp_impl_invokation_context * context, + json_t * params, + int id); + +extern void wfp_impl_open_default( + struct wfp_request * request, + ino_t inode, + int flags, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/read.c b/lib/webfuse/provider/impl/operation/read.c similarity index 68% rename from lib/wsfs/provider/impl/operation/read.c rename to lib/webfuse/provider/impl/operation/read.c index c92d6d2..8ea3801 100644 --- a/lib/wsfs/provider/impl/operation/read.c +++ b/lib/webfuse/provider/impl/operation/read.c @@ -1,14 +1,14 @@ -#include "wsfs/provider/impl/operation/read.h" +#include "webfuse/provider/impl/operation/read.h" #include #include -#include "wsfs/provider/impl/operation/error.h" -#include "wsfs/provider/impl/request.h" -#include "wsfs/core/util.h" +#include "webfuse/provider/impl/operation/error.h" +#include "webfuse/provider/impl/request.h" +#include "webfuse/core/util.h" -void wsfsp_impl_read( - struct wsfsp_impl_invokation_context * context, +void wfp_impl_read( + struct wfp_impl_invokation_context * context, json_t * params, int id) { @@ -29,26 +29,26 @@ void wsfsp_impl_read( int handle = json_integer_value(handle_holder); size_t offset = json_integer_value(offset_holder); size_t length = json_integer_value(length_holder); - struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); + struct wfp_request * request = wfp_impl_request_create(context->request, id); context->provider->read(request, inode, handle, offset, length, context->user_data); /* Flawfinder: ignore */ } } } -void wsfsp_impl_read_default( - struct wsfsp_request * request, - ino_t WSFS_UNUSED_PARAM(inode), - uint32_t WSFS_UNUSED_PARAM(handle), - size_t WSFS_UNUSED_PARAM(offset), - size_t WSFS_UNUSED_PARAM(length), - void * WSFS_UNUSED_PARAM(user_data)) +void wfp_impl_read_default( + struct wfp_request * request, + ino_t WF_UNUSED_PARAM(inode), + uint32_t WF_UNUSED_PARAM(handle), + size_t WF_UNUSED_PARAM(offset), + size_t WF_UNUSED_PARAM(length), + void * WF_UNUSED_PARAM(user_data)) { - wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); + wfp_impl_respond_error(request, WF_BAD_NOENTRY); } -void wsfsp_impl_respond_read( - struct wsfsp_request * request, +void wfp_impl_respond_read( + struct wfp_request * request, char const * data, size_t length) { @@ -65,12 +65,12 @@ void wsfsp_impl_respond_read( json_object_set_new(result, "format", json_string("base64")); json_object_set_new(result, "count", json_integer((int) length)); - wsfsp_impl_respond(request, result); + wfp_impl_respond(request, result); free(buffer); } else { - wsfsp_impl_respond_error(request, WSFS_BAD); + wfp_impl_respond_error(request, WF_BAD); } } else @@ -80,6 +80,6 @@ void wsfsp_impl_respond_read( json_object_set_new(result, "format", json_string("identitiy")); json_object_set_new(result, "count", json_integer(0)); - wsfsp_impl_respond(request, result); + wfp_impl_respond(request, result); } } \ No newline at end of file diff --git a/lib/webfuse/provider/impl/operation/read.h b/lib/webfuse/provider/impl/operation/read.h new file mode 100644 index 0000000..5376ee6 --- /dev/null +++ b/lib/webfuse/provider/impl/operation/read.h @@ -0,0 +1,33 @@ +#ifndef WF_PROVIDER_IMPL_OPERATION_READ_H +#define WF_PROVIDER_IMPL_OPERATION_READ_H + +#include "webfuse/provider/impl/provider.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wfp_impl_respond_read( + struct wfp_request * request, + char const * data, + size_t length); + +extern void wfp_impl_read( + struct wfp_impl_invokation_context * context, + json_t * params, + int id); + +extern void wfp_impl_read_default( + struct wfp_request * request, + ino_t inode, + uint32_t handle, + size_t offset, + size_t length, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/webfuse/provider/impl/operation/readdir.c b/lib/webfuse/provider/impl/operation/readdir.c new file mode 100644 index 0000000..96d0362 --- /dev/null +++ b/lib/webfuse/provider/impl/operation/readdir.c @@ -0,0 +1,42 @@ +#include "webfuse/provider/impl/operation/readdir.h" +#include "webfuse/provider/impl/operation/error.h" +#include "webfuse/provider/impl/dirbuffer.h" +#include "webfuse/provider/impl/request.h" +#include "webfuse/core/util.h" + +void wfp_impl_readdir( + struct wfp_impl_invokation_context * context, + json_t * params, + int id) +{ + size_t const count = json_array_size(params); + if (1 == count) + { + json_t * inode_holder = json_array_get(params, 0); + + if ((NULL != inode_holder) && (json_is_integer(inode_holder))) + { + ino_t inode = (ino_t) json_integer_value(inode_holder); + struct wfp_request * request = wfp_impl_request_create(context->request, id); + + context->provider->readdir(request, inode, context->user_data); + } + } +} + +void wfp_impl_readdir_default( + struct wfp_request * request, + ino_t WF_UNUSED_PARAM(directory), + void * WF_UNUSED_PARAM(user_data)) +{ + wfp_impl_respond_error(request, WF_BAD_NOENTRY); +} + +void wfp_impl_respond_readdir( + struct wfp_request * request, + struct wfp_dirbuffer * dirbuffer) +{ + json_t * result = wfp_impl_dirbuffer_take(dirbuffer); + wfp_impl_respond(request, result); +} + diff --git a/lib/webfuse/provider/impl/operation/readdir.h b/lib/webfuse/provider/impl/operation/readdir.h new file mode 100644 index 0000000..80e31af --- /dev/null +++ b/lib/webfuse/provider/impl/operation/readdir.h @@ -0,0 +1,29 @@ +#ifndef WF_PROVIDER_IMPL_OPERATION_READDIR_H +#define WF_PROVIDER_IMPL_OPERATION_READDIR_H + +#include "webfuse/provider/impl/provider.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wfp_impl_respond_readdir( + struct wfp_request * request, + struct wfp_dirbuffer * dirbuffer); + +extern void wfp_impl_readdir( + struct wfp_impl_invokation_context * context, + json_t * params, + int id); + +extern void wfp_impl_readdir_default( + struct wfp_request * request, + ino_t directory, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/webfuse/provider/impl/provider.c b/lib/webfuse/provider/impl/provider.c new file mode 100644 index 0000000..def9e4a --- /dev/null +++ b/lib/webfuse/provider/impl/provider.c @@ -0,0 +1,127 @@ +#include "webfuse/provider/impl/provider.h" + +#include +#include + +#include "webfuse/provider/impl/request.h" +#include "webfuse/provider/impl/operation/lookup.h" +#include "webfuse/provider/impl/operation/getattr.h" +#include "webfuse/provider/impl/operation/readdir.h" +#include "webfuse/provider/impl/operation/open.h" +#include "webfuse/provider/impl/operation/close.h" +#include "webfuse/provider/impl/operation/read.h" + +typedef void wfp_impl_invoke_fn( + struct wfp_impl_invokation_context * context, + json_t * params, + int id); + + +struct wfp_impl_method +{ + char const * name; + wfp_impl_invoke_fn * invoke; + bool is_notification; +}; + +static void wfp_impl_provider_invoke_method( + struct wfp_impl_invokation_context * context, + char const * method_name, + json_t * params, + int id) +{ + static struct wfp_impl_method const methods[] = + { + {"lookup", &wfp_impl_lookup, false}, + {"getattr", &wfp_impl_getattr, false}, + {"readdir", &wfp_impl_readdir, false}, + {"open", &wfp_impl_open, false}, + {"close", &wfp_impl_close, true}, + {"read", &wfp_impl_read, false} + }; + static size_t const count = sizeof(methods) / sizeof(methods[0]); + + for (size_t i = 0; i < count; i++) + { + struct wfp_impl_method const * method = &methods[i]; + if (0 == strcmp(method_name, method->name)) + { + if ((0 < id) || (method->is_notification)) + { + method->invoke(context, params, id); + } + break; + } + } +} + +void wfp_impl_provider_init( + struct wfp_provider * provider) +{ + provider->lookup = &wfp_impl_lookup_default; + provider->getattr = &wfp_impl_getattr_default; + provider->readdir = &wfp_impl_readdir_default; + provider->open = &wfp_impl_open_default; + provider->close = &wfp_impl_close_default; + provider->read = &wfp_impl_read_default; + provider->connected = &wfp_impl_connected_default; + provider->disconnected = &wfp_impl_disconnected_default; + provider->ontimer = &wfp_impl_ontimer_default; +} + +void wfp_impl_provider_init_from_prototype( + struct wfp_provider * provider, + struct wfp_provider const * prototype) +{ + provider->lookup = prototype->lookup; + provider->getattr = prototype->getattr; + provider->readdir = prototype->readdir; + provider->open = prototype->open; + provider->close = prototype->close; + provider->read = prototype->read; + provider->connected = prototype->connected; + provider->disconnected = prototype->disconnected; + provider->ontimer = prototype->ontimer; +} + +void wfp_impl_provider_invoke( + struct wfp_impl_invokation_context * context, + json_t * request) +{ + json_t * method_holder = json_object_get(request, "method"); + json_t * params = json_object_get(request, "params"); + json_t * id_holder = json_object_get(request, "id"); + + if ((NULL != method_holder) && (json_is_string(method_holder)) && + (NULL != params) && (json_is_array(params))) + { + char const * method = json_string_value(method_holder); + int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0; + + wfp_impl_provider_invoke_method(context, method, params, id); + } +} + +void wfp_impl_connected_default( + void * user_data) +{ + (void) user_data; + + // empty +} + +void wfp_impl_disconnected_default( + void * user_data) +{ + (void) user_data; + + // empty +} + +void wfp_impl_ontimer_default( + void * user_data) +{ + (void) user_data; + + // empty +} \ No newline at end of file diff --git a/lib/webfuse/provider/impl/provider.h b/lib/webfuse/provider/impl/provider.h new file mode 100644 index 0000000..ddee453 --- /dev/null +++ b/lib/webfuse/provider/impl/provider.h @@ -0,0 +1,57 @@ +#ifndef WF_PROVIDER_IMPL_PROVIDER_H +#define WF_PROVIDER_IMPL_PROVIDER_H + +#include +#include "webfuse/provider/client_config.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_provider +{ + wfp_connected_fn * connected; + wfp_disconnected_fn * disconnected; + wfp_ontimer_fn * ontimer; + wfp_lookup_fn * lookup; + wfp_getattr_fn * getattr; + wfp_readdir_fn * readdir; + wfp_open_fn * open; + wfp_close_fn * close; + wfp_read_fn * read; +}; + +struct wfp_impl_invokation_context +{ + struct wfp_provider * provider; + void * user_data; + struct wfp_request * request; +}; + +extern void wfp_impl_provider_init( + struct wfp_provider * provider); + +extern void wfp_impl_provider_init_from_prototype( + struct wfp_provider * provider, + struct wfp_provider const * prototype); + + +extern void wfp_impl_provider_invoke( + struct wfp_impl_invokation_context * context, + json_t * request); + +extern void wfp_impl_connected_default( + void * user_data); + +extern void wfp_impl_disconnected_default( + void * user_data); + +extern void wfp_impl_ontimer_default( + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/request.c b/lib/webfuse/provider/impl/request.c similarity index 60% rename from lib/wsfs/provider/impl/request.c rename to lib/webfuse/provider/impl/request.c index 1333526..42ea835 100644 --- a/lib/wsfs/provider/impl/request.c +++ b/lib/webfuse/provider/impl/request.c @@ -1,13 +1,13 @@ -#include "wsfs/provider/impl/request.h" +#include "webfuse/provider/impl/request.h" #include -#include "wsfs/provider/impl/operation/error.h" +#include "webfuse/provider/impl/operation/error.h" -struct wsfsp_request * wsfsp_impl_request_create( - struct wsfsp_request * prototype, +struct wfp_request * wfp_impl_request_create( + struct wfp_request * prototype, int id) { - struct wsfsp_request * request = malloc(sizeof(struct wsfsp_request)); + struct wfp_request * request = malloc(sizeof(struct wfp_request)); if (NULL != request) { request->respond = prototype->respond; @@ -18,14 +18,14 @@ struct wsfsp_request * wsfsp_impl_request_create( return request; } -void wsfsp_impl_request_dispose( - struct wsfsp_request * request) +void wfp_impl_request_dispose( + struct wfp_request * request) { free(request); } -extern void wsfsp_impl_respond( - struct wsfsp_request * request, +extern void wfp_impl_respond( + struct wfp_request * request, json_t * result) { json_t * response = json_object(); @@ -35,12 +35,12 @@ extern void wsfsp_impl_respond( request->respond(response, request->user_data); json_decref(response); - wsfsp_impl_request_dispose(request); + wfp_impl_request_dispose(request); } -void wsfsp_impl_respond_error( - struct wsfsp_request * request, - wsfs_status status) +void wfp_impl_respond_error( + struct wfp_request * request, + wf_status status) { json_t * response = json_object(); json_t * error = json_object(); @@ -51,5 +51,5 @@ void wsfsp_impl_respond_error( request->respond(response, request->user_data); json_decref(response); - wsfsp_impl_request_dispose(request); + wfp_impl_request_dispose(request); } \ No newline at end of file diff --git a/lib/webfuse/provider/impl/request.h b/lib/webfuse/provider/impl/request.h new file mode 100644 index 0000000..8377a80 --- /dev/null +++ b/lib/webfuse/provider/impl/request.h @@ -0,0 +1,43 @@ +#ifndef WF_PROVIDER_IMPL_REQUEST_H +#define WF_PROVIDER_IMPL_REQUEST_H + +#include +#include "webfuse/provider/impl/provider.h" +#include "webfuse/core/status.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef void wfp_impl_request_respond_fn( + json_t * response, + void * user_data); + +struct wfp_request +{ + wfp_impl_request_respond_fn * respond; + void * user_data; + int id; +}; + +extern void wfp_impl_respond_error( + struct wfp_request * request, + wf_status status); + +extern struct wfp_request * wfp_impl_request_create( + struct wfp_request * prototype, + int id); + +extern void wfp_impl_request_dispose( + struct wfp_request * request); + +extern void wfp_impl_respond( + struct wfp_request * request, + json_t * result); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsfs/provider/impl/url.c b/lib/webfuse/provider/impl/url.c similarity index 63% rename from lib/wsfs/provider/impl/url.c rename to lib/webfuse/provider/impl/url.c index 71a26a6..dc6813c 100644 --- a/lib/wsfs/provider/impl/url.c +++ b/lib/webfuse/provider/impl/url.c @@ -1,9 +1,9 @@ -#include "wsfs/provider/impl/url.h" +#include "webfuse/provider/impl/url.h" #include #include -struct wsfsp_impl_url_protocol +struct wfp_impl_url_protocol { char const * name; size_t name_length; @@ -11,11 +11,11 @@ struct wsfsp_impl_url_protocol bool use_tls; }; -static bool wsfsp_impl_url_readprotocol( - struct wsfsp_impl_url * url, +static bool wfp_impl_url_readprotocol( + struct wfp_impl_url * url, char const * * data) { - static struct wsfsp_impl_url_protocol const known_protocols[] = + static struct wfp_impl_url_protocol const known_protocols[] = { {"ws://", 5, 80, false}, {"wss://", 6, 443, true} @@ -25,7 +25,7 @@ static bool wsfsp_impl_url_readprotocol( bool found = false; for(size_t i = 0; (!found) && (i < count); i++) { - struct wsfsp_impl_url_protocol const * protocol = &known_protocols[i]; + struct wfp_impl_url_protocol const * protocol = &known_protocols[i]; if (0 == strncmp(*data, protocol->name, protocol->name_length)) { url->port = protocol->default_port; @@ -38,8 +38,8 @@ static bool wsfsp_impl_url_readprotocol( return found; } -static bool wsfsp_impl_url_readhost( - struct wsfsp_impl_url * url, +static bool wfp_impl_url_readhost( + struct wfp_impl_url * url, char const * * data) { char * end = strpbrk(*data, ":/"); @@ -55,8 +55,8 @@ static bool wsfsp_impl_url_readhost( return result; } -static bool wsfsp_impl_url_readport( - struct wsfsp_impl_url * url, +static bool wfp_impl_url_readport( + struct wfp_impl_url * url, char const * * data) { bool result; @@ -81,8 +81,8 @@ static bool wsfsp_impl_url_readport( return result; } -static bool wsfsp_impl_url_readpath( - struct wsfsp_impl_url * url, +static bool wfp_impl_url_readpath( + struct wfp_impl_url * url, char const * * data) { bool const result = ('/' == **data); @@ -93,33 +93,33 @@ static bool wsfsp_impl_url_readpath( } -bool wsfsp_impl_url_init( - struct wsfsp_impl_url * url, +bool wfp_impl_url_init( + struct wfp_impl_url * url, char const * value) { - memset(url, 0, sizeof(struct wsfsp_impl_url)); + memset(url, 0, sizeof(struct wfp_impl_url)); char const * data = value; bool const result = - wsfsp_impl_url_readprotocol(url, &data) && - wsfsp_impl_url_readhost(url, &data) && - wsfsp_impl_url_readport(url, &data) && - wsfsp_impl_url_readpath(url, &data) + wfp_impl_url_readprotocol(url, &data) && + wfp_impl_url_readhost(url, &data) && + wfp_impl_url_readport(url, &data) && + wfp_impl_url_readpath(url, &data) ; if (!result) { - wsfsp_impl_url_cleanup(url); + wfp_impl_url_cleanup(url); } return result; } -void wsfsp_impl_url_cleanup( - struct wsfsp_impl_url * url) +void wfp_impl_url_cleanup( + struct wfp_impl_url * url) { free(url->host); free(url->path); - memset(url, 0, sizeof(struct wsfsp_impl_url)); + memset(url, 0, sizeof(struct wfp_impl_url)); } diff --git a/lib/wsfs/provider/impl/url.h b/lib/webfuse/provider/impl/url.h similarity index 50% rename from lib/wsfs/provider/impl/url.h rename to lib/webfuse/provider/impl/url.h index ccb0fa6..7755e5c 100644 --- a/lib/wsfs/provider/impl/url.h +++ b/lib/webfuse/provider/impl/url.h @@ -1,5 +1,5 @@ -#ifndef WSFS_PROVIDER_IMPL_URL_H -#define WSFS_PROVIDER_IMPL_URL_H +#ifndef WF_PROVIDER_IMPL_URL_H +#define WF_PROVIDER_IMPL_URL_H #ifndef __cplusplus #include @@ -9,7 +9,7 @@ extern "C" { #endif -struct wsfsp_impl_url +struct wfp_impl_url { char * host; int port; @@ -17,12 +17,12 @@ struct wsfsp_impl_url bool use_tls; }; -extern bool wsfsp_impl_url_init( - struct wsfsp_impl_url * url, +extern bool wfp_impl_url_init( + struct wfp_impl_url * url, char const * value); -extern void wsfsp_impl_url_cleanup( - struct wsfsp_impl_url * url); +extern void wfp_impl_url_cleanup( + struct wfp_impl_url * url); #ifdef __cplusplus diff --git a/lib/wsfs/adapter/api.c b/lib/wsfs/adapter/api.c deleted file mode 100644 index 05121e8..0000000 --- a/lib/wsfs/adapter/api.c +++ /dev/null @@ -1,141 +0,0 @@ -#include "wsfs_adapter.h" - -#include "wsfs/adapter/impl/server.h" -#include "wsfs/adapter/impl/server_protocol.h" -#include "wsfs/adapter/impl/server_config.h" -#include "wsfs/adapter/impl/credentials.h" - -// server - -struct wsfs_server * wsfs_server_create( - struct wsfs_server_config * config) -{ - return wsfs_impl_server_create(config); -} - -void wsfs_server_dispose( - struct wsfs_server * server) -{ - wsfs_impl_server_dispose(server); -} - -void wsfs_server_run( - struct wsfs_server * server) -{ - wsfs_impl_server_run(server); -} - -void wsfs_server_shutdown( - struct wsfs_server * server) -{ - wsfs_impl_server_shutdown(server); -} - -// server protocol - -struct wsfs_server_protocol * wsfs_server_protocol_create( - char * mount_point) -{ - return wsfs_impl_server_protocol_create(mount_point); -} - -void wsfs_server_protocol_dispose( - struct wsfs_server_protocol * protocol) -{ - wsfs_impl_server_protocol_dispose(protocol); -} - -void wsfs_server_protocol_init_lws( - struct wsfs_server_protocol * protocol, - struct lws_protocols * lws_protocol) -{ - wsfs_impl_server_protocol_init_lws(protocol, lws_protocol); -} - -void wsfs_server_protocol_add_authenticator( - struct wsfs_server_protocol * protocol, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data) -{ - wsfs_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data); -} - -// server_config - -struct wsfs_server_config * wsfs_server_config_create(void) -{ - return wsfs_impl_server_config_create(); -} - -void wsfs_server_config_dispose( - struct wsfs_server_config * config) -{ - wsfs_impl_server_config_dispose(config); -} - -void wsfs_server_config_set_mountpoint( - struct wsfs_server_config * config, - char const * mount_point) -{ - wsfs_impl_server_config_set_mountpoint(config, mount_point); -} - -void wsfs_server_config_set_documentroot( - struct wsfs_server_config * config, - char const * document_root) -{ - wsfs_impl_server_config_set_documentroot(config, document_root); -} - -void wsfs_server_config_set_keypath( - struct wsfs_server_config * config, - char const * key_path) -{ - wsfs_impl_server_config_set_keypath(config, key_path); -} - -void wsfs_server_config_set_certpath( - struct wsfs_server_config * config, - char const * cert_path) -{ - wsfs_impl_server_config_set_certpath(config, cert_path); -} - -void wsfs_server_config_set_vhostname( - struct wsfs_server_config * config, - char const * vhost_name) -{ - wsfs_impl_server_config_set_vhostname(config, vhost_name); -} - -void wsfs_server_config_set_port( - struct wsfs_server_config * config, - int port) -{ - wsfs_impl_server_config_set_port(config, port); -} - -void wsfs_server_config_add_authenticator( - struct wsfs_server_config * config, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data) -{ - wsfs_impl_server_config_add_authenticator(config, type, authenticate, user_data); -} - -// credentials - -char const * wsfs_credentials_type( - struct wsfs_credentials const * credentials) -{ - return wsfs_impl_credentials_type(credentials); -} - -char const * wsfs_credentials_get( - struct wsfs_credentials const * credentials, - char const * key) -{ - return wsfs_impl_credentials_get(credentials, key); -} diff --git a/lib/wsfs/adapter/impl/authenticator.h b/lib/wsfs/adapter/impl/authenticator.h deleted file mode 100644 index da12d62..0000000 --- a/lib/wsfs/adapter/impl/authenticator.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATOR_H -#define WSFS_ADAPTER_IMPL_AUTHENTICATOR_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/authenticate.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_credentials; - -struct wsfs_impl_authenticator -{ - char * type; - wsfs_authenticate_fn * authenticate; - void * user_data; - struct wsfs_impl_authenticator * next; -}; - -extern struct wsfs_impl_authenticator * wsfs_impl_authenticator_create( - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data); - -extern void wsfs_impl_authenticator_dispose( - struct wsfs_impl_authenticator * authenticator); - -extern bool wsfs_impl_authenticator_autenticate( - struct wsfs_impl_authenticator * authenticator, - struct wsfs_credentials * credentials); - - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/wsfs/adapter/impl/authenticators.c b/lib/wsfs/adapter/impl/authenticators.c deleted file mode 100644 index 7b5808a..0000000 --- a/lib/wsfs/adapter/impl/authenticators.c +++ /dev/null @@ -1,101 +0,0 @@ -#include "wsfs/adapter/impl/authenticators.h" -#include -#include - -#include "wsfs/adapter/impl/authenticator.h" -#include "wsfs/adapter/impl/credentials.h" - -static struct wsfs_impl_authenticator * wsfs_impl_authenticators_find( - struct wsfs_impl_authenticators * authenticators, - char const * type) -{ - struct wsfs_impl_authenticator * result = NULL; - - struct wsfs_impl_authenticator * actual = authenticators->first; - while ((NULL == result) && (NULL != actual)) - { - struct wsfs_impl_authenticator * next = actual->next; - if (0 == strcmp(type, actual->type)) - { - result = actual; - } - - actual = next; - } - - return result; -} - -void wsfs_impl_authenticators_init( - struct wsfs_impl_authenticators * authenticators) -{ - authenticators->first = NULL; -} - -void wsfs_impl_authenticators_cleanup( - struct wsfs_impl_authenticators * authenticators) -{ - struct wsfs_impl_authenticator * actual = authenticators->first; - while (NULL != actual) - { - struct wsfs_impl_authenticator * next = actual->next; - wsfs_impl_authenticator_dispose(actual); - actual = next; - } - - authenticators->first = NULL; -} - -void wsfs_impl_authenticators_clone( - struct wsfs_impl_authenticators * authenticators, - struct wsfs_impl_authenticators * other) -{ - wsfs_impl_authenticators_init(other); - - struct wsfs_impl_authenticator * actual = authenticators->first; - while (NULL != actual) - { - struct wsfs_impl_authenticator * next = actual->next; - wsfs_impl_authenticators_add(other, - actual->type, actual->authenticate, actual->user_data); - actual = next; - } - -} - -extern void wsfs_impl_authenticators_move( - struct wsfs_impl_authenticators * authenticators, - struct wsfs_impl_authenticators * other) -{ - other->first = authenticators->first; - authenticators->first = NULL; -} - -void wsfs_impl_authenticators_add( - struct wsfs_impl_authenticators * authenticators, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data) -{ - struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(type, authenticate, user_data); - authenticator->next = authenticators->first; - authenticators->first = authenticator; -} - -bool wsfs_impl_authenticators_authenticate( - struct wsfs_impl_authenticators * authenticators, - struct wsfs_credentials * credentials) -{ - bool result = (NULL == authenticators->first); - - if (NULL != credentials) - { - struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticators_find(authenticators, credentials->type); - if (NULL != authenticator) - { - result = wsfs_impl_authenticator_autenticate(authenticator, credentials); - } - } - - return result; -} \ No newline at end of file diff --git a/lib/wsfs/adapter/impl/authenticators.h b/lib/wsfs/adapter/impl/authenticators.h deleted file mode 100644 index 0e9ce18..0000000 --- a/lib/wsfs/adapter/impl/authenticators.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATORS_H -#define WSFS_ADAPTER_IMPL_AUTHENTICATORS_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/authenticate.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_impl_authenticator; -struct wsfs_credentials; - -struct wsfs_impl_authenticators -{ - struct wsfs_impl_authenticator * first; -}; - -extern void wsfs_impl_authenticators_init( - struct wsfs_impl_authenticators * authenticators); - -extern void wsfs_impl_authenticators_cleanup( - struct wsfs_impl_authenticators * authenticators); - -extern void wsfs_impl_authenticators_clone( - struct wsfs_impl_authenticators * authenticators, - struct wsfs_impl_authenticators * other); - -extern void wsfs_impl_authenticators_move( - struct wsfs_impl_authenticators * authenticators, - struct wsfs_impl_authenticators * other); - -extern void wsfs_impl_authenticators_add( - struct wsfs_impl_authenticators * authenticators, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data); - -extern bool wsfs_impl_authenticators_authenticate( - struct wsfs_impl_authenticators * authenticators, - struct wsfs_credentials * credentials); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/impl/credentials.h b/lib/wsfs/adapter/impl/credentials.h deleted file mode 100644 index 368db1c..0000000 --- a/lib/wsfs/adapter/impl/credentials.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_CREDENTIALS_H -#define WSFS_ADAPTER_IMPL_CREDENTIALS_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_credentials -{ - char * type; - json_t * data; -}; - -extern void wsfs_impl_credentials_init( - struct wsfs_credentials * credentials, - char const * type, - json_t * data); - -extern void wsfs_impl_credentials_cleanup( - struct wsfs_credentials * credentials); - -extern char const * wsfs_impl_credentials_type( - struct wsfs_credentials const * credentials); - -extern char const * wsfs_impl_credentials_get( - struct wsfs_credentials const * credentials, - char const * key); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/adapter/impl/filesystem.h b/lib/wsfs/adapter/impl/filesystem.h deleted file mode 100644 index 5b65876..0000000 --- a/lib/wsfs/adapter/impl/filesystem.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_FILESYSTEM_H -#define WSFS_ADAPTER_IMPL_FILESYSTEM_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/impl/fuse_wrapper.h" -#include "wsfs/adapter/impl/operations.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_impl_jsonrpc_server; - -struct wsfs_impl_filesystem -{ - struct fuse_args args; - struct fuse_session * session; - struct fuse_buf buffer; - struct wsfs_impl_operations_context user_data; -}; - -extern bool wsfs_impl_filesystem_init( - struct wsfs_impl_filesystem * filesystem, - struct wsfs_impl_jsonrpc_server * rpc, - char * mount_point); - -extern void wsfs_impl_filesystem_cleanup( - struct wsfs_impl_filesystem * filesystem); - -extern int wsfs_impl_filesystem_get_fd( - struct wsfs_impl_filesystem * filesystem); - -extern void wsfs_impl_filesystem_process_request( - struct wsfs_impl_filesystem * filesystem); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/impl/jsonrpc/method.c b/lib/wsfs/adapter/impl/jsonrpc/method.c deleted file mode 100644 index 8bf3eda..0000000 --- a/lib/wsfs/adapter/impl/jsonrpc/method.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "wsfs/adapter/impl/jsonrpc/method_intern.h" - -#include -#include - -struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create( - char const * name, - wsfs_impl_jsonrpc_method_invoke_fn * invoke, - void * user_data) -{ - struct wsfs_impl_jsonrpc_method * method = malloc(sizeof(struct wsfs_impl_jsonrpc_method)); - if (NULL != method) - { - method->next = NULL; - method->name = strdup(name); - method->invoke = invoke; - method->user_data = user_data; - } - - return method; -} - -void wsfs_impl_jsonrpc_method_dispose( - struct wsfs_impl_jsonrpc_method * method) -{ - free(method->name); - free(method); -} diff --git a/lib/wsfs/adapter/impl/jsonrpc/method_intern.h b/lib/wsfs/adapter/impl/jsonrpc/method_intern.h deleted file mode 100644 index 04edb70..0000000 --- a/lib/wsfs/adapter/impl/jsonrpc/method_intern.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H -#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H - -#include "wsfs/adapter/impl/jsonrpc/method.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_impl_jsonrpc_method -{ - struct wsfs_impl_jsonrpc_method * next; - char * name; - wsfs_impl_jsonrpc_method_invoke_fn * invoke; - void * user_data; -}; - -extern struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create( - char const * name, - wsfs_impl_jsonrpc_method_invoke_fn * invoke, - void * user_data); - -extern void wsfs_impl_jsonrpc_method_dispose( - struct wsfs_impl_jsonrpc_method * method); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/impl/jsonrpc/response.h b/lib/wsfs/adapter/impl/jsonrpc/response.h deleted file mode 100644 index 65518dd..0000000 --- a/lib/wsfs/adapter/impl/jsonrpc/response.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H -#define WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H - -#ifndef __cplusplus -#include -#else -#include -using std::size_t; -#endif - -#include -#include "wsfs/core/status.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct wsfs_impl_jsonrpc_response -{ - wsfs_status status; - int id; - json_t * result; -}; - -extern void wsfs_impl_jsonrpc_response_init( - struct wsfs_impl_jsonrpc_response * response, - char const * buffer, - size_t buffer_length); - -extern void wsfs_impl_jsonrpc_response_cleanup( - struct wsfs_impl_jsonrpc_response * response); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/lib/wsfs/adapter/impl/jsonrpc/server.c b/lib/wsfs/adapter/impl/jsonrpc/server.c deleted file mode 100644 index ddd171f..0000000 --- a/lib/wsfs/adapter/impl/jsonrpc/server.c +++ /dev/null @@ -1,186 +0,0 @@ -#include "wsfs/adapter/impl/jsonrpc/server.h" -#include - -#include "wsfs/adapter/impl/jsonrpc/method_intern.h" -#include "wsfs/adapter/impl/jsonrpc/request.h" -#include "wsfs/adapter/impl/jsonrpc/response.h" - -#define WSFS_DEFAULT_TIMEOUT (10 * 1000) - -static struct wsfs_impl_jsonrpc_method const * wsfs_impl_jsonrpc_server_getmethod( - struct wsfs_impl_jsonrpc_server * server, - char const * name) -{ - struct wsfs_impl_jsonrpc_method * method = server->methods; - while ((NULL != method) && (0 == strcmp(name, method->name))) - { - method = method->next; - } - - return method; -} - -static void wsfs_impl_jsonrpc_server_timeout( - struct wsfs_impl_timer * timer) -{ - struct wsfs_impl_jsonrpc_server * server = timer->user_data; - - if (server->request.is_pending) - { - wsfs_impl_jsonrpc_method_finished_fn * finished = server->request.finished; - void * user_data = server->request.user_data; - - server->request.is_pending = false; - server->request.id = 0; - server->request.user_data = NULL; - server->request.finished = NULL; - wsfs_impl_timer_cancel(&server->request.timer); - - finished(user_data, WSFS_BAD_TIMEOUT, NULL); - } -} - -void wsfs_impl_jsonrpc_server_init( - struct wsfs_impl_jsonrpc_server * server, - struct wsfs_impl_timeout_manager * timeout_manager) -{ - server->methods = NULL; - server->request.is_pending = false; - - wsfs_impl_timer_init(&server->request.timer, timeout_manager); -} - -void wsfs_impl_jsonrpc_server_cleanup( - struct wsfs_impl_jsonrpc_server * server) -{ - wsfs_impl_timer_cleanup(&server->request.timer); - - if (server->request.is_pending) - { - server->request.finished(server->request.user_data, WSFS_BAD, NULL); - server->request.is_pending = false; - } - - struct wsfs_impl_jsonrpc_method * method = server->methods; - while (NULL != method) - { - struct wsfs_impl_jsonrpc_method * next = method->next; - method->next = NULL; - wsfs_impl_jsonrpc_method_dispose(method); - method = next; - } - server->methods = NULL; -} - -void wsfs_impl_jsonrpc_server_add( - struct wsfs_impl_jsonrpc_server * server, - char const * name, - wsfs_impl_jsonrpc_method_invoke_fn * invoke, - void * user_data) -{ - struct wsfs_impl_jsonrpc_method * method = wsfs_impl_jsonrpc_method_create(name, invoke, user_data); - method->next = server->methods; - server->methods = method; -} - -void wsfs_impl_jsonrpc_server_invoke( - struct wsfs_impl_jsonrpc_server * server, - wsfs_impl_jsonrpc_method_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - ... -) -{ - if (!server->request.is_pending) - { - struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name); - if (NULL != method) - { - server->request.is_pending = true; - server->request.finished = finished; - server->request.user_data = user_data; - server->request.id = 42; - wsfs_impl_timer_start(&server->request.timer, wsfs_impl_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT), - &wsfs_impl_jsonrpc_server_timeout, server); - - va_list args; - va_start(args, param_info); - json_t * request = wsfs_impl_jsonrpc_request_create(method_name, server->request.id, param_info, args); - va_end(args); - if (NULL != request) - { - if (!method->invoke(method->user_data, request)) - { - server->request.is_pending = false; - server->request.finished = NULL; - server->request.user_data = NULL; - server->request.id = 0; - wsfs_impl_timer_cancel(&server->request.timer); - - finished(user_data, WSFS_BAD, NULL); - } - json_decref(request); - } - } - else - { - finished(user_data, WSFS_BAD_NOTIMPLEMENTED, NULL); - } - } - else - { - finished(user_data, WSFS_BAD_BUSY, NULL); - } -} - -extern void wsfs_impl_jsonrpc_server_notify( - struct wsfs_impl_jsonrpc_server * server, - char const * method_name, - char const * param_info, - ... -) -{ - struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name); - if (NULL != method) - { - - va_list args; - va_start(args, param_info); - json_t * request = wsfs_impl_jsonrpc_request_create(method_name, 0, param_info, args); - va_end(args); - if (NULL != request) - { - method->invoke(method->user_data, request); - json_decref(request); - } - } - -} - - -void wsfs_impl_jsonrpc_server_onresult( - struct wsfs_impl_jsonrpc_server * server, - char const * message, - size_t length) -{ - struct wsfs_impl_jsonrpc_response response; - wsfs_impl_jsonrpc_response_init(&response, message, length); - - if ((server->request.is_pending) && (response.id == server->request.id)) - { - wsfs_impl_jsonrpc_method_finished_fn * finished = server->request.finished; - void * user_data = server->request.user_data; - - server->request.is_pending = false; - server->request.id = 0; - server->request.user_data = NULL; - server->request.finished = NULL; - wsfs_impl_timer_cancel(&server->request.timer); - - finished(user_data, response.status, response.result); - } - - wsfs_impl_jsonrpc_response_cleanup(&response); -} - diff --git a/lib/wsfs/adapter/impl/jsonrpc/server.h b/lib/wsfs/adapter/impl/jsonrpc/server.h deleted file mode 100644 index 140e6f5..0000000 --- a/lib/wsfs/adapter/impl/jsonrpc/server.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H -#define WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include "wsfs/adapter/impl/jsonrpc/method.h" -#include "wsfs/adapter/impl/time/timeout_manager.h" -#include "wsfs/adapter/impl/time/timer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct wsfs_impl_jsonrpc_request -{ - bool is_pending; - wsfs_impl_jsonrpc_method_finished_fn * finished; - void * user_data; - int id; - struct wsfs_impl_timer timer; -}; - -struct wsfs_impl_jsonrpc_server -{ - struct wsfs_impl_jsonrpc_method * methods; - struct wsfs_impl_jsonrpc_request request; -}; - -extern void wsfs_impl_jsonrpc_server_init( - struct wsfs_impl_jsonrpc_server * server, - struct wsfs_impl_timeout_manager * manager); - -extern void wsfs_impl_jsonrpc_server_cleanup( - struct wsfs_impl_jsonrpc_server * server); - -extern void wsfs_impl_jsonrpc_server_add( - struct wsfs_impl_jsonrpc_server * server, - char const * name, - wsfs_impl_jsonrpc_method_invoke_fn * invoke, - void * user_data ); - -extern void wsfs_impl_jsonrpc_server_invoke( - struct wsfs_impl_jsonrpc_server * server, - wsfs_impl_jsonrpc_method_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - ... -); - -extern void wsfs_impl_jsonrpc_server_notify( - struct wsfs_impl_jsonrpc_server * server, - char const * method_name, - char const * param_info, - ... -); - -extern void wsfs_impl_jsonrpc_server_onresult( - struct wsfs_impl_jsonrpc_server * server, - char const * message, - size_t length); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/impl/jsonrpc/util.h b/lib/wsfs/adapter/impl/jsonrpc/util.h deleted file mode 100644 index ae49ee2..0000000 --- a/lib/wsfs/adapter/impl/jsonrpc/util.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_JSON_UTIL_H -#define WSFS_ADAPTER_IMPL_JSON_UTIL_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/impl/operation/close.c b/lib/wsfs/adapter/impl/operation/close.c deleted file mode 100644 index b50bbcd..0000000 --- a/lib/wsfs/adapter/impl/operation/close.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "wsfs/adapter/impl/operations.h" - -#include -#include -#include - -#include "wsfs/adapter/impl/jsonrpc/server.h" -#include "wsfs/core/util.h" - -void wsfs_impl_operation_close( - fuse_req_t request, - fuse_ino_t inode, - struct fuse_file_info * file_info) -{ - struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; - - int handle = (int) (file_info->fh & INT_MAX); - wsfs_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags); - fuse_reply_err(request, 0); -} diff --git a/lib/wsfs/adapter/impl/server.h b/lib/wsfs/adapter/impl/server.h deleted file mode 100644 index ed5e290..0000000 --- a/lib/wsfs/adapter/impl/server.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_SERVER_H -#define WSFS_ADAPTER_IMPL_SERVER_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_server; -struct wsfs_server_config; - -extern struct wsfs_server * wsfs_impl_server_create( - struct wsfs_server_config * config); - -extern void wsfs_impl_server_dispose( - struct wsfs_server * server); - -extern void wsfs_impl_server_run( - struct wsfs_server * server); - -extern void wsfs_impl_server_shutdown( - struct wsfs_server * server); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/impl/server_config.c b/lib/wsfs/adapter/impl/server_config.c deleted file mode 100644 index ab45145..0000000 --- a/lib/wsfs/adapter/impl/server_config.c +++ /dev/null @@ -1,127 +0,0 @@ -#include "wsfs/adapter/impl/server_config.h" - -#include -#include - -static char * wsfs_impl_server_config_strdup(char const * value) -{ - char * result = NULL; - if (NULL != value) - { - result = strdup(value); - } - - return result; -} - -void wsfs_impl_server_config_init( - struct wsfs_server_config * config) -{ - memset(config, 0, sizeof(struct wsfs_server_config)); - - wsfs_impl_authenticators_init(&config->authenticators); -} - -void wsfs_impl_server_config_cleanup( - struct wsfs_server_config * config) -{ - wsfs_impl_authenticators_cleanup(&config->authenticators); - - free(config->mount_point); - free(config->document_root); - free(config->key_path); - free(config->cert_path); - free(config->vhost_name); - - wsfs_impl_server_config_init(config); -} - -void wsfs_impl_server_config_clone( - struct wsfs_server_config * config, - struct wsfs_server_config * clone) -{ - clone->mount_point = wsfs_impl_server_config_strdup(config->mount_point); - clone->document_root = wsfs_impl_server_config_strdup(config->document_root); - clone->key_path = wsfs_impl_server_config_strdup(config->key_path); - clone->cert_path = wsfs_impl_server_config_strdup(config->cert_path); - clone->vhost_name = wsfs_impl_server_config_strdup(config->vhost_name); - clone->port = config->port; - - wsfs_impl_authenticators_clone(&config->authenticators, &clone->authenticators); -} - -struct wsfs_server_config * wsfs_impl_server_config_create(void) -{ - struct wsfs_server_config * config = malloc(sizeof(struct wsfs_server_config)); - if (NULL != config) - { - wsfs_impl_server_config_init(config); - } - - return config; -} - -void wsfs_impl_server_config_dispose( - struct wsfs_server_config * config) -{ - wsfs_impl_server_config_cleanup(config); - free(config); -} - -void wsfs_impl_server_config_set_mountpoint( - struct wsfs_server_config * config, - char const * mount_point) -{ - free(config->mount_point); - config->mount_point = strdup(mount_point); -} - -void wsfs_impl_server_config_set_documentroot( - struct wsfs_server_config * config, - char const * document_root) -{ - free(config->document_root); - config->document_root = strdup(document_root); -} - -void wsfs_impl_server_config_set_keypath( - struct wsfs_server_config * config, - char const * key_path) -{ - free(config->key_path); - config->key_path = strdup(key_path); -} - -void wsfs_impl_server_config_set_certpath( - struct wsfs_server_config * config, - char const * cert_path) -{ - free(config->cert_path); - config->cert_path = strdup(cert_path); -} - -void wsfs_impl_server_config_set_vhostname( - struct wsfs_server_config * config, - char const * vhost_name) -{ - free(config->vhost_name); - config->vhost_name = strdup(vhost_name); -} - -void wsfs_impl_server_config_set_port( - struct wsfs_server_config * config, - int port) -{ - config->port = port; -} - -void wsfs_impl_server_config_add_authenticator( - struct wsfs_server_config * config, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data -) -{ - wsfs_impl_authenticators_add(&config->authenticators, type, authenticate, user_data); -} - diff --git a/lib/wsfs/adapter/impl/server_config.h b/lib/wsfs/adapter/impl/server_config.h deleted file mode 100644 index a0f1a65..0000000 --- a/lib/wsfs/adapter/impl/server_config.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_SERVER_CONFIG_H -#define WSFS_ADAPTER_IMPL_SERVER_CONFIG_H - -#include "wsfs/adapter/impl/authenticators.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct wsfs_server_config -{ - char * mount_point; - char * document_root; - char * key_path; - char * cert_path; - char * vhost_name; - int port; - struct wsfs_impl_authenticators authenticators; -}; - -extern struct wsfs_server_config * wsfs_impl_server_config_create(void); - -extern void wsfs_impl_server_config_dispose( - struct wsfs_server_config * config); - -extern void wsfs_impl_server_config_init( - struct wsfs_server_config * config); - -extern void wsfs_impl_server_config_cleanup( - struct wsfs_server_config * config); - -extern void wsfs_impl_server_config_clone( - struct wsfs_server_config * config, - struct wsfs_server_config * clone); - -extern void wsfs_impl_server_config_set_mountpoint( - struct wsfs_server_config * config, - char const * mount_point); - -extern void wsfs_impl_server_config_set_documentroot( - struct wsfs_server_config * config, - char const * document_root); - -extern void wsfs_impl_server_config_set_keypath( - struct wsfs_server_config * config, - char const * key_path); - -extern void wsfs_impl_server_config_set_certpath( - struct wsfs_server_config * config, - char const * cert_path); - -extern void wsfs_impl_server_config_set_vhostname( - struct wsfs_server_config * config, - char const * vhost_name); - -extern void wsfs_impl_server_config_set_port( - struct wsfs_server_config * config, - int port); - -extern void wsfs_impl_server_config_add_authenticator( - struct wsfs_server_config * config, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data -); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/impl/server_protocol.c b/lib/wsfs/adapter/impl/server_protocol.c deleted file mode 100644 index 60e69a6..0000000 --- a/lib/wsfs/adapter/impl/server_protocol.c +++ /dev/null @@ -1,166 +0,0 @@ -#include "wsfs/adapter/impl/server_protocol.h" - -#include -#include - -#include "wsfs/core/message.h" -#include "wsfs/core/util.h" - -#include "wsfs/adapter/impl/filesystem.h" - -static int wsfs_impl_server_protocol_callback( - struct lws * wsi, - enum lws_callback_reasons reason, - void * WSFS_UNUSED_PARAM(user), - void * in, - size_t len) -{ - struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); - struct wsfs_server_protocol * protocol = ws_protocol->user; - - wsfs_impl_timeout_manager_check(&protocol->timeout_manager); - struct wsfs_impl_session * session = wsfs_impl_session_manager_get(&protocol->session_manager, wsi); - - switch (reason) - { - case LWS_CALLBACK_PROTOCOL_INIT: - { - lws_sock_file_fd_type fd; - fd.filefd = wsfs_impl_filesystem_get_fd(&protocol->filesystem); - if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL)) - { - fprintf(stderr, "error: unable to adopt fd"); - } - } - break; - case LWS_CALLBACK_ESTABLISHED: - session = wsfs_impl_session_manager_add( - &protocol->session_manager, - wsi, - &protocol->authenticators, - &protocol->rpc); - - if (NULL != session) - { - wsfs_impl_session_authenticate(session, NULL); - } - break; - case LWS_CALLBACK_CLOSED: - wsfs_impl_session_manager_remove(&protocol->session_manager, wsi); - break; - case LWS_CALLBACK_SERVER_WRITEABLE: - if (NULL != session) - { - wsfs_impl_session_onwritable(session); - } - break; - case LWS_CALLBACK_RECEIVE: - if (NULL != session) - { - wsfs_impl_session_receive(session, in, len); - } - break; - case LWS_CALLBACK_RAW_RX_FILE: - wsfs_impl_filesystem_process_request(&protocol->filesystem); - break; - default: - break; - } - - return 0; -} - -static bool wsfs_impl_server_protocol_invoke( - void * user_data, - json_t const * request) -{ - struct wsfs_server_protocol * protocol = user_data; - struct wsfs_impl_session * session = &protocol->session_manager.session; - struct wsfs_message * message = wsfs_message_create(request); - - bool const result = wsfs_impl_session_send(session, message); - - return result; -} - - -struct wsfs_server_protocol * wsfs_impl_server_protocol_create( - char * mount_point) -{ - struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol)); - if (NULL != protocol) - { - if (!wsfs_impl_server_protocol_init(protocol, mount_point)) - { - free(protocol); - protocol = NULL; - } - } - - return protocol; -} - -void wsfs_impl_server_protocol_dispose( - struct wsfs_server_protocol * protocol) -{ - wsfs_impl_server_protocol_cleanup(protocol); - free(protocol); -} - -void wsfs_impl_server_protocol_init_lws( - struct wsfs_server_protocol * protocol, - struct lws_protocols * lws_protocol) -{ - lws_protocol->callback = &wsfs_impl_server_protocol_callback; - lws_protocol->per_session_data_size = 0; - lws_protocol->user = protocol; -} - -bool wsfs_impl_server_protocol_init( - struct wsfs_server_protocol * protocol, - char * mount_point) -{ - wsfs_impl_timeout_manager_init(&protocol->timeout_manager); - wsfs_impl_session_manager_init(&protocol->session_manager); - wsfs_impl_authenticators_init(&protocol->authenticators); - - wsfs_impl_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager); - wsfs_impl_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_impl_server_protocol_invoke, protocol); - wsfs_impl_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_impl_server_protocol_invoke, protocol); - wsfs_impl_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_impl_server_protocol_invoke, protocol); - wsfs_impl_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_impl_server_protocol_invoke, protocol); - wsfs_impl_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_impl_server_protocol_invoke, protocol); - wsfs_impl_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_impl_server_protocol_invoke, protocol); - - bool const success = wsfs_impl_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point); - - // cleanup on error - if (!success) - { - wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc); - wsfs_impl_authenticators_cleanup(&protocol->authenticators); - wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager); - wsfs_impl_session_manager_cleanup(&protocol->session_manager); - } - - return success; -} - -void wsfs_impl_server_protocol_cleanup( - struct wsfs_server_protocol * protocol) -{ - wsfs_impl_filesystem_cleanup(&protocol->filesystem); - wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc); - wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager); - wsfs_impl_authenticators_cleanup(&protocol->authenticators); - wsfs_impl_session_manager_cleanup(&protocol->session_manager); -} - -void wsfs_impl_server_protocol_add_authenticator( - struct wsfs_server_protocol * protocol, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data) -{ - wsfs_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data); -} diff --git a/lib/wsfs/adapter/impl/server_protocol.h b/lib/wsfs/adapter/impl/server_protocol.h deleted file mode 100644 index fee9ae6..0000000 --- a/lib/wsfs/adapter/impl/server_protocol.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H -#define WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H - -#include "wsfs/adapter/impl/filesystem.h" -#include "wsfs/adapter/impl/jsonrpc/server.h" -#include "wsfs/adapter/impl/time/timeout_manager.h" -#include "wsfs/adapter/impl/authenticators.h" -#include "wsfs/adapter/impl/session_manager.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct lws_protocols; - -struct wsfs_server_protocol -{ - struct wsfs_impl_timeout_manager timeout_manager; - struct wsfs_impl_filesystem filesystem; - struct wsfs_impl_jsonrpc_server rpc; - struct wsfs_impl_authenticators authenticators; - struct wsfs_impl_session_manager session_manager; -}; - -extern bool wsfs_impl_server_protocol_init( - struct wsfs_server_protocol * protocol, - char * mount_point); - -extern void wsfs_impl_server_protocol_cleanup( - struct wsfs_server_protocol * protocol); - -extern struct wsfs_server_protocol * wsfs_impl_server_protocol_create( - char * mount_point); - -extern void wsfs_impl_server_protocol_dispose( - struct wsfs_server_protocol * protocol); - -extern void wsfs_impl_server_protocol_init_lws( - struct wsfs_server_protocol * protocol, - struct lws_protocols * lws_protocol); - -extern void wsfs_impl_server_protocol_add_authenticator( - struct wsfs_server_protocol * protocol, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/impl/session.c b/lib/wsfs/adapter/impl/session.c deleted file mode 100644 index 436b039..0000000 --- a/lib/wsfs/adapter/impl/session.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "wsfs/adapter/impl/session.h" -#include "wsfs/adapter/impl/authenticators.h" -#include "wsfs/core/message_queue.h" -#include "wsfs/core/message.h" -#include "wsfs/adapter/impl/jsonrpc/server.h" - -#include -#include - -void wsfs_impl_session_init( - struct wsfs_impl_session * session, - struct lws * wsi, - struct wsfs_impl_authenticators * authenticators, - struct wsfs_impl_jsonrpc_server * rpc) - { - session->wsi = wsi; - session->is_authenticated = false; - session->authenticators = authenticators; - session->rpc = rpc; - wsfs_message_queue_init(&session->queue); - } - -void wsfs_impl_session_cleanup( - struct wsfs_impl_session * session) -{ - wsfs_message_queue_cleanup(&session->queue); - session->is_authenticated = false; - session->wsi = NULL; - session->authenticators = NULL; - session->rpc = NULL; -} - -void wsfs_impl_session_authenticate( - struct wsfs_impl_session * session, - struct wsfs_credentials * creds) -{ - session->is_authenticated = wsfs_impl_authenticators_authenticate(session->authenticators, creds); -} - -bool wsfs_impl_session_send( - struct wsfs_impl_session * session, - struct wsfs_message * message) -{ - bool result = (session->is_authenticated) && (NULL != session->wsi); - - if (result) - { - wsfs_message_queue_push(&session->queue, message); - lws_callback_on_writable(session->wsi); - - result = true; - } - else - { - wsfs_message_dispose(message); - } - - return result; -} - -void wsfs_impl_session_onwritable( - struct wsfs_impl_session * session) -{ - if (!wsfs_message_queue_empty(&session->queue)) - { - struct wsfs_message * message = wsfs_message_queue_pop(&session->queue); - lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT); - wsfs_message_dispose(message); - - if (!wsfs_message_queue_empty(&session->queue)) - { - lws_callback_on_writable(session->wsi); - } - } -} - - -void wsfs_impl_session_receive( - struct wsfs_impl_session * session, - char const * data, - size_t length) -{ - wsfs_impl_jsonrpc_server_onresult(session->rpc, data, length); -} \ No newline at end of file diff --git a/lib/wsfs/adapter/impl/session.h b/lib/wsfs/adapter/impl/session.h deleted file mode 100644 index ae24d97..0000000 --- a/lib/wsfs/adapter/impl/session.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_SESSION_H -#define WSFS_ADAPTER_IMPL_SESSION_H - -#ifndef __cplusplus -#include -#include -#else -#include -using std::size_t; -#endif - -#include "wsfs/core/message_queue.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct lws; -struct wsfs_message; -struct wsfs_credentials; -struct wsfs_impl_authenticators; -struct wsfs_impl_jsonrpc_server; - -struct wsfs_impl_session -{ - struct lws * wsi; - bool is_authenticated; - struct wsfs_message_queue queue; - struct wsfs_impl_authenticators * authenticators; - struct wsfs_impl_jsonrpc_server * rpc; -}; - -extern void wsfs_impl_session_init( - struct wsfs_impl_session * session, - struct lws * wsi, - struct wsfs_impl_authenticators * authenticators, - struct wsfs_impl_jsonrpc_server * rpc); - -extern void wsfs_impl_session_authenticate( - struct wsfs_impl_session * session, - struct wsfs_credentials * creds); - -extern bool wsfs_impl_session_send( - struct wsfs_impl_session * session, - struct wsfs_message * message); - -extern void wsfs_impl_session_receive( - struct wsfs_impl_session * session, - char const * data, - size_t length); - -extern void wsfs_impl_session_onwritable( - struct wsfs_impl_session * session); - -extern void wsfs_impl_session_cleanup( - struct wsfs_impl_session * session); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/impl/session_manager.c b/lib/wsfs/adapter/impl/session_manager.c deleted file mode 100644 index 783371f..0000000 --- a/lib/wsfs/adapter/impl/session_manager.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "wsfs/adapter/impl/session_manager.h" -#include - -void wsfs_impl_session_manager_init( - struct wsfs_impl_session_manager * manager) -{ - wsfs_impl_session_init(&manager->session, NULL, NULL, NULL); -} - -void wsfs_impl_session_manager_cleanup( - struct wsfs_impl_session_manager * manager) -{ - wsfs_impl_session_cleanup(&manager->session); -} - -struct wsfs_impl_session * wsfs_impl_session_manager_add( - struct wsfs_impl_session_manager * manager, - struct lws * wsi, - struct wsfs_impl_authenticators * authenticators, - struct wsfs_impl_jsonrpc_server * rpc) -{ - struct wsfs_impl_session * session = NULL; - if (NULL == manager->session.wsi) - { - session = &manager->session; - wsfs_impl_session_init(&manager->session, wsi, authenticators, rpc); - } - - return session; -} - -struct wsfs_impl_session * wsfs_impl_session_manager_get( - struct wsfs_impl_session_manager * manager, - struct lws * wsi) -{ - struct wsfs_impl_session * session = NULL; - if (wsi == manager->session.wsi) - { - session = &manager->session; - } - - return session; -} - -void wsfs_impl_session_manager_remove( - struct wsfs_impl_session_manager * manager, - struct lws * wsi) -{ - if (wsi == manager->session.wsi) - { - wsfs_impl_session_cleanup(&manager->session); - manager->session.wsi = NULL; - } -} diff --git a/lib/wsfs/adapter/impl/session_manager.h b/lib/wsfs/adapter/impl/session_manager.h deleted file mode 100644 index 4d54f43..0000000 --- a/lib/wsfs/adapter/impl/session_manager.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_SESSION_MANAGER_H -#define WSFS_ADAPTER_IMPL_SESSION_MANAGER_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/impl/session.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct lws; - -struct wsfs_impl_session_manager -{ - struct wsfs_impl_session session; -}; - -extern void wsfs_impl_session_manager_init( - struct wsfs_impl_session_manager * manager); - -extern void wsfs_impl_session_manager_cleanup( - struct wsfs_impl_session_manager * manager); - -extern struct wsfs_impl_session * wsfs_impl_session_manager_add( - struct wsfs_impl_session_manager * manager, - struct lws * wsi, - struct wsfs_impl_authenticators * authenticators, - struct wsfs_impl_jsonrpc_server * rpc); - -extern struct wsfs_impl_session * wsfs_impl_session_manager_get( - struct wsfs_impl_session_manager * manager, - struct lws * wsi); - -extern void wsfs_impl_session_manager_remove( - struct wsfs_impl_session_manager * manager, - struct lws * wsi); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/adapter/impl/time/timeout_manager.c b/lib/wsfs/adapter/impl/time/timeout_manager.c deleted file mode 100644 index 5c7af76..0000000 --- a/lib/wsfs/adapter/impl/time/timeout_manager.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "wsfs/adapter/impl/time/timeout_manager_intern.h" - -#include -#include "wsfs/adapter/impl/time/timer_intern.h" -#include "wsfs/adapter/impl/time/timepoint.h" - -void wsfs_impl_timeout_manager_init( - struct wsfs_impl_timeout_manager * manager) -{ - manager->timers = NULL; -} - -void wsfs_impl_timeout_manager_cleanup( - struct wsfs_impl_timeout_manager * manager) -{ - struct wsfs_impl_timer * timer = manager->timers; - while (NULL != timer) - { - struct wsfs_impl_timer * next = timer->next; - - wsfs_impl_timer_trigger(timer); - - timer = next; - } - - manager->timers = NULL; - -} - -void wsfs_impl_timeout_manager_check( - struct wsfs_impl_timeout_manager * manager) -{ - struct wsfs_impl_timer * timer = manager->timers; - while (NULL != timer) - { - struct wsfs_impl_timer * next = timer->next; - - if (wsfs_impl_timer_is_timeout(timer)) - { - wsfs_impl_timeout_manager_removetimer(manager, timer); - wsfs_impl_timer_trigger(timer); - } - - timer = next; - } -} - -void wsfs_impl_timeout_manager_addtimer( - struct wsfs_impl_timeout_manager * manager, - struct wsfs_impl_timer * timer) -{ - if (NULL != manager->timers) - { - manager->timers->prev = timer; - } - - timer->next = manager->timers; - timer->prev = NULL; - manager->timers = timer; -} - -void wsfs_impl_timeout_manager_removetimer( - struct wsfs_impl_timeout_manager * manager, - struct wsfs_impl_timer * timer) -{ - struct wsfs_impl_timer * prev = timer->prev; - struct wsfs_impl_timer * next = timer->next; - - if (NULL != prev) - { - prev->next = next; - } - - if (NULL != next) - { - next->prev = prev; - } - - if (manager->timers == timer) - { - manager->timers = next; - } -} - diff --git a/lib/wsfs/adapter/impl/time/timeout_manager.h b/lib/wsfs/adapter/impl/time/timeout_manager.h deleted file mode 100644 index 4580b96..0000000 --- a/lib/wsfs/adapter/impl/time/timeout_manager.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H -#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_impl_timer; -struct wsfs_impl_timeout_manager -{ - struct wsfs_impl_timer * timers; -}; - -extern void wsfs_impl_timeout_manager_init( - struct wsfs_impl_timeout_manager * manager); - -extern void wsfs_impl_timeout_manager_cleanup( - struct wsfs_impl_timeout_manager * manager); - -extern void wsfs_impl_timeout_manager_check( - struct wsfs_impl_timeout_manager * manager); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/impl/time/timeout_manager_intern.h b/lib/wsfs/adapter/impl/time/timeout_manager_intern.h deleted file mode 100644 index 4e81fde..0000000 --- a/lib/wsfs/adapter/impl/time/timeout_manager_intern.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H -#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H - -#include "wsfs/adapter/impl/time/timeout_manager.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_impl_timeout_manager_addtimer( - struct wsfs_impl_timeout_manager * manager, - struct wsfs_impl_timer * timer); - -extern void wsfs_impl_timeout_manager_removetimer( - struct wsfs_impl_timeout_manager * manager, - struct wsfs_impl_timer * timer); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/impl/time/timepoint.c b/lib/wsfs/adapter/impl/time/timepoint.c deleted file mode 100644 index 82e02e6..0000000 --- a/lib/wsfs/adapter/impl/time/timepoint.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "wsfs/adapter/impl/time/timepoint.h" - -#include - -#define WSFS_MSEC_PER_SEC ((wsfs_impl_timepoint) 1000) -#define WSFS_NSEC_PER_MSEC ((wsfs_impl_timepoint) 1000 * 1000) - -wsfs_impl_timepoint wsfs_impl_timepoint_now(void) -{ - struct timespec tp; - clock_gettime(CLOCK_MONOTONIC, &tp); - - wsfs_impl_timepoint const now = (tp.tv_sec * WSFS_MSEC_PER_SEC) + (tp.tv_nsec / WSFS_NSEC_PER_MSEC); - return now; -} - -wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(wsfs_impl_timediff value) -{ - wsfs_impl_timepoint const now = wsfs_impl_timepoint_now(); - wsfs_impl_timepoint result = now + ((wsfs_impl_timepoint) value); - - return result; -} - -bool wsfs_impl_timepoint_is_elapsed(wsfs_impl_timepoint tp) -{ - wsfs_impl_timepoint const now = wsfs_impl_timepoint_now(); - wsfs_impl_timediff const diff = (wsfs_impl_timediff) (tp - now); - - return (0 > diff); -} diff --git a/lib/wsfs/adapter/impl/time/timepoint.h b/lib/wsfs/adapter/impl/time/timepoint.h deleted file mode 100644 index c803653..0000000 --- a/lib/wsfs/adapter/impl/time/timepoint.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H -#define WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H - -#ifndef __cplusplus -#include -#include -#else -#include -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -typedef uint64_t wsfs_impl_timepoint; -typedef int64_t wsfs_impl_timediff; - -extern wsfs_impl_timepoint wsfs_impl_timepoint_now(void); - -extern wsfs_impl_timepoint wsfs_impl_timepoint_in_msec( - wsfs_impl_timediff value); - -extern bool wsfs_impl_timepoint_is_elapsed( - wsfs_impl_timepoint timepoint); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/impl/time/timer.c b/lib/wsfs/adapter/impl/time/timer.c deleted file mode 100644 index ec8dee0..0000000 --- a/lib/wsfs/adapter/impl/time/timer.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "wsfs/adapter/impl/time/timer_intern.h" -#include "wsfs/adapter/impl/time/timeout_manager_intern.h" - -#include -#include - -void wsfs_impl_timer_init( - struct wsfs_impl_timer * timer, - struct wsfs_impl_timeout_manager * manager) -{ - timer->manager = manager; - timer->timeout = 0; - timer->timeout_handler = NULL; - timer->user_data = NULL; - timer->prev = NULL; - timer->next = NULL; -} - -void wsfs_impl_timer_cleanup( - struct wsfs_impl_timer * timer) -{ - memset(timer, 0, sizeof(struct wsfs_impl_timer)); -} - -void wsfs_impl_timer_start( - struct wsfs_impl_timer * timer, - wsfs_impl_timepoint absolute_timeout, - wsfs_impl_timer_timeout_fn * handler, - void * user_data) -{ - timer->timeout = absolute_timeout; - timer->timeout_handler = handler; - timer->user_data = user_data; - - wsfs_impl_timeout_manager_addtimer(timer->manager, timer); -} - -void wsfs_impl_timer_cancel( - struct wsfs_impl_timer * timer) -{ - wsfs_impl_timeout_manager_removetimer(timer->manager, timer); - - timer->timeout = 0; - timer->timeout_handler = NULL; - timer->user_data = NULL; -} - -bool wsfs_impl_timer_is_timeout( - struct wsfs_impl_timer * timer) -{ - return wsfs_impl_timepoint_is_elapsed(timer->timeout); -} - - -void wsfs_impl_timer_trigger( - struct wsfs_impl_timer * timer) -{ - if (NULL != timer->timeout_handler) - { - timer->prev = NULL; - timer->next = NULL; - - timer->timeout_handler(timer); - } -} diff --git a/lib/wsfs/adapter/impl/time/timer.h b/lib/wsfs/adapter/impl/time/timer.h deleted file mode 100644 index 89b9154..0000000 --- a/lib/wsfs/adapter/impl/time/timer.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_H -#define WSFS_ADAPTER_IMPL_TIME_TIMER_H - -#include "wsfs/adapter/impl/time/timepoint.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfs_impl_timer; -struct wsfs_impl_timeout_manager; - -typedef void wsfs_impl_timer_timeout_fn(struct wsfs_impl_timer * timer); - -struct wsfs_impl_timer -{ - struct wsfs_impl_timeout_manager * manager; - wsfs_impl_timepoint timeout; - wsfs_impl_timer_timeout_fn * timeout_handler; - void * user_data; - struct wsfs_impl_timer * next; - struct wsfs_impl_timer * prev; -}; - -extern void wsfs_impl_timer_init( - struct wsfs_impl_timer * timer, - struct wsfs_impl_timeout_manager * manager); - -extern void wsfs_impl_timer_cleanup( - struct wsfs_impl_timer * timer); - -extern void wsfs_impl_timer_start( - struct wsfs_impl_timer * timer, - wsfs_impl_timepoint absolute_timeout, - wsfs_impl_timer_timeout_fn * handler, - void * user_data); - -extern void wsfs_impl_timer_cancel( - struct wsfs_impl_timer * timer); - -#ifdef __cplusplus -} -#endif - - - -#endif diff --git a/lib/wsfs/adapter/impl/time/timer_intern.h b/lib/wsfs/adapter/impl/time/timer_intern.h deleted file mode 100644 index 7695215..0000000 --- a/lib/wsfs/adapter/impl/time/timer_intern.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H -#define WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/impl/time/timer.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern bool wsfs_impl_timer_is_timeout( - struct wsfs_impl_timer * timer); - -extern void wsfs_impl_timer_trigger( - struct wsfs_impl_timer * timer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/core/message.c b/lib/wsfs/core/message.c deleted file mode 100644 index 4c6c790..0000000 --- a/lib/wsfs/core/message.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "wsfs/core/message.h" - -#include -#include - -extern struct wsfs_message * wsfs_message_create(json_t const * value) -{ - struct wsfs_message * message = NULL; - size_t const length = json_dumpb(value, NULL, 0, JSON_COMPACT); - - if (0 < length) - { - char * data = malloc(sizeof(struct wsfs_message) + LWS_PRE + length); - message = (struct wsfs_message *) data; - if (NULL != message) - { - message->data = &data[sizeof(struct wsfs_message) + LWS_PRE]; - message->length = length; - message->next = NULL; - - json_dumpb(value, message->data, length, JSON_COMPACT); - } - } - - return message; -} - -void wsfs_message_dispose( - struct wsfs_message * message) -{ - free(message); -} diff --git a/lib/wsfs/core/message.h b/lib/wsfs/core/message.h deleted file mode 100644 index e5f7f4d..0000000 --- a/lib/wsfs/core/message.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef WSFS_MESSAGE_H -#define WSFS_MESSAGE_H - -#ifndef __cplusplus -#include -#else -#include -using std::size_t; -#endif - -#include - -struct wsfs_message -{ - struct wsfs_message * next; - char * data; - size_t length; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern struct wsfs_message * wsfs_message_create(json_t const * value); - -extern void wsfs_message_dispose( - struct wsfs_message * message); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/core/message_queue.c b/lib/wsfs/core/message_queue.c deleted file mode 100644 index e758c67..0000000 --- a/lib/wsfs/core/message_queue.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "wsfs/core/message_queue.h" -#include "wsfs/core/message.h" - -void wsfs_message_queue_init( - struct wsfs_message_queue * queue) -{ - queue->first = NULL; - queue->last = NULL; - -} - -void wsfs_message_queue_cleanup( - struct wsfs_message_queue * queue) -{ - struct wsfs_message * message = queue->first; - while (NULL != message) - { - struct wsfs_message * next = message->next; - wsfs_message_dispose(message); - message = next; - } - wsfs_message_queue_init(queue); -} - -bool wsfs_message_queue_empty( - struct wsfs_message_queue * queue) -{ - return (NULL == queue->first); -} - -void wsfs_message_queue_push( - struct wsfs_message_queue * queue, - struct wsfs_message * message) -{ - message->next = NULL; - - if (NULL != queue->last) - { - queue->last->next = message; - queue->last = message; - } - else - { - queue->first = message; - queue->last = message; - } -} - -struct wsfs_message * wsfs_message_queue_pop( - struct wsfs_message_queue * queue) -{ - struct wsfs_message * const result = queue->first; - if (NULL != result) - { - queue->first = queue->first->next; - if (NULL == queue->first) - { - queue->last = NULL; - } - } - - return result; -} diff --git a/lib/wsfs/core/message_queue.h b/lib/wsfs/core/message_queue.h deleted file mode 100644 index 5715505..0000000 --- a/lib/wsfs/core/message_queue.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef WSFS_MESSAGE_QUEUE_H -#define WSFS_MESSAGE_QUEUE_H - -#ifndef __cplusplus -#include -#endif - -struct wsfs_message_queue; -struct wsfs_message; - -struct wsfs_message_queue -{ - struct wsfs_message * first; - struct wsfs_message * last; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_message_queue_init( - struct wsfs_message_queue * queue); - -extern void wsfs_message_queue_cleanup( - struct wsfs_message_queue * queue); - -extern bool wsfs_message_queue_empty( - struct wsfs_message_queue * queue); - -extern void wsfs_message_queue_push( - struct wsfs_message_queue * queue, - struct wsfs_message * message); - -extern struct wsfs_message * wsfs_message_queue_pop( - struct wsfs_message_queue * queue); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/core/status.c b/lib/wsfs/core/status.c deleted file mode 100644 index f2576f7..0000000 --- a/lib/wsfs/core/status.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "wsfs/core/status_intern.h" - -#include - - int wsfs_status_to_rc(wsfs_status status) -{ - switch(status) - { - case WSFS_GOOD: return 0; - case WSFS_BAD_NOTIMPLEMENTED: return -ENOSYS; - case WSFS_BAD_TIMEOUT: return -ETIMEDOUT; - case WSFS_BAD_BUSY: return -ENOENT; - case WSFS_BAD_FORMAT: return -ENOENT; - case WSFS_BAD_NOENTRY: return -ENOENT; - case WSFS_BAD_NOACCESS: return -EACCES; - default: return -ENOENT; - } -} - -char const * wsfs_status_tostring(wsfs_status status) -{ - switch(status) - { - case WSFS_GOOD: return "Good"; - case WSFS_BAD: return "Bad"; - case WSFS_BAD_NOTIMPLEMENTED: return "Bad (not implelemted)"; - case WSFS_BAD_TIMEOUT: return "Bad (timeout)"; - case WSFS_BAD_BUSY: return "Bad (busy)"; - case WSFS_BAD_FORMAT: return "Bad (format)"; - case WSFS_BAD_NOENTRY: return "Bad (no entry)"; - case WSFS_BAD_NOACCESS: return "Bad (no access)"; - default: return "Bad (unknown)"; - } -} diff --git a/lib/wsfs/core/status_intern.h b/lib/wsfs/core/status_intern.h deleted file mode 100644 index 08f4b04..0000000 --- a/lib/wsfs/core/status_intern.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef WSFS_STATUS_INTERN_H -#define WSFS_STATUS_INTERN_H - -#include "wsfs/core/status.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern int wsfs_status_to_rc(wsfs_status status); - -extern char const * wsfs_status_tostring(wsfs_status status); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/lib/wsfs/core/util.h b/lib/wsfs/core/util.h deleted file mode 100644 index 25f728d..0000000 --- a/lib/wsfs/core/util.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef WSFS_UTIL_H -#define WSFS_UTIL_H - -#ifdef __GNUC__ -#define WSFS_UNUSED_PARAM(param) param __attribute__((unused)) -#else -#define WSFS_UNUSED_PARAM(param) -#endif - -#endif diff --git a/lib/wsfs/provider/api.c b/lib/wsfs/provider/api.c deleted file mode 100644 index 3a88c92..0000000 --- a/lib/wsfs/provider/api.c +++ /dev/null @@ -1,240 +0,0 @@ -#include "wsfs_provider.h" - -#include "wsfs/provider/impl/request.h" -#include "wsfs/provider/impl/operation/getattr.h" -#include "wsfs/provider/impl/operation/lookup.h" -#include "wsfs/provider/impl/operation/readdir.h" -#include "wsfs/provider/impl/operation/open.h" -#include "wsfs/provider/impl/operation/close.h" -#include "wsfs/provider/impl/operation/read.h" -#include "wsfs/provider/impl/client_protocol.h" -#include "wsfs/provider/impl/client_config.h" -#include "wsfs/provider/impl/client.h" -#include "wsfs/provider/impl/dirbuffer.h" - -// respond - -void wsfsp_respond_error( - struct wsfsp_request * request, - wsfs_status status) -{ - wsfsp_impl_respond_error(request, status); -} - -void wsfsp_respond_getattr( - struct wsfsp_request * request, - struct stat const * stat) -{ - wsfsp_impl_respond_getattr(request, stat); -} - -void wsfsp_respond_lookup( - struct wsfsp_request * request, - struct stat const * stat) -{ - wsfsp_impl_respond_lookup(request, stat); -} - -void wsfsp_respond_open( - struct wsfsp_request * request, - uint32_t handle) -{ - wsfsp_impl_respond_open(request, handle); -} - -void wsfsp_respond_read( - struct wsfsp_request * request, - char const * data, - size_t length) -{ - wsfsp_impl_respond_read(request, data, length); -} - -void wsfsp_respond_readdir( - struct wsfsp_request * request, - struct wsfsp_dirbuffer * dirbuffer) -{ - wsfsp_impl_respond_readdir(request, dirbuffer); -} - -// config - - -struct wsfsp_client_config * wsfsp_client_config_create(void) -{ - return wsfsp_impl_client_config_create(); -} - -void wsfsp_client_config_dispose( - struct wsfsp_client_config * config) -{ - wsfsp_impl_client_config_dispose(config); -} - -void wsfsp_client_config_set_userdata( - struct wsfsp_client_config * config, - void * user_data) -{ - wsfsp_impl_client_config_set_userdata(config, user_data); -} - -void wsfsp_client_config_set_keypath( - struct wsfsp_client_config * config, - char const * key_path) -{ - wsfsp_impl_client_config_set_keypath(config, key_path); -} - -void wsfsp_client_config_set_certpath( - struct wsfsp_client_config * config, - char const * cert_path) -{ - wsfsp_impl_client_config_set_certpath(config, cert_path); -} - -void wsfsp_client_config_set_onconnected( - struct wsfsp_client_config * config, - wsfsp_connected_fn * handler) -{ - wsfsp_impl_client_config_set_onconnected(config, handler); -} - -void wsfsp_client_config_set_ondisconnected( - struct wsfsp_client_config * config, - wsfsp_disconnected_fn * handler) -{ - wsfsp_impl_client_config_set_ondisconnected(config, handler); -} - -void wsfsp_client_config_set_ontimer( - struct wsfsp_client_config * config, - wsfsp_ontimer_fn * handler) -{ - wsfsp_impl_client_config_set_ontimer(config, handler); -} - -void wsfsp_client_config_set_onlookup( - struct wsfsp_client_config * config, - wsfsp_lookup_fn * handler) -{ - wsfsp_impl_client_config_set_onlookup(config, handler); -} - -void wsfsp_client_config_set_ongetattr( - struct wsfsp_client_config * config, - wsfsp_getattr_fn * handler) -{ - wsfsp_impl_client_config_set_ongetattr(config, handler); -} - -void wsfsp_client_config_set_onreaddir( - struct wsfsp_client_config * config, - wsfsp_readdir_fn * handler) -{ - wsfsp_impl_client_config_set_onreaddir(config, handler); -} - -void wsfsp_client_config_set_onopen( - struct wsfsp_client_config * config, - wsfsp_open_fn * handler) -{ - wsfsp_impl_client_config_set_onopen(config, handler); -} - -void wsfsp_client_config_set_onclose( - struct wsfsp_client_config * config, - wsfsp_close_fn * handler) -{ - wsfsp_impl_client_config_set_onclose(config, handler); -} - -void wsfsp_client_config_set_onread( - struct wsfsp_client_config * config, - wsfsp_read_fn * handler) -{ - wsfsp_impl_client_config_set_onread(config, handler); -} - -// protocol - - -struct wsfsp_client_protocol * wsfsp_client_protocol_create( - struct wsfsp_provider const * provider, - void * user_data) -{ - return wsfsp_impl_client_protocol_create(provider, user_data); -} - -void wsfsp_client_protocol_dispose( - struct wsfsp_client_protocol * protocol) -{ - wsfsp_impl_client_protocol_dispose(protocol); -} - -void wsfsp_client_protocol_init_lws( - struct wsfsp_client_protocol * protocol, - struct lws_protocols * lws_protocol) -{ - wsfsp_impl_client_protocol_init_lws(protocol, lws_protocol); -} - -// client - -struct wsfsp_client * wsfsp_client_create( - struct wsfsp_client_config * config) -{ - return wsfsp_impl_client_create(config); -} - -void wsfsp_client_connect( - struct wsfsp_client * client, - char const * url) -{ - wsfsp_impl_client_connect(client, url); -} - -void wsfsp_client_disconnect( - struct wsfsp_client * client) -{ - wsfsp_impl_client_disconnect(client); -} - -void wsfsp_client_dispose( - struct wsfsp_client * client) -{ - wsfsp_impl_client_dispose(client); -} - -void wsfsp_client_run( - struct wsfsp_client * client) -{ - wsfsp_impl_client_run(client); -} - -void wsfsp_client_shutdown( - struct wsfsp_client * client) -{ - wsfsp_impl_client_shutdown(client); -} - -// dirbuffer - -struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void) -{ - return wsfsp_impl_dirbuffer_create(); -} - -void wsfsp_dirbuffer_dispose( - struct wsfsp_dirbuffer * buffer) -{ - wsfsp_impl_dirbuffer_dispose(buffer); -} - -void wsfsp_dirbuffer_add( - struct wsfsp_dirbuffer * buffer, - char const * name, - ino_t inode) -{ - wsfsp_impl_dirbuffer_add(buffer, name, inode); -} - diff --git a/lib/wsfs/provider/impl/client.h b/lib/wsfs/provider/impl/client.h deleted file mode 100644 index 9c7d79b..0000000 --- a/lib/wsfs/provider/impl/client.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_CLIENT_H -#define WSFS_PROVIDER_IMPL_CLIENT_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_client; -struct wsfsp_client_config; - -extern struct wsfsp_client * wsfsp_impl_client_create( - struct wsfsp_client_config * config); - -extern void wsfsp_impl_client_set_keypath( - struct wsfsp_client * client, - char * key_path); - -extern void wsfsp_impl_client_set_certpath( - struct wsfsp_client * client, - char * cert_path); - -extern void wsfsp_impl_client_connect( - struct wsfsp_client * client, - char const * url); - -extern void wsfsp_impl_client_disconnect( - struct wsfsp_client * client); - -extern void wsfsp_impl_client_settimeout( - struct wsfsp_client * client, - unsigned int timepoint); - -extern void wsfsp_impl_client_dispose( - struct wsfsp_client * client); - -extern void wsfsp_impl_client_run( - struct wsfsp_client * client); - -extern void wsfsp_impl_client_shutdown( - struct wsfsp_client * client); - - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/provider/impl/client_config.c b/lib/wsfs/provider/impl/client_config.c deleted file mode 100644 index 372021a..0000000 --- a/lib/wsfs/provider/impl/client_config.c +++ /dev/null @@ -1,112 +0,0 @@ -#include "wsfs/provider/impl/client_config.h" -#include "wsfs/provider/impl/provider.h" -#include -#include - -struct wsfsp_client_config * wsfsp_impl_client_config_create(void) -{ - struct wsfsp_client_config * config = malloc(sizeof(struct wsfsp_client_config)); - if (NULL != config) - { - wsfsp_impl_provider_init(&config->provider); - config->user_data = NULL; - config->key_path = NULL; - config->cert_path = NULL; - } - - return config; -} - -void wsfsp_impl_client_config_dispose( - struct wsfsp_client_config * config) -{ - free(config->key_path); - free(config->cert_path); - free(config); -} - -void wsfsp_impl_client_config_set_userdata( - struct wsfsp_client_config * config, - void * user_data) -{ - config->user_data = user_data; -} - -void wsfsp_impl_client_config_set_keypath( - struct wsfsp_client_config * config, - char const * key_path) -{ - free(config->key_path); - config->key_path = strdup(key_path); -} - -void wsfsp_impl_client_config_set_certpath( - struct wsfsp_client_config * config, - char const * cert_path) -{ - free(config->cert_path); - config->cert_path = strdup(cert_path); -} - -void wsfsp_impl_client_config_set_onconnected( - struct wsfsp_client_config * config, - wsfsp_connected_fn * handler) -{ - config->provider.connected = handler; -} - -void wsfsp_impl_client_config_set_ondisconnected( - struct wsfsp_client_config * config, - wsfsp_disconnected_fn * handler) -{ - config->provider.disconnected = handler; -} - -void wsfsp_impl_client_config_set_ontimer( - struct wsfsp_client_config * config, - wsfsp_ontimer_fn * handler) -{ - config->provider.ontimer = handler; -} - -void wsfsp_impl_client_config_set_onlookup( - struct wsfsp_client_config * config, - wsfsp_lookup_fn * handler) -{ - config->provider.lookup = handler; -} - -void wsfsp_impl_client_config_set_ongetattr( - struct wsfsp_client_config * config, - wsfsp_getattr_fn * handler) -{ - config->provider.getattr = handler; -} - -void wsfsp_impl_client_config_set_onreaddir( - struct wsfsp_client_config * config, - wsfsp_readdir_fn * handler) -{ - config->provider.readdir = handler; -} - -void wsfsp_impl_client_config_set_onopen( - struct wsfsp_client_config * config, - wsfsp_open_fn * handler) -{ - config->provider.open = handler; -} - -void wsfsp_impl_client_config_set_onclose( - struct wsfsp_client_config * config, - wsfsp_close_fn * handler) -{ - config->provider.close = handler; -} - -void wsfsp_impl_client_config_set_onread( - struct wsfsp_client_config * config, - wsfsp_read_fn * handler) -{ - config->provider.read = handler; -} diff --git a/lib/wsfs/provider/impl/client_config.h b/lib/wsfs/provider/impl/client_config.h deleted file mode 100644 index 4419636..0000000 --- a/lib/wsfs/provider/impl/client_config.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_CLIENT_CONFIG_H -#define WSFS_PROVIDER_IMPL_CLIENT_CONFIG_H - -#include "wsfs/provider/client_config.h" -#include "wsfs/provider/impl/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_client_config -{ - struct wsfsp_provider provider; - void * user_data; - char * key_path; - char * cert_path; -}; - -extern struct wsfsp_client_config * wsfsp_impl_client_config_create(void); - -extern void wsfsp_impl_client_config_dispose( - struct wsfsp_client_config * config); - -extern void wsfsp_impl_client_config_set_userdata( - struct wsfsp_client_config * config, - void * user_data); - -extern void wsfsp_impl_client_config_set_keypath( - struct wsfsp_client_config * config, - char const * key_path); - -extern void wsfsp_impl_client_config_set_certpath( - struct wsfsp_client_config * config, - char const * cert_path); - -extern void wsfsp_impl_client_config_set_onconnected( - struct wsfsp_client_config * config, - wsfsp_connected_fn * handler); - -extern void wsfsp_impl_client_config_set_ondisconnected( - struct wsfsp_client_config * config, - wsfsp_disconnected_fn * handler); - -extern void wsfsp_impl_client_config_set_ontimer( - struct wsfsp_client_config * config, - wsfsp_ontimer_fn * handler); - -extern void wsfsp_impl_client_config_set_onlookup( - struct wsfsp_client_config * config, - wsfsp_lookup_fn * handler); - -extern void wsfsp_impl_client_config_set_ongetattr( - struct wsfsp_client_config * config, - wsfsp_getattr_fn * handler); - -extern void wsfsp_impl_client_config_set_onreaddir( - struct wsfsp_client_config * config, - wsfsp_readdir_fn * handler); - -extern void wsfsp_impl_client_config_set_onopen( - struct wsfsp_client_config * config, - wsfsp_open_fn * handler); - -extern void wsfsp_impl_client_config_set_onclose( - struct wsfsp_client_config * config, - wsfsp_close_fn * handler); - -extern void wsfsp_impl_client_config_set_onread( - struct wsfsp_client_config * config, - wsfsp_read_fn * handler); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/provider/impl/client_protocol.c b/lib/wsfs/provider/impl/client_protocol.c deleted file mode 100644 index 7ac21f2..0000000 --- a/lib/wsfs/provider/impl/client_protocol.c +++ /dev/null @@ -1,149 +0,0 @@ -#include "wsfs/provider/impl/client_protocol.h" - -#include -#include - -#include -#include - - -#include "wsfs/provider/impl/provider.h" -#include "wsfs/core/util.h" -#include "wsfs/core/message.h" - -static void wsfsp_impl_client_protocol_respond( - json_t * response, - void * user_data) -{ - struct wsfsp_client_protocol * protocol = (struct wsfsp_client_protocol *) user_data; - - struct wsfs_message * message = wsfs_message_create(response); - if (NULL != message) - { - wsfs_message_queue_push(&protocol->queue, message); - lws_callback_on_writable(protocol->wsi); - } -} - -static void wsfsp_impl_client_protocol_process_request( - struct wsfsp_client_protocol * protocol, - char const * message, - size_t length) -{ - json_t * request = json_loadb(message, length, 0, NULL); - if (NULL != request) - { - struct wsfsp_impl_invokation_context context = - { - .provider = &protocol->provider, - .user_data = protocol->user_data, - .request = &protocol->request - }; - - wsfsp_impl_provider_invoke(&context, request); - json_decref(request); - } -} - - -static int wsfsp_impl_client_protocol_callback( - struct lws * wsi, - enum lws_callback_reasons reason, - void * WSFS_UNUSED_PARAM(user), - void * in, - size_t len) -{ - struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); - struct wsfsp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL; - - if (NULL != protocol) - { - switch (reason) - { - case LWS_CALLBACK_CLIENT_ESTABLISHED: - protocol->provider.connected(protocol->user_data); - break; - case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: - protocol->provider.disconnected(protocol->user_data); - break; - case LWS_CALLBACK_CLIENT_CLOSED: - protocol->provider.connected(protocol->user_data); - break; - case LWS_CALLBACK_CLIENT_RECEIVE: - wsfsp_impl_client_protocol_process_request(protocol, in, len); - break; - case LWS_CALLBACK_SERVER_WRITEABLE: - // fall-through - case LWS_CALLBACK_CLIENT_WRITEABLE: - if ((wsi == protocol->wsi) && (!wsfs_message_queue_empty(&protocol->queue))) - { - struct wsfs_message * message = wsfs_message_queue_pop(&protocol->queue); - lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT); - wsfs_message_dispose(message); - - if (!wsfs_message_queue_empty(&protocol->queue)) - { - lws_callback_on_writable(wsi); - - } - } - break; - default: - break; - } - } - - return 0; -} - - -void wsfsp_impl_client_protocol_init( - struct wsfsp_client_protocol * protocol, - struct wsfsp_provider const * provider, - void * user_data) -{ - wsfs_message_queue_init(&protocol->queue); - - protocol->wsi = NULL; - - protocol->request.respond = &wsfsp_impl_client_protocol_respond; - protocol->request.user_data = protocol; - - protocol->user_data = user_data; - wsfsp_impl_provider_init_from_prototype(&protocol->provider, provider); -} - -void wsfsp_impl_client_protocol_cleanup( - struct wsfsp_client_protocol * protocol) -{ - wsfs_message_queue_cleanup(&protocol->queue); -} - -struct wsfsp_client_protocol * wsfsp_impl_client_protocol_create( - struct wsfsp_provider const * provider, - void * user_data) -{ - struct wsfsp_client_protocol * protocol = malloc(sizeof(struct wsfsp_client_protocol)); - if (NULL != protocol) - { - wsfsp_impl_client_protocol_init(protocol, provider, user_data); - } - - return protocol; -} - -void wsfsp_impl_client_protocol_dispose( - struct wsfsp_client_protocol * protocol) -{ - wsfsp_impl_client_protocol_cleanup(protocol); - free(protocol); -} - -void wsfsp_impl_client_protocol_init_lws( - struct wsfsp_client_protocol * protocol, - struct lws_protocols * lws_protocol) -{ - lws_protocol->callback = &wsfsp_impl_client_protocol_callback; - lws_protocol->per_session_data_size = 0; - lws_protocol->user = protocol; -} diff --git a/lib/wsfs/provider/impl/client_protocol.h b/lib/wsfs/provider/impl/client_protocol.h deleted file mode 100644 index d83fc30..0000000 --- a/lib/wsfs/provider/impl/client_protocol.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_CLIENT_PROTOCOL_H -#define WSFS_PROVIDER_IMPL_CLIENT_PROTOCOL_H - -#include "wsfs/provider/impl/provider.h" -#include "wsfs/provider/impl/request.h" - -#include "wsfs/core/message_queue.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_provider; -struct lws_protocols; - -struct wsfsp_client_protocol -{ - struct wsfsp_request request; - struct wsfsp_provider provider; - void * user_data; - struct lws * wsi; - struct wsfs_message_queue queue; -}; - -extern void wsfsp_impl_client_protocol_init( - struct wsfsp_client_protocol * protocol, - struct wsfsp_provider const * provider, - void * user_data); - -extern void wsfsp_impl_client_protocol_cleanup( - struct wsfsp_client_protocol * protocol); - -extern struct wsfsp_client_protocol * wsfsp_impl_client_protocol_create( - struct wsfsp_provider const * provider, - void * user_data); - -extern void wsfsp_impl_client_protocol_dispose( - struct wsfsp_client_protocol * protocol); - -extern void wsfsp_impl_client_protocol_init_lws( - struct wsfsp_client_protocol * protocol, - struct lws_protocols * lws_protocol); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/provider/impl/dirbuffer.h b/lib/wsfs/provider/impl/dirbuffer.h deleted file mode 100644 index d70b494..0000000 --- a/lib/wsfs/provider/impl/dirbuffer.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_DIRBUFFER_H -#define WSFS_PROVIDER_IMPL_DIRBUFFER_H - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_dirbuffer -{ - json_t * entries; -}; - -extern struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void); - -extern void wsfsp_impl_dirbuffer_dispose( - struct wsfsp_dirbuffer * buffer); - -extern void wsfsp_impl_dirbuffer_add( - struct wsfsp_dirbuffer * buffer, - char const * name, - ino_t inode); - -extern json_t * wsfsp_impl_dirbuffer_take( - struct wsfsp_dirbuffer * buffer); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/provider/impl/operation/close.h b/lib/wsfs/provider/impl/operation/close.h deleted file mode 100644 index f92c66c..0000000 --- a/lib/wsfs/provider/impl/operation/close.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_OPERATION_CLOSE_H -#define WSFS_PROVIDER_IMPL_OPERATION_CLOSE_H - -#include "wsfs/provider/impl/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_impl_close( - struct wsfsp_impl_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_impl_close_default( - ino_t inode, - uint32_t handle, - int flags, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/error.h b/lib/wsfs/provider/impl/operation/error.h deleted file mode 100644 index 416bfe6..0000000 --- a/lib/wsfs/provider/impl/operation/error.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef WSFSP_OPERATION_IMPL_ERROR_H -#define WSFSP_OPERATION_IMPL_ERROR_H - -#include "wsfs/provider/api.h" -#include "wsfs/core/status.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_request; - -extern WSFSP_API void wsfsp_impl_respond_error( - struct wsfsp_request * request, - wsfs_status status); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/provider/impl/operation/getattr.h b/lib/wsfs/provider/impl/operation/getattr.h deleted file mode 100644 index f399e80..0000000 --- a/lib/wsfs/provider/impl/operation/getattr.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_OPERATION_GETATTR_H -#define WSFS_PROVIDER_IMPL_OPERATION_GETATTR_H - -#include "wsfs/provider/impl/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_impl_respond_getattr( - struct wsfsp_request * request, - struct stat const * stat); - -extern void wsfsp_impl_getattr( - struct wsfsp_impl_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_impl_getattr_default( - struct wsfsp_request * request, - ino_t inode, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/lookup.h b/lib/wsfs/provider/impl/operation/lookup.h deleted file mode 100644 index 082dc52..0000000 --- a/lib/wsfs/provider/impl/operation/lookup.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_OPERATION_LOOKUP_H -#define WSFS_PROVIDER_IMPL_OPERATION_LOOKUP_H - -#include "wsfs/provider/impl/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_impl_respond_lookup( - struct wsfsp_request * request, - struct stat const * stat); - -extern void wsfsp_impl_lookup( - struct wsfsp_impl_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_impl_lookup_default( - struct wsfsp_request * request, - ino_t parent, - char const * name, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/open.h b/lib/wsfs/provider/impl/operation/open.h deleted file mode 100644 index c589d44..0000000 --- a/lib/wsfs/provider/impl/operation/open.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_OPERATION_OPEN_H -#define WSFS_PROVIDER_IMPL_OPERATION_OPEN_H - -#include "wsfs/provider/impl/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_impl_respond_open( - struct wsfsp_request * request, - uint32_t handle); - -extern void wsfsp_impl_open( - struct wsfsp_impl_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_impl_open_default( - struct wsfsp_request * request, - ino_t inode, - int flags, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/read.h b/lib/wsfs/provider/impl/operation/read.h deleted file mode 100644 index 2f86ea3..0000000 --- a/lib/wsfs/provider/impl/operation/read.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_OPERATION_READ_H -#define WSFS_PROVIDER_IMPL_OPERATION_READ_H - -#include "wsfs/provider/impl/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_impl_respond_read( - struct wsfsp_request * request, - char const * data, - size_t length); - -extern void wsfsp_impl_read( - struct wsfsp_impl_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_impl_read_default( - struct wsfsp_request * request, - ino_t inode, - uint32_t handle, - size_t offset, - size_t length, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/readdir.c b/lib/wsfs/provider/impl/operation/readdir.c deleted file mode 100644 index 6777698..0000000 --- a/lib/wsfs/provider/impl/operation/readdir.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "wsfs/provider/impl/operation/readdir.h" -#include "wsfs/provider/impl/operation/error.h" -#include "wsfs/provider/impl/dirbuffer.h" -#include "wsfs/provider/impl/request.h" -#include "wsfs/core/util.h" - -void wsfsp_impl_readdir( - struct wsfsp_impl_invokation_context * context, - json_t * params, - int id) -{ - size_t const count = json_array_size(params); - if (1 == count) - { - json_t * inode_holder = json_array_get(params, 0); - - if ((NULL != inode_holder) && (json_is_integer(inode_holder))) - { - ino_t inode = (ino_t) json_integer_value(inode_holder); - struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); - - context->provider->readdir(request, inode, context->user_data); - } - } -} - -void wsfsp_impl_readdir_default( - struct wsfsp_request * request, - ino_t WSFS_UNUSED_PARAM(directory), - void * WSFS_UNUSED_PARAM(user_data)) -{ - wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); -} - -void wsfsp_impl_respond_readdir( - struct wsfsp_request * request, - struct wsfsp_dirbuffer * dirbuffer) -{ - json_t * result = wsfsp_impl_dirbuffer_take(dirbuffer); - wsfsp_impl_respond(request, result); -} - diff --git a/lib/wsfs/provider/impl/operation/readdir.h b/lib/wsfs/provider/impl/operation/readdir.h deleted file mode 100644 index c87e108..0000000 --- a/lib/wsfs/provider/impl/operation/readdir.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_OPERATION_READDIR_H -#define WSFS_PROVIDER_IMPL_OPERATION_READDIR_H - -#include "wsfs/provider/impl/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_impl_respond_readdir( - struct wsfsp_request * request, - struct wsfsp_dirbuffer * dirbuffer); - -extern void wsfsp_impl_readdir( - struct wsfsp_impl_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_impl_readdir_default( - struct wsfsp_request * request, - ino_t directory, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/provider.c b/lib/wsfs/provider/impl/provider.c deleted file mode 100644 index 7a70f91..0000000 --- a/lib/wsfs/provider/impl/provider.c +++ /dev/null @@ -1,127 +0,0 @@ -#include "wsfs/provider/impl/provider.h" - -#include -#include - -#include "wsfs/provider/impl/request.h" -#include "wsfs/provider/impl/operation/lookup.h" -#include "wsfs/provider/impl/operation/getattr.h" -#include "wsfs/provider/impl/operation/readdir.h" -#include "wsfs/provider/impl/operation/open.h" -#include "wsfs/provider/impl/operation/close.h" -#include "wsfs/provider/impl/operation/read.h" - -typedef void wsfsp_impl_invoke_fn( - struct wsfsp_impl_invokation_context * context, - json_t * params, - int id); - - -struct wsfsp_impl_method -{ - char const * name; - wsfsp_impl_invoke_fn * invoke; - bool is_notification; -}; - -static void wsfsp_impl_provider_invoke_method( - struct wsfsp_impl_invokation_context * context, - char const * method_name, - json_t * params, - int id) -{ - static struct wsfsp_impl_method const methods[] = - { - {"lookup", &wsfsp_impl_lookup, false}, - {"getattr", &wsfsp_impl_getattr, false}, - {"readdir", &wsfsp_impl_readdir, false}, - {"open", &wsfsp_impl_open, false}, - {"close", &wsfsp_impl_close, true}, - {"read", &wsfsp_impl_read, false} - }; - static size_t const count = sizeof(methods) / sizeof(methods[0]); - - for (size_t i = 0; i < count; i++) - { - struct wsfsp_impl_method const * method = &methods[i]; - if (0 == strcmp(method_name, method->name)) - { - if ((0 < id) || (method->is_notification)) - { - method->invoke(context, params, id); - } - break; - } - } -} - -void wsfsp_impl_provider_init( - struct wsfsp_provider * provider) -{ - provider->lookup = &wsfsp_impl_lookup_default; - provider->getattr = &wsfsp_impl_getattr_default; - provider->readdir = &wsfsp_impl_readdir_default; - provider->open = &wsfsp_impl_open_default; - provider->close = &wsfsp_impl_close_default; - provider->read = &wsfsp_impl_read_default; - provider->connected = &wsfsp_impl_connected_default; - provider->disconnected = &wsfsp_impl_disconnected_default; - provider->ontimer = &wsfsp_impl_ontimer_default; -} - -void wsfsp_impl_provider_init_from_prototype( - struct wsfsp_provider * provider, - struct wsfsp_provider const * prototype) -{ - provider->lookup = prototype->lookup; - provider->getattr = prototype->getattr; - provider->readdir = prototype->readdir; - provider->open = prototype->open; - provider->close = prototype->close; - provider->read = prototype->read; - provider->connected = prototype->connected; - provider->disconnected = prototype->disconnected; - provider->ontimer = prototype->ontimer; -} - -void wsfsp_impl_provider_invoke( - struct wsfsp_impl_invokation_context * context, - json_t * request) -{ - json_t * method_holder = json_object_get(request, "method"); - json_t * params = json_object_get(request, "params"); - json_t * id_holder = json_object_get(request, "id"); - - if ((NULL != method_holder) && (json_is_string(method_holder)) && - (NULL != params) && (json_is_array(params))) - { - char const * method = json_string_value(method_holder); - int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0; - - wsfsp_impl_provider_invoke_method(context, method, params, id); - } -} - -void wsfsp_impl_connected_default( - void * user_data) -{ - (void) user_data; - - // empty -} - -void wsfsp_impl_disconnected_default( - void * user_data) -{ - (void) user_data; - - // empty -} - -void wsfsp_impl_ontimer_default( - void * user_data) -{ - (void) user_data; - - // empty -} \ No newline at end of file diff --git a/lib/wsfs/provider/impl/provider.h b/lib/wsfs/provider/impl/provider.h deleted file mode 100644 index 072943a..0000000 --- a/lib/wsfs/provider/impl/provider.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_PROVIDER_H -#define WSFS_PROVIDER_IMPL_PROVIDER_H - -#include -#include "wsfs/provider/client_config.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wsfsp_provider -{ - wsfsp_connected_fn * connected; - wsfsp_disconnected_fn * disconnected; - wsfsp_ontimer_fn * ontimer; - wsfsp_lookup_fn * lookup; - wsfsp_getattr_fn * getattr; - wsfsp_readdir_fn * readdir; - wsfsp_open_fn * open; - wsfsp_close_fn * close; - wsfsp_read_fn * read; -}; - -struct wsfsp_impl_invokation_context -{ - struct wsfsp_provider * provider; - void * user_data; - struct wsfsp_request * request; -}; - -extern void wsfsp_impl_provider_init( - struct wsfsp_provider * provider); - -extern void wsfsp_impl_provider_init_from_prototype( - struct wsfsp_provider * provider, - struct wsfsp_provider const * prototype); - - -extern void wsfsp_impl_provider_invoke( - struct wsfsp_impl_invokation_context * context, - json_t * request); - -extern void wsfsp_impl_connected_default( - void * user_data); - -extern void wsfsp_impl_disconnected_default( - void * user_data); - -extern void wsfsp_impl_ontimer_default( - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/provider/impl/request.h b/lib/wsfs/provider/impl/request.h deleted file mode 100644 index c21d7ef..0000000 --- a/lib/wsfs/provider/impl/request.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef WSFS_PROVIDER_IMPL_REQUEST_H -#define WSFS_PROVIDER_IMPL_REQUEST_H - -#include -#include "wsfs/provider/impl/provider.h" -#include "wsfs/core/status.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -typedef void wsfsp_impl_request_respond_fn( - json_t * response, - void * user_data); - -struct wsfsp_request -{ - wsfsp_impl_request_respond_fn * respond; - void * user_data; - int id; -}; - -extern void wsfsp_impl_respond_error( - struct wsfsp_request * request, - wsfs_status status); - -extern struct wsfsp_request * wsfsp_impl_request_create( - struct wsfsp_request * prototype, - int id); - -extern void wsfsp_impl_request_dispose( - struct wsfsp_request * request); - -extern void wsfsp_impl_respond( - struct wsfsp_request * request, - json_t * result); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test/mock_authenticator.cc b/test/mock_authenticator.cc index f455270..f2decab 100644 --- a/test/mock_authenticator.cc +++ b/test/mock_authenticator.cc @@ -1,16 +1,16 @@ #include "mock_authenticator.hpp" -#define WSFS_AUTHENTICTOR_COUNT 3 +#define WF_AUTHENTICATOR_COUNT 3 namespace { -wsfs_test::Authenticator * g_authenticators[WSFS_AUTHENTICTOR_COUNT]; +webfuse_test::Authenticator * g_authenticators[WF_AUTHENTICATOR_COUNT]; } -namespace wsfs_test +namespace webfuse_test { void set_authenticator(Authenticator * authenticator) @@ -23,17 +23,17 @@ void set_authenticator(size_t i, Authenticator * authenticator) g_authenticators[i] = authenticator; } -bool authenticate(struct wsfs_credentials * creds, void * user_data) +bool authenticate(struct wf_credentials * creds, void * user_data) { return g_authenticators[0]->authenticate(creds, user_data); } -bool authenticate_1(struct wsfs_credentials * creds, void * user_data) +bool authenticate_1(struct wf_credentials * creds, void * user_data) { return g_authenticators[1]->authenticate(creds, user_data); } -bool authenticate_2(struct wsfs_credentials * creds, void * user_data) +bool authenticate_2(struct wf_credentials * creds, void * user_data) { return g_authenticators[2]->authenticate(creds, user_data); } diff --git a/test/mock_authenticator.hpp b/test/mock_authenticator.hpp index 1660fc9..bb38be3 100644 --- a/test/mock_authenticator.hpp +++ b/test/mock_authenticator.hpp @@ -2,9 +2,9 @@ #define MOCK_AUTHENTICATOR_H #include -#include "wsfs/adapter/impl/authenticator.h" +#include "webfuse/adapter/impl/authenticator.h" -namespace wsfs_test +namespace webfuse_test { class Authenticator @@ -12,22 +12,22 @@ class Authenticator public: virtual ~Authenticator() { } virtual bool authenticate( - struct wsfs_credentials * credentials, + struct wf_credentials * credentials, void * user_data) = 0; }; class MockAuthenticator: public Authenticator { public: - MOCK_METHOD2(authenticate, bool (struct wsfs_credentials * credentials, void * user_data)); + MOCK_METHOD2(authenticate, bool (struct wf_credentials * credentials, void * user_data)); }; void set_authenticator(Authenticator * authenticator); void set_authenticator(size_t index, Authenticator * authenticator); -bool authenticate(struct wsfs_credentials * creds, void * user_data); -bool authenticate_1(struct wsfs_credentials * creds, void * user_data); -bool authenticate_2(struct wsfs_credentials * creds, void * user_data); +bool authenticate(struct wf_credentials * creds, void * user_data); +bool authenticate_1(struct wf_credentials * creds, void * user_data); +bool authenticate_2(struct wf_credentials * creds, void * user_data); } diff --git a/test/msleep.cc b/test/msleep.cc index 7719810..cd989fb 100644 --- a/test/msleep.cc +++ b/test/msleep.cc @@ -1,7 +1,7 @@ #include "msleep.hpp" #include -namespace wsfs_test +namespace webfuse_test { void msleep(long millis) diff --git a/test/msleep.hpp b/test/msleep.hpp index 6d53e3c..47cb1e6 100644 --- a/test/msleep.hpp +++ b/test/msleep.hpp @@ -1,7 +1,7 @@ -#ifndef WSFS_TEST_MSLEEP_HPP -#define WSFS_TEST_MSLEEP_HPP +#ifndef WF_TEST_MSLEEP_HPP +#define WF_TEST_MSLEEP_HPP -namespace wsfs_test +namespace webfuse_test { extern void msleep(long millis); diff --git a/test/test_authenticator.cc b/test/test_authenticator.cc index e2249ce..93505a9 100644 --- a/test/test_authenticator.cc +++ b/test/test_authenticator.cc @@ -3,15 +3,15 @@ #include "mock_authenticator.hpp" -#include "wsfs/adapter/impl/authenticator.h" -#include "wsfs/adapter/impl/credentials.h" +#include "webfuse/adapter/impl/authenticator.h" +#include "webfuse/adapter/impl/credentials.h" using ::testing::Return; using ::testing::_; -using ::wsfs_test::Authenticator; -using ::wsfs_test::MockAuthenticator; -using ::wsfs_test::set_authenticator; -using ::wsfs_test::authenticate; +using ::webfuse_test::Authenticator; +using ::webfuse_test::MockAuthenticator; +using ::webfuse_test::set_authenticator; +using ::webfuse_test::authenticate; TEST(Authenticator, Authenticate) @@ -19,8 +19,8 @@ TEST(Authenticator, Authenticate) MockAuthenticator mock; set_authenticator(&mock); - struct wsfs_credentials creds; - wsfs_impl_credentials_init(&creds, "username", nullptr); + struct wf_credentials creds; + wf_impl_credentials_init(&creds, "username", nullptr); char dummy[] = "usr_data"; void * user_data = reinterpret_cast(dummy); @@ -28,16 +28,16 @@ TEST(Authenticator, Authenticate) .Times(1) .WillRepeatedly(Return(true)); - struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create( + struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create( "username", &authenticate, user_data); - bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds); + bool result = wf_impl_authenticator_autenticate(authenticator, &creds); ASSERT_TRUE(result); - wsfs_impl_authenticator_dispose(authenticator); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_authenticator_dispose(authenticator); + wf_impl_credentials_cleanup(&creds); } TEST(Authenticator, SkipAuthenticationWithWrongType) @@ -45,19 +45,19 @@ TEST(Authenticator, SkipAuthenticationWithWrongType) MockAuthenticator mock; set_authenticator(&mock); - struct wsfs_credentials creds; - wsfs_impl_credentials_init(&creds, "username", nullptr); + struct wf_credentials creds; + wf_impl_credentials_init(&creds, "username", nullptr); EXPECT_CALL(mock, authenticate(_, _)) .Times(0); - struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create( + struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create( "certificate", &authenticate, nullptr); - bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds); + bool result = wf_impl_authenticator_autenticate(authenticator, &creds); ASSERT_FALSE(result); - wsfs_impl_authenticator_dispose(authenticator); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_authenticator_dispose(authenticator); + wf_impl_credentials_cleanup(&creds); } \ No newline at end of file diff --git a/test/test_authenticators.cc b/test/test_authenticators.cc index 2030da7..3227e57 100644 --- a/test/test_authenticators.cc +++ b/test/test_authenticators.cc @@ -1,86 +1,86 @@ #include #include -#include "wsfs/adapter/impl/authenticators.h" -#include "wsfs/adapter/impl/credentials.h" +#include "webfuse/adapter/impl/authenticators.h" +#include "webfuse/adapter/impl/credentials.h" #include "mock_authenticator.hpp" using ::testing::_; using ::testing::Return; -using ::wsfs_test::MockAuthenticator; -using ::wsfs_test::set_authenticator; -using ::wsfs_test::authenticate; -using ::wsfs_test::authenticate_1; -using ::wsfs_test::authenticate_2; +using ::webfuse_test::MockAuthenticator; +using ::webfuse_test::set_authenticator; +using ::webfuse_test::authenticate; +using ::webfuse_test::authenticate_1; +using ::webfuse_test::authenticate_2; TEST(Authenticators, CloneEmpty) { - struct wsfs_impl_authenticators authenticators; - struct wsfs_impl_authenticators clone; + struct wf_impl_authenticators authenticators; + struct wf_impl_authenticators clone; - wsfs_impl_authenticators_init(&authenticators); + wf_impl_authenticators_init(&authenticators); ASSERT_EQ(nullptr, authenticators.first); - wsfs_impl_authenticators_clone(&authenticators, &clone); + wf_impl_authenticators_clone(&authenticators, &clone); ASSERT_EQ(nullptr, clone.first); - wsfs_impl_authenticators_cleanup(&authenticators); - wsfs_impl_authenticators_cleanup(&clone); + wf_impl_authenticators_cleanup(&authenticators); + wf_impl_authenticators_cleanup(&clone); } TEST(Authenticators, Clone) { - struct wsfs_impl_authenticators authenticators; - struct wsfs_impl_authenticators clone; + struct wf_impl_authenticators authenticators; + struct wf_impl_authenticators clone; - wsfs_impl_authenticators_init(&authenticators); - wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); + wf_impl_authenticators_init(&authenticators); + wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); ASSERT_NE(nullptr, authenticators.first); - wsfs_impl_authenticators_clone(&authenticators, &clone); + wf_impl_authenticators_clone(&authenticators, &clone); ASSERT_NE(nullptr, clone.first); ASSERT_NE(nullptr, authenticators.first); ASSERT_NE(authenticators.first, clone.first); - wsfs_impl_authenticators_cleanup(&authenticators); - wsfs_impl_authenticators_cleanup(&clone); + wf_impl_authenticators_cleanup(&authenticators); + wf_impl_authenticators_cleanup(&clone); } TEST(Authenticators, Move) { - struct wsfs_impl_authenticators authenticators; - struct wsfs_impl_authenticators clone; + struct wf_impl_authenticators authenticators; + struct wf_impl_authenticators clone; - wsfs_impl_authenticators_init(&authenticators); - wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); + wf_impl_authenticators_init(&authenticators); + wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); ASSERT_NE(nullptr, authenticators.first); - wsfs_impl_authenticators_move(&authenticators, &clone); + wf_impl_authenticators_move(&authenticators, &clone); ASSERT_NE(nullptr, clone.first); ASSERT_EQ(nullptr, authenticators.first); ASSERT_NE(authenticators.first, clone.first); - wsfs_impl_authenticators_cleanup(&authenticators); - wsfs_impl_authenticators_cleanup(&clone); + wf_impl_authenticators_cleanup(&authenticators); + wf_impl_authenticators_cleanup(&clone); } TEST(Authenticators, AuthenticateWithoutAuthenticators) { - struct wsfs_credentials creds; - wsfs_impl_credentials_init(&creds, "username", nullptr); + struct wf_credentials creds; + wf_impl_credentials_init(&creds, "username", nullptr); - struct wsfs_impl_authenticators authenticators; - wsfs_impl_authenticators_init(&authenticators); + struct wf_impl_authenticators authenticators; + wf_impl_authenticators_init(&authenticators); - bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds); + bool result = wf_impl_authenticators_authenticate(&authenticators, &creds); ASSERT_TRUE(result); - result = wsfs_impl_authenticators_authenticate(&authenticators, nullptr); + result = wf_impl_authenticators_authenticate(&authenticators, nullptr); ASSERT_TRUE(result); - wsfs_impl_authenticators_cleanup(&authenticators); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_authenticators_cleanup(&authenticators); + wf_impl_credentials_cleanup(&creds); } TEST(Authenticators, FailToAuthenticateWithoutCredentials) @@ -88,20 +88,20 @@ TEST(Authenticators, FailToAuthenticateWithoutCredentials) MockAuthenticator mock; set_authenticator(&mock); - struct wsfs_impl_authenticators authenticators; - wsfs_impl_authenticators_init(&authenticators); - wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); + struct wf_impl_authenticators authenticators; + wf_impl_authenticators_init(&authenticators); + wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); - bool result = wsfs_impl_authenticators_authenticate(&authenticators, nullptr); + bool result = wf_impl_authenticators_authenticate(&authenticators, nullptr); ASSERT_FALSE(result); - wsfs_impl_authenticators_cleanup(&authenticators); + wf_impl_authenticators_cleanup(&authenticators); } TEST(Authenticators, AuthenticateWithMultipleCredentials) { - struct wsfs_credentials creds; - wsfs_impl_credentials_init(&creds, "username", nullptr); + struct wf_credentials creds; + wf_impl_credentials_init(&creds, "username", nullptr); MockAuthenticator username_mock; set_authenticator(1, &username_mock); @@ -114,22 +114,22 @@ TEST(Authenticators, AuthenticateWithMultipleCredentials) EXPECT_CALL(certificate_mock, authenticate(_, _)) .Times(0); - struct wsfs_impl_authenticators authenticators; - wsfs_impl_authenticators_init(&authenticators); - wsfs_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr); - wsfs_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr); + struct wf_impl_authenticators authenticators; + wf_impl_authenticators_init(&authenticators); + wf_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr); + wf_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr); - bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds); + bool result = wf_impl_authenticators_authenticate(&authenticators, &creds); ASSERT_TRUE(result); - wsfs_impl_authenticators_cleanup(&authenticators); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_authenticators_cleanup(&authenticators); + wf_impl_credentials_cleanup(&creds); } TEST(Authenticators, FailedAuthenticateWithWrongType) { - struct wsfs_credentials creds; - wsfs_impl_credentials_init(&creds, "token", nullptr); + struct wf_credentials creds; + wf_impl_credentials_init(&creds, "token", nullptr); MockAuthenticator username_mock; set_authenticator(1, &username_mock); @@ -141,14 +141,14 @@ TEST(Authenticators, FailedAuthenticateWithWrongType) EXPECT_CALL(certificate_mock, authenticate(_, _)) .Times(0); - struct wsfs_impl_authenticators authenticators; - wsfs_impl_authenticators_init(&authenticators); - wsfs_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr); - wsfs_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr); + struct wf_impl_authenticators authenticators; + wf_impl_authenticators_init(&authenticators); + wf_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr); + wf_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr); - bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds); + bool result = wf_impl_authenticators_authenticate(&authenticators, &creds); ASSERT_FALSE(result); - wsfs_impl_authenticators_cleanup(&authenticators); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_authenticators_cleanup(&authenticators); + wf_impl_credentials_cleanup(&creds); } diff --git a/test/test_credentials.cc b/test/test_credentials.cc index 1599d20..72350d4 100644 --- a/test/test_credentials.cc +++ b/test/test_credentials.cc @@ -1,70 +1,70 @@ #include -#include "wsfs/adapter/impl/credentials.h" +#include "webfuse/adapter/impl/credentials.h" #include TEST(Credentials, Type) { - struct wsfs_credentials creds; + struct wf_credentials creds; - wsfs_impl_credentials_init(&creds, "test", nullptr); - ASSERT_STREQ("test", wsfs_impl_credentials_type(&creds)); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_credentials_init(&creds, "test", nullptr); + ASSERT_STREQ("test", wf_impl_credentials_type(&creds)); + wf_impl_credentials_cleanup(&creds); } TEST(Credentials, Get) { - struct wsfs_credentials creds; + struct wf_credentials creds; json_t * data = json_object(); json_object_set_new(data, "username", json_string("bob")); json_object_set_new(data, "password", json_string("")); - wsfs_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds)); - ASSERT_STREQ("bob", wsfs_impl_credentials_get(&creds, "username")); - ASSERT_STREQ("", wsfs_impl_credentials_get(&creds, "password")); + wf_impl_credentials_init(&creds, "username", data); + ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); + ASSERT_STREQ("bob", wf_impl_credentials_get(&creds, "username")); + ASSERT_STREQ("", wf_impl_credentials_get(&creds, "password")); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_credentials_cleanup(&creds); json_decref(data); } TEST(Credentials, FailedToGetNonexistingValue) { - struct wsfs_credentials creds; + struct wf_credentials creds; json_t * data = json_object(); - wsfs_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password")); + wf_impl_credentials_init(&creds, "username", data); + ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_credentials_cleanup(&creds); json_decref(data); } TEST(Credentials, FailedToGetWithoutData) { - struct wsfs_credentials creds; + struct wf_credentials creds; - wsfs_impl_credentials_init(&creds, "username", nullptr); - ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password")); + wf_impl_credentials_init(&creds, "username", nullptr); + ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_credentials_cleanup(&creds); } TEST(Credentials, FailedToGetWrongDataType) { - struct wsfs_credentials creds; + struct wf_credentials creds; json_t * data = json_string("invalid_creds"); - wsfs_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password")); + wf_impl_credentials_init(&creds, "username", data); + ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); - wsfs_impl_credentials_cleanup(&creds); + wf_impl_credentials_cleanup(&creds); json_decref(data); } diff --git a/test/test_fuse_req.cc b/test/test_fuse_req.cc index c01a6fc..efb63af 100644 --- a/test/test_fuse_req.cc +++ b/test/test_fuse_req.cc @@ -1,5 +1,5 @@ #include -#include "wsfs/adapter/fuse_wrapper.h" +#include "webfuse/adapter/fuse_wrapper.h" TEST(libfuse, fuse_req_t_size) { diff --git a/test/test_response_parser.cc b/test/test_response_parser.cc index 4e14e7a..bacb7a9 100644 --- a/test/test_response_parser.cc +++ b/test/test_response_parser.cc @@ -1,60 +1,60 @@ #include #include -#include "wsfs/adapter/impl/jsonrpc/response.h" +#include "webfuse/adapter/impl/jsonrpc/response.h" static void response_parse_str( std::string const & buffer, - struct wsfs_impl_jsonrpc_response * response) + struct wf_impl_jsonrpc_response * response) { - wsfs_impl_jsonrpc_response_init(response, buffer.c_str(), buffer.size()); + wf_impl_jsonrpc_response_init(response, buffer.c_str(), buffer.size()); } TEST(response_parser, test) { - struct wsfs_impl_jsonrpc_response response; + struct wf_impl_jsonrpc_response response; // invalid json response_parse_str("", &response); - ASSERT_NE(WSFS_GOOD, response.status); + ASSERT_NE(WF_GOOD, response.status); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); // invalid json response_parse_str("invalid_json", &response); - ASSERT_NE(WSFS_GOOD, response.status); + ASSERT_NE(WF_GOOD, response.status); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); // no object response_parse_str("[]", &response); - ASSERT_NE(WSFS_GOOD, response.status); + ASSERT_NE(WF_GOOD, response.status); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); // empty response_parse_str("{}", &response); - ASSERT_NE(WSFS_GOOD, response.status); + ASSERT_NE(WF_GOOD, response.status); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); // no data response_parse_str("{\"id\":42}", &response); - ASSERT_NE(WSFS_GOOD, response.status); + ASSERT_NE(WF_GOOD, response.status); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); // custom error code response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); - ASSERT_NE(WSFS_GOOD, response.status); + ASSERT_NE(WF_GOOD, response.status); ASSERT_EQ(42, response.status); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); // valid response response_parse_str("{\"result\": true, \"id\": 42}", &response); - ASSERT_EQ(WSFS_GOOD, response.status); + ASSERT_EQ(WF_GOOD, response.status); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); json_decref(response.result); diff --git a/test/test_server.cc b/test/test_server.cc index a5625c5..ef8fa25 100644 --- a/test/test_server.cc +++ b/test/test_server.cc @@ -5,21 +5,21 @@ #include #include -#include "wsfs/adapter/server.h" -#include "wsfs/adapter/server_config.h" +#include "webfuse/adapter/server.h" +#include "webfuse/adapter/server_config.h" TEST(server, create_dispose) { mkdir("test", 0700); - struct wsfs_server_config * config = wsfs_server_config_create(); - wsfs_server_config_set_mountpoint(config, "test"); - struct wsfs_server * server = wsfs_server_create(config); + struct wf_server_config * config = wf_server_config_create(); + wf_server_config_set_mountpoint(config, "test"); + struct wf_server * server = wf_server_create(config); ASSERT_NE(nullptr, server); - wsfs_server_dispose(server); - wsfs_server_config_dispose(config); + wf_server_dispose(server); + wf_server_config_dispose(config); rmdir("test"); } \ No newline at end of file diff --git a/test/test_timepoint.cc b/test/test_timepoint.cc index d395fb2..85de35d 100644 --- a/test/test_timepoint.cc +++ b/test/test_timepoint.cc @@ -1,15 +1,15 @@ #include #include "msleep.hpp" -#include "wsfs/adapter/impl/time/timepoint.h" +#include "webfuse/adapter/impl/time/timepoint.h" -using wsfs_test::msleep; +using webfuse_test::msleep; TEST(timepoint, now) { - wsfs_impl_timepoint start = wsfs_impl_timepoint_now(); + wf_impl_timepoint start = wf_impl_timepoint_now(); msleep(42); - wsfs_impl_timepoint end = wsfs_impl_timepoint_now(); + wf_impl_timepoint end = wf_impl_timepoint_now(); ASSERT_LT(start, end); ASSERT_LT(end, start + 500); @@ -17,20 +17,20 @@ TEST(timepoint, now) TEST(timepoint, in_msec) { - wsfs_impl_timepoint now = wsfs_impl_timepoint_now(); - wsfs_impl_timepoint later = wsfs_impl_timepoint_in_msec(42); + wf_impl_timepoint now = wf_impl_timepoint_now(); + wf_impl_timepoint later = wf_impl_timepoint_in_msec(42); ASSERT_LT(now, later); ASSERT_LT(later, now + 500); } -TEST(wsfs_impl_timepoint, elapsed) +TEST(wf_impl_timepoint, elapsed) { - wsfs_impl_timepoint now; + wf_impl_timepoint now; - now = wsfs_impl_timepoint_now(); - ASSERT_TRUE(wsfs_impl_timepoint_is_elapsed(now - 1)); + now = wf_impl_timepoint_now(); + ASSERT_TRUE(wf_impl_timepoint_is_elapsed(now - 1)); - now =wsfs_impl_timepoint_now(); - ASSERT_FALSE(wsfs_impl_timepoint_is_elapsed(now + 500)); + now =wf_impl_timepoint_now(); + ASSERT_FALSE(wf_impl_timepoint_is_elapsed(now + 500)); } diff --git a/test/test_timer.cc b/test/test_timer.cc index 66592e0..d33dea8 100644 --- a/test/test_timer.cc +++ b/test/test_timer.cc @@ -3,15 +3,15 @@ #include #include "msleep.hpp" -#include "wsfs/adapter/impl/time/timer.h" -#include "wsfs/adapter/impl/time/timeout_manager.h" +#include "webfuse/adapter/impl/time/timer.h" +#include "webfuse/adapter/impl/time/timeout_manager.h" using std::size_t; -using wsfs_test::msleep; +using webfuse_test::msleep; namespace { - void on_timeout(struct wsfs_impl_timer * timer) + void on_timeout(struct wf_impl_timer * timer) { bool * triggered = reinterpret_cast(timer->user_data); *triggered = true; @@ -20,82 +20,82 @@ namespace TEST(timer, init) { - struct wsfs_impl_timeout_manager manager; - struct wsfs_impl_timer timer; + struct wf_impl_timeout_manager manager; + struct wf_impl_timer timer; - wsfs_impl_timeout_manager_init(&manager); - wsfs_impl_timer_init(&timer, &manager); + wf_impl_timeout_manager_init(&manager); + wf_impl_timer_init(&timer, &manager); - wsfs_impl_timer_cleanup(&timer); - wsfs_impl_timeout_manager_cleanup(&manager); + wf_impl_timer_cleanup(&timer); + wf_impl_timeout_manager_cleanup(&manager); } TEST(timer, trigger) { - struct wsfs_impl_timeout_manager manager; - struct wsfs_impl_timer timer; + struct wf_impl_timeout_manager manager; + struct wf_impl_timer timer; - wsfs_impl_timeout_manager_init(&manager); - wsfs_impl_timer_init(&timer, &manager); + wf_impl_timeout_manager_init(&manager); + wf_impl_timer_init(&timer, &manager); bool triggered = false; - wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast(&triggered)); + wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast(&triggered)); msleep(500); - wsfs_impl_timeout_manager_check(&manager); + wf_impl_timeout_manager_check(&manager); ASSERT_TRUE(triggered); - wsfs_impl_timer_cleanup(&timer); - wsfs_impl_timeout_manager_cleanup(&manager); + wf_impl_timer_cleanup(&timer); + wf_impl_timeout_manager_cleanup(&manager); } TEST(timer, cancel) { - struct wsfs_impl_timeout_manager manager; - struct wsfs_impl_timer timer; + struct wf_impl_timeout_manager manager; + struct wf_impl_timer timer; - wsfs_impl_timeout_manager_init(&manager); - wsfs_impl_timer_init(&timer, &manager); + wf_impl_timeout_manager_init(&manager); + wf_impl_timer_init(&timer, &manager); bool triggered = false; - wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, &triggered); + wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(250), &on_timeout, &triggered); msleep(500); - wsfs_impl_timer_cancel(&timer); - wsfs_impl_timeout_manager_check(&manager); + wf_impl_timer_cancel(&timer); + wf_impl_timeout_manager_check(&manager); ASSERT_FALSE(triggered); - wsfs_impl_timer_cleanup(&timer); - wsfs_impl_timeout_manager_cleanup(&manager); + wf_impl_timer_cleanup(&timer); + wf_impl_timeout_manager_cleanup(&manager); } TEST(timer, multiple_timers) { static size_t const count = 5; - struct wsfs_impl_timeout_manager manager; - struct wsfs_impl_timer timer[count]; + struct wf_impl_timeout_manager manager; + struct wf_impl_timer timer[count]; bool triggered[count]; - wsfs_impl_timeout_manager_init(&manager); + wf_impl_timeout_manager_init(&manager); for(size_t i = 0; i < count; i++) { - wsfs_impl_timer_init(&timer[i], &manager); + wf_impl_timer_init(&timer[i], &manager); triggered[i] = false; - wsfs_impl_timer_start(&timer[i], wsfs_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]); + wf_impl_timer_start(&timer[i], wf_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]); } for(size_t i = 0; i < count; i++) { msleep(100); - wsfs_impl_timeout_manager_check(&manager); + wf_impl_timeout_manager_check(&manager); } for(size_t i = 0; i < count; i++) { ASSERT_TRUE(triggered[i]); - wsfs_impl_timer_cleanup(&timer[i]); + wf_impl_timer_cleanup(&timer[i]); } - wsfs_impl_timeout_manager_cleanup(&manager); + wf_impl_timeout_manager_cleanup(&manager); } diff --git a/test/test_url.cc b/test/test_url.cc index fe2a517..7f6a5e7 100644 --- a/test/test_url.cc +++ b/test/test_url.cc @@ -1,69 +1,69 @@ #include -#include "wsfs/provider/impl/url.h" +#include "webfuse/provider/impl/url.h" TEST(url, ParseWs) { - struct wsfsp_impl_url url; - bool result = wsfsp_impl_url_init(&url, "ws://localhost/"); + struct wfp_impl_url url; + bool result = wfp_impl_url_init(&url, "ws://localhost/"); ASSERT_TRUE(result); ASSERT_EQ(80, url.port); ASSERT_FALSE(url.use_tls); ASSERT_STREQ("localhost", url.host); ASSERT_STREQ("/", url.path); - wsfsp_impl_url_cleanup(&url); + wfp_impl_url_cleanup(&url); } TEST(url, ParswWss) { - struct wsfsp_impl_url url; - bool result = wsfsp_impl_url_init(&url, "wss://localhost/"); + struct wfp_impl_url url; + bool result = wfp_impl_url_init(&url, "wss://localhost/"); ASSERT_TRUE(result); ASSERT_EQ(443, url.port); ASSERT_TRUE(url.use_tls); ASSERT_STREQ("localhost", url.host); ASSERT_STREQ("/", url.path); - wsfsp_impl_url_cleanup(&url); + wfp_impl_url_cleanup(&url); } TEST(url, ParseIPAdress) { - struct wsfsp_impl_url url; - bool result = wsfsp_impl_url_init(&url, "ws://127.0.0.1/"); + struct wfp_impl_url url; + bool result = wfp_impl_url_init(&url, "ws://127.0.0.1/"); ASSERT_TRUE(result); ASSERT_EQ(80, url.port); ASSERT_STREQ("127.0.0.1", url.host); ASSERT_STREQ("/", url.path); - wsfsp_impl_url_cleanup(&url); + wfp_impl_url_cleanup(&url); } TEST(url, ParsePort) { - struct wsfsp_impl_url url; - bool result = wsfsp_impl_url_init(&url, "ws://localhost:54321/"); + struct wfp_impl_url url; + bool result = wfp_impl_url_init(&url, "ws://localhost:54321/"); ASSERT_TRUE(result); ASSERT_EQ(54321, url.port); - wsfsp_impl_url_cleanup(&url); + wfp_impl_url_cleanup(&url); } TEST(url, ParseNonEmptyPath) { - struct wsfsp_impl_url url; - bool result = wsfsp_impl_url_init(&url, "ws://localhost/some_path?query"); + struct wfp_impl_url url; + bool result = wfp_impl_url_init(&url, "ws://localhost/some_path?query"); ASSERT_TRUE(result); ASSERT_STREQ("/some_path?query", url.path); - wsfsp_impl_url_cleanup(&url); + wfp_impl_url_cleanup(&url); } TEST(url, FailToParseUnknownProtocol) { - struct wsfsp_impl_url url; - bool result = wsfsp_impl_url_init(&url, "unknown://localhost/"); + struct wfp_impl_url url; + bool result = wfp_impl_url_init(&url, "unknown://localhost/"); ASSERT_FALSE(result); ASSERT_EQ(0, url.port); ASSERT_EQ(nullptr, url.path); @@ -72,8 +72,8 @@ TEST(url, FailToParseUnknownProtocol) TEST(url, FailToParseMissingProtocol) { - struct wsfsp_impl_url url; - bool result = wsfsp_impl_url_init(&url, "unknown"); + struct wfp_impl_url url; + bool result = wfp_impl_url_init(&url, "unknown"); ASSERT_FALSE(result); ASSERT_EQ(0, url.port); ASSERT_EQ(nullptr, url.path); @@ -82,8 +82,8 @@ TEST(url, FailToParseMissingProtocol) TEST(url, FailToParseMissingPath) { - struct wsfsp_impl_url url; - bool result = wsfsp_impl_url_init(&url, "ws://localhost"); + struct wfp_impl_url url; + bool result = wfp_impl_url_init(&url, "ws://localhost"); ASSERT_FALSE(result); ASSERT_EQ(0, url.port); ASSERT_EQ(nullptr, url.path);