mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
Merge pull request #60 from falk-werner/investigate_coverage
Investigate coverage
This commit is contained in:
commit
cd0c4a5213
14
.travis.yml
14
.travis.yml
@ -12,18 +12,18 @@ addons:
|
|||||||
- qemu-user-static
|
- qemu-user-static
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- DISTRO=ubuntu
|
|
||||||
- PARALLELMFLAGS="-j4"
|
- PARALLELMFLAGS="-j4"
|
||||||
- PORTABLE_WORSPACE=1
|
- PORTABLE_WORSPACE=1
|
||||||
matrix:
|
matrix:
|
||||||
- BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck
|
- DISTRO=ubuntu BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck
|
||||||
- BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=check
|
- DISTRO=ubuntu BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=check
|
||||||
- BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck
|
- DISTRO=ubuntu BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck
|
||||||
- BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check
|
- DISTRO=ubuntu BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check
|
||||||
- BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check
|
- DISTRO=ubuntu BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check
|
||||||
|
- DISTRO=alpine BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=check
|
||||||
before_script:
|
before_script:
|
||||||
- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH
|
- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH
|
||||||
script:
|
script:
|
||||||
- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET
|
- make DISTRO=$DISTRO BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET
|
||||||
after_success:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
@ -37,8 +37,6 @@ add_compile_options(
|
|||||||
"-pthread"
|
"-pthread"
|
||||||
)
|
)
|
||||||
|
|
||||||
include(wf_timer)
|
|
||||||
include(wf_jsonrpc)
|
|
||||||
include(webfuse_core)
|
include(webfuse_core)
|
||||||
include(webfuse_adapter)
|
include(webfuse_adapter)
|
||||||
include(webfuse_provider)
|
include(webfuse_provider)
|
||||||
|
@ -58,6 +58,7 @@ RUN set -x \
|
|||||||
&& mkdir -p "$builddir" \
|
&& mkdir -p "$builddir" \
|
||||||
&& cd "$builddir" \
|
&& cd "$builddir" \
|
||||||
&& meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \
|
&& meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \
|
||||||
|
&& meson configure -Dexamples=false \
|
||||||
&& ninja \
|
&& ninja \
|
||||||
&& ninja install \
|
&& ninja install \
|
||||||
&& pip3 uninstall -y meson \
|
&& pip3 uninstall -y meson \
|
||||||
|
@ -61,6 +61,7 @@ RUN set -x \
|
|||||||
&& mkdir -p "$builddir" \
|
&& mkdir -p "$builddir" \
|
||||||
&& cd "$builddir" \
|
&& cd "$builddir" \
|
||||||
&& meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \
|
&& meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \
|
||||||
|
&& meson configure -Dexamples=false \
|
||||||
&& ninja \
|
&& ninja \
|
||||||
&& ninja install \
|
&& ninja install \
|
||||||
&& pip3 uninstall -y meson \
|
&& pip3 uninstall -y meson \
|
||||||
|
@ -1,31 +1,42 @@
|
|||||||
if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER)
|
if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER)
|
||||||
|
|
||||||
|
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1")
|
||||||
include (CTest)
|
include (CTest)
|
||||||
|
|
||||||
|
add_executable(fs_check
|
||||||
|
test/webfuse/tests/integration/fs_check.c
|
||||||
|
)
|
||||||
|
|
||||||
pkg_check_modules(GTEST gtest_main)
|
pkg_check_modules(GTEST gtest_main)
|
||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
pkg_check_modules(GMOCK gmock)
|
pkg_check_modules(GMOCK gmock)
|
||||||
|
|
||||||
add_executable(alltests
|
add_executable(alltests
|
||||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc
|
test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc
|
||||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc
|
test/webfuse/tests/core/jsonrpc/mock_timer.cc
|
||||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc
|
test/webfuse/tests/core/jsonrpc/test_is_request.cc
|
||||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc
|
test/webfuse/tests/core/jsonrpc/test_request.cc
|
||||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc
|
test/webfuse/tests/core/jsonrpc/test_is_response.cc
|
||||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc
|
test/webfuse/tests/core/jsonrpc/test_response.cc
|
||||||
lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc
|
test/webfuse/tests/core/jsonrpc/test_server.cc
|
||||||
lib/wf/timer/test/wf/timer/test_timepoint.cc
|
test/webfuse/tests/core/jsonrpc/test_proxy.cc
|
||||||
lib/wf/timer/test/wf/timer/test_timer.cc
|
test/webfuse/tests/core/jsonrpc/test_response_parser.cc
|
||||||
|
test/webfuse/tests/core/timer/test_timepoint.cc
|
||||||
|
test/webfuse/tests/core/timer/test_timer.cc
|
||||||
test/webfuse/utils/tempdir.cc
|
test/webfuse/utils/tempdir.cc
|
||||||
test/webfuse/utils/file_utils.cc
|
test/webfuse/utils/file_utils.cc
|
||||||
test/webfuse/utils/die_if.cc
|
|
||||||
test/webfuse/utils/timeout_watcher.cc
|
test/webfuse/utils/timeout_watcher.cc
|
||||||
test/webfuse/utils/path.c
|
test/webfuse/utils/path.c
|
||||||
test/webfuse/utils/static_filesystem.c
|
test/webfuse/utils/static_filesystem.c
|
||||||
test/webfuse/utils/ws_server.cc
|
test/webfuse/utils/ws_server.cc
|
||||||
|
test/webfuse/mocks/fake_invokation_context.cc
|
||||||
test/webfuse/mocks/mock_authenticator.cc
|
test/webfuse/mocks/mock_authenticator.cc
|
||||||
test/webfuse/mocks/mock_request.cc
|
test/webfuse/mocks/mock_request.cc
|
||||||
test/webfuse/mocks/mock_provider_client.cc
|
test/webfuse/mocks/mock_provider_client.cc
|
||||||
|
test/webfuse/mocks/mock_provider.cc
|
||||||
|
test/webfuse/mocks/mock_fuse.cc
|
||||||
|
test/webfuse/mocks/mock_operation_context.cc
|
||||||
|
test/webfuse/mocks/mock_jsonrpc_proxy.cc
|
||||||
test/webfuse//tests/core/test_util.cc
|
test/webfuse//tests/core/test_util.cc
|
||||||
test/webfuse/tests/core/test_container_of.cc
|
test/webfuse/tests/core/test_container_of.cc
|
||||||
test/webfuse/tests/core/test_string.cc
|
test/webfuse/tests/core/test_string.cc
|
||||||
@ -41,31 +52,50 @@ add_executable(alltests
|
|||||||
test/webfuse/tests/adapter/test_authenticators.cc
|
test/webfuse/tests/adapter/test_authenticators.cc
|
||||||
test/webfuse/tests/adapter/test_mountpoint.cc
|
test/webfuse/tests/adapter/test_mountpoint.cc
|
||||||
test/webfuse/tests/adapter/test_fuse_req.cc
|
test/webfuse/tests/adapter/test_fuse_req.cc
|
||||||
|
test/webfuse/tests/adapter/operation/test_context.cc
|
||||||
|
test/webfuse/tests/adapter/operation/test_open.cc
|
||||||
|
test/webfuse/tests/adapter/operation/test_close.cc
|
||||||
|
test/webfuse/tests/adapter/operation/test_read.cc
|
||||||
|
test/webfuse/tests/adapter/operation/test_readdir.cc
|
||||||
|
test/webfuse/tests/adapter/operation/test_getattr.cc
|
||||||
|
test/webfuse/tests/adapter/operation/test_lookup.cc
|
||||||
test/webfuse/tests/provider/test_url.cc
|
test/webfuse/tests/provider/test_url.cc
|
||||||
test/webfuse/tests/provider/test_client_protocol.cc
|
test/webfuse/tests/provider/test_client_protocol.cc
|
||||||
|
test/webfuse/tests/provider/operation/test_close.cc
|
||||||
|
test/webfuse/tests/provider/operation/test_getattr.cc
|
||||||
|
test/webfuse/tests/provider/operation/test_lookup.cc
|
||||||
|
test/webfuse/tests/provider/operation/test_open.cc
|
||||||
|
test/webfuse/tests/provider/operation/test_read.cc
|
||||||
|
test/webfuse/tests/provider/operation/test_readdir.cc
|
||||||
|
test/webfuse/tests/integration/test_lowlevel.cc
|
||||||
test/webfuse/tests/integration/test_integration.cc
|
test/webfuse/tests/integration/test_integration.cc
|
||||||
|
test/webfuse/tests/integration/file.cc
|
||||||
test/webfuse/tests/integration/server.cc
|
test/webfuse/tests/integration/server.cc
|
||||||
test/webfuse/tests/integration/provider.cc
|
test/webfuse/tests/integration/provider.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(alltests PRIVATE
|
|
||||||
lib/wf/jsonrpc/include
|
|
||||||
lib/wf/jsonrpc/src
|
|
||||||
lib/wf/timer/include
|
|
||||||
lib/wf/timer/src
|
|
||||||
${FUSE3_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_options(alltests PUBLIC
|
|
||||||
${FUSE3_CFLAGS_OTHER}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(alltests PUBLIC
|
target_link_libraries(alltests PUBLIC
|
||||||
|
-Wl,--wrap=wf_timer_manager_create
|
||||||
|
-Wl,--wrap=wf_timer_manager_dispose
|
||||||
|
-Wl,--wrap=wf_timer_manager_check
|
||||||
|
-Wl,--wrap=wf_timer_create
|
||||||
|
-Wl,--wrap=wf_timer_dispose
|
||||||
|
-Wl,--wrap=wf_timer_start
|
||||||
|
-Wl,--wrap=wf_timer_cancel
|
||||||
|
-Wl,--wrap=wf_impl_operation_context_get_proxy
|
||||||
|
-Wl,--wrap=wf_jsonrpc_proxy_vinvoke
|
||||||
|
-Wl,--wrap=wf_jsonrpc_proxy_vnotify
|
||||||
|
-Wl,--wrap=fuse_req_userdata
|
||||||
|
-Wl,--wrap=fuse_reply_open
|
||||||
|
-Wl,--wrap=fuse_reply_err
|
||||||
|
-Wl,--wrap=fuse_reply_buf
|
||||||
|
-Wl,--wrap=fuse_reply_attr
|
||||||
|
-Wl,--wrap=fuse_reply_entry
|
||||||
|
-Wl,--wrap=fuse_req_ctx
|
||||||
|
|
||||||
webfuse-adapter-static
|
webfuse-adapter-static
|
||||||
webfuse-provider-static
|
webfuse-provider-static
|
||||||
webfuse-core
|
webfuse-core
|
||||||
wf_jsonrpc
|
|
||||||
wf_timer
|
|
||||||
${FUSE3_LIBRARIES}
|
${FUSE3_LIBRARIES}
|
||||||
${LWS_LIBRARIES}
|
${LWS_LIBRARIES}
|
||||||
${JANSSON_LIBRARIES}
|
${JANSSON_LIBRARIES}
|
||||||
@ -74,8 +104,16 @@ target_link_libraries(alltests PUBLIC
|
|||||||
${GTEST_LIBRARIES}
|
${GTEST_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(alltests PUBLIC test lib ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS})
|
target_include_directories(alltests PUBLIC test lib ${FUSE3_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS})
|
||||||
target_compile_options(alltests PUBLIC ${GMOCK_CFLAGS} ${GTEST_CFLAGS})
|
target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} ${GMOCK_CFLAGS} ${GTEST_CFLAGS})
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT server-key.pem
|
||||||
|
COMMAND openssl req -x509 -newkey rsa:4096 -keyout server-key.pem -out server-cert.pem -days 365 -nodes -batch -subj '/CN=localhost'
|
||||||
|
COMMAND openssl req -x509 -newkey rsa:4096 -keyout client-key.pem -out client-cert.pem -days 365 -nodes -batch -subj '/CN=localhost'
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(gen-tls DEPENDS server-key.pem)
|
||||||
|
add_dependencies(alltests gen-tls)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
gtest_discover_tests(alltests TEST_PREFIX alltests:)
|
gtest_discover_tests(alltests TEST_PREFIX alltests:)
|
||||||
@ -91,7 +129,7 @@ add_custom_target(coverage
|
|||||||
add_dependencies(coverage alltests)
|
add_dependencies(coverage alltests)
|
||||||
|
|
||||||
add_custom_target(coverage-report
|
add_custom_target(coverage-report
|
||||||
COMMAND genhtml --branch-coverage --highlight --legend --prefix "${CMAKE_SOURCE_DIR}" coverage/lcov.info --output-directory coverage/report
|
COMMAND genhtml --branch-coverage --highlight --legend coverage/lcov.info --output-directory coverage/report
|
||||||
)
|
)
|
||||||
add_dependencies(coverage-report coverage)
|
add_dependencies(coverage-report coverage)
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@ add_library(webfuse-adapter-static STATIC
|
|||||||
lib/webfuse/adapter/impl/authenticator.c
|
lib/webfuse/adapter/impl/authenticator.c
|
||||||
lib/webfuse/adapter/impl/authenticators.c
|
lib/webfuse/adapter/impl/authenticators.c
|
||||||
lib/webfuse/adapter/impl/credentials.c
|
lib/webfuse/adapter/impl/credentials.c
|
||||||
lib/webfuse/adapter/impl/operations.c
|
|
||||||
lib/webfuse/adapter/impl/mountpoint.c
|
lib/webfuse/adapter/impl/mountpoint.c
|
||||||
lib/webfuse/adapter/impl/mountpoint_factory.c
|
lib/webfuse/adapter/impl/mountpoint_factory.c
|
||||||
|
lib/webfuse/adapter/impl/operation/context.c
|
||||||
lib/webfuse/adapter/impl/operation/lookup.c
|
lib/webfuse/adapter/impl/operation/lookup.c
|
||||||
lib/webfuse/adapter/impl/operation/getattr.c
|
lib/webfuse/adapter/impl/operation/getattr.c
|
||||||
lib/webfuse/adapter/impl/operation/readdir.c
|
lib/webfuse/adapter/impl/operation/readdir.c
|
||||||
@ -26,8 +26,6 @@ add_library(webfuse-adapter-static STATIC
|
|||||||
|
|
||||||
target_include_directories(webfuse-adapter-static PRIVATE
|
target_include_directories(webfuse-adapter-static PRIVATE
|
||||||
lib
|
lib
|
||||||
lib/wf/timer/include
|
|
||||||
lib/wf/jsonrpc/include
|
|
||||||
${FUSE3_INCLUDE_DIRS}
|
${FUSE3_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -56,7 +54,7 @@ set_target_properties(webfuse-adapter PROPERTIES SOVERSION 0)
|
|||||||
set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden)
|
set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden)
|
||||||
set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT")
|
set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT")
|
||||||
|
|
||||||
target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core wf_jsonrpc wf_timer)
|
target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core)
|
||||||
|
|
||||||
file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc"
|
file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc"
|
||||||
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
|
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
|
||||||
|
@ -9,6 +9,17 @@ add_library(webfuse-core STATIC
|
|||||||
lib/webfuse/core/base64.c
|
lib/webfuse/core/base64.c
|
||||||
lib/webfuse/core/lws_log.c
|
lib/webfuse/core/lws_log.c
|
||||||
lib/webfuse/core/json_util.c
|
lib/webfuse/core/json_util.c
|
||||||
|
lib/webfuse/core/timer/manager.c
|
||||||
|
lib/webfuse/core/timer/timepoint.c
|
||||||
|
lib/webfuse/core/timer/timer.c
|
||||||
|
lib/webfuse/core/jsonrpc/proxy.c
|
||||||
|
lib/webfuse/core/jsonrpc/proxy_variadic.c
|
||||||
|
lib/webfuse/core/jsonrpc/server.c
|
||||||
|
lib/webfuse/core/jsonrpc/method.c
|
||||||
|
lib/webfuse/core/jsonrpc/request.c
|
||||||
|
lib/webfuse/core/jsonrpc/response.c
|
||||||
|
lib/webfuse/core/jsonrpc/error.c
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core)
|
set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core)
|
||||||
|
@ -22,8 +22,6 @@ set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-pro
|
|||||||
set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden)
|
set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden)
|
||||||
target_include_directories(webfuse-provider-static PRIVATE
|
target_include_directories(webfuse-provider-static PRIVATE
|
||||||
lib
|
lib
|
||||||
lib/wf/timer/include
|
|
||||||
lib/wf/jsonrpc/include
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(webfuse-provider SHARED
|
add_library(webfuse-provider SHARED
|
||||||
@ -36,7 +34,7 @@ set_target_properties(webfuse-provider PROPERTIES C_VISIBILITY_PRESET hidden)
|
|||||||
set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT")
|
set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT")
|
||||||
|
|
||||||
target_include_directories(webfuse-provider PUBLIC lib)
|
target_include_directories(webfuse-provider PUBLIC lib)
|
||||||
target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core wf_jsonrpc wf_timer)
|
target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core)
|
||||||
|
|
||||||
file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc"
|
file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc"
|
||||||
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
|
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
# wf_jsonrpc
|
|
||||||
|
|
||||||
add_library(wf_jsonrpc STATIC
|
|
||||||
lib/wf/jsonrpc/src/wf/jsonrpc/api.c
|
|
||||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c
|
|
||||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c
|
|
||||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c
|
|
||||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c
|
|
||||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c
|
|
||||||
lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(wf_jsonrpc PUBLIC wf_timer)
|
|
||||||
|
|
||||||
target_include_directories(wf_jsonrpc PRIVATE
|
|
||||||
lib/wf/timer/include
|
|
||||||
lib/wf/jsonrpc/src
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(wf_jsonrpc PUBLIC
|
|
||||||
lib/wf/jsonrpc/include
|
|
||||||
)
|
|
||||||
|
|
||||||
set_target_properties(wf_jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden)
|
|
@ -1,18 +0,0 @@
|
|||||||
# timer
|
|
||||||
|
|
||||||
add_library(wf_timer STATIC
|
|
||||||
lib/wf/timer/src/wf/timer/api.c
|
|
||||||
lib/wf/timer/src/wf/timer/impl/manager.c
|
|
||||||
lib/wf/timer/src/wf/timer/impl/timepoint.c
|
|
||||||
lib/wf/timer/src/wf/timer/impl/timer.c
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(wf_timer PRIVATE
|
|
||||||
lib/wf/timer/src
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(wf_timer PUBLIC
|
|
||||||
lib/wf/timer/include
|
|
||||||
)
|
|
||||||
|
|
||||||
set_target_properties(wf_timer PROPERTIES C_VISIBILITY_PRESET hidden)
|
|
10
codecov.yml
10
codecov.yml
@ -1,2 +1,12 @@
|
|||||||
ignore:
|
ignore:
|
||||||
- test
|
- test
|
||||||
|
- lib/wf/timer/test
|
||||||
|
- lib/wf/jsonrpc/test
|
||||||
|
|
||||||
|
parsers:
|
||||||
|
gcov:
|
||||||
|
branch_detection:
|
||||||
|
conditional: yes
|
||||||
|
loop: yes
|
||||||
|
method: yes
|
||||||
|
macro: yes
|
||||||
|
@ -108,6 +108,19 @@ extern WFP_API void wfp_client_config_set_certpath(
|
|||||||
struct wfp_client_config * config,
|
struct wfp_client_config * config,
|
||||||
char const * cert_path);
|
char const * cert_path);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/// \brief Sets the path of ca file to verify servers.
|
||||||
|
///
|
||||||
|
/// \note To enable TLS both, private key and certificate, must be specified.
|
||||||
|
/// Otherwise, TLS is not used.
|
||||||
|
///
|
||||||
|
/// \param config pointer to client configuration
|
||||||
|
/// \param ca_filepath path of the ca file (pem file)
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
extern WFP_API void wfp_client_config_set_ca_filepath(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
char const * ca_filepath);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/// \brief Sets the onconnected handler.
|
/// \brief Sets the onconnected handler.
|
||||||
///
|
///
|
||||||
|
@ -11,13 +11,10 @@ struct wf_impl_authenticator * wf_impl_authenticator_create(
|
|||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator));
|
struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator));
|
||||||
if (NULL != authenticator)
|
authenticator->type = strdup(type);
|
||||||
{
|
authenticator->authenticate = authenticate;
|
||||||
authenticator->type = strdup(type);
|
authenticator->user_data = user_data;
|
||||||
authenticator->authenticate = authenticate;
|
authenticator->next = NULL;
|
||||||
authenticator->user_data = user_data;
|
|
||||||
authenticator->next = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return authenticator;
|
return authenticator;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
#include "webfuse/adapter/impl/filesystem.h"
|
#include "webfuse/adapter/impl/filesystem.h"
|
||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/open.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/close.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/read.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/readdir.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/getattr.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/lookup.h"
|
||||||
#include "webfuse/adapter/impl/session.h"
|
#include "webfuse/adapter/impl/session.h"
|
||||||
#include "webfuse/adapter/impl/mountpoint.h"
|
#include "webfuse/adapter/impl/mountpoint.h"
|
||||||
|
|
||||||
@ -99,14 +105,11 @@ struct wf_impl_filesystem * wf_impl_filesystem_create(
|
|||||||
struct wf_mountpoint * mountpoint)
|
struct wf_mountpoint * mountpoint)
|
||||||
{
|
{
|
||||||
struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem));
|
struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem));
|
||||||
if (NULL != filesystem)
|
bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint);
|
||||||
|
if (!success)
|
||||||
{
|
{
|
||||||
bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint);
|
free(filesystem);
|
||||||
if (!success)
|
filesystem = NULL;
|
||||||
{
|
|
||||||
free(filesystem);
|
|
||||||
filesystem = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return filesystem;
|
return filesystem;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
#include "webfuse/core/slist.h"
|
#include "webfuse/core/slist.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -24,7 +24,7 @@ struct wf_impl_filesystem
|
|||||||
struct fuse_args args;
|
struct fuse_args args;
|
||||||
struct fuse_session * session;
|
struct fuse_session * session;
|
||||||
struct fuse_buf buffer;
|
struct fuse_buf buffer;
|
||||||
struct wf_impl_operations_context user_data;
|
struct wf_impl_operation_context user_data;
|
||||||
struct lws * wsi;
|
struct lws * wsi;
|
||||||
struct wf_mountpoint * mountpoint;
|
struct wf_mountpoint * mountpoint;
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/close.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
|
|
||||||
void wf_impl_operation_close(
|
void wf_impl_operation_close(
|
||||||
@ -12,8 +13,8 @@ void wf_impl_operation_close(
|
|||||||
fuse_ino_t inode,
|
fuse_ino_t inode,
|
||||||
struct fuse_file_info * file_info)
|
struct fuse_file_info * file_info)
|
||||||
{
|
{
|
||||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||||
|
|
||||||
if (NULL != rpc)
|
if (NULL != rpc)
|
||||||
{
|
{
|
||||||
|
20
lib/webfuse/adapter/impl/operation/close.h
Normal file
20
lib/webfuse/adapter/impl/operation/close.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef WF_ADAPTER_IMPL_OPERATION_CLOSE_H
|
||||||
|
#define WF_ADAPTER_IMPL_OPERATION_CLOSE_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void wf_impl_operation_close(
|
||||||
|
fuse_req_t request,
|
||||||
|
fuse_ino_t inode,
|
||||||
|
struct fuse_file_info * file_info);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,10 +1,10 @@
|
|||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
#include "webfuse/adapter/impl/session_manager.h"
|
#include "webfuse/adapter/impl/session_manager.h"
|
||||||
#include "webfuse/adapter/impl/session.h"
|
#include "webfuse/adapter/impl/session.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy(
|
||||||
struct wf_impl_operations_context * context)
|
struct wf_impl_operation_context * context)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_proxy * proxy = NULL;
|
struct wf_jsonrpc_proxy * proxy = NULL;
|
||||||
|
|
28
lib/webfuse/adapter/impl/operation/context.h
Normal file
28
lib/webfuse/adapter/impl/operation/context.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef WF_ADAPTER_IMPL_OPERATION_CONTEXT_H
|
||||||
|
#define WF_ADAPTER_IMPL_OPERATION_CONTEXT_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_impl_session;
|
||||||
|
struct wf_jsonrpc_proxy;
|
||||||
|
|
||||||
|
struct wf_impl_operation_context
|
||||||
|
{
|
||||||
|
struct wf_impl_session * session;
|
||||||
|
double timeout;
|
||||||
|
char * name;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy(
|
||||||
|
struct wf_impl_operation_context * context);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/getattr.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -7,20 +8,11 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "webfuse/core/json_util.h"
|
#include "webfuse/core/json_util.h"
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
|
|
||||||
struct wf_impl_operation_getattr_context
|
void wf_impl_operation_getattr_finished(
|
||||||
{
|
|
||||||
fuse_req_t request;
|
|
||||||
fuse_ino_t inode;
|
|
||||||
double timeout;
|
|
||||||
uid_t uid;
|
|
||||||
gid_t gid;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void wf_impl_operation_getattr_finished(
|
|
||||||
void * user_data,
|
void * user_data,
|
||||||
json_t const * result,
|
json_t const * result,
|
||||||
json_t const * error)
|
json_t const * error)
|
||||||
@ -33,8 +25,7 @@ static void wf_impl_operation_getattr_finished(
|
|||||||
{
|
{
|
||||||
json_t * mode_holder = json_object_get(result, "mode");
|
json_t * mode_holder = json_object_get(result, "mode");
|
||||||
json_t * type_holder = json_object_get(result, "type");
|
json_t * type_holder = json_object_get(result, "type");
|
||||||
if ((NULL != mode_holder) && (json_is_integer(mode_holder)) &&
|
if ((json_is_integer(mode_holder)) && (json_is_string(type_holder)))
|
||||||
(NULL != type_holder) && (json_is_string(type_holder)))
|
|
||||||
{
|
{
|
||||||
memset(&buffer, 0, sizeof(struct stat));
|
memset(&buffer, 0, sizeof(struct stat));
|
||||||
|
|
||||||
@ -82,8 +73,8 @@ void wf_impl_operation_getattr (
|
|||||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||||
{
|
{
|
||||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||||
|
|
||||||
if (NULL != rpc)
|
if (NULL != rpc)
|
||||||
{
|
{
|
||||||
|
37
lib/webfuse/adapter/impl/operation/getattr.h
Normal file
37
lib/webfuse/adapter/impl/operation/getattr.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef WF_ADAPTER_IMPL_OPERATION_GETATTR_H
|
||||||
|
#define WF_ADAPTER_IMPL_OPERATION_GETATTR_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
|
|
||||||
|
#include <jansson.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_impl_operation_getattr_context
|
||||||
|
{
|
||||||
|
fuse_req_t request;
|
||||||
|
fuse_ino_t inode;
|
||||||
|
double timeout;
|
||||||
|
uid_t uid;
|
||||||
|
gid_t gid;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void wf_impl_operation_getattr_finished(
|
||||||
|
void * user_data,
|
||||||
|
json_t const * result,
|
||||||
|
json_t const * error);
|
||||||
|
|
||||||
|
extern void wf_impl_operation_getattr (
|
||||||
|
fuse_req_t request,
|
||||||
|
fuse_ino_t inode,
|
||||||
|
struct fuse_file_info *file_info);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/lookup.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -10,19 +11,11 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "webfuse/core/json_util.h"
|
#include "webfuse/core/json_util.h"
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
|
|
||||||
struct wf_impl_operation_lookup_context
|
void wf_impl_operation_lookup_finished(
|
||||||
{
|
|
||||||
fuse_req_t request;
|
|
||||||
double timeout;
|
|
||||||
uid_t uid;
|
|
||||||
gid_t gid;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void wf_impl_operation_lookup_finished(
|
|
||||||
void * user_data,
|
void * user_data,
|
||||||
json_t const * result,
|
json_t const * result,
|
||||||
json_t const * error
|
json_t const * error
|
||||||
@ -37,9 +30,9 @@ static void wf_impl_operation_lookup_finished(
|
|||||||
json_t * inode_holder = json_object_get(result, "inode");
|
json_t * inode_holder = json_object_get(result, "inode");
|
||||||
json_t * mode_holder = json_object_get(result, "mode");
|
json_t * mode_holder = json_object_get(result, "mode");
|
||||||
json_t * type_holder = json_object_get(result, "type");
|
json_t * type_holder = json_object_get(result, "type");
|
||||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)) &&
|
if ((json_is_integer(inode_holder)) &&
|
||||||
(NULL != mode_holder) && (json_is_integer(mode_holder)) &&
|
(json_is_integer(mode_holder)) &&
|
||||||
(NULL != type_holder) && (json_is_string(type_holder)))
|
(json_is_string(type_holder)))
|
||||||
{
|
{
|
||||||
memset(&buffer, 0, sizeof(struct stat));
|
memset(&buffer, 0, sizeof(struct stat));
|
||||||
|
|
||||||
@ -91,8 +84,8 @@ void wf_impl_operation_lookup (
|
|||||||
char const * name)
|
char const * name)
|
||||||
{
|
{
|
||||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||||
|
|
||||||
if (NULL != rpc)
|
if (NULL != rpc)
|
||||||
{
|
{
|
||||||
|
36
lib/webfuse/adapter/impl/operation/lookup.h
Normal file
36
lib/webfuse/adapter/impl/operation/lookup.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef WF_ADAPTER_IMPL_OPERATION_LOOKUP_H
|
||||||
|
#define WF_ADAPTER_IMPL_OPERATION_LOOKUP_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
|
|
||||||
|
#include <jansson.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_impl_operation_lookup_context
|
||||||
|
{
|
||||||
|
fuse_req_t request;
|
||||||
|
double timeout;
|
||||||
|
uid_t uid;
|
||||||
|
gid_t gid;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void wf_impl_operation_lookup_finished(
|
||||||
|
void * user_data,
|
||||||
|
json_t const * result,
|
||||||
|
json_t const * error);
|
||||||
|
|
||||||
|
extern void wf_impl_operation_lookup (
|
||||||
|
fuse_req_t req,
|
||||||
|
fuse_ino_t parent,
|
||||||
|
char const * name);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,15 +1,15 @@
|
|||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/open.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include <errno.h>
|
|
||||||
#include <jansson.h>
|
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy.h"
|
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
#include "webfuse/core/status.h"
|
#include "webfuse/core/status.h"
|
||||||
#include "webfuse/core/json_util.h"
|
#include "webfuse/core/json_util.h"
|
||||||
|
|
||||||
static void wf_impl_operation_open_finished(
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
void wf_impl_operation_open_finished(
|
||||||
void * user_data,
|
void * user_data,
|
||||||
json_t const * result,
|
json_t const * result,
|
||||||
json_t const * error)
|
json_t const * error)
|
||||||
@ -22,7 +22,7 @@ static void wf_impl_operation_open_finished(
|
|||||||
if (NULL != result)
|
if (NULL != result)
|
||||||
{
|
{
|
||||||
json_t * handle_holder = json_object_get(result, "handle");
|
json_t * handle_holder = json_object_get(result, "handle");
|
||||||
if ((NULL != handle_holder) && (json_is_integer(handle_holder)))
|
if (json_is_integer(handle_holder))
|
||||||
{
|
{
|
||||||
file_info.fh = json_integer_value(handle_holder);
|
file_info.fh = json_integer_value(handle_holder);
|
||||||
}
|
}
|
||||||
@ -48,8 +48,8 @@ void wf_impl_operation_open(
|
|||||||
fuse_ino_t inode,
|
fuse_ino_t inode,
|
||||||
struct fuse_file_info * file_info)
|
struct fuse_file_info * file_info)
|
||||||
{
|
{
|
||||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||||
|
|
||||||
if (NULL != rpc)
|
if (NULL != rpc)
|
||||||
{
|
{
|
||||||
|
26
lib/webfuse/adapter/impl/operation/open.h
Normal file
26
lib/webfuse/adapter/impl/operation/open.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef WF_ADAPTER_IMPL_OPERATION_OPEN_H
|
||||||
|
#define WF_ADAPTER_IMPL_OPERATION_OPEN_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
|
#include <jansson.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void wf_impl_operation_open(
|
||||||
|
fuse_req_t request,
|
||||||
|
fuse_ino_t inode,
|
||||||
|
struct fuse_file_info * file_info);
|
||||||
|
|
||||||
|
extern void wf_impl_operation_open_finished(
|
||||||
|
void * user_data,
|
||||||
|
json_t const * result,
|
||||||
|
json_t const * error);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,18 +1,20 @@
|
|||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/read.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "webfuse/core/base64.h"
|
#include "webfuse/core/base64.h"
|
||||||
#include "webfuse/core/json_util.h"
|
#include "webfuse/core/json_util.h"
|
||||||
|
|
||||||
#define WF_MAX_READ_LENGTH 4096
|
#define WF_MAX_READ_LENGTH 4096
|
||||||
|
|
||||||
static char * wf_impl_fill_buffer(
|
char * wf_impl_fill_buffer(
|
||||||
char const * data,
|
char const * data,
|
||||||
|
size_t data_size,
|
||||||
char const * format,
|
char const * format,
|
||||||
size_t count,
|
size_t count,
|
||||||
wf_status * status)
|
wf_status * status)
|
||||||
@ -20,15 +22,26 @@ static char * wf_impl_fill_buffer(
|
|||||||
*status = WF_GOOD;
|
*status = WF_GOOD;
|
||||||
char * buffer = malloc(count);
|
char * buffer = malloc(count);
|
||||||
|
|
||||||
if ((NULL != buffer) && (0 < count))
|
if (0 < count)
|
||||||
{
|
{
|
||||||
if (0 == strcmp("identity", format))
|
if (0 == strcmp("identity", format))
|
||||||
{
|
{
|
||||||
memcpy(buffer, data, count);
|
if (count == data_size)
|
||||||
|
{
|
||||||
|
memcpy(buffer, data, count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*status = WF_BAD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (0 == strcmp("base64", format))
|
else if (0 == strcmp("base64", format))
|
||||||
{
|
{
|
||||||
wf_base64_decode(data, strlen(data), (uint8_t *) buffer, count);
|
size_t result = wf_base64_decode(data, data_size, (uint8_t *) buffer, count);
|
||||||
|
if (result != count)
|
||||||
|
{
|
||||||
|
*status = WF_BAD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -36,10 +49,16 @@ static char * wf_impl_fill_buffer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (WF_GOOD != *status)
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
buffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wf_impl_operation_read_finished(
|
void wf_impl_operation_read_finished(
|
||||||
void * user_data,
|
void * user_data,
|
||||||
json_t const * result,
|
json_t const * result,
|
||||||
json_t const * error)
|
json_t const * error)
|
||||||
@ -60,10 +79,11 @@ static void wf_impl_operation_read_finished(
|
|||||||
json_is_integer(count_holder))
|
json_is_integer(count_holder))
|
||||||
{
|
{
|
||||||
char const * const data = json_string_value(data_holder);
|
char const * const data = json_string_value(data_holder);
|
||||||
|
size_t const data_size = json_string_length(data_holder);
|
||||||
char const * const format = json_string_value(format_holder);
|
char const * const format = json_string_value(format_holder);
|
||||||
length = (size_t) json_integer_value(count_holder);
|
length = (size_t) json_integer_value(count_holder);
|
||||||
|
|
||||||
buffer = wf_impl_fill_buffer(data, format, length, &status);
|
buffer = wf_impl_fill_buffer(data, data_size, format, length, &status);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -91,8 +111,8 @@ void wf_impl_operation_read(
|
|||||||
off_t offset,
|
off_t offset,
|
||||||
struct fuse_file_info * file_info)
|
struct fuse_file_info * file_info)
|
||||||
{
|
{
|
||||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||||
|
|
||||||
if (NULL != rpc)
|
if (NULL != rpc)
|
||||||
{
|
{
|
||||||
|
36
lib/webfuse/adapter/impl/operation/read.h
Normal file
36
lib/webfuse/adapter/impl/operation/read.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef WF_ADAPTER_IMPL_OPERATION_READ_H
|
||||||
|
#define WF_ADAPTER_IMPL_OPERATION_READ_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
|
#include "webfuse/core/status.h"
|
||||||
|
|
||||||
|
#include <jansson.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void wf_impl_operation_read(
|
||||||
|
fuse_req_t request,
|
||||||
|
fuse_ino_t ino, size_t size, off_t off,
|
||||||
|
struct fuse_file_info *fi);
|
||||||
|
|
||||||
|
extern char * wf_impl_fill_buffer(
|
||||||
|
char const * data,
|
||||||
|
size_t data_size,
|
||||||
|
char const * format,
|
||||||
|
size_t count,
|
||||||
|
wf_status * status);
|
||||||
|
|
||||||
|
extern void wf_impl_operation_read_finished(
|
||||||
|
void * user_data,
|
||||||
|
json_t const * result,
|
||||||
|
json_t const * error);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
#include "webfuse/adapter/impl/operations.h"
|
#include "webfuse/adapter/impl/operation/readdir.h"
|
||||||
|
#include "webfuse/adapter/impl/operation/context.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -8,20 +9,13 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
#include "webfuse/core/json_util.h"
|
#include "webfuse/core/json_util.h"
|
||||||
|
|
||||||
|
|
||||||
#define WF_DIRBUFFER_INITIAL_SIZE 1024
|
#define WF_DIRBUFFER_INITIAL_SIZE 1024
|
||||||
|
|
||||||
struct wf_impl_operation_readdir_context
|
|
||||||
{
|
|
||||||
fuse_req_t request;
|
|
||||||
size_t size;
|
|
||||||
off_t offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct wf_impl_dirbuffer
|
struct wf_impl_dirbuffer
|
||||||
{
|
{
|
||||||
char * data;
|
char * data;
|
||||||
@ -72,7 +66,7 @@ static size_t wf_impl_min(size_t a, size_t b)
|
|||||||
return (a < b) ? a : b;
|
return (a < b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wf_impl_operation_readdir_finished(
|
void wf_impl_operation_readdir_finished(
|
||||||
void * user_data,
|
void * user_data,
|
||||||
json_t const * result,
|
json_t const * result,
|
||||||
json_t const * error)
|
json_t const * error)
|
||||||
@ -83,31 +77,40 @@ static void wf_impl_operation_readdir_finished(
|
|||||||
struct wf_impl_dirbuffer buffer;
|
struct wf_impl_dirbuffer buffer;
|
||||||
wf_impl_dirbuffer_init(&buffer);
|
wf_impl_dirbuffer_init(&buffer);
|
||||||
|
|
||||||
if (NULL != result)
|
if (json_is_array(result))
|
||||||
{
|
{
|
||||||
if (json_is_array(result))
|
size_t const count = json_array_size(result);
|
||||||
|
for(size_t i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
bool buffer_full = false;
|
json_t * entry =json_array_get(result, i);
|
||||||
size_t const count = json_array_size(result);
|
if (json_is_object(entry))
|
||||||
for(size_t i = 0; (!buffer_full) && (i < count); i++)
|
|
||||||
{
|
{
|
||||||
json_t * entry =json_array_get(result, i);
|
json_t * name_holder = json_object_get(entry, "name");
|
||||||
if (json_is_object(entry))
|
json_t * inode_holder = json_object_get(entry, "inode");
|
||||||
{
|
|
||||||
json_t * name_holder = json_object_get(entry, "name");
|
|
||||||
json_t * inode_holder = json_object_get(entry, "inode");
|
|
||||||
|
|
||||||
if ((NULL != name_holder) && (json_is_string(name_holder)) &&
|
if ((json_is_string(name_holder)) && (json_is_integer(inode_holder)))
|
||||||
(NULL != inode_holder) && (json_is_integer(inode_holder)))
|
{
|
||||||
{
|
char const * name = json_string_value(name_holder);
|
||||||
char const * name = json_string_value(name_holder);
|
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
|
||||||
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
|
wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
|
||||||
wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
status = WF_BAD_FORMAT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = WF_BAD_FORMAT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (WF_GOOD == status)
|
||||||
|
{
|
||||||
|
status = WF_BAD_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
if (WF_GOOD == status)
|
if (WF_GOOD == status)
|
||||||
{
|
{
|
||||||
@ -138,8 +141,8 @@ void wf_impl_operation_readdir (
|
|||||||
off_t offset,
|
off_t offset,
|
||||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||||
{
|
{
|
||||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||||
|
|
||||||
if (NULL != rpc)
|
if (NULL != rpc)
|
||||||
{
|
{
|
||||||
|
35
lib/webfuse/adapter/impl/operation/readdir.h
Normal file
35
lib/webfuse/adapter/impl/operation/readdir.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef WF_ADAPTER_IMPL_OPERATION_READDIR_H
|
||||||
|
#define WF_ADAPTER_IMPL_OPERATION_READDIR_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
|
#include <jansson.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_impl_operation_readdir_context
|
||||||
|
{
|
||||||
|
fuse_req_t request;
|
||||||
|
size_t size;
|
||||||
|
off_t offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void wf_impl_operation_readdir (
|
||||||
|
fuse_req_t request,
|
||||||
|
fuse_ino_t inode,
|
||||||
|
size_t size,
|
||||||
|
off_t offset,
|
||||||
|
struct fuse_file_info *file_info);
|
||||||
|
|
||||||
|
extern void wf_impl_operation_readdir_finished(
|
||||||
|
void * user_data,
|
||||||
|
json_t const * result,
|
||||||
|
json_t const * error);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,60 +0,0 @@
|
|||||||
#ifndef WF_ADAPTER_IMPL_OPERATIONS_H
|
|
||||||
#define WF_ADAPTER_IMPL_OPERATIONS_H
|
|
||||||
|
|
||||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wf_impl_session;
|
|
||||||
struct wf_jsonrpc_proxy;
|
|
||||||
|
|
||||||
struct wf_impl_operations_context
|
|
||||||
{
|
|
||||||
struct wf_impl_session * session;
|
|
||||||
double timeout;
|
|
||||||
char * name;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern void wf_impl_operation_lookup (
|
|
||||||
fuse_req_t req,
|
|
||||||
fuse_ino_t parent,
|
|
||||||
char const * name);
|
|
||||||
|
|
||||||
extern void wf_impl_operation_getattr (
|
|
||||||
fuse_req_t request,
|
|
||||||
fuse_ino_t inode,
|
|
||||||
struct fuse_file_info *file_info);
|
|
||||||
|
|
||||||
extern void wf_impl_operation_readdir (
|
|
||||||
fuse_req_t request,
|
|
||||||
fuse_ino_t inode,
|
|
||||||
size_t size,
|
|
||||||
off_t offset,
|
|
||||||
struct fuse_file_info *file_info);
|
|
||||||
|
|
||||||
extern void wf_impl_operation_open(
|
|
||||||
fuse_req_t request,
|
|
||||||
fuse_ino_t inode,
|
|
||||||
struct fuse_file_info * file_info);
|
|
||||||
|
|
||||||
extern void wf_impl_operation_close(
|
|
||||||
fuse_req_t request,
|
|
||||||
fuse_ino_t inode,
|
|
||||||
struct fuse_file_info * file_info);
|
|
||||||
|
|
||||||
extern void wf_impl_operation_read(
|
|
||||||
fuse_req_t request,
|
|
||||||
fuse_ino_t ino, size_t size, off_t off,
|
|
||||||
struct fuse_file_info *fi);
|
|
||||||
|
|
||||||
extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
|
||||||
struct wf_impl_operations_context * context);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -83,13 +83,10 @@ struct wf_server * wf_impl_server_create(
|
|||||||
if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory))
|
if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory))
|
||||||
{
|
{
|
||||||
server = malloc(sizeof(struct wf_server));
|
server = malloc(sizeof(struct wf_server));
|
||||||
if (NULL != server)
|
wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory);
|
||||||
{
|
wf_impl_server_config_clone(config, &server->config);
|
||||||
wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory);
|
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
||||||
wf_impl_server_config_clone(config, &server->config);
|
server->context = wf_impl_server_context_create(server);
|
||||||
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
|
||||||
server->context = wf_impl_server_context_create(server);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
|
@ -56,10 +56,7 @@ void wf_impl_server_config_clone(
|
|||||||
struct wf_server_config * wf_impl_server_config_create(void)
|
struct wf_server_config * wf_impl_server_config_create(void)
|
||||||
{
|
{
|
||||||
struct wf_server_config * config = malloc(sizeof(struct wf_server_config));
|
struct wf_server_config * config = malloc(sizeof(struct wf_server_config));
|
||||||
if (NULL != config)
|
wf_impl_server_config_init(config);
|
||||||
{
|
|
||||||
wf_impl_server_config_init(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
#include "webfuse/adapter/impl/credentials.h"
|
#include "webfuse/adapter/impl/credentials.h"
|
||||||
#include "webfuse/core/status_intern.h"
|
#include "webfuse/core/status_intern.h"
|
||||||
|
|
||||||
#include "wf/jsonrpc/request.h"
|
#include "webfuse/core/jsonrpc/request.h"
|
||||||
#include "wf/timer/manager.h"
|
#include "webfuse/core/timer/manager.h"
|
||||||
#include "wf/timer/timer.h"
|
#include "webfuse/core/timer/timer.h"
|
||||||
|
|
||||||
static int wf_impl_server_protocol_callback(
|
static int wf_impl_server_protocol_callback(
|
||||||
struct lws * wsi,
|
struct lws * wsi,
|
||||||
@ -23,13 +23,10 @@ static int wf_impl_server_protocol_callback(
|
|||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||||
if (NULL == ws_protocol)
|
if (NULL == ws_protocol) { return 0; }
|
||||||
{
|
if (ws_protocol->callback != &wf_impl_server_protocol_callback) { return 0; }
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wf_server_protocol * protocol = ws_protocol->user;
|
struct wf_server_protocol * protocol = ws_protocol->user;
|
||||||
|
|
||||||
wf_timer_manager_check(protocol->timer_manager);
|
wf_timer_manager_check(protocol->timer_manager);
|
||||||
struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi);
|
struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi);
|
||||||
|
|
||||||
@ -85,14 +82,11 @@ struct wf_server_protocol * wf_impl_server_protocol_create(
|
|||||||
void * create_mountpoint_context)
|
void * create_mountpoint_context)
|
||||||
{
|
{
|
||||||
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
|
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
|
||||||
if (NULL != protocol)
|
struct wf_impl_mountpoint_factory mountpoint_factory;
|
||||||
{
|
wf_impl_mountpoint_factory_init(&mountpoint_factory,
|
||||||
struct wf_impl_mountpoint_factory mountpoint_factory;
|
create_mountpoint, create_mountpoint_context);
|
||||||
wf_impl_mountpoint_factory_init(&mountpoint_factory,
|
|
||||||
create_mountpoint, create_mountpoint_context);
|
|
||||||
|
|
||||||
wf_impl_server_protocol_init(protocol, &mountpoint_factory);
|
wf_impl_server_protocol_init(protocol, &mountpoint_factory);
|
||||||
}
|
|
||||||
|
|
||||||
return protocol;
|
return protocol;
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
#include "webfuse/adapter/impl/authenticators.h"
|
#include "webfuse/adapter/impl/authenticators.h"
|
||||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||||
#include "webfuse/adapter/impl/session_manager.h"
|
#include "webfuse/adapter/impl/session_manager.h"
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "wf/jsonrpc/server.h"
|
#include "webfuse/core/jsonrpc/server.h"
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
#include "webfuse/core/container_of.h"
|
#include "webfuse/core/container_of.h"
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "wf/jsonrpc/request.h"
|
#include "webfuse/core/jsonrpc/request.h"
|
||||||
#include "wf/jsonrpc/response.h"
|
#include "webfuse/core/jsonrpc/response.h"
|
||||||
|
|
||||||
#include <libwebsockets.h>
|
#include <libwebsockets.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -51,18 +51,15 @@ struct wf_impl_session * wf_impl_session_create(
|
|||||||
{
|
{
|
||||||
|
|
||||||
struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session));
|
struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session));
|
||||||
if (NULL != session)
|
wf_slist_init(&session->filesystems);
|
||||||
{
|
|
||||||
wf_slist_init(&session->filesystems);
|
|
||||||
|
|
||||||
session->wsi = wsi;
|
session->wsi = wsi;
|
||||||
session->is_authenticated = false;
|
session->is_authenticated = false;
|
||||||
session->authenticators = authenticators;
|
session->authenticators = authenticators;
|
||||||
session->server = server;
|
session->server = server;
|
||||||
session->mountpoint_factory = mountpoint_factory;
|
session->mountpoint_factory = mountpoint_factory;
|
||||||
session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||||
wf_slist_init(&session->messages);
|
wf_slist_init(&session->messages);
|
||||||
}
|
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ using std::size_t;
|
|||||||
#include "webfuse/adapter/impl/filesystem.h"
|
#include "webfuse/adapter/impl/filesystem.h"
|
||||||
#include "webfuse/core/slist.h"
|
#include "webfuse/core/slist.h"
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "wf/jsonrpc/server.h"
|
#include "webfuse/core/jsonrpc/server.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
|
@ -33,10 +33,7 @@ struct wf_impl_session * wf_impl_session_manager_add(
|
|||||||
{
|
{
|
||||||
struct wf_impl_session * session = wf_impl_session_create(
|
struct wf_impl_session * session = wf_impl_session_create(
|
||||||
wsi, authenticators, timer_manager, server, mountpoint_factory);
|
wsi, authenticators, timer_manager, server, mountpoint_factory);
|
||||||
if (NULL != session)
|
wf_slist_append(&manager->sessions, &session->item);
|
||||||
{
|
|
||||||
wf_slist_append(&manager->sessions, &session->item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "webfuse/core/json_util.h"
|
#include "webfuse/core/json_util.h"
|
||||||
#include "wf/jsonrpc/status.h"
|
|
||||||
|
|
||||||
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
||||||
{
|
{
|
||||||
@ -14,25 +13,6 @@ int wf_impl_json_get_int(json_t const * object, char const * key, int default_va
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static wf_status wf_impl_jsonrc_code_to_status(int code)
|
|
||||||
{
|
|
||||||
switch (code)
|
|
||||||
{
|
|
||||||
case WF_JSONRPC_GOOD:
|
|
||||||
return WF_GOOD;
|
|
||||||
case WF_JSONRPC_BAD:
|
|
||||||
return WF_BAD;
|
|
||||||
case WF_JSONRPC_BAD_BUSY:
|
|
||||||
return WF_BAD_BUSY;
|
|
||||||
case WF_JSONRPC_BAD_TIMEOUT:
|
|
||||||
return WF_BAD_TIMEOUT;
|
|
||||||
case WF_JSONRPC_BAD_FORMAT:
|
|
||||||
return WF_BAD_FORMAT;
|
|
||||||
default:
|
|
||||||
return (wf_status) code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wf_status
|
wf_status
|
||||||
wf_impl_jsonrpc_get_status(
|
wf_impl_jsonrpc_get_status(
|
||||||
json_t const * error)
|
json_t const * error)
|
||||||
@ -40,8 +20,7 @@ wf_impl_jsonrpc_get_status(
|
|||||||
wf_status status = WF_GOOD;
|
wf_status status = WF_GOOD;
|
||||||
if (NULL != error)
|
if (NULL != error)
|
||||||
{
|
{
|
||||||
int code = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT);
|
status = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT);
|
||||||
status = wf_impl_jsonrc_code_to_status(code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "wf/jsonrpc/impl/error.h"
|
#include "webfuse/core/jsonrpc/error.h"
|
||||||
|
|
||||||
json_t *
|
json_t *
|
||||||
wf_jsonrpc_impl_error(
|
wf_jsonrpc_error(
|
||||||
int code,
|
int code,
|
||||||
char const * message)
|
char const * message)
|
||||||
{
|
{
|
||||||
@ -13,13 +13,13 @@ wf_jsonrpc_impl_error(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wf_jsonrpc_impl_propate_error(
|
wf_jsonrpc_propate_error(
|
||||||
wf_jsonrpc_proxy_finished_fn * finised,
|
wf_jsonrpc_proxy_finished_fn * finised,
|
||||||
void * user_data,
|
void * user_data,
|
||||||
int code,
|
int code,
|
||||||
char const * message)
|
char const * message)
|
||||||
{
|
{
|
||||||
json_t * error = wf_jsonrpc_impl_error(code, message);
|
json_t * error = wf_jsonrpc_error(code, message);
|
||||||
finised(user_data, NULL, error);
|
finised(user_data, NULL, error);
|
||||||
|
|
||||||
json_decref(error);
|
json_decref(error);
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef WF_JSONRPC_IMPL_ERROR_H
|
#ifndef WF_JSONRPC_ERROR_H
|
||||||
#define WF_JSONRPC_IMPL_ERROR_H
|
#define WF_JSONRPC_ERROR_H
|
||||||
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include "wf/jsonrpc/proxy_finished_fn.h"
|
#include "webfuse/core/jsonrpc/proxy_finished_fn.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -10,12 +10,12 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern json_t *
|
extern json_t *
|
||||||
wf_jsonrpc_impl_error(
|
wf_jsonrpc_error(
|
||||||
int code,
|
int code,
|
||||||
char const * message);
|
char const * message);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
wf_jsonrpc_impl_propate_error(
|
wf_jsonrpc_propate_error(
|
||||||
wf_jsonrpc_proxy_finished_fn * finised,
|
wf_jsonrpc_proxy_finished_fn * finised,
|
||||||
void * user_data,
|
void * user_data,
|
||||||
int code,
|
int code,
|
@ -1,25 +1,22 @@
|
|||||||
#include "wf/jsonrpc/impl/method.h"
|
#include "webfuse/core/jsonrpc/method.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create(
|
struct wf_jsonrpc_method * wf_jsonrpc_method_create(
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
wf_jsonrpc_method_invoke_fn * invoke,
|
wf_jsonrpc_method_invoke_fn * invoke,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method));
|
struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method));
|
||||||
if (NULL != method)
|
method->next = NULL;
|
||||||
{
|
method->name = strdup(method_name);
|
||||||
method->next = NULL;
|
method->invoke = invoke;
|
||||||
method->name = strdup(method_name);
|
method->user_data = user_data;
|
||||||
method->invoke = invoke;
|
|
||||||
method->user_data = user_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_jsonrpc_impl_method_dispose(
|
void wf_jsonrpc_method_dispose(
|
||||||
struct wf_jsonrpc_method * method)
|
struct wf_jsonrpc_method * method)
|
||||||
{
|
{
|
||||||
free(method->name);
|
free(method->name);
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef WF_JSONRPC_IMPL_METHOD_H
|
#ifndef WF_JSONRPC_METHOD_H
|
||||||
#define WF_JSONRPC_IMPL_METHOD_H
|
#define WF_JSONRPC_METHOD_H
|
||||||
|
|
||||||
#include "wf/jsonrpc/method_invoke_fn.h"
|
#include "webfuse/core/jsonrpc/method_invoke_fn.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -17,13 +17,13 @@ struct wf_jsonrpc_method
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern struct wf_jsonrpc_method *
|
extern struct wf_jsonrpc_method *
|
||||||
wf_jsonrpc_impl_method_create(
|
wf_jsonrpc_method_create(
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
wf_jsonrpc_method_invoke_fn * invoke,
|
wf_jsonrpc_method_invoke_fn * invoke,
|
||||||
void * user_data);
|
void * user_data);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
wf_jsonrpc_impl_method_dispose(
|
wf_jsonrpc_method_dispose(
|
||||||
struct wf_jsonrpc_method * method);
|
struct wf_jsonrpc_method * method);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef WF_JSONRPC_METHOD_INVOKE_FN_H
|
#ifndef WF_JSONRPC_METHOD_INVOKE_FN_H
|
||||||
#define WF_JSONRPC_METHOD_INVOKE_FN_H
|
#define WF_JSONRPC_METHOD_INVOKE_FN_H
|
||||||
|
|
||||||
#include <wf/jsonrpc/api.h>
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -17,7 +16,6 @@ typedef void wf_jsonrpc_method_invoke_fn(
|
|||||||
json_t * params,
|
json_t * params,
|
||||||
void * user_data);
|
void * user_data);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@ -1,37 +1,34 @@
|
|||||||
#include "wf/jsonrpc/impl/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy_intern.h"
|
||||||
#include "wf/jsonrpc/impl/response.h"
|
#include "webfuse/core/jsonrpc/response_intern.h"
|
||||||
#include "wf/jsonrpc/impl/error.h"
|
#include "webfuse/core/jsonrpc/error.h"
|
||||||
#include "wf/jsonrpc/status.h"
|
#include "webfuse/core/status.h"
|
||||||
|
|
||||||
#include <wf/timer/timer.h>
|
#include "webfuse/core/timer/timer.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct wf_jsonrpc_proxy *
|
struct wf_jsonrpc_proxy *
|
||||||
wf_jsonrpc_impl_proxy_create(
|
wf_jsonrpc_proxy_create(
|
||||||
struct wf_timer_manager * manager,
|
struct wf_timer_manager * manager,
|
||||||
int timeout,
|
int timeout,
|
||||||
wf_jsonrpc_send_fn * send,
|
wf_jsonrpc_send_fn * send,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy));
|
struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy));
|
||||||
if (NULL != proxy)
|
wf_jsonrpc_proxy_init(proxy, manager, timeout, send, user_data);
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_jsonrpc_impl_proxy_dispose(
|
void wf_jsonrpc_proxy_dispose(
|
||||||
struct wf_jsonrpc_proxy * proxy)
|
struct wf_jsonrpc_proxy * proxy)
|
||||||
{
|
{
|
||||||
wf_jsonrpc_impl_proxy_cleanup(proxy);
|
wf_jsonrpc_proxy_cleanup(proxy);
|
||||||
free(proxy);
|
free(proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wf_jsonrpc_impl_proxy_on_timeout(
|
static void wf_jsonrpc_proxy_on_timeout(
|
||||||
struct wf_timer * timer, void * proxy_ptr)
|
struct wf_timer * timer, void * proxy_ptr)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_proxy * proxy = proxy_ptr;
|
struct wf_jsonrpc_proxy * proxy = proxy_ptr;
|
||||||
@ -47,11 +44,11 @@ static void wf_jsonrpc_impl_proxy_on_timeout(
|
|||||||
proxy->request.finished = NULL;
|
proxy->request.finished = NULL;
|
||||||
wf_timer_cancel(timer);
|
wf_timer_cancel(timer);
|
||||||
|
|
||||||
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_TIMEOUT, "Timeout");
|
wf_jsonrpc_propate_error(finished, user_data, WF_BAD_TIMEOUT, "Timeout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static json_t * wf_jsonrpc_impl_request_create(
|
static json_t * wf_jsonrpc_request_create(
|
||||||
char const * method,
|
char const * method,
|
||||||
int id,
|
int id,
|
||||||
char const * param_info,
|
char const * param_info,
|
||||||
@ -101,7 +98,7 @@ static json_t * wf_jsonrpc_impl_request_create(
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_jsonrpc_impl_proxy_init(
|
void wf_jsonrpc_proxy_init(
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
struct wf_timer_manager * timeout_manager,
|
struct wf_timer_manager * timeout_manager,
|
||||||
int timeout,
|
int timeout,
|
||||||
@ -113,10 +110,10 @@ void wf_jsonrpc_impl_proxy_init(
|
|||||||
proxy->user_data = user_data;
|
proxy->user_data = user_data;
|
||||||
proxy->request.is_pending = false;
|
proxy->request.is_pending = false;
|
||||||
proxy->request.timer = wf_timer_create(timeout_manager,
|
proxy->request.timer = wf_timer_create(timeout_manager,
|
||||||
&wf_jsonrpc_impl_proxy_on_timeout, proxy);
|
&wf_jsonrpc_proxy_on_timeout, proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_jsonrpc_impl_proxy_cleanup(
|
void wf_jsonrpc_proxy_cleanup(
|
||||||
struct wf_jsonrpc_proxy * proxy)
|
struct wf_jsonrpc_proxy * proxy)
|
||||||
{
|
{
|
||||||
if (proxy->request.is_pending)
|
if (proxy->request.is_pending)
|
||||||
@ -130,20 +127,19 @@ void wf_jsonrpc_impl_proxy_cleanup(
|
|||||||
proxy->request.id = 0;
|
proxy->request.id = 0;
|
||||||
wf_timer_cancel(proxy->request.timer);
|
wf_timer_cancel(proxy->request.timer);
|
||||||
|
|
||||||
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: cancelled pending request during shutdown");
|
wf_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: cancelled pending request during shutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
wf_timer_dispose(proxy->request.timer);
|
wf_timer_dispose(proxy->request.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_jsonrpc_impl_proxy_invoke(
|
void wf_jsonrpc_proxy_vinvoke(
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
wf_jsonrpc_proxy_finished_fn * finished,
|
wf_jsonrpc_proxy_finished_fn * finished,
|
||||||
void * user_data,
|
void * user_data,
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
char const * param_info,
|
char const * param_info,
|
||||||
va_list args
|
va_list args)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (!proxy->request.is_pending)
|
if (!proxy->request.is_pending)
|
||||||
{
|
{
|
||||||
@ -153,7 +149,7 @@ void wf_jsonrpc_impl_proxy_invoke(
|
|||||||
proxy->request.id = 42;
|
proxy->request.id = 42;
|
||||||
wf_timer_start(proxy->request.timer, proxy->timeout);
|
wf_timer_start(proxy->request.timer, proxy->timeout);
|
||||||
|
|
||||||
json_t * request = wf_jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args);
|
json_t * request = wf_jsonrpc_request_create(method_name, proxy->request.id, param_info, args);
|
||||||
|
|
||||||
bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data)));
|
bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data)));
|
||||||
if (!is_send)
|
if (!is_send)
|
||||||
@ -164,7 +160,7 @@ void wf_jsonrpc_impl_proxy_invoke(
|
|||||||
proxy->request.id = 0;
|
proxy->request.id = 0;
|
||||||
wf_timer_cancel(proxy->request.timer);
|
wf_timer_cancel(proxy->request.timer);
|
||||||
|
|
||||||
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: requenst is not sent");
|
wf_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: requenst is not sent");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != request)
|
if (NULL != request)
|
||||||
@ -174,18 +170,18 @@ void wf_jsonrpc_impl_proxy_invoke(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_BUSY, "Busy");
|
wf_jsonrpc_propate_error(finished, user_data, WF_BAD_BUSY, "Busy");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void wf_jsonrpc_impl_proxy_notify(
|
extern void wf_jsonrpc_proxy_vnotify(
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
char const * param_info,
|
char const * param_info,
|
||||||
va_list args
|
va_list args)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
json_t * request = wf_jsonrpc_impl_request_create(method_name, 0, param_info, args);
|
json_t * request = wf_jsonrpc_request_create(method_name, 0, param_info, args);
|
||||||
|
|
||||||
if (NULL != request)
|
if (NULL != request)
|
||||||
{
|
{
|
||||||
proxy->send(request, proxy->user_data);
|
proxy->send(request, proxy->user_data);
|
||||||
@ -194,12 +190,12 @@ extern void wf_jsonrpc_impl_proxy_notify(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wf_jsonrpc_impl_proxy_onresult(
|
void wf_jsonrpc_proxy_onresult(
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
json_t * message)
|
json_t * message)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_response response;
|
struct wf_jsonrpc_response response;
|
||||||
wf_jsonrpc_impl_response_init(&response, message);
|
wf_jsonrpc_response_init(&response, message);
|
||||||
|
|
||||||
if ((proxy->request.is_pending) && (response.id == proxy->request.id))
|
if ((proxy->request.is_pending) && (response.id == proxy->request.id))
|
||||||
{
|
{
|
||||||
@ -215,6 +211,6 @@ void wf_jsonrpc_impl_proxy_onresult(
|
|||||||
finished(user_data, response.result, response.error);
|
finished(user_data, response.result, response.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
wf_jsonrpc_impl_response_cleanup(&response);
|
wf_jsonrpc_response_cleanup(&response);
|
||||||
}
|
}
|
||||||
|
|
@ -12,9 +12,8 @@ using std::size_t;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include <wf/jsonrpc/api.h>
|
#include "webfuse/core/jsonrpc/send_fn.h"
|
||||||
#include <wf/jsonrpc/send_fn.h>
|
#include "webfuse/core/jsonrpc/proxy_finished_fn.h"
|
||||||
#include <wf/jsonrpc/proxy_finished_fn.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -23,14 +22,14 @@ extern "C" {
|
|||||||
struct wf_jsonrpc_proxy;
|
struct wf_jsonrpc_proxy;
|
||||||
struct wf_timer_manager;
|
struct wf_timer_manager;
|
||||||
|
|
||||||
extern WF_JSONRPC_API struct wf_jsonrpc_proxy *
|
extern struct wf_jsonrpc_proxy *
|
||||||
wf_jsonrpc_proxy_create(
|
wf_jsonrpc_proxy_create(
|
||||||
struct wf_timer_manager * manager,
|
struct wf_timer_manager * manager,
|
||||||
int timeout,
|
int timeout,
|
||||||
wf_jsonrpc_send_fn * send,
|
wf_jsonrpc_send_fn * send,
|
||||||
void * user_data);
|
void * user_data);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose(
|
extern void wf_jsonrpc_proxy_dispose(
|
||||||
struct wf_jsonrpc_proxy * proxy);
|
struct wf_jsonrpc_proxy * proxy);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -47,7 +46,7 @@ extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose(
|
|||||||
/// \param param_info types of the param (s = string, i = integer, j = json)
|
/// \param param_info types of the param (s = string, i = integer, j = json)
|
||||||
/// \param ... params
|
/// \param ... params
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke(
|
extern void wf_jsonrpc_proxy_invoke(
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
wf_jsonrpc_proxy_finished_fn * finished,
|
wf_jsonrpc_proxy_finished_fn * finished,
|
||||||
void * user_data,
|
void * user_data,
|
||||||
@ -56,14 +55,14 @@ extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke(
|
|||||||
...
|
...
|
||||||
);
|
);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_proxy_notify(
|
extern void wf_jsonrpc_proxy_notify(
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
char const * param_info,
|
char const * param_info,
|
||||||
...
|
...
|
||||||
);
|
);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_proxy_onresult(
|
extern void wf_jsonrpc_proxy_onresult(
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
json_t * message);
|
json_t * message);
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
#ifndef WF_JSONRPC_IMPL_PROXY_H
|
#ifndef WF_JSONRPC_PROXY_INTERN_H
|
||||||
#define WF_JSONRPC_IMPL_PROXY_H
|
#define WF_JSONRPC_PROXY_INTERN_H
|
||||||
|
|
||||||
#include "wf/jsonrpc/proxy_finished_fn.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
#include "wf/jsonrpc/send_fn.h"
|
#include "webfuse/core/jsonrpc/proxy_finished_fn.h"
|
||||||
|
#include "webfuse/core/jsonrpc/send_fn.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct wf_timer_manager;
|
|
||||||
struct wf_timer;
|
struct wf_timer;
|
||||||
|
|
||||||
struct wf_jsonrpc_request
|
struct wf_jsonrpc_request
|
||||||
@ -30,7 +30,7 @@ struct wf_jsonrpc_proxy
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
wf_jsonrpc_impl_proxy_init(
|
wf_jsonrpc_proxy_init(
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
struct wf_timer_manager * manager,
|
struct wf_timer_manager * manager,
|
||||||
int timeout,
|
int timeout,
|
||||||
@ -38,44 +38,22 @@ wf_jsonrpc_impl_proxy_init(
|
|||||||
void * user_data);
|
void * user_data);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
wf_jsonrpc_impl_proxy_cleanup(
|
wf_jsonrpc_proxy_cleanup(
|
||||||
struct wf_jsonrpc_proxy * proxy);
|
struct wf_jsonrpc_proxy * proxy);
|
||||||
|
|
||||||
extern struct wf_jsonrpc_proxy *
|
extern void wf_jsonrpc_proxy_vinvoke(
|
||||||
wf_jsonrpc_impl_proxy_create(
|
|
||||||
struct wf_timer_manager * manager,
|
|
||||||
int timeout,
|
|
||||||
wf_jsonrpc_send_fn * send,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wf_jsonrpc_impl_proxy_dispose(
|
|
||||||
struct wf_jsonrpc_proxy * proxy);
|
|
||||||
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wf_jsonrpc_impl_proxy_invoke(
|
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
wf_jsonrpc_proxy_finished_fn * finished,
|
wf_jsonrpc_proxy_finished_fn * finished,
|
||||||
void * user_data,
|
void * user_data,
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
char const * param_info,
|
char const * param_info,
|
||||||
va_list args
|
va_list args);
|
||||||
);
|
|
||||||
|
|
||||||
extern void
|
extern void wf_jsonrpc_proxy_vnotify(
|
||||||
wf_jsonrpc_impl_proxy_notify(
|
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
char const * param_info,
|
char const * param_info,
|
||||||
va_list args
|
va_list args);
|
||||||
);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wf_jsonrpc_impl_proxy_onresult(
|
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
|
||||||
json_t * message);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
28
lib/webfuse/core/jsonrpc/proxy_variadic.c
Normal file
28
lib/webfuse/core/jsonrpc/proxy_variadic.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "webfuse/core/jsonrpc/proxy_intern.h"
|
||||||
|
|
||||||
|
void wf_jsonrpc_proxy_invoke(
|
||||||
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
|
wf_jsonrpc_proxy_finished_fn * finished,
|
||||||
|
void * user_data,
|
||||||
|
char const * method_name,
|
||||||
|
char const * param_info,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, param_info);
|
||||||
|
wf_jsonrpc_proxy_vinvoke(proxy, finished, user_data, method_name, param_info, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void wf_jsonrpc_proxy_notify(
|
||||||
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
|
char const * method_name,
|
||||||
|
char const * param_info,
|
||||||
|
...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, param_info);
|
||||||
|
wf_jsonrpc_proxy_vnotify(proxy, method_name, param_info, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
#include "wf/jsonrpc/impl/request.h"
|
#include "webfuse/core/jsonrpc/request.h"
|
||||||
#include "wf/jsonrpc/impl/error.h"
|
#include "webfuse/core/jsonrpc/error.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct wf_jsonrpc_request
|
struct wf_jsonrpc_request
|
||||||
@ -10,7 +10,7 @@ struct wf_jsonrpc_request
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wf_jsonrpc_impl_is_request(
|
wf_jsonrpc_is_request(
|
||||||
json_t * message)
|
json_t * message)
|
||||||
{
|
{
|
||||||
json_t * id = json_object_get(message, "id");
|
json_t * id = json_object_get(message, "id");
|
||||||
@ -23,31 +23,28 @@ wf_jsonrpc_impl_is_request(
|
|||||||
|
|
||||||
|
|
||||||
struct wf_jsonrpc_request *
|
struct wf_jsonrpc_request *
|
||||||
wf_jsonrpc_impl_request_create(
|
wf_jsonrpc_request_create(
|
||||||
int id,
|
int id,
|
||||||
wf_jsonrpc_send_fn * send,
|
wf_jsonrpc_send_fn * send,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request));
|
struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request));
|
||||||
if (NULL != request)
|
request->id = id;
|
||||||
{
|
request->send = send;
|
||||||
request->id = id;
|
request->user_data = user_data;
|
||||||
request->send = send;
|
|
||||||
request->user_data = user_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wf_jsonrpc_impl_request_dispose(
|
wf_jsonrpc_request_dispose(
|
||||||
struct wf_jsonrpc_request * request)
|
struct wf_jsonrpc_request * request)
|
||||||
{
|
{
|
||||||
free(request);
|
free(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
wf_jsonrpc_impl_request_get_userdata(
|
wf_jsonrpc_request_get_userdata(
|
||||||
struct wf_jsonrpc_request * request)
|
struct wf_jsonrpc_request * request)
|
||||||
{
|
{
|
||||||
return request->user_data;
|
return request->user_data;
|
||||||
@ -55,7 +52,7 @@ wf_jsonrpc_impl_request_get_userdata(
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
wf_jsonrpc_impl_respond(
|
wf_jsonrpc_respond(
|
||||||
struct wf_jsonrpc_request * request,
|
struct wf_jsonrpc_request * request,
|
||||||
json_t * result)
|
json_t * result)
|
||||||
{
|
{
|
||||||
@ -65,20 +62,20 @@ wf_jsonrpc_impl_respond(
|
|||||||
|
|
||||||
request->send(response, request->user_data);
|
request->send(response, request->user_data);
|
||||||
json_decref(response);
|
json_decref(response);
|
||||||
wf_jsonrpc_impl_request_dispose(request);
|
wf_jsonrpc_request_dispose(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_jsonrpc_impl_respond_error(
|
void wf_jsonrpc_respond_error(
|
||||||
struct wf_jsonrpc_request * request,
|
struct wf_jsonrpc_request * request,
|
||||||
int code,
|
int code,
|
||||||
char const * message)
|
char const * message)
|
||||||
{
|
{
|
||||||
json_t * response = json_object();
|
json_t * response = json_object();
|
||||||
json_object_set_new(response, "error", wf_jsonrpc_impl_error(code, message));
|
json_object_set_new(response, "error", wf_jsonrpc_error(code, message));
|
||||||
json_object_set_new(response, "id", json_integer(request->id));
|
json_object_set_new(response, "id", json_integer(request->id));
|
||||||
|
|
||||||
request->send(response, request->user_data);
|
request->send(response, request->user_data);
|
||||||
json_decref(response);
|
json_decref(response);
|
||||||
wf_jsonrpc_impl_request_dispose(request);
|
wf_jsonrpc_request_dispose(request);
|
||||||
}
|
}
|
||||||
|
|
@ -12,8 +12,7 @@ using std::size_t;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include <wf/jsonrpc/api.h>
|
#include "webfuse/core/jsonrpc/send_fn.h"
|
||||||
#include "wf/jsonrpc/send_fn.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -22,26 +21,26 @@ extern "C"
|
|||||||
|
|
||||||
struct wf_jsonrpc_request;
|
struct wf_jsonrpc_request;
|
||||||
|
|
||||||
extern WF_JSONRPC_API bool wf_jsonrpc_is_request(
|
extern bool wf_jsonrpc_is_request(
|
||||||
json_t * message);
|
json_t * message);
|
||||||
|
|
||||||
extern WF_JSONRPC_API struct wf_jsonrpc_request *
|
extern struct wf_jsonrpc_request *
|
||||||
wf_jsonrpc_request_create(
|
wf_jsonrpc_request_create(
|
||||||
int id,
|
int id,
|
||||||
wf_jsonrpc_send_fn * send,
|
wf_jsonrpc_send_fn * send,
|
||||||
void * user_data);
|
void * user_data);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_request_dispose(
|
extern void wf_jsonrpc_request_dispose(
|
||||||
struct wf_jsonrpc_request * request);
|
struct wf_jsonrpc_request * request);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void * wf_jsonrpc_request_get_userdata(
|
extern void * wf_jsonrpc_request_get_userdata(
|
||||||
struct wf_jsonrpc_request * request);
|
struct wf_jsonrpc_request * request);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_respond(
|
extern void wf_jsonrpc_respond(
|
||||||
struct wf_jsonrpc_request * request,
|
struct wf_jsonrpc_request * request,
|
||||||
json_t * result);
|
json_t * result);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_respond_error(
|
extern void wf_jsonrpc_respond_error(
|
||||||
struct wf_jsonrpc_request * request,
|
struct wf_jsonrpc_request * request,
|
||||||
int code,
|
int code,
|
||||||
char const * message);
|
char const * message);
|
@ -1,9 +1,9 @@
|
|||||||
#include "wf/jsonrpc/impl/response.h"
|
#include "webfuse/core/jsonrpc/response_intern.h"
|
||||||
#include "wf/jsonrpc/impl/error.h"
|
#include "webfuse/core/jsonrpc/error.h"
|
||||||
#include "wf/jsonrpc/status.h"
|
#include "webfuse/core/status.h"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wf_jsonrpc_impl_is_response(
|
wf_jsonrpc_is_response(
|
||||||
json_t * message)
|
json_t * message)
|
||||||
{
|
{
|
||||||
json_t * id = json_object_get(message, "id");
|
json_t * id = json_object_get(message, "id");
|
||||||
@ -16,7 +16,7 @@ wf_jsonrpc_impl_is_response(
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
wf_jsonrpc_impl_response_init(
|
wf_jsonrpc_response_init(
|
||||||
struct wf_jsonrpc_response * result,
|
struct wf_jsonrpc_response * result,
|
||||||
json_t * response)
|
json_t * response)
|
||||||
{
|
{
|
||||||
@ -25,9 +25,9 @@ wf_jsonrpc_impl_response_init(
|
|||||||
result->error = NULL;
|
result->error = NULL;
|
||||||
|
|
||||||
json_t * id_holder = json_object_get(response, "id");
|
json_t * id_holder = json_object_get(response, "id");
|
||||||
if ((NULL == id_holder) || (!json_is_integer(id_holder)))
|
if (!json_is_integer(id_holder))
|
||||||
{
|
{
|
||||||
result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: missing id");
|
result->error = wf_jsonrpc_error(WF_BAD_FORMAT, "invalid format: missing id");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,13 +47,13 @@ wf_jsonrpc_impl_response_init(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: invalid error object");
|
result->error = wf_jsonrpc_error(WF_BAD_FORMAT, "invalid format: invalid error object");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wf_jsonrpc_impl_response_cleanup(
|
wf_jsonrpc_response_cleanup(
|
||||||
struct wf_jsonrpc_response * response)
|
struct wf_jsonrpc_response * response)
|
||||||
{
|
{
|
||||||
if (NULL != response->result)
|
if (NULL != response->result)
|
@ -6,14 +6,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include <wf/jsonrpc/api.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern WF_JSONRPC_API bool wf_jsonrpc_is_response(
|
extern bool wf_jsonrpc_is_response(
|
||||||
json_t * message);
|
json_t * message);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
@ -1,16 +1,15 @@
|
|||||||
#ifndef WF_JSONRPC_IMPL_RESPONSE_H
|
#ifndef WF_JSONRPC_RESPONSE_INTERN_H
|
||||||
#define WF_JSONRPC_IMPL_RESPONSE_H
|
#define WF_JSONRPC_RESPONSE_INTERN_H
|
||||||
|
|
||||||
|
#include "webfuse/core/jsonrpc/response.h"
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#else
|
#else
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
using std::size_t;
|
using std::size_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <jansson.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -22,14 +21,11 @@ struct wf_jsonrpc_response
|
|||||||
int id;
|
int id;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool wf_jsonrpc_impl_is_response(
|
extern void wf_jsonrpc_response_init(
|
||||||
json_t * message);
|
|
||||||
|
|
||||||
extern void wf_jsonrpc_impl_response_init(
|
|
||||||
struct wf_jsonrpc_response * response,
|
struct wf_jsonrpc_response * response,
|
||||||
json_t * message);
|
json_t * message);
|
||||||
|
|
||||||
extern void wf_jsonrpc_impl_response_cleanup(
|
extern void wf_jsonrpc_response_cleanup(
|
||||||
struct wf_jsonrpc_response * response);
|
struct wf_jsonrpc_response * response);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
@ -6,7 +6,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include <wf/jsonrpc/api.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
@ -1,8 +1,8 @@
|
|||||||
#include "wf/jsonrpc/impl/server.h"
|
#include "webfuse/core/jsonrpc/server.h"
|
||||||
#include "wf/jsonrpc/impl/method.h"
|
#include "webfuse/core/jsonrpc/method.h"
|
||||||
#include "wf/jsonrpc/impl/request.h"
|
#include "webfuse/core/jsonrpc/request.h"
|
||||||
#include "wf/jsonrpc/impl/unused_param.h"
|
#include "webfuse/core/status.h"
|
||||||
#include "wf/jsonrpc/status.h"
|
#include "webfuse/core/util.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -13,83 +13,79 @@ struct wf_jsonrpc_server
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wf_jsonrpc_impl_server_init(
|
wf_jsonrpc_server_init(
|
||||||
struct wf_jsonrpc_server * server);
|
struct wf_jsonrpc_server * server);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wf_jsonrpc_impl_server_cleanup(
|
wf_jsonrpc_server_cleanup(
|
||||||
struct wf_jsonrpc_server * server);
|
struct wf_jsonrpc_server * server);
|
||||||
|
|
||||||
struct wf_jsonrpc_server *
|
struct wf_jsonrpc_server *
|
||||||
wf_jsonrpc_impl_server_create(void)
|
wf_jsonrpc_server_create(void)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server));
|
struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server));
|
||||||
if (NULL != server)
|
wf_jsonrpc_server_init(server);
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_server_init(server);
|
|
||||||
}
|
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wf_jsonrpc_impl_server_dispose(
|
wf_jsonrpc_server_dispose(
|
||||||
struct wf_jsonrpc_server * server)
|
struct wf_jsonrpc_server * server)
|
||||||
{
|
{
|
||||||
wf_jsonrpc_impl_server_cleanup(server);
|
wf_jsonrpc_server_cleanup(server);
|
||||||
free(server);
|
free(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void wf_jsonrpc_server_init(
|
||||||
static void wf_jsonrpc_impl_server_init(
|
|
||||||
struct wf_jsonrpc_server * server)
|
struct wf_jsonrpc_server * server)
|
||||||
{
|
{
|
||||||
server->methods = NULL;
|
server->methods = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wf_jsonrpc_impl_server_cleanup(
|
static void wf_jsonrpc_server_cleanup(
|
||||||
struct wf_jsonrpc_server * server)
|
struct wf_jsonrpc_server * server)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_method * current = server->methods;
|
struct wf_jsonrpc_method * current = server->methods;
|
||||||
while (NULL != current)
|
while (NULL != current)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_method * next = current->next;
|
struct wf_jsonrpc_method * next = current->next;
|
||||||
wf_jsonrpc_impl_method_dispose(current);
|
wf_jsonrpc_method_dispose(current);
|
||||||
current = next;
|
current = next;
|
||||||
}
|
}
|
||||||
server->methods = NULL;
|
server->methods = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_jsonrpc_impl_server_add(
|
void wf_jsonrpc_server_add(
|
||||||
struct wf_jsonrpc_server * server,
|
struct wf_jsonrpc_server * server,
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
wf_jsonrpc_method_invoke_fn * invoke,
|
wf_jsonrpc_method_invoke_fn * invoke,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
struct wf_jsonrpc_method * method = wf_jsonrpc_impl_method_create(method_name, invoke, user_data);
|
struct wf_jsonrpc_method * method = wf_jsonrpc_method_create(method_name, invoke, user_data);
|
||||||
method->next = server->methods;
|
method->next = server->methods;
|
||||||
server->methods = method;
|
server->methods = method;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wf_jsonrpc_impl_server_invalid_method_invoke(
|
static void wf_jsonrpc_server_invalid_method_invoke(
|
||||||
struct wf_jsonrpc_request * request,
|
struct wf_jsonrpc_request * request,
|
||||||
char const * WF_JSONRPC_UNUSED_PARAM(method_name),
|
char const * WF_UNUSED_PARAM(method_name),
|
||||||
json_t * WF_JSONRPC_UNUSED_PARAM(params),
|
json_t * WF_UNUSED_PARAM(params),
|
||||||
void * WF_JSONRPC_UNUSED_PARAM(user_data))
|
void * WF_UNUSED_PARAM(user_data))
|
||||||
{
|
{
|
||||||
wf_jsonrpc_impl_respond_error(request, WF_JSONRPC_BAD_NOTIMPLEMENTED, "not implemented");
|
wf_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED, "not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wf_jsonrpc_method const wf_jsonrpc_impl_server_invalid_method =
|
static struct wf_jsonrpc_method const wf_jsonrpc_server_invalid_method =
|
||||||
{
|
{
|
||||||
.next = NULL,
|
.next = NULL,
|
||||||
.name = "<invalid>",
|
.name = "<invalid>",
|
||||||
.invoke = &wf_jsonrpc_impl_server_invalid_method_invoke,
|
.invoke = &wf_jsonrpc_server_invalid_method_invoke,
|
||||||
.user_data = NULL
|
.user_data = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct wf_jsonrpc_method const *
|
static struct wf_jsonrpc_method const *
|
||||||
wf_jsonrpc_impl_server_get_method(
|
wf_jsonrpc_server_get_method(
|
||||||
struct wf_jsonrpc_server * server,
|
struct wf_jsonrpc_server * server,
|
||||||
char const * method_name)
|
char const * method_name)
|
||||||
{
|
{
|
||||||
@ -104,10 +100,10 @@ wf_jsonrpc_impl_server_get_method(
|
|||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &wf_jsonrpc_impl_server_invalid_method;
|
return &wf_jsonrpc_server_invalid_method;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_jsonrpc_impl_server_process(
|
void wf_jsonrpc_server_process(
|
||||||
struct wf_jsonrpc_server * server,
|
struct wf_jsonrpc_server * server,
|
||||||
json_t * request_data,
|
json_t * request_data,
|
||||||
wf_jsonrpc_send_fn * send,
|
wf_jsonrpc_send_fn * send,
|
||||||
@ -123,8 +119,8 @@ void wf_jsonrpc_impl_server_process(
|
|||||||
{
|
{
|
||||||
char const * method_name = json_string_value(method_holder);
|
char const * method_name = json_string_value(method_holder);
|
||||||
int id = json_integer_value(id_holder);
|
int id = json_integer_value(id_holder);
|
||||||
struct wf_jsonrpc_request * request = wf_jsonrpc_impl_request_create(id, send, user_data);
|
struct wf_jsonrpc_request * request = wf_jsonrpc_request_create(id, send, user_data);
|
||||||
struct wf_jsonrpc_method const * method = wf_jsonrpc_impl_server_get_method(server, method_name);
|
struct wf_jsonrpc_method const * method = wf_jsonrpc_server_get_method(server, method_name);
|
||||||
|
|
||||||
method->invoke(request, method_name, params, method->user_data);
|
method->invoke(request, method_name, params, method->user_data);
|
||||||
}
|
}
|
@ -9,9 +9,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include <wf/jsonrpc/api.h>
|
#include "webfuse/core/jsonrpc/method_invoke_fn.h"
|
||||||
#include <wf/jsonrpc/send_fn.h>
|
#include "webfuse/core/jsonrpc/send_fn.h"
|
||||||
#include <wf/jsonrpc/method_invoke_fn.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -20,20 +19,20 @@ extern "C"
|
|||||||
|
|
||||||
struct wf_jsonrpc_server;
|
struct wf_jsonrpc_server;
|
||||||
|
|
||||||
extern WF_JSONRPC_API struct wf_jsonrpc_server *
|
extern struct wf_jsonrpc_server *
|
||||||
wf_jsonrpc_server_create(void);
|
wf_jsonrpc_server_create(void);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void
|
extern void
|
||||||
wf_jsonrpc_server_dispose(
|
wf_jsonrpc_server_dispose(
|
||||||
struct wf_jsonrpc_server * server);
|
struct wf_jsonrpc_server * server);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_server_add(
|
extern void wf_jsonrpc_server_add(
|
||||||
struct wf_jsonrpc_server * server,
|
struct wf_jsonrpc_server * server,
|
||||||
char const * method_name,
|
char const * method_name,
|
||||||
wf_jsonrpc_method_invoke_fn * invoke,
|
wf_jsonrpc_method_invoke_fn * invoke,
|
||||||
void * user_data);
|
void * user_data);
|
||||||
|
|
||||||
extern WF_JSONRPC_API void wf_jsonrpc_server_process(
|
extern void wf_jsonrpc_server_process(
|
||||||
struct wf_jsonrpc_server * server,
|
struct wf_jsonrpc_server * server,
|
||||||
json_t * request,
|
json_t * request,
|
||||||
wf_jsonrpc_send_fn * send,
|
wf_jsonrpc_send_fn * send,
|
@ -12,13 +12,10 @@ extern struct wf_message * wf_message_create(json_t const * value)
|
|||||||
{
|
{
|
||||||
char * data = malloc(sizeof(struct wf_message) + LWS_PRE + length);
|
char * data = malloc(sizeof(struct wf_message) + LWS_PRE + length);
|
||||||
message = (struct wf_message *) data;
|
message = (struct wf_message *) data;
|
||||||
if (NULL != message)
|
message->data = &data[sizeof(struct wf_message) + LWS_PRE];
|
||||||
{
|
message->length = length;
|
||||||
message->data = &data[sizeof(struct wf_message) + LWS_PRE];
|
|
||||||
message->length = length;
|
|
||||||
|
|
||||||
json_dumpb(value, message->data, length, JSON_COMPACT);
|
json_dumpb(value, message->data, length, JSON_COMPACT);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
|
@ -16,18 +16,15 @@ char * wf_create_string(char const * format, ...)
|
|||||||
if (0 <= needed)
|
if (0 <= needed)
|
||||||
{
|
{
|
||||||
result = malloc(needed + 1);
|
result = malloc(needed + 1);
|
||||||
if (NULL != result)
|
va_list args;
|
||||||
{
|
va_start(args, format);
|
||||||
va_list args;
|
int count = vsnprintf(result, needed + 1, format, args);
|
||||||
va_start(args, format);
|
va_end(args);
|
||||||
int count = vsnprintf(result, needed + 1, format, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
if ((count < 0) || (needed < count))
|
if ((count < 0) || (needed < count))
|
||||||
{
|
{
|
||||||
free(result);
|
free(result);
|
||||||
result = NULL;
|
result = NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "wf/timer/impl/manager.h"
|
#include "webfuse/core/timer/manager_intern.h"
|
||||||
#include "wf/timer/impl/timer.h"
|
#include "webfuse/core/timer/timer_intern.h"
|
||||||
#include "wf/timer/impl/timepoint.h"
|
#include "webfuse/core/timer/timepoint.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -11,19 +11,16 @@ struct wf_timer_manager
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct wf_timer_manager *
|
struct wf_timer_manager *
|
||||||
wf_timer_impl_manager_create(void)
|
wf_timer_manager_create(void)
|
||||||
{
|
{
|
||||||
struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager));
|
struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager));
|
||||||
if (NULL != manager)
|
manager->timers = NULL;
|
||||||
{
|
|
||||||
manager->timers = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wf_timer_impl_manager_dispose(
|
wf_timer_manager_dispose(
|
||||||
struct wf_timer_manager * manager)
|
struct wf_timer_manager * manager)
|
||||||
{
|
{
|
||||||
struct wf_timer * timer = manager->timers;
|
struct wf_timer * timer = manager->timers;
|
||||||
@ -31,7 +28,7 @@ wf_timer_impl_manager_dispose(
|
|||||||
{
|
{
|
||||||
struct wf_timer * next = timer->next;
|
struct wf_timer * next = timer->next;
|
||||||
|
|
||||||
wf_timer_impl_trigger(timer);
|
wf_timer_trigger(timer);
|
||||||
timer = next;
|
timer = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +36,7 @@ wf_timer_impl_manager_dispose(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wf_timer_impl_manager_check(
|
void wf_timer_manager_check(
|
||||||
struct wf_timer_manager * manager)
|
struct wf_timer_manager * manager)
|
||||||
{
|
{
|
||||||
struct wf_timer * timer = manager->timers;
|
struct wf_timer * timer = manager->timers;
|
||||||
@ -47,17 +44,17 @@ void wf_timer_impl_manager_check(
|
|||||||
{
|
{
|
||||||
struct wf_timer * next = timer->next;
|
struct wf_timer * next = timer->next;
|
||||||
|
|
||||||
if (wf_timer_impl_is_timeout(timer))
|
if (wf_timer_is_timeout(timer))
|
||||||
{
|
{
|
||||||
wf_timer_impl_manager_removetimer(manager, timer);
|
wf_timer_manager_removetimer(manager, timer);
|
||||||
wf_timer_impl_trigger(timer);
|
wf_timer_trigger(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
timer = next;
|
timer = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_timer_impl_manager_addtimer(
|
void wf_timer_manager_addtimer(
|
||||||
struct wf_timer_manager * manager,
|
struct wf_timer_manager * manager,
|
||||||
struct wf_timer * timer)
|
struct wf_timer * timer)
|
||||||
{
|
{
|
||||||
@ -71,7 +68,7 @@ void wf_timer_impl_manager_addtimer(
|
|||||||
manager->timers = timer;
|
manager->timers = timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_timer_impl_manager_removetimer(
|
void wf_timer_manager_removetimer(
|
||||||
struct wf_timer_manager * manager,
|
struct wf_timer_manager * manager,
|
||||||
struct wf_timer * timer)
|
struct wf_timer * timer)
|
||||||
{
|
{
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef WF_TIMER_MANAGER_H
|
#ifndef WF_TIMER_MANAGER_H
|
||||||
#define WF_TIMER_MANAGER_H
|
#define WF_TIMER_MANAGER_H
|
||||||
|
|
||||||
#include <wf/timer/api.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@ -10,14 +8,14 @@ extern "C"
|
|||||||
|
|
||||||
struct wf_timer_manager;
|
struct wf_timer_manager;
|
||||||
|
|
||||||
extern WF_TIMER_API struct wf_timer_manager *
|
extern struct wf_timer_manager *
|
||||||
wf_timer_manager_create(void);
|
wf_timer_manager_create(void);
|
||||||
|
|
||||||
extern WF_TIMER_API void
|
extern void
|
||||||
wf_timer_manager_dispose(
|
wf_timer_manager_dispose(
|
||||||
struct wf_timer_manager * manager);
|
struct wf_timer_manager * manager);
|
||||||
|
|
||||||
extern WF_TIMER_API void
|
extern void
|
||||||
wf_timer_manager_check(
|
wf_timer_manager_check(
|
||||||
struct wf_timer_manager * manager);
|
struct wf_timer_manager * manager);
|
||||||
|
|
26
lib/webfuse/core/timer/manager_intern.h
Normal file
26
lib/webfuse/core/timer/manager_intern.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef WF_TIMER_MANAGER_INTERN_H
|
||||||
|
#define WF_TIMER_MANAGER_INTERN_H
|
||||||
|
|
||||||
|
#include "webfuse/core/timer/manager.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_timer;
|
||||||
|
|
||||||
|
extern void wf_timer_manager_addtimer(
|
||||||
|
struct wf_timer_manager * manager,
|
||||||
|
struct wf_timer * timer);
|
||||||
|
|
||||||
|
extern void wf_timer_manager_removetimer(
|
||||||
|
struct wf_timer_manager * manager,
|
||||||
|
struct wf_timer * timer);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -1,11 +1,11 @@
|
|||||||
#include "wf/timer/impl/timepoint.h"
|
#include "webfuse/core/timer/timepoint.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 1000)
|
#define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 1000)
|
||||||
#define WF_TIMER_NSEC_PER_MSEC ((wf_timer_timepoint) 1000 * 1000)
|
#define WF_TIMER_NSEC_PER_MSEC ((wf_timer_timepoint) 1000 * 1000)
|
||||||
|
|
||||||
wf_timer_timepoint wf_timer_impl_timepoint_now(void)
|
wf_timer_timepoint wf_timer_timepoint_now(void)
|
||||||
{
|
{
|
||||||
struct timespec tp;
|
struct timespec tp;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||||
@ -14,17 +14,17 @@ wf_timer_timepoint wf_timer_impl_timepoint_now(void)
|
|||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
wf_timer_timepoint wf_timer_impl_timepoint_in_msec(wf_timer_timediff value)
|
wf_timer_timepoint wf_timer_timepoint_in_msec(wf_timer_timediff value)
|
||||||
{
|
{
|
||||||
wf_timer_timepoint const now = wf_timer_impl_timepoint_now();
|
wf_timer_timepoint const now = wf_timer_timepoint_now();
|
||||||
wf_timer_timepoint result = now + ((wf_timer_timepoint) value);
|
wf_timer_timepoint result = now + ((wf_timer_timepoint) value);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wf_timer_impl_timepoint_is_elapsed(wf_timer_timepoint tp)
|
bool wf_timer_timepoint_is_elapsed(wf_timer_timepoint tp)
|
||||||
{
|
{
|
||||||
wf_timer_timepoint const now = wf_timer_impl_timepoint_now();
|
wf_timer_timepoint const now = wf_timer_timepoint_now();
|
||||||
wf_timer_timediff const diff = (wf_timer_timediff) (tp - now);
|
wf_timer_timediff const diff = (wf_timer_timediff) (tp - now);
|
||||||
|
|
||||||
return (0 > diff);
|
return (0 > diff);
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef WF_TIMER_IMPL_TIMEPOINT_H
|
#ifndef WF_TIMER_TIMEPOINT_H
|
||||||
#define WF_TIMER_IMPL_TIMEPOINT_H
|
#define WF_TIMER_TIMEPOINT_H
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -16,12 +16,12 @@ extern "C"
|
|||||||
typedef uint64_t wf_timer_timepoint;
|
typedef uint64_t wf_timer_timepoint;
|
||||||
typedef int64_t wf_timer_timediff;
|
typedef int64_t wf_timer_timediff;
|
||||||
|
|
||||||
extern wf_timer_timepoint wf_timer_impl_timepoint_now(void);
|
extern wf_timer_timepoint wf_timer_timepoint_now(void);
|
||||||
|
|
||||||
extern wf_timer_timepoint wf_timer_impl_timepoint_in_msec(
|
extern wf_timer_timepoint wf_timer_timepoint_in_msec(
|
||||||
wf_timer_timediff value);
|
wf_timer_timediff value);
|
||||||
|
|
||||||
extern bool wf_timer_impl_timepoint_is_elapsed(
|
extern bool wf_timer_timepoint_is_elapsed(
|
||||||
wf_timer_timepoint timepoint);
|
wf_timer_timepoint timepoint);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
@ -1,13 +1,13 @@
|
|||||||
#include "wf/timer/impl/timer.h"
|
#include "webfuse/core/timer/timer_intern.h"
|
||||||
#include "wf/timer/impl/manager.h"
|
#include "webfuse/core/timer/manager_intern.h"
|
||||||
#include "wf/timer/impl/timepoint.h"
|
#include "webfuse/core/timer/timepoint.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct wf_timer *
|
struct wf_timer *
|
||||||
wf_timer_impl_create(
|
wf_timer_create(
|
||||||
struct wf_timer_manager * manager,
|
struct wf_timer_manager * manager,
|
||||||
wf_timer_on_timer_fn * on_timer,
|
wf_timer_on_timer_fn * on_timer,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
@ -24,37 +24,37 @@ wf_timer_impl_create(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wf_timer_impl_dispose(
|
wf_timer_dispose(
|
||||||
struct wf_timer * timer)
|
struct wf_timer * timer)
|
||||||
{
|
{
|
||||||
free(timer);
|
free(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_timer_impl_start(
|
void wf_timer_start(
|
||||||
struct wf_timer * timer,
|
struct wf_timer * timer,
|
||||||
int timeout_ms)
|
int timeout_ms)
|
||||||
{
|
{
|
||||||
timer->timeout = wf_timer_impl_timepoint_in_msec(timeout_ms);
|
timer->timeout = wf_timer_timepoint_in_msec(timeout_ms);
|
||||||
|
|
||||||
wf_timer_impl_manager_addtimer(timer->manager, timer);
|
wf_timer_manager_addtimer(timer->manager, timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_timer_impl_cancel(
|
void wf_timer_cancel(
|
||||||
struct wf_timer * timer)
|
struct wf_timer * timer)
|
||||||
{
|
{
|
||||||
wf_timer_impl_manager_removetimer(timer->manager, timer);
|
wf_timer_manager_removetimer(timer->manager, timer);
|
||||||
|
|
||||||
timer->timeout = 0;
|
timer->timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wf_timer_impl_is_timeout(
|
bool wf_timer_is_timeout(
|
||||||
struct wf_timer * timer)
|
struct wf_timer * timer)
|
||||||
{
|
{
|
||||||
return wf_timer_impl_timepoint_is_elapsed(timer->timeout);
|
return wf_timer_timepoint_is_elapsed(timer->timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wf_timer_impl_trigger(
|
void wf_timer_trigger(
|
||||||
struct wf_timer * timer)
|
struct wf_timer * timer)
|
||||||
{
|
{
|
||||||
if (0 != timer->on_timer)
|
if (0 != timer->on_timer)
|
@ -1,8 +1,7 @@
|
|||||||
#ifndef WF_TIMER_TIMER_H
|
#ifndef WF_TIMER_TIMER_H
|
||||||
#define WF_TIMER_TIMER_H
|
#define WF_TIMER_TIMER_H
|
||||||
|
|
||||||
#include <wf/timer/api.h>
|
#include "webfuse/core/timer/on_timer_fn.h"
|
||||||
#include <wf/timer/on_timer_fn.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -12,22 +11,22 @@ extern "C"
|
|||||||
struct wf_timer;
|
struct wf_timer;
|
||||||
struct wf_timer_manager;
|
struct wf_timer_manager;
|
||||||
|
|
||||||
extern WF_TIMER_API struct wf_timer *
|
extern struct wf_timer *
|
||||||
wf_timer_create(
|
wf_timer_create(
|
||||||
struct wf_timer_manager * manager,
|
struct wf_timer_manager * manager,
|
||||||
wf_timer_on_timer_fn * on_timer,
|
wf_timer_on_timer_fn * on_timer,
|
||||||
void * user_data);
|
void * user_data);
|
||||||
|
|
||||||
extern WF_TIMER_API void
|
extern void
|
||||||
wf_timer_dispose(
|
wf_timer_dispose(
|
||||||
struct wf_timer * timer);
|
struct wf_timer * timer);
|
||||||
|
|
||||||
extern WF_TIMER_API void
|
extern void
|
||||||
wf_timer_start(
|
wf_timer_start(
|
||||||
struct wf_timer * timer,
|
struct wf_timer * timer,
|
||||||
int timeout_ms);
|
int timeout_ms);
|
||||||
|
|
||||||
extern WF_TIMER_API void
|
extern void
|
||||||
wf_timer_cancel(
|
wf_timer_cancel(
|
||||||
struct wf_timer * timer);
|
struct wf_timer * timer);
|
||||||
|
|
40
lib/webfuse/core/timer/timer_intern.h
Normal file
40
lib/webfuse/core/timer/timer_intern.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifndef WF_TIMER_TIMER_H
|
||||||
|
#define WF_TIMER_TIMER_H
|
||||||
|
|
||||||
|
#include "webfuse/core/timer/timer.h"
|
||||||
|
#include "webfuse/core/timer/on_timer_fn.h"
|
||||||
|
#include "webfuse/core/timer/timepoint.h"
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
#include <stdbool.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_timer
|
||||||
|
{
|
||||||
|
struct wf_timer_manager * manager;
|
||||||
|
wf_timer_timepoint timeout;
|
||||||
|
wf_timer_on_timer_fn * on_timer;
|
||||||
|
void * user_data;
|
||||||
|
struct wf_timer * next;
|
||||||
|
struct wf_timer * prev;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern bool wf_timer_is_timeout(
|
||||||
|
struct wf_timer * timer);
|
||||||
|
|
||||||
|
extern void wf_timer_trigger(
|
||||||
|
struct wf_timer * timer);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -95,6 +95,13 @@ void wfp_client_config_set_certpath(
|
|||||||
wfp_impl_client_config_set_certpath(config, cert_path);
|
wfp_impl_client_config_set_certpath(config, cert_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wfp_client_config_set_ca_filepath(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
char const * ca_filepath)
|
||||||
|
{
|
||||||
|
wfp_impl_client_config_set_ca_filepath(config, ca_filepath);
|
||||||
|
}
|
||||||
|
|
||||||
void wfp_client_config_set_onconnected(
|
void wfp_client_config_set_onconnected(
|
||||||
struct wfp_client_config * config,
|
struct wfp_client_config * config,
|
||||||
wfp_connected_fn * handler)
|
wfp_connected_fn * handler)
|
||||||
|
@ -30,25 +30,32 @@ struct wfp_client * wfp_impl_client_create(
|
|||||||
wf_lwslog_disable();
|
wf_lwslog_disable();
|
||||||
|
|
||||||
struct wfp_client * client = malloc(sizeof(struct wfp_client));
|
struct wfp_client * client = malloc(sizeof(struct wfp_client));
|
||||||
if (NULL != client)
|
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
||||||
|
|
||||||
|
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
|
||||||
|
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||||
|
|
||||||
|
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
|
||||||
|
client->info.port = CONTEXT_PORT_NO_LISTEN;
|
||||||
|
client->info.protocols = client->protocols;
|
||||||
|
client->info.uid = -1;
|
||||||
|
client->info.gid = -1;
|
||||||
|
|
||||||
|
if ((NULL != config->cert_path) && (NULL != config->key_path))
|
||||||
{
|
{
|
||||||
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
client->info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
|
||||||
|
}
|
||||||
|
|
||||||
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
|
client->context = lws_create_context(&client->info);
|
||||||
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
|
||||||
|
|
||||||
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
|
if ((NULL != config->cert_path) && (NULL != config->key_path))
|
||||||
client->info.port = CONTEXT_PORT_NO_LISTEN;
|
{
|
||||||
client->info.protocols = client->protocols;
|
struct lws_vhost * vhost = lws_create_vhost(client->context, &client->info);
|
||||||
client->info.uid = -1;
|
client->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||||
client->info.gid = -1;
|
client->info.client_ssl_cert_filepath = config->cert_path;
|
||||||
|
client->info.client_ssl_private_key_filepath = config->key_path;
|
||||||
if ((NULL != config->cert_path) && (NULL != config->key_path))
|
client->info.client_ssl_ca_filepath = config->ca_filepath;
|
||||||
{
|
lws_init_vhost_client_ssl(&client->info, vhost);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
client->context = lws_create_context(&client->info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
@ -6,13 +6,11 @@
|
|||||||
struct wfp_client_config * wfp_impl_client_config_create(void)
|
struct wfp_client_config * wfp_impl_client_config_create(void)
|
||||||
{
|
{
|
||||||
struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config));
|
struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config));
|
||||||
if (NULL != config)
|
wfp_impl_provider_init(&config->provider);
|
||||||
{
|
config->user_data = NULL;
|
||||||
wfp_impl_provider_init(&config->provider);
|
config->key_path = NULL;
|
||||||
config->user_data = NULL;
|
config->cert_path = NULL;
|
||||||
config->key_path = NULL;
|
config->ca_filepath = NULL;
|
||||||
config->cert_path = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@ -22,6 +20,7 @@ void wfp_impl_client_config_dispose(
|
|||||||
{
|
{
|
||||||
free(config->key_path);
|
free(config->key_path);
|
||||||
free(config->cert_path);
|
free(config->cert_path);
|
||||||
|
free(config->ca_filepath);
|
||||||
free(config);
|
free(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +47,14 @@ void wfp_impl_client_config_set_certpath(
|
|||||||
config->cert_path = strdup(cert_path);
|
config->cert_path = strdup(cert_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wfp_impl_client_config_set_ca_filepath(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
char const * ca_filepath)
|
||||||
|
{
|
||||||
|
free(config->ca_filepath);
|
||||||
|
config->ca_filepath = strdup(ca_filepath);
|
||||||
|
}
|
||||||
|
|
||||||
void wfp_impl_client_config_set_onconnected(
|
void wfp_impl_client_config_set_onconnected(
|
||||||
struct wfp_client_config * config,
|
struct wfp_client_config * config,
|
||||||
wfp_connected_fn * handler)
|
wfp_connected_fn * handler)
|
||||||
|
@ -15,6 +15,7 @@ struct wfp_client_config
|
|||||||
void * user_data;
|
void * user_data;
|
||||||
char * key_path;
|
char * key_path;
|
||||||
char * cert_path;
|
char * cert_path;
|
||||||
|
char * ca_filepath;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct wfp_client_config * wfp_impl_client_config_create(void);
|
extern struct wfp_client_config * wfp_impl_client_config_create(void);
|
||||||
@ -34,6 +35,10 @@ extern void wfp_impl_client_config_set_certpath(
|
|||||||
struct wfp_client_config * config,
|
struct wfp_client_config * config,
|
||||||
char const * cert_path);
|
char const * cert_path);
|
||||||
|
|
||||||
|
extern void wfp_impl_client_config_set_ca_filepath(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
char const * ca_filepath);
|
||||||
|
|
||||||
extern void wfp_impl_client_config_set_onconnected(
|
extern void wfp_impl_client_config_set_onconnected(
|
||||||
struct wfp_client_config * config,
|
struct wfp_client_config * config,
|
||||||
wfp_connected_fn * handler);
|
wfp_connected_fn * handler);
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
#include "webfuse/provider/impl/url.h"
|
#include "webfuse/provider/impl/url.h"
|
||||||
#include "webfuse/core/protocol_names.h"
|
#include "webfuse/core/protocol_names.h"
|
||||||
|
|
||||||
#include "wf/timer/manager.h"
|
#include "webfuse/core/timer/manager.h"
|
||||||
|
|
||||||
#include "wf/jsonrpc/response.h"
|
#include "webfuse/core/jsonrpc/response.h"
|
||||||
#include "wf/jsonrpc/request.h"
|
#include "webfuse/core/jsonrpc/request.h"
|
||||||
#include "wf/jsonrpc/proxy.h"
|
#include "webfuse/core/jsonrpc/proxy.h"
|
||||||
|
|
||||||
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
||||||
|
|
||||||
@ -270,10 +270,7 @@ struct wfp_client_protocol * wfp_impl_client_protocol_create(
|
|||||||
struct wfp_client_config const * config)
|
struct wfp_client_config const * config)
|
||||||
{
|
{
|
||||||
struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol));
|
struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol));
|
||||||
if (NULL != protocol)
|
wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data);
|
||||||
{
|
|
||||||
wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return protocol;
|
return protocol;
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,7 @@
|
|||||||
struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void)
|
struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void)
|
||||||
{
|
{
|
||||||
struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer));
|
struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer));
|
||||||
if (NULL != buffer)
|
buffer->entries = json_array();
|
||||||
{
|
|
||||||
buffer->entries = json_array();
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -56,28 +56,21 @@ void wfp_impl_respond_read(
|
|||||||
{
|
{
|
||||||
size_t const size = wf_base64_encoded_size(length) + 1;
|
size_t const size = wf_base64_encoded_size(length) + 1;
|
||||||
char * buffer = malloc(size);
|
char * buffer = malloc(size);
|
||||||
if (NULL != buffer)
|
wf_base64_encode((uint8_t const *) data, length, buffer, size);
|
||||||
{
|
|
||||||
wf_base64_encode((uint8_t const *) data, length, buffer, size);
|
|
||||||
|
|
||||||
json_t * result = json_object();
|
json_t * result = json_object();
|
||||||
json_object_set_new(result, "data", json_string(buffer));
|
json_object_set_new(result, "data", json_string(buffer));
|
||||||
json_object_set_new(result, "format", json_string("base64"));
|
json_object_set_new(result, "format", json_string("base64"));
|
||||||
json_object_set_new(result, "count", json_integer((int) length));
|
json_object_set_new(result, "count", json_integer((int) length));
|
||||||
|
|
||||||
wfp_impl_respond(request, result);
|
wfp_impl_respond(request, result);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wfp_impl_respond_error(request, WF_BAD);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
json_t * result = json_object();
|
json_t * result = json_object();
|
||||||
json_object_set_new(result, "data", json_string(""));
|
json_object_set_new(result, "data", json_string(""));
|
||||||
json_object_set_new(result, "format", json_string("identitiy"));
|
json_object_set_new(result, "format", json_string("identity"));
|
||||||
json_object_set_new(result, "count", json_integer(0));
|
json_object_set_new(result, "count", json_integer(0));
|
||||||
|
|
||||||
wfp_impl_respond(request, result);
|
wfp_impl_respond(request, result);
|
||||||
|
@ -14,7 +14,7 @@ void wfp_impl_readdir(
|
|||||||
{
|
{
|
||||||
json_t * inode_holder = json_array_get(params, 1);
|
json_t * inode_holder = json_array_get(params, 1);
|
||||||
|
|
||||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)))
|
if (json_is_integer(inode_holder))
|
||||||
{
|
{
|
||||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||||
|
@ -94,8 +94,7 @@ void wfp_impl_provider_invoke(
|
|||||||
json_t * params = json_object_get(request, "params");
|
json_t * params = json_object_get(request, "params");
|
||||||
json_t * id_holder = json_object_get(request, "id");
|
json_t * id_holder = json_object_get(request, "id");
|
||||||
|
|
||||||
if ((NULL != method_holder) && (json_is_string(method_holder)) &&
|
if ((json_is_string(method_holder)) && (json_is_array(params)))
|
||||||
(NULL != params) && (json_is_array(params)))
|
|
||||||
{
|
{
|
||||||
char const * method = json_string_value(method_holder);
|
char const * method = json_string_value(method_holder);
|
||||||
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0;
|
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0;
|
||||||
|
@ -30,7 +30,7 @@ struct wfp_provider
|
|||||||
|
|
||||||
struct wfp_impl_invokation_context
|
struct wfp_impl_invokation_context
|
||||||
{
|
{
|
||||||
struct wfp_provider * provider;
|
struct wfp_provider const * provider;
|
||||||
void * user_data;
|
void * user_data;
|
||||||
struct wfp_request * request;
|
struct wfp_request * request;
|
||||||
};
|
};
|
||||||
|
@ -8,12 +8,9 @@ struct wfp_request * wfp_impl_request_create(
|
|||||||
int id)
|
int id)
|
||||||
{
|
{
|
||||||
struct wfp_request * request = malloc(sizeof(struct wfp_request));
|
struct wfp_request * request = malloc(sizeof(struct wfp_request));
|
||||||
if (NULL != request)
|
request->respond = prototype->respond;
|
||||||
{
|
request->user_data = prototype->user_data;
|
||||||
request->respond = prototype->respond;
|
request->id = id;
|
||||||
request->user_data = prototype->user_data;
|
|
||||||
request->id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
#ifndef WF_JSONRPC_H
|
|
||||||
#define WF_JSONRPC_H
|
|
||||||
|
|
||||||
#include <wf/jsonrpc/api.h>
|
|
||||||
#include <wf/jsonrpc/method_invoke_fn.h>
|
|
||||||
#include <wf/jsonrpc/proxy.h>
|
|
||||||
#include <wf/jsonrpc/proxy_finished_fn.h>
|
|
||||||
#include <wf/jsonrpc/request.h>
|
|
||||||
#include <wf/jsonrpc/response.h>
|
|
||||||
#include <wf/jsonrpc/send_fn.h>
|
|
||||||
#include <wf/jsonrpc/server.h>
|
|
||||||
#include <wf/jsonrpc/status.h>
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||||||
#ifndef WF_JSONRPC_API_H
|
|
||||||
#define WF_JSONRPC_API_H
|
|
||||||
|
|
||||||
#ifndef WF_JSONRPC_API
|
|
||||||
#define WF_JSONRPC_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,11 +0,0 @@
|
|||||||
#ifndef WF_JSONRPC_STATUS_H
|
|
||||||
#define WF_JSONRPC_STATUS_H
|
|
||||||
|
|
||||||
#define WF_JSONRPC_GOOD 0
|
|
||||||
#define WF_JSONRPC_BAD -1
|
|
||||||
#define WF_JSONRPC_BAD_NOTIMPLEMENTED -2
|
|
||||||
#define WF_JSONRPC_BAD_TIMEOUT -3
|
|
||||||
#define WF_JSONRPC_BAD_BUSY -4
|
|
||||||
#define WF_JSONRPC_BAD_FORMAT -5
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,144 +0,0 @@
|
|||||||
#include "wf/jsonrpc.h"
|
|
||||||
|
|
||||||
#include "wf/jsonrpc/impl/proxy.h"
|
|
||||||
#include "wf/jsonrpc/impl/request.h"
|
|
||||||
#include "wf/jsonrpc/impl/response.h"
|
|
||||||
#include "wf/jsonrpc/impl/server.h"
|
|
||||||
|
|
||||||
// proxy
|
|
||||||
|
|
||||||
struct wf_jsonrpc_proxy *
|
|
||||||
wf_jsonrpc_proxy_create(
|
|
||||||
struct wf_timer_manager * manager,
|
|
||||||
int timeout,
|
|
||||||
wf_jsonrpc_send_fn * send,
|
|
||||||
void * user_data)
|
|
||||||
{
|
|
||||||
return wf_jsonrpc_impl_proxy_create(manager, timeout, send, user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_proxy_dispose(
|
|
||||||
struct wf_jsonrpc_proxy * proxy)
|
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_proxy_dispose(proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_proxy_invoke(
|
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
|
||||||
wf_jsonrpc_proxy_finished_fn * finished,
|
|
||||||
void * user_data,
|
|
||||||
char const * method_name,
|
|
||||||
char const * param_info,
|
|
||||||
...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, param_info);
|
|
||||||
wf_jsonrpc_impl_proxy_invoke(proxy, finished, user_data, method_name, param_info, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_proxy_notify(
|
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
|
||||||
char const * method_name,
|
|
||||||
char const * param_info,
|
|
||||||
...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, param_info);
|
|
||||||
wf_jsonrpc_impl_proxy_notify(proxy, method_name, param_info, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_proxy_onresult(
|
|
||||||
struct wf_jsonrpc_proxy * proxy,
|
|
||||||
json_t * message)
|
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_proxy_onresult(proxy, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// request
|
|
||||||
|
|
||||||
bool wf_jsonrpc_is_request(
|
|
||||||
json_t * message)
|
|
||||||
{
|
|
||||||
return wf_jsonrpc_impl_is_request(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wf_jsonrpc_request * wf_jsonrpc_request_create(
|
|
||||||
int id,
|
|
||||||
wf_jsonrpc_send_fn * send,
|
|
||||||
void * user_data)
|
|
||||||
{
|
|
||||||
return wf_jsonrpc_impl_request_create(id, send, user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_request_dispose(
|
|
||||||
struct wf_jsonrpc_request * request)
|
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_request_dispose(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
void * wf_jsonrpc_request_get_userdata(
|
|
||||||
struct wf_jsonrpc_request * request)
|
|
||||||
{
|
|
||||||
return wf_jsonrpc_impl_request_get_userdata(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_respond(
|
|
||||||
struct wf_jsonrpc_request * request,
|
|
||||||
json_t * result)
|
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_respond(request, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_respond_error(
|
|
||||||
struct wf_jsonrpc_request * request,
|
|
||||||
int code,
|
|
||||||
char const * message)
|
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_respond_error(request, code, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// response
|
|
||||||
|
|
||||||
bool wf_jsonrpc_is_response(
|
|
||||||
json_t * message)
|
|
||||||
{
|
|
||||||
return wf_jsonrpc_impl_is_response(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// server
|
|
||||||
|
|
||||||
struct wf_jsonrpc_server *
|
|
||||||
wf_jsonrpc_server_create(void)
|
|
||||||
{
|
|
||||||
return wf_jsonrpc_impl_server_create();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
wf_jsonrpc_server_dispose(
|
|
||||||
struct wf_jsonrpc_server * server)
|
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_server_dispose(server);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_server_add(
|
|
||||||
struct wf_jsonrpc_server * server,
|
|
||||||
char const * method_name,
|
|
||||||
wf_jsonrpc_method_invoke_fn * invoke,
|
|
||||||
void * user_data)
|
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_server_add(server, method_name, invoke, user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wf_jsonrpc_server_process(
|
|
||||||
struct wf_jsonrpc_server * server,
|
|
||||||
json_t * request,
|
|
||||||
wf_jsonrpc_send_fn * send,
|
|
||||||
void * user_data)
|
|
||||||
{
|
|
||||||
wf_jsonrpc_impl_server_process(server, request, send, user_data);
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
#ifndef WF_JSONRPC_IMPL_REQUEST_H
|
|
||||||
#define WF_JSONRPC_IMPL_REQUEST_H
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#else
|
|
||||||
#include <cstdarg>
|
|
||||||
#include <cstddef>
|
|
||||||
using std::size_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <jansson.h>
|
|
||||||
#include <wf/jsonrpc/api.h>
|
|
||||||
#include "wf/jsonrpc/send_fn.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wf_jsonrpc_request;
|
|
||||||
|
|
||||||
extern bool wf_jsonrpc_impl_is_request(
|
|
||||||
json_t * message);
|
|
||||||
|
|
||||||
extern struct wf_jsonrpc_request * wf_jsonrpc_impl_request_create(
|
|
||||||
int id,
|
|
||||||
wf_jsonrpc_send_fn * send,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern void wf_jsonrpc_impl_request_dispose(
|
|
||||||
struct wf_jsonrpc_request * request);
|
|
||||||
|
|
||||||
extern void * wf_jsonrpc_impl_request_get_userdata(
|
|
||||||
struct wf_jsonrpc_request * request);
|
|
||||||
|
|
||||||
extern void wf_jsonrpc_impl_respond(
|
|
||||||
struct wf_jsonrpc_request * request,
|
|
||||||
json_t * result);
|
|
||||||
|
|
||||||
extern void wf_jsonrpc_impl_respond_error(
|
|
||||||
struct wf_jsonrpc_request * request,
|
|
||||||
int code,
|
|
||||||
char const * message);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,41 +0,0 @@
|
|||||||
#ifndef WF_JSONRPC_IMPL_SERVER_H
|
|
||||||
#define WF_JSONRPC_IMPL_SERVER_H
|
|
||||||
|
|
||||||
#include <jansson.h>
|
|
||||||
#include "wf/jsonrpc/method_invoke_fn.h"
|
|
||||||
#include "wf/jsonrpc/send_fn.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wf_jsonrpc_server;
|
|
||||||
|
|
||||||
extern struct wf_jsonrpc_server *
|
|
||||||
wf_jsonrpc_impl_server_create(void);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wf_jsonrpc_impl_server_dispose(
|
|
||||||
struct wf_jsonrpc_server * server);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wf_jsonrpc_impl_server_add(
|
|
||||||
struct wf_jsonrpc_server * server,
|
|
||||||
char const * method_name,
|
|
||||||
wf_jsonrpc_method_invoke_fn * invoke,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wf_jsonrpc_impl_server_process(
|
|
||||||
struct wf_jsonrpc_server * server,
|
|
||||||
json_t * request,
|
|
||||||
wf_jsonrpc_send_fn * send,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,10 +0,0 @@
|
|||||||
#ifndef WF_JSONRPC_UTIL_H
|
|
||||||
#define WF_JSONRPC_UTIL_H
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define WF_JSONRPC_UNUSED_PARAM(param) param __attribute__((unused))
|
|
||||||
#else
|
|
||||||
#define WF_JSONRPC_UNUSED_PARAM(param)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include "wf/jsonrpc/impl/response.h"
|
|
||||||
#include "wf/jsonrpc/status.h"
|
|
||||||
|
|
||||||
TEST(wf_json_response, init_result)
|
|
||||||
{
|
|
||||||
json_t * message = json_object();
|
|
||||||
json_object_set_new(message, "result", json_integer(47));
|
|
||||||
json_object_set_new(message, "id", json_integer(11));
|
|
||||||
|
|
||||||
struct wf_jsonrpc_response response;
|
|
||||||
wf_jsonrpc_impl_response_init(&response, message);
|
|
||||||
|
|
||||||
ASSERT_EQ(nullptr, response.error);
|
|
||||||
ASSERT_TRUE(json_is_integer(response.result));
|
|
||||||
ASSERT_EQ(47, json_integer_value(response.result));
|
|
||||||
ASSERT_EQ(11, response.id);
|
|
||||||
|
|
||||||
wf_jsonrpc_impl_response_cleanup(&response);
|
|
||||||
json_decref(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_json_response, init_error)
|
|
||||||
{
|
|
||||||
json_t * message = json_object();
|
|
||||||
json_t * err = json_object();
|
|
||||||
json_object_set_new(err, "code", json_integer(42));
|
|
||||||
json_object_set_new(err, "message", json_string("Don't Panic!"));
|
|
||||||
json_object_set_new(message, "error", err);
|
|
||||||
json_object_set_new(message, "id", json_integer(23));
|
|
||||||
|
|
||||||
struct wf_jsonrpc_response response;
|
|
||||||
wf_jsonrpc_impl_response_init(&response, message);
|
|
||||||
|
|
||||||
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
|
|
||||||
ASSERT_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message")));
|
|
||||||
ASSERT_EQ(nullptr, response.result);
|
|
||||||
ASSERT_EQ(23, response.id);
|
|
||||||
|
|
||||||
wf_jsonrpc_impl_response_cleanup(&response);
|
|
||||||
json_decref(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_json_response, init_format_error)
|
|
||||||
{
|
|
||||||
json_t * message = json_object();
|
|
||||||
json_object_set_new(message, "id", json_integer(12));
|
|
||||||
|
|
||||||
struct wf_jsonrpc_response response;
|
|
||||||
wf_jsonrpc_impl_response_init(&response, message);
|
|
||||||
|
|
||||||
ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
|
|
||||||
ASSERT_EQ(nullptr, response.result);
|
|
||||||
ASSERT_EQ(12, response.id);
|
|
||||||
|
|
||||||
wf_jsonrpc_impl_response_cleanup(&response);
|
|
||||||
json_decref(message);
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include "wf/jsonrpc/server.h"
|
|
||||||
#include "wf/jsonrpc/request.h"
|
|
||||||
#include "wf/jsonrpc/status.h"
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
struct Context
|
|
||||||
{
|
|
||||||
json_t * response;
|
|
||||||
bool is_called;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool jsonrpc_send(
|
|
||||||
json_t * request,
|
|
||||||
void * user_data)
|
|
||||||
{
|
|
||||||
Context * context = reinterpret_cast<Context*>(user_data);
|
|
||||||
context->is_called = true;
|
|
||||||
context->response = request;
|
|
||||||
json_incref(request);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sayHello(
|
|
||||||
struct wf_jsonrpc_request * request,
|
|
||||||
char const * method_name,
|
|
||||||
json_t * params,
|
|
||||||
void * user_data)
|
|
||||||
{
|
|
||||||
(void) method_name;
|
|
||||||
(void) params;
|
|
||||||
(void) user_data;
|
|
||||||
|
|
||||||
json_t * result = json_string("Hello");
|
|
||||||
wf_jsonrpc_respond(request, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_jsonrpc_server, process_request)
|
|
||||||
{
|
|
||||||
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
|
|
||||||
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
|
|
||||||
|
|
||||||
Context context{nullptr, false};
|
|
||||||
void * user_data = reinterpret_cast<void*>(&context);
|
|
||||||
json_t * request = json_object();
|
|
||||||
json_object_set_new(request, "method", json_string("sayHello"));
|
|
||||||
json_object_set_new(request, "params", json_array());
|
|
||||||
json_object_set_new(request, "id", json_integer(23));
|
|
||||||
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
|
||||||
|
|
||||||
ASSERT_TRUE(context.is_called);
|
|
||||||
ASSERT_NE(nullptr, context.response);
|
|
||||||
ASSERT_TRUE(json_is_object(context.response));
|
|
||||||
|
|
||||||
json_t * id = json_object_get(context.response, "id");
|
|
||||||
ASSERT_TRUE(json_is_integer(id));
|
|
||||||
ASSERT_EQ(23, json_integer_value(id));
|
|
||||||
|
|
||||||
json_t * result = json_object_get(context.response, "result");
|
|
||||||
ASSERT_TRUE(json_is_string(result));
|
|
||||||
ASSERT_STREQ("Hello", json_string_value(result));
|
|
||||||
|
|
||||||
json_decref(context.response);
|
|
||||||
json_decref(request);
|
|
||||||
wf_jsonrpc_server_dispose(server);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_jsonrpc_server, invoke_unknown_method)
|
|
||||||
{
|
|
||||||
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
|
|
||||||
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
|
|
||||||
|
|
||||||
Context context{nullptr, false};
|
|
||||||
void * user_data = reinterpret_cast<void*>(&context);
|
|
||||||
json_t * request = json_object();
|
|
||||||
json_object_set_new(request, "method", json_string("greet"));
|
|
||||||
json_object_set_new(request, "params", json_array());
|
|
||||||
json_object_set_new(request, "id", json_integer(42));
|
|
||||||
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
|
||||||
|
|
||||||
ASSERT_TRUE(context.is_called);
|
|
||||||
ASSERT_NE(nullptr, context.response);
|
|
||||||
ASSERT_TRUE(json_is_object(context.response));
|
|
||||||
|
|
||||||
json_t * id = json_object_get(context.response, "id");
|
|
||||||
ASSERT_TRUE(json_is_integer(id));
|
|
||||||
ASSERT_EQ(42, json_integer_value(id));
|
|
||||||
|
|
||||||
json_t * err = json_object_get(context.response, "error");
|
|
||||||
ASSERT_TRUE(json_is_object(err));
|
|
||||||
|
|
||||||
json_t * err_code = json_object_get(err, "code");
|
|
||||||
ASSERT_TRUE(json_is_integer(err_code));
|
|
||||||
ASSERT_EQ(WF_JSONRPC_BAD_NOTIMPLEMENTED, json_integer_value(err_code));
|
|
||||||
|
|
||||||
json_t * err_message = json_object_get(err, "message");
|
|
||||||
ASSERT_TRUE(json_is_string(err_message));
|
|
||||||
|
|
||||||
json_decref(context.response);
|
|
||||||
json_decref(request);
|
|
||||||
wf_jsonrpc_server_dispose(server);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_jsonrpc_server, skip_invalid_request)
|
|
||||||
{
|
|
||||||
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
|
|
||||||
|
|
||||||
Context context{nullptr, false};
|
|
||||||
void * user_data = reinterpret_cast<void*>(&context);
|
|
||||||
json_t * request = json_object();
|
|
||||||
json_object_set_new(request, "method", json_string("sayHello"));
|
|
||||||
json_object_set_new(request, "params", json_array());
|
|
||||||
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
|
|
||||||
|
|
||||||
ASSERT_FALSE(context.is_called);
|
|
||||||
|
|
||||||
json_decref(request);
|
|
||||||
wf_jsonrpc_server_dispose(server);
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
#ifndef WF_TIMER_H
|
|
||||||
#define WF_TIMER_H
|
|
||||||
|
|
||||||
#include <wf/timer/api.h>
|
|
||||||
#include <wf/timer/on_timer_fn.h>
|
|
||||||
#include <wf/timer/timer.h>
|
|
||||||
#include <wf/timer/manager.h>
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||||||
#ifndef WF_TIMER_API_H
|
|
||||||
#define WF_TIMER_API_H
|
|
||||||
|
|
||||||
#ifndef WF_TIMER_API
|
|
||||||
#define WF_TIMER_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,59 +0,0 @@
|
|||||||
#include "wf/timer.h"
|
|
||||||
|
|
||||||
#include "wf/timer/impl/manager.h"
|
|
||||||
#include "wf/timer/impl/timer.h"
|
|
||||||
|
|
||||||
// manager
|
|
||||||
|
|
||||||
struct wf_timer_manager *
|
|
||||||
wf_timer_manager_create(void)
|
|
||||||
{
|
|
||||||
return wf_timer_impl_manager_create();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
wf_timer_manager_dispose(
|
|
||||||
struct wf_timer_manager * manager)
|
|
||||||
{
|
|
||||||
wf_timer_impl_manager_dispose(manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
wf_timer_manager_check(
|
|
||||||
struct wf_timer_manager * manager)
|
|
||||||
{
|
|
||||||
wf_timer_impl_manager_check(manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
// timer
|
|
||||||
|
|
||||||
struct wf_timer *
|
|
||||||
wf_timer_create(
|
|
||||||
struct wf_timer_manager * manager,
|
|
||||||
wf_timer_on_timer_fn * on_timer,
|
|
||||||
void * user_data)
|
|
||||||
{
|
|
||||||
return wf_timer_impl_create(manager, on_timer, user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
wf_timer_dispose(
|
|
||||||
struct wf_timer * timer)
|
|
||||||
{
|
|
||||||
wf_timer_impl_dispose(timer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
wf_timer_start(
|
|
||||||
struct wf_timer * timer,
|
|
||||||
int timeout_ms)
|
|
||||||
{
|
|
||||||
wf_timer_impl_start(timer, timeout_ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
wf_timer_cancel(
|
|
||||||
struct wf_timer * timer)
|
|
||||||
{
|
|
||||||
wf_timer_impl_cancel(timer);
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
#ifndef WF_TIMER_IMPL_MANAGER_H
|
|
||||||
#define WF_TIMER_IMPL_MANAGER_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wf_timer;
|
|
||||||
struct wf_timer_manager;
|
|
||||||
|
|
||||||
extern struct wf_timer_manager *
|
|
||||||
wf_timer_impl_manager_create(void);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wf_timer_impl_manager_dispose(
|
|
||||||
struct wf_timer_manager * manager);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wf_timer_impl_manager_check(
|
|
||||||
struct wf_timer_manager * manager);
|
|
||||||
|
|
||||||
extern void wf_timer_impl_manager_addtimer(
|
|
||||||
struct wf_timer_manager * manager,
|
|
||||||
struct wf_timer * timer);
|
|
||||||
|
|
||||||
extern void wf_timer_impl_manager_removetimer(
|
|
||||||
struct wf_timer_manager * manager,
|
|
||||||
struct wf_timer * timer);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,59 +0,0 @@
|
|||||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMER_H
|
|
||||||
#define WF_ADAPTER_IMPL_TIME_TIMER_H
|
|
||||||
|
|
||||||
#include "wf/timer/on_timer_fn.h"
|
|
||||||
#include "wf/timer/impl/timepoint.h"
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wf_timer_manager;
|
|
||||||
|
|
||||||
struct wf_timer
|
|
||||||
{
|
|
||||||
struct wf_timer_manager * manager;
|
|
||||||
wf_timer_timepoint timeout;
|
|
||||||
wf_timer_on_timer_fn * on_timer;
|
|
||||||
void * user_data;
|
|
||||||
struct wf_timer * next;
|
|
||||||
struct wf_timer * prev;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct wf_timer *
|
|
||||||
wf_timer_impl_create(
|
|
||||||
struct wf_timer_manager * manager,
|
|
||||||
wf_timer_on_timer_fn * on_timer,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
void
|
|
||||||
wf_timer_impl_dispose(
|
|
||||||
struct wf_timer * timer);
|
|
||||||
|
|
||||||
extern void wf_timer_impl_start(
|
|
||||||
struct wf_timer * timer,
|
|
||||||
int timeout_ms);
|
|
||||||
|
|
||||||
extern void wf_timer_impl_cancel(
|
|
||||||
struct wf_timer * timer);
|
|
||||||
|
|
||||||
extern bool wf_timer_impl_is_timeout(
|
|
||||||
struct wf_timer * timer);
|
|
||||||
|
|
||||||
extern void wf_timer_impl_trigger(
|
|
||||||
struct wf_timer * timer);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,38 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "wf/timer/impl/timepoint.h"
|
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
|
|
||||||
TEST(wf_timer_timepoint, now)
|
|
||||||
{
|
|
||||||
wf_timer_timepoint start = wf_timer_impl_timepoint_now();
|
|
||||||
std::this_thread::sleep_for(42ms);
|
|
||||||
wf_timer_timepoint end = wf_timer_impl_timepoint_now();
|
|
||||||
|
|
||||||
ASSERT_LT(start, end);
|
|
||||||
ASSERT_LT(end, start + 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_timer_timepoint, in_msec)
|
|
||||||
{
|
|
||||||
wf_timer_timepoint now = wf_timer_impl_timepoint_now();
|
|
||||||
wf_timer_timepoint later = wf_timer_impl_timepoint_in_msec(42);
|
|
||||||
|
|
||||||
ASSERT_LT(now, later);
|
|
||||||
ASSERT_LT(later, now + 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_timer_timepoint, elapsed)
|
|
||||||
{
|
|
||||||
wf_timer_timepoint now;
|
|
||||||
|
|
||||||
now = wf_timer_impl_timepoint_now();
|
|
||||||
ASSERT_TRUE(wf_timer_impl_timepoint_is_elapsed(now - 1));
|
|
||||||
|
|
||||||
now = wf_timer_impl_timepoint_now();
|
|
||||||
ASSERT_FALSE(wf_timer_impl_timepoint_is_elapsed(now + 500));
|
|
||||||
}
|
|
17
test/webfuse/mocks/fake_invokation_context.cc
Normal file
17
test/webfuse/mocks/fake_invokation_context.cc
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "webfuse/mocks/fake_invokation_context.hpp"
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
wfp_impl_invokation_context create_context(MockProvider& provider, wfp_request * request)
|
||||||
|
{
|
||||||
|
wfp_impl_invokation_context context =
|
||||||
|
{
|
||||||
|
provider.get_provider(),
|
||||||
|
provider.get_userdata(),
|
||||||
|
request
|
||||||
|
};
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
test/webfuse/mocks/fake_invokation_context.hpp
Normal file
16
test/webfuse/mocks/fake_invokation_context.hpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef FAKE_INVOCATION_CONTEXT_HPP
|
||||||
|
#define FAKE_INVOCATION_CONTEXT_HPP
|
||||||
|
|
||||||
|
#include "webfuse/provider/impl/provider.h"
|
||||||
|
#include "webfuse/mocks/mock_provider.hpp"
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
wfp_impl_invokation_context create_context(
|
||||||
|
MockProvider& provider,
|
||||||
|
wfp_request * request = nullptr);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
31
test/webfuse/mocks/mock_fuse.cc
Normal file
31
test/webfuse/mocks/mock_fuse.cc
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "webfuse/mocks/mock_fuse.hpp"
|
||||||
|
#include "webfuse/utils/wrap.hpp"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
static webfuse_test::FuseMock * webfuse_test_FuseMock = nullptr;
|
||||||
|
|
||||||
|
WF_WRAP_FUNC1(webfuse_test_FuseMock, void*, fuse_req_userdata, fuse_req_t);
|
||||||
|
WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_open, fuse_req_t, const struct fuse_file_info *);
|
||||||
|
WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_err, fuse_req_t, int);
|
||||||
|
WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_buf, fuse_req_t, const char *, size_t);
|
||||||
|
WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_attr, fuse_req_t, const struct stat *, double);
|
||||||
|
WF_WRAP_FUNC1(webfuse_test_FuseMock, const struct fuse_ctx *, fuse_req_ctx, fuse_req_t);
|
||||||
|
WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_entry, fuse_req_t, const struct fuse_entry_param *);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
FuseMock::FuseMock()
|
||||||
|
{
|
||||||
|
webfuse_test_FuseMock = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FuseMock::~FuseMock()
|
||||||
|
{
|
||||||
|
webfuse_test_FuseMock = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
27
test/webfuse/mocks/mock_fuse.hpp
Normal file
27
test/webfuse/mocks/mock_fuse.hpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef MOCK_FUSE_HPP
|
||||||
|
#define MOCK_FUSE_HPP
|
||||||
|
|
||||||
|
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
class FuseMock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FuseMock();
|
||||||
|
virtual ~FuseMock();
|
||||||
|
|
||||||
|
MOCK_METHOD1(fuse_req_userdata, void *(fuse_req_t req));
|
||||||
|
MOCK_METHOD2(fuse_reply_open, int (fuse_req_t req, const struct fuse_file_info *fi));
|
||||||
|
MOCK_METHOD2(fuse_reply_err, int (fuse_req_t req, int err));
|
||||||
|
MOCK_METHOD3(fuse_reply_buf, int (fuse_req_t req, const char *buf, size_t size));
|
||||||
|
MOCK_METHOD3(fuse_reply_attr, int (fuse_req_t req, const struct stat *attr, double attr_timeout));
|
||||||
|
MOCK_METHOD1(fuse_req_ctx, const struct fuse_ctx *(fuse_req_t req));
|
||||||
|
MOCK_METHOD2(fuse_reply_entry, int (fuse_req_t req, const struct fuse_entry_param *e));
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
34
test/webfuse/mocks/mock_jsonrpc_proxy.cc
Normal file
34
test/webfuse/mocks/mock_jsonrpc_proxy.cc
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "webfuse/mocks/mock_jsonrpc_proxy.hpp"
|
||||||
|
#include "webfuse/utils/wrap.hpp"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
static webfuse_test::MockJsonRpcProxy * webfuse_test_MockJsonRpcProxy = nullptr;
|
||||||
|
|
||||||
|
WF_WRAP_VFUNC5(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke,
|
||||||
|
struct wf_jsonrpc_proxy *,
|
||||||
|
wf_jsonrpc_proxy_finished_fn *,
|
||||||
|
void *,
|
||||||
|
char const *,
|
||||||
|
char const *);
|
||||||
|
|
||||||
|
WF_WRAP_VFUNC3(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify,
|
||||||
|
struct wf_jsonrpc_proxy *,
|
||||||
|
char const *,
|
||||||
|
char const *);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
MockJsonRpcProxy::MockJsonRpcProxy()
|
||||||
|
{
|
||||||
|
webfuse_test_MockJsonRpcProxy = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
MockJsonRpcProxy::~MockJsonRpcProxy()
|
||||||
|
{
|
||||||
|
webfuse_test_MockJsonRpcProxy = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
test/webfuse/mocks/mock_jsonrpc_proxy.hpp
Normal file
30
test/webfuse/mocks/mock_jsonrpc_proxy.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef MOCK_JSONRPC_PROXY_HPP
|
||||||
|
#define MOCK_JSONRPC_PROXY_HPP
|
||||||
|
|
||||||
|
#include "webfuse/core/jsonrpc/proxy_intern.h"
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
class MockJsonRpcProxy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MockJsonRpcProxy();
|
||||||
|
virtual ~MockJsonRpcProxy();
|
||||||
|
MOCK_METHOD5(wf_jsonrpc_proxy_vinvoke, void (
|
||||||
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
|
wf_jsonrpc_proxy_finished_fn * finished,
|
||||||
|
void * user_data,
|
||||||
|
char const * method_name,
|
||||||
|
char const * param_info));
|
||||||
|
MOCK_METHOD3(wf_jsonrpc_proxy_vnotify, void (
|
||||||
|
struct wf_jsonrpc_proxy * proxy,
|
||||||
|
char const * method_name,
|
||||||
|
char const * param_info));
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
27
test/webfuse/mocks/mock_operation_context.cc
Normal file
27
test/webfuse/mocks/mock_operation_context.cc
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "webfuse/mocks/mock_operation_context.hpp"
|
||||||
|
#include "webfuse/utils/wrap.hpp"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
static webfuse_test::MockOperationContext * webfuse_test_MockOperationContext = nullptr;
|
||||||
|
|
||||||
|
WF_WRAP_FUNC1(webfuse_test_MockOperationContext,
|
||||||
|
struct wf_jsonrpc_proxy *, wf_impl_operation_context_get_proxy,
|
||||||
|
struct wf_impl_operation_context *);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
MockOperationContext::MockOperationContext()
|
||||||
|
{
|
||||||
|
webfuse_test_MockOperationContext = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
MockOperationContext::~MockOperationContext()
|
||||||
|
{
|
||||||
|
webfuse_test_MockOperationContext = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user