From 1c9d1c842028eecc537ff93f676603e60e81d19d Mon Sep 17 00:00:00 2001 From: Falk Werner <47070255+falk-werner@users.noreply.github.com> Date: Tue, 26 Mar 2019 15:35:33 +0100 Subject: [PATCH] feat(API wrapper): separates implementation from public API * moves implementation to impl subdirectory * adds prefix _impl to implementation symbols * removes double compilation for shared and static libraries * fixes include guards * fixes usage of extern "C" --- CMakeLists.txt | 132 +++++----- include/wsfs/adapter/authenticate.h | 8 + include/wsfs/adapter/credentials.h | 4 +- include/wsfs/adapter/server.h | 6 +- include/wsfs/adapter/server_config.h | 4 +- include/wsfs/adapter/server_protocol.h | 6 +- include/wsfs/{ => core}/status.h | 0 include/wsfs/provider/client.h | 18 +- include/wsfs/provider/client_config.h | 12 +- include/wsfs/provider/client_protocol.h | 8 +- include/wsfs/provider/dirbuffer.h | 4 +- include/wsfs/provider/operation/close.h | 10 +- include/wsfs/provider/operation/error.h | 6 +- include/wsfs/provider/operation/getattr.h | 11 +- include/wsfs/provider/operation/lookup.h | 10 +- include/wsfs/provider/operation/open.h | 10 +- include/wsfs/provider/operation/read.h | 10 +- include/wsfs/provider/operation/readdir.h | 11 +- include/wsfs_adapter.h | 2 +- include/wsfs_provider.h | 2 +- lib/wsfs/adapter/api.c | 141 ++++++++++ lib/wsfs/adapter/authenticator.h | 40 --- lib/wsfs/adapter/authenticators.c | 101 -------- lib/wsfs/adapter/authenticators.h | 51 ---- lib/wsfs/adapter/credentials_intern.h | 30 --- lib/wsfs/adapter/filesystem.h | 45 ---- lib/wsfs/adapter/{ => impl}/authenticator.c | 16 +- lib/wsfs/adapter/impl/authenticator.h | 42 +++ lib/wsfs/adapter/impl/authenticators.c | 101 ++++++++ lib/wsfs/adapter/impl/authenticators.h | 51 ++++ lib/wsfs/adapter/{ => impl}/credentials.c | 10 +- lib/wsfs/adapter/impl/credentials.h | 36 +++ lib/wsfs/adapter/{ => impl}/filesystem.c | 42 +-- lib/wsfs/adapter/impl/filesystem.h | 45 ++++ lib/wsfs/adapter/{ => impl}/fuse_wrapper.h | 4 +- lib/wsfs/adapter/impl/jsonrpc/method.c | 28 ++ lib/wsfs/adapter/impl/jsonrpc/method.h | 31 +++ lib/wsfs/adapter/impl/jsonrpc/method_intern.h | 31 +++ lib/wsfs/adapter/{ => impl}/jsonrpc/request.c | 4 +- lib/wsfs/adapter/{ => impl}/jsonrpc/request.h | 6 +- .../adapter/{ => impl}/jsonrpc/response.c | 10 +- lib/wsfs/adapter/impl/jsonrpc/response.h | 38 +++ lib/wsfs/adapter/{ => impl}/jsonrpc/server.c | 90 +++---- lib/wsfs/adapter/impl/jsonrpc/server.h | 77 ++++++ lib/wsfs/adapter/{ => impl}/jsonrpc/util.c | 4 +- lib/wsfs/adapter/impl/jsonrpc/util.h | 17 ++ lib/wsfs/adapter/impl/operation/close.c | 21 ++ .../adapter/{ => impl}/operation/getattr.c | 32 +-- .../adapter/{ => impl}/operation/lookup.c | 33 ++- lib/wsfs/adapter/{ => impl}/operation/open.c | 18 +- lib/wsfs/adapter/{ => impl}/operation/read.c | 18 +- .../adapter/{ => impl}/operation/readdir.c | 48 ++-- lib/wsfs/adapter/{ => impl}/operations.h | 34 +-- lib/wsfs/adapter/{ => impl}/server.c | 36 +-- lib/wsfs/adapter/impl/server.h | 29 +++ lib/wsfs/adapter/{ => impl}/server_config.c | 52 ++-- lib/wsfs/adapter/impl/server_config.h | 72 ++++++ lib/wsfs/adapter/impl/server_protocol.c | 166 ++++++++++++ lib/wsfs/adapter/impl/server_protocol.h | 53 ++++ lib/wsfs/adapter/{ => impl}/session.c | 42 +-- lib/wsfs/adapter/impl/session.h | 64 +++++ lib/wsfs/adapter/impl/session_manager.c | 54 ++++ lib/wsfs/adapter/impl/session_manager.h | 46 ++++ lib/wsfs/adapter/impl/time/timeout_manager.c | 84 ++++++ lib/wsfs/adapter/impl/time/timeout_manager.h | 29 +++ .../impl/time/timeout_manager_intern.h | 24 ++ lib/wsfs/adapter/impl/time/timepoint.c | 31 +++ lib/wsfs/adapter/impl/time/timepoint.h | 31 +++ lib/wsfs/adapter/impl/time/timer.c | 65 +++++ lib/wsfs/adapter/impl/time/timer.h | 48 ++++ lib/wsfs/adapter/impl/time/timer_intern.h | 25 ++ lib/wsfs/adapter/jsonrpc/method.c | 28 -- lib/wsfs/adapter/jsonrpc/method.h | 24 -- lib/wsfs/adapter/jsonrpc/method_intern.h | 31 --- lib/wsfs/adapter/jsonrpc/response.h | 38 --- lib/wsfs/adapter/jsonrpc/server.h | 80 ------ lib/wsfs/adapter/jsonrpc/util.h | 17 -- lib/wsfs/adapter/operation/close.c | 21 -- lib/wsfs/adapter/server_config_intern.h | 37 --- lib/wsfs/adapter/server_protocol.c | 166 ------------ lib/wsfs/adapter/server_protocol_intern.h | 27 -- lib/wsfs/adapter/session.h | 64 ----- lib/wsfs/adapter/session_manager.c | 54 ---- lib/wsfs/adapter/session_manager.h | 46 ---- lib/wsfs/adapter/time/timeout_manager.c | 84 ------ lib/wsfs/adapter/time/timeout_manager.h | 29 --- .../adapter/time/timeout_manager_intern.h | 24 -- lib/wsfs/adapter/time/timepoint.c | 31 --- lib/wsfs/adapter/time/timepoint.h | 31 --- lib/wsfs/adapter/time/timer.c | 65 ----- lib/wsfs/adapter/time/timer.h | 48 ---- lib/wsfs/adapter/time/timer_intern.h | 25 -- lib/wsfs/{ => core}/message.c | 2 +- lib/wsfs/{ => core}/message.h | 0 lib/wsfs/{ => core}/message_queue.c | 4 +- lib/wsfs/{ => core}/message_queue.h | 0 lib/wsfs/{ => core}/status.c | 2 +- lib/wsfs/{ => core}/status_intern.h | 2 +- lib/wsfs/{ => core}/util.h | 0 lib/wsfs/provider/api.c | 240 ++++++++++++++++++ lib/wsfs/provider/client_config_intern.h | 24 -- lib/wsfs/provider/client_protocol_intern.h | 36 --- lib/wsfs/provider/dirbuffer_intern.h | 15 -- lib/wsfs/provider/{ => impl}/client.c | 34 +-- lib/wsfs/provider/impl/client.h | 49 ++++ lib/wsfs/provider/{ => impl}/client_config.c | 34 +-- lib/wsfs/provider/impl/client_config.h | 77 ++++++ .../provider/{ => impl}/client_protocol.c | 40 +-- lib/wsfs/provider/impl/client_protocol.h | 49 ++++ lib/wsfs/provider/{ => impl}/dirbuffer.c | 10 +- lib/wsfs/provider/impl/dirbuffer.h | 37 +++ .../provider/{ => impl}/operation/close.c | 10 +- lib/wsfs/provider/impl/operation/close.h | 26 ++ lib/wsfs/provider/impl/operation/error.h | 22 ++ .../provider/{ => impl}/operation/getattr.c | 22 +- lib/wsfs/provider/impl/operation/getattr.h | 29 +++ .../provider/{ => impl}/operation/lookup.c | 21 +- lib/wsfs/provider/impl/operation/lookup.h | 30 +++ lib/wsfs/provider/{ => impl}/operation/open.c | 22 +- lib/wsfs/provider/impl/operation/open.h | 30 +++ lib/wsfs/provider/{ => impl}/operation/read.c | 25 +- lib/wsfs/provider/impl/operation/read.h | 33 +++ .../provider/{ => impl}/operation/readdir.c | 26 +- lib/wsfs/provider/impl/operation/readdir.h | 29 +++ lib/wsfs/provider/impl/provider.c | 127 +++++++++ lib/wsfs/provider/{ => impl}/provider.h | 40 ++- lib/wsfs/provider/{ => impl}/request.c | 16 +- lib/wsfs/provider/impl/request.h | 43 ++++ lib/wsfs/provider/{ => impl}/url.c | 54 ++-- lib/wsfs/provider/{ => impl}/url.h | 23 +- lib/wsfs/provider/operation/close_intern.h | 27 -- lib/wsfs/provider/operation/getattr_intern.h | 26 -- lib/wsfs/provider/operation/lookup_intern.h | 27 -- lib/wsfs/provider/operation/open_intern.h | 27 -- lib/wsfs/provider/operation/read_intern.h | 29 --- lib/wsfs/provider/operation/readdir_intern.h | 26 -- lib/wsfs/provider/provider.c | 127 --------- lib/wsfs/provider/request.h | 39 --- test/mock_authenticator.hpp | 2 +- test/test_authenticator.cc | 24 +- test/test_authenticators.cc | 100 ++++---- test/test_credentials.cc | 48 ++-- test/test_response_parser.cc | 24 +- test/test_timepoint.cc | 22 +- test/test_timer.cc | 68 ++--- test/test_url.cc | 44 ++-- 146 files changed, 3043 insertions(+), 2390 deletions(-) rename include/wsfs/{ => core}/status.h (100%) create mode 100644 lib/wsfs/adapter/api.c delete mode 100644 lib/wsfs/adapter/authenticator.h delete mode 100644 lib/wsfs/adapter/authenticators.c delete mode 100644 lib/wsfs/adapter/authenticators.h delete mode 100644 lib/wsfs/adapter/credentials_intern.h delete mode 100644 lib/wsfs/adapter/filesystem.h rename lib/wsfs/adapter/{ => impl}/authenticator.c (62%) create mode 100644 lib/wsfs/adapter/impl/authenticator.h create mode 100644 lib/wsfs/adapter/impl/authenticators.c create mode 100644 lib/wsfs/adapter/impl/authenticators.h rename lib/wsfs/adapter/{ => impl}/credentials.c (78%) create mode 100644 lib/wsfs/adapter/impl/credentials.h rename lib/wsfs/adapter/{ => impl}/filesystem.c (57%) create mode 100644 lib/wsfs/adapter/impl/filesystem.h rename lib/wsfs/adapter/{ => impl}/fuse_wrapper.h (67%) create mode 100644 lib/wsfs/adapter/impl/jsonrpc/method.c create mode 100644 lib/wsfs/adapter/impl/jsonrpc/method.h create mode 100644 lib/wsfs/adapter/impl/jsonrpc/method_intern.h rename lib/wsfs/adapter/{ => impl}/jsonrpc/request.c (90%) rename lib/wsfs/adapter/{ => impl}/jsonrpc/request.h (70%) rename lib/wsfs/adapter/{ => impl}/jsonrpc/response.c (83%) create mode 100644 lib/wsfs/adapter/impl/jsonrpc/response.h rename lib/wsfs/adapter/{ => impl}/jsonrpc/server.c (51%) create mode 100644 lib/wsfs/adapter/impl/jsonrpc/server.h rename lib/wsfs/adapter/{ => impl}/jsonrpc/util.c (60%) create mode 100644 lib/wsfs/adapter/impl/jsonrpc/util.h create mode 100644 lib/wsfs/adapter/impl/operation/close.c rename lib/wsfs/adapter/{ => impl}/operation/getattr.c (61%) rename lib/wsfs/adapter/{ => impl}/operation/lookup.c (64%) rename lib/wsfs/adapter/{ => impl}/operation/open.c (61%) rename lib/wsfs/adapter/{ => impl}/operation/read.c (72%) rename lib/wsfs/adapter/{ => impl}/operation/readdir.c (65%) rename lib/wsfs/adapter/{ => impl}/operations.h (56%) rename lib/wsfs/adapter/{ => impl}/server.c (76%) create mode 100644 lib/wsfs/adapter/impl/server.h rename lib/wsfs/adapter/{ => impl}/server_config.c (54%) create mode 100644 lib/wsfs/adapter/impl/server_config.h create mode 100644 lib/wsfs/adapter/impl/server_protocol.c create mode 100644 lib/wsfs/adapter/impl/server_protocol.h rename lib/wsfs/adapter/{ => impl}/session.c (59%) create mode 100644 lib/wsfs/adapter/impl/session.h create mode 100644 lib/wsfs/adapter/impl/session_manager.c create mode 100644 lib/wsfs/adapter/impl/session_manager.h create mode 100644 lib/wsfs/adapter/impl/time/timeout_manager.c create mode 100644 lib/wsfs/adapter/impl/time/timeout_manager.h create mode 100644 lib/wsfs/adapter/impl/time/timeout_manager_intern.h create mode 100644 lib/wsfs/adapter/impl/time/timepoint.c create mode 100644 lib/wsfs/adapter/impl/time/timepoint.h create mode 100644 lib/wsfs/adapter/impl/time/timer.c create mode 100644 lib/wsfs/adapter/impl/time/timer.h create mode 100644 lib/wsfs/adapter/impl/time/timer_intern.h delete mode 100644 lib/wsfs/adapter/jsonrpc/method.c delete mode 100644 lib/wsfs/adapter/jsonrpc/method.h delete mode 100644 lib/wsfs/adapter/jsonrpc/method_intern.h delete mode 100644 lib/wsfs/adapter/jsonrpc/response.h delete mode 100644 lib/wsfs/adapter/jsonrpc/server.h delete mode 100644 lib/wsfs/adapter/jsonrpc/util.h delete mode 100644 lib/wsfs/adapter/operation/close.c delete mode 100644 lib/wsfs/adapter/server_config_intern.h delete mode 100644 lib/wsfs/adapter/server_protocol.c delete mode 100644 lib/wsfs/adapter/server_protocol_intern.h delete mode 100644 lib/wsfs/adapter/session.h delete mode 100644 lib/wsfs/adapter/session_manager.c delete mode 100644 lib/wsfs/adapter/session_manager.h delete mode 100644 lib/wsfs/adapter/time/timeout_manager.c delete mode 100644 lib/wsfs/adapter/time/timeout_manager.h delete mode 100644 lib/wsfs/adapter/time/timeout_manager_intern.h delete mode 100644 lib/wsfs/adapter/time/timepoint.c delete mode 100644 lib/wsfs/adapter/time/timepoint.h delete mode 100644 lib/wsfs/adapter/time/timer.c delete mode 100644 lib/wsfs/adapter/time/timer.h delete mode 100644 lib/wsfs/adapter/time/timer_intern.h rename lib/wsfs/{ => core}/message.c (96%) rename lib/wsfs/{ => core}/message.h (100%) rename lib/wsfs/{ => core}/message_queue.c (94%) rename lib/wsfs/{ => core}/message_queue.h (100%) rename lib/wsfs/{ => core}/status.c (95%) rename lib/wsfs/{ => core}/status_intern.h (89%) rename lib/wsfs/{ => core}/util.h (100%) create mode 100644 lib/wsfs/provider/api.c delete mode 100644 lib/wsfs/provider/client_config_intern.h delete mode 100644 lib/wsfs/provider/client_protocol_intern.h delete mode 100644 lib/wsfs/provider/dirbuffer_intern.h rename lib/wsfs/provider/{ => impl}/client.c (74%) create mode 100644 lib/wsfs/provider/impl/client.h rename lib/wsfs/provider/{ => impl}/client_config.c (70%) create mode 100644 lib/wsfs/provider/impl/client_config.h rename lib/wsfs/provider/{ => impl}/client_protocol.c (75%) create mode 100644 lib/wsfs/provider/impl/client_protocol.h rename lib/wsfs/provider/{ => impl}/dirbuffer.c (79%) create mode 100644 lib/wsfs/provider/impl/dirbuffer.h rename lib/wsfs/provider/{ => impl}/operation/close.c (84%) create mode 100644 lib/wsfs/provider/impl/operation/close.h create mode 100644 lib/wsfs/provider/impl/operation/error.h rename lib/wsfs/provider/{ => impl}/operation/getattr.c (73%) create mode 100644 lib/wsfs/provider/impl/operation/getattr.h rename lib/wsfs/provider/{ => impl}/operation/lookup.c (76%) create mode 100644 lib/wsfs/provider/impl/operation/lookup.h rename lib/wsfs/provider/{ => impl}/operation/open.c (65%) create mode 100644 lib/wsfs/provider/impl/operation/open.h rename lib/wsfs/provider/{ => impl}/operation/read.c (77%) create mode 100644 lib/wsfs/provider/impl/operation/read.h rename lib/wsfs/provider/{ => impl}/operation/readdir.c (50%) create mode 100644 lib/wsfs/provider/impl/operation/readdir.h create mode 100644 lib/wsfs/provider/impl/provider.c rename lib/wsfs/provider/{ => impl}/provider.h (53%) rename lib/wsfs/provider/{ => impl}/request.c (77%) create mode 100644 lib/wsfs/provider/impl/request.h rename lib/wsfs/provider/{ => impl}/url.c (61%) rename lib/wsfs/provider/{ => impl}/url.h (50%) delete mode 100644 lib/wsfs/provider/operation/close_intern.h delete mode 100644 lib/wsfs/provider/operation/getattr_intern.h delete mode 100644 lib/wsfs/provider/operation/lookup_intern.h delete mode 100644 lib/wsfs/provider/operation/open_intern.h delete mode 100644 lib/wsfs/provider/operation/read_intern.h delete mode 100644 lib/wsfs/provider/operation/readdir_intern.h delete mode 100644 lib/wsfs/provider/provider.c delete mode 100644 lib/wsfs/provider/request.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cd01bc..96b0ef2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,45 +43,61 @@ set(EXTRA_CFLAGS ${JANSSON_CFLAGS_OTHER} "-pthread" ) -# libwsfs-common -set(WSFS_COMMON_SOURCES - lib/wsfs/message.c - lib/wsfs/message_queue.c - lib/wsfs/status.c + +# libwsfs-core + +add_library(wsfs-core STATIC + lib/wsfs/core/message.c + lib/wsfs/core/message_queue.c + lib/wsfs/core/status.c ) -install(FILES include/wsfs/status.h DESTINATION include/wsfs) +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 -set(WSFS_ADAPTER_SOURCES - lib/wsfs/adapter/filesystem.c - lib/wsfs/adapter/server.c - lib/wsfs/adapter/server_config.c - lib/wsfs/adapter/server_protocol.c - lib/wsfs/adapter/session.c - lib/wsfs/adapter/session_manager.c - lib/wsfs/adapter/authenticator.c - lib/wsfs/adapter/authenticators.c - lib/wsfs/adapter/credentials.c - lib/wsfs/adapter/time/timepoint.c - lib/wsfs/adapter/time/timer.c - lib/wsfs/adapter/time/timeout_manager.c - lib/wsfs/adapter/operation/lookup.c - lib/wsfs/adapter/operation/getattr.c - lib/wsfs/adapter/operation/readdir.c - lib/wsfs/adapter/operation/open.c - lib/wsfs/adapter/operation/close.c - lib/wsfs/adapter/operation/read.c - lib/wsfs/adapter/jsonrpc/server.c - lib/wsfs/adapter/jsonrpc/method.c - lib/wsfs/adapter/jsonrpc/request.c - lib/wsfs/adapter/jsonrpc/response.c - lib/wsfs/adapter/jsonrpc/util.c +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 ) -add_library(wsfs-adapter SHARED ${WSFS_ADAPTER_SOURCES} ${WSFS_COMMON_SOURCES}) +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) + +add_library(wsfs-adapter SHARED + lib/wsfs/adapter/api.c +) set_target_properties(wsfs-adapter PROPERTIES VERSION ${PROJECT_VERSION}) set_target_properties(wsfs-adapter PROPERTIES SOVERSION 0) @@ -90,6 +106,7 @@ set_target_properties(wsfs-adapter PROPERTIES COMPILE_DEFINITIONS "WSFSA_API=WSF 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) file(WRITE "${PROJECT_BINARY_DIR}/libwsfs-adapter.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" @@ -112,23 +129,31 @@ install(FILES "${PROJECT_BINARY_DIR}/libwsfs-adapter.pc" DESTINATION lib${LIB_SU #libwsfs-provider -set(WSFS_PROVIDER_SOURCES - lib/wsfs/provider/url.c - lib/wsfs/provider/client.c - lib/wsfs/provider/client_config.c - lib/wsfs/provider/client_protocol.c - lib/wsfs/provider/provider.c - lib/wsfs/provider/request.c - lib/wsfs/provider/dirbuffer.c - lib/wsfs/provider/operation/lookup.c - lib/wsfs/provider/operation/getattr.c - lib/wsfs/provider/operation/readdir.c - lib/wsfs/provider/operation/open.c - lib/wsfs/provider/operation/close.c - lib/wsfs/provider/operation/read.c +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 ) -add_library(wsfs-provider SHARED ${WSFS_PROVIDER_SOURCES} ${WSFS_COMMON_SOURCES}) +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) + +add_library(wsfs-provider SHARED + lib/wsfs/provider/api.c +) set_target_properties(wsfs-provider PROPERTIES VERSION ${PROJECT_VERSION}) set_target_properties(wsfs-provider PROPERTIES SOVERSION 0) @@ -137,6 +162,7 @@ set_target_properties(wsfs-provider PROPERTIES COMPILE_DEFINITIONS "WSFSP_API=WS 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) file(WRITE "${PROJECT_BINARY_DIR}/libwsfs-provider.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" @@ -242,17 +268,6 @@ pkg_check_modules(GTEST gtest_main) include(GoogleTest) pkg_check_modules(GMOCK gmock) -add_library(wsfs-adapter-static STATIC ${WSFS_ADAPTER_SOURCES}) -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}) - -add_library(wsfs-provider-static STATIC ${WSFS_PROVIDER_SOURCES}) -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}) - - add_executable(alltests test/msleep.cc test/mock_authenticator.cc @@ -264,10 +279,9 @@ add_executable(alltests test/test_credentials.cc test/test_authenticator.cc test/test_authenticators.cc - ${WSFS_COMMON_SOURCES} ) -target_link_libraries(alltests PUBLIC wsfs-adapter-static wsfs-provider-static ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES}) +target_link_libraries(alltests PUBLIC wsfs-adapter-static wsfs-provider-static wsfs-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/include/wsfs/adapter/authenticate.h b/include/wsfs/adapter/authenticate.h index 9e630ee..c34d402 100644 --- a/include/wsfs/adapter/authenticate.h +++ b/include/wsfs/adapter/authenticate.h @@ -5,11 +5,19 @@ #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 index 747b107..9e77113 100644 --- a/include/wsfs/adapter/credentials.h +++ b/include/wsfs/adapter/credentials.h @@ -3,13 +3,13 @@ #include "wsfs/adapter/api.h" -struct wsfs_credentials; - #ifdef __cplusplus extern "C" { #endif +struct wsfs_credentials; + extern WSFSA_API char const * wsfs_credentials_type( struct wsfs_credentials const * credentials); diff --git a/include/wsfs/adapter/server.h b/include/wsfs/adapter/server.h index 7886251..3a27bdc 100644 --- a/include/wsfs/adapter/server.h +++ b/include/wsfs/adapter/server.h @@ -3,14 +3,14 @@ #include "wsfs/adapter/api.h" -struct wsfs_server; -struct wsfs_server_config; - #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); diff --git a/include/wsfs/adapter/server_config.h b/include/wsfs/adapter/server_config.h index 639e1c1..8983693 100644 --- a/include/wsfs/adapter/server_config.h +++ b/include/wsfs/adapter/server_config.h @@ -4,13 +4,13 @@ #include "wsfs/adapter/api.h" #include "wsfs/adapter/authenticate.h" -struct wsfs_server_config; - #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( diff --git a/include/wsfs/adapter/server_protocol.h b/include/wsfs/adapter/server_protocol.h index 0579677..bfa33ee 100644 --- a/include/wsfs/adapter/server_protocol.h +++ b/include/wsfs/adapter/server_protocol.h @@ -4,14 +4,14 @@ #include #include -struct wsfs_server_protocol; -struct lws_protocols; - #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); diff --git a/include/wsfs/status.h b/include/wsfs/core/status.h similarity index 100% rename from include/wsfs/status.h rename to include/wsfs/core/status.h diff --git a/include/wsfs/provider/client.h b/include/wsfs/provider/client.h index d62a855..397b03a 100644 --- a/include/wsfs/provider/client.h +++ b/include/wsfs/provider/client.h @@ -3,25 +3,17 @@ #include "wsfs/provider/api.h" -struct wsfsp_client; -struct wsfsp_client_config; - #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_set_keypath( - struct wsfsp_client * client, - char * key_path); - -extern WSFSP_API void wsfsp_client_set_certpath( - struct wsfsp_client * client, - char * cert_path); - extern WSFSP_API void wsfsp_client_connect( struct wsfsp_client * client, char const * url); @@ -29,10 +21,6 @@ extern WSFSP_API void wsfsp_client_connect( extern WSFSP_API void wsfsp_client_disconnect( struct wsfsp_client * client); -extern WSFSP_API void wsfsp_client_settimeout( - struct wsfsp_client * client, - unsigned int timepoint); - extern WSFSP_API void wsfsp_client_dispose( struct wsfsp_client * client); diff --git a/include/wsfs/provider/client_config.h b/include/wsfs/provider/client_config.h index 875c8dd..2396a3d 100644 --- a/include/wsfs/provider/client_config.h +++ b/include/wsfs/provider/client_config.h @@ -10,22 +10,22 @@ #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); + void * user_data); typedef void wsfsp_ontimer_fn( void * user_data); -#ifdef __cplusplus -extern "C" -{ -#endif - extern WSFSP_API struct wsfsp_client_config * wsfsp_client_config_create(void); extern WSFSP_API void wsfsp_client_config_dispose( diff --git a/include/wsfs/provider/client_protocol.h b/include/wsfs/provider/client_protocol.h index 49410f5..23e1620 100644 --- a/include/wsfs/provider/client_protocol.h +++ b/include/wsfs/provider/client_protocol.h @@ -3,15 +3,15 @@ #include "wsfs/provider/api.h" -struct wsfsp_client_protocol; -struct wsfsp_provider; -struct lws_protocols; - #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); diff --git a/include/wsfs/provider/dirbuffer.h b/include/wsfs/provider/dirbuffer.h index a41e109..0c53157 100644 --- a/include/wsfs/provider/dirbuffer.h +++ b/include/wsfs/provider/dirbuffer.h @@ -7,13 +7,13 @@ #include "wsfs/provider/api.h" -struct wsfsp_dirbuffer; - #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( diff --git a/include/wsfs/provider/operation/close.h b/include/wsfs/provider/operation/close.h index aba4709..63851c7 100644 --- a/include/wsfs/provider/operation/close.h +++ b/include/wsfs/provider/operation/close.h @@ -13,17 +13,17 @@ #include "wsfs/provider/api.h" +#ifdef __cplusplus +extern "C" +{ +#endif + typedef void wsfsp_close_fn( ino_t inode, uint32_t handle, int flags, void * user_data); -#ifdef __cplusplus -extern "C" -{ -#endif - #ifdef __cplusplus } #endif diff --git a/include/wsfs/provider/operation/error.h b/include/wsfs/provider/operation/error.h index be2dd19..077963d 100644 --- a/include/wsfs/provider/operation/error.h +++ b/include/wsfs/provider/operation/error.h @@ -2,15 +2,15 @@ #define WSFSP_OPERATION_ERROR_H #include "wsfs/provider/api.h" -#include "wsfs/status.h" - -struct wsfsp_request; +#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); diff --git a/include/wsfs/provider/operation/getattr.h b/include/wsfs/provider/operation/getattr.h index ee7e9fb..a88b2af 100644 --- a/include/wsfs/provider/operation/getattr.h +++ b/include/wsfs/provider/operation/getattr.h @@ -7,6 +7,11 @@ #include "wsfs/provider/api.h" +#ifdef __cplusplus +extern "C" +{ +#endif + struct wsfsp_request; typedef void wsfsp_getattr_fn( @@ -14,12 +19,6 @@ typedef void wsfsp_getattr_fn( ino_t inode, void * user_data); -#ifdef __cplusplus -extern "C" -{ -#endif - - extern WSFSP_API void wsfsp_respond_getattr( struct wsfsp_request * request, struct stat const * stat); diff --git a/include/wsfs/provider/operation/lookup.h b/include/wsfs/provider/operation/lookup.h index 8e529c7..0cb2875 100644 --- a/include/wsfs/provider/operation/lookup.h +++ b/include/wsfs/provider/operation/lookup.h @@ -7,6 +7,11 @@ #include "wsfs/provider/api.h" +#ifdef __cplusplus +extern "C" +{ +#endif + struct wsfsp_request; typedef void wsfsp_lookup_fn( @@ -15,11 +20,6 @@ typedef void wsfsp_lookup_fn( char const * name, void * user_data); -#ifdef __cplusplus -extern "C" -{ -#endif - extern WSFSP_API void wsfsp_respond_lookup( struct wsfsp_request * request, struct stat const * stat); diff --git a/include/wsfs/provider/operation/open.h b/include/wsfs/provider/operation/open.h index ad471de..3ef7693 100644 --- a/include/wsfs/provider/operation/open.h +++ b/include/wsfs/provider/operation/open.h @@ -13,6 +13,11 @@ #include "wsfs/provider/api.h" +#ifdef __cplusplus +extern "C" +{ +#endif + struct wsfsp_request; typedef void wsfsp_open_fn( @@ -21,11 +26,6 @@ typedef void wsfsp_open_fn( int flags, void * user_data); -#ifdef __cplusplus -extern "C" -{ -#endif - extern WSFSP_API void wsfsp_respond_open( struct wsfsp_request * request, uint32_t handle); diff --git a/include/wsfs/provider/operation/read.h b/include/wsfs/provider/operation/read.h index efe1963..9440977 100644 --- a/include/wsfs/provider/operation/read.h +++ b/include/wsfs/provider/operation/read.h @@ -16,6 +16,11 @@ using std::size_t; #include "wsfs/provider/api.h" +#ifdef __cplusplus +extern "C" +{ +#endif + struct wsfsp_request; typedef void wsfsp_read_fn( @@ -26,11 +31,6 @@ typedef void wsfsp_read_fn( size_t length, void * user_data); -#ifdef __cplusplus -extern "C" -{ -#endif - extern WSFSP_API void wsfsp_respond_read( struct wsfsp_request * request, char const * data, diff --git a/include/wsfs/provider/operation/readdir.h b/include/wsfs/provider/operation/readdir.h index 4dd40da..e887ebf 100644 --- a/include/wsfs/provider/operation/readdir.h +++ b/include/wsfs/provider/operation/readdir.h @@ -7,6 +7,11 @@ #include "wsfs/provider/api.h" +#ifdef __cplusplus +extern "C" +{ +#endif + struct wsfsp_dirbuffer; struct wsfsp_request; @@ -15,12 +20,6 @@ typedef void wsfsp_readdir_fn( ino_t directory, void * user_data); - -#ifdef __cplusplus -extern "C" -{ -#endif - extern WSFSP_API void wsfsp_respond_readdir( struct wsfsp_request * request, struct wsfsp_dirbuffer * dirbuffer); diff --git a/include/wsfs_adapter.h b/include/wsfs_adapter.h index 6900f13..076267f 100644 --- a/include/wsfs_adapter.h +++ b/include/wsfs_adapter.h @@ -1,7 +1,7 @@ #ifndef WSFS_ADAPTER_H #define WSFS_ADAPTER_H -#include +#include #include #include diff --git a/include/wsfs_provider.h b/include/wsfs_provider.h index 63e09fc..1251212 100644 --- a/include/wsfs_provider.h +++ b/include/wsfs_provider.h @@ -1,7 +1,7 @@ #ifndef WSFS_PROVIDER_H #define WSFS_PROVIDER_H -#include +#include #include #include diff --git a/lib/wsfs/adapter/api.c b/lib/wsfs/adapter/api.c new file mode 100644 index 0000000..05121e8 --- /dev/null +++ b/lib/wsfs/adapter/api.c @@ -0,0 +1,141 @@ +#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/authenticator.h b/lib/wsfs/adapter/authenticator.h deleted file mode 100644 index 585cc24..0000000 --- a/lib/wsfs/adapter/authenticator.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef WSFS_ADAPTER_AUTHENTICATOR_H -#define WSFS_ADAPTER_AUTHENTICATOR_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/authenticate.h" - -struct wsfs_authenticator -{ - char * type; - wsfs_authenticate_fn * authenticate; - void * user_data; - struct wsfs_authenticator * next; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern struct wsfs_authenticator * wsfs_authenticator_create( - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data); - -extern void wsfs_authenticator_dispose( - struct wsfs_authenticator * authenticator); - -extern bool wsfs_authenticator_autenticate( - struct wsfs_authenticator * authenticator, - struct wsfs_credentials * credentials); - - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/wsfs/adapter/authenticators.c b/lib/wsfs/adapter/authenticators.c deleted file mode 100644 index 856354d..0000000 --- a/lib/wsfs/adapter/authenticators.c +++ /dev/null @@ -1,101 +0,0 @@ -#include "wsfs/adapter/authenticators.h" -#include -#include - -#include "wsfs/adapter/authenticator.h" -#include "wsfs/adapter/credentials_intern.h" - -static struct wsfs_authenticator * wsfs_authenticators_find( - struct wsfs_authenticators * authenticators, - char const * type) -{ - struct wsfs_authenticator * result = NULL; - - struct wsfs_authenticator * actual = authenticators->first; - while ((NULL == result) && (NULL != actual)) - { - struct wsfs_authenticator * next = actual->next; - if (0 == strcmp(type, actual->type)) - { - result = actual; - } - - actual = next; - } - - return result; -} - -void wsfs_authenticators_init( - struct wsfs_authenticators * authenticators) -{ - authenticators->first = NULL; -} - -void wsfs_authenticators_cleanup( - struct wsfs_authenticators * authenticators) -{ - struct wsfs_authenticator * actual = authenticators->first; - while (NULL != actual) - { - struct wsfs_authenticator * next = actual->next; - wsfs_authenticator_dispose(actual); - actual = next; - } - - authenticators->first = NULL; -} - -void wsfs_authenticators_clone( - struct wsfs_authenticators * authenticators, - struct wsfs_authenticators * other) -{ - wsfs_authenticators_init(other); - - struct wsfs_authenticator * actual = authenticators->first; - while (NULL != actual) - { - struct wsfs_authenticator * next = actual->next; - wsfs_authenticators_add(other, - actual->type, actual->authenticate, actual->user_data); - actual = next; - } - -} - -extern void wsfs_authenticators_move( - struct wsfs_authenticators * authenticators, - struct wsfs_authenticators * other) -{ - other->first = authenticators->first; - authenticators->first = NULL; -} - -void wsfs_authenticators_add( - struct wsfs_authenticators * authenticators, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data) -{ - struct wsfs_authenticator * authenticator = wsfs_authenticator_create(type, authenticate, user_data); - authenticator->next = authenticators->first; - authenticators->first = authenticator; -} - -bool wsfs_authenticators_authenticate( - struct wsfs_authenticators * authenticators, - struct wsfs_credentials * credentials) -{ - bool result = (NULL == authenticators->first); - - if (NULL != credentials) - { - struct wsfs_authenticator * authenticator = wsfs_authenticators_find(authenticators, credentials->type); - if (NULL != authenticator) - { - result = wsfs_authenticator_autenticate(authenticator, credentials); - } - } - - return result; -} \ No newline at end of file diff --git a/lib/wsfs/adapter/authenticators.h b/lib/wsfs/adapter/authenticators.h deleted file mode 100644 index 48b8056..0000000 --- a/lib/wsfs/adapter/authenticators.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef WSFS_ADAPTER_AUTHENTICATORS_H -#define WSFS_ADAPTER_AUTHENTICATORS_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/authenticate.h" - -struct wsfs_authenticator; -struct wsfs_credentials; - -struct wsfs_authenticators -{ - struct wsfs_authenticator * first; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_authenticators_init( - struct wsfs_authenticators * authenticators); - -extern void wsfs_authenticators_cleanup( - struct wsfs_authenticators * authenticators); - -extern void wsfs_authenticators_clone( - struct wsfs_authenticators * authenticators, - struct wsfs_authenticators * other); - -extern void wsfs_authenticators_move( - struct wsfs_authenticators * authenticators, - struct wsfs_authenticators * other); - -extern void wsfs_authenticators_add( - struct wsfs_authenticators * authenticators, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data); - -extern bool wsfs_authenticators_authenticate( - struct wsfs_authenticators * authenticators, - struct wsfs_credentials * credentials); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/credentials_intern.h b/lib/wsfs/adapter/credentials_intern.h deleted file mode 100644 index 026c515..0000000 --- a/lib/wsfs/adapter/credentials_intern.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef WSFS_ADAPTER_CREDENTIALS_INTERN_H -#define WSFS_ADAPTER_CREDENTIALS_INTERN_H - -#include "wsfs/adapter/credentials.h" -#include - -struct wsfs_credentials -{ - char * type; - json_t * data; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_credentials_init( - struct wsfs_credentials * credentials, - char const * type, - json_t * data); - -extern void wsfs_credentials_cleanup( - struct wsfs_credentials * credentials); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/adapter/filesystem.h b/lib/wsfs/adapter/filesystem.h deleted file mode 100644 index a88ac9d..0000000 --- a/lib/wsfs/adapter/filesystem.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef WSFS_ADAPTER_FILESYSTEM_H -#define WSFS_ADAPTER_FILESYSTEM_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/fuse_wrapper.h" -#include "wsfs/adapter/operations.h" - -struct wsfs_jsonrpc_server; - -struct wsfs_filesystem -{ - struct fuse_args args; - struct fuse_session * session; - struct fuse_buf buffer; - struct wsfs_operations_context user_data; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern bool wsfs_filesystem_init( - struct wsfs_filesystem * filesystem, - struct wsfs_jsonrpc_server * rpc, - char * mount_point); - -extern void wsfs_filesystem_cleanup( - struct wsfs_filesystem * filesystem); - -extern int wsfs_filesystem_get_fd( - struct wsfs_filesystem * filesystem); - -extern void wsfs_filesystem_process_request( - struct wsfs_filesystem * filesystem); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/authenticator.c b/lib/wsfs/adapter/impl/authenticator.c similarity index 62% rename from lib/wsfs/adapter/authenticator.c rename to lib/wsfs/adapter/impl/authenticator.c index 04f1c60..a4c8c34 100644 --- a/lib/wsfs/adapter/authenticator.c +++ b/lib/wsfs/adapter/impl/authenticator.c @@ -1,16 +1,16 @@ -#include "wsfs/adapter/authenticator.h" +#include "wsfs/adapter/impl/authenticator.h" #include #include -#include "wsfs/adapter/credentials_intern.h" +#include "wsfs/adapter/impl/credentials.h" -struct wsfs_authenticator * wsfs_authenticator_create( +struct wsfs_impl_authenticator * wsfs_impl_authenticator_create( char const * type, wsfs_authenticate_fn * authenticate, void * user_data) { - struct wsfs_authenticator * authenticator = malloc(sizeof(struct wsfs_authenticator)); + struct wsfs_impl_authenticator * authenticator = malloc(sizeof(struct wsfs_impl_authenticator)); if (NULL != authenticator) { authenticator->type = strdup(type); @@ -22,15 +22,15 @@ struct wsfs_authenticator * wsfs_authenticator_create( return authenticator; } -void wsfs_authenticator_dispose( - struct wsfs_authenticator * authenticator) +void wsfs_impl_authenticator_dispose( + struct wsfs_impl_authenticator * authenticator) { free(authenticator->type); free(authenticator); } -bool wsfs_authenticator_autenticate( - struct wsfs_authenticator * authenticator, +bool wsfs_impl_authenticator_autenticate( + struct wsfs_impl_authenticator * authenticator, struct wsfs_credentials * credentials) { bool result; diff --git a/lib/wsfs/adapter/impl/authenticator.h b/lib/wsfs/adapter/impl/authenticator.h new file mode 100644 index 0000000..da12d62 --- /dev/null +++ b/lib/wsfs/adapter/impl/authenticator.h @@ -0,0 +1,42 @@ +#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 new file mode 100644 index 0000000..7b5808a --- /dev/null +++ b/lib/wsfs/adapter/impl/authenticators.c @@ -0,0 +1,101 @@ +#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 new file mode 100644 index 0000000..0e9ce18 --- /dev/null +++ b/lib/wsfs/adapter/impl/authenticators.h @@ -0,0 +1,51 @@ +#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/credentials.c b/lib/wsfs/adapter/impl/credentials.c similarity index 78% rename from lib/wsfs/adapter/credentials.c rename to lib/wsfs/adapter/impl/credentials.c index fa8b09e..2c4619c 100644 --- a/lib/wsfs/adapter/credentials.c +++ b/lib/wsfs/adapter/impl/credentials.c @@ -1,7 +1,7 @@ -#include "wsfs/adapter/credentials_intern.h" +#include "wsfs/adapter/impl/credentials.h" #include -void wsfs_credentials_init( +void wsfs_impl_credentials_init( struct wsfs_credentials * credentials, char const * type, json_t * data) @@ -11,20 +11,20 @@ void wsfs_credentials_init( json_incref(credentials->data); } -void wsfs_credentials_cleanup( +void wsfs_impl_credentials_cleanup( struct wsfs_credentials * credentials) { free(credentials->type); json_decref(credentials->data); } -char const * wsfs_credentials_type( +char const * wsfs_impl_credentials_type( struct wsfs_credentials const * credentials) { return credentials->type; } -char const * wsfs_credentials_get( +char const * wsfs_impl_credentials_get( struct wsfs_credentials const * credentials, char const * key) { diff --git a/lib/wsfs/adapter/impl/credentials.h b/lib/wsfs/adapter/impl/credentials.h new file mode 100644 index 0000000..368db1c --- /dev/null +++ b/lib/wsfs/adapter/impl/credentials.h @@ -0,0 +1,36 @@ +#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/filesystem.c b/lib/wsfs/adapter/impl/filesystem.c similarity index 57% rename from lib/wsfs/adapter/filesystem.c rename to lib/wsfs/adapter/impl/filesystem.c index db62c99..25f1ba8 100644 --- a/lib/wsfs/adapter/filesystem.c +++ b/lib/wsfs/adapter/impl/filesystem.c @@ -1,25 +1,25 @@ -#include "wsfs/adapter/filesystem.h" -#include "wsfs/adapter/operations.h" -#include "wsfs/adapter/jsonrpc/server.h" +#include "wsfs/adapter/impl/filesystem.h" +#include "wsfs/adapter/impl/operations.h" +#include "wsfs/adapter/impl/jsonrpc/server.h" #include #include #include -static struct fuse_lowlevel_ops const wsfs_filesystem_operations = +static struct fuse_lowlevel_ops const filesystem_operations = { - .lookup = &wsfs_operation_lookup, - .getattr = &wsfs_operation_getattr, - .readdir = &wsfs_operation_readdir, - .open = &wsfs_operation_open, - .release = &wsfs_operation_close, - .read = &wsfs_operation_read + .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 }; -bool wsfs_filesystem_init( - struct wsfs_filesystem * filesystem, - struct wsfs_jsonrpc_server * rpc, +bool wsfs_impl_filesystem_init( + struct wsfs_impl_filesystem * filesystem, + struct wsfs_impl_jsonrpc_server * rpc, char * mount_point) { bool result = false; @@ -35,8 +35,8 @@ bool wsfs_filesystem_init( filesystem->session = fuse_session_new( &filesystem->args, - &wsfs_filesystem_operations, - sizeof(wsfs_filesystem_operations), + &filesystem_operations, + sizeof(filesystem_operations), &filesystem->user_data); if (NULL != filesystem->session) { @@ -46,8 +46,8 @@ bool wsfs_filesystem_init( return result; } -void wsfs_filesystem_cleanup( - struct wsfs_filesystem * filesystem) +void wsfs_impl_filesystem_cleanup( + struct wsfs_impl_filesystem * filesystem) { if (NULL != filesystem->session) { @@ -61,14 +61,14 @@ void wsfs_filesystem_cleanup( fuse_opt_free_args(&filesystem->args); } -int wsfs_filesystem_get_fd( - struct wsfs_filesystem * filesystem) +int wsfs_impl_filesystem_get_fd( + struct wsfs_impl_filesystem * filesystem) { return fuse_session_fd(filesystem->session); } -void wsfs_filesystem_process_request( - struct wsfs_filesystem * filesystem) +void wsfs_impl_filesystem_process_request( + struct wsfs_impl_filesystem * filesystem) { int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer); if (0 < result) diff --git a/lib/wsfs/adapter/impl/filesystem.h b/lib/wsfs/adapter/impl/filesystem.h new file mode 100644 index 0000000..5b65876 --- /dev/null +++ b/lib/wsfs/adapter/impl/filesystem.h @@ -0,0 +1,45 @@ +#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/fuse_wrapper.h b/lib/wsfs/adapter/impl/fuse_wrapper.h similarity index 67% rename from lib/wsfs/adapter/fuse_wrapper.h rename to lib/wsfs/adapter/impl/fuse_wrapper.h index 2f8d72b..0cba5c2 100644 --- a/lib/wsfs/adapter/fuse_wrapper.h +++ b/lib/wsfs/adapter/impl/fuse_wrapper.h @@ -1,5 +1,5 @@ -#ifndef WSFS_ADAPTER_FUSE_H -#define WSFS_ADAPTER_FUSE_H +#ifndef WSFS_ADAPTER_IMPL_FUSE_H +#define WSFS_ADAPTER_IMPL_FUSE_H #ifdef __cplusplus extern "C" { diff --git a/lib/wsfs/adapter/impl/jsonrpc/method.c b/lib/wsfs/adapter/impl/jsonrpc/method.c new file mode 100644 index 0000000..8bf3eda --- /dev/null +++ b/lib/wsfs/adapter/impl/jsonrpc/method.c @@ -0,0 +1,28 @@ +#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.h b/lib/wsfs/adapter/impl/jsonrpc/method.h new file mode 100644 index 0000000..fe3db02 --- /dev/null +++ b/lib/wsfs/adapter/impl/jsonrpc/method.h @@ -0,0 +1,31 @@ +#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H +#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H + +#ifndef __cplusplus +#include +#endif + +#include +#include "wsfs/core/status.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef bool wsfs_impl_jsonrpc_method_invoke_fn( + void * user_data, + struct json_t const * method_call); + +typedef void wsfs_impl_jsonrpc_method_finished_fn( + void * user_data, + wsfs_status status, + struct json_t const * result); + +#ifdef __cplusplus +} +#endif + + + +#endif diff --git a/lib/wsfs/adapter/impl/jsonrpc/method_intern.h b/lib/wsfs/adapter/impl/jsonrpc/method_intern.h new file mode 100644 index 0000000..04edb70 --- /dev/null +++ b/lib/wsfs/adapter/impl/jsonrpc/method_intern.h @@ -0,0 +1,31 @@ +#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/jsonrpc/request.c b/lib/wsfs/adapter/impl/jsonrpc/request.c similarity index 90% rename from lib/wsfs/adapter/jsonrpc/request.c rename to lib/wsfs/adapter/impl/jsonrpc/request.c index 04c3605..4894d41 100644 --- a/lib/wsfs/adapter/jsonrpc/request.c +++ b/lib/wsfs/adapter/impl/jsonrpc/request.c @@ -1,6 +1,6 @@ -#include "wsfs/adapter/jsonrpc/request.h" +#include "wsfs/adapter/impl/jsonrpc/request.h" -json_t * wsfs_jsonrpc_request_create( +json_t * wsfs_impl_jsonrpc_request_create( char const * method, int id, char const * param_info, diff --git a/lib/wsfs/adapter/jsonrpc/request.h b/lib/wsfs/adapter/impl/jsonrpc/request.h similarity index 70% rename from lib/wsfs/adapter/jsonrpc/request.h rename to lib/wsfs/adapter/impl/jsonrpc/request.h index 9f28c48..69a888d 100644 --- a/lib/wsfs/adapter/jsonrpc/request.h +++ b/lib/wsfs/adapter/impl/jsonrpc/request.h @@ -1,5 +1,5 @@ -#ifndef WSFS_ADAPTER_JSONRPC_REQUEST_H -#define WSFS_ADAPTER_JSONRPC_REQUEST_H +#ifndef WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H +#define WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H #ifndef __cplusplus #include @@ -18,7 +18,7 @@ extern "C" { #endif -extern json_t * wsfs_jsonrpc_request_create( +extern json_t * wsfs_impl_jsonrpc_request_create( char const * method, int id, char const * param_info, diff --git a/lib/wsfs/adapter/jsonrpc/response.c b/lib/wsfs/adapter/impl/jsonrpc/response.c similarity index 83% rename from lib/wsfs/adapter/jsonrpc/response.c rename to lib/wsfs/adapter/impl/jsonrpc/response.c index 95fe840..f0969d9 100644 --- a/lib/wsfs/adapter/jsonrpc/response.c +++ b/lib/wsfs/adapter/impl/jsonrpc/response.c @@ -1,7 +1,7 @@ -#include "wsfs/adapter/jsonrpc/response.h" +#include "wsfs/adapter/impl/jsonrpc/response.h" -void wsfs_jsonrpc_response_init( - struct wsfs_jsonrpc_response * result, +void wsfs_impl_jsonrpc_response_init( + struct wsfs_impl_jsonrpc_response * result, char const * buffer, size_t length) { @@ -49,8 +49,8 @@ void wsfs_jsonrpc_response_init( json_decref(response); } -void wsfs_jsonrpc_response_cleanup( - struct wsfs_jsonrpc_response * response) +void wsfs_impl_jsonrpc_response_cleanup( + struct wsfs_impl_jsonrpc_response * response) { if (NULL != response->result) { diff --git a/lib/wsfs/adapter/impl/jsonrpc/response.h b/lib/wsfs/adapter/impl/jsonrpc/response.h new file mode 100644 index 0000000..65518dd --- /dev/null +++ b/lib/wsfs/adapter/impl/jsonrpc/response.h @@ -0,0 +1,38 @@ +#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/jsonrpc/server.c b/lib/wsfs/adapter/impl/jsonrpc/server.c similarity index 51% rename from lib/wsfs/adapter/jsonrpc/server.c rename to lib/wsfs/adapter/impl/jsonrpc/server.c index 047effa..ddd171f 100644 --- a/lib/wsfs/adapter/jsonrpc/server.c +++ b/lib/wsfs/adapter/impl/jsonrpc/server.c @@ -1,17 +1,17 @@ -#include "wsfs/adapter/jsonrpc/server.h" +#include "wsfs/adapter/impl/jsonrpc/server.h" #include -#include "wsfs/adapter/jsonrpc/method_intern.h" -#include "wsfs/adapter/jsonrpc/request.h" -#include "wsfs/adapter/jsonrpc/response.h" +#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_jsonrpc_method const * wsfs_jsonrpc_server_getmethod( - struct wsfs_jsonrpc_server * server, +static struct wsfs_impl_jsonrpc_method const * wsfs_impl_jsonrpc_server_getmethod( + struct wsfs_impl_jsonrpc_server * server, char const * name) { - struct wsfs_jsonrpc_method * method = server->methods; + struct wsfs_impl_jsonrpc_method * method = server->methods; while ((NULL != method) && (0 == strcmp(name, method->name))) { method = method->next; @@ -20,40 +20,40 @@ static struct wsfs_jsonrpc_method const * wsfs_jsonrpc_server_getmethod( return method; } -static void wsfs_jsonrpc_server_timeout( - struct wsfs_timer * timer) +static void wsfs_impl_jsonrpc_server_timeout( + struct wsfs_impl_timer * timer) { - struct wsfs_jsonrpc_server * server = timer->user_data; + struct wsfs_impl_jsonrpc_server * server = timer->user_data; if (server->request.is_pending) { - wsfs_jsonrpc_method_finished_fn * finished = server->request.finished; + 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_timer_cancel(&server->request.timer); + wsfs_impl_timer_cancel(&server->request.timer); finished(user_data, WSFS_BAD_TIMEOUT, NULL); } } -void wsfs_jsonrpc_server_init( - struct wsfs_jsonrpc_server * server, - struct wsfs_timeout_manager * timeout_manager) +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_timer_init(&server->request.timer, timeout_manager); + wsfs_impl_timer_init(&server->request.timer, timeout_manager); } -void wsfs_jsonrpc_server_cleanup( - struct wsfs_jsonrpc_server * server) +void wsfs_impl_jsonrpc_server_cleanup( + struct wsfs_impl_jsonrpc_server * server) { - wsfs_timer_cleanup(&server->request.timer); + wsfs_impl_timer_cleanup(&server->request.timer); if (server->request.is_pending) { @@ -61,31 +61,31 @@ void wsfs_jsonrpc_server_cleanup( server->request.is_pending = false; } - struct wsfs_jsonrpc_method * method = server->methods; + struct wsfs_impl_jsonrpc_method * method = server->methods; while (NULL != method) { - struct wsfs_jsonrpc_method * next = method->next; + struct wsfs_impl_jsonrpc_method * next = method->next; method->next = NULL; - wsfs_jsonrpc_method_dispose(method); + wsfs_impl_jsonrpc_method_dispose(method); method = next; } server->methods = NULL; } -void wsfs_jsonrpc_server_add( - struct wsfs_jsonrpc_server * server, +void wsfs_impl_jsonrpc_server_add( + struct wsfs_impl_jsonrpc_server * server, char const * name, - wsfs_jsonrpc_method_invoke_fn * invoke, + wsfs_impl_jsonrpc_method_invoke_fn * invoke, void * user_data) { - struct wsfs_jsonrpc_method * method = wsfs_jsonrpc_method_create(name, invoke, 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_jsonrpc_server_invoke( - struct wsfs_jsonrpc_server * server, - wsfs_jsonrpc_method_finished_fn * finished, +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, @@ -94,19 +94,19 @@ void wsfs_jsonrpc_server_invoke( { if (!server->request.is_pending) { - struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name); + 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_timer_start(&server->request.timer, wsfs_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT), - &wsfs_jsonrpc_server_timeout, server); + 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_jsonrpc_request_create(method_name, server->request.id, param_info, args); + json_t * request = wsfs_impl_jsonrpc_request_create(method_name, server->request.id, param_info, args); va_end(args); if (NULL != request) { @@ -116,7 +116,7 @@ void wsfs_jsonrpc_server_invoke( server->request.finished = NULL; server->request.user_data = NULL; server->request.id = 0; - wsfs_timer_cancel(&server->request.timer); + wsfs_impl_timer_cancel(&server->request.timer); finished(user_data, WSFS_BAD, NULL); } @@ -134,20 +134,20 @@ void wsfs_jsonrpc_server_invoke( } } -extern void wsfs_jsonrpc_server_notify( - struct wsfs_jsonrpc_server * server, +extern void wsfs_impl_jsonrpc_server_notify( + struct wsfs_impl_jsonrpc_server * server, char const * method_name, char const * param_info, ... ) { - struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name); + 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_jsonrpc_request_create(method_name, 0, param_info, args); + json_t * request = wsfs_impl_jsonrpc_request_create(method_name, 0, param_info, args); va_end(args); if (NULL != request) { @@ -159,28 +159,28 @@ extern void wsfs_jsonrpc_server_notify( } -void wsfs_jsonrpc_server_onresult( - struct wsfs_jsonrpc_server * server, +void wsfs_impl_jsonrpc_server_onresult( + struct wsfs_impl_jsonrpc_server * server, char const * message, size_t length) { - struct wsfs_jsonrpc_response response; - wsfs_jsonrpc_response_init(&response, message, 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_jsonrpc_method_finished_fn * finished = server->request.finished; + 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_timer_cancel(&server->request.timer); + wsfs_impl_timer_cancel(&server->request.timer); finished(user_data, response.status, response.result); } - wsfs_jsonrpc_response_cleanup(&response); + wsfs_impl_jsonrpc_response_cleanup(&response); } diff --git a/lib/wsfs/adapter/impl/jsonrpc/server.h b/lib/wsfs/adapter/impl/jsonrpc/server.h new file mode 100644 index 0000000..140e6f5 --- /dev/null +++ b/lib/wsfs/adapter/impl/jsonrpc/server.h @@ -0,0 +1,77 @@ +#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/jsonrpc/util.c b/lib/wsfs/adapter/impl/jsonrpc/util.c similarity index 60% rename from lib/wsfs/adapter/jsonrpc/util.c rename to lib/wsfs/adapter/impl/jsonrpc/util.c index c43b430..fa00633 100644 --- a/lib/wsfs/adapter/jsonrpc/util.c +++ b/lib/wsfs/adapter/impl/jsonrpc/util.c @@ -1,6 +1,6 @@ -#include "wsfs/adapter/jsonrpc/util.h" +#include "wsfs/adapter/impl/jsonrpc/util.h" -int wsfs_json_get_int(json_t const * object, char const * key, int default_value) +int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value) { int result = default_value; diff --git a/lib/wsfs/adapter/impl/jsonrpc/util.h b/lib/wsfs/adapter/impl/jsonrpc/util.h new file mode 100644 index 0000000..ae49ee2 --- /dev/null +++ b/lib/wsfs/adapter/impl/jsonrpc/util.h @@ -0,0 +1,17 @@ +#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 new file mode 100644 index 0000000..b50bbcd --- /dev/null +++ b/lib/wsfs/adapter/impl/operation/close.c @@ -0,0 +1,21 @@ +#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/operation/getattr.c b/lib/wsfs/adapter/impl/operation/getattr.c similarity index 61% rename from lib/wsfs/adapter/operation/getattr.c rename to lib/wsfs/adapter/impl/operation/getattr.c index a11f225..a8c6b47 100644 --- a/lib/wsfs/adapter/operation/getattr.c +++ b/lib/wsfs/adapter/impl/operation/getattr.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/operations.h" +#include "wsfs/adapter/impl/operations.h" #include #include @@ -7,11 +7,11 @@ #include #include -#include "wsfs/adapter/jsonrpc/server.h" -#include "wsfs/adapter/jsonrpc/util.h" -#include "wsfs/util.h" +#include "wsfs/adapter/impl/jsonrpc/server.h" +#include "wsfs/adapter/impl/jsonrpc/util.h" +#include "wsfs/core/util.h" -struct wsfs_operation_getattr_context +struct wsfs_impl_operation_getattr_context { fuse_req_t request; double timeout; @@ -19,12 +19,12 @@ struct wsfs_operation_getattr_context gid_t gid; }; -static void wsfs_operation_getattr_finished( +static void wsfs_impl_operation_getattr_finished( void * user_data, wsfs_status status, json_t const * data) { - struct wsfs_operation_getattr_context * context = user_data; + struct wsfs_impl_operation_getattr_context * context = user_data; struct stat buffer; if (NULL != data) @@ -50,10 +50,10 @@ static void wsfs_operation_getattr_finished( buffer.st_uid = context->uid; buffer.st_gid = context->gid; buffer.st_nlink = 1; - buffer.st_size = wsfs_json_get_int(data, "size", 0); - buffer.st_atime = wsfs_json_get_int(data, "atime", 0); - buffer.st_mtime = wsfs_json_get_int(data, "mtime", 0); - buffer.st_ctime = wsfs_json_get_int(data, "ctime", 0); + 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); } else @@ -74,20 +74,20 @@ static void wsfs_operation_getattr_finished( free(context); } -void wsfs_operation_getattr ( +void wsfs_impl_operation_getattr ( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info * WSFS_UNUSED_PARAM(file_info)) { struct fuse_ctx const * context = fuse_req_ctx(request); - struct wsfs_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_jsonrpc_server * rpc = user_data->rpc; + struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); + struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; - struct wsfs_operation_getattr_context * getattr_context = malloc(sizeof(struct wsfs_operation_getattr_context)); + struct wsfs_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wsfs_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_jsonrpc_server_invoke(rpc, &wsfs_operation_getattr_finished, getattr_context, "getattr", "i", inode); + wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_getattr_finished, getattr_context, "getattr", "i", inode); } diff --git a/lib/wsfs/adapter/operation/lookup.c b/lib/wsfs/adapter/impl/operation/lookup.c similarity index 64% rename from lib/wsfs/adapter/operation/lookup.c rename to lib/wsfs/adapter/impl/operation/lookup.c index 2d70ea8..c1e06d9 100644 --- a/lib/wsfs/adapter/operation/lookup.c +++ b/lib/wsfs/adapter/impl/operation/lookup.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/operations.h" +#include "wsfs/adapter/impl/operations.h" #include #include @@ -10,11 +10,11 @@ #include -#include "wsfs/adapter/jsonrpc/server.h" -#include "wsfs/adapter/jsonrpc/util.h" -#include "wsfs/util.h" +#include "wsfs/adapter/impl/jsonrpc/server.h" +#include "wsfs/adapter/impl/jsonrpc/util.h" +#include "wsfs/core/util.h" -struct wsfs_operation_lookup_context +struct wsfs_impl_operation_lookup_context { fuse_req_t request; double timeout; @@ -22,13 +22,13 @@ struct wsfs_operation_lookup_context gid_t gid; }; -static void wsfs_operation_lookup_finished( +static void wsfs_impl_operation_lookup_finished( void * user_data, wsfs_status status, json_t const * data ) { - struct wsfs_operation_lookup_context * context = user_data; + struct wsfs_impl_operation_lookup_context * context = user_data; struct fuse_entry_param buffer; if (NULL != data) @@ -60,10 +60,10 @@ static void wsfs_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_json_get_int(data, "size", 0); - buffer.attr.st_atime = wsfs_json_get_int(data, "atime", 0); - buffer.attr.st_mtime = wsfs_json_get_int(data, "mtime", 0); - buffer.attr.st_ctime = wsfs_json_get_int(data, "ctime", 0); + 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); } else { @@ -83,21 +83,20 @@ static void wsfs_operation_lookup_finished( free(context); } -void wsfs_operation_lookup ( +void wsfs_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_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_jsonrpc_server * rpc = user_data->rpc; + struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); + struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; - struct wsfs_operation_lookup_context * lookup_context = malloc(sizeof(struct wsfs_operation_lookup_context)); + struct wsfs_impl_operation_lookup_context * lookup_context = malloc(sizeof(struct wsfs_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_jsonrpc_server_invoke(rpc, &wsfs_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name); - + wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name); } diff --git a/lib/wsfs/adapter/operation/open.c b/lib/wsfs/adapter/impl/operation/open.c similarity index 61% rename from lib/wsfs/adapter/operation/open.c rename to lib/wsfs/adapter/impl/operation/open.c index 27efc0c..63c8e91 100644 --- a/lib/wsfs/adapter/operation/open.c +++ b/lib/wsfs/adapter/impl/operation/open.c @@ -1,14 +1,14 @@ -#include "wsfs/adapter/operations.h" +#include "wsfs/adapter/impl/operations.h" #include #include #include -#include "wsfs/adapter/jsonrpc/server.h" -#include "wsfs/util.h" -#include "wsfs/status.h" +#include "wsfs/adapter/impl/jsonrpc/server.h" +#include "wsfs/core/util.h" +#include "wsfs/core/status.h" -static void wsfs_operation_open_finished( +static void wsfs_impl_operation_open_finished( void * user_data, wsfs_status status, json_t const * result) @@ -41,13 +41,13 @@ static void wsfs_operation_open_finished( } -void wsfs_operation_open( +void wsfs_impl_operation_open( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info * file_info) { - struct wsfs_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_jsonrpc_server * rpc = user_data->rpc; + struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); + struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; - wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_open_finished, request, "open", "ii", inode, file_info->flags); + wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags); } diff --git a/lib/wsfs/adapter/operation/read.c b/lib/wsfs/adapter/impl/operation/read.c similarity index 72% rename from lib/wsfs/adapter/operation/read.c rename to lib/wsfs/adapter/impl/operation/read.c index 6104c4b..d92bf40 100644 --- a/lib/wsfs/adapter/operation/read.c +++ b/lib/wsfs/adapter/impl/operation/read.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/operations.h" +#include "wsfs/adapter/impl/operations.h" #include #include @@ -6,11 +6,11 @@ #include #include -#include "wsfs/adapter/jsonrpc/server.h" +#include "wsfs/adapter/impl/jsonrpc/server.h" #define WSFS_MAX_READ_LENGTH 4096 -static char * wsfs_fill_buffer( +static char * wsfs_impl_fill_buffer( char const * data, char const * format, size_t count, @@ -38,7 +38,7 @@ static char * wsfs_fill_buffer( return buffer; } -static void wsfs_operation_read_finished(void * user_data, wsfs_status status, json_t const * data) +static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status status, json_t const * data) { fuse_req_t request = user_data; @@ -58,7 +58,7 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j char const * const format = json_string_value(format_holder); length = (size_t) json_integer_value(count_holder); - buffer = wsfs_fill_buffer(data, format, length, &status); + buffer = wsfs_impl_fill_buffer(data, format, length, &status); } else { @@ -79,17 +79,17 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j } -void wsfs_operation_read( +void wsfs_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_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_jsonrpc_server * rpc = user_data->rpc; + struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request); + struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc; int const length = (size <= WSFS_MAX_READ_LENGTH) ? (int) size : WSFS_MAX_READ_LENGTH; int handle = (file_info->fh & INT_MAX); - wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length); + wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length); } diff --git a/lib/wsfs/adapter/operation/readdir.c b/lib/wsfs/adapter/impl/operation/readdir.c similarity index 65% rename from lib/wsfs/adapter/operation/readdir.c rename to lib/wsfs/adapter/impl/operation/readdir.c index 2d9831f..16c6640 100644 --- a/lib/wsfs/adapter/operation/readdir.c +++ b/lib/wsfs/adapter/impl/operation/readdir.c @@ -1,4 +1,4 @@ -#include "wsfs/adapter/operations.h" +#include "wsfs/adapter/impl/operations.h" #include #include @@ -8,43 +8,43 @@ #include #include -#include "wsfs/adapter/jsonrpc/server.h" -#include "wsfs/util.h" +#include "wsfs/adapter/impl/jsonrpc/server.h" +#include "wsfs/core/util.h" #define WSFS_DIRBUFFER_INITIAL_SIZE 1024 -struct wsfs_operation_readdir_context +struct wsfs_impl_operation_readdir_context { fuse_req_t request; size_t size; off_t offset; }; -struct wsfs_dirbuffer +struct wsfs_impl_dirbuffer { char * data; size_t position; size_t capacity; }; -static void wsfs_dirbuffer_init( - struct wsfs_dirbuffer * buffer) +static void wsfs_impl_dirbuffer_init( + struct wsfs_impl_dirbuffer * buffer) { buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE); buffer->position = 0; buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE; } -static void wsfs_dirbuffer_dispose( - struct wsfs_dirbuffer * buffer) +static void wsfs_impl_dirbuffer_dispose( + struct wsfs_impl_dirbuffer * buffer) { free(buffer->data); } -static void wsfs_dirbuffer_add( +static void wsfs_impl_dirbuffer_add( fuse_req_t request, - struct wsfs_dirbuffer * buffer, + struct wsfs_impl_dirbuffer * buffer, char const * name, fuse_ino_t inode) { @@ -66,20 +66,20 @@ static void wsfs_dirbuffer_add( buffer->position += size; } -static size_t min(size_t a, size_t b) +static size_t wsfs_impl_min(size_t a, size_t b) { return (a < b) ? a : b; } -static void wsfs_operation_readdir_finished( +static void wsfs_impl_operation_readdir_finished( void * user_data, wsfs_status status, json_t const * result) { - struct wsfs_operation_readdir_context * context = user_data; + struct wsfs_impl_operation_readdir_context * context = user_data; - struct wsfs_dirbuffer buffer; - wsfs_dirbuffer_init(&buffer); + struct wsfs_impl_dirbuffer buffer; + wsfs_impl_dirbuffer_init(&buffer); if (NULL != result) { @@ -100,7 +100,7 @@ static void wsfs_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_dirbuffer_add(context->request, &buffer, name, entry_inode); + wsfs_impl_dirbuffer_add(context->request, &buffer, name, entry_inode); } } } @@ -112,7 +112,7 @@ static void wsfs_operation_readdir_finished( if (((size_t) context->offset) < buffer.position) { fuse_reply_buf(context->request, &buffer.data[context->offset], - min(buffer.position - context->offset, context->size)); + wsfs_impl_min(buffer.position - context->offset, context->size)); } else { @@ -125,23 +125,23 @@ static void wsfs_operation_readdir_finished( fuse_reply_err(context->request, ENOENT); } - wsfs_dirbuffer_dispose(&buffer); + wsfs_impl_dirbuffer_dispose(&buffer); free(context); } -void wsfs_operation_readdir ( +void wsfs_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 wsfs_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_jsonrpc_server * rpc = user_data->rpc; - struct wsfs_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_operation_readdir_context)); + 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)); readdir_context->request = request; readdir_context->size = size; readdir_context->offset = offset; - wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_readdir_finished, readdir_context, "readdir", "i", inode); + wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode); } diff --git a/lib/wsfs/adapter/operations.h b/lib/wsfs/adapter/impl/operations.h similarity index 56% rename from lib/wsfs/adapter/operations.h rename to lib/wsfs/adapter/impl/operations.h index ae82ce7..b2eef91 100644 --- a/lib/wsfs/adapter/operations.h +++ b/lib/wsfs/adapter/impl/operations.h @@ -1,48 +1,48 @@ -#ifndef WSFS_ADAPTER_OPERATIONS -#define WSFS_ADAPTER_OPERATIONS +#ifndef WSFS_ADAPTER_IMPL_OPERATIONS_H +#define WSFS_ADAPTER_IMPL_OPERATIONS_H -#include "wsfs/adapter/fuse_wrapper.h" - -struct wsfs_jsonrpc_server; - -struct wsfs_operations_context -{ - struct wsfs_jsonrpc_server * rpc; - double timeout; -}; +#include "wsfs/adapter/impl/fuse_wrapper.h" #ifdef __cplusplus extern "C" { #endif -extern void wsfs_operation_lookup ( +struct wsfs_impl_jsonrpc_server; + +struct wsfs_impl_operations_context +{ + struct wsfs_impl_jsonrpc_server * rpc; + double timeout; +}; + +extern void wsfs_impl_operation_lookup ( fuse_req_t req, fuse_ino_t parent, char const * name); -extern void wsfs_operation_getattr ( +extern void wsfs_impl_operation_getattr ( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info *file_info); -extern void wsfs_operation_readdir ( +extern void wsfs_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_operation_open( +extern void wsfs_impl_operation_open( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info * file_info); -extern void wsfs_operation_close( +extern void wsfs_impl_operation_close( fuse_req_t request, fuse_ino_t inode, struct fuse_file_info * file_info); -extern void wsfs_operation_read( +extern void wsfs_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/server.c b/lib/wsfs/adapter/impl/server.c similarity index 76% rename from lib/wsfs/adapter/server.c rename to lib/wsfs/adapter/impl/server.c index 0ca0c74..3777bbc 100644 --- a/lib/wsfs/adapter/server.c +++ b/lib/wsfs/adapter/impl/server.c @@ -8,8 +8,8 @@ #include #include -#include "wsfs/adapter/server_config_intern.h" -#include "wsfs/adapter/server_protocol_intern.h" +#include "wsfs/adapter/impl/server_config.h" +#include "wsfs/adapter/impl/server_protocol.h" #define WSFS_DISABLE_LWS_LOG 0 #define WSFS_SERVER_PROTOCOL_COUNT 3 @@ -26,13 +26,13 @@ struct wsfs_server struct lws_context_creation_info info; }; -static bool wsfs_server_tls_enabled( +static bool wsfs_impl_server_tls_enabled( struct wsfs_server * server) { return ((server->config.key_path != NULL) && (server->config.cert_path != NULL)); } -static struct lws_context * wsfs_server_context_create( +static struct lws_context * wsfs_impl_server_context_create( struct wsfs_server * server) { lws_set_log_level(WSFS_DISABLE_LWS_LOG, NULL); @@ -41,7 +41,7 @@ static struct lws_context * wsfs_server_context_create( server->ws_protocols[0].name = "http"; server->ws_protocols[0].callback = lws_callback_http_dummy; server->ws_protocols[1].name = "fs"; - wsfs_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]); + wsfs_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_server_context_create( server->info.mounts = NULL; } - if (wsfs_server_tls_enabled(server)) + if (wsfs_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,7 +78,7 @@ static struct lws_context * wsfs_server_context_create( } -static bool wsfs_server_check_mountpoint( +static bool wsfs_impl_server_check_mountpoint( struct wsfs_server_config * config) { bool result = false; @@ -98,22 +98,22 @@ static bool wsfs_server_check_mountpoint( return result; } -struct wsfs_server * wsfs_server_create( +struct wsfs_server * wsfs_impl_server_create( struct wsfs_server_config * config) { struct wsfs_server * server = NULL; - if (wsfs_server_check_mountpoint(config)) + if (wsfs_impl_server_check_mountpoint(config)) { server = malloc(sizeof(struct wsfs_server)); if (NULL != server) { - if (wsfs_server_protocol_init(&server->protocol, config->mount_point)) + if (wsfs_impl_server_protocol_init(&server->protocol, config->mount_point)) { server->shutdown_requested = false; - wsfs_server_config_clone(config, &server->config); - wsfs_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); - server->context = wsfs_server_context_create(server); + 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); } else { @@ -126,16 +126,16 @@ struct wsfs_server * wsfs_server_create( return server; } -void wsfs_server_dispose( +void wsfs_impl_server_dispose( struct wsfs_server * server) { lws_context_destroy(server->context); - wsfs_server_protocol_cleanup(&server->protocol); - wsfs_server_config_cleanup(&server->config); + wsfs_impl_server_protocol_cleanup(&server->protocol); + wsfs_impl_server_config_cleanup(&server->config); free(server); } -void wsfs_server_run( +void wsfs_impl_server_run( struct wsfs_server * server) { int n = 0; @@ -145,7 +145,7 @@ void wsfs_server_run( } } -void wsfs_server_shutdown( +void wsfs_impl_server_shutdown( struct wsfs_server * server) { server->shutdown_requested = true; diff --git a/lib/wsfs/adapter/impl/server.h b/lib/wsfs/adapter/impl/server.h new file mode 100644 index 0000000..ed5e290 --- /dev/null +++ b/lib/wsfs/adapter/impl/server.h @@ -0,0 +1,29 @@ +#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/server_config.c b/lib/wsfs/adapter/impl/server_config.c similarity index 54% rename from lib/wsfs/adapter/server_config.c rename to lib/wsfs/adapter/impl/server_config.c index 3eee3db..ab45145 100644 --- a/lib/wsfs/adapter/server_config.c +++ b/lib/wsfs/adapter/impl/server_config.c @@ -1,9 +1,9 @@ -#include "wsfs/adapter/server_config_intern.h" +#include "wsfs/adapter/impl/server_config.h" #include #include -static char * wsfs_server_config_strdup(char const * value) +static char * wsfs_impl_server_config_strdup(char const * value) { char * result = NULL; if (NULL != value) @@ -14,18 +14,18 @@ static char * wsfs_server_config_strdup(char const * value) return result; } -void wsfs_server_config_init( +void wsfs_impl_server_config_init( struct wsfs_server_config * config) { memset(config, 0, sizeof(struct wsfs_server_config)); - wsfs_authenticators_init(&config->authenticators); + wsfs_impl_authenticators_init(&config->authenticators); } -void wsfs_server_config_cleanup( +void wsfs_impl_server_config_cleanup( struct wsfs_server_config * config) { - wsfs_authenticators_cleanup(&config->authenticators); + wsfs_impl_authenticators_cleanup(&config->authenticators); free(config->mount_point); free(config->document_root); @@ -33,42 +33,42 @@ void wsfs_server_config_cleanup( free(config->cert_path); free(config->vhost_name); - wsfs_server_config_init(config); + wsfs_impl_server_config_init(config); } -void wsfs_server_config_clone( +void wsfs_impl_server_config_clone( struct wsfs_server_config * config, struct wsfs_server_config * clone) { - clone->mount_point = wsfs_server_config_strdup(config->mount_point); - clone->document_root = wsfs_server_config_strdup(config->document_root); - clone->key_path = wsfs_server_config_strdup(config->key_path); - clone->cert_path = wsfs_server_config_strdup(config->cert_path); - clone->vhost_name = wsfs_server_config_strdup(config->vhost_name); + 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_authenticators_clone(&config->authenticators, &clone->authenticators); + wsfs_impl_authenticators_clone(&config->authenticators, &clone->authenticators); } -struct wsfs_server_config * wsfs_server_config_create(void) +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_server_config_init(config); + wsfs_impl_server_config_init(config); } return config; } -void wsfs_server_config_dispose( +void wsfs_impl_server_config_dispose( struct wsfs_server_config * config) { - wsfs_server_config_cleanup(config); + wsfs_impl_server_config_cleanup(config); free(config); } -void wsfs_server_config_set_mountpoint( +void wsfs_impl_server_config_set_mountpoint( struct wsfs_server_config * config, char const * mount_point) { @@ -76,7 +76,7 @@ void wsfs_server_config_set_mountpoint( config->mount_point = strdup(mount_point); } -void wsfs_server_config_set_documentroot( +void wsfs_impl_server_config_set_documentroot( struct wsfs_server_config * config, char const * document_root) { @@ -84,7 +84,7 @@ void wsfs_server_config_set_documentroot( config->document_root = strdup(document_root); } -void wsfs_server_config_set_keypath( +void wsfs_impl_server_config_set_keypath( struct wsfs_server_config * config, char const * key_path) { @@ -92,7 +92,7 @@ void wsfs_server_config_set_keypath( config->key_path = strdup(key_path); } -void wsfs_server_config_set_certpath( +void wsfs_impl_server_config_set_certpath( struct wsfs_server_config * config, char const * cert_path) { @@ -100,7 +100,7 @@ void wsfs_server_config_set_certpath( config->cert_path = strdup(cert_path); } -void wsfs_server_config_set_vhostname( +void wsfs_impl_server_config_set_vhostname( struct wsfs_server_config * config, char const * vhost_name) { @@ -108,20 +108,20 @@ void wsfs_server_config_set_vhostname( config->vhost_name = strdup(vhost_name); } -void wsfs_server_config_set_port( +void wsfs_impl_server_config_set_port( struct wsfs_server_config * config, int port) { config->port = port; } -void wsfs_server_config_add_authenticator( +void wsfs_impl_server_config_add_authenticator( struct wsfs_server_config * config, char const * type, wsfs_authenticate_fn * authenticate, void * user_data ) { - wsfs_authenticators_add(&config->authenticators, type, authenticate, 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 new file mode 100644 index 0000000..a0f1a65 --- /dev/null +++ b/lib/wsfs/adapter/impl/server_config.h @@ -0,0 +1,72 @@ +#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 new file mode 100644 index 0000000..60e69a6 --- /dev/null +++ b/lib/wsfs/adapter/impl/server_protocol.c @@ -0,0 +1,166 @@ +#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 new file mode 100644 index 0000000..fee9ae6 --- /dev/null +++ b/lib/wsfs/adapter/impl/server_protocol.h @@ -0,0 +1,53 @@ +#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/session.c b/lib/wsfs/adapter/impl/session.c similarity index 59% rename from lib/wsfs/adapter/session.c rename to lib/wsfs/adapter/impl/session.c index 1112e64..436b039 100644 --- a/lib/wsfs/adapter/session.c +++ b/lib/wsfs/adapter/impl/session.c @@ -1,17 +1,17 @@ -#include "wsfs/adapter/session.h" -#include "wsfs/adapter/authenticators.h" -#include "wsfs/message_queue.h" -#include "wsfs/message.h" -#include "wsfs/adapter/jsonrpc/server.h" +#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_session_init( - struct wsfs_session * session, +void wsfs_impl_session_init( + struct wsfs_impl_session * session, struct lws * wsi, - struct wsfs_authenticators * authenticators, - struct wsfs_jsonrpc_server * rpc) + struct wsfs_impl_authenticators * authenticators, + struct wsfs_impl_jsonrpc_server * rpc) { session->wsi = wsi; session->is_authenticated = false; @@ -20,8 +20,8 @@ void wsfs_session_init( wsfs_message_queue_init(&session->queue); } -void wsfs_session_cleanup( - struct wsfs_session * session) +void wsfs_impl_session_cleanup( + struct wsfs_impl_session * session) { wsfs_message_queue_cleanup(&session->queue); session->is_authenticated = false; @@ -30,15 +30,15 @@ void wsfs_session_cleanup( session->rpc = NULL; } -void wsfs_session_authenticate( - struct wsfs_session * session, +void wsfs_impl_session_authenticate( + struct wsfs_impl_session * session, struct wsfs_credentials * creds) { - session->is_authenticated = wsfs_authenticators_authenticate(session->authenticators, creds); + session->is_authenticated = wsfs_impl_authenticators_authenticate(session->authenticators, creds); } -bool wsfs_session_send( - struct wsfs_session * session, +bool wsfs_impl_session_send( + struct wsfs_impl_session * session, struct wsfs_message * message) { bool result = (session->is_authenticated) && (NULL != session->wsi); @@ -58,8 +58,8 @@ bool wsfs_session_send( return result; } -void wsfs_session_onwritable( - struct wsfs_session * session) +void wsfs_impl_session_onwritable( + struct wsfs_impl_session * session) { if (!wsfs_message_queue_empty(&session->queue)) { @@ -75,10 +75,10 @@ void wsfs_session_onwritable( } -void wsfs_session_receive( - struct wsfs_session * session, +void wsfs_impl_session_receive( + struct wsfs_impl_session * session, char const * data, size_t length) { - wsfs_jsonrpc_server_onresult(session->rpc, data, 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 new file mode 100644 index 0000000..ae24d97 --- /dev/null +++ b/lib/wsfs/adapter/impl/session.h @@ -0,0 +1,64 @@ +#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 new file mode 100644 index 0000000..783371f --- /dev/null +++ b/lib/wsfs/adapter/impl/session_manager.c @@ -0,0 +1,54 @@ +#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 new file mode 100644 index 0000000..4d54f43 --- /dev/null +++ b/lib/wsfs/adapter/impl/session_manager.h @@ -0,0 +1,46 @@ +#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 new file mode 100644 index 0000000..5c7af76 --- /dev/null +++ b/lib/wsfs/adapter/impl/time/timeout_manager.c @@ -0,0 +1,84 @@ +#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 new file mode 100644 index 0000000..4580b96 --- /dev/null +++ b/lib/wsfs/adapter/impl/time/timeout_manager.h @@ -0,0 +1,29 @@ +#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 new file mode 100644 index 0000000..4e81fde --- /dev/null +++ b/lib/wsfs/adapter/impl/time/timeout_manager_intern.h @@ -0,0 +1,24 @@ +#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 new file mode 100644 index 0000000..82e02e6 --- /dev/null +++ b/lib/wsfs/adapter/impl/time/timepoint.c @@ -0,0 +1,31 @@ +#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 new file mode 100644 index 0000000..c803653 --- /dev/null +++ b/lib/wsfs/adapter/impl/time/timepoint.h @@ -0,0 +1,31 @@ +#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 new file mode 100644 index 0000000..ec8dee0 --- /dev/null +++ b/lib/wsfs/adapter/impl/time/timer.c @@ -0,0 +1,65 @@ +#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 new file mode 100644 index 0000000..89b9154 --- /dev/null +++ b/lib/wsfs/adapter/impl/time/timer.h @@ -0,0 +1,48 @@ +#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 new file mode 100644 index 0000000..7695215 --- /dev/null +++ b/lib/wsfs/adapter/impl/time/timer_intern.h @@ -0,0 +1,25 @@ +#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/adapter/jsonrpc/method.c b/lib/wsfs/adapter/jsonrpc/method.c deleted file mode 100644 index c762d1a..0000000 --- a/lib/wsfs/adapter/jsonrpc/method.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "wsfs/adapter/jsonrpc/method_intern.h" - -#include -#include - -struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create( - char const * name, - wsfs_jsonrpc_method_invoke_fn * invoke, - void * user_data) -{ - struct wsfs_jsonrpc_method * method = malloc(sizeof(struct wsfs_jsonrpc_method)); - if (NULL != method) - { - method->next = NULL; - method->name = strdup(name); - method->invoke = invoke; - method->user_data = user_data; - } - - return method; -} - -void wsfs_jsonrpc_method_dispose( - struct wsfs_jsonrpc_method * method) -{ - free(method->name); - free(method); -} diff --git a/lib/wsfs/adapter/jsonrpc/method.h b/lib/wsfs/adapter/jsonrpc/method.h deleted file mode 100644 index 038bce4..0000000 --- a/lib/wsfs/adapter/jsonrpc/method.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WSFS_ADAPTER_JSONRPC_METHOD_H -#define WSFS_ADAPTER_JSONRPC_METHOD_H - -#ifndef __cplusplus -#include -#endif - -#include -#include "wsfs/status.h" - - -typedef bool wsfs_jsonrpc_method_invoke_fn( - void * user_data, - struct json_t const * method_call); - -typedef void wsfs_jsonrpc_method_finished_fn( - void * user_data, - wsfs_status status, - struct json_t const * result); - - - - -#endif diff --git a/lib/wsfs/adapter/jsonrpc/method_intern.h b/lib/wsfs/adapter/jsonrpc/method_intern.h deleted file mode 100644 index e1fb46e..0000000 --- a/lib/wsfs/adapter/jsonrpc/method_intern.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H -#define WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H - -#include "wsfs/adapter/jsonrpc/method.h" - -struct wsfs_jsonrpc_method -{ - struct wsfs_jsonrpc_method * next; - char * name; - wsfs_jsonrpc_method_invoke_fn * invoke; - void * user_data; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create( - char const * name, - wsfs_jsonrpc_method_invoke_fn * invoke, - void * user_data); - -extern void wsfs_jsonrpc_method_dispose( - struct wsfs_jsonrpc_method * method); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/jsonrpc/response.h b/lib/wsfs/adapter/jsonrpc/response.h deleted file mode 100644 index 4e6e34a..0000000 --- a/lib/wsfs/adapter/jsonrpc/response.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef WSFS_ADAPTER_JSONRPC_RESPONSE_H -#define WSFS_ADAPTER_JSONRPC_RESPONSE_H - -#ifndef __cplusplus -#include -#else -#include -using std::size_t; -#endif - -#include -#include "wsfs/status.h" - -struct wsfs_jsonrpc_response -{ - wsfs_status status; - int id; - json_t * result; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -extern void wsfs_jsonrpc_response_init( - struct wsfs_jsonrpc_response * response, - char const * buffer, - size_t buffer_length); - -extern void wsfs_jsonrpc_response_cleanup( - struct wsfs_jsonrpc_response * response); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/lib/wsfs/adapter/jsonrpc/server.h b/lib/wsfs/adapter/jsonrpc/server.h deleted file mode 100644 index 0ebff63..0000000 --- a/lib/wsfs/adapter/jsonrpc/server.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef WSFS_ADAPTER_JSONRPC_SERVER_H -#define WSFS_ADAPTER_JSONRPC_SERVER_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include "wsfs/adapter/jsonrpc/method.h" -#include "wsfs/adapter/time/timeout_manager.h" -#include "wsfs/adapter/time/timer.h" - - -struct wsfs_jsonrpc_request -{ - bool is_pending; - wsfs_jsonrpc_method_finished_fn * finished; - void * user_data; - int id; - struct wsfs_timer timer; -}; - -struct wsfs_jsonrpc_server -{ - struct wsfs_jsonrpc_method * methods; - struct wsfs_jsonrpc_request request; -}; - - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_jsonrpc_server_init( - struct wsfs_jsonrpc_server * server, - struct wsfs_timeout_manager * manager); - -extern void wsfs_jsonrpc_server_cleanup( - struct wsfs_jsonrpc_server * server); - -extern void wsfs_jsonrpc_server_add( - struct wsfs_jsonrpc_server * server, - char const * name, - wsfs_jsonrpc_method_invoke_fn * invoke, - void * user_data ); - -extern void wsfs_jsonrpc_server_invoke( - struct wsfs_jsonrpc_server * server, - wsfs_jsonrpc_method_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - ... -); - -extern void wsfs_jsonrpc_server_notify( - struct wsfs_jsonrpc_server * server, - char const * method_name, - char const * param_info, - ... -); - -extern void wsfs_jsonrpc_server_onresult( - struct wsfs_jsonrpc_server * server, - char const * message, - size_t length); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/jsonrpc/util.h b/lib/wsfs/adapter/jsonrpc/util.h deleted file mode 100644 index 23370cd..0000000 --- a/lib/wsfs/adapter/jsonrpc/util.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WSFS_ADAPTER_JSON_UTIL_H -#define WSFS_ADAPTER_JSON_UTIL_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern int wsfs_json_get_int(json_t const * object, char const * key, int default_value); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/operation/close.c b/lib/wsfs/adapter/operation/close.c deleted file mode 100644 index 7c6593f..0000000 --- a/lib/wsfs/adapter/operation/close.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "wsfs/adapter/operations.h" - -#include -#include -#include - -#include "wsfs/adapter/jsonrpc/server.h" -#include "wsfs/util.h" - -void wsfs_operation_close( - fuse_req_t request, - fuse_ino_t inode, - struct fuse_file_info * file_info) -{ - struct wsfs_operations_context * user_data = fuse_req_userdata(request); - struct wsfs_jsonrpc_server * rpc = user_data->rpc; - - int handle = (int) (file_info->fh & INT_MAX); - wsfs_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags); - fuse_reply_err(request, 0); -} diff --git a/lib/wsfs/adapter/server_config_intern.h b/lib/wsfs/adapter/server_config_intern.h deleted file mode 100644 index 2ae0a2f..0000000 --- a/lib/wsfs/adapter/server_config_intern.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef WSFS_ADAPTER_SERVER_CONFIG_INTERN_H -#define WSFS_ADAPTER_SERVER_CONFIG_INTERN_H - -#include "wsfs/adapter/server_config.h" -#include "wsfs/adapter/authenticators.h" - -struct wsfs_server_config -{ - char * mount_point; - char * document_root; - char * key_path; - char * cert_path; - char * vhost_name; - int port; - struct wsfs_authenticators authenticators; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_server_config_init( - struct wsfs_server_config * config); - -extern void wsfs_server_config_cleanup( - struct wsfs_server_config * config); - -extern void wsfs_server_config_clone( - struct wsfs_server_config * config, - struct wsfs_server_config * clone); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/server_protocol.c b/lib/wsfs/adapter/server_protocol.c deleted file mode 100644 index 2d037c4..0000000 --- a/lib/wsfs/adapter/server_protocol.c +++ /dev/null @@ -1,166 +0,0 @@ -#include "wsfs/adapter/server_protocol_intern.h" - -#include -#include - -#include "wsfs/message.h" -#include "wsfs/util.h" - -#include "wsfs/adapter/filesystem.h" - -static int wsfs_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_timeout_manager_check(&protocol->timeout_manager); - struct wsfs_session * session = wsfs_session_manager_get(&protocol->session_manager, wsi); - - switch (reason) - { - case LWS_CALLBACK_PROTOCOL_INIT: - { - lws_sock_file_fd_type fd; - fd.filefd = wsfs_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_session_manager_add( - &protocol->session_manager, - wsi, - &protocol->authenticators, - &protocol->rpc); - - if (NULL != session) - { - wsfs_session_authenticate(session, NULL); - } - break; - case LWS_CALLBACK_CLOSED: - wsfs_session_manager_remove(&protocol->session_manager, wsi); - break; - case LWS_CALLBACK_SERVER_WRITEABLE: - if (NULL != session) - { - wsfs_session_onwritable(session); - } - break; - case LWS_CALLBACK_RECEIVE: - if (NULL != session) - { - wsfs_session_receive(session, in, len); - } - break; - case LWS_CALLBACK_RAW_RX_FILE: - wsfs_filesystem_process_request(&protocol->filesystem); - break; - default: - break; - } - - return 0; -} - -static bool wsfs_server_protocol_invoke( - void * user_data, - json_t const * request) -{ - struct wsfs_server_protocol * protocol = user_data; - struct wsfs_session * session = &protocol->session_manager.session; - struct wsfs_message * message = wsfs_message_create(request); - - bool const result = wsfs_session_send(session, message); - - return result; -} - - -struct wsfs_server_protocol * wsfs_server_protocol_create( - char * mount_point) -{ - struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol)); - if (NULL != protocol) - { - if (!wsfs_server_protocol_init(protocol, mount_point)) - { - free(protocol); - protocol = NULL; - } - } - - return protocol; -} - -void wsfs_server_protocol_dispose( - struct wsfs_server_protocol * protocol) -{ - wsfs_server_protocol_cleanup(protocol); - free(protocol); -} - -void wsfs_server_protocol_init_lws( - struct wsfs_server_protocol * protocol, - struct lws_protocols * lws_protocol) -{ - lws_protocol->callback = &wsfs_server_protocol_callback; - lws_protocol->per_session_data_size = 0; - lws_protocol->user = protocol; -} - -bool wsfs_server_protocol_init( - struct wsfs_server_protocol * protocol, - char * mount_point) -{ - wsfs_timeout_manager_init(&protocol->timeout_manager); - wsfs_session_manager_init(&protocol->session_manager); - wsfs_authenticators_init(&protocol->authenticators); - - wsfs_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager); - wsfs_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_server_protocol_invoke, protocol); - wsfs_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_server_protocol_invoke, protocol); - wsfs_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_server_protocol_invoke, protocol); - wsfs_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_server_protocol_invoke, protocol); - wsfs_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_server_protocol_invoke, protocol); - wsfs_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_server_protocol_invoke, protocol); - - bool const success = wsfs_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point); - - // cleanup on error - if (!success) - { - wsfs_jsonrpc_server_cleanup(&protocol->rpc); - wsfs_authenticators_cleanup(&protocol->authenticators); - wsfs_timeout_manager_cleanup(&protocol->timeout_manager); - wsfs_session_manager_cleanup(&protocol->session_manager); - } - - return success; -} - -void wsfs_server_protocol_cleanup( - struct wsfs_server_protocol * protocol) -{ - wsfs_filesystem_cleanup(&protocol->filesystem); - wsfs_jsonrpc_server_cleanup(&protocol->rpc); - wsfs_timeout_manager_cleanup(&protocol->timeout_manager); - wsfs_authenticators_cleanup(&protocol->authenticators); - wsfs_session_manager_cleanup(&protocol->session_manager); -} - -void wsfs_server_protocol_add_authenticator( - struct wsfs_server_protocol * protocol, - char const * type, - wsfs_authenticate_fn * authenticate, - void * user_data) -{ - wsfs_authenticators_add(&protocol->authenticators, type, authenticate, user_data); -} diff --git a/lib/wsfs/adapter/server_protocol_intern.h b/lib/wsfs/adapter/server_protocol_intern.h deleted file mode 100644 index 7304934..0000000 --- a/lib/wsfs/adapter/server_protocol_intern.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H -#define WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H - -#include "wsfs/adapter/server_protocol.h" -#include "wsfs/adapter/filesystem.h" -#include "wsfs/adapter/jsonrpc/server.h" -#include "wsfs/adapter/time/timeout_manager.h" -#include "wsfs/adapter/authenticators.h" -#include "wsfs/adapter/session_manager.h" - -struct wsfs_server_protocol -{ - struct wsfs_timeout_manager timeout_manager; - struct wsfs_filesystem filesystem; - struct wsfs_jsonrpc_server rpc; - struct wsfs_authenticators authenticators; - struct wsfs_session_manager session_manager; -}; - -extern bool wsfs_server_protocol_init( - struct wsfs_server_protocol * protocol, - char * mount_point); - -extern void wsfs_server_protocol_cleanup( - struct wsfs_server_protocol * protocol); - -#endif diff --git a/lib/wsfs/adapter/session.h b/lib/wsfs/adapter/session.h deleted file mode 100644 index 86d41d8..0000000 --- a/lib/wsfs/adapter/session.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef WSFS_ADAPTER_SESSION_H -#define WSFS_ADAPTER_SESSION_H - -#ifndef __cplusplus -#include -#include -#else -#include -using std::size_t; -#endif - -#include "wsfs/message_queue.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct lws; -struct wsfs_message; -struct wsfs_credentials; -struct wsfs_authenticators; -struct wsfs_jsonrpc_server; - -struct wsfs_session -{ - struct lws * wsi; - bool is_authenticated; - struct wsfs_message_queue queue; - struct wsfs_authenticators * authenticators; - struct wsfs_jsonrpc_server * rpc; -}; - -extern void wsfs_session_init( - struct wsfs_session * session, - struct lws * wsi, - struct wsfs_authenticators * authenticators, - struct wsfs_jsonrpc_server * rpc); - -extern void wsfs_session_authenticate( - struct wsfs_session * session, - struct wsfs_credentials * creds); - -extern bool wsfs_session_send( - struct wsfs_session * session, - struct wsfs_message * message); - -extern void wsfs_session_receive( - struct wsfs_session * session, - char const * data, - size_t length); - -extern void wsfs_session_onwritable( - struct wsfs_session * session); - -extern void wsfs_session_cleanup( - struct wsfs_session * session); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/session_manager.c b/lib/wsfs/adapter/session_manager.c deleted file mode 100644 index 290398e..0000000 --- a/lib/wsfs/adapter/session_manager.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "wsfs/adapter/session_manager.h" -#include - -void wsfs_session_manager_init( - struct wsfs_session_manager * manager) -{ - wsfs_session_init(&manager->session, NULL, NULL, NULL); -} - -void wsfs_session_manager_cleanup( - struct wsfs_session_manager * manager) -{ - wsfs_session_cleanup(&manager->session); -} - -struct wsfs_session * wsfs_session_manager_add( - struct wsfs_session_manager * manager, - struct lws * wsi, - struct wsfs_authenticators * authenticators, - struct wsfs_jsonrpc_server * rpc) -{ - struct wsfs_session * session = NULL; - if (NULL == manager->session.wsi) - { - session = &manager->session; - wsfs_session_init(&manager->session, wsi, authenticators, rpc); - } - - return session; -} - -struct wsfs_session * wsfs_session_manager_get( - struct wsfs_session_manager * manager, - struct lws * wsi) -{ - struct wsfs_session * session = NULL; - if (wsi == manager->session.wsi) - { - session = &manager->session; - } - - return session; -} - -void wsfs_session_manager_remove( - struct wsfs_session_manager * manager, - struct lws * wsi) -{ - if (wsi == manager->session.wsi) - { - wsfs_session_cleanup(&manager->session); - manager->session.wsi = NULL; - } -} diff --git a/lib/wsfs/adapter/session_manager.h b/lib/wsfs/adapter/session_manager.h deleted file mode 100644 index d047aef..0000000 --- a/lib/wsfs/adapter/session_manager.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef WSFS_ADAPTER_SESSION_MANAGER_H -#define WSFS_ADAPTER_SESSION_MANAGER_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/session.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct lws; - -struct wsfs_session_manager -{ - struct wsfs_session session; -}; - -extern void wsfs_session_manager_init( - struct wsfs_session_manager * manager); - -extern void wsfs_session_manager_cleanup( - struct wsfs_session_manager * manager); - -extern struct wsfs_session * wsfs_session_manager_add( - struct wsfs_session_manager * manager, - struct lws * wsi, - struct wsfs_authenticators * authenticators, - struct wsfs_jsonrpc_server * rpc); - -extern struct wsfs_session * wsfs_session_manager_get( - struct wsfs_session_manager * manager, - struct lws * wsi); - -extern void wsfs_session_manager_remove( - struct wsfs_session_manager * manager, - struct lws * wsi); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/lib/wsfs/adapter/time/timeout_manager.c b/lib/wsfs/adapter/time/timeout_manager.c deleted file mode 100644 index d0c223a..0000000 --- a/lib/wsfs/adapter/time/timeout_manager.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "wsfs/adapter/time/timeout_manager_intern.h" - -#include -#include "wsfs/adapter/time/timer_intern.h" -#include "wsfs/adapter/time/timepoint.h" - -void wsfs_timeout_manager_init( - struct wsfs_timeout_manager * manager) -{ - manager->timers = NULL; -} - -void wsfs_timeout_manager_cleanup( - struct wsfs_timeout_manager * manager) -{ - struct wsfs_timer * timer = manager->timers; - while (NULL != timer) - { - struct wsfs_timer * next = timer->next; - - wsfs_timer_trigger(timer); - - timer = next; - } - - manager->timers = NULL; - -} - -void wsfs_timeout_manager_check( - struct wsfs_timeout_manager * manager) -{ - struct wsfs_timer * timer = manager->timers; - while (NULL != timer) - { - struct wsfs_timer * next = timer->next; - - if (wsfs_timer_is_timeout(timer)) - { - wsfs_timeout_manager_removetimer(manager, timer); - wsfs_timer_trigger(timer); - } - - timer = next; - } -} - -void wsfs_timeout_manager_addtimer( - struct wsfs_timeout_manager * manager, - struct wsfs_timer * timer) -{ - if (NULL != manager->timers) - { - manager->timers->prev = timer; - } - - timer->next = manager->timers; - timer->prev = NULL; - manager->timers = timer; -} - -void wsfs_timeout_manager_removetimer( - struct wsfs_timeout_manager * manager, - struct wsfs_timer * timer) -{ - struct wsfs_timer * prev = timer->prev; - struct wsfs_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/time/timeout_manager.h b/lib/wsfs/adapter/time/timeout_manager.h deleted file mode 100644 index ce7d875..0000000 --- a/lib/wsfs/adapter/time/timeout_manager.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H -#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H - -struct wsfs_timer; -struct wsfs_timeout_manager -{ - struct wsfs_timer * timers; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_timeout_manager_init( - struct wsfs_timeout_manager * manager); - -extern void wsfs_timeout_manager_cleanup( - struct wsfs_timeout_manager * manager); - -extern void wsfs_timeout_manager_check( - struct wsfs_timeout_manager * manager); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/time/timeout_manager_intern.h b/lib/wsfs/adapter/time/timeout_manager_intern.h deleted file mode 100644 index 962954e..0000000 --- a/lib/wsfs/adapter/time/timeout_manager_intern.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H -#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H - -#include "wsfs/adapter/time/timeout_manager.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_timeout_manager_addtimer( - struct wsfs_timeout_manager * manager, - struct wsfs_timer * timer); - -extern void wsfs_timeout_manager_removetimer( - struct wsfs_timeout_manager * manager, - struct wsfs_timer * timer); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wsfs/adapter/time/timepoint.c b/lib/wsfs/adapter/time/timepoint.c deleted file mode 100644 index 0d14783..0000000 --- a/lib/wsfs/adapter/time/timepoint.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "wsfs/adapter/time/timepoint.h" - -#include - -#define WSFS_MSEC_PER_SEC ((wsfs_timepoint) 1000) -#define WSFS_NSEC_PER_MSEC ((wsfs_timepoint) 1000 * 1000) - -wsfs_timepoint wsfs_timepoint_now(void) -{ - struct timespec timepoint; - clock_gettime(CLOCK_MONOTONIC, &timepoint); - - wsfs_timepoint const now = (timepoint.tv_sec * WSFS_MSEC_PER_SEC) + (timepoint.tv_nsec / WSFS_NSEC_PER_MSEC); - return now; -} - -wsfs_timepoint wsfs_timepoint_in_msec(wsfs_timediff value) -{ - wsfs_timepoint const now = wsfs_timepoint_now(); - wsfs_timepoint result = now + ((wsfs_timepoint) value); - - return result; -} - -bool wsfs_timepoint_is_elapsed(wsfs_timepoint timepoint) -{ - wsfs_timepoint const now = wsfs_timepoint_now(); - wsfs_timediff const diff = (wsfs_timediff) (timepoint - now); - - return (0 > diff); -} diff --git a/lib/wsfs/adapter/time/timepoint.h b/lib/wsfs/adapter/time/timepoint.h deleted file mode 100644 index 44b1418..0000000 --- a/lib/wsfs/adapter/time/timepoint.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WSFS_ADAPTER_TIME_TIMEPOINT_H -#define WSFS_ADAPTER_TIME_TIMEPOINT_H - -#ifndef __cplusplus -#include -#include -#else -#include -#endif - -typedef uint64_t wsfs_timepoint; -typedef int64_t wsfs_timediff; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern wsfs_timepoint wsfs_timepoint_now(void); - -extern wsfs_timepoint wsfs_timepoint_in_msec( - wsfs_timediff value); - -extern bool wsfs_timepoint_is_elapsed( - wsfs_timepoint timepoint); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/adapter/time/timer.c b/lib/wsfs/adapter/time/timer.c deleted file mode 100644 index 7797cec..0000000 --- a/lib/wsfs/adapter/time/timer.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "wsfs/adapter/time/timer_intern.h" -#include "wsfs/adapter/time/timeout_manager_intern.h" - -#include -#include - -void wsfs_timer_init( - struct wsfs_timer * timer, - struct wsfs_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_timer_cleanup( - struct wsfs_timer * timer) -{ - memset(timer, 0, sizeof(struct wsfs_timer)); -} - -void wsfs_timer_start( - struct wsfs_timer * timer, - wsfs_timepoint absolute_timeout, - wsfs_timer_timeout_fn * handler, - void * user_data) -{ - timer->timeout = absolute_timeout; - timer->timeout_handler = handler; - timer->user_data = user_data; - - wsfs_timeout_manager_addtimer(timer->manager, timer); -} - -void wsfs_timer_cancel( - struct wsfs_timer * timer) -{ - wsfs_timeout_manager_removetimer(timer->manager, timer); - - timer->timeout = 0; - timer->timeout_handler = NULL; - timer->user_data = NULL; -} - -bool wsfs_timer_is_timeout( - struct wsfs_timer * timer) -{ - return wsfs_timepoint_is_elapsed(timer->timeout); -} - - -void wsfs_timer_trigger( - struct wsfs_timer * timer) -{ - if (NULL != timer->timeout_handler) - { - timer->prev = NULL; - timer->next = NULL; - - timer->timeout_handler(timer); - } -} diff --git a/lib/wsfs/adapter/time/timer.h b/lib/wsfs/adapter/time/timer.h deleted file mode 100644 index 1d215fc..0000000 --- a/lib/wsfs/adapter/time/timer.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef WSFS_ADAPTER_TIME_TIMER_H -#define WSFS_ADAPTER_TIME_TIMER_H - -#include "wsfs/adapter/time/timepoint.h" - -struct wsfs_timer; -struct wsfs_timeout_manager; - -typedef void wsfs_timer_timeout_fn(struct wsfs_timer * timer); - -struct wsfs_timer -{ - struct wsfs_timeout_manager * manager; - wsfs_timepoint timeout; - wsfs_timer_timeout_fn * timeout_handler; - void * user_data; - struct wsfs_timer * next; - struct wsfs_timer * prev; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfs_timer_init( - struct wsfs_timer * timer, - struct wsfs_timeout_manager * manager); - -extern void wsfs_timer_cleanup( - struct wsfs_timer * timer); - -extern void wsfs_timer_start( - struct wsfs_timer * timer, - wsfs_timepoint absolute_timeout, - wsfs_timer_timeout_fn * handler, - void * user_data); - -extern void wsfs_timer_cancel( - struct wsfs_timer * timer); - -#ifdef __cplusplus -} -#endif - - - -#endif diff --git a/lib/wsfs/adapter/time/timer_intern.h b/lib/wsfs/adapter/time/timer_intern.h deleted file mode 100644 index 572e53e..0000000 --- a/lib/wsfs/adapter/time/timer_intern.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef WSFS_ADAPTER_TIME_TIMER_INTERN_H -#define WSFS_ADAPTER_TIME_TIMER_INTERN_H - -#ifndef __cplusplus -#include -#endif - -#include "wsfs/adapter/time/timer.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern bool wsfs_timer_is_timeout( - struct wsfs_timer * timer); - -extern void wsfs_timer_trigger( - struct wsfs_timer * timer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/message.c b/lib/wsfs/core/message.c similarity index 96% rename from lib/wsfs/message.c rename to lib/wsfs/core/message.c index 73a756d..4c6c790 100644 --- a/lib/wsfs/message.c +++ b/lib/wsfs/core/message.c @@ -1,4 +1,4 @@ -#include "wsfs/message.h" +#include "wsfs/core/message.h" #include #include diff --git a/lib/wsfs/message.h b/lib/wsfs/core/message.h similarity index 100% rename from lib/wsfs/message.h rename to lib/wsfs/core/message.h diff --git a/lib/wsfs/message_queue.c b/lib/wsfs/core/message_queue.c similarity index 94% rename from lib/wsfs/message_queue.c rename to lib/wsfs/core/message_queue.c index 08b7e5e..e758c67 100644 --- a/lib/wsfs/message_queue.c +++ b/lib/wsfs/core/message_queue.c @@ -1,5 +1,5 @@ -#include "wsfs/message_queue.h" -#include "wsfs/message.h" +#include "wsfs/core/message_queue.h" +#include "wsfs/core/message.h" void wsfs_message_queue_init( struct wsfs_message_queue * queue) diff --git a/lib/wsfs/message_queue.h b/lib/wsfs/core/message_queue.h similarity index 100% rename from lib/wsfs/message_queue.h rename to lib/wsfs/core/message_queue.h diff --git a/lib/wsfs/status.c b/lib/wsfs/core/status.c similarity index 95% rename from lib/wsfs/status.c rename to lib/wsfs/core/status.c index f2db1b2..f2576f7 100644 --- a/lib/wsfs/status.c +++ b/lib/wsfs/core/status.c @@ -1,4 +1,4 @@ -#include "wsfs/status_intern.h" +#include "wsfs/core/status_intern.h" #include diff --git a/lib/wsfs/status_intern.h b/lib/wsfs/core/status_intern.h similarity index 89% rename from lib/wsfs/status_intern.h rename to lib/wsfs/core/status_intern.h index a5f1880..08f4b04 100644 --- a/lib/wsfs/status_intern.h +++ b/lib/wsfs/core/status_intern.h @@ -1,7 +1,7 @@ #ifndef WSFS_STATUS_INTERN_H #define WSFS_STATUS_INTERN_H -#include "wsfs/status.h" +#include "wsfs/core/status.h" #ifdef __cplusplus extern "C" { diff --git a/lib/wsfs/util.h b/lib/wsfs/core/util.h similarity index 100% rename from lib/wsfs/util.h rename to lib/wsfs/core/util.h diff --git a/lib/wsfs/provider/api.c b/lib/wsfs/provider/api.c new file mode 100644 index 0000000..3a88c92 --- /dev/null +++ b/lib/wsfs/provider/api.c @@ -0,0 +1,240 @@ +#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/client_config_intern.h b/lib/wsfs/provider/client_config_intern.h deleted file mode 100644 index 087e5de..0000000 --- a/lib/wsfs/provider/client_config_intern.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WSFS_PROVIDER_CLIENT_CONFIG_INTERN_H -#define WSFS_PROVIDER_CLIENT_CONFIG_INTERN_H - -#include "wsfs/provider/client_config.h" -#include "wsfs/provider/provider.h" - -struct wsfsp_client_config -{ - struct wsfsp_provider provider; - void * user_data; - char * key_path; - char * cert_path; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/provider/client_protocol_intern.h b/lib/wsfs/provider/client_protocol_intern.h deleted file mode 100644 index b452df0..0000000 --- a/lib/wsfs/provider/client_protocol_intern.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef WSFS_PROVIDER_CLIENT_PROTOCOL_INTERN_H -#define WSFS_PROVIDER_CLIENT_PROTOCOL_INTERN_H - -#include "wsfs/provider/client_protocol.h" -#include "wsfs/provider/provider.h" -#include "wsfs/provider/request.h" - -#include "wsfs/message_queue.h" - -struct wsfsp_client_protocol -{ - struct wsfsp_request request; - struct wsfsp_provider provider; - void * user_data; - struct lws * wsi; - struct wsfs_message_queue queue; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_client_protocol_init( - struct wsfsp_client_protocol * protocol, - struct wsfsp_provider const * provider, - void * user_data); - -extern void wsfsp_client_protocol_cleanup( - struct wsfsp_client_protocol * protocol); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wsfs/provider/dirbuffer_intern.h b/lib/wsfs/provider/dirbuffer_intern.h deleted file mode 100644 index f49e869..0000000 --- a/lib/wsfs/provider/dirbuffer_intern.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef WSFS_PROVIDER_DIRBUFFER_INTERN_H -#define WSFS_PROVIDER_DIRBUFFER_INTERN_H - -#include "wsfs/provider/dirbuffer.h" -#include - -struct wsfsp_dirbuffer -{ - json_t * entries; -}; - -extern json_t * wsfsp_dirbuffer_take( - struct wsfsp_dirbuffer * buffer); - -#endif diff --git a/lib/wsfs/provider/client.c b/lib/wsfs/provider/impl/client.c similarity index 74% rename from lib/wsfs/provider/client.c rename to lib/wsfs/provider/impl/client.c index 886880c..6ea28f1 100644 --- a/lib/wsfs/provider/client.c +++ b/lib/wsfs/provider/impl/client.c @@ -1,4 +1,4 @@ -#include "wsfs/provider/client.h" +#include "wsfs/provider/impl/client.h" #include #include @@ -6,10 +6,10 @@ #include -#include "wsfs/provider/provider.h" -#include "wsfs/provider/client_protocol_intern.h" -#include "wsfs/provider/client_config_intern.h" -#include "wsfs/provider/url.h" +#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" #define WSFSP_PROTOCOL ("fs") #define WSFSP_DISABLE_LWS_LOG 0 @@ -28,7 +28,7 @@ struct wsfsp_client }; -struct wsfsp_client * wsfsp_client_create( +struct wsfsp_client * wsfsp_impl_client_create( struct wsfsp_client_config * config) { lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL); @@ -37,11 +37,11 @@ struct wsfsp_client * wsfsp_client_create( if (NULL != client) { client->is_running = true; - wsfsp_client_protocol_init(&client->protocol, &config->provider, config->user_data); + wsfsp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); memset(client->protocols, 0, sizeof(struct lws_protocols) * WSFSP_CLIENT_PROTOCOL_COUNT); client->protocols[0].name = "fs"; - wsfsp_client_protocol_init_lws(&client->protocol, &client->protocols[0]); + wsfsp_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_client_create( return client; } -void wsfsp_client_dispose( +void wsfsp_impl_client_dispose( struct wsfsp_client * client) { lws_context_destroy(client->context); - wsfsp_client_protocol_cleanup(&client->protocol); + wsfsp_impl_client_protocol_cleanup(&client->protocol); free(client); } -void wsfsp_client_connect( +void wsfsp_impl_client_connect( struct wsfsp_client * client, char const * url) { - struct wsfsp_url url_data; - bool const success = wsfsp_url_init(&url_data, url); + struct wsfsp_impl_url url_data; + bool const success = wsfsp_impl_url_init(&url_data, url); if (success) { struct lws_client_connect_info info; @@ -90,11 +90,11 @@ void wsfsp_client_connect( lws_client_connect_via_info(&info); - wsfsp_url_cleanup(&url_data); + wsfsp_impl_url_cleanup(&url_data); } } -void wsfsp_client_disconnect( +void wsfsp_impl_client_disconnect( struct wsfsp_client * client) { (void) client; @@ -102,7 +102,7 @@ void wsfsp_client_disconnect( // ToDo: implement me } -void wsfsp_client_run( +void wsfsp_impl_client_run( struct wsfsp_client * client) { while (client->is_running) @@ -111,7 +111,7 @@ void wsfsp_client_run( } } -void wsfsp_client_shutdown( +void wsfsp_impl_client_shutdown( struct wsfsp_client * client) { client->is_running = false; diff --git a/lib/wsfs/provider/impl/client.h b/lib/wsfs/provider/impl/client.h new file mode 100644 index 0000000..9c7d79b --- /dev/null +++ b/lib/wsfs/provider/impl/client.h @@ -0,0 +1,49 @@ +#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/client_config.c b/lib/wsfs/provider/impl/client_config.c similarity index 70% rename from lib/wsfs/provider/client_config.c rename to lib/wsfs/provider/impl/client_config.c index 3eb53b2..372021a 100644 --- a/lib/wsfs/provider/client_config.c +++ b/lib/wsfs/provider/impl/client_config.c @@ -1,14 +1,14 @@ -#include "wsfs/provider/client_config_intern.h" -#include "wsfs/provider/provider.h" +#include "wsfs/provider/impl/client_config.h" +#include "wsfs/provider/impl/provider.h" #include #include -struct wsfsp_client_config * wsfsp_client_config_create(void) +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_provider_init(&config->provider); + wsfsp_impl_provider_init(&config->provider); config->user_data = NULL; config->key_path = NULL; config->cert_path = NULL; @@ -17,7 +17,7 @@ struct wsfsp_client_config * wsfsp_client_config_create(void) return config; } -void wsfsp_client_config_dispose( +void wsfsp_impl_client_config_dispose( struct wsfsp_client_config * config) { free(config->key_path); @@ -25,14 +25,14 @@ void wsfsp_client_config_dispose( free(config); } -void wsfsp_client_config_set_userdata( +void wsfsp_impl_client_config_set_userdata( struct wsfsp_client_config * config, void * user_data) { config->user_data = user_data; } -void wsfsp_client_config_set_keypath( +void wsfsp_impl_client_config_set_keypath( struct wsfsp_client_config * config, char const * key_path) { @@ -40,7 +40,7 @@ void wsfsp_client_config_set_keypath( config->key_path = strdup(key_path); } -void wsfsp_client_config_set_certpath( +void wsfsp_impl_client_config_set_certpath( struct wsfsp_client_config * config, char const * cert_path) { @@ -48,63 +48,63 @@ void wsfsp_client_config_set_certpath( config->cert_path = strdup(cert_path); } -void wsfsp_client_config_set_onconnected( +void wsfsp_impl_client_config_set_onconnected( struct wsfsp_client_config * config, wsfsp_connected_fn * handler) { config->provider.connected = handler; } -void wsfsp_client_config_set_ondisconnected( +void wsfsp_impl_client_config_set_ondisconnected( struct wsfsp_client_config * config, wsfsp_disconnected_fn * handler) { config->provider.disconnected = handler; } -void wsfsp_client_config_set_ontimer( +void wsfsp_impl_client_config_set_ontimer( struct wsfsp_client_config * config, wsfsp_ontimer_fn * handler) { config->provider.ontimer = handler; } -void wsfsp_client_config_set_onlookup( +void wsfsp_impl_client_config_set_onlookup( struct wsfsp_client_config * config, wsfsp_lookup_fn * handler) { config->provider.lookup = handler; } -void wsfsp_client_config_set_ongetattr( +void wsfsp_impl_client_config_set_ongetattr( struct wsfsp_client_config * config, wsfsp_getattr_fn * handler) { config->provider.getattr = handler; } -void wsfsp_client_config_set_onreaddir( +void wsfsp_impl_client_config_set_onreaddir( struct wsfsp_client_config * config, wsfsp_readdir_fn * handler) { config->provider.readdir = handler; } -void wsfsp_client_config_set_onopen( +void wsfsp_impl_client_config_set_onopen( struct wsfsp_client_config * config, wsfsp_open_fn * handler) { config->provider.open = handler; } -void wsfsp_client_config_set_onclose( +void wsfsp_impl_client_config_set_onclose( struct wsfsp_client_config * config, wsfsp_close_fn * handler) { config->provider.close = handler; } -void wsfsp_client_config_set_onread( +void wsfsp_impl_client_config_set_onread( struct wsfsp_client_config * config, wsfsp_read_fn * handler) { diff --git a/lib/wsfs/provider/impl/client_config.h b/lib/wsfs/provider/impl/client_config.h new file mode 100644 index 0000000..4419636 --- /dev/null +++ b/lib/wsfs/provider/impl/client_config.h @@ -0,0 +1,77 @@ +#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/client_protocol.c b/lib/wsfs/provider/impl/client_protocol.c similarity index 75% rename from lib/wsfs/provider/client_protocol.c rename to lib/wsfs/provider/impl/client_protocol.c index f3c026e..7ac21f2 100644 --- a/lib/wsfs/provider/client_protocol.c +++ b/lib/wsfs/provider/impl/client_protocol.c @@ -1,4 +1,4 @@ -#include "wsfs/provider/client_protocol_intern.h" +#include "wsfs/provider/impl/client_protocol.h" #include #include @@ -7,11 +7,11 @@ #include -#include "wsfs/provider/provider.h" -#include "wsfs/util.h" -#include "wsfs/message.h" +#include "wsfs/provider/impl/provider.h" +#include "wsfs/core/util.h" +#include "wsfs/core/message.h" -static void wsfsp_client_protocol_respond( +static void wsfsp_impl_client_protocol_respond( json_t * response, void * user_data) { @@ -25,7 +25,7 @@ static void wsfsp_client_protocol_respond( } } -static void wsfsp_client_protocol_process_request( +static void wsfsp_impl_client_protocol_process_request( struct wsfsp_client_protocol * protocol, char const * message, size_t length) @@ -33,20 +33,20 @@ static void wsfsp_client_protocol_process_request( json_t * request = json_loadb(message, length, 0, NULL); if (NULL != request) { - struct wsfsp_invokation_context context = + struct wsfsp_impl_invokation_context context = { .provider = &protocol->provider, .user_data = protocol->user_data, .request = &protocol->request }; - wsfsp_provider_invoke(&context, request); + wsfsp_impl_provider_invoke(&context, request); json_decref(request); } } -static int wsfsp_client_protocol_callback( +static int wsfsp_impl_client_protocol_callback( struct lws * wsi, enum lws_callback_reasons reason, void * WSFS_UNUSED_PARAM(user), @@ -70,7 +70,7 @@ static int wsfsp_client_protocol_callback( protocol->provider.connected(protocol->user_data); break; case LWS_CALLBACK_CLIENT_RECEIVE: - wsfsp_client_protocol_process_request(protocol, in, len); + wsfsp_impl_client_protocol_process_request(protocol, in, len); break; case LWS_CALLBACK_SERVER_WRITEABLE: // fall-through @@ -97,7 +97,7 @@ static int wsfsp_client_protocol_callback( } -void wsfsp_client_protocol_init( +void wsfsp_impl_client_protocol_init( struct wsfsp_client_protocol * protocol, struct wsfsp_provider const * provider, void * user_data) @@ -106,44 +106,44 @@ void wsfsp_client_protocol_init( protocol->wsi = NULL; - protocol->request.respond = &wsfsp_client_protocol_respond; + protocol->request.respond = &wsfsp_impl_client_protocol_respond; protocol->request.user_data = protocol; protocol->user_data = user_data; - wsfsp_provider_init_from_prototype(&protocol->provider, provider); + wsfsp_impl_provider_init_from_prototype(&protocol->provider, provider); } -void wsfsp_client_protocol_cleanup( +void wsfsp_impl_client_protocol_cleanup( struct wsfsp_client_protocol * protocol) { wsfs_message_queue_cleanup(&protocol->queue); } -struct wsfsp_client_protocol * wsfsp_client_protocol_create( +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_client_protocol_init(protocol, provider, user_data); + wsfsp_impl_client_protocol_init(protocol, provider, user_data); } return protocol; } -void wsfsp_client_protocol_dispose( +void wsfsp_impl_client_protocol_dispose( struct wsfsp_client_protocol * protocol) { - wsfsp_client_protocol_cleanup(protocol); + wsfsp_impl_client_protocol_cleanup(protocol); free(protocol); } -void wsfsp_client_protocol_init_lws( +void wsfsp_impl_client_protocol_init_lws( struct wsfsp_client_protocol * protocol, struct lws_protocols * lws_protocol) { - lws_protocol->callback = &wsfsp_client_protocol_callback; + 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 new file mode 100644 index 0000000..d83fc30 --- /dev/null +++ b/lib/wsfs/provider/impl/client_protocol.h @@ -0,0 +1,49 @@ +#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/dirbuffer.c b/lib/wsfs/provider/impl/dirbuffer.c similarity index 79% rename from lib/wsfs/provider/dirbuffer.c rename to lib/wsfs/provider/impl/dirbuffer.c index 085873a..70c9e52 100644 --- a/lib/wsfs/provider/dirbuffer.c +++ b/lib/wsfs/provider/impl/dirbuffer.c @@ -1,7 +1,7 @@ -#include "wsfs/provider/dirbuffer_intern.h" +#include "wsfs/provider/impl/dirbuffer.h" #include -struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void) +struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void) { struct wsfsp_dirbuffer * buffer = malloc(sizeof(struct wsfsp_dirbuffer)); if (NULL != buffer) @@ -12,7 +12,7 @@ struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void) return buffer; } -void wsfsp_dirbuffer_dispose( +void wsfsp_impl_dirbuffer_dispose( struct wsfsp_dirbuffer * buffer) { if (NULL != buffer->entries) @@ -23,7 +23,7 @@ void wsfsp_dirbuffer_dispose( free(buffer); } -void wsfsp_dirbuffer_add( +void wsfsp_impl_dirbuffer_add( struct wsfsp_dirbuffer * buffer, char const * name, ino_t inode) @@ -35,7 +35,7 @@ void wsfsp_dirbuffer_add( json_array_append_new(buffer->entries, entry); } -json_t * wsfsp_dirbuffer_take( +json_t * wsfsp_impl_dirbuffer_take( struct wsfsp_dirbuffer * buffer) { json_t * entries = buffer->entries; diff --git a/lib/wsfs/provider/impl/dirbuffer.h b/lib/wsfs/provider/impl/dirbuffer.h new file mode 100644 index 0000000..d70b494 --- /dev/null +++ b/lib/wsfs/provider/impl/dirbuffer.h @@ -0,0 +1,37 @@ +#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/operation/close.c b/lib/wsfs/provider/impl/operation/close.c similarity index 84% rename from lib/wsfs/provider/operation/close.c rename to lib/wsfs/provider/impl/operation/close.c index 4ef6837..c62381a 100644 --- a/lib/wsfs/provider/operation/close.c +++ b/lib/wsfs/provider/impl/operation/close.c @@ -1,9 +1,9 @@ -#include "wsfs/provider/operation/close_intern.h" +#include "wsfs/provider/impl/operation/close.h" #include -#include "wsfs/util.h" +#include "wsfs/core/util.h" -void wsfsp_close( - struct wsfsp_invokation_context * context, +void wsfsp_impl_close( + struct wsfsp_impl_invokation_context * context, json_t * params, int WSFS_UNUSED_PARAM(id)) { @@ -28,7 +28,7 @@ void wsfsp_close( } -void wsfsp_close_default( +void wsfsp_impl_close_default( ino_t WSFS_UNUSED_PARAM(inode), uint32_t WSFS_UNUSED_PARAM(handle), int WSFS_UNUSED_PARAM(flags), diff --git a/lib/wsfs/provider/impl/operation/close.h b/lib/wsfs/provider/impl/operation/close.h new file mode 100644 index 0000000..f92c66c --- /dev/null +++ b/lib/wsfs/provider/impl/operation/close.h @@ -0,0 +1,26 @@ +#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 new file mode 100644 index 0000000..416bfe6 --- /dev/null +++ b/lib/wsfs/provider/impl/operation/error.h @@ -0,0 +1,22 @@ +#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/operation/getattr.c b/lib/wsfs/provider/impl/operation/getattr.c similarity index 73% rename from lib/wsfs/provider/operation/getattr.c rename to lib/wsfs/provider/impl/operation/getattr.c index 90aefa0..eb49063 100644 --- a/lib/wsfs/provider/operation/getattr.c +++ b/lib/wsfs/provider/impl/operation/getattr.c @@ -1,14 +1,14 @@ -#include "wsfs/provider/operation/getattr_intern.h" +#include "wsfs/provider/impl/operation/getattr.h" #include -#include "wsfs/provider/operation/error.h" -#include "wsfs/provider/request.h" -#include "wsfs/util.h" +#include "wsfs/provider/impl/operation/error.h" +#include "wsfs/provider/impl/request.h" +#include "wsfs/core/util.h" -void wsfsp_getattr( - struct wsfsp_invokation_context * context, +void wsfsp_impl_getattr( + struct wsfsp_impl_invokation_context * context, json_t * params, int id) { @@ -20,22 +20,22 @@ void wsfsp_getattr( if (json_is_integer(inode_holder)) { ino_t inode = (ino_t) json_integer_value(inode_holder); - struct wsfsp_request * request = wsfsp_request_create(context->request, id); + struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); context->provider->getattr(request, inode, context->user_data); } } } -void wsfsp_getattr_default( +void wsfsp_impl_getattr_default( struct wsfsp_request * request, ino_t WSFS_UNUSED_PARAM(inode), void * WSFS_UNUSED_PARAM(user_data)) { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); } -void wsfsp_respond_getattr( +void wsfsp_impl_respond_getattr( struct wsfsp_request * request, struct stat const * stat) { @@ -60,5 +60,5 @@ void wsfsp_respond_getattr( json_object_set_new(result, "type", json_string("dir")); } - wsfsp_respond(request, result); + wsfsp_impl_respond(request, result); } diff --git a/lib/wsfs/provider/impl/operation/getattr.h b/lib/wsfs/provider/impl/operation/getattr.h new file mode 100644 index 0000000..f399e80 --- /dev/null +++ b/lib/wsfs/provider/impl/operation/getattr.h @@ -0,0 +1,29 @@ +#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/operation/lookup.c b/lib/wsfs/provider/impl/operation/lookup.c similarity index 76% rename from lib/wsfs/provider/operation/lookup.c rename to lib/wsfs/provider/impl/operation/lookup.c index 900b901..9b55a04 100644 --- a/lib/wsfs/provider/operation/lookup.c +++ b/lib/wsfs/provider/impl/operation/lookup.c @@ -1,12 +1,13 @@ -#include "wsfs/provider/operation/lookup_intern.h" +#include "wsfs/provider/impl/operation/lookup.h" #include -#include "wsfs/provider/operation/error.h" -#include "wsfs/util.h" +#include "wsfs/provider/impl/operation/error.h" +#include "wsfs/provider/impl/request.h" +#include "wsfs/core/util.h" -void wsfsp_lookup( - struct wsfsp_invokation_context * context, +void wsfsp_impl_lookup( + struct wsfsp_impl_invokation_context * context, json_t * params, int id) { @@ -22,13 +23,13 @@ void wsfsp_lookup( ino_t inode = json_integer_value(inode_holder); char const * name = json_string_value(name_holder); - struct wsfsp_request * request = wsfsp_request_create(context->request, id); + struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); context->provider->lookup(request, inode, name, context->user_data); } } } -void wsfsp_respond_lookup( +void wsfsp_impl_respond_lookup( struct wsfsp_request * request, struct stat const * stat) { @@ -53,15 +54,15 @@ void wsfsp_respond_lookup( json_object_set_new(result, "type", json_string("dir")); } - wsfsp_respond(request, result); + wsfsp_impl_respond(request, result); } -void wsfsp_lookup_default( +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)) { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); } diff --git a/lib/wsfs/provider/impl/operation/lookup.h b/lib/wsfs/provider/impl/operation/lookup.h new file mode 100644 index 0000000..082dc52 --- /dev/null +++ b/lib/wsfs/provider/impl/operation/lookup.h @@ -0,0 +1,30 @@ +#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/operation/open.c b/lib/wsfs/provider/impl/operation/open.c similarity index 65% rename from lib/wsfs/provider/operation/open.c rename to lib/wsfs/provider/impl/operation/open.c index 9196ded..ea28a93 100644 --- a/lib/wsfs/provider/operation/open.c +++ b/lib/wsfs/provider/impl/operation/open.c @@ -1,10 +1,10 @@ -#include "wsfs/provider/operation/open_intern.h" -#include "wsfs/provider/operation/error.h" -#include "wsfs/provider/request.h" -#include "wsfs/util.h" +#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" -void wsfsp_open( - struct wsfsp_invokation_context * context, +void wsfsp_impl_open( + struct wsfsp_impl_invokation_context * context, json_t * params, int id) { @@ -20,28 +20,28 @@ void wsfsp_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_request_create(context->request, id); + struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); context->provider->open(request, inode, flags, context->user_data); /* Flawfinder: ignore */ } } } -void wsfsp_open_default( +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)) { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); } -void wsfsp_respond_open( +void wsfsp_impl_respond_open( struct wsfsp_request * request, uint32_t handle) { json_t * result = json_object(); json_object_set_new(result, "handle", json_integer((int) handle)); - wsfsp_respond(request, result); + wsfsp_impl_respond(request, result); } diff --git a/lib/wsfs/provider/impl/operation/open.h b/lib/wsfs/provider/impl/operation/open.h new file mode 100644 index 0000000..c589d44 --- /dev/null +++ b/lib/wsfs/provider/impl/operation/open.h @@ -0,0 +1,30 @@ +#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/operation/read.c b/lib/wsfs/provider/impl/operation/read.c similarity index 77% rename from lib/wsfs/provider/operation/read.c rename to lib/wsfs/provider/impl/operation/read.c index ff03702..c92d6d2 100644 --- a/lib/wsfs/provider/operation/read.c +++ b/lib/wsfs/provider/impl/operation/read.c @@ -1,13 +1,14 @@ -#include "wsfs/provider/operation/read_intern.h" +#include "wsfs/provider/impl/operation/read.h" #include #include -#include "wsfs/provider/operation/error.h" -#include "wsfs/util.h" +#include "wsfs/provider/impl/operation/error.h" +#include "wsfs/provider/impl/request.h" +#include "wsfs/core/util.h" -void wsfsp_read( - struct wsfsp_invokation_context * context, +void wsfsp_impl_read( + struct wsfsp_impl_invokation_context * context, json_t * params, int id) { @@ -28,14 +29,14 @@ void wsfsp_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_request_create(context->request, id); + struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); context->provider->read(request, inode, handle, offset, length, context->user_data); /* Flawfinder: ignore */ } } } -void wsfsp_read_default( +void wsfsp_impl_read_default( struct wsfsp_request * request, ino_t WSFS_UNUSED_PARAM(inode), uint32_t WSFS_UNUSED_PARAM(handle), @@ -43,10 +44,10 @@ void wsfsp_read_default( size_t WSFS_UNUSED_PARAM(length), void * WSFS_UNUSED_PARAM(user_data)) { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); } -void wsfsp_respond_read( +void wsfsp_impl_respond_read( struct wsfsp_request * request, char const * data, size_t length) @@ -64,12 +65,12 @@ void wsfsp_respond_read( json_object_set_new(result, "format", json_string("base64")); json_object_set_new(result, "count", json_integer((int) length)); - wsfsp_respond(request, result); + wsfsp_impl_respond(request, result); free(buffer); } else { - wsfsp_respond_error(request, WSFS_BAD); + wsfsp_impl_respond_error(request, WSFS_BAD); } } else @@ -79,6 +80,6 @@ void wsfsp_respond_read( json_object_set_new(result, "format", json_string("identitiy")); json_object_set_new(result, "count", json_integer(0)); - wsfsp_respond(request, result); + wsfsp_impl_respond(request, result); } } \ No newline at end of file diff --git a/lib/wsfs/provider/impl/operation/read.h b/lib/wsfs/provider/impl/operation/read.h new file mode 100644 index 0000000..2f86ea3 --- /dev/null +++ b/lib/wsfs/provider/impl/operation/read.h @@ -0,0 +1,33 @@ +#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/operation/readdir.c b/lib/wsfs/provider/impl/operation/readdir.c similarity index 50% rename from lib/wsfs/provider/operation/readdir.c rename to lib/wsfs/provider/impl/operation/readdir.c index f94c0f3..6777698 100644 --- a/lib/wsfs/provider/operation/readdir.c +++ b/lib/wsfs/provider/impl/operation/readdir.c @@ -1,11 +1,11 @@ -#include "wsfs/provider/operation/readdir_intern.h" -#include "wsfs/provider/operation/error.h" -#include "wsfs/provider/dirbuffer_intern.h" -#include "wsfs/provider/request.h" -#include "wsfs/util.h" +#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_readdir( - struct wsfsp_invokation_context * context, +void wsfsp_impl_readdir( + struct wsfsp_impl_invokation_context * context, json_t * params, int id) { @@ -17,26 +17,26 @@ void wsfsp_readdir( if ((NULL != inode_holder) && (json_is_integer(inode_holder))) { ino_t inode = (ino_t) json_integer_value(inode_holder); - struct wsfsp_request * request = wsfsp_request_create(context->request, id); + struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id); context->provider->readdir(request, inode, context->user_data); } } } -void wsfsp_readdir_default( +void wsfsp_impl_readdir_default( struct wsfsp_request * request, ino_t WSFS_UNUSED_PARAM(directory), void * WSFS_UNUSED_PARAM(user_data)) { - wsfsp_respond_error(request, WSFS_BAD_NOENTRY); + wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY); } -void wsfsp_respond_readdir( +void wsfsp_impl_respond_readdir( struct wsfsp_request * request, struct wsfsp_dirbuffer * dirbuffer) { - json_t * result = wsfsp_dirbuffer_take(dirbuffer); - wsfsp_respond(request, result); + 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 new file mode 100644 index 0000000..c87e108 --- /dev/null +++ b/lib/wsfs/provider/impl/operation/readdir.h @@ -0,0 +1,29 @@ +#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 new file mode 100644 index 0000000..7a70f91 --- /dev/null +++ b/lib/wsfs/provider/impl/provider.c @@ -0,0 +1,127 @@ +#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/provider.h b/lib/wsfs/provider/impl/provider.h similarity index 53% rename from lib/wsfs/provider/provider.h rename to lib/wsfs/provider/impl/provider.h index e3594f6..072943a 100644 --- a/lib/wsfs/provider/provider.h +++ b/lib/wsfs/provider/impl/provider.h @@ -1,16 +1,13 @@ -#ifndef WSFS_PROVIDER_PROVIDER_H -#define WSFS_PROVIDER_PROVIDER_H - -#include "wsfs/provider/client_config.h" -#include "wsfs/provider/request.h" -#include -#include -#include -#include -#include -#include +#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 { @@ -25,37 +22,32 @@ struct wsfsp_provider wsfsp_read_fn * read; }; -struct wsfsp_invokation_context +struct wsfsp_impl_invokation_context { struct wsfsp_provider * provider; void * user_data; struct wsfsp_request * request; }; -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_provider_init( +extern void wsfsp_impl_provider_init( struct wsfsp_provider * provider); -extern void wsfsp_provider_init_from_prototype( +extern void wsfsp_impl_provider_init_from_prototype( struct wsfsp_provider * provider, struct wsfsp_provider const * prototype); -extern void wsfsp_provider_invoke( - struct wsfsp_invokation_context * context, +extern void wsfsp_impl_provider_invoke( + struct wsfsp_impl_invokation_context * context, json_t * request); -extern void wsfsp_connected_default( +extern void wsfsp_impl_connected_default( void * user_data); -extern void wsfsp_disconnected_default( +extern void wsfsp_impl_disconnected_default( void * user_data); -extern void wsfsp_ontimer_default( +extern void wsfsp_impl_ontimer_default( void * user_data); #ifdef __cplusplus diff --git a/lib/wsfs/provider/request.c b/lib/wsfs/provider/impl/request.c similarity index 77% rename from lib/wsfs/provider/request.c rename to lib/wsfs/provider/impl/request.c index 4f6d90f..1333526 100644 --- a/lib/wsfs/provider/request.c +++ b/lib/wsfs/provider/impl/request.c @@ -1,9 +1,9 @@ -#include "wsfs/provider/request.h" +#include "wsfs/provider/impl/request.h" #include -#include "wsfs/provider/operation/error.h" +#include "wsfs/provider/impl/operation/error.h" -struct wsfsp_request * wsfsp_request_create( +struct wsfsp_request * wsfsp_impl_request_create( struct wsfsp_request * prototype, int id) { @@ -18,13 +18,13 @@ struct wsfsp_request * wsfsp_request_create( return request; } -void wsfsp_request_dispose( +void wsfsp_impl_request_dispose( struct wsfsp_request * request) { free(request); } -extern void wsfsp_respond( +extern void wsfsp_impl_respond( struct wsfsp_request * request, json_t * result) { @@ -35,10 +35,10 @@ extern void wsfsp_respond( request->respond(response, request->user_data); json_decref(response); - wsfsp_request_dispose(request); + wsfsp_impl_request_dispose(request); } -void wsfsp_respond_error( +void wsfsp_impl_respond_error( struct wsfsp_request * request, wsfs_status status) { @@ -51,5 +51,5 @@ void wsfsp_respond_error( request->respond(response, request->user_data); json_decref(response); - wsfsp_request_dispose(request); + wsfsp_impl_request_dispose(request); } \ No newline at end of file diff --git a/lib/wsfs/provider/impl/request.h b/lib/wsfs/provider/impl/request.h new file mode 100644 index 0000000..c21d7ef --- /dev/null +++ b/lib/wsfs/provider/impl/request.h @@ -0,0 +1,43 @@ +#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/lib/wsfs/provider/url.c b/lib/wsfs/provider/impl/url.c similarity index 61% rename from lib/wsfs/provider/url.c rename to lib/wsfs/provider/impl/url.c index b250646..71a26a6 100644 --- a/lib/wsfs/provider/url.c +++ b/lib/wsfs/provider/impl/url.c @@ -1,9 +1,9 @@ -#include "wsfs/provider/url.h" +#include "wsfs/provider/impl/url.h" #include #include -struct wsfsp_url_protocol +struct wsfsp_impl_url_protocol { char const * name; size_t name_length; @@ -11,11 +11,11 @@ struct wsfsp_url_protocol bool use_tls; }; -static bool wsfsp_url_readprotocol( - struct wsfsp_url * url, +static bool wsfsp_impl_url_readprotocol( + struct wsfsp_impl_url * url, char const * * data) { - static struct wsfsp_url_protocol const known_protocols[] = + static struct wsfsp_impl_url_protocol const known_protocols[] = { {"ws://", 5, 80, false}, {"wss://", 6, 443, true} @@ -25,7 +25,7 @@ static bool wsfsp_url_readprotocol( bool found = false; for(size_t i = 0; (!found) && (i < count); i++) { - struct wsfsp_url_protocol const * protocol = &known_protocols[i]; + struct wsfsp_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_url_readprotocol( return found; } -static bool wsfsp_url_readhost( - struct wsfsp_url * url, +static bool wsfsp_impl_url_readhost( + struct wsfsp_impl_url * url, char const * * data) { char * end = strpbrk(*data, ":/"); @@ -55,8 +55,8 @@ static bool wsfsp_url_readhost( return result; } -static bool wsfsp_url_readport( - struct wsfsp_url * url, +static bool wsfsp_impl_url_readport( + struct wsfsp_impl_url * url, char const * * data) { bool result; @@ -81,8 +81,8 @@ static bool wsfsp_url_readport( return result; } -static bool wsfsp_url_readpath( - struct wsfsp_url * url, +static bool wsfsp_impl_url_readpath( + struct wsfsp_impl_url * url, char const * * data) { bool const result = ('/' == **data); @@ -93,41 +93,33 @@ static bool wsfsp_url_readpath( } -bool wsfsp_url_init( - struct wsfsp_url * url, +bool wsfsp_impl_url_init( + struct wsfsp_impl_url * url, char const * value) { - memset(url, 0, sizeof(struct wsfsp_url)); + memset(url, 0, sizeof(struct wsfsp_impl_url)); char const * data = value; bool const result = - wsfsp_url_readprotocol(url, &data) && - wsfsp_url_readhost(url, &data) && - wsfsp_url_readport(url, &data) && - wsfsp_url_readpath(url, &data) + wsfsp_impl_url_readprotocol(url, &data) && + wsfsp_impl_url_readhost(url, &data) && + wsfsp_impl_url_readport(url, &data) && + wsfsp_impl_url_readpath(url, &data) ; if (!result) { - wsfsp_url_cleanup(url); + wsfsp_impl_url_cleanup(url); } return result; } -void wsfsp_url_cleanup( - struct wsfsp_url * url) +void wsfsp_impl_url_cleanup( + struct wsfsp_impl_url * url) { free(url->host); free(url->path); - memset(url, 0, sizeof(struct wsfsp_url)); + memset(url, 0, sizeof(struct wsfsp_impl_url)); } -char const * wsfsp_url_gethost( - struct wsfsp_url const * url); - -int wsfsp_url_getport( - struct wsfsp_url const * url); - -char const * wsfsp_url_getpath( - struct wsfsp_url const * url); diff --git a/lib/wsfs/provider/url.h b/lib/wsfs/provider/impl/url.h similarity index 50% rename from lib/wsfs/provider/url.h rename to lib/wsfs/provider/impl/url.h index 896b537..ccb0fa6 100644 --- a/lib/wsfs/provider/url.h +++ b/lib/wsfs/provider/impl/url.h @@ -1,11 +1,15 @@ -#ifndef WSFS_PROVIDER_URL_H -#define WSFS_PROVIDER_URL_H +#ifndef WSFS_PROVIDER_IMPL_URL_H +#define WSFS_PROVIDER_IMPL_URL_H #ifndef __cplusplus #include #endif -struct wsfsp_url +#ifdef __cplusplus +extern "C" +{ +#endif +struct wsfsp_impl_url { char * host; int port; @@ -13,17 +17,12 @@ struct wsfsp_url bool use_tls; }; -#ifdef __cplusplus -extern "C" -{ -#endif - -extern bool wsfsp_url_init( - struct wsfsp_url * url, +extern bool wsfsp_impl_url_init( + struct wsfsp_impl_url * url, char const * value); -extern void wsfsp_url_cleanup( - struct wsfsp_url * url); +extern void wsfsp_impl_url_cleanup( + struct wsfsp_impl_url * url); #ifdef __cplusplus diff --git a/lib/wsfs/provider/operation/close_intern.h b/lib/wsfs/provider/operation/close_intern.h deleted file mode 100644 index ecc55e2..0000000 --- a/lib/wsfs/provider/operation/close_intern.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WSFS_PROVIDER_OPERATION_CLOSE_INTERN_H -#define WSFS_PROVIDER_OPERATION_CLOSE_INTERN_H - -#include "wsfs/provider/operation/close.h" -#include "wsfs/provider/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_close( - struct wsfsp_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_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/operation/getattr_intern.h b/lib/wsfs/provider/operation/getattr_intern.h deleted file mode 100644 index 2a92dc4..0000000 --- a/lib/wsfs/provider/operation/getattr_intern.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef WSFS_PROVIDER_OPERATION_GETATTR_INTERN_H -#define WSFS_PROVIDER_OPERATION_GETATTR_INTERN_H - -#include "wsfs/provider/operation/getattr.h" -#include "wsfs/provider/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_getattr( - struct wsfsp_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_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/operation/lookup_intern.h b/lib/wsfs/provider/operation/lookup_intern.h deleted file mode 100644 index 86bccec..0000000 --- a/lib/wsfs/provider/operation/lookup_intern.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WSFS_PROVIDER_OPERATION_LOOKUP_INTERN_H -#define WSFS_PROVIDER_OPERATION_LOOKUP_INTERN_H - -#include "wsfs/provider/operation/lookup.h" -#include "wsfs/provider/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_lookup( - struct wsfsp_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_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/operation/open_intern.h b/lib/wsfs/provider/operation/open_intern.h deleted file mode 100644 index 753ee46..0000000 --- a/lib/wsfs/provider/operation/open_intern.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WSFS_PROVIDER_OPERATION_OPEN_INTERN_H -#define WSFS_PROVIDER_OPERATION_OPEN_INTERN_H - -#include "wsfs/provider/operation/open.h" -#include "wsfs/provider/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_open( - struct wsfsp_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_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/operation/read_intern.h b/lib/wsfs/provider/operation/read_intern.h deleted file mode 100644 index 793572d..0000000 --- a/lib/wsfs/provider/operation/read_intern.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef WSFS_PROVIDER_OPERATION_READ_INTERN_H -#define WSFS_PROVIDER_OPERATION_READ_INTERN_H - -#include "wsfs/provider/operation/read.h" -#include "wsfs/provider/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_read( - struct wsfsp_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_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/operation/readdir_intern.h b/lib/wsfs/provider/operation/readdir_intern.h deleted file mode 100644 index b8cc225..0000000 --- a/lib/wsfs/provider/operation/readdir_intern.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef WSFS_PROVIDER_OPERATION_READDIR_INTERN_H -#define WSFS_PROVIDER_OPERATION_READDIR_INTERN_H - -#include "wsfs/provider/operation/readdir.h" -#include "wsfs/provider/provider.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wsfsp_readdir( - struct wsfsp_invokation_context * context, - json_t * params, - int id); - -extern void wsfsp_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/provider.c b/lib/wsfs/provider/provider.c deleted file mode 100644 index 5cb548a..0000000 --- a/lib/wsfs/provider/provider.c +++ /dev/null @@ -1,127 +0,0 @@ -#include "wsfs/provider/provider.h" - -#include -#include - -#include "wsfs/provider/request.h" -#include "wsfs/provider/operation/lookup_intern.h" -#include "wsfs/provider/operation/getattr_intern.h" -#include "wsfs/provider/operation/readdir_intern.h" -#include "wsfs/provider/operation/open_intern.h" -#include "wsfs/provider/operation/close_intern.h" -#include "wsfs/provider/operation/read_intern.h" - -typedef void wsfsp_invoke_fn( - struct wsfsp_invokation_context * context, - json_t * params, - int id); - - -struct wsfsp_method -{ - char const * name; - wsfsp_invoke_fn * invoke; - bool is_notification; -}; - -static void wsfsp_provider_invoke_method( - struct wsfsp_invokation_context * context, - char const * method_name, - json_t * params, - int id) -{ - static struct wsfsp_method const methods[] = - { - {"lookup", &wsfsp_lookup, false}, - {"getattr", &wsfsp_getattr, false}, - {"readdir", &wsfsp_readdir, false}, - {"open", &wsfsp_open, false}, - {"close", &wsfsp_close, true}, - {"read", &wsfsp_read, false} - }; - static size_t const count = sizeof(methods) / sizeof(methods[0]); - - for (size_t i = 0; i < count; i++) - { - struct wsfsp_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_provider_init( - struct wsfsp_provider * provider) -{ - provider->lookup = &wsfsp_lookup_default; - provider->getattr = &wsfsp_getattr_default; - provider->readdir = &wsfsp_readdir_default; - provider->open = &wsfsp_open_default; - provider->close = &wsfsp_close_default; - provider->read = &wsfsp_read_default; - provider->connected = &wsfsp_connected_default; - provider->disconnected = &wsfsp_disconnected_default; - provider->ontimer = &wsfsp_ontimer_default; -} - -void wsfsp_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_provider_invoke( - struct wsfsp_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_provider_invoke_method(context, method, params, id); - } -} - -void wsfsp_connected_default( - void * user_data) -{ - (void) user_data; - - // empty -} - -void wsfsp_disconnected_default( - void * user_data) -{ - (void) user_data; - - // empty -} - -void wsfsp_ontimer_default( - void * user_data) -{ - (void) user_data; - - // empty -} \ No newline at end of file diff --git a/lib/wsfs/provider/request.h b/lib/wsfs/provider/request.h deleted file mode 100644 index 157a5f7..0000000 --- a/lib/wsfs/provider/request.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef WSFS_PROVIDER_REQUEST_H -#define WSFS_PROVIDER_REQUEST_H - -#include -#include "wsfs/provider/provider.h" - -typedef void wsfsp_request_respond_fn( - json_t * response, - void * user_data); - -struct wsfsp_request -{ - wsfsp_request_respond_fn * respond; - void * user_data; - int id; -}; - - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern struct wsfsp_request * wsfsp_request_create( - struct wsfsp_request * prototype, - int id); - -extern void wsfsp_request_dispose( - struct wsfsp_request * request); - -extern void wsfsp_respond( - struct wsfsp_request * request, - json_t * result); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test/mock_authenticator.hpp b/test/mock_authenticator.hpp index ef5d909..1660fc9 100644 --- a/test/mock_authenticator.hpp +++ b/test/mock_authenticator.hpp @@ -2,7 +2,7 @@ #define MOCK_AUTHENTICATOR_H #include -#include "wsfs/adapter/authenticator.h" +#include "wsfs/adapter/impl/authenticator.h" namespace wsfs_test { diff --git a/test/test_authenticator.cc b/test/test_authenticator.cc index 71989f2..e2249ce 100644 --- a/test/test_authenticator.cc +++ b/test/test_authenticator.cc @@ -3,8 +3,8 @@ #include "mock_authenticator.hpp" -#include "wsfs/adapter/authenticator.h" -#include "wsfs/adapter/credentials_intern.h" +#include "wsfs/adapter/impl/authenticator.h" +#include "wsfs/adapter/impl/credentials.h" using ::testing::Return; using ::testing::_; @@ -20,7 +20,7 @@ TEST(Authenticator, Authenticate) set_authenticator(&mock); struct wsfs_credentials creds; - wsfs_credentials_init(&creds, "username", nullptr); + wsfs_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_authenticator * authenticator = wsfs_authenticator_create( + struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create( "username", &authenticate, user_data); - bool result = wsfs_authenticator_autenticate(authenticator, &creds); + bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds); ASSERT_TRUE(result); - wsfs_authenticator_dispose(authenticator); - wsfs_credentials_cleanup(&creds); + wsfs_impl_authenticator_dispose(authenticator); + wsfs_impl_credentials_cleanup(&creds); } TEST(Authenticator, SkipAuthenticationWithWrongType) @@ -46,18 +46,18 @@ TEST(Authenticator, SkipAuthenticationWithWrongType) set_authenticator(&mock); struct wsfs_credentials creds; - wsfs_credentials_init(&creds, "username", nullptr); + wsfs_impl_credentials_init(&creds, "username", nullptr); EXPECT_CALL(mock, authenticate(_, _)) .Times(0); - struct wsfs_authenticator * authenticator = wsfs_authenticator_create( + struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create( "certificate", &authenticate, nullptr); - bool result = wsfs_authenticator_autenticate(authenticator, &creds); + bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds); ASSERT_FALSE(result); - wsfs_authenticator_dispose(authenticator); - wsfs_credentials_cleanup(&creds); + wsfs_impl_authenticator_dispose(authenticator); + wsfs_impl_credentials_cleanup(&creds); } \ No newline at end of file diff --git a/test/test_authenticators.cc b/test/test_authenticators.cc index 6c7c021..2030da7 100644 --- a/test/test_authenticators.cc +++ b/test/test_authenticators.cc @@ -1,8 +1,8 @@ #include #include -#include "wsfs/adapter/authenticators.h" -#include "wsfs/adapter/credentials_intern.h" +#include "wsfs/adapter/impl/authenticators.h" +#include "wsfs/adapter/impl/credentials.h" #include "mock_authenticator.hpp" using ::testing::_; @@ -16,71 +16,71 @@ using ::wsfs_test::authenticate_2; TEST(Authenticators, CloneEmpty) { - struct wsfs_authenticators authenticators; - struct wsfs_authenticators clone; + struct wsfs_impl_authenticators authenticators; + struct wsfs_impl_authenticators clone; - wsfs_authenticators_init(&authenticators); + wsfs_impl_authenticators_init(&authenticators); ASSERT_EQ(nullptr, authenticators.first); - wsfs_authenticators_clone(&authenticators, &clone); + wsfs_impl_authenticators_clone(&authenticators, &clone); ASSERT_EQ(nullptr, clone.first); - wsfs_authenticators_cleanup(&authenticators); - wsfs_authenticators_cleanup(&clone); + wsfs_impl_authenticators_cleanup(&authenticators); + wsfs_impl_authenticators_cleanup(&clone); } TEST(Authenticators, Clone) { - struct wsfs_authenticators authenticators; - struct wsfs_authenticators clone; + struct wsfs_impl_authenticators authenticators; + struct wsfs_impl_authenticators clone; - wsfs_authenticators_init(&authenticators); - wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr); + wsfs_impl_authenticators_init(&authenticators); + wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); ASSERT_NE(nullptr, authenticators.first); - wsfs_authenticators_clone(&authenticators, &clone); + wsfs_impl_authenticators_clone(&authenticators, &clone); ASSERT_NE(nullptr, clone.first); ASSERT_NE(nullptr, authenticators.first); ASSERT_NE(authenticators.first, clone.first); - wsfs_authenticators_cleanup(&authenticators); - wsfs_authenticators_cleanup(&clone); + wsfs_impl_authenticators_cleanup(&authenticators); + wsfs_impl_authenticators_cleanup(&clone); } TEST(Authenticators, Move) { - struct wsfs_authenticators authenticators; - struct wsfs_authenticators clone; + struct wsfs_impl_authenticators authenticators; + struct wsfs_impl_authenticators clone; - wsfs_authenticators_init(&authenticators); - wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr); + wsfs_impl_authenticators_init(&authenticators); + wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); ASSERT_NE(nullptr, authenticators.first); - wsfs_authenticators_move(&authenticators, &clone); + wsfs_impl_authenticators_move(&authenticators, &clone); ASSERT_NE(nullptr, clone.first); ASSERT_EQ(nullptr, authenticators.first); ASSERT_NE(authenticators.first, clone.first); - wsfs_authenticators_cleanup(&authenticators); - wsfs_authenticators_cleanup(&clone); + wsfs_impl_authenticators_cleanup(&authenticators); + wsfs_impl_authenticators_cleanup(&clone); } TEST(Authenticators, AuthenticateWithoutAuthenticators) { struct wsfs_credentials creds; - wsfs_credentials_init(&creds, "username", nullptr); + wsfs_impl_credentials_init(&creds, "username", nullptr); - struct wsfs_authenticators authenticators; - wsfs_authenticators_init(&authenticators); + struct wsfs_impl_authenticators authenticators; + wsfs_impl_authenticators_init(&authenticators); - bool result = wsfs_authenticators_authenticate(&authenticators, &creds); + bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds); ASSERT_TRUE(result); - result = wsfs_authenticators_authenticate(&authenticators, nullptr); + result = wsfs_impl_authenticators_authenticate(&authenticators, nullptr); ASSERT_TRUE(result); - wsfs_authenticators_cleanup(&authenticators); - wsfs_credentials_cleanup(&creds); + wsfs_impl_authenticators_cleanup(&authenticators); + wsfs_impl_credentials_cleanup(&creds); } TEST(Authenticators, FailToAuthenticateWithoutCredentials) @@ -88,20 +88,20 @@ TEST(Authenticators, FailToAuthenticateWithoutCredentials) MockAuthenticator mock; set_authenticator(&mock); - struct wsfs_authenticators authenticators; - wsfs_authenticators_init(&authenticators); - wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr); + struct wsfs_impl_authenticators authenticators; + wsfs_impl_authenticators_init(&authenticators); + wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr); - bool result = wsfs_authenticators_authenticate(&authenticators, nullptr); + bool result = wsfs_impl_authenticators_authenticate(&authenticators, nullptr); ASSERT_FALSE(result); - wsfs_authenticators_cleanup(&authenticators); + wsfs_impl_authenticators_cleanup(&authenticators); } TEST(Authenticators, AuthenticateWithMultipleCredentials) { struct wsfs_credentials creds; - wsfs_credentials_init(&creds, "username", nullptr); + wsfs_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_authenticators authenticators; - wsfs_authenticators_init(&authenticators); - wsfs_authenticators_add(&authenticators, "username", &authenticate_1, nullptr); - wsfs_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr); + 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); - bool result = wsfs_authenticators_authenticate(&authenticators, &creds); + bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds); ASSERT_TRUE(result); - wsfs_authenticators_cleanup(&authenticators); - wsfs_credentials_cleanup(&creds); + wsfs_impl_authenticators_cleanup(&authenticators); + wsfs_impl_credentials_cleanup(&creds); } TEST(Authenticators, FailedAuthenticateWithWrongType) { struct wsfs_credentials creds; - wsfs_credentials_init(&creds, "token", nullptr); + wsfs_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_authenticators authenticators; - wsfs_authenticators_init(&authenticators); - wsfs_authenticators_add(&authenticators, "username", &authenticate_1, nullptr); - wsfs_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr); + 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); - bool result = wsfs_authenticators_authenticate(&authenticators, &creds); + bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds); ASSERT_FALSE(result); - wsfs_authenticators_cleanup(&authenticators); - wsfs_credentials_cleanup(&creds); + wsfs_impl_authenticators_cleanup(&authenticators); + wsfs_impl_credentials_cleanup(&creds); } diff --git a/test/test_credentials.cc b/test/test_credentials.cc index 9862d78..1599d20 100644 --- a/test/test_credentials.cc +++ b/test/test_credentials.cc @@ -1,15 +1,15 @@ #include -#include "wsfs/adapter/credentials_intern.h" +#include "wsfs/adapter/impl/credentials.h" #include TEST(Credentials, Type) { struct wsfs_credentials creds; - wsfs_credentials_init(&creds, "test", nullptr); - ASSERT_STREQ("test", wsfs_credentials_type(&creds)); - wsfs_credentials_cleanup(&creds); + wsfs_impl_credentials_init(&creds, "test", nullptr); + ASSERT_STREQ("test", wsfs_impl_credentials_type(&creds)); + wsfs_impl_credentials_cleanup(&creds); } TEST(Credentials, Get) @@ -19,12 +19,12 @@ TEST(Credentials, Get) json_object_set_new(data, "username", json_string("bob")); json_object_set_new(data, "password", json_string("")); - wsfs_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wsfs_credentials_type(&creds)); - ASSERT_STREQ("bob", wsfs_credentials_get(&creds, "username")); - ASSERT_STREQ("", wsfs_credentials_get(&creds, "password")); + 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")); - wsfs_credentials_cleanup(&creds); + wsfs_impl_credentials_cleanup(&creds); json_decref(data); } @@ -33,12 +33,12 @@ TEST(Credentials, FailedToGetNonexistingValue) struct wsfs_credentials creds; json_t * data = json_object(); - wsfs_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wsfs_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password")); + 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")); - wsfs_credentials_cleanup(&creds); + wsfs_impl_credentials_cleanup(&creds); json_decref(data); } @@ -46,12 +46,12 @@ TEST(Credentials, FailedToGetWithoutData) { struct wsfs_credentials creds; - wsfs_credentials_init(&creds, "username", nullptr); - ASSERT_STREQ("username", wsfs_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password")); + 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")); - wsfs_credentials_cleanup(&creds); + wsfs_impl_credentials_cleanup(&creds); } TEST(Credentials, FailedToGetWrongDataType) @@ -59,12 +59,12 @@ TEST(Credentials, FailedToGetWrongDataType) struct wsfs_credentials creds; json_t * data = json_string("invalid_creds"); - wsfs_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wsfs_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password")); + 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")); - wsfs_credentials_cleanup(&creds); + wsfs_impl_credentials_cleanup(&creds); json_decref(data); } diff --git a/test/test_response_parser.cc b/test/test_response_parser.cc index cf73c4e..4e14e7a 100644 --- a/test/test_response_parser.cc +++ b/test/test_response_parser.cc @@ -1,59 +1,59 @@ #include #include -#include "wsfs/adapter/jsonrpc/response.h" +#include "wsfs/adapter/impl/jsonrpc/response.h" -static void wsfs_response_parse_str( +static void response_parse_str( std::string const & buffer, - struct wsfs_jsonrpc_response * response) + struct wsfs_impl_jsonrpc_response * response) { - wsfs_jsonrpc_response_init(response, buffer.c_str(), buffer.size()); + wsfs_impl_jsonrpc_response_init(response, buffer.c_str(), buffer.size()); } TEST(response_parser, test) { - struct wsfs_jsonrpc_response response; + struct wsfs_impl_jsonrpc_response response; // invalid json - wsfs_response_parse_str("", &response); + response_parse_str("", &response); ASSERT_NE(WSFS_GOOD, response.status); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); // invalid json - wsfs_response_parse_str("invalid_json", &response); + response_parse_str("invalid_json", &response); ASSERT_NE(WSFS_GOOD, response.status); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); // no object - wsfs_response_parse_str("[]", &response); + response_parse_str("[]", &response); ASSERT_NE(WSFS_GOOD, response.status); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); // empty - wsfs_response_parse_str("{}", &response); + response_parse_str("{}", &response); ASSERT_NE(WSFS_GOOD, response.status); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); // no data - wsfs_response_parse_str("{\"id\":42}", &response); + response_parse_str("{\"id\":42}", &response); ASSERT_NE(WSFS_GOOD, response.status); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); // custom error code - wsfs_response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); + response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); ASSERT_NE(WSFS_GOOD, response.status); ASSERT_EQ(42, response.status); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); // valid response - wsfs_response_parse_str("{\"result\": true, \"id\": 42}", &response); + response_parse_str("{\"result\": true, \"id\": 42}", &response); ASSERT_EQ(WSFS_GOOD, response.status); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); diff --git a/test/test_timepoint.cc b/test/test_timepoint.cc index 2a4dc19..d395fb2 100644 --- a/test/test_timepoint.cc +++ b/test/test_timepoint.cc @@ -1,15 +1,15 @@ #include #include "msleep.hpp" -#include "wsfs/adapter/time/timepoint.h" +#include "wsfs/adapter/impl/time/timepoint.h" using wsfs_test::msleep; TEST(timepoint, now) { - wsfs_timepoint start = wsfs_timepoint_now(); + wsfs_impl_timepoint start = wsfs_impl_timepoint_now(); msleep(42); - wsfs_timepoint end = wsfs_timepoint_now(); + wsfs_impl_timepoint end = wsfs_impl_timepoint_now(); ASSERT_LT(start, end); ASSERT_LT(end, start + 500); @@ -17,20 +17,20 @@ TEST(timepoint, now) TEST(timepoint, in_msec) { - wsfs_timepoint now = wsfs_timepoint_now(); - wsfs_timepoint later = wsfs_timepoint_in_msec(42); + wsfs_impl_timepoint now = wsfs_impl_timepoint_now(); + wsfs_impl_timepoint later = wsfs_impl_timepoint_in_msec(42); ASSERT_LT(now, later); ASSERT_LT(later, now + 500); } -TEST(timepoint, elapsed) +TEST(wsfs_impl_timepoint, elapsed) { - wsfs_timepoint now; + wsfs_impl_timepoint now; - now = wsfs_timepoint_now(); - ASSERT_TRUE(wsfs_timepoint_is_elapsed(now - 1)); + now = wsfs_impl_timepoint_now(); + ASSERT_TRUE(wsfs_impl_timepoint_is_elapsed(now - 1)); - now = wsfs_timepoint_now(); - ASSERT_FALSE(wsfs_timepoint_is_elapsed(now + 500)); + now =wsfs_impl_timepoint_now(); + ASSERT_FALSE(wsfs_impl_timepoint_is_elapsed(now + 500)); } diff --git a/test/test_timer.cc b/test/test_timer.cc index 8b3cac7..66592e0 100644 --- a/test/test_timer.cc +++ b/test/test_timer.cc @@ -3,15 +3,15 @@ #include #include "msleep.hpp" -#include "wsfs/adapter/time/timer.h" -#include "wsfs/adapter/time/timeout_manager.h" +#include "wsfs/adapter/impl/time/timer.h" +#include "wsfs/adapter/impl/time/timeout_manager.h" using std::size_t; using wsfs_test::msleep; namespace { - void on_timeout(struct wsfs_timer * timer) + void on_timeout(struct wsfs_impl_timer * timer) { bool * triggered = reinterpret_cast(timer->user_data); *triggered = true; @@ -20,82 +20,82 @@ namespace TEST(timer, init) { - struct wsfs_timeout_manager manager; - struct wsfs_timer timer; + struct wsfs_impl_timeout_manager manager; + struct wsfs_impl_timer timer; - wsfs_timeout_manager_init(&manager); - wsfs_timer_init(&timer, &manager); + wsfs_impl_timeout_manager_init(&manager); + wsfs_impl_timer_init(&timer, &manager); - wsfs_timer_cleanup(&timer); - wsfs_timeout_manager_cleanup(&manager); + wsfs_impl_timer_cleanup(&timer); + wsfs_impl_timeout_manager_cleanup(&manager); } TEST(timer, trigger) { - struct wsfs_timeout_manager manager; - struct wsfs_timer timer; + struct wsfs_impl_timeout_manager manager; + struct wsfs_impl_timer timer; - wsfs_timeout_manager_init(&manager); - wsfs_timer_init(&timer, &manager); + wsfs_impl_timeout_manager_init(&manager); + wsfs_impl_timer_init(&timer, &manager); bool triggered = false; - wsfs_timer_start(&timer, wsfs_timepoint_in_msec(250), &on_timeout, reinterpret_cast(&triggered)); + wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast(&triggered)); msleep(500); - wsfs_timeout_manager_check(&manager); + wsfs_impl_timeout_manager_check(&manager); ASSERT_TRUE(triggered); - wsfs_timer_cleanup(&timer); - wsfs_timeout_manager_cleanup(&manager); + wsfs_impl_timer_cleanup(&timer); + wsfs_impl_timeout_manager_cleanup(&manager); } TEST(timer, cancel) { - struct wsfs_timeout_manager manager; - struct wsfs_timer timer; + struct wsfs_impl_timeout_manager manager; + struct wsfs_impl_timer timer; - wsfs_timeout_manager_init(&manager); - wsfs_timer_init(&timer, &manager); + wsfs_impl_timeout_manager_init(&manager); + wsfs_impl_timer_init(&timer, &manager); bool triggered = false; - wsfs_timer_start(&timer, wsfs_timepoint_in_msec(250), &on_timeout, &triggered); + wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, &triggered); msleep(500); - wsfs_timer_cancel(&timer); - wsfs_timeout_manager_check(&manager); + wsfs_impl_timer_cancel(&timer); + wsfs_impl_timeout_manager_check(&manager); ASSERT_FALSE(triggered); - wsfs_timer_cleanup(&timer); - wsfs_timeout_manager_cleanup(&manager); + wsfs_impl_timer_cleanup(&timer); + wsfs_impl_timeout_manager_cleanup(&manager); } TEST(timer, multiple_timers) { static size_t const count = 5; - struct wsfs_timeout_manager manager; - struct wsfs_timer timer[count]; + struct wsfs_impl_timeout_manager manager; + struct wsfs_impl_timer timer[count]; bool triggered[count]; - wsfs_timeout_manager_init(&manager); + wsfs_impl_timeout_manager_init(&manager); for(size_t i = 0; i < count; i++) { - wsfs_timer_init(&timer[i], &manager); + wsfs_impl_timer_init(&timer[i], &manager); triggered[i] = false; - wsfs_timer_start(&timer[i], wsfs_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]); + wsfs_impl_timer_start(&timer[i], wsfs_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]); } for(size_t i = 0; i < count; i++) { msleep(100); - wsfs_timeout_manager_check(&manager); + wsfs_impl_timeout_manager_check(&manager); } for(size_t i = 0; i < count; i++) { ASSERT_TRUE(triggered[i]); - wsfs_timer_cleanup(&timer[i]); + wsfs_impl_timer_cleanup(&timer[i]); } - wsfs_timeout_manager_cleanup(&manager); + wsfs_impl_timeout_manager_cleanup(&manager); } diff --git a/test/test_url.cc b/test/test_url.cc index 243f86e..fe2a517 100644 --- a/test/test_url.cc +++ b/test/test_url.cc @@ -1,69 +1,69 @@ #include -#include "wsfs/provider/url.h" +#include "wsfs/provider/impl/url.h" TEST(url, ParseWs) { - struct wsfsp_url url; - bool result = wsfsp_url_init(&url, "ws://localhost/"); + struct wsfsp_impl_url url; + bool result = wsfsp_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_url_cleanup(&url); + wsfsp_impl_url_cleanup(&url); } TEST(url, ParswWss) { - struct wsfsp_url url; - bool result = wsfsp_url_init(&url, "wss://localhost/"); + struct wsfsp_impl_url url; + bool result = wsfsp_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_url_cleanup(&url); + wsfsp_impl_url_cleanup(&url); } TEST(url, ParseIPAdress) { - struct wsfsp_url url; - bool result = wsfsp_url_init(&url, "ws://127.0.0.1/"); + struct wsfsp_impl_url url; + bool result = wsfsp_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_url_cleanup(&url); + wsfsp_impl_url_cleanup(&url); } TEST(url, ParsePort) { - struct wsfsp_url url; - bool result = wsfsp_url_init(&url, "ws://localhost:54321/"); + struct wsfsp_impl_url url; + bool result = wsfsp_impl_url_init(&url, "ws://localhost:54321/"); ASSERT_TRUE(result); ASSERT_EQ(54321, url.port); - wsfsp_url_cleanup(&url); + wsfsp_impl_url_cleanup(&url); } TEST(url, ParseNonEmptyPath) { - struct wsfsp_url url; - bool result = wsfsp_url_init(&url, "ws://localhost/some_path?query"); + struct wsfsp_impl_url url; + bool result = wsfsp_impl_url_init(&url, "ws://localhost/some_path?query"); ASSERT_TRUE(result); ASSERT_STREQ("/some_path?query", url.path); - wsfsp_url_cleanup(&url); + wsfsp_impl_url_cleanup(&url); } TEST(url, FailToParseUnknownProtocol) { - struct wsfsp_url url; - bool result = wsfsp_url_init(&url, "unknown://localhost/"); + struct wsfsp_impl_url url; + bool result = wsfsp_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_url url; - bool result = wsfsp_url_init(&url, "unknown"); + struct wsfsp_impl_url url; + bool result = wsfsp_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_url url; - bool result = wsfsp_url_init(&url, "ws://localhost"); + struct wsfsp_impl_url url; + bool result = wsfsp_impl_url_init(&url, "ws://localhost"); ASSERT_FALSE(result); ASSERT_EQ(0, url.port); ASSERT_EQ(nullptr, url.path);