From 9c7fe8531299a955834d8ef4e2d87630caed2ca3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 25 May 2019 01:57:04 +0200 Subject: [PATCH 001/138] replaces amd64-debian with amd64-alpine image --- CMakeLists.txt | 30 ++++++------- Makefile | 8 +++- ...erfile => amd64-alpine-builder.dockerfile} | 43 ++++++++++--------- 3 files changed, 45 insertions(+), 36 deletions(-) rename build/{amd64-debian-builder.dockerfile => amd64-alpine-builder.dockerfile} (74%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ce597b..a1170c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,24 +22,24 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(C_WARNINGS -Wall -Wextra) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") +#if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") +# +#add_definitions( +# -pg +# --coverage +# -fprofile-arcs +# -ftest-coverage +#) -add_definitions( - -pg - --coverage - -fprofile-arcs - -ftest-coverage -) +#if(CMAKE_C_COMPILER_ID STREQUAL "GNU") +# link_libraries(gcov) +#else() +# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") +#endif() -if(CMAKE_C_COMPILER_ID STREQUAL "GNU") - link_libraries(gcov) -else() - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") -endif() +#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -fprofile-arcs") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs") - -endif() +#endif() include_directories( "include" diff --git a/Makefile b/Makefile index b0982c5..fe9c5d9 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ CONTAINER_GROUP ?= user UBUNTU_CODENAME ?= bionic DEBIAN_CODENAME ?= testing-slim +ALPINE_CODENAME ?= 3.9 SKIP_MD5SUM ?= $(call filter_out_command,md5sum) SKIP_MD5SUM := $(SKIP_MD5SUM) @@ -84,7 +85,7 @@ $(SKIP_MD5SUM)$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa0 # Architecture-specific rule target configuration CMAKE_TARGETS += amd64-ubuntu-builder -CMAKE_TARGETS += amd64-debian-builder +CMAKE_TARGETS += amd64-alpine-builder CMAKE_TARGETS += arm32v7-ubuntu-builder CMAKE_TARGETS += arm32v7-debian-builder @@ -96,6 +97,9 @@ UBUNTU_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(UBUNTU_FI DEBIAN_FILTER = $(call regex_march_distro,'.*','debian') DEBIAN_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(DEBIAN_FILTER),$(TARGETS))) +ALPINE_FILTER = $(call regex_march_distro,'.*','alpine') +ALPINE_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(ALPINE_FILTER),$(TARGETS))) + ####################################################################################################################### # Common rule target configuration @@ -140,6 +144,8 @@ $(UBUNTU_TARGETS): CODENAME := $(UBUNTU_CODENAME) $(DEBIAN_TARGETS): CODENAME := $(DEBIAN_CODENAME) +$(ALPINE_TARGETS): CODENAME := $(ALPINE_CODENAME) + $(FETCH_TARGETS): | $(FETCHDIR) $(SILENT)$(call curl,$@,$(URL),$(MD5)) diff --git a/build/amd64-debian-builder.dockerfile b/build/amd64-alpine-builder.dockerfile similarity index 74% rename from build/amd64-debian-builder.dockerfile rename to build/amd64-alpine-builder.dockerfile index 5231e2d..7dd8194 100644 --- a/build/amd64-debian-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -1,20 +1,23 @@ ARG REGISTRY_PREFIX='' -ARG CODENAME=testing-slim +ARG CODENAME=3.9 -FROM ${REGISTRY_PREFIX}debian:${CODENAME} as builder +FROM ${REGISTRY_PREFIX}alpine:${CODENAME} as builder RUN set -x \ - && apt update \ - && apt upgrade -y \ - && apt install --yes --no-install-recommends \ - build-essential \ + && apk add --no-cache \ + bash \ + coreutils \ + gcc \ + g++ \ + make \ cmake \ - ninja-build \ - pkg-config \ + ninja \ + pkgconf \ rsync \ gdb \ - gdbserver \ - valgrind + valgrind \ + util-linux \ + util-linux-dev COPY src /usr/local/src @@ -23,8 +26,8 @@ ARG PARALLELMFLAGS=-j2 ARG DUMB_INIT_VERSION=1.2.2 RUN set -x \ - && builddeps="xxd" \ - && apt install --yes --no-install-recommends $builddeps \ + && builddeps="vim" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -35,7 +38,7 @@ RUN set -x \ && mv dumb-init /usr/local/bin/dumb-init \ && dumb-init --version \ && rm -rf "$builddir" \ - && apt purge -y $builddeps + && apk del .build-deps ARG GTEST_VERSION=1.8.1 @@ -50,8 +53,8 @@ RUN set -x \ ARG FUSE_VERSION=3.1.1 RUN set -x \ - && builddeps="libtool automake gettext" \ - && apt install --yes --no-install-recommends $builddeps \ + && builddeps="libtool automake autoconf gettext-dev m4 linux-headers" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ && ./makeconf.sh \ && builddir="/tmp/out" \ @@ -60,15 +63,15 @@ RUN set -x \ && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" \ - && apt purge -y $builddeps + && apk del .build-deps ARG WEBSOCKETS_VERSION=3.1.0 RUN set -x \ - && apt install --yes --no-install-recommends \ + && apk add --no-cache \ ca-certificates \ openssl \ - libssl-dev \ + openssl-dev \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -87,6 +90,7 @@ RUN set -x \ && rm -rf "$builddir" ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" +ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig ARG USERID=1000 @@ -95,7 +99,7 @@ ARG OUTDIR=/workspace/out ARG SCRIPTDIR=/workspace/bin RUN set -x \ - && useradd -u "$USERID" -ms /bin/bash user \ + && adduser -u "$USERID" -s /bin/bash -D user \ && mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \ && chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" @@ -105,4 +109,3 @@ ENTRYPOINT ["dumb-init", "--"] # unused ARG QEMU_VERSION_=v3.1.0-2 - From 8ede6595d93743bc5db0bdbe4e29063f70976d2c Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 25 May 2019 02:44:32 +0200 Subject: [PATCH 002/138] replaces arm32v7-debian by arm32v7-alpine image --- Makefile | 8 +--- ...file => arm32v7-alpine-builder.dockerfile} | 41 +++++++++++-------- 2 files changed, 24 insertions(+), 25 deletions(-) rename build/{arm32v7-debian-builder.dockerfile => arm32v7-alpine-builder.dockerfile} (75%) diff --git a/Makefile b/Makefile index fe9c5d9..8c74204 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,6 @@ CONTAINER_USER ?= user CONTAINER_GROUP ?= user UBUNTU_CODENAME ?= bionic -DEBIAN_CODENAME ?= testing-slim ALPINE_CODENAME ?= 3.9 SKIP_MD5SUM ?= $(call filter_out_command,md5sum) @@ -87,16 +86,13 @@ $(SKIP_MD5SUM)$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa0 CMAKE_TARGETS += amd64-ubuntu-builder CMAKE_TARGETS += amd64-alpine-builder CMAKE_TARGETS += arm32v7-ubuntu-builder -CMAKE_TARGETS += arm32v7-debian-builder +CMAKE_TARGETS += arm32v7-alpine-builder MEMCHECK_FILTER = $(call regex_march_distro,'$(HOST_MARCH)','.*') UBUNTU_FILTER = $(call regex_march_distro,'.*','ubuntu') UBUNTU_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(UBUNTU_FILTER),$(TARGETS))) -DEBIAN_FILTER = $(call regex_march_distro,'.*','debian') -DEBIAN_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(DEBIAN_FILTER),$(TARGETS))) - ALPINE_FILTER = $(call regex_march_distro,'.*','alpine') ALPINE_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(ALPINE_FILTER),$(TARGETS))) @@ -142,8 +138,6 @@ $(CHECK_TARGETS): GOALS := test $(UBUNTU_TARGETS): CODENAME := $(UBUNTU_CODENAME) -$(DEBIAN_TARGETS): CODENAME := $(DEBIAN_CODENAME) - $(ALPINE_TARGETS): CODENAME := $(ALPINE_CODENAME) $(FETCH_TARGETS): | $(FETCHDIR) diff --git a/build/arm32v7-debian-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile similarity index 75% rename from build/arm32v7-debian-builder.dockerfile rename to build/arm32v7-alpine-builder.dockerfile index b34fdfa..a60bc80 100644 --- a/build/arm32v7-debian-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -1,23 +1,27 @@ ARG REGISTRY_PREFIX='' -ARG CODENAME=testing-slim +ARG CODENAME=3.9 -FROM ${REGISTRY_PREFIX}arm32v7/debian:${CODENAME} as builder +FROM ${REGISTRY_PREFIX}arm32v7/alpine:${CODENAME} as builder ARG QEMU_VERSION_=v3.1.0-2 COPY docker/qemu-arm-static-$QEMU_VERSION_ /usr/bin/qemu-arm-static RUN set -x \ - && apt update \ - && apt upgrade -y \ - && apt install --yes --no-install-recommends \ - build-essential \ + && apk add --no-cache \ + bash \ + coreutils \ + gcc \ + g++ \ + make \ cmake \ - ninja-build \ - pkg-config \ + ninja \ + pkgconf \ rsync \ gdb \ - gdbserver + valgrind \ + util-linux \ + util-linux-dev COPY src /usr/local/src @@ -26,8 +30,8 @@ ARG PARALLELMFLAGS=-j2 ARG DUMB_INIT_VERSION=1.2.2 RUN set -x \ - && builddeps="xxd" \ - && apt install --yes --no-install-recommends $builddeps \ + && builddeps="vim" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -38,7 +42,7 @@ RUN set -x \ && mv dumb-init /usr/local/bin/dumb-init \ && dumb-init --version \ && rm -rf "$builddir" \ - && apt purge -y $builddeps + && apk del .build-deps ARG GTEST_VERSION=1.8.1 @@ -53,8 +57,8 @@ RUN set -x \ ARG FUSE_VERSION=3.1.1 RUN set -x \ - && builddeps="libtool automake gettext" \ - && apt install --yes --no-install-recommends $builddeps \ + && builddeps="libtool automake autoconf gettext-dev m4 linux-headers" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ && ./makeconf.sh \ && builddir="/tmp/out" \ @@ -63,15 +67,15 @@ RUN set -x \ && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" \ - && apt purge -y $builddeps + && apk del .build-deps ARG WEBSOCKETS_VERSION=3.1.0 RUN set -x \ - && apt install --yes --no-install-recommends \ + && apk add --no-cache \ ca-certificates \ openssl \ - libssl-dev \ + openssl-dev \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -90,6 +94,7 @@ RUN set -x \ && rm -rf "$builddir" ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" +ENV PKG_CONFIG_PATH=/usr/local/lib32/pkgconfig ARG USERID=1000 @@ -98,7 +103,7 @@ ARG OUTDIR=/workspace/out ARG SCRIPTDIR=/workspace/bin RUN set -x \ - && useradd -u "$USERID" -ms /bin/bash user \ + && adduser -u "$USERID" -s /bin/bash -D user \ && mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \ && chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" From 943499118471c99fc7f822d955bcbee8b911fd33 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 25 May 2019 03:18:25 +0200 Subject: [PATCH 003/138] enables coverage generation again (but uses guard) --- .travis.yml | 12 ++++++------ CMakeLists.txt | 35 ++++++++++++++++++----------------- Makefile | 3 +++ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index c4da690..9166367 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,13 +16,13 @@ env: - PARALLELMFLAGS="-j4" - PORTABLE_WORSPACE=1 matrix: - - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check - - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check + - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck COVERAGE=ON + - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck COVERAGE=OFF + - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check COVERAGE=OFF + - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check COVERAGE=OFF before_script: -- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH +- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH COVERAGE=$COVERAGE script: -- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET +- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH COVERAGE=$COVERAGE $CHECK_TARGET after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1170c1..58aac5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,9 @@ cmake_minimum_required (VERSION 3.10) project(webfuse VERSION 0.2.0 DESCRIPTION "Websocket filesystem based on libfuse") -option(WITHOUT_TESTS "disable unit tests" OFF) -option(WITHOUT_EXAMPLE "disable example" OFF) +option(WITHOUT_TESTS "disable unit tests" OFF) +option(WITHOUT_EXAMPLE "disable example" OFF) +option(WITH_COVERAGE "enable code coverage" OFF) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) @@ -22,24 +23,24 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(C_WARNINGS -Wall -Wextra) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -#if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") -# -#add_definitions( -# -pg -# --coverage -# -fprofile-arcs -# -ftest-coverage -#) +if(("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND WITHOUT_COVERAGE) -#if(CMAKE_C_COMPILER_ID STREQUAL "GNU") -# link_libraries(gcov) -#else() -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") -#endif() +add_definitions( + -pg + --coverage + -fprofile-arcs + -ftest-coverage +) -#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -fprofile-arcs") +if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + link_libraries(gcov) +else() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") +endif() -#endif() +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -fprofile-arcs") + +endif() include_directories( "include" diff --git a/Makefile b/Makefile index 8c74204..2929f83 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ SCRIPTDIR ?= $(PROJECTDIR)/build/mkdocker OUTDIR ?= $(PROJECTDIR)/.build FETCHDIR ?= $(PROJECTDIR)/.deps BUILDTYPE ?= Debug +COVERAGE ?= OFF SKIP_FETCH ?= @@ -115,6 +116,8 @@ OUTDIRS += $(OUTDIR)/src EXTRACT_TARGETS += $(OUTDIR)/docker/qemu-arm-static-$(QEMU_VERSION) EXTRACT_TARGETS += $(patsubst $(FETCHDIR)/%.tar.gz,$(OUTDIR)/src/%,$(FETCH_TARGETS)) +CMAKEFLAGS += -DWITH_COVERAGE=$(COVERAGE) + ####################################################################################################################### # Makefile dependencies From 6f792cc368de95d07acc32aa190d2cf8c9f451c1 Mon Sep 17 00:00:00 2001 From: Falk Werner <47070255+falk-werner@users.noreply.github.com> Date: Sat, 25 May 2019 09:18:36 +0200 Subject: [PATCH 004/138] removes unused scripts (#36) --- install_deps.sh | 172 ---------------------------------------------- run-clang-tidy.sh | 8 --- 2 files changed, 180 deletions(-) delete mode 100755 install_deps.sh delete mode 100755 run-clang-tidy.sh diff --git a/install_deps.sh b/install_deps.sh deleted file mode 100755 index cb1e4a8..0000000 --- a/install_deps.sh +++ /dev/null @@ -1,172 +0,0 @@ -#!/bin/bash -# -# Checks for dependencies and install them, if needed. -# -# A valid package description is defined as follows: -# local _name= -# local _type= -# local _archive= -# local _dir= -# local _url= -# -# - symbolid id of package -# - name of the package (used for pkg-config) -# - type of project ("cmake" or "autotools") -# - archive file name -# - dir of package sources -# - url of the project archive -# -# For examples, see below. -# -# Since _ variables are not used directly, shellcheck will complain: -# shellcheck disable=SC2034 - - -####################################### -# Installs a cmake package. -# -# Arguments: -# package - name of package -# Returns: -# 0 on success, otherwise failure -####################################### -function install_cmake_package() { - local package="$1" - local archive="${package}_archive" - local dir="${package}_dir" - local url="${package}_url" - - wget -O "${!archive}" "${!url}" && \ - tar -xf "${!archive}" && \ - cd "${!dir}" && \ - mkdir .build && \ - cd .build && \ - cmake .. && \ - make && \ - sudo make install && \ - cd .. && \ - cd .. - - return "$?" -} - -####################################### -# Installs a autotools package. -# -# Arguments: -# package - name of package -# Returns: -# 0 on success, otherwise failure -####################################### -function install_autotools_package() { - local package="$1" - local archive="${package}_archive" - local dir="${package}_dir" - local url="${package}_url" - - wget -O "${!archive}" "${!url}" && \ - tar -xf "${!archive}" && \ - cd "${!dir}" && \ - ./makeconf.sh && \ - ./configure && \ - make && \ - sudo make install && \ - cd .. - - return "$?" -} - -####################################### -# Checks, whether a package exists. -# -# Arguments: -# package_name - name of package -# Returns: -# 0 if package exists, otherwise failure -####################################### -function package_exists() { - local package_name="$1" - - pkg-config --exists "${package_name}" - return "$?" -} - -####################################### -# Installs a package, if it is not available. -# -# Arguments: -# package - name of package -# Returns: -# 0 if package exists, otherwise failure -####################################### -function install_if_needed() { - local package="$1" - local package_name="${package}_name" - local package_type="${package}_type" - local result=0 - - package_exists "${!package_name}" - if [[ "$?" -ne 0 ]]; then - "install_${!package_type}_package" "$package" - result="$?" - fi - - return "${result}" -} - -####################################### -# Main -# -# Arguments: -# None -# Returns: -# 0 on success, otherwise failure -####################################### -function main() { - rm -rf .deps - mkdir .deps - cd .deps - - local packages=(fuse3 lws jansson gtest) - - local fuse3_name=fuse3 - local fuse3_type=autotools - local fuse3_archive=fuse-3.1.1.tar.gz - local fuse3_dir=libfuse-fuse-3.1.1 - local fuse3_url=https://github.com/libfuse/libfuse/archive/fuse-3.1.1.tar.gz - - local lws_name=libwebsockets - local lws_type=cmake - local lws_archive=libwebsockets-3.1.0.tar.gz - local lws_dir=libwebsockets-3.1.0 - local lws_url=https://github.com/warmcat/libwebsockets/archive/v3.1.0.tar.gz - - local jansson_name=jansson - local jansson_type=cmake - local jansson_archive=libjansson-2.12.tar.gz - local jansson_dir=jansson-2.12 - local jansson_url=https://github.com/akheron/jansson/archive/v2.12.tar.gz - - local gtest_name=gtest_main - local gtest_type=cmake - local gtest_archive=gtest-1.8.1.tar.gz - local gtest_dir=googletest-release-1.8.1 - local gtest_url=https://github.com/google/googletest/archive/release-1.8.1.tar.gz - - local result=0 - local package="" - for package in "${packages[@]}" ; do - install_if_needed $package - result="$?" - - if [[ "${result}" -ne 0 ]] ; then - cd .. - return "${result}" - fi - done - - cd .. - return 0 -} - -main "$@" diff --git a/run-clang-tidy.sh b/run-clang-tidy.sh deleted file mode 100755 index f4e98d4..0000000 --- a/run-clang-tidy.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# -# Helper to run clang-tidy to perform some additional checks. - -FILES=$(find lib -name '*.c') -INCLUDES="-Iinclude -Ilib $(pkg-config fuse3 --cflags) $(pkg-config libwebsockets --cflags)" - -clang-tidy -header-filter='.*' ${FILES} -- ${INCLUDES} From a0ae32caa65115cd8d3ce8a07c574d18c33d094c Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 25 May 2019 02:07:35 +0200 Subject: [PATCH 005/138] fixes adding multiple files to same directory --- lib/webfuse/provider/impl/static_filesystem.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/webfuse/provider/impl/static_filesystem.c b/lib/webfuse/provider/impl/static_filesystem.c index f378f3d..aeb9c54 100644 --- a/lib/webfuse/provider/impl/static_filesystem.c +++ b/lib/webfuse/provider/impl/static_filesystem.c @@ -182,8 +182,6 @@ wfp_impl_static_filesystem_add_dir( char const * name ) { - size_t result = 0; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry_by_name(filesystem, parent, name); if (NULL == entry) { @@ -197,11 +195,9 @@ wfp_impl_static_filesystem_add_dir( entry->get_info = &wfp_impl_static_filesystem_entry_get_info; entry->size = 0; entry->content = NULL; - - result = entry->inode; } - - return result; + + return entry->inode; } static size_t From 2ab4ce0c5c840e08596327736786a6fb3fd8d705 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 25 May 2019 02:08:50 +0200 Subject: [PATCH 006/138] fixes crash using -h / --help arguments --- example/provider/static_filesystem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/example/provider/static_filesystem.c b/example/provider/static_filesystem.c index ee06489..631274e 100644 --- a/example/provider/static_filesystem.c +++ b/example/provider/static_filesystem.c @@ -75,12 +75,17 @@ int main(int argc, char* argv[]) struct args args; int result = parse_args(&args, argc, argv); - if (EXIT_SUCCESS == result) + if ((EXIT_SUCCESS == result) && (!args.show_help)) { struct wfp_client_config * config = wfp_client_config_create(); struct wfp_static_filesystem * fs = wfp_static_filesystem_create(config); - wfp_static_filesystem_add_text(fs, "hello.txt", 0444, "Hello, World!"); + wfp_static_filesystem_add_text(fs, "brummni/hello_world.txt", 0444, "Hello, World!\n"); + wfp_static_filesystem_add_text(fs, "brummni/hello_bob.txt", 0444, "Hello, Bob!\n"); + wfp_static_filesystem_add_text(fs, "brummni/hello_bob.txt", 0444, "Hello, Alice!\n"); + wfp_static_filesystem_add_text(fs, "bla/hello_world.txt", 0444, "Hello, World!\n"); + wfp_static_filesystem_add_text(fs, "foo.txt", 0444, "foo\n"); + wfp_static_filesystem_add_text(fs, "bar.txt", 0444, "bar\n"); struct wfp_client * client = wfp_client_create(config); wfp_client_connect(client, args.url); From 835cd1cb21a1e2c15b26dcec1b08a478c8b9510e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 25 May 2019 01:57:04 +0200 Subject: [PATCH 007/138] replaces amd64-debian with amd64-alpine image --- CMakeLists.txt | 30 ++++++------- Makefile | 8 +++- ...erfile => amd64-alpine-builder.dockerfile} | 43 ++++++++++--------- 3 files changed, 45 insertions(+), 36 deletions(-) rename build/{amd64-debian-builder.dockerfile => amd64-alpine-builder.dockerfile} (74%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ce597b..a1170c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,24 +22,24 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(C_WARNINGS -Wall -Wextra) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") +#if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") +# +#add_definitions( +# -pg +# --coverage +# -fprofile-arcs +# -ftest-coverage +#) -add_definitions( - -pg - --coverage - -fprofile-arcs - -ftest-coverage -) +#if(CMAKE_C_COMPILER_ID STREQUAL "GNU") +# link_libraries(gcov) +#else() +# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") +#endif() -if(CMAKE_C_COMPILER_ID STREQUAL "GNU") - link_libraries(gcov) -else() - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") -endif() +#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -fprofile-arcs") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs") - -endif() +#endif() include_directories( "include" diff --git a/Makefile b/Makefile index b0982c5..fe9c5d9 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ CONTAINER_GROUP ?= user UBUNTU_CODENAME ?= bionic DEBIAN_CODENAME ?= testing-slim +ALPINE_CODENAME ?= 3.9 SKIP_MD5SUM ?= $(call filter_out_command,md5sum) SKIP_MD5SUM := $(SKIP_MD5SUM) @@ -84,7 +85,7 @@ $(SKIP_MD5SUM)$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa0 # Architecture-specific rule target configuration CMAKE_TARGETS += amd64-ubuntu-builder -CMAKE_TARGETS += amd64-debian-builder +CMAKE_TARGETS += amd64-alpine-builder CMAKE_TARGETS += arm32v7-ubuntu-builder CMAKE_TARGETS += arm32v7-debian-builder @@ -96,6 +97,9 @@ UBUNTU_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(UBUNTU_FI DEBIAN_FILTER = $(call regex_march_distro,'.*','debian') DEBIAN_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(DEBIAN_FILTER),$(TARGETS))) +ALPINE_FILTER = $(call regex_march_distro,'.*','alpine') +ALPINE_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(ALPINE_FILTER),$(TARGETS))) + ####################################################################################################################### # Common rule target configuration @@ -140,6 +144,8 @@ $(UBUNTU_TARGETS): CODENAME := $(UBUNTU_CODENAME) $(DEBIAN_TARGETS): CODENAME := $(DEBIAN_CODENAME) +$(ALPINE_TARGETS): CODENAME := $(ALPINE_CODENAME) + $(FETCH_TARGETS): | $(FETCHDIR) $(SILENT)$(call curl,$@,$(URL),$(MD5)) diff --git a/build/amd64-debian-builder.dockerfile b/build/amd64-alpine-builder.dockerfile similarity index 74% rename from build/amd64-debian-builder.dockerfile rename to build/amd64-alpine-builder.dockerfile index 5231e2d..7dd8194 100644 --- a/build/amd64-debian-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -1,20 +1,23 @@ ARG REGISTRY_PREFIX='' -ARG CODENAME=testing-slim +ARG CODENAME=3.9 -FROM ${REGISTRY_PREFIX}debian:${CODENAME} as builder +FROM ${REGISTRY_PREFIX}alpine:${CODENAME} as builder RUN set -x \ - && apt update \ - && apt upgrade -y \ - && apt install --yes --no-install-recommends \ - build-essential \ + && apk add --no-cache \ + bash \ + coreutils \ + gcc \ + g++ \ + make \ cmake \ - ninja-build \ - pkg-config \ + ninja \ + pkgconf \ rsync \ gdb \ - gdbserver \ - valgrind + valgrind \ + util-linux \ + util-linux-dev COPY src /usr/local/src @@ -23,8 +26,8 @@ ARG PARALLELMFLAGS=-j2 ARG DUMB_INIT_VERSION=1.2.2 RUN set -x \ - && builddeps="xxd" \ - && apt install --yes --no-install-recommends $builddeps \ + && builddeps="vim" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -35,7 +38,7 @@ RUN set -x \ && mv dumb-init /usr/local/bin/dumb-init \ && dumb-init --version \ && rm -rf "$builddir" \ - && apt purge -y $builddeps + && apk del .build-deps ARG GTEST_VERSION=1.8.1 @@ -50,8 +53,8 @@ RUN set -x \ ARG FUSE_VERSION=3.1.1 RUN set -x \ - && builddeps="libtool automake gettext" \ - && apt install --yes --no-install-recommends $builddeps \ + && builddeps="libtool automake autoconf gettext-dev m4 linux-headers" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ && ./makeconf.sh \ && builddir="/tmp/out" \ @@ -60,15 +63,15 @@ RUN set -x \ && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" \ - && apt purge -y $builddeps + && apk del .build-deps ARG WEBSOCKETS_VERSION=3.1.0 RUN set -x \ - && apt install --yes --no-install-recommends \ + && apk add --no-cache \ ca-certificates \ openssl \ - libssl-dev \ + openssl-dev \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -87,6 +90,7 @@ RUN set -x \ && rm -rf "$builddir" ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" +ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig ARG USERID=1000 @@ -95,7 +99,7 @@ ARG OUTDIR=/workspace/out ARG SCRIPTDIR=/workspace/bin RUN set -x \ - && useradd -u "$USERID" -ms /bin/bash user \ + && adduser -u "$USERID" -s /bin/bash -D user \ && mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \ && chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" @@ -105,4 +109,3 @@ ENTRYPOINT ["dumb-init", "--"] # unused ARG QEMU_VERSION_=v3.1.0-2 - From 47ef598fa6679ebb18638e703a1f6c156a52db71 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 25 May 2019 02:44:32 +0200 Subject: [PATCH 008/138] replaces arm32v7-debian by arm32v7-alpine image --- Makefile | 8 +--- ...file => arm32v7-alpine-builder.dockerfile} | 41 +++++++++++-------- 2 files changed, 24 insertions(+), 25 deletions(-) rename build/{arm32v7-debian-builder.dockerfile => arm32v7-alpine-builder.dockerfile} (75%) diff --git a/Makefile b/Makefile index fe9c5d9..8c74204 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,6 @@ CONTAINER_USER ?= user CONTAINER_GROUP ?= user UBUNTU_CODENAME ?= bionic -DEBIAN_CODENAME ?= testing-slim ALPINE_CODENAME ?= 3.9 SKIP_MD5SUM ?= $(call filter_out_command,md5sum) @@ -87,16 +86,13 @@ $(SKIP_MD5SUM)$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa0 CMAKE_TARGETS += amd64-ubuntu-builder CMAKE_TARGETS += amd64-alpine-builder CMAKE_TARGETS += arm32v7-ubuntu-builder -CMAKE_TARGETS += arm32v7-debian-builder +CMAKE_TARGETS += arm32v7-alpine-builder MEMCHECK_FILTER = $(call regex_march_distro,'$(HOST_MARCH)','.*') UBUNTU_FILTER = $(call regex_march_distro,'.*','ubuntu') UBUNTU_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(UBUNTU_FILTER),$(TARGETS))) -DEBIAN_FILTER = $(call regex_march_distro,'.*','debian') -DEBIAN_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(DEBIAN_FILTER),$(TARGETS))) - ALPINE_FILTER = $(call regex_march_distro,'.*','alpine') ALPINE_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(ALPINE_FILTER),$(TARGETS))) @@ -142,8 +138,6 @@ $(CHECK_TARGETS): GOALS := test $(UBUNTU_TARGETS): CODENAME := $(UBUNTU_CODENAME) -$(DEBIAN_TARGETS): CODENAME := $(DEBIAN_CODENAME) - $(ALPINE_TARGETS): CODENAME := $(ALPINE_CODENAME) $(FETCH_TARGETS): | $(FETCHDIR) diff --git a/build/arm32v7-debian-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile similarity index 75% rename from build/arm32v7-debian-builder.dockerfile rename to build/arm32v7-alpine-builder.dockerfile index b34fdfa..a60bc80 100644 --- a/build/arm32v7-debian-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -1,23 +1,27 @@ ARG REGISTRY_PREFIX='' -ARG CODENAME=testing-slim +ARG CODENAME=3.9 -FROM ${REGISTRY_PREFIX}arm32v7/debian:${CODENAME} as builder +FROM ${REGISTRY_PREFIX}arm32v7/alpine:${CODENAME} as builder ARG QEMU_VERSION_=v3.1.0-2 COPY docker/qemu-arm-static-$QEMU_VERSION_ /usr/bin/qemu-arm-static RUN set -x \ - && apt update \ - && apt upgrade -y \ - && apt install --yes --no-install-recommends \ - build-essential \ + && apk add --no-cache \ + bash \ + coreutils \ + gcc \ + g++ \ + make \ cmake \ - ninja-build \ - pkg-config \ + ninja \ + pkgconf \ rsync \ gdb \ - gdbserver + valgrind \ + util-linux \ + util-linux-dev COPY src /usr/local/src @@ -26,8 +30,8 @@ ARG PARALLELMFLAGS=-j2 ARG DUMB_INIT_VERSION=1.2.2 RUN set -x \ - && builddeps="xxd" \ - && apt install --yes --no-install-recommends $builddeps \ + && builddeps="vim" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -38,7 +42,7 @@ RUN set -x \ && mv dumb-init /usr/local/bin/dumb-init \ && dumb-init --version \ && rm -rf "$builddir" \ - && apt purge -y $builddeps + && apk del .build-deps ARG GTEST_VERSION=1.8.1 @@ -53,8 +57,8 @@ RUN set -x \ ARG FUSE_VERSION=3.1.1 RUN set -x \ - && builddeps="libtool automake gettext" \ - && apt install --yes --no-install-recommends $builddeps \ + && builddeps="libtool automake autoconf gettext-dev m4 linux-headers" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ && ./makeconf.sh \ && builddir="/tmp/out" \ @@ -63,15 +67,15 @@ RUN set -x \ && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" \ - && apt purge -y $builddeps + && apk del .build-deps ARG WEBSOCKETS_VERSION=3.1.0 RUN set -x \ - && apt install --yes --no-install-recommends \ + && apk add --no-cache \ ca-certificates \ openssl \ - libssl-dev \ + openssl-dev \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -90,6 +94,7 @@ RUN set -x \ && rm -rf "$builddir" ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" +ENV PKG_CONFIG_PATH=/usr/local/lib32/pkgconfig ARG USERID=1000 @@ -98,7 +103,7 @@ ARG OUTDIR=/workspace/out ARG SCRIPTDIR=/workspace/bin RUN set -x \ - && useradd -u "$USERID" -ms /bin/bash user \ + && adduser -u "$USERID" -s /bin/bash -D user \ && mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \ && chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" From 973f95f30b011db325a490dcbac43895773f1cd3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 25 May 2019 03:18:25 +0200 Subject: [PATCH 009/138] enables coverage generation again (but uses guard) --- .travis.yml | 12 ++++++------ CMakeLists.txt | 35 ++++++++++++++++++----------------- Makefile | 3 +++ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index c4da690..9166367 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,13 +16,13 @@ env: - PARALLELMFLAGS="-j4" - PORTABLE_WORSPACE=1 matrix: - - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check - - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check + - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck COVERAGE=ON + - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck COVERAGE=OFF + - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check COVERAGE=OFF + - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check COVERAGE=OFF before_script: -- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH +- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH COVERAGE=$COVERAGE script: -- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET +- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH COVERAGE=$COVERAGE $CHECK_TARGET after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1170c1..58aac5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,9 @@ cmake_minimum_required (VERSION 3.10) project(webfuse VERSION 0.2.0 DESCRIPTION "Websocket filesystem based on libfuse") -option(WITHOUT_TESTS "disable unit tests" OFF) -option(WITHOUT_EXAMPLE "disable example" OFF) +option(WITHOUT_TESTS "disable unit tests" OFF) +option(WITHOUT_EXAMPLE "disable example" OFF) +option(WITH_COVERAGE "enable code coverage" OFF) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) @@ -22,24 +23,24 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(C_WARNINGS -Wall -Wextra) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -#if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") -# -#add_definitions( -# -pg -# --coverage -# -fprofile-arcs -# -ftest-coverage -#) +if(("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND WITHOUT_COVERAGE) -#if(CMAKE_C_COMPILER_ID STREQUAL "GNU") -# link_libraries(gcov) -#else() -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") -#endif() +add_definitions( + -pg + --coverage + -fprofile-arcs + -ftest-coverage +) -#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -fprofile-arcs") +if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + link_libraries(gcov) +else() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") +endif() -#endif() +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -fprofile-arcs") + +endif() include_directories( "include" diff --git a/Makefile b/Makefile index 8c74204..2929f83 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ SCRIPTDIR ?= $(PROJECTDIR)/build/mkdocker OUTDIR ?= $(PROJECTDIR)/.build FETCHDIR ?= $(PROJECTDIR)/.deps BUILDTYPE ?= Debug +COVERAGE ?= OFF SKIP_FETCH ?= @@ -115,6 +116,8 @@ OUTDIRS += $(OUTDIR)/src EXTRACT_TARGETS += $(OUTDIR)/docker/qemu-arm-static-$(QEMU_VERSION) EXTRACT_TARGETS += $(patsubst $(FETCHDIR)/%.tar.gz,$(OUTDIR)/src/%,$(FETCH_TARGETS)) +CMAKEFLAGS += -DWITH_COVERAGE=$(COVERAGE) + ####################################################################################################################### # Makefile dependencies From 83c7feee822b151c8ace2289b9226d6f01abc6e7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 26 May 2019 16:30:01 +0200 Subject: [PATCH 010/138] fixes missing inode using stat and ls -i --- lib/webfuse/adapter/impl/operation/getattr.c | 4 +++- lib/webfuse/adapter/impl/operation/lookup.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index 75736a2..cef8eac 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -14,6 +14,7 @@ struct wf_impl_operation_getattr_context { fuse_req_t request; + fuse_ino_t inode; double timeout; uid_t uid; gid_t gid; @@ -36,6 +37,7 @@ static void wf_impl_operation_getattr_finished( { memset(&buffer, 0, sizeof(struct stat)); + buffer.st_ino = context->inode; buffer.st_mode = json_integer_value(mode_holder) & 0555; char const * type = json_string_value(type_holder); if (0 == strcmp("file", type)) @@ -54,7 +56,6 @@ static void wf_impl_operation_getattr_finished( buffer.st_atime = wf_impl_json_get_int(data, "atime", 0); buffer.st_mtime = wf_impl_json_get_int(data, "mtime", 0); buffer.st_ctime = wf_impl_json_get_int(data, "ctime", 0); - } else { @@ -87,6 +88,7 @@ void wf_impl_operation_getattr ( { struct wf_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wf_impl_operation_getattr_context)); getattr_context->request = request; + getattr_context->inode = inode; getattr_context->uid = context->uid; getattr_context->gid = context->gid; getattr_context->timeout = user_data->timeout; diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index 3749123..3f0cd3b 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -43,6 +43,7 @@ static void wf_impl_operation_lookup_finished( memset(&buffer, 0, sizeof(struct stat)); buffer.ino = json_integer_value(inode_holder); + buffer.attr.st_ino = buffer.ino; buffer.attr.st_mode = json_integer_value(mode_holder) & 0555; char const * type = json_string_value(type_holder); if (0 == strcmp("file", type)) From ce6affd4a2df3aae475834090a855fff88823d12 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 26 May 2019 20:46:41 +0200 Subject: [PATCH 011/138] fixes type in define --- lib/webfuse/provider/impl/static_filesystem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/webfuse/provider/impl/static_filesystem.c b/lib/webfuse/provider/impl/static_filesystem.c index aeb9c54..83c3b92 100644 --- a/lib/webfuse/provider/impl/static_filesystem.c +++ b/lib/webfuse/provider/impl/static_filesystem.c @@ -16,7 +16,7 @@ #include #define WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY (16) -#define WFP_STATIC_FILSYSTEM_INDOE_ROOT (1) +#define WFP_STATIC_FILSYSTEM_INODE_ROOT (1) #define WFP_STATIC_FILESYSTEM_MAX_READ_SIZE (4 * 1024) struct wfp_static_filesystem_entry @@ -205,7 +205,7 @@ wfp_impl_static_filesystem_make_parent( struct wfp_static_filesystem * filesystem, struct wf_path * path) { - size_t result = WFP_STATIC_FILSYSTEM_INDOE_ROOT; + size_t result = WFP_STATIC_FILSYSTEM_INODE_ROOT; size_t count = wf_path_element_count(path); if (0 < count) From b500ebeeaf63d8c376a7d0efdfca527149bec757 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 11:01:00 +0100 Subject: [PATCH 012/138] introduced new build type "Coverage" --- .travis.yml | 13 +++++++------ CMakeLists.txt | 23 +++-------------------- Makefile | 3 --- cmake/coverage.cmake | 30 ++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 cmake/coverage.cmake diff --git a/.travis.yml b/.travis.yml index 9166367..0378814 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,13 +16,14 @@ env: - PARALLELMFLAGS="-j4" - PORTABLE_WORSPACE=1 matrix: - - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck COVERAGE=ON - - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck COVERAGE=OFF - - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check COVERAGE=OFF - - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check COVERAGE=OFF + - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck + - BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=memcheck + - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck + - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check + - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check before_script: -- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH COVERAGE=$COVERAGE +- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH script: -- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH COVERAGE=$COVERAGE $CHECK_TARGET +- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58aac5d..5de6ea3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,9 @@ project(webfuse VERSION 0.2.0 DESCRIPTION "Websocket filesystem based on libfuse option(WITHOUT_TESTS "disable unit tests" OFF) option(WITHOUT_EXAMPLE "disable example" OFF) -option(WITH_COVERAGE "enable code coverage" OFF) + +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(coverage) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) @@ -23,25 +25,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(C_WARNINGS -Wall -Wextra) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -if(("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND WITHOUT_COVERAGE) - -add_definitions( - -pg - --coverage - -fprofile-arcs - -ftest-coverage -) - -if(CMAKE_C_COMPILER_ID STREQUAL "GNU") - link_libraries(gcov) -else() - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") -endif() - -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -fprofile-arcs") - -endif() - include_directories( "include" ${FUSE3_INCLUDE_DIRS} diff --git a/Makefile b/Makefile index 2929f83..8c74204 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,6 @@ SCRIPTDIR ?= $(PROJECTDIR)/build/mkdocker OUTDIR ?= $(PROJECTDIR)/.build FETCHDIR ?= $(PROJECTDIR)/.deps BUILDTYPE ?= Debug -COVERAGE ?= OFF SKIP_FETCH ?= @@ -116,8 +115,6 @@ OUTDIRS += $(OUTDIR)/src EXTRACT_TARGETS += $(OUTDIR)/docker/qemu-arm-static-$(QEMU_VERSION) EXTRACT_TARGETS += $(patsubst $(FETCHDIR)/%.tar.gz,$(OUTDIR)/src/%,$(FETCH_TARGETS)) -CMAKEFLAGS += -DWITH_COVERAGE=$(COVERAGE) - ####################################################################################################################### # Makefile dependencies diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake new file mode 100644 index 0000000..4660d6a --- /dev/null +++ b/cmake/coverage.cmake @@ -0,0 +1,30 @@ +set(CMAKE_C_FLAGS_COVERAGE + "${CMAKE_C_FLAGS_DEBUG} -pg --coverage -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C compiler during coverage builds" + FORCE +) + +set(CMAKE_CXX_FLAGS_COVERAGE + "${CMAKE_CXX_FLAGS_DEBUG} -pg --coverage -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C++ compiler during coverage builds." + FORCE +) + +set(CMAKE_EXE_LINKER_FLAGS_COVERAGE + "" + CACHE STRING "Flags used for linking binaries during coverage builds." + FORCE +) + +set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "" + CACHE STRING "Flags used by the shared libraries linker during coverage builds." + FORCE +) + +mark_as_advanced( + CMAKE_C_FLAGS_COVERAGE + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE +) From c598b983cb7ef5b85e72ea5d49d2b72d859bca9b Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 11:05:50 +0100 Subject: [PATCH 013/138] updated C++ standard to C++14 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5de6ea3..bebca1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ pkg_check_modules(UUID REQUIRED uuid) add_definitions(-D_FILE_OFFSET_BITS=64) set(CMAKE_C_STANDARD 99) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(C_WARNINGS -Wall -Wextra) From c34476ce38aa89cc9fbd06abdca56bb44b624e3a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 11:10:17 +0100 Subject: [PATCH 014/138] updated gtest to 1.10.0 --- Makefile | 4 ++-- build/amd64-alpine-builder.dockerfile | 2 +- build/amd64-ubuntu-builder.dockerfile | 2 +- build/arm32v7-alpine-builder.dockerfile | 2 +- build/arm32v7-ubuntu-builder.dockerfile | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 8c74204..0ffe511 100644 --- a/Makefile +++ b/Makefile @@ -50,11 +50,11 @@ FETCH_TARGETS += $(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz $(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: URL := https://github.com/Yelp/dumb-init/archive/v${DUMB_INIT_VERSION}.tar.gz $(SKIP_MD5SUM)$(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: MD5 := 6166084b05772cdcf615a762c6f3b32e -GTEST_VERSION ?= 1.8.1 +GTEST_VERSION ?= 1.10.0 DOCKER_BUILDARGS += GTEST_VERSION=$(GTEST_VERSION) FETCH_TARGETS += $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: URL := https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz -$(SKIP_MD5SUM)$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := 2e6fbeb6a91310a16efe181886c59596 +$(SKIP_MD5SUM)$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := ecd1fa65e7de707cd5c00bdac56022cd FUSE_VERSION ?= 3.1.1 DOCKER_BUILDARGS += FUSE_VERSION=$(FUSE_VERSION) diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index 7dd8194..c1169c0 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -40,7 +40,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apk del .build-deps -ARG GTEST_VERSION=1.8.1 +ARG GTEST_VERSION=1.10.0 RUN set -x \ && builddir="/tmp/out" \ diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index ddfe61a..d840961 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -39,7 +39,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apt purge -y $builddeps -ARG GTEST_VERSION=1.8.1 +ARG GTEST_VERSION=1.10.0 RUN set -x \ && builddir="/tmp/out" \ diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index a60bc80..8421f18 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -44,7 +44,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apk del .build-deps -ARG GTEST_VERSION=1.8.1 +ARG GTEST_VERSION=1.10.0 RUN set -x \ && builddir="/tmp/out" \ diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index 77ce038..7c059ff 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -42,7 +42,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apt purge -y $builddeps -ARG GTEST_VERSION=1.8.1 +ARG GTEST_VERSION=1.10.0 RUN set -x \ && builddir="/tmp/out" \ From 1f20115e66642ae7773f26442f4d426ce028c0c6 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 11:13:53 +0100 Subject: [PATCH 015/138] updated libwebsockets to 3.2.0 --- Makefile | 4 ++-- build/amd64-alpine-builder.dockerfile | 2 +- build/amd64-ubuntu-builder.dockerfile | 2 +- build/arm32v7-alpine-builder.dockerfile | 2 +- build/arm32v7-ubuntu-builder.dockerfile | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0ffe511..b182fb8 100644 --- a/Makefile +++ b/Makefile @@ -62,11 +62,11 @@ FETCH_TARGETS += $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz $(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 097f194856938afdd98bea1a5c046edd -WEBSOCKETS_VERSION ?= 3.1.0 +WEBSOCKETS_VERSION ?= 3.2.0 DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION) FETCH_TARGETS += $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: URL := https://github.com/warmcat/libwebsockets/archive/v$(WEBSOCKETS_VERSION).tar.gz -$(SKIP_MD5SUM)$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := 325359a25d5f6d22725ff5d086db1c76 +$(SKIP_MD5SUM)$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := 1d06f5602604e67e6f50cef9857c6b0c JANSSON_VERSION ?= 2.12 DOCKER_BUILDARGS += JANSSON_VERSION=$(JANSSON_VERSION) diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index c1169c0..2961a54 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -65,7 +65,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apk del .build-deps -ARG WEBSOCKETS_VERSION=3.1.0 +ARG WEBSOCKETS_VERSION=3.2.0 RUN set -x \ && apk add --no-cache \ diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index d840961..0ca147f 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -64,7 +64,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apt purge -y $builddeps -ARG WEBSOCKETS_VERSION=3.1.0 +ARG WEBSOCKETS_VERSION=3.2.0 RUN set -x \ && apt install --yes --no-install-recommends \ diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index 8421f18..035ff6c 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -69,7 +69,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apk del .build-deps -ARG WEBSOCKETS_VERSION=3.1.0 +ARG WEBSOCKETS_VERSION=3.2.0 RUN set -x \ && apk add --no-cache \ diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index 7c059ff..212eb90 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -67,7 +67,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apt purge -y $builddeps -ARG WEBSOCKETS_VERSION=3.1.0 +ARG WEBSOCKETS_VERSION=3.2.0 RUN set -x \ && apt install --yes --no-install-recommends \ From 63c2b0621315757486b9c941dc6b805c2c406473 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 11:44:35 +0100 Subject: [PATCH 016/138] fix: run coverage tests without valgrind (SIGPROF) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0378814..ceddb6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: - PORTABLE_WORSPACE=1 matrix: - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=memcheck + - BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=check - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check From c98a2146683f85fb6a83141c9b15ed61e6db7583 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 12:16:20 +0100 Subject: [PATCH 017/138] updated dependency versions --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f656bde..733f872 100644 --- a/README.md +++ b/README.md @@ -419,9 +419,9 @@ By default, unit tests and example application are enabled. You can disable them #### libwebsockets - wget -O libwebsockets-3.1.0.tar.gz https://github.com/warmcat/libwebsockets/archive/v3.1.0.tar.gz - tar -xf libwebsockets-3.1.0.tar.gz - cd libwebsockets-3.1.0 + wget -O libwebsockets-3.2.0.tar.gz https://github.com/warmcat/libwebsockets/archive/v3.2.0.tar.gz + tar -xf libwebsockets-3.2.0.tar.gz + cd libwebsockets-3.2.0 mkdir .build cd .build cmake .. @@ -443,9 +443,9 @@ By default, unit tests and example application are enabled. You can disable them Installation of GoogleTest is optional webfuse library, but required to compile tests. - wget -O gtest-1.8.1.tar.gz https://github.com/google/googletest/archive/release-1.8.1.tar.gz - tar -xf gtest-1.8.1.tar.gz - cd googletest-release-1.8.1 + wget -O gtest-1.10.0.tar.gz https://github.com/google/googletest/archive/release-1.10.0.tar.gz + tar -xf gtest-1.10.0.tar.gz + cd googletest-release-1.10.0 mkdir .build cd .build cmake .. From 7f29a7987e12b6e502aaef549938974f94e53006 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 13:10:26 +0100 Subject: [PATCH 018/138] workaround: lws decode base64 size requirements changed --- lib/webfuse/adapter/impl/operation/read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 11eb0f2..f30902b 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -17,7 +17,7 @@ static char * wf_impl_fill_buffer( wf_status * status) { *status = WF_GOOD; - char * buffer = malloc(count + 1); + char * buffer = malloc(count + 4); // FixMe: lws 3.2.0 needs more buffer to decode (bug?) if ((NULL != buffer) && (0 < count)) { @@ -27,7 +27,7 @@ static char * wf_impl_fill_buffer( } else if (0 == strcmp("base64", format)) { - lws_b64_decode_string(data, buffer, count + 1); + lws_b64_decode_string(data, buffer, count + 4); } else { From 9cd058a7471e352693921120bcd88f1f331444b4 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 17:17:21 +0100 Subject: [PATCH 019/138] switched to own base64 implementation --- CMakeLists.txt | 2 + lib/webfuse/adapter/impl/operation/read.c | 6 +- lib/webfuse/core/base64.c | 183 +++++++++++++++++++++ lib/webfuse/core/base64.h | 40 +++++ lib/webfuse/provider/impl/operation/read.c | 6 +- test/core/test_base64.cc | 122 ++++++++++++++ 6 files changed, 353 insertions(+), 6 deletions(-) create mode 100644 lib/webfuse/core/base64.c create mode 100644 lib/webfuse/core/base64.h create mode 100644 test/core/test_base64.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index bebca1e..ae4ee7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ add_library(webfuse-core STATIC lib/webfuse/core/status.c lib/webfuse/core/string.c lib/webfuse/core/path.c + lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c ) @@ -283,6 +284,7 @@ add_executable(alltests test/core/test_string.cc test/core/test_slist.cc test/core/test_path.cc + test/core/test_base64.cc test/core/test_status.cc test/core/test_message.cc test/core/test_message_queue.cc diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index f30902b..ec434c5 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -4,9 +4,9 @@ #include #include #include -#include #include "webfuse/adapter/impl/jsonrpc/proxy.h" +#include "webfuse/core/base64.h" #define WF_MAX_READ_LENGTH 4096 @@ -17,7 +17,7 @@ static char * wf_impl_fill_buffer( wf_status * status) { *status = WF_GOOD; - char * buffer = malloc(count + 4); // FixMe: lws 3.2.0 needs more buffer to decode (bug?) + char * buffer = malloc(count); if ((NULL != buffer) && (0 < count)) { @@ -27,7 +27,7 @@ static char * wf_impl_fill_buffer( } else if (0 == strcmp("base64", format)) { - lws_b64_decode_string(data, buffer, count + 4); + wf_base64_decode(data, strlen(data), (uint8_t *) buffer, count); } else { diff --git a/lib/webfuse/core/base64.c b/lib/webfuse/core/base64.c new file mode 100644 index 0000000..2b24688 --- /dev/null +++ b/lib/webfuse/core/base64.c @@ -0,0 +1,183 @@ +#include "webfuse/core/base64.h" + +static const uint8_t wf_base64_decode_table[256] = { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0 + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 1 + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 62, 0x80, 0x80, 0x80, 63, // 2 + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0x80, 0x80, 0x80, 0, 0x80, 0x80, // 3 + 0x80, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 4 + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0x80, 0x80, 0x80, 0x80, 0x80, // 5 + 0x80, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 6 + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0x80, 0x80, 0x80, 0x80, 0x80, // 7 + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 8 + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 9 + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // A + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // B + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // C + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // D + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // E + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // F +}; + + + +size_t wf_base64_encoded_size(size_t length) +{ + return ((length + 2) / 3) * 4; +} + +size_t wf_base64_encode( + uint8_t const * data, + size_t length, + char * buffer, + size_t buffer_size) +{ + // 0 1 2 3 4 5 6 + // 0123456789012345678901234567890123456789012345678901234567890123 + static char const table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + size_t const length_needed = wf_base64_encoded_size(length); + if (buffer_size < length_needed) + { + return 0; + } + + size_t pos = 0; + size_t out_pos = 0; + for(; (length - pos) >= 3; pos += 3) + { + buffer[out_pos++] = table[ data[pos] >> 2 ]; + buffer[out_pos++] = table[ ((data[pos ] & 0x03) << 4) | (data[pos + 1] >> 4) ]; + buffer[out_pos++] = table[ ((data[pos + 1] & 0x0f) << 2) | (data[pos + 2] >> 6) ]; + buffer[out_pos++] = table[ data[pos + 2] & 0x3f ]; + } + + switch((length - pos)) + { + case 1: + buffer[out_pos++] = table[ data[pos] >> 2 ]; + buffer[out_pos++] = table[ ((data[pos] & 0x03) << 4) ]; + buffer[out_pos++] = '='; + buffer[out_pos++] = '='; + break; + case 2: + buffer[out_pos++] = table[ data[pos] >> 2 ]; + buffer[out_pos++] = table[ ((data[pos ] & 0x03) << 4) | (data[pos + 1] >> 4) ]; + buffer[out_pos++] = table[ ((data[pos + 1] & 0x0f) << 2) ]; + buffer[out_pos++] = '='; + break; + default: + break; + } + + if (buffer_size > out_pos) + { + buffer[out_pos] = '\0'; + } + + return out_pos; +} + +size_t wf_base64_decoded_size(char const * data, size_t length) +{ + size_t result = 0; + if ((length > 0) && ((length % 4) == 0)) + { + result = (length / 4) * 3; + + if ('=' == data[length - 1]) + { + result--; + if ('=' == data[length - 2]) + { + result--; + } + } + } + + return result; +} + +size_t wf_base64_decode( + char const * data, + size_t length, + uint8_t * buffer, + size_t buffer_size) +{ + uint8_t const * table = wf_base64_decode_table; + size_t needed_size = wf_base64_decoded_size(data, length); + if ((0 == needed_size) || (buffer_size < needed_size)) + { + return 0; + } + + size_t out_pos = 0; + size_t pos = 0; + for(; pos < length - 4; pos += 4) + { + uint8_t a = table[ (unsigned char) data[pos ] ]; + uint8_t b = table[ (unsigned char) data[pos + 1] ]; + uint8_t c = table[ (unsigned char) data[pos + 2] ]; + uint8_t d = table[ (unsigned char) data[pos + 3] ]; + + buffer[out_pos++] = (a << 2) | (b >> 4); + buffer[out_pos++] = (b << 4) | (c >> 2); + buffer[out_pos++] = (c << 6) | d; + } + + // decode last block + { + uint8_t a = table[ (unsigned char) data[pos ] ]; + uint8_t b = table[ (unsigned char) data[pos + 1] ]; + uint8_t c = table[ (unsigned char) data[pos + 2] ]; + uint8_t d = table[ (unsigned char) data[pos + 3] ]; + + buffer[out_pos++] = (a << 2) | (b >> 4); + if ('=' != data[pos + 2]) + { + buffer[out_pos++] = (b << 4) | (c >> 2); + if ('=' != data[pos + 3]) + { + buffer[out_pos++] = (c << 6) | d; + } + } + } + + return out_pos; +} + +extern bool wf_base64_isvalid(char const * data, size_t length) +{ + uint8_t const * table = wf_base64_decode_table; + + if ((length == 0) || ((length % 4) != 0)) + { + return false; + } + + size_t pos = 0; + for(; pos < (length - 2); pos++) + { + unsigned char c = (unsigned char) data[pos]; + if (('=' == c) || (0x80 == table[c])) + { + return false; + } + } + + if (('=' == data[pos]) && ('=' != data[pos + 1])) + { + return false; + } + + for(;pos < length; pos++) + { + char c = data[pos]; + if (0x80 == table[ (unsigned char) c]) + { + return false; + } + } + + return true; +} diff --git a/lib/webfuse/core/base64.h b/lib/webfuse/core/base64.h new file mode 100644 index 0000000..6803afb --- /dev/null +++ b/lib/webfuse/core/base64.h @@ -0,0 +1,40 @@ +#ifndef WF_BASE64_H +#define WF_BASE64_H + +#ifndef __cplusplus +#include +#include +#include +#else +#include +#include +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern size_t wf_base64_encoded_size(size_t length); + +extern size_t wf_base64_encode( + uint8_t const * data, + size_t length, + char * buffer, + size_t buffer_size); + +extern size_t wf_base64_decoded_size(char const * data, size_t length); + +extern size_t wf_base64_decode( + char const * data, + size_t length, + uint8_t * buffer, + size_t buffer_size); + +extern bool wf_base64_isvalid(char const * data, size_t length); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/provider/impl/operation/read.c b/lib/webfuse/provider/impl/operation/read.c index 64188b4..3101ea0 100644 --- a/lib/webfuse/provider/impl/operation/read.c +++ b/lib/webfuse/provider/impl/operation/read.c @@ -1,11 +1,11 @@ #include "webfuse/provider/impl/operation/read.h" #include -#include #include "webfuse/provider/impl/operation/error.h" #include "webfuse/provider/impl/request.h" #include "webfuse/core/util.h" +#include "webfuse/core/base64.h" void wfp_impl_read( struct wfp_impl_invokation_context * context, @@ -54,11 +54,11 @@ void wfp_impl_respond_read( { if (0 < length) { - size_t const size = 4 * ((length / 3) + 2); + size_t const size = wf_base64_encoded_size(length) + 1; char * buffer = malloc(size); if (NULL != buffer) { - lws_b64_encode_string(data, length, buffer, size); + wf_base64_encode((uint8_t const *) data, length, buffer, size); json_t * result = json_object(); json_object_set_new(result, "data", json_string(buffer)); diff --git a/test/core/test_base64.cc b/test/core/test_base64.cc new file mode 100644 index 0000000..e6ae97d --- /dev/null +++ b/test/core/test_base64.cc @@ -0,0 +1,122 @@ +#include +#include "webfuse/core/base64.h" + +TEST(Base64, EncodedSize) +{ + ASSERT_EQ(4, wf_base64_encoded_size(1)); + ASSERT_EQ(4, wf_base64_encoded_size(2)); + ASSERT_EQ(4, wf_base64_encoded_size(3)); + + ASSERT_EQ(8, wf_base64_encoded_size(4)); + ASSERT_EQ(8, wf_base64_encoded_size(5)); + ASSERT_EQ(8, wf_base64_encoded_size(6)); + + ASSERT_EQ(120, wf_base64_encoded_size(90)); +} + +TEST(Base64, Encode) +{ + char buffer[42]; + + std::string in = "Hello"; + size_t length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); + ASSERT_EQ(8, length); + ASSERT_STREQ("SGVsbG8=", buffer); + + in = "Hello\n"; + length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); + ASSERT_EQ(8, length); + ASSERT_STREQ("SGVsbG8K", buffer); + + in = "Blue"; + length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); + ASSERT_EQ(8, length); + ASSERT_STREQ("Qmx1ZQ==", buffer); +} + +TEST(Base64, FailedToEncodeBufferTooSmall) +{ + char buffer[1]; + + std::string in = "Hello"; + size_t length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 1); + ASSERT_EQ(0, length); +} + +TEST(Base64, DecodedSize) +{ + std::string in = "SGVsbG8="; // Hello + size_t length = wf_base64_decoded_size(in.c_str(), in.size()); + ASSERT_EQ(5, length); + + in = "SGVsbG8K"; // Hello\n + length = wf_base64_decoded_size(in.c_str(), in.size()); + ASSERT_EQ(6, length); + + in = "Qmx1ZQ=="; // Blue + length = wf_base64_decoded_size(in.c_str(), in.size()); + ASSERT_EQ(4, length); +} + +TEST(Base64, IsValid) +{ + std::string in = "SGVsbG8="; // Hello + ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size())); + + in = "SGVsbG8K"; // Hello\n + ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size())); + + in = "Qmx1ZQ=="; // Blue + ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size())); + + in = "Qmx1ZQ=a"; + ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size())); + + in = "Qmx1ZQ"; + ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size())); + + in = "Qmx1ZQ="; + ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size())); + + in = "Qmx1Z==="; + ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size())); + + in = "Qmx1ZQ?="; + ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size())); + + in = "Qm?1ZQ=="; + ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size())); +} + +TEST(Base64, Decode) +{ + char buffer[42]; + + std::string in = "SGVsbG8="; // Hello + size_t length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); + ASSERT_EQ(5, length); + buffer[length] = '\0'; + ASSERT_STREQ("Hello", buffer); + + in = "SGVsbG8K"; // Hello\n + length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); + ASSERT_EQ(6, length); + buffer[length] = '\0'; + ASSERT_STREQ("Hello\n", buffer); + + in = "Qmx1ZQ=="; // Blue + length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); + ASSERT_EQ(4, length); + buffer[length] = '\0'; + ASSERT_STREQ("Blue", buffer); +} + +TEST(Base64, FailToDecodeBufferTooSmall) +{ + char buffer[1]; + + std::string in = "SGVsbG8="; // Hello + size_t length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 1); + ASSERT_EQ(0, length); +} + From 7a79c5e8a9966e517918d1d08ca0e62027f575f5 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 19:01:40 +0100 Subject: [PATCH 020/138] updated qemu-user-static to 4.1.0-1 --- Makefile | 4 ++-- build/amd64-alpine-builder.dockerfile | 3 --- build/amd64-ubuntu-builder.dockerfile | 4 ---- build/arm32v7-alpine-builder.dockerfile | 2 +- build/arm32v7-ubuntu-builder.dockerfile | 2 +- 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index b182fb8..5b3aeaf 100644 --- a/Makefile +++ b/Makefile @@ -74,11 +74,11 @@ FETCH_TARGETS += $(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz $(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz: URL := https://github.com/akheron/jansson/archive/v$(JANSSON_VERSION).tar.gz $(SKIP_MD5SUM)$(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz: MD5 := c4b106528d5ffb521178565de1ba950d -QEMU_VERSION ?= v3.1.0-2 +QEMU_VERSION ?= v4.1.0-1 DOCKER_BUILDARGS += QEMU_VERSION_=$(QEMU_VERSION) FETCH_TARGETS += $(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION) $(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): URL := https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-arm-static -$(SKIP_MD5SUM)$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa07c557d45373bd831b1 +$(SKIP_MD5SUM)$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): MD5 := e508e6e4dd7f3a851207aac245a4653f ####################################################################################################################### # Architecture-specific rule target configuration diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index 2961a54..c2a3096 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -106,6 +106,3 @@ RUN set -x \ WORKDIR "$OUTDIR" ENTRYPOINT ["dumb-init", "--"] - -# unused -ARG QEMU_VERSION_=v3.1.0-2 diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index 0ca147f..bd0f707 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -104,7 +104,3 @@ RUN set -x \ WORKDIR "$OUTDIR" ENTRYPOINT ["dumb-init", "--"] - -# unused -ARG QEMU_VERSION_=v3.1.0-2 - diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index 035ff6c..3405ee9 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -3,7 +3,7 @@ ARG CODENAME=3.9 FROM ${REGISTRY_PREFIX}arm32v7/alpine:${CODENAME} as builder -ARG QEMU_VERSION_=v3.1.0-2 +ARG QEMU_VERSION_=v4.1.0-1 COPY docker/qemu-arm-static-$QEMU_VERSION_ /usr/bin/qemu-arm-static diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index 212eb90..efb2957 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -3,7 +3,7 @@ ARG CODENAME=bionic FROM ${REGISTRY_PREFIX}arm32v7/ubuntu:${CODENAME} as builder -ARG QEMU_VERSION_=v3.1.0-2 +ARG QEMU_VERSION_=v4.1.0-1 COPY docker/qemu-arm-static-$QEMU_VERSION_ /usr/bin/qemu-arm-static From 494035e5a69e4f75691ad5cc659d0ed95b4ccfd8 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 20:27:10 +0100 Subject: [PATCH 021/138] updated libfuse to 3.8.0 --- Makefile | 4 ++-- README.md | 17 ++++++++++------- build/amd64-alpine-builder.dockerfile | 17 +++++++++++------ build/amd64-ubuntu-builder.dockerfile | 14 +++++++++----- build/arm32v7-alpine-builder.dockerfile | 16 ++++++++++------ build/arm32v7-ubuntu-builder.dockerfile | 14 +++++++++----- lib/webfuse/adapter/impl/fuse_wrapper.h | 2 +- 7 files changed, 52 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 5b3aeaf..01c9f3d 100644 --- a/Makefile +++ b/Makefile @@ -56,11 +56,11 @@ FETCH_TARGETS += $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: URL := https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz $(SKIP_MD5SUM)$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := ecd1fa65e7de707cd5c00bdac56022cd -FUSE_VERSION ?= 3.1.1 +FUSE_VERSION ?= 3.8.0 DOCKER_BUILDARGS += FUSE_VERSION=$(FUSE_VERSION) FETCH_TARGETS += $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz -$(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 097f194856938afdd98bea1a5c046edd +$(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 909d6b2cfc2faa9f4b6033d356280540 WEBSOCKETS_VERSION ?= 3.2.0 DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION) diff --git a/README.md b/README.md index 733f872..1062e1c 100644 --- a/README.md +++ b/README.md @@ -409,13 +409,16 @@ By default, unit tests and example application are enabled. You can disable them #### libfuse - wget -O fuse-3.1.1.tar.gz https://github.com/libfuse/libfuse/archive/fuse-3.1.1.tar.gz - tar -xf fuse-3.1.1.tar.gz - cd libfuse-fuse-3.1.1 - ./makeconf.sh - ./configure - make - sudo make install +To install libfuse, meson is neede. Please refer to [meson quick guide](https://mesonbuild.com/Quick-guide.html) for setup instructions. + + wget -O fuse-3.8.0.tar.gz https://github.com/libfuse/libfuse/archive/fuse-3.8.0.tar.gz + tar -xf fuse-3.8.0.tar.gz + cd libfuse-fuse-3.8.0 + mkdir .build + cd .build + meson .. + ninja + sudo ninja install #### libwebsockets diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index c2a3096..e13924a 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -50,18 +50,23 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.1.1 +RUN set -x \ + && builddeps="linux-headers udev eudev-dev python3 py3-pip py3-setuptools py3-cryptography ninja" \ + && apk add --no-cache --virtual .build-deps $builddeps \ + && pip3 install meson + +ARG FUSE_VERSION=3.8.0 RUN set -x \ - && builddeps="libtool automake autoconf gettext-dev m4 linux-headers" \ + && builddeps="libtool automake autoconf gettext-dev m4" \ && apk add --no-cache --virtual .build-deps $builddeps \ - && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ - && ./makeconf.sh \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ - && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ - && make "$PARALLELMFLAGS" install \ + && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && meson configure -Dexamples=false \ + && ninja \ + && ninja install \ && rm -rf "$builddir" \ && apk del .build-deps diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index bd0f707..acd51ac 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -49,18 +49,22 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.1.1 +RUN set -x \ + && builddeps="udev python3 python3-pip python3-setuptools python3-wheel ninja-build" \ + && apt install --yes --no-install-recommends $builddeps \ + && pip3 install --system meson + +ARG FUSE_VERSION=3.8.0 RUN set -x \ && builddeps="libtool automake gettext" \ && apt install --yes --no-install-recommends $builddeps \ - && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ - && ./makeconf.sh \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ - && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ - && make "$PARALLELMFLAGS" install \ + && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && ninja \ + && ninja install \ && rm -rf "$builddir" \ && apt purge -y $builddeps diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index 3405ee9..63f910e 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -54,18 +54,22 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.1.1 +RUN set -x \ + && builddeps="linux-headers udev eudev-dev python3 py3-pip py3-setuptools py3-cryptography ninja" \ + && apk add --no-cache --virtual .build-deps $builddeps \ + && pip3 install meson + +ARG FUSE_VERSION=3.8.0 RUN set -x \ - && builddeps="libtool automake autoconf gettext-dev m4 linux-headers" \ + && builddeps="libtool automake autoconf gettext-dev m4" \ && apk add --no-cache --virtual .build-deps $builddeps \ - && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ - && ./makeconf.sh \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ - && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ - && make "$PARALLELMFLAGS" install \ + && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && ninja \ + && ninja install \ && rm -rf "$builddir" \ && apk del .build-deps diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index efb2957..1b4f735 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -52,18 +52,22 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.1.1 +RUN set -x \ + && builddeps="udev python3 python3-pip python3-setuptools python3-wheel ninja-build" \ + && apt install --yes --no-install-recommends $builddeps \ + && pip3 install --system meson + +ARG FUSE_VERSION=3.8.0 RUN set -x \ && builddeps="libtool automake gettext" \ && apt install --yes --no-install-recommends $builddeps \ - && cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ - && ./makeconf.sh \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ - && "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \ - && make "$PARALLELMFLAGS" install \ + && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && ninja \ + && ninja install \ && rm -rf "$builddir" \ && apt purge -y $builddeps diff --git a/lib/webfuse/adapter/impl/fuse_wrapper.h b/lib/webfuse/adapter/impl/fuse_wrapper.h index 719d758..b234e73 100644 --- a/lib/webfuse/adapter/impl/fuse_wrapper.h +++ b/lib/webfuse/adapter/impl/fuse_wrapper.h @@ -5,7 +5,7 @@ extern "C" { #endif -#define FUSE_USE_VERSION 31 +#define FUSE_USE_VERSION 38 #include #ifdef __cplusplus From 4e7586883597c95c190bb00be30550f04a65c3d6 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 20:35:51 +0100 Subject: [PATCH 022/138] added codecov config: ignore tests --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..2efff1f --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +ignore: + - test From f63d6f6b6e02cd441aa52a64ebd435d48a6fb428 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Dec 2019 20:36:08 +0100 Subject: [PATCH 023/138] fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1062e1c..fbaba22 100644 --- a/README.md +++ b/README.md @@ -409,7 +409,7 @@ By default, unit tests and example application are enabled. You can disable them #### libfuse -To install libfuse, meson is neede. Please refer to [meson quick guide](https://mesonbuild.com/Quick-guide.html) for setup instructions. +To install libfuse, meson is needed. Please refer to [meson quick guide](https://mesonbuild.com/Quick-guide.html) for setup instructions. wget -O fuse-3.8.0.tar.gz https://github.com/libfuse/libfuse/archive/fuse-3.8.0.tar.gz tar -xf fuse-3.8.0.tar.gz From cc22bb6756ff2b5c616dfe64334fded411594d49 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 2 Dec 2019 19:25:07 +0100 Subject: [PATCH 024/138] remove build dependencies during build (ubuntu) --- build/amd64-ubuntu-builder.dockerfile | 9 +++------ build/arm32v7-ubuntu-builder.dockerfile | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index acd51ac..b089e86 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -49,22 +49,19 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -RUN set -x \ - && builddeps="udev python3 python3-pip python3-setuptools python3-wheel ninja-build" \ - && apt install --yes --no-install-recommends $builddeps \ - && pip3 install --system meson - ARG FUSE_VERSION=3.8.0 RUN set -x \ - && builddeps="libtool automake gettext" \ + && builddeps="udev gettext python3 python3-pip python3-setuptools python3-wheel" \ && apt install --yes --no-install-recommends $builddeps \ + && pip3 install --system meson \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ && ninja \ && ninja install \ + && pip3 uninstall -y meson \ && rm -rf "$builddir" \ && apt purge -y $builddeps diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index 1b4f735..96f154a 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -52,22 +52,19 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -RUN set -x \ - && builddeps="udev python3 python3-pip python3-setuptools python3-wheel ninja-build" \ - && apt install --yes --no-install-recommends $builddeps \ - && pip3 install --system meson - ARG FUSE_VERSION=3.8.0 RUN set -x \ - && builddeps="libtool automake gettext" \ + && builddeps="udev gettext python3 python3-pip python3-setuptools python3-wheel" \ && apt install --yes --no-install-recommends $builddeps \ + && pip3 install --system meson \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ && ninja \ && ninja install \ + && pip3 uninstall -y meson \ && rm -rf "$builddir" \ && apt purge -y $builddeps From 1e57523ef781501252f5c69515f650a90dd7ede1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 2 Dec 2019 20:21:19 +0100 Subject: [PATCH 025/138] remove build dependencies during build (alpine) --- build/amd64-alpine-builder.dockerfile | 9 +++------ build/arm32v7-alpine-builder.dockerfile | 10 ++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index e13924a..fa0d6cb 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -50,16 +50,12 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -RUN set -x \ - && builddeps="linux-headers udev eudev-dev python3 py3-pip py3-setuptools py3-cryptography ninja" \ - && apk add --no-cache --virtual .build-deps $builddeps \ - && pip3 install meson - ARG FUSE_VERSION=3.8.0 RUN set -x \ - && builddeps="libtool automake autoconf gettext-dev m4" \ + && builddeps="linux-headers eudev-dev python3 py3-pip py3-setuptools py3-cryptography" \ && apk add --no-cache --virtual .build-deps $builddeps \ + && pip3 install meson \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ @@ -67,6 +63,7 @@ RUN set -x \ && meson configure -Dexamples=false \ && ninja \ && ninja install \ + && pip3 uninstall -y meson \ && rm -rf "$builddir" \ && apk del .build-deps diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index 63f910e..b7a7ef6 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -54,22 +54,20 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -RUN set -x \ - && builddeps="linux-headers udev eudev-dev python3 py3-pip py3-setuptools py3-cryptography ninja" \ - && apk add --no-cache --virtual .build-deps $builddeps \ - && pip3 install meson - ARG FUSE_VERSION=3.8.0 RUN set -x \ - && builddeps="libtool automake autoconf gettext-dev m4" \ + && builddeps="linux-headers eudev-dev python3 py3-pip py3-setuptools py3-cryptography" \ && apk add --no-cache --virtual .build-deps $builddeps \ + && pip3 install meson \ && builddir="/tmp/out" \ && mkdir -p "$builddir" \ && cd "$builddir" \ && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && meson configure -Dexamples=false \ && ninja \ && ninja install \ + && pip3 uninstall -y meson \ && rm -rf "$builddir" \ && apk del .build-deps From cae0e0613c0a34f664d34c32366c324bdb4ca2c9 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 2 Dec 2019 20:44:56 +0100 Subject: [PATCH 026/138] be compatible to libfuse 3.1+ --- lib/webfuse/adapter/impl/fuse_wrapper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webfuse/adapter/impl/fuse_wrapper.h b/lib/webfuse/adapter/impl/fuse_wrapper.h index b234e73..719d758 100644 --- a/lib/webfuse/adapter/impl/fuse_wrapper.h +++ b/lib/webfuse/adapter/impl/fuse_wrapper.h @@ -5,7 +5,7 @@ extern "C" { #endif -#define FUSE_USE_VERSION 38 +#define FUSE_USE_VERSION 31 #include #ifdef __cplusplus From f504a01cb22fac3c283bb71dc1c0280fad59e274 Mon Sep 17 00:00:00 2001 From: Falk Werner <47070255+falk-werner@users.noreply.github.com> Date: Tue, 17 Dec 2019 23:52:47 +0100 Subject: [PATCH 027/138] chore: update libfuse to 3.9.0 * updated libfuse to 3.9.0 --- Makefile | 4 ++-- build/amd64-alpine-builder.dockerfile | 2 +- build/amd64-ubuntu-builder.dockerfile | 2 +- build/arm32v7-alpine-builder.dockerfile | 2 +- build/arm32v7-ubuntu-builder.dockerfile | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 01c9f3d..bdcc591 100644 --- a/Makefile +++ b/Makefile @@ -56,11 +56,11 @@ FETCH_TARGETS += $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: URL := https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz $(SKIP_MD5SUM)$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := ecd1fa65e7de707cd5c00bdac56022cd -FUSE_VERSION ?= 3.8.0 +FUSE_VERSION ?= 3.9.0 DOCKER_BUILDARGS += FUSE_VERSION=$(FUSE_VERSION) FETCH_TARGETS += $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz -$(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 909d6b2cfc2faa9f4b6033d356280540 +$(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 31b19277c039ae225927edc29193d34f WEBSOCKETS_VERSION ?= 3.2.0 DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION) diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index fa0d6cb..d4de18e 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -50,7 +50,7 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.8.0 +ARG FUSE_VERSION=3.9.0 RUN set -x \ && builddeps="linux-headers eudev-dev python3 py3-pip py3-setuptools py3-cryptography" \ diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index b089e86..6888ad3 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -49,7 +49,7 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.8.0 +ARG FUSE_VERSION=3.9.0 RUN set -x \ && builddeps="udev gettext python3 python3-pip python3-setuptools python3-wheel" \ diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index b7a7ef6..48c2e1f 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -54,7 +54,7 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.8.0 +ARG FUSE_VERSION=3.9.0 RUN set -x \ && builddeps="linux-headers eudev-dev python3 py3-pip py3-setuptools py3-cryptography" \ diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index 96f154a..cc7e851 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -52,7 +52,7 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.8.0 +ARG FUSE_VERSION=3.9.0 RUN set -x \ && builddeps="udev gettext python3 python3-pip python3-setuptools python3-wheel" \ From bd82b06c8aae50301e22d338987eaaa73e933079 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 9 Feb 2020 20:42:57 +0100 Subject: [PATCH 028/138] feature: removed example --- CMakeLists.txt | 75 ---- README.md | 7 + example/daemon/main.c | 196 ---------- example/daemon/www/index.html | 18 - example/daemon/www/js/.eslintrc.js | 287 -------------- example/daemon/www/js/connection_view.js | 93 ----- example/daemon/www/js/filesystem_provider.js | 122 ------ example/daemon/www/js/package.json | 11 - example/daemon/www/js/startup.js | 25 -- example/daemon/www/js/webfuse/bad_state.js | 15 - example/daemon/www/js/webfuse/client.js | 223 ----------- example/daemon/www/js/webfuse/file_mode.js | 10 - example/daemon/www/js/webfuse/provider.js | 30 -- example/daemon/www/style/main.css | 47 --- example/lib/userdb/include/userdb.h | 46 --- example/lib/userdb/src/userdb.c | 277 ------------- example/passwd/main.c | 304 --------------- example/provider/main.c | 385 ------------------- example/provider/static_filesystem.c | 109 ------ 19 files changed, 7 insertions(+), 2273 deletions(-) delete mode 100644 example/daemon/main.c delete mode 100644 example/daemon/www/index.html delete mode 100644 example/daemon/www/js/.eslintrc.js delete mode 100644 example/daemon/www/js/connection_view.js delete mode 100644 example/daemon/www/js/filesystem_provider.js delete mode 100644 example/daemon/www/js/package.json delete mode 100644 example/daemon/www/js/startup.js delete mode 100644 example/daemon/www/js/webfuse/bad_state.js delete mode 100644 example/daemon/www/js/webfuse/client.js delete mode 100644 example/daemon/www/js/webfuse/file_mode.js delete mode 100644 example/daemon/www/js/webfuse/provider.js delete mode 100644 example/daemon/www/style/main.css delete mode 100644 example/lib/userdb/include/userdb.h delete mode 100644 example/lib/userdb/src/userdb.c delete mode 100644 example/passwd/main.c delete mode 100644 example/provider/main.c delete mode 100644 example/provider/static_filesystem.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ae4ee7c..48df128 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,81 +190,6 @@ install(FILES include/webfuse_provider.h DESTINATION include) install(DIRECTORY include/webfuse/provider DESTINATION include/webfuse) install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) - -# examples - -pkg_check_modules(OPENSSL REQUIRED openssl) - -if(NOT WITHOUT_EXAMPLE) - -# libuserdb - -add_library(userdb STATIC - example/lib/userdb/src/userdb.c -) - -target_include_directories(userdb PUBLIC - example/lib/userdb/include - ${OPENSSL_INCLUDE_DIRS} - ${JANSSON_INCLUDE_DIRS} -) - -target_compile_options(userdb PUBLIC ${OPENSSL_CFLAGS_OTHER}) - -# daemon - -add_executable(webfused - example/daemon/main.c -) - -target_link_libraries(webfused PUBLIC webfuse-adapter userdb ${OPENSSL_LIBRARIES} ${EXTRA_LIBS}) -target_compile_options(webfused PUBLIC ${OPENSSL_CFLAGS_OTHER}) - -# provider - -add_executable(webfuse-provider-app - example/provider/main.c -) - -set_target_properties(webfuse-provider-app PROPERTIES OUTPUT_NAME webfuse-provider) - -target_link_libraries(webfuse-provider-app PUBLIC webfuse-provider ${EXTRA_LIBS}) -target_include_directories(webfuse-provider-app PUBLIC ${EXTRA_INCLUDE_DIRS}) - -# static-filesystem-provider - -add_executable(static-filesystem-provider - example/provider/static_filesystem.c -) - -target_link_libraries(static-filesystem-provider PUBLIC webfuse-provider ${EXTRA_LIBS}) -target_include_directories(static-filesystem-provider PUBLIC ${EXTRA_INCLUDE_DIRS}) -target_compile_options(static-filesystem-provider PUBLIC ${EXTRA_CFLAGS}) - -# webfuse-passwd - -add_executable(webfuse-passwd - example/passwd/main.c -) - -target_link_libraries(webfuse-passwd PUBLIC - userdb - ${OPENSSL_LIBRARIES} - ${JANSSON_LIBRARIES} -) - -target_include_directories(webfuse-passwd PUBLIC - example/passwd - example/lib/userdb/include - ${OPENSSL_INCLUDE_DIRS} - ${JANSSON_INCLUDE_DIRS} -) - -target_compile_options(webfuse-passwd PUBLIC ${OPENSSL_CFLAGS_OTHER}) - - -endif(NOT WITHOUT_EXAMPLE) - # tests if(NOT WITHOUT_TESTS) diff --git a/README.md b/README.md index fbaba22..716e079 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ webfuse combines libwebsockets and libfuse. It allows ot attach a remote filesys ## Contents - [Motivation](#Motivation) +- [Fellow Repositories](#Fellow-Repositories) - [Concept](#Concept) - [Similar Projects](#Similar-Projects) - [API](#API) @@ -32,6 +33,12 @@ To avoid Steps 1 and 2, it would be great to keep the update file entirely in we webfuse solves this problem by using the [WebSocket](https://en.wikipedia.org/wiki/WebSocket) protocol. The emdedded device runs a service, known as webfuse adapter, awaiting incoming connections, e.g. from a web browser. The browser acts as a file system provider, providing the update file to the device. +## Fellow Repositories + +- **[webfuse-example](https://github.com/falk-werner/webfuse-example)**: Example of webfuse +- **[webfused](https://github.com/falk-werner/webfused)**: Reference implementation of webfuse daemon +- **[webfuse-provider](https://github.com/falk-werner/webfuse-provider)**: Reference implementation of webfuse provider + ## Concept ![concept](doc/concept.png) diff --git a/example/daemon/main.c b/example/daemon/main.c deleted file mode 100644 index 2cde4ab..0000000 --- a/example/daemon/main.c +++ /dev/null @@ -1,196 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#define SERVICE_TIMEOUT (1 * 1000) - -struct args -{ - struct wf_server_config * config; - char * passwd_path; - bool show_help; -}; - -static bool shutdown_requested = false; - -static void show_help(void) -{ - printf( - "webfused, Copyright (c) 2019, webfuse authors \n" - "Websocket file system daemon\n" - "\n" - "Usage: webfused [m ] [-d ] [-p ]\n" - " [-c ] [-k ] [-P ]\n" - "\n" - "Options:\n" - "\t-m, --mount_point Path of mount point (required)\n" - "\t-d, --document_root Path of www directory (default: not set, www disabled)\n" - "\t-c, --server_cert_path Path of servers own certificate (default: not set, TLS disabled)\n" - "\t-k, --server_key_path Path of servers private key (default: not set, TLS disabled)\n" - "\t-n, --vhost_name Name of virtual host (default: \"localhost\")\n" - "\t-p, --port Number of servers port (default: 8080)\n" - "\t-P, --passwd_path Path to password file (default: not set, authentication disabled)\n" - "\n"); -} - -static bool authenticate(struct wf_credentials * creds, void * user_data) -{ - bool result = false; - struct args * args = user_data; - - char const * username = wf_credentials_get(creds, "username"); - char const * password = wf_credentials_get(creds, "password"); - if ((NULL != username) && (NULL != password)) - { - struct userdb * db = userdb_create(""); - result = userdb_load(db, args->passwd_path); - if (result) - { - result = userdb_check(db, username, password); - } - - userdb_dispose(db); - } - - return result; -} - -static int parse_arguments(int argc, char * argv[], struct args * args) -{ - static struct option const options[] = - { - {"mount_point", required_argument, NULL, 'm'}, - {"document_root", required_argument, NULL, 'd'}, - {"server_cert_path", required_argument, NULL, 'c'}, - {"server_key_path", required_argument, NULL, 'k'}, - {"vhost_name", required_argument, NULL, 'n'}, - {"port", required_argument, NULL, 'p'}, - {"passwd_path", required_argument, NULL, 'P'}, - {"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0} - }; - - bool result = EXIT_SUCCESS; - bool finished = false; - bool has_mountpoint = false; - while ((!finished) && (EXIT_SUCCESS == result)) - { - int option_index = 0; - int const c = getopt_long(argc, argv, "m:d:c:k:n:p:P:h", options, &option_index); - - switch (c) - { - case -1: - finished = true; - break; - case 'h': - args->show_help = true; - finished = true; - break; - case 'm': - wf_server_config_set_mountpoint(args->config, optarg); - has_mountpoint = true; - break; - case 'd': - wf_server_config_set_documentroot(args->config, optarg); - break; - case 'c': - wf_server_config_set_certpath(args->config, optarg); - break; - case 'k': - wf_server_config_set_keypath(args->config, optarg); - break; - case 'n': - wf_server_config_set_vhostname(args->config, optarg); - break; - case 'p': - wf_server_config_set_port(args->config, atoi(optarg)); - break; - case 'P': - free(args->passwd_path); - args->passwd_path = strdup(optarg); - wf_server_config_add_authenticator(args->config, - "username", - &authenticate, - args); - break; - default: - fprintf(stderr, "error: unknown argument\n"); - result = EXIT_FAILURE; - break; - } - } - - if ((EXIT_SUCCESS == result) && (!args->show_help)) - { - if (!has_mountpoint) - { - fprintf(stderr, "error: missing mount point\n"); - result = EXIT_FAILURE; - } - } - - if (EXIT_SUCCESS != result) - { - args->show_help = true; - } - - return result; -} - -static void on_interrupt(int signal_id) -{ - (void) signal_id; - - shutdown_requested = true; -} - -int main(int argc, char * argv[]) -{ - struct args args; - args.config = wf_server_config_create(); - wf_server_config_set_vhostname(args.config, "localhost"); - wf_server_config_set_port(args.config, 8080); - args.passwd_path = NULL; - args.show_help = false; - - int result = parse_arguments(argc, argv, &args); - - if (!args.show_help) - { - signal(SIGINT, on_interrupt); - struct wf_server * server = wf_server_create(args.config); - if (NULL != server) - { - while (!shutdown_requested) - { - wf_server_service(server, SERVICE_TIMEOUT); - } - - wf_server_dispose(server); - } - else - { - fprintf(stderr, "fatal: unable start server\n"); - result = EXIT_FAILURE; - } - } - else - { - show_help(); - } - - free(args.passwd_path); - wf_server_config_dispose(args.config); - return result; -} - diff --git a/example/daemon/www/index.html b/example/daemon/www/index.html deleted file mode 100644 index 0cb0918..0000000 --- a/example/daemon/www/index.html +++ /dev/null @@ -1,18 +0,0 @@ - - - WebFuse Example - - - - - - -
-
-
Connection
-
-
-
- - - \ No newline at end of file diff --git a/example/daemon/www/js/.eslintrc.js b/example/daemon/www/js/.eslintrc.js deleted file mode 100644 index 9090e7d..0000000 --- a/example/daemon/www/js/.eslintrc.js +++ /dev/null @@ -1,287 +0,0 @@ -module.exports = { - "env": { - "browser": true, - "es6": true - }, - "extends": "eslint:recommended", - "globals": { - "Atomics": "readonly", - "SharedArrayBuffer": "readonly" - }, - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module" - }, - "rules": { - "accessor-pairs": "error", - "array-bracket-newline": "error", - "array-bracket-spacing": "error", - "array-callback-return": "error", - "array-element-newline": ["error", "consistent"], - "arrow-body-style": "error", - "arrow-parens": [ - "error", - "always" - ], - "arrow-spacing": [ - "error", - { - "after": true, - "before": true - } - ], - "block-scoped-var": "error", - "block-spacing": [ - "error", - "always" - ], - "brace-style": "off", - "callback-return": "off", - "camelcase": "error", - "capitalized-comments": [ - "error", - "never" - ], - "class-methods-use-this": "off", - "comma-dangle": "error", - "comma-spacing": [ - "error", - { - "after": true, - "before": false - } - ], - "comma-style": [ - "error", - "last" - ], - "complexity": "error", - "computed-property-spacing": [ - "error", - "never" - ], - "consistent-return": "error", - "consistent-this": "error", - "curly": "error", - "default-case": "error", - "dot-location": "error", - "dot-notation": "error", - "eol-last": "off", - "eqeqeq": "off", - "func-call-spacing": "error", - "func-name-matching": "error", - "func-names": "error", - "func-style": [ - "error", - "declaration" - ], - "function-paren-newline": "error", - "generator-star-spacing": "error", - "global-require": "error", - "guard-for-in": "error", - "handle-callback-err": "error", - "id-blacklist": "error", - "id-length": "error", - "id-match": "error", - "implicit-arrow-linebreak": [ - "error", - "beside" - ], - "indent": "off", - "indent-legacy": "off", - "init-declarations": "off", - "jsx-quotes": "error", - "key-spacing": "off", - "keyword-spacing": "off", - "line-comment-position": "error", - "linebreak-style": [ - "error", - "unix" - ], - "lines-around-comment": "error", - "lines-around-directive": "error", - "lines-between-class-members": "off", - "max-classes-per-file": "error", - "max-depth": "error", - "max-len": "off", - "max-lines": "error", - "max-lines-per-function": "off", - "max-nested-callbacks": "error", - "max-params": "off", - "max-statements": "off", - "max-statements-per-line": "off", - "multiline-comment-style": "error", - "new-cap": "error", - "new-parens": "error", - "newline-after-var": "off", - "newline-before-return": "error", - "newline-per-chained-call": "error", - "no-alert": "error", - "no-array-constructor": "error", - "no-async-promise-executor": "error", - "no-await-in-loop": "error", - "no-bitwise": "off", - "no-buffer-constructor": "error", - "no-caller": "error", - "no-catch-shadow": "error", - "no-confusing-arrow": "error", - "no-continue": "error", - "no-div-regex": "error", - "no-duplicate-imports": "error", - "no-else-return": "off", - "no-empty-function": "off", - "no-eq-null": "error", - "no-eval": "error", - "no-extend-native": "error", - "no-extra-bind": "error", - "no-extra-label": "error", - "no-extra-parens": "off", - "no-floating-decimal": "error", - "no-implicit-coercion": "error", - "no-implicit-globals": "off", - "no-implied-eval": "error", - "no-inline-comments": "error", - "no-invalid-this": "error", - "no-iterator": "error", - "no-label-var": "error", - "no-labels": "error", - "no-lone-blocks": "error", - "no-lonely-if": "error", - "no-loop-func": "error", - "no-magic-numbers": "off", - "no-misleading-character-class": "error", - "no-mixed-operators": "error", - "no-mixed-requires": "error", - "no-multi-assign": "error", - "no-multi-spaces": "off", - "no-multi-str": "error", - "no-multiple-empty-lines": "error", - "no-native-reassign": "error", - "no-negated-condition": "off", - "no-negated-in-lhs": "error", - "no-nested-ternary": "error", - "no-new": "error", - "no-new-func": "error", - "no-new-object": "error", - "no-new-require": "error", - "no-new-wrappers": "error", - "no-octal-escape": "error", - "no-param-reassign": "error", - "no-path-concat": "error", - "no-plusplus": "error", - "no-process-env": "error", - "no-process-exit": "error", - "no-proto": "error", - "no-prototype-builtins": "error", - "no-restricted-globals": "error", - "no-restricted-imports": "error", - "no-restricted-modules": "error", - "no-restricted-properties": "error", - "no-restricted-syntax": "error", - "no-return-assign": "error", - "no-return-await": "error", - "no-script-url": "error", - "no-self-compare": "error", - "no-sequences": "error", - "no-shadow": "off", - "no-shadow-restricted-names": "error", - "no-spaced-func": "error", - "no-sync": "error", - "no-tabs": "off", - "no-template-curly-in-string": "error", - "no-ternary": "off", - "no-throw-literal": "error", - "no-trailing-spaces": "off", - "no-undef-init": "error", - "no-undefined": "error", - "no-unmodified-loop-condition": "error", - "no-unneeded-ternary": "error", - "no-unused-expressions": "error", - "no-use-before-define": "error", - "no-useless-call": "error", - // "no-useless-catch": "error", - "no-useless-computed-key": "error", - "no-useless-concat": "error", - "no-useless-constructor": "error", - "no-useless-rename": "error", - "no-useless-return": "error", - "no-var": "error", - "no-void": "error", - "no-warning-comments": "error", - "no-whitespace-before-property": "error", - "no-with": "error", - "nonblock-statement-body-position": "error", - "object-curly-newline": "error", - "object-curly-spacing": "off", - "object-shorthand": "off", - "one-var": "off", - "one-var-declaration-per-line": "error", - "operator-assignment": "error", - "operator-linebreak": "error", - "padded-blocks": "off", - "padding-line-between-statements": "error", - "prefer-arrow-callback": "error", - "prefer-const": "off", - "prefer-destructuring": "off", - "prefer-numeric-literals": "off", - "prefer-object-spread": "error", - "prefer-promise-reject-errors": "error", - "prefer-reflect": "error", - "prefer-rest-params": "error", - "prefer-spread": "error", - "prefer-template": "error", - "quote-props": "off", - "quotes": "off", - "radix": "error", - "require-atomic-updates": "error", - "require-await": "off", - "require-jsdoc": "off", - "require-unicode-regexp": "off", - "rest-spread-spacing": "error", - "semi": "error", - "semi-spacing": "error", - "semi-style": [ - "error", - "last" - ], - "sort-imports": "error", - "sort-keys": "off", - "sort-vars": "error", - "space-before-blocks": "error", - "space-before-function-paren": "off", - "space-in-parens": [ - "error", - "never" - ], - "space-infix-ops": "error", - "space-unary-ops": [ - "error", - { - "nonwords": false, - "words": false - } - ], - "spaced-comment": [ - "error", - "always" - ], - "strict": [ - "error", - "never" - ], - "switch-colon-spacing": "error", - "symbol-description": "error", - "template-curly-spacing": "error", - "template-tag-spacing": "error", - "unicode-bom": [ - "error", - "never" - ], - "valid-jsdoc": "error", - "vars-on-top": "error", - "wrap-iife": "error", - "wrap-regex": "error", - "yield-star-spacing": "error", - "yoda": "off" - } -}; \ No newline at end of file diff --git a/example/daemon/www/js/connection_view.js b/example/daemon/www/js/connection_view.js deleted file mode 100644 index 31576ae..0000000 --- a/example/daemon/www/js/connection_view.js +++ /dev/null @@ -1,93 +0,0 @@ -export class ConnectionView { - constructor(client, provider) { - this._provider = provider; - this._client = client; - this._client.onopen = () => { this._onConnectionOpened(); }; - this._client.onclose = () => { this._onConnectionClosed(); }; - - this.element = document.createElement("div"); - - const connectBox = document.createElement("div"); - this.element.appendChild(connectBox); - - const urlLabel = document.createElement("span"); - urlLabel.textContent = "URL:"; - connectBox.appendChild(urlLabel); - - this.urlTextbox = document.createElement("input"); - this.urlTextbox.type = "text"; - this.urlTextbox.value = window.location.href.replace(/^http/, "ws"); - connectBox.appendChild(this.urlTextbox); - - this.connectButton = document.createElement("input"); - this.connectButton.type = "button"; - this.connectButton.value = "connect"; - this.connectButton.addEventListener("click", () => { this._onConnectButtonClicked(); }); - connectBox.appendChild(this.connectButton); - - - const authenticateBox = document.createElement("div"); - this.element.appendChild(authenticateBox); - - const authLabel = document.createElement("span"); - authLabel.textContent = "use authentication:"; - authenticateBox.appendChild(authLabel); - - this.authenticateCheckbox = document.createElement("input"); - this.authenticateCheckbox.type = "checkbox"; - authenticateBox.appendChild(this.authenticateCheckbox); - - const usernameLabel = document.createElement("span"); - usernameLabel.textContent = "user:"; - authenticateBox.appendChild(usernameLabel); - - this.usernameTextbox = document.createElement("input"); - this.usernameTextbox.type = "text"; - this.usernameTextbox.value = "bob"; - authenticateBox.appendChild(this.usernameTextbox); - - const passwordLabel = document.createElement("span"); - passwordLabel.textContent = "user:"; - authenticateBox.appendChild(passwordLabel); - - this.passwordTextbox = document.createElement("input"); - this.passwordTextbox.type = "password"; - this.passwordTextbox.value = "secret"; - authenticateBox.appendChild(this.passwordTextbox); - } - - _onConnectButtonClicked() { - if (!this._client.isConnected()) { - let url = this.urlTextbox.value; - this._client.connectTo(url); - } - else { - this._client.disconnect(); - } - } - - _onAuthenticateButtonClicked() { - if (this._client.isConnected()) { - - } - } - - _onConnectionOpened() { - if (this.authenticateCheckbox.checked) { - const username = this.usernameTextbox.value; - const password = this.passwordTextbox.value; - - const promise = this._client.authenticate("username", { username, password }); - promise.then(() => { this._client.addProvider("test", this._provider); }); - } else { - this._client.addProvider("test", this._provider); - } - - this.connectButton.value = "disconnect"; - } - - _onConnectionClosed() { - this.connectButton.value = "connect"; - } - -} diff --git a/example/daemon/www/js/filesystem_provider.js b/example/daemon/www/js/filesystem_provider.js deleted file mode 100644 index 85ad287..0000000 --- a/example/daemon/www/js/filesystem_provider.js +++ /dev/null @@ -1,122 +0,0 @@ -/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */ - -import { BadState } from "./webfuse/bad_state.js"; -import { FileMode } from "./webfuse/file_mode.js"; -import { Provider } from "./webfuse/provider.js"; - -export class FileSystemProvider extends Provider { - constructor(root) { - super(); - - this.root = root; - this._inodes = { }; - - this._walk(this.root, (entry) => { this._inodes[entry.inode] = entry; }); - } - - _walk(node, callback) { - callback(node); - - const entries = node.entries; - if (entries) { - for(let entry of Object.entries(entries)) { - this._walk(entry[1], callback); - } - } - } - - - async lookup(parent, name) { - const parentEntry = this._inodes[parent]; - const entry = (parentEntry && parentEntry.entries && parentEntry.entries[name]) || null; - if (entry) { - return { - inode: entry.inode, - mode: entry.mode || parseInt("755", 8), - type: entry.type || "file", - size: entry.size || (entry.contents && entry.contents.length) || 0, - atime: entry.atime || 0, - mtime: entry.mtime || 0, - ctime: entry.ctime || 0 - }; - } - else { - throw new BadState(BadState.NO_ENTRY); - } - } - - - async getattr(inode) { - let entry = this._inodes[inode]; - if (entry) { - return { - mode: entry.mode || parseInt("755", 8), - type: entry.type || "file", - size: entry.size || (entry.contents && entry.contents.length) || 0, - atime: entry.atime || 0, - mtime: entry.mtime || 0, - ctime: entry.ctime || 0 - }; - } - else { - throw new BadState(BadState.NO_ENTRY); - } - } - - async readdir(inode) { - let entry = this._inodes[inode]; - - if ((entry) && ("dir" === entry.type)) { - let result = [ - {name: ".", inode: entry.inode}, - {name: "..", inode: entry.inode} - ]; - for(let subdir of Object.entries(entry.entries)) { - const name = subdir[0]; - const inode = subdir[1].inode; - result.push({name, inode}); - } - - return result; - } - else { - throw new BadState(BadState.NO_ENTRY); - } - - } - - async open(inode, mode) { - let entry = this._inodes[inode]; - - if (entry.type === "file") { - if ((mode & FileMode.ACCESS_MODE) === FileMode.READONLY) { - return {handle: 1337}; - } - else { - throw new BadState(BadState.NO_ACCESS); - } - } - else { - throw new BadState(BadState.NO_ENTRY); - } - } - - close(_inode, _handle, _mode) { - // do nothing - return true; - } - - async read(inode, handle, offset, length) { - let entry = this._inodes[inode]; - - if (entry.type === "file") { - const end = Math.min(offset + length, entry.contents.length); - const data = (offset < entry.contents.length) ? entry.contents.substring(offset, end) : ""; - - return data; - } - else { - throw new BadState(BadState.NO_ENTRY); - } - } -} \ No newline at end of file diff --git a/example/daemon/www/js/package.json b/example/daemon/www/js/package.json deleted file mode 100644 index 6c553ef..0000000 --- a/example/daemon/www/js/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "webfuse-provider", - "version": "0.2.0", - "description": "Provider for websocket filesystem (webfuse)", - "main": "startup.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Falk Werner", - "license": "LGPL-3.0" -} diff --git a/example/daemon/www/js/startup.js b/example/daemon/www/js/startup.js deleted file mode 100644 index 284d229..0000000 --- a/example/daemon/www/js/startup.js +++ /dev/null @@ -1,25 +0,0 @@ -import { Client } from "./webfuse/client.js"; -import { ConnectionView } from "./connection_view.js"; -import { FileSystemProvider } from "./filesystem_provider.js"; - - -function mode(value) { - return parseInt(value, 8); -} - -function startup() { - const provider = new FileSystemProvider({ - inode: 1, - mode: mode("0755"), - type: "dir", - entries: { - "hello.txt" : { inode: 2, mode: mode("0444"), type: "file", contents: "Hello, World!"}, - "say_hello.sh": { inode: 3, mode: mode("0555"), type: "file", contents: "#!/bin/sh\necho hello\n"} - } - }); - const client = new Client(); - const connectionView = new ConnectionView(client, provider); - document.getElementById('connection').appendChild(connectionView.element); -} - -window.onload = startup; diff --git a/example/daemon/www/js/webfuse/bad_state.js b/example/daemon/www/js/webfuse/bad_state.js deleted file mode 100644 index fdb05d9..0000000 --- a/example/daemon/www/js/webfuse/bad_state.js +++ /dev/null @@ -1,15 +0,0 @@ -export class BadState extends Error { - static get BAD() { return 1; } - - static get NOT_IMPLEMENTED() { return 2; } - static get TIMEOUT() { return 3; } - static get FORMAT() { return 4; } - - static get NO_ENTRY() { return 101; } - static get NO_ACCESS() { return 102; } - - constructor(code) { - super("Bad State"); - this.code = code; - } -} \ No newline at end of file diff --git a/example/daemon/www/js/webfuse/client.js b/example/daemon/www/js/webfuse/client.js deleted file mode 100644 index 65d24f2..0000000 --- a/example/daemon/www/js/webfuse/client.js +++ /dev/null @@ -1,223 +0,0 @@ -import { BadState } from "./bad_state.js"; - -export class Client { - static get _PROTOCOL() { return "fs"; } - - constructor(provider) { - this._provider = { }; - this._pendingRequests = {}; - this._id = 0; - this._ws = null; - this.onopen = () => { }; - this.onclose = () => { }; - this.onerror = () => { }; - } - - connectTo(url) { - this.disconnect(); - - this._ws = new WebSocket(url, Client._PROTOCOL); - this._ws.onopen = this.onopen; - this._ws.onclose = this.onclose; - this._ws.onerror = this.onerror; - - this._ws.onmessage = (message) => { - this._onmessage(message); - }; - } - - _invokeRequest(method, params) { - this._id += 1; - const id = this._id; - const request = {method, params, id}; - - return new Promise((resolve, reject) => { - this._pendingRequests[id] = {resolve, reject}; - this._ws.send(JSON.stringify(request)); - }); - } - - authenticate(type, credentials) { - return this._invokeRequest("authenticate", [type, credentials]); - } - - addProvider(name, provider) { - this._provider[name] = provider; - const request = { - "method": "add_filesystem", - "params": [name], - "id": 23 - }; - - this._ws.send(JSON.stringify(request)); - } - - disconnect() { - if (this._ws) { - this._ws.close(); - this._ws = null; - } - } - - isConnected() { - return ((this._ws) && (this._ws.readyState === WebSocket.OPEN)); - } - - _isRequest(request) { - const method = request.method; - - return (("string" === typeof(method)) && ("params" in request)); - } - - _isResponse(response) { - const id = response.id; - - return (("number" === typeof(id)) && (("result" in response) || ("error" in response))); - } - - _removePendingRequest(id) { - let result = null; - - if (id in this._pendingRequests) { - result = this._pendingRequests[id]; - Reflect.deleteProperty(this._pendingRequests, id); - } - - return result; - } - - _onmessage(message) { - try { - const data = JSON.parse(message.data); - - if (this._isRequest(data)) { - const method = data.method; - const id = data.id; - const params = data.params; - - if ("number" === typeof(id)) { - this._invoke(method, params, id); - } - else { - this._notify(method, params); - } - } - else if (this._isResponse(data)) { - const id = data.id; - const result = data.result; - const error = data.error; - - const request = this._removePendingRequest(id); - if (request) { - if (result) { - request.resolve(result); - } - else { - request.reject(error); - } - } - } - - } - catch (ex) { - // swallow - } - } - - _invoke(method, params, id) { - this._invokeAsync(method, params). - then((result) => { - const response = { result, id }; - this._ws.send(JSON.stringify(response)); - }). - catch((ex) => { - const code = ex.code || BadState.BAD; - const response = {error: {code}, id}; - this._ws.send(JSON.stringify(response)); - }); - - } - - async _invokeAsync(method, params) { - switch(method) - { - case "lookup": - return this._lookup(params); - case "getattr": - return this._getattr(params); - case "readdir": - return this._readdir(params); - case "open": - return this._open(params); - case "read": - return this._read(params); - default: - throw new BadState(BadState.NOT_IMPLEMENTED); - } - } - - _notify(method, params) { - switch(method) { - case 'close': - this._close(params); - break; - default: - throw new Error(`Invalid method: "${method}"`); - } - } - - _getProvider(name) { - if (name in this._provider) { - return this._provider[name]; - } - else { - throw new Error('Unknown provider'); - } - } - - async _lookup([providerName, parent, name]) { - const provider = this._getProvider(providerName); - - return provider.lookup(parent, name); - } - - async _getattr([providerName, inode]) { - const provider = this._getProvider(providerName); - - return provider.getattr(inode); - } - - async _readdir([providerName, inode]) { - const provider = this._getProvider(providerName); - - return provider.readdir(inode); - } - - async _open([providerName, inode, mode]) { - const provider = this._getProvider(providerName); - - return provider.open(inode, mode); - } - - _close([providerName, inode, handle, mode]) { - const provider = this._getProvider(providerName); - - provider.close(inode, handle, mode); - } - - async _read([providerName, inode, handle, offset, length]) { - const provider = this._getProvider(providerName); - const data = await provider.read(inode, handle, offset, length); - - if ("string" === typeof(data)) { - return { - data: btoa(data), - format: "base64", - count: data.length - }; - } - else { - throw new BadState(BadState.BAD); - } - } -} \ No newline at end of file diff --git a/example/daemon/www/js/webfuse/file_mode.js b/example/daemon/www/js/webfuse/file_mode.js deleted file mode 100644 index b81a1ea..0000000 --- a/example/daemon/www/js/webfuse/file_mode.js +++ /dev/null @@ -1,10 +0,0 @@ -export class FileMode { - static get ACCESS_MODE() { return 0x003; } - static get READONLY() { return 0x000; } - static get WRITEONLY() { return 0x001; } - static get READWRITE() { return 0x002; } - static get CREATE() { return 0x040; } - static get EXCLUSIVE() { return 0x080; } - static get TRUNKATE() { return 0x200; } - static get APPEND() { return 0x400; } -} \ No newline at end of file diff --git a/example/daemon/www/js/webfuse/provider.js b/example/daemon/www/js/webfuse/provider.js deleted file mode 100644 index b9c5dc2..0000000 --- a/example/daemon/www/js/webfuse/provider.js +++ /dev/null @@ -1,30 +0,0 @@ -/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */ - -import { BadState } from "./bad_state.js"; - -export class Provider { - - async lookup(_parent, _name) { - throw new BadState(BadState.NOT_IMPLEMENTED); - } - - async getattr(_inode) { - throw new BadState(BadState.NOT_IMPLEMENTED); - } - - async readdir(_inode) { - throw new BadState(BadState.NOT_IMPLEMENTED); - } - - async open(_inode, _mode) { - throw new BadState(BadState.NOT_IMPLEMENTED); - } - - close(_inode, _handle, _mode) { - // empty - } - - async read(_inode, _handle, _offset, _length) { - throw new BadState(BadState.NOT_IMPLEMENTED); - } -} diff --git a/example/daemon/www/style/main.css b/example/daemon/www/style/main.css deleted file mode 100644 index 399bfd1..0000000 --- a/example/daemon/www/style/main.css +++ /dev/null @@ -1,47 +0,0 @@ -html, body { - font-family: monospace; - background-color: #c0c0c0; -} - -.page { - margin-left: 50px; - margin-right: 50px; - width: auto; -} - -.window { - border: 1px solid black; - background-color: black; - border-radius: 5px; - padding: 10px; - margin-bottom: 25px; - color: white; -} - -.window .title { - text-align: center; - color: #dba329; - font-weight: bold; - padding-bottom: 10px; - margin-bottom: 10px; - border-bottom: 1px solid #dba329; -} - -.commands { - text-align: right; -} - -.content { - column-count: 2; - column-width: 50%; -} - -.content > div { - display: inline-block; - width: 100%; -} - -#connection { - text-align: center; -} - diff --git a/example/lib/userdb/include/userdb.h b/example/lib/userdb/include/userdb.h deleted file mode 100644 index cf133d0..0000000 --- a/example/lib/userdb/include/userdb.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef USERDB_H -#define USERDB_H - -#ifndef __cplusplus -#include -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct userdb; - -extern struct userdb * userdb_create( - char const * pepper); - -extern void userdb_dispose(struct userdb * db); - -extern bool userdb_save( - struct userdb * db, - char const * filename); - -extern bool userdb_load( - struct userdb * db, - char const * filename); - -extern void userdb_add( - struct userdb * db, - char const * username, - char const * password); - -extern void userdb_remove( - struct userdb * db, - char const * user); - -extern bool userdb_check( - struct userdb * db, - char const * username, - char const * password); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/example/lib/userdb/src/userdb.c b/example/lib/userdb/src/userdb.c deleted file mode 100644 index 172742a..0000000 --- a/example/lib/userdb/src/userdb.c +++ /dev/null @@ -1,277 +0,0 @@ -#include "userdb.h" - -#include -#include -#include -#include - -#include -#include - -#define USERDB_HASH_ALGORITHM "sha512" -#define USERDB_MAJOR 1 -#define USERDB_MINOR 0 - -#define USERDB_SALT_SIZE 32 - -struct userdb -{ - json_t * users; - char * pepper; - char * hash_algorithm; -}; - -static bool is_compatible(json_t * meta) -{ - bool result = false; - if (json_is_object(meta)) - { - json_t * type = json_object_get(meta, "type"); - json_t * major = json_object_get(meta, "major"); - json_t * minor = json_object_get(meta, "minor"); - json_t * hash_algorithm = json_object_get(meta, "hash_algorithm"); - - result = ( - json_is_string(type) && - (0 == strcmp(json_string_value(type), "wf-userdb")) && - json_is_integer(major) && - (USERDB_MAJOR == json_integer_value(major)) && - json_is_integer(minor) && - json_is_string(hash_algorithm) - ); - - if (result) - { - char const * algorithm = json_string_value(hash_algorithm); - result = (NULL != EVP_get_digestbyname(algorithm)); - } - - } - return result; -} - -static char hex_char(unsigned char value) -{ - switch (value) - { - case 0x00: return '0'; - case 0x01: return '1'; - case 0x02: return '2'; - case 0x03: return '3'; - case 0x04: return '4'; - case 0x05: return '5'; - case 0x06: return '6'; - case 0x07: return '7'; - case 0x08: return '8'; - case 0x09: return '9'; - case 0x0a: return 'a'; - case 0x0b: return 'b'; - case 0x0c: return 'c'; - case 0x0d: return 'd'; - case 0x0e: return 'e'; - case 0x0f: return 'f'; - default: return '?'; - } -} - -static char * to_hex(unsigned char const * value, size_t length) -{ - char * result = malloc((2 * length) + 1); - if (NULL != result) - { - for (size_t i = 0, j = 0; i < length; i++, j+=2) - { - unsigned char high = (value[i] >> 4) & 0x0f; - unsigned char low = value[i] & 0x0f; - - result[j ] = hex_char(high); - result[j + 1] = hex_char(low); - } - - result[2 * length] = '\0'; - } - - return result; -} - -static char * generate_salt(void) -{ - unsigned char buffer[USERDB_SALT_SIZE]; - int rc = RAND_bytes(buffer, USERDB_SALT_SIZE); - if (1 != rc) - { - fprintf(stderr, "fatal: failed to generate salt (OpenSSL RAND_bytes failed)\n"); - exit(EXIT_FAILURE); - } - - return to_hex(buffer, USERDB_SALT_SIZE); -} - -static char * compute_hash( - struct userdb * db, - char const * password, - char const * salt) -{ - EVP_MD const * digest = EVP_get_digestbyname(db->hash_algorithm); - if (NULL == digest) - { - fprintf(stderr, "error: hash algorithm %s not supported\n", db->hash_algorithm); - return NULL; - } - - char * result = NULL; - unsigned int hash_size = EVP_MD_size(digest); - unsigned char * hash = malloc(hash_size); - - if (NULL != hash) - { - EVP_MD_CTX * context = EVP_MD_CTX_new(); - EVP_DigestInit_ex(context, digest, NULL); - EVP_DigestUpdate(context, password, strlen(password)); - EVP_DigestUpdate(context, salt, strlen(salt)); - EVP_DigestUpdate(context, db->pepper, strlen(db->pepper)); - EVP_DigestFinal_ex(context, hash, &hash_size); - EVP_MD_CTX_free(context); - - result = to_hex(hash, hash_size); - free(hash); - } - - return result; -} - -struct userdb * userdb_create( - char const * pepper) -{ - struct userdb * db = malloc(sizeof(struct userdb)); - if (NULL != db) - { - db->users = json_object(); - db->pepper = strdup(pepper); - db->hash_algorithm = strdup(USERDB_HASH_ALGORITHM); - } - - return db; -} - -void userdb_dispose( - struct userdb * db) -{ - json_decref(db->users); - free(db->pepper); - free(db->hash_algorithm); - free(db); -} - -bool userdb_save( - struct userdb * db, - char const * filename) -{ - json_t * container = json_object(); - - json_t * meta = json_object(); - json_object_set_new(meta, "type", json_string("wf-userdb")); - json_object_set_new(meta, "major", json_integer(USERDB_MAJOR)); - json_object_set_new(meta, "minor", json_integer(USERDB_MINOR)); - json_object_set_new(meta, "hash_algorithm", json_string(db->hash_algorithm)); - json_object_set_new(container, "meta", meta); - - json_object_set(container, "users", db->users); - - int result = json_dump_file(container, filename, JSON_INDENT(2)); - json_decref(container); - - return (0 == result); -} - - -bool userdb_load( - struct userdb * db, - char const * filename) -{ - bool result = false; - json_t * container = json_load_file(filename, 0, NULL); - if (NULL != container) - { - json_t * meta = json_object_get(container, "meta"); - json_t * users = json_object_get(container, "users"); - - if ((is_compatible(meta)) && (json_is_object(users))) { - json_t * hash_algorithm = json_object_get(meta, "hash_algorithm"); - free(db->hash_algorithm); - db->hash_algorithm = strdup(json_string_value(hash_algorithm)); - - json_decref(db->users); - json_incref(users); - db->users = users; - - result = true; - } - - json_decref(container); - } - - return result; -} - -void userdb_add( - struct userdb * db, - char const * username, - char const * password) -{ - char * salt = generate_salt(); - char * hash = compute_hash(db, password, salt); - - json_t * user = json_object(); - json_object_set_new(user, "password_hash", json_string(hash)); - json_object_set_new(user, "salt", json_string(salt)); - - json_object_set_new(db->users, username, user); - - free(salt); - free(hash); -} - -void userdb_remove( - struct userdb * db, - char const * user) -{ - json_object_del(db->users, user); -} - -static char const * json_object_get_string( - json_t * object, - char const * key) -{ - char const * result = NULL; - - json_t * string_holder = json_object_get(object, key); - if (json_is_string(string_holder)) - { - result = json_string_value(string_holder); - } - - return result; -} - -bool userdb_check( - struct userdb * db, - char const * username, - char const * password) -{ - bool result = false; - - json_t * user = json_object_get(db->users, username); - if (json_is_object(user)) - { - char const * salt = json_object_get_string(user, "salt"); - char const * hash = json_object_get_string(user, "password_hash"); - - char * computed_hash = compute_hash(db, password, salt); - - result = (0 == strcmp(computed_hash, hash)); - free(computed_hash); - } - - return result; -} \ No newline at end of file diff --git a/example/passwd/main.c b/example/passwd/main.c deleted file mode 100644 index 83862cc..0000000 --- a/example/passwd/main.c +++ /dev/null @@ -1,304 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - -struct args -{ - char * file; - char * command; - char * username; - char * password; - char * pepper; - bool show_help; -}; - -typedef int command_invoke_fn( - struct args * args); - -struct command -{ - char const * name; - command_invoke_fn * invoke; -}; - -static void print_usage(void) -{ - printf( - "webfuse-passwd, Copyright (c) 2019, webfuse authors \n" - "Manage webfuse passwd file\n" - "\n" - "Usage: webfuse-passwd -f -c [-u ] [-p ] [-P ]\n" - "\n" - "Options:\n" - "\t-f, --file Path of wf passwd file\n" - "\t-c, --command Command to execute\n" - "\t-u, --username Name of user\n" - "\t-p, --password Password of user\n" - "\t-P, --pepper pepper\n" - "\t-h, --help Shows this message\n" - "\n" - "Commands:\n" - "\tcreate Creates an empty passwd file (or cleans an existing)\n" - "\t Example: webfuse-passwd -f passwd.json -c create\n" - "\tadd Adds or replaces a user\n" - "\t Example: webfuse-passwd -f passwd.json -c add -u bob -p secret\n" - "\tremove Removes a user\n" - "\t Example: webfuse-passwd -f passwd.json -c remove -u bob\n" - "\tcheck Checks password of a user\n" - "\t Example: webfuse-passwd -f passwd.json -c check -u bob -p secret\n" - "\n" - ); -} - -static int parse_args(struct args * args, int argc, char * argv[]) -{ - static struct option const options[] = - { - {"file", required_argument, NULL, 'f'}, - {"command", required_argument, NULL, 'c'}, - {"username", required_argument, NULL, 'u'}, - {"password", required_argument, NULL, 'p'}, - {"Pepper", required_argument, NULL, 'P'}, - {"help", required_argument, NULL, 'h'}, - {NULL, 0, NULL, 0} - }; - - int result = EXIT_SUCCESS; - bool finished = false; - while ((!finished) && (EXIT_SUCCESS == result)) - { - int option_index = 0; - int const c = getopt_long(argc, argv, "f:c:u:p:P:h", options, &option_index); - - switch (c) - { - case -1: - finished = true; - break; - case 'h': - args->show_help = true; - finished = true; - break; - case 'f': - free(args->file); - args->file = strdup(optarg); - break; - case 'c': - free(args->command); - args->command = strdup(optarg); - break; - case 'u': - free(args->username); - args->username = strdup(optarg); - break; - case 'p': - free(args->password); - args->password = strdup(optarg); - break; - case 'P': - free(args->pepper); - args->pepper = strdup(optarg); - break; - default: - fprintf(stderr, "error: unknown argument\n"); - result = EXIT_FAILURE; - break; - } - } - - if ((result == EXIT_SUCCESS) && (!args->show_help)) - { - if (NULL == args->file) - { - fprintf(stderr, "error: missing file\n"); - args->show_help = true; - result = EXIT_FAILURE; - } - else if (NULL == args->command) - { - fprintf(stderr, "error: missing command\n"); - args->show_help = true; - result = EXIT_FAILURE; - } - } - - return result; -} - -static void args_init(struct args * args) -{ - args->file = NULL; - args->command = NULL; - args->username = NULL; - args->password = NULL; - args->pepper = strdup(""); - args->show_help = false; -} - -static int create_passwd(struct args * args) -{ - struct userdb * db = userdb_create(args->pepper); - bool result = userdb_save(db, args->file); - userdb_dispose(db); - - return (result) ? EXIT_SUCCESS : EXIT_FAILURE; -} - -static int add_user(struct args * args) -{ - if (NULL == args->username) - { - fprintf(stderr, "error: missing username"); - args->show_help = true; - return EXIT_FAILURE; - } - - if (NULL == args->password) - { - fprintf(stderr, "error: missing password"); - args->show_help = true; - return EXIT_FAILURE; - } - - struct userdb * db = userdb_create(args->pepper); - userdb_load(db, args->file); - userdb_add(db, args->username, args->password); - bool result = userdb_save(db, args->file); - userdb_dispose(db); - - return (result) ? EXIT_SUCCESS : EXIT_FAILURE; -} - -static int remove_user(struct args * args) -{ - if (NULL == args->username) - { - fprintf(stderr, "error: missing username"); - args->show_help = true; - return EXIT_FAILURE; - } - - struct userdb * db = userdb_create(args->pepper); - userdb_load(db, args->file); - userdb_remove(db, args->username); - bool result = userdb_save(db, args->file); - userdb_dispose(db); - - return (result) ? EXIT_SUCCESS : EXIT_FAILURE; -} - -static int check_password(struct args * args) -{ - if (NULL == args->username) - { - fprintf(stderr, "error: missing username"); - args->show_help = true; - return EXIT_FAILURE; - } - - if (NULL == args->password) - { - fprintf(stderr, "error: missing password"); - args->show_help = true; - return EXIT_FAILURE; - } - - struct userdb * db = userdb_create(args->pepper); - userdb_load(db, args->file); - bool result = userdb_check(db, args->username, args->password); - userdb_dispose(db); - - printf("%s\n", (result) ? "OK" : "FAILURE"); - return (result) ? EXIT_SUCCESS : EXIT_FAILURE; -} - -static int invoke_invalid_command(struct args * args) -{ - (void) args; - - fprintf(stderr, "error: unknown command\n"); - return EXIT_FAILURE; -} - -static struct command const commands[] = -{ - {"create", &create_passwd}, - {"add", &add_user}, - {"remove", &remove_user}, - {"check", &check_password}, - {NULL, NULL} -}; - -static struct command const invalid_command = -{ - "", - &invoke_invalid_command -}; - -static struct command const * get_command(char const * name) -{ - for(size_t i = 0; NULL != commands[i].name; i++) - { - if (0 == strcmp(name, commands[i].name)) - { - return &commands[i]; - } - } - - return &invalid_command; -} - -static void args_cleanup(struct args * args) -{ - free(args->file); - free(args->command); - free(args->username); - free(args->password); - free(args->pepper); -} - -static void openssl_cleanup(void) -{ - FIPS_mode_set(0); - ENGINE_cleanup(); - CONF_modules_unload(1); - EVP_cleanup(); - CRYPTO_cleanup_all_ex_data(); - ERR_free_strings(); -} - -int main(int argc, char * argv[]) -{ - OPENSSL_init(); - OPENSSL_add_all_algorithms_conf(); - - struct args args; - args_init(&args); - int result = parse_args(&args, argc, argv); - if ((EXIT_SUCCESS == result) && (!args.show_help)) - { - struct command const * command = get_command(args.command); - result = command->invoke(&args); - } - - if (args.show_help) - { - print_usage(); - } - - args_cleanup(&args); - openssl_cleanup(); - return result; -} \ No newline at end of file diff --git a/example/provider/main.c b/example/provider/main.c deleted file mode 100644 index 18fe42e..0000000 --- a/example/provider/main.c +++ /dev/null @@ -1,385 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "webfuse_provider.h" - -#define SERVICE_TIMEOUT (1 * 1000) - -struct config -{ - char * url; - struct wfp_client_config * client_config; - bool show_help; -}; - -enum fs_entry_type -{ - FS_FILE, - FS_DIR -}; - -struct fs_entry -{ - ino_t parent; - ino_t inode; - char const * name; - int mode; - enum fs_entry_type type; - size_t content_length; - char const * content; -}; - -struct fs -{ - struct fs_entry const * entries; -}; - -static void show_help() -{ - printf( - "webfuse-provider, Copyright (c) 2019, webfuse authors \n" - "Example for websocket file system provider\n" - "\n" - "Usage: webfuse-provider -u [-k ] [-c ]\n" - "\n" - "Options:\n" - "\t-u, --url URL of webfuse server (required)\n" - "\t-k, --key_path Path to private key of provider (default: not set, TLS disabled)\n" - "\t-c, --cert_path Path to certificate of provider (defautl: not set, TLS disabled)\n" - "\t-h, --help prints this message\n" - "\n" - "Example:\n" - "\twebfuse-provider -u ws://localhost:8080/\n" - "\n" - ); -} - -static int parse_arguments( - int argc, - char* argv[], - struct config * config) -{ - static struct option const options[] = - { - {"url", required_argument, NULL, 'u'}, - {"key_path", required_argument, NULL, 'k'}, - {"cert_path", required_argument, NULL, 'c'}, - {"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0} - }; - - int result = EXIT_SUCCESS; - bool finished = false; - while (!finished) - { - int option_index = 0; - int const c = getopt_long(argc, argv, "u:k:c:h", options, &option_index); - - switch (c) - { - case -1: - finished = true; - break; - case 'h': - config->show_help = true; - finished = true; - break; - case 'u': - free(config->url); - config->url = strdup(optarg); - break; - case 'k': - wfp_client_config_set_keypath(config->client_config, optarg); - break; - case 'c': - wfp_client_config_set_certpath(config->client_config, optarg); - break; - default: - fprintf(stderr, "error: unknown argument\n"); - finished = true; - result = EXIT_FAILURE; - break; - } - - if (NULL == config->url) - { - fprintf(stderr, "error: missing required argument \"-u\"\n"); - result = EXIT_FAILURE; - } - - if (result != EXIT_SUCCESS) - { - config->show_help = true; - } - } - - return result; -} - -static struct fs_entry const * fs_getentry( - struct fs * fs, - ino_t inode) -{ - for (size_t i = 0; 0 != fs->entries[i].inode; i++) - { - struct fs_entry const * entry = &fs->entries[i]; - if (inode == entry->inode) - { - return entry; - } - } - - return NULL; -} - -static struct fs_entry const * fs_getentry_byname( - struct fs * fs, - ino_t parent, - char const * name) -{ - for( size_t i = 0; 0 != fs->entries[i].inode; i++) - { - struct fs_entry const * entry = &fs->entries[i]; - if ((parent == entry->parent) && (0 == strcmp(name, entry->name))) - { - return entry; - } - } - - return NULL; -} - -static void fs_stat( - struct fs_entry const * entry, - struct stat * stat) -{ - memset(stat, 0, sizeof(struct stat)); - - stat->st_ino = entry->inode; - stat->st_mode = entry->mode; - - if (FS_DIR == entry->type) - { - stat->st_mode |= S_IFDIR; - } - - if (FS_FILE == entry->type) - { - stat->st_mode |= S_IFREG; - stat->st_size = entry->content_length; - } -} - -static void fs_lookup( - struct wfp_request * request, - ino_t parent, - char const * name, - void * user_data) -{ - struct fs * fs = (struct fs*) user_data; - struct fs_entry const * entry = fs_getentry_byname(fs, parent, name); - if (NULL != entry) - { - struct stat stat; - fs_stat(entry, &stat); - - wfp_respond_lookup(request, &stat); - } - else - { - wfp_respond_error(request, WF_BAD_NOENTRY); - } -} - - -static void fs_getattr( - struct wfp_request * request, - ino_t inode, - void * user_data) -{ - struct fs * fs = (struct fs*) user_data; - struct fs_entry const * entry = fs_getentry(fs, inode); - - if (NULL != entry) - { - struct stat stat; - fs_stat(entry, &stat); - - wfp_respond_getattr(request, &stat); - } - else - { - wfp_respond_error(request, WF_BAD_NOENTRY); - } -} - -static void fs_readdir( - struct wfp_request * request, - ino_t directory, - void * user_data) -{ - struct fs * fs = (struct fs*) user_data; - - struct fs_entry const * dir = fs_getentry(fs, directory); - if ((NULL != dir) && (FS_DIR == dir->type)) - { - struct wfp_dirbuffer * buffer = wfp_dirbuffer_create(); - wfp_dirbuffer_add(buffer, ".", dir->inode); - wfp_dirbuffer_add(buffer, "..", dir->inode); - - for(size_t i = 0; 0 != fs->entries[i].inode; i++) - { - struct fs_entry const * entry = &fs->entries[i]; - if (directory == entry->parent) - { - wfp_dirbuffer_add(buffer, entry->name, entry->inode); - } - } - - wfp_respond_readdir(request, buffer); - wfp_dirbuffer_dispose(buffer); - } - else - { - wfp_respond_error(request, WF_BAD_NOENTRY); - } -} - -static void fs_open( - struct wfp_request * request, - ino_t inode, - int flags, - void * user_data) -{ - struct fs * fs = (struct fs*) user_data; - - struct fs_entry const * entry = fs_getentry(fs, inode); - if ((NULL != entry) && (FS_FILE == entry->type)) - { - if (O_RDONLY == (flags & O_ACCMODE)) - { - wfp_respond_open(request, 0U); - } - else - { - wfp_respond_error(request, WF_BAD_ACCESS_DENIED); - } - } - else - { - wfp_respond_error(request, WF_BAD_NOENTRY); - } -} - -static size_t min(size_t const a, size_t const b) -{ - return (a < b) ? a : b; -} - -static void fs_read( - struct wfp_request * request, - ino_t inode, - uint32_t handle, - size_t offset, - size_t length, - void * user_data) -{ - (void) handle; - - struct fs * fs = (struct fs*) user_data; - struct fs_entry const * entry = fs_getentry(fs, inode); - if ((NULL != entry) && (FS_FILE == entry->type)) - { - if (entry->content_length > offset) - { - size_t const remaining = entry->content_length - offset; - size_t const count = min(remaining, length); - - wfp_respond_read(request, &entry->content[offset], count); - } - else - { - wfp_respond_error(request, WF_BAD); - } - } - else - { - wfp_respond_error(request, WF_BAD_NOENTRY); - } -} - -static volatile bool shutdown_requested = false; - -static void on_interrupt(int signal_id) -{ - (void) signal_id; - shutdown_requested = true; -} - -int main(int argc, char* argv[]) -{ - struct config config; - config.url = NULL; - config.show_help = false; - config.client_config = wfp_client_config_create(); - int result = parse_arguments(argc, argv, &config); - - if (EXIT_SUCCESS == result) - { - static struct fs_entry const entries[]= - { - {.parent = 0, .inode = 1, .name = "", .mode = 0555, .type = FS_DIR}, - { - .parent = 1, - .inode = 2, - .name = "hello.txt", - .mode = 0444, - .type = FS_FILE, - .content="hello, world!", - .content_length = 13, - }, - {.parent = 0, .inode = 0, .name = NULL} - }; - - struct fs fs = - { - .entries = entries - }; - - signal(SIGINT, &on_interrupt); - - wfp_client_config_set_userdata(config.client_config, &fs); - wfp_client_config_set_onlookup(config.client_config, &fs_lookup); - wfp_client_config_set_ongetattr(config.client_config, &fs_getattr); - wfp_client_config_set_onreaddir(config.client_config, &fs_readdir); - wfp_client_config_set_onopen(config.client_config, &fs_open); - wfp_client_config_set_onread(config.client_config, &fs_read); - - struct wfp_client * client = wfp_client_create(config.client_config); - wfp_client_connect(client, config.url); - - while (!shutdown_requested) - { - wfp_client_service(client, SERVICE_TIMEOUT); - } - - wfp_client_dispose(client); - } - - if (config.show_help) - { - show_help(); - } - - free(config.url); - wfp_client_config_dispose(config.client_config); - return result; -} \ No newline at end of file diff --git a/example/provider/static_filesystem.c b/example/provider/static_filesystem.c deleted file mode 100644 index 631274e..0000000 --- a/example/provider/static_filesystem.c +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include -#include -#include - -#include "webfuse_provider.h" - -#define SERVICE_TIMEOUT (1 * 1000) - -struct args -{ - char const * url; - bool show_help; -}; - -static int -parse_args( - struct args * args, - int argc, - char * argv[]) -{ - int result = EXIT_FAILURE; - args->show_help = true; - args->url = NULL; - - if (2 == argc) - { - result = EXIT_SUCCESS; - - char const * url = argv[1]; - if ((0 != strcmp(url, "-h")) && (0 != strcmp(url, "--help"))) - { - args->show_help = false; - args->url = url; - } - } - else - { - fprintf(stderr, "error: missing argument\n"); - } - - return result; -} - -static volatile bool shutdown_requested = false; - -static void on_interrupt(int signal_id) -{ - (void) signal_id; - shutdown_requested = true; -} - -static void print_usage() -{ - printf( - "static-filesystem-provider Copyright (c) 2019, webfuse authors \n" - "Example of webfuse static filesystem provider\n" - "\n" - "Usage: static-filesystem-provider \n" - "\n" - "Arguments:\n" - "\t URL of webfuse server (required)\n" - "\t-h, --help prints this message\n" - "\n" - "Example:\n" - "\tstatic-filesystem-provider ws://localhost:8080/\n" - "\n" - ); -} - -int main(int argc, char* argv[]) -{ - signal(SIGINT, &on_interrupt); - - struct args args; - int result = parse_args(&args, argc, argv); - if ((EXIT_SUCCESS == result) && (!args.show_help)) - { - struct wfp_client_config * config = wfp_client_config_create(); - - struct wfp_static_filesystem * fs = wfp_static_filesystem_create(config); - wfp_static_filesystem_add_text(fs, "brummni/hello_world.txt", 0444, "Hello, World!\n"); - wfp_static_filesystem_add_text(fs, "brummni/hello_bob.txt", 0444, "Hello, Bob!\n"); - wfp_static_filesystem_add_text(fs, "brummni/hello_bob.txt", 0444, "Hello, Alice!\n"); - wfp_static_filesystem_add_text(fs, "bla/hello_world.txt", 0444, "Hello, World!\n"); - wfp_static_filesystem_add_text(fs, "foo.txt", 0444, "foo\n"); - wfp_static_filesystem_add_text(fs, "bar.txt", 0444, "bar\n"); - - struct wfp_client * client = wfp_client_create(config); - wfp_client_connect(client, args.url); - - while (!shutdown_requested) - { - wfp_client_service(client, SERVICE_TIMEOUT); - } - - wfp_client_dispose(client); - wfp_static_filesystem_dispose(fs); - wfp_client_config_dispose(config); - } - - if (args.show_help) - { - print_usage(); - } - - return result; -} From 0d0a070267acad638e48f7c39940a022ccd8d9e1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 10 Feb 2020 15:40:04 +0100 Subject: [PATCH 029/138] chore: removed WITHOUT_TEST option --- CMakeLists.txt | 1 - README.md | 12 ++++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48df128..504ef4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required (VERSION 3.10) project(webfuse VERSION 0.2.0 DESCRIPTION "Websocket filesystem based on libfuse") option(WITHOUT_TESTS "disable unit tests" OFF) -option(WITHOUT_EXAMPLE "disable example" OFF) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(coverage) diff --git a/README.md b/README.md index 716e079..7ea0d16 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ webfuse combines libwebsockets and libfuse. It allows ot attach a remote filesys - [Concept](#Concept) - [Similar Projects](#Similar-Projects) - [API](#API) -- [Build and run](#Build-and-run) +- [Build](#Build) - [Dependencies](#Dependencies) ## Motivation @@ -384,7 +384,7 @@ The authenticator type **username** is used to authenticate via username and pas **Note** that no further encryption is done, so this authenticator type should not be used over unencrypted websocket connections. -## Build and run +## Build To install dependencies, see below. @@ -392,19 +392,15 @@ To install dependencies, see below. mkdir .build cd .build cmake .. - mkdir test - ./webfused -m test --document_root=../exmaple/daemon/www --port=4711 + make ### Build options -By default, unit tests and example application are enabled. You can disable them using the following cmake options: +By default, unit tests are enabled. You can disable them using the following cmake options: - **WITHOUT_TESTS**: disable tests `cmake -DWITHOUT_TESTS=ON ..` -- **WITHOUT_EXAMPLE**: disable example - `cmake -DWITHOUD_EXAMPLE=ON ..` - ## Dependencies - [libfuse3](https://github.com/libfuse/libfuse/) From 39129bc4bafcc473485e4ebd54024151dfe56bcc Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 10 Feb 2020 16:58:04 +0100 Subject: [PATCH 030/138] feature: adapter and provider libraries can be build separately --- CMakeLists.txt | 82 ++++++++++++++++++++++++++++++++++++++------------ README.md | 10 ++++++ 2 files changed, 72 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 504ef4c..70ef8cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,9 @@ cmake_minimum_required (VERSION 3.10) project(webfuse VERSION 0.2.0 DESCRIPTION "Websocket filesystem based on libfuse") -option(WITHOUT_TESTS "disable unit tests" OFF) +option(WITHOUT_TESTS "disable unit tests" OFF) +option(WITHOUT_ADAPTER "disable adapter library" OFF) +option(WITHOUT_PROVIDER "disable provider library" OFF) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(coverage) @@ -10,10 +12,8 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) -pkg_check_modules(FUSE3 REQUIRED fuse3) pkg_check_modules(LWS REQUIRED libwebsockets) pkg_check_modules(JANSSON REQUIRED jansson) -pkg_check_modules(UUID REQUIRED uuid) add_definitions(-D_FILE_OFFSET_BITS=64) @@ -26,27 +26,14 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) include_directories( "include" - ${FUSE3_INCLUDE_DIRS} ${LWS_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} -) - -set(EXTRA_LIBS - ${EXTRA_LIBS} - ${FUSE3_LIBRARIES} - ${LWS_LIBRARIES} - ${JANSSON_LIBRARIES} - ${UUID_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} ) add_compile_options( ${C_WARNINGS} - ${FUSE3_CFLAGS_OTHER} ${LWS_CFLAGS_OTHER} ${JANSSON_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} "-pthread" ) @@ -72,6 +59,11 @@ install(DIRECTORY include/webfuse/core DESTINATION include/webfuse) # libwebfuse-adapter +if(NOT WITHOUT_ADAPTER) + +pkg_check_modules(FUSE3 REQUIRED fuse3) +pkg_check_modules(UUID REQUIRED uuid) + add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/api.c lib/webfuse/adapter/impl/filesystem.c @@ -101,14 +93,35 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/jsonrpc/util.c ) +target_include_directories(webfuse-adapter-static PRIVATE + lib + ${FUSE3_INCLUDE_DIRS} + ${UUID_INCLUDE_DIRS} +) + +target_compile_options(webfuse-adapter-static PUBLIC + ${FUSE3_CFLAGS_OTHER} + ${UUID_CFLAGS_OTHER} +) + set_target_properties(webfuse-adapter-static PROPERTIES OUTPUT_NAME webfuse-adapter) set_target_properties(webfuse-adapter-static PROPERTIES C_VISIBILITY_PRESET hidden) -target_include_directories(webfuse-adapter-static PUBLIC lib) add_library(webfuse-adapter SHARED lib/webfuse/adapter/api.c ) +target_include_directories(webfuse-adapter PRIVATE + ${FUSE3_INCLUDE_DIRS} + ${UUID_INCLUDE_DIRS} +) + +target_compile_options(webfuse-adapter PUBLIC + ${FUSE3_CFLAGS_OTHER} + ${UUID_CFLAGS_OTHER} +) + + set_target_properties(webfuse-adapter PROPERTIES VERSION ${PROJECT_VERSION}) set_target_properties(webfuse-adapter PROPERTIES SOVERSION 0) set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden) @@ -135,8 +148,13 @@ install(FILES include/webfuse_adapter.h DESTINATION include) install(DIRECTORY include/webfuse/adapter DESTINATION include/webfuse) install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) +endif(NOT WITHOUT_ADAPTER) + + #libwebfuse-provider +if(NOT WITHOUT_PROVIDER) + add_library(webfuse-provider-static STATIC lib/webfuse/provider/api.c lib/webfuse/provider/impl/url.c @@ -189,9 +207,11 @@ install(FILES include/webfuse_provider.h DESTINATION include) install(DIRECTORY include/webfuse/provider DESTINATION include/webfuse) install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) +endif(NOT WITHOUT_PROVIDER) + # tests -if(NOT WITHOUT_TESTS) +if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) include (CTest) @@ -234,7 +254,29 @@ add_executable(alltests test/integration/provider.cc ) -target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES}) +target_include_directories(alltests PRIVATE + ${FUSE3_INCLUDE_DIRS} + ${UUID_INCLUDE_DIRS} +) + +target_compile_options(alltests PUBLIC + ${FUSE3_CFLAGS_OTHER} + ${UUID_CFLAGS_OTHER} +) + +target_link_libraries(alltests PUBLIC + webfuse-adapter-static + webfuse-provider-static + webfuse-core + ${FUSE3_LIBRARIES} + ${LWS_LIBRARIES} + ${JANSSON_LIBRARIES} + ${UUID_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${GMOCK_LIBRARIES} + ${GTEST_LIBRARIES} +) + target_include_directories(alltests PUBLIC test lib ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) target_compile_options(alltests PUBLIC ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) @@ -255,4 +297,4 @@ add_custom_target(coverage-report ) add_dependencies(coverage-report coverage) -endif(NOT WITHOUT_TESTS) +endif(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) diff --git a/README.md b/README.md index 7ea0d16..d2cf16f 100644 --- a/README.md +++ b/README.md @@ -401,6 +401,16 @@ By default, unit tests are enabled. You can disable them using the following cma - **WITHOUT_TESTS**: disable tests `cmake -DWITHOUT_TESTS=ON ..` +Since webfuse consists of two libraries, it is possible to disable one of them +in order to reduce build dependencies. +*Note that unit tests are only available, when both libraries are built.* + +- **WITHOUT_ADAPTER**: omit adapter library + `cmake -DWITHOUT_ADAPTER=ON` + +- **WIHTOU_PROVIDER**: omit provider library + `cmake -DWITHOUT_PROVIDER=ON` + ## Dependencies - [libfuse3](https://github.com/libfuse/libfuse/) From 47eec1c9e145118e2fd2cd3189124d23c01b9225 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 10 Feb 2020 17:35:27 +0100 Subject: [PATCH 031/138] chore: split monolithic CMakeLists.txt into separate parts --- CMakeLists.txt | 265 +---------------------------------- cmake/unit_tests.cmake | 87 ++++++++++++ cmake/webfuse_adapter.cmake | 90 ++++++++++++ cmake/webfuse_core.cmake | 18 +++ cmake/webfuse_provider.cmake | 55 ++++++++ 5 files changed, 254 insertions(+), 261 deletions(-) create mode 100644 cmake/unit_tests.cmake create mode 100644 cmake/webfuse_adapter.cmake create mode 100644 cmake/webfuse_core.cmake create mode 100644 cmake/webfuse_provider.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 70ef8cb..f346e9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,264 +37,7 @@ add_compile_options( "-pthread" ) -# libwebfuse-core - -add_library(webfuse-core STATIC - lib/webfuse/core/slist.c - lib/webfuse/core/message.c - lib/webfuse/core/message_queue.c - lib/webfuse/core/status.c - lib/webfuse/core/string.c - lib/webfuse/core/path.c - lib/webfuse/core/base64.c - lib/webfuse/core/lws_log.c -) - -set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) -target_include_directories(webfuse-core PUBLIC lib) -set_target_properties(webfuse-core PROPERTIES C_VISIBILITY_PRESET hidden) - -install(DIRECTORY include/webfuse/core DESTINATION include/webfuse) - - -# libwebfuse-adapter - -if(NOT WITHOUT_ADAPTER) - -pkg_check_modules(FUSE3 REQUIRED fuse3) -pkg_check_modules(UUID REQUIRED uuid) - -add_library(webfuse-adapter-static STATIC - lib/webfuse/adapter/api.c - lib/webfuse/adapter/impl/filesystem.c - lib/webfuse/adapter/impl/server.c - lib/webfuse/adapter/impl/server_config.c - lib/webfuse/adapter/impl/server_protocol.c - lib/webfuse/adapter/impl/session.c - lib/webfuse/adapter/impl/session_manager.c - lib/webfuse/adapter/impl/authenticator.c - lib/webfuse/adapter/impl/authenticators.c - lib/webfuse/adapter/impl/credentials.c - lib/webfuse/adapter/impl/operations.c - lib/webfuse/adapter/impl/time/timepoint.c - lib/webfuse/adapter/impl/time/timer.c - lib/webfuse/adapter/impl/time/timeout_manager.c - lib/webfuse/adapter/impl/operation/lookup.c - lib/webfuse/adapter/impl/operation/getattr.c - lib/webfuse/adapter/impl/operation/readdir.c - lib/webfuse/adapter/impl/operation/open.c - lib/webfuse/adapter/impl/operation/close.c - lib/webfuse/adapter/impl/operation/read.c - lib/webfuse/adapter/impl/jsonrpc/proxy.c - lib/webfuse/adapter/impl/jsonrpc/server.c - lib/webfuse/adapter/impl/jsonrpc/method.c - lib/webfuse/adapter/impl/jsonrpc/request.c - lib/webfuse/adapter/impl/jsonrpc/response.c - lib/webfuse/adapter/impl/jsonrpc/util.c -) - -target_include_directories(webfuse-adapter-static PRIVATE - lib - ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} -) - -target_compile_options(webfuse-adapter-static PUBLIC - ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} -) - -set_target_properties(webfuse-adapter-static PROPERTIES OUTPUT_NAME webfuse-adapter) -set_target_properties(webfuse-adapter-static PROPERTIES C_VISIBILITY_PRESET hidden) - -add_library(webfuse-adapter SHARED - lib/webfuse/adapter/api.c -) - -target_include_directories(webfuse-adapter PRIVATE - ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} -) - -target_compile_options(webfuse-adapter PUBLIC - ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} -) - - -set_target_properties(webfuse-adapter PROPERTIES VERSION ${PROJECT_VERSION}) -set_target_properties(webfuse-adapter PROPERTIES SOVERSION 0) -set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden) -set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT") - -target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core) - -file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" -"prefix=\"${CMAKE_INSTALL_PREFIX}\" - -exec_prefix=\${prefix} -libdir=\${exec_prefix}/lib${LIB_SUFFIX} -includedir=\${prefix}/include -Name: libwebfuse -Description: Websockets filesystem server library -Version: ${PROJECT_VERSION} - -Libs: -L\${libdir} -lwebfuse-adapter -l${FUSE3_LIBRARIES} -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} -Cflags: -I\${includedir}" -) - -install(TARGETS webfuse-adapter DESTINATION lib${LIB_SUFFIX}) -install(FILES include/webfuse_adapter.h DESTINATION include) -install(DIRECTORY include/webfuse/adapter DESTINATION include/webfuse) -install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) - -endif(NOT WITHOUT_ADAPTER) - - -#libwebfuse-provider - -if(NOT WITHOUT_PROVIDER) - -add_library(webfuse-provider-static STATIC - lib/webfuse/provider/api.c - lib/webfuse/provider/impl/url.c - lib/webfuse/provider/impl/client.c - lib/webfuse/provider/impl/client_config.c - lib/webfuse/provider/impl/client_protocol.c - lib/webfuse/provider/impl/provider.c - lib/webfuse/provider/impl/request.c - lib/webfuse/provider/impl/dirbuffer.c - lib/webfuse/provider/impl/operation/lookup.c - lib/webfuse/provider/impl/operation/getattr.c - lib/webfuse/provider/impl/operation/readdir.c - lib/webfuse/provider/impl/operation/open.c - lib/webfuse/provider/impl/operation/close.c - lib/webfuse/provider/impl/operation/read.c - lib/webfuse/provider/impl/static_filesystem.c -) - -set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider) -set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden) -target_include_directories(webfuse-provider-static PUBLIC lib) - -add_library(webfuse-provider SHARED - lib/webfuse/provider/api.c -) - -set_target_properties(webfuse-provider PROPERTIES VERSION ${PROJECT_VERSION}) -set_target_properties(webfuse-provider PROPERTIES SOVERSION 0) -set_target_properties(webfuse-provider PROPERTIES C_VISIBILITY_PRESET hidden) -set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT") - -target_include_directories(webfuse-provider PUBLIC lib) -target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core) - -file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" -"prefix=\"${CMAKE_INSTALL_PREFIX}\" -exec_prefix=\${prefix} -libdir=\${exec_prefix}/lib${LIB_SUFFIX} -includedir=\${prefix}/include -Name: libwebfuse-provider -Description: Provider library for websockets filesystem -Version: ${PROJECT_VERSION} - -Libs: -L\${libdir} -lwebfuse-provider -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} -Cflags: -I\${includedir}" -) - -install(TARGETS webfuse-provider DESTINATION lib${LIB_SUFFIX}) -install(FILES include/webfuse_provider.h DESTINATION include) -install(DIRECTORY include/webfuse/provider DESTINATION include/webfuse) -install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) - -endif(NOT WITHOUT_PROVIDER) - -# tests - -if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) - -include (CTest) - -pkg_check_modules(GTEST gtest_main) -include(GoogleTest) -pkg_check_modules(GMOCK gmock) - -add_executable(alltests - test/msleep.cc - test/die_if.cc - test/mock_authenticator.cc - test/mock_request.cc - test/core/test_container_of.cc - test/core/test_string.cc - test/core/test_slist.cc - test/core/test_path.cc - test/core/test_base64.cc - test/core/test_status.cc - test/core/test_message.cc - test/core/test_message_queue.cc - test/adapter/test_response_parser.cc - test/adapter/test_server.cc - test/adapter/test_timepoint.cc - test/adapter/test_timer.cc - test/adapter/test_credentials.cc - test/adapter/test_authenticator.cc - test/adapter/test_authenticators.cc - test/adapter/test_fuse_req.cc - test/adapter/jsonrpc/test_util.cc - test/adapter/jsonrpc/test_is_request.cc - test/adapter/jsonrpc/test_request.cc - test/adapter/jsonrpc/test_is_response.cc - test/adapter/jsonrpc/test_response.cc - test/adapter/jsonrpc/test_server.cc - test/adapter/jsonrpc/test_proxy.cc - test/provider/test_url.cc - test/provider/test_static_filesystem.cc - test/integration/test_integration.cc - test/integration/server.cc - test/integration/provider.cc -) - -target_include_directories(alltests PRIVATE - ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} -) - -target_compile_options(alltests PUBLIC - ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} -) - -target_link_libraries(alltests PUBLIC - webfuse-adapter-static - webfuse-provider-static - webfuse-core - ${FUSE3_LIBRARIES} - ${LWS_LIBRARIES} - ${JANSSON_LIBRARIES} - ${UUID_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - ${GMOCK_LIBRARIES} - ${GTEST_LIBRARIES} -) - -target_include_directories(alltests PUBLIC test lib ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) -target_compile_options(alltests PUBLIC ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) - -enable_testing() -gtest_discover_tests(alltests TEST_PREFIX alltests:) - -add_custom_target(coverage - ./alltests - COMMAND mkdir -p coverage - COMMAND lcov --capture --directory . --output-file coverage/lcov.info - COMMAND lcov --remove coverage/lcov.info '/usr/*' --output-file coverage/lcov.info - COMMAND lcov --remove coverage/lcov.info '*/test/*' --output-file coverage/lcov.info -) -add_dependencies(coverage alltests) - -add_custom_target(coverage-report - COMMAND genhtml coverage/lcov.info --output-directory coverage/report -) -add_dependencies(coverage-report coverage) - -endif(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) +include(webfuse_core) +include(webfuse_adapter) +include(webfuse_provider) +include(unit_tests) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake new file mode 100644 index 0000000..5af183a --- /dev/null +++ b/cmake/unit_tests.cmake @@ -0,0 +1,87 @@ +if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) + +include (CTest) + +pkg_check_modules(GTEST gtest_main) +include(GoogleTest) +pkg_check_modules(GMOCK gmock) + +add_executable(alltests + test/msleep.cc + test/die_if.cc + test/mock_authenticator.cc + test/mock_request.cc + test/core/test_container_of.cc + test/core/test_string.cc + test/core/test_slist.cc + test/core/test_path.cc + test/core/test_base64.cc + test/core/test_status.cc + test/core/test_message.cc + test/core/test_message_queue.cc + test/adapter/test_response_parser.cc + test/adapter/test_server.cc + test/adapter/test_timepoint.cc + test/adapter/test_timer.cc + test/adapter/test_credentials.cc + test/adapter/test_authenticator.cc + test/adapter/test_authenticators.cc + test/adapter/test_fuse_req.cc + test/adapter/jsonrpc/test_util.cc + test/adapter/jsonrpc/test_is_request.cc + test/adapter/jsonrpc/test_request.cc + test/adapter/jsonrpc/test_is_response.cc + test/adapter/jsonrpc/test_response.cc + test/adapter/jsonrpc/test_server.cc + test/adapter/jsonrpc/test_proxy.cc + test/provider/test_url.cc + test/provider/test_static_filesystem.cc + test/integration/test_integration.cc + test/integration/server.cc + test/integration/provider.cc +) + +target_include_directories(alltests PRIVATE + ${FUSE3_INCLUDE_DIRS} + ${UUID_INCLUDE_DIRS} +) + +target_compile_options(alltests PUBLIC + ${FUSE3_CFLAGS_OTHER} + ${UUID_CFLAGS_OTHER} +) + +target_link_libraries(alltests PUBLIC + webfuse-adapter-static + webfuse-provider-static + webfuse-core + ${FUSE3_LIBRARIES} + ${LWS_LIBRARIES} + ${JANSSON_LIBRARIES} + ${UUID_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${GMOCK_LIBRARIES} + ${GTEST_LIBRARIES} +) + +target_include_directories(alltests PUBLIC test lib ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) +target_compile_options(alltests PUBLIC ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) + +enable_testing() +gtest_discover_tests(alltests TEST_PREFIX alltests:) + +add_custom_target(coverage + ./alltests + COMMAND mkdir -p coverage + COMMAND lcov --capture --directory . --output-file coverage/lcov.info + COMMAND lcov --remove coverage/lcov.info '/usr/*' --output-file coverage/lcov.info + COMMAND lcov --remove coverage/lcov.info '*/test/*' --output-file coverage/lcov.info +) +add_dependencies(coverage alltests) + +add_custom_target(coverage-report + COMMAND genhtml coverage/lcov.info --output-directory coverage/report +) +add_dependencies(coverage-report coverage) + +endif(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake new file mode 100644 index 0000000..710c7a6 --- /dev/null +++ b/cmake/webfuse_adapter.cmake @@ -0,0 +1,90 @@ +if(NOT WITHOUT_ADAPTER) + +pkg_check_modules(FUSE3 REQUIRED fuse3) +pkg_check_modules(UUID REQUIRED uuid) + +add_library(webfuse-adapter-static STATIC + lib/webfuse/adapter/api.c + lib/webfuse/adapter/impl/filesystem.c + lib/webfuse/adapter/impl/server.c + lib/webfuse/adapter/impl/server_config.c + lib/webfuse/adapter/impl/server_protocol.c + lib/webfuse/adapter/impl/session.c + lib/webfuse/adapter/impl/session_manager.c + lib/webfuse/adapter/impl/authenticator.c + lib/webfuse/adapter/impl/authenticators.c + lib/webfuse/adapter/impl/credentials.c + lib/webfuse/adapter/impl/operations.c + lib/webfuse/adapter/impl/time/timepoint.c + lib/webfuse/adapter/impl/time/timer.c + lib/webfuse/adapter/impl/time/timeout_manager.c + lib/webfuse/adapter/impl/operation/lookup.c + lib/webfuse/adapter/impl/operation/getattr.c + lib/webfuse/adapter/impl/operation/readdir.c + lib/webfuse/adapter/impl/operation/open.c + lib/webfuse/adapter/impl/operation/close.c + lib/webfuse/adapter/impl/operation/read.c + lib/webfuse/adapter/impl/jsonrpc/proxy.c + lib/webfuse/adapter/impl/jsonrpc/server.c + lib/webfuse/adapter/impl/jsonrpc/method.c + lib/webfuse/adapter/impl/jsonrpc/request.c + lib/webfuse/adapter/impl/jsonrpc/response.c + lib/webfuse/adapter/impl/jsonrpc/util.c +) + +target_include_directories(webfuse-adapter-static PRIVATE + lib + ${FUSE3_INCLUDE_DIRS} + ${UUID_INCLUDE_DIRS} +) + +target_compile_options(webfuse-adapter-static PUBLIC + ${FUSE3_CFLAGS_OTHER} + ${UUID_CFLAGS_OTHER} +) + +set_target_properties(webfuse-adapter-static PROPERTIES OUTPUT_NAME webfuse-adapter) +set_target_properties(webfuse-adapter-static PROPERTIES C_VISIBILITY_PRESET hidden) + +add_library(webfuse-adapter SHARED + lib/webfuse/adapter/api.c +) + +target_include_directories(webfuse-adapter PRIVATE + ${FUSE3_INCLUDE_DIRS} + ${UUID_INCLUDE_DIRS} +) + +target_compile_options(webfuse-adapter PUBLIC + ${FUSE3_CFLAGS_OTHER} + ${UUID_CFLAGS_OTHER} +) + + +set_target_properties(webfuse-adapter PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(webfuse-adapter PROPERTIES SOVERSION 0) +set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden) +set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT") + +target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core) + +file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" +"prefix=\"${CMAKE_INSTALL_PREFIX}\" + +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib${LIB_SUFFIX} +includedir=\${prefix}/include +Name: libwebfuse +Description: Websockets filesystem server library +Version: ${PROJECT_VERSION} + +Libs: -L\${libdir} -lwebfuse-adapter -l${FUSE3_LIBRARIES} -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} +Cflags: -I\${includedir}" +) + +install(TARGETS webfuse-adapter DESTINATION lib${LIB_SUFFIX}) +install(FILES include/webfuse_adapter.h DESTINATION include) +install(DIRECTORY include/webfuse/adapter DESTINATION include/webfuse) +install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) + +endif(NOT WITHOUT_ADAPTER) diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake new file mode 100644 index 0000000..9af4b2b --- /dev/null +++ b/cmake/webfuse_core.cmake @@ -0,0 +1,18 @@ +# libwebfuse-core + +add_library(webfuse-core STATIC + lib/webfuse/core/slist.c + lib/webfuse/core/message.c + lib/webfuse/core/message_queue.c + lib/webfuse/core/status.c + lib/webfuse/core/string.c + lib/webfuse/core/path.c + lib/webfuse/core/base64.c + lib/webfuse/core/lws_log.c +) + +set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) +target_include_directories(webfuse-core PUBLIC lib) +set_target_properties(webfuse-core PROPERTIES C_VISIBILITY_PRESET hidden) + +install(DIRECTORY include/webfuse/core DESTINATION include/webfuse) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake new file mode 100644 index 0000000..efbae88 --- /dev/null +++ b/cmake/webfuse_provider.cmake @@ -0,0 +1,55 @@ +if(NOT WITHOUT_PROVIDER) + +add_library(webfuse-provider-static STATIC + lib/webfuse/provider/api.c + lib/webfuse/provider/impl/url.c + lib/webfuse/provider/impl/client.c + lib/webfuse/provider/impl/client_config.c + lib/webfuse/provider/impl/client_protocol.c + lib/webfuse/provider/impl/provider.c + lib/webfuse/provider/impl/request.c + lib/webfuse/provider/impl/dirbuffer.c + lib/webfuse/provider/impl/operation/lookup.c + lib/webfuse/provider/impl/operation/getattr.c + lib/webfuse/provider/impl/operation/readdir.c + lib/webfuse/provider/impl/operation/open.c + lib/webfuse/provider/impl/operation/close.c + lib/webfuse/provider/impl/operation/read.c + lib/webfuse/provider/impl/static_filesystem.c +) + +set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider) +set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden) +target_include_directories(webfuse-provider-static PUBLIC lib) + +add_library(webfuse-provider SHARED + lib/webfuse/provider/api.c +) + +set_target_properties(webfuse-provider PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(webfuse-provider PROPERTIES SOVERSION 0) +set_target_properties(webfuse-provider PROPERTIES C_VISIBILITY_PRESET hidden) +set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT") + +target_include_directories(webfuse-provider PUBLIC lib) +target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core) + +file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" +"prefix=\"${CMAKE_INSTALL_PREFIX}\" +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib${LIB_SUFFIX} +includedir=\${prefix}/include +Name: libwebfuse-provider +Description: Provider library for websockets filesystem +Version: ${PROJECT_VERSION} + +Libs: -L\${libdir} -lwebfuse-provider -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} +Cflags: -I\${includedir}" +) + +install(TARGETS webfuse-provider DESTINATION lib${LIB_SUFFIX}) +install(FILES include/webfuse_provider.h DESTINATION include) +install(DIRECTORY include/webfuse/provider DESTINATION include/webfuse) +install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) + +endif(NOT WITHOUT_PROVIDER) From 8ef90fb50497ad513a4a04aa0e386f7756b51291 Mon Sep 17 00:00:00 2001 From: Falk Werner <47070255+falk-werner@users.noreply.github.com> Date: Tue, 11 Feb 2020 22:23:51 +0100 Subject: [PATCH 032/138] feature: create debian and source packages (#44) Added cpack to create debian and source packages. There are 3 packages: webfuse-VERSION-Source.tar.gz: packaged sources webfuse_VERSION_ARCH.deb: install webfuse libraries webfuse-dev_VERSION_ARCH.deb: install headers, depends on libraries --- CMakeLists.txt | 20 ++++++++++++++++++++ cmake/webfuse_adapter.cmake | 9 +++++---- cmake/webfuse_core.cmake | 2 +- cmake/webfuse_provider.cmake | 9 +++++---- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f346e9d..3b77e46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,3 +41,23 @@ include(webfuse_core) include(webfuse_adapter) include(webfuse_provider) include(unit_tests) + +set(CPACK_SOURCE_GENERATOR "TGZ") +set(CPACK_GENERATOR "DEB") +set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") +set(CPACK_DESCRIPTION "Websocket filesystem based on libfuse") +#set(CPACK_COMPONENTS_ALL libraries) +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Falk Werner") +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) + +set(CPACK_DEBIAN_LIBRARIES_FILE_NAME "webfuse_${PROJECT_VERSION}_${CMAKE_SYSTEM_NAME}.deb") +set(CPACK_DEBIAN_LIBRARIES_PACKAGE_NAME "webfuse") + +set(CPACK_DEBIAN_HEADERS_FILE_NAME "webfuse-dev_${PROJECT_VERSION}_${CMAKE_SYSTEM_NAME}.deb") +set(CPACK_DEBIAN_HEADERS_PACKAGE_NAME "webfuse-dev") +set(CPACK_DEBIAN_HEADERS_PACKAGE_DEPENDS "webfuse") + +include(CPack) \ No newline at end of file diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index 710c7a6..329a123 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -82,9 +82,10 @@ Libs: -L\${libdir} -lwebfuse-adapter -l${FUSE3_LIBRARIES} -l${LWS_LIBRARIES} -l$ Cflags: -I\${includedir}" ) -install(TARGETS webfuse-adapter DESTINATION lib${LIB_SUFFIX}) -install(FILES include/webfuse_adapter.h DESTINATION include) -install(DIRECTORY include/webfuse/adapter DESTINATION include/webfuse) -install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) +install(TARGETS webfuse-adapter DESTINATION lib${LIB_SUFFIX} COMPONENT libraries) +install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig COMPONENT libraries) + +install(FILES include/webfuse_adapter.h DESTINATION include COMPONENT headers) +install(DIRECTORY include/webfuse/adapter DESTINATION include/webfuse COMPONENT headers) endif(NOT WITHOUT_ADAPTER) diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 9af4b2b..b162f40 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -15,4 +15,4 @@ set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) target_include_directories(webfuse-core PUBLIC lib) set_target_properties(webfuse-core PROPERTIES C_VISIBILITY_PRESET hidden) -install(DIRECTORY include/webfuse/core DESTINATION include/webfuse) +install(DIRECTORY include/webfuse/core DESTINATION include/webfuse COMPONENT headers) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index efbae88..b42f1f4 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -47,9 +47,10 @@ Libs: -L\${libdir} -lwebfuse-provider -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} Cflags: -I\${includedir}" ) -install(TARGETS webfuse-provider DESTINATION lib${LIB_SUFFIX}) -install(FILES include/webfuse_provider.h DESTINATION include) -install(DIRECTORY include/webfuse/provider DESTINATION include/webfuse) -install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) +install(TARGETS webfuse-provider DESTINATION lib${LIB_SUFFIX} COMPONENT libraries) +install(FILES "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig COMPONENT libraries) + +install(FILES include/webfuse_provider.h DESTINATION include COMPONENT headers) +install(DIRECTORY include/webfuse/provider DESTINATION include/webfuse COMPONENT headers) endif(NOT WITHOUT_PROVIDER) From 16705acf810d33739795055c7876f6d55d685578 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 13 Feb 2020 21:48:42 +0100 Subject: [PATCH 033/138] added mountpoint factory interface --- include/webfuse/adapter/mountpoint.h | 28 ++++++++++++++++++++ include/webfuse/adapter/mountpoint_factory.h | 24 +++++++++++++++++ include/webfuse/adapter/server_config.h | 7 ++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 include/webfuse/adapter/mountpoint.h create mode 100644 include/webfuse/adapter/mountpoint_factory.h diff --git a/include/webfuse/adapter/mountpoint.h b/include/webfuse/adapter/mountpoint.h new file mode 100644 index 0000000..9b1d57f --- /dev/null +++ b/include/webfuse/adapter/mountpoint.h @@ -0,0 +1,28 @@ +#ifndef WF_ADAPTER_MOUNTPOINT_H +#define WF_ADAPTER_MOUNTPOINT_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_mountpoint; + +extern struct wf_mountpoint * +wf_mountpoint_create( + char const * path); + +extern void +wf_mountpoint_release( + struct wf_mountpoint * mountpoint); + +extern char const * +wf_mountpoint_get_path( + struct wf_mountpoint const * mountpoint); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/webfuse/adapter/mountpoint_factory.h b/include/webfuse/adapter/mountpoint_factory.h new file mode 100644 index 0000000..a265c6f --- /dev/null +++ b/include/webfuse/adapter/mountpoint_factory.h @@ -0,0 +1,24 @@ +#ifndef WF_ADAPTER_MOUNTPOINT_FACTORY_H +#define WF_ADAPTER_MOUNTPOINT_FACTORY_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_mountpoint; + +typedef struct wf_mountpoint * +wf_create_mountpoint_fn( + char const * filesystem, + void * user_data); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/webfuse/adapter/server_config.h b/include/webfuse/adapter/server_config.h index cc1b6d3..778cc8c 100644 --- a/include/webfuse/adapter/server_config.h +++ b/include/webfuse/adapter/server_config.h @@ -3,6 +3,7 @@ #include "webfuse/adapter/api.h" #include "webfuse/adapter/authenticate.h" +#include "webfuse/adapter/mountpoint_factory.h" #ifdef __cplusplus extern "C" @@ -16,11 +17,15 @@ extern WF_API struct wf_server_config * wf_server_config_create(void); extern WF_API void wf_server_config_dispose( struct wf_server_config * config); - extern WF_API void wf_server_config_set_mountpoint( struct wf_server_config * config, char const * mount_point); +extern WF_API void wf_server_config_set_mountpoint_factory( + struct wf_server_config * config, + wf_create_mountpoint_fn * create_mountpoint, + void * user_data); + extern WF_API void wf_server_config_set_documentroot( struct wf_server_config * config, char const * document_root); From e727a9a54d3505f911aee201cc3da0c545e7185a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 15 Feb 2020 15:11:35 +0100 Subject: [PATCH 034/138] added implementation of mountpoint --- cmake/unit_tests.cmake | 1 + cmake/webfuse_adapter.cmake | 1 + include/webfuse/adapter/mountpoint.h | 2 +- include/webfuse_adapter.h | 1 + lib/webfuse/adapter/api.c | 24 +++++++++++++++++++ lib/webfuse/adapter/impl/mountpoint.c | 34 +++++++++++++++++++++++++++ lib/webfuse/adapter/impl/mountpoint.h | 26 ++++++++++++++++++++ test/adapter/test_mountpoint.cc | 12 ++++++++++ 8 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 lib/webfuse/adapter/impl/mountpoint.c create mode 100644 lib/webfuse/adapter/impl/mountpoint.h create mode 100644 test/adapter/test_mountpoint.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 5af183a..b5ae7ad 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -26,6 +26,7 @@ add_executable(alltests test/adapter/test_credentials.cc test/adapter/test_authenticator.cc test/adapter/test_authenticators.cc + test/adapter/test_mountpoint.cc test/adapter/test_fuse_req.cc test/adapter/jsonrpc/test_util.cc test/adapter/jsonrpc/test_is_request.cc diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index 329a123..f970ef7 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -15,6 +15,7 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/authenticators.c lib/webfuse/adapter/impl/credentials.c lib/webfuse/adapter/impl/operations.c + lib/webfuse/adapter/impl/mountpoint.c lib/webfuse/adapter/impl/time/timepoint.c lib/webfuse/adapter/impl/time/timer.c lib/webfuse/adapter/impl/time/timeout_manager.c diff --git a/include/webfuse/adapter/mountpoint.h b/include/webfuse/adapter/mountpoint.h index 9b1d57f..0dba1cd 100644 --- a/include/webfuse/adapter/mountpoint.h +++ b/include/webfuse/adapter/mountpoint.h @@ -13,7 +13,7 @@ wf_mountpoint_create( char const * path); extern void -wf_mountpoint_release( +wf_mountpoint_dispose( struct wf_mountpoint * mountpoint); extern char const * diff --git a/include/webfuse_adapter.h b/include/webfuse_adapter.h index 8edad51..37c39c2 100644 --- a/include/webfuse_adapter.h +++ b/include/webfuse_adapter.h @@ -9,5 +9,6 @@ #include #include #include +#include #endif diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index af68a8e..370a55e 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -4,6 +4,7 @@ #include "webfuse/adapter/impl/server_protocol.h" #include "webfuse/adapter/impl/server_config.h" #include "webfuse/adapter/impl/credentials.h" +#include "webfuse/adapter/impl/mountpoint.h" // server @@ -134,3 +135,26 @@ char const * wf_credentials_get( { return wf_impl_credentials_get(credentials, key); } + +// mountpoint + +struct wf_mountpoint * +wf_mountpoint_create( + char const * path) +{ + return wf_impl_mountpoint_create(path); +} + +void +wf_mountpoint_dispose( + struct wf_mountpoint * mountpoint) +{ + wf_impl_mountpoint_dispose(mountpoint); +} + +char const * +wf_mountpoint_get_path( + struct wf_mountpoint const * mountpoint) +{ + return wf_impl_mountpoint_get_path(mountpoint); +} diff --git a/lib/webfuse/adapter/impl/mountpoint.c b/lib/webfuse/adapter/impl/mountpoint.c new file mode 100644 index 0000000..55535d6 --- /dev/null +++ b/lib/webfuse/adapter/impl/mountpoint.c @@ -0,0 +1,34 @@ +#include "webfuse/adapter/impl/mountpoint.h" + +#include +#include + +struct wf_mountpoint +{ + char * path; +}; + +struct wf_mountpoint * +wf_impl_mountpoint_create( + char const * path) +{ + struct wf_mountpoint * mountpoint = malloc(sizeof(struct wf_mountpoint)); + mountpoint->path = strdup(path); + + return mountpoint; +} + +void +wf_impl_mountpoint_dispose( + struct wf_mountpoint * mountpoint) +{ + free(mountpoint->path); + free(mountpoint); +} + +char const * +wf_impl_mountpoint_get_path( + struct wf_mountpoint const * mountpoint) +{ + return mountpoint->path; +} diff --git a/lib/webfuse/adapter/impl/mountpoint.h b/lib/webfuse/adapter/impl/mountpoint.h new file mode 100644 index 0000000..eb0145c --- /dev/null +++ b/lib/webfuse/adapter/impl/mountpoint.h @@ -0,0 +1,26 @@ +#ifndef WF_IMPL_MOUNTPOINT_H +#define WF_IMPL_MOUNTPOINT_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern struct wf_mountpoint * +wf_impl_mountpoint_create( + char const * path); + +extern void +wf_impl_mountpoint_dispose( + struct wf_mountpoint * mountpoint); + +extern char const * +wf_impl_mountpoint_get_path( + struct wf_mountpoint const * mountpoint); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/adapter/test_mountpoint.cc b/test/adapter/test_mountpoint.cc new file mode 100644 index 0000000..e21d176 --- /dev/null +++ b/test/adapter/test_mountpoint.cc @@ -0,0 +1,12 @@ +#include +#include "webfuse/adapter/mountpoint.h" + +TEST(mountpoint, get_path) +{ + wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path"); + + ASSERT_NE(nullptr, mountpoint); + ASSERT_STREQ("/some/path", wf_mountpoint_get_path(mountpoint)); + + wf_mountpoint_dispose(mountpoint); +} From 6a94cea6f91497653900e6d6f36eef333bc314e8 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 15 Feb 2020 15:50:32 +0100 Subject: [PATCH 035/138] added ondispose to mountpoint to allow custom cleanup --- include/webfuse/adapter/mountpoint.h | 9 +++++++ lib/webfuse/adapter/api.c | 8 ++++++ lib/webfuse/adapter/impl/mountpoint.c | 19 +++++++++++++++ lib/webfuse/adapter/impl/mountpoint.h | 6 +++++ test/adapter/test_mountpoint.cc | 35 ++++++++++++++++++++++++++- 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/include/webfuse/adapter/mountpoint.h b/include/webfuse/adapter/mountpoint.h index 0dba1cd..7936b83 100644 --- a/include/webfuse/adapter/mountpoint.h +++ b/include/webfuse/adapter/mountpoint.h @@ -8,6 +8,10 @@ extern "C" struct wf_mountpoint; +typedef void +wf_mountpoint_ondispose_fn( + struct wf_mountpoint * mountpoint); + extern struct wf_mountpoint * wf_mountpoint_create( char const * path); @@ -20,6 +24,11 @@ extern char const * wf_mountpoint_get_path( struct wf_mountpoint const * mountpoint); +extern void +wf_mountpoint_set_ondispose( + struct wf_mountpoint * mountpoint, + wf_mountpoint_ondispose_fn * ondispose); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 370a55e..64f55a3 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -158,3 +158,11 @@ wf_mountpoint_get_path( { return wf_impl_mountpoint_get_path(mountpoint); } + +void +wf_mountpoint_set_ondispose( + struct wf_mountpoint * mountpoint, + wf_mountpoint_ondispose_fn * ondispose) +{ + wf_impl_mountpoint_set_ondispose(mountpoint, ondispose); +} diff --git a/lib/webfuse/adapter/impl/mountpoint.c b/lib/webfuse/adapter/impl/mountpoint.c index 55535d6..ade1223 100644 --- a/lib/webfuse/adapter/impl/mountpoint.c +++ b/lib/webfuse/adapter/impl/mountpoint.c @@ -6,14 +6,23 @@ struct wf_mountpoint { char * path; + wf_mountpoint_ondispose_fn * ondispose; }; +static void wf_impl_mountpoint_default_ondispose( + struct wf_mountpoint * mountpoint) +{ + (void) mountpoint; + // empty +} + struct wf_mountpoint * wf_impl_mountpoint_create( char const * path) { struct wf_mountpoint * mountpoint = malloc(sizeof(struct wf_mountpoint)); mountpoint->path = strdup(path); + mountpoint->ondispose = &wf_impl_mountpoint_default_ondispose; return mountpoint; } @@ -22,6 +31,8 @@ void wf_impl_mountpoint_dispose( struct wf_mountpoint * mountpoint) { + mountpoint->ondispose(mountpoint); + free(mountpoint->path); free(mountpoint); } @@ -32,3 +43,11 @@ wf_impl_mountpoint_get_path( { return mountpoint->path; } + +void +wf_impl_mountpoint_set_ondispose( + struct wf_mountpoint * mountpoint, + wf_mountpoint_ondispose_fn * ondispose) +{ + mountpoint->ondispose = ondispose; +} diff --git a/lib/webfuse/adapter/impl/mountpoint.h b/lib/webfuse/adapter/impl/mountpoint.h index eb0145c..a7041f8 100644 --- a/lib/webfuse/adapter/impl/mountpoint.h +++ b/lib/webfuse/adapter/impl/mountpoint.h @@ -1,6 +1,8 @@ #ifndef WF_IMPL_MOUNTPOINT_H #define WF_IMPL_MOUNTPOINT_H +#include "webfuse/adapter/mountpoint.h" + #ifdef __cplusplus extern "C" { @@ -18,6 +20,10 @@ extern char const * wf_impl_mountpoint_get_path( struct wf_mountpoint const * mountpoint); +extern void +wf_impl_mountpoint_set_ondispose( + struct wf_mountpoint * mointpoint, + wf_mountpoint_ondispose_fn * ondispose); #ifdef __cplusplus } diff --git a/test/adapter/test_mountpoint.cc b/test/adapter/test_mountpoint.cc index e21d176..a3d82c6 100644 --- a/test/adapter/test_mountpoint.cc +++ b/test/adapter/test_mountpoint.cc @@ -1,12 +1,45 @@ #include +#include #include "webfuse/adapter/mountpoint.h" +namespace +{ + class MockMountpointDisposer + { + public: + MOCK_METHOD1(ondispose, void(wf_mountpoint * mountpoint)); + }; + + MockMountpointDisposer * global_disposer = nullptr; + + void ondispose(wf_mountpoint * mountpoint) + { + global_disposer->ondispose(mountpoint); + } +} + TEST(mountpoint, get_path) { wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path"); - ASSERT_NE(nullptr, mountpoint); + ASSERT_STREQ("/some/path", wf_mountpoint_get_path(mountpoint)); wf_mountpoint_dispose(mountpoint); } + + + +TEST(mountpoint, ondispose) +{ + MockMountpointDisposer disposer; + global_disposer = &disposer; + + wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path"); + ASSERT_NE(nullptr, mountpoint); + + wf_mountpoint_set_ondispose(mountpoint, ondispose); + EXPECT_CALL(disposer, ondispose(mountpoint)).Times(1); + + wf_mountpoint_dispose(mountpoint); +} \ No newline at end of file From cfadf85f49f16a1f3396950d3a3d72b13b3e47fb Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 16 Feb 2020 04:02:23 +0100 Subject: [PATCH 036/138] added uuid mountpoint and factory --- cmake/webfuse_adapter.cmake | 2 + include/webfuse/adapter/mountpoint.h | 11 +- lib/webfuse/adapter/api.c | 7 +- lib/webfuse/adapter/impl/mountpoint.c | 28 ++-- lib/webfuse/adapter/impl/mountpoint.h | 7 +- lib/webfuse/adapter/impl/uuid_mountpoint.c | 123 ++++++++++++++++++ lib/webfuse/adapter/impl/uuid_mountpoint.h | 20 +++ .../adapter/impl/uuid_mountpoint_factory.c | 47 +++++++ .../adapter/impl/uuid_mountpoint_factory.h | 29 +++++ test/adapter/test_mountpoint.cc | 18 +-- 10 files changed, 259 insertions(+), 33 deletions(-) create mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint.c create mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint.h create mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint_factory.c create mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint_factory.h diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index f970ef7..aa343b7 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -16,6 +16,8 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/credentials.c lib/webfuse/adapter/impl/operations.c lib/webfuse/adapter/impl/mountpoint.c + lib/webfuse/adapter/impl/uuid_mountpoint_factory.c + lib/webfuse/adapter/impl/uuid_mountpoint.c lib/webfuse/adapter/impl/time/timepoint.c lib/webfuse/adapter/impl/time/timer.c lib/webfuse/adapter/impl/time/timeout_manager.c diff --git a/include/webfuse/adapter/mountpoint.h b/include/webfuse/adapter/mountpoint.h index 7936b83..62f59f3 100644 --- a/include/webfuse/adapter/mountpoint.h +++ b/include/webfuse/adapter/mountpoint.h @@ -9,8 +9,8 @@ extern "C" struct wf_mountpoint; typedef void -wf_mountpoint_ondispose_fn( - struct wf_mountpoint * mountpoint); +wf_mountpoint_userdata_dispose_fn( + void * user_data); extern struct wf_mountpoint * wf_mountpoint_create( @@ -25,9 +25,10 @@ wf_mountpoint_get_path( struct wf_mountpoint const * mountpoint); extern void -wf_mountpoint_set_ondispose( - struct wf_mountpoint * mountpoint, - wf_mountpoint_ondispose_fn * ondispose); +wf_mountpoint_set_userdata( + struct wf_mountpoint * mointpoint, + void * user_data, + wf_mountpoint_userdata_dispose_fn * dispose); #ifdef __cplusplus } diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 64f55a3..2d1bac2 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -160,9 +160,10 @@ wf_mountpoint_get_path( } void -wf_mountpoint_set_ondispose( +wf_mountpoint_set_userdata( struct wf_mountpoint * mountpoint, - wf_mountpoint_ondispose_fn * ondispose) + void * user_data, + wf_mountpoint_userdata_dispose_fn * dispose) { - wf_impl_mountpoint_set_ondispose(mountpoint, ondispose); + wf_impl_mountpoint_set_userdata(mountpoint, user_data, dispose); } diff --git a/lib/webfuse/adapter/impl/mountpoint.c b/lib/webfuse/adapter/impl/mountpoint.c index ade1223..a459510 100644 --- a/lib/webfuse/adapter/impl/mountpoint.c +++ b/lib/webfuse/adapter/impl/mountpoint.c @@ -6,23 +6,18 @@ struct wf_mountpoint { char * path; - wf_mountpoint_ondispose_fn * ondispose; + void * user_data; + wf_mountpoint_userdata_dispose_fn * dispose; }; -static void wf_impl_mountpoint_default_ondispose( - struct wf_mountpoint * mountpoint) -{ - (void) mountpoint; - // empty -} - struct wf_mountpoint * wf_impl_mountpoint_create( char const * path) { struct wf_mountpoint * mountpoint = malloc(sizeof(struct wf_mountpoint)); mountpoint->path = strdup(path); - mountpoint->ondispose = &wf_impl_mountpoint_default_ondispose; + mountpoint->user_data = NULL; + mountpoint->dispose = NULL; return mountpoint; } @@ -31,7 +26,10 @@ void wf_impl_mountpoint_dispose( struct wf_mountpoint * mountpoint) { - mountpoint->ondispose(mountpoint); + if (NULL != mountpoint->dispose) + { + mountpoint->dispose(mountpoint->user_data); + } free(mountpoint->path); free(mountpoint); @@ -44,10 +42,12 @@ wf_impl_mountpoint_get_path( return mountpoint->path; } -void -wf_impl_mountpoint_set_ondispose( +extern void +wf_impl_mountpoint_set_userdata( struct wf_mountpoint * mountpoint, - wf_mountpoint_ondispose_fn * ondispose) + void * user_data, + wf_mountpoint_userdata_dispose_fn * dispose) { - mountpoint->ondispose = ondispose; + mountpoint->user_data = user_data; + mountpoint->dispose = dispose; } diff --git a/lib/webfuse/adapter/impl/mountpoint.h b/lib/webfuse/adapter/impl/mountpoint.h index a7041f8..77fc0ea 100644 --- a/lib/webfuse/adapter/impl/mountpoint.h +++ b/lib/webfuse/adapter/impl/mountpoint.h @@ -21,9 +21,10 @@ wf_impl_mountpoint_get_path( struct wf_mountpoint const * mountpoint); extern void -wf_impl_mountpoint_set_ondispose( - struct wf_mountpoint * mointpoint, - wf_mountpoint_ondispose_fn * ondispose); +wf_impl_mountpoint_set_userdata( + struct wf_mountpoint * mountpoint, + void * user_data, + wf_mountpoint_userdata_dispose_fn * dispose); #ifdef __cplusplus } diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint.c b/lib/webfuse/adapter/impl/uuid_mountpoint.c new file mode 100644 index 0000000..1b0cd8a --- /dev/null +++ b/lib/webfuse/adapter/impl/uuid_mountpoint.c @@ -0,0 +1,123 @@ +#include "webfuse/adapter/impl/uuid_mountpoint.h" +#include "webfuse/adapter/impl/mountpoint.h" + +#include "webfuse/core/string.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include + +struct wf_impl_uuid_mountpoint_data +{ + char * id; + char * filesystem_path; + char * default_path; + char * full_path; +}; + +static char * wf_impl_uuid_mountpoint_create_id(void) +{ + uuid_t uuid; + uuid_generate(uuid); + char id[UUID_STR_LEN]; + uuid_unparse(uuid, id); + + return strdup(id); +} + +static bool wf_impl_uuid_mountpoint_is_link_broken(char const * path, char const * id) +{ + bool result = false; + + char buffer[UUID_STR_LEN]; + ssize_t count = readlink(path, buffer, UUID_STR_LEN); + if ((0 < count) && (count < UUID_STR_LEN)) + { + buffer[count] = '\0'; + result = (0 == strcmp(buffer, id)); + } + + return result; +} + +static bool wf_impl_uuid_mountpoint_link_first_subdir( + char const * link_path, + char const * path) +{ + bool result = false; + DIR * dir = opendir(path); + if (NULL != dir) + { + struct dirent * entry = readdir(dir); + while (NULL != entry) + { + if ((DT_DIR == entry->d_type) && ('.' != entry->d_name[0])) + { + symlink(entry->d_name, link_path); + result = true; + break; + } + + entry = readdir(dir); + } + + closedir(dir); + } + + return result; +} + +static void +wf_impl_uuid_mountpoint_data_dispose( + void * user_data) +{ + struct wf_impl_uuid_mountpoint_data * data = user_data; + + rmdir(data->full_path); + + if (wf_impl_filesystem_is_link_broken(data->default_path, data->id)) + { + unlink(data->default_path); + + bool const success = wf_impl_filesystem_link_first_subdir(data->default_path, data->filesystem_path); + if (!success) + { + rmdir(data->filesystem_path); + } + } + + free(data->id); + free(data->filesystem_path); + free(data->default_path); + free(data->full_path); + free(data); +} + +struct wf_mountpoint * +wf_impl_uuid_mountpoint_create( + char const * root_path, + char const * filesystem) +{ + struct wf_impl_uuid_mountpoint_data * data = malloc(sizeof(struct wf_impl_uuid_mountpoint_data)); + data->filesystem_path = wf_create_string("%s/%s", root_path, filesystem); + mkdir(data->filesystem_path, 0755); + + data->id = wf_impl_uuid_mountpoint_create_id(); + char * full_path = wf_create_string("%s/%s/%s", root_path, filesystem, data->id); + mkdir(data->full_path, 0755); + + data->default_path = wf_create_string("%s/%s/default", root_path, data->filesystem_path); + symlink(data->id, data->default_path); + + struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(full_path); + wf_impl_mountpoint_set_userdata(mountpoint, data, &wf_impl_uuid_mountpoint_data_dispose); + + return mountpoint; +} diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint.h b/lib/webfuse/adapter/impl/uuid_mountpoint.h new file mode 100644 index 0000000..7287be3 --- /dev/null +++ b/lib/webfuse/adapter/impl/uuid_mountpoint.h @@ -0,0 +1,20 @@ +#ifndef WF_IMPL_UUID_MOUNTPOINT_H +#define WF_IMPL_UUID_MOUNTPOINT_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_mountpoint; + +extern struct wf_mountpoint * +wf_impl_uuid_mountpoint_create( + char const * root_path, + char const * filesystem); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c new file mode 100644 index 0000000..f982f5b --- /dev/null +++ b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c @@ -0,0 +1,47 @@ +#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" +#include "webfuse/adapter/impl/uuid_mountpoint.h" + +#include +#include +#include + +#include +#include + +struct wf_impl_uuid_mountpoint_factory +{ + char * root_path; +}; + +void * +wf_impl_uuid_mountpoint_factory_create( + char * root_path) +{ + mkdir(root_path, 0755); + + struct wf_impl_uuid_mountpoint_factory * factory = malloc(sizeof(struct wf_impl_uuid_mountpoint_factory)); + factory->root_path = strdup(root_path); + + return factory; +} + +void +wf_impl_uuid_mountpoint_factory_dispose( + void * user_data) +{ + struct wf_impl_uuid_mountpoint_factory * factory = user_data; + + rmdir(factory->root_path); + free(factory->root_path); + free(factory); +} + +struct wf_mountpoint * +wf_impl_uuid_mountpoint_factory_create_mountpoint( + char const * filesystem, + void * user_data) +{ + struct wf_impl_uuid_mountpoint_factory * factory = user_data; + + return wf_impl_uuid_mountpoint_create(factory->root_path, filesystem); +} diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h new file mode 100644 index 0000000..a406597 --- /dev/null +++ b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h @@ -0,0 +1,29 @@ +#ifndef WF_IMPL_UUID_MOUNTPOINT_FACTORY_H +#define WF_IMPL_UUID_MOUNTPOINT_FACTORY_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_mountpoint; + +extern void * +wf_impl_uuid_mountpoint_factory_create( + char * root_path); + +extern void +wf_impl_uuid_mountpoint_factory_dispose( + void * user_data); + +extern struct wf_mountpoint * +wf_impl_uuid_mountpoint_factory_create_mountpiont( + char const * filesystem, + void * user_data); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/adapter/test_mountpoint.cc b/test/adapter/test_mountpoint.cc index a3d82c6..6bb486b 100644 --- a/test/adapter/test_mountpoint.cc +++ b/test/adapter/test_mountpoint.cc @@ -4,17 +4,17 @@ namespace { - class MockMountpointDisposer + class MockUserDataDisposer { public: - MOCK_METHOD1(ondispose, void(wf_mountpoint * mountpoint)); + MOCK_METHOD1(dispose, void(void * mountpoint)); }; - MockMountpointDisposer * global_disposer = nullptr; + MockUserDataDisposer * global_disposer = nullptr; - void ondispose(wf_mountpoint * mountpoint) + void ondispose(void * user_data) { - global_disposer->ondispose(mountpoint); + global_disposer->dispose(user_data); } } @@ -32,14 +32,16 @@ TEST(mountpoint, get_path) TEST(mountpoint, ondispose) { - MockMountpointDisposer disposer; + MockUserDataDisposer disposer; global_disposer = &disposer; wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path"); ASSERT_NE(nullptr, mountpoint); - wf_mountpoint_set_ondispose(mountpoint, ondispose); - EXPECT_CALL(disposer, ondispose(mountpoint)).Times(1); + int value = 42; + void * user_data = reinterpret_cast(&value); + wf_mountpoint_set_userdata(mountpoint, user_data, ondispose); + EXPECT_CALL(disposer, dispose(user_data)).Times(1); wf_mountpoint_dispose(mountpoint); } \ No newline at end of file From 096c24444596a38d072ed070bf359fd285132160 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 16 Feb 2020 14:47:21 +0100 Subject: [PATCH 037/138] added unit tests for uuid_mountpoint --- cmake/unit_tests.cmake | 2 + lib/webfuse/adapter/impl/uuid_mountpoint.c | 10 +- test/adapter/test_uuid_mountpoint.cc | 102 +++++++++++++++++++++ test/tempdir.cc | 33 +++++++ test/tempdir.hpp | 21 +++++ 5 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 test/adapter/test_uuid_mountpoint.cc create mode 100644 test/tempdir.cc create mode 100644 test/tempdir.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index b5ae7ad..1301b15 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,6 +7,7 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests + test/tempdir.cc test/msleep.cc test/die_if.cc test/mock_authenticator.cc @@ -27,6 +28,7 @@ add_executable(alltests test/adapter/test_authenticator.cc test/adapter/test_authenticators.cc test/adapter/test_mountpoint.cc + test/adapter/test_uuid_mountpoint.cc test/adapter/test_fuse_req.cc test/adapter/jsonrpc/test_util.cc test/adapter/jsonrpc/test_is_request.cc diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint.c b/lib/webfuse/adapter/impl/uuid_mountpoint.c index 1b0cd8a..eafa444 100644 --- a/lib/webfuse/adapter/impl/uuid_mountpoint.c +++ b/lib/webfuse/adapter/impl/uuid_mountpoint.c @@ -82,11 +82,11 @@ wf_impl_uuid_mountpoint_data_dispose( rmdir(data->full_path); - if (wf_impl_filesystem_is_link_broken(data->default_path, data->id)) + if (wf_impl_uuid_mountpoint_is_link_broken(data->default_path, data->id)) { unlink(data->default_path); - bool const success = wf_impl_filesystem_link_first_subdir(data->default_path, data->filesystem_path); + bool const success = wf_impl_uuid_mountpoint_link_first_subdir(data->default_path, data->filesystem_path); if (!success) { rmdir(data->filesystem_path); @@ -110,13 +110,13 @@ wf_impl_uuid_mountpoint_create( mkdir(data->filesystem_path, 0755); data->id = wf_impl_uuid_mountpoint_create_id(); - char * full_path = wf_create_string("%s/%s/%s", root_path, filesystem, data->id); + data->full_path = wf_create_string("%s/%s/%s", root_path, filesystem, data->id); mkdir(data->full_path, 0755); - data->default_path = wf_create_string("%s/%s/default", root_path, data->filesystem_path); + data->default_path = wf_create_string("%s/%s/default", root_path, filesystem); symlink(data->id, data->default_path); - struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(full_path); + struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(data->full_path); wf_impl_mountpoint_set_userdata(mountpoint, data, &wf_impl_uuid_mountpoint_data_dispose); return mountpoint; diff --git a/test/adapter/test_uuid_mountpoint.cc b/test/adapter/test_uuid_mountpoint.cc new file mode 100644 index 0000000..cfa4000 --- /dev/null +++ b/test/adapter/test_uuid_mountpoint.cc @@ -0,0 +1,102 @@ +#include + +#include +#include +#include + +#include "tempdir.hpp" +#include "webfuse_adapter.h" +#include "webfuse/adapter/impl/uuid_mountpoint.h" + +#include + +using webfuse_test::TempDir; + +namespace +{ + bool is_dir(std::string const & path) + { + struct stat info; + int rc = stat(path.c_str(), &info); + + return (0 == rc) && (S_ISDIR(info.st_mode)); + } + + bool is_symlink(std::string const & path) + { + struct stat info; + int rc = lstat(path.c_str(), &info); + + return (0 == rc) && (S_ISLNK(info.st_mode)); + } + + bool is_same_path(std::string const & path, std::string const & other) + { + struct stat info; + int rc = stat(path.c_str(), &info); + + struct stat info_other; + int rc_other = stat(other.c_str(), &info_other); + + return (0 == rc) && (0 == rc_other) && (info.st_ino == info_other.st_ino); + } +} + +TEST(uuid_mountpoint, create) +{ + TempDir temp("uuid_mountpoint"); + + std::string filesystem_path = std::string(temp.path()) + "/dummy"; + std::string default_path = std::string(temp.path()) + "/dummy/default"; + + wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); + std::string path = wf_mountpoint_get_path(mountpoint); + ASSERT_NE(nullptr, mountpoint); + ASSERT_TRUE(is_dir(filesystem_path)); + ASSERT_TRUE(is_symlink(default_path)); + ASSERT_TRUE(is_dir(default_path)); + ASSERT_TRUE(is_dir(path)); + ASSERT_TRUE(is_same_path(default_path, path)); + + wf_mountpoint_dispose(mountpoint); + ASSERT_FALSE(is_dir(filesystem_path)); + ASSERT_FALSE(is_symlink(default_path)); + ASSERT_FALSE(is_dir(default_path)); + ASSERT_FALSE(is_dir(path)); +} + +TEST(uuid_mountpoint, relink_default) +{ + TempDir temp("uuid_mountpoint"); + + std::string filesystem_path = std::string(temp.path()) + "/dummy"; + std::string default_path = std::string(temp.path()) + "/dummy/default"; + + wf_mountpoint * mountpoint_a = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); + std::string path_a = wf_mountpoint_get_path(mountpoint_a); + + wf_mountpoint * mountpoint_b = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); + std::string path_b = wf_mountpoint_get_path(mountpoint_b); + + ASSERT_TRUE(is_dir(filesystem_path)); + ASSERT_TRUE(is_symlink(default_path)); + ASSERT_TRUE(is_dir(default_path)); + ASSERT_TRUE(is_dir(path_a)); + ASSERT_TRUE(is_dir(path_b)); + ASSERT_TRUE(is_same_path(default_path, path_a)); + + wf_mountpoint_dispose(mountpoint_a); + ASSERT_TRUE(is_dir(filesystem_path)); + ASSERT_TRUE(is_symlink(default_path)); + ASSERT_TRUE(is_dir(default_path)); + ASSERT_FALSE(is_dir(path_a)); + ASSERT_TRUE(is_dir(path_b)); + ASSERT_TRUE(is_same_path(default_path, path_b)); + + wf_mountpoint_dispose(mountpoint_b); + ASSERT_FALSE(is_dir(filesystem_path)); + ASSERT_FALSE(is_symlink(default_path)); + ASSERT_FALSE(is_dir(default_path)); + ASSERT_FALSE(is_dir(path_a)); + ASSERT_FALSE(is_dir(path_b)); +} diff --git a/test/tempdir.cc b/test/tempdir.cc new file mode 100644 index 0000000..040aed1 --- /dev/null +++ b/test/tempdir.cc @@ -0,0 +1,33 @@ +#include "webfuse/core/string.h" +#include "tempdir.hpp" + +#include +#include +#include + +namespace webfuse_test +{ + +TempDir::TempDir(char const * prefix) +: path_(wf_create_string("/tmp/%s_XXXXXX", prefix)) +{ + char * result = mkdtemp(path_); + if (NULL == result) + { + throw std::runtime_error("unable to create temp dir"); + } +} + +TempDir::~TempDir() +{ + rmdir(path_); + free(path_); +} + +char const * TempDir::path() +{ + return path_; +} + + +} \ No newline at end of file diff --git a/test/tempdir.hpp b/test/tempdir.hpp new file mode 100644 index 0000000..0c28a80 --- /dev/null +++ b/test/tempdir.hpp @@ -0,0 +1,21 @@ +#ifndef WF_TEST_TEMPDIR_HPP +#define WF_TEST_TEMPDIR_HPP + +namespace webfuse_test +{ + +class TempDir +{ + TempDir(TempDir const &) = delete; + TempDir & operator=(TempDir const &) = delete; +public: + TempDir(char const * prefix); + ~TempDir(); + char const * path(); +private: + char * path_; +}; + +} + +#endif From 2b91f159cf278850444645f910393435b761b169 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 16 Feb 2020 17:33:11 +0100 Subject: [PATCH 038/138] added unit tests of uuid_mountpoint_factory --- cmake/unit_tests.cmake | 2 + .../adapter/impl/uuid_mountpoint_factory.c | 30 ++++++++-- .../adapter/impl/uuid_mountpoint_factory.h | 4 +- test/adapter/test_uuid_mountpoint.cc | 38 ++---------- test/adapter/test_uuid_mountpoint_factory.cc | 60 +++++++++++++++++++ test/file_utils.cc | 38 ++++++++++++ test/file_utils.hpp | 17 ++++++ 7 files changed, 148 insertions(+), 41 deletions(-) create mode 100644 test/adapter/test_uuid_mountpoint_factory.cc create mode 100644 test/file_utils.cc create mode 100644 test/file_utils.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1301b15..933d78e 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -8,6 +8,7 @@ pkg_check_modules(GMOCK gmock) add_executable(alltests test/tempdir.cc + test/file_utils.cc test/msleep.cc test/die_if.cc test/mock_authenticator.cc @@ -29,6 +30,7 @@ add_executable(alltests test/adapter/test_authenticators.cc test/adapter/test_mountpoint.cc test/adapter/test_uuid_mountpoint.cc + test/adapter/test_uuid_mountpoint_factory.cc test/adapter/test_fuse_req.cc test/adapter/jsonrpc/test_util.cc test/adapter/jsonrpc/test_is_request.cc diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c index f982f5b..1f28e64 100644 --- a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c +++ b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c @@ -7,20 +7,36 @@ #include #include +#include struct wf_impl_uuid_mountpoint_factory { char * root_path; + bool root_created; }; void * wf_impl_uuid_mountpoint_factory_create( - char * root_path) + char const * root_path) { - mkdir(root_path, 0755); + struct wf_impl_uuid_mountpoint_factory * factory = NULL; + bool root_created = false; + + struct stat info; + int rc = stat(root_path, &info); + if ((0 != rc) || (!S_ISDIR(info.st_mode))) + { + rc = mkdir(root_path, 0755); + root_created = true; + } + + if (0 == rc) + { + factory = malloc(sizeof(struct wf_impl_uuid_mountpoint_factory)); + factory->root_path = strdup(root_path); + factory->root_created = root_created; + } - struct wf_impl_uuid_mountpoint_factory * factory = malloc(sizeof(struct wf_impl_uuid_mountpoint_factory)); - factory->root_path = strdup(root_path); return factory; } @@ -31,7 +47,11 @@ wf_impl_uuid_mountpoint_factory_dispose( { struct wf_impl_uuid_mountpoint_factory * factory = user_data; - rmdir(factory->root_path); + if (factory->root_created) + { + rmdir(factory->root_path); + } + free(factory->root_path); free(factory); } diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h index a406597..52d5c57 100644 --- a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h +++ b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h @@ -10,14 +10,14 @@ struct wf_mountpoint; extern void * wf_impl_uuid_mountpoint_factory_create( - char * root_path); + char const * root_path); extern void wf_impl_uuid_mountpoint_factory_dispose( void * user_data); extern struct wf_mountpoint * -wf_impl_uuid_mountpoint_factory_create_mountpiont( +wf_impl_uuid_mountpoint_factory_create_mountpoint( char const * filesystem, void * user_data); diff --git a/test/adapter/test_uuid_mountpoint.cc b/test/adapter/test_uuid_mountpoint.cc index cfa4000..8bff760 100644 --- a/test/adapter/test_uuid_mountpoint.cc +++ b/test/adapter/test_uuid_mountpoint.cc @@ -1,46 +1,16 @@ #include -#include -#include -#include - #include "tempdir.hpp" +#include "file_utils.hpp" #include "webfuse_adapter.h" #include "webfuse/adapter/impl/uuid_mountpoint.h" #include using webfuse_test::TempDir; - -namespace -{ - bool is_dir(std::string const & path) - { - struct stat info; - int rc = stat(path.c_str(), &info); - - return (0 == rc) && (S_ISDIR(info.st_mode)); - } - - bool is_symlink(std::string const & path) - { - struct stat info; - int rc = lstat(path.c_str(), &info); - - return (0 == rc) && (S_ISLNK(info.st_mode)); - } - - bool is_same_path(std::string const & path, std::string const & other) - { - struct stat info; - int rc = stat(path.c_str(), &info); - - struct stat info_other; - int rc_other = stat(other.c_str(), &info_other); - - return (0 == rc) && (0 == rc_other) && (info.st_ino == info_other.st_ino); - } -} +using webfuse_test::is_dir; +using webfuse_test::is_symlink; +using webfuse_test::is_same_path; TEST(uuid_mountpoint, create) { diff --git a/test/adapter/test_uuid_mountpoint_factory.cc b/test/adapter/test_uuid_mountpoint_factory.cc new file mode 100644 index 0000000..abb0b27 --- /dev/null +++ b/test/adapter/test_uuid_mountpoint_factory.cc @@ -0,0 +1,60 @@ +#include +#include "webfuse_adapter.h" +#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" +#include "tempdir.hpp" +#include "file_utils.hpp" + +using webfuse_test::TempDir; +using webfuse_test::is_dir; + +TEST(uuid_mountpoint_factory, create_existing_dir) +{ + TempDir temp("uuid_mountpoint_factory"); + + void * factory = wf_impl_uuid_mountpoint_factory_create(temp.path()); + ASSERT_NE(nullptr, factory); + ASSERT_TRUE(is_dir(temp.path())); + + wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory); + std::string path = wf_mountpoint_get_path(mountpoint); + ASSERT_NE(nullptr, factory); + ASSERT_TRUE(is_dir(path)); + + wf_mountpoint_dispose(mountpoint); + ASSERT_FALSE(is_dir(path)); + + wf_impl_uuid_mountpoint_factory_dispose(factory); + // keep dir not created by factory + ASSERT_TRUE(is_dir(temp.path())); +} + +TEST(uuid_mountpoint_factory, create_nonexisting_dir) +{ + TempDir temp("uuid_mountpoint_factory"); + std::string root_path = std::string(temp.path()) + "/root"; + + void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str()); + ASSERT_NE(nullptr, factory); + ASSERT_TRUE(is_dir(root_path)); + + wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory); + std::string path = wf_mountpoint_get_path(mountpoint); + ASSERT_NE(nullptr, factory); + ASSERT_TRUE(is_dir(path)); + + wf_mountpoint_dispose(mountpoint); + ASSERT_FALSE(is_dir(path)); + + wf_impl_uuid_mountpoint_factory_dispose(factory); + // remove dir, created by factory + ASSERT_FALSE(is_dir(root_path)); +} + +TEST(uuid_mountpoint_factory, fail_to_created_nested_dir) +{ + TempDir temp("uuid_mountpoint_factory"); + std::string root_path = std::string(temp.path()) + "/nested/root"; + + void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str()); + ASSERT_EQ(nullptr, factory); +} \ No newline at end of file diff --git a/test/file_utils.cc b/test/file_utils.cc new file mode 100644 index 0000000..0d3ff81 --- /dev/null +++ b/test/file_utils.cc @@ -0,0 +1,38 @@ +#include "file_utils.hpp" + +#include +#include +#include + +namespace webfuse_test +{ + +bool is_dir(std::string const & path) +{ + struct stat info; + int rc = stat(path.c_str(), &info); + + return (0 == rc) && (S_ISDIR(info.st_mode)); +} + +bool is_symlink(std::string const & path) +{ + struct stat info; + int rc = lstat(path.c_str(), &info); + + return (0 == rc) && (S_ISLNK(info.st_mode)); +} + +bool is_same_path(std::string const & path, std::string const & other) +{ + struct stat info; + int rc = stat(path.c_str(), &info); + + struct stat info_other; + int rc_other = stat(other.c_str(), &info_other); + + return (0 == rc) && (0 == rc_other) && (info.st_ino == info_other.st_ino); +} + + +} \ No newline at end of file diff --git a/test/file_utils.hpp b/test/file_utils.hpp new file mode 100644 index 0000000..0c8cbc1 --- /dev/null +++ b/test/file_utils.hpp @@ -0,0 +1,17 @@ +#ifndef WF_TEST_FILE_UTILS_HPP +#define WF_TEST_FILE_UTILS_HPP + +#include + +namespace webfuse_test +{ + +bool is_dir(std::string const & path); + +bool is_symlink(std::string const & path); + +bool is_same_path(std::string const & path, std::string const & other); + +} + +#endif From 77627b7c8b4aef842a89be323afbff5c258ad26c Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 16 Feb 2020 21:03:17 +0100 Subject: [PATCH 039/138] integrated uuid_mountpoint_factory --- cmake/webfuse_adapter.cmake | 1 + include/webfuse/adapter/server_protocol.h | 5 + lib/webfuse/adapter/api.c | 16 ++++ lib/webfuse/adapter/impl/filesystem.c | 92 ++----------------- lib/webfuse/adapter/impl/filesystem.h | 10 +- lib/webfuse/adapter/impl/mountpoint_factory.c | 67 ++++++++++++++ lib/webfuse/adapter/impl/mountpoint_factory.h | 61 ++++++++++++ lib/webfuse/adapter/impl/server.c | 24 +---- lib/webfuse/adapter/impl/server_config.c | 22 ++++- lib/webfuse/adapter/impl/server_config.h | 8 +- lib/webfuse/adapter/impl/server_protocol.c | 37 ++++++-- lib/webfuse/adapter/impl/server_protocol.h | 9 +- lib/webfuse/adapter/impl/session.c | 33 +++++-- lib/webfuse/adapter/impl/session.h | 5 +- lib/webfuse/adapter/impl/session_manager.c | 6 +- lib/webfuse/adapter/impl/session_manager.h | 4 +- .../adapter/impl/uuid_mountpoint_factory.c | 27 +++++- .../adapter/impl/uuid_mountpoint_factory.h | 20 ++-- test/adapter/test_uuid_mountpoint_factory.cc | 25 ++--- 19 files changed, 304 insertions(+), 168 deletions(-) create mode 100644 lib/webfuse/adapter/impl/mountpoint_factory.c create mode 100644 lib/webfuse/adapter/impl/mountpoint_factory.h diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index aa343b7..269204d 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -16,6 +16,7 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/credentials.c lib/webfuse/adapter/impl/operations.c lib/webfuse/adapter/impl/mountpoint.c + lib/webfuse/adapter/impl/mountpoint_factory.c lib/webfuse/adapter/impl/uuid_mountpoint_factory.c lib/webfuse/adapter/impl/uuid_mountpoint.c lib/webfuse/adapter/impl/time/timepoint.c diff --git a/include/webfuse/adapter/server_protocol.h b/include/webfuse/adapter/server_protocol.h index d77cbc3..6491a05 100644 --- a/include/webfuse/adapter/server_protocol.h +++ b/include/webfuse/adapter/server_protocol.h @@ -3,6 +3,7 @@ #include #include +#include #ifdef __cplusplus extern "C" @@ -15,6 +16,10 @@ struct lws_protocols; extern WF_API struct wf_server_protocol * wf_server_protocol_create( char * mount_point); +extern WF_API struct wf_server_protocol * wf_server_protocol_create2( + wf_create_mountpoint_fn * create_mountpoint, + void * create_mountpoint_context); + extern WF_API void wf_server_protocol_dispose( struct wf_server_protocol * protocol); diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 2d1bac2..adecac2 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -35,6 +35,13 @@ struct wf_server_protocol * wf_server_protocol_create( return wf_impl_server_protocol_create(mount_point); } +struct wf_server_protocol * wf_server_protocol_create2( + wf_create_mountpoint_fn * create_mountpoint, + void * create_mountpoint_context) +{ + return wf_impl_server_protocol_create2(create_mountpoint, create_mountpoint_context); +} + void wf_server_protocol_dispose( struct wf_server_protocol * protocol) { @@ -77,6 +84,15 @@ void wf_server_config_set_mountpoint( wf_impl_server_config_set_mountpoint(config, mount_point); } +void wf_server_config_set_mountpoint_factory( + struct wf_server_config * config, + wf_create_mountpoint_fn * create_mountpoint, + void * user_data) +{ + wf_impl_server_config_set_mountpoint_factory( + config, create_mountpoint, user_data); +} + void wf_server_config_set_documentroot( struct wf_server_config * config, char const * document_root) diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 3cfcca7..e4a3435 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -1,6 +1,7 @@ #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/adapter/impl/operations.h" #include "webfuse/adapter/impl/session.h" +#include "webfuse/adapter/impl/mountpoint.h" #include "webfuse/core/string.h" @@ -27,58 +28,6 @@ static struct fuse_lowlevel_ops const filesystem_operations = .read = &wf_impl_operation_read }; -static char * wf_impl_filesystem_create_id(void) -{ - uuid_t uuid; - uuid_generate(uuid); - char id[UUID_STR_LEN]; - uuid_unparse(uuid, id); - - return strdup(id); -} - -static bool wf_impl_filesystem_is_link_broken(char const * path, char const * id) -{ - bool result = false; - - char buffer[UUID_STR_LEN]; - ssize_t count = readlink(path, buffer, UUID_STR_LEN); - if ((0 < count) && (count < UUID_STR_LEN)) - { - buffer[count] = '\0'; - result = (0 == strcmp(buffer, id)); - } - - return result; -} - -static bool wf_impl_filesystem_link_first_subdir( - char const * link_path, - char const * path) -{ - bool result = false; - DIR * dir = opendir(path); - if (NULL != dir) - { - struct dirent * entry = readdir(dir); - while (NULL != entry) - { - if ((DT_DIR == entry->d_type) && ('.' != entry->d_name[0])) - { - symlink(entry->d_name, link_path); - result = true; - break; - } - - entry = readdir(dir); - } - - closedir(dir); - } - - return result; -} - static void wf_impl_filesystem_cleanup( struct wf_impl_filesystem * filesystem) { @@ -90,32 +39,17 @@ static void wf_impl_filesystem_cleanup( free(filesystem->buffer.mem); fuse_opt_free_args(&filesystem->args); - rmdir(filesystem->root_path); - - if (wf_impl_filesystem_is_link_broken(filesystem->default_path, filesystem->id)) - { - unlink(filesystem->default_path); - - bool const success = wf_impl_filesystem_link_first_subdir(filesystem->default_path, filesystem->service_path); - if (!success) - { - rmdir(filesystem->service_path); - } - } - + wf_mountpoint_dispose(filesystem->mountpoint); free(filesystem->user_data.name); - free(filesystem->id); - free(filesystem->root_path); - free(filesystem->default_path); - free(filesystem->service_path); } static bool wf_impl_filesystem_init( struct wf_impl_filesystem * filesystem, struct wf_impl_session * session, - char const * name) + char const * name, + struct wf_mountpoint * mountpoint) { bool result = false; @@ -129,15 +63,7 @@ static bool wf_impl_filesystem_init( filesystem->user_data.name = strdup(name); memset(&filesystem->buffer, 0, sizeof(struct fuse_buf)); - filesystem->service_path = wf_create_string("%s/%s", session->mount_point, name); - mkdir(filesystem->service_path, 0755); - - filesystem->id = wf_impl_filesystem_create_id(); - filesystem->root_path = wf_create_string("%s/%s/%s", session->mount_point, name, filesystem->id); - mkdir(filesystem->root_path, 0755); - - filesystem->default_path = wf_create_string("%s/%s/default", session->mount_point, name); - symlink(filesystem->id, filesystem->default_path); + filesystem->mountpoint = mountpoint; filesystem->session = fuse_session_new( &filesystem->args, @@ -146,7 +72,8 @@ static bool wf_impl_filesystem_init( &filesystem->user_data); if (NULL != filesystem->session) { - result = (0 == fuse_session_mount(filesystem->session, filesystem->root_path)); + char const * path = wf_mountpoint_get_path(filesystem->mountpoint); + result = (0 == fuse_session_mount(filesystem->session, path)); } if (result) @@ -169,12 +96,13 @@ static bool wf_impl_filesystem_init( struct wf_impl_filesystem * wf_impl_filesystem_create( struct wf_impl_session * session, - char const * name) + char const * name, + struct wf_mountpoint * mountpoint) { struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem)); if (NULL != filesystem) { - bool success = wf_impl_filesystem_init(filesystem, session, name); + bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint); if (!success) { free(filesystem); diff --git a/lib/webfuse/adapter/impl/filesystem.h b/lib/webfuse/adapter/impl/filesystem.h index 648dfbd..83660d8 100644 --- a/lib/webfuse/adapter/impl/filesystem.h +++ b/lib/webfuse/adapter/impl/filesystem.h @@ -14,6 +14,7 @@ extern "C" { #endif +struct wf_mountpoint; struct wf_impl_session; struct lws; @@ -25,16 +26,13 @@ struct wf_impl_filesystem struct fuse_buf buffer; struct wf_impl_operations_context user_data; struct lws * wsi; - char * name; - char * id; - char * service_path; - char * default_path; - char * root_path; + struct wf_mountpoint * mountpoint; }; extern struct wf_impl_filesystem * wf_impl_filesystem_create( struct wf_impl_session * session, - char const * name); + char const * name, + struct wf_mountpoint * mountpoint); extern void wf_impl_filesystem_dispose( struct wf_impl_filesystem * filesystem); diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.c b/lib/webfuse/adapter/impl/mountpoint_factory.c new file mode 100644 index 0000000..54679ef --- /dev/null +++ b/lib/webfuse/adapter/impl/mountpoint_factory.c @@ -0,0 +1,67 @@ +#include "webfuse/adapter/impl/mountpoint_factory.h" +#include + +void +wf_impl_mountpoint_factory_init_default( + struct wf_impl_mountpoint_factory * factory) +{ + factory->create_mountpoint = NULL; + factory->user_data = NULL; + factory->dispose = NULL; +} + +void +wf_impl_mountpoint_factory_init( + struct wf_impl_mountpoint_factory * factory, + wf_create_mountpoint_fn * create_mountpoint, + void * user_data, + wf_impl_mountpoint_factory_dispose_fn * dispose) +{ + factory->create_mountpoint = create_mountpoint; + factory->user_data = user_data; + factory->dispose = dispose; +} + +void +wf_impl_mountpoint_factory_move( + struct wf_impl_mountpoint_factory * factory, + struct wf_impl_mountpoint_factory * other) +{ + other->create_mountpoint = factory->create_mountpoint; + other->user_data = factory->user_data; + other->dispose = factory->dispose; + + factory->create_mountpoint = NULL; + factory->dispose = NULL; + factory->user_data = NULL; +} + +bool +wf_impl_mountpoint_factory_isvalid( + struct wf_impl_mountpoint_factory * factory) +{ + return (NULL != factory->create_mountpoint); +} + +void +wf_impl_mountpoint_factory_cleanup( + struct wf_impl_mountpoint_factory * factory) +{ + if (NULL != factory->dispose) + { + factory->dispose(factory->user_data); + } + + factory->create_mountpoint = NULL; + factory->dispose = NULL; + factory->user_data = NULL; +} + +struct wf_mountpoint * +wf_impl_mountpoint_factory_create_mountpoint( + struct wf_impl_mountpoint_factory * factory, + char const * filesystem) +{ + return factory->create_mountpoint(filesystem, factory->user_data); +} + diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.h b/lib/webfuse/adapter/impl/mountpoint_factory.h new file mode 100644 index 0000000..98e5469 --- /dev/null +++ b/lib/webfuse/adapter/impl/mountpoint_factory.h @@ -0,0 +1,61 @@ +#ifndef WF_ADAPTER_IMPL_MOUNTPOINT_FACTORY_H +#define WF_ADAPTER_IMPL_MOUNTPOINT_FACTORY_H + +#include "webfuse/adapter/mountpoint_factory.h" +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef void +wf_impl_mountpoint_factory_dispose_fn( + void * user_data); + +struct wf_impl_mountpoint_factory +{ + wf_create_mountpoint_fn * create_mountpoint; + wf_impl_mountpoint_factory_dispose_fn * dispose; + void * user_data; +}; + +extern void +wf_impl_mountpoint_factory_init_default( + struct wf_impl_mountpoint_factory * factory); + +extern void +wf_impl_mountpoint_factory_init( + struct wf_impl_mountpoint_factory * factory, + wf_create_mountpoint_fn * create_mountpoint, + void * user_data, + wf_impl_mountpoint_factory_dispose_fn * dispose); + +extern void +wf_impl_mountpoint_factory_move( + struct wf_impl_mountpoint_factory * factory, + struct wf_impl_mountpoint_factory * other); + +extern bool +wf_impl_mountpoint_factory_isvalid( + struct wf_impl_mountpoint_factory * factory); + +extern void +wf_impl_mountpoint_factory_init_from( + struct wf_impl_mountpoint_factory * factory, + struct wf_impl_mountpoint_factory * other); + +extern void +wf_impl_mountpoint_factory_cleanup( + struct wf_impl_mountpoint_factory * factory); + +extern struct wf_mountpoint * +wf_impl_mountpoint_factory_create_mountpoint( + struct wf_impl_mountpoint_factory * factory, + char const * filesystem); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/server.c b/lib/webfuse/adapter/impl/server.c index 15e18f4..ad3e5c2 100644 --- a/lib/webfuse/adapter/impl/server.c +++ b/lib/webfuse/adapter/impl/server.c @@ -76,37 +76,17 @@ static struct lws_context * wf_impl_server_context_create( } -static bool wf_impl_server_check_mountpoint( - struct wf_server_config * config) -{ - bool result = false; - - if (NULL != config->mount_point) - { - struct stat info; - int const rc = stat(config->mount_point, &info); - result = ((0 == rc) && (S_ISDIR(info.st_mode))); - - if (!result) - { - result = (0 == mkdir(config->mount_point, 0755)); - } - } - - return result; -} - struct wf_server * wf_impl_server_create( struct wf_server_config * config) { struct wf_server * server = NULL; - if (wf_impl_server_check_mountpoint(config)) + if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory)) { server = malloc(sizeof(struct wf_server)); if (NULL != server) { - wf_impl_server_protocol_init(&server->protocol, config->mount_point); + wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory); wf_impl_server_config_clone(config, &server->config); wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); server->context = wf_impl_server_context_create(server); diff --git a/lib/webfuse/adapter/impl/server_config.c b/lib/webfuse/adapter/impl/server_config.c index 7098dac..2d9fc6d 100644 --- a/lib/webfuse/adapter/impl/server_config.c +++ b/lib/webfuse/adapter/impl/server_config.c @@ -1,4 +1,5 @@ #include "webfuse/adapter/impl/server_config.h" +#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" #include #include @@ -20,14 +21,15 @@ void wf_impl_server_config_init( memset(config, 0, sizeof(struct wf_server_config)); wf_impl_authenticators_init(&config->authenticators); + wf_impl_mountpoint_factory_init_default(&config->mountpoint_factory); } void wf_impl_server_config_cleanup( struct wf_server_config * config) { wf_impl_authenticators_cleanup(&config->authenticators); + wf_impl_mountpoint_factory_cleanup(&config->mountpoint_factory); - free(config->mount_point); free(config->document_root); free(config->key_path); free(config->cert_path); @@ -40,7 +42,6 @@ void wf_impl_server_config_clone( struct wf_server_config * config, struct wf_server_config * clone) { - clone->mount_point = wf_impl_server_config_strdup(config->mount_point); clone->document_root = wf_impl_server_config_strdup(config->document_root); clone->key_path = wf_impl_server_config_strdup(config->key_path); clone->cert_path = wf_impl_server_config_strdup(config->cert_path); @@ -48,6 +49,9 @@ void wf_impl_server_config_clone( clone->port = config->port; wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators); + + // ToDo: remove this: move is not clone :-/ + wf_impl_mountpoint_factory_move(&config->mountpoint_factory, &clone->mountpoint_factory); } struct wf_server_config * wf_impl_server_config_create(void) @@ -72,10 +76,20 @@ void wf_impl_server_config_set_mountpoint( struct wf_server_config * config, char const * mount_point) { - free(config->mount_point); - config->mount_point = strdup(mount_point); + wf_impl_uuid_mountpoint_factory_init(&config->mountpoint_factory, + mount_point); } +void wf_impl_server_config_set_mountpoint_factory( + struct wf_server_config * config, + wf_create_mountpoint_fn * create_mountpoint, + void * create_mountpoint_context) +{ + wf_impl_mountpoint_factory_init(&config->mountpoint_factory, + create_mountpoint, create_mountpoint_context, NULL); +} + + void wf_impl_server_config_set_documentroot( struct wf_server_config * config, char const * document_root) diff --git a/lib/webfuse/adapter/impl/server_config.h b/lib/webfuse/adapter/impl/server_config.h index 734c83a..48de4ed 100644 --- a/lib/webfuse/adapter/impl/server_config.h +++ b/lib/webfuse/adapter/impl/server_config.h @@ -2,6 +2,7 @@ #define WF_ADAPTER_IMPL_SERVER_CONFIG_H #include "webfuse/adapter/impl/authenticators.h" +#include "webfuse/adapter/impl/mountpoint_factory.h" #ifdef __cplusplus extern "C" { @@ -9,13 +10,13 @@ extern "C" { struct wf_server_config { - char * mount_point; char * document_root; char * key_path; char * cert_path; char * vhost_name; int port; struct wf_impl_authenticators authenticators; + struct wf_impl_mountpoint_factory mountpoint_factory; }; extern struct wf_server_config * wf_impl_server_config_create(void); @@ -37,6 +38,11 @@ extern void wf_impl_server_config_set_mountpoint( struct wf_server_config * config, char const * mount_point); +extern void wf_impl_server_config_set_mountpoint_factory( + struct wf_server_config * config, + wf_create_mountpoint_fn * create_mountpoint, + void * create_mountpoint_context); + extern void wf_impl_server_config_set_documentroot( struct wf_server_config * config, char const * document_root); diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 65f6047..02efd80 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -9,6 +9,7 @@ #include "webfuse/adapter/impl/credentials.h" #include "webfuse/adapter/impl/jsonrpc/request.h" +#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" static int wf_impl_server_protocol_callback( struct lws * wsi, @@ -38,9 +39,9 @@ static int wf_impl_server_protocol_callback( &protocol->session_manager, wsi, &protocol->authenticators, + &protocol->mountpoint_factory, &protocol->timeout_manager, - &protocol->server, - protocol->mount_point); + &protocol->server); if (NULL != session) { @@ -81,12 +82,34 @@ struct wf_server_protocol * wf_impl_server_protocol_create( struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol)); if (NULL != protocol) { - wf_impl_server_protocol_init(protocol, mount_point); + struct wf_impl_mountpoint_factory mountpoint_factory; + wf_impl_uuid_mountpoint_factory_init(&mountpoint_factory, mount_point); + + wf_impl_server_protocol_init(protocol, &mountpoint_factory); } return protocol; } +struct wf_server_protocol * wf_impl_server_protocol_create2( + wf_create_mountpoint_fn * create_mountpoint, + void * create_mountpoint_context) +{ + 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, + create_mountpoint, create_mountpoint_context, NULL); + + wf_impl_server_protocol_init(protocol, &mountpoint_factory); + } + + return protocol; + +} + + void wf_impl_server_protocol_dispose( struct wf_server_protocol * protocol) { @@ -203,14 +226,14 @@ static void wf_impl_server_protocol_add_filesystem( } - void wf_impl_server_protocol_init( struct wf_server_protocol * protocol, - char * mount_point) + struct wf_impl_mountpoint_factory * mountpoint_factory) { - protocol->mount_point = strdup(mount_point); protocol->is_operational = false; + wf_impl_mountpoint_factory_move(mountpoint_factory, &protocol->mountpoint_factory); + wf_impl_timeout_manager_init(&protocol->timeout_manager); wf_impl_session_manager_init(&protocol->session_manager); wf_impl_authenticators_init(&protocol->authenticators); @@ -223,13 +246,13 @@ void wf_impl_server_protocol_init( void wf_impl_server_protocol_cleanup( struct wf_server_protocol * protocol) { - free(protocol->mount_point); protocol->is_operational = false; wf_impl_jsonrpc_server_cleanup(&protocol->server); wf_impl_timeout_manager_cleanup(&protocol->timeout_manager); wf_impl_authenticators_cleanup(&protocol->authenticators); wf_impl_session_manager_cleanup(&protocol->session_manager); + wf_impl_mountpoint_factory_cleanup(&protocol->mountpoint_factory); } void wf_impl_server_protocol_add_authenticator( diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 8e4cd8d..16da34d 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -4,6 +4,7 @@ #include "webfuse/adapter/impl/jsonrpc/proxy.h" #include "webfuse/adapter/impl/time/timeout_manager.h" #include "webfuse/adapter/impl/authenticators.h" +#include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/session_manager.h" #include "webfuse/adapter/impl/jsonrpc/server.h" @@ -20,9 +21,9 @@ struct lws_protocols; struct wf_server_protocol { - char * mount_point; struct wf_impl_timeout_manager timeout_manager; struct wf_impl_authenticators authenticators; + struct wf_impl_mountpoint_factory mountpoint_factory; struct wf_impl_session_manager session_manager; struct wf_impl_jsonrpc_server server; bool is_operational; @@ -30,7 +31,7 @@ struct wf_server_protocol extern void wf_impl_server_protocol_init( struct wf_server_protocol * protocol, - char * mount_point); + struct wf_impl_mountpoint_factory * mountpoint_factory); extern void wf_impl_server_protocol_cleanup( struct wf_server_protocol * protocol); @@ -38,6 +39,10 @@ extern void wf_impl_server_protocol_cleanup( extern struct wf_server_protocol * wf_impl_server_protocol_create( char * mount_point); +extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create2( + wf_create_mountpoint_fn * create_mountpoint, + void * create_mountpoint_context); + extern void wf_impl_server_protocol_dispose( struct wf_server_protocol * protocol); diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index 82f9b80..fb2885a 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -5,6 +5,8 @@ #include "webfuse/adapter/impl/jsonrpc/proxy.h" #include "webfuse/adapter/impl/jsonrpc/request.h" #include "webfuse/adapter/impl/jsonrpc/response.h" +#include "webfuse/adapter/impl/mountpoint_factory.h" +#include "webfuse/adapter/impl/mountpoint.h" #include "webfuse/core/container_of.h" #include "webfuse/core/util.h" @@ -44,7 +46,7 @@ struct wf_impl_session * wf_impl_session_create( struct wf_impl_authenticators * authenticators, struct wf_impl_timeout_manager * timeout_manager, struct wf_impl_jsonrpc_server * server, - char const * mount_point) + struct wf_impl_mountpoint_factory * mountpoint_factory) { struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session)); @@ -52,11 +54,11 @@ struct wf_impl_session * wf_impl_session_create( { wf_slist_init(&session->filesystems); - session->mount_point = strdup(mount_point); session->wsi = wsi; session->is_authenticated = false; session->authenticators = authenticators; session->server = server; + session->mountpoint_factory = mountpoint_factory; wf_impl_jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); wf_slist_init(&session->messages); } @@ -88,8 +90,8 @@ void wf_impl_session_dispose( session->is_authenticated = false; session->wsi = NULL; session->authenticators = NULL; + session->mountpoint_factory = NULL; session->server = NULL; - free(session->mount_point); free(session); } @@ -106,9 +108,28 @@ bool wf_impl_session_add_filesystem( struct wf_impl_session * session, char const * name) { - struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session, name); - wf_slist_append(&session->filesystems, &filesystem->item); - return (NULL != filesystem); + bool result; + + struct wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(session->mountpoint_factory, name); + result = (NULL != mountpoint); + + if (result) + { + struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session, name, mountpoint); + wf_slist_append(&session->filesystems, &filesystem->item); + result = (NULL != filesystem); + } + + // cleanup on error + if (!result) + { + if (NULL != mountpoint) + { + wf_impl_mountpoint_dispose(mountpoint); + } + } + + return result; } diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h index cb1a19d..9f9b10a 100644 --- a/lib/webfuse/adapter/impl/session.h +++ b/lib/webfuse/adapter/impl/session.h @@ -24,16 +24,17 @@ struct lws; struct wf_message; struct wf_credentials; struct wf_impl_authenticators; +struct wf_impl_mountpoint_factory; struct wf_impl_timeout_manager; struct wf_impl_session { struct wf_slist_item item; - char * mount_point; struct lws * wsi; bool is_authenticated; struct wf_slist messages; struct wf_impl_authenticators * authenticators; + struct wf_impl_mountpoint_factory * mountpoint_factory; struct wf_impl_jsonrpc_server * server; struct wf_impl_jsonrpc_proxy rpc; struct wf_slist filesystems; @@ -44,7 +45,7 @@ extern struct wf_impl_session * wf_impl_session_create( struct wf_impl_authenticators * authenticators, struct wf_impl_timeout_manager * timeout_manager, struct wf_impl_jsonrpc_server * server, - char const * mount_point); + struct wf_impl_mountpoint_factory * mountpoint_factory); extern void wf_impl_session_dispose( struct wf_impl_session * session); diff --git a/lib/webfuse/adapter/impl/session_manager.c b/lib/webfuse/adapter/impl/session_manager.c index a48489b..0574c98 100644 --- a/lib/webfuse/adapter/impl/session_manager.c +++ b/lib/webfuse/adapter/impl/session_manager.c @@ -27,12 +27,12 @@ struct wf_impl_session * wf_impl_session_manager_add( struct wf_impl_session_manager * manager, struct lws * wsi, struct wf_impl_authenticators * authenticators, + struct wf_impl_mountpoint_factory * mountpoint_factory, struct wf_impl_timeout_manager * timeout_manager, - struct wf_impl_jsonrpc_server * server, - char const * mount_point) + struct wf_impl_jsonrpc_server * server) { struct wf_impl_session * session = wf_impl_session_create( - wsi, authenticators, timeout_manager, server, mount_point); + wsi, authenticators, timeout_manager, server, mountpoint_factory); if (NULL != session) { wf_slist_append(&manager->sessions, &session->item); diff --git a/lib/webfuse/adapter/impl/session_manager.h b/lib/webfuse/adapter/impl/session_manager.h index bfe4aa3..25b4367 100644 --- a/lib/webfuse/adapter/impl/session_manager.h +++ b/lib/webfuse/adapter/impl/session_manager.h @@ -33,9 +33,9 @@ extern struct wf_impl_session * wf_impl_session_manager_add( struct wf_impl_session_manager * manager, struct lws * wsi, struct wf_impl_authenticators * authenticators, + struct wf_impl_mountpoint_factory * mountpoint_factory, struct wf_impl_timeout_manager * timeout_manager, - struct wf_impl_jsonrpc_server * server, - char const * mount_point); + struct wf_impl_jsonrpc_server * server); extern struct wf_impl_session * wf_impl_session_manager_get( struct wf_impl_session_manager * manager, diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c index 1f28e64..3b4d543 100644 --- a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c +++ b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c @@ -15,8 +15,8 @@ struct wf_impl_uuid_mountpoint_factory bool root_created; }; -void * -wf_impl_uuid_mountpoint_factory_create( +static void * +wf_impl_uuid_mountpoint_factory_create_context( char const * root_path) { struct wf_impl_uuid_mountpoint_factory * factory = NULL; @@ -37,11 +37,10 @@ wf_impl_uuid_mountpoint_factory_create( factory->root_created = root_created; } - return factory; } -void +static void wf_impl_uuid_mountpoint_factory_dispose( void * user_data) { @@ -56,7 +55,7 @@ wf_impl_uuid_mountpoint_factory_dispose( free(factory); } -struct wf_mountpoint * +static struct wf_mountpoint * wf_impl_uuid_mountpoint_factory_create_mountpoint( char const * filesystem, void * user_data) @@ -65,3 +64,21 @@ wf_impl_uuid_mountpoint_factory_create_mountpoint( return wf_impl_uuid_mountpoint_create(factory->root_path, filesystem); } + +bool +wf_impl_uuid_mountpoint_factory_init( + struct wf_impl_mountpoint_factory * factory, + char const * root_path) +{ + void * context = wf_impl_uuid_mountpoint_factory_create_context(root_path); + bool const result = (NULL != context); + + if (result) + { + factory->create_mountpoint = &wf_impl_uuid_mountpoint_factory_create_mountpoint; + factory->user_data = context; + factory->dispose = &wf_impl_uuid_mountpoint_factory_dispose; + } + + return result; +} diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h index 52d5c57..eed8fa0 100644 --- a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h +++ b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h @@ -1,27 +1,19 @@ #ifndef WF_IMPL_UUID_MOUNTPOINT_FACTORY_H #define WF_IMPL_UUID_MOUNTPOINT_FACTORY_H +#include "webfuse/adapter/impl/mountpoint_factory.h" +#include + #ifdef __cplusplus extern "C" { #endif -struct wf_mountpoint; - -extern void * -wf_impl_uuid_mountpoint_factory_create( +extern bool +wf_impl_uuid_mountpoint_factory_init( + struct wf_impl_mountpoint_factory * factory, char const * root_path); -extern void -wf_impl_uuid_mountpoint_factory_dispose( - void * user_data); - -extern struct wf_mountpoint * -wf_impl_uuid_mountpoint_factory_create_mountpoint( - char const * filesystem, - void * user_data); - - #ifdef __cplusplus } #endif diff --git a/test/adapter/test_uuid_mountpoint_factory.cc b/test/adapter/test_uuid_mountpoint_factory.cc index abb0b27..b097ae0 100644 --- a/test/adapter/test_uuid_mountpoint_factory.cc +++ b/test/adapter/test_uuid_mountpoint_factory.cc @@ -11,19 +11,19 @@ TEST(uuid_mountpoint_factory, create_existing_dir) { TempDir temp("uuid_mountpoint_factory"); - void * factory = wf_impl_uuid_mountpoint_factory_create(temp.path()); - ASSERT_NE(nullptr, factory); + struct wf_impl_mountpoint_factory factory; + bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, temp.path()); + ASSERT_TRUE(factory_created); ASSERT_TRUE(is_dir(temp.path())); - wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory); + wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy"); std::string path = wf_mountpoint_get_path(mountpoint); - ASSERT_NE(nullptr, factory); ASSERT_TRUE(is_dir(path)); wf_mountpoint_dispose(mountpoint); ASSERT_FALSE(is_dir(path)); - wf_impl_uuid_mountpoint_factory_dispose(factory); + wf_impl_mountpoint_factory_cleanup(&factory); // keep dir not created by factory ASSERT_TRUE(is_dir(temp.path())); } @@ -33,19 +33,19 @@ TEST(uuid_mountpoint_factory, create_nonexisting_dir) TempDir temp("uuid_mountpoint_factory"); std::string root_path = std::string(temp.path()) + "/root"; - void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str()); - ASSERT_NE(nullptr, factory); + struct wf_impl_mountpoint_factory factory; + bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str()); + ASSERT_TRUE(factory_created); ASSERT_TRUE(is_dir(root_path)); - wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory); + wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy"); std::string path = wf_mountpoint_get_path(mountpoint); - ASSERT_NE(nullptr, factory); ASSERT_TRUE(is_dir(path)); wf_mountpoint_dispose(mountpoint); ASSERT_FALSE(is_dir(path)); - wf_impl_uuid_mountpoint_factory_dispose(factory); + wf_impl_mountpoint_factory_cleanup(&factory); // remove dir, created by factory ASSERT_FALSE(is_dir(root_path)); } @@ -55,6 +55,7 @@ TEST(uuid_mountpoint_factory, fail_to_created_nested_dir) TempDir temp("uuid_mountpoint_factory"); std::string root_path = std::string(temp.path()) + "/nested/root"; - void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str()); - ASSERT_EQ(nullptr, factory); + struct wf_impl_mountpoint_factory factory; + bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str()); + ASSERT_FALSE(factory_created); } \ No newline at end of file From ae9fb639009b8d780de42b6c1520d7988b7cb5a3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 16 Feb 2020 21:38:37 +0100 Subject: [PATCH 040/138] fix: made c'tor explicit --- test/tempdir.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tempdir.hpp b/test/tempdir.hpp index 0c28a80..6a03fc5 100644 --- a/test/tempdir.hpp +++ b/test/tempdir.hpp @@ -9,7 +9,7 @@ class TempDir TempDir(TempDir const &) = delete; TempDir & operator=(TempDir const &) = delete; public: - TempDir(char const * prefix); + explicit TempDir(char const * prefix); ~TempDir(); char const * path(); private: From bc1b5343df2f3d301beb5a9a6ce0e295426281e7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 16 Feb 2020 22:36:31 +0100 Subject: [PATCH 041/138] added unit tests for server_config --- cmake/unit_tests.cmake | 1 + test/adapter/test_server_config.cc | 175 +++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 test/adapter/test_server_config.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 933d78e..b49cca9 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -23,6 +23,7 @@ add_executable(alltests test/core/test_message_queue.cc test/adapter/test_response_parser.cc test/adapter/test_server.cc + test/adapter/test_server_config.cc test/adapter/test_timepoint.cc test/adapter/test_timer.cc test/adapter/test_credentials.cc diff --git a/test/adapter/test_server_config.cc b/test/adapter/test_server_config.cc new file mode 100644 index 0000000..5a03f5c --- /dev/null +++ b/test/adapter/test_server_config.cc @@ -0,0 +1,175 @@ +#include +#include "webfuse/adapter/server_config.h" +#include "webfuse/adapter/impl/server_config.h" +#include "webfuse/adapter/impl/authenticator.h" +#include "tempdir.hpp" + +using webfuse_test::TempDir; + +namespace +{ + +wf_mountpoint * create_mountpoint( + char const * filesystem, + void * user_data) +{ + (void) filesystem; + (void) user_data; + + return nullptr; +} + +bool authenticate( + wf_credentials * credentials, + void * user_data) +{ + (void) credentials; + (void) user_data; + + return false; +} + +} + + +TEST(server_config, create_dispose) +{ + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + + wf_server_config_dispose(config); +} + +TEST(server_config, set_documentroot) +{ + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + + ASSERT_EQ(nullptr, config->document_root); + + wf_server_config_set_documentroot(config, "www"); + ASSERT_STREQ("www", config->document_root); + + wf_server_config_set_documentroot(config, "/var/www"); + ASSERT_STREQ("/var/www", config->document_root); + + wf_server_config_dispose(config); +} + +TEST(server_config, set_keypath) +{ + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + + ASSERT_EQ(nullptr, config->key_path); + + wf_server_config_set_keypath(config, "key.pem"); + ASSERT_STREQ("key.pem", config->key_path); + + wf_server_config_set_keypath(config, "pki/self/key.pem"); + ASSERT_STREQ("pki/self/key.pem", config->key_path); + + wf_server_config_dispose(config); +} + +TEST(server_config, set_certpath) +{ + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + + ASSERT_EQ(nullptr, config->key_path); + + wf_server_config_set_certpath(config, "cert.pem"); + ASSERT_STREQ("cert.pem", config->cert_path); + + wf_server_config_set_certpath(config, "pki/self/cert.pem"); + ASSERT_STREQ("pki/self/cert.pem", config->cert_path); + + wf_server_config_dispose(config); +} + +TEST(server_config, set_vhostname) +{ + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + + ASSERT_EQ(nullptr, config->key_path); + + wf_server_config_set_vhostname(config, "webfuse"); + ASSERT_STREQ("webfuse", config->vhost_name); + + wf_server_config_set_vhostname(config, "localhost"); + ASSERT_STREQ("localhost", config->vhost_name); + + wf_server_config_dispose(config); +} + +TEST(server_config, set_port) +{ + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + + ASSERT_EQ(0, config->port); + + wf_server_config_set_port(config, 8443); + ASSERT_EQ(8443, config->port); + + wf_server_config_set_port(config, 8080); + ASSERT_EQ(8080, config->port); + + wf_server_config_dispose(config); +} + +TEST(server_config, set_mountpoint) +{ + TempDir temp("server_config"); + + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint); + ASSERT_EQ(nullptr, config->mountpoint_factory.user_data); + ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); + + wf_server_config_set_mountpoint(config, temp.path()); + ASSERT_NE(nullptr, config->mountpoint_factory.create_mountpoint); + ASSERT_NE(nullptr, config->mountpoint_factory.user_data); + ASSERT_NE(nullptr, config->mountpoint_factory.dispose); + + wf_server_config_dispose(config); +} + +TEST(server_cnfig, set_mounpoint_factory) +{ + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint); + ASSERT_EQ(nullptr, config->mountpoint_factory.user_data); + ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); + + int value = 42; + void * user_data = reinterpret_cast(&value); + wf_server_config_set_mountpoint_factory(config, &create_mountpoint, user_data); + ASSERT_NE(&create_mountpoint, config->mountpoint_factory.create_mountpoint); + ASSERT_EQ(user_data, config->mountpoint_factory.user_data); + ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); + + wf_server_config_dispose(config); +} + +TEST(server_config, add_authenticator) +{ + wf_server_config * config = wf_server_config_create(); + ASSERT_NE(nullptr, config); + ASSERT_EQ(nullptr, config->authenticators.first); + + int value = 42; + void * user_data = reinterpret_cast(&value); + wf_server_config_add_authenticator(config, "username", &authenticate, user_data); + + wf_impl_authenticator * authenticator = config->authenticators.first; + ASSERT_STREQ("username", authenticator->type); + ASSERT_EQ(&authenticate, authenticator->authenticate); + ASSERT_EQ(user_data, authenticator->user_data); + + wf_server_config_dispose(config); +} \ No newline at end of file From 8f40f73072817dfe1f59487dd819ac44f28f4668 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 16 Feb 2020 22:58:28 +0100 Subject: [PATCH 042/138] fixed test expectation --- test/adapter/test_server_config.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/adapter/test_server_config.cc b/test/adapter/test_server_config.cc index 5a03f5c..cb176d6 100644 --- a/test/adapter/test_server_config.cc +++ b/test/adapter/test_server_config.cc @@ -138,7 +138,7 @@ TEST(server_config, set_mountpoint) wf_server_config_dispose(config); } -TEST(server_cnfig, set_mounpoint_factory) +TEST(server_config, set_mounpoint_factory) { wf_server_config * config = wf_server_config_create(); ASSERT_NE(nullptr, config); @@ -149,7 +149,7 @@ TEST(server_cnfig, set_mounpoint_factory) int value = 42; void * user_data = reinterpret_cast(&value); wf_server_config_set_mountpoint_factory(config, &create_mountpoint, user_data); - ASSERT_NE(&create_mountpoint, config->mountpoint_factory.create_mountpoint); + ASSERT_EQ(&create_mountpoint, config->mountpoint_factory.create_mountpoint); ASSERT_EQ(user_data, config->mountpoint_factory.user_data); ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); From 7b8616fcb394c665435313c46f26233176a89a48 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 17 Feb 2020 21:53:42 +0100 Subject: [PATCH 043/138] added API documentation --- .gitignore | 1 + Doxyfile | 331 +++++++++++++++++++ include/webfuse/adapter/api.h | 16 + include/webfuse/adapter/authenticate.h | 18 + include/webfuse/adapter/credentials.h | 48 +++ include/webfuse/adapter/mountpoint.h | 54 ++- include/webfuse/adapter/mountpoint_factory.h | 15 + include/webfuse/adapter/server.h | 32 ++ include/webfuse/adapter/server_config.h | 114 ++++++- include/webfuse/adapter/server_protocol.h | 68 ++++ include/webfuse/core/status.h | 22 +- include/webfuse/provider/api.h | 16 + include/webfuse/provider/client.h | 57 ++++ include/webfuse/provider/client_config.h | 149 ++++++++- include/webfuse/provider/client_protocol.h | 50 +++ include/webfuse/provider/dirbuffer.h | 28 ++ include/webfuse/provider/operation/close.h | 15 + include/webfuse/provider/operation/error.h | 14 + include/webfuse/provider/operation/getattr.h | 24 ++ include/webfuse/provider/operation/lookup.h | 25 ++ include/webfuse/provider/operation/open.h | 25 ++ include/webfuse/provider/operation/read.h | 34 +- include/webfuse/provider/operation/readdir.h | 27 ++ include/webfuse/provider/static_filesystem.h | 38 +++ include/webfuse_adapter.h | 5 + include/webfuse_provider.h | 5 + 26 files changed, 1215 insertions(+), 16 deletions(-) create mode 100644 Doxyfile diff --git a/.gitignore b/.gitignore index 95be7aa..3aba301 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.build/ /.deps/ /.settings/language.settings.xml +/doc/api diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..7c48a25 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,331 @@ +# Doxyfile 1.8.13 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = "webfuse" +PROJECT_NUMBER = 0.2.0 +PROJECT_BRIEF = "Websocket filesystem based on libfuse" +PROJECT_LOGO = +OUTPUT_DIRECTORY = "doc/api" +CREATE_SUBDIRS = NO +ALLOW_UNICODE_NAMES = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 4 +ALIASES = +TCL_SUBST = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +MARKDOWN_SUPPORT = YES +TOC_INCLUDE_HEADINGS = 0 +AUTOLINK_SUPPORT = YES +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +GROUP_NESTED_COMPOUNDS = NO +SUBGROUPING = YES +INLINE_GROUPED_CLASSES = NO +INLINE_SIMPLE_STRUCTS = NO +TYPEDEF_HIDES_STRUCT = NO +LOOKUP_CACHE_SIZE = 0 +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = NO +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +HIDE_COMPOUND_REFERENCE= NO +SHOW_INCLUDE_FILES = YES +SHOW_GROUPED_MEMB_INC = NO +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_MEMBERS_CTORS_1ST = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +STRICT_PROTO_MATCHING = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = +CITE_BIB_FILES = +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_AS_ERROR = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = README.md include +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.h +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = +USE_MDFILE_AS_MAINPAGE = README.md +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = NO +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +SOURCE_TOOLTIPS = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +CLANG_ASSISTED_PARSING = NO +CLANG_OPTIONS = +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = wf_ wfp_ +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_EXTRA_STYLESHEET = +HTML_EXTRA_FILES = +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_GAMMA = 80 +HTML_TIMESTAMP = NO +HTML_DYNAMIC_SECTIONS = NO +HTML_INDEX_NUM_ENTRIES = 100 +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +DOCSET_PUBLISHER_ID = org.doxygen.Publisher +DOCSET_PUBLISHER_NAME = Publisher +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +GENERATE_QHP = NO +QCH_FILE = +QHP_NAMESPACE = org.doxygen.Project +QHP_VIRTUAL_FOLDER = doc +QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = +QHG_LOCATION = +GENERATE_ECLIPSEHELP = NO +ECLIPSE_DOC_ID = org.doxygen.Project +DISABLE_INDEX = NO +GENERATE_TREEVIEW = NO +ENUM_VALUES_PER_LINE = 4 +TREEVIEW_WIDTH = 250 +EXT_LINKS_IN_WINDOW = NO +FORMULA_FONTSIZE = 10 +FORMULA_TRANSPARENT = YES +USE_MATHJAX = NO +MATHJAX_FORMAT = HTML-CSS +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +MATHJAX_EXTENSIONS = +MATHJAX_CODEFILE = +SEARCHENGINE = YES +SERVER_BASED_SEARCH = NO +EXTERNAL_SEARCH = NO +SEARCHENGINE_URL = +SEARCHDATA_FILE = searchdata.xml +EXTERNAL_SEARCH_ID = +EXTRA_SEARCH_MAPPINGS = +#--------------------------------------------------------------------------- +# Configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4 +EXTRA_PACKAGES = +LATEX_HEADER = +LATEX_FOOTER = +LATEX_EXTRA_STYLESHEET = +LATEX_EXTRA_FILES = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +LATEX_SOURCE_CODE = NO +LATEX_BIB_STYLE = plain +LATEX_TIMESTAMP = NO +#--------------------------------------------------------------------------- +# Configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +RTF_SOURCE_CODE = NO +#--------------------------------------------------------------------------- +# Configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_SUBDIR = +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# Configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# Configuration options related to the DOCBOOK output +#--------------------------------------------------------------------------- +GENERATE_DOCBOOK = NO +DOCBOOK_OUTPUT = docbook +DOCBOOK_PROGRAMLISTING = NO +#--------------------------------------------------------------------------- +# Configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# Configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration options related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +EXTERNAL_PAGES = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +DIA_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = YES +DOT_NUM_THREADS = 0 +DOT_FONTNAME = Helvetica +DOT_FONTSIZE = 10 +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +UML_LIMIT_NUM_FIELDS = 10 +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +INTERACTIVE_SVG = NO +DOT_PATH = +DOTFILE_DIRS = +MSCFILE_DIRS = +DIAFILE_DIRS = +PLANTUML_JAR_PATH = +PLANTUML_CFG_FILE = +PLANTUML_INCLUDE_PATH = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES diff --git a/include/webfuse/adapter/api.h b/include/webfuse/adapter/api.h index 5d00900..6ab7d30 100644 --- a/include/webfuse/adapter/api.h +++ b/include/webfuse/adapter/api.h @@ -1,10 +1,26 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file adapter/api.h +/// \brief API define for webfuse adapter. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_API_H #define WF_ADAPTER_API_H +//------------------------------------------------------------------------------ +/// \def WF_API +/// \brief Marks public symbols of libwebfuse_adapter. +//------------------------------------------------------------------------------ #ifndef WF_API #define WF_API #endif +//------------------------------------------------------------------------------ +/// \def WF_EXPORT +/// \brief Marks exported symbols as visible. +/// +/// Set WF_API to WF_EXPORT when building libwebfuse_adapter.so to export +/// public symbols. +//------------------------------------------------------------------------------ #ifndef WF_EXPORT #ifdef __GNUC__ #define WF_EXPORT __attribute__ ((visibility ("default"))) diff --git a/include/webfuse/adapter/authenticate.h b/include/webfuse/adapter/authenticate.h index e9113a6..e11e300 100644 --- a/include/webfuse/adapter/authenticate.h +++ b/include/webfuse/adapter/authenticate.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file adapter/authenticate.h +/// \brief Authenticate function. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_AUTHENTICATE_H #define WF_ADAPTER_AUTHENTICATE_H @@ -12,6 +17,19 @@ extern "C" struct wf_credentials; +//------------------------------------------------------------------------------ +/// \brief Authentication function type. +/// +/// Functions of this type are used to authenticate a user by some provided +/// credentials. +/// +/// \param credentials credentials to authenticate the user +/// \param user_data context of the authentication function +/// \return true, if authentication was successful, false otherwise +/// +/// \see wf_server_config_add_authenticator +/// \see wf_server_protocol_add_authenticator +//------------------------------------------------------------------------------ typedef bool wf_authenticate_fn( struct wf_credentials * credentials, void * user_data); diff --git a/include/webfuse/adapter/credentials.h b/include/webfuse/adapter/credentials.h index 82a8094..e3e65fc 100644 --- a/include/webfuse/adapter/credentials.h +++ b/include/webfuse/adapter/credentials.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file adapter/credentials.h +/// \brief Credentials used for user authentication. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_CREDENTIALS_H #define WF_ADAPTER_CREDENTIALS_H @@ -8,11 +13,54 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wf_credentials +/// \brief Credentials used for user authentication. +/// +/// Credentials are used during authentication to authenticate a user. +/// In order to support multiple types of credentials, e.g. username + password, +/// certifactes and / or authentication tokens, credentials are modelled as +/// opaque type with some access functions. +/// +/// \see wf_authenticate_fn +/// \see wf_credentials_type +/// \see wf_credentials_get +//------------------------------------------------------------------------------ struct wf_credentials; +//------------------------------------------------------------------------------ +/// \brief Returns the type of the credentials object. +/// +/// The type of the credentials objects defines, which keys are available +/// for a given instance. +/// +/// \note When an authenticate function is called, the credentials type +/// matches the type provided during _add_authenticator function call. +/// Therefore, it is not necessary to check credentials type within +/// the authenticate function. +/// +/// \note Within webfuse protocol documentation, only one type of credentials +/// is described byte now: username +/// +/// \param credentials Pointer to credentials object +/// \return type of the credentials object +/// +/// \see wf_server_config_add_authenticator +/// \see wf_server_protocol_add_authenticator +/// \see wf_authenticate_fn +//------------------------------------------------------------------------------ extern WF_API char const * wf_credentials_type( struct wf_credentials const * credentials); +//------------------------------------------------------------------------------ +/// \brief Return the value of a credentials item identified by the provided +/// key. +/// +/// \param credentials Pointer to credentials object. +/// \param key String to identify the item. +/// \return value of credentials item or null, if there is no item with that +/// key +//------------------------------------------------------------------------------ extern WF_API char const * wf_credentials_get( struct wf_credentials const * credentials, char const * key); diff --git a/include/webfuse/adapter/mountpoint.h b/include/webfuse/adapter/mountpoint.h index 62f59f3..9b77165 100644 --- a/include/webfuse/adapter/mountpoint.h +++ b/include/webfuse/adapter/mountpoint.h @@ -1,30 +1,76 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file adapter/mountpoint.h +/// \brief Mointpoint. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_MOUNTPOINT_H #define WF_ADAPTER_MOUNTPOINT_H +#include + #ifdef __cplusplus extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wf_mountpoint +/// \brief Mointpoint. +//------------------------------------------------------------------------------ struct wf_mountpoint; +//------------------------------------------------------------------------------ +/// \brief Disposes the user defined context of a mountpoint. +/// +/// \param user_data user defined context of the mointpoint. +/// +/// \see wf_mountpoint_set_userdata +//------------------------------------------------------------------------------ typedef void wf_mountpoint_userdata_dispose_fn( void * user_data); -extern struct wf_mountpoint * +//------------------------------------------------------------------------------ +/// \brief Creates a mountpoint. +/// +/// \param path local path of the mounpoint +/// \return Newly created mountpoint. +//------------------------------------------------------------------------------ +extern WF_API struct wf_mountpoint * wf_mountpoint_create( char const * path); -extern void +//------------------------------------------------------------------------------ +/// \brief Disposes a mountpoint. +/// +/// \param mountpoint pointer to the mountpoint +//------------------------------------------------------------------------------ +extern WF_API void wf_mountpoint_dispose( struct wf_mountpoint * mountpoint); -extern char const * +//------------------------------------------------------------------------------ +/// \brief Returns the local path of the mountpoint. +/// +/// \param mountpoint pointer to the mountpoint +/// \return local path of the mountpoint +//------------------------------------------------------------------------------ +extern WF_API char const * wf_mountpoint_get_path( struct wf_mountpoint const * mountpoint); -extern void +//------------------------------------------------------------------------------ +/// \brief Sets user data of the mointpoint. +/// +/// \note This function is intended for custom mountpoint factories to +/// annotate mountpoints with a user specified context. +/// +/// \param mounpoint pointer to the mountpoint +/// \param user_data user data +/// \param dispose pointer to dipose function of user data or NULL, +/// if there is no need to dispose user data +//------------------------------------------------------------------------------ +extern WF_API void wf_mountpoint_set_userdata( struct wf_mountpoint * mointpoint, void * user_data, diff --git a/include/webfuse/adapter/mountpoint_factory.h b/include/webfuse/adapter/mountpoint_factory.h index a265c6f..8a69821 100644 --- a/include/webfuse/adapter/mountpoint_factory.h +++ b/include/webfuse/adapter/mountpoint_factory.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file adapter/mountpoint_factory.h +/// \brief Defines a factory function to create mointpoints. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_MOUNTPOINT_FACTORY_H #define WF_ADAPTER_MOUNTPOINT_FACTORY_H @@ -10,6 +15,16 @@ extern "C" struct wf_mountpoint; +//------------------------------------------------------------------------------ +/// \brief Factory function to create mountpoints. +/// +/// \param filesystem name the filesystem +/// \param user_data context of the factory +/// \return newly created mountpoint or NULL, on error +/// +/// \see wf_server_config_set_mountpoint_factory +/// \see wf_server_protocol_create2 +//------------------------------------------------------------------------------ typedef struct wf_mountpoint * wf_create_mountpoint_fn( char const * filesystem, diff --git a/include/webfuse/adapter/server.h b/include/webfuse/adapter/server.h index 8a6a3a1..8e392ac 100644 --- a/include/webfuse/adapter/server.h +++ b/include/webfuse/adapter/server.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file adapter/server.h +/// \brief Adapter server. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_SERVER_H #define WF_ADAPTER_SERVER_H @@ -8,15 +13,42 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wf_server +/// \brief Webfuse adapter server object. +//------------------------------------------------------------------------------ struct wf_server; + struct wf_server_config; +//------------------------------------------------------------------------------ +/// \brief Creates a new server. +/// +/// \param config pointer to server configuration. +/// \return newly created server or NULL in case of an error +//------------------------------------------------------------------------------ extern WF_API struct wf_server * wf_server_create( struct wf_server_config * config); +//------------------------------------------------------------------------------ +/// \brief Disposes a server. +/// +/// \note server configuration is not managed by server. +/// +/// \param server pointer to server +//------------------------------------------------------------------------------ extern WF_API void wf_server_dispose( struct wf_server * server); +//------------------------------------------------------------------------------ +/// \brief Triggers the server. +/// +/// This function must be invoked in a loop while the server is running. It +/// makes the server wait for the next event and processes it. +/// +/// \param server pointer to server +/// \param timeout_ms timeout in milliseconds. +//------------------------------------------------------------------------------ extern WF_API void wf_server_service( struct wf_server * server, int timeout_ms); diff --git a/include/webfuse/adapter/server_config.h b/include/webfuse/adapter/server_config.h index 778cc8c..83a1c34 100644 --- a/include/webfuse/adapter/server_config.h +++ b/include/webfuse/adapter/server_config.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file adapter/server_config.h +/// \brief Server configuration. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_SERVER_CONFIG_H #define WF_ADAPTER_SERVER_CONFIG_H @@ -10,48 +15,153 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wf_server_config +/// \brief Holds configuration of webfuse adapter server. +//------------------------------------------------------------------------------ struct wf_server_config; +//------------------------------------------------------------------------------ +/// \brief Creates a new server configuration. +/// +/// \return newly created server configuration +//------------------------------------------------------------------------------ extern WF_API struct wf_server_config * wf_server_config_create(void); +//------------------------------------------------------------------------------ +/// \brief Disposes a server configuration. +/// +/// \note Contexts of mounpoint factory and added authenticators are not +/// disposed by default. +/// +/// \param config pointer of configuration object +/// +/// \see wf_server_config_set_mountpoint_factory +/// \see wf_server_config_add_authenticator +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_dispose( struct wf_server_config * config); +//------------------------------------------------------------------------------ +/// \brief Sets a mountpoint path. +/// \deprecated This function will be removed soon. Use \ref +/// wf_server_config_set_mountpoint_factory instead. +/// +/// Sets the root path of UUID-based file system. +/// +/// \note A valid configuration needs either a mountpoint or a mounpoint +/// factory. +/// +/// \param config pointer of configuration object +/// \param mount_point root path of UUID-based file system. +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_set_mountpoint( struct wf_server_config * config, char const * mount_point); +//------------------------------------------------------------------------------ +/// \brief Sets the mountpoint factory of the configuration. +/// +/// The mountpoint factory is called when a authenticated user adds a +/// filesystem. +/// +/// \note The user is responsible to manage the lifetime of the mountpoint +/// factory. +/// +/// \note A valid configuration needs either a mountpoint or a mounpoint +/// factory. +/// +/// \param config pointer of configuration object +/// \param create_mountpoint factory function to create a mountpoint +/// \param user_data context of mountpoint factory +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_set_mountpoint_factory( struct wf_server_config * config, wf_create_mountpoint_fn * create_mountpoint, void * user_data); +//------------------------------------------------------------------------------ +/// \brief Sets the path of HTTP servers root context. +/// +/// Webfuse adapter server is capable of serving static HTTP context. This +/// function is used to specify the path of HTTP servers root context. +/// If not specified, no HTTP content is served. +/// +/// \param config pointer of configuration object +/// \param document_root path to static HTTP content +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_set_documentroot( struct wf_server_config * config, char const * document_root); +//------------------------------------------------------------------------------ +/// \brief Sets the path to the servers private key. +/// +/// \note To enable TLS, private key and server certificate must be set. +/// Otherwise, only plain HTTP is supported. +/// +/// \param config pointer of configuration object +/// \param key_path path to servers private key (pem file) +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_set_keypath( struct wf_server_config * config, char const * key_path); +//------------------------------------------------------------------------------ +/// \brief Sets path to servers certificate. +/// +/// \note To enable TLS, private key and server certificate must be set. +/// Otherwise, only plain HTTP is supported. +/// +/// \param config pointer of configuration object +/// \param cert_path path to servers certificate (pem file) +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_set_certpath( struct wf_server_config * config, char const * cert_path); +//------------------------------------------------------------------------------ +/// \brief Sets the virtual hostname of the websockets server. +/// +/// \param config pointer of configuration object +/// \param vhost_name virtual hostname of the websockets server +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_set_vhostname( struct wf_server_config * config, char const * vhost_name); +//------------------------------------------------------------------------------ +/// \brief Sets the port number of the websockets server. +/// +/// \param config pointer of configuration object +/// \param port port number of the websockets server +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_set_port( struct wf_server_config * config, int port); +//------------------------------------------------------------------------------ +/// \brief Adds an authenticator. +/// +/// Authenticators are used to authenticate users by some provided credentials. +/// Multiple providers can be specified to support different types of +/// credentials. +/// +/// \note Adding multiple providers for the same credentials type results +/// in undefined behavior. +/// +/// \note The user is responsible to manage the lifetime of user data. +/// +/// \param config pointer to configuration object +/// \param type type of the credentials the authenticator supports +/// \param authenticate function called to authenticate a user +/// \param user_data context of authenticate function +//------------------------------------------------------------------------------ extern WF_API void wf_server_config_add_authenticator( struct wf_server_config * config, char const * type, wf_authenticate_fn * authenticate, - void * user_data -); + void * user_data); #ifdef __cplusplus } diff --git a/include/webfuse/adapter/server_protocol.h b/include/webfuse/adapter/server_protocol.h index 6491a05..8808669 100644 --- a/include/webfuse/adapter/server_protocol.h +++ b/include/webfuse/adapter/server_protocol.h @@ -1,3 +1,13 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file adapter/server_protocol.h +/// \brief Provides low level access to libwebsockets protocol. +/// +/// By default, libwebfuse encapsulates libwebsockets protocol by \ref +/// wf_server. But sometimes it might come in handy to have access to +/// libwebsockets protocol. This allows to integrate libwebfuse in existing +/// libwebsockets applications. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_SERVER_PROTOCOL_H #define WF_ADAPTER_SERVER_PROTOCOL_H @@ -10,23 +20,81 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wf_server_protocol +/// \brief Opaque webfuse server protocol. +//------------------------------------------------------------------------------ struct wf_server_protocol; + +//------------------------------------------------------------------------------ +/// \struct lws_protocols +/// \brief Forward declaration of libwebsockets protocols structure. +//------------------------------------------------------------------------------ struct lws_protocols; +//------------------------------------------------------------------------------ +/// \brief Creates a new protocol with a given mounpoint. +/// \deprecated This function will be removed soon. Use \ref +/// wf_server_protocol_create2 instead. +/// +/// \param mount_point root path of UUID-based file system. +/// \return newly created protocol +//------------------------------------------------------------------------------ extern WF_API struct wf_server_protocol * wf_server_protocol_create( char * mount_point); +//------------------------------------------------------------------------------ +/// \brief Creates a new protocol by a mountpoint factory. +/// +/// \note This function might be renamed in future releases. +/// +/// \note The user is responsible to manage the lifetime of mountpoint factory. +/// +/// \param create_mountpoint factory function to create mountpoints +/// \param create_mountpoint_context context of mountpoint factory +//------------------------------------------------------------------------------ extern WF_API struct wf_server_protocol * wf_server_protocol_create2( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context); +//------------------------------------------------------------------------------ +/// \brief Disposes a protocol. +/// +/// \note Contexts of mountpoint factory and added authenticators are not +/// managed by dispose. +/// +/// \param protocol pointer to protocol +//------------------------------------------------------------------------------ extern WF_API void wf_server_protocol_dispose( struct wf_server_protocol * protocol); +//------------------------------------------------------------------------------ +/// \brief Intializes a libwebsockets protocol structure. +/// +/// \param protocol pointer to protocol +/// \param lws_protocols pointer to libwebsockets protocol structure +//------------------------------------------------------------------------------ extern WF_API void wf_server_protocol_init_lws( struct wf_server_protocol * protocol, struct lws_protocols * lws_protocol); +//------------------------------------------------------------------------------ +/// \brief Adds an authenticator. +/// +/// Authenticators are used to authenticate users by some provided credentials. +/// Multiple providers can be specified to support different types of +/// credentials. +/// +/// \note Adding multiple providers for the same credentials type results +/// in undefined behavior. +/// +/// \note The user is responsible to manage the lifetime of user data. +/// +/// \param protocol pointer to protocol +/// \param type type of the credentials the authenticator supports +/// \param authenticate function called to authenticate a user +/// \param user_data context of authenticate function +//------------------------------------------------------------------------------ extern WF_API void wf_server_protocol_add_authenticator( struct wf_server_protocol * protocol, char const * type, diff --git a/include/webfuse/core/status.h b/include/webfuse/core/status.h index 7b3c95f..49e53e5 100644 --- a/include/webfuse/core/status.h +++ b/include/webfuse/core/status.h @@ -1,17 +1,23 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file status.h +/// \brief Generic status code. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_STATUS_H #define WF_STATUS_H -#define WF_GOOD 0 -#define WF_BAD 1 +#define WF_GOOD 0 ///< Positive status code. +#define WF_BAD 1 ///< Generic negative status code. -#define WF_BAD_NOTIMPLEMENTED 2 -#define WF_BAD_TIMEOUT 3 -#define WF_BAD_BUSY 4 -#define WF_BAD_FORMAT 5 +#define WF_BAD_NOTIMPLEMENTED 2 ///< The called function is not implemented (yet). +#define WF_BAD_TIMEOUT 3 ///< A timeout occured. +#define WF_BAD_BUSY 4 ///< Resource is busy, try again later. +#define WF_BAD_FORMAT 5 ///< Invalid format. -#define WF_BAD_NOENTRY 101 -#define WF_BAD_ACCESS_DENIED 102 +#define WF_BAD_NOENTRY 101 ///< Entry not found. +#define WF_BAD_ACCESS_DENIED 102 ///< Access is denied. +/// Status code. typedef int wf_status; #endif diff --git a/include/webfuse/provider/api.h b/include/webfuse/provider/api.h index 5b3c572..963e038 100644 --- a/include/webfuse/provider/api.h +++ b/include/webfuse/provider/api.h @@ -1,10 +1,26 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/api.h +/// \brief API define for webfuse provider. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_PROVIDER_API_H #define WFP_PROVIDER_API_H +//------------------------------------------------------------------------------ +/// \def WFP_API +/// \brief Marks public symbols of libwebfuse_provider. +//------------------------------------------------------------------------------ #ifndef WFP_API #define WFP_API #endif +//------------------------------------------------------------------------------ +/// \def WFP_EXPORT +/// \brief Marks exported symbols as visible. +/// +/// Set WFP_API to WFP_EXPORT when building libwebfuse_provider.so to export +/// public symbols. +//------------------------------------------------------------------------------ #ifndef WFP_EXPORT #ifdef __GNUC__ #define WFP_EXPORT __attribute__ ((visibility ("default"))) diff --git a/include/webfuse/provider/client.h b/include/webfuse/provider/client.h index 142bfae..b78fc4a 100644 --- a/include/webfuse/provider/client.h +++ b/include/webfuse/provider/client.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/client.h +/// \brief Webfuse provider client. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_PROVIDER_CLIENT_H #define WF_PROVIDER_CLIENT_H @@ -8,22 +13,74 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wfp_client +/// \brief Webfuse provider client. +//------------------------------------------------------------------------------ struct wfp_client; + struct wfp_client_config; +//------------------------------------------------------------------------------ +/// \brief Creates a webfuse provider client. +/// +/// \note Client configuration is not managed by the client. +/// +/// \param config pointer to client configuration. +/// \return newly created client or NULL in case of an error. +//------------------------------------------------------------------------------ extern WFP_API struct wfp_client * wfp_client_create( struct wfp_client_config * config); +//------------------------------------------------------------------------------ +/// \brief Connects the client to a remote webfuse adapter server. +/// +/// \note This call starts to establish a connection. A callback is invoked, +/// when the connection is estanlished. +/// +/// \param client pointer to client +/// \param url URL of remote webfuse adapter server +/// +/// \see wfp_connected_fn +/// \see wfp_client_config_set_onconnected +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_connect( struct wfp_client * client, char const * url); +//------------------------------------------------------------------------------ +/// \brief Disconnects a connected client. +/// +/// \note This call starts to disconnect the connection. A callback is invoked +/// when conntection is disconnected. +/// +/// \param client pointer to client +/// +/// \see wfp_disconnected_fn +/// \see wfp_client_config_set_ondisconnected +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_disconnect( struct wfp_client * client); +//------------------------------------------------------------------------------ +/// \brief Disposes a client. +/// +/// \note Client configuration is not managed by client. +/// +/// \param client pointer to client +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_dispose( struct wfp_client * client); +//------------------------------------------------------------------------------ +/// \brief Triggers the client. +/// +/// This function must be invoked in a loop while the client is running. It +/// makes the server wait for the next event and processes it. +/// +/// \param client pointer to client +/// \param timeout_ms timeout in milliseconds. +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_service( struct wfp_client * client, int timeout_ms); diff --git a/include/webfuse/provider/client_config.h b/include/webfuse/provider/client_config.h index 4a9cebc..73775f1 100644 --- a/include/webfuse/provider/client_config.h +++ b/include/webfuse/provider/client_config.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/client_config.h +/// \brief Client configuration of webfuse provider. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_PROVIDER_CLIENT_CONFIG_H #define WF_PROVIDER_CLIENT_CONFIG_H @@ -15,67 +20,209 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wfp_client_config +/// \brief Provider client configuration object. +/// +/// Holds configuration of webfuse provider client. +//------------------------------------------------------------------------------ struct wfp_client_config; +//------------------------------------------------------------------------------ +/// \brief Callback to signal when the client's connection is established. +/// +/// \param user_data user defined context +//------------------------------------------------------------------------------ typedef void wfp_connected_fn( void * user_data); +//------------------------------------------------------------------------------ +/// \brief Callback to signal when a client's connection is disconnected. +/// +/// \param user_data user defined context +//------------------------------------------------------------------------------ typedef void wfp_disconnected_fn( void * user_data); +//------------------------------------------------------------------------------ +/// \brief Callback to signal when a timer event occued. +/// +/// \param user_data user defined context +//------------------------------------------------------------------------------ typedef void wfp_ontimer_fn( void * user_data); +//------------------------------------------------------------------------------ +/// \brief Creates a new client configuration. +/// +/// \return newly created client configuration +//------------------------------------------------------------------------------ extern WFP_API struct wfp_client_config * wfp_client_config_create(void); +//------------------------------------------------------------------------------ +/// \brief Disposes a client configuration. +/// +/// \note The user defined context is not managed by the client configuration. +/// +/// \param config pointer to client configuration +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_dispose( struct wfp_client_config * config); +//------------------------------------------------------------------------------ +/// \brief Sets a user defined context. +/// +/// \note The user is responsible to manage the lifetime of user data. +/// +/// \param config pointer to client configuration +/// \param user_data user defined context +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_userdata( struct wfp_client_config * config, void * user_data); +//------------------------------------------------------------------------------ +/// \brief Sets the path to clients private key. +/// +/// \note To enable TLS both, private key and certificate, must be specified. +/// Otherwise, TLS is not used. +/// +/// \param config pointer to client configuration +/// \param key_path path of clients private key (pem file) +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_keypath( struct wfp_client_config * config, char const * key_path); +//------------------------------------------------------------------------------ +/// \brief Sets the path of clients certificate. +/// +/// \note To enable TLS both, private key and certificate, must be specified. +/// Otherwise, TLS is not used. +/// +/// \param config pointer to client configuration +/// \param cert_path path of the clients certificate (pem file) +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_certpath( struct wfp_client_config * config, char const * cert_path); +//------------------------------------------------------------------------------ +/// \brief Sets the onconnected handler. +/// +/// The handler is invoked, when the client's conntection is established. +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_onconnected( struct wfp_client_config * config, wfp_connected_fn * handler); +//------------------------------------------------------------------------------ +/// \brief Sets ondisconnected handler +/// +/// The handler is invoked, when the client's conntection is lost. +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_ondisconnected( struct wfp_client_config * config, wfp_disconnected_fn * handler); +//------------------------------------------------------------------------------ +/// \brief Sets ontimer handler. +/// +/// The handler is invoked, when a timer event occured. +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_ontimer( struct wfp_client_config * config, wfp_ontimer_fn * handler); - +//------------------------------------------------------------------------------ +/// \brief Sets onlookup handler. +/// +/// The handler is invoked, when the identifier of a file is requested. +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +/// +/// \see wfp_lookup_fn +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_onlookup( struct wfp_client_config * config, wfp_lookup_fn * handler); +//------------------------------------------------------------------------------ +/// \brief Sets ongetattr handler. +/// +/// The handler is invoked, when attributes of a file are requested. +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +/// +/// \see wfp_getattr_fn +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_ongetattr( struct wfp_client_config * config, wfp_getattr_fn * handler); +//------------------------------------------------------------------------------ +/// \brief Sets onreaddir handler. +/// +/// The handler is invoked, when the contents of directory are requested- +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +/// +/// \see wfp_readdir_fn +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_onreaddir( struct wfp_client_config * config, wfp_readdir_fn * handler); +//------------------------------------------------------------------------------ +/// \brief Sets onopen handler. +/// +/// The handler is invoked, whe a file should be opened. +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +/// +/// \see wfp_open_fn +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_onopen( struct wfp_client_config * config, wfp_open_fn * handler); +//------------------------------------------------------------------------------ +/// \brief Sets onclose handler. +/// +/// The handler is invoked, when a file is closed. +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +/// +/// \see wfp_close_fn +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_onclose( struct wfp_client_config * config, wfp_close_fn * handler); +//------------------------------------------------------------------------------ +/// \brief Sets onread handler. +/// +/// The handler is invoked, when a files content is requested. +/// +/// \param config pointer to client configuration +/// \param handler pointer to handler +/// +/// \see wfp_read_fn +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_config_set_onread( struct wfp_client_config * config, wfp_read_fn * handler); diff --git a/include/webfuse/provider/client_protocol.h b/include/webfuse/provider/client_protocol.h index 8bda896..bfb6d8a 100644 --- a/include/webfuse/provider/client_protocol.h +++ b/include/webfuse/provider/client_protocol.h @@ -1,3 +1,13 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/client_protocol.h +/// \brief Provides low level access to libwebsockets protocol. +/// +/// By default, libwebfuse encapsulates libwebsockets protocol by \ref +/// wfp_client. But sometimes it might come in handy to have access to +/// libwebsockets protocol. This allows to integrate libwebfuse in existing +/// libwebsockets applications. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_PROVIDER_CLIENT_PROTOCOL_H #define WF_PROVIDER_CLIENT_PROTOCOL_H @@ -8,17 +18,57 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wfp_client_protocol +/// \brief Opaque webfuse client protocol.. +//------------------------------------------------------------------------------ struct wfp_client_protocol; + +//------------------------------------------------------------------------------ +/// \struct wfp_provider +/// \brief Provider. +/// +/// \todo How is a user supposed to get a provider's instance? +//------------------------------------------------------------------------------ struct wfp_provider; + +//------------------------------------------------------------------------------ +/// \struct lws_protocols +/// \brief Forward declaration of libwebsockets protocols structure. +//------------------------------------------------------------------------------ struct lws_protocols; +//------------------------------------------------------------------------------ +/// \brief Creates a new webfuse provider client protocol. +/// +/// \note The user is responsible to manage lifetime of \arg user_data. +/// +/// \todo How is a user supposed to get a provider's instance? +/// +/// \param provider pointer to provider +/// \param user_data user defined context +/// \return newly created protocol +//------------------------------------------------------------------------------ extern WFP_API struct wfp_client_protocol * wfp_client_protocol_create( struct wfp_provider const * provider, void * user_data); +//------------------------------------------------------------------------------ +/// \brief Disposes a protocol. +/// +/// \note The user defined context is not managed by the protocol. +/// +/// \param protocol pointer to protocol. +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_protocol_dispose( struct wfp_client_protocol * protocol); +//------------------------------------------------------------------------------ +/// \brief Initialized libwebsockets protocol structure. +/// +/// \param protocol pointer to protocol +/// \param lws_protocol pointer to libwebsockets protocol structure. +//------------------------------------------------------------------------------ extern WFP_API void wfp_client_protocol_init_lws( struct wfp_client_protocol * protocol, struct lws_protocols * lws_protocol); diff --git a/include/webfuse/provider/dirbuffer.h b/include/webfuse/provider/dirbuffer.h index d0770e5..2737ab4 100644 --- a/include/webfuse/provider/dirbuffer.h +++ b/include/webfuse/provider/dirbuffer.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/dirbuffer.h +/// \brief Buffer used for directory listing. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_PROVIDER_DIRBUFFER_H #define WF_PROVIDER_DIRBUFFER_H @@ -12,13 +17,36 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \struct wfp_dirbuffer +/// \brief Buffer used for directory listing. +/// +/// \see wfp_respond_readdir +//------------------------------------------------------------------------------ struct wfp_dirbuffer; +//------------------------------------------------------------------------------ +/// \brief Creates a new dir buffer. +/// +/// \return newly created dir buffer. +//------------------------------------------------------------------------------ extern WFP_API struct wfp_dirbuffer * wfp_dirbuffer_create(void); +//------------------------------------------------------------------------------ +/// \brief Disposes a dir buffer. +/// +/// \param buffer pointer to dir buffer +//------------------------------------------------------------------------------ extern WFP_API void wfp_dirbuffer_dispose( struct wfp_dirbuffer * buffer); +//------------------------------------------------------------------------------ +/// \brief Adds an entry to dir buffer. +/// +/// \param buffer pointer to dir buffer +/// \param name name of the entry (file or directory) +/// \param inode inode of the entry +//------------------------------------------------------------------------------ extern WFP_API void wfp_dirbuffer_add( struct wfp_dirbuffer * buffer, char const * name, diff --git a/include/webfuse/provider/operation/close.h b/include/webfuse/provider/operation/close.h index bb1eef1..ae17a28 100644 --- a/include/webfuse/provider/operation/close.h +++ b/include/webfuse/provider/operation/close.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/operation/close.h +/// \brief Provider's close callback. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_OPERATION_CLOSE_H #define WFP_OPERATION_CLOSE_H @@ -18,6 +23,16 @@ extern "C" { #endif +//------------------------------------------------------------------------------ +/// \brief Callback invoked when a file is invoked. +/// +/// This function does not respond. +/// +/// \param inode inode of file to close +/// \param handle handle of file to close +/// \param flags file close flags +/// \param user_data user defined context +//------------------------------------------------------------------------------ typedef void wfp_close_fn( ino_t inode, uint32_t handle, diff --git a/include/webfuse/provider/operation/error.h b/include/webfuse/provider/operation/error.h index 4e8e1fe..556a630 100644 --- a/include/webfuse/provider/operation/error.h +++ b/include/webfuse/provider/operation/error.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/operation/error.h +/// \brief Respond with error code. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_OPERATION_ERROR_H #define WFP_OPERATION_ERROR_H @@ -11,6 +16,15 @@ extern "C" struct wfp_request; +//------------------------------------------------------------------------------ +/// \brief Respond to a request with an error. +/// +/// A client's callback must respond with exactly one responde, either with a +/// valid reponse regarding to the concrete request or with an error response. +/// +/// \param request pointer to request +/// \param status error code +//------------------------------------------------------------------------------ extern WFP_API void wfp_respond_error( struct wfp_request * request, wf_status status); diff --git a/include/webfuse/provider/operation/getattr.h b/include/webfuse/provider/operation/getattr.h index 14af3dc..4c9564f 100644 --- a/include/webfuse/provider/operation/getattr.h +++ b/include/webfuse/provider/operation/getattr.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/operation/getattr.h +/// \brief Get file attributes. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_OPERATION_GETATTR_H #define WFP_OPERATION_GETATTR_H @@ -14,11 +19,30 @@ extern "C" struct wfp_request; +//------------------------------------------------------------------------------ +/// \brief Get file attributes. +/// +/// \note After this function is called, exactly one response must be sent, +/// either via \ref wfp_respond_getattr or via \ref wfp_respond_error. +/// +/// \param request pointer to request +/// \param inode inode of file to get attributes +/// \param user_data user defined context +/// +/// \see wfp_respond_getattr +/// \see wfp_respond_error +//------------------------------------------------------------------------------ typedef void wfp_getattr_fn( struct wfp_request * request, ino_t inode, void * user_data); +//------------------------------------------------------------------------------ +/// \brief Respond to a get attributes request. +/// +/// \param request pointer to request +/// \param stat file attributes +//------------------------------------------------------------------------------ extern WFP_API void wfp_respond_getattr( struct wfp_request * request, struct stat const * stat); diff --git a/include/webfuse/provider/operation/lookup.h b/include/webfuse/provider/operation/lookup.h index 5e177d7..e8f9ca6 100644 --- a/include/webfuse/provider/operation/lookup.h +++ b/include/webfuse/provider/operation/lookup.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/operation/lookup.h +/// \brief Lookup file. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_OPERATION_LOOKUP_H #define WFP_OPERATION_LOOKUP_H @@ -14,12 +19,32 @@ extern "C" struct wfp_request; +//------------------------------------------------------------------------------ +/// \brief Lookup a file or directory. +/// +/// \note After this function is called, exactly one response must be sent, +/// either via \ref wfp_respond_lookup or via \ref wfp_respond_error. +/// +/// \param request pointer to request +/// \param parent inode of parent +/// \param name name of the filesystem object to lookup +/// \param user_data pointer to user defined context +/// +/// \see wfp_respond_lookup +/// \see wfp_respond_error +//------------------------------------------------------------------------------ typedef void wfp_lookup_fn( struct wfp_request * request, ino_t parent, char const * name, void * user_data); +//------------------------------------------------------------------------------ +/// \brief Respond to lookup request. +/// +/// \param request pointer to request +/// \param stat attributes of filesystem object +//------------------------------------------------------------------------------ extern WFP_API void wfp_respond_lookup( struct wfp_request * request, struct stat const * stat); diff --git a/include/webfuse/provider/operation/open.h b/include/webfuse/provider/operation/open.h index 9114828..d5d9f9a 100644 --- a/include/webfuse/provider/operation/open.h +++ b/include/webfuse/provider/operation/open.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/operation/open.h +/// \brief Open a file. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_OPERATION_OPEN_H #define WFP_OPERATION_OPEN_H @@ -20,12 +25,32 @@ extern "C" struct wfp_request; +//------------------------------------------------------------------------------ +/// \brief Open a file. +/// +/// \note After this function is called, exactly one response must be sent, +/// either via \ref wfp_respond_open or via \ref wfp_respond_error. +/// +/// \param request pointer to request +/// \param inode inode of the file to open +/// \param flags file open flags +/// \param user_data user defined context +/// +/// \see wfp_respond_open +/// \see wfp_respond_error +//------------------------------------------------------------------------------ typedef void wfp_open_fn( struct wfp_request * request, ino_t inode, int flags, void * user_data); +//------------------------------------------------------------------------------ +/// \brief Respond to open file. +/// +/// \param request pointer to request +/// \param handle handle of the opened file +//------------------------------------------------------------------------------ extern WFP_API void wfp_respond_open( struct wfp_request * request, uint32_t handle); diff --git a/include/webfuse/provider/operation/read.h b/include/webfuse/provider/operation/read.h index 570c310..64d0047 100644 --- a/include/webfuse/provider/operation/read.h +++ b/include/webfuse/provider/operation/read.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/operation/read.h +/// \brief Read contents of a file. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_OPERATION_READ_H #define WFP_OPERATION_READ_H @@ -23,6 +28,25 @@ extern "C" struct wfp_request; +//------------------------------------------------------------------------------ +/// \brief Requests content of a file. +/// +/// On success, up to \arg length bytes should be returned via \ref +/// wfp_respond_read. +/// +/// \note After this function is called, exactly one response must be sent, +/// either via \ref wfp_respond_read or via \ref wfp_respond_error. +/// +/// \param request pointer to request +/// \param inode inode of the file to read +/// \param handle handle of the file to read (returned by open) +/// \param offset offset within the file where to start reading +/// \param length amount of bytes to read +/// \param user_data used defined context +/// +/// \see wfp_respond_read +/// \see wfp_respond_error +//------------------------------------------------------------------------------ typedef void wfp_read_fn( struct wfp_request * request, ino_t inode, @@ -31,12 +55,20 @@ typedef void wfp_read_fn( size_t length, void * user_data); +//------------------------------------------------------------------------------ +/// \brief Respond to read. +/// +/// \note The user is responsible to manage lifetime of \arg data. +/// +/// \param request pointer to request +/// \param data data read from file +/// \param length amount of bytes read +//------------------------------------------------------------------------------ extern WFP_API void wfp_respond_read( struct wfp_request * request, char const * data, size_t length); - #ifdef __cplusplus } #endif diff --git a/include/webfuse/provider/operation/readdir.h b/include/webfuse/provider/operation/readdir.h index 968b7f3..aef2f07 100644 --- a/include/webfuse/provider/operation/readdir.h +++ b/include/webfuse/provider/operation/readdir.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/operation/readdir.h +/// \brief List directory contents. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_OPERATION_READDIR_H #define WFP_OPERATION_READDIR_H @@ -15,11 +20,33 @@ extern "C" struct wfp_dirbuffer; struct wfp_request; +//------------------------------------------------------------------------------ +/// \brief Requests the contents of a directory. +/// +/// \note After this function is called, exactly one response must be sent, +/// either via \ref wfp_respond_readdir or via \ref wfp_respond_error. +/// +/// \param request pointer to request +/// \param directory inode of directory to list +/// \param user_data user defined context +/// +/// \see wfp_respond_readdir +/// \see wfp_respond_error +//------------------------------------------------------------------------------ typedef void wfp_readdir_fn( struct wfp_request * request, ino_t directory, void * user_data); +//------------------------------------------------------------------------------ +/// \brief Respond to list directory contents. +/// +/// \note The user is responsible to manage dirbuffe, p.e. to dispose +/// it after this function is called. +/// +/// \param request pointer to request +/// \param dirbuffer contains contents of directory +//------------------------------------------------------------------------------ extern WFP_API void wfp_respond_readdir( struct wfp_request * request, struct wfp_dirbuffer * dirbuffer); diff --git a/include/webfuse/provider/static_filesystem.h b/include/webfuse/provider/static_filesystem.h index b2bdbfc..e736976 100644 --- a/include/webfuse/provider/static_filesystem.h +++ b/include/webfuse/provider/static_filesystem.h @@ -1,3 +1,13 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file provider/static_filesystem.h +/// \brief Reference implementation of static filesystem. +/// +/// This header is used by integration tests. It may be removed from the +/// library. +/// +/// \todo Remove this header from library +//////////////////////////////////////////////////////////////////////////////// + #ifndef WFP_STATIC_FILESYSTEM_H #define WFP_STATIC_FILESYSTEM_H @@ -16,8 +26,15 @@ extern "C" #endif struct wfp_client_config; + +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ struct wfp_static_filesystem; +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ typedef size_t wfp_static_filesystem_read_fn( size_t offset, @@ -25,6 +42,9 @@ wfp_static_filesystem_read_fn( size_t buffer_size, void * user_data); +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ typedef void wfp_static_filesystem_get_info_fn( void * user_data, @@ -32,14 +52,23 @@ wfp_static_filesystem_get_info_fn( size_t * result_size); +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ extern WFP_API struct wfp_static_filesystem * wfp_static_filesystem_create( struct wfp_client_config * config); +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ extern WFP_API void wfp_static_filesystem_dispose( struct wfp_static_filesystem * filesystem); +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ extern WFP_API void wfp_static_filesystem_add( struct wfp_static_filesystem * filesystem, @@ -48,6 +77,9 @@ wfp_static_filesystem_add( char const * content, size_t length); +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ extern WFP_API void wfp_static_filesystem_add_text( struct wfp_static_filesystem * filesystem, @@ -55,12 +87,18 @@ wfp_static_filesystem_add_text( int mode, char const * content); +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ extern WFP_API void wfp_static_filesystem_add_file( struct wfp_static_filesystem * filesystem, char const * path, char const * filename); +//------------------------------------------------------------------------------ +/// \deprecated This will be removed. Dont use it. +//------------------------------------------------------------------------------ extern WFP_API void wfp_static_filesystem_add_generic( struct wfp_static_filesystem * filesystem, diff --git a/include/webfuse_adapter.h b/include/webfuse_adapter.h index 37c39c2..af37c14 100644 --- a/include/webfuse_adapter.h +++ b/include/webfuse_adapter.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file webfuse_adapter.h +/// \brief Convenience header to include all functionality of libfuse_adapter. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_ADAPTER_H #define WF_ADAPTER_H diff --git a/include/webfuse_provider.h b/include/webfuse_provider.h index e37fd68..5882c60 100644 --- a/include/webfuse_provider.h +++ b/include/webfuse_provider.h @@ -1,3 +1,8 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file webfuse_provider.h +/// \brief Convenience header to include all functionality of libfuse_provider. +//////////////////////////////////////////////////////////////////////////////// + #ifndef WF_PROVIDER_H #define WF_PROVIDER_H From 4ae7160919cf463064f710a3f152ce62051391f6 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 18 Feb 2020 21:48:52 +0100 Subject: [PATCH 044/138] refactored README --- Doxyfile | 4 +- README.md | 416 ++------------------------------------------- doc/api.md | 55 ++++++ doc/build.md | 92 ++++++++++ doc/filesystem.png | Bin 5354 -> 0 bytes doc/filesystem.uml | 16 -- doc/protocol.md | 253 +++++++++++++++++++++++++++ 7 files changed, 414 insertions(+), 422 deletions(-) create mode 100644 doc/api.md create mode 100644 doc/build.md delete mode 100644 doc/filesystem.png delete mode 100644 doc/filesystem.uml create mode 100644 doc/protocol.md diff --git a/Doxyfile b/Doxyfile index 7c48a25..088248a 100644 --- a/Doxyfile +++ b/Doxyfile @@ -112,7 +112,9 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = README.md include +INPUT = README.md \ + doc/build.md doc/protocol.md doc/api.md \ + include INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.h RECURSIVE = YES diff --git a/README.md b/README.md index d2cf16f..1c25a55 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,7 @@ webfuse combines libwebsockets and libfuse. It allows ot attach a remote filesys - [Fellow Repositories](#Fellow-Repositories) - [Concept](#Concept) - [Similar Projects](#Similar-Projects) -- [API](#API) -- [Build](#Build) -- [Dependencies](#Dependencies) +- [Further Documentation](#Further-Documentation) ## Motivation @@ -53,27 +51,14 @@ A reference implementation of such a daemon is provided within the examples. The - Whenever the user makes filesystem requests, such as *ls*, the request is redirected via webfuse daemon to the connected filesystem provider -Currently all requests are initiated by webfuse daemon and responded by filesystem provider. This may change in future, e.g. when authentication is supported. +### Adapters and Providers -### Filesystem represenation +In webfuse, an adapter is a component that adapts the libfuse API to a websocket interface. +Currently, libwebfuse implements only a server based adapter - a websocket server, that allows clients to connect a remote file system which +is represented via libfuse on the server side. -![filesystem](doc/filesystem.png) - -To handle multiple filesystems, that are registered by one or more providers, webfuse daemon maintains a directory structure as shown above. - -- **mount_point** is the entry point of the drectory structure - -- **fwupdate** is a name defined by the provider when filesystem was registered - *Note: the picture above shows two providers, where both registered a filesystem named "fwupdate"* - -- **<uuid>** is the filesystem id choosen by webfuse daemon to distinguish different filesystems - -- **default** is a symbolic link maintained by webfuse daemon to identify the default filesystem - -This directoy structure allows to handle multiple filesystems registered by multiple providers. -It can be used as a kind of service registry, where each filesystem represents a service. -The named subdirectores distinguish differend service types. The symbolic link *default* can be used to identify the -default service and the listing of a named subdirectory can be used to list available services of a particular type. +In webfuse, a provider is a component that provides a filesystem via websocket interface. +Currently, libwebfuse implements only a client based provider - a websocket client that provides a local filesystem to a remote server. ## Similar Projects @@ -83,387 +68,8 @@ default service and the listing of a named subdirectory can be used to list avai Unlike webfuse, davfs2 mounts a remote filesystem locally, that is provided by a WebDAV server. In contrast, webfuse starts a server awaiting client connections to attach the remote file system. -## API +## Further Documentation -### Requests, responses and notifications - -There are three types of messages, used for communication between webfuse daemon and filesystem provider. All message types are encoded in [JSON](https://www.json.org/) and strongly inspired by [JSON-RPC](https://www.jsonrpc.org/). - -#### Request - -A request is used by a sender to invoke a method on the receiver. The sender awaits a response from the receiver. Since requests and responses can be sendet or answered in any order, an id is provided in each request to identify it. - - { - "method": , - "params": , - "id" : - } - -| Item | Data type | Description | -| ----------- |:---------:| --------------------------------- | -| method_name | string | name of the method to invoke | -| params | array | method specific parameters | -| id | integer | id, which is repeated in response | - -#### Response - -A response is used to answer a prior request. There are two kinds of responses: - -##### Successful Results - - { - "result": , - "id": - } - -| Item | Data type | Description | -| ----------- |:---------:| ----------------------- | -| result | any | request specific result | -| id | integer | id, same as request | - -##### Error notifications - - { - "error": { - "code": - }, - "id": - } - -| Item | Data type | Description | -| ----------- |:---------:| ------------------- | -| code | integer | error code | -| id | integer | id, same as request | - -##### Error codes - -| Symbolic name | Code | Description | -| ------------------ | ---------:| ---------------------- | -| GOOD | 0 | no error | -| BAD | 1 | generic error | -| BAD_NOTIMPLEMENTED | 2 | method not implemented | -| BAD_TIMEOUT | 3 | timeout occured | -| BAD_BUSY | 4 | resource busy | -| BAD_FORMAT | 5 | invalid formt | -| BAD_NOENTRY | 101 | invalid entry | -| BAD_ACCESS_DENIED | 102 | access not allowed | - -#### Notification - -Notfications are used to inform a receiver about something. Unlike requests, notifications are not answered. Therefore, an id is not supplied. - - { - "method": , - "params": - } - -| Item | Data type | Description | -| ----------- |:---------:| --------------------------------- | -| method_name | string | name of the method to invoke | -| params | array | method specific parameters | - -### Requests (Adapter -> Provider) - -#### lookup - -Retrieve information about a filesystem entry by name. - - webfuse daemon: {"method": "lookup", "params": [, , ], "id": } - fs provider: {"result": { - "inode": , - "mode" : , - "type" : , - "size" : , - "atime": , - "mtime": , - "ctime": - }, "id": } - -| Item | Data type | Description | -| ----------- | --------------- | ------------------------------------------- | -| filesystem | string | name of the filesystem | -| parent | integer | inode of parent directory (1 = root) | -| name | string | name of the filesystem object to look up | -| inode | integer | inode of the filesystem object | -| mode | integer | unix file mode | -| type | "file" or "dir" | type of filesystem object | -| size | integer | required for files; file size in bytes | -| atime | integer | optional; unix time of last access | -| mtime | integer | optional; unix time of last modification | -| ctime | intefer | optional; unix time of last metadata change | - -#### getattr - -Get file attributes. - - webfuse daemon: {"method": "getattr", "params": [, ], "id": } - fs provider: {"result": { - "mode" : , - "type" : , - "size" : , - "atime": , - "mtime": , - "ctime": - }, "id": } - -| Item | Data type | Description | -| ----------- | --------------- | ------------------------------------------- | -| filesystem | string | name of the filesystem | -| inode | integer | inode of the filesystem object | -| mode | integer | unix file mode | -| type | "file" or "dir" | type of filesystem object | -| size | integer | required for files; file size in bytes | -| atime | integer | optional; unix time of last access | -| mtime | integer | optional; unix time of last modification | -| ctime | intefer | optional; unix time of last metadata change | - -#### readdir - -Read directory contents. -Result is an array of name-inode pairs for each entry. The generic entries -"." and ".." should also be provided. - - webfuse daemon: {"method": "readdir", "params": [, ], "id": } - fs provider: {"result": [ - {"name": , "inode": }, - ... - ], "id": } - -| Item | Data type | Description | -| ----------- | --------------- | ------------------------------ | -| filesystem | string | name of the filesystem | -| dir_inode | integer | inode of the directory to read | -| name | integer | name of the entry | -| inode | integer | inode of the entry | - -#### open - -Open a file. - - webfuse daemon: {"method": "readdir", "params": [, , ], "id": } - fs provider: {"result": {"handle": }, "id": } - -| Item | Data type | Description | -| ----------- | ----------| ----------------------------- | -| filesystem | string | name of the filesystem | -| inode | integer | inode of the file | -| flags | integer | access mode flags (see below) | -| handle | integer | handle of the file | - -##### Flags - -| Symbolic name | Code | Description | -| --------------| ---------:| --------------------------- | -| O_ACCMODE | 0x003 | access mode mask | -| O_RDONLY | 0x000 | open for reading only | -| O_WRONLY | 0x001 | open for writing only | -| O_RDWR | 0x002 | open for reading an writing | -| O_CREAT | 0x040 | create (a new) file | -| O_EXCL | 0x080 | open file exclusivly | -| O_TRUNC | 0x200 | open file to truncate | -| O_APPEND | 0x400 | open file to append | - -#### close - -Informs filesystem provider, that a file is closed. -Since `close` is a notification, it cannot fail. - - webfuse daemon: {"method": "close", "params": [, , , ], "id": } - -| Item | Data type | Description | -| ----------- | ----------| ---------------------------- | -| filesystem | string | name of the filesystem | -| inode | integer | inode of the file | -| handle | integer | handle of the file | -| flags | integer | access mode flags (see open) | - -#### read - -Read from an open file. - - webfuse daemon: {"method": "close", "params": [, , , , ], "id": } - fs provider: {"result": { - "data": , - "format": , - "count": - }, "id": } - -| Item | Data type | Description | -| ----------- | ----------| ----------------------------- | -| filesystem | string | name of the filesystem | -| inode | integer | inode of the file | -| handle | integer | handle of the file | -| offset | integer | Offet to start read operation | -| length | integer | Max. number of bytes to read | -| data | integer | handle of the file | -| format | string | Encoding of data (see below) | -| count | integer | Actual number of bytes read | - -##### Format - -| Format | Description | -| ---------- | -------------------------------------------------------- | -| "identiy" | Use data as is; note that JSON strings are UTF-8 encoded | -| "base64" | data is base64 encoded | - -### Requests (Provider -> Adapter) - -#### add_filesystem - -Adds a filesystem. - - fs provider: {"method": "add_filesytem", "params": [], "id": } - webfuse daemon: {"result": {"id": }, "id": } - -| Item | Data type | Description | -| ----------- | ----------| ------------------------------- | -| name | string | name and id of filesystem | - -#### authtenticate - -Authenticate the provider. -If authentication is enabled, a provider must be authenticated by the adapter before filesystems can be added. - - fs provider: {"method": "authenticate", "params": [, ], "id": } - webfuse daemon: {"result": {}, "id": } - -| Item | Data type | Description | -| ----------- | ----------| ------------------------------- | -| type | string | authentication type (see below) | -| credentials | object | credentials to authenticate | - -##### authentication types - -- **username**: authenticate via username and password - `{"username": , "password": }` - -## Authentication - -By default, webfuse daemon will redirect each filesystem call to the first connected provider without any authentication. -This might be good for testing purposes or when an external authentication mechanism is used. In some use cases, explicit authentication is needed. Therefore, authentication can be enabled within webfuse daemon. - -When authentication is enabled, filesystem calls are only redirected to a connected provider, after `authenticate` -has succeeded. - -![authenticate](doc/authenticate.png) - -### Enable authentication - -Authentication is enabled, if one or more authenticators are registered via `wf_server_config`. - - static bool authenticate(struct wf_credentials * creds, void * user_data) - { - char const * username = wf_credentials_get(creds, "username"); - char const * password = wf_credentials_get(creds, "password"); - - return ((NULL != username) && (0 == strcmp(username, "bob")) && - (NULL != password) && (0 == strcmp(password, "???"))); - } - - wf_server_config * config = wf_server_config_create(); - wf_server_config_add_authenticator(config, "username", &authenticate, NULL); - - wf_server * server = wf_server_create(config); - //... - -### Authenticator types and credentidals - -Each authenticator is identified by a user defined string, called `type`. The type is provided by the `authenticate` request, so you can define different authenticators for different authentication types, e.g. username, certificate, token. - -Actually, only one type is used: **username** -**It is strongly recommended to prefix custom authenticator types with an underscore (`_`) to avoid name clashes.** - -The `wf_credentials`struct represents a map to access credentials as key-value pairs, where both, key and value, are of type string. - -#### username - -The authenticator type **username** is used to authenticate via username and password. Valid credentials should contain two keys. - -- **username** refers to the name of the user -- **password** refers to the password of the user - -**Note** that no further encryption is done, so this authenticator type should not be used over unencrypted websocket connections. - -## Build - -To install dependencies, see below. - - cd webfuse - mkdir .build - cd .build - cmake .. - make - -### Build options - -By default, unit tests are enabled. You can disable them using the following cmake options: - -- **WITHOUT_TESTS**: disable tests - `cmake -DWITHOUT_TESTS=ON ..` - -Since webfuse consists of two libraries, it is possible to disable one of them -in order to reduce build dependencies. -*Note that unit tests are only available, when both libraries are built.* - -- **WITHOUT_ADAPTER**: omit adapter library - `cmake -DWITHOUT_ADAPTER=ON` - -- **WIHTOU_PROVIDER**: omit provider library - `cmake -DWITHOUT_PROVIDER=ON` - -## Dependencies - -- [libfuse3](https://github.com/libfuse/libfuse/) -- [libwebsockets](https://libwebsockets.org/) -- [Jansson](https://jansson.readthedocs.io) -- [GoogleTest](https://github.com/google/googletest) *(optional)* - -### Installation from source - -#### libfuse - -To install libfuse, meson is needed. Please refer to [meson quick guide](https://mesonbuild.com/Quick-guide.html) for setup instructions. - - wget -O fuse-3.8.0.tar.gz https://github.com/libfuse/libfuse/archive/fuse-3.8.0.tar.gz - tar -xf fuse-3.8.0.tar.gz - cd libfuse-fuse-3.8.0 - mkdir .build - cd .build - meson .. - ninja - sudo ninja install - -#### libwebsockets - - wget -O libwebsockets-3.2.0.tar.gz https://github.com/warmcat/libwebsockets/archive/v3.2.0.tar.gz - tar -xf libwebsockets-3.2.0.tar.gz - cd libwebsockets-3.2.0 - mkdir .build - cd .build - cmake .. - make - sudo make install - -#### Jansson - - wget -O libjansson-2.12.tar.gz https://github.com/akheron/jansson/archive/v2.12.tar.gz - tar -xf libjansson-2.12.tar.gz - cd jansson-2.12 - mkdir .build - cd .build - cmake .. - make - sudo make install - -#### GoogleTest - -Installation of GoogleTest is optional webfuse library, but required to compile tests. - - wget -O gtest-1.10.0.tar.gz https://github.com/google/googletest/archive/release-1.10.0.tar.gz - tar -xf gtest-1.10.0.tar.gz - cd googletest-release-1.10.0 - mkdir .build - cd .build - cmake .. - make - sudo make install +- [Build instructions](doc/build.md) +- [Webfuse Protocol](doc/protocol.md) +- [API](doc/api.md) diff --git a/doc/api.md b/doc/api.md new file mode 100644 index 0000000..6cd8340 --- /dev/null +++ b/doc/api.md @@ -0,0 +1,55 @@ +# Webfuse API introduction + +This introduction provides a general overview to webfuse API. +Please refer to the [build instructions](build.md) to generate API reference documentation. + +## Contents + +- [Authentication](#Authentication) + +## Authentication + +By default, webfuse daemon will redirect each filesystem call to the first connected provider without any authentication. +This might be good for testing purposes or when an external authentication mechanism is used. In some use cases, explicit authentication is needed. Therefore, authentication can be enabled within webfuse daemon. + +When authentication is enabled, filesystem calls are only redirected to a connected provider, after `authenticate` +has succeeded. + +![authenticate](authenticate.png) + +### Enable authentication + +Authentication is enabled, if one or more authenticators are registered via `wf_server_config`. + + static bool authenticate(struct wf_credentials * creds, void * user_data) + { + char const * username = wf_credentials_get(creds, "username"); + char const * password = wf_credentials_get(creds, "password"); + + return ((NULL != username) && (0 == strcmp(username, "bob")) && + (NULL != password) && (0 == strcmp(password, "???"))); + } + + wf_server_config * config = wf_server_config_create(); + wf_server_config_add_authenticator(config, "username", &authenticate, NULL); + + wf_server * server = wf_server_create(config); + //... + +### Authenticator types and credentidals + +Each authenticator is identified by a user defined string, called `type`. The type is provided by the `authenticate` request, so you can define different authenticators for different authentication types, e.g. username, certificate, token. + +Actually, only one type is used: **username** +**It is strongly recommended to prefix custom authenticator types with an underscore (`_`) to avoid name clashes.** + +The `wf_credentials`struct represents a map to access credentials as key-value pairs, where both, key and value, are of type string. + +#### username + +The authenticator type **username** is used to authenticate via username and password. Valid credentials should contain two keys. + +- **username** refers to the name of the user +- **password** refers to the password of the user + +**Note** that no further encryption is done, so this authenticator type should not be used over unencrypted websocket connections. diff --git a/doc/build.md b/doc/build.md new file mode 100644 index 0000000..9a90ea3 --- /dev/null +++ b/doc/build.md @@ -0,0 +1,92 @@ +# Build Instructions + +To install dependencies, see below. + + cd webfuse + mkdir .build + cd .build + cmake .. + make + +## Build options + +By default, unit tests are enabled. You can disable them using the following cmake options: + +- **WITHOUT_TESTS**: disable tests + `cmake -DWITHOUT_TESTS=ON ..` + +Since webfuse consists of two libraries, it is possible to disable one of them +in order to reduce build dependencies. +*Note that unit tests are only available, when both libraries are built.* + +- **WITHOUT_ADAPTER**: omit adapter library + `cmake -DWITHOUT_ADAPTER=ON` + +- **WIHTOU_PROVIDER**: omit provider library + `cmake -DWITHOUT_PROVIDER=ON` + +## Create API documentation + +To create API documentation, you must install doxygen and dot first. +After that, run doxygen in the project root directory. + + doxygen + +After that, you will find the API documentation in the doc/api subdirectory. + +## Dependencies + +- [libfuse3](https://github.com/libfuse/libfuse/) +- [libwebsockets](https://libwebsockets.org/) +- [Jansson](https://jansson.readthedocs.io) +- [GoogleTest](https://github.com/google/googletest) *(optional)* + +### Installation from source + +#### libfuse + +To install libfuse, meson is needed. Please refer to [meson quick guide](https://mesonbuild.com/Quick-guide.html) for setup instructions. + + wget -O fuse-3.8.0.tar.gz https://github.com/libfuse/libfuse/archive/fuse-3.8.0.tar.gz + tar -xf fuse-3.8.0.tar.gz + cd libfuse-fuse-3.8.0 + mkdir .build + cd .build + meson .. + ninja + sudo ninja install + +#### libwebsockets + + wget -O libwebsockets-3.2.0.tar.gz https://github.com/warmcat/libwebsockets/archive/v3.2.0.tar.gz + tar -xf libwebsockets-3.2.0.tar.gz + cd libwebsockets-3.2.0 + mkdir .build + cd .build + cmake .. + make + sudo make install + +#### Jansson + + wget -O libjansson-2.12.tar.gz https://github.com/akheron/jansson/archive/v2.12.tar.gz + tar -xf libjansson-2.12.tar.gz + cd jansson-2.12 + mkdir .build + cd .build + cmake .. + make + sudo make install + +#### GoogleTest + +Installation of GoogleTest is optional webfuse library, but required to compile tests. + + wget -O gtest-1.10.0.tar.gz https://github.com/google/googletest/archive/release-1.10.0.tar.gz + tar -xf gtest-1.10.0.tar.gz + cd googletest-release-1.10.0 + mkdir .build + cd .build + cmake .. + make + sudo make install diff --git a/doc/filesystem.png b/doc/filesystem.png deleted file mode 100644 index 4b4106a5baa940e2e070fac600acdbbf8f44384c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5354 zcmZWtc|6o_*S4=?8A~RblCh3tkTAArG?ub&m2I*{2s3usqcA0F3WMxxveVcK*%|v1 zij1AIgwp%f?|Gm1`Ml3Rv)jVCQKmd8ecq>vnF#iL*yaUXZY}z zWB<#>#@fbN%l>6H&zI=|{WCIN%|338`T4JGAdh#@a_>Sh5Mh)#8u-Gz#?X#g98SA8%ie8Ysv_xn-CeWr0eO9SNVO6zV&L70 zV7xAme36hK3rFHiT?Raa8pt;onoF)^{P9dRzMu1P^PuG6N5hA-mdr2>C$ z*UmkwLnqm>{GRSAUfmN#xTxNRsMufMCz zr+i)aa6$cHd{Ppw6YBHp$AD@jbgyh5hH12g(0$B>{c-JdiaM^StE;Q8ug}W5sHn)d zIU2_&w>e$AHLN39T38s$>gwuBkRBZ!m5`8d87tA!(J3x3=h20pm2v1TZ$4>o8NXcj z-mJv@;+&Z z5wF}DwB&K9vl0D($Im-6Mh;SqRI|@Gm;*okBl5 zuk5oq(|mHo%xh$5sD!f{DKNm{aGlRCr2MH4i!0+nn>TizeXcLpsa5fdE8fg%T8%x9+o0|4#C^wdt_WdFl?Tmm= z49~Ws;`+zqpKyv0e}0K^aB*x0z}{XLS<}3Kzwk(b97fCB@$7=+w3nBcd))$^UtqUb z{)3r11Nmm*XAV0jyCgk;;P3tSc;(z?62*)X@v*$JOfy0vBJKI##T~uBZ)PY5*iZx= z?Vi2jG$=Em1kOy}f|%vT}0mvx*PruT4%g`nWrB z=|a`s`9`rqkw6m0#>RX;`_cEy?!$mz?o`@oSy^QS<_;ggfNV&@;SFnLjr$wZ2S7=% zot0h$q8=Quhjg%gMt-^GjnFkf3Q*l;o8WIc{Pv2Qo12!F_95H&=%^)b)a1KS6n^5i z%v|7)TXV#q(Px(3-Q9x+X(T<>ptZ5m>>PaHpWg@kR;x41nZYMxciml8!vS6JB}Y?R z-oj#`Vv>^9RZc@Cx8GR>|K3|&UA6B?Ze{re>`ady6nW2aCydbY8FiKFo#TKhl4_cL z;@JtC^9o*0nlXoCTf1ZGBc26Jx~3#KcTXNCA4YjXNdpkO4Yb(wepLSv(BA zIaAMRCFDjt{MH&yUpze>e-g8a2CB?)3vF{isZO1F^7~+J+q&YA4q?;M`%Or z5YybeJl1pa4?n#SD*FBY;IsIpOE-0N6aiT^E4M10s&$*aV_^Z>aD46Y7)~vU>{v*# zegr7DmY&|$T(c^Tz5^t>rTo+4^O4L~8h(4DW&jJ*;^Per3_Qq#7bhV__`2oX!a~N& zSyfddzxYGk9NQnW0Gy6=`P9>Mml){RiN9RHuOB+PV}V1mhC2zG*eRtvg$k`^pOcBf ztKFN=~$%QRLwu^I~z6qIXPy3uBZB&i|!AQy1?BbbfvN})MG&B_U*}3Dci6iFa(aG zqx&)Gn5hnk*RtCVFRLB%t=tK7SCYq>z3HFGU3EwQ7cA8gP01syJ>V8#h2jV|M5eC|ze-RFn^ zMG>uoo~jM8$mX7&~W4+zu8YNb?}a=6q`!G0Z@bF2&OOWg1K|m2Q(?)7XYqnL-bZ zY*4%M!q_f0S0GxnUa~vmHWtJ&OZm8P2tD<^XlnfN!~McAig6r-I7n8Iz=11#&56lM6rk@aHyWP%KqipQX;r zp)XBHh7m<(9NTZwoWDrtRqM5^8$_$PUcg$xxiVg!8B5K3liG(J)!AZ5&Cn6AE=P_Q z&PVx5{0$zu&ABmt!Bx) zH6S;eRL#z3-SdyA$KeVEMB@4L!m9zbMPLWrl_8h%_sN-=>J z5A_HobR{c6i0nr>F70&0_4G=K#-%~K+oF#|4<5(Y%LTc zt)Wt{UIXMZRw+{vcQSOJKvrT`4DZv|ko*wX^qQf9QF_CK`qCJPPW~S2eBPFukY8?>Js9IBVWgGqA zK}Hu@atfm!x4e0^bJ8!Tk59R`i$tGYzg1!Sb!ek~!+-3yV=L|nUVH+BrpgcT@x9t| zV$I$<0<90Xp-<)w$%jqe|`Hx0way?=4{bDkmOwpO0m2(p@XhBPXz^vjs5i#&HQy z@KQQ2`9j)|R#i^%N~Rvqiz$=S9z=~k-1*2;Y((>xmuuVHRGbZThKsAq)>$=7H@Ri= zOxA4Z)5S%*g{mB*+qcDjR1Dgz%7=x}{dH9h!i5#w=z{1(K7H{uTX4TO+m^7dXqxk( zM$b}F+ZgvIuIs;C4Wpa&TTW-U-|M+b4>U_1Jv~+5ZGto9@#-x;fJ3+V^14qL73xx@ z?U}0hnhU7sJ$BoHDfe(W6PTtKLnx^enYrmxhe}FHL^6D-RGgii;c$4^%DBWtv08pZ z1FvcR3}d^Ij`EJWcEy>A*?Ts>0%@wLQxv?u-K-0qpWI$bu?`EzdHfKtJQa888Jn6iSK49ti(imx}NVNJpN&&QV9&TdTR!kCX7IY&%Jio;^bR z(eXwtFbVCikkEf};*Jlt=r!m=!!gBk6LNQC-=C4Rx}+NB!^Eyawl*}ZwC_1H3A72y z51Vbwk`a!~N_e;WrR3z~Gn1_2Wz(q4!wPe8I9ys4J@n%HaEQB z-&%b_61|d&bYedjnoBqDy@=4%7>))t7<1i79E{=E?KQO3hwKlHiZc95OA(+1-@oG@ z&wq4BT?XhRc;Qm7{tu&Hu_8ZrpEH0@TOo)Pi84VeCGfKpfHdHo@jvXtBbcbT&C{P_ zKVaD778zej@@)Ytu!Dk{)K{*@ccT^qZ}+EEOKM{VF3Hk8alK#}$J9>zI>q_oG6@W0 z9PV%0?bT0wNGyr?VL!`bKX3^NESmF@o!ZAK{jmRuR z1%>vf$S-p{2#EEZVgvSl=y=9+Y$$MSOtAT{jB%jRVFSlx zc$ii@Ce?S5W*A&Vr!is!#c*(s#gki+ZG!N(xiDkP;^!RB8iW~CZHpY(M9QXdtlZLI zg5veq$Ov$TaCCHJ?#(06#|pO@nzbT!bZ5w#nvB&PIgkqCg)BJJT8I&uG&1r=j?Ty? zRXakXJPgAT(zVJEIav+et>MB_F{ed26P{A8A=OQ|#whcFQ=k;D&?Z&8@fSvaZcqXR zN*~=u@m@lM%vkLtWn+mhc-n@XH~y_5t2Ti;waWAb4iTn|mVjoh?q%zF!r7AGbS2|Q zxqxZ1>Y3aJ+0@^DGk9f#?;_Pl*ZLTRvXcM)uYALp>#~HzXgVC41+2;Azzh}Jq|)%$ zU?YmgUvb`3m$(C(DAZz9u_Bg!6!%`rqTZkP0>e zlWHzJg{;g;V5;+XAVn~_`+Z4EO(UlA-o!@N;K{kJg`Q2ViKTlZ;Gzb&z0%M6TJh%O zq@+)h`IIkTzAQ@ruCZ79Hb?=13`p+6UDIGI&06aOa|?{bGyI}7TWR~5(?{M_pt~`N z&U$UQLAF6f>wb-KT8oCyuZngm!lEmy-Jl-EX1TFOUhcMLk0Q_9R_qA*7v@9k4V^_p z`RwJgEOB+LAep@$IvMgeIT4q1@((xs4~y`zFq`=|NJLi9Q{-|E|A+3z;bxzYAbz z)s_VS&<6X^@TzpfjS(Bse8y{Uu!7I=2a-1$;g{w`JH_v>nb#zDZ|?QZXcQOoc4*ja zDkpdhb(aeen793bW2k4p!g9f|Hq&%UV{^oJA*o^fYpk$`iXx>fTu`IL(Y?QvLK96wbunVsL<+*5q)M0*g8M zb?D%NwnjPycmI`UAJcTnZ-px*aZ}ZGDQ>|1OgNCbXO4>iiKA z#Ccz!0EP+qoGkE=eu^>Cn684q@@hR%vK@brJZ7 Za@|c+MQhBn1h~Vb(9+OFm8si={SRI2Miu}7 diff --git a/doc/filesystem.uml b/doc/filesystem.uml deleted file mode 100644 index 1b78837..0000000 --- a/doc/filesystem.uml +++ /dev/null @@ -1,16 +0,0 @@ -@startuml - -salt -{ -{T -+ mount_point -++ fwupdate -+++ default -> 7c029f81-6bdf-4d3c-82dc-26f748164012 -+++ 7c029f81-6bdf-4d3c-82dc-26f748164012 -++++ update.raucb -+++ f93de23b-4535-4a47-a287-a381b78a11b8 -++++ update.raucb -} -} - -@enduml \ No newline at end of file diff --git a/doc/protocol.md b/doc/protocol.md new file mode 100644 index 0000000..5245b3d --- /dev/null +++ b/doc/protocol.md @@ -0,0 +1,253 @@ +# Webfuse Protocol + +## Requests, responses and notifications + +There are three types of messages, used for communication between webfuse daemon and filesystem provider. All message types are encoded in [JSON](https://www.json.org/) and strongly inspired by [JSON-RPC](https://www.jsonrpc.org/). + +### Request + +A request is used by a sender to invoke a method on the receiver. The sender awaits a response from the receiver. Since requests and responses can be sendet or answered in any order, an id is provided in each request to identify it. + + { + "method": , + "params": , + "id" : + } + +| Item | Data type | Description | +| ----------- |:---------:| --------------------------------- | +| method_name | string | name of the method to invoke | +| params | array | method specific parameters | +| id | integer | id, which is repeated in response | + +### Response + +A response is used to answer a prior request. There are two kinds of responses: + +#### Successful Results + + { + "result": , + "id": + } + +| Item | Data type | Description | +| ----------- |:---------:| ----------------------- | +| result | any | request specific result | +| id | integer | id, same as request | + +#### Error notifications + + { + "error": { + "code": + }, + "id": + } + +| Item | Data type | Description | +| ----------- |:---------:| ------------------- | +| code | integer | error code | +| id | integer | id, same as request | + +#### Error codes + +| Symbolic name | Code | Description | +| ------------------ | ---------:| ---------------------- | +| GOOD | 0 | no error | +| BAD | 1 | generic error | +| BAD_NOTIMPLEMENTED | 2 | method not implemented | +| BAD_TIMEOUT | 3 | timeout occured | +| BAD_BUSY | 4 | resource busy | +| BAD_FORMAT | 5 | invalid formt | +| BAD_NOENTRY | 101 | invalid entry | +| BAD_ACCESS_DENIED | 102 | access not allowed | + +### Notification + +Notfications are used to inform a receiver about something. Unlike requests, notifications are not answered. Therefore, an id is not supplied. + + { + "method": , + "params": + } + +| Item | Data type | Description | +| ----------- |:---------:| --------------------------------- | +| method_name | string | name of the method to invoke | +| params | array | method specific parameters | + +## Requests (Adapter -> Provider) + +### lookup + +Retrieve information about a filesystem entry by name. + + webfuse daemon: {"method": "lookup", "params": [, , ], "id": } + fs provider: {"result": { + "inode": , + "mode" : , + "type" : , + "size" : , + "atime": , + "mtime": , + "ctime": + }, "id": } + +| Item | Data type | Description | +| ----------- | --------------- | ------------------------------------------- | +| filesystem | string | name of the filesystem | +| parent | integer | inode of parent directory (1 = root) | +| name | string | name of the filesystem object to look up | +| inode | integer | inode of the filesystem object | +| mode | integer | unix file mode | +| type | "file" or "dir" | type of filesystem object | +| size | integer | required for files; file size in bytes | +| atime | integer | optional; unix time of last access | +| mtime | integer | optional; unix time of last modification | +| ctime | intefer | optional; unix time of last metadata change | + +### getattr + +Get file attributes. + + webfuse daemon: {"method": "getattr", "params": [, ], "id": } + fs provider: {"result": { + "mode" : , + "type" : , + "size" : , + "atime": , + "mtime": , + "ctime": + }, "id": } + +| Item | Data type | Description | +| ----------- | --------------- | ------------------------------------------- | +| filesystem | string | name of the filesystem | +| inode | integer | inode of the filesystem object | +| mode | integer | unix file mode | +| type | "file" or "dir" | type of filesystem object | +| size | integer | required for files; file size in bytes | +| atime | integer | optional; unix time of last access | +| mtime | integer | optional; unix time of last modification | +| ctime | intefer | optional; unix time of last metadata change | + +### readdir + +Read directory contents. +Result is an array of name-inode pairs for each entry. The generic entries +"." and ".." should also be provided. + + webfuse daemon: {"method": "readdir", "params": [, ], "id": } + fs provider: {"result": [ + {"name": , "inode": }, + ... + ], "id": } + +| Item | Data type | Description | +| ----------- | --------------- | ------------------------------ | +| filesystem | string | name of the filesystem | +| dir_inode | integer | inode of the directory to read | +| name | integer | name of the entry | +| inode | integer | inode of the entry | + +### open + +Open a file. + + webfuse daemon: {"method": "readdir", "params": [, , ], "id": } + fs provider: {"result": {"handle": }, "id": } + +| Item | Data type | Description | +| ----------- | ----------| ----------------------------- | +| filesystem | string | name of the filesystem | +| inode | integer | inode of the file | +| flags | integer | access mode flags (see below) | +| handle | integer | handle of the file | + +#### Flags + +| Symbolic name | Code | Description | +| --------------| ---------:| --------------------------- | +| O_ACCMODE | 0x003 | access mode mask | +| O_RDONLY | 0x000 | open for reading only | +| O_WRONLY | 0x001 | open for writing only | +| O_RDWR | 0x002 | open for reading an writing | +| O_CREAT | 0x040 | create (a new) file | +| O_EXCL | 0x080 | open file exclusivly | +| O_TRUNC | 0x200 | open file to truncate | +| O_APPEND | 0x400 | open file to append | + +### close + +Informs filesystem provider, that a file is closed. +Since `close` is a notification, it cannot fail. + + webfuse daemon: {"method": "close", "params": [, , , ], "id": } + +| Item | Data type | Description | +| ----------- | ----------| ---------------------------- | +| filesystem | string | name of the filesystem | +| inode | integer | inode of the file | +| handle | integer | handle of the file | +| flags | integer | access mode flags (see open) | + +### read + +Read from an open file. + + webfuse daemon: {"method": "close", "params": [, , , , ], "id": } + fs provider: {"result": { + "data": , + "format": , + "count": + }, "id": } + +| Item | Data type | Description | +| ----------- | ----------| ----------------------------- | +| filesystem | string | name of the filesystem | +| inode | integer | inode of the file | +| handle | integer | handle of the file | +| offset | integer | Offet to start read operation | +| length | integer | Max. number of bytes to read | +| data | integer | handle of the file | +| format | string | Encoding of data (see below) | +| count | integer | Actual number of bytes read | + +#### Format + +| Format | Description | +| ---------- | -------------------------------------------------------- | +| "identiy" | Use data as is; note that JSON strings are UTF-8 encoded | +| "base64" | data is base64 encoded | + +## Requests (Provider -> Adapter) + +### add_filesystem + +Adds a filesystem. + + fs provider: {"method": "add_filesytem", "params": [], "id": } + webfuse daemon: {"result": {"id": }, "id": } + +| Item | Data type | Description | +| ----------- | ----------| ------------------------------- | +| name | string | name and id of filesystem | + +### authtenticate + +Authenticate the provider. +If authentication is enabled, a provider must be authenticated by the adapter before filesystems can be added. + + fs provider: {"method": "authenticate", "params": [, ], "id": } + webfuse daemon: {"result": {}, "id": } + +| Item | Data type | Description | +| ----------- | ----------| ------------------------------- | +| type | string | authentication type (see below) | +| credentials | object | credentials to authenticate | + +#### authentication types + +- **username**: authenticate via username and password + `{"username": , "password": }` From abd6efe477c4fb3c704aad61248e3cc1e28cd71b Mon Sep 17 00:00:00 2001 From: Falk Werner <47070255+falk-werner@users.noreply.github.com> Date: Wed, 19 Feb 2020 22:44:56 +0100 Subject: [PATCH 045/138] fixed client protocol low level API (#49) * fixed client protocol low level API: enables usage of providing clients along with other websocket protocols * fix: made some c'tors explicit --- cmake/unit_tests.cmake | 3 + include/webfuse/provider/client_protocol.h | 50 +++-- lib/webfuse/provider/api.c | 14 +- lib/webfuse/provider/impl/client.c | 25 +-- lib/webfuse/provider/impl/client_protocol.c | 39 +++- lib/webfuse/provider/impl/client_protocol.h | 13 +- test/fake_adapter_server.cc | 196 ++++++++++++++++++++ test/fake_adapter_server.hpp | 24 +++ test/provider/test_client_protocol.cc | 72 +++++++ test/timeout_watcher.cc | 44 +++++ test/timeout_watcher.hpp | 26 +++ 11 files changed, 460 insertions(+), 46 deletions(-) create mode 100644 test/fake_adapter_server.cc create mode 100644 test/fake_adapter_server.hpp create mode 100644 test/provider/test_client_protocol.cc create mode 100644 test/timeout_watcher.cc create mode 100644 test/timeout_watcher.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index b49cca9..c4f779e 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -11,6 +11,8 @@ add_executable(alltests test/file_utils.cc test/msleep.cc test/die_if.cc + test/timeout_watcher.cc + test/fake_adapter_server.cc test/mock_authenticator.cc test/mock_request.cc test/core/test_container_of.cc @@ -42,6 +44,7 @@ add_executable(alltests test/adapter/jsonrpc/test_proxy.cc test/provider/test_url.cc test/provider/test_static_filesystem.cc + test/provider/test_client_protocol.cc test/integration/test_integration.cc test/integration/server.cc test/integration/provider.cc diff --git a/include/webfuse/provider/client_protocol.h b/include/webfuse/provider/client_protocol.h index bfb6d8a..ab1ba85 100644 --- a/include/webfuse/provider/client_protocol.h +++ b/include/webfuse/provider/client_protocol.h @@ -24,34 +24,36 @@ extern "C" //------------------------------------------------------------------------------ struct wfp_client_protocol; -//------------------------------------------------------------------------------ -/// \struct wfp_provider -/// \brief Provider. -/// -/// \todo How is a user supposed to get a provider's instance? -//------------------------------------------------------------------------------ -struct wfp_provider; - //------------------------------------------------------------------------------ /// \struct lws_protocols /// \brief Forward declaration of libwebsockets protocols structure. //------------------------------------------------------------------------------ struct lws_protocols; +//------------------------------------------------------------------------------ +/// \struct lws_context +/// \brief Forward declaration of libwebsockets context structure. +//------------------------------------------------------------------------------ +struct lws_context; + +//------------------------------------------------------------------------------ +/// \struct wfp_client_config +/// \copydoc wfp_client_config +//------------------------------------------------------------------------------ +struct wfp_client_config; + //------------------------------------------------------------------------------ /// \brief Creates a new webfuse provider client protocol. /// -/// \note The user is responsible to manage lifetime of \arg user_data. +/// \note The user is responsible to manage lifetime of \arg config. /// -/// \todo How is a user supposed to get a provider's instance? +/// \note TLS configuration is ignored, since TLS is managed by libwebsockets. /// -/// \param provider pointer to provider -/// \param user_data user defined context +/// \param config pointer to client config /// \return newly created protocol //------------------------------------------------------------------------------ extern WFP_API struct wfp_client_protocol * wfp_client_protocol_create( - struct wfp_provider const * provider, - void * user_data); + struct wfp_client_config const * config); //------------------------------------------------------------------------------ /// \brief Disposes a protocol. @@ -73,6 +75,26 @@ extern WFP_API void wfp_client_protocol_init_lws( struct wfp_client_protocol * protocol, struct lws_protocols * lws_protocol); + +//------------------------------------------------------------------------------ +/// \brief Connects the protocol to a remote webfuse adapter server. +/// +/// \note This call starts to establish a connection. A callback is invoked, +/// when the connection is estanlished. +/// +/// \param protocol pointer to protocol +/// \param context lws context +/// \param url URL of remote webfuse adapter server +/// +/// \see wfp_connected_fn +/// \see wfp_client_config_set_onconnected +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +extern WFP_API void wfp_client_protocol_connect( + struct wfp_client_protocol * protocol, + struct lws_context * context, + char const * url); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index c5caa21..933516b 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -160,10 +160,9 @@ void wfp_client_config_set_onread( struct wfp_client_protocol * wfp_client_protocol_create( - struct wfp_provider const * provider, - void * user_data) + struct wfp_client_config const * config) { - return wfp_impl_client_protocol_create(provider, user_data); + return wfp_impl_client_protocol_create(config); } void wfp_client_protocol_dispose( @@ -179,6 +178,15 @@ void wfp_client_protocol_init_lws( wfp_impl_client_protocol_init_lws(protocol, lws_protocol); } +void wfp_client_protocol_connect( + struct wfp_client_protocol * protocol, + struct lws_context * context, + char const * url) +{ + wfp_impl_client_protocol_connect(protocol, context, url); +} + + // client struct wfp_client * wfp_client_create( diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index b88207a..8b3c06b 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -9,10 +9,8 @@ #include "webfuse/provider/impl/provider.h" #include "webfuse/provider/impl/client_protocol.h" #include "webfuse/provider/impl/client_config.h" -#include "webfuse/provider/impl/url.h" #include "webfuse/core/lws_log.h" -#define WFP_PROTOCOL ("fs") #define WFP_CLIENT_PROTOCOL_COUNT 2 struct wfp_client @@ -37,7 +35,7 @@ struct wfp_client * wfp_impl_client_create( wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT); - client->protocols[0].name = "fs"; + client->protocols[0].name = WFP_CLIENT_PROTOCOL_NAME; wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]); memset(&client->info, 0, sizeof(struct lws_context_creation_info)); @@ -69,26 +67,7 @@ void wfp_impl_client_connect( struct wfp_client * client, char const * url) { - struct wfp_impl_url url_data; - bool const success = wfp_impl_url_init(&url_data, url); - if (success) - { - struct lws_client_connect_info info; - memset(&info, 0, sizeof(struct lws_client_connect_info)); - info.context = client->context; - info.port = url_data.port; - info.address = url_data.host; - info.path = url_data.path; - info.host = info.address; - info.origin = info.address; - info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0; - info.protocol = WFP_PROTOCOL; - info.pwsi = &client->protocol.wsi; - - lws_client_connect_via_info(&info); - - wfp_impl_url_cleanup(&url_data); - } + wfp_impl_client_protocol_connect(&client->protocol, client->context, url); } void wfp_impl_client_disconnect( diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index cf31a98..6d5ba85 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -7,11 +7,13 @@ #include +#include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/provider.h" #include "webfuse/core/util.h" #include "webfuse/core/message.h" #include "webfuse/core/message_queue.h" #include "webfuse/core/container_of.h" +#include "webfuse/provider/impl/url.h" static void wfp_impl_client_protocol_respond( json_t * response, @@ -156,13 +158,12 @@ void wfp_impl_client_protocol_cleanup( } struct wfp_client_protocol * wfp_impl_client_protocol_create( - struct wfp_provider const * provider, - void * user_data) + struct wfp_client_config const * config) { struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol)); if (NULL != protocol) { - wfp_impl_client_protocol_init(protocol, provider, user_data); + wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data); } return protocol; @@ -183,3 +184,35 @@ void wfp_impl_client_protocol_init_lws( lws_protocol->per_session_data_size = 0; lws_protocol->user = protocol; } + +void wfp_impl_client_protocol_connect( + struct wfp_client_protocol * protocol, + struct lws_context * context, + char const * url) +{ + struct wfp_impl_url url_data; + bool const success = wfp_impl_url_init(&url_data, url); + if (success) + { + struct lws_client_connect_info info; + memset(&info, 0, sizeof(struct lws_client_connect_info)); + info.context = context; + info.port = url_data.port; + info.address = url_data.host; + info.path = url_data.path; + info.host = info.address; + info.origin = info.address; + info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0; + info.protocol = WFP_CLIENT_PROTOCOL_NAME; + info.pwsi = &protocol->wsi; + + lws_client_connect_via_info(&info); + + wfp_impl_url_cleanup(&url_data); + } + else + { + protocol->provider.disconnected(protocol->user_data); + } + +} diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index 9087d94..d197559 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -11,8 +11,11 @@ extern "C" { #endif -struct wfp_provider; +#define WFP_CLIENT_PROTOCOL_NAME ("fs") + +struct wfp_client_config; struct lws_protocols; +struct lws_context; struct wfp_client_protocol { @@ -33,8 +36,7 @@ extern void wfp_impl_client_protocol_cleanup( struct wfp_client_protocol * protocol); extern struct wfp_client_protocol * wfp_impl_client_protocol_create( - struct wfp_provider const * provider, - void * user_data); + struct wfp_client_config const * config); extern void wfp_impl_client_protocol_dispose( struct wfp_client_protocol * protocol); @@ -43,6 +45,11 @@ extern void wfp_impl_client_protocol_init_lws( struct wfp_client_protocol * protocol, struct lws_protocols * lws_protocol); +extern void wfp_impl_client_protocol_connect( + struct wfp_client_protocol * protocol, + struct lws_context * context, + char const * url); + #ifdef __cplusplus } #endif diff --git a/test/fake_adapter_server.cc b/test/fake_adapter_server.cc new file mode 100644 index 0000000..72a1831 --- /dev/null +++ b/test/fake_adapter_server.cc @@ -0,0 +1,196 @@ +#include "fake_adapter_server.hpp" +#include "timeout_watcher.hpp" + +#include "webfuse/core/util.h" +#include +#include +#include +#include +#include + +using webfuse_test::TimeoutWatcher; + +#define DEFAULT_TIMEOUT (std::chrono::milliseconds(5 * 1000)) + +namespace +{ + +class IServer +{ +public: + virtual ~IServer() = default; + virtual void onConnectionEstablished(struct lws * wsi) = 0; + virtual void onConnectionClosed(struct lws * wsi) = 0; + virtual void onMessageReceived(struct lws * wsi, char const * data, size_t length) = 0; + virtual void onWritable(struct lws * wsi) = 0; +}; + +} + +extern "C" +{ + +static int wf_test_fake_adapter_server_callback( + struct lws * wsi, + enum lws_callback_reasons reason, + void * WF_UNUSED_PARAM(user), + void * in, + size_t len) +{ + struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); + if (NULL == ws_protocol) + { + return 0; + } + + auto * server = reinterpret_cast(ws_protocol->user); + switch(reason) + { + case LWS_CALLBACK_ESTABLISHED: + server->onConnectionEstablished(wsi); + break; + case LWS_CALLBACK_CLOSED: + server->onConnectionClosed(wsi); + break; + case LWS_CALLBACK_RECEIVE: + { + auto * data = reinterpret_cast(in); + server->onMessageReceived(wsi, data, len); + } + break; + case LWS_CALLBACK_SERVER_WRITEABLE: + server->onWritable(wsi); + break; + default: + break; + } + + + return 0; +} + +} + +namespace webfuse_test +{ + +class FakeAdapterServer::Private: public IServer +{ +public: + explicit Private(int port) + : client_wsi(nullptr) + , message_received(false) + { + memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2); + ws_protocols[0].name = "fs"; + ws_protocols[0].callback = &wf_test_fake_adapter_server_callback; + ws_protocols[0].per_session_data_size = 0; + ws_protocols[0].user = reinterpret_cast(this); + + memset(&info, 0, sizeof(struct lws_context_creation_info)); + info.port = port; + info.mounts = NULL; + info.protocols =ws_protocols; + info.vhost_name = "localhost"; + info.ws_ping_pong_interval = 10; + info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + + context = lws_create_context(&info); + } + + virtual ~Private() + { + lws_context_destroy(context); + } + + void waitForConnection() + { + TimeoutWatcher watcher(DEFAULT_TIMEOUT); + + while (nullptr == client_wsi) + { + watcher.check(); + lws_service(context, 100); + } + } + + void onConnectionEstablished(struct lws * wsi) override + { + client_wsi = wsi; + } + + void onConnectionClosed(struct lws * wsi) override + { + if (wsi == client_wsi) + { + client_wsi = nullptr; + } + } + + void onMessageReceived(struct lws * wsi, char const * data, size_t length) override + { + if (wsi == client_wsi) + { + last_message.assign(length, *data); + message_received = true; + } + } + + void onWritable(struct lws * wsi) override + { + if (!queue.empty()) + { + std::string const & message = queue.front(); + + unsigned char * data = new unsigned char[LWS_PRE + message.size()]; + memcpy(&data[LWS_PRE], message.c_str(), message.size()); + lws_write(wsi, &data[LWS_PRE], message.size(), LWS_WRITE_TEXT); + delete[] data; + + queue.pop(); + if (!queue.empty()) + { + lws_callback_on_writable(wsi); + } + } + } + + +private: + void send(std::string const & message) + { + if (nullptr != client_wsi) + { + queue.push(message); + lws_callback_on_writable(client_wsi); + } + } + + struct lws * client_wsi; + bool message_received; + + struct lws_protocols ws_protocols[2]; + struct lws_context_creation_info info; + struct lws_context * context; + std::vector last_message; + std::queue queue; + +}; + +FakeAdapterServer::FakeAdapterServer(int port) +: d(new Private(port)) +{ + +} + +FakeAdapterServer::~FakeAdapterServer() +{ + delete d; +} + +void FakeAdapterServer::waitForConnection() +{ + d->waitForConnection(); +} + +} \ No newline at end of file diff --git a/test/fake_adapter_server.hpp b/test/fake_adapter_server.hpp new file mode 100644 index 0000000..9cc51f0 --- /dev/null +++ b/test/fake_adapter_server.hpp @@ -0,0 +1,24 @@ +#ifndef WF_TEST_FAKE_SERVER_HPP +#define WF_TEST_FAKE_SERVER_HPP + +#include + +namespace webfuse_test +{ + +class FakeAdapterServer +{ + FakeAdapterServer(FakeAdapterServer const &) = delete; + FakeAdapterServer & operator=(FakeAdapterServer const &) = delete; +public: + explicit FakeAdapterServer(int port); + ~FakeAdapterServer(); + void waitForConnection(); +private: + class Private; + Private * d; +}; + +} + +#endif diff --git a/test/provider/test_client_protocol.cc b/test/provider/test_client_protocol.cc new file mode 100644 index 0000000..4e78f8e --- /dev/null +++ b/test/provider/test_client_protocol.cc @@ -0,0 +1,72 @@ +#include +#include + +#include +#include +#include "fake_adapter_server.hpp" + +#include +#include +#include + +using webfuse_test::FakeAdapterServer; +using testing::_; + +namespace +{ + +struct Context +{ + lws_context * context; + std::atomic isShutdownRequested; +}; + +void run(Context * context) +{ + while (!context->isShutdownRequested) + { + lws_service(context->context, 100); + } +} + + +} + + +TEST(client_protocol, connect) +{ + FakeAdapterServer server(54321); + + wfp_client_config * config = wfp_client_config_create(); + wfp_client_protocol * protocol = wfp_client_protocol_create(config); + + struct lws_protocols protocols[2]; + memset(protocols, 0, sizeof(struct lws_protocols) * 2); + protocols[0].name = "fs"; + wfp_client_protocol_init_lws(protocol, &protocols[0]); + + struct lws_context_creation_info info; + memset(&info, 0, sizeof(struct lws_context_creation_info)); + info.port = CONTEXT_PORT_NO_LISTEN; + info.protocols = protocols; + info.uid = -1; + info.gid = -1; + + struct lws_context * context = lws_create_context(&info); + wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/"); + + Context ctx; + ctx.context = context; + ctx.isShutdownRequested = false; + std::thread client_thread(run, &ctx); + + server.waitForConnection(); + + ctx.isShutdownRequested = true; + client_thread.join(); + + lws_context_destroy(context); + + wfp_client_protocol_dispose(protocol); + wfp_client_config_dispose(config); +} \ No newline at end of file diff --git a/test/timeout_watcher.cc b/test/timeout_watcher.cc new file mode 100644 index 0000000..7e3bb52 --- /dev/null +++ b/test/timeout_watcher.cc @@ -0,0 +1,44 @@ +#include "timeout_watcher.hpp" +#include + +using std::chrono::milliseconds; +using std::chrono::duration_cast; +using std::chrono::steady_clock; + +namespace +{ + milliseconds now() + { + return duration_cast(steady_clock::now().time_since_epoch()); + } +} + +namespace webfuse_test +{ + +TimeoutWatcher::TimeoutWatcher(milliseconds timeout) +: startedAt(now()) +, timeout_(timeout) +{ + +} + +TimeoutWatcher::~TimeoutWatcher() +{ + +} + +bool TimeoutWatcher::isTimeout() +{ + return (now() - startedAt) > timeout_; +} + +void TimeoutWatcher::check() +{ + if (isTimeout()) + { + throw std::runtime_error("timeout"); + } +} + +} \ No newline at end of file diff --git a/test/timeout_watcher.hpp b/test/timeout_watcher.hpp new file mode 100644 index 0000000..278d25f --- /dev/null +++ b/test/timeout_watcher.hpp @@ -0,0 +1,26 @@ +#ifndef WF_TEST_TIMEOUT_WATCHER_HPP +#define WF_TEST_TIMEOUT_WATCHER_HPP + +#include + +namespace webfuse_test +{ + +class TimeoutWatcher final +{ + TimeoutWatcher(TimeoutWatcher const & other) = delete; + TimeoutWatcher& operator=(TimeoutWatcher const & other) = delete; +public: + explicit TimeoutWatcher(std::chrono::milliseconds timeout); + ~TimeoutWatcher(); + bool isTimeout(); + void check(); +private: + std::chrono::milliseconds startedAt; + std::chrono::milliseconds timeout_; +}; + +} + + +#endif From a27e68f5a60d605d5bbe46b42bb5b634225564bc Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 20 Feb 2020 17:15:13 +0100 Subject: [PATCH 046/138] organized unit tests --- cmake/unit_tests.cmake | 82 +++++++++---------- .../fakes}/fake_adapter_server.cc | 4 +- .../fakes}/fake_adapter_server.hpp | 0 .../{ => webfuse/mocks}/mock_authenticator.cc | 2 +- .../mocks}/mock_authenticator.hpp | 0 test/{ => webfuse/mocks}/mock_request.cc | 2 +- test/{ => webfuse/mocks}/mock_request.hpp | 0 .../tests}/adapter/jsonrpc/test_is_request.cc | 0 .../adapter/jsonrpc/test_is_response.cc | 0 .../tests}/adapter/jsonrpc/test_proxy.cc | 2 +- .../tests}/adapter/jsonrpc/test_request.cc | 0 .../tests}/adapter/jsonrpc/test_response.cc | 0 .../tests}/adapter/jsonrpc/test_server.cc | 0 .../tests}/adapter/jsonrpc/test_util.cc | 0 .../tests}/adapter/test_authenticator.cc | 2 +- .../tests}/adapter/test_authenticators.cc | 2 +- .../tests}/adapter/test_credentials.cc | 0 .../tests}/adapter/test_fuse_req.cc | 0 .../tests}/adapter/test_mountpoint.cc | 0 .../tests}/adapter/test_response_parser.cc | 0 .../tests}/adapter/test_server.cc | 0 .../tests}/adapter/test_server_config.cc | 2 +- .../tests}/adapter/test_timepoint.cc | 2 +- .../{ => webfuse/tests}/adapter/test_timer.cc | 2 +- .../tests}/adapter/test_uuid_mountpoint.cc | 4 +- .../adapter/test_uuid_mountpoint_factory.cc | 4 +- test/{ => webfuse/tests}/core/test_base64.cc | 0 .../tests}/core/test_container_of.cc | 0 test/{ => webfuse/tests}/core/test_message.cc | 0 .../tests}/core/test_message_queue.cc | 0 test/{ => webfuse/tests}/core/test_path.cc | 0 test/{ => webfuse/tests}/core/test_slist.cc | 0 test/{ => webfuse/tests}/core/test_status.cc | 0 test/{ => webfuse/tests}/core/test_string.cc | 0 .../tests}/integration/provider.cc | 4 +- .../tests}/integration/provider.hpp | 0 .../{ => webfuse/tests}/integration/server.cc | 4 +- .../tests}/integration/server.hpp | 0 .../tests}/integration/test_integration.cc | 6 +- .../tests}/provider/test_client_protocol.cc | 2 +- .../tests}/provider/test_static_filesystem.cc | 2 +- test/{ => webfuse/tests}/provider/test_url.cc | 0 test/{ => webfuse/utils}/die_if.cc | 2 +- test/{ => webfuse/utils}/die_if.hpp | 0 test/{ => webfuse/utils}/file_utils.cc | 2 +- test/{ => webfuse/utils}/file_utils.hpp | 0 test/{ => webfuse/utils}/msleep.cc | 2 +- test/{ => webfuse/utils}/msleep.hpp | 0 test/{ => webfuse/utils}/tempdir.cc | 2 +- test/{ => webfuse/utils}/tempdir.hpp | 0 test/{ => webfuse/utils}/timeout_watcher.cc | 2 +- test/{ => webfuse/utils}/timeout_watcher.hpp | 0 52 files changed, 69 insertions(+), 69 deletions(-) rename test/{ => webfuse/fakes}/fake_adapter_server.cc (97%) rename test/{ => webfuse/fakes}/fake_adapter_server.hpp (100%) rename test/{ => webfuse/mocks}/mock_authenticator.cc (94%) rename test/{ => webfuse/mocks}/mock_authenticator.hpp (100%) rename test/{ => webfuse/mocks}/mock_request.cc (95%) rename test/{ => webfuse/mocks}/mock_request.hpp (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_is_request.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_is_response.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_proxy.cc (99%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_request.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_response.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_server.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_util.cc (100%) rename test/{ => webfuse/tests}/adapter/test_authenticator.cc (97%) rename test/{ => webfuse/tests}/adapter/test_authenticators.cc (99%) rename test/{ => webfuse/tests}/adapter/test_credentials.cc (100%) rename test/{ => webfuse/tests}/adapter/test_fuse_req.cc (100%) rename test/{ => webfuse/tests}/adapter/test_mountpoint.cc (100%) rename test/{ => webfuse/tests}/adapter/test_response_parser.cc (100%) rename test/{ => webfuse/tests}/adapter/test_server.cc (100%) rename test/{ => webfuse/tests}/adapter/test_server_config.cc (99%) rename test/{ => webfuse/tests}/adapter/test_timepoint.cc (95%) rename test/{ => webfuse/tests}/adapter/test_timer.cc (99%) rename test/{ => webfuse/tests}/adapter/test_uuid_mountpoint.cc (96%) rename test/{ => webfuse/tests}/adapter/test_uuid_mountpoint_factory.cc (96%) rename test/{ => webfuse/tests}/core/test_base64.cc (100%) rename test/{ => webfuse/tests}/core/test_container_of.cc (100%) rename test/{ => webfuse/tests}/core/test_message.cc (100%) rename test/{ => webfuse/tests}/core/test_message_queue.cc (100%) rename test/{ => webfuse/tests}/core/test_path.cc (100%) rename test/{ => webfuse/tests}/core/test_slist.cc (100%) rename test/{ => webfuse/tests}/core/test_status.cc (100%) rename test/{ => webfuse/tests}/core/test_string.cc (100%) rename test/{ => webfuse/tests}/integration/provider.cc (95%) rename test/{ => webfuse/tests}/integration/provider.hpp (100%) rename test/{ => webfuse/tests}/integration/server.cc (95%) rename test/{ => webfuse/tests}/integration/server.hpp (100%) rename test/{ => webfuse/tests}/integration/test_integration.cc (96%) rename test/{ => webfuse/tests}/provider/test_client_protocol.cc (97%) rename test/{ => webfuse/tests}/provider/test_static_filesystem.cc (98%) rename test/{ => webfuse/tests}/provider/test_url.cc (100%) rename test/{ => webfuse/utils}/die_if.cc (80%) rename test/{ => webfuse/utils}/die_if.hpp (100%) rename test/{ => webfuse/utils}/file_utils.cc (94%) rename test/{ => webfuse/utils}/file_utils.hpp (100%) rename test/{ => webfuse/utils}/msleep.cc (91%) rename test/{ => webfuse/utils}/msleep.hpp (100%) rename test/{ => webfuse/utils}/tempdir.cc (92%) rename test/{ => webfuse/utils}/tempdir.hpp (100%) rename test/{ => webfuse/utils}/timeout_watcher.cc (93%) rename test/{ => webfuse/utils}/timeout_watcher.hpp (100%) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index c4f779e..14ff04d 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,47 +7,47 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests - test/tempdir.cc - test/file_utils.cc - test/msleep.cc - test/die_if.cc - test/timeout_watcher.cc - test/fake_adapter_server.cc - test/mock_authenticator.cc - test/mock_request.cc - test/core/test_container_of.cc - test/core/test_string.cc - test/core/test_slist.cc - test/core/test_path.cc - test/core/test_base64.cc - test/core/test_status.cc - test/core/test_message.cc - test/core/test_message_queue.cc - test/adapter/test_response_parser.cc - test/adapter/test_server.cc - test/adapter/test_server_config.cc - test/adapter/test_timepoint.cc - test/adapter/test_timer.cc - test/adapter/test_credentials.cc - test/adapter/test_authenticator.cc - test/adapter/test_authenticators.cc - test/adapter/test_mountpoint.cc - test/adapter/test_uuid_mountpoint.cc - test/adapter/test_uuid_mountpoint_factory.cc - test/adapter/test_fuse_req.cc - test/adapter/jsonrpc/test_util.cc - test/adapter/jsonrpc/test_is_request.cc - test/adapter/jsonrpc/test_request.cc - test/adapter/jsonrpc/test_is_response.cc - test/adapter/jsonrpc/test_response.cc - test/adapter/jsonrpc/test_server.cc - test/adapter/jsonrpc/test_proxy.cc - test/provider/test_url.cc - test/provider/test_static_filesystem.cc - test/provider/test_client_protocol.cc - test/integration/test_integration.cc - test/integration/server.cc - test/integration/provider.cc + test/webfuse/utils/tempdir.cc + test/webfuse/utils/file_utils.cc + test/webfuse/utils/msleep.cc + test/webfuse/utils/die_if.cc + test/webfuse/utils/timeout_watcher.cc + test/webfuse/fakes/fake_adapter_server.cc + test/webfuse/mocks/mock_authenticator.cc + test/webfuse/mocks/mock_request.cc + test/webfuse/tests/core/test_container_of.cc + test/webfuse/tests/core/test_string.cc + test/webfuse/tests/core/test_slist.cc + test/webfuse/tests/core/test_path.cc + test/webfuse/tests/core/test_base64.cc + test/webfuse/tests/core/test_status.cc + test/webfuse/tests/core/test_message.cc + test/webfuse/tests/core/test_message_queue.cc + test/webfuse/tests/adapter/test_response_parser.cc + test/webfuse/tests/adapter/test_server.cc + test/webfuse/tests/adapter/test_server_config.cc + test/webfuse/tests/adapter/test_timepoint.cc + test/webfuse/tests/adapter/test_timer.cc + test/webfuse/tests/adapter/test_credentials.cc + test/webfuse/tests/adapter/test_authenticator.cc + test/webfuse/tests/adapter/test_authenticators.cc + test/webfuse/tests/adapter/test_mountpoint.cc + test/webfuse/tests/adapter/test_uuid_mountpoint.cc + test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc + test/webfuse/tests/adapter/test_fuse_req.cc + test/webfuse/tests/adapter/jsonrpc/test_util.cc + test/webfuse/tests/adapter/jsonrpc/test_is_request.cc + test/webfuse/tests/adapter/jsonrpc/test_request.cc + test/webfuse/tests/adapter/jsonrpc/test_is_response.cc + test/webfuse/tests/adapter/jsonrpc/test_response.cc + test/webfuse/tests/adapter/jsonrpc/test_server.cc + test/webfuse/tests/adapter/jsonrpc/test_proxy.cc + test/webfuse/tests/provider/test_url.cc + test/webfuse/tests/provider/test_static_filesystem.cc + test/webfuse/tests/provider/test_client_protocol.cc + test/webfuse/tests/integration/test_integration.cc + test/webfuse/tests/integration/server.cc + test/webfuse/tests/integration/provider.cc ) target_include_directories(alltests PRIVATE diff --git a/test/fake_adapter_server.cc b/test/webfuse/fakes/fake_adapter_server.cc similarity index 97% rename from test/fake_adapter_server.cc rename to test/webfuse/fakes/fake_adapter_server.cc index 72a1831..bebd3d9 100644 --- a/test/fake_adapter_server.cc +++ b/test/webfuse/fakes/fake_adapter_server.cc @@ -1,5 +1,5 @@ -#include "fake_adapter_server.hpp" -#include "timeout_watcher.hpp" +#include "webfuse/fakes/fake_adapter_server.hpp" +#include "webfuse/utils/timeout_watcher.hpp" #include "webfuse/core/util.h" #include diff --git a/test/fake_adapter_server.hpp b/test/webfuse/fakes/fake_adapter_server.hpp similarity index 100% rename from test/fake_adapter_server.hpp rename to test/webfuse/fakes/fake_adapter_server.hpp diff --git a/test/mock_authenticator.cc b/test/webfuse/mocks/mock_authenticator.cc similarity index 94% rename from test/mock_authenticator.cc rename to test/webfuse/mocks/mock_authenticator.cc index f2decab..35648ed 100644 --- a/test/mock_authenticator.cc +++ b/test/webfuse/mocks/mock_authenticator.cc @@ -1,4 +1,4 @@ -#include "mock_authenticator.hpp" +#include "webfuse/mocks/mock_authenticator.hpp" #define WF_AUTHENTICATOR_COUNT 3 diff --git a/test/mock_authenticator.hpp b/test/webfuse/mocks/mock_authenticator.hpp similarity index 100% rename from test/mock_authenticator.hpp rename to test/webfuse/mocks/mock_authenticator.hpp diff --git a/test/mock_request.cc b/test/webfuse/mocks/mock_request.cc similarity index 95% rename from test/mock_request.cc rename to test/webfuse/mocks/mock_request.cc index efd8334..c2dd441 100644 --- a/test/mock_request.cc +++ b/test/webfuse/mocks/mock_request.cc @@ -1,4 +1,4 @@ -#include "mock_request.hpp" +#include "webfuse/mocks/mock_request.hpp" #include namespace diff --git a/test/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp similarity index 100% rename from test/mock_request.hpp rename to test/webfuse/mocks/mock_request.hpp diff --git a/test/adapter/jsonrpc/test_is_request.cc b/test/webfuse/tests/adapter/jsonrpc/test_is_request.cc similarity index 100% rename from test/adapter/jsonrpc/test_is_request.cc rename to test/webfuse/tests/adapter/jsonrpc/test_is_request.cc diff --git a/test/adapter/jsonrpc/test_is_response.cc b/test/webfuse/tests/adapter/jsonrpc/test_is_response.cc similarity index 100% rename from test/adapter/jsonrpc/test_is_response.cc rename to test/webfuse/tests/adapter/jsonrpc/test_is_response.cc diff --git a/test/adapter/jsonrpc/test_proxy.cc b/test/webfuse/tests/adapter/jsonrpc/test_proxy.cc similarity index 99% rename from test/adapter/jsonrpc/test_proxy.cc rename to test/webfuse/tests/adapter/jsonrpc/test_proxy.cc index 1355c4e..8f99312 100644 --- a/test/adapter/jsonrpc/test_proxy.cc +++ b/test/webfuse/tests/adapter/jsonrpc/test_proxy.cc @@ -1,7 +1,7 @@ #include #include "webfuse/adapter/impl/jsonrpc/proxy.h" #include "webfuse/adapter/impl/time/timeout_manager.h" -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" using webfuse_test::msleep; diff --git a/test/adapter/jsonrpc/test_request.cc b/test/webfuse/tests/adapter/jsonrpc/test_request.cc similarity index 100% rename from test/adapter/jsonrpc/test_request.cc rename to test/webfuse/tests/adapter/jsonrpc/test_request.cc diff --git a/test/adapter/jsonrpc/test_response.cc b/test/webfuse/tests/adapter/jsonrpc/test_response.cc similarity index 100% rename from test/adapter/jsonrpc/test_response.cc rename to test/webfuse/tests/adapter/jsonrpc/test_response.cc diff --git a/test/adapter/jsonrpc/test_server.cc b/test/webfuse/tests/adapter/jsonrpc/test_server.cc similarity index 100% rename from test/adapter/jsonrpc/test_server.cc rename to test/webfuse/tests/adapter/jsonrpc/test_server.cc diff --git a/test/adapter/jsonrpc/test_util.cc b/test/webfuse/tests/adapter/jsonrpc/test_util.cc similarity index 100% rename from test/adapter/jsonrpc/test_util.cc rename to test/webfuse/tests/adapter/jsonrpc/test_util.cc diff --git a/test/adapter/test_authenticator.cc b/test/webfuse/tests/adapter/test_authenticator.cc similarity index 97% rename from test/adapter/test_authenticator.cc rename to test/webfuse/tests/adapter/test_authenticator.cc index 93505a9..07e06e5 100644 --- a/test/adapter/test_authenticator.cc +++ b/test/webfuse/tests/adapter/test_authenticator.cc @@ -1,7 +1,7 @@ #include #include -#include "mock_authenticator.hpp" +#include "webfuse/mocks/mock_authenticator.hpp" #include "webfuse/adapter/impl/authenticator.h" #include "webfuse/adapter/impl/credentials.h" diff --git a/test/adapter/test_authenticators.cc b/test/webfuse/tests/adapter/test_authenticators.cc similarity index 99% rename from test/adapter/test_authenticators.cc rename to test/webfuse/tests/adapter/test_authenticators.cc index 3227e57..6cb8064 100644 --- a/test/adapter/test_authenticators.cc +++ b/test/webfuse/tests/adapter/test_authenticators.cc @@ -3,7 +3,7 @@ #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/credentials.h" -#include "mock_authenticator.hpp" +#include "webfuse/mocks/mock_authenticator.hpp" using ::testing::_; using ::testing::Return; diff --git a/test/adapter/test_credentials.cc b/test/webfuse/tests/adapter/test_credentials.cc similarity index 100% rename from test/adapter/test_credentials.cc rename to test/webfuse/tests/adapter/test_credentials.cc diff --git a/test/adapter/test_fuse_req.cc b/test/webfuse/tests/adapter/test_fuse_req.cc similarity index 100% rename from test/adapter/test_fuse_req.cc rename to test/webfuse/tests/adapter/test_fuse_req.cc diff --git a/test/adapter/test_mountpoint.cc b/test/webfuse/tests/adapter/test_mountpoint.cc similarity index 100% rename from test/adapter/test_mountpoint.cc rename to test/webfuse/tests/adapter/test_mountpoint.cc diff --git a/test/adapter/test_response_parser.cc b/test/webfuse/tests/adapter/test_response_parser.cc similarity index 100% rename from test/adapter/test_response_parser.cc rename to test/webfuse/tests/adapter/test_response_parser.cc diff --git a/test/adapter/test_server.cc b/test/webfuse/tests/adapter/test_server.cc similarity index 100% rename from test/adapter/test_server.cc rename to test/webfuse/tests/adapter/test_server.cc diff --git a/test/adapter/test_server_config.cc b/test/webfuse/tests/adapter/test_server_config.cc similarity index 99% rename from test/adapter/test_server_config.cc rename to test/webfuse/tests/adapter/test_server_config.cc index cb176d6..f85aa92 100644 --- a/test/adapter/test_server_config.cc +++ b/test/webfuse/tests/adapter/test_server_config.cc @@ -2,7 +2,7 @@ #include "webfuse/adapter/server_config.h" #include "webfuse/adapter/impl/server_config.h" #include "webfuse/adapter/impl/authenticator.h" -#include "tempdir.hpp" +#include "webfuse/utils/tempdir.hpp" using webfuse_test::TempDir; diff --git a/test/adapter/test_timepoint.cc b/test/webfuse/tests/adapter/test_timepoint.cc similarity index 95% rename from test/adapter/test_timepoint.cc rename to test/webfuse/tests/adapter/test_timepoint.cc index 85de35d..8b0db97 100644 --- a/test/adapter/test_timepoint.cc +++ b/test/webfuse/tests/adapter/test_timepoint.cc @@ -1,6 +1,6 @@ #include -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" #include "webfuse/adapter/impl/time/timepoint.h" using webfuse_test::msleep; diff --git a/test/adapter/test_timer.cc b/test/webfuse/tests/adapter/test_timer.cc similarity index 99% rename from test/adapter/test_timer.cc rename to test/webfuse/tests/adapter/test_timer.cc index b838147..d554f2d 100644 --- a/test/adapter/test_timer.cc +++ b/test/webfuse/tests/adapter/test_timer.cc @@ -2,7 +2,7 @@ #include -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" #include "webfuse/adapter/impl/time/timer.h" #include "webfuse/adapter/impl/time/timeout_manager.h" diff --git a/test/adapter/test_uuid_mountpoint.cc b/test/webfuse/tests/adapter/test_uuid_mountpoint.cc similarity index 96% rename from test/adapter/test_uuid_mountpoint.cc rename to test/webfuse/tests/adapter/test_uuid_mountpoint.cc index 8bff760..7549b84 100644 --- a/test/adapter/test_uuid_mountpoint.cc +++ b/test/webfuse/tests/adapter/test_uuid_mountpoint.cc @@ -1,7 +1,7 @@ #include -#include "tempdir.hpp" -#include "file_utils.hpp" +#include "webfuse/utils/tempdir.hpp" +#include "webfuse/utils/file_utils.hpp" #include "webfuse_adapter.h" #include "webfuse/adapter/impl/uuid_mountpoint.h" diff --git a/test/adapter/test_uuid_mountpoint_factory.cc b/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc similarity index 96% rename from test/adapter/test_uuid_mountpoint_factory.cc rename to test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc index b097ae0..dca941f 100644 --- a/test/adapter/test_uuid_mountpoint_factory.cc +++ b/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc @@ -1,8 +1,8 @@ #include #include "webfuse_adapter.h" #include "webfuse/adapter/impl/uuid_mountpoint_factory.h" -#include "tempdir.hpp" -#include "file_utils.hpp" +#include "webfuse/utils/tempdir.hpp" +#include "webfuse/utils/file_utils.hpp" using webfuse_test::TempDir; using webfuse_test::is_dir; diff --git a/test/core/test_base64.cc b/test/webfuse/tests/core/test_base64.cc similarity index 100% rename from test/core/test_base64.cc rename to test/webfuse/tests/core/test_base64.cc diff --git a/test/core/test_container_of.cc b/test/webfuse/tests/core/test_container_of.cc similarity index 100% rename from test/core/test_container_of.cc rename to test/webfuse/tests/core/test_container_of.cc diff --git a/test/core/test_message.cc b/test/webfuse/tests/core/test_message.cc similarity index 100% rename from test/core/test_message.cc rename to test/webfuse/tests/core/test_message.cc diff --git a/test/core/test_message_queue.cc b/test/webfuse/tests/core/test_message_queue.cc similarity index 100% rename from test/core/test_message_queue.cc rename to test/webfuse/tests/core/test_message_queue.cc diff --git a/test/core/test_path.cc b/test/webfuse/tests/core/test_path.cc similarity index 100% rename from test/core/test_path.cc rename to test/webfuse/tests/core/test_path.cc diff --git a/test/core/test_slist.cc b/test/webfuse/tests/core/test_slist.cc similarity index 100% rename from test/core/test_slist.cc rename to test/webfuse/tests/core/test_slist.cc diff --git a/test/core/test_status.cc b/test/webfuse/tests/core/test_status.cc similarity index 100% rename from test/core/test_status.cc rename to test/webfuse/tests/core/test_status.cc diff --git a/test/core/test_string.cc b/test/webfuse/tests/core/test_string.cc similarity index 100% rename from test/core/test_string.cc rename to test/webfuse/tests/core/test_string.cc diff --git a/test/integration/provider.cc b/test/webfuse/tests/integration/provider.cc similarity index 95% rename from test/integration/provider.cc rename to test/webfuse/tests/integration/provider.cc index 3ee4285..49c334a 100644 --- a/test/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -1,10 +1,10 @@ -#include "integration/provider.hpp" +#include "webfuse/tests/integration/provider.hpp" #include "webfuse_provider.h" #include "webfuse/provider/impl/client.h" #include #include #include -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" namespace webfuse_test { diff --git a/test/integration/provider.hpp b/test/webfuse/tests/integration/provider.hpp similarity index 100% rename from test/integration/provider.hpp rename to test/webfuse/tests/integration/provider.hpp diff --git a/test/integration/server.cc b/test/webfuse/tests/integration/server.cc similarity index 95% rename from test/integration/server.cc rename to test/webfuse/tests/integration/server.cc index 0659efe..1360934 100644 --- a/test/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -1,4 +1,4 @@ -#include "integration/server.hpp" +#include "webfuse/tests/integration/server.hpp" #include #include #include @@ -6,7 +6,7 @@ #include #include "webfuse_adapter.h" #include "webfuse/adapter/impl/server.h" -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" #define WF_PATH_MAX (100) diff --git a/test/integration/server.hpp b/test/webfuse/tests/integration/server.hpp similarity index 100% rename from test/integration/server.hpp rename to test/webfuse/tests/integration/server.hpp diff --git a/test/integration/test_integration.cc b/test/webfuse/tests/integration/test_integration.cc similarity index 96% rename from test/integration/test_integration.cc rename to test/webfuse/tests/integration/test_integration.cc index 8bd21c6..203856c 100644 --- a/test/integration/test_integration.cc +++ b/test/webfuse/tests/integration/test_integration.cc @@ -1,6 +1,6 @@ #include -#include "integration/server.hpp" -#include "integration/provider.hpp" +#include "webfuse/tests/integration/server.hpp" +#include "webfuse/tests/integration/provider.hpp" #include #include @@ -15,7 +15,7 @@ #include #include "webfuse/core/lws_log.h" -#include "die_if.hpp" +#include "webfuse/utils/die_if.hpp" using webfuse_test::Server; using webfuse_test::Provider; diff --git a/test/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc similarity index 97% rename from test/provider/test_client_protocol.cc rename to test/webfuse/tests/provider/test_client_protocol.cc index 4e78f8e..ef058f7 100644 --- a/test/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -3,7 +3,7 @@ #include #include -#include "fake_adapter_server.hpp" +#include "webfuse/fakes/fake_adapter_server.hpp" #include #include diff --git a/test/provider/test_static_filesystem.cc b/test/webfuse/tests/provider/test_static_filesystem.cc similarity index 98% rename from test/provider/test_static_filesystem.cc rename to test/webfuse/tests/provider/test_static_filesystem.cc index e7db28e..64a2736 100644 --- a/test/provider/test_static_filesystem.cc +++ b/test/webfuse/tests/provider/test_static_filesystem.cc @@ -4,7 +4,7 @@ #include "webfuse/provider/client_config.h" #include "webfuse/provider/impl/client_config.h" -#include "mock_request.hpp" +#include "webfuse/mocks/mock_request.hpp" using webfuse_test::request_create; using webfuse_test::MockRequest; diff --git a/test/provider/test_url.cc b/test/webfuse/tests/provider/test_url.cc similarity index 100% rename from test/provider/test_url.cc rename to test/webfuse/tests/provider/test_url.cc diff --git a/test/die_if.cc b/test/webfuse/utils/die_if.cc similarity index 80% rename from test/die_if.cc rename to test/webfuse/utils/die_if.cc index 3eff5ae..bd8dd70 100644 --- a/test/die_if.cc +++ b/test/webfuse/utils/die_if.cc @@ -1,4 +1,4 @@ -#include "die_if.hpp" +#include "webfuse/utils/die_if.hpp" #include namespace webfuse_test diff --git a/test/die_if.hpp b/test/webfuse/utils/die_if.hpp similarity index 100% rename from test/die_if.hpp rename to test/webfuse/utils/die_if.hpp diff --git a/test/file_utils.cc b/test/webfuse/utils/file_utils.cc similarity index 94% rename from test/file_utils.cc rename to test/webfuse/utils/file_utils.cc index 0d3ff81..7a3d29c 100644 --- a/test/file_utils.cc +++ b/test/webfuse/utils/file_utils.cc @@ -1,4 +1,4 @@ -#include "file_utils.hpp" +#include "webfuse/utils/file_utils.hpp" #include #include diff --git a/test/file_utils.hpp b/test/webfuse/utils/file_utils.hpp similarity index 100% rename from test/file_utils.hpp rename to test/webfuse/utils/file_utils.hpp diff --git a/test/msleep.cc b/test/webfuse/utils/msleep.cc similarity index 91% rename from test/msleep.cc rename to test/webfuse/utils/msleep.cc index 5f76e49..659bb81 100644 --- a/test/msleep.cc +++ b/test/webfuse/utils/msleep.cc @@ -1,4 +1,4 @@ -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" #include namespace webfuse_test diff --git a/test/msleep.hpp b/test/webfuse/utils/msleep.hpp similarity index 100% rename from test/msleep.hpp rename to test/webfuse/utils/msleep.hpp diff --git a/test/tempdir.cc b/test/webfuse/utils/tempdir.cc similarity index 92% rename from test/tempdir.cc rename to test/webfuse/utils/tempdir.cc index 040aed1..31dce25 100644 --- a/test/tempdir.cc +++ b/test/webfuse/utils/tempdir.cc @@ -1,5 +1,5 @@ #include "webfuse/core/string.h" -#include "tempdir.hpp" +#include "webfuse/utils/tempdir.hpp" #include #include diff --git a/test/tempdir.hpp b/test/webfuse/utils/tempdir.hpp similarity index 100% rename from test/tempdir.hpp rename to test/webfuse/utils/tempdir.hpp diff --git a/test/timeout_watcher.cc b/test/webfuse/utils/timeout_watcher.cc similarity index 93% rename from test/timeout_watcher.cc rename to test/webfuse/utils/timeout_watcher.cc index 7e3bb52..8d9add7 100644 --- a/test/timeout_watcher.cc +++ b/test/webfuse/utils/timeout_watcher.cc @@ -1,4 +1,4 @@ -#include "timeout_watcher.hpp" +#include "webfuse/utils/timeout_watcher.hpp" #include using std::chrono::milliseconds; diff --git a/test/timeout_watcher.hpp b/test/webfuse/utils/timeout_watcher.hpp similarity index 100% rename from test/timeout_watcher.hpp rename to test/webfuse/utils/timeout_watcher.hpp From 17fa84bc3871eec23edfcc1bcf2be15489499180 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 20 Feb 2020 18:54:29 +0100 Subject: [PATCH 047/138] made static_filesystem private (used for test purposes only) --- cmake/unit_tests.cmake | 4 +- cmake/webfuse_core.cmake | 1 - cmake/webfuse_provider.cmake | 1 - include/webfuse/provider/static_filesystem.h | 114 ------------------ include/webfuse_provider.h | 2 - lib/webfuse/provider/api.c | 58 --------- lib/webfuse/provider/impl/static_filesystem.h | 52 -------- test/webfuse/tests/core/test_path.cc | 58 --------- test/webfuse/tests/integration/provider.cc | 1 + .../tests/provider/test_static_filesystem.cc | 61 ---------- .../core => test/webfuse/utils}/path.c | 2 +- .../core => test/webfuse/utils}/path.h | 0 .../webfuse/utils}/static_filesystem.c | 104 ++++++++-------- test/webfuse/utils/static_filesystem.h | 77 ++++++++++++ 14 files changed, 133 insertions(+), 402 deletions(-) delete mode 100644 include/webfuse/provider/static_filesystem.h delete mode 100644 lib/webfuse/provider/impl/static_filesystem.h delete mode 100644 test/webfuse/tests/core/test_path.cc delete mode 100644 test/webfuse/tests/provider/test_static_filesystem.cc rename {lib/webfuse/core => test/webfuse/utils}/path.c (98%) rename {lib/webfuse/core => test/webfuse/utils}/path.h (100%) rename {lib/webfuse/provider/impl => test/webfuse/utils}/static_filesystem.c (75%) create mode 100644 test/webfuse/utils/static_filesystem.h diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 14ff04d..dfc804e 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -12,13 +12,14 @@ add_executable(alltests test/webfuse/utils/msleep.cc test/webfuse/utils/die_if.cc test/webfuse/utils/timeout_watcher.cc + test/webfuse/utils/path.c + test/webfuse/utils/static_filesystem.c test/webfuse/fakes/fake_adapter_server.cc test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc test/webfuse/tests/core/test_slist.cc - test/webfuse/tests/core/test_path.cc test/webfuse/tests/core/test_base64.cc test/webfuse/tests/core/test_status.cc test/webfuse/tests/core/test_message.cc @@ -43,7 +44,6 @@ add_executable(alltests test/webfuse/tests/adapter/jsonrpc/test_server.cc test/webfuse/tests/adapter/jsonrpc/test_proxy.cc test/webfuse/tests/provider/test_url.cc - test/webfuse/tests/provider/test_static_filesystem.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index b162f40..52c7681 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -6,7 +6,6 @@ add_library(webfuse-core STATIC lib/webfuse/core/message_queue.c lib/webfuse/core/status.c lib/webfuse/core/string.c - lib/webfuse/core/path.c lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c ) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index b42f1f4..5079cb1 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -15,7 +15,6 @@ add_library(webfuse-provider-static STATIC lib/webfuse/provider/impl/operation/open.c lib/webfuse/provider/impl/operation/close.c lib/webfuse/provider/impl/operation/read.c - lib/webfuse/provider/impl/static_filesystem.c ) set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider) diff --git a/include/webfuse/provider/static_filesystem.h b/include/webfuse/provider/static_filesystem.h deleted file mode 100644 index e736976..0000000 --- a/include/webfuse/provider/static_filesystem.h +++ /dev/null @@ -1,114 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// \file provider/static_filesystem.h -/// \brief Reference implementation of static filesystem. -/// -/// This header is used by integration tests. It may be removed from the -/// library. -/// -/// \todo Remove this header from library -//////////////////////////////////////////////////////////////////////////////// - -#ifndef WFP_STATIC_FILESYSTEM_H -#define WFP_STATIC_FILESYSTEM_H - -#ifndef __cplusplus -#include -#else -#include -using ::std::size_t; -#endif - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wfp_client_config; - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -struct wfp_static_filesystem; - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -typedef size_t -wfp_static_filesystem_read_fn( - size_t offset, - char * buffer, - size_t buffer_size, - void * user_data); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -typedef void -wfp_static_filesystem_get_info_fn( - void * user_data, - int * result_mode, - size_t * result_size); - - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API struct wfp_static_filesystem * -wfp_static_filesystem_create( - struct wfp_client_config * config); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_dispose( - struct wfp_static_filesystem * filesystem); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_add( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content, - size_t length); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_add_text( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/webfuse_provider.h b/include/webfuse_provider.h index 5882c60..bd119ac 100644 --- a/include/webfuse_provider.h +++ b/include/webfuse_provider.h @@ -22,6 +22,4 @@ #include #include -#include - #endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 933516b..0c0e88a 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -11,7 +11,6 @@ #include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/client.h" #include "webfuse/provider/impl/dirbuffer.h" -#include "webfuse/provider/impl/static_filesystem.h" // respond @@ -241,60 +240,3 @@ void wfp_dirbuffer_add( { wfp_impl_dirbuffer_add(buffer, name, inode); } - -// static_filesystem - -struct wfp_static_filesystem * -wfp_static_filesystem_create( - struct wfp_client_config * config) -{ - return wfp_impl_static_filesystem_create(config); -} - -void -wfp_static_filesystem_dispose( - struct wfp_static_filesystem * filesystem) -{ - wfp_impl_static_filesystem_dispose(filesystem); -} - -void -wfp_static_filesystem_add( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content, - size_t length) -{ - wfp_impl_static_filesystem_add(filesystem, path, mode, content, length); -} - -void -wfp_static_filesystem_add_text( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content) -{ - wfp_impl_static_filesystem_add_text(filesystem, path, mode, content); -} - -void -wfp_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename) -{ - wfp_impl_static_filesystem_add_file(filesystem, path, filename); -} - -void -wfp_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data) -{ - wfp_impl_static_filesystem_add_generic(filesystem, path, read, get_info, user_data); -} diff --git a/lib/webfuse/provider/impl/static_filesystem.h b/lib/webfuse/provider/impl/static_filesystem.h deleted file mode 100644 index a18835d..0000000 --- a/lib/webfuse/provider/impl/static_filesystem.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef WFP_IMPL_STATIC_FILESYSTEM_H -#define WFP_IMPL_STATIC_FILESYSTEM_H - -#include "webfuse/provider/static_filesystem.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern struct wfp_static_filesystem * -wfp_impl_static_filesystem_create( - struct wfp_client_config * config); - -extern void -wfp_impl_static_filesystem_dispose( - struct wfp_static_filesystem * filesystem); - -extern void -wfp_impl_static_filesystem_add( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content, - size_t length); - -extern void -wfp_impl_static_filesystem_add_text( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content); - -extern void -wfp_impl_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename); - -extern void -wfp_impl_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test/webfuse/tests/core/test_path.cc b/test/webfuse/tests/core/test_path.cc deleted file mode 100644 index 93783ec..0000000 --- a/test/webfuse/tests/core/test_path.cc +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include "webfuse/core/path.h" - -TEST(wf_path, empty) -{ - struct wf_path * path = wf_path_create(""); - ASSERT_EQ(0, wf_path_element_count(path)); - ASSERT_EQ(nullptr, wf_path_get_element(path, 0)); - - wf_path_dispose(path); -} - -TEST(wf_path, relative_file) -{ - struct wf_path * path = wf_path_create("some.file"); - ASSERT_EQ(1, wf_path_element_count(path)); - ASSERT_STREQ("some.file", wf_path_get_element(path, 0)); - - wf_path_dispose(path); -} - -TEST(wf_path, absolute_file) -{ - struct wf_path * path = wf_path_create("/absolute.file"); - ASSERT_EQ(1, wf_path_element_count(path)); - ASSERT_STREQ("absolute.file", wf_path_get_element(path, 0)); - - wf_path_dispose(path); -} - -TEST(wf_path, nested_path) -{ - struct wf_path * path = wf_path_create("/a/nested/path"); - ASSERT_EQ(3, wf_path_element_count(path)); - ASSERT_STREQ("a", wf_path_get_element(path, 0)); - ASSERT_STREQ("nested", wf_path_get_element(path, 1)); - ASSERT_STREQ("path", wf_path_get_element(path, 2)); - - wf_path_dispose(path); -} - -TEST(wf_path, deep_nested_path) -{ - struct wf_path * path = wf_path_create("/this/is/a/very/deep/nested/path/to/some/file"); - ASSERT_EQ(10, wf_path_element_count(path)); - ASSERT_STREQ("this", wf_path_get_element(path, 0)); - ASSERT_STREQ("is", wf_path_get_element(path, 1)); - ASSERT_STREQ("a", wf_path_get_element(path, 2)); - ASSERT_STREQ("very", wf_path_get_element(path, 3)); - ASSERT_STREQ("deep", wf_path_get_element(path, 4)); - ASSERT_STREQ("nested", wf_path_get_element(path, 5)); - ASSERT_STREQ("path", wf_path_get_element(path, 6)); - ASSERT_STREQ("to", wf_path_get_element(path, 7)); - ASSERT_STREQ("some", wf_path_get_element(path, 8)); - ASSERT_STREQ("file", wf_path_get_element(path, 9)); - - wf_path_dispose(path); -} \ No newline at end of file diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index 49c334a..5142ca8 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -5,6 +5,7 @@ #include #include #include "webfuse/utils/msleep.hpp" +#include "webfuse/utils/static_filesystem.h" namespace webfuse_test { diff --git a/test/webfuse/tests/provider/test_static_filesystem.cc b/test/webfuse/tests/provider/test_static_filesystem.cc deleted file mode 100644 index 64a2736..0000000 --- a/test/webfuse/tests/provider/test_static_filesystem.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#include "webfuse/provider/impl/static_filesystem.h" -#include "webfuse/provider/client_config.h" -#include "webfuse/provider/impl/client_config.h" - -#include "webfuse/mocks/mock_request.hpp" - -using webfuse_test::request_create; -using webfuse_test::MockRequest; -using webfuse_test::GetAttrMatcher; -using webfuse_test::ReaddirMatcher; -using testing::_; - -TEST(wfp_static_filesystem, has_root_dir) -{ - struct wfp_client_config * config = wfp_client_config_create(); - struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config); - - MockRequest mock; - struct wfp_request * request = request_create(&mock, 42); - EXPECT_CALL(mock, respond(GetAttrMatcher(1, 0555, "dir"), 42)).Times(1); - - config->provider.getattr(request, 1, config->user_data); - - wfp_impl_static_filesystem_dispose(filesystem); - wfp_client_config_dispose(config); -} - -TEST(wfp_static_filesystem, contains_default_dirs) -{ - struct wfp_client_config * config = wfp_client_config_create(); - struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config); - - MockRequest mock; - struct wfp_request * request = request_create(&mock, 23); - char const * default_dirs[] = {".", "..", nullptr}; - EXPECT_CALL(mock, respond(ReaddirMatcher(default_dirs), 23)).Times(1); - - config->provider.readdir(request, 1, config->user_data); - - wfp_impl_static_filesystem_dispose(filesystem); - wfp_client_config_dispose(config); -} - -TEST(wfp_static_filesystem, add_text) -{ - struct wfp_client_config * config = wfp_client_config_create(); - struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config); - wfp_impl_static_filesystem_add_text(filesystem, "text.file", 666, "some text"); - - MockRequest mock; - struct wfp_request * request = request_create(&mock, 23); - char const * contained_elements[] = {"text.file", nullptr}; - EXPECT_CALL(mock, respond(ReaddirMatcher(contained_elements), 23)).Times(1); - - config->provider.readdir(request, 1, config->user_data); - - wfp_impl_static_filesystem_dispose(filesystem); - wfp_client_config_dispose(config); -} diff --git a/lib/webfuse/core/path.c b/test/webfuse/utils/path.c similarity index 98% rename from lib/webfuse/core/path.c rename to test/webfuse/utils/path.c index 36689f0..3cb222e 100644 --- a/lib/webfuse/core/path.c +++ b/test/webfuse/utils/path.c @@ -1,4 +1,4 @@ -#include "webfuse/core/path.h" +#include "webfuse/utils/path.h" #include #include diff --git a/lib/webfuse/core/path.h b/test/webfuse/utils/path.h similarity index 100% rename from lib/webfuse/core/path.h rename to test/webfuse/utils/path.h diff --git a/lib/webfuse/provider/impl/static_filesystem.c b/test/webfuse/utils/static_filesystem.c similarity index 75% rename from lib/webfuse/provider/impl/static_filesystem.c rename to test/webfuse/utils/static_filesystem.c index 83c3b92..7212e7a 100644 --- a/lib/webfuse/provider/impl/static_filesystem.c +++ b/test/webfuse/utils/static_filesystem.c @@ -1,9 +1,9 @@ -#include "webfuse/provider/impl/static_filesystem.h" +#include "webfuse/utils/static_filesystem.h" #include "webfuse/provider/client_config.h" #include "webfuse/provider/dirbuffer.h" #include "webfuse/provider/operation/error.h" -#include "webfuse/core/path.h" +#include "webfuse/utils/path.h" #include "webfuse/core/util.h" #include @@ -41,7 +41,7 @@ struct wfp_static_filesystem }; static struct wfp_static_filesystem_entry * -wfp_impl_static_filesystem_get_entry( +wfp_static_filesystem_get_entry( struct wfp_static_filesystem * filesystem, size_t inode) { @@ -56,7 +56,7 @@ wfp_impl_static_filesystem_get_entry( } static struct wfp_static_filesystem_entry * -wfp_impl_static_filesystem_get_entry_by_name( +wfp_static_filesystem_get_entry_by_name( struct wfp_static_filesystem * filesystem, size_t parent, char const * name) @@ -76,7 +76,7 @@ wfp_impl_static_filesystem_get_entry_by_name( } static struct wfp_static_filesystem_entry * -wfp_impl_static_filesystem_add_entry( +wfp_static_filesystem_add_entry( struct wfp_static_filesystem * filesystem) { struct wfp_static_filesystem_entry * entry = NULL; @@ -107,7 +107,7 @@ wfp_impl_static_filesystem_add_entry( } static size_t -wfp_impl_static_filesystem_entry_read( +wfp_static_filesystem_entry_read( size_t offset, char * buffer, size_t buffer_size, @@ -126,7 +126,7 @@ wfp_impl_static_filesystem_entry_read( } static void -wfp_impl_static_filesystem_entry_get_info( +wfp_static_filesystem_entry_get_info( void * user_data, int * result_mode, size_t * result_size) @@ -137,7 +137,7 @@ wfp_impl_static_filesystem_entry_get_info( } static size_t -wfp_impl_static_filesystem_file_read( +wfp_static_filesystem_file_read( size_t offset, char * buffer, size_t buffer_size, @@ -159,7 +159,7 @@ wfp_impl_static_filesystem_file_read( } static void -wfp_impl_static_filesystem_file_get_info( +wfp_static_filesystem_file_get_info( void * user_data, int * result_mode, size_t * result_size) @@ -176,23 +176,23 @@ wfp_impl_static_filesystem_file_get_info( static size_t -wfp_impl_static_filesystem_add_dir( +wfp_static_filesystem_add_dir( struct wfp_static_filesystem * filesystem, size_t parent, char const * name ) { - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry_by_name(filesystem, parent, name); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name); if (NULL == entry) { - entry = wfp_impl_static_filesystem_add_entry(filesystem); + entry = wfp_static_filesystem_add_entry(filesystem); entry->parent = parent; entry->is_file = false; entry->mode = 0555; entry->name = strdup(name); entry->user_data = entry; - entry->read = &wfp_impl_static_filesystem_entry_read; - entry->get_info = &wfp_impl_static_filesystem_entry_get_info; + entry->read = &wfp_static_filesystem_entry_read; + entry->get_info = &wfp_static_filesystem_entry_get_info; entry->size = 0; entry->content = NULL; } @@ -201,7 +201,7 @@ wfp_impl_static_filesystem_add_dir( } static size_t -wfp_impl_static_filesystem_make_parent( +wfp_static_filesystem_make_parent( struct wfp_static_filesystem * filesystem, struct wf_path * path) { @@ -213,7 +213,7 @@ wfp_impl_static_filesystem_make_parent( for(size_t i = 0; i < (count - 1); i++) { char const * name = wf_path_get_element(path, i); - result = wfp_impl_static_filesystem_add_dir(filesystem, result, name); + result = wfp_static_filesystem_add_dir(filesystem, result, name); } } @@ -221,7 +221,7 @@ wfp_impl_static_filesystem_make_parent( } static void -wfp_impl_static_filesystem_stat( +wfp_static_filesystem_stat( struct wfp_static_filesystem_entry * entry, struct stat * stat ) @@ -238,19 +238,19 @@ wfp_impl_static_filesystem_stat( stat->st_mode |= (entry->is_file) ? S_IFREG: S_IFDIR; } -static void wfp_impl_static_filesystem_lookup( +static void wfp_static_filesystem_lookup( struct wfp_request * request, ino_t parent, char const * name, void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry_by_name(filesystem, parent, name); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name); if (NULL != entry) { struct stat stat; - wfp_impl_static_filesystem_stat(entry, &stat); + wfp_static_filesystem_stat(entry, &stat); wfp_respond_lookup(request, &stat); } else @@ -260,18 +260,18 @@ static void wfp_impl_static_filesystem_lookup( } -static void wfp_impl_static_filesystem_getattr( +static void wfp_static_filesystem_getattr( struct wfp_request * request, ino_t inode, void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode); if (NULL != entry) { struct stat stat; - wfp_impl_static_filesystem_stat(entry, &stat); + wfp_static_filesystem_stat(entry, &stat); wfp_respond_getattr(request, &stat); } else @@ -280,13 +280,13 @@ static void wfp_impl_static_filesystem_getattr( } } -static void wfp_impl_static_filesystem_readdir( +static void wfp_static_filesystem_readdir( struct wfp_request * request, ino_t directory, void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * dir = wfp_impl_static_filesystem_get_entry(filesystem, directory); + struct wfp_static_filesystem_entry * dir = wfp_static_filesystem_get_entry(filesystem, directory); if ((NULL != dir) && (!dir->is_file)) { @@ -312,14 +312,14 @@ static void wfp_impl_static_filesystem_readdir( } } -static void wfp_impl_static_filesystem_open( +static void wfp_static_filesystem_open( struct wfp_request * request, ino_t inode, int flags, void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode); if ((NULL != entry) && (entry->is_file)) { @@ -338,7 +338,7 @@ static void wfp_impl_static_filesystem_open( } } -static void wfp_impl_static_filesystem_read( +static void wfp_static_filesystem_read( struct wfp_request * request, ino_t inode, uint32_t WF_UNUSED_PARAM(handle), @@ -347,7 +347,7 @@ static void wfp_impl_static_filesystem_read( void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode); if ((NULL != entry) && (entry->is_file)) { @@ -365,7 +365,7 @@ static void wfp_impl_static_filesystem_read( struct wfp_static_filesystem * -wfp_impl_static_filesystem_create( +wfp_static_filesystem_create( struct wfp_client_config * config) { (void) config; @@ -377,21 +377,21 @@ wfp_impl_static_filesystem_create( filesystem->size = 0; filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY; - wfp_impl_static_filesystem_add_dir(filesystem, 0, ""); + wfp_static_filesystem_add_dir(filesystem, 0, ""); wfp_client_config_set_userdata(config, filesystem); - wfp_client_config_set_onlookup(config, &wfp_impl_static_filesystem_lookup); - wfp_client_config_set_ongetattr(config, &wfp_impl_static_filesystem_getattr); - wfp_client_config_set_onreaddir(config, &wfp_impl_static_filesystem_readdir); - wfp_client_config_set_onopen(config, &wfp_impl_static_filesystem_open); - wfp_client_config_set_onread(config, &wfp_impl_static_filesystem_read); + wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup); + wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr); + wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir); + wfp_client_config_set_onopen(config, &wfp_static_filesystem_open); + wfp_client_config_set_onread(config, &wfp_static_filesystem_read); } return filesystem; } void -wfp_impl_static_filesystem_dispose( +wfp_static_filesystem_dispose( struct wfp_static_filesystem * filesystem) { for(size_t i = 0; i < filesystem->size; i++) @@ -406,7 +406,7 @@ wfp_impl_static_filesystem_dispose( } void -wfp_impl_static_filesystem_add( +wfp_static_filesystem_add( struct wfp_static_filesystem * filesystem, char const * path, int mode, @@ -416,15 +416,15 @@ wfp_impl_static_filesystem_add( struct wf_path * path_ = wf_path_create(path); if (NULL != path_) { - size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); + size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); entry->parent = parent; entry->is_file = true; entry->name = strdup(wf_path_get_filename(path_)); entry->mode = mode; entry->size = length; - entry->get_info = &wfp_impl_static_filesystem_entry_get_info; - entry->read = &wfp_impl_static_filesystem_entry_read; + entry->get_info = &wfp_static_filesystem_entry_get_info; + entry->read = &wfp_static_filesystem_entry_read; entry->user_data = entry; entry->content = malloc(length); @@ -435,18 +435,18 @@ wfp_impl_static_filesystem_add( } void -wfp_impl_static_filesystem_add_text( +wfp_static_filesystem_add_text( struct wfp_static_filesystem * filesystem, char const * path, int mode, char const * content) { size_t length = strlen(content); - wfp_impl_static_filesystem_add(filesystem, path, mode, content, length); + wfp_static_filesystem_add(filesystem, path, mode, content, length); } void -wfp_impl_static_filesystem_add_file( +wfp_static_filesystem_add_file( struct wfp_static_filesystem * filesystem, char const * path, char const * filename) @@ -454,16 +454,16 @@ wfp_impl_static_filesystem_add_file( struct wf_path * path_ = wf_path_create(path); if (NULL != path_) { - size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); + size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); entry->parent = parent; entry->is_file = true; entry->mode = 0; entry->content = strdup(filename); entry->size = 0; entry->name = strdup(wf_path_get_filename(path_)); - entry->get_info = &wfp_impl_static_filesystem_file_get_info; - entry->read = &wfp_impl_static_filesystem_file_read; + entry->get_info = &wfp_static_filesystem_file_get_info; + entry->read = &wfp_static_filesystem_file_read; entry->user_data = entry; wf_path_dispose(path_); @@ -471,7 +471,7 @@ wfp_impl_static_filesystem_add_file( } void -wfp_impl_static_filesystem_add_generic( +wfp_static_filesystem_add_generic( struct wfp_static_filesystem * filesystem, char const * path, wfp_static_filesystem_read_fn * read, @@ -481,8 +481,8 @@ wfp_impl_static_filesystem_add_generic( struct wf_path * path_ = wf_path_create(path); if (NULL != path_) { - size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); + size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); entry->parent = parent; entry->is_file = true; entry->mode = 0; diff --git a/test/webfuse/utils/static_filesystem.h b/test/webfuse/utils/static_filesystem.h new file mode 100644 index 0000000..4f72b1b --- /dev/null +++ b/test/webfuse/utils/static_filesystem.h @@ -0,0 +1,77 @@ +#ifndef WFP_STATIC_FILESYSTEM_H +#define WFP_STATIC_FILESYSTEM_H + +#ifndef __cplusplus +#include +#else +#include +using ::std::size_t; +#endif + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_client_config; + +struct wfp_static_filesystem; + +typedef size_t +wfp_static_filesystem_read_fn( + size_t offset, + char * buffer, + size_t buffer_size, + void * user_data); + +typedef void +wfp_static_filesystem_get_info_fn( + void * user_data, + int * result_mode, + size_t * result_size); + + +extern WFP_API struct wfp_static_filesystem * +wfp_static_filesystem_create( + struct wfp_client_config * config); + +extern WFP_API void +wfp_static_filesystem_dispose( + struct wfp_static_filesystem * filesystem); + +extern WFP_API void +wfp_static_filesystem_add( + struct wfp_static_filesystem * filesystem, + char const * path, + int mode, + char const * content, + size_t length); + +extern WFP_API void +wfp_static_filesystem_add_text( + struct wfp_static_filesystem * filesystem, + char const * path, + int mode, + char const * content); + +extern WFP_API void +wfp_static_filesystem_add_file( + struct wfp_static_filesystem * filesystem, + char const * path, + char const * filename); + +extern WFP_API void +wfp_static_filesystem_add_generic( + struct wfp_static_filesystem * filesystem, + char const * path, + wfp_static_filesystem_read_fn * read, + wfp_static_filesystem_get_info_fn * get_info, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif From 384de32bf5948f843dc32d0545f4dea40ad21e26 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 20 Feb 2020 19:06:38 +0100 Subject: [PATCH 048/138] removed some dead code --- test/webfuse/utils/static_filesystem.c | 91 -------------------------- test/webfuse/utils/static_filesystem.h | 14 ---- 2 files changed, 105 deletions(-) diff --git a/test/webfuse/utils/static_filesystem.c b/test/webfuse/utils/static_filesystem.c index 7212e7a..62b507a 100644 --- a/test/webfuse/utils/static_filesystem.c +++ b/test/webfuse/utils/static_filesystem.c @@ -136,45 +136,6 @@ wfp_static_filesystem_entry_get_info( *result_size = entry->size; } -static size_t -wfp_static_filesystem_file_read( - size_t offset, - char * buffer, - size_t buffer_size, - void * user_data) -{ - size_t result = 0; - struct wfp_static_filesystem_entry * entry = user_data; - char const * filename = entry->content; - - FILE * file = fopen(filename, "rb"); - if (NULL != file) - { - fseek(file, offset, SEEK_SET); - result = fread(buffer, buffer_size, 1, file); - fclose(file); - } - - return result; -} - -static void -wfp_static_filesystem_file_get_info( - void * user_data, - int * result_mode, - size_t * result_size) -{ - struct wfp_static_filesystem_entry * entry = user_data; - char const * filename = entry->content; - - struct stat buffer; - stat(filename, &buffer); - - *result_mode = (int) (buffer.st_mode & 0777); - *result_size = (size_t) buffer.st_size; -} - - static size_t wfp_static_filesystem_add_dir( struct wfp_static_filesystem * filesystem, @@ -444,55 +405,3 @@ wfp_static_filesystem_add_text( size_t length = strlen(content); wfp_static_filesystem_add(filesystem, path, mode, content, length); } - -void -wfp_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename) -{ - struct wf_path * path_ = wf_path_create(path); - if (NULL != path_) - { - size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); - entry->parent = parent; - entry->is_file = true; - entry->mode = 0; - entry->content = strdup(filename); - entry->size = 0; - entry->name = strdup(wf_path_get_filename(path_)); - entry->get_info = &wfp_static_filesystem_file_get_info; - entry->read = &wfp_static_filesystem_file_read; - entry->user_data = entry; - - wf_path_dispose(path_); - } -} - -void -wfp_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data) -{ - struct wf_path * path_ = wf_path_create(path); - if (NULL != path_) - { - size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); - entry->parent = parent; - entry->is_file = true; - entry->mode = 0; - entry->content = NULL; - entry->size = 0; - entry->name = strdup(wf_path_get_filename(path_)); - entry->get_info = get_info; - entry->read = read; - entry->user_data = user_data; - - wf_path_dispose(path_); - } -} diff --git a/test/webfuse/utils/static_filesystem.h b/test/webfuse/utils/static_filesystem.h index 4f72b1b..bf23b88 100644 --- a/test/webfuse/utils/static_filesystem.h +++ b/test/webfuse/utils/static_filesystem.h @@ -56,20 +56,6 @@ wfp_static_filesystem_add_text( int mode, char const * content); -extern WFP_API void -wfp_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename); - -extern WFP_API void -wfp_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data); - #ifdef __cplusplus } #endif From 4b418a45d4b34938f5d1c13e968cb6ea75ddd8d9 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 20 Feb 2020 20:13:39 +0100 Subject: [PATCH 049/138] chore: refactored test --- .../tests/provider/test_client_protocol.cc | 104 ++++++++++-------- 1 file changed, 59 insertions(+), 45 deletions(-) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index ef058f7..4faba4f 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -15,58 +15,72 @@ using testing::_; namespace { -struct Context +class ClientProtocolTest: public ::testing::Test { - lws_context * context; +protected: + void SetUp() + { + server = new FakeAdapterServer(54321); + + config = wfp_client_config_create(); + protocol = wfp_client_protocol_create(config); + + struct lws_protocols protocols[2]; + memset(protocols, 0, sizeof(struct lws_protocols) * 2); + protocols[0].name = "fs"; + wfp_client_protocol_init_lws(protocol, &protocols[0]); + + struct lws_context_creation_info info; + memset(&info, 0, sizeof(struct lws_context_creation_info)); + info.port = CONTEXT_PORT_NO_LISTEN; + info.protocols = protocols; + info.uid = -1; + info.gid = -1; + + context = lws_create_context(&info); + wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/"); + + isShutdownRequested = false; + thread = std::thread(run, this); + } + + void TearDown() + { + isShutdownRequested = true; + thread.join(); + + lws_context_destroy(context); + + wfp_client_protocol_dispose(protocol); + wfp_client_config_dispose(config); + + delete server; + } + + FakeAdapterServer * server; + +private: + static void run(ClientProtocolTest * self) + { + while (!self->isShutdownRequested) + { + lws_service(self->context, 100); + } + } + + wfp_client_config * config; + wfp_client_protocol * protocol; + std::thread thread; std::atomic isShutdownRequested; + lws_context * context; + }; -void run(Context * context) -{ - while (!context->isShutdownRequested) - { - lws_service(context->context, 100); - } -} - } -TEST(client_protocol, connect) +TEST_F(ClientProtocolTest, connect) { - FakeAdapterServer server(54321); - - wfp_client_config * config = wfp_client_config_create(); - wfp_client_protocol * protocol = wfp_client_protocol_create(config); - - struct lws_protocols protocols[2]; - memset(protocols, 0, sizeof(struct lws_protocols) * 2); - protocols[0].name = "fs"; - wfp_client_protocol_init_lws(protocol, &protocols[0]); - - struct lws_context_creation_info info; - memset(&info, 0, sizeof(struct lws_context_creation_info)); - info.port = CONTEXT_PORT_NO_LISTEN; - info.protocols = protocols; - info.uid = -1; - info.gid = -1; - - struct lws_context * context = lws_create_context(&info); - wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/"); - - Context ctx; - ctx.context = context; - ctx.isShutdownRequested = false; - std::thread client_thread(run, &ctx); - - server.waitForConnection(); - - ctx.isShutdownRequested = true; - client_thread.join(); - - lws_context_destroy(context); - - wfp_client_protocol_dispose(protocol); - wfp_client_config_dispose(config); + server->waitForConnection(); } \ No newline at end of file From 1a1367eae75cf9a403da1fb18b144e86c89b3798 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 22 Feb 2020 15:55:32 +0100 Subject: [PATCH 050/138] fixed typo --- doc/protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/protocol.md b/doc/protocol.md index 5245b3d..32eaa9d 100644 --- a/doc/protocol.md +++ b/doc/protocol.md @@ -227,7 +227,7 @@ Read from an open file. Adds a filesystem. - fs provider: {"method": "add_filesytem", "params": [], "id": } + fs provider: {"method": "add_filesystem", "params": [], "id": } webfuse daemon: {"result": {"id": }, "id": } | Item | Data type | Description | From e21c716d348d8d71bf109f95f40b9c54a5411644 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 22 Feb 2020 16:46:21 +0100 Subject: [PATCH 051/138] refactored fake adapter server into ws server; added test for client protocol getattr --- cmake/unit_tests.cmake | 2 +- test/webfuse/fakes/fake_adapter_server.hpp | 24 ------ .../tests/provider/test_client_protocol.cc | 65 ++++++++++++++- .../ws_server.cc} | 83 ++++++++++++++----- test/webfuse/utils/ws_server.hpp | 27 ++++++ 5 files changed, 153 insertions(+), 48 deletions(-) delete mode 100644 test/webfuse/fakes/fake_adapter_server.hpp rename test/webfuse/{fakes/fake_adapter_server.cc => utils/ws_server.cc} (68%) create mode 100644 test/webfuse/utils/ws_server.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index dfc804e..3e445ed 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -14,7 +14,7 @@ add_executable(alltests test/webfuse/utils/timeout_watcher.cc test/webfuse/utils/path.c test/webfuse/utils/static_filesystem.c - test/webfuse/fakes/fake_adapter_server.cc + test/webfuse/utils/ws_server.cc test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc test/webfuse/tests/core/test_container_of.cc diff --git a/test/webfuse/fakes/fake_adapter_server.hpp b/test/webfuse/fakes/fake_adapter_server.hpp deleted file mode 100644 index 9cc51f0..0000000 --- a/test/webfuse/fakes/fake_adapter_server.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WF_TEST_FAKE_SERVER_HPP -#define WF_TEST_FAKE_SERVER_HPP - -#include - -namespace webfuse_test -{ - -class FakeAdapterServer -{ - FakeAdapterServer(FakeAdapterServer const &) = delete; - FakeAdapterServer & operator=(FakeAdapterServer const &) = delete; -public: - explicit FakeAdapterServer(int port); - ~FakeAdapterServer(); - void waitForConnection(); -private: - class Private; - Private * d; -}; - -} - -#endif diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 4faba4f..5212f45 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -3,13 +3,13 @@ #include #include -#include "webfuse/fakes/fake_adapter_server.hpp" +#include "webfuse/utils/ws_server.hpp" #include #include #include -using webfuse_test::FakeAdapterServer; +using webfuse_test::WebsocketServer; using testing::_; namespace @@ -20,7 +20,7 @@ class ClientProtocolTest: public ::testing::Test protected: void SetUp() { - server = new FakeAdapterServer(54321); + server = new WebsocketServer(54321); config = wfp_client_config_create(); protocol = wfp_client_protocol_create(config); @@ -57,7 +57,40 @@ protected: delete server; } - FakeAdapterServer * server; + void awaitAddFilesystem(std::string& filesystemName) + { + json_t * addFilesystemRequest = server->receiveMessage(); + ASSERT_NE(nullptr, addFilesystemRequest); + ASSERT_TRUE(json_is_object(addFilesystemRequest)); + + json_t * method = json_object_get(addFilesystemRequest, "method"); + ASSERT_TRUE(json_is_string(method)); + ASSERT_STREQ("add_filesystem", json_string_value(method)); + + json_t * params = json_object_get(addFilesystemRequest, "params"); + ASSERT_TRUE(json_is_array(params)); + ASSERT_EQ(1, json_array_size(params)); + + json_t * filesystem = json_array_get(params, 0); + ASSERT_TRUE(json_is_string(filesystem)); + filesystemName = json_string_value(filesystem); + + json_t * id = json_object_get(addFilesystemRequest, "id"); + ASSERT_TRUE(json_is_integer(id)); + + json_t * response = json_object(); + json_t * result = json_object(); + json_object_set(result, "id", filesystem); + json_object_set_new(response, "result", result); + json_object_set(response, "id", id); + + server->sendMessage(response); + + json_decref(addFilesystemRequest); + + } + + WebsocketServer * server; private: static void run(ClientProtocolTest * self) @@ -77,10 +110,34 @@ private: }; + } TEST_F(ClientProtocolTest, connect) { server->waitForConnection(); +} + +TEST_F(ClientProtocolTest, getattr) +{ + server->waitForConnection(); + + std::string filesystem; + awaitAddFilesystem(filesystem); + if (HasFatalFailure()) { return; } + + json_t * params = json_array(); + json_array_append_new(params, json_string(filesystem.c_str())); + json_array_append_new(params, json_integer(1)); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("getattr")); + json_object_set_new(request, "params", params); + json_object_set_new(request, "id", json_integer(42)); + + server->sendMessage(request); + json_t * response = server->receiveMessage(); + ASSERT_TRUE(json_is_object(response)); + + json_decref(response); } \ No newline at end of file diff --git a/test/webfuse/fakes/fake_adapter_server.cc b/test/webfuse/utils/ws_server.cc similarity index 68% rename from test/webfuse/fakes/fake_adapter_server.cc rename to test/webfuse/utils/ws_server.cc index bebd3d9..995d0b8 100644 --- a/test/webfuse/fakes/fake_adapter_server.cc +++ b/test/webfuse/utils/ws_server.cc @@ -1,4 +1,4 @@ -#include "webfuse/fakes/fake_adapter_server.hpp" +#include "webfuse/utils/ws_server.hpp" #include "webfuse/utils/timeout_watcher.hpp" #include "webfuse/core/util.h" @@ -30,7 +30,7 @@ public: extern "C" { -static int wf_test_fake_adapter_server_callback( +static int wf_test_utils_ws_server_callback( struct lws * wsi, enum lws_callback_reasons reason, void * WF_UNUSED_PARAM(user), @@ -65,7 +65,6 @@ static int wf_test_fake_adapter_server_callback( break; } - return 0; } @@ -74,16 +73,15 @@ static int wf_test_fake_adapter_server_callback( namespace webfuse_test { -class FakeAdapterServer::Private: public IServer +class WebsocketServer::Private: public IServer { public: explicit Private(int port) : client_wsi(nullptr) - , message_received(false) { memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2); ws_protocols[0].name = "fs"; - ws_protocols[0].callback = &wf_test_fake_adapter_server_callback; + ws_protocols[0].callback = &wf_test_utils_ws_server_callback; ws_protocols[0].per_session_data_size = 0; ws_protocols[0].user = reinterpret_cast(this); @@ -114,6 +112,44 @@ public: } } + void sendMessage(json_t * message) + { + char* message_text = json_dumps(message, JSON_COMPACT); + writeQueue.push(message_text); + json_decref(message); + free(message_text); + + if (nullptr != client_wsi) + { + lws_callback_on_writable(client_wsi); + + TimeoutWatcher watcher(DEFAULT_TIMEOUT); + while (!writeQueue.empty()) + { + watcher.check(); + lws_service(context, 100); + } + } + + } + + json_t * receiveMessage() + { + TimeoutWatcher watcher(DEFAULT_TIMEOUT); + + while (recvQueue.empty()) + { + watcher.check(); + lws_service(context, 100); + } + + std::string const & message_text = recvQueue.front(); + json_t * message = json_loads(message_text.c_str(), JSON_DECODE_ANY, nullptr); + recvQueue.pop(); + + return message; + } + void onConnectionEstablished(struct lws * wsi) override { client_wsi = wsi; @@ -131,24 +167,23 @@ public: { if (wsi == client_wsi) { - last_message.assign(length, *data); - message_received = true; + recvQueue.push(std::string(data, length)); } } void onWritable(struct lws * wsi) override { - if (!queue.empty()) + if (!writeQueue.empty()) { - std::string const & message = queue.front(); + std::string const & message = writeQueue.front(); unsigned char * data = new unsigned char[LWS_PRE + message.size()]; memcpy(&data[LWS_PRE], message.c_str(), message.size()); lws_write(wsi, &data[LWS_PRE], message.size(), LWS_WRITE_TEXT); delete[] data; - queue.pop(); - if (!queue.empty()) + writeQueue.pop(); + if (!writeQueue.empty()) { lws_callback_on_writable(wsi); } @@ -161,36 +196,46 @@ private: { if (nullptr != client_wsi) { - queue.push(message); + writeQueue.push(message); lws_callback_on_writable(client_wsi); } } struct lws * client_wsi; - bool message_received; struct lws_protocols ws_protocols[2]; struct lws_context_creation_info info; struct lws_context * context; - std::vector last_message; - std::queue queue; + std::queue writeQueue; + std::queue recvQueue; }; -FakeAdapterServer::FakeAdapterServer(int port) +WebsocketServer::WebsocketServer(int port) : d(new Private(port)) { } -FakeAdapterServer::~FakeAdapterServer() +WebsocketServer::~WebsocketServer() { delete d; } -void FakeAdapterServer::waitForConnection() +void WebsocketServer::waitForConnection() { d->waitForConnection(); } +void WebsocketServer::sendMessage(json_t * message) +{ + d->sendMessage(message); +} + +json_t * WebsocketServer::receiveMessage() +{ + return d->receiveMessage(); +} + + } \ No newline at end of file diff --git a/test/webfuse/utils/ws_server.hpp b/test/webfuse/utils/ws_server.hpp new file mode 100644 index 0000000..bacab51 --- /dev/null +++ b/test/webfuse/utils/ws_server.hpp @@ -0,0 +1,27 @@ +#ifndef WF_TEST_UTILS_WS_SERVER_HPP +#define WF_TEST_UTILS_WS_SERVER_HPP + +#include +#include + +namespace webfuse_test +{ + +class WebsocketServer +{ + WebsocketServer(WebsocketServer const &) = delete; + WebsocketServer & operator=(WebsocketServer const &) = delete; +public: + explicit WebsocketServer(int port); + ~WebsocketServer(); + void waitForConnection(); + void sendMessage(json_t * message); + json_t * receiveMessage(); +private: + class Private; + Private * d; +}; + +} + +#endif From c6265aeaf74906c0c51cfe400dd6dba7692f3285 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 22 Feb 2020 16:49:56 +0100 Subject: [PATCH 052/138] chore: added default ctor for ClientProtocolTest (to initialize members properly) --- test/webfuse/tests/provider/test_client_protocol.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 5212f45..409efc3 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -17,6 +17,15 @@ namespace class ClientProtocolTest: public ::testing::Test { +public: + ClientProtocolTest() + : server(nullptr) + , config(nullptr) + , protocol(nullptr) + { + // empty + } + protected: void SetUp() { From 77810168e04950e57872d66da51c1fb57ab55d73 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 22 Feb 2020 16:58:11 +0100 Subject: [PATCH 053/138] fix: initialize context --- test/webfuse/tests/provider/test_client_protocol.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 409efc3..beeaf52 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -22,6 +22,7 @@ public: : server(nullptr) , config(nullptr) , protocol(nullptr) + , context(nullptr) { // empty } From 8841ac40f82befdcced3fc2e61252b580c12b0cc Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 21:01:05 +0100 Subject: [PATCH 054/138] add toString function for lws reasons (for debugging and logging purposes) --- cmake/webfuse_core.cmake | 1 + lib/webfuse/core/lws_utils.c | 210 +++++++++++++++++++++++++++++++++++ lib/webfuse/core/lws_utils.h | 19 ++++ 3 files changed, 230 insertions(+) create mode 100644 lib/webfuse/core/lws_utils.c create mode 100644 lib/webfuse/core/lws_utils.h diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 52c7681..3daded5 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -8,6 +8,7 @@ add_library(webfuse-core STATIC lib/webfuse/core/string.c lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c + lib/webfuse/core/lws_utils.c ) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) diff --git a/lib/webfuse/core/lws_utils.c b/lib/webfuse/core/lws_utils.c new file mode 100644 index 0000000..700b084 --- /dev/null +++ b/lib/webfuse/core/lws_utils.c @@ -0,0 +1,210 @@ +#include "webfuse/core/lws_utils.h" + +extern char const * +wf_lws_reason_tostring( + enum lws_callback_reasons reason) +{ + switch (reason) + { + case LWS_CALLBACK_PROTOCOL_INIT: + return "protocol_init"; + case LWS_CALLBACK_PROTOCOL_DESTROY: + return "protcol_destory"; + case LWS_CALLBACK_WSI_CREATE: + return "wsi_create"; + case LWS_CALLBACK_WSI_DESTROY: + return "wsi_destroy"; + case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: + return "openssl_load_extra_client_verify_certs"; + case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: + return "openssl_load_extra_server_verify_certs"; + case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: + return "openssl_perform_client_cert_verification"; + case LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION: + return "openssl_perform_server_cert_verification"; + case LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY: + return "openssl_context_required_private_key"; + case LWS_CALLBACK_SSL_INFO: + return "ssl_info"; + case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED: + return "server_new_client_instantiated"; + case LWS_CALLBACK_HTTP: + return "http"; + case LWS_CALLBACK_HTTP_BODY: + return "http_body"; + case LWS_CALLBACK_HTTP_BODY_COMPLETION: + return "http_body_completion"; + case LWS_CALLBACK_HTTP_FILE_COMPLETION: + return "http_file_completion"; + case LWS_CALLBACK_HTTP_WRITEABLE: + return "http_writeable"; + case LWS_CALLBACK_CLOSED_HTTP: + return "closed_http"; + case LWS_CALLBACK_FILTER_HTTP_CONNECTION: + return "filter_http_connection"; + case LWS_CALLBACK_ADD_HEADERS: + return "add_headers"; + case LWS_CALLBACK_CHECK_ACCESS_RIGHTS: + return "check_access_rights"; + case LWS_CALLBACK_PROCESS_HTML: + return "process_html"; + case LWS_CALLBACK_HTTP_BIND_PROTOCOL: + return "http_bind_protocol"; + case LWS_CALLBACK_HTTP_DROP_PROTOCOL: + return "http_drop_protocol"; + case LWS_CALLBACK_HTTP_CONFIRM_UPGRADE: + return "http_confirm_upgrade"; + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + return "established_client_http"; + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + return "closed_http_client"; + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: + return "receive_client_http_read"; + case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: + return "completed_client_http"; + case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: + return "client_http_writeable"; + case LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL: + return "client_http_bind_protocol"; + case LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL: + return "client_http_drop_protocol"; + case LWS_CALLBACK_ESTABLISHED: + return "established"; + case LWS_CALLBACK_CLOSED: + return "closed"; + case LWS_CALLBACK_SERVER_WRITEABLE: + return "server_writeable"; + case LWS_CALLBACK_RECEIVE: + return "receive"; + case LWS_CALLBACK_RECEIVE_PONG: + return "receive_pong"; + case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: + return "ws_peer_initiated_close"; + case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: + return "filter_protocol_connection"; + case LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: + return "confirm_extension_okay"; + case LWS_CALLBACK_WS_SERVER_BIND_PROTOCOL: + return "ws_server_bind_protocol"; + case LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL: + return "ws_server_drop_protocol"; + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + return "client_connection_error"; + case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: + return "client_filter_pre_establish"; + case LWS_CALLBACK_CLIENT_ESTABLISHED: + return "client_established"; + case LWS_CALLBACK_CLIENT_CLOSED: + return "client_closed"; + case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: + return "client_append_handshake_header"; + case LWS_CALLBACK_CLIENT_RECEIVE: + return "client_receive"; + case LWS_CALLBACK_CLIENT_RECEIVE_PONG: + return "client_receive_pong"; + case LWS_CALLBACK_CLIENT_WRITEABLE: + return "client_writeable"; + case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: + return "client_confirm_extension_supported"; + case LWS_CALLBACK_WS_EXT_DEFAULTS: + return "ws_ext_defaults"; + case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: + return "filter_network_connection"; + case LWS_CALLBACK_WS_CLIENT_BIND_PROTOCOL: + return "ws_client_bind_protocol"; + case LWS_CALLBACK_WS_CLIENT_DROP_PROTOCOL: + return "ws_client_drop_protocol"; + case LWS_CALLBACK_GET_THREAD_ID: + return "get_thread_id"; + case LWS_CALLBACK_ADD_POLL_FD: + return "add_poll_fd"; + case LWS_CALLBACK_DEL_POLL_FD: + return "del_poll_fd"; + case LWS_CALLBACK_CHANGE_MODE_POLL_FD: + return "change_mode_poll_fd"; + case LWS_CALLBACK_LOCK_POLL: + return "lock_poll"; + case LWS_CALLBACK_UNLOCK_POLL: + return "unlock_poll"; + case LWS_CALLBACK_CGI: + return "cgi"; + case LWS_CALLBACK_CGI_TERMINATED: + return "cgi_terminated"; + case LWS_CALLBACK_CGI_STDIN_DATA: + return "cgi_stdin_data"; + case LWS_CALLBACK_CGI_STDIN_COMPLETED: + return "cgi_stdin_completed"; + case LWS_CALLBACK_CGI_PROCESS_ATTACH: + return "cgi_process_attach"; + case LWS_CALLBACK_SESSION_INFO: + return "session_info"; + case LWS_CALLBACK_GS_EVENT: + return "gs_event"; + case LWS_CALLBACK_HTTP_PMO: + return "http_pmo"; + case LWS_CALLBACK_RAW_PROXY_CLI_RX: + return "raw_proxy_cli_rx"; + case LWS_CALLBACK_RAW_PROXY_SRV_RX: + return "raw_proxy_srv_rx"; + case LWS_CALLBACK_RAW_PROXY_CLI_CLOSE: + return "raw_proxy_cli_close"; + case LWS_CALLBACK_RAW_PROXY_SRV_CLOSE: + return "raw_proxy_srv_close"; + case LWS_CALLBACK_RAW_PROXY_CLI_WRITEABLE: + return "raw_proxy_cli_writeable"; + case LWS_CALLBACK_RAW_PROXY_SRV_WRITEABLE: + return "raw_prxy_srv_wrtieable"; + case LWS_CALLBACK_RAW_PROXY_CLI_ADOPT: + return "raw_proxy_cli_adopt"; + case LWS_CALLBACK_RAW_PROXY_SRV_ADOPT: + return "raw_proxy_srv_adopt"; + case LWS_CALLBACK_RAW_PROXY_CLI_BIND_PROTOCOL: + return "raw_proxy_cli_bind_protocol"; + case LWS_CALLBACK_RAW_PROXY_SRV_BIND_PROTOCOL: + return "raw_proxy_srv_bind_protocol"; + case LWS_CALLBACK_RAW_PROXY_CLI_DROP_PROTOCOL: + return "raw_proxy_cli_drop_protocol"; + case LWS_CALLBACK_RAW_PROXY_SRV_DROP_PROTOCOL: + return "raw_proxy_srv_drop_protocol"; + case LWS_CALLBACK_RAW_RX: + return "raw_rx"; + case LWS_CALLBACK_RAW_CLOSE: + return "raw_close"; + case LWS_CALLBACK_RAW_WRITEABLE: + return "raw_writeable"; + case LWS_CALLBACK_RAW_ADOPT: + return "raw_adopt"; + case LWS_CALLBACK_RAW_CONNECTED: + return "raw_connected"; + case LWS_CALLBACK_RAW_SKT_BIND_PROTOCOL: + return "raw_skt_bind_protocol"; + case LWS_CALLBACK_RAW_SKT_DROP_PROTOCOL: + return "raw_skt_drop_protocol"; + case LWS_CALLBACK_RAW_ADOPT_FILE: + return "raw_adopt_file"; + case LWS_CALLBACK_RAW_RX_FILE: + return "raw_rx_file"; + case LWS_CALLBACK_RAW_WRITEABLE_FILE: + return "raw_writeable_file"; + case LWS_CALLBACK_RAW_CLOSE_FILE: + return "raw_close_file"; + case LWS_CALLBACK_RAW_FILE_BIND_PROTOCOL: + return "raw_file_bind_protocol"; + case LWS_CALLBACK_RAW_FILE_DROP_PROTOCOL: + return "raw_file_drop_protocol"; + case LWS_CALLBACK_TIMER: + return "timer"; + case LWS_CALLBACK_EVENT_WAIT_CANCELLED: + return "event_wait_cancelled"; + case LWS_CALLBACK_CHILD_CLOSING: + return "child_closing"; + case LWS_CALLBACK_VHOST_CERT_AGING: + return "vhost_cert_aging"; + case LWS_CALLBACK_VHOST_CERT_UPDATE: + return "vhost_cert_update"; + case LWS_CALLBACK_USER: + return "user"; + default: + return ""; + } +} diff --git a/lib/webfuse/core/lws_utils.h b/lib/webfuse/core/lws_utils.h new file mode 100644 index 0000000..d97ed69 --- /dev/null +++ b/lib/webfuse/core/lws_utils.h @@ -0,0 +1,19 @@ +#ifndef WF_LWS_UTILS_H +#define WF_LWS_UTILS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern char const * +wf_lws_reason_tostring( + enum lws_callback_reasons reason); + +#ifdef __cplusplus +} +#endif + +#endif From 555058dbb578908576315b559a9c764325743814 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 21:02:01 +0100 Subject: [PATCH 055/138] made client protocol test single threaded --- include/webfuse/core/protocol_names.h | 21 ++++++++ include/webfuse_adapter.h | 1 + include/webfuse_provider.h | 1 + lib/webfuse/adapter/impl/server.c | 1 - lib/webfuse/adapter/impl/server_protocol.c | 2 + lib/webfuse/provider/impl/client.c | 1 - lib/webfuse/provider/impl/client_protocol.c | 8 +-- lib/webfuse/provider/impl/client_protocol.h | 2 - .../tests/provider/test_client_protocol.cc | 53 ++++++------------- test/webfuse/utils/ws_server.cc | 37 ++++++++++--- test/webfuse/utils/ws_server.hpp | 2 + 11 files changed, 78 insertions(+), 51 deletions(-) create mode 100644 include/webfuse/core/protocol_names.h diff --git a/include/webfuse/core/protocol_names.h b/include/webfuse/core/protocol_names.h new file mode 100644 index 0000000..4de8c4a --- /dev/null +++ b/include/webfuse/core/protocol_names.h @@ -0,0 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file protocol_names.h +/// \brief Names of websocket protocol. +//////////////////////////////////////////////////////////////////////////////// +#ifndef WF_PROTOCOL_NAMES_H +#define WF_PROTOCOL_NAMES_H + + +//------------------------------------------------------------------------------ +/// \def WF_PROTOCOL_NAME_ADAPTER_SERVER +/// \brief Name of the websocket protocol an adapter server is running. +//------------------------------------------------------------------------------ +#define WF_PROTOCOL_NAME_ADAPTER_SERVER ("webfuse-adapter-server") + +//------------------------------------------------------------------------------ +/// \def WF_PROTOCOL_NAME_PROVIDER_CLIENT +/// \brief Name of the websocket protocol an provider client is running. +//------------------------------------------------------------------------------ +#define WF_PROTOCOL_NAME_PROVIDER_CLIENT ("webfuse-provider-client") + +#endif diff --git a/include/webfuse_adapter.h b/include/webfuse_adapter.h index af37c14..1ff048f 100644 --- a/include/webfuse_adapter.h +++ b/include/webfuse_adapter.h @@ -7,6 +7,7 @@ #define WF_ADAPTER_H #include +#include #include #include diff --git a/include/webfuse_provider.h b/include/webfuse_provider.h index bd119ac..7af3934 100644 --- a/include/webfuse_provider.h +++ b/include/webfuse_provider.h @@ -7,6 +7,7 @@ #define WF_PROVIDER_H #include +#include #include #include diff --git a/lib/webfuse/adapter/impl/server.c b/lib/webfuse/adapter/impl/server.c index ad3e5c2..bf32b85 100644 --- a/lib/webfuse/adapter/impl/server.c +++ b/lib/webfuse/adapter/impl/server.c @@ -38,7 +38,6 @@ static struct lws_context * wf_impl_server_context_create( memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT); server->ws_protocols[0].name = "http"; server->ws_protocols[0].callback = lws_callback_http_dummy; - server->ws_protocols[1].name = "fs"; wf_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]); memset(&server->mount, 0, sizeof(struct lws_http_mount)); diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 02efd80..74d4631 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -6,6 +6,7 @@ #include "webfuse/core/message.h" #include "webfuse/core/util.h" +#include "webfuse/core/protocol_names.h" #include "webfuse/adapter/impl/credentials.h" #include "webfuse/adapter/impl/jsonrpc/request.h" @@ -121,6 +122,7 @@ void wf_impl_server_protocol_init_lws( struct wf_server_protocol * protocol, struct lws_protocols * lws_protocol) { + lws_protocol->name = WF_PROTOCOL_NAME_ADAPTER_SERVER; lws_protocol->callback = &wf_impl_server_protocol_callback; lws_protocol->per_session_data_size = 0; lws_protocol->user = protocol; diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index 8b3c06b..4ddae92 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -35,7 +35,6 @@ struct wfp_client * wfp_impl_client_create( wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT); - client->protocols[0].name = WFP_CLIENT_PROTOCOL_NAME; wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]); memset(&client->info, 0, sizeof(struct lws_context_creation_info)); diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 6d5ba85..59945bd 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -6,7 +6,6 @@ #include #include - #include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/provider.h" #include "webfuse/core/util.h" @@ -14,6 +13,7 @@ #include "webfuse/core/message_queue.h" #include "webfuse/core/container_of.h" #include "webfuse/provider/impl/url.h" +#include "webfuse/core/protocol_names.h" static void wfp_impl_client_protocol_respond( json_t * response, @@ -112,7 +112,7 @@ static int wfp_impl_client_protocol_callback( // fall-through case LWS_CALLBACK_CLIENT_WRITEABLE: if ((wsi == protocol->wsi) && (!wf_slist_empty(&protocol->messages))) - { + { struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages); struct wf_message * message = wf_container_of(item, struct wf_message, item); lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT); @@ -180,6 +180,7 @@ void wfp_impl_client_protocol_init_lws( struct wfp_client_protocol * protocol, struct lws_protocols * lws_protocol) { + lws_protocol->name = WF_PROTOCOL_NAME_PROVIDER_CLIENT; lws_protocol->callback = &wfp_impl_client_protocol_callback; lws_protocol->per_session_data_size = 0; lws_protocol->user = protocol; @@ -203,7 +204,8 @@ void wfp_impl_client_protocol_connect( info.host = info.address; info.origin = info.address; info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0; - info.protocol = WFP_CLIENT_PROTOCOL_NAME; + info.protocol = WF_PROTOCOL_NAME_ADAPTER_SERVER; + info.local_protocol_name = WF_PROTOCOL_NAME_PROVIDER_CLIENT; info.pwsi = &protocol->wsi; lws_client_connect_via_info(&info); diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index d197559..d6f537d 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -11,8 +11,6 @@ extern "C" { #endif -#define WFP_CLIENT_PROTOCOL_NAME ("fs") - struct wfp_client_config; struct lws_protocols; struct lws_context; diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index beeaf52..b602e58 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -22,7 +22,6 @@ public: : server(nullptr) , config(nullptr) , protocol(nullptr) - , context(nullptr) { // empty } @@ -30,41 +29,29 @@ public: protected: void SetUp() { - server = new WebsocketServer(54321); - config = wfp_client_config_create(); protocol = wfp_client_protocol_create(config); - struct lws_protocols protocols[2]; - memset(protocols, 0, sizeof(struct lws_protocols) * 2); - protocols[0].name = "fs"; - wfp_client_protocol_init_lws(protocol, &protocols[0]); + struct lws_protocols client_protocol; + memset(&client_protocol, 0, sizeof(struct lws_protocols)); + wfp_client_protocol_init_lws(protocol, &client_protocol); - struct lws_context_creation_info info; - memset(&info, 0, sizeof(struct lws_context_creation_info)); - info.port = CONTEXT_PORT_NO_LISTEN; - info.protocols = protocols; - info.uid = -1; - info.gid = -1; - - context = lws_create_context(&info); - wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/"); - - isShutdownRequested = false; - thread = std::thread(run, this); + server = new WebsocketServer(54321, &client_protocol, 1); } void TearDown() { - isShutdownRequested = true; - thread.join(); - - lws_context_destroy(context); + delete server; wfp_client_protocol_dispose(protocol); wfp_client_config_dispose(config); - delete server; + } + + void connect() + { + wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); + server->waitForConnection(); } void awaitAddFilesystem(std::string& filesystemName) @@ -103,20 +90,8 @@ protected: WebsocketServer * server; private: - static void run(ClientProtocolTest * self) - { - while (!self->isShutdownRequested) - { - lws_service(self->context, 100); - } - } - wfp_client_config * config; wfp_client_protocol * protocol; - std::thread thread; - std::atomic isShutdownRequested; - lws_context * context; - }; @@ -126,12 +101,14 @@ private: TEST_F(ClientProtocolTest, connect) { - server->waitForConnection(); + connect(); + if (HasFatalFailure()) { return; } } TEST_F(ClientProtocolTest, getattr) { - server->waitForConnection(); + connect(); + if (HasFatalFailure()) { return; } std::string filesystem; awaitAddFilesystem(filesystem); diff --git a/test/webfuse/utils/ws_server.cc b/test/webfuse/utils/ws_server.cc index 995d0b8..48e2588 100644 --- a/test/webfuse/utils/ws_server.cc +++ b/test/webfuse/utils/ws_server.cc @@ -2,6 +2,7 @@ #include "webfuse/utils/timeout_watcher.hpp" #include "webfuse/core/util.h" +#include "webfuse/core/protocol_names.h" #include #include #include @@ -76,15 +77,22 @@ namespace webfuse_test class WebsocketServer::Private: public IServer { public: - explicit Private(int port) + Private(int port, struct lws_protocols * additionalProtocols, size_t additionalProtocolsCount) : client_wsi(nullptr) { - memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2); - ws_protocols[0].name = "fs"; + ws_protocols = new struct lws_protocols[2 + additionalProtocolsCount]; + memset(ws_protocols, 0, sizeof(struct lws_protocols) * (2 + additionalProtocolsCount)); + + ws_protocols[0].name = WF_PROTOCOL_NAME_ADAPTER_SERVER; ws_protocols[0].callback = &wf_test_utils_ws_server_callback; ws_protocols[0].per_session_data_size = 0; ws_protocols[0].user = reinterpret_cast(this); + if (0 < additionalProtocolsCount) + { + memcpy(&ws_protocols[additionalProtocolsCount], additionalProtocols, sizeof(struct lws_protocols) * additionalProtocolsCount); + } + memset(&info, 0, sizeof(struct lws_context_creation_info)); info.port = port; info.mounts = NULL; @@ -94,11 +102,18 @@ public: info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); + } virtual ~Private() { lws_context_destroy(context); + delete[] ws_protocols; + } + + struct lws_context * getContext() + { + return context; } void waitForConnection() @@ -130,7 +145,6 @@ public: lws_service(context, 100); } } - } json_t * receiveMessage() @@ -203,7 +217,7 @@ private: struct lws * client_wsi; - struct lws_protocols ws_protocols[2]; + struct lws_protocols * ws_protocols; struct lws_context_creation_info info; struct lws_context * context; std::queue writeQueue; @@ -212,7 +226,13 @@ private: }; WebsocketServer::WebsocketServer(int port) -: d(new Private(port)) +: d(new Private(port, nullptr, 0)) +{ + +} + +WebsocketServer::WebsocketServer(int port, struct lws_protocols * additionalProtocols, std::size_t additionalProtocolsCount) +: d(new Private(port, additionalProtocols, additionalProtocolsCount)) { } @@ -222,6 +242,11 @@ WebsocketServer::~WebsocketServer() delete d; } +struct lws_context * WebsocketServer::getContext() +{ + return d->getContext(); +} + void WebsocketServer::waitForConnection() { d->waitForConnection(); diff --git a/test/webfuse/utils/ws_server.hpp b/test/webfuse/utils/ws_server.hpp index bacab51..e9d825a 100644 --- a/test/webfuse/utils/ws_server.hpp +++ b/test/webfuse/utils/ws_server.hpp @@ -13,7 +13,9 @@ class WebsocketServer WebsocketServer & operator=(WebsocketServer const &) = delete; public: explicit WebsocketServer(int port); + WebsocketServer(int port, struct lws_protocols * additionalProtocols, std::size_t additionalProtocolsCount); ~WebsocketServer(); + struct lws_context * getContext(); void waitForConnection(); void sendMessage(json_t * message); json_t * receiveMessage(); From 391b5926b6387860cf370e82d379e891d5a9d793 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 23:20:26 +0100 Subject: [PATCH 056/138] added mock for provider client --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_provider_client.cc | 204 ++++++++++++++++++ test/webfuse/mocks/mock_provider_client.hpp | 55 +++++ .../tests/provider/test_client_protocol.cc | 55 ++++- 4 files changed, 306 insertions(+), 9 deletions(-) create mode 100644 test/webfuse/mocks/mock_provider_client.cc create mode 100644 test/webfuse/mocks/mock_provider_client.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 3e445ed..1ff1be5 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -17,6 +17,7 @@ add_executable(alltests test/webfuse/utils/ws_server.cc test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc + test/webfuse/mocks/mock_provider_client.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc test/webfuse/tests/core/test_slist.cc diff --git a/test/webfuse/mocks/mock_provider_client.cc b/test/webfuse/mocks/mock_provider_client.cc new file mode 100644 index 0000000..a906d95 --- /dev/null +++ b/test/webfuse/mocks/mock_provider_client.cc @@ -0,0 +1,204 @@ +#include "webfuse/mocks/mock_provider_client.hpp" +#include "webfuse/provider/operation/error.h" +#include "webfuse/provider/dirbuffer.h" + +extern "C" +{ +using webfuse_test::IProviderClient; +using webfuse_test::ProviderClientException; + +static void webfuse_test_iproviderclient_onconnected( + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->OnConnected(); +} + +static void webfuse_test_iproviderclient_ondisconnected( + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->OnDisconnected(); +} + +static void webfuse_test_iproviderclient_ontimer( + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->OnTimer(); +} + +static void webfuse_test_iproviderclient_onlookup( + struct wfp_request * request, + ino_t parent, + char const * name, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + + try + { + struct stat buffer; + self->Lookup(parent, name, &buffer); + wfp_respond_lookup(request, &buffer); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } +} + +static void webfuse_test_iproviderclient_ongetattr( + struct wfp_request * request, + ino_t inode, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + + try + { + struct stat buffer; + memset(&buffer, 0, sizeof(struct stat)); + self->GetAttr(inode, &buffer); + wfp_respond_getattr(request,&buffer); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } + +} + +static void webfuse_test_iproviderclient_onreaddir( + struct wfp_request * request, + ino_t directory, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + wfp_dirbuffer * buffer = wfp_dirbuffer_create(); + + try + { + self->ReadDir(directory, buffer); + wfp_respond_readdir(request, buffer); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } + + wfp_dirbuffer_dispose(buffer); + +} + +static void webfuse_test_iproviderclient_onopen( + struct wfp_request * request, + ino_t inode, + int flags, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + + try + { + uint32_t handle = 0; + self->Open(inode, flags, &handle); + wfp_respond_open(request, handle); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } + +} + +static void webfuse_test_iproviderclient_onclose( + ino_t inode, + uint32_t handle, + int flags, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->Close(inode, handle, flags); +} + +static void webfuse_test_iproviderclient_onread( + struct wfp_request * request, + ino_t inode, + uint32_t handle, + size_t offset, + size_t length, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + char * data = new char[length]; + + try + { + size_t bytes_read = 0; + self->Read(inode, handle, offset, length, data, &bytes_read); + wfp_respond_read(request, data, bytes_read); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } + + delete[] data; +} + +} + +namespace webfuse_test +{ + +ProviderClientException::ProviderClientException(wf_status error_code) +: runtime_error("ProviderClientException") +, error_code_(error_code) +{ + +} + +wf_status ProviderClientException::GetErrorCode() +{ + return error_code_; +} + + +void IProviderClient::AttachTo(wfp_client_config * config) +{ + void * self = reinterpret_cast(this); + wfp_client_config_set_userdata(config, self); + wfp_client_config_set_onconnected(config, &webfuse_test_iproviderclient_onconnected); + wfp_client_config_set_ondisconnected(config, &webfuse_test_iproviderclient_ondisconnected); + wfp_client_config_set_ontimer(config, &webfuse_test_iproviderclient_ontimer); + + wfp_client_config_set_onlookup(config, &webfuse_test_iproviderclient_onlookup); + wfp_client_config_set_ongetattr(config, &webfuse_test_iproviderclient_ongetattr); + wfp_client_config_set_onreaddir(config, &webfuse_test_iproviderclient_onreaddir); + wfp_client_config_set_onopen(config, &webfuse_test_iproviderclient_onopen); + wfp_client_config_set_onclose(config, &webfuse_test_iproviderclient_onclose); + wfp_client_config_set_onread(config, &webfuse_test_iproviderclient_onread); +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_provider_client.hpp b/test/webfuse/mocks/mock_provider_client.hpp new file mode 100644 index 0000000..2db3127 --- /dev/null +++ b/test/webfuse/mocks/mock_provider_client.hpp @@ -0,0 +1,55 @@ +#ifndef WF_MOCK_PROVIDER_CLIENT_HPP +#define WF_MOCK_PROVIDER_CLIENT_HPP + +#include +#include "webfuse/provider/client_config.h" +#include "webfuse/core/status.h" +#include + +namespace webfuse_test +{ + class ProviderClientException: public std::runtime_error + { + public: + ProviderClientException(wf_status error_code); + wf_status GetErrorCode(); + private: + wf_status error_code_; + }; + + + + class IProviderClient + { + public: + virtual ~IProviderClient() = default; + virtual void OnConnected() = 0; + virtual void OnDisconnected() = 0; + virtual void OnTimer() = 0; + virtual void Lookup(ino_t parent, char const * name, struct stat * result) = 0; + virtual void GetAttr(ino_t inode, struct stat * buffer) = 0; + virtual void ReadDir(ino_t directory, wfp_dirbuffer * buffer) = 0; + virtual void Open(ino_t inode, int flags, uint32_t * handle) = 0; + virtual void Close(ino_t inode, uint32_t handle, int flags) = 0; + virtual void Read(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read) = 0; + + void AttachTo(wfp_client_config * config); + }; + + class MockProviderClient: public IProviderClient + { + public: + ~MockProviderClient() override = default; + MOCK_METHOD0( OnConnected, void()); + MOCK_METHOD0( OnDisconnected, void()); + MOCK_METHOD0( OnTimer, void()); + MOCK_METHOD3( Lookup, void(ino_t parent, char const * name, struct stat * result)); + MOCK_METHOD2( GetAttr, void(ino_t inode, struct stat * buffer)); + MOCK_METHOD2( ReadDir, void(ino_t directory, wfp_dirbuffer * buffer)); + MOCK_METHOD3( Open, void(ino_t inode, int flags, uint32_t * handle)); + MOCK_METHOD3( Close, void(ino_t inode, uint32_t handle, int flags)); + MOCK_METHOD6( Read, void(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read)); + }; +} + +#endif diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index b602e58..954a253 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -4,17 +4,20 @@ #include #include #include "webfuse/utils/ws_server.hpp" +#include "webfuse/mocks/mock_provider_client.hpp" #include #include #include using webfuse_test::WebsocketServer; +using webfuse_test::MockProviderClient; using testing::_; namespace { +// ToDo: Refactor Me class ClientProtocolTest: public ::testing::Test { public: @@ -30,6 +33,22 @@ protected: void SetUp() { config = wfp_client_config_create(); + + server = nullptr; + protocol = nullptr; + } + + void TearDown() + { + if (nullptr != server) + { + StopServer(); + } + + } + + void StartServer() + { protocol = wfp_client_protocol_create(config); struct lws_protocols client_protocol; @@ -39,22 +58,29 @@ protected: server = new WebsocketServer(54321, &client_protocol, 1); } - void TearDown() + void StopServer() { delete server; - wfp_client_protocol_dispose(protocol); wfp_client_config_dispose(config); + server = nullptr; + protocol = nullptr; + config = nullptr; } - void connect() + wfp_client_config * GetClientConfig() + { + return config; + } + + void Connect() { wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); server->waitForConnection(); } - void awaitAddFilesystem(std::string& filesystemName) + void AwaitAddFilesystem(std::string& filesystemName) { json_t * addFilesystemRequest = server->receiveMessage(); ASSERT_NE(nullptr, addFilesystemRequest); @@ -94,24 +120,33 @@ private: wfp_client_protocol * protocol; }; - - } TEST_F(ClientProtocolTest, connect) { - connect(); + StartServer(); + Connect(); if (HasFatalFailure()) { return; } + + StopServer(); } TEST_F(ClientProtocolTest, getattr) { - connect(); + MockProviderClient client; + client.AttachTo(GetClientConfig()); + + EXPECT_CALL(client, OnConnected()).Times(1); + EXPECT_CALL(client, OnDisconnected()).Times(1); + EXPECT_CALL(client, GetAttr(1, _)).Times(1); + + StartServer(); + Connect(); if (HasFatalFailure()) { return; } std::string filesystem; - awaitAddFilesystem(filesystem); + AwaitAddFilesystem(filesystem); if (HasFatalFailure()) { return; } json_t * params = json_array(); @@ -127,4 +162,6 @@ TEST_F(ClientProtocolTest, getattr) ASSERT_TRUE(json_is_object(response)); json_decref(response); + + StopServer(); } \ No newline at end of file From 7c02b12449a55c215e8409fc81e2a820b77629e3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 23:25:17 +0100 Subject: [PATCH 057/138] fix: don't copy exceptions --- test/webfuse/mocks/mock_provider_client.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/webfuse/mocks/mock_provider_client.cc b/test/webfuse/mocks/mock_provider_client.cc index a906d95..a624ba3 100644 --- a/test/webfuse/mocks/mock_provider_client.cc +++ b/test/webfuse/mocks/mock_provider_client.cc @@ -42,7 +42,7 @@ static void webfuse_test_iproviderclient_onlookup( self->Lookup(parent, name, &buffer); wfp_respond_lookup(request, &buffer); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } @@ -66,7 +66,7 @@ static void webfuse_test_iproviderclient_ongetattr( self->GetAttr(inode, &buffer); wfp_respond_getattr(request,&buffer); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } @@ -90,7 +90,7 @@ static void webfuse_test_iproviderclient_onreaddir( self->ReadDir(directory, buffer); wfp_respond_readdir(request, buffer); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } @@ -117,7 +117,7 @@ static void webfuse_test_iproviderclient_onopen( self->Open(inode, flags, &handle); wfp_respond_open(request, handle); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } @@ -155,7 +155,7 @@ static void webfuse_test_iproviderclient_onread( self->Read(inode, handle, offset, length, data, &bytes_read); wfp_respond_read(request, data, bytes_read); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } From 7ed99088db32fa30a9d8c093f12133c14a7d09d1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 23:26:30 +0100 Subject: [PATCH 058/138] fix: make c'tor explicit --- test/webfuse/mocks/mock_provider_client.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/webfuse/mocks/mock_provider_client.hpp b/test/webfuse/mocks/mock_provider_client.hpp index 2db3127..45fdf91 100644 --- a/test/webfuse/mocks/mock_provider_client.hpp +++ b/test/webfuse/mocks/mock_provider_client.hpp @@ -11,7 +11,7 @@ namespace webfuse_test class ProviderClientException: public std::runtime_error { public: - ProviderClientException(wf_status error_code); + explicit ProviderClientException(wf_status error_code); wf_status GetErrorCode(); private: wf_status error_code_; From 5a80e0233c617d161a1166e0da0ac1cba87c71c2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 24 Feb 2020 18:16:30 +0100 Subject: [PATCH 059/138] refactored test fixture --- .../tests/provider/test_client_protocol.cc | 105 ++++++++---------- 1 file changed, 44 insertions(+), 61 deletions(-) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 954a253..8aa3a81 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -12,43 +12,21 @@ using webfuse_test::WebsocketServer; using webfuse_test::MockProviderClient; +using webfuse_test::IProviderClient; using testing::_; +using testing::AtMost; namespace { -// ToDo: Refactor Me -class ClientProtocolTest: public ::testing::Test +class ClientProtocolFixture { public: - ClientProtocolTest() - : server(nullptr) - , config(nullptr) - , protocol(nullptr) - { - // empty - } - -protected: - void SetUp() + ClientProtocolFixture(IProviderClient& client) { config = wfp_client_config_create(); + client.AttachTo(config); - server = nullptr; - protocol = nullptr; - } - - void TearDown() - { - if (nullptr != server) - { - StopServer(); - } - - } - - void StartServer() - { protocol = wfp_client_protocol_create(config); struct lws_protocols client_protocol; @@ -58,20 +36,11 @@ protected: server = new WebsocketServer(54321, &client_protocol, 1); } - void StopServer() + ~ClientProtocolFixture() { delete server; wfp_client_protocol_dispose(protocol); wfp_client_config_dispose(config); - - server = nullptr; - protocol = nullptr; - config = nullptr; - } - - wfp_client_config * GetClientConfig() - { - return config; } void Connect() @@ -80,6 +49,16 @@ protected: server->waitForConnection(); } + void SendToClient(json_t * request) + { + server->sendMessage(request); + } + + json_t * ReceiveMessageFromClient() + { + return server->receiveMessage(); + } + void AwaitAddFilesystem(std::string& filesystemName) { json_t * addFilesystemRequest = server->receiveMessage(); @@ -113,40 +92,46 @@ protected: } - WebsocketServer * server; - private: + WebsocketServer * server; wfp_client_config * config; wfp_client_protocol * protocol; }; + } -TEST_F(ClientProtocolTest, connect) +TEST(client_protocol, connect) { - StartServer(); - Connect(); - if (HasFatalFailure()) { return; } + MockProviderClient provider; + ClientProtocolFixture fixture(provider); - StopServer(); -} + EXPECT_CALL(provider, OnConnected()).Times(AtMost(1)); + EXPECT_CALL(provider, OnDisconnected()).Times(1); -TEST_F(ClientProtocolTest, getattr) -{ - MockProviderClient client; - client.AttachTo(GetClientConfig()); - - EXPECT_CALL(client, OnConnected()).Times(1); - EXPECT_CALL(client, OnDisconnected()).Times(1); - EXPECT_CALL(client, GetAttr(1, _)).Times(1); - - StartServer(); - Connect(); + fixture.Connect(); if (HasFatalFailure()) { return; } std::string filesystem; - AwaitAddFilesystem(filesystem); + fixture.AwaitAddFilesystem(filesystem); + if (HasFatalFailure()) { return; } +} + +TEST(client_protocol, getattr) +{ + MockProviderClient provider; + ClientProtocolFixture fixture(provider); + + EXPECT_CALL(provider, OnConnected()).Times(1); + EXPECT_CALL(provider, OnDisconnected()).Times(1); + EXPECT_CALL(provider, GetAttr(1, _)).Times(1); + + fixture.Connect(); + if (HasFatalFailure()) { return; } + + std::string filesystem; + fixture.AwaitAddFilesystem(filesystem); if (HasFatalFailure()) { return; } json_t * params = json_array(); @@ -157,11 +142,9 @@ TEST_F(ClientProtocolTest, getattr) json_object_set_new(request, "params", params); json_object_set_new(request, "id", json_integer(42)); - server->sendMessage(request); - json_t * response = server->receiveMessage(); + fixture.SendToClient(request); + json_t * response = fixture.ReceiveMessageFromClient(); ASSERT_TRUE(json_is_object(response)); json_decref(response); - - StopServer(); } \ No newline at end of file From 85b283c1e319f54fae6026494d83a31874237e5f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 24 Feb 2020 18:20:26 +0100 Subject: [PATCH 060/138] removed dead code --- cmake/webfuse_core.cmake | 1 - lib/webfuse/core/lws_utils.c | 210 ----------------------------------- lib/webfuse/core/lws_utils.h | 19 ---- 3 files changed, 230 deletions(-) delete mode 100644 lib/webfuse/core/lws_utils.c delete mode 100644 lib/webfuse/core/lws_utils.h diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 3daded5..52c7681 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -8,7 +8,6 @@ add_library(webfuse-core STATIC lib/webfuse/core/string.c lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c - lib/webfuse/core/lws_utils.c ) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) diff --git a/lib/webfuse/core/lws_utils.c b/lib/webfuse/core/lws_utils.c deleted file mode 100644 index 700b084..0000000 --- a/lib/webfuse/core/lws_utils.c +++ /dev/null @@ -1,210 +0,0 @@ -#include "webfuse/core/lws_utils.h" - -extern char const * -wf_lws_reason_tostring( - enum lws_callback_reasons reason) -{ - switch (reason) - { - case LWS_CALLBACK_PROTOCOL_INIT: - return "protocol_init"; - case LWS_CALLBACK_PROTOCOL_DESTROY: - return "protcol_destory"; - case LWS_CALLBACK_WSI_CREATE: - return "wsi_create"; - case LWS_CALLBACK_WSI_DESTROY: - return "wsi_destroy"; - case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: - return "openssl_load_extra_client_verify_certs"; - case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: - return "openssl_load_extra_server_verify_certs"; - case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: - return "openssl_perform_client_cert_verification"; - case LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION: - return "openssl_perform_server_cert_verification"; - case LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY: - return "openssl_context_required_private_key"; - case LWS_CALLBACK_SSL_INFO: - return "ssl_info"; - case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED: - return "server_new_client_instantiated"; - case LWS_CALLBACK_HTTP: - return "http"; - case LWS_CALLBACK_HTTP_BODY: - return "http_body"; - case LWS_CALLBACK_HTTP_BODY_COMPLETION: - return "http_body_completion"; - case LWS_CALLBACK_HTTP_FILE_COMPLETION: - return "http_file_completion"; - case LWS_CALLBACK_HTTP_WRITEABLE: - return "http_writeable"; - case LWS_CALLBACK_CLOSED_HTTP: - return "closed_http"; - case LWS_CALLBACK_FILTER_HTTP_CONNECTION: - return "filter_http_connection"; - case LWS_CALLBACK_ADD_HEADERS: - return "add_headers"; - case LWS_CALLBACK_CHECK_ACCESS_RIGHTS: - return "check_access_rights"; - case LWS_CALLBACK_PROCESS_HTML: - return "process_html"; - case LWS_CALLBACK_HTTP_BIND_PROTOCOL: - return "http_bind_protocol"; - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - return "http_drop_protocol"; - case LWS_CALLBACK_HTTP_CONFIRM_UPGRADE: - return "http_confirm_upgrade"; - case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - return "established_client_http"; - case LWS_CALLBACK_CLOSED_CLIENT_HTTP: - return "closed_http_client"; - case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: - return "receive_client_http_read"; - case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: - return "completed_client_http"; - case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: - return "client_http_writeable"; - case LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL: - return "client_http_bind_protocol"; - case LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL: - return "client_http_drop_protocol"; - case LWS_CALLBACK_ESTABLISHED: - return "established"; - case LWS_CALLBACK_CLOSED: - return "closed"; - case LWS_CALLBACK_SERVER_WRITEABLE: - return "server_writeable"; - case LWS_CALLBACK_RECEIVE: - return "receive"; - case LWS_CALLBACK_RECEIVE_PONG: - return "receive_pong"; - case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: - return "ws_peer_initiated_close"; - case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: - return "filter_protocol_connection"; - case LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: - return "confirm_extension_okay"; - case LWS_CALLBACK_WS_SERVER_BIND_PROTOCOL: - return "ws_server_bind_protocol"; - case LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL: - return "ws_server_drop_protocol"; - case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: - return "client_connection_error"; - case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: - return "client_filter_pre_establish"; - case LWS_CALLBACK_CLIENT_ESTABLISHED: - return "client_established"; - case LWS_CALLBACK_CLIENT_CLOSED: - return "client_closed"; - case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: - return "client_append_handshake_header"; - case LWS_CALLBACK_CLIENT_RECEIVE: - return "client_receive"; - case LWS_CALLBACK_CLIENT_RECEIVE_PONG: - return "client_receive_pong"; - case LWS_CALLBACK_CLIENT_WRITEABLE: - return "client_writeable"; - case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: - return "client_confirm_extension_supported"; - case LWS_CALLBACK_WS_EXT_DEFAULTS: - return "ws_ext_defaults"; - case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: - return "filter_network_connection"; - case LWS_CALLBACK_WS_CLIENT_BIND_PROTOCOL: - return "ws_client_bind_protocol"; - case LWS_CALLBACK_WS_CLIENT_DROP_PROTOCOL: - return "ws_client_drop_protocol"; - case LWS_CALLBACK_GET_THREAD_ID: - return "get_thread_id"; - case LWS_CALLBACK_ADD_POLL_FD: - return "add_poll_fd"; - case LWS_CALLBACK_DEL_POLL_FD: - return "del_poll_fd"; - case LWS_CALLBACK_CHANGE_MODE_POLL_FD: - return "change_mode_poll_fd"; - case LWS_CALLBACK_LOCK_POLL: - return "lock_poll"; - case LWS_CALLBACK_UNLOCK_POLL: - return "unlock_poll"; - case LWS_CALLBACK_CGI: - return "cgi"; - case LWS_CALLBACK_CGI_TERMINATED: - return "cgi_terminated"; - case LWS_CALLBACK_CGI_STDIN_DATA: - return "cgi_stdin_data"; - case LWS_CALLBACK_CGI_STDIN_COMPLETED: - return "cgi_stdin_completed"; - case LWS_CALLBACK_CGI_PROCESS_ATTACH: - return "cgi_process_attach"; - case LWS_CALLBACK_SESSION_INFO: - return "session_info"; - case LWS_CALLBACK_GS_EVENT: - return "gs_event"; - case LWS_CALLBACK_HTTP_PMO: - return "http_pmo"; - case LWS_CALLBACK_RAW_PROXY_CLI_RX: - return "raw_proxy_cli_rx"; - case LWS_CALLBACK_RAW_PROXY_SRV_RX: - return "raw_proxy_srv_rx"; - case LWS_CALLBACK_RAW_PROXY_CLI_CLOSE: - return "raw_proxy_cli_close"; - case LWS_CALLBACK_RAW_PROXY_SRV_CLOSE: - return "raw_proxy_srv_close"; - case LWS_CALLBACK_RAW_PROXY_CLI_WRITEABLE: - return "raw_proxy_cli_writeable"; - case LWS_CALLBACK_RAW_PROXY_SRV_WRITEABLE: - return "raw_prxy_srv_wrtieable"; - case LWS_CALLBACK_RAW_PROXY_CLI_ADOPT: - return "raw_proxy_cli_adopt"; - case LWS_CALLBACK_RAW_PROXY_SRV_ADOPT: - return "raw_proxy_srv_adopt"; - case LWS_CALLBACK_RAW_PROXY_CLI_BIND_PROTOCOL: - return "raw_proxy_cli_bind_protocol"; - case LWS_CALLBACK_RAW_PROXY_SRV_BIND_PROTOCOL: - return "raw_proxy_srv_bind_protocol"; - case LWS_CALLBACK_RAW_PROXY_CLI_DROP_PROTOCOL: - return "raw_proxy_cli_drop_protocol"; - case LWS_CALLBACK_RAW_PROXY_SRV_DROP_PROTOCOL: - return "raw_proxy_srv_drop_protocol"; - case LWS_CALLBACK_RAW_RX: - return "raw_rx"; - case LWS_CALLBACK_RAW_CLOSE: - return "raw_close"; - case LWS_CALLBACK_RAW_WRITEABLE: - return "raw_writeable"; - case LWS_CALLBACK_RAW_ADOPT: - return "raw_adopt"; - case LWS_CALLBACK_RAW_CONNECTED: - return "raw_connected"; - case LWS_CALLBACK_RAW_SKT_BIND_PROTOCOL: - return "raw_skt_bind_protocol"; - case LWS_CALLBACK_RAW_SKT_DROP_PROTOCOL: - return "raw_skt_drop_protocol"; - case LWS_CALLBACK_RAW_ADOPT_FILE: - return "raw_adopt_file"; - case LWS_CALLBACK_RAW_RX_FILE: - return "raw_rx_file"; - case LWS_CALLBACK_RAW_WRITEABLE_FILE: - return "raw_writeable_file"; - case LWS_CALLBACK_RAW_CLOSE_FILE: - return "raw_close_file"; - case LWS_CALLBACK_RAW_FILE_BIND_PROTOCOL: - return "raw_file_bind_protocol"; - case LWS_CALLBACK_RAW_FILE_DROP_PROTOCOL: - return "raw_file_drop_protocol"; - case LWS_CALLBACK_TIMER: - return "timer"; - case LWS_CALLBACK_EVENT_WAIT_CANCELLED: - return "event_wait_cancelled"; - case LWS_CALLBACK_CHILD_CLOSING: - return "child_closing"; - case LWS_CALLBACK_VHOST_CERT_AGING: - return "vhost_cert_aging"; - case LWS_CALLBACK_VHOST_CERT_UPDATE: - return "vhost_cert_update"; - case LWS_CALLBACK_USER: - return "user"; - default: - return ""; - } -} diff --git a/lib/webfuse/core/lws_utils.h b/lib/webfuse/core/lws_utils.h deleted file mode 100644 index d97ed69..0000000 --- a/lib/webfuse/core/lws_utils.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef WF_LWS_UTILS_H -#define WF_LWS_UTILS_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern char const * -wf_lws_reason_tostring( - enum lws_callback_reasons reason); - -#ifdef __cplusplus -} -#endif - -#endif From afb9c528e7bd7cdef34f969a79a4498642c04331 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 24 Feb 2020 18:25:25 +0100 Subject: [PATCH 061/138] made c'tor explicit; disallow copy and assign --- test/webfuse/tests/provider/test_client_protocol.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 8aa3a81..ff7be74 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -21,8 +21,10 @@ namespace class ClientProtocolFixture { + ClientProtocolFixture(ClientProtocolFixture const &) = delete; + ClientProtocolFixture& operator=(ClientProtocolFixture const &) = delete; public: - ClientProtocolFixture(IProviderClient& client) + explicit ClientProtocolFixture(IProviderClient& client) { config = wfp_client_config_create(); client.AttachTo(config); From 767bafcd01696e5b3ded34a3d0cd5db99836a375 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 25 Feb 2020 15:36:28 +0100 Subject: [PATCH 062/138] added first idea of API --- include/webfuse/provider/client_config.h | 21 ++++++ lib/webfuse/provider/api.c | 17 +++++ lib/webfuse/provider/impl/client_config.c | 26 +++++++ lib/webfuse/provider/impl/client_config.h | 10 +++ .../tests/provider/test_client_protocol.cc | 72 ++++++++++++++++++- 5 files changed, 143 insertions(+), 3 deletions(-) diff --git a/include/webfuse/provider/client_config.h b/include/webfuse/provider/client_config.h index 73775f1..ec4c85b 100644 --- a/include/webfuse/provider/client_config.h +++ b/include/webfuse/provider/client_config.h @@ -227,6 +227,27 @@ extern WFP_API void wfp_client_config_set_onread( struct wfp_client_config * config, wfp_read_fn * handler); +//------------------------------------------------------------------------------ +/// \brief Enabled authentication with username and password. +/// +/// Sets username and password for built-in username authentication. +/// +/// \param config pointer to client configuration +/// \param username pointer to username +/// \param password pointer to password +//------------------------------------------------------------------------------ +extern WFP_API void wfp_client_config_set_username_credentials( + struct wfp_client_config * config, + char const * username, + char const * password); + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +extern WFP_API void wfp_client_config_set_generic_credentials( + struct wfp_client_config * config, + char const * credentials_type, + char const * contents[]); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 0c0e88a..6e507e8 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -155,6 +155,23 @@ void wfp_client_config_set_onread( wfp_impl_client_config_set_onread(config, handler); } +void wfp_client_config_set_username_credentials( + struct wfp_client_config * config, + char const * username, + char const * password) +{ + wfp_impl_client_config_set_username_credentials(config, username, password); +} + +void wfp_client_config_set_generic_credentials( + struct wfp_client_config * config, + char const * credentials_type, + char const * contents[]) +{ + wfp_impl_client_config_set_generic_credentials(config, credentials_type, contents); +} + + // protocol diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c index 7d121da..7163830 100644 --- a/lib/webfuse/provider/impl/client_config.c +++ b/lib/webfuse/provider/impl/client_config.c @@ -110,3 +110,29 @@ void wfp_impl_client_config_set_onread( { config->provider.read = handler; } + + +void wfp_impl_client_config_set_username_credentials( + struct wfp_client_config * config, + char const * username, + char const * password) +{ + (void) config; + (void) username; + (void) password; + + // ToDo: implement me +} + +void wfp_impl_client_config_set_generic_credentials( + struct wfp_client_config * config, + char const * credentials_type, + char const * contents[]) +{ + (void) config; + (void) credentials_type; + (void) contents; + + // ToDo: implement me + +} diff --git a/lib/webfuse/provider/impl/client_config.h b/lib/webfuse/provider/impl/client_config.h index 190a3cb..4b94f49 100644 --- a/lib/webfuse/provider/impl/client_config.h +++ b/lib/webfuse/provider/impl/client_config.h @@ -70,6 +70,16 @@ extern void wfp_impl_client_config_set_onread( struct wfp_client_config * config, wfp_read_fn * handler); +extern void wfp_impl_client_config_set_username_credentials( + struct wfp_client_config * config, + char const * username, + char const * password); + +extern void wfp_impl_client_config_set_generic_credentials( + struct wfp_client_config * config, + char const * credentials_type, + char const * contents[]); + #ifdef __cplusplus } #endif diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index ff7be74..c5e5008 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -45,6 +45,13 @@ public: wfp_client_config_dispose(config); } + void SetUsernameCredentials( + std::string const & username, + std::string const & password) + { + wfp_client_config_set_username_credentials(config, username.c_str(), password.c_str()); + } + void Connect() { wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); @@ -61,6 +68,47 @@ public: return server->receiveMessage(); } + void AwaitAuthentication( + std::string const & expected_username, + std::string const & expected_password) + { + json_t * request = server->receiveMessage(); + ASSERT_TRUE(json_is_object(request)); + + json_t * method = json_object_get(request, "method"); + ASSERT_TRUE(json_is_string(method)); + ASSERT_STREQ("authenticate", json_string_value(method)); + + json_t * id = json_object_get(request, "id"); + ASSERT_TRUE(json_is_integer(id)); + + json_t * params = json_object_get(request, "params"); + ASSERT_TRUE(json_is_array(params)); + ASSERT_EQ(2, json_array_size(params)); + + json_t * type = json_array_get(params, 0); + ASSERT_TRUE(json_is_string(type)); + ASSERT_STREQ("username", json_string_value(type)); + + json_t * credentials = json_array_get(params, 1); + ASSERT_TRUE(json_is_object(credentials)); + + json_t * username = json_object_get(credentials, "username"); + ASSERT_TRUE(json_is_string(username)); + ASSERT_STREQ(expected_username.c_str(), json_string_value(username)); + + json_t * password = json_object_get(credentials, "password"); + ASSERT_TRUE(json_is_string(password)); + ASSERT_STREQ(expected_password.c_str(), json_string_value(password)); + + json_t * response = json_object(); + json_object_set_new(response, "result", json_object()); + json_object_set(response, "id", id); + server->sendMessage(response); + + json_decref(request); + } + void AwaitAddFilesystem(std::string& filesystemName) { json_t * addFilesystemRequest = server->receiveMessage(); @@ -91,7 +139,6 @@ public: server->sendMessage(response); json_decref(addFilesystemRequest); - } private: @@ -100,10 +147,8 @@ private: wfp_client_protocol * protocol; }; - } - TEST(client_protocol, connect) { MockProviderClient provider; @@ -120,6 +165,27 @@ TEST(client_protocol, connect) if (HasFatalFailure()) { return; } } +TEST(client_protocol, connect_with_username_authentication) +{ + MockProviderClient provider; + ClientProtocolFixture fixture(provider); + fixture.SetUsernameCredentials("bob", "secret"); + + EXPECT_CALL(provider, OnConnected()).Times(AtMost(1)); + EXPECT_CALL(provider, OnDisconnected()).Times(1); + + fixture.Connect(); + if (HasFatalFailure()) { return; } + + fixture.AwaitAuthentication("bob", "secret"); + if (HasFatalFailure()) { return; } + + std::string filesystem; + fixture.AwaitAddFilesystem(filesystem); + if (HasFatalFailure()) { return; } + +} + TEST(client_protocol, getattr) { MockProviderClient provider; From c6ca2e14bdb330ba41e42a8ec76f8d7f5c83627c Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 25 Feb 2020 22:05:48 +0100 Subject: [PATCH 063/138] changed credentials API --- cmake/webfuse_provider.cmake | 1 + include/webfuse/provider/client_config.h | 21 +++------- include/webfuse/provider/credentials.h | 30 +++++++++++++++ include/webfuse_provider.h | 1 + lib/webfuse/provider/api.c | 34 ++++++++++------- lib/webfuse/provider/impl/client_config.c | 25 ++---------- lib/webfuse/provider/impl/client_config.h | 10 +---- lib/webfuse/provider/impl/credentials.c | 34 +++++++++++++++++ lib/webfuse/provider/impl/credentials.h | 38 +++++++++++++++++++ lib/webfuse/provider/impl/provider.c | 2 + lib/webfuse/provider/impl/provider.h | 1 + .../tests/provider/test_client_protocol.cc | 9 +---- 12 files changed, 140 insertions(+), 66 deletions(-) create mode 100644 include/webfuse/provider/credentials.h create mode 100644 lib/webfuse/provider/impl/credentials.c create mode 100644 lib/webfuse/provider/impl/credentials.h diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index 5079cb1..0d80d2d 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -9,6 +9,7 @@ add_library(webfuse-provider-static STATIC lib/webfuse/provider/impl/provider.c lib/webfuse/provider/impl/request.c lib/webfuse/provider/impl/dirbuffer.c + lib/webfuse/provider/impl/credentials.c lib/webfuse/provider/impl/operation/lookup.c lib/webfuse/provider/impl/operation/getattr.c lib/webfuse/provider/impl/operation/readdir.c diff --git a/include/webfuse/provider/client_config.h b/include/webfuse/provider/client_config.h index ec4c85b..0c79dd7 100644 --- a/include/webfuse/provider/client_config.h +++ b/include/webfuse/provider/client_config.h @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" @@ -228,25 +229,15 @@ extern WFP_API void wfp_client_config_set_onread( wfp_read_fn * handler); //------------------------------------------------------------------------------ -/// \brief Enabled authentication with username and password. -/// -/// Sets username and password for built-in username authentication. +/// \brief Enabled authentication. /// /// \param config pointer to client configuration -/// \param username pointer to username -/// \param password pointer to password +/// \param get_credentials pointer to function providing credentials when +// needed. //------------------------------------------------------------------------------ -extern WFP_API void wfp_client_config_set_username_credentials( +extern WFP_API void wfp_client_config_enable_authentication( struct wfp_client_config * config, - char const * username, - char const * password); - -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -extern WFP_API void wfp_client_config_set_generic_credentials( - struct wfp_client_config * config, - char const * credentials_type, - char const * contents[]); + wfp_get_credentials_fn * get_credentials); #ifdef __cplusplus } diff --git a/include/webfuse/provider/credentials.h b/include/webfuse/provider/credentials.h new file mode 100644 index 0000000..a6b0806 --- /dev/null +++ b/include/webfuse/provider/credentials.h @@ -0,0 +1,30 @@ +#ifndef WF_PROVIDER_CREDENTIALS_H +#define WF_PROVIDER_CREDENTIALS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_credentials; + +typedef void wfp_get_credentials_fn( + struct wfp_credentials * credentials, + void * user_data); + +extern WFP_API void wfp_credentials_set_type( + struct wfp_credentials * credentials, + char const * type); + +extern WFP_API void wfp_credentials_add( + struct wfp_credentials * credentials, + char const * key, + char const * value); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/webfuse_provider.h b/include/webfuse_provider.h index 7af3934..19afad2 100644 --- a/include/webfuse_provider.h +++ b/include/webfuse_provider.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 6e507e8..7c3220b 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -11,6 +11,7 @@ #include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/client.h" #include "webfuse/provider/impl/dirbuffer.h" +#include "webfuse/provider/impl/credentials.h" // respond @@ -155,23 +156,13 @@ void wfp_client_config_set_onread( wfp_impl_client_config_set_onread(config, handler); } -void wfp_client_config_set_username_credentials( +void wfp_client_config_enable_authentication( struct wfp_client_config * config, - char const * username, - char const * password) + wfp_get_credentials_fn * get_credentials) { - wfp_impl_client_config_set_username_credentials(config, username, password); + wfp_impl_client_config_enable_authentication(config, get_credentials); } -void wfp_client_config_set_generic_credentials( - struct wfp_client_config * config, - char const * credentials_type, - char const * contents[]) -{ - wfp_impl_client_config_set_generic_credentials(config, credentials_type, contents); -} - - // protocol @@ -257,3 +248,20 @@ void wfp_dirbuffer_add( { wfp_impl_dirbuffer_add(buffer, name, inode); } + +// credentials + +void wfp_credentials_set_type( + struct wfp_credentials * credentials, + char const * type) +{ + wfp_impl_credentials_set_type(credentials, type); +} + +void wfp_credentials_add( + struct wfp_credentials * credentials, + char const * key, + char const * value) +{ + wfp_impl_credentials_add(credentials, key, value); +} diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c index 7163830..0e8afc6 100644 --- a/lib/webfuse/provider/impl/client_config.c +++ b/lib/webfuse/provider/impl/client_config.c @@ -111,28 +111,9 @@ void wfp_impl_client_config_set_onread( config->provider.read = handler; } - -void wfp_impl_client_config_set_username_credentials( +void wfp_impl_client_config_enable_authentication( struct wfp_client_config * config, - char const * username, - char const * password) + wfp_get_credentials_fn * get_credentials) { - (void) config; - (void) username; - (void) password; - - // ToDo: implement me -} - -void wfp_impl_client_config_set_generic_credentials( - struct wfp_client_config * config, - char const * credentials_type, - char const * contents[]) -{ - (void) config; - (void) credentials_type; - (void) contents; - - // ToDo: implement me - + config->provider.get_credentials = get_credentials; } diff --git a/lib/webfuse/provider/impl/client_config.h b/lib/webfuse/provider/impl/client_config.h index 4b94f49..f8d5b9b 100644 --- a/lib/webfuse/provider/impl/client_config.h +++ b/lib/webfuse/provider/impl/client_config.h @@ -70,15 +70,9 @@ extern void wfp_impl_client_config_set_onread( struct wfp_client_config * config, wfp_read_fn * handler); -extern void wfp_impl_client_config_set_username_credentials( +extern void wfp_impl_client_config_enable_authentication( struct wfp_client_config * config, - char const * username, - char const * password); - -extern void wfp_impl_client_config_set_generic_credentials( - struct wfp_client_config * config, - char const * credentials_type, - char const * contents[]); + wfp_get_credentials_fn * get_credentials); #ifdef __cplusplus } diff --git a/lib/webfuse/provider/impl/credentials.c b/lib/webfuse/provider/impl/credentials.c new file mode 100644 index 0000000..8e788ca --- /dev/null +++ b/lib/webfuse/provider/impl/credentials.c @@ -0,0 +1,34 @@ +#include "webfuse/provider/impl/credentials.h" + +#include +#include + +void wfp_impl_credentials_init( + struct wfp_credentials * credentials) +{ + credentials->type = NULL; + credentials->contents = json_object(); +} + +void wfp_impl_credentials_cleanup( + struct wfp_credentials * credentials) +{ + free(credentials->type); + json_decref(credentials->contents); +} + +void wfp_impl_credentials_set_type( + struct wfp_credentials * credentials, + char const * type) +{ + free(credentials->type); + credentials->type = strdup(type); +} + +void wfp_impl_credentials_add( + struct wfp_credentials * credentials, + char const * key, + char const * value) +{ + json_object_set_new(credentials->contents, key, json_string(value)); +} diff --git a/lib/webfuse/provider/impl/credentials.h b/lib/webfuse/provider/impl/credentials.h new file mode 100644 index 0000000..6da40b9 --- /dev/null +++ b/lib/webfuse/provider/impl/credentials.h @@ -0,0 +1,38 @@ +#ifndef WF_PROVIDER_IMPL_CREDENTIALS_H +#define WF_PROVIDER_IMPL_CREDENTIALS_H + +#include "webfuse/provider/credentials.h" +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_credentials +{ + char * type; + json_t * contents; +}; + +extern void wfp_impl_credentials_init( + struct wfp_credentials * credentials); + +extern void wfp_impl_credentials_cleanup( + struct wfp_credentials * credentials); + +extern void wfp_impl_credentials_set_type( + struct wfp_credentials * credentials, + char const * type); + +extern void wfp_impl_credentials_add( + struct wfp_credentials * credentials, + char const * key, + char const * value); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/provider/impl/provider.c b/lib/webfuse/provider/impl/provider.c index def9e4a..d3ba96c 100644 --- a/lib/webfuse/provider/impl/provider.c +++ b/lib/webfuse/provider/impl/provider.c @@ -67,6 +67,7 @@ void wfp_impl_provider_init( provider->connected = &wfp_impl_connected_default; provider->disconnected = &wfp_impl_disconnected_default; provider->ontimer = &wfp_impl_ontimer_default; + provider->get_credentials = NULL; } void wfp_impl_provider_init_from_prototype( @@ -82,6 +83,7 @@ void wfp_impl_provider_init_from_prototype( provider->connected = prototype->connected; provider->disconnected = prototype->disconnected; provider->ontimer = prototype->ontimer; + provider->get_credentials = prototype->get_credentials; } void wfp_impl_provider_invoke( diff --git a/lib/webfuse/provider/impl/provider.h b/lib/webfuse/provider/impl/provider.h index ddee453..8f6d115 100644 --- a/lib/webfuse/provider/impl/provider.h +++ b/lib/webfuse/provider/impl/provider.h @@ -20,6 +20,7 @@ struct wfp_provider wfp_open_fn * open; wfp_close_fn * close; wfp_read_fn * read; + wfp_get_credentials_fn * get_credentials; }; struct wfp_impl_invokation_context diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index c5e5008..b9d6252 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -45,13 +45,6 @@ public: wfp_client_config_dispose(config); } - void SetUsernameCredentials( - std::string const & username, - std::string const & password) - { - wfp_client_config_set_username_credentials(config, username.c_str(), password.c_str()); - } - void Connect() { wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); @@ -169,7 +162,7 @@ TEST(client_protocol, connect_with_username_authentication) { MockProviderClient provider; ClientProtocolFixture fixture(provider); - fixture.SetUsernameCredentials("bob", "secret"); + // ToDo: enable authentication EXPECT_CALL(provider, OnConnected()).Times(AtMost(1)); EXPECT_CALL(provider, OnDisconnected()).Times(1); From e3a3427ca89c617d7a38cb634a8e374170250a21 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 28 Feb 2020 23:17:41 +0100 Subject: [PATCH 064/138] refactor: made jsonrpc an independent library --- CMakeLists.txt | 1 + cmake/jsonrpc.cmake | 13 ++ cmake/unit_tests.cmake | 15 ++- cmake/webfuse_adapter.cmake | 8 +- cmake/webfuse_core.cmake | 1 + include/jsonrpc/method.h | 40 ++++++ include/jsonrpc/proxy.h | 81 ++++++++++++ include/jsonrpc/request.h | 52 ++++++++ include/jsonrpc/response.h | 40 ++++++ .../impl => include}/jsonrpc/send_fn.h | 6 +- include/jsonrpc/server.h | 47 +++++++ include/jsonrpc/status.h | 10 ++ lib/jsonrpc/error.c | 27 ++++ lib/jsonrpc/error.h | 29 +++++ .../adapter/impl => }/jsonrpc/method.c | 12 +- .../adapter/impl => }/jsonrpc/proxy.c | 67 +++++----- .../adapter/impl => }/jsonrpc/request.c | 34 ++--- .../adapter/impl => }/jsonrpc/response.c | 39 +++--- lib/jsonrpc/server.c | 95 ++++++++++++++ lib/webfuse/adapter/impl/jsonrpc/method.h | 40 ------ lib/webfuse/adapter/impl/jsonrpc/proxy.h | 82 ------------ lib/webfuse/adapter/impl/jsonrpc/request.h | 52 -------- lib/webfuse/adapter/impl/jsonrpc/response.h | 41 ------ lib/webfuse/adapter/impl/jsonrpc/server.c | 95 -------------- lib/webfuse/adapter/impl/jsonrpc/server.h | 48 ------- lib/webfuse/adapter/impl/jsonrpc/util.c | 14 -- lib/webfuse/adapter/impl/jsonrpc/util.h | 17 --- lib/webfuse/adapter/impl/operation/close.c | 6 +- lib/webfuse/adapter/impl/operation/getattr.c | 27 ++-- lib/webfuse/adapter/impl/operation/lookup.c | 29 +++-- lib/webfuse/adapter/impl/operation/open.c | 12 +- lib/webfuse/adapter/impl/operation/read.c | 21 +-- lib/webfuse/adapter/impl/operation/readdir.c | 12 +- lib/webfuse/adapter/impl/operations.c | 4 +- lib/webfuse/adapter/impl/operations.h | 4 +- lib/webfuse/adapter/impl/server_protocol.c | 26 ++-- lib/webfuse/adapter/impl/server_protocol.h | 6 +- lib/webfuse/adapter/impl/session.c | 22 ++-- lib/webfuse/adapter/impl/session.h | 10 +- lib/webfuse/adapter/impl/session_manager.c | 2 +- lib/webfuse/adapter/impl/session_manager.h | 4 +- lib/webfuse/core/json_util.c | 48 +++++++ lib/webfuse/core/json_util.h | 26 ++++ .../adapter => }/jsonrpc/test_is_request.cc | 22 ++-- .../adapter => }/jsonrpc/test_is_response.cc | 20 +-- .../tests/adapter => }/jsonrpc/test_proxy.cc | 122 +++++++++--------- .../adapter => }/jsonrpc/test_request.cc | 22 ++-- .../adapter => }/jsonrpc/test_response.cc | 28 ++-- .../tests/adapter => }/jsonrpc/test_server.cc | 36 +++--- .../tests/adapter => }/jsonrpc/test_util.cc | 2 +- test/webfuse/mocks/mock_provider_client.cc | 23 +++- test/webfuse/mocks/mock_provider_client.hpp | 6 +- .../tests/adapter/test_response_parser.cc | 27 ++-- .../tests/provider/test_client_protocol.cc | 16 ++- 54 files changed, 882 insertions(+), 707 deletions(-) create mode 100644 cmake/jsonrpc.cmake create mode 100644 include/jsonrpc/method.h create mode 100644 include/jsonrpc/proxy.h create mode 100644 include/jsonrpc/request.h create mode 100644 include/jsonrpc/response.h rename {lib/webfuse/adapter/impl => include}/jsonrpc/send_fn.h (61%) create mode 100644 include/jsonrpc/server.h create mode 100644 include/jsonrpc/status.h create mode 100644 lib/jsonrpc/error.c create mode 100644 lib/jsonrpc/error.h rename lib/{webfuse/adapter/impl => }/jsonrpc/method.c (50%) rename lib/{webfuse/adapter/impl => }/jsonrpc/proxy.c (68%) rename lib/{webfuse/adapter/impl => }/jsonrpc/request.c (64%) rename lib/{webfuse/adapter/impl => }/jsonrpc/response.c (53%) create mode 100644 lib/jsonrpc/server.c delete mode 100644 lib/webfuse/adapter/impl/jsonrpc/method.h delete mode 100644 lib/webfuse/adapter/impl/jsonrpc/proxy.h delete mode 100644 lib/webfuse/adapter/impl/jsonrpc/request.h delete mode 100644 lib/webfuse/adapter/impl/jsonrpc/response.h delete mode 100644 lib/webfuse/adapter/impl/jsonrpc/server.c delete mode 100644 lib/webfuse/adapter/impl/jsonrpc/server.h delete mode 100644 lib/webfuse/adapter/impl/jsonrpc/util.c delete mode 100644 lib/webfuse/adapter/impl/jsonrpc/util.h create mode 100644 lib/webfuse/core/json_util.c create mode 100644 lib/webfuse/core/json_util.h rename test/{webfuse/tests/adapter => }/jsonrpc/test_is_request.cc (81%) rename test/{webfuse/tests/adapter => }/jsonrpc/test_is_response.cc (76%) rename test/{webfuse/tests/adapter => }/jsonrpc/test_proxy.cc (72%) rename test/{webfuse/tests/adapter => }/jsonrpc/test_request.cc (75%) rename test/{webfuse/tests/adapter => }/jsonrpc/test_response.cc (59%) rename test/{webfuse/tests/adapter => }/jsonrpc/test_server.cc (75%) rename test/{webfuse/tests/adapter => }/jsonrpc/test_util.cc (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b77e46..cbdf5f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ add_compile_options( "-pthread" ) +include(jsonrpc) include(webfuse_core) include(webfuse_adapter) include(webfuse_provider) diff --git a/cmake/jsonrpc.cmake b/cmake/jsonrpc.cmake new file mode 100644 index 0000000..40be948 --- /dev/null +++ b/cmake/jsonrpc.cmake @@ -0,0 +1,13 @@ +# jsonrpc + +add_library(jsonrpc STATIC + lib/jsonrpc/proxy.c + lib/jsonrpc/server.c + lib/jsonrpc/method.c + lib/jsonrpc/request.c + lib/jsonrpc/response.c + lib/jsonrpc/error.c +) + +target_include_directories(jsonrpc PUBLIC lib) +set_target_properties(jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1ff1be5..43c6a4f 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,6 +7,13 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests + test/jsonrpc/test_util.cc + test/jsonrpc/test_is_request.cc + test/jsonrpc/test_request.cc + test/jsonrpc/test_is_response.cc + test/jsonrpc/test_response.cc + test/jsonrpc/test_server.cc + test/jsonrpc/test_proxy.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc test/webfuse/utils/msleep.cc @@ -37,13 +44,6 @@ add_executable(alltests test/webfuse/tests/adapter/test_uuid_mountpoint.cc test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc test/webfuse/tests/adapter/test_fuse_req.cc - test/webfuse/tests/adapter/jsonrpc/test_util.cc - test/webfuse/tests/adapter/jsonrpc/test_is_request.cc - test/webfuse/tests/adapter/jsonrpc/test_request.cc - test/webfuse/tests/adapter/jsonrpc/test_is_response.cc - test/webfuse/tests/adapter/jsonrpc/test_response.cc - test/webfuse/tests/adapter/jsonrpc/test_server.cc - test/webfuse/tests/adapter/jsonrpc/test_proxy.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/integration/test_integration.cc @@ -65,6 +65,7 @@ target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core + jsonrpc ${FUSE3_LIBRARIES} ${LWS_LIBRARIES} ${JANSSON_LIBRARIES} diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index 269204d..719f699 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -28,12 +28,6 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/operation/open.c lib/webfuse/adapter/impl/operation/close.c lib/webfuse/adapter/impl/operation/read.c - lib/webfuse/adapter/impl/jsonrpc/proxy.c - lib/webfuse/adapter/impl/jsonrpc/server.c - lib/webfuse/adapter/impl/jsonrpc/method.c - lib/webfuse/adapter/impl/jsonrpc/request.c - lib/webfuse/adapter/impl/jsonrpc/response.c - lib/webfuse/adapter/impl/jsonrpc/util.c ) target_include_directories(webfuse-adapter-static PRIVATE @@ -70,7 +64,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 COMPILE_DEFINITIONS "WF_API=WF_EXPORT") -target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core) +target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core jsonrpc) file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 52c7681..2926384 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -8,6 +8,7 @@ add_library(webfuse-core STATIC lib/webfuse/core/string.c lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c + lib/webfuse/core/json_util.c ) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) diff --git a/include/jsonrpc/method.h b/include/jsonrpc/method.h new file mode 100644 index 0000000..8e9cb3a --- /dev/null +++ b/include/jsonrpc/method.h @@ -0,0 +1,40 @@ +#ifndef JSONRPC_METHOD_H +#define JSONRPC_METHOD_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct jsonrpc_request; + +typedef void jsonrpc_method_invoke_fn( + struct jsonrpc_request * request, + char const * method_name, + json_t * params, + void * user_data); + +struct jsonrpc_method +{ + struct jsonrpc_method * next; + char * name; + jsonrpc_method_invoke_fn * invoke; + void * user_data; +}; + +extern struct jsonrpc_method * jsonrpc_method_create( + char const * method_name, + jsonrpc_method_invoke_fn * invoke, + void * user_data); + +extern void jsonrpc_method_dispose( + struct jsonrpc_method * method); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/jsonrpc/proxy.h b/include/jsonrpc/proxy.h new file mode 100644 index 0000000..eb44991 --- /dev/null +++ b/include/jsonrpc/proxy.h @@ -0,0 +1,81 @@ +#ifndef JSONRPC_PROXY_H +#define JSONRPC_PROXY_H + +#ifndef __cplusplus +#include +#include +#include +#else +#include +#include +using std::size_t; +#endif + +#include +#include "jsonrpc/send_fn.h" +#include "webfuse/adapter/impl/time/timeout_manager.h" +#include "webfuse/adapter/impl/time/timer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void jsonrpc_proxy_finished_fn( + void * user_data, + json_t const * result, + json_t const * error); + + +struct jsonrpc_request +{ + bool is_pending; + jsonrpc_proxy_finished_fn * finished; + void * user_data; + int id; + struct wf_impl_timer timer; +}; + +struct jsonrpc_proxy +{ + struct jsonrpc_request request; + int timeout; + jsonrpc_send_fn * send; + void * user_data; +}; + +extern void jsonrpc_proxy_init( + struct jsonrpc_proxy * proxy, + struct wf_impl_timeout_manager * manager, + int timeout, + jsonrpc_send_fn * send, + void * user_data); + +extern void jsonrpc_proxy_cleanup( + struct jsonrpc_proxy * proxy); + +extern void jsonrpc_proxy_invoke( + struct jsonrpc_proxy * proxy, + jsonrpc_proxy_finished_fn * finished, + void * user_data, + char const * method_name, + char const * param_info, + ... +); + +extern void jsonrpc_proxy_notify( + struct jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + ... +); + +extern void jsonrpc_proxy_onresult( + struct jsonrpc_proxy * proxy, + json_t * message); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/jsonrpc/request.h b/include/jsonrpc/request.h new file mode 100644 index 0000000..496a4e0 --- /dev/null +++ b/include/jsonrpc/request.h @@ -0,0 +1,52 @@ +#ifndef JSONRPC_REQUEST_H +#define JSONRPC_REQUEST_H + +#ifndef __cplusplus +#include +#include +#include +#else +#include +#include +using std::size_t; +#endif + +#include +#include "webfuse/core/status.h" +#include "jsonrpc/send_fn.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct jsonrpc_request; + +extern bool jsonrpc_is_request( + json_t * message); + +extern struct jsonrpc_request * jsonrpc_request_create( + int id, + jsonrpc_send_fn * send, + void * user_data); + +extern void jsonrpc_request_dispose( + struct jsonrpc_request * request); + +extern void * jsonrpc_request_get_userdata( + struct jsonrpc_request * request); + +extern void jsonrpc_respond( + struct jsonrpc_request * request, + json_t * result); + +extern void jsonrpc_respond_error( + struct jsonrpc_request * request, + wf_status status); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/jsonrpc/response.h b/include/jsonrpc/response.h new file mode 100644 index 0000000..fbdaa7e --- /dev/null +++ b/include/jsonrpc/response.h @@ -0,0 +1,40 @@ +#ifndef WF_JSONRPC_RESPONSE_H +#define WF_JSONRPC_RESPONSE_H + +#ifndef __cplusplus +#include +#include +#else +#include +using std::size_t; +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct jsonrpc_response +{ + json_t * result; + json_t * error; + int id; +}; + +extern bool jsonrpc_is_response( + json_t * message); + +extern void jsonrpc_response_init( + struct jsonrpc_response * response, + json_t * message); + +extern void jsonrpc_response_cleanup( + struct jsonrpc_response * response); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/lib/webfuse/adapter/impl/jsonrpc/send_fn.h b/include/jsonrpc/send_fn.h similarity index 61% rename from lib/webfuse/adapter/impl/jsonrpc/send_fn.h rename to include/jsonrpc/send_fn.h index baeedf7..b25bdbb 100644 --- a/lib/webfuse/adapter/impl/jsonrpc/send_fn.h +++ b/include/jsonrpc/send_fn.h @@ -1,5 +1,5 @@ -#ifndef WF_ADAPTER_IMPL_JSONRPC_SEND_FN_H -#define WF_ADAPTER_IMPL_JSONRPC_SEND_FN_H +#ifndef JSONRPC_SEND_FN_H +#define JSONRPC_SEND_FN_H #ifndef __cplusplus #include @@ -12,7 +12,7 @@ extern "C" { #endif -typedef bool wf_impl_jsonrpc_send_fn( +typedef bool jsonrpc_send_fn( json_t * request, void * user_data); diff --git a/include/jsonrpc/server.h b/include/jsonrpc/server.h new file mode 100644 index 0000000..778a7e2 --- /dev/null +++ b/include/jsonrpc/server.h @@ -0,0 +1,47 @@ +#ifndef JSONRPC_SERVER_H +#define JSONRPC_SERVER_H + +#ifndef __cplusplus +#include +#include +#else +#include +#endif + +#include +#include "jsonrpc/send_fn.h" +#include "jsonrpc/method.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct jsonrpc_server +{ + struct jsonrpc_method * methods; +}; + +extern void jsonrpc_server_init( + struct jsonrpc_server * server); + +extern void jsonrpc_server_cleanup( + struct jsonrpc_server * server); + +extern void jsonrpc_server_add( + struct jsonrpc_server * server, + char const * method_name, + jsonrpc_method_invoke_fn * invoke, + void * user_data); + +extern void jsonrpc_server_process( + struct jsonrpc_server * server, + json_t * request, + jsonrpc_send_fn * send, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/jsonrpc/status.h b/include/jsonrpc/status.h new file mode 100644 index 0000000..b7368b3 --- /dev/null +++ b/include/jsonrpc/status.h @@ -0,0 +1,10 @@ +#ifndef JSONRPC_STATUS_H +#define JSONRPC_STATUS_H + +#define JSONRPC_GOOD 0 +#define JSONRPC_BAD -1 +#define JSONRPC_BAD_TIMEOUT -3 +#define JSONRPC_BAD_BUSY -4 +#define JSONRPC_BAD_FORMAT -5 + +#endif diff --git a/lib/jsonrpc/error.c b/lib/jsonrpc/error.c new file mode 100644 index 0000000..7613766 --- /dev/null +++ b/lib/jsonrpc/error.c @@ -0,0 +1,27 @@ +#include "jsonrpc/error.h" + +json_t * +jsonrpc_error( + int code, + char const * message) +{ + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(code)); + json_object_set_new(error, "message", json_string(message)); + + return error; +} + +void +jsonrpc_propate_error( + jsonrpc_proxy_finished_fn * finised, + void * user_data, + int code, + char const * message) +{ + json_t * error = jsonrpc_error(code, message); + finised(user_data, NULL, error); + + json_decref(error); +} + diff --git a/lib/jsonrpc/error.h b/lib/jsonrpc/error.h new file mode 100644 index 0000000..38bbcd2 --- /dev/null +++ b/lib/jsonrpc/error.h @@ -0,0 +1,29 @@ +#ifndef JSONRPC_ERROR_H +#define JSONRPC_ERROR_H + +#include +#include "jsonrpc/proxy.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern json_t * +jsonrpc_error( + int code, + char const * message); + +extern void +jsonrpc_propate_error( + jsonrpc_proxy_finished_fn * finised, + void * user_data, + int code, + char const * message); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/webfuse/adapter/impl/jsonrpc/method.c b/lib/jsonrpc/method.c similarity index 50% rename from lib/webfuse/adapter/impl/jsonrpc/method.c rename to lib/jsonrpc/method.c index 8485471..31414d4 100644 --- a/lib/webfuse/adapter/impl/jsonrpc/method.c +++ b/lib/jsonrpc/method.c @@ -1,13 +1,13 @@ -#include "webfuse/adapter/impl/jsonrpc/method.h" +#include "jsonrpc/method.h" #include #include -struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create( +struct jsonrpc_method * jsonrpc_method_create( char const * method_name, - wf_impl_jsonrpc_method_invoke_fn * invoke, + jsonrpc_method_invoke_fn * invoke, void * user_data) { - struct wf_impl_jsonrpc_method * method = malloc(sizeof(struct wf_impl_jsonrpc_method)); + struct jsonrpc_method * method = malloc(sizeof(struct jsonrpc_method)); if (NULL != method) { method->next = NULL; @@ -19,8 +19,8 @@ struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create( return method; } -void wf_impl_jsonrpc_method_dispose( - struct wf_impl_jsonrpc_method * method) +void jsonrpc_method_dispose( + struct jsonrpc_method * method) { free(method->name); free(method); diff --git a/lib/webfuse/adapter/impl/jsonrpc/proxy.c b/lib/jsonrpc/proxy.c similarity index 68% rename from lib/webfuse/adapter/impl/jsonrpc/proxy.c rename to lib/jsonrpc/proxy.c index ec0da2e..b12571e 100644 --- a/lib/webfuse/adapter/impl/jsonrpc/proxy.c +++ b/lib/jsonrpc/proxy.c @@ -1,16 +1,18 @@ -#include "webfuse/adapter/impl/jsonrpc/proxy.h" +#include "jsonrpc/proxy.h" +#include "jsonrpc/response.h" +#include "jsonrpc/error.h" +#include "jsonrpc/status.h" + #include -#include "webfuse/adapter/impl/jsonrpc/response.h" - -static void wf_impl_jsonrpc_proxy_timeout( +static void jsonrpc_proxy_timeout( struct wf_impl_timer * timer) { - struct wf_impl_jsonrpc_proxy * proxy = timer->user_data; + struct jsonrpc_proxy * proxy = timer->user_data; if (proxy->request.is_pending) { - wf_impl_jsonrpc_proxy_finished_fn * finished = proxy->request.finished; + jsonrpc_proxy_finished_fn * finished = proxy->request.finished; void * user_data = proxy->request.user_data; proxy->request.is_pending = false; @@ -19,11 +21,11 @@ static void wf_impl_jsonrpc_proxy_timeout( proxy->request.finished = NULL; wf_impl_timer_cancel(&proxy->request.timer); - finished(user_data, WF_BAD_TIMEOUT, NULL); + jsonrpc_propate_error(finished, user_data, JSONRPC_BAD_TIMEOUT, "Timeout"); } } -static json_t * wf_impl_jsonrpc_request_create( +static json_t * jsonrpc_request_create( char const * method, int id, char const * param_info, @@ -67,11 +69,11 @@ static json_t * wf_impl_jsonrpc_request_create( return request; } -void wf_impl_jsonrpc_proxy_init( - struct wf_impl_jsonrpc_proxy * proxy, +void jsonrpc_proxy_init( + struct jsonrpc_proxy * proxy, struct wf_impl_timeout_manager * timeout_manager, int timeout, - wf_impl_jsonrpc_send_fn * send, + jsonrpc_send_fn * send, void * user_data) { proxy->send = send; @@ -82,13 +84,13 @@ void wf_impl_jsonrpc_proxy_init( wf_impl_timer_init(&proxy->request.timer, timeout_manager); } -void wf_impl_jsonrpc_proxy_cleanup( - struct wf_impl_jsonrpc_proxy * proxy) +void jsonrpc_proxy_cleanup( + struct jsonrpc_proxy * proxy) { if (proxy->request.is_pending) { void * user_data = proxy->request.user_data; - wf_impl_jsonrpc_proxy_finished_fn * finished = proxy->request.finished; + jsonrpc_proxy_finished_fn * finished = proxy->request.finished; proxy->request.is_pending = false; proxy->request.finished = NULL; @@ -96,15 +98,15 @@ void wf_impl_jsonrpc_proxy_cleanup( proxy->request.id = 0; wf_impl_timer_cancel(&proxy->request.timer); - finished(user_data, WF_BAD, NULL); + jsonrpc_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); } wf_impl_timer_cleanup(&proxy->request.timer); } -void wf_impl_jsonrpc_proxy_invoke( - struct wf_impl_jsonrpc_proxy * proxy, - wf_impl_jsonrpc_proxy_finished_fn * finished, +void jsonrpc_proxy_invoke( + struct jsonrpc_proxy * proxy, + jsonrpc_proxy_finished_fn * finished, void * user_data, char const * method_name, char const * param_info, @@ -118,11 +120,11 @@ void wf_impl_jsonrpc_proxy_invoke( proxy->request.user_data = user_data; proxy->request.id = 42; wf_impl_timer_start(&proxy->request.timer, wf_impl_timepoint_in_msec(proxy->timeout), - &wf_impl_jsonrpc_proxy_timeout, proxy); + &jsonrpc_proxy_timeout, proxy); va_list args; va_start(args, param_info); - json_t * request = wf_impl_jsonrpc_request_create(method_name, proxy->request.id, param_info, args); + json_t * request = jsonrpc_request_create(method_name, proxy->request.id, param_info, args); va_end(args); bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data))); @@ -134,8 +136,7 @@ void wf_impl_jsonrpc_proxy_invoke( proxy->request.id = 0; wf_impl_timer_cancel(&proxy->request.timer); - finished(user_data, WF_BAD, NULL); - + jsonrpc_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); } if (NULL != request) @@ -145,12 +146,12 @@ void wf_impl_jsonrpc_proxy_invoke( } else { - finished(user_data, WF_BAD_BUSY, NULL); + jsonrpc_propate_error(finished, user_data, JSONRPC_BAD_BUSY, "Busy"); } } -extern void wf_impl_jsonrpc_proxy_notify( - struct wf_impl_jsonrpc_proxy * proxy, +extern void jsonrpc_proxy_notify( + struct jsonrpc_proxy * proxy, char const * method_name, char const * param_info, ... @@ -158,7 +159,7 @@ extern void wf_impl_jsonrpc_proxy_notify( { va_list args; va_start(args, param_info); - json_t * request = wf_impl_jsonrpc_request_create(method_name, 0, param_info, args); + json_t * request = jsonrpc_request_create(method_name, 0, param_info, args); va_end(args); if (NULL != request) { @@ -168,16 +169,16 @@ extern void wf_impl_jsonrpc_proxy_notify( } -void wf_impl_jsonrpc_proxy_onresult( - struct wf_impl_jsonrpc_proxy * proxy, +void jsonrpc_proxy_onresult( + struct jsonrpc_proxy * proxy, json_t * message) { - struct wf_impl_jsonrpc_response response; - wf_impl_jsonrpc_response_init(&response, message); + struct jsonrpc_response response; + jsonrpc_response_init(&response, message); if ((proxy->request.is_pending) && (response.id == proxy->request.id)) { - wf_impl_jsonrpc_proxy_finished_fn * finished = proxy->request.finished; + jsonrpc_proxy_finished_fn * finished = proxy->request.finished; void * user_data = proxy->request.user_data; proxy->request.is_pending = false; @@ -186,9 +187,9 @@ void wf_impl_jsonrpc_proxy_onresult( proxy->request.finished = NULL; wf_impl_timer_cancel(&proxy->request.timer); - finished(user_data, response.status, response.result); + finished(user_data, response.result, response.error); } - wf_impl_jsonrpc_response_cleanup(&response); + jsonrpc_response_cleanup(&response); } diff --git a/lib/webfuse/adapter/impl/jsonrpc/request.c b/lib/jsonrpc/request.c similarity index 64% rename from lib/webfuse/adapter/impl/jsonrpc/request.c rename to lib/jsonrpc/request.c index e016e1c..8790ce9 100644 --- a/lib/webfuse/adapter/impl/jsonrpc/request.c +++ b/lib/jsonrpc/request.c @@ -1,15 +1,15 @@ -#include "webfuse/adapter/impl/jsonrpc/request.h" +#include "jsonrpc/request.h" #include "webfuse/core/status_intern.h" #include -struct wf_impl_jsonrpc_request +struct jsonrpc_request { int id; - wf_impl_jsonrpc_send_fn * send; + jsonrpc_send_fn * send; void * user_data; }; -bool wf_impl_jsonrpc_is_request( +bool jsonrpc_is_request( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -21,12 +21,12 @@ bool wf_impl_jsonrpc_is_request( } -struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create( +struct jsonrpc_request * jsonrpc_request_create( int id, - wf_impl_jsonrpc_send_fn * send, + jsonrpc_send_fn * send, void * user_data) { - struct wf_impl_jsonrpc_request * request = malloc(sizeof(struct wf_impl_jsonrpc_request)); + struct jsonrpc_request * request = malloc(sizeof(struct jsonrpc_request)); if (NULL != request) { request->id = id; @@ -37,21 +37,21 @@ struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create( return request; } -void wf_impl_jsonrpc_request_dispose( - struct wf_impl_jsonrpc_request * request) +void jsonrpc_request_dispose( + struct jsonrpc_request * request) { free(request); } -void * wf_impl_jsonrpc_request_get_userdata( - struct wf_impl_jsonrpc_request * request) +void * jsonrpc_request_get_userdata( + struct jsonrpc_request * request) { return request->user_data; } -void wf_impl_jsonrpc_respond( - struct wf_impl_jsonrpc_request * request, +void jsonrpc_respond( + struct jsonrpc_request * request, json_t * result) { json_t * response = json_object(); @@ -60,11 +60,11 @@ void wf_impl_jsonrpc_respond( request->send(response, request->user_data); json_decref(response); - wf_impl_jsonrpc_request_dispose(request); + jsonrpc_request_dispose(request); } -void wf_impl_jsonrpc_respond_error( - struct wf_impl_jsonrpc_request * request, +void jsonrpc_respond_error( + struct jsonrpc_request * request, wf_status status) { json_t * err = json_object(); @@ -77,6 +77,6 @@ void wf_impl_jsonrpc_respond_error( request->send(response, request->user_data); json_decref(response); - wf_impl_jsonrpc_request_dispose(request); + jsonrpc_request_dispose(request); } diff --git a/lib/webfuse/adapter/impl/jsonrpc/response.c b/lib/jsonrpc/response.c similarity index 53% rename from lib/webfuse/adapter/impl/jsonrpc/response.c rename to lib/jsonrpc/response.c index 00eb396..c11bbc7 100644 --- a/lib/webfuse/adapter/impl/jsonrpc/response.c +++ b/lib/jsonrpc/response.c @@ -1,6 +1,8 @@ -#include "webfuse/adapter/impl/jsonrpc/response.h" +#include "jsonrpc/response.h" +#include "jsonrpc/error.h" +#include "jsonrpc/status.h" -extern bool wf_impl_jsonrpc_is_response( +extern bool jsonrpc_is_response( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -12,22 +14,21 @@ extern bool wf_impl_jsonrpc_is_response( } -void wf_impl_jsonrpc_response_init( - struct wf_impl_jsonrpc_response * result, +void jsonrpc_response_init( + struct jsonrpc_response * result, json_t * response) { - result->status = WF_BAD; result->id = -1; result->result = NULL; + result->error = NULL; json_t * id_holder = json_object_get(response, "id"); if ((NULL == id_holder) || (!json_is_integer(id_holder))) { - result->status = WF_BAD_FORMAT; + result->error = jsonrpc_error(JSONRPC_BAD_FORMAT, "invalid format: missing id"); return; } - result->status = WF_GOOD; result->id = json_integer_value(id_holder); result->result = json_object_get(response, "result"); if (NULL != result->result) @@ -36,25 +37,29 @@ void wf_impl_jsonrpc_response_init( } else { - result->status = WF_BAD_FORMAT; - json_t * error = json_object_get(response, "error"); - if (NULL != error) + if ((json_is_object(error)) && (json_is_integer(json_object_get(error, "code")))) { - json_t * error_code = json_object_get(error, "code"); - if ((NULL != error_code) && (json_is_integer(error_code))) - { - result->status = json_integer_value(error_code); - } + result->error = error; + json_incref(result->error); + } + else + { + result->error = jsonrpc_error(JSONRPC_BAD_FORMAT, "invalid format: invalid error object"); } } } -void wf_impl_jsonrpc_response_cleanup( - struct wf_impl_jsonrpc_response * response) +void jsonrpc_response_cleanup( + struct jsonrpc_response * response) { if (NULL != response->result) { json_decref(response->result); } + + if (NULL != response->error) + { + json_decref(response->error); + } } diff --git a/lib/jsonrpc/server.c b/lib/jsonrpc/server.c new file mode 100644 index 0000000..6e62c3b --- /dev/null +++ b/lib/jsonrpc/server.c @@ -0,0 +1,95 @@ +#include "jsonrpc/server.h" +#include "jsonrpc/method.h" +#include "jsonrpc/request.h" +#include "webfuse/core/util.h" + +#include + +void jsonrpc_server_init( + struct jsonrpc_server * server) +{ + server->methods = NULL; +} + +void jsonrpc_server_cleanup( + struct jsonrpc_server * server) +{ + struct jsonrpc_method * current = server->methods; + while (NULL != current) + { + struct jsonrpc_method * next = current->next; + jsonrpc_method_dispose(current); + current = next; + } + server->methods = NULL; +} + +void jsonrpc_server_add( + struct jsonrpc_server * server, + char const * method_name, + jsonrpc_method_invoke_fn * invoke, + void * user_data) +{ + struct jsonrpc_method * method = jsonrpc_method_create(method_name, invoke, user_data); + method->next = server->methods; + server->methods = method; +} + +static void jsonrpc_server_invalid_method_invoke( + struct jsonrpc_request * request, + char const * WF_UNUSED_PARAM(method_name), + json_t * WF_UNUSED_PARAM(params), + void * WF_UNUSED_PARAM(user_data)) +{ + jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED); +} + +static struct jsonrpc_method const jsonrpc_server_invalid_method = +{ + .next = NULL, + .name = "", + .invoke = &jsonrpc_server_invalid_method_invoke, + .user_data = NULL +}; + +static struct jsonrpc_method const * jsonrpc_server_get_method( + struct jsonrpc_server * server, + char const * method_name) +{ + struct jsonrpc_method const * current = server->methods; + while (NULL != current) + { + if (0 == strcmp(method_name, current->name)) + { + return current; + } + + current = current->next; + } + + return &jsonrpc_server_invalid_method; +} + +void jsonrpc_server_process( + struct jsonrpc_server * server, + json_t * request_data, + jsonrpc_send_fn * send, + void * user_data) +{ + json_t * method_holder = json_object_get(request_data, "method"); + json_t * params = json_object_get(request_data, "params"); + json_t * id_holder = json_object_get(request_data, "id"); + + if (json_is_string(method_holder) && + (json_is_array(params) || (json_is_object(params))) && + json_is_integer(id_holder)) + { + char const * method_name = json_string_value(method_holder); + int id = json_integer_value(id_holder); + struct jsonrpc_request * request = jsonrpc_request_create(id, send, user_data); + struct jsonrpc_method const * method = jsonrpc_server_get_method(server, method_name); + + method->invoke(request, method_name, params, method->user_data); + } +} + diff --git a/lib/webfuse/adapter/impl/jsonrpc/method.h b/lib/webfuse/adapter/impl/jsonrpc/method.h deleted file mode 100644 index 739f692..0000000 --- a/lib/webfuse/adapter/impl/jsonrpc/method.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_JSONRPC_METHOD_H -#define WF_ADAPTER_IMPL_JSONRPC_METHOD_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_impl_jsonrpc_request; - -typedef void wf_impl_jsonrpc_method_invoke_fn( - struct wf_impl_jsonrpc_request * request, - char const * method_name, - json_t * params, - void * user_data); - -struct wf_impl_jsonrpc_method -{ - struct wf_impl_jsonrpc_method * next; - char * name; - wf_impl_jsonrpc_method_invoke_fn * invoke; - void * user_data; -}; - -extern struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create( - char const * method_name, - wf_impl_jsonrpc_method_invoke_fn * invoke, - void * user_data); - -extern void wf_impl_jsonrpc_method_dispose( - struct wf_impl_jsonrpc_method * method); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/webfuse/adapter/impl/jsonrpc/proxy.h b/lib/webfuse/adapter/impl/jsonrpc/proxy.h deleted file mode 100644 index 0433747..0000000 --- a/lib/webfuse/adapter/impl/jsonrpc/proxy.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_JSONRPC_PROXY_H -#define WF_ADAPTER_IMPL_JSONRPC_PROXY_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include "webfuse/adapter/impl/jsonrpc/send_fn.h" -#include "webfuse/adapter/impl/time/timeout_manager.h" -#include "webfuse/adapter/impl/time/timer.h" -#include "webfuse/core/status.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void wf_impl_jsonrpc_proxy_finished_fn( - void * user_data, - wf_status status, - struct json_t const * result); - - -struct wf_impl_jsonrpc_request -{ - bool is_pending; - wf_impl_jsonrpc_proxy_finished_fn * finished; - void * user_data; - int id; - struct wf_impl_timer timer; -}; - -struct wf_impl_jsonrpc_proxy -{ - struct wf_impl_jsonrpc_request request; - int timeout; - wf_impl_jsonrpc_send_fn * send; - void * user_data; -}; - -extern void wf_impl_jsonrpc_proxy_init( - struct wf_impl_jsonrpc_proxy * proxy, - struct wf_impl_timeout_manager * manager, - int timeout, - wf_impl_jsonrpc_send_fn * send, - void * user_data); - -extern void wf_impl_jsonrpc_proxy_cleanup( - struct wf_impl_jsonrpc_proxy * proxy); - -extern void wf_impl_jsonrpc_proxy_invoke( - struct wf_impl_jsonrpc_proxy * proxy, - wf_impl_jsonrpc_proxy_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - ... -); - -extern void wf_impl_jsonrpc_proxy_notify( - struct wf_impl_jsonrpc_proxy * proxy, - char const * method_name, - char const * param_info, - ... -); - -extern void wf_impl_jsonrpc_proxy_onresult( - struct wf_impl_jsonrpc_proxy * proxy, - json_t * message); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/webfuse/adapter/impl/jsonrpc/request.h b/lib/webfuse/adapter/impl/jsonrpc/request.h deleted file mode 100644 index 7d26228..0000000 --- a/lib/webfuse/adapter/impl/jsonrpc/request.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_JSONRPC_REQUEST_H -#define WF_ADAPTER_IMPL_JSONRPC_REQUEST_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include "webfuse/core/status.h" -#include "webfuse/adapter/impl/jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_impl_jsonrpc_request; - -extern bool wf_impl_jsonrpc_is_request( - json_t * message); - -extern struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create( - int id, - wf_impl_jsonrpc_send_fn * send, - void * user_data); - -extern void wf_impl_jsonrpc_request_dispose( - struct wf_impl_jsonrpc_request * request); - -extern void * wf_impl_jsonrpc_request_get_userdata( - struct wf_impl_jsonrpc_request * request); - -extern void wf_impl_jsonrpc_respond( - struct wf_impl_jsonrpc_request * request, - json_t * result); - -extern void wf_impl_jsonrpc_respond_error( - struct wf_impl_jsonrpc_request * request, - wf_status status); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/webfuse/adapter/impl/jsonrpc/response.h b/lib/webfuse/adapter/impl/jsonrpc/response.h deleted file mode 100644 index d53f667..0000000 --- a/lib/webfuse/adapter/impl/jsonrpc/response.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H -#define WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H - -#ifndef __cplusplus -#include -#include -#else -#include -using std::size_t; -#endif - -#include -#include "webfuse/core/status.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct wf_impl_jsonrpc_response -{ - wf_status status; - int id; - json_t * result; -}; - -extern bool wf_impl_jsonrpc_is_response( - json_t * message); - -extern void wf_impl_jsonrpc_response_init( - struct wf_impl_jsonrpc_response * response, - json_t * message); - -extern void wf_impl_jsonrpc_response_cleanup( - struct wf_impl_jsonrpc_response * response); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/lib/webfuse/adapter/impl/jsonrpc/server.c b/lib/webfuse/adapter/impl/jsonrpc/server.c deleted file mode 100644 index 717d71b..0000000 --- a/lib/webfuse/adapter/impl/jsonrpc/server.c +++ /dev/null @@ -1,95 +0,0 @@ -#include "webfuse/adapter/impl/jsonrpc/server.h" -#include "webfuse/adapter/impl/jsonrpc/method.h" -#include "webfuse/adapter/impl/jsonrpc/request.h" -#include "webfuse/core/util.h" - -#include - -void wf_impl_jsonrpc_server_init( - struct wf_impl_jsonrpc_server * server) -{ - server->methods = NULL; -} - -void wf_impl_jsonrpc_server_cleanup( - struct wf_impl_jsonrpc_server * server) -{ - struct wf_impl_jsonrpc_method * current = server->methods; - while (NULL != current) - { - struct wf_impl_jsonrpc_method * next = current->next; - wf_impl_jsonrpc_method_dispose(current); - current = next; - } - server->methods = NULL; -} - -void wf_impl_jsonrpc_server_add( - struct wf_impl_jsonrpc_server * server, - char const * method_name, - wf_impl_jsonrpc_method_invoke_fn * invoke, - void * user_data) -{ - struct wf_impl_jsonrpc_method * method = wf_impl_jsonrpc_method_create(method_name, invoke, user_data); - method->next = server->methods; - server->methods = method; -} - -static void wf_impl_jsonrpc_server_invalid_method_invoke( - struct wf_impl_jsonrpc_request * request, - char const * WF_UNUSED_PARAM(method_name), - json_t * WF_UNUSED_PARAM(params), - void * WF_UNUSED_PARAM(user_data)) -{ - wf_impl_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED); -} - -static struct wf_impl_jsonrpc_method const wf_impl_jsonrpc_server_invalid_method = -{ - .next = NULL, - .name = "", - .invoke = &wf_impl_jsonrpc_server_invalid_method_invoke, - .user_data = NULL -}; - -static struct wf_impl_jsonrpc_method const * wf_impl_jsonrpc_server_get_method( - struct wf_impl_jsonrpc_server * server, - char const * method_name) -{ - struct wf_impl_jsonrpc_method const * current = server->methods; - while (NULL != current) - { - if (0 == strcmp(method_name, current->name)) - { - return current; - } - - current = current->next; - } - - return &wf_impl_jsonrpc_server_invalid_method; -} - -void wf_impl_jsonrpc_server_process( - struct wf_impl_jsonrpc_server * server, - json_t * request_data, - wf_impl_jsonrpc_send_fn * send, - void * user_data) -{ - json_t * method_holder = json_object_get(request_data, "method"); - json_t * params = json_object_get(request_data, "params"); - json_t * id_holder = json_object_get(request_data, "id"); - - if (json_is_string(method_holder) && - (json_is_array(params) || (json_is_object(params))) && - json_is_integer(id_holder)) - { - char const * method_name = json_string_value(method_holder); - int id = json_integer_value(id_holder); - struct wf_impl_jsonrpc_request * request = wf_impl_jsonrpc_request_create(id, send, user_data); - struct wf_impl_jsonrpc_method const * method = wf_impl_jsonrpc_server_get_method(server, method_name); - - method->invoke(request, method_name, params, method->user_data); - } -} - diff --git a/lib/webfuse/adapter/impl/jsonrpc/server.h b/lib/webfuse/adapter/impl/jsonrpc/server.h deleted file mode 100644 index 51c827b..0000000 --- a/lib/webfuse/adapter/impl/jsonrpc/server.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_JSONRPC_SERVER_H -#define WF_ADAPTER_IMPL_JSONRPC_SERVER_H - -#ifndef __cplusplus -#include -#include -#else -#include -#endif - -#include -#include "webfuse/core/status.h" -#include "webfuse/adapter/impl/jsonrpc/send_fn.h" -#include "webfuse/adapter/impl/jsonrpc/method.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_impl_jsonrpc_server -{ - struct wf_impl_jsonrpc_method * methods; -}; - -extern void wf_impl_jsonrpc_server_init( - struct wf_impl_jsonrpc_server * server); - -extern void wf_impl_jsonrpc_server_cleanup( - struct wf_impl_jsonrpc_server * server); - -extern void wf_impl_jsonrpc_server_add( - struct wf_impl_jsonrpc_server * server, - char const * method_name, - wf_impl_jsonrpc_method_invoke_fn * invoke, - void * user_data); - -extern void wf_impl_jsonrpc_server_process( - struct wf_impl_jsonrpc_server * server, - json_t * request, - wf_impl_jsonrpc_send_fn * send, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/webfuse/adapter/impl/jsonrpc/util.c b/lib/webfuse/adapter/impl/jsonrpc/util.c deleted file mode 100644 index 439eddb..0000000 --- a/lib/webfuse/adapter/impl/jsonrpc/util.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "webfuse/adapter/impl/jsonrpc/util.h" - -int wf_impl_json_get_int(json_t const * object, char const * key, int default_value) -{ - int result = default_value; - - json_t * holder = json_object_get(object, key); - if ((NULL != holder) && (json_is_integer(holder))) - { - result = json_integer_value(holder); - } - - return result; -} \ No newline at end of file diff --git a/lib/webfuse/adapter/impl/jsonrpc/util.h b/lib/webfuse/adapter/impl/jsonrpc/util.h deleted file mode 100644 index 0d5c6ab..0000000 --- a/lib/webfuse/adapter/impl/jsonrpc/util.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_JSON_UTIL_H -#define WF_ADAPTER_IMPL_JSON_UTIL_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern int wf_impl_json_get_int(json_t const * object, char const * key, int default_value); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index ca63a8e..fc1b1a0 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -4,7 +4,7 @@ #include #include -#include "webfuse/adapter/impl/jsonrpc/proxy.h" +#include "jsonrpc/proxy.h" #include "webfuse/core/util.h" void wf_impl_operation_close( @@ -13,12 +13,12 @@ void wf_impl_operation_close( struct fuse_file_info * file_info) { struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { int handle = (int) (file_info->fh & INT_MAX); - wf_impl_jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags); + jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags); } fuse_reply_err(request, 0); diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index cef8eac..f7be79d 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -7,8 +7,8 @@ #include #include -#include "webfuse/adapter/impl/jsonrpc/proxy.h" -#include "webfuse/adapter/impl/jsonrpc/util.h" +#include "jsonrpc/proxy.h" +#include "webfuse/core/json_util.h" #include "webfuse/core/util.h" struct wf_impl_operation_getattr_context @@ -22,16 +22,17 @@ struct wf_impl_operation_getattr_context static void wf_impl_operation_getattr_finished( void * user_data, - wf_status status, - json_t const * data) + json_t const * result, + json_t const * error) { + wf_status status = wf_impl_jsonrpc_get_status(error); struct wf_impl_operation_getattr_context * context = user_data; struct stat buffer; - if (NULL != data) + if (NULL != result) { - json_t * mode_holder = json_object_get(data, "mode"); - json_t * type_holder = json_object_get(data, "type"); + json_t * mode_holder = json_object_get(result, "mode"); + json_t * type_holder = json_object_get(result, "type"); if ((NULL != mode_holder) && (json_is_integer(mode_holder)) && (NULL != type_holder) && (json_is_string(type_holder))) { @@ -52,10 +53,10 @@ static void wf_impl_operation_getattr_finished( buffer.st_uid = context->uid; buffer.st_gid = context->gid; buffer.st_nlink = 1; - buffer.st_size = wf_impl_json_get_int(data, "size", 0); - buffer.st_atime = wf_impl_json_get_int(data, "atime", 0); - buffer.st_mtime = wf_impl_json_get_int(data, "mtime", 0); - buffer.st_ctime = wf_impl_json_get_int(data, "ctime", 0); + buffer.st_size = wf_impl_json_get_int(result, "size", 0); + buffer.st_atime = wf_impl_json_get_int(result, "atime", 0); + buffer.st_mtime = wf_impl_json_get_int(result, "mtime", 0); + buffer.st_ctime = wf_impl_json_get_int(result, "ctime", 0); } else { @@ -82,7 +83,7 @@ void wf_impl_operation_getattr ( { struct fuse_ctx const * context = fuse_req_ctx(request); struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { @@ -93,7 +94,7 @@ void wf_impl_operation_getattr ( getattr_context->gid = context->gid; getattr_context->timeout = user_data->timeout; - wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode); + jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode); } else { diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index 3f0cd3b..eaacf8d 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -10,8 +10,8 @@ #include -#include "webfuse/adapter/impl/jsonrpc/proxy.h" -#include "webfuse/adapter/impl/jsonrpc/util.h" +#include "jsonrpc/proxy.h" +#include "webfuse/core/json_util.h" #include "webfuse/core/util.h" struct wf_impl_operation_lookup_context @@ -24,18 +24,19 @@ struct wf_impl_operation_lookup_context static void wf_impl_operation_lookup_finished( void * user_data, - wf_status status, - json_t const * data + json_t const * result, + json_t const * error ) { + wf_status status = wf_impl_jsonrpc_get_status(error); struct wf_impl_operation_lookup_context * context = user_data; struct fuse_entry_param buffer; - if (NULL != data) + if (NULL != result) { - json_t * inode_holder = json_object_get(data, "inode"); - json_t * mode_holder = json_object_get(data, "mode"); - json_t * type_holder = json_object_get(data, "type"); + json_t * inode_holder = json_object_get(result, "inode"); + json_t * mode_holder = json_object_get(result, "mode"); + json_t * type_holder = json_object_get(result, "type"); if ((NULL != inode_holder) && (json_is_integer(inode_holder)) && (NULL != mode_holder) && (json_is_integer(mode_holder)) && (NULL != type_holder) && (json_is_string(type_holder))) @@ -61,10 +62,10 @@ static void wf_impl_operation_lookup_finished( buffer.attr.st_uid = context->uid; buffer.attr.st_gid = context->gid; buffer.attr.st_nlink = 1; - buffer.attr.st_size = wf_impl_json_get_int(data, "size", 0); - buffer.attr.st_atime = wf_impl_json_get_int(data, "atime", 0); - buffer.attr.st_mtime = wf_impl_json_get_int(data, "mtime", 0); - buffer.attr.st_ctime = wf_impl_json_get_int(data, "ctime", 0); + buffer.attr.st_size = wf_impl_json_get_int(result, "size", 0); + buffer.attr.st_atime = wf_impl_json_get_int(result, "atime", 0); + buffer.attr.st_mtime = wf_impl_json_get_int(result, "mtime", 0); + buffer.attr.st_ctime = wf_impl_json_get_int(result, "ctime", 0); } else { @@ -91,7 +92,7 @@ void wf_impl_operation_lookup ( { struct fuse_ctx const * context = fuse_req_ctx(request); struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { @@ -101,7 +102,7 @@ void wf_impl_operation_lookup ( lookup_context->gid = context->gid; lookup_context->timeout = user_data->timeout; - wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name); + jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name); } else { diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index e82b865..05fcec3 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -4,15 +4,17 @@ #include #include -#include "webfuse/adapter/impl/jsonrpc/proxy.h" +#include "jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/status.h" +#include "webfuse/core/json_util.h" static void wf_impl_operation_open_finished( void * user_data, - wf_status status, - json_t const * result) + json_t const * result, + json_t const * error) { + wf_status status = wf_impl_jsonrpc_get_status(error); fuse_req_t request = user_data; struct fuse_file_info file_info; memset(&file_info, 0, sizeof(struct fuse_file_info)); @@ -47,11 +49,11 @@ void wf_impl_operation_open( struct fuse_file_info * file_info) { struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { - wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags); + jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags); } else { diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index ec434c5..b9cfa1a 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -5,8 +5,9 @@ #include #include -#include "webfuse/adapter/impl/jsonrpc/proxy.h" +#include "jsonrpc/proxy.h" #include "webfuse/core/base64.h" +#include "webfuse/core/json_util.h" #define WF_MAX_READ_LENGTH 4096 @@ -38,17 +39,21 @@ static char * wf_impl_fill_buffer( return buffer; } -static void wf_impl_operation_read_finished(void * user_data, wf_status status, json_t const * data) +static void wf_impl_operation_read_finished( + void * user_data, + json_t const * result, + json_t const * error) { + wf_status status = wf_impl_jsonrpc_get_status(error); fuse_req_t request = user_data; char * buffer = NULL; size_t length = 0; - if (NULL != data) + if (NULL != result) { - json_t * data_holder = json_object_get(data, "data"); - json_t * format_holder = json_object_get(data, "format"); - json_t * count_holder = json_object_get(data, "count"); + json_t * data_holder = json_object_get(result, "data"); + json_t * format_holder = json_object_get(result, "format"); + json_t * count_holder = json_object_get(result, "count"); if (json_is_string(data_holder) && json_is_string(format_holder) && @@ -87,13 +92,13 @@ void wf_impl_operation_read( struct fuse_file_info * file_info) { struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH; int handle = (file_info->fh & INT_MAX); - wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length); + jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length); } else { diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index 85cfd5b..76414ea 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -8,8 +8,9 @@ #include #include -#include "webfuse/adapter/impl/jsonrpc/proxy.h" +#include "jsonrpc/proxy.h" #include "webfuse/core/util.h" +#include "webfuse/core/json_util.h" #define WF_DIRBUFFER_INITIAL_SIZE 1024 @@ -73,9 +74,10 @@ static size_t wf_impl_min(size_t a, size_t b) static void wf_impl_operation_readdir_finished( void * user_data, - wf_status status, - json_t const * result) + json_t const * result, + json_t const * error) { + wf_status status = wf_impl_jsonrpc_get_status(error); struct wf_impl_operation_readdir_context * context = user_data; struct wf_impl_dirbuffer buffer; @@ -137,7 +139,7 @@ void wf_impl_operation_readdir ( struct fuse_file_info * WF_UNUSED_PARAM(file_info)) { struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { @@ -146,7 +148,7 @@ void wf_impl_operation_readdir ( readdir_context->size = size; readdir_context->offset = offset; - wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode); + jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode); } else { diff --git a/lib/webfuse/adapter/impl/operations.c b/lib/webfuse/adapter/impl/operations.c index 393ab99..ac9fb96 100644 --- a/lib/webfuse/adapter/impl/operations.c +++ b/lib/webfuse/adapter/impl/operations.c @@ -3,10 +3,10 @@ #include "webfuse/adapter/impl/session.h" #include -struct wf_impl_jsonrpc_proxy * wf_impl_operations_context_get_proxy( +struct jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context) { - struct wf_impl_jsonrpc_proxy * proxy = NULL; + struct jsonrpc_proxy * proxy = NULL; struct wf_impl_session * session = context->session; if (NULL != session) diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index debe4fa..50bcef6 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -8,7 +8,7 @@ extern "C" { #endif struct wf_impl_session; -struct wf_impl_jsonrpc_proxy; +struct jsonrpc_proxy; struct wf_impl_operations_context { @@ -49,7 +49,7 @@ extern void wf_impl_operation_read( fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi); -extern struct wf_impl_jsonrpc_proxy * wf_impl_operations_context_get_proxy( +extern struct jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context); #ifdef __cplusplus diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 74d4631..746df5c 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -9,7 +9,7 @@ #include "webfuse/core/protocol_names.h" #include "webfuse/adapter/impl/credentials.h" -#include "webfuse/adapter/impl/jsonrpc/request.h" +#include "jsonrpc/request.h" #include "webfuse/adapter/impl/uuid_mountpoint_factory.h" static int wf_impl_server_protocol_callback( @@ -129,7 +129,7 @@ void wf_impl_server_protocol_init_lws( } static void wf_impl_server_protocol_authenticate( - struct wf_impl_jsonrpc_request * request, + struct jsonrpc_request * request, char const * WF_UNUSED_PARAM(method_name), json_t * params, void * WF_UNUSED_PARAM(user_data)) @@ -145,7 +145,7 @@ static void wf_impl_server_protocol_authenticate( struct wf_credentials creds; wf_impl_credentials_init(&creds, type, creds_holder); - struct wf_impl_session * session = wf_impl_jsonrpc_request_get_userdata(request); + struct wf_impl_session * session = jsonrpc_request_get_userdata(request); result = wf_impl_session_authenticate(session, &creds); wf_impl_credentials_cleanup(&creds); @@ -155,11 +155,11 @@ static void wf_impl_server_protocol_authenticate( if (result) { json_t * result = json_object(); - wf_impl_jsonrpc_respond(request, result); + jsonrpc_respond(request, result); } else { - wf_impl_jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED); + jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED); } } @@ -179,12 +179,12 @@ static bool wf_impl_server_protocol_check_name(char const * value) } static void wf_impl_server_protocol_add_filesystem( - struct wf_impl_jsonrpc_request * request, + struct jsonrpc_request * request, char const * WF_UNUSED_PARAM(method_name), json_t * params, void * WF_UNUSED_PARAM(user_data)) { - struct wf_impl_session * session = wf_impl_jsonrpc_request_get_userdata(request); + struct wf_impl_session * session = jsonrpc_request_get_userdata(request); wf_status status = (session->is_authenticated) ? WF_GOOD : WF_BAD_ACCESS_DENIED; char const * name = NULL; @@ -218,11 +218,11 @@ static void wf_impl_server_protocol_add_filesystem( { json_t * result = json_object(); json_object_set_new(result, "id", json_string(name)); - wf_impl_jsonrpc_respond(request, result); + jsonrpc_respond(request, result); } else { - wf_impl_jsonrpc_respond_error(request, status); + jsonrpc_respond_error(request, status); } @@ -240,9 +240,9 @@ void wf_impl_server_protocol_init( wf_impl_session_manager_init(&protocol->session_manager); wf_impl_authenticators_init(&protocol->authenticators); - wf_impl_jsonrpc_server_init(&protocol->server); - wf_impl_jsonrpc_server_add(&protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol); - wf_impl_jsonrpc_server_add(&protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol); + jsonrpc_server_init(&protocol->server); + jsonrpc_server_add(&protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol); + jsonrpc_server_add(&protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol); } void wf_impl_server_protocol_cleanup( @@ -250,7 +250,7 @@ void wf_impl_server_protocol_cleanup( { protocol->is_operational = false; - wf_impl_jsonrpc_server_cleanup(&protocol->server); + jsonrpc_server_cleanup(&protocol->server); wf_impl_timeout_manager_cleanup(&protocol->timeout_manager); wf_impl_authenticators_cleanup(&protocol->authenticators); wf_impl_session_manager_cleanup(&protocol->session_manager); diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 16da34d..85c94c1 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -1,12 +1,12 @@ #ifndef WF_ADAPTER_IMPL_SERVER_PROTOCOL_H #define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H -#include "webfuse/adapter/impl/jsonrpc/proxy.h" +#include "jsonrpc/proxy.h" #include "webfuse/adapter/impl/time/timeout_manager.h" #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/session_manager.h" -#include "webfuse/adapter/impl/jsonrpc/server.h" +#include "jsonrpc/server.h" #ifndef __cplusplus #include @@ -25,7 +25,7 @@ struct wf_server_protocol struct wf_impl_authenticators authenticators; struct wf_impl_mountpoint_factory mountpoint_factory; struct wf_impl_session_manager session_manager; - struct wf_impl_jsonrpc_server server; + struct jsonrpc_server server; bool is_operational; }; diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index fb2885a..5690c4f 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -2,9 +2,9 @@ #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/core/message_queue.h" #include "webfuse/core/message.h" -#include "webfuse/adapter/impl/jsonrpc/proxy.h" -#include "webfuse/adapter/impl/jsonrpc/request.h" -#include "webfuse/adapter/impl/jsonrpc/response.h" +#include "jsonrpc/proxy.h" +#include "jsonrpc/request.h" +#include "jsonrpc/response.h" #include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/mountpoint.h" @@ -24,7 +24,7 @@ static bool wf_impl_session_send( struct wf_impl_session * session = user_data; struct wf_message * message = wf_message_create(request); - bool result = (session->is_authenticated || wf_impl_jsonrpc_is_response(request)) && (NULL != session->wsi); + bool result = (session->is_authenticated || jsonrpc_is_response(request)) && (NULL != session->wsi); if (result) { @@ -45,7 +45,7 @@ struct wf_impl_session * wf_impl_session_create( struct lws * wsi, struct wf_impl_authenticators * authenticators, struct wf_impl_timeout_manager * timeout_manager, - struct wf_impl_jsonrpc_server * server, + struct jsonrpc_server * server, struct wf_impl_mountpoint_factory * mountpoint_factory) { @@ -59,7 +59,7 @@ struct wf_impl_session * wf_impl_session_create( session->authenticators = authenticators; session->server = server; session->mountpoint_factory = mountpoint_factory; - wf_impl_jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); + jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); wf_slist_init(&session->messages); } @@ -83,7 +83,7 @@ static void wf_impl_session_dispose_filesystems( void wf_impl_session_dispose( struct wf_impl_session * session) { - wf_impl_jsonrpc_proxy_cleanup(&session->rpc); + jsonrpc_proxy_cleanup(&session->rpc); wf_message_queue_cleanup(&session->messages); wf_impl_session_dispose_filesystems(&session->filesystems); @@ -159,13 +159,13 @@ void wf_impl_session_receive( json_t * message = json_loadb(data, length, 0, NULL); if (NULL != message) { - if (wf_impl_jsonrpc_is_response(message)) + if (jsonrpc_is_response(message)) { - wf_impl_jsonrpc_proxy_onresult(&session->rpc, message); + jsonrpc_proxy_onresult(&session->rpc, message); } - else if (wf_impl_jsonrpc_is_request(message)) + else if (jsonrpc_is_request(message)) { - wf_impl_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session); + jsonrpc_server_process(session->server, message, &wf_impl_session_send, session); } json_decref(message); diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h index 9f9b10a..90f8f4e 100644 --- a/lib/webfuse/adapter/impl/session.h +++ b/lib/webfuse/adapter/impl/session.h @@ -10,8 +10,8 @@ using std::size_t; #endif #include "webfuse/core/message_queue.h" -#include "webfuse/adapter/impl/jsonrpc/proxy.h" -#include "webfuse/adapter/impl/jsonrpc/server.h" +#include "jsonrpc/proxy.h" +#include "jsonrpc/server.h" #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/core/slist.h" @@ -35,8 +35,8 @@ struct wf_impl_session struct wf_slist messages; struct wf_impl_authenticators * authenticators; struct wf_impl_mountpoint_factory * mountpoint_factory; - struct wf_impl_jsonrpc_server * server; - struct wf_impl_jsonrpc_proxy rpc; + struct jsonrpc_server * server; + struct jsonrpc_proxy rpc; struct wf_slist filesystems; }; @@ -44,7 +44,7 @@ extern struct wf_impl_session * wf_impl_session_create( struct lws * wsi, struct wf_impl_authenticators * authenticators, struct wf_impl_timeout_manager * timeout_manager, - struct wf_impl_jsonrpc_server * server, + struct jsonrpc_server * server, struct wf_impl_mountpoint_factory * mountpoint_factory); extern void wf_impl_session_dispose( diff --git a/lib/webfuse/adapter/impl/session_manager.c b/lib/webfuse/adapter/impl/session_manager.c index 0574c98..e7e109d 100644 --- a/lib/webfuse/adapter/impl/session_manager.c +++ b/lib/webfuse/adapter/impl/session_manager.c @@ -29,7 +29,7 @@ struct wf_impl_session * wf_impl_session_manager_add( struct wf_impl_authenticators * authenticators, struct wf_impl_mountpoint_factory * mountpoint_factory, struct wf_impl_timeout_manager * timeout_manager, - struct wf_impl_jsonrpc_server * server) + struct jsonrpc_server * server) { struct wf_impl_session * session = wf_impl_session_create( wsi, authenticators, timeout_manager, server, mountpoint_factory); diff --git a/lib/webfuse/adapter/impl/session_manager.h b/lib/webfuse/adapter/impl/session_manager.h index 25b4367..51c8910 100644 --- a/lib/webfuse/adapter/impl/session_manager.h +++ b/lib/webfuse/adapter/impl/session_manager.h @@ -16,7 +16,7 @@ extern "C" struct lws; struct wf_impl_timeout_manager; -struct wf_impl_jsonrpc_server; +struct jsonrpc_server; struct wf_impl_session_manager { @@ -35,7 +35,7 @@ extern struct wf_impl_session * wf_impl_session_manager_add( struct wf_impl_authenticators * authenticators, struct wf_impl_mountpoint_factory * mountpoint_factory, struct wf_impl_timeout_manager * timeout_manager, - struct wf_impl_jsonrpc_server * server); + struct jsonrpc_server * server); extern struct wf_impl_session * wf_impl_session_manager_get( struct wf_impl_session_manager * manager, diff --git a/lib/webfuse/core/json_util.c b/lib/webfuse/core/json_util.c new file mode 100644 index 0000000..dfe95cd --- /dev/null +++ b/lib/webfuse/core/json_util.c @@ -0,0 +1,48 @@ +#include "webfuse/core/json_util.h" +#include "jsonrpc/status.h" + +int wf_impl_json_get_int(json_t const * object, char const * key, int default_value) +{ + int result = default_value; + + json_t * holder = json_object_get(object, key); + if ((NULL != holder) && (json_is_integer(holder))) + { + result = json_integer_value(holder); + } + + return result; +} + +static wf_status wf_impl_jsonrc_code_to_status(int code) +{ + switch (code) + { + case JSONRPC_GOOD: + return WF_GOOD; + case JSONRPC_BAD: + return WF_BAD; + case JSONRPC_BAD_BUSY: + return WF_BAD_BUSY; + case JSONRPC_BAD_TIMEOUT: + return WF_BAD_TIMEOUT; + case JSONRPC_BAD_FORMAT: + return WF_BAD_FORMAT; + default: + return (wf_status) code; + } +} + +wf_status +wf_impl_jsonrpc_get_status( + json_t const * error) +{ + wf_status status = WF_GOOD; + if (NULL != error) + { + int code = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT); + status = wf_impl_jsonrc_code_to_status(code); + } + + return status; +} diff --git a/lib/webfuse/core/json_util.h b/lib/webfuse/core/json_util.h new file mode 100644 index 0000000..db21ed1 --- /dev/null +++ b/lib/webfuse/core/json_util.h @@ -0,0 +1,26 @@ +#ifndef WF_JSON_UTIL_H +#define WF_JSON_UTIL_H + +#include +#include "webfuse/core/status.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern int +wf_impl_json_get_int( + json_t const * object, + char const * key, + int default_value); + +extern wf_status +wf_impl_jsonrpc_get_status( + json_t const * error); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/webfuse/tests/adapter/jsonrpc/test_is_request.cc b/test/jsonrpc/test_is_request.cc similarity index 81% rename from test/webfuse/tests/adapter/jsonrpc/test_is_request.cc rename to test/jsonrpc/test_is_request.cc index 5fef81e..03d95f7 100644 --- a/test/webfuse/tests/adapter/jsonrpc/test_is_request.cc +++ b/test/jsonrpc/test_is_request.cc @@ -1,5 +1,5 @@ #include -#include "webfuse/adapter/impl/jsonrpc/request.h" +#include "jsonrpc/request.h" TEST(jsonrpc_is_request, request_with_object_params) { @@ -8,7 +8,7 @@ TEST(jsonrpc_is_request, request_with_object_params) json_object_set_new(request, "params", json_object()); json_object_set_new(request, "id", json_integer(42)); - ASSERT_TRUE(wf_impl_jsonrpc_is_request(request)); + ASSERT_TRUE(jsonrpc_is_request(request)); json_decref(request); } @@ -20,14 +20,14 @@ TEST(jsonrpc_is_request, request_with_array_params) json_object_set_new(request, "params", json_array()); json_object_set_new(request, "id", json_integer(42)); - ASSERT_TRUE(wf_impl_jsonrpc_is_request(request)); + ASSERT_TRUE(jsonrpc_is_request(request)); json_decref(request); } TEST(jsonrpc_is_request, null_request) { - ASSERT_FALSE(wf_impl_jsonrpc_is_request(nullptr)); + ASSERT_FALSE(jsonrpc_is_request(nullptr)); } TEST(jsonrpc_is_request, invalid_request) @@ -37,7 +37,7 @@ TEST(jsonrpc_is_request, invalid_request) json_array_append_new(request, json_object()); json_array_append_new(request, json_integer(42)); - ASSERT_FALSE(wf_impl_jsonrpc_is_request(request)); + ASSERT_FALSE(jsonrpc_is_request(request)); json_decref(request); } @@ -48,7 +48,7 @@ TEST(jsonrpc_is_request, invalid_request_without_id) json_object_set_new(request, "method", json_string("method")); json_object_set_new(request, "params", json_object()); - ASSERT_FALSE(wf_impl_jsonrpc_is_request(request)); + ASSERT_FALSE(jsonrpc_is_request(request)); json_decref(request); } @@ -60,7 +60,7 @@ TEST(jsonrpc_is_request, invalid_request_due_to_invalid_id) json_object_set_new(request, "params", json_object()); json_object_set_new(request, "id", json_string("42")); - ASSERT_FALSE(wf_impl_jsonrpc_is_request(request)); + ASSERT_FALSE(jsonrpc_is_request(request)); json_decref(request); } @@ -71,7 +71,7 @@ TEST(jsonrpc_is_request, invalid_request_without_method) json_object_set_new(request, "params", json_object()); json_object_set_new(request, "id", json_integer(42)); - ASSERT_FALSE(wf_impl_jsonrpc_is_request(request)); + ASSERT_FALSE(jsonrpc_is_request(request)); json_decref(request); } @@ -83,7 +83,7 @@ TEST(jsonrpc_is_request, invalid_request_due_to_invalid_method) json_object_set_new(request, "params", json_object()); json_object_set_new(request, "id", json_integer(42)); - ASSERT_FALSE(wf_impl_jsonrpc_is_request(request)); + ASSERT_FALSE(jsonrpc_is_request(request)); json_decref(request); } @@ -94,7 +94,7 @@ TEST(jsonrpc_is_request, invalid_request_without_params) json_object_set_new(request, "method", json_string("method")); json_object_set_new(request, "id", json_integer(42)); - ASSERT_FALSE(wf_impl_jsonrpc_is_request(request)); + ASSERT_FALSE(jsonrpc_is_request(request)); json_decref(request); } @@ -106,7 +106,7 @@ TEST(jsonrpc_is_request, invalid_request_due_to_invalid_params) json_object_set_new(request, "params", json_string("params")); json_object_set_new(request, "id", json_integer(42)); - ASSERT_FALSE(wf_impl_jsonrpc_is_request(request)); + ASSERT_FALSE(jsonrpc_is_request(request)); json_decref(request); } diff --git a/test/webfuse/tests/adapter/jsonrpc/test_is_response.cc b/test/jsonrpc/test_is_response.cc similarity index 76% rename from test/webfuse/tests/adapter/jsonrpc/test_is_response.cc rename to test/jsonrpc/test_is_response.cc index 6182cd0..b32a284 100644 --- a/test/webfuse/tests/adapter/jsonrpc/test_is_response.cc +++ b/test/jsonrpc/test_is_response.cc @@ -1,5 +1,5 @@ #include -#include "webfuse/adapter/impl/jsonrpc/response.h" +#include "jsonrpc/response.h" TEST(jsonrpc_is_response, valid_result) { @@ -7,7 +7,7 @@ TEST(jsonrpc_is_response, valid_result) json_object_set_new(message, "result", json_object()); json_object_set_new(message, "id", json_integer(42)); - ASSERT_TRUE(wf_impl_jsonrpc_is_response(message)); + ASSERT_TRUE(jsonrpc_is_response(message)); json_decref(message); } @@ -18,7 +18,7 @@ TEST(jsonrpc_is_response, valid_result_string) json_object_set_new(message, "result", json_string("also valid")); json_object_set_new(message, "id", json_integer(42)); - ASSERT_TRUE(wf_impl_jsonrpc_is_response(message)); + ASSERT_TRUE(jsonrpc_is_response(message)); json_decref(message); } @@ -29,14 +29,14 @@ TEST(jsonrpc_is_response, valid_error) json_object_set_new(message, "error", json_object()); json_object_set_new(message, "id", json_integer(42)); - ASSERT_TRUE(wf_impl_jsonrpc_is_response(message)); + ASSERT_TRUE(jsonrpc_is_response(message)); json_decref(message); } TEST(jsonrpc_is_response, invalid_null) { - ASSERT_FALSE(wf_impl_jsonrpc_is_response(nullptr)); + ASSERT_FALSE(jsonrpc_is_response(nullptr)); } TEST(jsonrpc_is_response, invalid_message) @@ -45,7 +45,7 @@ TEST(jsonrpc_is_response, invalid_message) json_array_append_new(message, json_object()); json_array_append_new(message, json_integer(42)); - ASSERT_FALSE(wf_impl_jsonrpc_is_response(message)); + ASSERT_FALSE(jsonrpc_is_response(message)); json_decref(message); } @@ -55,7 +55,7 @@ TEST(jsonrpc_is_response, invalid_missing_id) json_t * message = json_object(); json_object_set_new(message, "result", json_object()); - ASSERT_FALSE(wf_impl_jsonrpc_is_response(message)); + ASSERT_FALSE(jsonrpc_is_response(message)); json_decref(message); } @@ -66,7 +66,7 @@ TEST(jsonrpc_is_response, invalid_id_wrong_type) json_object_set_new(message, "result", json_object()); json_object_set_new(message, "id", json_string("42")); - ASSERT_FALSE(wf_impl_jsonrpc_is_response(message)); + ASSERT_FALSE(jsonrpc_is_response(message)); json_decref(message); } @@ -77,7 +77,7 @@ TEST(jsonrpc_is_response, invalid_missing_result_and_error) json_t * message = json_object(); json_object_set_new(message, "id", json_integer(42)); - ASSERT_FALSE(wf_impl_jsonrpc_is_response(message)); + ASSERT_FALSE(jsonrpc_is_response(message)); json_decref(message); } @@ -88,7 +88,7 @@ TEST(jsonrpc_is_response, invalid_error_wrong_type) json_object_set_new(message, "error", json_array()); json_object_set_new(message, "id", json_integer(42)); - ASSERT_FALSE(wf_impl_jsonrpc_is_response(message)); + ASSERT_FALSE(jsonrpc_is_response(message)); json_decref(message); } diff --git a/test/webfuse/tests/adapter/jsonrpc/test_proxy.cc b/test/jsonrpc/test_proxy.cc similarity index 72% rename from test/webfuse/tests/adapter/jsonrpc/test_proxy.cc rename to test/jsonrpc/test_proxy.cc index 8f99312..79fb090 100644 --- a/test/webfuse/tests/adapter/jsonrpc/test_proxy.cc +++ b/test/jsonrpc/test_proxy.cc @@ -1,7 +1,8 @@ #include -#include "webfuse/adapter/impl/jsonrpc/proxy.h" +#include "jsonrpc/proxy.h" #include "webfuse/adapter/impl/time/timeout_manager.h" #include "webfuse/utils/msleep.hpp" +#include "webfuse/core/json_util.h" using webfuse_test::msleep; @@ -47,13 +48,13 @@ namespace struct FinishedContext { bool is_called; - wf_status status; json_t * result; + json_t * error; FinishedContext() : is_called(false) - , status(WF_BAD) , result(nullptr) + , error(nullptr) { } @@ -64,18 +65,23 @@ namespace { json_decref(result); } + + if (nullptr != error) + { + json_decref(error); + } } }; void jsonrpc_finished( void * user_data, - wf_status status, - struct json_t const * result) + json_t const * result, + json_t const * error) { FinishedContext * context = reinterpret_cast(user_data); context->is_called = true; - context->status = status; context->result = json_deep_copy(result); + context->error = json_deep_copy(error); } } @@ -86,10 +92,10 @@ TEST(jsonrpc_proxy, init) SendContext context; void * user_data = reinterpret_cast(&context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); ASSERT_FALSE(context.is_called); @@ -102,12 +108,12 @@ TEST(jsonrpc_proxy, invoke) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -129,11 +135,11 @@ TEST(jsonrpc_proxy, invoke) ASSERT_FALSE(finished_context.is_called); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); ASSERT_TRUE(finished_context.is_called); - ASSERT_FALSE(WF_GOOD == finished_context.status); + ASSERT_FALSE(nullptr == finished_context.error); } TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails) @@ -143,20 +149,20 @@ TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails) SendContext send_context(false); void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); ASSERT_TRUE(finished_context.is_called); - ASSERT_FALSE(WF_GOOD == finished_context.status); + ASSERT_FALSE(nullptr == finished_context.error); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -167,16 +173,16 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); FinishedContext finished_context2; void * finished_data2 = reinterpret_cast(&finished_context2); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data2, "foo", ""); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data2, "foo", ""); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -184,9 +190,9 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending) ASSERT_FALSE(finished_context.is_called); ASSERT_TRUE(finished_context2.is_called); - ASSERT_EQ(WF_BAD_BUSY, finished_context2.status); + ASSERT_EQ(WF_BAD_BUSY, wf_impl_jsonrpc_get_status(finished_context2.error)); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -197,19 +203,19 @@ TEST(jsonrpc_proxy, invoke_fails_if_request_is_invalid) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "?", "error"); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "?", "error"); ASSERT_FALSE(send_context.is_called); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_BAD, finished_context.status); + ASSERT_EQ(WF_BAD, wf_impl_jsonrpc_get_status(finished_context.error)); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -220,12 +226,12 @@ TEST(jsonrpc_proxy, on_result) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -237,15 +243,15 @@ TEST(jsonrpc_proxy, on_result) json_object_set_new(response, "result", json_string("okay")); json_object_set(response, "id", id); - wf_impl_jsonrpc_proxy_onresult(&proxy, response); + jsonrpc_proxy_onresult(&proxy, response); json_decref(response); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_GOOD, finished_context.status); + ASSERT_EQ(nullptr, finished_context.error); ASSERT_TRUE(json_is_string(finished_context.result)); ASSERT_STREQ("okay", json_string_value(finished_context.result)); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -256,12 +262,12 @@ TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -273,12 +279,12 @@ TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id) json_object_set_new(response, "result", json_string("okay")); json_object_set_new(response, "id", json_integer(1 + json_integer_value(id))); - wf_impl_jsonrpc_proxy_onresult(&proxy, response); + jsonrpc_proxy_onresult(&proxy, response); json_decref(response); ASSERT_FALSE(finished_context.is_called); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -289,12 +295,12 @@ TEST(jsonrpc_proxy, timeout) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, 0, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, 0, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -303,9 +309,9 @@ TEST(jsonrpc_proxy, timeout) wf_impl_timeout_manager_check(&timeout_manager); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_BAD_TIMEOUT, finished_context.status); + ASSERT_EQ(WF_BAD_TIMEOUT, wf_impl_jsonrpc_get_status(finished_context.error)); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -316,12 +322,12 @@ TEST(jsonrpc_proxy, cleanup_pending_request) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, 10, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, 10, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -329,7 +335,7 @@ TEST(jsonrpc_proxy, cleanup_pending_request) ASSERT_FALSE(finished_context.is_called); ASSERT_NE(nullptr, timeout_manager.timers); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); ASSERT_TRUE(finished_context.is_called); ASSERT_EQ(nullptr, timeout_manager.timers); @@ -346,10 +352,10 @@ TEST(jsonrpc_proxy, notify) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); - wf_impl_jsonrpc_proxy_notify(&proxy, "foo", "si", "bar", 42); + jsonrpc_proxy_notify(&proxy, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -370,7 +376,7 @@ TEST(jsonrpc_proxy, notify) ASSERT_EQ(nullptr, id); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -381,13 +387,13 @@ TEST(jsonrpc_proxy, notify_dont_send_invalid_request) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct wf_impl_jsonrpc_proxy proxy; - wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy proxy; + jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); - wf_impl_jsonrpc_proxy_notify(&proxy, "foo", "?"); + jsonrpc_proxy_notify(&proxy, "foo", "?"); ASSERT_FALSE(send_context.is_called); - wf_impl_jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_cleanup(&proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } diff --git a/test/webfuse/tests/adapter/jsonrpc/test_request.cc b/test/jsonrpc/test_request.cc similarity index 75% rename from test/webfuse/tests/adapter/jsonrpc/test_request.cc rename to test/jsonrpc/test_request.cc index 07c3da8..94f87ee 100644 --- a/test/webfuse/tests/adapter/jsonrpc/test_request.cc +++ b/test/jsonrpc/test_request.cc @@ -1,5 +1,5 @@ #include -#include "webfuse/adapter/impl/jsonrpc/request.h" +#include "jsonrpc/request.h" namespace { @@ -27,13 +27,13 @@ TEST(jsonrpc_request, create_dispose) Context context{nullptr}; void * user_data = reinterpret_cast(&context); - struct wf_impl_jsonrpc_request * request = - wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data); + struct jsonrpc_request * request = + jsonrpc_request_create(42, &jsonrpc_send, user_data); ASSERT_NE(nullptr, request); - ASSERT_EQ(user_data, wf_impl_jsonrpc_request_get_userdata(request)); + ASSERT_EQ(user_data, jsonrpc_request_get_userdata(request)); - wf_impl_jsonrpc_request_dispose(request); + jsonrpc_request_dispose(request); } TEST(jsonrpc_request, respond) @@ -41,10 +41,10 @@ TEST(jsonrpc_request, respond) Context context{nullptr}; void * user_data = reinterpret_cast(&context); - struct wf_impl_jsonrpc_request * request = - wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data); + struct jsonrpc_request * request = + jsonrpc_request_create(42, &jsonrpc_send, user_data); - wf_impl_jsonrpc_respond(request, json_string("okay")); + jsonrpc_respond(request, json_string("okay")); ASSERT_NE(nullptr, context.response); @@ -70,10 +70,10 @@ TEST(jsonrpc_request, respond_error) Context context{nullptr}; void * user_data = reinterpret_cast(&context); - struct wf_impl_jsonrpc_request * request = - wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data); + struct jsonrpc_request * request = + jsonrpc_request_create(42, &jsonrpc_send, user_data); - wf_impl_jsonrpc_respond_error(request, WF_BAD); + jsonrpc_respond_error(request, WF_BAD); ASSERT_NE(nullptr, context.response); diff --git a/test/webfuse/tests/adapter/jsonrpc/test_response.cc b/test/jsonrpc/test_response.cc similarity index 59% rename from test/webfuse/tests/adapter/jsonrpc/test_response.cc rename to test/jsonrpc/test_response.cc index 3a63d0f..1745bdb 100644 --- a/test/webfuse/tests/adapter/jsonrpc/test_response.cc +++ b/test/jsonrpc/test_response.cc @@ -1,5 +1,7 @@ #include -#include "webfuse/adapter/impl/jsonrpc/response.h" +#include "jsonrpc/response.h" +#include "webfuse/core/status.h" +#include "webfuse/core/json_util.h" TEST(json_response, init_result) { @@ -7,15 +9,15 @@ TEST(json_response, init_result) json_object_set_new(message, "result", json_integer(47)); json_object_set_new(message, "id", json_integer(11)); - struct wf_impl_jsonrpc_response response; - wf_impl_jsonrpc_response_init(&response, message); + struct jsonrpc_response response; + jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_GOOD, response.status); + 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_impl_jsonrpc_response_cleanup(&response); + jsonrpc_response_cleanup(&response); json_decref(message); } @@ -28,14 +30,14 @@ TEST(json_response, init_error) json_object_set_new(message, "error", err); json_object_set_new(message, "id", json_integer(23)); - struct wf_impl_jsonrpc_response response; - wf_impl_jsonrpc_response_init(&response, message); + struct jsonrpc_response response; + jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_BAD_ACCESS_DENIED, response.status); + ASSERT_EQ(WF_BAD_ACCESS_DENIED, wf_impl_jsonrpc_get_status(response.error)) << json_string_value(json_object_get(response.error, "message")); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_impl_jsonrpc_response_cleanup(&response); + jsonrpc_response_cleanup(&response); json_decref(message); } @@ -44,13 +46,13 @@ TEST(json_response, init_format_error) json_t * message = json_object(); json_object_set_new(message, "id", json_integer(12)); - struct wf_impl_jsonrpc_response response; - wf_impl_jsonrpc_response_init(&response, message); + struct jsonrpc_response response; + jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_BAD_FORMAT, response.status); + ASSERT_EQ(WF_BAD_FORMAT, wf_impl_jsonrpc_get_status(response.error)); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(12, response.id); - wf_impl_jsonrpc_response_cleanup(&response); + jsonrpc_response_cleanup(&response); json_decref(message); } diff --git a/test/webfuse/tests/adapter/jsonrpc/test_server.cc b/test/jsonrpc/test_server.cc similarity index 75% rename from test/webfuse/tests/adapter/jsonrpc/test_server.cc rename to test/jsonrpc/test_server.cc index 20d5d0f..4e0b2bc 100644 --- a/test/webfuse/tests/adapter/jsonrpc/test_server.cc +++ b/test/jsonrpc/test_server.cc @@ -1,6 +1,6 @@ #include -#include "webfuse/adapter/impl/jsonrpc/server.h" -#include "webfuse/adapter/impl/jsonrpc/request.h" +#include "jsonrpc/server.h" +#include "jsonrpc/request.h" namespace { @@ -23,7 +23,7 @@ namespace } void sayHello( - struct wf_impl_jsonrpc_request * request, + struct jsonrpc_request * request, char const * method_name, json_t * params, void * user_data) @@ -33,16 +33,16 @@ namespace (void) user_data; json_t * result = json_string("Hello"); - wf_impl_jsonrpc_respond(request, result); + jsonrpc_respond(request, result); } } TEST(jsonrpc_server, process_request) { - struct wf_impl_jsonrpc_server server; - wf_impl_jsonrpc_server_init(&server); - wf_impl_jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr); + struct jsonrpc_server server; + jsonrpc_server_init(&server); + jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr); Context context{nullptr, false}; void * user_data = reinterpret_cast(&context); @@ -50,7 +50,7 @@ TEST(jsonrpc_server, process_request) 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_impl_jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); + jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); ASSERT_TRUE(context.is_called); ASSERT_NE(nullptr, context.response); @@ -66,14 +66,14 @@ TEST(jsonrpc_server, process_request) json_decref(context.response); json_decref(request); - wf_impl_jsonrpc_server_cleanup(&server); + jsonrpc_server_cleanup(&server); } TEST(jsonrpc_server, invoke_unknown_method) { - struct wf_impl_jsonrpc_server server; - wf_impl_jsonrpc_server_init(&server); - wf_impl_jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr); + struct jsonrpc_server server; + jsonrpc_server_init(&server); + jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr); Context context{nullptr, false}; void * user_data = reinterpret_cast(&context); @@ -81,7 +81,7 @@ TEST(jsonrpc_server, invoke_unknown_method) 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_impl_jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); + jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); ASSERT_TRUE(context.is_called); ASSERT_NE(nullptr, context.response); @@ -103,23 +103,23 @@ TEST(jsonrpc_server, invoke_unknown_method) json_decref(context.response); json_decref(request); - wf_impl_jsonrpc_server_cleanup(&server); + jsonrpc_server_cleanup(&server); } TEST(jsonrpc_server, skip_invalid_request) { - struct wf_impl_jsonrpc_server server; - wf_impl_jsonrpc_server_init(&server); + struct jsonrpc_server server; + jsonrpc_server_init(&server); Context context{nullptr, false}; void * user_data = reinterpret_cast(&context); json_t * request = json_object(); json_object_set_new(request, "method", json_string("sayHello")); json_object_set_new(request, "params", json_array()); - wf_impl_jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); + jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); ASSERT_FALSE(context.is_called); json_decref(request); - wf_impl_jsonrpc_server_cleanup(&server); + jsonrpc_server_cleanup(&server); } diff --git a/test/webfuse/tests/adapter/jsonrpc/test_util.cc b/test/jsonrpc/test_util.cc similarity index 95% rename from test/webfuse/tests/adapter/jsonrpc/test_util.cc rename to test/jsonrpc/test_util.cc index 562b7c4..3e4b75d 100644 --- a/test/webfuse/tests/adapter/jsonrpc/test_util.cc +++ b/test/jsonrpc/test_util.cc @@ -1,5 +1,5 @@ #include -#include "webfuse/adapter/impl/jsonrpc/util.h" +#include "webfuse/core/json_util.h" TEST(jsonrpc_util, get_int) { diff --git a/test/webfuse/mocks/mock_provider_client.cc b/test/webfuse/mocks/mock_provider_client.cc index a624ba3..ff73bd9 100644 --- a/test/webfuse/mocks/mock_provider_client.cc +++ b/test/webfuse/mocks/mock_provider_client.cc @@ -167,6 +167,22 @@ static void webfuse_test_iproviderclient_onread( delete[] data; } +static void webfuse_test_iproviderclient_get_credentials( + wfp_credentials * credentials, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + + try + { + self->GetCredentials(credentials); + } + catch (...) + { + // swallow + } +} + } namespace webfuse_test @@ -185,7 +201,7 @@ wf_status ProviderClientException::GetErrorCode() } -void IProviderClient::AttachTo(wfp_client_config * config) +void IProviderClient::AttachTo(wfp_client_config * config, bool enableAuthentication) { void * self = reinterpret_cast(this); wfp_client_config_set_userdata(config, self); @@ -199,6 +215,11 @@ void IProviderClient::AttachTo(wfp_client_config * config) wfp_client_config_set_onopen(config, &webfuse_test_iproviderclient_onopen); wfp_client_config_set_onclose(config, &webfuse_test_iproviderclient_onclose); wfp_client_config_set_onread(config, &webfuse_test_iproviderclient_onread); + + if (enableAuthentication) + { + wfp_client_config_enable_authentication(config, &webfuse_test_iproviderclient_get_credentials); + } } } \ No newline at end of file diff --git a/test/webfuse/mocks/mock_provider_client.hpp b/test/webfuse/mocks/mock_provider_client.hpp index 45fdf91..57db042 100644 --- a/test/webfuse/mocks/mock_provider_client.hpp +++ b/test/webfuse/mocks/mock_provider_client.hpp @@ -16,8 +16,6 @@ namespace webfuse_test private: wf_status error_code_; }; - - class IProviderClient { @@ -32,8 +30,9 @@ namespace webfuse_test virtual void Open(ino_t inode, int flags, uint32_t * handle) = 0; virtual void Close(ino_t inode, uint32_t handle, int flags) = 0; virtual void Read(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read) = 0; + virtual void GetCredentials(wfp_credentials * credentials) = 0; - void AttachTo(wfp_client_config * config); + void AttachTo(wfp_client_config * config, bool enableAuthentication = false); }; class MockProviderClient: public IProviderClient @@ -49,6 +48,7 @@ namespace webfuse_test MOCK_METHOD3( Open, void(ino_t inode, int flags, uint32_t * handle)); MOCK_METHOD3( Close, void(ino_t inode, uint32_t handle, int flags)); MOCK_METHOD6( Read, void(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read)); + MOCK_METHOD1( GetCredentials, void (wfp_credentials * credentials)); }; } diff --git a/test/webfuse/tests/adapter/test_response_parser.cc b/test/webfuse/tests/adapter/test_response_parser.cc index db7fe2f..0973e9c 100644 --- a/test/webfuse/tests/adapter/test_response_parser.cc +++ b/test/webfuse/tests/adapter/test_response_parser.cc @@ -1,54 +1,59 @@ #include #include -#include "webfuse/adapter/impl/jsonrpc/response.h" +#include "jsonrpc/response.h" +#include "webfuse/core/json_util.h" static void response_parse_str( std::string const & buffer, - struct wf_impl_jsonrpc_response * response) + struct jsonrpc_response * response) { json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr); if (nullptr != message) { - wf_impl_jsonrpc_response_init(response, message); + jsonrpc_response_init(response, message); json_decref(message); } } TEST(response_parser, test) { - struct wf_impl_jsonrpc_response response; + struct jsonrpc_response response; // no object response_parse_str("[]", &response); - ASSERT_NE(WF_GOOD, response.status); + ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); + jsonrpc_response_cleanup(&response); // empty response_parse_str("{}", &response); - ASSERT_NE(WF_GOOD, response.status); + ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); + jsonrpc_response_cleanup(&response); // no data response_parse_str("{\"id\":42}", &response); - ASSERT_NE(WF_GOOD, response.status); + ASSERT_NE(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); + jsonrpc_response_cleanup(&response); // custom error code response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); - ASSERT_NE(WF_GOOD, response.status); - ASSERT_EQ(42, response.status); + ASSERT_NE(nullptr, response.error); + ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); + jsonrpc_response_cleanup(&response); // valid response response_parse_str("{\"result\": true, \"id\": 42}", &response); - ASSERT_EQ(WF_GOOD, response.status); + ASSERT_EQ(WF_GOOD, response.error); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); - json_decref(response.result); + jsonrpc_response_cleanup(&response); } diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index b9d6252..53529c7 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -15,6 +15,7 @@ using webfuse_test::MockProviderClient; using webfuse_test::IProviderClient; using testing::_; using testing::AtMost; +using testing::Invoke; namespace { @@ -24,10 +25,10 @@ class ClientProtocolFixture ClientProtocolFixture(ClientProtocolFixture const &) = delete; ClientProtocolFixture& operator=(ClientProtocolFixture const &) = delete; public: - explicit ClientProtocolFixture(IProviderClient& client) + explicit ClientProtocolFixture(IProviderClient& client, bool enableAuthentication = false) { config = wfp_client_config_create(); - client.AttachTo(config); + client.AttachTo(config, enableAuthentication); protocol = wfp_client_protocol_create(config); @@ -140,6 +141,13 @@ private: wfp_client_protocol * protocol; }; +void GetCredentials(wfp_credentials * credentials) +{ + wfp_credentials_set_type(credentials, "username"); + wfp_credentials_add(credentials, "username", "bob"); + wfp_credentials_add(credentials, "password", "secret"); +} + } TEST(client_protocol, connect) @@ -161,11 +169,11 @@ TEST(client_protocol, connect) TEST(client_protocol, connect_with_username_authentication) { MockProviderClient provider; - ClientProtocolFixture fixture(provider); - // ToDo: enable authentication + ClientProtocolFixture fixture(provider, true); EXPECT_CALL(provider, OnConnected()).Times(AtMost(1)); EXPECT_CALL(provider, OnDisconnected()).Times(1); + EXPECT_CALL(provider, GetCredentials(_)).WillOnce(Invoke(GetCredentials)).Times(1); fixture.Connect(); if (HasFatalFailure()) { return; } From 69a1faaa3fdbb8d87cf5f80f6ff21fca27ed3487 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 29 Feb 2020 02:32:03 +0100 Subject: [PATCH 065/138] chore: cleanup jsonrpc library --- CMakeLists.txt | 2 +- cmake/jsonrpc.cmake | 13 +- cmake/unit_tests.cmake | 2 +- include/jsonrpc.h | 14 ++ include/jsonrpc/api.h | 8 + include/jsonrpc/method_invoke_fn.h | 26 ++++ include/jsonrpc/proxy.h | 41 ++--- include/jsonrpc/proxy_finished_fn.h | 20 +++ include/jsonrpc/request.h | 17 ++- include/jsonrpc/response.h | 29 +--- include/jsonrpc/send_fn.h | 1 + include/jsonrpc/server.h | 23 ++- include/jsonrpc/status.h | 1 + lib/jsonrpc/api.c | 144 ++++++++++++++++++ lib/jsonrpc/{ => impl}/error.c | 8 +- lib/jsonrpc/{ => impl}/error.h | 10 +- lib/jsonrpc/{ => impl}/method.c | 6 +- .../jsonrpc => lib/jsonrpc/impl}/method.h | 20 +-- lib/jsonrpc/{ => impl}/proxy.c | 72 +++++---- lib/jsonrpc/impl/proxy.h | 84 ++++++++++ lib/jsonrpc/{ => impl}/request.c | 34 +++-- lib/jsonrpc/impl/request.h | 53 +++++++ lib/jsonrpc/{ => impl}/response.c | 17 ++- lib/jsonrpc/impl/response.h | 40 +++++ lib/jsonrpc/impl/server.c | 132 ++++++++++++++++ lib/jsonrpc/impl/server.h | 41 +++++ lib/jsonrpc/impl/unused_param.h | 10 ++ lib/jsonrpc/server.c | 95 ------------ lib/webfuse/adapter/impl/operations.c | 2 +- lib/webfuse/adapter/impl/server_protocol.c | 15 +- lib/webfuse/adapter/impl/server_protocol.h | 2 +- lib/webfuse/adapter/impl/session.c | 11 +- lib/webfuse/adapter/impl/session.h | 2 +- test/jsonrpc/test_proxy.cc | 81 +++++----- test/jsonrpc/test_request.cc | 5 +- test/jsonrpc/test_response.cc | 14 +- .../test_response_parser.cc | 14 +- test/jsonrpc/test_server.cc | 28 ++-- 38 files changed, 792 insertions(+), 345 deletions(-) create mode 100644 include/jsonrpc.h create mode 100644 include/jsonrpc/api.h create mode 100644 include/jsonrpc/method_invoke_fn.h create mode 100644 include/jsonrpc/proxy_finished_fn.h create mode 100644 lib/jsonrpc/api.c rename lib/jsonrpc/{ => impl}/error.c (75%) rename lib/jsonrpc/{ => impl}/error.h (65%) rename lib/jsonrpc/{ => impl}/method.c (80%) rename {include/jsonrpc => lib/jsonrpc/impl}/method.h (50%) rename lib/jsonrpc/{ => impl}/proxy.c (71%) create mode 100644 lib/jsonrpc/impl/proxy.h rename lib/jsonrpc/{ => impl}/request.c (70%) create mode 100644 lib/jsonrpc/impl/request.h rename lib/jsonrpc/{ => impl}/response.c (76%) create mode 100644 lib/jsonrpc/impl/response.h create mode 100644 lib/jsonrpc/impl/server.c create mode 100644 lib/jsonrpc/impl/server.h create mode 100644 lib/jsonrpc/impl/unused_param.h delete mode 100644 lib/jsonrpc/server.c rename test/{webfuse/tests/adapter => jsonrpc}/test_response_parser.cc (81%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbdf5f2..6e87f52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ set(CMAKE_C_STANDARD 99) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(C_WARNINGS -Wall -Wextra) +set(C_WARNINGS -Wall -Wextra -Werror) set(CMAKE_POSITION_INDEPENDENT_CODE ON) include_directories( diff --git a/cmake/jsonrpc.cmake b/cmake/jsonrpc.cmake index 40be948..fb417bb 100644 --- a/cmake/jsonrpc.cmake +++ b/cmake/jsonrpc.cmake @@ -1,12 +1,13 @@ # jsonrpc add_library(jsonrpc STATIC - lib/jsonrpc/proxy.c - lib/jsonrpc/server.c - lib/jsonrpc/method.c - lib/jsonrpc/request.c - lib/jsonrpc/response.c - lib/jsonrpc/error.c + lib/jsonrpc/api.c + lib/jsonrpc/impl/proxy.c + lib/jsonrpc/impl/server.c + lib/jsonrpc/impl/method.c + lib/jsonrpc/impl/request.c + lib/jsonrpc/impl/response.c + lib/jsonrpc/impl/error.c ) target_include_directories(jsonrpc PUBLIC lib) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 43c6a4f..37ef85f 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -14,6 +14,7 @@ add_executable(alltests test/jsonrpc/test_response.cc test/jsonrpc/test_server.cc test/jsonrpc/test_proxy.cc + test/jsonrpc/test_response_parser.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc test/webfuse/utils/msleep.cc @@ -32,7 +33,6 @@ add_executable(alltests test/webfuse/tests/core/test_status.cc test/webfuse/tests/core/test_message.cc test/webfuse/tests/core/test_message_queue.cc - test/webfuse/tests/adapter/test_response_parser.cc test/webfuse/tests/adapter/test_server.cc test/webfuse/tests/adapter/test_server_config.cc test/webfuse/tests/adapter/test_timepoint.cc diff --git a/include/jsonrpc.h b/include/jsonrpc.h new file mode 100644 index 0000000..b0e2999 --- /dev/null +++ b/include/jsonrpc.h @@ -0,0 +1,14 @@ +#ifndef JSONRPC_H +#define JSONRPC_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/jsonrpc/api.h b/include/jsonrpc/api.h new file mode 100644 index 0000000..41b8563 --- /dev/null +++ b/include/jsonrpc/api.h @@ -0,0 +1,8 @@ +#ifndef JSONRPC_API_H +#define JSONRPC_API_H + +#ifndef JSONRPC_API +#define JSONRPC_API +#endif + +#endif diff --git a/include/jsonrpc/method_invoke_fn.h b/include/jsonrpc/method_invoke_fn.h new file mode 100644 index 0000000..96fecea --- /dev/null +++ b/include/jsonrpc/method_invoke_fn.h @@ -0,0 +1,26 @@ +#ifndef JSONRPC_METHOD_INVOKE_FN_H +#define JSONRPC_METHOD_INVOKE_FN_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct jsonrpc_request; + +typedef void jsonrpc_method_invoke_fn( + struct jsonrpc_request * request, + char const * method_name, + json_t * params, + void * user_data); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/jsonrpc/proxy.h b/include/jsonrpc/proxy.h index eb44991..d433253 100644 --- a/include/jsonrpc/proxy.h +++ b/include/jsonrpc/proxy.h @@ -12,7 +12,10 @@ using std::size_t; #endif #include -#include "jsonrpc/send_fn.h" +#include +#include +#include + #include "webfuse/adapter/impl/time/timeout_manager.h" #include "webfuse/adapter/impl/time/timer.h" @@ -20,40 +23,20 @@ using std::size_t; extern "C" { #endif -typedef void jsonrpc_proxy_finished_fn( - void * user_data, - json_t const * result, - json_t const * error); +struct jsonrpc_proxy; - -struct jsonrpc_request -{ - bool is_pending; - jsonrpc_proxy_finished_fn * finished; - void * user_data; - int id; - struct wf_impl_timer timer; -}; - -struct jsonrpc_proxy -{ - struct jsonrpc_request request; - int timeout; - jsonrpc_send_fn * send; - void * user_data; -}; - -extern void jsonrpc_proxy_init( - struct jsonrpc_proxy * proxy, +extern JSONRPC_API struct jsonrpc_proxy * +jsonrpc_proxy_create( struct wf_impl_timeout_manager * manager, int timeout, jsonrpc_send_fn * send, void * user_data); -extern void jsonrpc_proxy_cleanup( +extern JSONRPC_API void jsonrpc_proxy_dispose( struct jsonrpc_proxy * proxy); -extern void jsonrpc_proxy_invoke( + +extern JSONRPC_API void jsonrpc_proxy_invoke( struct jsonrpc_proxy * proxy, jsonrpc_proxy_finished_fn * finished, void * user_data, @@ -62,14 +45,14 @@ extern void jsonrpc_proxy_invoke( ... ); -extern void jsonrpc_proxy_notify( +extern JSONRPC_API void jsonrpc_proxy_notify( struct jsonrpc_proxy * proxy, char const * method_name, char const * param_info, ... ); -extern void jsonrpc_proxy_onresult( +extern JSONRPC_API void jsonrpc_proxy_onresult( struct jsonrpc_proxy * proxy, json_t * message); diff --git a/include/jsonrpc/proxy_finished_fn.h b/include/jsonrpc/proxy_finished_fn.h new file mode 100644 index 0000000..4c96b2b --- /dev/null +++ b/include/jsonrpc/proxy_finished_fn.h @@ -0,0 +1,20 @@ +#ifndef JSONRPC_PROXY_FINISHED_FN_H +#define JSONRPC_PROXY_FINISHED_FN_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef void jsonrpc_proxy_finished_fn( + void * user_data, + json_t const * result, + json_t const * error); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/jsonrpc/request.h b/include/jsonrpc/request.h index 496a4e0..8c5cbae 100644 --- a/include/jsonrpc/request.h +++ b/include/jsonrpc/request.h @@ -12,7 +12,7 @@ using std::size_t; #endif #include -#include "webfuse/core/status.h" +#include #include "jsonrpc/send_fn.h" #ifdef __cplusplus @@ -22,27 +22,28 @@ extern "C" struct jsonrpc_request; -extern bool jsonrpc_is_request( +extern JSONRPC_API bool jsonrpc_is_request( json_t * message); -extern struct jsonrpc_request * jsonrpc_request_create( +extern JSONRPC_API struct jsonrpc_request * jsonrpc_request_create( int id, jsonrpc_send_fn * send, void * user_data); -extern void jsonrpc_request_dispose( +extern JSONRPC_API void jsonrpc_request_dispose( struct jsonrpc_request * request); -extern void * jsonrpc_request_get_userdata( +extern JSONRPC_API void * jsonrpc_request_get_userdata( struct jsonrpc_request * request); -extern void jsonrpc_respond( +extern JSONRPC_API void jsonrpc_respond( struct jsonrpc_request * request, json_t * result); -extern void jsonrpc_respond_error( +extern JSONRPC_API void jsonrpc_respond_error( struct jsonrpc_request * request, - wf_status status); + int code, + char const * message); #ifdef __cplusplus diff --git a/include/jsonrpc/response.h b/include/jsonrpc/response.h index fbdaa7e..64414ec 100644 --- a/include/jsonrpc/response.h +++ b/include/jsonrpc/response.h @@ -1,40 +1,23 @@ -#ifndef WF_JSONRPC_RESPONSE_H -#define WF_JSONRPC_RESPONSE_H +#ifndef JSONRPC_RESPONSE_H +#define JSONRPC_RESPONSE_H #ifndef __cplusplus #include -#include -#else -#include -using std::size_t; #endif #include +#include #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -struct jsonrpc_response -{ - json_t * result; - json_t * error; - int id; -}; - -extern bool jsonrpc_is_response( +extern JSONRPC_API bool jsonrpc_is_response( json_t * message); -extern void jsonrpc_response_init( - struct jsonrpc_response * response, - json_t * message); - -extern void jsonrpc_response_cleanup( - struct jsonrpc_response * response); - #ifdef __cplusplus } #endif #endif - diff --git a/include/jsonrpc/send_fn.h b/include/jsonrpc/send_fn.h index b25bdbb..fe866af 100644 --- a/include/jsonrpc/send_fn.h +++ b/include/jsonrpc/send_fn.h @@ -6,6 +6,7 @@ #endif #include +#include #ifdef __cplusplus extern "C" diff --git a/include/jsonrpc/server.h b/include/jsonrpc/server.h index 778a7e2..7c215ec 100644 --- a/include/jsonrpc/server.h +++ b/include/jsonrpc/server.h @@ -9,32 +9,31 @@ #endif #include -#include "jsonrpc/send_fn.h" -#include "jsonrpc/method.h" +#include +#include +#include #ifdef __cplusplus extern "C" { #endif -struct jsonrpc_server -{ - struct jsonrpc_method * methods; -}; +struct jsonrpc_server; -extern void jsonrpc_server_init( +extern JSONRPC_API struct jsonrpc_server * +jsonrpc_server_create(void); + +extern JSONRPC_API void +jsonrpc_server_dispose( struct jsonrpc_server * server); -extern void jsonrpc_server_cleanup( - struct jsonrpc_server * server); - -extern void jsonrpc_server_add( +extern JSONRPC_API void jsonrpc_server_add( struct jsonrpc_server * server, char const * method_name, jsonrpc_method_invoke_fn * invoke, void * user_data); -extern void jsonrpc_server_process( +extern JSONRPC_API void jsonrpc_server_process( struct jsonrpc_server * server, json_t * request, jsonrpc_send_fn * send, diff --git a/include/jsonrpc/status.h b/include/jsonrpc/status.h index b7368b3..905a161 100644 --- a/include/jsonrpc/status.h +++ b/include/jsonrpc/status.h @@ -3,6 +3,7 @@ #define JSONRPC_GOOD 0 #define JSONRPC_BAD -1 +#define JSONRPC_BAD_NOTIMPLEMENTED -2 #define JSONRPC_BAD_TIMEOUT -3 #define JSONRPC_BAD_BUSY -4 #define JSONRPC_BAD_FORMAT -5 diff --git a/lib/jsonrpc/api.c b/lib/jsonrpc/api.c new file mode 100644 index 0000000..a6d7d1c --- /dev/null +++ b/lib/jsonrpc/api.c @@ -0,0 +1,144 @@ +#include "jsonrpc.h" + +#include "jsonrpc/impl/proxy.h" +#include "jsonrpc/impl/request.h" +#include "jsonrpc/impl/response.h" +#include "jsonrpc/impl/server.h" + +// proxy + +struct jsonrpc_proxy * +jsonrpc_proxy_create( + struct wf_impl_timeout_manager * manager, + int timeout, + jsonrpc_send_fn * send, + void * user_data) +{ + return jsonrpc_impl_proxy_create(manager, timeout, send, user_data); +} + +void jsonrpc_proxy_dispose( + struct jsonrpc_proxy * proxy) +{ + jsonrpc_impl_proxy_dispose(proxy); +} + +void jsonrpc_proxy_invoke( + struct jsonrpc_proxy * proxy, + jsonrpc_proxy_finished_fn * finished, + void * user_data, + char const * method_name, + char const * param_info, + ... +) +{ + va_list args; + va_start(args, param_info); + jsonrpc_impl_proxy_invoke(proxy, finished, user_data, method_name, param_info, args); + va_end(args); +} + +void jsonrpc_proxy_notify( + struct jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + ... +) +{ + va_list args; + va_start(args, param_info); + jsonrpc_impl_proxy_notify(proxy, method_name, param_info, args); + va_end(args); +} + +void jsonrpc_proxy_onresult( + struct jsonrpc_proxy * proxy, + json_t * message) +{ + jsonrpc_impl_proxy_onresult(proxy, message); +} + + +// request + +bool jsonrpc_is_request( + json_t * message) +{ + return jsonrpc_impl_is_request(message); +} + +struct jsonrpc_request * jsonrpc_request_create( + int id, + jsonrpc_send_fn * send, + void * user_data) +{ + return jsonrpc_impl_request_create(id, send, user_data); +} + +void jsonrpc_request_dispose( + struct jsonrpc_request * request) +{ + jsonrpc_impl_request_dispose(request); +} + +void * jsonrpc_request_get_userdata( + struct jsonrpc_request * request) +{ + return jsonrpc_impl_request_get_userdata(request); +} + +void jsonrpc_respond( + struct jsonrpc_request * request, + json_t * result) +{ + jsonrpc_impl_respond(request, result); +} + +void jsonrpc_respond_error( + struct jsonrpc_request * request, + int code, + char const * message) +{ + jsonrpc_impl_respond_error(request, code, message); +} + +// response + +bool jsonrpc_is_response( + json_t * message) +{ + return jsonrpc_impl_is_response(message); +} + +// server + +struct jsonrpc_server * +jsonrpc_server_create(void) +{ + return jsonrpc_impl_server_create(); +} + +void +jsonrpc_server_dispose( + struct jsonrpc_server * server) +{ + jsonrpc_impl_server_dispose(server); +} + +void jsonrpc_server_add( + struct jsonrpc_server * server, + char const * method_name, + jsonrpc_method_invoke_fn * invoke, + void * user_data) +{ + jsonrpc_impl_server_add(server, method_name, invoke, user_data); +} + +void jsonrpc_server_process( + struct jsonrpc_server * server, + json_t * request, + jsonrpc_send_fn * send, + void * user_data) +{ + jsonrpc_impl_server_process(server, request, send, user_data); +} diff --git a/lib/jsonrpc/error.c b/lib/jsonrpc/impl/error.c similarity index 75% rename from lib/jsonrpc/error.c rename to lib/jsonrpc/impl/error.c index 7613766..716f6de 100644 --- a/lib/jsonrpc/error.c +++ b/lib/jsonrpc/impl/error.c @@ -1,7 +1,7 @@ -#include "jsonrpc/error.h" +#include "jsonrpc/impl/error.h" json_t * -jsonrpc_error( +jsonrpc_impl_error( int code, char const * message) { @@ -13,13 +13,13 @@ jsonrpc_error( } void -jsonrpc_propate_error( +jsonrpc_impl_propate_error( jsonrpc_proxy_finished_fn * finised, void * user_data, int code, char const * message) { - json_t * error = jsonrpc_error(code, message); + json_t * error = jsonrpc_impl_error(code, message); finised(user_data, NULL, error); json_decref(error); diff --git a/lib/jsonrpc/error.h b/lib/jsonrpc/impl/error.h similarity index 65% rename from lib/jsonrpc/error.h rename to lib/jsonrpc/impl/error.h index 38bbcd2..6485f05 100644 --- a/lib/jsonrpc/error.h +++ b/lib/jsonrpc/impl/error.h @@ -1,8 +1,8 @@ -#ifndef JSONRPC_ERROR_H -#define JSONRPC_ERROR_H +#ifndef JSONRPC_IMPL_ERROR_H +#define JSONRPC_IMPL_ERROR_H #include -#include "jsonrpc/proxy.h" +#include "jsonrpc/proxy_finished_fn.h" #ifdef __cplusplus extern "C" @@ -10,12 +10,12 @@ extern "C" #endif extern json_t * -jsonrpc_error( +jsonrpc_impl_error( int code, char const * message); extern void -jsonrpc_propate_error( +jsonrpc_impl_propate_error( jsonrpc_proxy_finished_fn * finised, void * user_data, int code, diff --git a/lib/jsonrpc/method.c b/lib/jsonrpc/impl/method.c similarity index 80% rename from lib/jsonrpc/method.c rename to lib/jsonrpc/impl/method.c index 31414d4..073e8b3 100644 --- a/lib/jsonrpc/method.c +++ b/lib/jsonrpc/impl/method.c @@ -1,8 +1,8 @@ -#include "jsonrpc/method.h" +#include "jsonrpc/impl/method.h" #include #include -struct jsonrpc_method * jsonrpc_method_create( +struct jsonrpc_method * jsonrpc_impl_method_create( char const * method_name, jsonrpc_method_invoke_fn * invoke, void * user_data) @@ -19,7 +19,7 @@ struct jsonrpc_method * jsonrpc_method_create( return method; } -void jsonrpc_method_dispose( +void jsonrpc_impl_method_dispose( struct jsonrpc_method * method) { free(method->name); diff --git a/include/jsonrpc/method.h b/lib/jsonrpc/impl/method.h similarity index 50% rename from include/jsonrpc/method.h rename to lib/jsonrpc/impl/method.h index 8e9cb3a..595d35d 100644 --- a/include/jsonrpc/method.h +++ b/lib/jsonrpc/impl/method.h @@ -1,21 +1,13 @@ -#ifndef JSONRPC_METHOD_H -#define JSONRPC_METHOD_H +#ifndef JSONRPC_IMPL_METHOD_H +#define JSONRPC_IMPL_METHOD_H -#include +#include "jsonrpc/method_invoke_fn.h" #ifdef __cplusplus extern "C" { #endif -struct jsonrpc_request; - -typedef void jsonrpc_method_invoke_fn( - struct jsonrpc_request * request, - char const * method_name, - json_t * params, - void * user_data); - struct jsonrpc_method { struct jsonrpc_method * next; @@ -24,12 +16,14 @@ struct jsonrpc_method void * user_data; }; -extern struct jsonrpc_method * jsonrpc_method_create( +extern struct jsonrpc_method * +jsonrpc_impl_method_create( char const * method_name, jsonrpc_method_invoke_fn * invoke, void * user_data); -extern void jsonrpc_method_dispose( +extern void +jsonrpc_impl_method_dispose( struct jsonrpc_method * method); #ifdef __cplusplus diff --git a/lib/jsonrpc/proxy.c b/lib/jsonrpc/impl/proxy.c similarity index 71% rename from lib/jsonrpc/proxy.c rename to lib/jsonrpc/impl/proxy.c index b12571e..446cd91 100644 --- a/lib/jsonrpc/proxy.c +++ b/lib/jsonrpc/impl/proxy.c @@ -1,11 +1,35 @@ -#include "jsonrpc/proxy.h" -#include "jsonrpc/response.h" -#include "jsonrpc/error.h" +#include "jsonrpc/impl/proxy.h" +#include "jsonrpc/impl/response.h" +#include "jsonrpc/impl/error.h" #include "jsonrpc/status.h" +#include #include -static void jsonrpc_proxy_timeout( +struct jsonrpc_proxy * +jsonrpc_impl_proxy_create( + struct wf_impl_timeout_manager * manager, + int timeout, + jsonrpc_send_fn * send, + void * user_data) +{ + struct jsonrpc_proxy * proxy = malloc(sizeof(struct jsonrpc_proxy)); + if (NULL != proxy) + { + jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); + } + + return proxy; +} + +void jsonrpc_impl_proxy_dispose( + struct jsonrpc_proxy * proxy) +{ + jsonrpc_impl_proxy_cleanup(proxy); + free(proxy); +} + +static void jsonrpc_impl_proxy_timeout( struct wf_impl_timer * timer) { struct jsonrpc_proxy * proxy = timer->user_data; @@ -21,11 +45,11 @@ static void jsonrpc_proxy_timeout( proxy->request.finished = NULL; wf_impl_timer_cancel(&proxy->request.timer); - jsonrpc_propate_error(finished, user_data, JSONRPC_BAD_TIMEOUT, "Timeout"); + jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD_TIMEOUT, "Timeout"); } } -static json_t * jsonrpc_request_create( +static json_t * jsonrpc_impl_request_create( char const * method, int id, char const * param_info, @@ -69,7 +93,7 @@ static json_t * jsonrpc_request_create( return request; } -void jsonrpc_proxy_init( +void jsonrpc_impl_proxy_init( struct jsonrpc_proxy * proxy, struct wf_impl_timeout_manager * timeout_manager, int timeout, @@ -84,7 +108,7 @@ void jsonrpc_proxy_init( wf_impl_timer_init(&proxy->request.timer, timeout_manager); } -void jsonrpc_proxy_cleanup( +void jsonrpc_impl_proxy_cleanup( struct jsonrpc_proxy * proxy) { if (proxy->request.is_pending) @@ -98,19 +122,19 @@ void jsonrpc_proxy_cleanup( proxy->request.id = 0; wf_impl_timer_cancel(&proxy->request.timer); - jsonrpc_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); + jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); } wf_impl_timer_cleanup(&proxy->request.timer); } -void jsonrpc_proxy_invoke( +void jsonrpc_impl_proxy_invoke( struct jsonrpc_proxy * proxy, jsonrpc_proxy_finished_fn * finished, void * user_data, char const * method_name, char const * param_info, - ... + va_list args ) { if (!proxy->request.is_pending) @@ -120,12 +144,9 @@ void jsonrpc_proxy_invoke( proxy->request.user_data = user_data; proxy->request.id = 42; wf_impl_timer_start(&proxy->request.timer, wf_impl_timepoint_in_msec(proxy->timeout), - &jsonrpc_proxy_timeout, proxy); + &jsonrpc_impl_proxy_timeout, proxy); - va_list args; - va_start(args, param_info); - json_t * request = jsonrpc_request_create(method_name, proxy->request.id, param_info, args); - va_end(args); + json_t * request = jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args); bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data))); if (!is_send) @@ -136,7 +157,7 @@ void jsonrpc_proxy_invoke( proxy->request.id = 0; wf_impl_timer_cancel(&proxy->request.timer); - jsonrpc_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); + jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); } if (NULL != request) @@ -146,21 +167,18 @@ void jsonrpc_proxy_invoke( } else { - jsonrpc_propate_error(finished, user_data, JSONRPC_BAD_BUSY, "Busy"); + jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD_BUSY, "Busy"); } } -extern void jsonrpc_proxy_notify( +extern void jsonrpc_impl_proxy_notify( struct jsonrpc_proxy * proxy, char const * method_name, char const * param_info, - ... + va_list args ) { - va_list args; - va_start(args, param_info); - json_t * request = jsonrpc_request_create(method_name, 0, param_info, args); - va_end(args); + json_t * request = jsonrpc_impl_request_create(method_name, 0, param_info, args); if (NULL != request) { proxy->send(request, proxy->user_data); @@ -169,12 +187,12 @@ extern void jsonrpc_proxy_notify( } -void jsonrpc_proxy_onresult( +void jsonrpc_impl_proxy_onresult( struct jsonrpc_proxy * proxy, json_t * message) { struct jsonrpc_response response; - jsonrpc_response_init(&response, message); + jsonrpc_impl_response_init(&response, message); if ((proxy->request.is_pending) && (response.id == proxy->request.id)) { @@ -190,6 +208,6 @@ void jsonrpc_proxy_onresult( finished(user_data, response.result, response.error); } - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); } diff --git a/lib/jsonrpc/impl/proxy.h b/lib/jsonrpc/impl/proxy.h new file mode 100644 index 0000000..0556e0d --- /dev/null +++ b/lib/jsonrpc/impl/proxy.h @@ -0,0 +1,84 @@ +#ifndef JSONRPC_IMPL_PROXY_H +#define JSONRPC_IMPL_PROXY_H + +#include "jsonrpc/proxy_finished_fn.h" +#include "jsonrpc/send_fn.h" + +#include "webfuse/adapter/impl/time/timeout_manager.h" +#include "webfuse/adapter/impl/time/timer.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct jsonrpc_request +{ + bool is_pending; + jsonrpc_proxy_finished_fn * finished; + void * user_data; + int id; + struct wf_impl_timer timer; +}; + +struct jsonrpc_proxy +{ + struct jsonrpc_request request; + int timeout; + jsonrpc_send_fn * send; + void * user_data; +}; + +extern void +jsonrpc_impl_proxy_init( + struct jsonrpc_proxy * proxy, + struct wf_impl_timeout_manager * manager, + int timeout, + jsonrpc_send_fn * send, + void * user_data); + +extern void +jsonrpc_impl_proxy_cleanup( + struct jsonrpc_proxy * proxy); + +extern struct jsonrpc_proxy * +jsonrpc_impl_proxy_create( + struct wf_impl_timeout_manager * manager, + int timeout, + jsonrpc_send_fn * send, + void * user_data); + +extern void +jsonrpc_impl_proxy_dispose( + struct jsonrpc_proxy * proxy); + + +extern void +jsonrpc_impl_proxy_invoke( + struct jsonrpc_proxy * proxy, + jsonrpc_proxy_finished_fn * finished, + void * user_data, + char const * method_name, + char const * param_info, + va_list args +); + +extern void +jsonrpc_impl_proxy_notify( + struct jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + va_list args +); + +extern void +jsonrpc_impl_proxy_onresult( + struct jsonrpc_proxy * proxy, + json_t * message); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/jsonrpc/request.c b/lib/jsonrpc/impl/request.c similarity index 70% rename from lib/jsonrpc/request.c rename to lib/jsonrpc/impl/request.c index 8790ce9..91ffd96 100644 --- a/lib/jsonrpc/request.c +++ b/lib/jsonrpc/impl/request.c @@ -1,5 +1,5 @@ -#include "jsonrpc/request.h" -#include "webfuse/core/status_intern.h" +#include "jsonrpc/impl/request.h" +#include "jsonrpc/impl/error.h" #include struct jsonrpc_request @@ -9,7 +9,8 @@ struct jsonrpc_request void * user_data; }; -bool jsonrpc_is_request( +bool +jsonrpc_impl_is_request( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -21,7 +22,8 @@ bool jsonrpc_is_request( } -struct jsonrpc_request * jsonrpc_request_create( +struct jsonrpc_request * +jsonrpc_impl_request_create( int id, jsonrpc_send_fn * send, void * user_data) @@ -37,20 +39,23 @@ struct jsonrpc_request * jsonrpc_request_create( return request; } -void jsonrpc_request_dispose( +void +jsonrpc_impl_request_dispose( struct jsonrpc_request * request) { free(request); } -void * jsonrpc_request_get_userdata( +void * +jsonrpc_impl_request_get_userdata( struct jsonrpc_request * request) { return request->user_data; } -void jsonrpc_respond( +void +jsonrpc_impl_respond( struct jsonrpc_request * request, json_t * result) { @@ -60,23 +65,20 @@ void jsonrpc_respond( request->send(response, request->user_data); json_decref(response); - jsonrpc_request_dispose(request); + jsonrpc_impl_request_dispose(request); } -void jsonrpc_respond_error( +void jsonrpc_impl_respond_error( struct jsonrpc_request * request, - wf_status status) + int code, + char const * message) { - json_t * err = json_object(); - json_object_set_new(err, "code", json_integer(status)); - json_object_set_new(err, "message", json_string(wf_status_tostring(status))); - json_t * response = json_object(); - json_object_set_new(response, "error", err); + json_object_set_new(response, "error", jsonrpc_impl_error(code, message)); json_object_set_new(response, "id", json_integer(request->id)); request->send(response, request->user_data); json_decref(response); - jsonrpc_request_dispose(request); + jsonrpc_impl_request_dispose(request); } diff --git a/lib/jsonrpc/impl/request.h b/lib/jsonrpc/impl/request.h new file mode 100644 index 0000000..234a508 --- /dev/null +++ b/lib/jsonrpc/impl/request.h @@ -0,0 +1,53 @@ +#ifndef JSONRPC_IMPL_REQUEST_H +#define JSONRPC_IMPL_REQUEST_H + +#ifndef __cplusplus +#include +#include +#include +#else +#include +#include +using std::size_t; +#endif + +#include +#include +#include "jsonrpc/send_fn.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct jsonrpc_request; + +extern bool jsonrpc_impl_is_request( + json_t * message); + +extern struct jsonrpc_request * jsonrpc_impl_request_create( + int id, + jsonrpc_send_fn * send, + void * user_data); + +extern void jsonrpc_impl_request_dispose( + struct jsonrpc_request * request); + +extern void * jsonrpc_impl_request_get_userdata( + struct jsonrpc_request * request); + +extern void jsonrpc_impl_respond( + struct jsonrpc_request * request, + json_t * result); + +extern void jsonrpc_impl_respond_error( + struct jsonrpc_request * request, + int code, + char const * message); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/jsonrpc/response.c b/lib/jsonrpc/impl/response.c similarity index 76% rename from lib/jsonrpc/response.c rename to lib/jsonrpc/impl/response.c index c11bbc7..9f3d04e 100644 --- a/lib/jsonrpc/response.c +++ b/lib/jsonrpc/impl/response.c @@ -1,8 +1,9 @@ -#include "jsonrpc/response.h" -#include "jsonrpc/error.h" +#include "jsonrpc/impl/response.h" +#include "jsonrpc/impl/error.h" #include "jsonrpc/status.h" -extern bool jsonrpc_is_response( +bool +jsonrpc_impl_is_response( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -14,7 +15,8 @@ extern bool jsonrpc_is_response( } -void jsonrpc_response_init( +void +jsonrpc_impl_response_init( struct jsonrpc_response * result, json_t * response) { @@ -25,7 +27,7 @@ void jsonrpc_response_init( json_t * id_holder = json_object_get(response, "id"); if ((NULL == id_holder) || (!json_is_integer(id_holder))) { - result->error = jsonrpc_error(JSONRPC_BAD_FORMAT, "invalid format: missing id"); + result->error = jsonrpc_impl_error(JSONRPC_BAD_FORMAT, "invalid format: missing id"); return; } @@ -45,12 +47,13 @@ void jsonrpc_response_init( } else { - result->error = jsonrpc_error(JSONRPC_BAD_FORMAT, "invalid format: invalid error object"); + result->error = jsonrpc_impl_error(JSONRPC_BAD_FORMAT, "invalid format: invalid error object"); } } } -void jsonrpc_response_cleanup( +void +jsonrpc_impl_response_cleanup( struct jsonrpc_response * response) { if (NULL != response->result) diff --git a/lib/jsonrpc/impl/response.h b/lib/jsonrpc/impl/response.h new file mode 100644 index 0000000..b39e30e --- /dev/null +++ b/lib/jsonrpc/impl/response.h @@ -0,0 +1,40 @@ +#ifndef JSONRPC_IMPL_RESPONSE_H +#define JSONRPC_IMPL_RESPONSE_H + +#ifndef __cplusplus +#include +#include +#else +#include +using std::size_t; +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct jsonrpc_response +{ + json_t * result; + json_t * error; + int id; +}; + +extern bool jsonrpc_impl_is_response( + json_t * message); + +extern void jsonrpc_impl_response_init( + struct jsonrpc_response * response, + json_t * message); + +extern void jsonrpc_impl_response_cleanup( + struct jsonrpc_response * response); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/lib/jsonrpc/impl/server.c b/lib/jsonrpc/impl/server.c new file mode 100644 index 0000000..7da42a3 --- /dev/null +++ b/lib/jsonrpc/impl/server.c @@ -0,0 +1,132 @@ +#include "jsonrpc/impl/server.h" +#include "jsonrpc/impl/method.h" +#include "jsonrpc/impl/request.h" +#include "jsonrpc/impl/unused_param.h" +#include "jsonrpc/status.h" + +#include +#include + +struct jsonrpc_server +{ + struct jsonrpc_method * methods; +}; + +static void +jsonrpc_impl_server_init( + struct jsonrpc_server * server); + +static void +jsonrpc_impl_server_cleanup( + struct jsonrpc_server * server); + +struct jsonrpc_server * +jsonrpc_impl_server_create(void) +{ + struct jsonrpc_server * server = malloc(sizeof(struct jsonrpc_server)); + if (NULL != server) + { + jsonrpc_impl_server_init(server); + } + + return server; +} + +void +jsonrpc_impl_server_dispose( + struct jsonrpc_server * server) +{ + jsonrpc_impl_server_cleanup(server); + free(server); +} + + +static void jsonrpc_impl_server_init( + struct jsonrpc_server * server) +{ + server->methods = NULL; +} + +static void jsonrpc_impl_server_cleanup( + struct jsonrpc_server * server) +{ + struct jsonrpc_method * current = server->methods; + while (NULL != current) + { + struct jsonrpc_method * next = current->next; + jsonrpc_impl_method_dispose(current); + current = next; + } + server->methods = NULL; +} + +void jsonrpc_impl_server_add( + struct jsonrpc_server * server, + char const * method_name, + jsonrpc_method_invoke_fn * invoke, + void * user_data) +{ + struct jsonrpc_method * method = jsonrpc_impl_method_create(method_name, invoke, user_data); + method->next = server->methods; + server->methods = method; +} + +static void jsonrpc_impl_server_invalid_method_invoke( + struct jsonrpc_request * request, + char const * JSONRPC_UNUSED_PARAM(method_name), + json_t * JSONRPC_UNUSED_PARAM(params), + void * JSONRPC_UNUSED_PARAM(user_data)) +{ + jsonrpc_impl_respond_error(request, JSONRPC_BAD_NOTIMPLEMENTED, "not implemented"); +} + +static struct jsonrpc_method const jsonrpc_impl_server_invalid_method = +{ + .next = NULL, + .name = "", + .invoke = &jsonrpc_impl_server_invalid_method_invoke, + .user_data = NULL +}; + +static struct jsonrpc_method const * +jsonrpc_impl_server_get_method( + struct jsonrpc_server * server, + char const * method_name) +{ + struct jsonrpc_method const * current = server->methods; + while (NULL != current) + { + if (0 == strcmp(method_name, current->name)) + { + return current; + } + + current = current->next; + } + + return &jsonrpc_impl_server_invalid_method; +} + +void jsonrpc_impl_server_process( + struct jsonrpc_server * server, + json_t * request_data, + jsonrpc_send_fn * send, + void * user_data) +{ + json_t * method_holder = json_object_get(request_data, "method"); + json_t * params = json_object_get(request_data, "params"); + json_t * id_holder = json_object_get(request_data, "id"); + + if (json_is_string(method_holder) && + (json_is_array(params) || (json_is_object(params))) && + json_is_integer(id_holder)) + { + char const * method_name = json_string_value(method_holder); + int id = json_integer_value(id_holder); + struct jsonrpc_request * request = jsonrpc_impl_request_create(id, send, user_data); + struct jsonrpc_method const * method = jsonrpc_impl_server_get_method(server, method_name); + + method->invoke(request, method_name, params, method->user_data); + } +} + diff --git a/lib/jsonrpc/impl/server.h b/lib/jsonrpc/impl/server.h new file mode 100644 index 0000000..6263c66 --- /dev/null +++ b/lib/jsonrpc/impl/server.h @@ -0,0 +1,41 @@ +#ifndef JSONRPC_IMPL_SERVER_H +#define JSONRPC_IMPL_SERVER_H + +#include +#include "jsonrpc/method_invoke_fn.h" +#include "jsonrpc/send_fn.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct jsonrpc_server; + +extern struct jsonrpc_server * +jsonrpc_impl_server_create(void); + +extern void +jsonrpc_impl_server_dispose( + struct jsonrpc_server * server); + +extern void +jsonrpc_impl_server_add( + struct jsonrpc_server * server, + char const * method_name, + jsonrpc_method_invoke_fn * invoke, + void * user_data); + +extern void +jsonrpc_impl_server_process( + struct jsonrpc_server * server, + json_t * request, + jsonrpc_send_fn * send, + void * user_data); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/jsonrpc/impl/unused_param.h b/lib/jsonrpc/impl/unused_param.h new file mode 100644 index 0000000..cde12d0 --- /dev/null +++ b/lib/jsonrpc/impl/unused_param.h @@ -0,0 +1,10 @@ +#ifndef JSONRPC_UTIL_H +#define JSONRPC_UTIL_H + +#ifdef __GNUC__ +#define JSONRPC_UNUSED_PARAM(param) param __attribute__((unused)) +#else +#define JSONRPC_UNUSED_PARAM(param) +#endif + +#endif diff --git a/lib/jsonrpc/server.c b/lib/jsonrpc/server.c deleted file mode 100644 index 6e62c3b..0000000 --- a/lib/jsonrpc/server.c +++ /dev/null @@ -1,95 +0,0 @@ -#include "jsonrpc/server.h" -#include "jsonrpc/method.h" -#include "jsonrpc/request.h" -#include "webfuse/core/util.h" - -#include - -void jsonrpc_server_init( - struct jsonrpc_server * server) -{ - server->methods = NULL; -} - -void jsonrpc_server_cleanup( - struct jsonrpc_server * server) -{ - struct jsonrpc_method * current = server->methods; - while (NULL != current) - { - struct jsonrpc_method * next = current->next; - jsonrpc_method_dispose(current); - current = next; - } - server->methods = NULL; -} - -void jsonrpc_server_add( - struct jsonrpc_server * server, - char const * method_name, - jsonrpc_method_invoke_fn * invoke, - void * user_data) -{ - struct jsonrpc_method * method = jsonrpc_method_create(method_name, invoke, user_data); - method->next = server->methods; - server->methods = method; -} - -static void jsonrpc_server_invalid_method_invoke( - struct jsonrpc_request * request, - char const * WF_UNUSED_PARAM(method_name), - json_t * WF_UNUSED_PARAM(params), - void * WF_UNUSED_PARAM(user_data)) -{ - jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED); -} - -static struct jsonrpc_method const jsonrpc_server_invalid_method = -{ - .next = NULL, - .name = "", - .invoke = &jsonrpc_server_invalid_method_invoke, - .user_data = NULL -}; - -static struct jsonrpc_method const * jsonrpc_server_get_method( - struct jsonrpc_server * server, - char const * method_name) -{ - struct jsonrpc_method const * current = server->methods; - while (NULL != current) - { - if (0 == strcmp(method_name, current->name)) - { - return current; - } - - current = current->next; - } - - return &jsonrpc_server_invalid_method; -} - -void jsonrpc_server_process( - struct jsonrpc_server * server, - json_t * request_data, - jsonrpc_send_fn * send, - void * user_data) -{ - json_t * method_holder = json_object_get(request_data, "method"); - json_t * params = json_object_get(request_data, "params"); - json_t * id_holder = json_object_get(request_data, "id"); - - if (json_is_string(method_holder) && - (json_is_array(params) || (json_is_object(params))) && - json_is_integer(id_holder)) - { - char const * method_name = json_string_value(method_holder); - int id = json_integer_value(id_holder); - struct jsonrpc_request * request = jsonrpc_request_create(id, send, user_data); - struct jsonrpc_method const * method = jsonrpc_server_get_method(server, method_name); - - method->invoke(request, method_name, params, method->user_data); - } -} - diff --git a/lib/webfuse/adapter/impl/operations.c b/lib/webfuse/adapter/impl/operations.c index ac9fb96..d3f9e96 100644 --- a/lib/webfuse/adapter/impl/operations.c +++ b/lib/webfuse/adapter/impl/operations.c @@ -11,7 +11,7 @@ struct jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_session * session = context->session; if (NULL != session) { - proxy = &session->rpc; + proxy = session->rpc; } return proxy; diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 746df5c..061fa5c 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -11,6 +11,7 @@ #include "webfuse/adapter/impl/credentials.h" #include "jsonrpc/request.h" #include "webfuse/adapter/impl/uuid_mountpoint_factory.h" +#include "webfuse/core/status_intern.h" static int wf_impl_server_protocol_callback( struct lws * wsi, @@ -42,7 +43,7 @@ static int wf_impl_server_protocol_callback( &protocol->authenticators, &protocol->mountpoint_factory, &protocol->timeout_manager, - &protocol->server); + protocol->server); if (NULL != session) { @@ -159,7 +160,7 @@ static void wf_impl_server_protocol_authenticate( } else { - jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED); + jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED, wf_status_tostring(WF_BAD_ACCESS_DENIED)); } } @@ -222,7 +223,7 @@ static void wf_impl_server_protocol_add_filesystem( } else { - jsonrpc_respond_error(request, status); + jsonrpc_respond_error(request, status, wf_status_tostring(status)); } @@ -240,9 +241,9 @@ void wf_impl_server_protocol_init( wf_impl_session_manager_init(&protocol->session_manager); wf_impl_authenticators_init(&protocol->authenticators); - jsonrpc_server_init(&protocol->server); - jsonrpc_server_add(&protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol); - jsonrpc_server_add(&protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol); + protocol->server = jsonrpc_server_create(); + jsonrpc_server_add(protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol); + jsonrpc_server_add(protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol); } void wf_impl_server_protocol_cleanup( @@ -250,7 +251,7 @@ void wf_impl_server_protocol_cleanup( { protocol->is_operational = false; - jsonrpc_server_cleanup(&protocol->server); + jsonrpc_server_dispose(protocol->server); wf_impl_timeout_manager_cleanup(&protocol->timeout_manager); wf_impl_authenticators_cleanup(&protocol->authenticators); wf_impl_session_manager_cleanup(&protocol->session_manager); diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 85c94c1..0677c84 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -25,7 +25,7 @@ struct wf_server_protocol struct wf_impl_authenticators authenticators; struct wf_impl_mountpoint_factory mountpoint_factory; struct wf_impl_session_manager session_manager; - struct jsonrpc_server server; + struct jsonrpc_server * server; bool is_operational; }; diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index 5690c4f..deafb92 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -59,7 +59,7 @@ struct wf_impl_session * wf_impl_session_create( session->authenticators = authenticators; session->server = server; session->mountpoint_factory = mountpoint_factory; - jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); + session->rpc = jsonrpc_proxy_create(timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); wf_slist_init(&session->messages); } @@ -83,15 +83,10 @@ static void wf_impl_session_dispose_filesystems( void wf_impl_session_dispose( struct wf_impl_session * session) { - jsonrpc_proxy_cleanup(&session->rpc); + jsonrpc_proxy_dispose(session->rpc); wf_message_queue_cleanup(&session->messages); wf_impl_session_dispose_filesystems(&session->filesystems); - session->is_authenticated = false; - session->wsi = NULL; - session->authenticators = NULL; - session->mountpoint_factory = NULL; - session->server = NULL; free(session); } @@ -161,7 +156,7 @@ void wf_impl_session_receive( { if (jsonrpc_is_response(message)) { - jsonrpc_proxy_onresult(&session->rpc, message); + jsonrpc_proxy_onresult(session->rpc, message); } else if (jsonrpc_is_request(message)) { diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h index 90f8f4e..cc95911 100644 --- a/lib/webfuse/adapter/impl/session.h +++ b/lib/webfuse/adapter/impl/session.h @@ -36,7 +36,7 @@ struct wf_impl_session struct wf_impl_authenticators * authenticators; struct wf_impl_mountpoint_factory * mountpoint_factory; struct jsonrpc_server * server; - struct jsonrpc_proxy rpc; + struct jsonrpc_proxy * rpc; struct wf_slist filesystems; }; diff --git a/test/jsonrpc/test_proxy.cc b/test/jsonrpc/test_proxy.cc index 79fb090..834a7ef 100644 --- a/test/jsonrpc/test_proxy.cc +++ b/test/jsonrpc/test_proxy.cc @@ -92,10 +92,9 @@ TEST(jsonrpc_proxy, init) SendContext context; void * user_data = reinterpret_cast(&context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); ASSERT_FALSE(context.is_called); @@ -108,12 +107,11 @@ TEST(jsonrpc_proxy, invoke) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -135,7 +133,7 @@ TEST(jsonrpc_proxy, invoke) ASSERT_FALSE(finished_context.is_called); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); ASSERT_TRUE(finished_context.is_called); @@ -149,12 +147,11 @@ TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails) SendContext send_context(false); void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -162,7 +159,7 @@ TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails) ASSERT_TRUE(finished_context.is_called); ASSERT_FALSE(nullptr == finished_context.error); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -173,16 +170,15 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); FinishedContext finished_context2; void * finished_data2 = reinterpret_cast(&finished_context2); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data2, "foo", ""); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", ""); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -192,7 +188,7 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending) ASSERT_TRUE(finished_context2.is_called); ASSERT_EQ(WF_BAD_BUSY, wf_impl_jsonrpc_get_status(finished_context2.error)); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -203,19 +199,18 @@ TEST(jsonrpc_proxy, invoke_fails_if_request_is_invalid) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "?", "error"); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error"); ASSERT_FALSE(send_context.is_called); ASSERT_TRUE(finished_context.is_called); ASSERT_EQ(WF_BAD, wf_impl_jsonrpc_get_status(finished_context.error)); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -226,12 +221,11 @@ TEST(jsonrpc_proxy, on_result) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -243,7 +237,7 @@ TEST(jsonrpc_proxy, on_result) json_object_set_new(response, "result", json_string("okay")); json_object_set(response, "id", id); - jsonrpc_proxy_onresult(&proxy, response); + jsonrpc_proxy_onresult(proxy, response); json_decref(response); ASSERT_TRUE(finished_context.is_called); @@ -251,7 +245,7 @@ TEST(jsonrpc_proxy, on_result) ASSERT_TRUE(json_is_string(finished_context.result)); ASSERT_STREQ("okay", json_string_value(finished_context.result)); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -262,12 +256,11 @@ TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -279,12 +272,12 @@ TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id) json_object_set_new(response, "result", json_string("okay")); json_object_set_new(response, "id", json_integer(1 + json_integer_value(id))); - jsonrpc_proxy_onresult(&proxy, response); + jsonrpc_proxy_onresult(proxy, response); json_decref(response); ASSERT_FALSE(finished_context.is_called); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -295,12 +288,11 @@ TEST(jsonrpc_proxy, timeout) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, 0, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, 0, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -311,7 +303,7 @@ TEST(jsonrpc_proxy, timeout) ASSERT_TRUE(finished_context.is_called); ASSERT_EQ(WF_BAD_TIMEOUT, wf_impl_jsonrpc_get_status(finished_context.error)); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -322,12 +314,11 @@ TEST(jsonrpc_proxy, cleanup_pending_request) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, 10, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, 10, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -335,7 +326,7 @@ TEST(jsonrpc_proxy, cleanup_pending_request) ASSERT_FALSE(finished_context.is_called); ASSERT_NE(nullptr, timeout_manager.timers); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); ASSERT_TRUE(finished_context.is_called); ASSERT_EQ(nullptr, timeout_manager.timers); @@ -352,10 +343,9 @@ TEST(jsonrpc_proxy, notify) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); - jsonrpc_proxy_notify(&proxy, "foo", "si", "bar", 42); + jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -376,7 +366,7 @@ TEST(jsonrpc_proxy, notify) ASSERT_EQ(nullptr, id); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } @@ -387,13 +377,12 @@ TEST(jsonrpc_proxy, notify_dont_send_invalid_request) SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy proxy; - jsonrpc_proxy_init(&proxy, &timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); - jsonrpc_proxy_notify(&proxy, "foo", "?"); + jsonrpc_proxy_notify(proxy, "foo", "?"); ASSERT_FALSE(send_context.is_called); - jsonrpc_proxy_cleanup(&proxy); + jsonrpc_proxy_dispose(proxy); wf_impl_timeout_manager_cleanup(&timeout_manager); } diff --git a/test/jsonrpc/test_request.cc b/test/jsonrpc/test_request.cc index 94f87ee..a5f956e 100644 --- a/test/jsonrpc/test_request.cc +++ b/test/jsonrpc/test_request.cc @@ -1,5 +1,6 @@ #include #include "jsonrpc/request.h" +#include "jsonrpc/status.h" namespace { @@ -73,7 +74,7 @@ TEST(jsonrpc_request, respond_error) struct jsonrpc_request * request = jsonrpc_request_create(42, &jsonrpc_send, user_data); - jsonrpc_respond_error(request, WF_BAD); + jsonrpc_respond_error(request, JSONRPC_BAD, "Bad"); ASSERT_NE(nullptr, context.response); @@ -92,7 +93,7 @@ TEST(jsonrpc_request, respond_error) json_t * err_code = json_object_get(err, "code"); ASSERT_TRUE(json_is_integer(err_code)); - ASSERT_EQ(WF_BAD, json_integer_value(err_code)); + ASSERT_EQ(JSONRPC_BAD, json_integer_value(err_code)); json_t * err_message = json_object_get(err, "message"); ASSERT_TRUE(json_is_string(err_message)); diff --git a/test/jsonrpc/test_response.cc b/test/jsonrpc/test_response.cc index 1745bdb..bdf6e61 100644 --- a/test/jsonrpc/test_response.cc +++ b/test/jsonrpc/test_response.cc @@ -1,5 +1,5 @@ #include -#include "jsonrpc/response.h" +#include "jsonrpc/impl/response.h" #include "webfuse/core/status.h" #include "webfuse/core/json_util.h" @@ -10,14 +10,14 @@ TEST(json_response, init_result) json_object_set_new(message, "id", json_integer(11)); struct jsonrpc_response response; - jsonrpc_response_init(&response, message); + 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); - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); json_decref(message); } @@ -31,13 +31,13 @@ TEST(json_response, init_error) json_object_set_new(message, "id", json_integer(23)); struct jsonrpc_response response; - jsonrpc_response_init(&response, message); + jsonrpc_impl_response_init(&response, message); ASSERT_EQ(WF_BAD_ACCESS_DENIED, wf_impl_jsonrpc_get_status(response.error)) << json_string_value(json_object_get(response.error, "message")); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); json_decref(message); } @@ -47,12 +47,12 @@ TEST(json_response, init_format_error) json_object_set_new(message, "id", json_integer(12)); struct jsonrpc_response response; - jsonrpc_response_init(&response, message); + jsonrpc_impl_response_init(&response, message); ASSERT_EQ(WF_BAD_FORMAT, wf_impl_jsonrpc_get_status(response.error)); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(12, response.id); - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); json_decref(message); } diff --git a/test/webfuse/tests/adapter/test_response_parser.cc b/test/jsonrpc/test_response_parser.cc similarity index 81% rename from test/webfuse/tests/adapter/test_response_parser.cc rename to test/jsonrpc/test_response_parser.cc index 0973e9c..f65fa6f 100644 --- a/test/webfuse/tests/adapter/test_response_parser.cc +++ b/test/jsonrpc/test_response_parser.cc @@ -1,7 +1,7 @@ #include #include -#include "jsonrpc/response.h" +#include "jsonrpc/impl/response.h" #include "webfuse/core/json_util.h" @@ -12,7 +12,7 @@ static void response_parse_str( json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr); if (nullptr != message) { - jsonrpc_response_init(response, message); + jsonrpc_impl_response_init(response, message); json_decref(message); } } @@ -26,21 +26,21 @@ TEST(response_parser, test) ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); // empty response_parse_str("{}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); // no data response_parse_str("{\"id\":42}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); // custom error code response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); @@ -48,12 +48,12 @@ TEST(response_parser, test) ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); // valid response response_parse_str("{\"result\": true, \"id\": 42}", &response); ASSERT_EQ(WF_GOOD, response.error); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); - jsonrpc_response_cleanup(&response); + jsonrpc_impl_response_cleanup(&response); } diff --git a/test/jsonrpc/test_server.cc b/test/jsonrpc/test_server.cc index 4e0b2bc..e8e879a 100644 --- a/test/jsonrpc/test_server.cc +++ b/test/jsonrpc/test_server.cc @@ -1,6 +1,7 @@ #include #include "jsonrpc/server.h" #include "jsonrpc/request.h" +#include "jsonrpc/status.h" namespace { @@ -40,9 +41,8 @@ namespace TEST(jsonrpc_server, process_request) { - struct jsonrpc_server server; - jsonrpc_server_init(&server); - jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr); + struct jsonrpc_server * server = jsonrpc_server_create(); + jsonrpc_server_add(server, "sayHello", &sayHello, nullptr); Context context{nullptr, false}; void * user_data = reinterpret_cast(&context); @@ -50,7 +50,7 @@ TEST(jsonrpc_server, process_request) 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)); - jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); + jsonrpc_server_process(server, request, &jsonrpc_send, user_data); ASSERT_TRUE(context.is_called); ASSERT_NE(nullptr, context.response); @@ -66,14 +66,13 @@ TEST(jsonrpc_server, process_request) json_decref(context.response); json_decref(request); - jsonrpc_server_cleanup(&server); + jsonrpc_server_dispose(server); } TEST(jsonrpc_server, invoke_unknown_method) { - struct jsonrpc_server server; - jsonrpc_server_init(&server); - jsonrpc_server_add(&server, "sayHello", &sayHello, nullptr); + struct jsonrpc_server * server = jsonrpc_server_create(); + jsonrpc_server_add(server, "sayHello", &sayHello, nullptr); Context context{nullptr, false}; void * user_data = reinterpret_cast(&context); @@ -81,7 +80,7 @@ TEST(jsonrpc_server, invoke_unknown_method) 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)); - jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); + jsonrpc_server_process(server, request, &jsonrpc_send, user_data); ASSERT_TRUE(context.is_called); ASSERT_NE(nullptr, context.response); @@ -96,30 +95,29 @@ TEST(jsonrpc_server, invoke_unknown_method) json_t * err_code = json_object_get(err, "code"); ASSERT_TRUE(json_is_integer(err_code)); - ASSERT_EQ(WF_BAD_NOTIMPLEMENTED, json_integer_value(err_code)); + ASSERT_EQ(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); - jsonrpc_server_cleanup(&server); + jsonrpc_server_dispose(server); } TEST(jsonrpc_server, skip_invalid_request) { - struct jsonrpc_server server; - jsonrpc_server_init(&server); + struct jsonrpc_server * server = jsonrpc_server_create(); Context context{nullptr, false}; void * user_data = reinterpret_cast(&context); json_t * request = json_object(); json_object_set_new(request, "method", json_string("sayHello")); json_object_set_new(request, "params", json_array()); - jsonrpc_server_process(&server, request, &jsonrpc_send, user_data); + jsonrpc_server_process(server, request, &jsonrpc_send, user_data); ASSERT_FALSE(context.is_called); json_decref(request); - jsonrpc_server_cleanup(&server); + jsonrpc_server_dispose(server); } From b2d6ed87543bac7a21c57c0e06d134d6777906c2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 29 Feb 2020 02:44:26 +0100 Subject: [PATCH 066/138] reorganized library code --- cmake/jsonrpc.cmake | 21 ++++++++++++------- cmake/unit_tests.cmake | 17 ++++++++------- cmake/webfuse_adapter.cmake | 1 + cmake/webfuse_core.cmake | 2 +- {include => lib/jsonrpc/include}/jsonrpc.h | 0 .../jsonrpc/include}/jsonrpc/api.h | 0 .../include}/jsonrpc/method_invoke_fn.h | 0 .../jsonrpc/include}/jsonrpc/proxy.h | 0 .../include}/jsonrpc/proxy_finished_fn.h | 0 .../jsonrpc/include}/jsonrpc/request.h | 0 .../jsonrpc/include}/jsonrpc/response.h | 0 .../jsonrpc/include}/jsonrpc/send_fn.h | 0 .../jsonrpc/include}/jsonrpc/server.h | 0 .../jsonrpc/include}/jsonrpc/status.h | 0 lib/jsonrpc/{ => src/jsonrpc}/api.c | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/error.c | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/error.h | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/method.c | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/method.h | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/proxy.c | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/proxy.h | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/request.c | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/request.h | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/response.c | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/response.h | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/server.c | 0 lib/jsonrpc/{ => src/jsonrpc}/impl/server.h | 0 .../{ => src/jsonrpc}/impl/unused_param.h | 0 .../jsonrpc/test}/jsonrpc/test_is_request.cc | 0 .../jsonrpc/test}/jsonrpc/test_is_response.cc | 0 .../jsonrpc/test}/jsonrpc/test_proxy.cc | 0 .../jsonrpc/test}/jsonrpc/test_request.cc | 0 .../jsonrpc/test}/jsonrpc/test_response.cc | 0 .../test}/jsonrpc/test_response_parser.cc | 0 .../jsonrpc/test}/jsonrpc/test_server.cc | 0 .../jsonrpc/test}/jsonrpc/test_util.cc | 0 36 files changed, 24 insertions(+), 17 deletions(-) rename {include => lib/jsonrpc/include}/jsonrpc.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/api.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/method_invoke_fn.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/proxy.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/proxy_finished_fn.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/request.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/response.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/send_fn.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/server.h (100%) rename {include => lib/jsonrpc/include}/jsonrpc/status.h (100%) rename lib/jsonrpc/{ => src/jsonrpc}/api.c (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/error.c (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/error.h (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/method.c (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/method.h (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/proxy.c (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/proxy.h (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/request.c (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/request.h (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/response.c (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/response.h (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/server.c (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/server.h (100%) rename lib/jsonrpc/{ => src/jsonrpc}/impl/unused_param.h (100%) rename {test => lib/jsonrpc/test}/jsonrpc/test_is_request.cc (100%) rename {test => lib/jsonrpc/test}/jsonrpc/test_is_response.cc (100%) rename {test => lib/jsonrpc/test}/jsonrpc/test_proxy.cc (100%) rename {test => lib/jsonrpc/test}/jsonrpc/test_request.cc (100%) rename {test => lib/jsonrpc/test}/jsonrpc/test_response.cc (100%) rename {test => lib/jsonrpc/test}/jsonrpc/test_response_parser.cc (100%) rename {test => lib/jsonrpc/test}/jsonrpc/test_server.cc (100%) rename {test => lib/jsonrpc/test}/jsonrpc/test_util.cc (100%) diff --git a/cmake/jsonrpc.cmake b/cmake/jsonrpc.cmake index fb417bb..76653bb 100644 --- a/cmake/jsonrpc.cmake +++ b/cmake/jsonrpc.cmake @@ -1,14 +1,19 @@ # jsonrpc add_library(jsonrpc STATIC - lib/jsonrpc/api.c - lib/jsonrpc/impl/proxy.c - lib/jsonrpc/impl/server.c - lib/jsonrpc/impl/method.c - lib/jsonrpc/impl/request.c - lib/jsonrpc/impl/response.c - lib/jsonrpc/impl/error.c + lib/jsonrpc/src/jsonrpc/api.c + lib/jsonrpc/src/jsonrpc/impl/proxy.c + lib/jsonrpc/src/jsonrpc/impl/server.c + lib/jsonrpc/src/jsonrpc/impl/method.c + lib/jsonrpc/src/jsonrpc/impl/request.c + lib/jsonrpc/src/jsonrpc/impl/response.c + lib/jsonrpc/src/jsonrpc/impl/error.c +) + +target_include_directories(jsonrpc PUBLIC + lib/jsonrpc/include + lib/jsonrpc/src + lib ) -target_include_directories(jsonrpc PUBLIC lib) set_target_properties(jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 37ef85f..a6fbc8e 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,14 +7,14 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests - test/jsonrpc/test_util.cc - test/jsonrpc/test_is_request.cc - test/jsonrpc/test_request.cc - test/jsonrpc/test_is_response.cc - test/jsonrpc/test_response.cc - test/jsonrpc/test_server.cc - test/jsonrpc/test_proxy.cc - test/jsonrpc/test_response_parser.cc + lib/jsonrpc/test/jsonrpc/test_util.cc + lib/jsonrpc/test/jsonrpc/test_is_request.cc + lib/jsonrpc/test/jsonrpc/test_request.cc + lib/jsonrpc/test/jsonrpc/test_is_response.cc + lib/jsonrpc/test/jsonrpc/test_response.cc + lib/jsonrpc/test/jsonrpc/test_server.cc + lib/jsonrpc/test/jsonrpc/test_proxy.cc + lib/jsonrpc/test/jsonrpc/test_response_parser.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc test/webfuse/utils/msleep.cc @@ -52,6 +52,7 @@ add_executable(alltests ) target_include_directories(alltests PRIVATE + lib/jsonrpc/include ${FUSE3_INCLUDE_DIRS} ${UUID_INCLUDE_DIRS} ) diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index 719f699..7362802 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -32,6 +32,7 @@ add_library(webfuse-adapter-static STATIC target_include_directories(webfuse-adapter-static PRIVATE lib + lib/jsonrpc/include ${FUSE3_INCLUDE_DIRS} ${UUID_INCLUDE_DIRS} ) diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 2926384..8db1dad 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -12,7 +12,7 @@ add_library(webfuse-core STATIC ) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) -target_include_directories(webfuse-core PUBLIC lib) +target_include_directories(webfuse-core PUBLIC lib lib/jsonrpc/include) set_target_properties(webfuse-core PROPERTIES C_VISIBILITY_PRESET hidden) install(DIRECTORY include/webfuse/core DESTINATION include/webfuse COMPONENT headers) diff --git a/include/jsonrpc.h b/lib/jsonrpc/include/jsonrpc.h similarity index 100% rename from include/jsonrpc.h rename to lib/jsonrpc/include/jsonrpc.h diff --git a/include/jsonrpc/api.h b/lib/jsonrpc/include/jsonrpc/api.h similarity index 100% rename from include/jsonrpc/api.h rename to lib/jsonrpc/include/jsonrpc/api.h diff --git a/include/jsonrpc/method_invoke_fn.h b/lib/jsonrpc/include/jsonrpc/method_invoke_fn.h similarity index 100% rename from include/jsonrpc/method_invoke_fn.h rename to lib/jsonrpc/include/jsonrpc/method_invoke_fn.h diff --git a/include/jsonrpc/proxy.h b/lib/jsonrpc/include/jsonrpc/proxy.h similarity index 100% rename from include/jsonrpc/proxy.h rename to lib/jsonrpc/include/jsonrpc/proxy.h diff --git a/include/jsonrpc/proxy_finished_fn.h b/lib/jsonrpc/include/jsonrpc/proxy_finished_fn.h similarity index 100% rename from include/jsonrpc/proxy_finished_fn.h rename to lib/jsonrpc/include/jsonrpc/proxy_finished_fn.h diff --git a/include/jsonrpc/request.h b/lib/jsonrpc/include/jsonrpc/request.h similarity index 100% rename from include/jsonrpc/request.h rename to lib/jsonrpc/include/jsonrpc/request.h diff --git a/include/jsonrpc/response.h b/lib/jsonrpc/include/jsonrpc/response.h similarity index 100% rename from include/jsonrpc/response.h rename to lib/jsonrpc/include/jsonrpc/response.h diff --git a/include/jsonrpc/send_fn.h b/lib/jsonrpc/include/jsonrpc/send_fn.h similarity index 100% rename from include/jsonrpc/send_fn.h rename to lib/jsonrpc/include/jsonrpc/send_fn.h diff --git a/include/jsonrpc/server.h b/lib/jsonrpc/include/jsonrpc/server.h similarity index 100% rename from include/jsonrpc/server.h rename to lib/jsonrpc/include/jsonrpc/server.h diff --git a/include/jsonrpc/status.h b/lib/jsonrpc/include/jsonrpc/status.h similarity index 100% rename from include/jsonrpc/status.h rename to lib/jsonrpc/include/jsonrpc/status.h diff --git a/lib/jsonrpc/api.c b/lib/jsonrpc/src/jsonrpc/api.c similarity index 100% rename from lib/jsonrpc/api.c rename to lib/jsonrpc/src/jsonrpc/api.c diff --git a/lib/jsonrpc/impl/error.c b/lib/jsonrpc/src/jsonrpc/impl/error.c similarity index 100% rename from lib/jsonrpc/impl/error.c rename to lib/jsonrpc/src/jsonrpc/impl/error.c diff --git a/lib/jsonrpc/impl/error.h b/lib/jsonrpc/src/jsonrpc/impl/error.h similarity index 100% rename from lib/jsonrpc/impl/error.h rename to lib/jsonrpc/src/jsonrpc/impl/error.h diff --git a/lib/jsonrpc/impl/method.c b/lib/jsonrpc/src/jsonrpc/impl/method.c similarity index 100% rename from lib/jsonrpc/impl/method.c rename to lib/jsonrpc/src/jsonrpc/impl/method.c diff --git a/lib/jsonrpc/impl/method.h b/lib/jsonrpc/src/jsonrpc/impl/method.h similarity index 100% rename from lib/jsonrpc/impl/method.h rename to lib/jsonrpc/src/jsonrpc/impl/method.h diff --git a/lib/jsonrpc/impl/proxy.c b/lib/jsonrpc/src/jsonrpc/impl/proxy.c similarity index 100% rename from lib/jsonrpc/impl/proxy.c rename to lib/jsonrpc/src/jsonrpc/impl/proxy.c diff --git a/lib/jsonrpc/impl/proxy.h b/lib/jsonrpc/src/jsonrpc/impl/proxy.h similarity index 100% rename from lib/jsonrpc/impl/proxy.h rename to lib/jsonrpc/src/jsonrpc/impl/proxy.h diff --git a/lib/jsonrpc/impl/request.c b/lib/jsonrpc/src/jsonrpc/impl/request.c similarity index 100% rename from lib/jsonrpc/impl/request.c rename to lib/jsonrpc/src/jsonrpc/impl/request.c diff --git a/lib/jsonrpc/impl/request.h b/lib/jsonrpc/src/jsonrpc/impl/request.h similarity index 100% rename from lib/jsonrpc/impl/request.h rename to lib/jsonrpc/src/jsonrpc/impl/request.h diff --git a/lib/jsonrpc/impl/response.c b/lib/jsonrpc/src/jsonrpc/impl/response.c similarity index 100% rename from lib/jsonrpc/impl/response.c rename to lib/jsonrpc/src/jsonrpc/impl/response.c diff --git a/lib/jsonrpc/impl/response.h b/lib/jsonrpc/src/jsonrpc/impl/response.h similarity index 100% rename from lib/jsonrpc/impl/response.h rename to lib/jsonrpc/src/jsonrpc/impl/response.h diff --git a/lib/jsonrpc/impl/server.c b/lib/jsonrpc/src/jsonrpc/impl/server.c similarity index 100% rename from lib/jsonrpc/impl/server.c rename to lib/jsonrpc/src/jsonrpc/impl/server.c diff --git a/lib/jsonrpc/impl/server.h b/lib/jsonrpc/src/jsonrpc/impl/server.h similarity index 100% rename from lib/jsonrpc/impl/server.h rename to lib/jsonrpc/src/jsonrpc/impl/server.h diff --git a/lib/jsonrpc/impl/unused_param.h b/lib/jsonrpc/src/jsonrpc/impl/unused_param.h similarity index 100% rename from lib/jsonrpc/impl/unused_param.h rename to lib/jsonrpc/src/jsonrpc/impl/unused_param.h diff --git a/test/jsonrpc/test_is_request.cc b/lib/jsonrpc/test/jsonrpc/test_is_request.cc similarity index 100% rename from test/jsonrpc/test_is_request.cc rename to lib/jsonrpc/test/jsonrpc/test_is_request.cc diff --git a/test/jsonrpc/test_is_response.cc b/lib/jsonrpc/test/jsonrpc/test_is_response.cc similarity index 100% rename from test/jsonrpc/test_is_response.cc rename to lib/jsonrpc/test/jsonrpc/test_is_response.cc diff --git a/test/jsonrpc/test_proxy.cc b/lib/jsonrpc/test/jsonrpc/test_proxy.cc similarity index 100% rename from test/jsonrpc/test_proxy.cc rename to lib/jsonrpc/test/jsonrpc/test_proxy.cc diff --git a/test/jsonrpc/test_request.cc b/lib/jsonrpc/test/jsonrpc/test_request.cc similarity index 100% rename from test/jsonrpc/test_request.cc rename to lib/jsonrpc/test/jsonrpc/test_request.cc diff --git a/test/jsonrpc/test_response.cc b/lib/jsonrpc/test/jsonrpc/test_response.cc similarity index 100% rename from test/jsonrpc/test_response.cc rename to lib/jsonrpc/test/jsonrpc/test_response.cc diff --git a/test/jsonrpc/test_response_parser.cc b/lib/jsonrpc/test/jsonrpc/test_response_parser.cc similarity index 100% rename from test/jsonrpc/test_response_parser.cc rename to lib/jsonrpc/test/jsonrpc/test_response_parser.cc diff --git a/test/jsonrpc/test_server.cc b/lib/jsonrpc/test/jsonrpc/test_server.cc similarity index 100% rename from test/jsonrpc/test_server.cc rename to lib/jsonrpc/test/jsonrpc/test_server.cc diff --git a/test/jsonrpc/test_util.cc b/lib/jsonrpc/test/jsonrpc/test_util.cc similarity index 100% rename from test/jsonrpc/test_util.cc rename to lib/jsonrpc/test/jsonrpc/test_util.cc From 79318c47b8994060a864128f0e68d83c982bdc68 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 29 Feb 2020 21:06:40 +0100 Subject: [PATCH 067/138] refactor: extracted timer function of adapter into separate library --- CMakeLists.txt | 1 + cmake/jsonrpc.cmake | 10 +- cmake/unit_tests.cmake | 8 +- cmake/webfuse_adapter.cmake | 6 +- cmake/wf_timer.cmake | 18 +++ lib/jsonrpc/include/jsonrpc/proxy.h | 6 +- lib/jsonrpc/src/jsonrpc/api.c | 2 +- lib/jsonrpc/src/jsonrpc/impl/proxy.c | 29 ++-- lib/jsonrpc/src/jsonrpc/impl/proxy.h | 12 +- lib/jsonrpc/test/jsonrpc/test_proxy.cc | 84 ++++------ lib/webfuse/adapter/impl/server_protocol.c | 11 +- lib/webfuse/adapter/impl/server_protocol.h | 4 +- lib/webfuse/adapter/impl/session.c | 4 +- lib/webfuse/adapter/impl/session.h | 4 +- lib/webfuse/adapter/impl/session_manager.c | 4 +- lib/webfuse/adapter/impl/session_manager.h | 4 +- .../adapter/impl/time/timeout_manager.c | 84 ---------- .../adapter/impl/time/timeout_manager.h | 29 ---- .../impl/time/timeout_manager_intern.h | 24 --- lib/webfuse/adapter/impl/time/timepoint.c | 31 ---- lib/webfuse/adapter/impl/time/timepoint.h | 31 ---- lib/webfuse/adapter/impl/time/timer.c | 65 -------- lib/webfuse/adapter/impl/time/timer.h | 48 ------ lib/webfuse/adapter/impl/time/timer_intern.h | 25 --- lib/wf/timer/include/wf/timer.h | 9 ++ lib/wf/timer/include/wf/timer/api.h | 8 + lib/wf/timer/include/wf/timer/manager.h | 29 ++++ lib/wf/timer/include/wf/timer/on_timer_fn.h | 19 +++ lib/wf/timer/include/wf/timer/timer.h | 38 +++++ lib/wf/timer/src/wf/timer/api.c | 59 +++++++ lib/wf/timer/src/wf/timer/impl/manager.c | 96 +++++++++++ lib/wf/timer/src/wf/timer/impl/manager.h | 36 +++++ lib/wf/timer/src/wf/timer/impl/timepoint.c | 31 ++++ lib/wf/timer/src/wf/timer/impl/timepoint.h | 31 ++++ lib/wf/timer/src/wf/timer/impl/timer.c | 67 ++++++++ lib/wf/timer/src/wf/timer/impl/timer.h | 59 +++++++ lib/wf/timer/test/wf/timer/test_timepoint.cc | 36 +++++ lib/wf/timer/test/wf/timer/test_timer.cc | 136 ++++++++++++++++ test/webfuse/tests/adapter/test_timepoint.cc | 36 ----- test/webfuse/tests/adapter/test_timer.cc | 149 ------------------ 40 files changed, 765 insertions(+), 618 deletions(-) create mode 100644 cmake/wf_timer.cmake delete mode 100644 lib/webfuse/adapter/impl/time/timeout_manager.c delete mode 100644 lib/webfuse/adapter/impl/time/timeout_manager.h delete mode 100644 lib/webfuse/adapter/impl/time/timeout_manager_intern.h delete mode 100644 lib/webfuse/adapter/impl/time/timepoint.c delete mode 100644 lib/webfuse/adapter/impl/time/timepoint.h delete mode 100644 lib/webfuse/adapter/impl/time/timer.c delete mode 100644 lib/webfuse/adapter/impl/time/timer.h delete mode 100644 lib/webfuse/adapter/impl/time/timer_intern.h create mode 100644 lib/wf/timer/include/wf/timer.h create mode 100644 lib/wf/timer/include/wf/timer/api.h create mode 100644 lib/wf/timer/include/wf/timer/manager.h create mode 100644 lib/wf/timer/include/wf/timer/on_timer_fn.h create mode 100644 lib/wf/timer/include/wf/timer/timer.h create mode 100644 lib/wf/timer/src/wf/timer/api.c create mode 100644 lib/wf/timer/src/wf/timer/impl/manager.c create mode 100644 lib/wf/timer/src/wf/timer/impl/manager.h create mode 100644 lib/wf/timer/src/wf/timer/impl/timepoint.c create mode 100644 lib/wf/timer/src/wf/timer/impl/timepoint.h create mode 100644 lib/wf/timer/src/wf/timer/impl/timer.c create mode 100644 lib/wf/timer/src/wf/timer/impl/timer.h create mode 100644 lib/wf/timer/test/wf/timer/test_timepoint.cc create mode 100644 lib/wf/timer/test/wf/timer/test_timer.cc delete mode 100644 test/webfuse/tests/adapter/test_timepoint.cc delete mode 100644 test/webfuse/tests/adapter/test_timer.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e87f52..a856e45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ add_compile_options( "-pthread" ) +include(wf_timer) include(jsonrpc) include(webfuse_core) include(webfuse_adapter) diff --git a/cmake/jsonrpc.cmake b/cmake/jsonrpc.cmake index 76653bb..a7a643f 100644 --- a/cmake/jsonrpc.cmake +++ b/cmake/jsonrpc.cmake @@ -10,10 +10,16 @@ add_library(jsonrpc STATIC lib/jsonrpc/src/jsonrpc/impl/error.c ) -target_include_directories(jsonrpc PUBLIC - lib/jsonrpc/include +target_link_libraries(jsonrpc PUBLIC wf_timer) + +target_include_directories(jsonrpc PRIVATE + lib/wf/timer/include lib/jsonrpc/src lib ) +target_include_directories(jsonrpc PUBLIC + lib/jsonrpc/include +) + set_target_properties(jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index a6fbc8e..0ba1878 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -15,6 +15,8 @@ add_executable(alltests lib/jsonrpc/test/jsonrpc/test_server.cc lib/jsonrpc/test/jsonrpc/test_proxy.cc lib/jsonrpc/test/jsonrpc/test_response_parser.cc + lib/wf/timer/test/wf/timer/test_timepoint.cc + lib/wf/timer/test/wf/timer/test_timer.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc test/webfuse/utils/msleep.cc @@ -35,8 +37,6 @@ add_executable(alltests test/webfuse/tests/core/test_message_queue.cc test/webfuse/tests/adapter/test_server.cc test/webfuse/tests/adapter/test_server_config.cc - test/webfuse/tests/adapter/test_timepoint.cc - test/webfuse/tests/adapter/test_timer.cc test/webfuse/tests/adapter/test_credentials.cc test/webfuse/tests/adapter/test_authenticator.cc test/webfuse/tests/adapter/test_authenticators.cc @@ -53,6 +53,9 @@ add_executable(alltests target_include_directories(alltests PRIVATE lib/jsonrpc/include + lib/jsonrpc/src + lib/wf/timer/include + lib/wf/timer/src ${FUSE3_INCLUDE_DIRS} ${UUID_INCLUDE_DIRS} ) @@ -67,6 +70,7 @@ target_link_libraries(alltests PUBLIC webfuse-provider-static webfuse-core jsonrpc + wf_timer ${FUSE3_LIBRARIES} ${LWS_LIBRARIES} ${JANSSON_LIBRARIES} diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index 7362802..f6fb6af 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -19,9 +19,6 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/mountpoint_factory.c lib/webfuse/adapter/impl/uuid_mountpoint_factory.c lib/webfuse/adapter/impl/uuid_mountpoint.c - lib/webfuse/adapter/impl/time/timepoint.c - lib/webfuse/adapter/impl/time/timer.c - lib/webfuse/adapter/impl/time/timeout_manager.c lib/webfuse/adapter/impl/operation/lookup.c lib/webfuse/adapter/impl/operation/getattr.c lib/webfuse/adapter/impl/operation/readdir.c @@ -32,6 +29,7 @@ add_library(webfuse-adapter-static STATIC target_include_directories(webfuse-adapter-static PRIVATE lib + lib/wf/timer/include lib/jsonrpc/include ${FUSE3_INCLUDE_DIRS} ${UUID_INCLUDE_DIRS} @@ -65,7 +63,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 COMPILE_DEFINITIONS "WF_API=WF_EXPORT") -target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core jsonrpc) +target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core jsonrpc wf_timer) file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/wf_timer.cmake b/cmake/wf_timer.cmake new file mode 100644 index 0000000..8bdecf2 --- /dev/null +++ b/cmake/wf_timer.cmake @@ -0,0 +1,18 @@ +# 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) diff --git a/lib/jsonrpc/include/jsonrpc/proxy.h b/lib/jsonrpc/include/jsonrpc/proxy.h index d433253..3f2dca5 100644 --- a/lib/jsonrpc/include/jsonrpc/proxy.h +++ b/lib/jsonrpc/include/jsonrpc/proxy.h @@ -16,18 +16,16 @@ using std::size_t; #include #include -#include "webfuse/adapter/impl/time/timeout_manager.h" -#include "webfuse/adapter/impl/time/timer.h" - #ifdef __cplusplus extern "C" { #endif struct jsonrpc_proxy; +struct wf_timer_manager; extern JSONRPC_API struct jsonrpc_proxy * jsonrpc_proxy_create( - struct wf_impl_timeout_manager * manager, + struct wf_timer_manager * manager, int timeout, jsonrpc_send_fn * send, void * user_data); diff --git a/lib/jsonrpc/src/jsonrpc/api.c b/lib/jsonrpc/src/jsonrpc/api.c index a6d7d1c..817438c 100644 --- a/lib/jsonrpc/src/jsonrpc/api.c +++ b/lib/jsonrpc/src/jsonrpc/api.c @@ -9,7 +9,7 @@ struct jsonrpc_proxy * jsonrpc_proxy_create( - struct wf_impl_timeout_manager * manager, + struct wf_timer_manager * manager, int timeout, jsonrpc_send_fn * send, void * user_data) diff --git a/lib/jsonrpc/src/jsonrpc/impl/proxy.c b/lib/jsonrpc/src/jsonrpc/impl/proxy.c index 446cd91..fa4f3ad 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/proxy.c +++ b/lib/jsonrpc/src/jsonrpc/impl/proxy.c @@ -3,12 +3,14 @@ #include "jsonrpc/impl/error.h" #include "jsonrpc/status.h" +#include + #include #include struct jsonrpc_proxy * jsonrpc_impl_proxy_create( - struct wf_impl_timeout_manager * manager, + struct wf_timer_manager * manager, int timeout, jsonrpc_send_fn * send, void * user_data) @@ -29,10 +31,10 @@ void jsonrpc_impl_proxy_dispose( free(proxy); } -static void jsonrpc_impl_proxy_timeout( - struct wf_impl_timer * timer) +static void jsonrpc_impl_proxy_on_timeout( + struct wf_timer * timer, void * proxy_ptr) { - struct jsonrpc_proxy * proxy = timer->user_data; + struct jsonrpc_proxy * proxy = proxy_ptr; if (proxy->request.is_pending) { @@ -43,7 +45,7 @@ static void jsonrpc_impl_proxy_timeout( proxy->request.id = 0; proxy->request.user_data = NULL; proxy->request.finished = NULL; - wf_impl_timer_cancel(&proxy->request.timer); + wf_timer_cancel(timer); jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD_TIMEOUT, "Timeout"); } @@ -95,7 +97,7 @@ static json_t * jsonrpc_impl_request_create( void jsonrpc_impl_proxy_init( struct jsonrpc_proxy * proxy, - struct wf_impl_timeout_manager * timeout_manager, + struct wf_timer_manager * timeout_manager, int timeout, jsonrpc_send_fn * send, void * user_data) @@ -104,8 +106,8 @@ void jsonrpc_impl_proxy_init( proxy->timeout = timeout; proxy->user_data = user_data; proxy->request.is_pending = false; - - wf_impl_timer_init(&proxy->request.timer, timeout_manager); + proxy->request.timer = wf_timer_create(timeout_manager, + &jsonrpc_impl_proxy_on_timeout, proxy); } void jsonrpc_impl_proxy_cleanup( @@ -120,12 +122,12 @@ void jsonrpc_impl_proxy_cleanup( proxy->request.finished = NULL; proxy->request.user_data = NULL; proxy->request.id = 0; - wf_impl_timer_cancel(&proxy->request.timer); + wf_timer_cancel(proxy->request.timer); jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); } - wf_impl_timer_cleanup(&proxy->request.timer); + wf_timer_dispose(proxy->request.timer); } void jsonrpc_impl_proxy_invoke( @@ -143,8 +145,7 @@ void jsonrpc_impl_proxy_invoke( proxy->request.finished = finished; proxy->request.user_data = user_data; proxy->request.id = 42; - wf_impl_timer_start(&proxy->request.timer, wf_impl_timepoint_in_msec(proxy->timeout), - &jsonrpc_impl_proxy_timeout, proxy); + wf_timer_start(proxy->request.timer, proxy->timeout); json_t * request = jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args); @@ -155,7 +156,7 @@ void jsonrpc_impl_proxy_invoke( proxy->request.finished = NULL; proxy->request.user_data = NULL; proxy->request.id = 0; - wf_impl_timer_cancel(&proxy->request.timer); + wf_timer_cancel(proxy->request.timer); jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); } @@ -203,7 +204,7 @@ void jsonrpc_impl_proxy_onresult( proxy->request.id = 0; proxy->request.user_data = NULL; proxy->request.finished = NULL; - wf_impl_timer_cancel(&proxy->request.timer); + wf_timer_cancel(proxy->request.timer); finished(user_data, response.result, response.error); } diff --git a/lib/jsonrpc/src/jsonrpc/impl/proxy.h b/lib/jsonrpc/src/jsonrpc/impl/proxy.h index 0556e0d..940f853 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/proxy.h +++ b/lib/jsonrpc/src/jsonrpc/impl/proxy.h @@ -4,21 +4,21 @@ #include "jsonrpc/proxy_finished_fn.h" #include "jsonrpc/send_fn.h" -#include "webfuse/adapter/impl/time/timeout_manager.h" -#include "webfuse/adapter/impl/time/timer.h" - #ifdef __cplusplus extern "C" { #endif +struct wf_timer_manager; +struct wf_timer; + struct jsonrpc_request { bool is_pending; jsonrpc_proxy_finished_fn * finished; void * user_data; int id; - struct wf_impl_timer timer; + struct wf_timer * timer; }; struct jsonrpc_proxy @@ -32,7 +32,7 @@ struct jsonrpc_proxy extern void jsonrpc_impl_proxy_init( struct jsonrpc_proxy * proxy, - struct wf_impl_timeout_manager * manager, + struct wf_timer_manager * manager, int timeout, jsonrpc_send_fn * send, void * user_data); @@ -43,7 +43,7 @@ jsonrpc_impl_proxy_cleanup( extern struct jsonrpc_proxy * jsonrpc_impl_proxy_create( - struct wf_impl_timeout_manager * manager, + struct wf_timer_manager * manager, int timeout, jsonrpc_send_fn * send, void * user_data); diff --git a/lib/jsonrpc/test/jsonrpc/test_proxy.cc b/lib/jsonrpc/test/jsonrpc/test_proxy.cc index 834a7ef..cc71ae8 100644 --- a/lib/jsonrpc/test/jsonrpc/test_proxy.cc +++ b/lib/jsonrpc/test/jsonrpc/test_proxy.cc @@ -1,6 +1,6 @@ #include #include "jsonrpc/proxy.h" -#include "webfuse/adapter/impl/time/timeout_manager.h" +#include "wf/timer/manager.h" #include "webfuse/utils/msleep.hpp" #include "webfuse/core/json_util.h" @@ -87,27 +87,25 @@ namespace TEST(jsonrpc_proxy, init) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext context; void * user_data = reinterpret_cast(&context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); ASSERT_FALSE(context.is_called); } TEST(jsonrpc_proxy, invoke) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); @@ -134,7 +132,7 @@ TEST(jsonrpc_proxy, invoke) ASSERT_FALSE(finished_context.is_called); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); ASSERT_TRUE(finished_context.is_called); ASSERT_FALSE(nullptr == finished_context.error); @@ -142,12 +140,11 @@ TEST(jsonrpc_proxy, invoke) TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context(false); void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); @@ -160,17 +157,16 @@ TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails) ASSERT_FALSE(nullptr == finished_context.error); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); @@ -189,17 +185,16 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending) ASSERT_EQ(WF_BAD_BUSY, wf_impl_jsonrpc_get_status(finished_context2.error)); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } TEST(jsonrpc_proxy, invoke_fails_if_request_is_invalid) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); @@ -211,17 +206,16 @@ TEST(jsonrpc_proxy, invoke_fails_if_request_is_invalid) ASSERT_EQ(WF_BAD, wf_impl_jsonrpc_get_status(finished_context.error)); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } TEST(jsonrpc_proxy, on_result) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); @@ -246,17 +240,16 @@ TEST(jsonrpc_proxy, on_result) ASSERT_STREQ("okay", json_string_value(finished_context.result)); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); @@ -278,17 +271,16 @@ TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id) ASSERT_FALSE(finished_context.is_called); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } TEST(jsonrpc_proxy, timeout) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, 0, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); @@ -298,23 +290,22 @@ TEST(jsonrpc_proxy, timeout) ASSERT_TRUE(json_is_object(send_context.response)); msleep(10); - wf_impl_timeout_manager_check(&timeout_manager); + wf_timer_manager_check(timer_manager); ASSERT_TRUE(finished_context.is_called); ASSERT_EQ(WF_BAD_TIMEOUT, wf_impl_jsonrpc_get_status(finished_context.error)); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } TEST(jsonrpc_proxy, cleanup_pending_request) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, 10, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); @@ -324,26 +315,23 @@ TEST(jsonrpc_proxy, cleanup_pending_request) ASSERT_TRUE(json_is_object(send_context.response)); ASSERT_FALSE(finished_context.is_called); - ASSERT_NE(nullptr, timeout_manager.timers); jsonrpc_proxy_dispose(proxy); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(nullptr, timeout_manager.timers); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } TEST(jsonrpc_proxy, notify) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42); @@ -365,24 +353,22 @@ TEST(jsonrpc_proxy, notify) json_t * id = json_object_get(send_context.response, "id"); ASSERT_EQ(nullptr, id); - jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } TEST(jsonrpc_proxy, notify_dont_send_invalid_request) { - struct wf_impl_timeout_manager timeout_manager; - wf_impl_timeout_manager_init(&timeout_manager); + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(&timeout_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); jsonrpc_proxy_notify(proxy, "foo", "?"); ASSERT_FALSE(send_context.is_called); jsonrpc_proxy_dispose(proxy); - wf_impl_timeout_manager_cleanup(&timeout_manager); + wf_timer_manager_dispose(timer_manager); } diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 061fa5c..7bf17c9 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -13,6 +13,9 @@ #include "webfuse/adapter/impl/uuid_mountpoint_factory.h" #include "webfuse/core/status_intern.h" +#include "wf/timer/manager.h" +#include "wf/timer/timer.h" + static int wf_impl_server_protocol_callback( struct lws * wsi, enum lws_callback_reasons reason, @@ -28,7 +31,7 @@ static int wf_impl_server_protocol_callback( struct wf_server_protocol * protocol = ws_protocol->user; - wf_impl_timeout_manager_check(&protocol->timeout_manager); + wf_timer_manager_check(protocol->timer_manager); struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi); switch (reason) @@ -42,7 +45,7 @@ static int wf_impl_server_protocol_callback( wsi, &protocol->authenticators, &protocol->mountpoint_factory, - &protocol->timeout_manager, + protocol->timer_manager, protocol->server); if (NULL != session) @@ -237,7 +240,7 @@ void wf_impl_server_protocol_init( wf_impl_mountpoint_factory_move(mountpoint_factory, &protocol->mountpoint_factory); - wf_impl_timeout_manager_init(&protocol->timeout_manager); + protocol->timer_manager = wf_timer_manager_create(); wf_impl_session_manager_init(&protocol->session_manager); wf_impl_authenticators_init(&protocol->authenticators); @@ -252,7 +255,7 @@ void wf_impl_server_protocol_cleanup( protocol->is_operational = false; jsonrpc_server_dispose(protocol->server); - wf_impl_timeout_manager_cleanup(&protocol->timeout_manager); + wf_timer_manager_dispose(protocol->timer_manager); wf_impl_authenticators_cleanup(&protocol->authenticators); wf_impl_session_manager_cleanup(&protocol->session_manager); wf_impl_mountpoint_factory_cleanup(&protocol->mountpoint_factory); diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 0677c84..0a9fdbd 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -2,7 +2,6 @@ #define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H #include "jsonrpc/proxy.h" -#include "webfuse/adapter/impl/time/timeout_manager.h" #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/session_manager.h" @@ -18,14 +17,15 @@ extern "C" #endif struct lws_protocols; +struct wf_timer_manager; struct wf_server_protocol { - struct wf_impl_timeout_manager timeout_manager; struct wf_impl_authenticators authenticators; struct wf_impl_mountpoint_factory mountpoint_factory; struct wf_impl_session_manager session_manager; struct jsonrpc_server * server; + struct wf_timer_manager * timer_manager; bool is_operational; }; diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index deafb92..870f6c0 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -44,7 +44,7 @@ static bool wf_impl_session_send( struct wf_impl_session * wf_impl_session_create( struct lws * wsi, struct wf_impl_authenticators * authenticators, - struct wf_impl_timeout_manager * timeout_manager, + struct wf_timer_manager * timer_manager, struct jsonrpc_server * server, struct wf_impl_mountpoint_factory * mountpoint_factory) { @@ -59,7 +59,7 @@ struct wf_impl_session * wf_impl_session_create( session->authenticators = authenticators; session->server = server; session->mountpoint_factory = mountpoint_factory; - session->rpc = jsonrpc_proxy_create(timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); + session->rpc = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); wf_slist_init(&session->messages); } diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h index cc95911..a9d15af 100644 --- a/lib/webfuse/adapter/impl/session.h +++ b/lib/webfuse/adapter/impl/session.h @@ -25,7 +25,7 @@ struct wf_message; struct wf_credentials; struct wf_impl_authenticators; struct wf_impl_mountpoint_factory; -struct wf_impl_timeout_manager; +struct timer_manager; struct wf_impl_session { @@ -43,7 +43,7 @@ struct wf_impl_session extern struct wf_impl_session * wf_impl_session_create( struct lws * wsi, struct wf_impl_authenticators * authenticators, - struct wf_impl_timeout_manager * timeout_manager, + struct wf_timer_manager * timer_manager, struct jsonrpc_server * server, struct wf_impl_mountpoint_factory * mountpoint_factory); diff --git a/lib/webfuse/adapter/impl/session_manager.c b/lib/webfuse/adapter/impl/session_manager.c index e7e109d..6474c06 100644 --- a/lib/webfuse/adapter/impl/session_manager.c +++ b/lib/webfuse/adapter/impl/session_manager.c @@ -28,11 +28,11 @@ struct wf_impl_session * wf_impl_session_manager_add( struct lws * wsi, struct wf_impl_authenticators * authenticators, struct wf_impl_mountpoint_factory * mountpoint_factory, - struct wf_impl_timeout_manager * timeout_manager, + struct wf_timer_manager * timer_manager, struct jsonrpc_server * server) { struct wf_impl_session * session = wf_impl_session_create( - wsi, authenticators, timeout_manager, server, mountpoint_factory); + wsi, authenticators, timer_manager, server, mountpoint_factory); if (NULL != session) { wf_slist_append(&manager->sessions, &session->item); diff --git a/lib/webfuse/adapter/impl/session_manager.h b/lib/webfuse/adapter/impl/session_manager.h index 51c8910..4f5f218 100644 --- a/lib/webfuse/adapter/impl/session_manager.h +++ b/lib/webfuse/adapter/impl/session_manager.h @@ -15,7 +15,7 @@ extern "C" #endif struct lws; -struct wf_impl_timeout_manager; +struct wf_timer_manager; struct jsonrpc_server; struct wf_impl_session_manager @@ -34,7 +34,7 @@ extern struct wf_impl_session * wf_impl_session_manager_add( struct lws * wsi, struct wf_impl_authenticators * authenticators, struct wf_impl_mountpoint_factory * mountpoint_factory, - struct wf_impl_timeout_manager * timeout_manager, + struct wf_timer_manager * timer_manager, struct jsonrpc_server * server); extern struct wf_impl_session * wf_impl_session_manager_get( diff --git a/lib/webfuse/adapter/impl/time/timeout_manager.c b/lib/webfuse/adapter/impl/time/timeout_manager.c deleted file mode 100644 index 155ffe6..0000000 --- a/lib/webfuse/adapter/impl/time/timeout_manager.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "webfuse/adapter/impl/time/timeout_manager_intern.h" - -#include -#include "webfuse/adapter/impl/time/timer_intern.h" -#include "webfuse/adapter/impl/time/timepoint.h" - -void wf_impl_timeout_manager_init( - struct wf_impl_timeout_manager * manager) -{ - manager->timers = NULL; -} - -void wf_impl_timeout_manager_cleanup( - struct wf_impl_timeout_manager * manager) -{ - struct wf_impl_timer * timer = manager->timers; - while (NULL != timer) - { - struct wf_impl_timer * next = timer->next; - - wf_impl_timer_trigger(timer); - - timer = next; - } - - manager->timers = NULL; - -} - -void wf_impl_timeout_manager_check( - struct wf_impl_timeout_manager * manager) -{ - struct wf_impl_timer * timer = manager->timers; - while (NULL != timer) - { - struct wf_impl_timer * next = timer->next; - - if (wf_impl_timer_is_timeout(timer)) - { - wf_impl_timeout_manager_removetimer(manager, timer); - wf_impl_timer_trigger(timer); - } - - timer = next; - } -} - -void wf_impl_timeout_manager_addtimer( - struct wf_impl_timeout_manager * manager, - struct wf_impl_timer * timer) -{ - if (NULL != manager->timers) - { - manager->timers->prev = timer; - } - - timer->next = manager->timers; - timer->prev = NULL; - manager->timers = timer; -} - -void wf_impl_timeout_manager_removetimer( - struct wf_impl_timeout_manager * manager, - struct wf_impl_timer * timer) -{ - struct wf_impl_timer * prev = timer->prev; - struct wf_impl_timer * next = timer->next; - - if (NULL != prev) - { - prev->next = next; - } - - if (NULL != next) - { - next->prev = prev; - } - - if (manager->timers == timer) - { - manager->timers = next; - } -} - diff --git a/lib/webfuse/adapter/impl/time/timeout_manager.h b/lib/webfuse/adapter/impl/time/timeout_manager.h deleted file mode 100644 index 0e33c1b..0000000 --- a/lib/webfuse/adapter/impl/time/timeout_manager.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H -#define WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_impl_timer; -struct wf_impl_timeout_manager -{ - struct wf_impl_timer * timers; -}; - -extern void wf_impl_timeout_manager_init( - struct wf_impl_timeout_manager * manager); - -extern void wf_impl_timeout_manager_cleanup( - struct wf_impl_timeout_manager * manager); - -extern void wf_impl_timeout_manager_check( - struct wf_impl_timeout_manager * manager); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/webfuse/adapter/impl/time/timeout_manager_intern.h b/lib/webfuse/adapter/impl/time/timeout_manager_intern.h deleted file mode 100644 index 67ee0f8..0000000 --- a/lib/webfuse/adapter/impl/time/timeout_manager_intern.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H -#define WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H - -#include "webfuse/adapter/impl/time/timeout_manager.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern void wf_impl_timeout_manager_addtimer( - struct wf_impl_timeout_manager * manager, - struct wf_impl_timer * timer); - -extern void wf_impl_timeout_manager_removetimer( - struct wf_impl_timeout_manager * manager, - struct wf_impl_timer * timer); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/webfuse/adapter/impl/time/timepoint.c b/lib/webfuse/adapter/impl/time/timepoint.c deleted file mode 100644 index 8425000..0000000 --- a/lib/webfuse/adapter/impl/time/timepoint.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "webfuse/adapter/impl/time/timepoint.h" - -#include - -#define WF_MSEC_PER_SEC ((wf_impl_timepoint) 1000) -#define WF_NSEC_PER_MSEC ((wf_impl_timepoint) 1000 * 1000) - -wf_impl_timepoint wf_impl_timepoint_now(void) -{ - struct timespec tp; - clock_gettime(CLOCK_MONOTONIC, &tp); - - wf_impl_timepoint const now = (tp.tv_sec * WF_MSEC_PER_SEC) + (tp.tv_nsec / WF_NSEC_PER_MSEC); - return now; -} - -wf_impl_timepoint wf_impl_timepoint_in_msec(wf_impl_timediff value) -{ - wf_impl_timepoint const now = wf_impl_timepoint_now(); - wf_impl_timepoint result = now + ((wf_impl_timepoint) value); - - return result; -} - -bool wf_impl_timepoint_is_elapsed(wf_impl_timepoint tp) -{ - wf_impl_timepoint const now = wf_impl_timepoint_now(); - wf_impl_timediff const diff = (wf_impl_timediff) (tp - now); - - return (0 > diff); -} diff --git a/lib/webfuse/adapter/impl/time/timepoint.h b/lib/webfuse/adapter/impl/time/timepoint.h deleted file mode 100644 index c9f6560..0000000 --- a/lib/webfuse/adapter/impl/time/timepoint.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_TIME_TIMEPOINT_H -#define WF_ADAPTER_IMPL_TIME_TIMEPOINT_H - -#ifndef __cplusplus -#include -#include -#else -#include -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -typedef uint64_t wf_impl_timepoint; -typedef int64_t wf_impl_timediff; - -extern wf_impl_timepoint wf_impl_timepoint_now(void); - -extern wf_impl_timepoint wf_impl_timepoint_in_msec( - wf_impl_timediff value); - -extern bool wf_impl_timepoint_is_elapsed( - wf_impl_timepoint timepoint); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/webfuse/adapter/impl/time/timer.c b/lib/webfuse/adapter/impl/time/timer.c deleted file mode 100644 index 9d1da17..0000000 --- a/lib/webfuse/adapter/impl/time/timer.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "webfuse/adapter/impl/time/timer_intern.h" -#include "webfuse/adapter/impl/time/timeout_manager_intern.h" - -#include -#include - -void wf_impl_timer_init( - struct wf_impl_timer * timer, - struct wf_impl_timeout_manager * manager) -{ - timer->manager = manager; - timer->timeout = 0; - timer->timeout_handler = NULL; - timer->user_data = NULL; - timer->prev = NULL; - timer->next = NULL; -} - -void wf_impl_timer_cleanup( - struct wf_impl_timer * timer) -{ - memset(timer, 0, sizeof(struct wf_impl_timer)); -} - -void wf_impl_timer_start( - struct wf_impl_timer * timer, - wf_impl_timepoint absolute_timeout, - wf_impl_timer_timeout_fn * handler, - void * user_data) -{ - timer->timeout = absolute_timeout; - timer->timeout_handler = handler; - timer->user_data = user_data; - - wf_impl_timeout_manager_addtimer(timer->manager, timer); -} - -void wf_impl_timer_cancel( - struct wf_impl_timer * timer) -{ - wf_impl_timeout_manager_removetimer(timer->manager, timer); - - timer->timeout = 0; - timer->timeout_handler = NULL; - timer->user_data = NULL; -} - -bool wf_impl_timer_is_timeout( - struct wf_impl_timer * timer) -{ - return wf_impl_timepoint_is_elapsed(timer->timeout); -} - - -void wf_impl_timer_trigger( - struct wf_impl_timer * timer) -{ - if (NULL != timer->timeout_handler) - { - timer->prev = NULL; - timer->next = NULL; - - timer->timeout_handler(timer); - } -} diff --git a/lib/webfuse/adapter/impl/time/timer.h b/lib/webfuse/adapter/impl/time/timer.h deleted file mode 100644 index bbc840d..0000000 --- a/lib/webfuse/adapter/impl/time/timer.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_TIME_TIMER_H -#define WF_ADAPTER_IMPL_TIME_TIMER_H - -#include "webfuse/adapter/impl/time/timepoint.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_impl_timer; -struct wf_impl_timeout_manager; - -typedef void wf_impl_timer_timeout_fn(struct wf_impl_timer * timer); - -struct wf_impl_timer -{ - struct wf_impl_timeout_manager * manager; - wf_impl_timepoint timeout; - wf_impl_timer_timeout_fn * timeout_handler; - void * user_data; - struct wf_impl_timer * next; - struct wf_impl_timer * prev; -}; - -extern void wf_impl_timer_init( - struct wf_impl_timer * timer, - struct wf_impl_timeout_manager * manager); - -extern void wf_impl_timer_cleanup( - struct wf_impl_timer * timer); - -extern void wf_impl_timer_start( - struct wf_impl_timer * timer, - wf_impl_timepoint absolute_timeout, - wf_impl_timer_timeout_fn * handler, - void * user_data); - -extern void wf_impl_timer_cancel( - struct wf_impl_timer * timer); - -#ifdef __cplusplus -} -#endif - - - -#endif diff --git a/lib/webfuse/adapter/impl/time/timer_intern.h b/lib/webfuse/adapter/impl/time/timer_intern.h deleted file mode 100644 index 6f1f19f..0000000 --- a/lib/webfuse/adapter/impl/time/timer_intern.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_TIME_TIMER_INTERN_H -#define WF_ADAPTER_IMPL_TIME_TIMER_INTERN_H - -#ifndef __cplusplus -#include -#endif - -#include "webfuse/adapter/impl/time/timer.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern bool wf_impl_timer_is_timeout( - struct wf_impl_timer * timer); - -extern void wf_impl_timer_trigger( - struct wf_impl_timer * timer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wf/timer/include/wf/timer.h b/lib/wf/timer/include/wf/timer.h new file mode 100644 index 0000000..341792b --- /dev/null +++ b/lib/wf/timer/include/wf/timer.h @@ -0,0 +1,9 @@ +#ifndef WF_TIMER_H +#define WF_TIMER_H + +#include +#include +#include +#include + +#endif diff --git a/lib/wf/timer/include/wf/timer/api.h b/lib/wf/timer/include/wf/timer/api.h new file mode 100644 index 0000000..c327ba7 --- /dev/null +++ b/lib/wf/timer/include/wf/timer/api.h @@ -0,0 +1,8 @@ +#ifndef WF_TIMER_API_H +#define WF_TIMER_API_H + +#ifndef WF_TIMER_API +#define WF_TIMER_API +#endif + +#endif diff --git a/lib/wf/timer/include/wf/timer/manager.h b/lib/wf/timer/include/wf/timer/manager.h new file mode 100644 index 0000000..e0febc0 --- /dev/null +++ b/lib/wf/timer/include/wf/timer/manager.h @@ -0,0 +1,29 @@ +#ifndef WF_TIMER_MANAGER_H +#define WF_TIMER_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_timer_manager; + +extern WF_TIMER_API struct wf_timer_manager * +wf_timer_manager_create(void); + +extern WF_TIMER_API void +wf_timer_manager_dispose( + struct wf_timer_manager * manager); + +extern WF_TIMER_API void +wf_timer_manager_check( + struct wf_timer_manager * manager); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/wf/timer/include/wf/timer/on_timer_fn.h b/lib/wf/timer/include/wf/timer/on_timer_fn.h new file mode 100644 index 0000000..d250bae --- /dev/null +++ b/lib/wf/timer/include/wf/timer/on_timer_fn.h @@ -0,0 +1,19 @@ +#ifndef WF_TIMER_ON_TIMER_FN_H +#define WF_TIMER_ON_TIMER_FN_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_timer; + +typedef void wf_timer_on_timer_fn( + struct wf_timer * timer, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wf/timer/include/wf/timer/timer.h b/lib/wf/timer/include/wf/timer/timer.h new file mode 100644 index 0000000..686eb89 --- /dev/null +++ b/lib/wf/timer/include/wf/timer/timer.h @@ -0,0 +1,38 @@ +#ifndef WF_TIMER_TIMER_H +#define WF_TIMER_TIMER_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_timer; +struct wf_timer_manager; + +extern WF_TIMER_API struct wf_timer * +wf_timer_create( + struct wf_timer_manager * manager, + wf_timer_on_timer_fn * on_timer, + void * user_data); + +extern WF_TIMER_API void +wf_timer_dispose( + struct wf_timer * timer); + +extern WF_TIMER_API void +wf_timer_start( + struct wf_timer * timer, + int timeout_ms); + +extern WF_TIMER_API void +wf_timer_cancel( + struct wf_timer * timer); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wf/timer/src/wf/timer/api.c b/lib/wf/timer/src/wf/timer/api.c new file mode 100644 index 0000000..d0399a9 --- /dev/null +++ b/lib/wf/timer/src/wf/timer/api.c @@ -0,0 +1,59 @@ +#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); +} diff --git a/lib/wf/timer/src/wf/timer/impl/manager.c b/lib/wf/timer/src/wf/timer/impl/manager.c new file mode 100644 index 0000000..2b00f80 --- /dev/null +++ b/lib/wf/timer/src/wf/timer/impl/manager.c @@ -0,0 +1,96 @@ +#include "wf/timer/impl/manager.h" +#include "wf/timer/impl/timer.h" +#include "wf/timer/impl/timepoint.h" + +#include +#include + +struct wf_timer_manager +{ + struct wf_timer * timers; +}; + +struct wf_timer_manager * +wf_timer_impl_manager_create(void) +{ + struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager)); + if (NULL != manager) + { + manager->timers = NULL; + } + + return manager; +} + +void +wf_timer_impl_manager_dispose( + struct wf_timer_manager * manager) +{ + struct wf_timer * timer = manager->timers; + while (NULL != timer) + { + struct wf_timer * next = timer->next; + + wf_timer_impl_trigger(timer); + timer = next; + } + + free(manager); +} + + +void wf_timer_impl_manager_check( + struct wf_timer_manager * manager) +{ + struct wf_timer * timer = manager->timers; + while (NULL != timer) + { + struct wf_timer * next = timer->next; + + if (wf_timer_impl_is_timeout(timer)) + { + wf_timer_impl_manager_removetimer(manager, timer); + wf_timer_impl_trigger(timer); + } + + timer = next; + } +} + +void wf_timer_impl_manager_addtimer( + struct wf_timer_manager * manager, + struct wf_timer * timer) +{ + if (NULL != manager->timers) + { + manager->timers->prev = timer; + } + + timer->next = manager->timers; + timer->prev = NULL; + manager->timers = timer; +} + +void wf_timer_impl_manager_removetimer( + struct wf_timer_manager * manager, + struct wf_timer * timer) +{ + struct wf_timer * prev = timer->prev; + struct wf_timer * next = timer->next; + + if (NULL != prev) + { + prev->next = next; + } + + if (NULL != next) + { + next->prev = prev; + } + + if (manager->timers == timer) + { + manager->timers = next; + } +} + diff --git a/lib/wf/timer/src/wf/timer/impl/manager.h b/lib/wf/timer/src/wf/timer/impl/manager.h new file mode 100644 index 0000000..c4fc64a --- /dev/null +++ b/lib/wf/timer/src/wf/timer/impl/manager.h @@ -0,0 +1,36 @@ +#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 diff --git a/lib/wf/timer/src/wf/timer/impl/timepoint.c b/lib/wf/timer/src/wf/timer/impl/timepoint.c new file mode 100644 index 0000000..877b9c9 --- /dev/null +++ b/lib/wf/timer/src/wf/timer/impl/timepoint.c @@ -0,0 +1,31 @@ +#include "wf/timer/impl/timepoint.h" + +#include + +#define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 1000) +#define WF_TIMER_NSEC_PER_MSEC ((wf_timer_timepoint) 1000 * 1000) + +wf_timer_timepoint wf_timer_impl_timepoint_now(void) +{ + struct timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + + wf_timer_timepoint const now = (tp.tv_sec * WF_TIMER_MSEC_PER_SEC) + (tp.tv_nsec / WF_TIMER_NSEC_PER_MSEC); + return now; +} + +wf_timer_timepoint wf_timer_impl_timepoint_in_msec(wf_timer_timediff value) +{ + wf_timer_timepoint const now = wf_timer_impl_timepoint_now(); + wf_timer_timepoint result = now + ((wf_timer_timepoint) value); + + return result; +} + +bool wf_timer_impl_timepoint_is_elapsed(wf_timer_timepoint tp) +{ + wf_timer_timepoint const now = wf_timer_impl_timepoint_now(); + wf_timer_timediff const diff = (wf_timer_timediff) (tp - now); + + return (0 > diff); +} diff --git a/lib/wf/timer/src/wf/timer/impl/timepoint.h b/lib/wf/timer/src/wf/timer/impl/timepoint.h new file mode 100644 index 0000000..584aa92 --- /dev/null +++ b/lib/wf/timer/src/wf/timer/impl/timepoint.h @@ -0,0 +1,31 @@ +#ifndef WF_TIMER_IMPL_TIMEPOINT_H +#define WF_TIMER_IMPL_TIMEPOINT_H + +#ifndef __cplusplus +#include +#include +#else +#include +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef uint64_t wf_timer_timepoint; +typedef int64_t wf_timer_timediff; + +extern wf_timer_timepoint wf_timer_impl_timepoint_now(void); + +extern wf_timer_timepoint wf_timer_impl_timepoint_in_msec( + wf_timer_timediff value); + +extern bool wf_timer_impl_timepoint_is_elapsed( + wf_timer_timepoint timepoint); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wf/timer/src/wf/timer/impl/timer.c b/lib/wf/timer/src/wf/timer/impl/timer.c new file mode 100644 index 0000000..5559451 --- /dev/null +++ b/lib/wf/timer/src/wf/timer/impl/timer.c @@ -0,0 +1,67 @@ +#include "wf/timer/impl/timer.h" +#include "wf/timer/impl/manager.h" +#include "wf/timer/impl/timepoint.h" + +#include +#include +#include + +struct wf_timer * +wf_timer_impl_create( + struct wf_timer_manager * manager, + wf_timer_on_timer_fn * on_timer, + void * user_data) +{ + struct wf_timer * timer = malloc(sizeof(struct wf_timer)); + timer->manager = manager; + timer->timeout = 0; + timer->on_timer = on_timer; + timer->user_data = user_data; + timer->prev = NULL; + timer->next = NULL; + + return timer; +} + +void +wf_timer_impl_dispose( + struct wf_timer * timer) +{ + free(timer); +} + +void wf_timer_impl_start( + struct wf_timer * timer, + int timeout_ms) +{ + timer->timeout = wf_timer_impl_timepoint_in_msec(timeout_ms); + + wf_timer_impl_manager_addtimer(timer->manager, timer); +} + +void wf_timer_impl_cancel( + struct wf_timer * timer) +{ + wf_timer_impl_manager_removetimer(timer->manager, timer); + + timer->timeout = 0; +} + +bool wf_timer_impl_is_timeout( + struct wf_timer * timer) +{ + return wf_timer_impl_timepoint_is_elapsed(timer->timeout); +} + + +void wf_timer_impl_trigger( + struct wf_timer * timer) +{ + if (0 != timer->on_timer) + { + timer->prev = NULL; + timer->next = NULL; + + timer->on_timer(timer, timer->user_data); + } +} diff --git a/lib/wf/timer/src/wf/timer/impl/timer.h b/lib/wf/timer/src/wf/timer/impl/timer.h new file mode 100644 index 0000000..2e18a8b --- /dev/null +++ b/lib/wf/timer/src/wf/timer/impl/timer.h @@ -0,0 +1,59 @@ +#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 +#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 diff --git a/lib/wf/timer/test/wf/timer/test_timepoint.cc b/lib/wf/timer/test/wf/timer/test_timepoint.cc new file mode 100644 index 0000000..bd7774a --- /dev/null +++ b/lib/wf/timer/test/wf/timer/test_timepoint.cc @@ -0,0 +1,36 @@ +#include + +#include "webfuse/utils/msleep.hpp" +#include "wf/timer/impl/timepoint.h" + +using webfuse_test::msleep; + +TEST(wf_timer_timepoint, now) +{ + wf_timer_timepoint start = wf_timer_impl_timepoint_now(); + msleep(42); + 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)); +} diff --git a/lib/wf/timer/test/wf/timer/test_timer.cc b/lib/wf/timer/test/wf/timer/test_timer.cc new file mode 100644 index 0000000..ffeb1d3 --- /dev/null +++ b/lib/wf/timer/test/wf/timer/test_timer.cc @@ -0,0 +1,136 @@ +#include + +#include + +#include "webfuse/utils/msleep.hpp" +#include "wf/timer/timer.h" +#include "wf/timer/manager.h" + +using std::size_t; +using webfuse_test::msleep; + +extern "C" +{ + void on_timeout(struct wf_timer * timer, void * user_data) + { + (void) timer; + + bool * triggered = reinterpret_cast(user_data); + *triggered = true; + } +} + +TEST(wf_timer, init) +{ + bool triggered = false; + struct wf_timer_manager * manager = wf_timer_manager_create(); + struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); + + wf_timer_dispose(timer); + wf_timer_manager_dispose(manager); +} + +TEST(wf_timer, trigger) +{ + bool triggered = false; + struct wf_timer_manager * manager = wf_timer_manager_create(); + struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); + + wf_timer_start(timer, 250); + msleep(500); + wf_timer_manager_check(manager); + + ASSERT_TRUE(triggered); + + wf_timer_dispose(timer); + wf_timer_manager_dispose(manager); +} + +TEST(wf_timer, trigger_on_dispose) +{ + bool triggered = false; + struct wf_timer_manager * manager = wf_timer_manager_create(); + struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); + + wf_timer_start(timer, (5 * 60 * 1000)); + + wf_timer_manager_dispose(manager); + ASSERT_TRUE(triggered); + + wf_timer_dispose(timer); +} + +TEST(wf_timer, cancel) +{ + bool triggered = false; + struct wf_timer_manager * manager = wf_timer_manager_create(); + struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); + + wf_timer_start(timer, 250); + msleep(500); + wf_timer_cancel(timer); + wf_timer_manager_check(manager); + + ASSERT_FALSE(triggered); + + wf_timer_dispose(timer); + wf_timer_manager_dispose(manager); +} + +TEST(wf_timer, cancel_multiple_timers) +{ + static size_t const count = 5; + struct wf_timer_manager * manager = wf_timer_manager_create(); + struct wf_timer * timer[count]; + + bool triggered = false; + for(size_t i = 0; i < count; i++) + { + timer[i] = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); + wf_timer_start(timer[i], 0); + } + + msleep(10); + for(size_t i = 0; i < count; i++) + { + wf_timer_cancel(timer[i]); + } + + wf_timer_manager_check(manager); + ASSERT_FALSE(triggered); + + for(size_t i = 0; i < count; i++) + { + wf_timer_dispose(timer[i]); + } + wf_timer_manager_dispose(manager); +} + +TEST(wf_timer, multiple_timers) +{ + static size_t const count = 5; + struct wf_timer_manager * manager = wf_timer_manager_create(); + struct wf_timer * timer[count]; + bool triggered[count]; + + for(size_t i = 0; i < count; i++) + { + timer[i] = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered[i])); + triggered[i] = false; + wf_timer_start(timer[i], (300 - (50 * i))); + } + + for(size_t i = 0; i < count; i++) + { + msleep(100); + wf_timer_manager_check(manager); + } + + for(size_t i = 0; i < count; i++) + { + ASSERT_TRUE(triggered[i]); + wf_timer_dispose(timer[i]); + } + + wf_timer_manager_dispose(manager); +} diff --git a/test/webfuse/tests/adapter/test_timepoint.cc b/test/webfuse/tests/adapter/test_timepoint.cc deleted file mode 100644 index 8b0db97..0000000 --- a/test/webfuse/tests/adapter/test_timepoint.cc +++ /dev/null @@ -1,36 +0,0 @@ -#include - -#include "webfuse/utils/msleep.hpp" -#include "webfuse/adapter/impl/time/timepoint.h" - -using webfuse_test::msleep; - -TEST(timepoint, now) -{ - wf_impl_timepoint start = wf_impl_timepoint_now(); - msleep(42); - wf_impl_timepoint end = wf_impl_timepoint_now(); - - ASSERT_LT(start, end); - ASSERT_LT(end, start + 500); -} - -TEST(timepoint, in_msec) -{ - wf_impl_timepoint now = wf_impl_timepoint_now(); - wf_impl_timepoint later = wf_impl_timepoint_in_msec(42); - - ASSERT_LT(now, later); - ASSERT_LT(later, now + 500); -} - -TEST(wf_impl_timepoint, elapsed) -{ - wf_impl_timepoint now; - - now = wf_impl_timepoint_now(); - ASSERT_TRUE(wf_impl_timepoint_is_elapsed(now - 1)); - - now =wf_impl_timepoint_now(); - ASSERT_FALSE(wf_impl_timepoint_is_elapsed(now + 500)); -} diff --git a/test/webfuse/tests/adapter/test_timer.cc b/test/webfuse/tests/adapter/test_timer.cc deleted file mode 100644 index d554f2d..0000000 --- a/test/webfuse/tests/adapter/test_timer.cc +++ /dev/null @@ -1,149 +0,0 @@ -#include - -#include - -#include "webfuse/utils/msleep.hpp" -#include "webfuse/adapter/impl/time/timer.h" -#include "webfuse/adapter/impl/time/timeout_manager.h" - -using std::size_t; -using webfuse_test::msleep; - -namespace -{ - void on_timeout(struct wf_impl_timer * timer) - { - bool * triggered = reinterpret_cast(timer->user_data); - *triggered = true; - } -} - -TEST(timer, init) -{ - struct wf_impl_timeout_manager manager; - struct wf_impl_timer timer; - - wf_impl_timeout_manager_init(&manager); - wf_impl_timer_init(&timer, &manager); - - wf_impl_timer_cleanup(&timer); - wf_impl_timeout_manager_cleanup(&manager); -} - -TEST(timer, trigger) -{ - struct wf_impl_timeout_manager manager; - struct wf_impl_timer timer; - - wf_impl_timeout_manager_init(&manager); - wf_impl_timer_init(&timer, &manager); - - bool triggered = false; - wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast(&triggered)); - msleep(500); - wf_impl_timeout_manager_check(&manager); - - ASSERT_TRUE(triggered); - - wf_impl_timer_cleanup(&timer); - wf_impl_timeout_manager_cleanup(&manager); -} - -TEST(timer, trigger_on_cleanup) -{ - struct wf_impl_timeout_manager manager; - struct wf_impl_timer timer; - - wf_impl_timeout_manager_init(&manager); - wf_impl_timer_init(&timer, &manager); - - bool triggered = false; - wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(5 * 60 * 1000), &on_timeout, reinterpret_cast(&triggered)); - - wf_impl_timeout_manager_cleanup(&manager); - ASSERT_TRUE(triggered); - - wf_impl_timer_cleanup(&timer); -} - -TEST(timer, cancel) -{ - struct wf_impl_timeout_manager manager; - struct wf_impl_timer timer; - - wf_impl_timeout_manager_init(&manager); - wf_impl_timer_init(&timer, &manager); - - bool triggered = false; - wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(250), &on_timeout, &triggered); - msleep(500); - wf_impl_timer_cancel(&timer); - wf_impl_timeout_manager_check(&manager); - - ASSERT_FALSE(triggered); - - wf_impl_timer_cleanup(&timer); - wf_impl_timeout_manager_cleanup(&manager); -} - -TEST(timer, cancel_multiple_timers) -{ - static size_t const count = 5; - struct wf_impl_timeout_manager manager; - struct wf_impl_timer timer[count]; - - wf_impl_timeout_manager_init(&manager); - - bool triggered = false; - for(size_t i = 0; i < count; i++) - { - wf_impl_timer_init(&timer[i], &manager); - wf_impl_timer_start(&timer[i], wf_impl_timepoint_in_msec(0), &on_timeout, &triggered); - } - - msleep(10); - for(size_t i = 0; i < count; i++) - { - wf_impl_timer_cancel(&timer[i]); - } - - wf_impl_timeout_manager_check(&manager); - ASSERT_FALSE(triggered); - - for(size_t i = 0; i < count; i++) - { - wf_impl_timer_cleanup(&timer[0]); - } - wf_impl_timeout_manager_cleanup(&manager); -} - -TEST(timer, multiple_timers) -{ - static size_t const count = 5; - struct wf_impl_timeout_manager manager; - struct wf_impl_timer timer[count]; - bool triggered[count]; - - wf_impl_timeout_manager_init(&manager); - - for(size_t i = 0; i < count; i++) - { - wf_impl_timer_init(&timer[i], &manager); - triggered[i] = false; - wf_impl_timer_start(&timer[i], wf_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]); - } - - for(size_t i = 0; i < count; i++) - { - msleep(100); - wf_impl_timeout_manager_check(&manager); - } - - for(size_t i = 0; i < count; i++) - { - ASSERT_TRUE(triggered[i]); - wf_impl_timer_cleanup(&timer[i]); - } - - wf_impl_timeout_manager_cleanup(&manager); -} From 97eb420ef211a8446ed7b931c3253e6f6897fffd Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 29 Feb 2020 23:53:48 +0100 Subject: [PATCH 068/138] chore: removed dependency to lib --- cmake/jsonrpc.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/jsonrpc.cmake b/cmake/jsonrpc.cmake index a7a643f..e50e1c6 100644 --- a/cmake/jsonrpc.cmake +++ b/cmake/jsonrpc.cmake @@ -15,7 +15,6 @@ target_link_libraries(jsonrpc PUBLIC wf_timer) target_include_directories(jsonrpc PRIVATE lib/wf/timer/include lib/jsonrpc/src - lib ) target_include_directories(jsonrpc PUBLIC From af2343c67a46922391550fd047dbe3d02be52122 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 01:13:24 +0100 Subject: [PATCH 069/138] use jsonrpc_proxy to send requests within client_protocol (provider) --- cmake/webfuse_provider.cmake | 6 +- lib/jsonrpc/src/jsonrpc/impl/proxy.c | 4 +- lib/webfuse/provider/impl/client_protocol.c | 112 ++++++++++++++------ lib/webfuse/provider/impl/client_protocol.h | 4 + 4 files changed, 88 insertions(+), 38 deletions(-) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index 0d80d2d..8e829a4 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -20,7 +20,11 @@ add_library(webfuse-provider-static STATIC set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider) set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden) -target_include_directories(webfuse-provider-static PUBLIC lib) +target_include_directories(webfuse-provider-static PUBLIC + lib + lib/wf/timer/include + lib/jsonrpc/include +) add_library(webfuse-provider SHARED lib/webfuse/provider/api.c diff --git a/lib/jsonrpc/src/jsonrpc/impl/proxy.c b/lib/jsonrpc/src/jsonrpc/impl/proxy.c index fa4f3ad..caea4a4 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/proxy.c +++ b/lib/jsonrpc/src/jsonrpc/impl/proxy.c @@ -124,7 +124,7 @@ void jsonrpc_impl_proxy_cleanup( proxy->request.id = 0; wf_timer_cancel(proxy->request.timer); - jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); + jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad: cancelled pending request during shutdown"); } wf_timer_dispose(proxy->request.timer); @@ -158,7 +158,7 @@ void jsonrpc_impl_proxy_invoke( proxy->request.id = 0; wf_timer_cancel(proxy->request.timer); - jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad"); + jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad: requenst is not sent"); } if (NULL != request) diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 59945bd..46d2133 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -15,6 +15,14 @@ #include "webfuse/provider/impl/url.h" #include "webfuse/core/protocol_names.h" +#include "wf/timer/manager.h" + +#include "jsonrpc/response.h" +#include "jsonrpc/request.h" +#include "jsonrpc/proxy.h" + +#define WF_DEFAULT_TIMEOUT (10 * 1000) + static void wfp_impl_client_protocol_respond( json_t * response, void * user_data) @@ -29,54 +37,65 @@ static void wfp_impl_client_protocol_respond( } } -static void wfp_impl_client_protocol_process_request( +static void wfp_impl_client_protocol_process( struct wfp_client_protocol * protocol, - char const * message, + char const * data, size_t length) { - json_t * request = json_loadb(message, length, 0, NULL); - if (NULL != request) + json_t * message = json_loadb(data, length, 0, NULL); + if (NULL != message) { - // FIXME: is_connected should be invoked, when filesystem added - if ((!protocol->is_connected) && (NULL != json_object_get(request, "result"))) + if (jsonrpc_is_response(message)) { - protocol->is_connected = true; - protocol->provider.connected(protocol->user_data); + jsonrpc_proxy_onresult(protocol->proxy, message); } - - - struct wfp_impl_invokation_context context = + if (jsonrpc_is_request(message)) { - .provider = &protocol->provider, - .user_data = protocol->user_data, - .request = &protocol->request - }; + struct wfp_impl_invokation_context context = + { + .provider = &protocol->provider, + .user_data = protocol->user_data, + .request = &protocol->request + }; - wfp_impl_provider_invoke(&context, request); - json_decref(request); + wfp_impl_provider_invoke(&context, message); + } + + json_decref(message); } } +static void +wfp_impl_client_protocol_on_authenticate_finished( + void * user_data, + json_t const * result, + json_t const * WF_UNUSED_PARAM(error)) +{ + struct wfp_client_protocol * protocol = user_data; + + if (NULL != result) + { + protocol->is_connected = true; + protocol->provider.connected(protocol->user_data); + } + else + { + // ToDo: handle error + } + +} + static void wfp_impl_client_protocol_add_filesystem( struct wfp_client_protocol * protocol) { - json_t * params = json_array(); - json_array_append_new(params, json_string("cprovider")); - - json_t * request = json_object(); - json_object_set_new(request, "method", json_string("add_filesystem")); - json_object_set_new(request, "params", params); - json_object_set_new(request, "id", json_integer(42)); - - struct wf_message * message = wf_message_create(request); - if (NULL != message) - { - wf_slist_append(&protocol->messages, &message->item); - lws_callback_on_writable(protocol->wsi); - } - - json_decref(request); + jsonrpc_proxy_invoke( + protocol->proxy, + &wfp_impl_client_protocol_on_authenticate_finished, + protocol, + "add_filesystem", + "s", + "cprovider"); } static int wfp_impl_client_protocol_callback( @@ -91,11 +110,12 @@ static int wfp_impl_client_protocol_callback( if (NULL != protocol) { + wf_timer_manager_check(protocol->timer_manager); + switch (reason) { case LWS_CALLBACK_CLIENT_ESTABLISHED: wfp_impl_client_protocol_add_filesystem(protocol); - // Defer is_connected until response received break; case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: protocol->is_connected = false; @@ -106,7 +126,7 @@ static int wfp_impl_client_protocol_callback( protocol->provider.disconnected(protocol->user_data); break; case LWS_CALLBACK_CLIENT_RECEIVE: - wfp_impl_client_protocol_process_request(protocol, in, len); + wfp_impl_client_protocol_process(protocol, in, len); break; case LWS_CALLBACK_SERVER_WRITEABLE: // fall-through @@ -133,6 +153,23 @@ static int wfp_impl_client_protocol_callback( return 0; } +static bool wfp_impl_client_protocol_send( + json_t * request, + void * user_data) +{ + bool result = false; + struct wfp_client_protocol * protocol = user_data; + + struct wf_message * message = wf_message_create(request); + if (NULL != message) + { + wf_slist_append(&protocol->messages, &message->item); + lws_callback_on_writable(protocol->wsi); + result = true; + } + + return result; +} void wfp_impl_client_protocol_init( struct wfp_client_protocol * protocol, @@ -147,6 +184,9 @@ void wfp_impl_client_protocol_init( protocol->request.respond = &wfp_impl_client_protocol_respond; protocol->request.user_data = protocol; + protocol->timer_manager = wf_timer_manager_create(); + protocol->proxy = jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wfp_impl_client_protocol_send, protocol); + protocol->user_data = user_data; wfp_impl_provider_init_from_prototype(&protocol->provider, provider); } @@ -154,6 +194,8 @@ void wfp_impl_client_protocol_init( void wfp_impl_client_protocol_cleanup( struct wfp_client_protocol * protocol) { + jsonrpc_proxy_dispose(protocol->proxy); + wf_timer_manager_dispose(protocol->timer_manager); wf_message_queue_cleanup(&protocol->messages); } diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index d6f537d..77a99d5 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -14,6 +14,8 @@ extern "C" struct wfp_client_config; struct lws_protocols; struct lws_context; +struct jsonrpc_proxy; +struct wf_timer_manager; struct wfp_client_protocol { @@ -22,6 +24,8 @@ struct wfp_client_protocol struct wfp_provider provider; void * user_data; struct lws * wsi; + struct wf_timer_manager * timer_manager; + struct jsonrpc_proxy * proxy; struct wf_slist messages; }; From f79b9c998a5709e0608fc393acfaddec02196ff0 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 11:06:09 +0100 Subject: [PATCH 070/138] added error handling on authentication failure --- lib/webfuse/provider/impl/client_protocol.c | 42 +++++++++++++-------- lib/webfuse/provider/impl/client_protocol.h | 1 + 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 46d2133..fdbcaf1 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -73,7 +73,8 @@ wfp_impl_client_protocol_on_authenticate_finished( json_t const * WF_UNUSED_PARAM(error)) { struct wfp_client_protocol * protocol = user_data; - + if (NULL == protocol->wsi) { return; } + if (NULL != result) { protocol->is_connected = true; @@ -81,9 +82,9 @@ wfp_impl_client_protocol_on_authenticate_finished( } else { - // ToDo: handle error - } - + protocol->is_shutdown_requested = true; + lws_callback_on_writable(protocol->wsi); + } } static void wfp_impl_client_protocol_add_filesystem( @@ -105,6 +106,7 @@ static int wfp_impl_client_protocol_callback( void * in, size_t len) { + int result = 0; struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); struct wfp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL; @@ -123,7 +125,8 @@ static int wfp_impl_client_protocol_callback( break; case LWS_CALLBACK_CLIENT_CLOSED: protocol->is_connected = false; - protocol->provider.disconnected(protocol->user_data); + protocol->provider.disconnected(protocol->user_data); + protocol->wsi = NULL; break; case LWS_CALLBACK_CLIENT_RECEIVE: wfp_impl_client_protocol_process(protocol, in, len); @@ -131,26 +134,32 @@ static int wfp_impl_client_protocol_callback( case LWS_CALLBACK_SERVER_WRITEABLE: // fall-through case LWS_CALLBACK_CLIENT_WRITEABLE: - if ((wsi == protocol->wsi) && (!wf_slist_empty(&protocol->messages))) + if (wsi == protocol->wsi) { - struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages); - struct wf_message * message = wf_container_of(item, struct wf_message, item); - lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT); - wf_message_dispose(message); - - if (!wf_slist_empty(&protocol->messages)) + if (protocol->is_shutdown_requested) { - lws_callback_on_writable(wsi); - + result = 1; } - } + else if (!wf_slist_empty(&protocol->messages)) + { + struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages); + struct wf_message * message = wf_container_of(item, struct wf_message, item); + lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT); + wf_message_dispose(message); + + if (!wf_slist_empty(&protocol->messages)) + { + lws_callback_on_writable(wsi); + } + } + } break; default: break; } } - return 0; + return result; } static bool wfp_impl_client_protocol_send( @@ -177,6 +186,7 @@ void wfp_impl_client_protocol_init( void * user_data) { protocol->is_connected = false; + protocol->is_shutdown_requested = false; wf_slist_init(&protocol->messages); protocol->wsi = NULL; diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index 77a99d5..d0e6660 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -20,6 +20,7 @@ struct wf_timer_manager; struct wfp_client_protocol { bool is_connected; + bool is_shutdown_requested; struct wfp_request request; struct wfp_provider provider; void * user_data; From 7856b5a99d158803c8f07ffd7d92462124e025f1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 13:42:46 +0100 Subject: [PATCH 071/138] feature: enabled authentication --- lib/jsonrpc/include/jsonrpc/proxy.h | 15 ++++- lib/jsonrpc/src/jsonrpc/impl/proxy.c | 6 ++ lib/webfuse/provider/impl/client_protocol.c | 65 +++++++++++++++++-- lib/webfuse/provider/impl/credentials.c | 12 ++++ lib/webfuse/provider/impl/credentials.h | 5 ++ lib/webfuse/provider/impl/provider.c | 9 ++- lib/webfuse/provider/impl/provider.h | 8 +++ .../tests/provider/test_client_protocol.cc | 2 +- 8 files changed, 115 insertions(+), 7 deletions(-) diff --git a/lib/jsonrpc/include/jsonrpc/proxy.h b/lib/jsonrpc/include/jsonrpc/proxy.h index 3f2dca5..a7573fa 100644 --- a/lib/jsonrpc/include/jsonrpc/proxy.h +++ b/lib/jsonrpc/include/jsonrpc/proxy.h @@ -33,7 +33,20 @@ jsonrpc_proxy_create( extern JSONRPC_API void jsonrpc_proxy_dispose( struct jsonrpc_proxy * proxy); - +//------------------------------------------------------------------------------ +/// \brief Invokes a method. +/// +/// Creates a method an sends it using the send function. +/// Proxy keeps track of method invokation. If no response is returned within +/// timeout, an error is propagated. +/// +/// \param proxy pointer to proxy instance +/// \param finished function which is called exactly once, either on success or +/// on failure. +/// \param method_name name of the method to invoke +/// \param param_info types of the param (s = string, i = integer, j = json) +/// \param ... params +//------------------------------------------------------------------------------ extern JSONRPC_API void jsonrpc_proxy_invoke( struct jsonrpc_proxy * proxy, jsonrpc_proxy_finished_fn * finished, diff --git a/lib/jsonrpc/src/jsonrpc/impl/proxy.c b/lib/jsonrpc/src/jsonrpc/impl/proxy.c index caea4a4..976da05 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/proxy.c +++ b/lib/jsonrpc/src/jsonrpc/impl/proxy.c @@ -77,6 +77,12 @@ static json_t * jsonrpc_impl_request_create( json_array_append_new(params, json_integer(value)); } break; + case 'j': + { + json_t * const value = va_arg(args, json_t *); + json_array_append_new(params, value); + } + break; default: fprintf(stderr, "fatal: unknown param_type '%c'\n", *param_type); json_decref(params); diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index fdbcaf1..1b434fc 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -8,6 +8,7 @@ #include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/provider.h" +#include "webfuse/provider/impl/credentials.h" #include "webfuse/core/util.h" #include "webfuse/core/message.h" #include "webfuse/core/message_queue.h" @@ -67,14 +68,14 @@ static void wfp_impl_client_protocol_process( } static void -wfp_impl_client_protocol_on_authenticate_finished( +wfp_impl_client_protocol_on_add_filesystem_finished( void * user_data, json_t const * result, json_t const * WF_UNUSED_PARAM(error)) { struct wfp_client_protocol * protocol = user_data; if (NULL == protocol->wsi) { return; } - + if (NULL != result) { protocol->is_connected = true; @@ -92,13 +93,69 @@ static void wfp_impl_client_protocol_add_filesystem( { jsonrpc_proxy_invoke( protocol->proxy, - &wfp_impl_client_protocol_on_authenticate_finished, + &wfp_impl_client_protocol_on_add_filesystem_finished, protocol, "add_filesystem", "s", "cprovider"); } +static void +wfp_impl_client_protocol_on_authenticate_finished( + void * user_data, + json_t const * result, + json_t const * WF_UNUSED_PARAM(error)) +{ + struct wfp_client_protocol * protocol = user_data; + if (NULL == protocol->wsi) { return; } + + if (NULL != result) + { + wfp_impl_client_protocol_add_filesystem(protocol); + } + else + { + protocol->is_shutdown_requested = true; + lws_callback_on_writable(protocol->wsi); + } +} + +static void wfp_impl_client_protocol_authenticate( + struct wfp_client_protocol * protocol) +{ + struct wfp_credentials credentials; + wfp_impl_credentials_init(&credentials); + + protocol->provider.get_credentials(&credentials, protocol->user_data); + + char const * cred_type = wfp_impl_credentials_get_type(&credentials); + json_t * creds = wfp_impl_credentials_get(&credentials); + json_incref(creds); + + jsonrpc_proxy_invoke( + protocol->proxy, + &wfp_impl_client_protocol_on_authenticate_finished, + protocol, + "authenticate", + "sj", + cred_type, creds); + + wfp_impl_credentials_cleanup(&credentials); +} + +static void wfp_impl_client_protocol_handshake( + struct wfp_client_protocol * protocol) +{ + if (wfp_impl_provider_is_authentication_enabled(&protocol->provider)) + { + wfp_impl_client_protocol_authenticate(protocol); + } + else + { + wfp_impl_client_protocol_add_filesystem(protocol); + } +} + static int wfp_impl_client_protocol_callback( struct lws * wsi, enum lws_callback_reasons reason, @@ -117,7 +174,7 @@ static int wfp_impl_client_protocol_callback( switch (reason) { case LWS_CALLBACK_CLIENT_ESTABLISHED: - wfp_impl_client_protocol_add_filesystem(protocol); + wfp_impl_client_protocol_handshake(protocol); break; case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: protocol->is_connected = false; diff --git a/lib/webfuse/provider/impl/credentials.c b/lib/webfuse/provider/impl/credentials.c index 8e788ca..f2d254f 100644 --- a/lib/webfuse/provider/impl/credentials.c +++ b/lib/webfuse/provider/impl/credentials.c @@ -32,3 +32,15 @@ void wfp_impl_credentials_add( { json_object_set_new(credentials->contents, key, json_string(value)); } + +char const * wfp_impl_credentials_get_type( + struct wfp_credentials * credentials) +{ + return credentials->type; +} + +json_t * wfp_impl_credentials_get( + struct wfp_credentials * credentials) +{ + return credentials->contents; +} diff --git a/lib/webfuse/provider/impl/credentials.h b/lib/webfuse/provider/impl/credentials.h index 6da40b9..304b067 100644 --- a/lib/webfuse/provider/impl/credentials.h +++ b/lib/webfuse/provider/impl/credentials.h @@ -30,6 +30,11 @@ extern void wfp_impl_credentials_add( char const * key, char const * value); +extern char const * wfp_impl_credentials_get_type( + struct wfp_credentials * credentials); + +extern json_t * wfp_impl_credentials_get( + struct wfp_credentials * credentials); #ifdef __cplusplus } diff --git a/lib/webfuse/provider/impl/provider.c b/lib/webfuse/provider/impl/provider.c index d3ba96c..14282d2 100644 --- a/lib/webfuse/provider/impl/provider.c +++ b/lib/webfuse/provider/impl/provider.c @@ -126,4 +126,11 @@ void wfp_impl_ontimer_default( (void) user_data; // empty -} \ No newline at end of file +} + + bool wfp_impl_provider_is_authentication_enabled( + struct wfp_provider * provider) +{ + return (NULL != provider->get_credentials); +} + diff --git a/lib/webfuse/provider/impl/provider.h b/lib/webfuse/provider/impl/provider.h index 8f6d115..a9b814d 100644 --- a/lib/webfuse/provider/impl/provider.h +++ b/lib/webfuse/provider/impl/provider.h @@ -1,9 +1,14 @@ #ifndef WF_PROVIDER_IMPL_PROVIDER_H #define WF_PROVIDER_IMPL_PROVIDER_H +#ifndef __cplusplus +#include +#endif + #include #include "webfuse/provider/client_config.h" + #ifdef __cplusplus extern "C" { @@ -42,6 +47,9 @@ extern void wfp_impl_provider_invoke( struct wfp_impl_invokation_context * context, json_t * request); +extern bool wfp_impl_provider_is_authentication_enabled( + struct wfp_provider * provider); + extern void wfp_impl_connected_default( void * user_data); diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 53529c7..3563949 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -173,7 +173,7 @@ TEST(client_protocol, connect_with_username_authentication) EXPECT_CALL(provider, OnConnected()).Times(AtMost(1)); EXPECT_CALL(provider, OnDisconnected()).Times(1); - EXPECT_CALL(provider, GetCredentials(_)).WillOnce(Invoke(GetCredentials)).Times(1); + EXPECT_CALL(provider, GetCredentials(_)).Times(1).WillOnce(Invoke(GetCredentials)); fixture.Connect(); if (HasFatalFailure()) { return; } From 1b4034e08111781b27309dcb2445aa1791c2aac7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 14:00:49 +0100 Subject: [PATCH 072/138] fix: do not ignore return value of mkdtemp --- test/webfuse/tests/integration/server.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index 1360934..847efa2 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -20,7 +20,12 @@ public: : is_shutdown_requested(false) { snprintf(base_dir, WF_PATH_MAX, "%s", "/tmp/webfuse_test_integration_XXXXXX"); - mkdtemp(base_dir); + char const * result = mkdtemp(base_dir); + if (NULL == result) + { + throw std::runtime_error("unable to create temp dir"); + } + config = wf_server_config_create(); wf_server_config_set_port(config, 8080); From 8a40919296fb0896baa1b707b36bd855f00e7e27 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 14:39:58 +0100 Subject: [PATCH 073/138] fix: do not ignore return value of symlink --- lib/webfuse/adapter/impl/uuid_mountpoint.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint.c b/lib/webfuse/adapter/impl/uuid_mountpoint.c index eafa444..4573329 100644 --- a/lib/webfuse/adapter/impl/uuid_mountpoint.c +++ b/lib/webfuse/adapter/impl/uuid_mountpoint.c @@ -60,8 +60,8 @@ static bool wf_impl_uuid_mountpoint_link_first_subdir( { if ((DT_DIR == entry->d_type) && ('.' != entry->d_name[0])) { - symlink(entry->d_name, link_path); - result = true; + int rc = symlink(entry->d_name, link_path); + result = (0 == rc); break; } @@ -114,7 +114,8 @@ wf_impl_uuid_mountpoint_create( mkdir(data->full_path, 0755); data->default_path = wf_create_string("%s/%s/default", root_path, filesystem); - symlink(data->id, data->default_path); + int rc = symlink(data->id, data->default_path); + (void) rc; // ignore missing symlink struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(data->full_path); wf_impl_mountpoint_set_userdata(mountpoint, data, &wf_impl_uuid_mountpoint_data_dispose); From 1a29b44ad67394b87ee08818f97b23a8e707e77f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 16:55:58 +0100 Subject: [PATCH 074/138] chore: prefixed jsonrpc by wf_ --- CMakeLists.txt | 2 +- cmake/jsonrpc.cmake | 24 --- cmake/unit_tests.cmake | 22 +-- cmake/webfuse_adapter.cmake | 4 +- cmake/webfuse_core.cmake | 2 +- cmake/webfuse_provider.cmake | 2 +- cmake/wf_jsonrpc.cmake | 24 +++ lib/jsonrpc/include/jsonrpc.h | 14 -- lib/jsonrpc/include/jsonrpc/api.h | 8 - .../include/jsonrpc/method_invoke_fn.h | 26 ---- lib/jsonrpc/include/jsonrpc/request.h | 53 ------- lib/jsonrpc/include/jsonrpc/server.h | 46 ------ lib/jsonrpc/include/jsonrpc/status.h | 11 -- lib/jsonrpc/src/jsonrpc/api.c | 144 ------------------ lib/jsonrpc/src/jsonrpc/impl/method.h | 34 ----- lib/jsonrpc/src/jsonrpc/impl/proxy.h | 84 ---------- lib/jsonrpc/src/jsonrpc/impl/request.h | 53 ------- lib/jsonrpc/src/jsonrpc/impl/server.c | 132 ---------------- lib/jsonrpc/src/jsonrpc/impl/server.h | 41 ----- lib/jsonrpc/src/jsonrpc/impl/unused_param.h | 10 -- lib/webfuse/adapter/impl/operation/close.c | 6 +- lib/webfuse/adapter/impl/operation/getattr.c | 6 +- lib/webfuse/adapter/impl/operation/lookup.c | 6 +- lib/webfuse/adapter/impl/operation/open.c | 6 +- lib/webfuse/adapter/impl/operation/read.c | 6 +- lib/webfuse/adapter/impl/operation/readdir.c | 14 +- lib/webfuse/adapter/impl/operations.c | 4 +- lib/webfuse/adapter/impl/operations.h | 4 +- lib/webfuse/adapter/impl/server_protocol.c | 26 ++-- lib/webfuse/adapter/impl/server_protocol.h | 6 +- lib/webfuse/adapter/impl/session.c | 23 +-- lib/webfuse/adapter/impl/session.h | 12 +- lib/webfuse/adapter/impl/session_manager.c | 2 +- lib/webfuse/adapter/impl/session_manager.h | 4 +- lib/webfuse/core/json_util.c | 12 +- lib/webfuse/provider/impl/client_protocol.c | 20 +-- lib/webfuse/provider/impl/client_protocol.h | 4 +- lib/wf/jsonrpc/include/wf/jsonrpc.h | 14 ++ lib/wf/jsonrpc/include/wf/jsonrpc/api.h | 8 + .../include/wf/jsonrpc/method_invoke_fn.h | 26 ++++ .../jsonrpc/include/wf}/jsonrpc/proxy.h | 36 ++--- .../include/wf}/jsonrpc/proxy_finished_fn.h | 6 +- lib/wf/jsonrpc/include/wf/jsonrpc/request.h | 54 +++++++ .../jsonrpc/include/wf}/jsonrpc/response.h | 8 +- .../jsonrpc/include/wf}/jsonrpc/send_fn.h | 8 +- lib/wf/jsonrpc/include/wf/jsonrpc/server.h | 46 ++++++ lib/wf/jsonrpc/include/wf/jsonrpc/status.h | 11 ++ lib/wf/jsonrpc/src/wf/jsonrpc/api.c | 144 ++++++++++++++++++ .../jsonrpc/src/wf}/jsonrpc/impl/error.c | 10 +- .../jsonrpc/src/wf}/jsonrpc/impl/error.h | 12 +- .../jsonrpc/src/wf}/jsonrpc/impl/method.c | 12 +- lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h | 34 +++++ .../jsonrpc/src/wf}/jsonrpc/impl/proxy.c | 80 +++++----- lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h | 84 ++++++++++ .../jsonrpc/src/wf}/jsonrpc/impl/request.c | 40 ++--- lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h | 53 +++++++ .../jsonrpc/src/wf}/jsonrpc/impl/response.c | 20 +-- .../jsonrpc/src/wf}/jsonrpc/impl/response.h | 16 +- lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c | 132 ++++++++++++++++ lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h | 41 +++++ .../src/wf/jsonrpc/impl/unused_param.h | 10 ++ .../test/wf}/jsonrpc/test_is_request.cc | 42 ++--- .../test/wf}/jsonrpc/test_is_response.cc | 38 ++--- .../jsonrpc/test/wf}/jsonrpc/test_proxy.cc | 94 ++++++------ .../jsonrpc/test/wf}/jsonrpc/test_request.cc | 32 ++-- .../jsonrpc/test/wf}/jsonrpc/test_response.cc | 26 ++-- .../test/wf}/jsonrpc/test_response_parser.cc | 18 +-- .../jsonrpc/test/wf}/jsonrpc/test_server.cc | 40 ++--- .../webfuse/tests/core}/test_util.cc | 0 69 files changed, 1047 insertions(+), 1045 deletions(-) delete mode 100644 cmake/jsonrpc.cmake create mode 100644 cmake/wf_jsonrpc.cmake delete mode 100644 lib/jsonrpc/include/jsonrpc.h delete mode 100644 lib/jsonrpc/include/jsonrpc/api.h delete mode 100644 lib/jsonrpc/include/jsonrpc/method_invoke_fn.h delete mode 100644 lib/jsonrpc/include/jsonrpc/request.h delete mode 100644 lib/jsonrpc/include/jsonrpc/server.h delete mode 100644 lib/jsonrpc/include/jsonrpc/status.h delete mode 100644 lib/jsonrpc/src/jsonrpc/api.c delete mode 100644 lib/jsonrpc/src/jsonrpc/impl/method.h delete mode 100644 lib/jsonrpc/src/jsonrpc/impl/proxy.h delete mode 100644 lib/jsonrpc/src/jsonrpc/impl/request.h delete mode 100644 lib/jsonrpc/src/jsonrpc/impl/server.c delete mode 100644 lib/jsonrpc/src/jsonrpc/impl/server.h delete mode 100644 lib/jsonrpc/src/jsonrpc/impl/unused_param.h create mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc.h create mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/api.h create mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h rename lib/{jsonrpc/include => wf/jsonrpc/include/wf}/jsonrpc/proxy.h (63%) rename lib/{jsonrpc/include => wf/jsonrpc/include/wf}/jsonrpc/proxy_finished_fn.h (58%) create mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/request.h rename lib/{jsonrpc/include => wf/jsonrpc/include/wf}/jsonrpc/response.h (55%) rename lib/{jsonrpc/include => wf/jsonrpc/include/wf}/jsonrpc/send_fn.h (61%) create mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/server.h create mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/status.h create mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/api.c rename lib/{jsonrpc/src => wf/jsonrpc/src/wf}/jsonrpc/impl/error.c (65%) rename lib/{jsonrpc/src => wf/jsonrpc/src/wf}/jsonrpc/impl/error.h (53%) rename lib/{jsonrpc/src => wf/jsonrpc/src/wf}/jsonrpc/impl/method.c (53%) create mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h rename lib/{jsonrpc/src => wf/jsonrpc/src/wf}/jsonrpc/impl/proxy.c (64%) create mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h rename lib/{jsonrpc/src => wf/jsonrpc/src/wf}/jsonrpc/impl/request.c (58%) create mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h rename lib/{jsonrpc/src => wf/jsonrpc/src/wf}/jsonrpc/impl/response.c (69%) rename lib/{jsonrpc/src => wf/jsonrpc/src/wf}/jsonrpc/impl/response.h (50%) create mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c create mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h create mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h rename lib/{jsonrpc/test => wf/jsonrpc/test/wf}/jsonrpc/test_is_request.cc (65%) rename lib/{jsonrpc/test => wf/jsonrpc/test/wf}/jsonrpc/test_is_response.cc (60%) rename lib/{jsonrpc/test => wf/jsonrpc/test/wf}/jsonrpc/test_proxy.cc (73%) rename lib/{jsonrpc/test => wf/jsonrpc/test/wf}/jsonrpc/test_request.cc (70%) rename lib/{jsonrpc/test => wf/jsonrpc/test/wf}/jsonrpc/test_response.cc (69%) rename lib/{jsonrpc/test => wf/jsonrpc/test/wf}/jsonrpc/test_response_parser.cc (75%) rename lib/{jsonrpc/test => wf/jsonrpc/test/wf}/jsonrpc/test_server.cc (72%) rename {lib/jsonrpc/test/jsonrpc => test/webfuse/tests/core}/test_util.cc (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a856e45..00daef9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ add_compile_options( ) include(wf_timer) -include(jsonrpc) +include(wf_jsonrpc) include(webfuse_core) include(webfuse_adapter) include(webfuse_provider) diff --git a/cmake/jsonrpc.cmake b/cmake/jsonrpc.cmake deleted file mode 100644 index e50e1c6..0000000 --- a/cmake/jsonrpc.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# jsonrpc - -add_library(jsonrpc STATIC - lib/jsonrpc/src/jsonrpc/api.c - lib/jsonrpc/src/jsonrpc/impl/proxy.c - lib/jsonrpc/src/jsonrpc/impl/server.c - lib/jsonrpc/src/jsonrpc/impl/method.c - lib/jsonrpc/src/jsonrpc/impl/request.c - lib/jsonrpc/src/jsonrpc/impl/response.c - lib/jsonrpc/src/jsonrpc/impl/error.c -) - -target_link_libraries(jsonrpc PUBLIC wf_timer) - -target_include_directories(jsonrpc PRIVATE - lib/wf/timer/include - lib/jsonrpc/src -) - -target_include_directories(jsonrpc PUBLIC - lib/jsonrpc/include -) - -set_target_properties(jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 0ba1878..b7887fa 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,14 +7,13 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests - lib/jsonrpc/test/jsonrpc/test_util.cc - lib/jsonrpc/test/jsonrpc/test_is_request.cc - lib/jsonrpc/test/jsonrpc/test_request.cc - lib/jsonrpc/test/jsonrpc/test_is_response.cc - lib/jsonrpc/test/jsonrpc/test_response.cc - lib/jsonrpc/test/jsonrpc/test_server.cc - lib/jsonrpc/test/jsonrpc/test_proxy.cc - lib/jsonrpc/test/jsonrpc/test_response_parser.cc + lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc + lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc + lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc + lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc + lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc + lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc + lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc lib/wf/timer/test/wf/timer/test_timepoint.cc lib/wf/timer/test/wf/timer/test_timer.cc test/webfuse/utils/tempdir.cc @@ -28,6 +27,7 @@ add_executable(alltests test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc test/webfuse/mocks/mock_provider_client.cc + test/webfuse//tests/core/test_util.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc test/webfuse/tests/core/test_slist.cc @@ -52,8 +52,8 @@ add_executable(alltests ) target_include_directories(alltests PRIVATE - lib/jsonrpc/include - lib/jsonrpc/src + lib/wf/jsonrpc/include + lib/wf/jsonrpc/src lib/wf/timer/include lib/wf/timer/src ${FUSE3_INCLUDE_DIRS} @@ -69,7 +69,7 @@ target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core - jsonrpc + wf_jsonrpc wf_timer ${FUSE3_LIBRARIES} ${LWS_LIBRARIES} diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index f6fb6af..bb0f723 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -30,7 +30,7 @@ add_library(webfuse-adapter-static STATIC target_include_directories(webfuse-adapter-static PRIVATE lib lib/wf/timer/include - lib/jsonrpc/include + lib/wf/jsonrpc/include ${FUSE3_INCLUDE_DIRS} ${UUID_INCLUDE_DIRS} ) @@ -63,7 +63,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 COMPILE_DEFINITIONS "WF_API=WF_EXPORT") -target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core jsonrpc wf_timer) +target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core wf_jsonrpc wf_timer) file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 8db1dad..dab6223 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -12,7 +12,7 @@ add_library(webfuse-core STATIC ) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) -target_include_directories(webfuse-core PUBLIC lib lib/jsonrpc/include) +target_include_directories(webfuse-core PUBLIC lib lib/wf/jsonrpc/include) set_target_properties(webfuse-core PROPERTIES C_VISIBILITY_PRESET hidden) install(DIRECTORY include/webfuse/core DESTINATION include/webfuse COMPONENT headers) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index 8e829a4..a0c9e08 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -23,7 +23,7 @@ set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hid target_include_directories(webfuse-provider-static PUBLIC lib lib/wf/timer/include - lib/jsonrpc/include + lib/wf/jsonrpc/include ) add_library(webfuse-provider SHARED diff --git a/cmake/wf_jsonrpc.cmake b/cmake/wf_jsonrpc.cmake new file mode 100644 index 0000000..fae8d74 --- /dev/null +++ b/cmake/wf_jsonrpc.cmake @@ -0,0 +1,24 @@ +# 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) diff --git a/lib/jsonrpc/include/jsonrpc.h b/lib/jsonrpc/include/jsonrpc.h deleted file mode 100644 index b0e2999..0000000 --- a/lib/jsonrpc/include/jsonrpc.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef JSONRPC_H -#define JSONRPC_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/lib/jsonrpc/include/jsonrpc/api.h b/lib/jsonrpc/include/jsonrpc/api.h deleted file mode 100644 index 41b8563..0000000 --- a/lib/jsonrpc/include/jsonrpc/api.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef JSONRPC_API_H -#define JSONRPC_API_H - -#ifndef JSONRPC_API -#define JSONRPC_API -#endif - -#endif diff --git a/lib/jsonrpc/include/jsonrpc/method_invoke_fn.h b/lib/jsonrpc/include/jsonrpc/method_invoke_fn.h deleted file mode 100644 index 96fecea..0000000 --- a/lib/jsonrpc/include/jsonrpc/method_invoke_fn.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef JSONRPC_METHOD_INVOKE_FN_H -#define JSONRPC_METHOD_INVOKE_FN_H - -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct jsonrpc_request; - -typedef void jsonrpc_method_invoke_fn( - struct jsonrpc_request * request, - char const * method_name, - json_t * params, - void * user_data); - - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/jsonrpc/include/jsonrpc/request.h b/lib/jsonrpc/include/jsonrpc/request.h deleted file mode 100644 index 8c5cbae..0000000 --- a/lib/jsonrpc/include/jsonrpc/request.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef JSONRPC_REQUEST_H -#define JSONRPC_REQUEST_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include -#include "jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct jsonrpc_request; - -extern JSONRPC_API bool jsonrpc_is_request( - json_t * message); - -extern JSONRPC_API struct jsonrpc_request * jsonrpc_request_create( - int id, - jsonrpc_send_fn * send, - void * user_data); - -extern JSONRPC_API void jsonrpc_request_dispose( - struct jsonrpc_request * request); - -extern JSONRPC_API void * jsonrpc_request_get_userdata( - struct jsonrpc_request * request); - -extern JSONRPC_API void jsonrpc_respond( - struct jsonrpc_request * request, - json_t * result); - -extern JSONRPC_API void jsonrpc_respond_error( - struct jsonrpc_request * request, - int code, - char const * message); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/jsonrpc/include/jsonrpc/server.h b/lib/jsonrpc/include/jsonrpc/server.h deleted file mode 100644 index 7c215ec..0000000 --- a/lib/jsonrpc/include/jsonrpc/server.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef JSONRPC_SERVER_H -#define JSONRPC_SERVER_H - -#ifndef __cplusplus -#include -#include -#else -#include -#endif - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct jsonrpc_server; - -extern JSONRPC_API struct jsonrpc_server * -jsonrpc_server_create(void); - -extern JSONRPC_API void -jsonrpc_server_dispose( - struct jsonrpc_server * server); - -extern JSONRPC_API void jsonrpc_server_add( - struct jsonrpc_server * server, - char const * method_name, - jsonrpc_method_invoke_fn * invoke, - void * user_data); - -extern JSONRPC_API void jsonrpc_server_process( - struct jsonrpc_server * server, - json_t * request, - jsonrpc_send_fn * send, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/jsonrpc/include/jsonrpc/status.h b/lib/jsonrpc/include/jsonrpc/status.h deleted file mode 100644 index 905a161..0000000 --- a/lib/jsonrpc/include/jsonrpc/status.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef JSONRPC_STATUS_H -#define JSONRPC_STATUS_H - -#define JSONRPC_GOOD 0 -#define JSONRPC_BAD -1 -#define JSONRPC_BAD_NOTIMPLEMENTED -2 -#define JSONRPC_BAD_TIMEOUT -3 -#define JSONRPC_BAD_BUSY -4 -#define JSONRPC_BAD_FORMAT -5 - -#endif diff --git a/lib/jsonrpc/src/jsonrpc/api.c b/lib/jsonrpc/src/jsonrpc/api.c deleted file mode 100644 index 817438c..0000000 --- a/lib/jsonrpc/src/jsonrpc/api.c +++ /dev/null @@ -1,144 +0,0 @@ -#include "jsonrpc.h" - -#include "jsonrpc/impl/proxy.h" -#include "jsonrpc/impl/request.h" -#include "jsonrpc/impl/response.h" -#include "jsonrpc/impl/server.h" - -// proxy - -struct jsonrpc_proxy * -jsonrpc_proxy_create( - struct wf_timer_manager * manager, - int timeout, - jsonrpc_send_fn * send, - void * user_data) -{ - return jsonrpc_impl_proxy_create(manager, timeout, send, user_data); -} - -void jsonrpc_proxy_dispose( - struct jsonrpc_proxy * proxy) -{ - jsonrpc_impl_proxy_dispose(proxy); -} - -void jsonrpc_proxy_invoke( - struct jsonrpc_proxy * proxy, - jsonrpc_proxy_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - ... -) -{ - va_list args; - va_start(args, param_info); - jsonrpc_impl_proxy_invoke(proxy, finished, user_data, method_name, param_info, args); - va_end(args); -} - -void jsonrpc_proxy_notify( - struct jsonrpc_proxy * proxy, - char const * method_name, - char const * param_info, - ... -) -{ - va_list args; - va_start(args, param_info); - jsonrpc_impl_proxy_notify(proxy, method_name, param_info, args); - va_end(args); -} - -void jsonrpc_proxy_onresult( - struct jsonrpc_proxy * proxy, - json_t * message) -{ - jsonrpc_impl_proxy_onresult(proxy, message); -} - - -// request - -bool jsonrpc_is_request( - json_t * message) -{ - return jsonrpc_impl_is_request(message); -} - -struct jsonrpc_request * jsonrpc_request_create( - int id, - jsonrpc_send_fn * send, - void * user_data) -{ - return jsonrpc_impl_request_create(id, send, user_data); -} - -void jsonrpc_request_dispose( - struct jsonrpc_request * request) -{ - jsonrpc_impl_request_dispose(request); -} - -void * jsonrpc_request_get_userdata( - struct jsonrpc_request * request) -{ - return jsonrpc_impl_request_get_userdata(request); -} - -void jsonrpc_respond( - struct jsonrpc_request * request, - json_t * result) -{ - jsonrpc_impl_respond(request, result); -} - -void jsonrpc_respond_error( - struct jsonrpc_request * request, - int code, - char const * message) -{ - jsonrpc_impl_respond_error(request, code, message); -} - -// response - -bool jsonrpc_is_response( - json_t * message) -{ - return jsonrpc_impl_is_response(message); -} - -// server - -struct jsonrpc_server * -jsonrpc_server_create(void) -{ - return jsonrpc_impl_server_create(); -} - -void -jsonrpc_server_dispose( - struct jsonrpc_server * server) -{ - jsonrpc_impl_server_dispose(server); -} - -void jsonrpc_server_add( - struct jsonrpc_server * server, - char const * method_name, - jsonrpc_method_invoke_fn * invoke, - void * user_data) -{ - jsonrpc_impl_server_add(server, method_name, invoke, user_data); -} - -void jsonrpc_server_process( - struct jsonrpc_server * server, - json_t * request, - jsonrpc_send_fn * send, - void * user_data) -{ - jsonrpc_impl_server_process(server, request, send, user_data); -} diff --git a/lib/jsonrpc/src/jsonrpc/impl/method.h b/lib/jsonrpc/src/jsonrpc/impl/method.h deleted file mode 100644 index 595d35d..0000000 --- a/lib/jsonrpc/src/jsonrpc/impl/method.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef JSONRPC_IMPL_METHOD_H -#define JSONRPC_IMPL_METHOD_H - -#include "jsonrpc/method_invoke_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct jsonrpc_method -{ - struct jsonrpc_method * next; - char * name; - jsonrpc_method_invoke_fn * invoke; - void * user_data; -}; - -extern struct jsonrpc_method * -jsonrpc_impl_method_create( - char const * method_name, - jsonrpc_method_invoke_fn * invoke, - void * user_data); - -extern void -jsonrpc_impl_method_dispose( - struct jsonrpc_method * method); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/jsonrpc/src/jsonrpc/impl/proxy.h b/lib/jsonrpc/src/jsonrpc/impl/proxy.h deleted file mode 100644 index 940f853..0000000 --- a/lib/jsonrpc/src/jsonrpc/impl/proxy.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef JSONRPC_IMPL_PROXY_H -#define JSONRPC_IMPL_PROXY_H - -#include "jsonrpc/proxy_finished_fn.h" -#include "jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_timer_manager; -struct wf_timer; - -struct jsonrpc_request -{ - bool is_pending; - jsonrpc_proxy_finished_fn * finished; - void * user_data; - int id; - struct wf_timer * timer; -}; - -struct jsonrpc_proxy -{ - struct jsonrpc_request request; - int timeout; - jsonrpc_send_fn * send; - void * user_data; -}; - -extern void -jsonrpc_impl_proxy_init( - struct jsonrpc_proxy * proxy, - struct wf_timer_manager * manager, - int timeout, - jsonrpc_send_fn * send, - void * user_data); - -extern void -jsonrpc_impl_proxy_cleanup( - struct jsonrpc_proxy * proxy); - -extern struct jsonrpc_proxy * -jsonrpc_impl_proxy_create( - struct wf_timer_manager * manager, - int timeout, - jsonrpc_send_fn * send, - void * user_data); - -extern void -jsonrpc_impl_proxy_dispose( - struct jsonrpc_proxy * proxy); - - -extern void -jsonrpc_impl_proxy_invoke( - struct jsonrpc_proxy * proxy, - jsonrpc_proxy_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - va_list args -); - -extern void -jsonrpc_impl_proxy_notify( - struct jsonrpc_proxy * proxy, - char const * method_name, - char const * param_info, - va_list args -); - -extern void -jsonrpc_impl_proxy_onresult( - struct jsonrpc_proxy * proxy, - json_t * message); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/jsonrpc/src/jsonrpc/impl/request.h b/lib/jsonrpc/src/jsonrpc/impl/request.h deleted file mode 100644 index 234a508..0000000 --- a/lib/jsonrpc/src/jsonrpc/impl/request.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef JSONRPC_IMPL_REQUEST_H -#define JSONRPC_IMPL_REQUEST_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include -#include "jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct jsonrpc_request; - -extern bool jsonrpc_impl_is_request( - json_t * message); - -extern struct jsonrpc_request * jsonrpc_impl_request_create( - int id, - jsonrpc_send_fn * send, - void * user_data); - -extern void jsonrpc_impl_request_dispose( - struct jsonrpc_request * request); - -extern void * jsonrpc_impl_request_get_userdata( - struct jsonrpc_request * request); - -extern void jsonrpc_impl_respond( - struct jsonrpc_request * request, - json_t * result); - -extern void jsonrpc_impl_respond_error( - struct jsonrpc_request * request, - int code, - char const * message); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/jsonrpc/src/jsonrpc/impl/server.c b/lib/jsonrpc/src/jsonrpc/impl/server.c deleted file mode 100644 index 7da42a3..0000000 --- a/lib/jsonrpc/src/jsonrpc/impl/server.c +++ /dev/null @@ -1,132 +0,0 @@ -#include "jsonrpc/impl/server.h" -#include "jsonrpc/impl/method.h" -#include "jsonrpc/impl/request.h" -#include "jsonrpc/impl/unused_param.h" -#include "jsonrpc/status.h" - -#include -#include - -struct jsonrpc_server -{ - struct jsonrpc_method * methods; -}; - -static void -jsonrpc_impl_server_init( - struct jsonrpc_server * server); - -static void -jsonrpc_impl_server_cleanup( - struct jsonrpc_server * server); - -struct jsonrpc_server * -jsonrpc_impl_server_create(void) -{ - struct jsonrpc_server * server = malloc(sizeof(struct jsonrpc_server)); - if (NULL != server) - { - jsonrpc_impl_server_init(server); - } - - return server; -} - -void -jsonrpc_impl_server_dispose( - struct jsonrpc_server * server) -{ - jsonrpc_impl_server_cleanup(server); - free(server); -} - - -static void jsonrpc_impl_server_init( - struct jsonrpc_server * server) -{ - server->methods = NULL; -} - -static void jsonrpc_impl_server_cleanup( - struct jsonrpc_server * server) -{ - struct jsonrpc_method * current = server->methods; - while (NULL != current) - { - struct jsonrpc_method * next = current->next; - jsonrpc_impl_method_dispose(current); - current = next; - } - server->methods = NULL; -} - -void jsonrpc_impl_server_add( - struct jsonrpc_server * server, - char const * method_name, - jsonrpc_method_invoke_fn * invoke, - void * user_data) -{ - struct jsonrpc_method * method = jsonrpc_impl_method_create(method_name, invoke, user_data); - method->next = server->methods; - server->methods = method; -} - -static void jsonrpc_impl_server_invalid_method_invoke( - struct jsonrpc_request * request, - char const * JSONRPC_UNUSED_PARAM(method_name), - json_t * JSONRPC_UNUSED_PARAM(params), - void * JSONRPC_UNUSED_PARAM(user_data)) -{ - jsonrpc_impl_respond_error(request, JSONRPC_BAD_NOTIMPLEMENTED, "not implemented"); -} - -static struct jsonrpc_method const jsonrpc_impl_server_invalid_method = -{ - .next = NULL, - .name = "", - .invoke = &jsonrpc_impl_server_invalid_method_invoke, - .user_data = NULL -}; - -static struct jsonrpc_method const * -jsonrpc_impl_server_get_method( - struct jsonrpc_server * server, - char const * method_name) -{ - struct jsonrpc_method const * current = server->methods; - while (NULL != current) - { - if (0 == strcmp(method_name, current->name)) - { - return current; - } - - current = current->next; - } - - return &jsonrpc_impl_server_invalid_method; -} - -void jsonrpc_impl_server_process( - struct jsonrpc_server * server, - json_t * request_data, - jsonrpc_send_fn * send, - void * user_data) -{ - json_t * method_holder = json_object_get(request_data, "method"); - json_t * params = json_object_get(request_data, "params"); - json_t * id_holder = json_object_get(request_data, "id"); - - if (json_is_string(method_holder) && - (json_is_array(params) || (json_is_object(params))) && - json_is_integer(id_holder)) - { - char const * method_name = json_string_value(method_holder); - int id = json_integer_value(id_holder); - struct jsonrpc_request * request = jsonrpc_impl_request_create(id, send, user_data); - struct jsonrpc_method const * method = jsonrpc_impl_server_get_method(server, method_name); - - method->invoke(request, method_name, params, method->user_data); - } -} - diff --git a/lib/jsonrpc/src/jsonrpc/impl/server.h b/lib/jsonrpc/src/jsonrpc/impl/server.h deleted file mode 100644 index 6263c66..0000000 --- a/lib/jsonrpc/src/jsonrpc/impl/server.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef JSONRPC_IMPL_SERVER_H -#define JSONRPC_IMPL_SERVER_H - -#include -#include "jsonrpc/method_invoke_fn.h" -#include "jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct jsonrpc_server; - -extern struct jsonrpc_server * -jsonrpc_impl_server_create(void); - -extern void -jsonrpc_impl_server_dispose( - struct jsonrpc_server * server); - -extern void -jsonrpc_impl_server_add( - struct jsonrpc_server * server, - char const * method_name, - jsonrpc_method_invoke_fn * invoke, - void * user_data); - -extern void -jsonrpc_impl_server_process( - struct jsonrpc_server * server, - json_t * request, - jsonrpc_send_fn * send, - void * user_data); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/jsonrpc/src/jsonrpc/impl/unused_param.h b/lib/jsonrpc/src/jsonrpc/impl/unused_param.h deleted file mode 100644 index cde12d0..0000000 --- a/lib/jsonrpc/src/jsonrpc/impl/unused_param.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef JSONRPC_UTIL_H -#define JSONRPC_UTIL_H - -#ifdef __GNUC__ -#define JSONRPC_UNUSED_PARAM(param) param __attribute__((unused)) -#else -#define JSONRPC_UNUSED_PARAM(param) -#endif - -#endif diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index fc1b1a0..dcb65fb 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -4,7 +4,7 @@ #include #include -#include "jsonrpc/proxy.h" +#include "wf/jsonrpc/proxy.h" #include "webfuse/core/util.h" void wf_impl_operation_close( @@ -13,12 +13,12 @@ void wf_impl_operation_close( struct fuse_file_info * file_info) { struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { int handle = (int) (file_info->fh & INT_MAX); - jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags); + wf_jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags); } fuse_reply_err(request, 0); diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index f7be79d..767b06c 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -7,7 +7,7 @@ #include #include -#include "jsonrpc/proxy.h" +#include "wf/jsonrpc/proxy.h" #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" @@ -83,7 +83,7 @@ void wf_impl_operation_getattr ( { struct fuse_ctx const * context = fuse_req_ctx(request); struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { @@ -94,7 +94,7 @@ void wf_impl_operation_getattr ( getattr_context->gid = context->gid; getattr_context->timeout = user_data->timeout; - jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode); + wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode); } else { diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index eaacf8d..596f7e4 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -10,7 +10,7 @@ #include -#include "jsonrpc/proxy.h" +#include "wf/jsonrpc/proxy.h" #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" @@ -92,7 +92,7 @@ void wf_impl_operation_lookup ( { struct fuse_ctx const * context = fuse_req_ctx(request); struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { @@ -102,7 +102,7 @@ void wf_impl_operation_lookup ( lookup_context->gid = context->gid; lookup_context->timeout = user_data->timeout; - jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name); + wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name); } else { diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 05fcec3..0c10c45 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -4,7 +4,7 @@ #include #include -#include "jsonrpc/proxy.h" +#include "wf/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/status.h" #include "webfuse/core/json_util.h" @@ -49,11 +49,11 @@ void wf_impl_operation_open( struct fuse_file_info * file_info) { struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { - jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags); + wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags); } else { diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index b9cfa1a..87330fc 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -5,7 +5,7 @@ #include #include -#include "jsonrpc/proxy.h" +#include "wf/jsonrpc/proxy.h" #include "webfuse/core/base64.h" #include "webfuse/core/json_util.h" @@ -92,13 +92,13 @@ void wf_impl_operation_read( struct fuse_file_info * file_info) { struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH; int handle = (file_info->fh & INT_MAX); - jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length); + wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length); } else { diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index 76414ea..f188084 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -8,7 +8,7 @@ #include #include -#include "jsonrpc/proxy.h" +#include "wf/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/json_util.h" @@ -139,16 +139,16 @@ void wf_impl_operation_readdir ( struct fuse_file_info * WF_UNUSED_PARAM(file_info)) { struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); if (NULL != rpc) { - struct wf_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wf_impl_operation_readdir_context)); - readdir_context->request = request; - readdir_context->size = size; - readdir_context->offset = offset; + struct wf_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wf_impl_operation_readdir_context)); + readdir_context->request = request; + readdir_context->size = size; + readdir_context->offset = offset; - jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode); + wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode); } else { diff --git a/lib/webfuse/adapter/impl/operations.c b/lib/webfuse/adapter/impl/operations.c index d3f9e96..9ddad3e 100644 --- a/lib/webfuse/adapter/impl/operations.c +++ b/lib/webfuse/adapter/impl/operations.c @@ -3,10 +3,10 @@ #include "webfuse/adapter/impl/session.h" #include -struct jsonrpc_proxy * wf_impl_operations_context_get_proxy( +struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context) { - struct jsonrpc_proxy * proxy = NULL; + struct wf_jsonrpc_proxy * proxy = NULL; struct wf_impl_session * session = context->session; if (NULL != session) diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index 50bcef6..4d23db2 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -8,7 +8,7 @@ extern "C" { #endif struct wf_impl_session; -struct jsonrpc_proxy; +struct wf_jsonrpc_proxy; struct wf_impl_operations_context { @@ -49,7 +49,7 @@ extern void wf_impl_operation_read( fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi); -extern struct jsonrpc_proxy * wf_impl_operations_context_get_proxy( +extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context); #ifdef __cplusplus diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 7bf17c9..9085a14 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -9,10 +9,10 @@ #include "webfuse/core/protocol_names.h" #include "webfuse/adapter/impl/credentials.h" -#include "jsonrpc/request.h" #include "webfuse/adapter/impl/uuid_mountpoint_factory.h" #include "webfuse/core/status_intern.h" +#include "wf/jsonrpc/request.h" #include "wf/timer/manager.h" #include "wf/timer/timer.h" @@ -133,7 +133,7 @@ void wf_impl_server_protocol_init_lws( } static void wf_impl_server_protocol_authenticate( - struct jsonrpc_request * request, + struct wf_jsonrpc_request * request, char const * WF_UNUSED_PARAM(method_name), json_t * params, void * WF_UNUSED_PARAM(user_data)) @@ -149,7 +149,7 @@ static void wf_impl_server_protocol_authenticate( struct wf_credentials creds; wf_impl_credentials_init(&creds, type, creds_holder); - struct wf_impl_session * session = jsonrpc_request_get_userdata(request); + struct wf_impl_session * session = wf_jsonrpc_request_get_userdata(request); result = wf_impl_session_authenticate(session, &creds); wf_impl_credentials_cleanup(&creds); @@ -159,11 +159,11 @@ static void wf_impl_server_protocol_authenticate( if (result) { json_t * result = json_object(); - jsonrpc_respond(request, result); + wf_jsonrpc_respond(request, result); } else { - jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED, wf_status_tostring(WF_BAD_ACCESS_DENIED)); + wf_jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED, wf_status_tostring(WF_BAD_ACCESS_DENIED)); } } @@ -183,12 +183,12 @@ static bool wf_impl_server_protocol_check_name(char const * value) } static void wf_impl_server_protocol_add_filesystem( - struct jsonrpc_request * request, + struct wf_jsonrpc_request * request, char const * WF_UNUSED_PARAM(method_name), json_t * params, void * WF_UNUSED_PARAM(user_data)) { - struct wf_impl_session * session = jsonrpc_request_get_userdata(request); + struct wf_impl_session * session = wf_jsonrpc_request_get_userdata(request); wf_status status = (session->is_authenticated) ? WF_GOOD : WF_BAD_ACCESS_DENIED; char const * name = NULL; @@ -222,11 +222,11 @@ static void wf_impl_server_protocol_add_filesystem( { json_t * result = json_object(); json_object_set_new(result, "id", json_string(name)); - jsonrpc_respond(request, result); + wf_jsonrpc_respond(request, result); } else { - jsonrpc_respond_error(request, status, wf_status_tostring(status)); + wf_jsonrpc_respond_error(request, status, wf_status_tostring(status)); } @@ -244,9 +244,9 @@ void wf_impl_server_protocol_init( wf_impl_session_manager_init(&protocol->session_manager); wf_impl_authenticators_init(&protocol->authenticators); - protocol->server = jsonrpc_server_create(); - jsonrpc_server_add(protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol); - jsonrpc_server_add(protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol); + protocol->server = wf_jsonrpc_server_create(); + wf_jsonrpc_server_add(protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol); + wf_jsonrpc_server_add(protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol); } void wf_impl_server_protocol_cleanup( @@ -254,7 +254,7 @@ void wf_impl_server_protocol_cleanup( { protocol->is_operational = false; - jsonrpc_server_dispose(protocol->server); + wf_jsonrpc_server_dispose(protocol->server); wf_timer_manager_dispose(protocol->timer_manager); wf_impl_authenticators_cleanup(&protocol->authenticators); wf_impl_session_manager_cleanup(&protocol->session_manager); diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 0a9fdbd..5d8052e 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -1,11 +1,11 @@ #ifndef WF_ADAPTER_IMPL_SERVER_PROTOCOL_H #define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H -#include "jsonrpc/proxy.h" #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/session_manager.h" -#include "jsonrpc/server.h" +#include "wf/jsonrpc/proxy.h" +#include "wf/jsonrpc/server.h" #ifndef __cplusplus #include @@ -24,7 +24,7 @@ struct wf_server_protocol struct wf_impl_authenticators authenticators; struct wf_impl_mountpoint_factory mountpoint_factory; struct wf_impl_session_manager session_manager; - struct jsonrpc_server * server; + struct wf_jsonrpc_server * server; struct wf_timer_manager * timer_manager; bool is_operational; }; diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index 870f6c0..e1fdd87 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -2,15 +2,16 @@ #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/core/message_queue.h" #include "webfuse/core/message.h" -#include "jsonrpc/proxy.h" -#include "jsonrpc/request.h" -#include "jsonrpc/response.h" #include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/mountpoint.h" #include "webfuse/core/container_of.h" #include "webfuse/core/util.h" +#include "wf/jsonrpc/proxy.h" +#include "wf/jsonrpc/request.h" +#include "wf/jsonrpc/response.h" + #include #include #include @@ -24,7 +25,7 @@ static bool wf_impl_session_send( struct wf_impl_session * session = user_data; struct wf_message * message = wf_message_create(request); - bool result = (session->is_authenticated || jsonrpc_is_response(request)) && (NULL != session->wsi); + bool result = (session->is_authenticated || wf_jsonrpc_is_response(request)) && (NULL != session->wsi); if (result) { @@ -45,7 +46,7 @@ struct wf_impl_session * wf_impl_session_create( struct lws * wsi, struct wf_impl_authenticators * authenticators, struct wf_timer_manager * timer_manager, - struct jsonrpc_server * server, + struct wf_jsonrpc_server * server, struct wf_impl_mountpoint_factory * mountpoint_factory) { @@ -59,7 +60,7 @@ struct wf_impl_session * wf_impl_session_create( session->authenticators = authenticators; session->server = server; session->mountpoint_factory = mountpoint_factory; - session->rpc = 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); } @@ -83,7 +84,7 @@ static void wf_impl_session_dispose_filesystems( void wf_impl_session_dispose( struct wf_impl_session * session) { - jsonrpc_proxy_dispose(session->rpc); + wf_jsonrpc_proxy_dispose(session->rpc); wf_message_queue_cleanup(&session->messages); wf_impl_session_dispose_filesystems(&session->filesystems); @@ -154,13 +155,13 @@ void wf_impl_session_receive( json_t * message = json_loadb(data, length, 0, NULL); if (NULL != message) { - if (jsonrpc_is_response(message)) + if (wf_jsonrpc_is_response(message)) { - jsonrpc_proxy_onresult(session->rpc, message); + wf_jsonrpc_proxy_onresult(session->rpc, message); } - else if (jsonrpc_is_request(message)) + else if (wf_jsonrpc_is_request(message)) { - jsonrpc_server_process(session->server, message, &wf_impl_session_send, session); + wf_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session); } json_decref(message); diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h index a9d15af..82b042f 100644 --- a/lib/webfuse/adapter/impl/session.h +++ b/lib/webfuse/adapter/impl/session.h @@ -10,11 +10,12 @@ using std::size_t; #endif #include "webfuse/core/message_queue.h" -#include "jsonrpc/proxy.h" -#include "jsonrpc/server.h" #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/core/slist.h" +#include "wf/jsonrpc/proxy.h" +#include "wf/jsonrpc/server.h" + #ifdef __cplusplus extern "C" { @@ -25,7 +26,6 @@ struct wf_message; struct wf_credentials; struct wf_impl_authenticators; struct wf_impl_mountpoint_factory; -struct timer_manager; struct wf_impl_session { @@ -35,8 +35,8 @@ struct wf_impl_session struct wf_slist messages; struct wf_impl_authenticators * authenticators; struct wf_impl_mountpoint_factory * mountpoint_factory; - struct jsonrpc_server * server; - struct jsonrpc_proxy * rpc; + struct wf_jsonrpc_server * server; + struct wf_jsonrpc_proxy * rpc; struct wf_slist filesystems; }; @@ -44,7 +44,7 @@ extern struct wf_impl_session * wf_impl_session_create( struct lws * wsi, struct wf_impl_authenticators * authenticators, struct wf_timer_manager * timer_manager, - struct jsonrpc_server * server, + struct wf_jsonrpc_server * server, struct wf_impl_mountpoint_factory * mountpoint_factory); extern void wf_impl_session_dispose( diff --git a/lib/webfuse/adapter/impl/session_manager.c b/lib/webfuse/adapter/impl/session_manager.c index 6474c06..cc41fa0 100644 --- a/lib/webfuse/adapter/impl/session_manager.c +++ b/lib/webfuse/adapter/impl/session_manager.c @@ -29,7 +29,7 @@ struct wf_impl_session * wf_impl_session_manager_add( struct wf_impl_authenticators * authenticators, struct wf_impl_mountpoint_factory * mountpoint_factory, struct wf_timer_manager * timer_manager, - struct jsonrpc_server * server) + struct wf_jsonrpc_server * server) { struct wf_impl_session * session = wf_impl_session_create( wsi, authenticators, timer_manager, server, mountpoint_factory); diff --git a/lib/webfuse/adapter/impl/session_manager.h b/lib/webfuse/adapter/impl/session_manager.h index 4f5f218..691f133 100644 --- a/lib/webfuse/adapter/impl/session_manager.h +++ b/lib/webfuse/adapter/impl/session_manager.h @@ -16,7 +16,7 @@ extern "C" struct lws; struct wf_timer_manager; -struct jsonrpc_server; +struct wf_jsonrpc_server; struct wf_impl_session_manager { @@ -35,7 +35,7 @@ extern struct wf_impl_session * wf_impl_session_manager_add( struct wf_impl_authenticators * authenticators, struct wf_impl_mountpoint_factory * mountpoint_factory, struct wf_timer_manager * timer_manager, - struct jsonrpc_server * server); + struct wf_jsonrpc_server * server); extern struct wf_impl_session * wf_impl_session_manager_get( struct wf_impl_session_manager * manager, diff --git a/lib/webfuse/core/json_util.c b/lib/webfuse/core/json_util.c index dfe95cd..48fe956 100644 --- a/lib/webfuse/core/json_util.c +++ b/lib/webfuse/core/json_util.c @@ -1,5 +1,5 @@ #include "webfuse/core/json_util.h" -#include "jsonrpc/status.h" +#include "wf/jsonrpc/status.h" int wf_impl_json_get_int(json_t const * object, char const * key, int default_value) { @@ -18,15 +18,15 @@ static wf_status wf_impl_jsonrc_code_to_status(int code) { switch (code) { - case JSONRPC_GOOD: + case WF_JSONRPC_GOOD: return WF_GOOD; - case JSONRPC_BAD: + case WF_JSONRPC_BAD: return WF_BAD; - case JSONRPC_BAD_BUSY: + case WF_JSONRPC_BAD_BUSY: return WF_BAD_BUSY; - case JSONRPC_BAD_TIMEOUT: + case WF_JSONRPC_BAD_TIMEOUT: return WF_BAD_TIMEOUT; - case JSONRPC_BAD_FORMAT: + case WF_JSONRPC_BAD_FORMAT: return WF_BAD_FORMAT; default: return (wf_status) code; diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 1b434fc..4f61b8a 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -18,9 +18,9 @@ #include "wf/timer/manager.h" -#include "jsonrpc/response.h" -#include "jsonrpc/request.h" -#include "jsonrpc/proxy.h" +#include "wf/jsonrpc/response.h" +#include "wf/jsonrpc/request.h" +#include "wf/jsonrpc/proxy.h" #define WF_DEFAULT_TIMEOUT (10 * 1000) @@ -46,12 +46,12 @@ static void wfp_impl_client_protocol_process( json_t * message = json_loadb(data, length, 0, NULL); if (NULL != message) { - if (jsonrpc_is_response(message)) + if (wf_jsonrpc_is_response(message)) { - jsonrpc_proxy_onresult(protocol->proxy, message); + wf_jsonrpc_proxy_onresult(protocol->proxy, message); } - if (jsonrpc_is_request(message)) + if (wf_jsonrpc_is_request(message)) { struct wfp_impl_invokation_context context = { @@ -91,7 +91,7 @@ wfp_impl_client_protocol_on_add_filesystem_finished( static void wfp_impl_client_protocol_add_filesystem( struct wfp_client_protocol * protocol) { - jsonrpc_proxy_invoke( + wf_jsonrpc_proxy_invoke( protocol->proxy, &wfp_impl_client_protocol_on_add_filesystem_finished, protocol, @@ -132,7 +132,7 @@ static void wfp_impl_client_protocol_authenticate( json_t * creds = wfp_impl_credentials_get(&credentials); json_incref(creds); - jsonrpc_proxy_invoke( + wf_jsonrpc_proxy_invoke( protocol->proxy, &wfp_impl_client_protocol_on_authenticate_finished, protocol, @@ -252,7 +252,7 @@ void wfp_impl_client_protocol_init( protocol->request.user_data = protocol; protocol->timer_manager = wf_timer_manager_create(); - protocol->proxy = jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wfp_impl_client_protocol_send, protocol); + protocol->proxy = wf_jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wfp_impl_client_protocol_send, protocol); protocol->user_data = user_data; wfp_impl_provider_init_from_prototype(&protocol->provider, provider); @@ -261,7 +261,7 @@ void wfp_impl_client_protocol_init( void wfp_impl_client_protocol_cleanup( struct wfp_client_protocol * protocol) { - jsonrpc_proxy_dispose(protocol->proxy); + wf_jsonrpc_proxy_dispose(protocol->proxy); wf_timer_manager_dispose(protocol->timer_manager); wf_message_queue_cleanup(&protocol->messages); } diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index d0e6660..af5c74b 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -14,7 +14,7 @@ extern "C" struct wfp_client_config; struct lws_protocols; struct lws_context; -struct jsonrpc_proxy; +struct wf_jsonrpc_proxy; struct wf_timer_manager; struct wfp_client_protocol @@ -26,7 +26,7 @@ struct wfp_client_protocol void * user_data; struct lws * wsi; struct wf_timer_manager * timer_manager; - struct jsonrpc_proxy * proxy; + struct wf_jsonrpc_proxy * proxy; struct wf_slist messages; }; diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc.h b/lib/wf/jsonrpc/include/wf/jsonrpc.h new file mode 100644 index 0000000..ab7f1dc --- /dev/null +++ b/lib/wf/jsonrpc/include/wf/jsonrpc.h @@ -0,0 +1,14 @@ +#ifndef WF_JSONRPC_H +#define WF_JSONRPC_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/api.h b/lib/wf/jsonrpc/include/wf/jsonrpc/api.h new file mode 100644 index 0000000..648bf0f --- /dev/null +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/api.h @@ -0,0 +1,8 @@ +#ifndef WF_JSONRPC_API_H +#define WF_JSONRPC_API_H + +#ifndef WF_JSONRPC_API +#define WF_JSONRPC_API +#endif + +#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h b/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h new file mode 100644 index 0000000..d7a9cc8 --- /dev/null +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h @@ -0,0 +1,26 @@ +#ifndef WF_JSONRPC_METHOD_INVOKE_FN_H +#define WF_JSONRPC_METHOD_INVOKE_FN_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_jsonrpc_request; + +typedef void wf_jsonrpc_method_invoke_fn( + struct wf_jsonrpc_request * request, + char const * method_name, + json_t * params, + void * user_data); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/jsonrpc/include/jsonrpc/proxy.h b/lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h similarity index 63% rename from lib/jsonrpc/include/jsonrpc/proxy.h rename to lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h index a7573fa..66fd1a5 100644 --- a/lib/jsonrpc/include/jsonrpc/proxy.h +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h @@ -1,5 +1,5 @@ -#ifndef JSONRPC_PROXY_H -#define JSONRPC_PROXY_H +#ifndef WF_JSONRPC_PROXY_H +#define WF_JSONRPC_PROXY_H #ifndef __cplusplus #include @@ -12,26 +12,26 @@ using std::size_t; #endif #include -#include -#include -#include +#include +#include +#include #ifdef __cplusplus extern "C" { #endif -struct jsonrpc_proxy; +struct wf_jsonrpc_proxy; struct wf_timer_manager; -extern JSONRPC_API struct jsonrpc_proxy * -jsonrpc_proxy_create( +extern WF_JSONRPC_API struct wf_jsonrpc_proxy * +wf_jsonrpc_proxy_create( struct wf_timer_manager * manager, int timeout, - jsonrpc_send_fn * send, + wf_jsonrpc_send_fn * send, void * user_data); -extern JSONRPC_API void jsonrpc_proxy_dispose( - struct jsonrpc_proxy * proxy); +extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose( + struct wf_jsonrpc_proxy * proxy); //------------------------------------------------------------------------------ /// \brief Invokes a method. @@ -47,24 +47,24 @@ extern JSONRPC_API void jsonrpc_proxy_dispose( /// \param param_info types of the param (s = string, i = integer, j = json) /// \param ... params //------------------------------------------------------------------------------ -extern JSONRPC_API void jsonrpc_proxy_invoke( - struct jsonrpc_proxy * proxy, - jsonrpc_proxy_finished_fn * finished, +extern WF_JSONRPC_API 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, ... ); -extern JSONRPC_API void jsonrpc_proxy_notify( - struct jsonrpc_proxy * proxy, +extern WF_JSONRPC_API void wf_jsonrpc_proxy_notify( + struct wf_jsonrpc_proxy * proxy, char const * method_name, char const * param_info, ... ); -extern JSONRPC_API void jsonrpc_proxy_onresult( - struct jsonrpc_proxy * proxy, +extern WF_JSONRPC_API void wf_jsonrpc_proxy_onresult( + struct wf_jsonrpc_proxy * proxy, json_t * message); #ifdef __cplusplus diff --git a/lib/jsonrpc/include/jsonrpc/proxy_finished_fn.h b/lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h similarity index 58% rename from lib/jsonrpc/include/jsonrpc/proxy_finished_fn.h rename to lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h index 4c96b2b..cd59c87 100644 --- a/lib/jsonrpc/include/jsonrpc/proxy_finished_fn.h +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h @@ -1,5 +1,5 @@ -#ifndef JSONRPC_PROXY_FINISHED_FN_H -#define JSONRPC_PROXY_FINISHED_FN_H +#ifndef WF_JSONRPC_PROXY_FINISHED_FN_H +#define WF_JSONRPC_PROXY_FINISHED_FN_H #include @@ -8,7 +8,7 @@ extern "C" { #endif -typedef void jsonrpc_proxy_finished_fn( +typedef void wf_jsonrpc_proxy_finished_fn( void * user_data, json_t const * result, json_t const * error); diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/request.h b/lib/wf/jsonrpc/include/wf/jsonrpc/request.h new file mode 100644 index 0000000..73295e6 --- /dev/null +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/request.h @@ -0,0 +1,54 @@ +#ifndef WF_JSONRPC_REQUEST_H +#define WF_JSONRPC_REQUEST_H + +#ifndef __cplusplus +#include +#include +#include +#else +#include +#include +using std::size_t; +#endif + +#include +#include +#include "wf/jsonrpc/send_fn.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_jsonrpc_request; + +extern WF_JSONRPC_API bool wf_jsonrpc_is_request( + json_t * message); + +extern WF_JSONRPC_API struct wf_jsonrpc_request * +wf_jsonrpc_request_create( + int id, + wf_jsonrpc_send_fn * send, + void * user_data); + +extern WF_JSONRPC_API void wf_jsonrpc_request_dispose( + struct wf_jsonrpc_request * request); + +extern WF_JSONRPC_API void * wf_jsonrpc_request_get_userdata( + struct wf_jsonrpc_request * request); + +extern WF_JSONRPC_API void wf_jsonrpc_respond( + struct wf_jsonrpc_request * request, + json_t * result); + +extern WF_JSONRPC_API void wf_jsonrpc_respond_error( + struct wf_jsonrpc_request * request, + int code, + char const * message); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/jsonrpc/include/jsonrpc/response.h b/lib/wf/jsonrpc/include/wf/jsonrpc/response.h similarity index 55% rename from lib/jsonrpc/include/jsonrpc/response.h rename to lib/wf/jsonrpc/include/wf/jsonrpc/response.h index 64414ec..abe2011 100644 --- a/lib/jsonrpc/include/jsonrpc/response.h +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/response.h @@ -1,19 +1,19 @@ -#ifndef JSONRPC_RESPONSE_H -#define JSONRPC_RESPONSE_H +#ifndef WF_JSONRPC_RESPONSE_H +#define WF_JSONRPC_RESPONSE_H #ifndef __cplusplus #include #endif #include -#include +#include #ifdef __cplusplus extern "C" { #endif -extern JSONRPC_API bool jsonrpc_is_response( +extern WF_JSONRPC_API bool wf_jsonrpc_is_response( json_t * message); #ifdef __cplusplus diff --git a/lib/jsonrpc/include/jsonrpc/send_fn.h b/lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h similarity index 61% rename from lib/jsonrpc/include/jsonrpc/send_fn.h rename to lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h index fe866af..9ea9ef4 100644 --- a/lib/jsonrpc/include/jsonrpc/send_fn.h +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h @@ -1,19 +1,19 @@ -#ifndef JSONRPC_SEND_FN_H -#define JSONRPC_SEND_FN_H +#ifndef WF_JSONRPC_SEND_FN_H +#define WF_JSONRPC_SEND_FN_H #ifndef __cplusplus #include #endif #include -#include +#include #ifdef __cplusplus extern "C" { #endif -typedef bool jsonrpc_send_fn( +typedef bool wf_jsonrpc_send_fn( json_t * request, void * user_data); diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/server.h b/lib/wf/jsonrpc/include/wf/jsonrpc/server.h new file mode 100644 index 0000000..c4850a5 --- /dev/null +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/server.h @@ -0,0 +1,46 @@ +#ifndef WF_JSONRPC_SERVER_H +#define WF_JSONRPC_SERVER_H + +#ifndef __cplusplus +#include +#include +#else +#include +#endif + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_jsonrpc_server; + +extern WF_JSONRPC_API struct wf_jsonrpc_server * +wf_jsonrpc_server_create(void); + +extern WF_JSONRPC_API void +wf_jsonrpc_server_dispose( + struct wf_jsonrpc_server * server); + +extern WF_JSONRPC_API void wf_jsonrpc_server_add( + struct wf_jsonrpc_server * server, + char const * method_name, + wf_jsonrpc_method_invoke_fn * invoke, + void * user_data); + +extern WF_JSONRPC_API void wf_jsonrpc_server_process( + struct wf_jsonrpc_server * server, + json_t * request, + wf_jsonrpc_send_fn * send, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/status.h b/lib/wf/jsonrpc/include/wf/jsonrpc/status.h new file mode 100644 index 0000000..85da73d --- /dev/null +++ b/lib/wf/jsonrpc/include/wf/jsonrpc/status.h @@ -0,0 +1,11 @@ +#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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/api.c b/lib/wf/jsonrpc/src/wf/jsonrpc/api.c new file mode 100644 index 0000000..891bcce --- /dev/null +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/api.c @@ -0,0 +1,144 @@ +#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); +} diff --git a/lib/jsonrpc/src/jsonrpc/impl/error.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c similarity index 65% rename from lib/jsonrpc/src/jsonrpc/impl/error.c rename to lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c index 716f6de..eba2e86 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/error.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c @@ -1,7 +1,7 @@ -#include "jsonrpc/impl/error.h" +#include "wf/jsonrpc/impl/error.h" json_t * -jsonrpc_impl_error( +wf_jsonrpc_impl_error( int code, char const * message) { @@ -13,13 +13,13 @@ jsonrpc_impl_error( } void -jsonrpc_impl_propate_error( - jsonrpc_proxy_finished_fn * finised, +wf_jsonrpc_impl_propate_error( + wf_jsonrpc_proxy_finished_fn * finised, void * user_data, int code, char const * message) { - json_t * error = jsonrpc_impl_error(code, message); + json_t * error = wf_jsonrpc_impl_error(code, message); finised(user_data, NULL, error); json_decref(error); diff --git a/lib/jsonrpc/src/jsonrpc/impl/error.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h similarity index 53% rename from lib/jsonrpc/src/jsonrpc/impl/error.h rename to lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h index 6485f05..fda0f89 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/error.h +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h @@ -1,8 +1,8 @@ -#ifndef JSONRPC_IMPL_ERROR_H -#define JSONRPC_IMPL_ERROR_H +#ifndef WF_JSONRPC_IMPL_ERROR_H +#define WF_JSONRPC_IMPL_ERROR_H #include -#include "jsonrpc/proxy_finished_fn.h" +#include "wf/jsonrpc/proxy_finished_fn.h" #ifdef __cplusplus extern "C" @@ -10,13 +10,13 @@ extern "C" #endif extern json_t * -jsonrpc_impl_error( +wf_jsonrpc_impl_error( int code, char const * message); extern void -jsonrpc_impl_propate_error( - jsonrpc_proxy_finished_fn * finised, +wf_jsonrpc_impl_propate_error( + wf_jsonrpc_proxy_finished_fn * finised, void * user_data, int code, char const * message); diff --git a/lib/jsonrpc/src/jsonrpc/impl/method.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c similarity index 53% rename from lib/jsonrpc/src/jsonrpc/impl/method.c rename to lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c index 073e8b3..87b3ff1 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/method.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c @@ -1,13 +1,13 @@ -#include "jsonrpc/impl/method.h" +#include "wf/jsonrpc/impl/method.h" #include #include -struct jsonrpc_method * jsonrpc_impl_method_create( +struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( char const * method_name, - jsonrpc_method_invoke_fn * invoke, + wf_jsonrpc_method_invoke_fn * invoke, void * user_data) { - struct jsonrpc_method * method = malloc(sizeof(struct jsonrpc_method)); + struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method)); if (NULL != method) { method->next = NULL; @@ -19,8 +19,8 @@ struct jsonrpc_method * jsonrpc_impl_method_create( return method; } -void jsonrpc_impl_method_dispose( - struct jsonrpc_method * method) +void wf_jsonrpc_impl_method_dispose( + struct wf_jsonrpc_method * method) { free(method->name); free(method); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h new file mode 100644 index 0000000..d0e42f0 --- /dev/null +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h @@ -0,0 +1,34 @@ +#ifndef WF_JSONRPC_IMPL_METHOD_H +#define WF_JSONRPC_IMPL_METHOD_H + +#include "wf/jsonrpc/method_invoke_fn.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_jsonrpc_method +{ + struct wf_jsonrpc_method * next; + char * name; + wf_jsonrpc_method_invoke_fn * invoke; + void * user_data; +}; + +extern struct wf_jsonrpc_method * +wf_jsonrpc_impl_method_create( + char const * method_name, + wf_jsonrpc_method_invoke_fn * invoke, + void * user_data); + +extern void +wf_jsonrpc_impl_method_dispose( + struct wf_jsonrpc_method * method); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/jsonrpc/src/jsonrpc/impl/proxy.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c similarity index 64% rename from lib/jsonrpc/src/jsonrpc/impl/proxy.c rename to lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c index 976da05..a2b9816 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/proxy.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c @@ -1,44 +1,44 @@ -#include "jsonrpc/impl/proxy.h" -#include "jsonrpc/impl/response.h" -#include "jsonrpc/impl/error.h" -#include "jsonrpc/status.h" +#include "wf/jsonrpc/impl/proxy.h" +#include "wf/jsonrpc/impl/response.h" +#include "wf/jsonrpc/impl/error.h" +#include "wf/jsonrpc/status.h" #include #include #include -struct jsonrpc_proxy * -jsonrpc_impl_proxy_create( +struct wf_jsonrpc_proxy * +wf_jsonrpc_impl_proxy_create( struct wf_timer_manager * manager, int timeout, - jsonrpc_send_fn * send, + wf_jsonrpc_send_fn * send, void * user_data) { - struct jsonrpc_proxy * proxy = malloc(sizeof(struct jsonrpc_proxy)); + struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy)); if (NULL != proxy) { - jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); + wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); } return proxy; } -void jsonrpc_impl_proxy_dispose( - struct jsonrpc_proxy * proxy) +void wf_jsonrpc_impl_proxy_dispose( + struct wf_jsonrpc_proxy * proxy) { - jsonrpc_impl_proxy_cleanup(proxy); + wf_jsonrpc_impl_proxy_cleanup(proxy); free(proxy); } -static void jsonrpc_impl_proxy_on_timeout( +static void wf_jsonrpc_impl_proxy_on_timeout( struct wf_timer * timer, void * proxy_ptr) { - struct jsonrpc_proxy * proxy = proxy_ptr; + struct wf_jsonrpc_proxy * proxy = proxy_ptr; if (proxy->request.is_pending) { - jsonrpc_proxy_finished_fn * finished = proxy->request.finished; + wf_jsonrpc_proxy_finished_fn * finished = proxy->request.finished; void * user_data = proxy->request.user_data; proxy->request.is_pending = false; @@ -47,11 +47,11 @@ static void jsonrpc_impl_proxy_on_timeout( proxy->request.finished = NULL; wf_timer_cancel(timer); - jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD_TIMEOUT, "Timeout"); + wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_TIMEOUT, "Timeout"); } } -static json_t * jsonrpc_impl_request_create( +static json_t * wf_jsonrpc_impl_request_create( char const * method, int id, char const * param_info, @@ -101,11 +101,11 @@ static json_t * jsonrpc_impl_request_create( return request; } -void jsonrpc_impl_proxy_init( - struct jsonrpc_proxy * proxy, +void wf_jsonrpc_impl_proxy_init( + struct wf_jsonrpc_proxy * proxy, struct wf_timer_manager * timeout_manager, int timeout, - jsonrpc_send_fn * send, + wf_jsonrpc_send_fn * send, void * user_data) { proxy->send = send; @@ -113,16 +113,16 @@ void jsonrpc_impl_proxy_init( proxy->user_data = user_data; proxy->request.is_pending = false; proxy->request.timer = wf_timer_create(timeout_manager, - &jsonrpc_impl_proxy_on_timeout, proxy); + &wf_jsonrpc_impl_proxy_on_timeout, proxy); } -void jsonrpc_impl_proxy_cleanup( - struct jsonrpc_proxy * proxy) +void wf_jsonrpc_impl_proxy_cleanup( + struct wf_jsonrpc_proxy * proxy) { if (proxy->request.is_pending) { void * user_data = proxy->request.user_data; - jsonrpc_proxy_finished_fn * finished = proxy->request.finished; + wf_jsonrpc_proxy_finished_fn * finished = proxy->request.finished; proxy->request.is_pending = false; proxy->request.finished = NULL; @@ -130,15 +130,15 @@ void jsonrpc_impl_proxy_cleanup( proxy->request.id = 0; wf_timer_cancel(proxy->request.timer); - jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad: cancelled pending request during shutdown"); + wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: cancelled pending request during shutdown"); } wf_timer_dispose(proxy->request.timer); } -void jsonrpc_impl_proxy_invoke( - struct jsonrpc_proxy * proxy, - jsonrpc_proxy_finished_fn * finished, +void wf_jsonrpc_impl_proxy_invoke( + struct wf_jsonrpc_proxy * proxy, + wf_jsonrpc_proxy_finished_fn * finished, void * user_data, char const * method_name, char const * param_info, @@ -153,7 +153,7 @@ void jsonrpc_impl_proxy_invoke( proxy->request.id = 42; wf_timer_start(proxy->request.timer, proxy->timeout); - json_t * request = jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args); + json_t * request = wf_jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args); bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data))); if (!is_send) @@ -164,7 +164,7 @@ void jsonrpc_impl_proxy_invoke( proxy->request.id = 0; wf_timer_cancel(proxy->request.timer); - jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD, "Bad: requenst is not sent"); + wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: requenst is not sent"); } if (NULL != request) @@ -174,18 +174,18 @@ void jsonrpc_impl_proxy_invoke( } else { - jsonrpc_impl_propate_error(finished, user_data, JSONRPC_BAD_BUSY, "Busy"); + wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_BUSY, "Busy"); } } -extern void jsonrpc_impl_proxy_notify( - struct jsonrpc_proxy * proxy, +extern void wf_jsonrpc_impl_proxy_notify( + struct wf_jsonrpc_proxy * proxy, char const * method_name, char const * param_info, va_list args ) { - json_t * request = jsonrpc_impl_request_create(method_name, 0, param_info, args); + json_t * request = wf_jsonrpc_impl_request_create(method_name, 0, param_info, args); if (NULL != request) { proxy->send(request, proxy->user_data); @@ -194,16 +194,16 @@ extern void jsonrpc_impl_proxy_notify( } -void jsonrpc_impl_proxy_onresult( - struct jsonrpc_proxy * proxy, +void wf_jsonrpc_impl_proxy_onresult( + struct wf_jsonrpc_proxy * proxy, json_t * message) { - struct jsonrpc_response response; - jsonrpc_impl_response_init(&response, message); + struct wf_jsonrpc_response response; + wf_jsonrpc_impl_response_init(&response, message); if ((proxy->request.is_pending) && (response.id == proxy->request.id)) { - jsonrpc_proxy_finished_fn * finished = proxy->request.finished; + wf_jsonrpc_proxy_finished_fn * finished = proxy->request.finished; void * user_data = proxy->request.user_data; proxy->request.is_pending = false; @@ -215,6 +215,6 @@ void jsonrpc_impl_proxy_onresult( finished(user_data, response.result, response.error); } - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h new file mode 100644 index 0000000..60d2f7a --- /dev/null +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h @@ -0,0 +1,84 @@ +#ifndef WF_JSONRPC_IMPL_PROXY_H +#define WF_JSONRPC_IMPL_PROXY_H + +#include "wf/jsonrpc/proxy_finished_fn.h" +#include "wf/jsonrpc/send_fn.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_timer_manager; +struct wf_timer; + +struct wf_jsonrpc_request +{ + bool is_pending; + wf_jsonrpc_proxy_finished_fn * finished; + void * user_data; + int id; + struct wf_timer * timer; +}; + +struct wf_jsonrpc_proxy +{ + struct wf_jsonrpc_request request; + int timeout; + wf_jsonrpc_send_fn * send; + void * user_data; +}; + +extern void +wf_jsonrpc_impl_proxy_init( + struct wf_jsonrpc_proxy * proxy, + struct wf_timer_manager * manager, + int timeout, + wf_jsonrpc_send_fn * send, + void * user_data); + +extern void +wf_jsonrpc_impl_proxy_cleanup( + struct wf_jsonrpc_proxy * proxy); + +extern struct wf_jsonrpc_proxy * +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, + wf_jsonrpc_proxy_finished_fn * finished, + void * user_data, + char const * method_name, + char const * param_info, + va_list args +); + +extern void +wf_jsonrpc_impl_proxy_notify( + struct wf_jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + va_list args +); + +extern void +wf_jsonrpc_impl_proxy_onresult( + struct wf_jsonrpc_proxy * proxy, + json_t * message); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/jsonrpc/src/jsonrpc/impl/request.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c similarity index 58% rename from lib/jsonrpc/src/jsonrpc/impl/request.c rename to lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c index 91ffd96..e46f19e 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/request.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c @@ -1,16 +1,16 @@ -#include "jsonrpc/impl/request.h" -#include "jsonrpc/impl/error.h" +#include "wf/jsonrpc/impl/request.h" +#include "wf/jsonrpc/impl/error.h" #include -struct jsonrpc_request +struct wf_jsonrpc_request { int id; - jsonrpc_send_fn * send; + wf_jsonrpc_send_fn * send; void * user_data; }; bool -jsonrpc_impl_is_request( +wf_jsonrpc_impl_is_request( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -22,13 +22,13 @@ jsonrpc_impl_is_request( } -struct jsonrpc_request * -jsonrpc_impl_request_create( +struct wf_jsonrpc_request * +wf_jsonrpc_impl_request_create( int id, - jsonrpc_send_fn * send, + wf_jsonrpc_send_fn * send, void * user_data) { - struct jsonrpc_request * request = malloc(sizeof(struct jsonrpc_request)); + struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request)); if (NULL != request) { request->id = id; @@ -40,23 +40,23 @@ jsonrpc_impl_request_create( } void -jsonrpc_impl_request_dispose( - struct jsonrpc_request * request) +wf_jsonrpc_impl_request_dispose( + struct wf_jsonrpc_request * request) { free(request); } void * -jsonrpc_impl_request_get_userdata( - struct jsonrpc_request * request) +wf_jsonrpc_impl_request_get_userdata( + struct wf_jsonrpc_request * request) { return request->user_data; } void -jsonrpc_impl_respond( - struct jsonrpc_request * request, +wf_jsonrpc_impl_respond( + struct wf_jsonrpc_request * request, json_t * result) { json_t * response = json_object(); @@ -65,20 +65,20 @@ jsonrpc_impl_respond( request->send(response, request->user_data); json_decref(response); - jsonrpc_impl_request_dispose(request); + wf_jsonrpc_impl_request_dispose(request); } -void jsonrpc_impl_respond_error( - struct jsonrpc_request * request, +void wf_jsonrpc_impl_respond_error( + struct wf_jsonrpc_request * request, int code, char const * message) { json_t * response = json_object(); - json_object_set_new(response, "error", jsonrpc_impl_error(code, message)); + json_object_set_new(response, "error", wf_jsonrpc_impl_error(code, message)); json_object_set_new(response, "id", json_integer(request->id)); request->send(response, request->user_data); json_decref(response); - jsonrpc_impl_request_dispose(request); + wf_jsonrpc_impl_request_dispose(request); } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h new file mode 100644 index 0000000..0d510e9 --- /dev/null +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h @@ -0,0 +1,53 @@ +#ifndef WF_JSONRPC_IMPL_REQUEST_H +#define WF_JSONRPC_IMPL_REQUEST_H + +#ifndef __cplusplus +#include +#include +#include +#else +#include +#include +using std::size_t; +#endif + +#include +#include +#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 diff --git a/lib/jsonrpc/src/jsonrpc/impl/response.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c similarity index 69% rename from lib/jsonrpc/src/jsonrpc/impl/response.c rename to lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c index 9f3d04e..07171fb 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/response.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c @@ -1,9 +1,9 @@ -#include "jsonrpc/impl/response.h" -#include "jsonrpc/impl/error.h" -#include "jsonrpc/status.h" +#include "wf/jsonrpc/impl/response.h" +#include "wf/jsonrpc/impl/error.h" +#include "wf/jsonrpc/status.h" bool -jsonrpc_impl_is_response( +wf_jsonrpc_impl_is_response( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -16,8 +16,8 @@ jsonrpc_impl_is_response( void -jsonrpc_impl_response_init( - struct jsonrpc_response * result, +wf_jsonrpc_impl_response_init( + struct wf_jsonrpc_response * result, json_t * response) { result->id = -1; @@ -27,7 +27,7 @@ jsonrpc_impl_response_init( json_t * id_holder = json_object_get(response, "id"); if ((NULL == id_holder) || (!json_is_integer(id_holder))) { - result->error = jsonrpc_impl_error(JSONRPC_BAD_FORMAT, "invalid format: missing id"); + result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: missing id"); return; } @@ -47,14 +47,14 @@ jsonrpc_impl_response_init( } else { - result->error = jsonrpc_impl_error(JSONRPC_BAD_FORMAT, "invalid format: invalid error object"); + result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: invalid error object"); } } } void -jsonrpc_impl_response_cleanup( - struct jsonrpc_response * response) +wf_jsonrpc_impl_response_cleanup( + struct wf_jsonrpc_response * response) { if (NULL != response->result) { diff --git a/lib/jsonrpc/src/jsonrpc/impl/response.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h similarity index 50% rename from lib/jsonrpc/src/jsonrpc/impl/response.h rename to lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h index b39e30e..3e1e02e 100644 --- a/lib/jsonrpc/src/jsonrpc/impl/response.h +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h @@ -1,5 +1,5 @@ -#ifndef JSONRPC_IMPL_RESPONSE_H -#define JSONRPC_IMPL_RESPONSE_H +#ifndef WF_JSONRPC_IMPL_RESPONSE_H +#define WF_JSONRPC_IMPL_RESPONSE_H #ifndef __cplusplus #include @@ -15,22 +15,22 @@ using std::size_t; extern "C" { #endif -struct jsonrpc_response +struct wf_jsonrpc_response { json_t * result; json_t * error; int id; }; -extern bool jsonrpc_impl_is_response( +extern bool wf_jsonrpc_impl_is_response( json_t * message); -extern void jsonrpc_impl_response_init( - struct jsonrpc_response * response, +extern void wf_jsonrpc_impl_response_init( + struct wf_jsonrpc_response * response, json_t * message); -extern void jsonrpc_impl_response_cleanup( - struct jsonrpc_response * response); +extern void wf_jsonrpc_impl_response_cleanup( + struct wf_jsonrpc_response * response); #ifdef __cplusplus } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c new file mode 100644 index 0000000..e510daa --- /dev/null +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c @@ -0,0 +1,132 @@ +#include "wf/jsonrpc/impl/server.h" +#include "wf/jsonrpc/impl/method.h" +#include "wf/jsonrpc/impl/request.h" +#include "wf/jsonrpc/impl/unused_param.h" +#include "wf/jsonrpc/status.h" + +#include +#include + +struct wf_jsonrpc_server +{ + struct wf_jsonrpc_method * methods; +}; + +static void +wf_jsonrpc_impl_server_init( + struct wf_jsonrpc_server * server); + +static void +wf_jsonrpc_impl_server_cleanup( + struct wf_jsonrpc_server * server); + +struct wf_jsonrpc_server * +wf_jsonrpc_impl_server_create(void) +{ + struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server)); + if (NULL != server) + { + wf_jsonrpc_impl_server_init(server); + } + + return server; +} + +void +wf_jsonrpc_impl_server_dispose( + struct wf_jsonrpc_server * server) +{ + wf_jsonrpc_impl_server_cleanup(server); + free(server); +} + + +static void wf_jsonrpc_impl_server_init( + struct wf_jsonrpc_server * server) +{ + server->methods = NULL; +} + +static void wf_jsonrpc_impl_server_cleanup( + struct wf_jsonrpc_server * server) +{ + struct wf_jsonrpc_method * current = server->methods; + while (NULL != current) + { + struct wf_jsonrpc_method * next = current->next; + wf_jsonrpc_impl_method_dispose(current); + current = next; + } + server->methods = NULL; +} + +void wf_jsonrpc_impl_server_add( + struct wf_jsonrpc_server * server, + char const * method_name, + wf_jsonrpc_method_invoke_fn * invoke, + void * user_data) +{ + struct wf_jsonrpc_method * method = wf_jsonrpc_impl_method_create(method_name, invoke, user_data); + method->next = server->methods; + server->methods = method; +} + +static void wf_jsonrpc_impl_server_invalid_method_invoke( + struct wf_jsonrpc_request * request, + char const * WF_JSONRPC_UNUSED_PARAM(method_name), + json_t * WF_JSONRPC_UNUSED_PARAM(params), + void * WF_JSONRPC_UNUSED_PARAM(user_data)) +{ + wf_jsonrpc_impl_respond_error(request, WF_JSONRPC_BAD_NOTIMPLEMENTED, "not implemented"); +} + +static struct wf_jsonrpc_method const wf_jsonrpc_impl_server_invalid_method = +{ + .next = NULL, + .name = "", + .invoke = &wf_jsonrpc_impl_server_invalid_method_invoke, + .user_data = NULL +}; + +static struct wf_jsonrpc_method const * +wf_jsonrpc_impl_server_get_method( + struct wf_jsonrpc_server * server, + char const * method_name) +{ + struct wf_jsonrpc_method const * current = server->methods; + while (NULL != current) + { + if (0 == strcmp(method_name, current->name)) + { + return current; + } + + current = current->next; + } + + return &wf_jsonrpc_impl_server_invalid_method; +} + +void wf_jsonrpc_impl_server_process( + struct wf_jsonrpc_server * server, + json_t * request_data, + wf_jsonrpc_send_fn * send, + void * user_data) +{ + json_t * method_holder = json_object_get(request_data, "method"); + json_t * params = json_object_get(request_data, "params"); + json_t * id_holder = json_object_get(request_data, "id"); + + if (json_is_string(method_holder) && + (json_is_array(params) || (json_is_object(params))) && + json_is_integer(id_holder)) + { + char const * method_name = json_string_value(method_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_method const * method = wf_jsonrpc_impl_server_get_method(server, method_name); + + method->invoke(request, method_name, params, method->user_data); + } +} + diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h new file mode 100644 index 0000000..82c7421 --- /dev/null +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h @@ -0,0 +1,41 @@ +#ifndef WF_JSONRPC_IMPL_SERVER_H +#define WF_JSONRPC_IMPL_SERVER_H + +#include +#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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h new file mode 100644 index 0000000..41323c8 --- /dev/null +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h @@ -0,0 +1,10 @@ +#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 diff --git a/lib/jsonrpc/test/jsonrpc/test_is_request.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc similarity index 65% rename from lib/jsonrpc/test/jsonrpc/test_is_request.cc rename to lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc index 03d95f7..55e40c6 100644 --- a/lib/jsonrpc/test/jsonrpc/test_is_request.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc @@ -1,112 +1,112 @@ #include -#include "jsonrpc/request.h" +#include "wf/jsonrpc/request.h" -TEST(jsonrpc_is_request, request_with_object_params) +TEST(wf_jsonrpc_is_request, request_with_object_params) { json_t * request = json_object(); json_object_set_new(request, "method", json_string("method")); json_object_set_new(request, "params", json_object()); json_object_set_new(request, "id", json_integer(42)); - ASSERT_TRUE(jsonrpc_is_request(request)); + ASSERT_TRUE(wf_jsonrpc_is_request(request)); json_decref(request); } -TEST(jsonrpc_is_request, request_with_array_params) +TEST(wf_jsonrpc_is_request, request_with_array_params) { json_t * request = json_object(); json_object_set_new(request, "method", json_string("method")); json_object_set_new(request, "params", json_array()); json_object_set_new(request, "id", json_integer(42)); - ASSERT_TRUE(jsonrpc_is_request(request)); + ASSERT_TRUE(wf_jsonrpc_is_request(request)); json_decref(request); } -TEST(jsonrpc_is_request, null_request) +TEST(wf_jsonrpc_is_request, null_request) { - ASSERT_FALSE(jsonrpc_is_request(nullptr)); + ASSERT_FALSE(wf_jsonrpc_is_request(nullptr)); } -TEST(jsonrpc_is_request, invalid_request) +TEST(wf_jsonrpc_is_request, invalid_request) { json_t * request = json_array(); json_array_append_new(request, json_string("method")); json_array_append_new(request, json_object()); json_array_append_new(request, json_integer(42)); - ASSERT_FALSE(jsonrpc_is_request(request)); + ASSERT_FALSE(wf_jsonrpc_is_request(request)); json_decref(request); } -TEST(jsonrpc_is_request, invalid_request_without_id) +TEST(wf_jsonrpc_is_request, invalid_request_without_id) { json_t * request = json_object(); json_object_set_new(request, "method", json_string("method")); json_object_set_new(request, "params", json_object()); - ASSERT_FALSE(jsonrpc_is_request(request)); + ASSERT_FALSE(wf_jsonrpc_is_request(request)); json_decref(request); } -TEST(jsonrpc_is_request, invalid_request_due_to_invalid_id) +TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_id) { json_t * request = json_object(); json_object_set_new(request, "method", json_string("method")); json_object_set_new(request, "params", json_object()); json_object_set_new(request, "id", json_string("42")); - ASSERT_FALSE(jsonrpc_is_request(request)); + ASSERT_FALSE(wf_jsonrpc_is_request(request)); json_decref(request); } -TEST(jsonrpc_is_request, invalid_request_without_method) +TEST(wf_jsonrpc_is_request, invalid_request_without_method) { json_t * request = json_object(); json_object_set_new(request, "params", json_object()); json_object_set_new(request, "id", json_integer(42)); - ASSERT_FALSE(jsonrpc_is_request(request)); + ASSERT_FALSE(wf_jsonrpc_is_request(request)); json_decref(request); } -TEST(jsonrpc_is_request, invalid_request_due_to_invalid_method) +TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_method) { json_t * request = json_object(); json_object_set_new(request, "method", json_integer(42)); json_object_set_new(request, "params", json_object()); json_object_set_new(request, "id", json_integer(42)); - ASSERT_FALSE(jsonrpc_is_request(request)); + ASSERT_FALSE(wf_jsonrpc_is_request(request)); json_decref(request); } -TEST(jsonrpc_is_request, invalid_request_without_params) +TEST(wf_jsonrpc_is_request, invalid_request_without_params) { json_t * request = json_object(); json_object_set_new(request, "method", json_string("method")); json_object_set_new(request, "id", json_integer(42)); - ASSERT_FALSE(jsonrpc_is_request(request)); + ASSERT_FALSE(wf_jsonrpc_is_request(request)); json_decref(request); } -TEST(jsonrpc_is_request, invalid_request_due_to_invalid_params) +TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_params) { json_t * request = json_object(); json_object_set_new(request, "methdo", json_string("method")); json_object_set_new(request, "params", json_string("params")); json_object_set_new(request, "id", json_integer(42)); - ASSERT_FALSE(jsonrpc_is_request(request)); + ASSERT_FALSE(wf_jsonrpc_is_request(request)); json_decref(request); } diff --git a/lib/jsonrpc/test/jsonrpc/test_is_response.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc similarity index 60% rename from lib/jsonrpc/test/jsonrpc/test_is_response.cc rename to lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc index b32a284..690bb6c 100644 --- a/lib/jsonrpc/test/jsonrpc/test_is_response.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc @@ -1,94 +1,94 @@ #include -#include "jsonrpc/response.h" +#include "wf/jsonrpc/response.h" -TEST(jsonrpc_is_response, valid_result) +TEST(wf_jsonrpc_is_response, valid_result) { json_t * message = json_object(); json_object_set_new(message, "result", json_object()); json_object_set_new(message, "id", json_integer(42)); - ASSERT_TRUE(jsonrpc_is_response(message)); + ASSERT_TRUE(wf_jsonrpc_is_response(message)); json_decref(message); } -TEST(jsonrpc_is_response, valid_result_string) +TEST(wf_jsonrpc_is_response, valid_result_string) { json_t * message = json_object(); json_object_set_new(message, "result", json_string("also valid")); json_object_set_new(message, "id", json_integer(42)); - ASSERT_TRUE(jsonrpc_is_response(message)); + ASSERT_TRUE(wf_jsonrpc_is_response(message)); json_decref(message); } -TEST(jsonrpc_is_response, valid_error) +TEST(wf_jsonrpc_is_response, valid_error) { json_t * message = json_object(); json_object_set_new(message, "error", json_object()); json_object_set_new(message, "id", json_integer(42)); - ASSERT_TRUE(jsonrpc_is_response(message)); + ASSERT_TRUE(wf_jsonrpc_is_response(message)); json_decref(message); } -TEST(jsonrpc_is_response, invalid_null) +TEST(wf_jsonrpc_is_response, invalid_null) { - ASSERT_FALSE(jsonrpc_is_response(nullptr)); + ASSERT_FALSE(wf_jsonrpc_is_response(nullptr)); } -TEST(jsonrpc_is_response, invalid_message) +TEST(wf_jsonrpc_is_response, invalid_message) { json_t * message = json_array(); json_array_append_new(message, json_object()); json_array_append_new(message, json_integer(42)); - ASSERT_FALSE(jsonrpc_is_response(message)); + ASSERT_FALSE(wf_jsonrpc_is_response(message)); json_decref(message); } -TEST(jsonrpc_is_response, invalid_missing_id) +TEST(wf_jsonrpc_is_response, invalid_missing_id) { json_t * message = json_object(); json_object_set_new(message, "result", json_object()); - ASSERT_FALSE(jsonrpc_is_response(message)); + ASSERT_FALSE(wf_jsonrpc_is_response(message)); json_decref(message); } -TEST(jsonrpc_is_response, invalid_id_wrong_type) +TEST(wf_jsonrpc_is_response, invalid_id_wrong_type) { json_t * message = json_object(); json_object_set_new(message, "result", json_object()); json_object_set_new(message, "id", json_string("42")); - ASSERT_FALSE(jsonrpc_is_response(message)); + ASSERT_FALSE(wf_jsonrpc_is_response(message)); json_decref(message); } -TEST(jsonrpc_is_response, invalid_missing_result_and_error) +TEST(wf_jsonrpc_is_response, invalid_missing_result_and_error) { json_t * message = json_object(); json_object_set_new(message, "id", json_integer(42)); - ASSERT_FALSE(jsonrpc_is_response(message)); + ASSERT_FALSE(wf_jsonrpc_is_response(message)); json_decref(message); } -TEST(jsonrpc_is_response, invalid_error_wrong_type) +TEST(wf_jsonrpc_is_response, invalid_error_wrong_type) { json_t * message = json_object(); json_object_set_new(message, "error", json_array()); json_object_set_new(message, "id", json_integer(42)); - ASSERT_FALSE(jsonrpc_is_response(message)); + ASSERT_FALSE(wf_jsonrpc_is_response(message)); json_decref(message); } diff --git a/lib/jsonrpc/test/jsonrpc/test_proxy.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc similarity index 73% rename from lib/jsonrpc/test/jsonrpc/test_proxy.cc rename to lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc index cc71ae8..416c25f 100644 --- a/lib/jsonrpc/test/jsonrpc/test_proxy.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc @@ -1,5 +1,5 @@ #include -#include "jsonrpc/proxy.h" +#include "wf/jsonrpc/proxy.h" #include "wf/timer/manager.h" #include "webfuse/utils/msleep.hpp" #include "webfuse/core/json_util.h" @@ -85,31 +85,31 @@ namespace } } -TEST(jsonrpc_proxy, init) +TEST(wf_jsonrpc_proxy, init) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext context; void * user_data = reinterpret_cast(&context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); ASSERT_FALSE(context.is_called); } -TEST(jsonrpc_proxy, invoke) +TEST(wf_jsonrpc_proxy, invoke) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -131,24 +131,24 @@ TEST(jsonrpc_proxy, invoke) ASSERT_FALSE(finished_context.is_called); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); ASSERT_TRUE(finished_context.is_called); ASSERT_FALSE(nullptr == finished_context.error); } -TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails) +TEST(wf_jsonrpc_proxy, invoke_calls_finish_if_send_fails) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context(false); void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -156,25 +156,25 @@ TEST(jsonrpc_proxy, invoke_calls_finish_if_send_fails) ASSERT_TRUE(finished_context.is_called); ASSERT_FALSE(nullptr == finished_context.error); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } -TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending) +TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); FinishedContext finished_context2; void * finished_data2 = reinterpret_cast(&finished_context2); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", ""); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", ""); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -184,42 +184,42 @@ TEST(jsonrpc_proxy, invoke_fails_if_another_request_is_pending) ASSERT_TRUE(finished_context2.is_called); ASSERT_EQ(WF_BAD_BUSY, wf_impl_jsonrpc_get_status(finished_context2.error)); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } -TEST(jsonrpc_proxy, invoke_fails_if_request_is_invalid) +TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error"); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error"); ASSERT_FALSE(send_context.is_called); ASSERT_TRUE(finished_context.is_called); ASSERT_EQ(WF_BAD, wf_impl_jsonrpc_get_status(finished_context.error)); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } -TEST(jsonrpc_proxy, on_result) +TEST(wf_jsonrpc_proxy, on_result) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -231,7 +231,7 @@ TEST(jsonrpc_proxy, on_result) json_object_set_new(response, "result", json_string("okay")); json_object_set(response, "id", id); - jsonrpc_proxy_onresult(proxy, response); + wf_jsonrpc_proxy_onresult(proxy, response); json_decref(response); ASSERT_TRUE(finished_context.is_called); @@ -239,21 +239,21 @@ TEST(jsonrpc_proxy, on_result) ASSERT_TRUE(json_is_string(finished_context.result)); ASSERT_STREQ("okay", json_string_value(finished_context.result)); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } -TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id) +TEST(wf_jsonrpc_proxy, on_result_reject_response_with_unknown_id) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -265,26 +265,26 @@ TEST(jsonrpc_proxy, on_result_reject_response_with_unknown_id) json_object_set_new(response, "result", json_string("okay")); json_object_set_new(response, "id", json_integer(1 + json_integer_value(id))); - jsonrpc_proxy_onresult(proxy, response); + wf_jsonrpc_proxy_onresult(proxy, response); json_decref(response); ASSERT_FALSE(finished_context.is_called); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } -TEST(jsonrpc_proxy, timeout) +TEST(wf_jsonrpc_proxy, timeout) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -295,28 +295,28 @@ TEST(jsonrpc_proxy, timeout) ASSERT_TRUE(finished_context.is_called); ASSERT_EQ(WF_BAD_TIMEOUT, wf_impl_jsonrpc_get_status(finished_context.error)); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } -TEST(jsonrpc_proxy, cleanup_pending_request) +TEST(wf_jsonrpc_proxy, cleanup_pending_request) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data); FinishedContext finished_context; void * finished_data = reinterpret_cast(&finished_context); - jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); + wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); ASSERT_FALSE(finished_context.is_called); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); ASSERT_TRUE(finished_context.is_called); @@ -325,15 +325,15 @@ TEST(jsonrpc_proxy, cleanup_pending_request) -TEST(jsonrpc_proxy, notify) +TEST(wf_jsonrpc_proxy, notify) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); - jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42); + wf_jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42); ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); @@ -353,22 +353,22 @@ TEST(jsonrpc_proxy, notify) json_t * id = json_object_get(send_context.response, "id"); ASSERT_EQ(nullptr, id); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } -TEST(jsonrpc_proxy, notify_dont_send_invalid_request) +TEST(wf_jsonrpc_proxy, notify_dont_send_invalid_request) { struct wf_timer_manager * timer_manager = wf_timer_manager_create(); SendContext send_context; void * send_data = reinterpret_cast(&send_context); - struct jsonrpc_proxy * proxy = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); - jsonrpc_proxy_notify(proxy, "foo", "?"); + wf_jsonrpc_proxy_notify(proxy, "foo", "?"); ASSERT_FALSE(send_context.is_called); - jsonrpc_proxy_dispose(proxy); + wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } diff --git a/lib/jsonrpc/test/jsonrpc/test_request.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc similarity index 70% rename from lib/jsonrpc/test/jsonrpc/test_request.cc rename to lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc index a5f956e..eb15e91 100644 --- a/lib/jsonrpc/test/jsonrpc/test_request.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc @@ -1,6 +1,6 @@ #include -#include "jsonrpc/request.h" -#include "jsonrpc/status.h" +#include "wf/jsonrpc/request.h" +#include "wf/jsonrpc/status.h" namespace { @@ -23,29 +23,29 @@ bool jsonrpc_send( } -TEST(jsonrpc_request, create_dispose) +TEST(wf_jsonrpc_request, create_dispose) { Context context{nullptr}; void * user_data = reinterpret_cast(&context); - struct jsonrpc_request * request = - jsonrpc_request_create(42, &jsonrpc_send, user_data); + struct wf_jsonrpc_request * request = + wf_jsonrpc_request_create(42, &jsonrpc_send, user_data); ASSERT_NE(nullptr, request); - ASSERT_EQ(user_data, jsonrpc_request_get_userdata(request)); + ASSERT_EQ(user_data, wf_jsonrpc_request_get_userdata(request)); - jsonrpc_request_dispose(request); + wf_jsonrpc_request_dispose(request); } -TEST(jsonrpc_request, respond) +TEST(wf_jsonrpc_request, respond) { Context context{nullptr}; void * user_data = reinterpret_cast(&context); - struct jsonrpc_request * request = - jsonrpc_request_create(42, &jsonrpc_send, user_data); + struct wf_jsonrpc_request * request = + wf_jsonrpc_request_create(42, &jsonrpc_send, user_data); - jsonrpc_respond(request, json_string("okay")); + wf_jsonrpc_respond(request, json_string("okay")); ASSERT_NE(nullptr, context.response); @@ -66,15 +66,15 @@ TEST(jsonrpc_request, respond) json_decref(response); } -TEST(jsonrpc_request, respond_error) +TEST(wf_jsonrpc_request, respond_error) { Context context{nullptr}; void * user_data = reinterpret_cast(&context); - struct jsonrpc_request * request = - jsonrpc_request_create(42, &jsonrpc_send, user_data); + struct wf_jsonrpc_request * request = + wf_jsonrpc_request_create(42, &jsonrpc_send, user_data); - jsonrpc_respond_error(request, JSONRPC_BAD, "Bad"); + wf_jsonrpc_respond_error(request, WF_JSONRPC_BAD, "Bad"); ASSERT_NE(nullptr, context.response); @@ -93,7 +93,7 @@ TEST(jsonrpc_request, respond_error) json_t * err_code = json_object_get(err, "code"); ASSERT_TRUE(json_is_integer(err_code)); - ASSERT_EQ(JSONRPC_BAD, json_integer_value(err_code)); + ASSERT_EQ(WF_JSONRPC_BAD, json_integer_value(err_code)); json_t * err_message = json_object_get(err, "message"); ASSERT_TRUE(json_is_string(err_message)); diff --git a/lib/jsonrpc/test/jsonrpc/test_response.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc similarity index 69% rename from lib/jsonrpc/test/jsonrpc/test_response.cc rename to lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc index bdf6e61..911319d 100644 --- a/lib/jsonrpc/test/jsonrpc/test_response.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc @@ -1,27 +1,27 @@ #include -#include "jsonrpc/impl/response.h" +#include "wf/jsonrpc/impl/response.h" #include "webfuse/core/status.h" #include "webfuse/core/json_util.h" -TEST(json_response, init_result) +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 jsonrpc_response response; - jsonrpc_impl_response_init(&response, message); + 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); - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); json_decref(message); } -TEST(json_response, init_error) +TEST(wf_json_response, init_error) { json_t * message = json_object(); json_t * err = json_object(); @@ -30,29 +30,29 @@ TEST(json_response, init_error) json_object_set_new(message, "error", err); json_object_set_new(message, "id", json_integer(23)); - struct jsonrpc_response response; - jsonrpc_impl_response_init(&response, message); + struct wf_jsonrpc_response response; + wf_jsonrpc_impl_response_init(&response, message); ASSERT_EQ(WF_BAD_ACCESS_DENIED, wf_impl_jsonrpc_get_status(response.error)) << json_string_value(json_object_get(response.error, "message")); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); json_decref(message); } -TEST(json_response, init_format_error) +TEST(wf_json_response, init_format_error) { json_t * message = json_object(); json_object_set_new(message, "id", json_integer(12)); - struct jsonrpc_response response; - jsonrpc_impl_response_init(&response, message); + struct wf_jsonrpc_response response; + wf_jsonrpc_impl_response_init(&response, message); ASSERT_EQ(WF_BAD_FORMAT, wf_impl_jsonrpc_get_status(response.error)); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(12, response.id); - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); json_decref(message); } diff --git a/lib/jsonrpc/test/jsonrpc/test_response_parser.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc similarity index 75% rename from lib/jsonrpc/test/jsonrpc/test_response_parser.cc rename to lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc index f65fa6f..81a73bd 100644 --- a/lib/jsonrpc/test/jsonrpc/test_response_parser.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc @@ -1,46 +1,46 @@ #include #include -#include "jsonrpc/impl/response.h" +#include "wf/jsonrpc/impl/response.h" #include "webfuse/core/json_util.h" static void response_parse_str( std::string const & buffer, - struct jsonrpc_response * response) + struct wf_jsonrpc_response * response) { json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr); if (nullptr != message) { - jsonrpc_impl_response_init(response, message); + wf_jsonrpc_impl_response_init(response, message); json_decref(message); } } TEST(response_parser, test) { - struct jsonrpc_response response; + struct wf_jsonrpc_response response; // no object response_parse_str("[]", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); // empty response_parse_str("{}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); // no data response_parse_str("{\"id\":42}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); // custom error code response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); @@ -48,12 +48,12 @@ TEST(response_parser, test) ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); // valid response response_parse_str("{\"result\": true, \"id\": 42}", &response); ASSERT_EQ(WF_GOOD, response.error); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); - jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_impl_response_cleanup(&response); } diff --git a/lib/jsonrpc/test/jsonrpc/test_server.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc similarity index 72% rename from lib/jsonrpc/test/jsonrpc/test_server.cc rename to lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc index e8e879a..14f7ac5 100644 --- a/lib/jsonrpc/test/jsonrpc/test_server.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc @@ -1,7 +1,7 @@ #include -#include "jsonrpc/server.h" -#include "jsonrpc/request.h" -#include "jsonrpc/status.h" +#include "wf/jsonrpc/server.h" +#include "wf/jsonrpc/request.h" +#include "wf/jsonrpc/status.h" namespace { @@ -24,7 +24,7 @@ namespace } void sayHello( - struct jsonrpc_request * request, + struct wf_jsonrpc_request * request, char const * method_name, json_t * params, void * user_data) @@ -34,15 +34,15 @@ namespace (void) user_data; json_t * result = json_string("Hello"); - jsonrpc_respond(request, result); + wf_jsonrpc_respond(request, result); } } -TEST(jsonrpc_server, process_request) +TEST(wf_jsonrpc_server, process_request) { - struct jsonrpc_server * server = jsonrpc_server_create(); - jsonrpc_server_add(server, "sayHello", &sayHello, nullptr); + 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(&context); @@ -50,7 +50,7 @@ TEST(jsonrpc_server, process_request) 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)); - jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); ASSERT_TRUE(context.is_called); ASSERT_NE(nullptr, context.response); @@ -66,13 +66,13 @@ TEST(jsonrpc_server, process_request) json_decref(context.response); json_decref(request); - jsonrpc_server_dispose(server); + wf_jsonrpc_server_dispose(server); } -TEST(jsonrpc_server, invoke_unknown_method) +TEST(wf_jsonrpc_server, invoke_unknown_method) { - struct jsonrpc_server * server = jsonrpc_server_create(); - jsonrpc_server_add(server, "sayHello", &sayHello, nullptr); + 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(&context); @@ -80,7 +80,7 @@ TEST(jsonrpc_server, invoke_unknown_method) 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)); - jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); ASSERT_TRUE(context.is_called); ASSERT_NE(nullptr, context.response); @@ -95,29 +95,29 @@ TEST(jsonrpc_server, invoke_unknown_method) json_t * err_code = json_object_get(err, "code"); ASSERT_TRUE(json_is_integer(err_code)); - ASSERT_EQ(JSONRPC_BAD_NOTIMPLEMENTED, json_integer_value(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); - jsonrpc_server_dispose(server); + wf_jsonrpc_server_dispose(server); } -TEST(jsonrpc_server, skip_invalid_request) +TEST(wf_jsonrpc_server, skip_invalid_request) { - struct jsonrpc_server * server = jsonrpc_server_create(); + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); Context context{nullptr, false}; void * user_data = reinterpret_cast(&context); json_t * request = json_object(); json_object_set_new(request, "method", json_string("sayHello")); json_object_set_new(request, "params", json_array()); - jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); ASSERT_FALSE(context.is_called); json_decref(request); - jsonrpc_server_dispose(server); + wf_jsonrpc_server_dispose(server); } diff --git a/lib/jsonrpc/test/jsonrpc/test_util.cc b/test/webfuse/tests/core/test_util.cc similarity index 100% rename from lib/jsonrpc/test/jsonrpc/test_util.cc rename to test/webfuse/tests/core/test_util.cc From 107e66b65a992d5da0e0d5e64abf0c3ccfe1d41d Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 17:23:59 +0100 Subject: [PATCH 075/138] chore: replaced msleep by std::this_thread::sleep_for --- cmake/unit_tests.cmake | 1 - lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc | 9 ++++++--- lib/wf/timer/test/wf/timer/test_timepoint.cc | 8 +++++--- lib/wf/timer/test/wf/timer/test_timer.cc | 13 +++++++------ test/webfuse/tests/integration/provider.cc | 6 ++++-- test/webfuse/tests/integration/server.cc | 1 - test/webfuse/utils/msleep.cc | 19 ------------------- test/webfuse/utils/msleep.hpp | 12 ------------ 8 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 test/webfuse/utils/msleep.cc delete mode 100644 test/webfuse/utils/msleep.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index b7887fa..13b91f9 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -18,7 +18,6 @@ add_executable(alltests lib/wf/timer/test/wf/timer/test_timer.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc - test/webfuse/utils/msleep.cc test/webfuse/utils/die_if.cc test/webfuse/utils/timeout_watcher.cc test/webfuse/utils/path.c diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc index 416c25f..af38a5c 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc @@ -1,10 +1,13 @@ #include #include "wf/jsonrpc/proxy.h" #include "wf/timer/manager.h" -#include "webfuse/utils/msleep.hpp" #include "webfuse/core/json_util.h" -using webfuse_test::msleep; +#include +#include + +using namespace std::chrono_literals; + #define WF_DEFAULT_TIMEOUT (10 * 1000) @@ -289,7 +292,7 @@ TEST(wf_jsonrpc_proxy, timeout) ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); - msleep(10); + std::this_thread::sleep_for(10ms); wf_timer_manager_check(timer_manager); ASSERT_TRUE(finished_context.is_called); diff --git a/lib/wf/timer/test/wf/timer/test_timepoint.cc b/lib/wf/timer/test/wf/timer/test_timepoint.cc index bd7774a..723ff6a 100644 --- a/lib/wf/timer/test/wf/timer/test_timepoint.cc +++ b/lib/wf/timer/test/wf/timer/test_timepoint.cc @@ -1,14 +1,16 @@ #include -#include "webfuse/utils/msleep.hpp" #include "wf/timer/impl/timepoint.h" -using webfuse_test::msleep; +#include +#include + +using namespace std::chrono_literals; TEST(wf_timer_timepoint, now) { wf_timer_timepoint start = wf_timer_impl_timepoint_now(); - msleep(42); + std::this_thread::sleep_for(42ms); wf_timer_timepoint end = wf_timer_impl_timepoint_now(); ASSERT_LT(start, end); diff --git a/lib/wf/timer/test/wf/timer/test_timer.cc b/lib/wf/timer/test/wf/timer/test_timer.cc index ffeb1d3..e97c011 100644 --- a/lib/wf/timer/test/wf/timer/test_timer.cc +++ b/lib/wf/timer/test/wf/timer/test_timer.cc @@ -1,13 +1,14 @@ #include #include +#include +#include -#include "webfuse/utils/msleep.hpp" #include "wf/timer/timer.h" #include "wf/timer/manager.h" using std::size_t; -using webfuse_test::msleep; +using namespace std::chrono_literals; extern "C" { @@ -37,7 +38,7 @@ TEST(wf_timer, trigger) struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); wf_timer_start(timer, 250); - msleep(500); + std::this_thread::sleep_for(500ms); wf_timer_manager_check(manager); ASSERT_TRUE(triggered); @@ -67,7 +68,7 @@ TEST(wf_timer, cancel) struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); wf_timer_start(timer, 250); - msleep(500); + std::this_thread::sleep_for(500ms); wf_timer_cancel(timer); wf_timer_manager_check(manager); @@ -90,7 +91,7 @@ TEST(wf_timer, cancel_multiple_timers) wf_timer_start(timer[i], 0); } - msleep(10); + std::this_thread::sleep_for(10ms); for(size_t i = 0; i < count; i++) { wf_timer_cancel(timer[i]); @@ -122,7 +123,7 @@ TEST(wf_timer, multiple_timers) for(size_t i = 0; i < count; i++) { - msleep(100); + std::this_thread::sleep_for(100ms); wf_timer_manager_check(manager); } diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index 5142ca8..45e331a 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -3,10 +3,12 @@ #include "webfuse/provider/impl/client.h" #include #include +#include #include -#include "webfuse/utils/msleep.hpp" #include "webfuse/utils/static_filesystem.h" +using namespace std::chrono_literals; + namespace webfuse_test { @@ -29,7 +31,7 @@ public: } thread = std::thread(Run, this); - webfuse_test::msleep(200); + std::this_thread::sleep_for(200ms); } ~Private() diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index 847efa2..e48f074 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -6,7 +6,6 @@ #include #include "webfuse_adapter.h" #include "webfuse/adapter/impl/server.h" -#include "webfuse/utils/msleep.hpp" #define WF_PATH_MAX (100) diff --git a/test/webfuse/utils/msleep.cc b/test/webfuse/utils/msleep.cc deleted file mode 100644 index 659bb81..0000000 --- a/test/webfuse/utils/msleep.cc +++ /dev/null @@ -1,19 +0,0 @@ -#include "webfuse/utils/msleep.hpp" -#include - -namespace webfuse_test -{ - -void msleep(long millis) -{ - long const secs_per_msec = 1000; - long const msecs_per_nsec = (1000 * 1000); - - long const seconds = millis / secs_per_msec; - long const nanos = (millis % secs_per_msec) * msecs_per_nsec; - - struct timespec timeout = { seconds, nanos }; - while (0 != nanosleep(&timeout, &timeout)); -} - -} \ No newline at end of file diff --git a/test/webfuse/utils/msleep.hpp b/test/webfuse/utils/msleep.hpp deleted file mode 100644 index 47cb1e6..0000000 --- a/test/webfuse/utils/msleep.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef WF_TEST_MSLEEP_HPP -#define WF_TEST_MSLEEP_HPP - -namespace webfuse_test -{ - -extern void msleep(long millis); - -} - - -#endif From ab6a6198b197b1c7992c6f5d172ec3e1a80fff73 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 17:44:12 +0100 Subject: [PATCH 076/138] chore: removed webfuse dependency in unit tests --- lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc | 13 +++++++++---- lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc | 12 ++++++------ .../jsonrpc/test/wf/jsonrpc/test_response_parser.cc | 3 +-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc index af38a5c..66eafa9 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc @@ -1,7 +1,7 @@ #include #include "wf/jsonrpc/proxy.h" +#include "wf/jsonrpc/status.h" #include "wf/timer/manager.h" -#include "webfuse/core/json_util.h" #include #include @@ -13,6 +13,11 @@ using namespace std::chrono_literals; namespace { + int jsonrpc_get_status(json_t * error) + { + json_t * code = json_object_get(error, "code"); + return (json_is_integer(code)) ? json_integer_value(code) : WF_JSONRPC_BAD_FORMAT; + } struct SendContext { @@ -185,7 +190,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending) ASSERT_FALSE(finished_context.is_called); ASSERT_TRUE(finished_context2.is_called); - ASSERT_EQ(WF_BAD_BUSY, wf_impl_jsonrpc_get_status(finished_context2.error)); + ASSERT_EQ(WF_JSONRPC_BAD_BUSY, jsonrpc_get_status(finished_context2.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); @@ -206,7 +211,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid) ASSERT_FALSE(send_context.is_called); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_BAD, wf_impl_jsonrpc_get_status(finished_context.error)); + ASSERT_EQ(WF_JSONRPC_BAD, jsonrpc_get_status(finished_context.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); @@ -296,7 +301,7 @@ TEST(wf_jsonrpc_proxy, timeout) wf_timer_manager_check(timer_manager); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_BAD_TIMEOUT, wf_impl_jsonrpc_get_status(finished_context.error)); + ASSERT_EQ(WF_JSONRPC_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc index 911319d..e8515aa 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc @@ -1,7 +1,6 @@ #include #include "wf/jsonrpc/impl/response.h" -#include "webfuse/core/status.h" -#include "webfuse/core/json_util.h" +#include "wf/jsonrpc/status.h" TEST(wf_json_response, init_result) { @@ -25,15 +24,16 @@ TEST(wf_json_response, init_error) { json_t * message = json_object(); json_t * err = json_object(); - json_object_set_new(err, "code", json_integer(WF_BAD_ACCESS_DENIED)); - json_object_set_new(err, "message", json_string("access denied")); + 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(WF_BAD_ACCESS_DENIED, wf_impl_jsonrpc_get_status(response.error)) << json_string_value(json_object_get(response.error, "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); @@ -49,7 +49,7 @@ TEST(wf_json_response, init_format_error) struct wf_jsonrpc_response response; wf_jsonrpc_impl_response_init(&response, message); - ASSERT_EQ(WF_BAD_FORMAT, wf_impl_jsonrpc_get_status(response.error)); + 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); diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc index 81a73bd..e3301fa 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc @@ -2,7 +2,6 @@ #include #include "wf/jsonrpc/impl/response.h" -#include "webfuse/core/json_util.h" static void response_parse_str( @@ -52,7 +51,7 @@ TEST(response_parser, test) // valid response response_parse_str("{\"result\": true, \"id\": 42}", &response); - ASSERT_EQ(WF_GOOD, response.error); + ASSERT_EQ(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); wf_jsonrpc_impl_response_cleanup(&response); From adfce8551edc4cfa3c8b23e2c0bf872a5642e365 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 19:08:39 +0100 Subject: [PATCH 077/138] fix: added dependend libs to libwebfuse-provider --- cmake/webfuse_provider.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index a0c9e08..4cf285d 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -20,7 +20,7 @@ add_library(webfuse-provider-static STATIC set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider) set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden) -target_include_directories(webfuse-provider-static PUBLIC +target_include_directories(webfuse-provider-static PRIVATE lib lib/wf/timer/include lib/wf/jsonrpc/include @@ -36,7 +36,7 @@ set_target_properties(webfuse-provider PROPERTIES C_VISIBILITY_PRESET hidden) set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT") target_include_directories(webfuse-provider PUBLIC lib) -target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core) +target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core wf_jsonrpc wf_timer) file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" From 670705bccf438cbe4119f5570273bd409a58bc22 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 20:17:41 +0100 Subject: [PATCH 078/138] increased version number --- CMakeLists.txt | 2 +- Doxyfile | 2 +- VERSION | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00daef9..cfe430b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 3.10) -project(webfuse VERSION 0.2.0 DESCRIPTION "Websocket filesystem based on libfuse") +project(webfuse VERSION 0.3.0 DESCRIPTION "Websocket filesystem based on libfuse") option(WITHOUT_TESTS "disable unit tests" OFF) option(WITHOUT_ADAPTER "disable adapter library" OFF) diff --git a/Doxyfile b/Doxyfile index 088248a..4f4ccdf 100644 --- a/Doxyfile +++ b/Doxyfile @@ -5,7 +5,7 @@ #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = "webfuse" -PROJECT_NUMBER = 0.2.0 +PROJECT_NUMBER = 0.3.0 PROJECT_BRIEF = "Websocket filesystem based on libfuse" PROJECT_LOGO = OUTPUT_DIRECTORY = "doc/api" diff --git a/VERSION b/VERSION index 0ea3a94..0d91a54 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.3.0 From 872b17e7e96b37bba9d2b5bd7ddf6b46cfc629c3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 7 Mar 2020 15:07:25 +0100 Subject: [PATCH 079/138] removed unnecessary stuff --- .github/ISSUE_TEMPLATE/bug_report.md | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index c6f8c69..b8f9cff 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -2,15 +2,15 @@ name: Bug report about: Create a report to help us improve title: '' -labels: '' +labels: 'bug' assignees: '' --- -**Describe the bug** +**Description** A clear and concise description of what the bug is. -**To Reproduce** +**Steps To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' @@ -20,19 +20,5 @@ Steps to reproduce the behavior: **Expected behavior** A clear and concise description of what you expected to happen. -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** -- OS: \[e.g. iOS\] -- Browser \[e.g. chrome, safari\] -- Version \[e.g. 22\] - -**Smartphone (please complete the following information):** -- Device: \[e.g. iPhone6\] -- OS: \[e.g. iOS8.1\] -- Browser \[e.g. stock browser, safari\] -- Version \[e.g. 22\] - **Additional context** Add any other context about the problem here. From d2f078298eb5610a4a3a8c8445d9d9141d4c77fd Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 7 Mar 2020 15:27:04 +0100 Subject: [PATCH 080/138] added function to interrupt _service calls --- include/webfuse/adapter/server.h | 18 +++++++++++++++++- include/webfuse/provider/client.h | 18 +++++++++++++++++- lib/webfuse/adapter/api.c | 13 +++++++++++-- lib/webfuse/adapter/impl/server.c | 12 +++++++++--- lib/webfuse/adapter/impl/server.h | 6 ++++-- lib/webfuse/provider/api.c | 13 +++++++++++-- lib/webfuse/provider/impl/client.c | 10 +++++++--- lib/webfuse/provider/impl/client.h | 6 ++++-- 8 files changed, 80 insertions(+), 16 deletions(-) diff --git a/include/webfuse/adapter/server.h b/include/webfuse/adapter/server.h index 8e392ac..150ded5 100644 --- a/include/webfuse/adapter/server.h +++ b/include/webfuse/adapter/server.h @@ -46,13 +46,29 @@ extern WF_API void wf_server_dispose( /// This function must be invoked in a loop while the server is running. It /// makes the server wait for the next event and processes it. /// +/// \note timeout_ms is no longer used +/// /// \param server pointer to server -/// \param timeout_ms timeout in milliseconds. +/// \param timeout_ms unused; set to 0; used for backward compatibility +/// +/// \see wf_server_interrupt //------------------------------------------------------------------------------ extern WF_API void wf_server_service( struct wf_server * server, int timeout_ms); +//------------------------------------------------------------------------------ +/// \brief Interrupts wf_server_service +/// +/// This function can be used from another thread. +/// +/// \param server pointer to server +/// +/// \see wf_server_service +//------------------------------------------------------------------------------ +extern WF_API void wf_server_interrupt( + struct wf_server * server); + #ifdef __cplusplus } #endif diff --git a/include/webfuse/provider/client.h b/include/webfuse/provider/client.h index b78fc4a..0f6ba4f 100644 --- a/include/webfuse/provider/client.h +++ b/include/webfuse/provider/client.h @@ -78,13 +78,29 @@ extern WFP_API void wfp_client_dispose( /// This function must be invoked in a loop while the client is running. It /// makes the server wait for the next event and processes it. /// +/// \note timeout is ignored +/// /// \param client pointer to client -/// \param timeout_ms timeout in milliseconds. +/// \param timeout_ms unused; set to 0; for backward compatibilty +/// +/// \see wfp_client_interrupt //------------------------------------------------------------------------------ extern WFP_API void wfp_client_service( struct wfp_client * client, int timeout_ms); +//------------------------------------------------------------------------------ +/// \brief interrupt wfp_client_service +/// +/// This function can be called from another thread. +/// +/// \param client pointer to client +/// +/// \see wfp_client_service +//------------------------------------------------------------------------------ +extern WFP_API void wfp_client_interrupt( + struct wfp_client * client); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index adecac2..2047029 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -6,6 +6,8 @@ #include "webfuse/adapter/impl/credentials.h" #include "webfuse/adapter/impl/mountpoint.h" +#include "webfuse/core/util.h" + // server struct wf_server * wf_server_create( @@ -22,11 +24,18 @@ void wf_server_dispose( void wf_server_service( struct wf_server * server, - int timeout_ms) + int WF_UNUSED_PARAM(imeout_ms)) { - wf_impl_server_service(server, timeout_ms); + wf_impl_server_service(server); } +void wf_server_interrupt( + struct wf_server * server) +{ + wf_impl_server_interrupt(server); +} + + // server protocol struct wf_server_protocol * wf_server_protocol_create( diff --git a/lib/webfuse/adapter/impl/server.c b/lib/webfuse/adapter/impl/server.c index bf32b85..f6e1f63 100644 --- a/lib/webfuse/adapter/impl/server.c +++ b/lib/webfuse/adapter/impl/server.c @@ -111,8 +111,14 @@ bool wf_impl_server_is_operational( } void wf_impl_server_service( - struct wf_server * server, - int timeout_ms) + struct wf_server * server) { - lws_service(server->context, timeout_ms); + lws_service(server->context, 0); } + +void wf_impl_server_interrupt( + struct wf_server * server) +{ + lws_cancel_service(server->context); +} + diff --git a/lib/webfuse/adapter/impl/server.h b/lib/webfuse/adapter/impl/server.h index 1f04cc7..56dab8d 100644 --- a/lib/webfuse/adapter/impl/server.h +++ b/lib/webfuse/adapter/impl/server.h @@ -23,8 +23,10 @@ extern bool wf_impl_server_is_operational( struct wf_server * server); extern void wf_impl_server_service( - struct wf_server * server, - int timeout_ms); + struct wf_server * server); + +extern void wf_impl_server_interrupt( + struct wf_server * server); #ifdef __cplusplus } diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 7c3220b..0704095 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -13,6 +13,8 @@ #include "webfuse/provider/impl/dirbuffer.h" #include "webfuse/provider/impl/credentials.h" +#include "webfuse/core/util.h" + // respond void wfp_respond_error( @@ -223,11 +225,18 @@ void wfp_client_dispose( void wfp_client_service( struct wfp_client * client, - int timeout_ms) + int WF_UNUSED_PARAM(timeout_ms)) { - wfp_impl_client_service(client, timeout_ms); + wfp_impl_client_service(client); } +void wfp_client_interrupt( + struct wfp_client * client) +{ + wfp_impl_client_interrupt(client); +} + + // dirbuffer struct wfp_dirbuffer * wfp_dirbuffer_create(void) diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index 4ddae92..21af148 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -84,9 +84,13 @@ bool wfp_impl_client_is_connected( } void wfp_impl_client_service( - struct wfp_client * client, - int timeout_ms) + struct wfp_client * client) { - lws_service(client->context, timeout_ms); + lws_service(client->context, 0); } +void wfp_impl_client_interrupt( + struct wfp_client * client) +{ + lws_cancel_service(client->context); +} diff --git a/lib/webfuse/provider/impl/client.h b/lib/webfuse/provider/impl/client.h index 4ade5f2..46e41f9 100644 --- a/lib/webfuse/provider/impl/client.h +++ b/lib/webfuse/provider/impl/client.h @@ -38,8 +38,10 @@ extern bool wfp_impl_client_is_connected( struct wfp_client * client); extern void wfp_impl_client_service( - struct wfp_client * client, - int timeout_ms); + struct wfp_client * client); + +extern void wfp_impl_client_interrupt( + struct wfp_client * client); #ifdef __cplusplus } From e5da835e80e0875f9a6b26b9a0b2456218b1df06 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 7 Mar 2020 17:13:16 +0100 Subject: [PATCH 081/138] chore: use interrupt function in tests --- test/webfuse/tests/integration/provider.cc | 1 + test/webfuse/tests/integration/server.cc | 1 + 2 files changed, 2 insertions(+) diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index 45e331a..b1fa44d 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -55,6 +55,7 @@ private: { std::lock_guard lock(shutdown_lock); is_shutdown_requested = true; + wfp_client_interrupt(client); } static void Run(Provider::Private * context) diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index e48f074..177a69f 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -61,6 +61,7 @@ private: { std::lock_guard lock(shutdown_lock); is_shutdown_requested = true; + wf_server_interrupt(server); } static void Run(Server::Private * context) From 50c5e57a69ea4dba6b2424f35808b20f3ecc2365 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 20 Mar 2020 17:03:33 +0100 Subject: [PATCH 082/138] updated libfuse to 3.9.1 --- Makefile | 4 ++-- build/amd64-alpine-builder.dockerfile | 2 +- build/amd64-ubuntu-builder.dockerfile | 2 +- build/arm32v7-alpine-builder.dockerfile | 2 +- build/arm32v7-ubuntu-builder.dockerfile | 2 +- doc/build.md | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index bdcc591..4f45263 100644 --- a/Makefile +++ b/Makefile @@ -56,11 +56,11 @@ FETCH_TARGETS += $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: URL := https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz $(SKIP_MD5SUM)$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := ecd1fa65e7de707cd5c00bdac56022cd -FUSE_VERSION ?= 3.9.0 +FUSE_VERSION ?= 3.9.1 DOCKER_BUILDARGS += FUSE_VERSION=$(FUSE_VERSION) FETCH_TARGETS += $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz -$(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 31b19277c039ae225927edc29193d34f +$(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 5f7c1062def710d8b60343524a18cc82 WEBSOCKETS_VERSION ?= 3.2.0 DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION) diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index d4de18e..50e0490 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -50,7 +50,7 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.9.0 +ARG FUSE_VERSION=3.9.1 RUN set -x \ && builddeps="linux-headers eudev-dev python3 py3-pip py3-setuptools py3-cryptography" \ diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index 6888ad3..37a5f35 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -49,7 +49,7 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.9.0 +ARG FUSE_VERSION=3.9.1 RUN set -x \ && builddeps="udev gettext python3 python3-pip python3-setuptools python3-wheel" \ diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index 48c2e1f..e3a53ca 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -54,7 +54,7 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.9.0 +ARG FUSE_VERSION=3.9.1 RUN set -x \ && builddeps="linux-headers eudev-dev python3 py3-pip py3-setuptools py3-cryptography" \ diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index cc7e851..b3c368d 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -52,7 +52,7 @@ RUN set -x \ && make "$PARALLELMFLAGS" install \ && rm -rf "$builddir" -ARG FUSE_VERSION=3.9.0 +ARG FUSE_VERSION=3.9.1 RUN set -x \ && builddeps="udev gettext python3 python3-pip python3-setuptools python3-wheel" \ diff --git a/doc/build.md b/doc/build.md index 9a90ea3..fe16a11 100644 --- a/doc/build.md +++ b/doc/build.md @@ -47,9 +47,9 @@ After that, you will find the API documentation in the doc/api subdirectory. To install libfuse, meson is needed. Please refer to [meson quick guide](https://mesonbuild.com/Quick-guide.html) for setup instructions. - wget -O fuse-3.8.0.tar.gz https://github.com/libfuse/libfuse/archive/fuse-3.8.0.tar.gz - tar -xf fuse-3.8.0.tar.gz - cd libfuse-fuse-3.8.0 + wget -O fuse-3.9.1.tar.gz https://github.com/libfuse/libfuse/archive/fuse-3.9.1.tar.gz + tar -xf fuse-3.9.1.tar.gz + cd libfuse-fuse-3.9.1 mkdir .build cd .build meson .. From 1feaad6d5563a37cec0d959e6e4b685ab812d026 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 20 Mar 2020 18:18:35 +0100 Subject: [PATCH 083/138] fixed report branch coverage --- cmake/unit_tests.cmake | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 13b91f9..b541706 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -86,16 +86,17 @@ enable_testing() gtest_discover_tests(alltests TEST_PREFIX alltests:) add_custom_target(coverage - ./alltests - COMMAND mkdir -p coverage - COMMAND lcov --capture --directory . --output-file coverage/lcov.info - COMMAND lcov --remove coverage/lcov.info '/usr/*' --output-file coverage/lcov.info - COMMAND lcov --remove coverage/lcov.info '*/test/*' --output-file coverage/lcov.info + mkdir -p coverage + COMMAND lcov --initial --capture --directory . --output-file coverage/lcov_base.info --rc lcov_branch_coverage=1 + COMMAND ./alltests + COMMAND lcov --capture --directory . --output-file coverage/lcov.info --rc lcov_branch_coverage=1 + COMMAND lcov --remove coverage/lcov.info '/usr/*' --output-file coverage/lcov.info --rc lcov_branch_coverage=1 + COMMAND lcov --remove coverage/lcov.info '*/test/*' --output-file coverage/lcov.info --rc lcov_branch_coverage=1 ) add_dependencies(coverage alltests) add_custom_target(coverage-report - COMMAND genhtml coverage/lcov.info --output-directory coverage/report + COMMAND genhtml --branch-coverage --highlight --legend --prefix "${CMAKE_SOURCE_DIR}" coverage/lcov.info --output-directory coverage/report ) add_dependencies(coverage-report coverage) From 43c989e7af53b1190b14f6f85a2d604c04688db1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 09:11:18 +0100 Subject: [PATCH 084/138] removed uuid mountpoint and factory --- build/amd64-alpine-builder.dockerfile | 6 +- build/amd64-ubuntu-builder.dockerfile | 3 +- build/arm32v7-alpine-builder.dockerfile | 6 +- build/arm32v7-ubuntu-builder.dockerfile | 3 +- cmake/unit_tests.cmake | 5 - cmake/webfuse_adapter.cmake | 7 - include/webfuse/adapter/server_config.h | 17 --- lib/webfuse/adapter/api.c | 13 -- lib/webfuse/adapter/impl/filesystem.c | 1 - lib/webfuse/adapter/impl/mountpoint_factory.c | 12 +- lib/webfuse/adapter/impl/mountpoint_factory.h | 8 +- lib/webfuse/adapter/impl/server_config.c | 11 +- lib/webfuse/adapter/impl/server_config.h | 4 - lib/webfuse/adapter/impl/server_protocol.c | 18 +-- lib/webfuse/adapter/impl/server_protocol.h | 3 - lib/webfuse/adapter/impl/uuid_mountpoint.c | 124 ------------------ lib/webfuse/adapter/impl/uuid_mountpoint.h | 20 --- .../adapter/impl/uuid_mountpoint_factory.c | 84 ------------ .../adapter/impl/uuid_mountpoint_factory.h | 21 --- test/webfuse/tests/adapter/test_server.cc | 16 ++- .../tests/adapter/test_server_config.cc | 20 --- .../tests/adapter/test_uuid_mountpoint.cc | 72 ---------- .../adapter/test_uuid_mountpoint_factory.cc | 61 --------- test/webfuse/tests/integration/server.cc | 36 ++++- .../tests/integration/test_integration.cc | 6 +- 25 files changed, 65 insertions(+), 512 deletions(-) delete mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint.c delete mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint.h delete mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint_factory.c delete mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint_factory.h delete mode 100644 test/webfuse/tests/adapter/test_uuid_mountpoint.cc delete mode 100644 test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index 50e0490..6bd7713 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -15,9 +15,9 @@ RUN set -x \ pkgconf \ rsync \ gdb \ - valgrind \ - util-linux \ - util-linux-dev + valgrind +# util-linux \ +# util-linux-dev COPY src /usr/local/src diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index 37a5f35..7f5cc46 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -15,8 +15,7 @@ RUN set -x \ gdb \ gdbserver \ valgrind \ - lcov \ - uuid-dev + lcov COPY src /usr/local/src diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index e3a53ca..4eca9a6 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -19,9 +19,9 @@ RUN set -x \ pkgconf \ rsync \ gdb \ - valgrind \ - util-linux \ - util-linux-dev + valgrind +# util-linux \ +# util-linux-dev COPY src /usr/local/src diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index b3c368d..a84a8e3 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -18,8 +18,7 @@ RUN set -x \ rsync \ gdb \ gdbserver \ - lcov \ - uuid-dev + lcov COPY src /usr/local/src diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index b541706..aaf5381 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -40,8 +40,6 @@ add_executable(alltests test/webfuse/tests/adapter/test_authenticator.cc test/webfuse/tests/adapter/test_authenticators.cc test/webfuse/tests/adapter/test_mountpoint.cc - test/webfuse/tests/adapter/test_uuid_mountpoint.cc - test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc test/webfuse/tests/adapter/test_fuse_req.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc @@ -56,12 +54,10 @@ target_include_directories(alltests PRIVATE lib/wf/timer/include lib/wf/timer/src ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} ) target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} ) target_link_libraries(alltests PUBLIC @@ -73,7 +69,6 @@ target_link_libraries(alltests PUBLIC ${FUSE3_LIBRARIES} ${LWS_LIBRARIES} ${JANSSON_LIBRARIES} - ${UUID_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index bb0f723..f6e777c 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -1,7 +1,6 @@ if(NOT WITHOUT_ADAPTER) pkg_check_modules(FUSE3 REQUIRED fuse3) -pkg_check_modules(UUID REQUIRED uuid) add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/api.c @@ -17,8 +16,6 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/operations.c lib/webfuse/adapter/impl/mountpoint.c lib/webfuse/adapter/impl/mountpoint_factory.c - lib/webfuse/adapter/impl/uuid_mountpoint_factory.c - lib/webfuse/adapter/impl/uuid_mountpoint.c lib/webfuse/adapter/impl/operation/lookup.c lib/webfuse/adapter/impl/operation/getattr.c lib/webfuse/adapter/impl/operation/readdir.c @@ -32,12 +29,10 @@ target_include_directories(webfuse-adapter-static PRIVATE lib/wf/timer/include lib/wf/jsonrpc/include ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} ) target_compile_options(webfuse-adapter-static PUBLIC ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} ) set_target_properties(webfuse-adapter-static PROPERTIES OUTPUT_NAME webfuse-adapter) @@ -49,12 +44,10 @@ add_library(webfuse-adapter SHARED target_include_directories(webfuse-adapter PRIVATE ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} ) target_compile_options(webfuse-adapter PUBLIC ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} ) diff --git a/include/webfuse/adapter/server_config.h b/include/webfuse/adapter/server_config.h index 83a1c34..e140c4d 100644 --- a/include/webfuse/adapter/server_config.h +++ b/include/webfuse/adapter/server_config.h @@ -42,23 +42,6 @@ extern WF_API struct wf_server_config * wf_server_config_create(void); extern WF_API void wf_server_config_dispose( struct wf_server_config * config); -//------------------------------------------------------------------------------ -/// \brief Sets a mountpoint path. -/// \deprecated This function will be removed soon. Use \ref -/// wf_server_config_set_mountpoint_factory instead. -/// -/// Sets the root path of UUID-based file system. -/// -/// \note A valid configuration needs either a mountpoint or a mounpoint -/// factory. -/// -/// \param config pointer of configuration object -/// \param mount_point root path of UUID-based file system. -//------------------------------------------------------------------------------ -extern WF_API void wf_server_config_set_mountpoint( - struct wf_server_config * config, - char const * mount_point); - //------------------------------------------------------------------------------ /// \brief Sets the mountpoint factory of the configuration. /// diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 2047029..6b08e0f 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -38,12 +38,6 @@ void wf_server_interrupt( // server protocol -struct wf_server_protocol * wf_server_protocol_create( - char * mount_point) -{ - return wf_impl_server_protocol_create(mount_point); -} - struct wf_server_protocol * wf_server_protocol_create2( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) @@ -86,13 +80,6 @@ void wf_server_config_dispose( wf_impl_server_config_dispose(config); } -void wf_server_config_set_mountpoint( - struct wf_server_config * config, - char const * mount_point) -{ - wf_impl_server_config_set_mountpoint(config, mount_point); -} - void wf_server_config_set_mountpoint_factory( struct wf_server_config * config, wf_create_mountpoint_fn * create_mountpoint, diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index e4a3435..03c2217 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -6,7 +6,6 @@ #include "webfuse/core/string.h" #include -#include #include #include diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.c b/lib/webfuse/adapter/impl/mountpoint_factory.c index 54679ef..2da5db3 100644 --- a/lib/webfuse/adapter/impl/mountpoint_factory.c +++ b/lib/webfuse/adapter/impl/mountpoint_factory.c @@ -7,19 +7,16 @@ wf_impl_mountpoint_factory_init_default( { factory->create_mountpoint = NULL; factory->user_data = NULL; - factory->dispose = NULL; } void wf_impl_mountpoint_factory_init( struct wf_impl_mountpoint_factory * factory, wf_create_mountpoint_fn * create_mountpoint, - void * user_data, - wf_impl_mountpoint_factory_dispose_fn * dispose) + void * user_data) { factory->create_mountpoint = create_mountpoint; factory->user_data = user_data; - factory->dispose = dispose; } void @@ -29,10 +26,8 @@ wf_impl_mountpoint_factory_move( { other->create_mountpoint = factory->create_mountpoint; other->user_data = factory->user_data; - other->dispose = factory->dispose; factory->create_mountpoint = NULL; - factory->dispose = NULL; factory->user_data = NULL; } @@ -47,13 +42,8 @@ void wf_impl_mountpoint_factory_cleanup( struct wf_impl_mountpoint_factory * factory) { - if (NULL != factory->dispose) - { - factory->dispose(factory->user_data); - } factory->create_mountpoint = NULL; - factory->dispose = NULL; factory->user_data = NULL; } diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.h b/lib/webfuse/adapter/impl/mountpoint_factory.h index 98e5469..63bbbfc 100644 --- a/lib/webfuse/adapter/impl/mountpoint_factory.h +++ b/lib/webfuse/adapter/impl/mountpoint_factory.h @@ -9,14 +9,9 @@ extern "C" { #endif -typedef void -wf_impl_mountpoint_factory_dispose_fn( - void * user_data); - struct wf_impl_mountpoint_factory { wf_create_mountpoint_fn * create_mountpoint; - wf_impl_mountpoint_factory_dispose_fn * dispose; void * user_data; }; @@ -28,8 +23,7 @@ extern void wf_impl_mountpoint_factory_init( struct wf_impl_mountpoint_factory * factory, wf_create_mountpoint_fn * create_mountpoint, - void * user_data, - wf_impl_mountpoint_factory_dispose_fn * dispose); + void * user_data); extern void wf_impl_mountpoint_factory_move( diff --git a/lib/webfuse/adapter/impl/server_config.c b/lib/webfuse/adapter/impl/server_config.c index 2d9fc6d..bcf022e 100644 --- a/lib/webfuse/adapter/impl/server_config.c +++ b/lib/webfuse/adapter/impl/server_config.c @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/server_config.h" -#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" #include #include @@ -72,21 +71,13 @@ void wf_impl_server_config_dispose( free(config); } -void wf_impl_server_config_set_mountpoint( - struct wf_server_config * config, - char const * mount_point) -{ - wf_impl_uuid_mountpoint_factory_init(&config->mountpoint_factory, - mount_point); -} - void wf_impl_server_config_set_mountpoint_factory( struct wf_server_config * config, wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) { wf_impl_mountpoint_factory_init(&config->mountpoint_factory, - create_mountpoint, create_mountpoint_context, NULL); + create_mountpoint, create_mountpoint_context); } diff --git a/lib/webfuse/adapter/impl/server_config.h b/lib/webfuse/adapter/impl/server_config.h index 48de4ed..400b842 100644 --- a/lib/webfuse/adapter/impl/server_config.h +++ b/lib/webfuse/adapter/impl/server_config.h @@ -34,10 +34,6 @@ extern void wf_impl_server_config_clone( struct wf_server_config * config, struct wf_server_config * clone); -extern void wf_impl_server_config_set_mountpoint( - struct wf_server_config * config, - char const * mount_point); - extern void wf_impl_server_config_set_mountpoint_factory( struct wf_server_config * config, wf_create_mountpoint_fn * create_mountpoint, diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 9085a14..7bcec27 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -9,7 +9,6 @@ #include "webfuse/core/protocol_names.h" #include "webfuse/adapter/impl/credentials.h" -#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" #include "webfuse/core/status_intern.h" #include "wf/jsonrpc/request.h" @@ -81,21 +80,6 @@ static int wf_impl_server_protocol_callback( return 0; } -struct wf_server_protocol * wf_impl_server_protocol_create( - char * mount_point) -{ - struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol)); - if (NULL != protocol) - { - struct wf_impl_mountpoint_factory mountpoint_factory; - wf_impl_uuid_mountpoint_factory_init(&mountpoint_factory, mount_point); - - wf_impl_server_protocol_init(protocol, &mountpoint_factory); - } - - return protocol; -} - struct wf_server_protocol * wf_impl_server_protocol_create2( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) @@ -105,7 +89,7 @@ struct wf_server_protocol * wf_impl_server_protocol_create2( { struct wf_impl_mountpoint_factory mountpoint_factory; wf_impl_mountpoint_factory_init(&mountpoint_factory, - create_mountpoint, create_mountpoint_context, NULL); + create_mountpoint, create_mountpoint_context); wf_impl_server_protocol_init(protocol, &mountpoint_factory); } diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 5d8052e..05ebe12 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -36,9 +36,6 @@ extern void wf_impl_server_protocol_init( extern void wf_impl_server_protocol_cleanup( struct wf_server_protocol * protocol); -extern struct wf_server_protocol * wf_impl_server_protocol_create( - char * mount_point); - extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create2( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context); diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint.c b/lib/webfuse/adapter/impl/uuid_mountpoint.c deleted file mode 100644 index 4573329..0000000 --- a/lib/webfuse/adapter/impl/uuid_mountpoint.c +++ /dev/null @@ -1,124 +0,0 @@ -#include "webfuse/adapter/impl/uuid_mountpoint.h" -#include "webfuse/adapter/impl/mountpoint.h" - -#include "webfuse/core/string.h" - -#include - -#include -#include -#include -#include - -#include -#include -#include - -struct wf_impl_uuid_mountpoint_data -{ - char * id; - char * filesystem_path; - char * default_path; - char * full_path; -}; - -static char * wf_impl_uuid_mountpoint_create_id(void) -{ - uuid_t uuid; - uuid_generate(uuid); - char id[UUID_STR_LEN]; - uuid_unparse(uuid, id); - - return strdup(id); -} - -static bool wf_impl_uuid_mountpoint_is_link_broken(char const * path, char const * id) -{ - bool result = false; - - char buffer[UUID_STR_LEN]; - ssize_t count = readlink(path, buffer, UUID_STR_LEN); - if ((0 < count) && (count < UUID_STR_LEN)) - { - buffer[count] = '\0'; - result = (0 == strcmp(buffer, id)); - } - - return result; -} - -static bool wf_impl_uuid_mountpoint_link_first_subdir( - char const * link_path, - char const * path) -{ - bool result = false; - DIR * dir = opendir(path); - if (NULL != dir) - { - struct dirent * entry = readdir(dir); - while (NULL != entry) - { - if ((DT_DIR == entry->d_type) && ('.' != entry->d_name[0])) - { - int rc = symlink(entry->d_name, link_path); - result = (0 == rc); - break; - } - - entry = readdir(dir); - } - - closedir(dir); - } - - return result; -} - -static void -wf_impl_uuid_mountpoint_data_dispose( - void * user_data) -{ - struct wf_impl_uuid_mountpoint_data * data = user_data; - - rmdir(data->full_path); - - if (wf_impl_uuid_mountpoint_is_link_broken(data->default_path, data->id)) - { - unlink(data->default_path); - - bool const success = wf_impl_uuid_mountpoint_link_first_subdir(data->default_path, data->filesystem_path); - if (!success) - { - rmdir(data->filesystem_path); - } - } - - free(data->id); - free(data->filesystem_path); - free(data->default_path); - free(data->full_path); - free(data); -} - -struct wf_mountpoint * -wf_impl_uuid_mountpoint_create( - char const * root_path, - char const * filesystem) -{ - struct wf_impl_uuid_mountpoint_data * data = malloc(sizeof(struct wf_impl_uuid_mountpoint_data)); - data->filesystem_path = wf_create_string("%s/%s", root_path, filesystem); - mkdir(data->filesystem_path, 0755); - - data->id = wf_impl_uuid_mountpoint_create_id(); - data->full_path = wf_create_string("%s/%s/%s", root_path, filesystem, data->id); - mkdir(data->full_path, 0755); - - data->default_path = wf_create_string("%s/%s/default", root_path, filesystem); - int rc = symlink(data->id, data->default_path); - (void) rc; // ignore missing symlink - - struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(data->full_path); - wf_impl_mountpoint_set_userdata(mountpoint, data, &wf_impl_uuid_mountpoint_data_dispose); - - return mountpoint; -} diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint.h b/lib/webfuse/adapter/impl/uuid_mountpoint.h deleted file mode 100644 index 7287be3..0000000 --- a/lib/webfuse/adapter/impl/uuid_mountpoint.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef WF_IMPL_UUID_MOUNTPOINT_H -#define WF_IMPL_UUID_MOUNTPOINT_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_mountpoint; - -extern struct wf_mountpoint * -wf_impl_uuid_mountpoint_create( - char const * root_path, - char const * filesystem); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c deleted file mode 100644 index 3b4d543..0000000 --- a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" -#include "webfuse/adapter/impl/uuid_mountpoint.h" - -#include -#include -#include - -#include -#include -#include - -struct wf_impl_uuid_mountpoint_factory -{ - char * root_path; - bool root_created; -}; - -static void * -wf_impl_uuid_mountpoint_factory_create_context( - char const * root_path) -{ - struct wf_impl_uuid_mountpoint_factory * factory = NULL; - bool root_created = false; - - struct stat info; - int rc = stat(root_path, &info); - if ((0 != rc) || (!S_ISDIR(info.st_mode))) - { - rc = mkdir(root_path, 0755); - root_created = true; - } - - if (0 == rc) - { - factory = malloc(sizeof(struct wf_impl_uuid_mountpoint_factory)); - factory->root_path = strdup(root_path); - factory->root_created = root_created; - } - - return factory; -} - -static void -wf_impl_uuid_mountpoint_factory_dispose( - void * user_data) -{ - struct wf_impl_uuid_mountpoint_factory * factory = user_data; - - if (factory->root_created) - { - rmdir(factory->root_path); - } - - free(factory->root_path); - free(factory); -} - -static struct wf_mountpoint * -wf_impl_uuid_mountpoint_factory_create_mountpoint( - char const * filesystem, - void * user_data) -{ - struct wf_impl_uuid_mountpoint_factory * factory = user_data; - - return wf_impl_uuid_mountpoint_create(factory->root_path, filesystem); -} - -bool -wf_impl_uuid_mountpoint_factory_init( - struct wf_impl_mountpoint_factory * factory, - char const * root_path) -{ - void * context = wf_impl_uuid_mountpoint_factory_create_context(root_path); - bool const result = (NULL != context); - - if (result) - { - factory->create_mountpoint = &wf_impl_uuid_mountpoint_factory_create_mountpoint; - factory->user_data = context; - factory->dispose = &wf_impl_uuid_mountpoint_factory_dispose; - } - - return result; -} diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h deleted file mode 100644 index eed8fa0..0000000 --- a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef WF_IMPL_UUID_MOUNTPOINT_FACTORY_H -#define WF_IMPL_UUID_MOUNTPOINT_FACTORY_H - -#include "webfuse/adapter/impl/mountpoint_factory.h" -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern bool -wf_impl_uuid_mountpoint_factory_init( - struct wf_impl_mountpoint_factory * factory, - char const * root_path); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test/webfuse/tests/adapter/test_server.cc b/test/webfuse/tests/adapter/test_server.cc index ef8fa25..1b2a881 100644 --- a/test/webfuse/tests/adapter/test_server.cc +++ b/test/webfuse/tests/adapter/test_server.cc @@ -8,13 +8,27 @@ #include "webfuse/adapter/server.h" #include "webfuse/adapter/server_config.h" +namespace +{ +struct wf_mountpoint * +create_mountpoint( + char const * filesystem, + void * user_data) +{ + (void) filesystem; + (void) user_data; + + return nullptr; +} + +} TEST(server, create_dispose) { mkdir("test", 0700); struct wf_server_config * config = wf_server_config_create(); - wf_server_config_set_mountpoint(config, "test"); + wf_server_config_set_mountpoint_factory(config, &create_mountpoint, nullptr); struct wf_server * server = wf_server_create(config); ASSERT_NE(nullptr, server); diff --git a/test/webfuse/tests/adapter/test_server_config.cc b/test/webfuse/tests/adapter/test_server_config.cc index f85aa92..b9687be 100644 --- a/test/webfuse/tests/adapter/test_server_config.cc +++ b/test/webfuse/tests/adapter/test_server_config.cc @@ -120,38 +120,18 @@ TEST(server_config, set_port) wf_server_config_dispose(config); } -TEST(server_config, set_mountpoint) -{ - TempDir temp("server_config"); - - wf_server_config * config = wf_server_config_create(); - ASSERT_NE(nullptr, config); - ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint); - ASSERT_EQ(nullptr, config->mountpoint_factory.user_data); - ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); - - wf_server_config_set_mountpoint(config, temp.path()); - ASSERT_NE(nullptr, config->mountpoint_factory.create_mountpoint); - ASSERT_NE(nullptr, config->mountpoint_factory.user_data); - ASSERT_NE(nullptr, config->mountpoint_factory.dispose); - - wf_server_config_dispose(config); -} - TEST(server_config, set_mounpoint_factory) { wf_server_config * config = wf_server_config_create(); ASSERT_NE(nullptr, config); ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint); ASSERT_EQ(nullptr, config->mountpoint_factory.user_data); - ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); int value = 42; void * user_data = reinterpret_cast(&value); wf_server_config_set_mountpoint_factory(config, &create_mountpoint, user_data); ASSERT_EQ(&create_mountpoint, config->mountpoint_factory.create_mountpoint); ASSERT_EQ(user_data, config->mountpoint_factory.user_data); - ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); wf_server_config_dispose(config); } diff --git a/test/webfuse/tests/adapter/test_uuid_mountpoint.cc b/test/webfuse/tests/adapter/test_uuid_mountpoint.cc deleted file mode 100644 index 7549b84..0000000 --- a/test/webfuse/tests/adapter/test_uuid_mountpoint.cc +++ /dev/null @@ -1,72 +0,0 @@ -#include - -#include "webfuse/utils/tempdir.hpp" -#include "webfuse/utils/file_utils.hpp" -#include "webfuse_adapter.h" -#include "webfuse/adapter/impl/uuid_mountpoint.h" - -#include - -using webfuse_test::TempDir; -using webfuse_test::is_dir; -using webfuse_test::is_symlink; -using webfuse_test::is_same_path; - -TEST(uuid_mountpoint, create) -{ - TempDir temp("uuid_mountpoint"); - - std::string filesystem_path = std::string(temp.path()) + "/dummy"; - std::string default_path = std::string(temp.path()) + "/dummy/default"; - - wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); - std::string path = wf_mountpoint_get_path(mountpoint); - ASSERT_NE(nullptr, mountpoint); - ASSERT_TRUE(is_dir(filesystem_path)); - ASSERT_TRUE(is_symlink(default_path)); - ASSERT_TRUE(is_dir(default_path)); - ASSERT_TRUE(is_dir(path)); - ASSERT_TRUE(is_same_path(default_path, path)); - - wf_mountpoint_dispose(mountpoint); - ASSERT_FALSE(is_dir(filesystem_path)); - ASSERT_FALSE(is_symlink(default_path)); - ASSERT_FALSE(is_dir(default_path)); - ASSERT_FALSE(is_dir(path)); -} - -TEST(uuid_mountpoint, relink_default) -{ - TempDir temp("uuid_mountpoint"); - - std::string filesystem_path = std::string(temp.path()) + "/dummy"; - std::string default_path = std::string(temp.path()) + "/dummy/default"; - - wf_mountpoint * mountpoint_a = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); - std::string path_a = wf_mountpoint_get_path(mountpoint_a); - - wf_mountpoint * mountpoint_b = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); - std::string path_b = wf_mountpoint_get_path(mountpoint_b); - - ASSERT_TRUE(is_dir(filesystem_path)); - ASSERT_TRUE(is_symlink(default_path)); - ASSERT_TRUE(is_dir(default_path)); - ASSERT_TRUE(is_dir(path_a)); - ASSERT_TRUE(is_dir(path_b)); - ASSERT_TRUE(is_same_path(default_path, path_a)); - - wf_mountpoint_dispose(mountpoint_a); - ASSERT_TRUE(is_dir(filesystem_path)); - ASSERT_TRUE(is_symlink(default_path)); - ASSERT_TRUE(is_dir(default_path)); - ASSERT_FALSE(is_dir(path_a)); - ASSERT_TRUE(is_dir(path_b)); - ASSERT_TRUE(is_same_path(default_path, path_b)); - - wf_mountpoint_dispose(mountpoint_b); - ASSERT_FALSE(is_dir(filesystem_path)); - ASSERT_FALSE(is_symlink(default_path)); - ASSERT_FALSE(is_dir(default_path)); - ASSERT_FALSE(is_dir(path_a)); - ASSERT_FALSE(is_dir(path_b)); -} diff --git a/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc b/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc deleted file mode 100644 index dca941f..0000000 --- a/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include "webfuse_adapter.h" -#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" -#include "webfuse/utils/tempdir.hpp" -#include "webfuse/utils/file_utils.hpp" - -using webfuse_test::TempDir; -using webfuse_test::is_dir; - -TEST(uuid_mountpoint_factory, create_existing_dir) -{ - TempDir temp("uuid_mountpoint_factory"); - - struct wf_impl_mountpoint_factory factory; - bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, temp.path()); - ASSERT_TRUE(factory_created); - ASSERT_TRUE(is_dir(temp.path())); - - wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy"); - std::string path = wf_mountpoint_get_path(mountpoint); - ASSERT_TRUE(is_dir(path)); - - wf_mountpoint_dispose(mountpoint); - ASSERT_FALSE(is_dir(path)); - - wf_impl_mountpoint_factory_cleanup(&factory); - // keep dir not created by factory - ASSERT_TRUE(is_dir(temp.path())); -} - -TEST(uuid_mountpoint_factory, create_nonexisting_dir) -{ - TempDir temp("uuid_mountpoint_factory"); - std::string root_path = std::string(temp.path()) + "/root"; - - struct wf_impl_mountpoint_factory factory; - bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str()); - ASSERT_TRUE(factory_created); - ASSERT_TRUE(is_dir(root_path)); - - wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy"); - std::string path = wf_mountpoint_get_path(mountpoint); - ASSERT_TRUE(is_dir(path)); - - wf_mountpoint_dispose(mountpoint); - ASSERT_FALSE(is_dir(path)); - - wf_impl_mountpoint_factory_cleanup(&factory); - // remove dir, created by factory - ASSERT_FALSE(is_dir(root_path)); -} - -TEST(uuid_mountpoint_factory, fail_to_created_nested_dir) -{ - TempDir temp("uuid_mountpoint_factory"); - std::string root_path = std::string(temp.path()) + "/nested/root"; - - struct wf_impl_mountpoint_factory factory; - bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str()); - ASSERT_FALSE(factory_created); -} \ No newline at end of file diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index 177a69f..931f932 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -4,11 +4,43 @@ #include #include #include +#include #include "webfuse_adapter.h" #include "webfuse/adapter/impl/server.h" #define WF_PATH_MAX (100) +extern "C" +{ + +static void webfuse_test_server_cleanup_mountpoint( + void * user_data) +{ + char * path = reinterpret_cast(user_data); + rmdir(path); + free(path); +} + +static struct wf_mountpoint * +webfuse_test_server_create_mountpoint( + char const * filesystem, + void * user_data) +{ + char const * base_dir = reinterpret_cast(user_data); + char path[WF_PATH_MAX]; + snprintf(path, WF_PATH_MAX, "%s/%s", base_dir, filesystem); + mkdir(path, 0755); + struct wf_mountpoint * mountpoint = wf_mountpoint_create(path); + wf_mountpoint_set_userdata( + mountpoint, + reinterpret_cast(strdup(path)), + &webfuse_test_server_cleanup_mountpoint); + + return mountpoint; +} + +} + namespace webfuse_test { @@ -28,7 +60,9 @@ public: config = wf_server_config_create(); wf_server_config_set_port(config, 8080); - wf_server_config_set_mountpoint(config, base_dir); + wf_server_config_set_mountpoint_factory(config, + &webfuse_test_server_create_mountpoint, + reinterpret_cast(base_dir)); server = wf_server_create(config); diff --git a/test/webfuse/tests/integration/test_integration.cc b/test/webfuse/tests/integration/test_integration.cc index 203856c..4cc2844 100644 --- a/test/webfuse/tests/integration/test_integration.cc +++ b/test/webfuse/tests/integration/test_integration.cc @@ -68,7 +68,7 @@ TEST_F(IntegrationTest, HasMountpoint) TEST_F(IntegrationTest, ProvidesTextFile) { - std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt"; + std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; ASSERT_EXIT({ struct stat buffer; @@ -85,7 +85,7 @@ TEST_F(IntegrationTest, ProvidesTextFile) TEST_F(IntegrationTest, ReadTextFile) { - std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt"; + std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; ASSERT_EXIT({ FILE * file = fopen(file_name.c_str(), "rb"); @@ -106,7 +106,7 @@ TEST_F(IntegrationTest, ReadTextFile) TEST_F(IntegrationTest, ReadDir) { - std::string dir_name = std::string(GetBaseDir()) + "/cprovider/default"; + std::string dir_name = std::string(GetBaseDir()) + "/cprovider"; ASSERT_EXIT({ From 425e017bc4906949de8b6ea02d5fdbf188fed41f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 09:18:04 +0100 Subject: [PATCH 085/138] renamed function: wf_impl_server_protocol_create2 to ..create: remove of uuid mountpoint was already API breaking --- include/webfuse/adapter/mountpoint_factory.h | 2 +- include/webfuse/adapter/server_protocol.h | 13 +------------ lib/webfuse/adapter/api.c | 4 ++-- lib/webfuse/adapter/impl/server_protocol.c | 2 +- lib/webfuse/adapter/impl/server_protocol.h | 2 +- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/include/webfuse/adapter/mountpoint_factory.h b/include/webfuse/adapter/mountpoint_factory.h index 8a69821..7a10bb1 100644 --- a/include/webfuse/adapter/mountpoint_factory.h +++ b/include/webfuse/adapter/mountpoint_factory.h @@ -23,7 +23,7 @@ struct wf_mountpoint; /// \return newly created mountpoint or NULL, on error /// /// \see wf_server_config_set_mountpoint_factory -/// \see wf_server_protocol_create2 +/// \see wf_server_protocol_create //------------------------------------------------------------------------------ typedef struct wf_mountpoint * wf_create_mountpoint_fn( diff --git a/include/webfuse/adapter/server_protocol.h b/include/webfuse/adapter/server_protocol.h index 8808669..68b1dbe 100644 --- a/include/webfuse/adapter/server_protocol.h +++ b/include/webfuse/adapter/server_protocol.h @@ -32,17 +32,6 @@ struct wf_server_protocol; //------------------------------------------------------------------------------ struct lws_protocols; -//------------------------------------------------------------------------------ -/// \brief Creates a new protocol with a given mounpoint. -/// \deprecated This function will be removed soon. Use \ref -/// wf_server_protocol_create2 instead. -/// -/// \param mount_point root path of UUID-based file system. -/// \return newly created protocol -//------------------------------------------------------------------------------ -extern WF_API struct wf_server_protocol * wf_server_protocol_create( - char * mount_point); - //------------------------------------------------------------------------------ /// \brief Creates a new protocol by a mountpoint factory. /// @@ -53,7 +42,7 @@ extern WF_API struct wf_server_protocol * wf_server_protocol_create( /// \param create_mountpoint factory function to create mountpoints /// \param create_mountpoint_context context of mountpoint factory //------------------------------------------------------------------------------ -extern WF_API struct wf_server_protocol * wf_server_protocol_create2( +extern WF_API struct wf_server_protocol * wf_server_protocol_create( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context); diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 6b08e0f..72ab6bc 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -38,11 +38,11 @@ void wf_server_interrupt( // server protocol -struct wf_server_protocol * wf_server_protocol_create2( +struct wf_server_protocol * wf_server_protocol_create( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) { - return wf_impl_server_protocol_create2(create_mountpoint, create_mountpoint_context); + return wf_impl_server_protocol_create(create_mountpoint, create_mountpoint_context); } void wf_server_protocol_dispose( diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 7bcec27..927d1cb 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -80,7 +80,7 @@ static int wf_impl_server_protocol_callback( return 0; } -struct wf_server_protocol * wf_impl_server_protocol_create2( +struct wf_server_protocol * wf_impl_server_protocol_create( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) { diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 05ebe12..df98c8f 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -36,7 +36,7 @@ extern void wf_impl_server_protocol_init( extern void wf_impl_server_protocol_cleanup( struct wf_server_protocol * protocol); -extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create2( +extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context); From 220df4ad5001e0c92682c5dc860a1f815049062f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 21:08:25 +0100 Subject: [PATCH 086/138] specify branch detection --- codecov.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/codecov.yml b/codecov.yml index 2efff1f..c629bb3 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,2 +1,10 @@ ignore: - test + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no From 214d6b738d4f586e63922361337415c45ad7a4d7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 21:22:22 +0100 Subject: [PATCH 087/138] removed NULL-checks after malloc: they are not necessary, they were not consequently used and objects constructed by 3rd party libs are also unchecked --- lib/webfuse/adapter/impl/authenticator.c | 11 +++---- lib/webfuse/adapter/impl/filesystem.c | 11 +++---- lib/webfuse/adapter/impl/operation/read.c | 2 +- lib/webfuse/adapter/impl/server.c | 11 +++---- lib/webfuse/adapter/impl/server_config.c | 5 +-- lib/webfuse/adapter/impl/server_protocol.c | 11 +++---- lib/webfuse/adapter/impl/session.c | 21 ++++++------- lib/webfuse/core/message.c | 9 ++---- lib/webfuse/core/string.c | 19 +++++------ lib/webfuse/provider/impl/client.c | 33 +++++++++----------- lib/webfuse/provider/impl/client_config.c | 11 +++---- lib/webfuse/provider/impl/client_protocol.c | 5 +-- lib/webfuse/provider/impl/dirbuffer.c | 5 +-- lib/webfuse/provider/impl/operation/read.c | 21 +++++-------- lib/webfuse/provider/impl/request.c | 9 ++---- lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c | 11 +++---- lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c | 5 +-- lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c | 9 ++---- lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c | 5 +-- lib/wf/timer/src/wf/timer/impl/manager.c | 5 +-- test/webfuse/utils/path.c | 27 +++++++--------- test/webfuse/utils/static_filesystem.c | 23 ++++++-------- 22 files changed, 101 insertions(+), 168 deletions(-) diff --git a/lib/webfuse/adapter/impl/authenticator.c b/lib/webfuse/adapter/impl/authenticator.c index 0be4b62..562a1dd 100644 --- a/lib/webfuse/adapter/impl/authenticator.c +++ b/lib/webfuse/adapter/impl/authenticator.c @@ -11,13 +11,10 @@ struct wf_impl_authenticator * wf_impl_authenticator_create( void * user_data) { struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator)); - if (NULL != authenticator) - { - authenticator->type = strdup(type); - authenticator->authenticate = authenticate; - authenticator->user_data = user_data; - authenticator->next = NULL; - } + authenticator->type = strdup(type); + authenticator->authenticate = authenticate; + authenticator->user_data = user_data; + authenticator->next = NULL; return authenticator; } diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 03c2217..b7966a1 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -99,14 +99,11 @@ struct wf_impl_filesystem * wf_impl_filesystem_create( struct wf_mountpoint * mountpoint) { 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); - if (!success) - { - free(filesystem); - filesystem = NULL; - } + free(filesystem); + filesystem = NULL; } return filesystem; diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 87330fc..8fa5bee 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -20,7 +20,7 @@ static char * wf_impl_fill_buffer( *status = WF_GOOD; char * buffer = malloc(count); - if ((NULL != buffer) && (0 < count)) + if (0 < count) { if (0 == strcmp("identity", format)) { diff --git a/lib/webfuse/adapter/impl/server.c b/lib/webfuse/adapter/impl/server.c index f6e1f63..8f9a01d 100644 --- a/lib/webfuse/adapter/impl/server.c +++ b/lib/webfuse/adapter/impl/server.c @@ -83,13 +83,10 @@ struct wf_server * wf_impl_server_create( if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory)) { 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_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); - server->context = wf_impl_server_context_create(server); - } + wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory); + wf_impl_server_config_clone(config, &server->config); + wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); + server->context = wf_impl_server_context_create(server); } return server; diff --git a/lib/webfuse/adapter/impl/server_config.c b/lib/webfuse/adapter/impl/server_config.c index bcf022e..ab214f3 100644 --- a/lib/webfuse/adapter/impl/server_config.c +++ b/lib/webfuse/adapter/impl/server_config.c @@ -56,10 +56,7 @@ void wf_impl_server_config_clone( struct wf_server_config * wf_impl_server_config_create(void) { struct wf_server_config * config = malloc(sizeof(struct wf_server_config)); - if (NULL != config) - { - wf_impl_server_config_init(config); - } + wf_impl_server_config_init(config); return config; } diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 927d1cb..ee5cbb0 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -85,14 +85,11 @@ struct wf_server_protocol * wf_impl_server_protocol_create( void * create_mountpoint_context) { 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, - create_mountpoint, create_mountpoint_context); + struct wf_impl_mountpoint_factory mountpoint_factory; + 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; diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index e1fdd87..778d155 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -51,18 +51,15 @@ struct wf_impl_session * wf_impl_session_create( { struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session)); - if (NULL != session) - { - wf_slist_init(&session->filesystems); - - session->wsi = wsi; - session->is_authenticated = false; - session->authenticators = authenticators; - session->server = server; - session->mountpoint_factory = mountpoint_factory; - 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->filesystems); + + session->wsi = wsi; + session->is_authenticated = false; + session->authenticators = authenticators; + session->server = server; + session->mountpoint_factory = mountpoint_factory; + session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); + wf_slist_init(&session->messages); return session; } diff --git a/lib/webfuse/core/message.c b/lib/webfuse/core/message.c index e94d1c6..bfb0016 100644 --- a/lib/webfuse/core/message.c +++ b/lib/webfuse/core/message.c @@ -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); 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; diff --git a/lib/webfuse/core/string.c b/lib/webfuse/core/string.c index c5117eb..84608cb 100644 --- a/lib/webfuse/core/string.c +++ b/lib/webfuse/core/string.c @@ -16,18 +16,15 @@ char * wf_create_string(char const * format, ...) if (0 <= needed) { result = malloc(needed + 1); - if (NULL != result) - { - va_list args; - va_start(args, format); - int count = vsnprintf(result, needed + 1, format, args); - va_end(args); + va_list args; + va_start(args, format); + int count = vsnprintf(result, needed + 1, format, args); + va_end(args); - if ((count < 0) || (needed < count)) - { - free(result); - result = NULL; - } + if ((count < 0) || (needed < count)) + { + free(result); + result = NULL; } } diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index 21af148..c3b432c 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -30,27 +30,24 @@ struct wfp_client * wfp_impl_client_create( wf_lwslog_disable(); 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); - - 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)) - { - - } - - client->context = lws_create_context(&client->info); + } + client->context = lws_create_context(&client->info); + return client; } diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c index 0e8afc6..3bbb3ea 100644 --- a/lib/webfuse/provider/impl/client_config.c +++ b/lib/webfuse/provider/impl/client_config.c @@ -6,13 +6,10 @@ struct wfp_client_config * wfp_impl_client_config_create(void) { struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config)); - if (NULL != config) - { - wfp_impl_provider_init(&config->provider); - config->user_data = NULL; - config->key_path = NULL; - config->cert_path = NULL; - } + wfp_impl_provider_init(&config->provider); + config->user_data = NULL; + config->key_path = NULL; + config->cert_path = NULL; return config; } diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 4f61b8a..4e2b176 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -270,10 +270,7 @@ struct wfp_client_protocol * wfp_impl_client_protocol_create( struct wfp_client_config const * config) { 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; } diff --git a/lib/webfuse/provider/impl/dirbuffer.c b/lib/webfuse/provider/impl/dirbuffer.c index db401ef..9bc5f22 100644 --- a/lib/webfuse/provider/impl/dirbuffer.c +++ b/lib/webfuse/provider/impl/dirbuffer.c @@ -4,10 +4,7 @@ struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void) { struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer)); - if (NULL != buffer) - { - buffer->entries = json_array(); - } + buffer->entries = json_array(); return buffer; } diff --git a/lib/webfuse/provider/impl/operation/read.c b/lib/webfuse/provider/impl/operation/read.c index 3101ea0..7be4bf3 100644 --- a/lib/webfuse/provider/impl/operation/read.c +++ b/lib/webfuse/provider/impl/operation/read.c @@ -56,22 +56,15 @@ void wfp_impl_respond_read( { size_t const size = wf_base64_encoded_size(length) + 1; 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_object_set_new(result, "data", json_string(buffer)); - json_object_set_new(result, "format", json_string("base64")); - json_object_set_new(result, "count", json_integer((int) length)); + json_t * result = json_object(); + json_object_set_new(result, "data", json_string(buffer)); + json_object_set_new(result, "format", json_string("base64")); + json_object_set_new(result, "count", json_integer((int) length)); - wfp_impl_respond(request, result); - free(buffer); - } - else - { - wfp_impl_respond_error(request, WF_BAD); - } + wfp_impl_respond(request, result); + free(buffer); } else { diff --git a/lib/webfuse/provider/impl/request.c b/lib/webfuse/provider/impl/request.c index 42ea835..7f8b05f 100644 --- a/lib/webfuse/provider/impl/request.c +++ b/lib/webfuse/provider/impl/request.c @@ -8,12 +8,9 @@ struct wfp_request * wfp_impl_request_create( int id) { struct wfp_request * request = malloc(sizeof(struct wfp_request)); - if (NULL != request) - { - request->respond = prototype->respond; - request->user_data = prototype->user_data; - request->id = id; - } + request->respond = prototype->respond; + request->user_data = prototype->user_data; + request->id = id; return request; } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c index 87b3ff1..ef0d16c 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c @@ -8,13 +8,10 @@ struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( void * user_data) { struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method)); - if (NULL != method) - { - method->next = NULL; - method->name = strdup(method_name); - method->invoke = invoke; - method->user_data = user_data; - } + method->next = NULL; + method->name = strdup(method_name); + method->invoke = invoke; + method->user_data = user_data; return method; } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c index a2b9816..99b3f03 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c @@ -16,10 +16,7 @@ wf_jsonrpc_impl_proxy_create( void * user_data) { struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy)); - if (NULL != proxy) - { - wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); - } + wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); return proxy; } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c index e46f19e..071ec4b 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c @@ -29,12 +29,9 @@ wf_jsonrpc_impl_request_create( void * user_data) { struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request)); - if (NULL != request) - { - request->id = id; - request->send = send; - request->user_data = user_data; - } + request->id = id; + request->send = send; + request->user_data = user_data; return request; } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c index e510daa..b3e27c8 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c @@ -24,10 +24,7 @@ struct wf_jsonrpc_server * wf_jsonrpc_impl_server_create(void) { struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server)); - if (NULL != server) - { - wf_jsonrpc_impl_server_init(server); - } + wf_jsonrpc_impl_server_init(server); return server; } diff --git a/lib/wf/timer/src/wf/timer/impl/manager.c b/lib/wf/timer/src/wf/timer/impl/manager.c index 2b00f80..f198502 100644 --- a/lib/wf/timer/src/wf/timer/impl/manager.c +++ b/lib/wf/timer/src/wf/timer/impl/manager.c @@ -14,10 +14,7 @@ struct wf_timer_manager * wf_timer_impl_manager_create(void) { struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager)); - if (NULL != manager) - { - manager->timers = NULL; - } + manager->timers = NULL; return manager; } diff --git a/test/webfuse/utils/path.c b/test/webfuse/utils/path.c index 3cb222e..e63aafb 100644 --- a/test/webfuse/utils/path.c +++ b/test/webfuse/utils/path.c @@ -45,24 +45,21 @@ wf_path_create( char const * value) { struct wf_path * path = malloc(sizeof(struct wf_path)); - if (NULL != path) + path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY); + path->capacity = WF_PATH_DEFAULT_CAPACITY; + path->count = 0; + + char const * remainder = value; + char const * pos = strchr(remainder, '/'); + while (NULL != pos) { - path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY); - path->capacity = WF_PATH_DEFAULT_CAPACITY; - path->count = 0; - - char const * remainder = value; - char const * pos = strchr(remainder, '/'); - while (NULL != pos) - { - wf_path_add(path, remainder, (pos - remainder)); - remainder = pos + 1; - pos = strchr(remainder, '/'); - } - - wf_path_add(path, remainder, strlen(remainder)); + wf_path_add(path, remainder, (pos - remainder)); + remainder = pos + 1; + pos = strchr(remainder, '/'); } + wf_path_add(path, remainder, strlen(remainder)); + return path; } diff --git a/test/webfuse/utils/static_filesystem.c b/test/webfuse/utils/static_filesystem.c index 62b507a..855564b 100644 --- a/test/webfuse/utils/static_filesystem.c +++ b/test/webfuse/utils/static_filesystem.c @@ -332,21 +332,18 @@ wfp_static_filesystem_create( (void) config; struct wfp_static_filesystem * filesystem = malloc(sizeof(struct wfp_static_filesystem)); - if (NULL != filesystem) - { - filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY); - filesystem->size = 0; - filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY; + filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY); + filesystem->size = 0; + filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY; - wfp_static_filesystem_add_dir(filesystem, 0, ""); + wfp_static_filesystem_add_dir(filesystem, 0, ""); - wfp_client_config_set_userdata(config, filesystem); - wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup); - wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr); - wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir); - wfp_client_config_set_onopen(config, &wfp_static_filesystem_open); - wfp_client_config_set_onread(config, &wfp_static_filesystem_read); - } + wfp_client_config_set_userdata(config, filesystem); + wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup); + wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr); + wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir); + wfp_client_config_set_onopen(config, &wfp_static_filesystem_open); + wfp_client_config_set_onread(config, &wfp_static_filesystem_read); return filesystem; } From 6a2b423a105ded958ee25154c2bdeb40d9c3ad10 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 21:57:33 +0100 Subject: [PATCH 088/138] enhanced branch detection --- codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codecov.yml b/codecov.yml index c629bb3..0937e15 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,5 +6,5 @@ parsers: branch_detection: conditional: yes loop: yes - method: no - macro: no + method: yes + macro: yes From b3ec92b202390a591b35b97b0de8ab674371e07c Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 22:06:36 +0100 Subject: [PATCH 089/138] ignore test dirs --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codecov.yml b/codecov.yml index 0937e15..e0d4bce 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,5 +1,7 @@ ignore: - test + - lib/wf/timer/test + - lib/wf/jsonrpc/test parsers: gcov: From 71a8c30d36abcd76533ffbcbb0ff0fb2e1b47641 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 22:25:50 +0100 Subject: [PATCH 090/138] increased test coverage --- .../webfuse/tests/adapter/test_credentials.cc | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/test/webfuse/tests/adapter/test_credentials.cc b/test/webfuse/tests/adapter/test_credentials.cc index 72350d4..88e2552 100644 --- a/test/webfuse/tests/adapter/test_credentials.cc +++ b/test/webfuse/tests/adapter/test_credentials.cc @@ -1,5 +1,6 @@ #include +#include "webfuse/adapter/credentials.h" #include "webfuse/adapter/impl/credentials.h" #include @@ -8,7 +9,7 @@ TEST(Credentials, Type) struct wf_credentials creds; wf_impl_credentials_init(&creds, "test", nullptr); - ASSERT_STREQ("test", wf_impl_credentials_type(&creds)); + ASSERT_STREQ("test", wf_credentials_type(&creds)); wf_impl_credentials_cleanup(&creds); } @@ -20,9 +21,9 @@ TEST(Credentials, Get) json_object_set_new(data, "password", json_string("")); wf_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); - ASSERT_STREQ("bob", wf_impl_credentials_get(&creds, "username")); - ASSERT_STREQ("", wf_impl_credentials_get(&creds, "password")); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ("bob", wf_credentials_get(&creds, "username")); + ASSERT_STREQ("", wf_credentials_get(&creds, "password")); wf_impl_credentials_cleanup(&creds); json_decref(data); @@ -34,9 +35,9 @@ TEST(Credentials, FailedToGetNonexistingValue) json_t * data = json_object(); wf_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password")); wf_impl_credentials_cleanup(&creds); json_decref(data); @@ -47,9 +48,9 @@ TEST(Credentials, FailedToGetWithoutData) struct wf_credentials creds; wf_impl_credentials_init(&creds, "username", nullptr); - ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password")); wf_impl_credentials_cleanup(&creds); } @@ -60,11 +61,25 @@ TEST(Credentials, FailedToGetWrongDataType) json_t * data = json_string("invalid_creds"); wf_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password")); wf_impl_credentials_cleanup(&creds); json_decref(data); } +TEST(Credentials, FailedToGetWrongElementDataType) +{ + struct wf_credentials creds; + json_t * data = json_object(); + json_object_set_new(data, "username", json_integer(42)); + + wf_impl_credentials_init(&creds, "username", data); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password")); + + wf_impl_credentials_cleanup(&creds); + json_decref(data); +} From d5adfc6f81803386c142160e4c1113e7d4b44d02 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 11:36:45 +0100 Subject: [PATCH 091/138] increased test coverage --- lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc | 120 +++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc index 14f7ac5..894c607 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc @@ -69,6 +69,36 @@ TEST(wf_jsonrpc_server, process_request) wf_jsonrpc_server_dispose(server); } +TEST(wf_jsonrpc_server, process_request_with_oject_params) +{ + 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(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("sayHello")); + json_object_set_new(request, "params", json_object()); + 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(); @@ -105,7 +135,7 @@ TEST(wf_jsonrpc_server, invoke_unknown_method) wf_jsonrpc_server_dispose(server); } -TEST(wf_jsonrpc_server, skip_invalid_request) +TEST(wf_jsonrpc_server, skip_invalid_request_missing_id) { struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); @@ -121,3 +151,91 @@ TEST(wf_jsonrpc_server, skip_invalid_request) json_decref(request); wf_jsonrpc_server_dispose(server); } + +TEST(wf_jsonrpc_server, skip_invalid_request_wrong_id_type) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&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_string("42")); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + +TEST(wf_jsonrpc_server, skip_invalid_request_missing_params) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("sayHello")); + json_object_set_new(request, "id", json_integer(42)); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + +TEST(wf_jsonrpc_server, skip_invalid_request_wrong_params_type) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("sayHello")); + json_object_set_new(request, "params", json_string("invalid")); + json_object_set_new(request, "id", json_integer(42)); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + +TEST(wf_jsonrpc_server, skip_invalid_request_missing_method) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + 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_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + +TEST(wf_jsonrpc_server, skip_invalid_request_wront_method_type) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_integer(42)); + 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_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} \ No newline at end of file From 843368f483ef1437d1d548d93ef657e70bccbed8 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 12:51:54 +0100 Subject: [PATCH 092/138] increased test coverage --- lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c | 2 +- .../jsonrpc/test/wf/jsonrpc/test_response.cc | 91 ++++++++++++++++++- 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c index 07171fb..f9fe180 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c @@ -25,7 +25,7 @@ wf_jsonrpc_impl_response_init( result->error = NULL; 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"); return; diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc index e8515aa..b71d7f3 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc @@ -41,7 +41,7 @@ TEST(wf_json_response, init_error) json_decref(message); } -TEST(wf_json_response, init_format_error) +TEST(wf_json_response, init_fail_missing_result_and_error) { json_t * message = json_object(); json_object_set_new(message, "id", json_integer(12)); @@ -56,3 +56,92 @@ TEST(wf_json_response, init_format_error) wf_jsonrpc_impl_response_cleanup(&response); json_decref(message); } + +TEST(wf_json_response, init_fail_missing_id) +{ + json_t * message = json_object(); + json_object_set_new(message, "result", json_integer(47)); + + 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(-1, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} + +TEST(wf_json_response, init_fail_wrong_id_type) +{ + json_t * message = json_object(); + json_object_set_new(message, "result", json_integer(47)); + json_object_set_new(message, "id", json_string("42")); + + 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(-1, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} + +TEST(wf_json_response, init_fail_error_missing_code) +{ + json_t * message = json_object(); + json_t * err = json_object(); + 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(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(nullptr, response.result); + ASSERT_EQ(23, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} + +TEST(wf_json_response, init_fail_error_wrong_code_type) +{ + json_t * message = json_object(); + json_t * err = json_object(); + json_object_set_new(err, "code", json_string("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(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(nullptr, response.result); + ASSERT_EQ(23, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} + +TEST(wf_json_response, init_fail_error_wrong_type) +{ + json_t * message = json_object(); + json_object_set_new(message, "error", json_string("invalid error type")); + json_object_set_new(message, "id", json_integer(23)); + + 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(23, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} From 643d1d52373c9264808887c7cffbd6830de479f5 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 13:36:03 +0100 Subject: [PATCH 093/138] increased test coverage --- .../jsonrpc/test/wf/jsonrpc/test_request.cc | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc index eb15e91..a8f7986 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc @@ -101,3 +101,38 @@ TEST(wf_jsonrpc_request, respond_error) json_decref(response); } + +TEST(wf_jsonrpc_request, is_request_object_params) +{ + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("some_method")); + json_object_set_new(request, "params", json_object()); + json_object_set_new(request, "id", json_integer(42)); + + ASSERT_TRUE(wf_jsonrpc_is_request(request)); + + json_decref(request); +} + +TEST(wf_jsonrpc_request, is_request_fail_missing_params) +{ + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("some_method")); + json_object_set_new(request, "id", json_integer(42)); + + ASSERT_FALSE(wf_jsonrpc_is_request(request)); + + json_decref(request); +} + +TEST(wf_jsonrpc_request, is_request_fail_params_wrong_type) +{ + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("some_method")); + json_object_set_new(request, "params", json_string("invalid_params")); + json_object_set_new(request, "id", json_integer(42)); + + ASSERT_FALSE(wf_jsonrpc_is_request(request)); + + json_decref(request); +} From 7e1d9bbb507267f3f565a5d56385fd6586dfdf7a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 17:41:34 +0100 Subject: [PATCH 094/138] increased test coverage --- lib/wf/timer/test/wf/timer/test_timer.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/wf/timer/test/wf/timer/test_timer.cc b/lib/wf/timer/test/wf/timer/test_timer.cc index e97c011..2141314 100644 --- a/lib/wf/timer/test/wf/timer/test_timer.cc +++ b/lib/wf/timer/test/wf/timer/test_timer.cc @@ -37,8 +37,7 @@ TEST(wf_timer, trigger) struct wf_timer_manager * manager = wf_timer_manager_create(); struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); - wf_timer_start(timer, 250); - std::this_thread::sleep_for(500ms); + wf_timer_start(timer, -1); wf_timer_manager_check(manager); ASSERT_TRUE(triggered); @@ -135,3 +134,15 @@ TEST(wf_timer, multiple_timers) wf_timer_manager_dispose(manager); } + +TEST(wf_timer, dont_trigger_null_callback) +{ + struct wf_timer_manager * manager = wf_timer_manager_create(); + struct wf_timer * timer = wf_timer_create(manager, nullptr, nullptr); + + wf_timer_start(timer, -1); + wf_timer_manager_check(manager); + + wf_timer_dispose(timer); + wf_timer_manager_dispose(manager); +} From 1d4db34ecb2921a32c4cedb5b0d9923d5e9f0588 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 20:09:40 +0100 Subject: [PATCH 095/138] increased test coverage --- cmake/unit_tests.cmake | 13 +++- lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc | 31 ++++++++ lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp | 47 ++++++++++++ .../test/wf/jsonrpc/mock_timer_callback.cc | 41 ++++++++++ .../test/wf/jsonrpc/mock_timer_callback.hpp | 23 ++++++ lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc | 49 +++++++++++- lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp | 74 +++++++++++++++++++ 7 files changed, 276 insertions(+), 2 deletions(-) create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index aaf5381..1722301 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,6 +7,8 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests + lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc + lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc @@ -51,6 +53,7 @@ add_executable(alltests target_include_directories(alltests PRIVATE lib/wf/jsonrpc/include lib/wf/jsonrpc/src + lib/wf/jsonrpc/test lib/wf/timer/include lib/wf/timer/src ${FUSE3_INCLUDE_DIRS} @@ -60,7 +63,15 @@ 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 + webfuse-adapter-static webfuse-provider-static webfuse-core diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc new file mode 100644 index 0000000..bdfde2b --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc @@ -0,0 +1,31 @@ +#include "wf/jsonrpc/mock_timer.hpp" +#include "wf/jsonrpc/wrap.hpp" + +extern "C" +{ +static wf_jsonrpc_test::ITimer * wf_jsonrpc_MockTimer = nullptr; + +WF_WRAP_FUNC0(wf_jsonrpc_MockTimer, wf_timer_manager *, wf_timer_manager_create); +WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_manager_dispose, wf_timer_manager *); +WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_manager_check, wf_timer_manager *); + +WF_WRAP_FUNC3(wf_jsonrpc_MockTimer, wf_timer *, wf_timer_create, wf_timer_manager *, wf_timer_on_timer_fn *, void *); +WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_dispose, wf_timer *); +WF_WRAP_FUNC2(wf_jsonrpc_MockTimer, void, wf_timer_start, wf_timer *, int); +WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_cancel, wf_timer *); + +} + +namespace wf_jsonrpc_test +{ +MockTimer::MockTimer() +{ + wf_jsonrpc_MockTimer = this; +} + +MockTimer::~MockTimer() +{ + wf_jsonrpc_MockTimer = nullptr; +} + +} \ No newline at end of file diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp new file mode 100644 index 0000000..3fde45e --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp @@ -0,0 +1,47 @@ +#ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP +#define WF_JSONRPC_MOCK_TIMERMANAGER_HPP + +#include +#include + +namespace wf_jsonrpc_test +{ + +class ITimer +{ +public: + virtual ~ITimer() = default; + virtual wf_timer_manager * wf_timer_manager_create() = 0; + virtual void wf_timer_manager_dispose(wf_timer_manager * manager) = 0; + virtual void wf_timer_manager_check(wf_timer_manager * manager) = 0; + virtual wf_timer * wf_timer_create( + wf_timer_manager * manager, + wf_timer_on_timer_fn * on_timer, + void * user_data) = 0; + virtual void wf_timer_dispose(wf_timer * timer) = 0; + virtual void wf_timer_start(wf_timer * timer, int timeout_ms) = 0; + virtual void wf_timer_cancel(wf_timer * timer) = 0; +}; + +class MockTimer: public ITimer +{ +public: + MockTimer(); + ~MockTimer() override; + MOCK_METHOD0(wf_timer_manager_create, wf_timer_manager * ()); + MOCK_METHOD1(wf_timer_manager_dispose, void(wf_timer_manager * manager)); + MOCK_METHOD1(wf_timer_manager_check, void (wf_timer_manager * manager)); + MOCK_METHOD3(wf_timer_create, wf_timer *( + wf_timer_manager * manager, + wf_timer_on_timer_fn * on_timer, + void * user_data)); + MOCK_METHOD1(wf_timer_dispose, void (wf_timer * timer)); + MOCK_METHOD2(wf_timer_start, void (wf_timer * timer, int timeout_ms)); + MOCK_METHOD1(wf_timer_cancel, void (wf_timer * timer)); + +}; + + +} + +#endif diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc new file mode 100644 index 0000000..dd3cc3b --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc @@ -0,0 +1,41 @@ +#include "wf/jsonrpc/mock_timer_callback.hpp" + +extern "C" +{ +using wf_jsonrpc_test::MockTimerCallback; + +static void wf_jsonrpc_test_MockTimerCallback_on_timer( + wf_timer * timer, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->on_timer(timer, user_data); +} + +} + +namespace wf_jsonrpc_test +{ + +MockTimerCallback::MockTimerCallback() +{ + +} + +MockTimerCallback::~MockTimerCallback() +{ + +} + +wf_timer_on_timer_fn * MockTimerCallback::on_timer_fn() +{ + return &wf_jsonrpc_test_MockTimerCallback_on_timer; +} + +void * MockTimerCallback::user_data() +{ + return reinterpret_cast(this); +} + + +} \ No newline at end of file diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp new file mode 100644 index 0000000..cdbf2d6 --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp @@ -0,0 +1,23 @@ +#ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP +#define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP + +#include "wf/timer.h" +#include + +namespace wf_jsonrpc_test +{ +class MockTimerCallback +{ +public: + MockTimerCallback(); + virtual ~MockTimerCallback(); + wf_timer_on_timer_fn * on_timer_fn(); + void * user_data(); + + MOCK_METHOD2(on_timer, void (wf_timer * timer, void * user_data)); + +}; + +} + +#endif diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc index 66eafa9..763fa51 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc @@ -3,11 +3,17 @@ #include "wf/jsonrpc/status.h" #include "wf/timer/manager.h" +#include "wf/jsonrpc/mock_timer.hpp" + #include #include using namespace std::chrono_literals; - +using wf_jsonrpc_test::MockTimer; +using testing::Return; +using testing::_; +using testing::DoAll; +using testing::SaveArg; #define WF_DEFAULT_TIMEOUT (10 * 1000) @@ -380,3 +386,44 @@ TEST(wf_jsonrpc_proxy, notify_dont_send_invalid_request) wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } + +TEST(wf_jsonrpc_proxy, swallow_timeout_if_no_request_pending) +{ + MockTimer timer_api; + + wf_timer_on_timer_fn * on_timer = nullptr; + void * timer_context = nullptr; + EXPECT_CALL(timer_api, wf_timer_create(_, _, _)) + .Times(1) + .WillOnce(DoAll(SaveArg<1>(&on_timer), SaveArg<2>(&timer_context), Return(nullptr))); + + SendContext send_context; + void * send_data = reinterpret_cast(&send_context); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(nullptr, 1, &jsonrpc_send, send_data); + + on_timer(nullptr, timer_context); + ASSERT_FALSE(send_context.is_called); + + + wf_jsonrpc_proxy_dispose(proxy); +} + +TEST(wf_jsonrpc_proxy, on_result_swallow_if_no_request_pending) +{ + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); + + SendContext send_context; + void * send_data = reinterpret_cast(&send_context); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + + json_t * response = json_object(); + json_object_set_new(response, "result", json_string("okay")); + json_object_set_new(response, "id", json_integer(42)); + + wf_jsonrpc_proxy_onresult(proxy, response); + json_decref(response); + + wf_jsonrpc_proxy_dispose(proxy); + wf_timer_manager_dispose(timer_manager); +} + diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp b/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp new file mode 100644 index 0000000..9d062d8 --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp @@ -0,0 +1,74 @@ +#ifndef WF_WRAP_HPP +#define WF_WRAP_HPP + +#define WF_WRAP_FUNC0( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (); \ + RETURN_TYPE __wrap_ ## FUNC_NAME () \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(); \ + } \ + } + +#define WF_WRAP_FUNC1( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1); \ + } \ + } + +#define WF_WRAP_FUNC2( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2); \ + } \ + } + +#define WF_WRAP_FUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3); \ + } \ + } + +#define WF_WRAP_FUNC4( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4); \ + } \ + } + +#endif From bbdd5a24f59f5b301b7d70c15134637fc8ec6143 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 17:40:33 +0200 Subject: [PATCH 096/138] integrated libwf_timer and libwf_jsonrpc into libwebfuse-core --- CMakeLists.txt | 2 - cmake/unit_tests.cmake | 43 ++---- cmake/webfuse_adapter.cmake | 4 +- cmake/webfuse_core.cmake | 10 ++ cmake/webfuse_provider.cmake | 4 +- cmake/wf_jsonrpc.cmake | 24 --- cmake/wf_timer.cmake | 18 --- lib/webfuse/adapter/impl/operation/close.c | 2 +- lib/webfuse/adapter/impl/operation/getattr.c | 2 +- lib/webfuse/adapter/impl/operation/lookup.c | 2 +- lib/webfuse/adapter/impl/operation/open.c | 2 +- lib/webfuse/adapter/impl/operation/read.c | 2 +- lib/webfuse/adapter/impl/operation/readdir.c | 2 +- lib/webfuse/adapter/impl/server_protocol.c | 6 +- lib/webfuse/adapter/impl/server_protocol.h | 4 +- lib/webfuse/adapter/impl/session.c | 6 +- lib/webfuse/adapter/impl/session.h | 4 +- lib/webfuse/core/json_util.c | 23 +-- .../impl => webfuse/core/jsonrpc}/error.c | 8 +- .../impl => webfuse/core/jsonrpc}/error.h | 10 +- .../impl => webfuse/core/jsonrpc}/method.c | 6 +- .../impl => webfuse/core/jsonrpc}/method.h | 10 +- .../core}/jsonrpc/method_invoke_fn.h | 2 - .../impl => webfuse/core/jsonrpc}/proxy.c | 63 ++++---- .../wf => webfuse/core}/jsonrpc/proxy.h | 15 +- .../core}/jsonrpc/proxy_finished_fn.h | 0 lib/webfuse/core/jsonrpc/proxy_intern.h | 48 ++++++ .../impl => webfuse/core/jsonrpc}/request.c | 22 +-- .../wf => webfuse/core}/jsonrpc/request.h | 15 +- .../impl => webfuse/core/jsonrpc}/response.c | 16 +- .../wf => webfuse/core}/jsonrpc/response.h | 3 +- .../core/jsonrpc/response_intern.h} | 16 +- .../wf => webfuse/core}/jsonrpc/send_fn.h | 1 - .../impl => webfuse/core/jsonrpc}/server.c | 57 ++++--- .../wf => webfuse/core}/jsonrpc/server.h | 13 +- .../impl => webfuse/core/timer}/manager.c | 24 +-- .../wf => webfuse/core}/timer/manager.h | 8 +- lib/webfuse/core/timer/manager_intern.h | 26 ++++ .../wf => webfuse/core}/timer/on_timer_fn.h | 0 .../impl => webfuse/core/timer}/timepoint.c | 12 +- .../impl => webfuse/core/timer}/timepoint.h | 10 +- .../timer/impl => webfuse/core/timer}/timer.c | 26 ++-- .../include/wf => webfuse/core}/timer/timer.h | 11 +- lib/webfuse/core/timer/timer_intern.h | 40 +++++ lib/webfuse/provider/impl/client_protocol.c | 8 +- lib/wf/jsonrpc/include/wf/jsonrpc.h | 14 -- lib/wf/jsonrpc/include/wf/jsonrpc/api.h | 8 - lib/wf/jsonrpc/include/wf/jsonrpc/status.h | 11 -- lib/wf/jsonrpc/src/wf/jsonrpc/api.c | 144 ------------------ lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h | 84 ---------- lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h | 53 ------- lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h | 41 ----- .../src/wf/jsonrpc/impl/unused_param.h | 10 -- lib/wf/timer/include/wf/timer.h | 9 -- lib/wf/timer/include/wf/timer/api.h | 8 - lib/wf/timer/src/wf/timer/api.c | 59 ------- lib/wf/timer/src/wf/timer/impl/manager.h | 36 ----- lib/wf/timer/src/wf/timer/impl/timer.h | 59 ------- lib/wf/timer/test/wf/timer/test_timepoint.cc | 38 ----- .../webfuse/tests/core}/jsonrpc/mock_timer.cc | 4 +- .../tests/core}/jsonrpc/mock_timer.hpp | 3 +- .../core}/jsonrpc/mock_timer_callback.cc | 2 +- .../core}/jsonrpc/mock_timer_callback.hpp | 2 +- .../tests/core}/jsonrpc/test_is_request.cc | 2 +- .../tests/core}/jsonrpc/test_is_response.cc | 2 +- .../webfuse/tests/core}/jsonrpc/test_proxy.cc | 16 +- .../tests/core}/jsonrpc/test_request.cc | 8 +- .../tests/core}/jsonrpc/test_response.cc | 48 +++--- .../core}/jsonrpc/test_response_parser.cc | 14 +- .../tests/core}/jsonrpc/test_server.cc | 8 +- .../tests/core/timer/test_timepoint.cc | 38 +++++ .../webfuse/tests/core}/timer/test_timer.cc | 4 +- .../jsonrpc => test/webfuse/utils}/wrap.hpp | 0 73 files changed, 426 insertions(+), 929 deletions(-) delete mode 100644 cmake/wf_jsonrpc.cmake delete mode 100644 cmake/wf_timer.cmake rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/error.c (73%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/error.h (63%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/method.c (77%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/method.h (70%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/method_invoke_fn.h (92%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/proxy.c (74%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/proxy.h (80%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/proxy_finished_fn.h (100%) create mode 100644 lib/webfuse/core/jsonrpc/proxy_intern.h rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/request.c (76%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/request.h (64%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/response.c (73%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/response.h (74%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl/response.h => webfuse/core/jsonrpc/response_intern.h} (57%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/send_fn.h (90%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/server.c (59%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/server.h (69%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/manager.c (73%) rename lib/{wf/timer/include/wf => webfuse/core}/timer/manager.h (72%) create mode 100644 lib/webfuse/core/timer/manager_intern.h rename lib/{wf/timer/include/wf => webfuse/core}/timer/on_timer_fn.h (100%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timepoint.c (59%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timepoint.h (57%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timer.c (61%) rename lib/{wf/timer/include/wf => webfuse/core}/timer/timer.h (72%) create mode 100644 lib/webfuse/core/timer/timer_intern.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/api.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/status.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/api.c delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h delete mode 100644 lib/wf/timer/include/wf/timer.h delete mode 100644 lib/wf/timer/include/wf/timer/api.h delete mode 100644 lib/wf/timer/src/wf/timer/api.c delete mode 100644 lib/wf/timer/src/wf/timer/impl/manager.h delete mode 100644 lib/wf/timer/src/wf/timer/impl/timer.h delete mode 100644 lib/wf/timer/test/wf/timer/test_timepoint.cc rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer.cc (90%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer.hpp (94%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer_callback.cc (90%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer_callback.hpp (89%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_is_request.cc (98%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_is_response.cc (98%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_proxy.cc (97%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_request.cc (95%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_response.cc (69%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_response_parser.cc (80%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_server.cc (97%) create mode 100644 test/webfuse/tests/core/timer/test_timepoint.cc rename {lib/wf/timer/test/wf => test/webfuse/tests/core}/timer/test_timer.cc (97%) rename {lib/wf/jsonrpc/test/wf/jsonrpc => test/webfuse/utils}/wrap.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfe430b..5e3f18c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,6 @@ add_compile_options( "-pthread" ) -include(wf_timer) -include(wf_jsonrpc) include(webfuse_core) include(webfuse_adapter) include(webfuse_provider) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1722301..8f21188 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,17 +7,17 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests - lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc - lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc - lib/wf/timer/test/wf/timer/test_timepoint.cc - lib/wf/timer/test/wf/timer/test_timer.cc + test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc + test/webfuse/tests/core/jsonrpc/mock_timer.cc + test/webfuse/tests/core/jsonrpc/test_is_request.cc + test/webfuse/tests/core/jsonrpc/test_request.cc + test/webfuse/tests/core/jsonrpc/test_is_response.cc + test/webfuse/tests/core/jsonrpc/test_response.cc + test/webfuse/tests/core/jsonrpc/test_server.cc + test/webfuse/tests/core/jsonrpc/test_proxy.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/file_utils.cc test/webfuse/utils/die_if.cc @@ -50,19 +50,6 @@ add_executable(alltests test/webfuse/tests/integration/provider.cc ) -target_include_directories(alltests PRIVATE - lib/wf/jsonrpc/include - lib/wf/jsonrpc/src - lib/wf/jsonrpc/test - lib/wf/timer/include - lib/wf/timer/src - ${FUSE3_INCLUDE_DIRS} -) - -target_compile_options(alltests PUBLIC - ${FUSE3_CFLAGS_OTHER} -) - target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_manager_create -Wl,--wrap=wf_timer_manager_dispose @@ -75,8 +62,6 @@ target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core - wf_jsonrpc - wf_timer ${FUSE3_LIBRARIES} ${LWS_LIBRARIES} ${JANSSON_LIBRARIES} @@ -85,8 +70,8 @@ target_link_libraries(alltests PUBLIC ${GTEST_LIBRARIES} ) -target_include_directories(alltests PUBLIC test lib ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) -target_compile_options(alltests PUBLIC ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) +target_include_directories(alltests PUBLIC test lib ${FUSE3_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) +target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) enable_testing() gtest_discover_tests(alltests TEST_PREFIX alltests:) @@ -102,7 +87,7 @@ add_custom_target(coverage add_dependencies(coverage alltests) 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) diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index f6e777c..fab0f55 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -26,8 +26,6 @@ add_library(webfuse-adapter-static STATIC target_include_directories(webfuse-adapter-static PRIVATE lib - lib/wf/timer/include - lib/wf/jsonrpc/include ${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 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" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index dab6223..fb25b75 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -9,6 +9,16 @@ add_library(webfuse-core STATIC lib/webfuse/core/base64.c lib/webfuse/core/lws_log.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/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) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index 4cf285d..fbfa104 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -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) target_include_directories(webfuse-provider-static PRIVATE lib - lib/wf/timer/include - lib/wf/jsonrpc/include ) 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") 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" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/wf_jsonrpc.cmake b/cmake/wf_jsonrpc.cmake deleted file mode 100644 index fae8d74..0000000 --- a/cmake/wf_jsonrpc.cmake +++ /dev/null @@ -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) diff --git a/cmake/wf_timer.cmake b/cmake/wf_timer.cmake deleted file mode 100644 index 8bdecf2..0000000 --- a/cmake/wf_timer.cmake +++ /dev/null @@ -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) diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index dcb65fb..5f6e49b 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -4,7 +4,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" void wf_impl_operation_close( diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index 767b06c..ae64a25 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -7,7 +7,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index 596f7e4..4b64320 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -10,7 +10,7 @@ #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 0c10c45..8e21100 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -4,7 +4,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/status.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 8fa5bee..7896b30 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -5,7 +5,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/base64.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index f188084..804a80e 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -8,7 +8,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index ee5cbb0..7caf0bc 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -11,9 +11,9 @@ #include "webfuse/adapter/impl/credentials.h" #include "webfuse/core/status_intern.h" -#include "wf/jsonrpc/request.h" -#include "wf/timer/manager.h" -#include "wf/timer/timer.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/timer/manager.h" +#include "webfuse/core/timer/timer.h" static int wf_impl_server_protocol_callback( struct lws * wsi, diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index df98c8f..269e3be 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -4,8 +4,8 @@ #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/session_manager.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/server.h" #ifndef __cplusplus #include diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index 778d155..6bacd10 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -8,9 +8,9 @@ #include "webfuse/core/container_of.h" #include "webfuse/core/util.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/response.h" #include #include diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h index 82b042f..1046a2e 100644 --- a/lib/webfuse/adapter/impl/session.h +++ b/lib/webfuse/adapter/impl/session.h @@ -13,8 +13,8 @@ using std::size_t; #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/core/slist.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/server.h" #ifdef __cplusplus extern "C" diff --git a/lib/webfuse/core/json_util.c b/lib/webfuse/core/json_util.c index 48fe956..535e07e 100644 --- a/lib/webfuse/core/json_util.c +++ b/lib/webfuse/core/json_util.c @@ -1,5 +1,4 @@ #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) { @@ -14,25 +13,6 @@ int wf_impl_json_get_int(json_t const * object, char const * key, int default_va 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_impl_jsonrpc_get_status( json_t const * error) @@ -40,8 +20,7 @@ wf_impl_jsonrpc_get_status( wf_status status = WF_GOOD; if (NULL != error) { - int code = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT); - status = wf_impl_jsonrc_code_to_status(code); + status = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT); } return status; diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c b/lib/webfuse/core/jsonrpc/error.c similarity index 73% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c rename to lib/webfuse/core/jsonrpc/error.c index eba2e86..ad74a58 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c +++ b/lib/webfuse/core/jsonrpc/error.c @@ -1,7 +1,7 @@ -#include "wf/jsonrpc/impl/error.h" +#include "webfuse/core/jsonrpc/error.h" json_t * -wf_jsonrpc_impl_error( +wf_jsonrpc_error( int code, char const * message) { @@ -13,13 +13,13 @@ wf_jsonrpc_impl_error( } void -wf_jsonrpc_impl_propate_error( +wf_jsonrpc_propate_error( wf_jsonrpc_proxy_finished_fn * finised, void * user_data, int code, 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); json_decref(error); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h b/lib/webfuse/core/jsonrpc/error.h similarity index 63% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h rename to lib/webfuse/core/jsonrpc/error.h index fda0f89..2edfd92 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h +++ b/lib/webfuse/core/jsonrpc/error.h @@ -1,8 +1,8 @@ -#ifndef WF_JSONRPC_IMPL_ERROR_H -#define WF_JSONRPC_IMPL_ERROR_H +#ifndef WF_JSONRPC_ERROR_H +#define WF_JSONRPC_ERROR_H #include -#include "wf/jsonrpc/proxy_finished_fn.h" +#include "webfuse/core/jsonrpc/proxy_finished_fn.h" #ifdef __cplusplus extern "C" @@ -10,12 +10,12 @@ extern "C" #endif extern json_t * -wf_jsonrpc_impl_error( +wf_jsonrpc_error( int code, char const * message); extern void -wf_jsonrpc_impl_propate_error( +wf_jsonrpc_propate_error( wf_jsonrpc_proxy_finished_fn * finised, void * user_data, int code, diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c b/lib/webfuse/core/jsonrpc/method.c similarity index 77% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c rename to lib/webfuse/core/jsonrpc/method.c index ef0d16c..a184dca 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c +++ b/lib/webfuse/core/jsonrpc/method.c @@ -1,8 +1,8 @@ -#include "wf/jsonrpc/impl/method.h" +#include "webfuse/core/jsonrpc/method.h" #include #include -struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( +struct wf_jsonrpc_method * wf_jsonrpc_method_create( char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data) @@ -16,7 +16,7 @@ struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( return method; } -void wf_jsonrpc_impl_method_dispose( +void wf_jsonrpc_method_dispose( struct wf_jsonrpc_method * method) { free(method->name); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h b/lib/webfuse/core/jsonrpc/method.h similarity index 70% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h rename to lib/webfuse/core/jsonrpc/method.h index d0e42f0..e196bff 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h +++ b/lib/webfuse/core/jsonrpc/method.h @@ -1,7 +1,7 @@ -#ifndef WF_JSONRPC_IMPL_METHOD_H -#define WF_JSONRPC_IMPL_METHOD_H +#ifndef WF_JSONRPC_METHOD_H +#define WF_JSONRPC_METHOD_H -#include "wf/jsonrpc/method_invoke_fn.h" +#include "webfuse/core/jsonrpc/method_invoke_fn.h" #ifdef __cplusplus extern "C" @@ -17,13 +17,13 @@ struct wf_jsonrpc_method }; extern struct wf_jsonrpc_method * -wf_jsonrpc_impl_method_create( +wf_jsonrpc_method_create( char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data); extern void -wf_jsonrpc_impl_method_dispose( +wf_jsonrpc_method_dispose( struct wf_jsonrpc_method * method); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h b/lib/webfuse/core/jsonrpc/method_invoke_fn.h similarity index 92% rename from lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h rename to lib/webfuse/core/jsonrpc/method_invoke_fn.h index d7a9cc8..046dfb6 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h +++ b/lib/webfuse/core/jsonrpc/method_invoke_fn.h @@ -1,7 +1,6 @@ #ifndef WF_JSONRPC_METHOD_INVOKE_FN_H #define WF_JSONRPC_METHOD_INVOKE_FN_H -#include #include #ifdef __cplusplus @@ -17,7 +16,6 @@ typedef void wf_jsonrpc_method_invoke_fn( json_t * params, void * user_data); - #ifdef __cplusplus } #endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c b/lib/webfuse/core/jsonrpc/proxy.c similarity index 74% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c rename to lib/webfuse/core/jsonrpc/proxy.c index 99b3f03..67fd6d8 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c +++ b/lib/webfuse/core/jsonrpc/proxy.c @@ -1,34 +1,34 @@ -#include "wf/jsonrpc/impl/proxy.h" -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/impl/error.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/proxy_intern.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/jsonrpc/error.h" +#include "webfuse/core/status.h" -#include +#include "webfuse/core/timer/timer.h" #include #include struct wf_jsonrpc_proxy * -wf_jsonrpc_impl_proxy_create( +wf_jsonrpc_proxy_create( struct wf_timer_manager * manager, int timeout, wf_jsonrpc_send_fn * send, void * user_data) { struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy)); - wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); + wf_jsonrpc_proxy_init(proxy, manager, timeout, send, user_data); return proxy; } -void wf_jsonrpc_impl_proxy_dispose( +void wf_jsonrpc_proxy_dispose( struct wf_jsonrpc_proxy * proxy) { - wf_jsonrpc_impl_proxy_cleanup(proxy); + wf_jsonrpc_proxy_cleanup(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_jsonrpc_proxy * proxy = proxy_ptr; @@ -44,11 +44,11 @@ static void wf_jsonrpc_impl_proxy_on_timeout( proxy->request.finished = NULL; 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, int id, char const * param_info, @@ -98,7 +98,7 @@ static json_t * wf_jsonrpc_impl_request_create( return request; } -void wf_jsonrpc_impl_proxy_init( +void wf_jsonrpc_proxy_init( struct wf_jsonrpc_proxy * proxy, struct wf_timer_manager * timeout_manager, int timeout, @@ -110,10 +110,10 @@ void wf_jsonrpc_impl_proxy_init( proxy->user_data = user_data; proxy->request.is_pending = false; 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) { if (proxy->request.is_pending) @@ -127,19 +127,19 @@ void wf_jsonrpc_impl_proxy_cleanup( proxy->request.id = 0; 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); } -void wf_jsonrpc_impl_proxy_invoke( +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 + ... ) { if (!proxy->request.is_pending) @@ -150,7 +150,10 @@ void wf_jsonrpc_impl_proxy_invoke( proxy->request.id = 42; wf_timer_start(proxy->request.timer, proxy->timeout); - json_t * request = wf_jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args); + va_list args; + va_start(args, param_info); + json_t * request = wf_jsonrpc_request_create(method_name, proxy->request.id, param_info, args); + va_end(args); bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data))); if (!is_send) @@ -161,7 +164,7 @@ void wf_jsonrpc_impl_proxy_invoke( proxy->request.id = 0; 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) @@ -171,18 +174,22 @@ void wf_jsonrpc_impl_proxy_invoke( } 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_notify( struct wf_jsonrpc_proxy * proxy, char const * method_name, char const * param_info, - va_list args + ... ) -{ - json_t * request = wf_jsonrpc_impl_request_create(method_name, 0, param_info, args); +{ + va_list args; + va_start(args, param_info); + json_t * request = wf_jsonrpc_request_create(method_name, 0, param_info, args); + va_end(args); + if (NULL != request) { proxy->send(request, proxy->user_data); @@ -191,12 +198,12 @@ extern void wf_jsonrpc_impl_proxy_notify( } -void wf_jsonrpc_impl_proxy_onresult( +void wf_jsonrpc_proxy_onresult( struct wf_jsonrpc_proxy * proxy, json_t * message) { 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)) { @@ -212,6 +219,6 @@ void wf_jsonrpc_impl_proxy_onresult( finished(user_data, response.result, response.error); } - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h b/lib/webfuse/core/jsonrpc/proxy.h similarity index 80% rename from lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h rename to lib/webfuse/core/jsonrpc/proxy.h index 66fd1a5..8a69936 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h +++ b/lib/webfuse/core/jsonrpc/proxy.h @@ -12,9 +12,8 @@ using std::size_t; #endif #include -#include -#include -#include +#include "webfuse/core/jsonrpc/send_fn.h" +#include "webfuse/core/jsonrpc/proxy_finished_fn.h" #ifdef __cplusplus extern "C" { @@ -23,14 +22,14 @@ extern "C" { struct wf_jsonrpc_proxy; struct wf_timer_manager; -extern WF_JSONRPC_API struct wf_jsonrpc_proxy * +extern struct wf_jsonrpc_proxy * wf_jsonrpc_proxy_create( struct wf_timer_manager * manager, int timeout, wf_jsonrpc_send_fn * send, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose( +extern void wf_jsonrpc_proxy_dispose( 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 ... params //------------------------------------------------------------------------------ -extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke( +extern void wf_jsonrpc_proxy_invoke( struct wf_jsonrpc_proxy * proxy, wf_jsonrpc_proxy_finished_fn * finished, 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, char const * method_name, char const * param_info, ... ); -extern WF_JSONRPC_API void wf_jsonrpc_proxy_onresult( +extern void wf_jsonrpc_proxy_onresult( struct wf_jsonrpc_proxy * proxy, json_t * message); diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h b/lib/webfuse/core/jsonrpc/proxy_finished_fn.h similarity index 100% rename from lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h rename to lib/webfuse/core/jsonrpc/proxy_finished_fn.h diff --git a/lib/webfuse/core/jsonrpc/proxy_intern.h b/lib/webfuse/core/jsonrpc/proxy_intern.h new file mode 100644 index 0000000..3186e14 --- /dev/null +++ b/lib/webfuse/core/jsonrpc/proxy_intern.h @@ -0,0 +1,48 @@ +#ifndef WF_JSONRPC_PROXY_INTERN_H +#define WF_JSONRPC_PROXY_INTERN_H + +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy_finished_fn.h" +#include "webfuse/core/jsonrpc/send_fn.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_timer; + +struct wf_jsonrpc_request +{ + bool is_pending; + wf_jsonrpc_proxy_finished_fn * finished; + void * user_data; + int id; + struct wf_timer * timer; +}; + +struct wf_jsonrpc_proxy +{ + struct wf_jsonrpc_request request; + int timeout; + wf_jsonrpc_send_fn * send; + void * user_data; +}; + +extern void +wf_jsonrpc_proxy_init( + struct wf_jsonrpc_proxy * proxy, + struct wf_timer_manager * manager, + int timeout, + wf_jsonrpc_send_fn * send, + void * user_data); + +extern void +wf_jsonrpc_proxy_cleanup( + struct wf_jsonrpc_proxy * proxy); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c b/lib/webfuse/core/jsonrpc/request.c similarity index 76% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c rename to lib/webfuse/core/jsonrpc/request.c index 071ec4b..30212bd 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c +++ b/lib/webfuse/core/jsonrpc/request.c @@ -1,5 +1,5 @@ -#include "wf/jsonrpc/impl/request.h" -#include "wf/jsonrpc/impl/error.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/error.h" #include struct wf_jsonrpc_request @@ -10,7 +10,7 @@ struct wf_jsonrpc_request }; bool -wf_jsonrpc_impl_is_request( +wf_jsonrpc_is_request( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -23,7 +23,7 @@ wf_jsonrpc_impl_is_request( struct wf_jsonrpc_request * -wf_jsonrpc_impl_request_create( +wf_jsonrpc_request_create( int id, wf_jsonrpc_send_fn * send, void * user_data) @@ -37,14 +37,14 @@ wf_jsonrpc_impl_request_create( } void -wf_jsonrpc_impl_request_dispose( +wf_jsonrpc_request_dispose( struct wf_jsonrpc_request * request) { free(request); } void * -wf_jsonrpc_impl_request_get_userdata( +wf_jsonrpc_request_get_userdata( struct wf_jsonrpc_request * request) { return request->user_data; @@ -52,7 +52,7 @@ wf_jsonrpc_impl_request_get_userdata( void -wf_jsonrpc_impl_respond( +wf_jsonrpc_respond( struct wf_jsonrpc_request * request, json_t * result) { @@ -62,20 +62,20 @@ wf_jsonrpc_impl_respond( request->send(response, request->user_data); 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, int code, char const * message) { 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)); request->send(response, request->user_data); json_decref(response); - wf_jsonrpc_impl_request_dispose(request); + wf_jsonrpc_request_dispose(request); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/request.h b/lib/webfuse/core/jsonrpc/request.h similarity index 64% rename from lib/wf/jsonrpc/include/wf/jsonrpc/request.h rename to lib/webfuse/core/jsonrpc/request.h index 73295e6..234ec62 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/request.h +++ b/lib/webfuse/core/jsonrpc/request.h @@ -12,8 +12,7 @@ using std::size_t; #endif #include -#include -#include "wf/jsonrpc/send_fn.h" +#include "webfuse/core/jsonrpc/send_fn.h" #ifdef __cplusplus extern "C" @@ -22,26 +21,26 @@ extern "C" struct wf_jsonrpc_request; -extern WF_JSONRPC_API bool wf_jsonrpc_is_request( +extern bool wf_jsonrpc_is_request( json_t * message); -extern WF_JSONRPC_API struct wf_jsonrpc_request * +extern struct wf_jsonrpc_request * wf_jsonrpc_request_create( int id, wf_jsonrpc_send_fn * send, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_request_dispose( +extern void wf_jsonrpc_request_dispose( 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); -extern WF_JSONRPC_API void wf_jsonrpc_respond( +extern void wf_jsonrpc_respond( struct wf_jsonrpc_request * request, json_t * result); -extern WF_JSONRPC_API void wf_jsonrpc_respond_error( +extern void wf_jsonrpc_respond_error( struct wf_jsonrpc_request * request, int code, char const * message); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c b/lib/webfuse/core/jsonrpc/response.c similarity index 73% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c rename to lib/webfuse/core/jsonrpc/response.c index f9fe180..69f7033 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c +++ b/lib/webfuse/core/jsonrpc/response.c @@ -1,9 +1,9 @@ -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/impl/error.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/jsonrpc/error.h" +#include "webfuse/core/status.h" bool -wf_jsonrpc_impl_is_response( +wf_jsonrpc_is_response( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -16,7 +16,7 @@ wf_jsonrpc_impl_is_response( void -wf_jsonrpc_impl_response_init( +wf_jsonrpc_response_init( struct wf_jsonrpc_response * result, json_t * response) { @@ -27,7 +27,7 @@ wf_jsonrpc_impl_response_init( json_t * id_holder = json_object_get(response, "id"); 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; } @@ -47,13 +47,13 @@ wf_jsonrpc_impl_response_init( } 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 -wf_jsonrpc_impl_response_cleanup( +wf_jsonrpc_response_cleanup( struct wf_jsonrpc_response * response) { if (NULL != response->result) diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/response.h b/lib/webfuse/core/jsonrpc/response.h similarity index 74% rename from lib/wf/jsonrpc/include/wf/jsonrpc/response.h rename to lib/webfuse/core/jsonrpc/response.h index abe2011..0bf0561 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/response.h +++ b/lib/webfuse/core/jsonrpc/response.h @@ -6,14 +6,13 @@ #endif #include -#include #ifdef __cplusplus extern "C" { #endif -extern WF_JSONRPC_API bool wf_jsonrpc_is_response( +extern bool wf_jsonrpc_is_response( json_t * message); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h b/lib/webfuse/core/jsonrpc/response_intern.h similarity index 57% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h rename to lib/webfuse/core/jsonrpc/response_intern.h index 3e1e02e..137a615 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h +++ b/lib/webfuse/core/jsonrpc/response_intern.h @@ -1,16 +1,15 @@ -#ifndef WF_JSONRPC_IMPL_RESPONSE_H -#define WF_JSONRPC_IMPL_RESPONSE_H +#ifndef WF_JSONRPC_RESPONSE_INTERN_H +#define WF_JSONRPC_RESPONSE_INTERN_H + +#include "webfuse/core/jsonrpc/response.h" #ifndef __cplusplus -#include #include #else #include using std::size_t; #endif -#include - #ifdef __cplusplus extern "C" { #endif @@ -22,14 +21,11 @@ struct wf_jsonrpc_response int id; }; -extern bool wf_jsonrpc_impl_is_response( - json_t * message); - -extern void wf_jsonrpc_impl_response_init( +extern void wf_jsonrpc_response_init( struct wf_jsonrpc_response * response, json_t * message); -extern void wf_jsonrpc_impl_response_cleanup( +extern void wf_jsonrpc_response_cleanup( struct wf_jsonrpc_response * response); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h b/lib/webfuse/core/jsonrpc/send_fn.h similarity index 90% rename from lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h rename to lib/webfuse/core/jsonrpc/send_fn.h index 9ea9ef4..2892687 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h +++ b/lib/webfuse/core/jsonrpc/send_fn.h @@ -6,7 +6,6 @@ #endif #include -#include #ifdef __cplusplus extern "C" diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c b/lib/webfuse/core/jsonrpc/server.c similarity index 59% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c rename to lib/webfuse/core/jsonrpc/server.c index b3e27c8..03e30ae 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c +++ b/lib/webfuse/core/jsonrpc/server.c @@ -1,8 +1,8 @@ -#include "wf/jsonrpc/impl/server.h" -#include "wf/jsonrpc/impl/method.h" -#include "wf/jsonrpc/impl/request.h" -#include "wf/jsonrpc/impl/unused_param.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/method.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" +#include "webfuse/core/util.h" #include #include @@ -13,80 +13,79 @@ struct wf_jsonrpc_server }; static void -wf_jsonrpc_impl_server_init( +wf_jsonrpc_server_init( struct wf_jsonrpc_server * server); static void -wf_jsonrpc_impl_server_cleanup( +wf_jsonrpc_server_cleanup( struct wf_jsonrpc_server * 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)); - wf_jsonrpc_impl_server_init(server); + wf_jsonrpc_server_init(server); return server; } void -wf_jsonrpc_impl_server_dispose( +wf_jsonrpc_server_dispose( struct wf_jsonrpc_server * server) { - wf_jsonrpc_impl_server_cleanup(server); + wf_jsonrpc_server_cleanup(server); free(server); } - -static void wf_jsonrpc_impl_server_init( +static void wf_jsonrpc_server_init( struct wf_jsonrpc_server * server) { server->methods = NULL; } -static void wf_jsonrpc_impl_server_cleanup( +static void wf_jsonrpc_server_cleanup( struct wf_jsonrpc_server * server) { struct wf_jsonrpc_method * current = server->methods; while (NULL != current) { struct wf_jsonrpc_method * next = current->next; - wf_jsonrpc_impl_method_dispose(current); + wf_jsonrpc_method_dispose(current); current = next; } server->methods = NULL; } -void wf_jsonrpc_impl_server_add( +void wf_jsonrpc_server_add( struct wf_jsonrpc_server * server, char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, 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; 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, - char const * WF_JSONRPC_UNUSED_PARAM(method_name), - json_t * WF_JSONRPC_UNUSED_PARAM(params), - void * WF_JSONRPC_UNUSED_PARAM(user_data)) + char const * WF_UNUSED_PARAM(method_name), + json_t * WF_UNUSED_PARAM(params), + 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, .name = "", - .invoke = &wf_jsonrpc_impl_server_invalid_method_invoke, + .invoke = &wf_jsonrpc_server_invalid_method_invoke, .user_data = NULL }; static struct wf_jsonrpc_method const * -wf_jsonrpc_impl_server_get_method( +wf_jsonrpc_server_get_method( struct wf_jsonrpc_server * server, char const * method_name) { @@ -101,10 +100,10 @@ wf_jsonrpc_impl_server_get_method( 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, json_t * request_data, wf_jsonrpc_send_fn * send, @@ -120,8 +119,8 @@ void wf_jsonrpc_impl_server_process( { char const * method_name = json_string_value(method_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_method const * method = wf_jsonrpc_impl_server_get_method(server, method_name); + struct wf_jsonrpc_request * request = wf_jsonrpc_request_create(id, send, user_data); + struct wf_jsonrpc_method const * method = wf_jsonrpc_server_get_method(server, method_name); method->invoke(request, method_name, params, method->user_data); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/server.h b/lib/webfuse/core/jsonrpc/server.h similarity index 69% rename from lib/wf/jsonrpc/include/wf/jsonrpc/server.h rename to lib/webfuse/core/jsonrpc/server.h index c4850a5..143f121 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/server.h +++ b/lib/webfuse/core/jsonrpc/server.h @@ -9,9 +9,8 @@ #endif #include -#include -#include -#include +#include "webfuse/core/jsonrpc/method_invoke_fn.h" +#include "webfuse/core/jsonrpc/send_fn.h" #ifdef __cplusplus extern "C" @@ -20,20 +19,20 @@ extern "C" struct wf_jsonrpc_server; -extern WF_JSONRPC_API struct wf_jsonrpc_server * +extern struct wf_jsonrpc_server * wf_jsonrpc_server_create(void); -extern WF_JSONRPC_API void +extern void wf_jsonrpc_server_dispose( 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, char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_server_process( +extern void wf_jsonrpc_server_process( struct wf_jsonrpc_server * server, json_t * request, wf_jsonrpc_send_fn * send, diff --git a/lib/wf/timer/src/wf/timer/impl/manager.c b/lib/webfuse/core/timer/manager.c similarity index 73% rename from lib/wf/timer/src/wf/timer/impl/manager.c rename to lib/webfuse/core/timer/manager.c index f198502..99540e9 100644 --- a/lib/wf/timer/src/wf/timer/impl/manager.c +++ b/lib/webfuse/core/timer/manager.c @@ -1,6 +1,6 @@ -#include "wf/timer/impl/manager.h" -#include "wf/timer/impl/timer.h" -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/manager_intern.h" +#include "webfuse/core/timer/timer_intern.h" +#include "webfuse/core/timer/timepoint.h" #include #include @@ -11,7 +11,7 @@ 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)); manager->timers = NULL; @@ -20,7 +20,7 @@ wf_timer_impl_manager_create(void) } void -wf_timer_impl_manager_dispose( +wf_timer_manager_dispose( struct wf_timer_manager * manager) { struct wf_timer * timer = manager->timers; @@ -28,7 +28,7 @@ wf_timer_impl_manager_dispose( { struct wf_timer * next = timer->next; - wf_timer_impl_trigger(timer); + wf_timer_trigger(timer); timer = next; } @@ -36,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 * timer = manager->timers; @@ -44,17 +44,17 @@ void wf_timer_impl_manager_check( { 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_impl_trigger(timer); + wf_timer_manager_removetimer(manager, timer); + wf_timer_trigger(timer); } timer = next; } } -void wf_timer_impl_manager_addtimer( +void wf_timer_manager_addtimer( struct wf_timer_manager * manager, struct wf_timer * timer) { @@ -68,7 +68,7 @@ void wf_timer_impl_manager_addtimer( manager->timers = timer; } -void wf_timer_impl_manager_removetimer( +void wf_timer_manager_removetimer( struct wf_timer_manager * manager, struct wf_timer * timer) { diff --git a/lib/wf/timer/include/wf/timer/manager.h b/lib/webfuse/core/timer/manager.h similarity index 72% rename from lib/wf/timer/include/wf/timer/manager.h rename to lib/webfuse/core/timer/manager.h index e0febc0..870a2d0 100644 --- a/lib/wf/timer/include/wf/timer/manager.h +++ b/lib/webfuse/core/timer/manager.h @@ -1,8 +1,6 @@ #ifndef WF_TIMER_MANAGER_H #define WF_TIMER_MANAGER_H -#include - #ifdef __cplusplus extern "C" { @@ -10,14 +8,14 @@ extern "C" struct wf_timer_manager; -extern WF_TIMER_API struct wf_timer_manager * +extern struct wf_timer_manager * wf_timer_manager_create(void); -extern WF_TIMER_API void +extern void wf_timer_manager_dispose( struct wf_timer_manager * manager); -extern WF_TIMER_API void +extern void wf_timer_manager_check( struct wf_timer_manager * manager); diff --git a/lib/webfuse/core/timer/manager_intern.h b/lib/webfuse/core/timer/manager_intern.h new file mode 100644 index 0000000..473df2b --- /dev/null +++ b/lib/webfuse/core/timer/manager_intern.h @@ -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 diff --git a/lib/wf/timer/include/wf/timer/on_timer_fn.h b/lib/webfuse/core/timer/on_timer_fn.h similarity index 100% rename from lib/wf/timer/include/wf/timer/on_timer_fn.h rename to lib/webfuse/core/timer/on_timer_fn.h diff --git a/lib/wf/timer/src/wf/timer/impl/timepoint.c b/lib/webfuse/core/timer/timepoint.c similarity index 59% rename from lib/wf/timer/src/wf/timer/impl/timepoint.c rename to lib/webfuse/core/timer/timepoint.c index 877b9c9..09fc025 100644 --- a/lib/wf/timer/src/wf/timer/impl/timepoint.c +++ b/lib/webfuse/core/timer/timepoint.c @@ -1,11 +1,11 @@ -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/timepoint.h" #include #define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 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; clock_gettime(CLOCK_MONOTONIC, &tp); @@ -14,17 +14,17 @@ wf_timer_timepoint wf_timer_impl_timepoint_now(void) 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); 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); return (0 > diff); diff --git a/lib/wf/timer/src/wf/timer/impl/timepoint.h b/lib/webfuse/core/timer/timepoint.h similarity index 57% rename from lib/wf/timer/src/wf/timer/impl/timepoint.h rename to lib/webfuse/core/timer/timepoint.h index 584aa92..cb78197 100644 --- a/lib/wf/timer/src/wf/timer/impl/timepoint.h +++ b/lib/webfuse/core/timer/timepoint.h @@ -1,5 +1,5 @@ -#ifndef WF_TIMER_IMPL_TIMEPOINT_H -#define WF_TIMER_IMPL_TIMEPOINT_H +#ifndef WF_TIMER_TIMEPOINT_H +#define WF_TIMER_TIMEPOINT_H #ifndef __cplusplus #include @@ -16,12 +16,12 @@ extern "C" typedef uint64_t wf_timer_timepoint; 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); -extern bool wf_timer_impl_timepoint_is_elapsed( +extern bool wf_timer_timepoint_is_elapsed( wf_timer_timepoint timepoint); #ifdef __cplusplus diff --git a/lib/wf/timer/src/wf/timer/impl/timer.c b/lib/webfuse/core/timer/timer.c similarity index 61% rename from lib/wf/timer/src/wf/timer/impl/timer.c rename to lib/webfuse/core/timer/timer.c index 5559451..1f4d650 100644 --- a/lib/wf/timer/src/wf/timer/impl/timer.c +++ b/lib/webfuse/core/timer/timer.c @@ -1,13 +1,13 @@ -#include "wf/timer/impl/timer.h" -#include "wf/timer/impl/manager.h" -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/timer_intern.h" +#include "webfuse/core/timer/manager_intern.h" +#include "webfuse/core/timer/timepoint.h" #include #include #include struct wf_timer * -wf_timer_impl_create( +wf_timer_create( struct wf_timer_manager * manager, wf_timer_on_timer_fn * on_timer, void * user_data) @@ -24,37 +24,37 @@ wf_timer_impl_create( } void -wf_timer_impl_dispose( +wf_timer_dispose( struct wf_timer * timer) { free(timer); } -void wf_timer_impl_start( +void wf_timer_start( struct wf_timer * timer, 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) { - wf_timer_impl_manager_removetimer(timer->manager, timer); + wf_timer_manager_removetimer(timer->manager, timer); timer->timeout = 0; } -bool wf_timer_impl_is_timeout( +bool wf_timer_is_timeout( 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) { if (0 != timer->on_timer) diff --git a/lib/wf/timer/include/wf/timer/timer.h b/lib/webfuse/core/timer/timer.h similarity index 72% rename from lib/wf/timer/include/wf/timer/timer.h rename to lib/webfuse/core/timer/timer.h index 686eb89..48149bd 100644 --- a/lib/wf/timer/include/wf/timer/timer.h +++ b/lib/webfuse/core/timer/timer.h @@ -1,8 +1,7 @@ #ifndef WF_TIMER_TIMER_H #define WF_TIMER_TIMER_H -#include -#include +#include "webfuse/core/timer/on_timer_fn.h" #ifdef __cplusplus extern "C" @@ -12,22 +11,22 @@ extern "C" struct wf_timer; struct wf_timer_manager; -extern WF_TIMER_API struct wf_timer * +extern struct wf_timer * wf_timer_create( struct wf_timer_manager * manager, wf_timer_on_timer_fn * on_timer, void * user_data); -extern WF_TIMER_API void +extern void wf_timer_dispose( struct wf_timer * timer); -extern WF_TIMER_API void +extern void wf_timer_start( struct wf_timer * timer, int timeout_ms); -extern WF_TIMER_API void +extern void wf_timer_cancel( struct wf_timer * timer); diff --git a/lib/webfuse/core/timer/timer_intern.h b/lib/webfuse/core/timer/timer_intern.h new file mode 100644 index 0000000..c910a3b --- /dev/null +++ b/lib/webfuse/core/timer/timer_intern.h @@ -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 +#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 diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 4e2b176..a85514a 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -16,11 +16,11 @@ #include "webfuse/provider/impl/url.h" #include "webfuse/core/protocol_names.h" -#include "wf/timer/manager.h" +#include "webfuse/core/timer/manager.h" -#include "wf/jsonrpc/response.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/proxy.h" #define WF_DEFAULT_TIMEOUT (10 * 1000) diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc.h b/lib/wf/jsonrpc/include/wf/jsonrpc.h deleted file mode 100644 index ab7f1dc..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef WF_JSONRPC_H -#define WF_JSONRPC_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/api.h b/lib/wf/jsonrpc/include/wf/jsonrpc/api.h deleted file mode 100644 index 648bf0f..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/api.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WF_JSONRPC_API_H -#define WF_JSONRPC_API_H - -#ifndef WF_JSONRPC_API -#define WF_JSONRPC_API -#endif - -#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/status.h b/lib/wf/jsonrpc/include/wf/jsonrpc/status.h deleted file mode 100644 index 85da73d..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/status.h +++ /dev/null @@ -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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/api.c b/lib/wf/jsonrpc/src/wf/jsonrpc/api.c deleted file mode 100644 index 891bcce..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/api.c +++ /dev/null @@ -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); -} diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h deleted file mode 100644 index 60d2f7a..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef WF_JSONRPC_IMPL_PROXY_H -#define WF_JSONRPC_IMPL_PROXY_H - -#include "wf/jsonrpc/proxy_finished_fn.h" -#include "wf/jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_timer_manager; -struct wf_timer; - -struct wf_jsonrpc_request -{ - bool is_pending; - wf_jsonrpc_proxy_finished_fn * finished; - void * user_data; - int id; - struct wf_timer * timer; -}; - -struct wf_jsonrpc_proxy -{ - struct wf_jsonrpc_request request; - int timeout; - wf_jsonrpc_send_fn * send; - void * user_data; -}; - -extern void -wf_jsonrpc_impl_proxy_init( - struct wf_jsonrpc_proxy * proxy, - struct wf_timer_manager * manager, - int timeout, - wf_jsonrpc_send_fn * send, - void * user_data); - -extern void -wf_jsonrpc_impl_proxy_cleanup( - struct wf_jsonrpc_proxy * proxy); - -extern struct wf_jsonrpc_proxy * -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, - wf_jsonrpc_proxy_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - va_list args -); - -extern void -wf_jsonrpc_impl_proxy_notify( - struct wf_jsonrpc_proxy * proxy, - char const * method_name, - char const * param_info, - va_list args -); - -extern void -wf_jsonrpc_impl_proxy_onresult( - struct wf_jsonrpc_proxy * proxy, - json_t * message); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h deleted file mode 100644 index 0d510e9..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef WF_JSONRPC_IMPL_REQUEST_H -#define WF_JSONRPC_IMPL_REQUEST_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include -#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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h deleted file mode 100644 index 82c7421..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef WF_JSONRPC_IMPL_SERVER_H -#define WF_JSONRPC_IMPL_SERVER_H - -#include -#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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h deleted file mode 100644 index 41323c8..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h +++ /dev/null @@ -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 diff --git a/lib/wf/timer/include/wf/timer.h b/lib/wf/timer/include/wf/timer.h deleted file mode 100644 index 341792b..0000000 --- a/lib/wf/timer/include/wf/timer.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef WF_TIMER_H -#define WF_TIMER_H - -#include -#include -#include -#include - -#endif diff --git a/lib/wf/timer/include/wf/timer/api.h b/lib/wf/timer/include/wf/timer/api.h deleted file mode 100644 index c327ba7..0000000 --- a/lib/wf/timer/include/wf/timer/api.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WF_TIMER_API_H -#define WF_TIMER_API_H - -#ifndef WF_TIMER_API -#define WF_TIMER_API -#endif - -#endif diff --git a/lib/wf/timer/src/wf/timer/api.c b/lib/wf/timer/src/wf/timer/api.c deleted file mode 100644 index d0399a9..0000000 --- a/lib/wf/timer/src/wf/timer/api.c +++ /dev/null @@ -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); -} diff --git a/lib/wf/timer/src/wf/timer/impl/manager.h b/lib/wf/timer/src/wf/timer/impl/manager.h deleted file mode 100644 index c4fc64a..0000000 --- a/lib/wf/timer/src/wf/timer/impl/manager.h +++ /dev/null @@ -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 diff --git a/lib/wf/timer/src/wf/timer/impl/timer.h b/lib/wf/timer/src/wf/timer/impl/timer.h deleted file mode 100644 index 2e18a8b..0000000 --- a/lib/wf/timer/src/wf/timer/impl/timer.h +++ /dev/null @@ -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 -#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 diff --git a/lib/wf/timer/test/wf/timer/test_timepoint.cc b/lib/wf/timer/test/wf/timer/test_timepoint.cc deleted file mode 100644 index 723ff6a..0000000 --- a/lib/wf/timer/test/wf/timer/test_timepoint.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#include "wf/timer/impl/timepoint.h" - -#include -#include - -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)); -} diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc b/test/webfuse/tests/core/jsonrpc/mock_timer.cc similarity index 90% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc rename to test/webfuse/tests/core/jsonrpc/mock_timer.cc index bdfde2b..3cf8e74 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc +++ b/test/webfuse/tests/core/jsonrpc/mock_timer.cc @@ -1,5 +1,5 @@ -#include "wf/jsonrpc/mock_timer.hpp" -#include "wf/jsonrpc/wrap.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer.hpp" +#include "webfuse/utils/wrap.hpp" extern "C" { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp b/test/webfuse/tests/core/jsonrpc/mock_timer.hpp similarity index 94% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp rename to test/webfuse/tests/core/jsonrpc/mock_timer.hpp index 3fde45e..5c95852 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp +++ b/test/webfuse/tests/core/jsonrpc/mock_timer.hpp @@ -1,7 +1,8 @@ #ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP #define WF_JSONRPC_MOCK_TIMERMANAGER_HPP -#include +#include "webfuse/core/timer/timer.h" +#include "webfuse/core/timer/manager.h" #include namespace wf_jsonrpc_test diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc similarity index 90% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc rename to test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc index dd3cc3b..7e62c31 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc +++ b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc @@ -1,4 +1,4 @@ -#include "wf/jsonrpc/mock_timer_callback.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer_callback.hpp" extern "C" { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp similarity index 89% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp rename to test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp index cdbf2d6..e55b7e1 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp +++ b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp @@ -1,7 +1,7 @@ #ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP #define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP -#include "wf/timer.h" +#include "webfuse/core/timer/on_timer_fn.h" #include namespace wf_jsonrpc_test diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc b/test/webfuse/tests/core/jsonrpc/test_is_request.cc similarity index 98% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc rename to test/webfuse/tests/core/jsonrpc/test_is_request.cc index 55e40c6..4599611 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc +++ b/test/webfuse/tests/core/jsonrpc/test_is_request.cc @@ -1,5 +1,5 @@ #include -#include "wf/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/request.h" TEST(wf_jsonrpc_is_request, request_with_object_params) { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc b/test/webfuse/tests/core/jsonrpc/test_is_response.cc similarity index 98% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc rename to test/webfuse/tests/core/jsonrpc/test_is_response.cc index 690bb6c..908ddf0 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc +++ b/test/webfuse/tests/core/jsonrpc/test_is_response.cc @@ -1,5 +1,5 @@ #include -#include "wf/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/response.h" TEST(wf_jsonrpc_is_response, valid_result) { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc b/test/webfuse/tests/core/jsonrpc/test_proxy.cc similarity index 97% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc rename to test/webfuse/tests/core/jsonrpc/test_proxy.cc index 763fa51..bdc8a15 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc +++ b/test/webfuse/tests/core/jsonrpc/test_proxy.cc @@ -1,9 +1,9 @@ #include -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/status.h" -#include "wf/timer/manager.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/status.h" +#include "webfuse/core/timer/manager.h" -#include "wf/jsonrpc/mock_timer.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer.hpp" #include #include @@ -22,7 +22,7 @@ namespace int jsonrpc_get_status(json_t * error) { json_t * code = json_object_get(error, "code"); - return (json_is_integer(code)) ? json_integer_value(code) : WF_JSONRPC_BAD_FORMAT; + return (json_is_integer(code)) ? json_integer_value(code) : WF_BAD_FORMAT; } struct SendContext @@ -196,7 +196,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending) ASSERT_FALSE(finished_context.is_called); ASSERT_TRUE(finished_context2.is_called); - ASSERT_EQ(WF_JSONRPC_BAD_BUSY, jsonrpc_get_status(finished_context2.error)); + ASSERT_EQ(WF_BAD_BUSY, jsonrpc_get_status(finished_context2.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); @@ -217,7 +217,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid) ASSERT_FALSE(send_context.is_called); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_JSONRPC_BAD, jsonrpc_get_status(finished_context.error)); + ASSERT_EQ(WF_BAD, jsonrpc_get_status(finished_context.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); @@ -307,7 +307,7 @@ TEST(wf_jsonrpc_proxy, timeout) wf_timer_manager_check(timer_manager); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_JSONRPC_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error)); + ASSERT_EQ(WF_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc b/test/webfuse/tests/core/jsonrpc/test_request.cc similarity index 95% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc rename to test/webfuse/tests/core/jsonrpc/test_request.cc index a8f7986..8d37a9f 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc +++ b/test/webfuse/tests/core/jsonrpc/test_request.cc @@ -1,6 +1,6 @@ #include -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" namespace { @@ -74,7 +74,7 @@ TEST(wf_jsonrpc_request, respond_error) struct wf_jsonrpc_request * request = wf_jsonrpc_request_create(42, &jsonrpc_send, user_data); - wf_jsonrpc_respond_error(request, WF_JSONRPC_BAD, "Bad"); + wf_jsonrpc_respond_error(request, WF_BAD, "Bad"); ASSERT_NE(nullptr, context.response); @@ -93,7 +93,7 @@ TEST(wf_jsonrpc_request, respond_error) json_t * err_code = json_object_get(err, "code"); ASSERT_TRUE(json_is_integer(err_code)); - ASSERT_EQ(WF_JSONRPC_BAD, json_integer_value(err_code)); + ASSERT_EQ(WF_BAD, json_integer_value(err_code)); json_t * err_message = json_object_get(err, "message"); ASSERT_TRUE(json_is_string(err_message)); diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc b/test/webfuse/tests/core/jsonrpc/test_response.cc similarity index 69% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc rename to test/webfuse/tests/core/jsonrpc/test_response.cc index b71d7f3..f6ef9e7 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc +++ b/test/webfuse/tests/core/jsonrpc/test_response.cc @@ -1,6 +1,6 @@ #include -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/status.h" TEST(wf_json_response, init_result) { @@ -9,14 +9,14 @@ TEST(wf_json_response, init_result) json_object_set_new(message, "id", json_integer(11)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_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); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -30,14 +30,14 @@ TEST(wf_json_response, init_error) json_object_set_new(message, "id", json_integer(23)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_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); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -47,13 +47,13 @@ TEST(wf_json_response, init_fail_missing_result_and_error) json_object_set_new(message, "id", json_integer(12)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_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); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -63,13 +63,13 @@ TEST(wf_json_response, init_fail_missing_id) json_object_set_new(message, "result", json_integer(47)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(-1, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -80,13 +80,13 @@ TEST(wf_json_response, init_fail_wrong_id_type) json_object_set_new(message, "id", json_string("42")); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(-1, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -99,13 +99,13 @@ TEST(wf_json_response, init_fail_error_missing_code) json_object_set_new(message, "id", json_integer(23)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -119,13 +119,13 @@ TEST(wf_json_response, init_fail_error_wrong_code_type) json_object_set_new(message, "id", json_integer(23)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -136,12 +136,12 @@ TEST(wf_json_response, init_fail_error_wrong_type) json_object_set_new(message, "id", json_integer(23)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc b/test/webfuse/tests/core/jsonrpc/test_response_parser.cc similarity index 80% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc rename to test/webfuse/tests/core/jsonrpc/test_response_parser.cc index e3301fa..f9941c1 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc +++ b/test/webfuse/tests/core/jsonrpc/test_response_parser.cc @@ -1,7 +1,7 @@ #include #include -#include "wf/jsonrpc/impl/response.h" +#include "webfuse/core/jsonrpc/response_intern.h" static void response_parse_str( @@ -11,7 +11,7 @@ static void response_parse_str( json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr); if (nullptr != message) { - wf_jsonrpc_impl_response_init(response, message); + wf_jsonrpc_response_init(response, message); json_decref(message); } } @@ -25,21 +25,21 @@ TEST(response_parser, test) ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // empty response_parse_str("{}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // no data response_parse_str("{\"id\":42}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // custom error code response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); @@ -47,12 +47,12 @@ TEST(response_parser, test) ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // valid response response_parse_str("{\"result\": true, \"id\": 42}", &response); ASSERT_EQ(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); } diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc b/test/webfuse/tests/core/jsonrpc/test_server.cc similarity index 97% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc rename to test/webfuse/tests/core/jsonrpc/test_server.cc index 894c607..688028f 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc +++ b/test/webfuse/tests/core/jsonrpc/test_server.cc @@ -1,7 +1,7 @@ #include -#include "wf/jsonrpc/server.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" namespace { @@ -125,7 +125,7 @@ TEST(wf_jsonrpc_server, invoke_unknown_method) 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)); + ASSERT_EQ(WF_BAD_NOTIMPLEMENTED, json_integer_value(err_code)); json_t * err_message = json_object_get(err, "message"); ASSERT_TRUE(json_is_string(err_message)); diff --git a/test/webfuse/tests/core/timer/test_timepoint.cc b/test/webfuse/tests/core/timer/test_timepoint.cc new file mode 100644 index 0000000..f55adab --- /dev/null +++ b/test/webfuse/tests/core/timer/test_timepoint.cc @@ -0,0 +1,38 @@ +#include + +#include "webfuse/core/timer/timepoint.h" + +#include +#include + +using namespace std::chrono_literals; + +TEST(wf_timer_timepoint, now) +{ + wf_timer_timepoint start = wf_timer_timepoint_now(); + std::this_thread::sleep_for(42ms); + wf_timer_timepoint end = wf_timer_timepoint_now(); + + ASSERT_LT(start, end); + ASSERT_LT(end, start + 500); +} + +TEST(wf_timer_timepoint, in_msec) +{ + wf_timer_timepoint now = wf_timer_timepoint_now(); + wf_timer_timepoint later = wf_timer_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_timepoint_now(); + ASSERT_TRUE(wf_timer_timepoint_is_elapsed(now - 1)); + + now = wf_timer_timepoint_now(); + ASSERT_FALSE(wf_timer_timepoint_is_elapsed(now + 500)); +} diff --git a/lib/wf/timer/test/wf/timer/test_timer.cc b/test/webfuse/tests/core/timer/test_timer.cc similarity index 97% rename from lib/wf/timer/test/wf/timer/test_timer.cc rename to test/webfuse/tests/core/timer/test_timer.cc index 2141314..d25b1f5 100644 --- a/lib/wf/timer/test/wf/timer/test_timer.cc +++ b/test/webfuse/tests/core/timer/test_timer.cc @@ -4,8 +4,8 @@ #include #include -#include "wf/timer/timer.h" -#include "wf/timer/manager.h" +#include "webfuse/core/timer/timer.h" +#include "webfuse/core/timer/manager.h" using std::size_t; using namespace std::chrono_literals; diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp b/test/webfuse/utils/wrap.hpp similarity index 100% rename from lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp rename to test/webfuse/utils/wrap.hpp From 39855a99952744188f71c1d623f70772b6d16b91 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 18:38:58 +0200 Subject: [PATCH 097/138] fix: make provider const --- lib/webfuse/provider/impl/provider.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webfuse/provider/impl/provider.h b/lib/webfuse/provider/impl/provider.h index a9b814d..1e8ec1f 100644 --- a/lib/webfuse/provider/impl/provider.h +++ b/lib/webfuse/provider/impl/provider.h @@ -30,7 +30,7 @@ struct wfp_provider struct wfp_impl_invokation_context { - struct wfp_provider * provider; + struct wfp_provider const * provider; void * user_data; struct wfp_request * request; }; From 8d28da5e82b22e80174d37672252535b4e041714 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 19:30:08 +0200 Subject: [PATCH 098/138] added tests for wfp_impl_close --- cmake/unit_tests.cmake | 2 + test/webfuse/mocks/mock_provider.cc | 138 ++++++++++++++++++ test/webfuse/mocks/mock_provider.hpp | 31 ++++ .../tests/provider/operation/test_close.cc | 111 ++++++++++++++ 4 files changed, 282 insertions(+) create mode 100644 test/webfuse/mocks/mock_provider.cc create mode 100644 test/webfuse/mocks/mock_provider.hpp create mode 100644 test/webfuse/tests/provider/operation/test_close.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 8f21188..adbde38 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -28,6 +28,7 @@ add_executable(alltests test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc test/webfuse/mocks/mock_provider_client.cc + test/webfuse/mocks/mock_provider.cc test/webfuse//tests/core/test_util.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc @@ -45,6 +46,7 @@ add_executable(alltests test/webfuse/tests/adapter/test_fuse_req.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc + test/webfuse/tests/provider/operation/test_close.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_provider.cc b/test/webfuse/mocks/mock_provider.cc new file mode 100644 index 0000000..a81b302 --- /dev/null +++ b/test/webfuse/mocks/mock_provider.cc @@ -0,0 +1,138 @@ +#include "webfuse/mocks/mock_provider.hpp" + +extern "C" +{ +using webfuse_test::MockProvider; + +static void webfuse_test_MockProvider_connected( + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->connected(); +} + +static void webfuse_test_MockProvider_disconnected( + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->disconnected(); +} + +static void webfuse_test_MockProvider_on_timer( + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->on_timer(); +} + +static void webfuse_test_MockProvider_lookup( + wfp_request * request, + ino_t parent, + char const * name, + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->lookup(request, parent, name); +} + +static void webfuse_test_MockProvider_getattr( + wfp_request * request, + ino_t inode, + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->getattr(request, inode); +} + +static void webfuse_test_MockProvider_readdir( + wfp_request * request, + ino_t directory, + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->readdir(request, directory); +} + +static void webfuse_test_MockProvider_open( + wfp_request * request, + ino_t inode, + int flags, + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->open(request, inode, flags); + +} + +static void webfuse_test_MockProvider_close( + ino_t inode, + uint32_t handle, + int flags, + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->close(inode, handle, flags); + +} + +static void webfuse_test_MockProvider_read( + wfp_request * request, + ino_t inode, + uint32_t handle, + size_t offset, + size_t length, + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->read(request, inode, handle, offset, length); +} + +static void webfuse_test_MockProvider_get_credentials( + wfp_credentials * credentials, + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->get_credentials(credentials); +} + + +static wfp_provider const webfuse_test_MockProvider = +{ + &webfuse_test_MockProvider_connected, + &webfuse_test_MockProvider_disconnected, + &webfuse_test_MockProvider_on_timer, + &webfuse_test_MockProvider_lookup, + &webfuse_test_MockProvider_getattr, + &webfuse_test_MockProvider_readdir, + &webfuse_test_MockProvider_open, + &webfuse_test_MockProvider_close, + &webfuse_test_MockProvider_read, + &webfuse_test_MockProvider_get_credentials, +}; + +} + +namespace webfuse_test +{ + +MockProvider::MockProvider() +{ + +} + +MockProvider::~MockProvider() +{ + +} + +wfp_provider const * MockProvider::get_provider() +{ + return &webfuse_test_MockProvider; +} + +void * MockProvider::get_userdata() +{ + return reinterpret_cast(this); +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_provider.hpp b/test/webfuse/mocks/mock_provider.hpp new file mode 100644 index 0000000..1f03b08 --- /dev/null +++ b/test/webfuse/mocks/mock_provider.hpp @@ -0,0 +1,31 @@ +#ifndef WF_MOCK_PROVIDER_HPP +#define WF_MOCK_PROVIDER_HPP + +#include "webfuse/provider/impl/provider.h" +#include + +namespace webfuse_test +{ + +class MockProvider +{ +public: + MockProvider(); + ~MockProvider(); + wfp_provider const * get_provider(); + void * get_userdata(); + MOCK_METHOD0(connected, void ()); + MOCK_METHOD0(disconnected, void ()); + MOCK_METHOD0(on_timer, void()); + MOCK_METHOD3(lookup, void(wfp_request * request, ino_t parent, char const * name)); + MOCK_METHOD2(getattr, void(wfp_request * request, ino_t inode)); + MOCK_METHOD2(readdir, void(wfp_request * request, ino_t directory)); + MOCK_METHOD3(open, void(wfp_request * request, ino_t inode, int flags)); + MOCK_METHOD3(close, void(ino_t inode, uint32_t handle, int flags)); + MOCK_METHOD5(read, void(wfp_request * request, ino_t inode, uint32_t handle, size_t offset, size_t length)); + MOCK_METHOD1(get_credentials, void(wfp_credentials * credentials)); +}; + +} + +#endif diff --git a/test/webfuse/tests/provider/operation/test_close.cc b/test/webfuse/tests/provider/operation/test_close.cc new file mode 100644 index 0000000..8c5fc2d --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_close.cc @@ -0,0 +1,111 @@ +#include "webfuse/provider/impl/operation/close.h" +#include "webfuse/mocks/mock_provider.hpp" + +#include + +using ::webfuse_test::MockProvider; +using ::testing::_; + +namespace +{ + wfp_impl_invokation_context create_context(MockProvider& provider) + { + wfp_impl_invokation_context context = + { + provider.get_provider(), + provider.get_userdata(), + nullptr + }; + return context; + } +} + +TEST(wfp_close, close) +{ + int inode = 42; + int handle = 0xdeadbeef; + int flags = 23; + + MockProvider provider; + EXPECT_CALL(provider, close(inode, handle, flags)).Times(1); + + wfp_impl_invokation_context context = create_context(provider); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(inode)); + json_array_append_new(params, json_integer(handle)); + json_array_append_new(params, json_integer(flags)); + + wfp_impl_close(&context, params, 42); + json_decref(params); +} + +TEST(wfp_close, close_fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider, close(_,_,_)).Times(0); + + wfp_impl_invokation_context context = create_context(provider); + + json_t * params = json_array(); + wfp_impl_close(&context, params, 42); + json_decref(params); +} + +TEST(wfp_close, close_fail_inode_invalid_type) +{ + MockProvider provider; + EXPECT_CALL(provider, close(_,_,_)).Times(0); + + wfp_impl_invokation_context context = create_context(provider); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_string("42")); + json_array_append_new(params, json_integer(0)); + json_array_append_new(params, json_integer(0)); + + wfp_impl_close(&context, params, 42); + json_decref(params); +} + +TEST(wfp_close, close_fail_handle_invalid_type) +{ + MockProvider provider; + EXPECT_CALL(provider, close(_,_,_)).Times(0); + + wfp_impl_invokation_context context = create_context(provider); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(0)); + json_array_append_new(params, json_string("42")); + json_array_append_new(params, json_integer(0)); + + wfp_impl_close(&context, params, 42); + json_decref(params); +} + +TEST(wfp_close, close_fail_flags_invalid_type) +{ + MockProvider provider; + EXPECT_CALL(provider, close(_,_,_)).Times(0); + + wfp_impl_invokation_context context = create_context(provider); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(0)); + json_array_append_new(params, json_integer(0)); + json_array_append_new(params, json_string("42")); + + wfp_impl_close(&context, params, 42); + json_decref(params); +} + + +TEST(wfp_close, default_nop) +{ + wfp_impl_close_default(0, 0, 0, nullptr); +} \ No newline at end of file From 70e9f0a278495cfc82133966407bd7ca3a099e6e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 20:41:31 +0200 Subject: [PATCH 099/138] added tests for wfp_impl_getattr --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_request.cc | 19 ++++----- test/webfuse/mocks/mock_request.hpp | 16 +------ .../tests/provider/operation/test_getattr.cc | 42 +++++++++++++++++++ 4 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 test/webfuse/tests/provider/operation/test_getattr.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index adbde38..24cf694 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -47,6 +47,7 @@ add_executable(alltests test/webfuse/tests/provider/test_url.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/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_request.cc b/test/webfuse/mocks/mock_request.cc index c2dd441..5b31c63 100644 --- a/test/webfuse/mocks/mock_request.cc +++ b/test/webfuse/mocks/mock_request.cc @@ -1,15 +1,14 @@ #include "webfuse/mocks/mock_request.hpp" #include -namespace +extern "C" { -extern "C" void -respond( +static void webfuse_test_MockRequest_respond( json_t * response, void * user_data) { - webfuse_test::Request * request = reinterpret_cast(user_data); + auto * request = reinterpret_cast(user_data); json_t * result = json_object_get(response, "result"); json_t * error = json_object_get(response, "error"); @@ -31,21 +30,17 @@ respond( } } - } namespace webfuse_test { -struct wfp_request * -request_create( - Request * req, - int id) +struct wfp_request * MockRequest::create_request(int id) { - struct wfp_request * request = reinterpret_cast(malloc(sizeof(struct wfp_request))); + auto * request = reinterpret_cast(malloc(sizeof(wfp_request))); + request->respond = &webfuse_test_MockRequest_respond; + request->user_data = reinterpret_cast(this); request->id = id; - request->user_data = reinterpret_cast(req); - request->respond = &respond; return request; } diff --git a/test/webfuse/mocks/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp index 51884f4..fec99d2 100644 --- a/test/webfuse/mocks/mock_request.hpp +++ b/test/webfuse/mocks/mock_request.hpp @@ -10,26 +10,14 @@ namespace webfuse_test { -class Request -{ -public: - virtual ~Request() { } - virtual void respond(json_t * result, int id) = 0; - virtual void respond_error(json_t * error, int id) = 0; -}; - -class MockRequest: public Request +class MockRequest { public: + struct wfp_request * create_request(int id); MOCK_METHOD2(respond, void(json_t * result, int id)); MOCK_METHOD2(respond_error, void(json_t * error, int id)); }; -extern struct wfp_request * -request_create( - Request * req, - int id); - MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "") { json_t * inode_holder = json_object_get(arg, "inode"); diff --git a/test/webfuse/tests/provider/operation/test_getattr.cc b/test/webfuse/tests/provider/operation/test_getattr.cc new file mode 100644 index 0000000..39a40c7 --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_getattr.cc @@ -0,0 +1,42 @@ +#include "webfuse/provider/impl/operation/getattr.h" +#include "webfuse/mocks/mock_request.hpp" +#include + +using ::webfuse_test::MockRequest; +using ::webfuse_test::GetAttrMatcher; +using ::testing::_; + +TEST(wfp_impl_getattr, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_getattr_default(req, 0, nullptr); +} + +TEST(wfp_impl_getattr, respond_file) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "file"), 42)).Times(1); + + struct stat buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.st_ino = 23; + buffer.st_mode = S_IFREG | 0754; + wfp_impl_respond_getattr(req, &buffer); +} + +TEST(wfp_impl_getattr, respond_dir) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "dir"), 42)).Times(1); + + struct stat buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.st_ino = 23; + buffer.st_mode = S_IFDIR | 0754; + wfp_impl_respond_getattr(req, &buffer); +} \ No newline at end of file From e9f371c14a54b358094305a481cf351cb07bf76f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 20:40:03 +0200 Subject: [PATCH 100/138] added tests for wfp_impl_getattr --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/fake_invokation_context.cc | 17 +++++ .../webfuse/mocks/fake_invokation_context.hpp | 16 +++++ .../tests/provider/operation/test_close.cc | 16 +---- .../tests/provider/operation/test_getattr.cc | 69 ++++++++++++++++++- 5 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 test/webfuse/mocks/fake_invokation_context.cc create mode 100644 test/webfuse/mocks/fake_invokation_context.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 24cf694..1205ae4 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -25,6 +25,7 @@ add_executable(alltests test/webfuse/utils/path.c test/webfuse/utils/static_filesystem.c test/webfuse/utils/ws_server.cc + test/webfuse/mocks/fake_invokation_context.cc test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc test/webfuse/mocks/mock_provider_client.cc diff --git a/test/webfuse/mocks/fake_invokation_context.cc b/test/webfuse/mocks/fake_invokation_context.cc new file mode 100644 index 0000000..4aea3ee --- /dev/null +++ b/test/webfuse/mocks/fake_invokation_context.cc @@ -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; +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/fake_invokation_context.hpp b/test/webfuse/mocks/fake_invokation_context.hpp new file mode 100644 index 0000000..07eb971 --- /dev/null +++ b/test/webfuse/mocks/fake_invokation_context.hpp @@ -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 \ No newline at end of file diff --git a/test/webfuse/tests/provider/operation/test_close.cc b/test/webfuse/tests/provider/operation/test_close.cc index 8c5fc2d..3769579 100644 --- a/test/webfuse/tests/provider/operation/test_close.cc +++ b/test/webfuse/tests/provider/operation/test_close.cc @@ -1,25 +1,13 @@ #include "webfuse/provider/impl/operation/close.h" #include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" #include using ::webfuse_test::MockProvider; +using ::webfuse_test::create_context; using ::testing::_; -namespace -{ - wfp_impl_invokation_context create_context(MockProvider& provider) - { - wfp_impl_invokation_context context = - { - provider.get_provider(), - provider.get_userdata(), - nullptr - }; - return context; - } -} - TEST(wfp_close, close) { int inode = 42; diff --git a/test/webfuse/tests/provider/operation/test_getattr.cc b/test/webfuse/tests/provider/operation/test_getattr.cc index 39a40c7..b499d1c 100644 --- a/test/webfuse/tests/provider/operation/test_getattr.cc +++ b/test/webfuse/tests/provider/operation/test_getattr.cc @@ -1,10 +1,27 @@ #include "webfuse/provider/impl/operation/getattr.h" #include "webfuse/mocks/mock_request.hpp" -#include +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" +#include +#include + +using ::webfuse_test::MockProvider; using ::webfuse_test::MockRequest; using ::webfuse_test::GetAttrMatcher; +using ::webfuse_test::create_context; using ::testing::_; +using ::testing::Invoke; + +namespace +{ + +void free_request(wfp_request * request, ino_t) +{ + free(request); +} + +} TEST(wfp_impl_getattr, default_responds_error) { @@ -39,4 +56,52 @@ TEST(wfp_impl_getattr, respond_dir) buffer.st_ino = 23; buffer.st_mode = S_IFDIR | 0754; wfp_impl_respond_getattr(req, &buffer); -} \ No newline at end of file +} + +TEST(wfp_impl_getattr, invoke_provider) +{ + ino_t inode = 23; + MockProvider provider; + EXPECT_CALL(provider,getattr(_, inode)).Times(1).WillOnce(Invoke(free_request)); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(inode)); + + wfp_impl_getattr(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_getattr, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider,getattr(_, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + + wfp_impl_getattr(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_getattr, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider,getattr(_, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_string("42")); + + wfp_impl_getattr(&context, params, 42); + json_decref(params); +} From 2c62e16c98a1ab4d7fb7b98242facf75a13aee15 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 21:16:32 +0200 Subject: [PATCH 101/138] added test for wfp_impl_lookup --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_request.hpp | 3 +- .../tests/provider/operation/test_getattr.cc | 6 +- .../tests/provider/operation/test_lookup.cc | 129 ++++++++++++++++++ 4 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 test/webfuse/tests/provider/operation/test_lookup.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1205ae4..3ded8ae 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -49,6 +49,7 @@ add_executable(alltests 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/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp index fec99d2..e3476ba 100644 --- a/test/webfuse/mocks/mock_request.hpp +++ b/test/webfuse/mocks/mock_request.hpp @@ -18,7 +18,7 @@ public: MOCK_METHOD2(respond_error, void(json_t * error, int id)); }; -MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "") +MATCHER_P3(StatMatcher, inode, mode, file_type, "") { json_t * inode_holder = json_object_get(arg, "inode"); if ((!json_is_integer(inode_holder)) || (inode != json_integer_value(inode_holder))) @@ -44,7 +44,6 @@ MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "") return true; } - MATCHER_P(ReaddirMatcher, contained_elements , "") { if (!json_is_array(arg)) diff --git a/test/webfuse/tests/provider/operation/test_getattr.cc b/test/webfuse/tests/provider/operation/test_getattr.cc index b499d1c..332ab89 100644 --- a/test/webfuse/tests/provider/operation/test_getattr.cc +++ b/test/webfuse/tests/provider/operation/test_getattr.cc @@ -8,7 +8,7 @@ using ::webfuse_test::MockProvider; using ::webfuse_test::MockRequest; -using ::webfuse_test::GetAttrMatcher; +using ::webfuse_test::StatMatcher; using ::webfuse_test::create_context; using ::testing::_; using ::testing::Invoke; @@ -36,7 +36,7 @@ TEST(wfp_impl_getattr, respond_file) { MockRequest request; auto * req = request.create_request(42); - EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "file"), 42)).Times(1); + EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1); struct stat buffer; memset(&buffer, 0, sizeof(buffer)); @@ -49,7 +49,7 @@ TEST(wfp_impl_getattr, respond_dir) { MockRequest request; auto * req = request.create_request(42); - EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "dir"), 42)).Times(1); + EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1); struct stat buffer; memset(&buffer, 0, sizeof(buffer)); diff --git a/test/webfuse/tests/provider/operation/test_lookup.cc b/test/webfuse/tests/provider/operation/test_lookup.cc new file mode 100644 index 0000000..32d98eb --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_lookup.cc @@ -0,0 +1,129 @@ +#include "webfuse/provider/impl/operation/lookup.h" +#include "webfuse/mocks/mock_request.hpp" +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" + +#include +#include + +using ::webfuse_test::MockProvider; +using ::webfuse_test::MockRequest; +using ::webfuse_test::StatMatcher; +using ::webfuse_test::create_context; +using ::testing::_; +using ::testing::Invoke; +using ::testing::StrEq; + +namespace +{ + +void free_request(wfp_request * request, ino_t, char const *) +{ + free(request); +} + +} + +TEST(wfp_impl_lookup, invoke_provider) +{ + ino_t inode = 42; + MockProvider provider; + EXPECT_CALL(provider,lookup(_, inode,StrEq("some.file"))).Times(1) + .WillOnce(Invoke(free_request)); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(inode)); + json_array_append_new(params, json_string("some.file")); + + wfp_impl_lookup(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_lookup, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider,lookup(_, _,_)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(23)); + + wfp_impl_lookup(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_lookup, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider,lookup(_, _,_)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_string("23")); + json_array_append_new(params, json_string("some.file")); + + wfp_impl_lookup(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_lookup, fail_invalid_name_type) +{ + MockProvider provider; + EXPECT_CALL(provider,lookup(_, _,_)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_string("23")); + json_array_append_new(params, json_integer(1)); + + wfp_impl_lookup(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_lookup, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_lookup_default(req, 1, "some.file", nullptr); +} + +TEST(wfp_impl_lookup, respond_file) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1); + + struct stat buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.st_ino = 23; + buffer.st_mode = S_IFREG | 0754; + wfp_impl_respond_lookup(req, &buffer); +} + +TEST(wfp_impl_lookup, respond_dir) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1); + + struct stat buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.st_ino = 23; + buffer.st_mode = S_IFDIR | 0754; + wfp_impl_respond_lookup(req, &buffer); +} From 821c67ee4661a53c8122832107f6d3952f015bdd Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 21:28:59 +0200 Subject: [PATCH 102/138] fixed test --- test/webfuse/tests/provider/operation/test_lookup.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/webfuse/tests/provider/operation/test_lookup.cc b/test/webfuse/tests/provider/operation/test_lookup.cc index 32d98eb..4cbccd4 100644 --- a/test/webfuse/tests/provider/operation/test_lookup.cc +++ b/test/webfuse/tests/provider/operation/test_lookup.cc @@ -86,7 +86,7 @@ TEST(wfp_impl_lookup, fail_invalid_name_type) json_t * params = json_array(); json_array_append_new(params, json_string("test.filesystem")); - json_array_append_new(params, json_string("23")); + json_array_append_new(params, json_integer(23)); json_array_append_new(params, json_integer(1)); wfp_impl_lookup(&context, params, 42); From 0b0c16bf10708f41ba7dda4725bca581bac22aaf Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 21:42:13 +0200 Subject: [PATCH 103/138] added tests for wfp_impl_open --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_request.hpp | 12 ++ .../tests/provider/operation/test_open.cc | 110 ++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 test/webfuse/tests/provider/operation/test_open.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 3ded8ae..2c271b5 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -50,6 +50,7 @@ add_executable(alltests 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/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp index e3476ba..f286409 100644 --- a/test/webfuse/mocks/mock_request.hpp +++ b/test/webfuse/mocks/mock_request.hpp @@ -44,6 +44,18 @@ MATCHER_P3(StatMatcher, inode, mode, file_type, "") return true; } +MATCHER_P(OpenMatcher, handle, "") +{ + json_t * handle_holder = json_object_get(arg, "handle"); + if ((!json_is_integer(handle_holder)) || (handle != json_integer_value(handle_holder))) + { + *result_listener << "missing handle"; + return false; + } + + return true; +} + MATCHER_P(ReaddirMatcher, contained_elements , "") { if (!json_is_array(arg)) diff --git a/test/webfuse/tests/provider/operation/test_open.cc b/test/webfuse/tests/provider/operation/test_open.cc new file mode 100644 index 0000000..68a53f0 --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_open.cc @@ -0,0 +1,110 @@ +#include "webfuse/provider/impl/operation/open.h" +#include "webfuse/mocks/mock_request.hpp" +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" + +#include +#include + +using ::webfuse_test::MockProvider; +using ::webfuse_test::MockRequest; +using ::webfuse_test::OpenMatcher; +using ::webfuse_test::create_context; +using ::testing::_; +using ::testing::Invoke; +using ::testing::StrEq; + +namespace +{ + +void free_request(wfp_request * request, ino_t, int) +{ + free(request); +} + +} + +TEST(wfp_impl_open, invoke_provider) +{ + ino_t inode = 42; + int flags = 0; + MockProvider provider; + EXPECT_CALL(provider,open(_, inode, flags)).Times(1) + .WillOnce(Invoke(free_request)); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(inode)); + json_array_append_new(params, json_integer(flags)); + + wfp_impl_open(&context, params, 42); +} + +TEST(wfp_impl_open, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider,open(_, _, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(23)); + + wfp_impl_open(&context, params, 42); +} + +TEST(wfp_impl_open, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider,open(_, _, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_string("")); + json_array_append_new(params, json_integer(0)); + + wfp_impl_open(&context, params, 42); +} + +TEST(wfp_impl_open, fail_invalid_flags_type) +{ + MockProvider provider; + EXPECT_CALL(provider,open(_, _, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(23)); + json_array_append_new(params, json_string("")); + + wfp_impl_open(&context, params, 42); +} + +TEST(wfp_impl_open, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_open_default(req, 1, 0, nullptr); +} + +TEST(wfp_impl_open, respond) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(OpenMatcher(23), 42)).Times(1); + + wfp_impl_respond_open(req, 23); +} + From 6ccc738d17d28e6aff3f32a3b3baa426b6139c0b Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 21:50:49 +0200 Subject: [PATCH 104/138] simplified check --- lib/webfuse/provider/impl/provider.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/webfuse/provider/impl/provider.c b/lib/webfuse/provider/impl/provider.c index 14282d2..c9c159f 100644 --- a/lib/webfuse/provider/impl/provider.c +++ b/lib/webfuse/provider/impl/provider.c @@ -94,8 +94,7 @@ void wfp_impl_provider_invoke( json_t * params = json_object_get(request, "params"); json_t * id_holder = json_object_get(request, "id"); - if ((NULL != method_holder) && (json_is_string(method_holder)) && - (NULL != params) && (json_is_array(params))) + if ((json_is_string(method_holder)) && (json_is_array(params))) { char const * method = json_string_value(method_holder); int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0; From db536142de7692a307b82673a5026c9179f3d3b3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 22:21:41 +0200 Subject: [PATCH 105/138] fixed empty result --- lib/webfuse/provider/impl/operation/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webfuse/provider/impl/operation/read.c b/lib/webfuse/provider/impl/operation/read.c index 7be4bf3..5c2b639 100644 --- a/lib/webfuse/provider/impl/operation/read.c +++ b/lib/webfuse/provider/impl/operation/read.c @@ -70,7 +70,7 @@ void wfp_impl_respond_read( { json_t * result = json_object(); 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)); wfp_impl_respond(request, result); From d482f4dfe5963e66adb21ed41a31772fc361114e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 22:25:14 +0200 Subject: [PATCH 106/138] added test for wfp_impl_read --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_request.hpp | 26 +++ .../tests/provider/operation/test_read.cc | 173 ++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 test/webfuse/tests/provider/operation/test_read.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 2c271b5..156ee61 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -51,6 +51,7 @@ add_executable(alltests 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/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp index f286409..0582d6a 100644 --- a/test/webfuse/mocks/mock_request.hpp +++ b/test/webfuse/mocks/mock_request.hpp @@ -56,6 +56,32 @@ MATCHER_P(OpenMatcher, handle, "") return true; } +MATCHER_P3(ReadResultMatcher, data, format, count, "") +{ + json_t * format_holder = json_object_get(arg, "format"); + if ((!json_is_string(format_holder)) || (0 != strcmp(format, json_string_value(format_holder)))) + { + *result_listener << "invalid or missing format: " << json_string_value(format_holder); + return false; + } + + json_t * count_holder = json_object_get(arg, "count"); + if ((!json_is_integer(count_holder)) || (count != json_integer_value(count_holder))) + { + *result_listener << "invalid or missing count: " << json_integer_value(count_holder); + return false; + } + + json_t * data_holder = json_object_get(arg, "data"); + if ((!json_is_string(data_holder)) || (0 != strcmp(data, json_string_value(data_holder)))) + { + *result_listener << "invalid or missing data: " << json_string_value(data_holder); + return false; + } + + return true; +} + MATCHER_P(ReaddirMatcher, contained_elements , "") { if (!json_is_array(arg)) diff --git a/test/webfuse/tests/provider/operation/test_read.cc b/test/webfuse/tests/provider/operation/test_read.cc new file mode 100644 index 0000000..36bf14f --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_read.cc @@ -0,0 +1,173 @@ +#include "webfuse/provider/impl/operation/read.h" +#include "webfuse/mocks/mock_request.hpp" +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" + +#include +#include + +using ::webfuse_test::MockProvider; +using ::webfuse_test::MockRequest; +using ::webfuse_test::ReadResultMatcher; +using ::webfuse_test::create_context; +using ::testing::_; +using ::testing::Invoke; +using ::testing::StrEq; + +namespace +{ + +void free_request(wfp_request * request, ino_t, uint32_t, size_t ,size_t) +{ + free(request); +} + +} + +TEST(wfp_impl_read, invoke_provider) +{ + ino_t inode = 42; + uint32_t handle = 5; + size_t offset = 2; + size_t length = 1; + MockProvider provider; + EXPECT_CALL(provider, read(_, inode, handle, offset, length)).Times(1) + .WillOnce(Invoke(free_request)); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(inode)); + json_array_append_new(params, json_integer(handle)); + json_array_append_new(params, json_integer(offset)); + json_array_append_new(params, json_integer(length)); + + wfp_impl_read(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_read, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(1)); + json_array_append_new(params, json_integer(2)); + json_array_append_new(params, json_integer(3)); + json_array_append_new(params, json_integer(4)); + json_array_append_new(params, json_integer(5)); + + wfp_impl_read(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_read, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_string("42")); + json_array_append_new(params, json_integer(2)); + json_array_append_new(params, json_integer(3)); + json_array_append_new(params, json_integer(4)); + + wfp_impl_read(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_read, fail_invalid_handle_type) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(1)); + json_array_append_new(params, json_string("42")); + json_array_append_new(params, json_integer(3)); + json_array_append_new(params, json_integer(4)); + + wfp_impl_read(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_read, fail_invalid_offset_type) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(1)); + json_array_append_new(params, json_integer(2)); + json_array_append_new(params, json_string("42")); + json_array_append_new(params, json_integer(4)); + + wfp_impl_read(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_read, fail_invalid_length_type) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(1)); + json_array_append_new(params, json_integer(2)); + json_array_append_new(params, json_integer(3)); + json_array_append_new(params, json_string("42")); + + wfp_impl_read(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_read, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_read_default(req, 0, 0, 1, 2, nullptr); +} + +TEST(wfp_impl_read, respond) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(ReadResultMatcher("d2Y=", "base64", 2), 42)).Times(1); + + char const data[] = "wf"; + wfp_impl_respond_read(req, data, 2); +} + +TEST(wfp_impl_read, respond_empty) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(ReadResultMatcher("", "identity", 0), 42)).Times(1); + + wfp_impl_respond_read(req, nullptr, 0); +} From b2142ee963f96676a57642eceed6244423d86cb0 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 22:38:12 +0200 Subject: [PATCH 107/138] added tests for wfp_impl_readdir --- cmake/unit_tests.cmake | 1 + .../tests/provider/operation/test_readdir.cc | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/webfuse/tests/provider/operation/test_readdir.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 156ee61..b1d9b99 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -52,6 +52,7 @@ add_executable(alltests 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_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/tests/provider/operation/test_readdir.cc b/test/webfuse/tests/provider/operation/test_readdir.cc new file mode 100644 index 0000000..33557f5 --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_readdir.cc @@ -0,0 +1,100 @@ +#include "webfuse/provider/impl/operation/readdir.h" +#include "webfuse/mocks/mock_request.hpp" +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" +#include "webfuse/provider/dirbuffer.h" + +#include +#include + +using ::webfuse_test::MockProvider; +using ::webfuse_test::MockRequest; +using ::webfuse_test::ReaddirMatcher; +using ::webfuse_test::create_context; +using ::testing::_; +using ::testing::Invoke; + +namespace +{ + +void free_request(wfp_request * request, ino_t) +{ + free(request); +} + +} + +TEST(wfp_impl_readdir, invoke_provider) +{ + ino_t inode = 23; + MockProvider provider; + EXPECT_CALL(provider,readdir(_, inode)).Times(1).WillOnce(Invoke(free_request)); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(inode)); + + wfp_impl_readdir(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_readdir, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider,readdir(_, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_integer(1)); + json_array_append_new(params, json_integer(1)); + + wfp_impl_readdir(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_readdir, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider,readdir(_, _)).Times(0); + + wfp_request request = {nullptr, nullptr, 0}; + wfp_impl_invokation_context context = create_context(provider, &request); + + json_t * params = json_array(); + json_array_append_new(params, json_string("test.filesystem")); + json_array_append_new(params, json_string("1")); + + wfp_impl_readdir(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_readdir, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_readdir_default(req, 0, nullptr); +} + +TEST(wfp_impl_readdir, respond) +{ + char const item0[] = "some.file"; + char const * items[] = { item0, nullptr }; + + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(ReaddirMatcher(items), 42)).Times(1); + + wfp_dirbuffer * buffer = wfp_dirbuffer_create(); + wfp_dirbuffer_add(buffer, item0, 42); + wfp_impl_respond_readdir(req, buffer); + wfp_dirbuffer_dispose(buffer); + +} From c62b6edde21b0deeda6a48406f7c68bf1959c6a8 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 22:40:15 +0200 Subject: [PATCH 108/138] chore: simplified check --- lib/webfuse/provider/impl/operation/readdir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webfuse/provider/impl/operation/readdir.c b/lib/webfuse/provider/impl/operation/readdir.c index 4fc3db7..63d59c1 100644 --- a/lib/webfuse/provider/impl/operation/readdir.c +++ b/lib/webfuse/provider/impl/operation/readdir.c @@ -14,7 +14,7 @@ void wfp_impl_readdir( { 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); struct wfp_request * request = wfp_impl_request_create(context->request, id); From f8a402c3a1ed5069d6e5a032a9b4eecceadff8a7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Wed, 1 Apr 2020 21:42:50 +0200 Subject: [PATCH 109/138] use TLS in integration test --- cmake/unit_tests.cmake | 8 ++++++++ include/webfuse/provider/client_config.h | 13 +++++++++++++ lib/webfuse/provider/api.c | 7 +++++++ lib/webfuse/provider/impl/client.c | 5 ++++- lib/webfuse/provider/impl/client_config.c | 10 ++++++++++ lib/webfuse/provider/impl/client_config.h | 5 +++++ test/webfuse/tests/integration/provider.cc | 3 +++ test/webfuse/tests/integration/server.cc | 2 ++ test/webfuse/tests/integration/test_integration.cc | 2 +- 9 files changed, 53 insertions(+), 2 deletions(-) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index b1d9b99..31d3c12 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -81,6 +81,14 @@ target_link_libraries(alltests PUBLIC target_include_directories(alltests PUBLIC test lib ${FUSE3_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) 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() gtest_discover_tests(alltests TEST_PREFIX alltests:) diff --git a/include/webfuse/provider/client_config.h b/include/webfuse/provider/client_config.h index 0c79dd7..fe138f6 100644 --- a/include/webfuse/provider/client_config.h +++ b/include/webfuse/provider/client_config.h @@ -108,6 +108,19 @@ extern WFP_API void wfp_client_config_set_certpath( struct wfp_client_config * config, 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. /// diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 0704095..dc42fba 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -95,6 +95,13 @@ void wfp_client_config_set_certpath( 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( struct wfp_client_config * config, wfp_connected_fn * handler) diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index c3b432c..f10450f 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -43,7 +43,10 @@ struct wfp_client * wfp_impl_client_create( if ((NULL != config->cert_path) && (NULL != config->key_path)) { - + client->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + client->info.client_ssl_cert_filepath = config->cert_path; + client->info.client_ssl_private_key_filepath = config->key_path; + client->info.client_ssl_ca_filepath = config->ca_filepath; } client->context = lws_create_context(&client->info); diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c index 3bbb3ea..9e6489b 100644 --- a/lib/webfuse/provider/impl/client_config.c +++ b/lib/webfuse/provider/impl/client_config.c @@ -10,6 +10,7 @@ struct wfp_client_config * wfp_impl_client_config_create(void) config->user_data = NULL; config->key_path = NULL; config->cert_path = NULL; + config->ca_filepath = NULL; return config; } @@ -19,6 +20,7 @@ void wfp_impl_client_config_dispose( { free(config->key_path); free(config->cert_path); + free(config->ca_filepath); free(config); } @@ -45,6 +47,14 @@ void wfp_impl_client_config_set_certpath( 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( struct wfp_client_config * config, wfp_connected_fn * handler) diff --git a/lib/webfuse/provider/impl/client_config.h b/lib/webfuse/provider/impl/client_config.h index f8d5b9b..a15ff87 100644 --- a/lib/webfuse/provider/impl/client_config.h +++ b/lib/webfuse/provider/impl/client_config.h @@ -15,6 +15,7 @@ struct wfp_client_config void * user_data; char * key_path; char * cert_path; + char * ca_filepath; }; 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, 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( struct wfp_client_config * config, wfp_connected_fn * handler); diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index b1fa44d..e635c9b 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -19,6 +19,9 @@ public: : is_shutdown_requested(false) { config = wfp_client_config_create(); + wfp_client_config_set_certpath(config, "client-cert.pem"); + wfp_client_config_set_keypath(config, "client-key.pem"); + wfp_client_config_set_ca_filepath(config, "server-cert.pem"); fs = wfp_static_filesystem_create(config); wfp_static_filesystem_add_text(fs, "hello.txt", 0444, "Hello, World"); diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index 931f932..8f15161 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -63,6 +63,8 @@ public: wf_server_config_set_mountpoint_factory(config, &webfuse_test_server_create_mountpoint, reinterpret_cast(base_dir)); + wf_server_config_set_keypath(config, "server-key.pem"); + wf_server_config_set_certpath(config, "server-cert.pem"); server = wf_server_create(config); diff --git a/test/webfuse/tests/integration/test_integration.cc b/test/webfuse/tests/integration/test_integration.cc index 4cc2844..57c1a91 100644 --- a/test/webfuse/tests/integration/test_integration.cc +++ b/test/webfuse/tests/integration/test_integration.cc @@ -38,7 +38,7 @@ namespace void SetUp() { server = new Server(); - provider = new Provider("ws://localhost:8080/"); + provider = new Provider("wss://localhost:8080/"); } void TearDown() From 06c01995feb5553486df37caf3fce9121d377910 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 2 Apr 2020 19:34:52 +0200 Subject: [PATCH 110/138] removed unnecessary NULL check --- lib/webfuse/adapter/impl/session_manager.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/webfuse/adapter/impl/session_manager.c b/lib/webfuse/adapter/impl/session_manager.c index cc41fa0..a872d54 100644 --- a/lib/webfuse/adapter/impl/session_manager.c +++ b/lib/webfuse/adapter/impl/session_manager.c @@ -33,10 +33,7 @@ struct wf_impl_session * wf_impl_session_manager_add( { struct wf_impl_session * session = wf_impl_session_create( 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; } From 48e3575d6d95b2ea1fd52073cd4800be80ee3ce7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 2 Apr 2020 22:00:01 +0200 Subject: [PATCH 111/138] added integrative test of low level api --- cmake/unit_tests.cmake | 1 + lib/webfuse/adapter/impl/server_protocol.c | 7 +- .../tests/integration/test_lowlevel.cc | 112 ++++++++++++++++++ 3 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 test/webfuse/tests/integration/test_lowlevel.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 31d3c12..619afbe 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -53,6 +53,7 @@ add_executable(alltests 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/server.cc test/webfuse/tests/integration/provider.cc diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 7caf0bc..d97c9a8 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -23,13 +23,10 @@ static int wf_impl_server_protocol_callback( size_t len) { struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); - if (NULL == ws_protocol) - { - return 0; - } + if (NULL == ws_protocol) { return 0; } + if (ws_protocol->callback != &wf_impl_server_protocol_callback) { return 0; } struct wf_server_protocol * protocol = ws_protocol->user; - wf_timer_manager_check(protocol->timer_manager); struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi); diff --git a/test/webfuse/tests/integration/test_lowlevel.cc b/test/webfuse/tests/integration/test_lowlevel.cc new file mode 100644 index 0000000..050b23a --- /dev/null +++ b/test/webfuse/tests/integration/test_lowlevel.cc @@ -0,0 +1,112 @@ +#include "webfuse_adapter.h" +#include "webfuse_provider.h" +#include + +#include "webfuse/utils/tempdir.hpp" + +#include + +using ::webfuse_test::TempDir; + +extern "C" +{ + +wf_mountpoint * +wf_test_integration_lowlevel_create_mountpoint( + char const *, void * user_data) +{ + auto * tempDir = reinterpret_cast(user_data); + return wf_mountpoint_create(tempDir->path()); +} + +void +wf_test_integration_lowlevel_on_connected( + void * user_data) +{ + int * state = reinterpret_cast(user_data); + *state = 1; +} + +void +wf_test_integration_lowlevel_on_disconnected( + void * user_data) +{ + int * state = reinterpret_cast(user_data); + *state = -1; +} + +bool +wf_test_integration_lowlevel_authenticate( + struct wf_credentials * credentials, + void * ) +{ + char const * username = wf_credentials_get(credentials, "username"); + char const * password = wf_credentials_get(credentials, "password"); + + return ((0 == strcmp(username, "bob")) && (0 == strcmp(password, "secret"))); +} + +void +wf_test_integration_lowlevel_get_credentials( + struct wfp_credentials * credentials, + void * ) +{ + wfp_credentials_set_type(credentials, "username"); + wfp_credentials_add(credentials, "username", "bob"); + wfp_credentials_add(credentials, "password", "secret"); +} + +} + +TEST(integration, lowlevel) +{ + TempDir dir("wf_test"); + + wf_server_protocol * server_protocol = wf_server_protocol_create( + &wf_test_integration_lowlevel_create_mountpoint, + reinterpret_cast(&dir)); + ASSERT_NE(nullptr, server_protocol); + wf_server_protocol_add_authenticator(server_protocol, "username", + &wf_test_integration_lowlevel_authenticate, nullptr); + + int state = 0; + wfp_client_config * client_config = wfp_client_config_create(); + ASSERT_NE(nullptr, client_config); + wfp_client_config_set_userdata(client_config, reinterpret_cast(&state)); + wfp_client_config_set_onconnected(client_config, &wf_test_integration_lowlevel_on_connected); + wfp_client_config_set_ondisconnected(client_config, &wf_test_integration_lowlevel_on_disconnected); + wfp_client_config_enable_authentication(client_config, &wf_test_integration_lowlevel_get_credentials); + + wfp_client_protocol * client_protocol = wfp_client_protocol_create(client_config); + ASSERT_NE(nullptr, client_protocol); + + lws_protocols protocols[3]; + memset(protocols, 0, 3 * sizeof(lws_protocols)); + wf_server_protocol_init_lws(server_protocol, &protocols[0]); + wfp_client_protocol_init_lws(client_protocol, &protocols[1]); + + lws_context_creation_info info; + memset(&info, 0, sizeof(info)); + info.port = 8080; + info.protocols = protocols; + info.vhost_name = "localhost"; + info.ws_ping_pong_interval = 10; + info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + + struct lws_context * context = lws_create_context(&info); + ASSERT_NE(nullptr, context); + + wfp_client_protocol_connect(client_protocol, context, "ws://localhost:8080/"); + while (0 == state) + { + lws_service(context, 0); + } + + EXPECT_EQ(1, state); + + lws_context_destroy(context); + + wfp_client_protocol_dispose(client_protocol); + wfp_client_config_dispose(client_config); + wf_server_protocol_dispose(server_protocol); +} \ No newline at end of file From d56bbcbd3965af19554338085d1772ee13b3c5a6 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 3 Apr 2020 22:46:47 +0200 Subject: [PATCH 112/138] added test for open (adapter) --- cmake/unit_tests.cmake | 5 ++++ lib/webfuse/adapter/impl/operation/open.c | 2 +- test/webfuse/mocks/mock_fuse.cc | 28 +++++++++++++++++++ test/webfuse/mocks/mock_fuse.hpp | 19 +++++++++++++ .../tests/adapter/operation/test_open.cc | 28 +++++++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/webfuse/mocks/mock_fuse.cc create mode 100644 test/webfuse/mocks/mock_fuse.hpp create mode 100644 test/webfuse/tests/adapter/operation/test_open.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 619afbe..06d510d 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -30,6 +30,7 @@ add_executable(alltests test/webfuse/mocks/mock_request.cc test/webfuse/mocks/mock_provider_client.cc test/webfuse/mocks/mock_provider.cc + test/webfuse/mocks/mock_fuse.cc test/webfuse//tests/core/test_util.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc @@ -45,6 +46,7 @@ add_executable(alltests test/webfuse/tests/adapter/test_authenticators.cc test/webfuse/tests/adapter/test_mountpoint.cc test/webfuse/tests/adapter/test_fuse_req.cc + test/webfuse/tests/adapter/operation/test_open.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -67,6 +69,9 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_dispose -Wl,--wrap=wf_timer_start -Wl,--wrap=wf_timer_cancel + -Wl,--wrap=fuse_req_userdata + -Wl,--wrap=fuse_reply_open + -Wl,--wrap=fuse_reply_err webfuse-adapter-static webfuse-provider-static diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 8e21100..07d8ea9 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -22,7 +22,7 @@ static void wf_impl_operation_open_finished( if (NULL != result) { 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); } diff --git a/test/webfuse/mocks/mock_fuse.cc b/test/webfuse/mocks/mock_fuse.cc new file mode 100644 index 0000000..fa2f981 --- /dev/null +++ b/test/webfuse/mocks/mock_fuse.cc @@ -0,0 +1,28 @@ +#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); + +} + +namespace webfuse_test +{ + +FuseMock::FuseMock() +{ + webfuse_test_FuseMock = this; +} + +FuseMock::~FuseMock() +{ + webfuse_test_FuseMock = nullptr; +} + + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp new file mode 100644 index 0000000..ed6e6ff --- /dev/null +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -0,0 +1,19 @@ +#include "webfuse/adapter/impl/fuse_wrapper.h" +#include + +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)); +}; + + +} \ No newline at end of file diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc new file mode 100644 index 0000000..d1b5960 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -0,0 +1,28 @@ +#include "webfuse/adapter/impl/operations.h" +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/adapter/impl/session.h" + +#include + +using webfuse_test::FuseMock; +using testing::_; +using testing::Return; + +TEST(wf_impl_operation_open, fail_rpc_null) +{ + wf_impl_session session; + memset(&session, 0, sizeof(session)); + wf_impl_operations_context context = + {&session, 1.0f, nullptr }; + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&context))); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1) + .WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info * file_info = nullptr; + wf_impl_operation_open(request, inode, file_info); +} \ No newline at end of file From 77a870b9b78fed97627c92a56190202a225c3580 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 08:32:26 +0200 Subject: [PATCH 113/138] added unit tests for open (adapter) --- cmake/unit_tests.cmake | 4 + cmake/webfuse_core.cmake | 1 + lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/open.c | 10 +- lib/webfuse/adapter/impl/operation/open.h | 26 ++++++ lib/webfuse/adapter/impl/operations.h | 5 - lib/webfuse/core/jsonrpc/proxy.c | 8 +- lib/webfuse/core/jsonrpc/proxy_intern.h | 8 ++ lib/webfuse/core/jsonrpc/proxy_invoke.c | 15 +++ test/webfuse/mocks/mock_fuse.hpp | 6 +- test/webfuse/mocks/mock_jsonrpc_proxy.cc | 30 ++++++ test/webfuse/mocks/mock_jsonrpc_proxy.hpp | 27 ++++++ test/webfuse/mocks/mock_operations_context.cc | 27 ++++++ .../webfuse/mocks/mock_operations_context.hpp | 22 +++++ .../tests/adapter/operation/test_open.cc | 93 +++++++++++++++++-- test/webfuse/utils/wrap.hpp | 28 ++++++ 16 files changed, 284 insertions(+), 27 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/open.h create mode 100644 lib/webfuse/core/jsonrpc/proxy_invoke.c create mode 100644 test/webfuse/mocks/mock_jsonrpc_proxy.cc create mode 100644 test/webfuse/mocks/mock_jsonrpc_proxy.hpp create mode 100644 test/webfuse/mocks/mock_operations_context.cc create mode 100644 test/webfuse/mocks/mock_operations_context.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 06d510d..4934a05 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -31,6 +31,8 @@ add_executable(alltests test/webfuse/mocks/mock_provider_client.cc test/webfuse/mocks/mock_provider.cc test/webfuse/mocks/mock_fuse.cc + test/webfuse/mocks/mock_operations_context.cc + test/webfuse/mocks/mock_jsonrpc_proxy.cc test/webfuse//tests/core/test_util.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc @@ -69,6 +71,8 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_dispose -Wl,--wrap=wf_timer_start -Wl,--wrap=wf_timer_cancel + -Wl,--wrap=wf_impl_operations_context_get_proxy + -Wl,--wrap=wf_jsonrpc_proxy_vinvoke -Wl,--wrap=fuse_req_userdata -Wl,--wrap=fuse_reply_open -Wl,--wrap=fuse_reply_err diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index fb25b75..3dfa958 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -13,6 +13,7 @@ add_library(webfuse-core STATIC lib/webfuse/core/timer/timepoint.c lib/webfuse/core/timer/timer.c lib/webfuse/core/jsonrpc/proxy.c + lib/webfuse/core/jsonrpc/proxy_invoke.c lib/webfuse/core/jsonrpc/server.c lib/webfuse/core/jsonrpc/method.c lib/webfuse/core/jsonrpc/request.c diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index b7966a1..67fef92 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -1,5 +1,6 @@ #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 07d8ea9..630e9c8 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -1,15 +1,15 @@ +#include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/operations.h" -#include -#include -#include - #include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/status.h" #include "webfuse/core/json_util.h" -static void wf_impl_operation_open_finished( +#include +#include + +void wf_impl_operation_open_finished( void * user_data, json_t const * result, json_t const * error) diff --git a/lib/webfuse/adapter/impl/operation/open.h b/lib/webfuse/adapter/impl/operation/open.h new file mode 100644 index 0000000..eb40490 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/open.h @@ -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 + +#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 diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index 4d23db2..162ee15 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -34,11 +34,6 @@ extern void wf_impl_operation_readdir ( 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, diff --git a/lib/webfuse/core/jsonrpc/proxy.c b/lib/webfuse/core/jsonrpc/proxy.c index 67fd6d8..90a9d56 100644 --- a/lib/webfuse/core/jsonrpc/proxy.c +++ b/lib/webfuse/core/jsonrpc/proxy.c @@ -133,14 +133,13 @@ void wf_jsonrpc_proxy_cleanup( wf_timer_dispose(proxy->request.timer); } -void wf_jsonrpc_proxy_invoke( +void wf_jsonrpc_proxy_vinvoke( 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) { if (!proxy->request.is_pending) { @@ -150,10 +149,7 @@ void wf_jsonrpc_proxy_invoke( proxy->request.id = 42; wf_timer_start(proxy->request.timer, proxy->timeout); - va_list args; - va_start(args, param_info); json_t * request = wf_jsonrpc_request_create(method_name, proxy->request.id, param_info, args); - va_end(args); bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data))); if (!is_send) diff --git a/lib/webfuse/core/jsonrpc/proxy_intern.h b/lib/webfuse/core/jsonrpc/proxy_intern.h index 3186e14..920bd56 100644 --- a/lib/webfuse/core/jsonrpc/proxy_intern.h +++ b/lib/webfuse/core/jsonrpc/proxy_intern.h @@ -41,6 +41,14 @@ extern void wf_jsonrpc_proxy_cleanup( struct wf_jsonrpc_proxy * proxy); +extern void wf_jsonrpc_proxy_vinvoke( + 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); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/core/jsonrpc/proxy_invoke.c b/lib/webfuse/core/jsonrpc/proxy_invoke.c new file mode 100644 index 0000000..ada6b9e --- /dev/null +++ b/lib/webfuse/core/jsonrpc/proxy_invoke.c @@ -0,0 +1,15 @@ +#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); +} diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp index ed6e6ff..07bcb60 100644 --- a/test/webfuse/mocks/mock_fuse.hpp +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -1,3 +1,6 @@ +#ifndef MOCK_FUSE_HPP +#define MOCK_FUSE_HPP + #include "webfuse/adapter/impl/fuse_wrapper.h" #include @@ -15,5 +18,6 @@ public: MOCK_METHOD2(fuse_reply_err, int (fuse_req_t req, int err)); }; +} -} \ No newline at end of file +#endif diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.cc b/test/webfuse/mocks/mock_jsonrpc_proxy.cc new file mode 100644 index 0000000..569dfa8 --- /dev/null +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.cc @@ -0,0 +1,30 @@ +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" +#include "webfuse/utils/wrap.hpp" + +extern "C" +{ +static webfuse_test::MockJsonRpcProxy * webfuse_test_MockJsonRpcProxy = nullptr; + +WF_WRAP_FUNC6(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke, + struct wf_jsonrpc_proxy *, + wf_jsonrpc_proxy_finished_fn *, + void *, + char const *, + char const *, + va_list); +} + +namespace webfuse_test +{ + +MockJsonRpcProxy::MockJsonRpcProxy() +{ + webfuse_test_MockJsonRpcProxy = this; +} + +MockJsonRpcProxy::~MockJsonRpcProxy() +{ + webfuse_test_MockJsonRpcProxy = nullptr; +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp new file mode 100644 index 0000000..97a1b1b --- /dev/null +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp @@ -0,0 +1,27 @@ +#ifndef MOCK_JSONRPC_PROXY_HPP +#define MOCK_JSONRPC_PROXY_HPP + +#include "webfuse/core/jsonrpc/proxy_intern.h" +#include + +namespace webfuse_test +{ + +class MockJsonRpcProxy +{ +public: + MockJsonRpcProxy(); + virtual ~MockJsonRpcProxy(); + MOCK_METHOD6(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, + va_list args)); + +}; + +} + +#endif diff --git a/test/webfuse/mocks/mock_operations_context.cc b/test/webfuse/mocks/mock_operations_context.cc new file mode 100644 index 0000000..89498f7 --- /dev/null +++ b/test/webfuse/mocks/mock_operations_context.cc @@ -0,0 +1,27 @@ +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/utils/wrap.hpp" + +extern "C" +{ +static webfuse_test::MockOperationsContext * webfuse_test_MockOperationsContext = nullptr; + +WF_WRAP_FUNC1(webfuse_test_MockOperationsContext, + struct wf_jsonrpc_proxy *, wf_impl_operations_context_get_proxy, + struct wf_impl_operations_context *); + +} + +namespace webfuse_test +{ + +MockOperationsContext::MockOperationsContext() +{ + webfuse_test_MockOperationsContext = this; +} + +MockOperationsContext::~MockOperationsContext() +{ + webfuse_test_MockOperationsContext = nullptr; +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_operations_context.hpp b/test/webfuse/mocks/mock_operations_context.hpp new file mode 100644 index 0000000..a12aa7b --- /dev/null +++ b/test/webfuse/mocks/mock_operations_context.hpp @@ -0,0 +1,22 @@ +#ifndef MOCK_OPERATIONS_CONTEXT_HPP +#define MOCK_OPERATIONS_CONTEXT_HPP + +#include "webfuse/adapter/impl/operations.h" +#include + +namespace webfuse_test +{ + +class MockOperationsContext +{ +public: + MockOperationsContext(); + virtual ~MockOperationsContext(); + MOCK_METHOD1(wf_impl_operations_context_get_proxy, wf_jsonrpc_proxy * ( + struct wf_impl_operations_context * context)); + +}; + +} + +#endif diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc index d1b5960..e7e5ca4 100644 --- a/test/webfuse/tests/adapter/operation/test_open.cc +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -1,28 +1,101 @@ +#include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/operations.h" + +#include "webfuse/core/status.h" + #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/adapter/impl/session.h" +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include +using webfuse_test::MockJsonRpcProxy; +using webfuse_test::MockOperationsContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; +using testing::StrEq; + +TEST(wf_impl_operation_open, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"),_)).Times(1); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&proxy))); + + wf_impl_operations_context op_context; + op_context.name = nullptr; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info file_info; + file_info.flags = 0; + wf_impl_operation_open(request, inode, &file_info); +} TEST(wf_impl_operation_open, fail_rpc_null) { - wf_impl_session session; - memset(&session, 0, sizeof(session)); - wf_impl_operations_context context = - {&session, 1.0f, nullptr }; + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); FuseMock fuse; - EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1) - .WillOnce(Return(reinterpret_cast(&context))); - EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1) - .WillOnce(Return(0)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); fuse_req_t request = nullptr; fuse_ino_t inode = 1; fuse_file_info * file_info = nullptr; wf_impl_operation_open(request, inode, file_info); -} \ No newline at end of file +} + +TEST(wf_impl_operation_open, finished) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "handle", json_integer(42)); + wf_impl_operation_open_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_open, finished_fail_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + wf_impl_operation_open_finished(nullptr, nullptr, error); + json_decref(error); +} + +TEST(wf_impl_operation_open, finished_fail_no_handle) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + wf_impl_operation_open_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_open, finished_fail_invalid_handle_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "handle", json_string("42")); + wf_impl_operation_open_finished(nullptr, result, nullptr); + json_decref(result); +} diff --git a/test/webfuse/utils/wrap.hpp b/test/webfuse/utils/wrap.hpp index 9d062d8..4402598 100644 --- a/test/webfuse/utils/wrap.hpp +++ b/test/webfuse/utils/wrap.hpp @@ -71,4 +71,32 @@ } \ } +#define WF_WRAP_FUNC5( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4, arg5); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4, arg5); \ + } \ + } + +#define WF_WRAP_FUNC6( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, ARG6_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, ARG6_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5, ARG6_TYPE arg6) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4, arg5, arg6); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4, arg5, arg6); \ + } \ + } + #endif From 289264e2691f39ddb20afc75cd386551eb715741 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 08:55:59 +0200 Subject: [PATCH 114/138] added unit tests for close operation (adapter) --- cmake/unit_tests.cmake | 2 + cmake/webfuse_core.cmake | 2 +- lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/close.h | 20 +++++++ lib/webfuse/adapter/impl/operations.h | 5 -- lib/webfuse/core/jsonrpc/proxy.c | 8 +-- lib/webfuse/core/jsonrpc/proxy_intern.h | 6 ++ .../{proxy_invoke.c => proxy_variadic.c} | 13 +++++ test/webfuse/mocks/mock_jsonrpc_proxy.cc | 6 ++ test/webfuse/mocks/mock_jsonrpc_proxy.hpp | 5 ++ .../tests/adapter/operation/test_close.cc | 56 +++++++++++++++++++ 11 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/close.h rename lib/webfuse/core/jsonrpc/{proxy_invoke.c => proxy_variadic.c} (59%) create mode 100644 test/webfuse/tests/adapter/operation/test_close.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 4934a05..1ba7e5a 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -49,6 +49,7 @@ add_executable(alltests test/webfuse/tests/adapter/test_mountpoint.cc test/webfuse/tests/adapter/test_fuse_req.cc test/webfuse/tests/adapter/operation/test_open.cc + test/webfuse/tests/adapter/operation/test_close.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -73,6 +74,7 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_cancel -Wl,--wrap=wf_impl_operations_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 diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 3dfa958..c0b1b88 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -13,7 +13,7 @@ add_library(webfuse-core STATIC lib/webfuse/core/timer/timepoint.c lib/webfuse/core/timer/timer.c lib/webfuse/core/jsonrpc/proxy.c - lib/webfuse/core/jsonrpc/proxy_invoke.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 diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 67fef92..da9c87b 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -1,6 +1,7 @@ #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/adapter/impl/operations.h" #include "webfuse/adapter/impl/operation/open.h" +#include "webfuse/adapter/impl/operation/close.h" #include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/close.h b/lib/webfuse/adapter/impl/operation/close.h new file mode 100644 index 0000000..d254f67 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/close.h @@ -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 diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index 162ee15..01808bc 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -34,11 +34,6 @@ extern void wf_impl_operation_readdir ( off_t offset, 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, diff --git a/lib/webfuse/core/jsonrpc/proxy.c b/lib/webfuse/core/jsonrpc/proxy.c index 90a9d56..ee5fc0d 100644 --- a/lib/webfuse/core/jsonrpc/proxy.c +++ b/lib/webfuse/core/jsonrpc/proxy.c @@ -174,17 +174,13 @@ void wf_jsonrpc_proxy_vinvoke( } } -extern void wf_jsonrpc_proxy_notify( +extern void wf_jsonrpc_proxy_vnotify( struct wf_jsonrpc_proxy * proxy, char const * method_name, char const * param_info, - ... -) + va_list args) { - va_list args; - va_start(args, param_info); json_t * request = wf_jsonrpc_request_create(method_name, 0, param_info, args); - va_end(args); if (NULL != request) { diff --git a/lib/webfuse/core/jsonrpc/proxy_intern.h b/lib/webfuse/core/jsonrpc/proxy_intern.h index 920bd56..fd284a0 100644 --- a/lib/webfuse/core/jsonrpc/proxy_intern.h +++ b/lib/webfuse/core/jsonrpc/proxy_intern.h @@ -49,6 +49,12 @@ extern void wf_jsonrpc_proxy_vinvoke( char const * param_info, va_list args); +extern void wf_jsonrpc_proxy_vnotify( + struct wf_jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + va_list args); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/core/jsonrpc/proxy_invoke.c b/lib/webfuse/core/jsonrpc/proxy_variadic.c similarity index 59% rename from lib/webfuse/core/jsonrpc/proxy_invoke.c rename to lib/webfuse/core/jsonrpc/proxy_variadic.c index ada6b9e..2447511 100644 --- a/lib/webfuse/core/jsonrpc/proxy_invoke.c +++ b/lib/webfuse/core/jsonrpc/proxy_variadic.c @@ -13,3 +13,16 @@ void wf_jsonrpc_proxy_invoke( 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); +} diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.cc b/test/webfuse/mocks/mock_jsonrpc_proxy.cc index 569dfa8..3cb0a8e 100644 --- a/test/webfuse/mocks/mock_jsonrpc_proxy.cc +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.cc @@ -12,6 +12,12 @@ WF_WRAP_FUNC6(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke, char const *, char const *, va_list); + +WF_WRAP_FUNC4(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify, + struct wf_jsonrpc_proxy *, + char const *, + char const *, + va_list); } namespace webfuse_test diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp index 97a1b1b..fc39e1f 100644 --- a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp @@ -19,6 +19,11 @@ public: char const * method_name, char const * param_info, va_list args)); + MOCK_METHOD4(wf_jsonrpc_proxy_vnotify, void ( + struct wf_jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + va_list args)); }; diff --git a/test/webfuse/tests/adapter/operation/test_close.cc b/test/webfuse/tests/adapter/operation/test_close.cc new file mode 100644 index 0000000..b7a7a9b --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_close.cc @@ -0,0 +1,56 @@ +#include "webfuse/adapter/impl/operation/close.h" +#include + +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" + +#include + +using webfuse_test::MockJsonRpcProxy; +using webfuse_test::MockOperationsContext; +using webfuse_test::FuseMock; +using testing::_; +using testing::Return; +using testing::StrEq; + +TEST(wf_impl_operation_close, notify_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,StrEq("close"),StrEq("siii"),_)).Times(1); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&proxy))); + + wf_impl_operations_context op_context; + op_context.name = nullptr; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + EXPECT_CALL(fuse, fuse_reply_err(_, 0)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info file_info; + file_info.flags = 0; + wf_impl_operation_close(request, inode, &file_info); +} + +TEST(wf_impl_operation_close, fail_rpc_null) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_,_)).Times(0); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, 0)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info * file_info = nullptr; + wf_impl_operation_close(request, inode, file_info); +} From bfd4d43dee6358f11cba44cf0554371524c34fd7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 12:49:02 +0200 Subject: [PATCH 115/138] fix: compile error on arm targets --- test/webfuse/mocks/mock_jsonrpc_proxy.cc | 10 +++---- test/webfuse/mocks/mock_jsonrpc_proxy.hpp | 10 +++---- .../tests/adapter/operation/test_close.cc | 4 +-- .../tests/adapter/operation/test_open.cc | 2 +- test/webfuse/utils/wrap.hpp | 30 +++++++++++++++++++ 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.cc b/test/webfuse/mocks/mock_jsonrpc_proxy.cc index 3cb0a8e..3fb243e 100644 --- a/test/webfuse/mocks/mock_jsonrpc_proxy.cc +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.cc @@ -5,19 +5,17 @@ extern "C" { static webfuse_test::MockJsonRpcProxy * webfuse_test_MockJsonRpcProxy = nullptr; -WF_WRAP_FUNC6(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke, +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 *, - va_list); + char const *); -WF_WRAP_FUNC4(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify, +WF_WRAP_VFUNC3(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify, struct wf_jsonrpc_proxy *, char const *, - char const *, - va_list); + char const *); } namespace webfuse_test diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp index fc39e1f..74d61af 100644 --- a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp @@ -12,18 +12,16 @@ class MockJsonRpcProxy public: MockJsonRpcProxy(); virtual ~MockJsonRpcProxy(); - MOCK_METHOD6(wf_jsonrpc_proxy_vinvoke, void ( + 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, - va_list args)); - MOCK_METHOD4(wf_jsonrpc_proxy_vnotify, void ( + char const * param_info)); + MOCK_METHOD3(wf_jsonrpc_proxy_vnotify, void ( struct wf_jsonrpc_proxy * proxy, char const * method_name, - char const * param_info, - va_list args)); + char const * param_info)); }; diff --git a/test/webfuse/tests/adapter/operation/test_close.cc b/test/webfuse/tests/adapter/operation/test_close.cc index b7a7a9b..885e3bb 100644 --- a/test/webfuse/tests/adapter/operation/test_close.cc +++ b/test/webfuse/tests/adapter/operation/test_close.cc @@ -17,7 +17,7 @@ using testing::StrEq; TEST(wf_impl_operation_close, notify_proxy) { MockJsonRpcProxy proxy; - EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,StrEq("close"),StrEq("siii"),_)).Times(1); + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,StrEq("close"),StrEq("siii"))).Times(1); MockOperationsContext context; EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) @@ -39,7 +39,7 @@ TEST(wf_impl_operation_close, notify_proxy) TEST(wf_impl_operation_close, fail_rpc_null) { MockJsonRpcProxy proxy; - EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_,_)).Times(0); + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_)).Times(0); MockOperationsContext context; EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc index e7e5ca4..f82e81e 100644 --- a/test/webfuse/tests/adapter/operation/test_open.cc +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -19,7 +19,7 @@ using testing::StrEq; TEST(wf_impl_operation_open, invoke_proxy) { MockJsonRpcProxy proxy; - EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"),_)).Times(1); + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"))).Times(1); MockOperationsContext context; EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) diff --git a/test/webfuse/utils/wrap.hpp b/test/webfuse/utils/wrap.hpp index 4402598..30694de 100644 --- a/test/webfuse/utils/wrap.hpp +++ b/test/webfuse/utils/wrap.hpp @@ -99,4 +99,34 @@ } \ } + +#define WF_WRAP_VFUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, va_list); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, va_list args) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, args); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3); \ + } \ + } + +#define WF_WRAP_VFUNC5( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, va_list); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5, va_list args) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4, arg5, args); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4, arg5); \ + } \ + } + + #endif From ac09ee9c2fc23a4a8f57092b865b26dd26dbeb63 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 12:51:26 +0200 Subject: [PATCH 116/138] disabled build of libfuse examples --- build/amd64-ubuntu-builder.dockerfile | 1 + build/arm32v7-ubuntu-builder.dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index 7f5cc46..cbdc241 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -58,6 +58,7 @@ RUN set -x \ && mkdir -p "$builddir" \ && cd "$builddir" \ && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && meson configure -Dexamples=false \ && ninja \ && ninja install \ && pip3 uninstall -y meson \ diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index a84a8e3..a9da298 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -61,6 +61,7 @@ RUN set -x \ && mkdir -p "$builddir" \ && cd "$builddir" \ && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && meson configure -Dexamples=false \ && ninja \ && ninja install \ && pip3 uninstall -y meson \ From e00050073549038c6a50885a7581d19f25c89ac2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 15:41:33 +0200 Subject: [PATCH 117/138] added unit tests for read operation (adapter); did some hardening --- cmake/unit_tests.cmake | 2 + lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/read.c | 30 ++- lib/webfuse/adapter/impl/operation/read.h | 36 +++ lib/webfuse/adapter/impl/operations.h | 5 - test/webfuse/mocks/mock_fuse.cc | 1 + test/webfuse/mocks/mock_fuse.hpp | 1 + .../tests/adapter/operation/test_read.cc | 237 ++++++++++++++++++ 8 files changed, 303 insertions(+), 10 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/read.h create mode 100644 test/webfuse/tests/adapter/operation/test_read.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1ba7e5a..2b2d445 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -50,6 +50,7 @@ add_executable(alltests test/webfuse/tests/adapter/test_fuse_req.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/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -78,6 +79,7 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=fuse_req_userdata -Wl,--wrap=fuse_reply_open -Wl,--wrap=fuse_reply_err + -Wl,--wrap=fuse_reply_buf webfuse-adapter-static webfuse-provider-static diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index da9c87b..66ee76c 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -2,6 +2,7 @@ #include "webfuse/adapter/impl/operations.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/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 7896b30..59c3180 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -1,3 +1,4 @@ +#include "webfuse/adapter/impl/operation/read.h" #include "webfuse/adapter/impl/operations.h" #include @@ -11,8 +12,9 @@ #define WF_MAX_READ_LENGTH 4096 -static char * wf_impl_fill_buffer( +char * wf_impl_fill_buffer( char const * data, + size_t data_size, char const * format, size_t count, wf_status * status) @@ -24,11 +26,22 @@ static char * wf_impl_fill_buffer( { 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)) { - 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 { @@ -36,10 +49,16 @@ static char * wf_impl_fill_buffer( } } + if (WF_GOOD != *status) + { + free(buffer); + buffer = NULL; + } + return buffer; } -static void wf_impl_operation_read_finished( +void wf_impl_operation_read_finished( void * user_data, json_t const * result, json_t const * error) @@ -60,10 +79,11 @@ static void wf_impl_operation_read_finished( json_is_integer(count_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); 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 { diff --git a/lib/webfuse/adapter/impl/operation/read.h b/lib/webfuse/adapter/impl/operation/read.h new file mode 100644 index 0000000..89228b0 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/read.h @@ -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 + +#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 diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index 01808bc..6217de7 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -34,11 +34,6 @@ extern void wf_impl_operation_readdir ( off_t offset, 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); diff --git a/test/webfuse/mocks/mock_fuse.cc b/test/webfuse/mocks/mock_fuse.cc index fa2f981..1cf6aa1 100644 --- a/test/webfuse/mocks/mock_fuse.cc +++ b/test/webfuse/mocks/mock_fuse.cc @@ -8,6 +8,7 @@ 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); } diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp index 07bcb60..1b81e71 100644 --- a/test/webfuse/mocks/mock_fuse.hpp +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -16,6 +16,7 @@ public: 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)); }; } diff --git a/test/webfuse/tests/adapter/operation/test_read.cc b/test/webfuse/tests/adapter/operation/test_read.cc new file mode 100644 index 0000000..85fcf34 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_read.cc @@ -0,0 +1,237 @@ +#include "webfuse/adapter/impl/operation/read.h" +#include "webfuse/adapter/impl/operations.h" + +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" + +#include + +using webfuse_test::MockJsonRpcProxy; +using webfuse_test::MockOperationsContext; +using webfuse_test::FuseMock; +using testing::_; +using testing::Return; +using testing::StrEq; + +TEST(wf_impl_operation_read, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&proxy))); + + wf_impl_operations_context op_context; + op_context.name = nullptr; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 42; + off_t offset = 0; + fuse_file_info file_info; + file_info.fh = 1; + wf_impl_operation_read(request, inode, size, offset, &file_info); +} + +TEST(wf_impl_operation_read, invoke_proxy_limit_size) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&proxy))); + + wf_impl_operations_context op_context; + op_context.name = nullptr; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 100 * 1024 * 1024; + off_t offset = 0; + fuse_file_info file_info; + file_info.fh = 1; + wf_impl_operation_read(request, inode, size, offset, &file_info); +} + +TEST(wf_impl_operation_read, fail_rpc_null) +{ + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 42; + off_t offset = 0; + fuse_file_info * file_info = nullptr; + wf_impl_operation_read(request, inode, size, offset, file_info); +} + +TEST(wf_impl_operation_read, fill_buffer_identity) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("brummni", 8, "identity", 8, &status); + ASSERT_EQ(WF_GOOD, status); + ASSERT_STREQ("brummni", buffer); + free(buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_identity_fail_inconsistent_size) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("brummni", 8, "identity", 7, &status); + ASSERT_NE(WF_GOOD, status); + ASSERT_EQ(nullptr, buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_base64) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("YnJ1bW1uaQ==", 12, "base64", 7, &status); + + ASSERT_EQ(WF_GOOD, status); + ASSERT_EQ(0, strncmp("brummni", buffer, 7)); + free(buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_base64_fail_invalid_data) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("YnJ1bW1uaQ=A", 12, "base64", 8, &status); + ASSERT_NE(WF_GOOD, status); + ASSERT_EQ(nullptr, buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_empty) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer(nullptr, 0, "identity", 0, &status); + + ASSERT_EQ(WF_GOOD, status); + free(buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_fail_invalid_format) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("some data", 9, "unknown", 9, &status); + ASSERT_NE(WF_GOOD, status); + ASSERT_EQ(nullptr, buffer); +} + +TEST(wf_impl_operation_read, finished) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,7)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "format", json_string("identity")); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_no_data) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "format", json_string("identity")); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_invalid_data_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_integer(42)); + json_object_set_new(result, "format", json_string("identity")); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_no_format) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_invalid_format_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "format", json_integer(42)); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_no_count) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "format", json_string("identity")); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_invalid_count_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "format", json_string("identity")); + json_object_set_new(result, "count", json_string("7")); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + wf_impl_operation_read_finished(nullptr, nullptr, error); + json_decref(error); +} From a532197e245657454177703c9525fb4b45536a2d Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 16:56:20 +0200 Subject: [PATCH 118/138] added alpine build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ceddb6c..1af60eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ env: - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check + - BUILDTYPE=Debug MARCH=amd54 CHECK_TARGET=check DISTRO=alpine before_script: - make BUILDTYPE=$BUILDTYPE MARCH=$MARCH script: From 7b78194cb3aaee49860138042cfdd690183be3e2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 17:18:24 +0200 Subject: [PATCH 119/138] specify distro for make --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1af60eb..cff549d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,6 @@ env: before_script: - make BUILDTYPE=$BUILDTYPE MARCH=$MARCH script: -- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET +- make DISTRO=$DISTRO BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET after_success: - bash <(curl -s https://codecov.io/bash) From 9095fbc1b7a1e978185d4c51a41c26fb66f5c14f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 17:45:48 +0200 Subject: [PATCH 120/138] fixed alpine build --- .travis.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index cff549d..ae18a7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,16 +12,15 @@ addons: - qemu-user-static env: global: - - DISTRO=ubuntu - PARALLELMFLAGS="-j4" - PORTABLE_WORSPACE=1 matrix: - - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=check - - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check - - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check - - BUILDTYPE=Debug MARCH=amd54 CHECK_TARGET=check DISTRO=alpine + - DISTRO=ubuntu BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck + - DISTRO=ubuntu BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=check + - DISTRO=ubuntu BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck + - DISTRO=ubuntu BUILDTYPE=Debug 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: - make BUILDTYPE=$BUILDTYPE MARCH=$MARCH script: From 98e02240e9d01b9f6f359a2123505b19189e005e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 18:20:45 +0200 Subject: [PATCH 121/138] fixed memory leak --- test/webfuse/tests/provider/operation/test_open.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/webfuse/tests/provider/operation/test_open.cc b/test/webfuse/tests/provider/operation/test_open.cc index 68a53f0..4c52b02 100644 --- a/test/webfuse/tests/provider/operation/test_open.cc +++ b/test/webfuse/tests/provider/operation/test_open.cc @@ -41,6 +41,7 @@ TEST(wfp_impl_open, invoke_provider) json_array_append_new(params, json_integer(flags)); wfp_impl_open(&context, params, 42); + json_decref(params); } TEST(wfp_impl_open, fail_invalid_param_count) @@ -56,6 +57,7 @@ TEST(wfp_impl_open, fail_invalid_param_count) json_array_append_new(params, json_integer(23)); wfp_impl_open(&context, params, 42); + json_decref(params); } TEST(wfp_impl_open, fail_invalid_inode_type) @@ -72,6 +74,7 @@ TEST(wfp_impl_open, fail_invalid_inode_type) json_array_append_new(params, json_integer(0)); wfp_impl_open(&context, params, 42); + json_decref(params); } TEST(wfp_impl_open, fail_invalid_flags_type) @@ -88,6 +91,7 @@ TEST(wfp_impl_open, fail_invalid_flags_type) json_array_append_new(params, json_string("")); wfp_impl_open(&context, params, 42); + json_decref(params); } TEST(wfp_impl_open, default_responds_error) From c769c02c55e63a82e3a8a2fcec10c95308c6901f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 20:23:50 +0200 Subject: [PATCH 122/138] added unit tests for readdir operation (adapter) --- cmake/unit_tests.cmake | 1 + lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/readdir.c | 53 ++-- lib/webfuse/adapter/impl/operation/readdir.h | 35 +++ .../tests/adapter/operation/test_readdir.cc | 266 ++++++++++++++++++ 5 files changed, 331 insertions(+), 25 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/readdir.h create mode 100644 test/webfuse/tests/adapter/operation/test_readdir.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 2b2d445..1444ee5 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -51,6 +51,7 @@ add_executable(alltests 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/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 66ee76c..2573753 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -3,6 +3,7 @@ #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/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index 804a80e..d82fc62 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -1,3 +1,4 @@ +#include "webfuse/adapter/impl/operation/readdir.h" #include "webfuse/adapter/impl/operations.h" #include @@ -15,13 +16,6 @@ #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 { char * data; @@ -72,7 +66,7 @@ static size_t wf_impl_min(size_t a, size_t b) return (a < b) ? a : b; } -static void wf_impl_operation_readdir_finished( +void wf_impl_operation_readdir_finished( void * user_data, json_t const * result, json_t const * error) @@ -83,31 +77,40 @@ static void wf_impl_operation_readdir_finished( struct wf_impl_dirbuffer 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; - size_t const count = json_array_size(result); - for(size_t i = 0; (!buffer_full) && (i < count); i++) + json_t * entry =json_array_get(result, i); + if (json_is_object(entry)) { - json_t * entry =json_array_get(result, i); - if (json_is_object(entry)) - { - json_t * name_holder = json_object_get(entry, "name"); - 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)) && - (NULL != inode_holder) && (json_is_integer(inode_holder))) - { - char const * name = json_string_value(name_holder); - fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder); - wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode); - } + if ((json_is_string(name_holder)) && (json_is_integer(inode_holder))) + { + char const * name = json_string_value(name_holder); + fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder); + 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) { diff --git a/lib/webfuse/adapter/impl/operation/readdir.h b/lib/webfuse/adapter/impl/operation/readdir.h new file mode 100644 index 0000000..40eb09e --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/readdir.h @@ -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 + +#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 diff --git a/test/webfuse/tests/adapter/operation/test_readdir.cc b/test/webfuse/tests/adapter/operation/test_readdir.cc new file mode 100644 index 0000000..3ae9df2 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_readdir.cc @@ -0,0 +1,266 @@ +#include "webfuse/adapter/impl/operation/readdir.h" +#include "webfuse/adapter/impl/operations.h" + +#include "webfuse/core/status.h" + +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" + +#include + +using webfuse_test::MockJsonRpcProxy; +using webfuse_test::MockOperationsContext; +using webfuse_test::FuseMock; +using testing::_; +using testing::Return; +using testing::Invoke; +using testing::StrEq; + +namespace +{ + +void free_context( + struct wf_jsonrpc_proxy * , + wf_jsonrpc_proxy_finished_fn * , + void * user_data, + char const * , + char const *) +{ + free(user_data); +} + +} + +TEST(wf_impl_operation_readdir, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("readdir"),StrEq("si"))) + .Times(1).WillOnce(Invoke(free_context)); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&proxy))); + + wf_impl_operations_context op_context; + op_context.name = nullptr; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 10; + size_t offset = 0; + fuse_file_info file_info; + file_info.flags = 0; + wf_impl_operation_readdir(request, inode, size, offset, &file_info); +} + +TEST(wf_impl_operation_readdir, fail_rpc_null) +{ + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 10; + size_t offset = 0; + fuse_file_info file_info; + file_info.flags = 0; + wf_impl_operation_readdir(request, inode, size, offset, &file_info); +} + +TEST(wf_impl_operation_readdir, finished) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_string("a.file")); + json_object_set_new(item, "inode", json_integer(42)); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_many_items) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + for(int i = 0; i < 100; i++) + { + json_t * item = json_object(); + json_object_set_new(item, "name", json_sprintf("file_%d.txt", i)); + json_object_set_new(item, "inode", json_integer(1 + i)); + json_array_append_new(result, item); + } + + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 100; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_read_after_end) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_string("a.file")); + json_object_set_new(item, "inode", json_integer(42)); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 10; + context->offset = 2; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * error = json_array(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), nullptr, error); + json_decref(error); +} + +TEST(wf_impl_operation_readdir, finished_fail_invalid_result_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_missing_name) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "inode", json_integer(42)); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_invalid_name_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_integer(42)); + json_object_set_new(item, "inode", json_integer(42)); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_missing_inode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_string("a.file")); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_invalid_inode_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_string("a.file")); + json_object_set_new(item, "inode", json_string("42")); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_invalid_item_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_array_append_new(result, json_string("item")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} From 654015c95c4b55ccdca1b680aa4dc9c8f31b4ddf Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 22:26:15 +0200 Subject: [PATCH 123/138] added unit tests for getattr operation (adapter) --- cmake/unit_tests.cmake | 3 + lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/getattr.c | 15 +- lib/webfuse/adapter/impl/operation/getattr.h | 37 +++ lib/webfuse/adapter/impl/operations.h | 12 - test/webfuse/mocks/mock_fuse.cc | 2 + test/webfuse/mocks/mock_fuse.hpp | 2 + .../tests/adapter/operation/test_getattr.cc | 214 ++++++++++++++++++ 8 files changed, 262 insertions(+), 24 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/getattr.h create mode 100644 test/webfuse/tests/adapter/operation/test_getattr.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1444ee5..0e3f8dd 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -52,6 +52,7 @@ add_executable(alltests 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/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -81,6 +82,8 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=fuse_reply_open -Wl,--wrap=fuse_reply_err -Wl,--wrap=fuse_reply_buf + -Wl,--wrap=fuse_reply_attr + -Wl,--wrap=fuse_req_ctx webfuse-adapter-static webfuse-provider-static diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 2573753..d614cd4 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -4,6 +4,7 @@ #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/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index ae64a25..6185044 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -1,3 +1,4 @@ +#include "webfuse/adapter/impl/operation/getattr.h" #include "webfuse/adapter/impl/operations.h" #include @@ -11,16 +12,7 @@ #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" -struct wf_impl_operation_getattr_context -{ - fuse_req_t request; - fuse_ino_t inode; - double timeout; - uid_t uid; - gid_t gid; -}; - -static void wf_impl_operation_getattr_finished( +void wf_impl_operation_getattr_finished( void * user_data, json_t const * result, 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 * type_holder = json_object_get(result, "type"); - if ((NULL != mode_holder) && (json_is_integer(mode_holder)) && - (NULL != type_holder) && (json_is_string(type_holder))) + if ((json_is_integer(mode_holder)) && (json_is_string(type_holder))) { memset(&buffer, 0, sizeof(struct stat)); diff --git a/lib/webfuse/adapter/impl/operation/getattr.h b/lib/webfuse/adapter/impl/operation/getattr.h new file mode 100644 index 0000000..3908922 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/getattr.h @@ -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 +#include + +#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 diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index 6217de7..e52d09e 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -22,18 +22,6 @@ extern void wf_impl_operation_lookup ( 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 struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context); diff --git a/test/webfuse/mocks/mock_fuse.cc b/test/webfuse/mocks/mock_fuse.cc index 1cf6aa1..96eb6fa 100644 --- a/test/webfuse/mocks/mock_fuse.cc +++ b/test/webfuse/mocks/mock_fuse.cc @@ -9,6 +9,8 @@ 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); } diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp index 1b81e71..02f6e75 100644 --- a/test/webfuse/mocks/mock_fuse.hpp +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -17,6 +17,8 @@ public: 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)); }; } diff --git a/test/webfuse/tests/adapter/operation/test_getattr.cc b/test/webfuse/tests/adapter/operation/test_getattr.cc new file mode 100644 index 0000000..cced583 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_getattr.cc @@ -0,0 +1,214 @@ +#include "webfuse/adapter/impl/operation/getattr.h" +#include "webfuse/adapter/impl/operations.h" + +#include "webfuse/core/status.h" + +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" + +#include + +using webfuse_test::MockJsonRpcProxy; +using webfuse_test::MockOperationsContext; +using webfuse_test::FuseMock; +using testing::_; +using testing::Return; +using testing::Invoke; +using testing::StrEq; + +namespace +{ + +void free_context( + struct wf_jsonrpc_proxy * , + wf_jsonrpc_proxy_finished_fn * , + void * user_data, + char const * , + char const *) +{ + free(user_data); +} + +} + +TEST(wf_impl_operation_getattr, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("getattr"),StrEq("si"))).Times(1) + .WillOnce(Invoke(free_context)); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&proxy))); + + wf_impl_operations_context op_context; + op_context.name = nullptr; + fuse_ctx fuse_context; + fuse_context.gid = 0; + fuse_context.uid = 0; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(&fuse_context)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info * file_info = nullptr; + wf_impl_operation_getattr(request, inode, file_info); +} + +TEST(wf_impl_operation_getattr, fail_rpc_null) +{ + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info * file_info = nullptr; + wf_impl_operation_getattr(request, inode, file_info); +} + +TEST(wf_impl_operation_getattr, finished_file) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_dir) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("dir")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_unknown_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("unknown")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_fail_missing_mode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_fail_invalid_mode_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_string("0755")); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_fail_type_mode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_fail_invalid_type_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_integer(42)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, nullptr, error); + json_decref(error); +} From 745d47bb30a8746059cb41b43fc8961af29b75df Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 23:16:25 +0200 Subject: [PATCH 124/138] added unit tests for lookup operation (adapter) --- cmake/unit_tests.cmake | 3 + cmake/webfuse_adapter.cmake | 2 +- lib/webfuse/adapter/impl/filesystem.c | 3 +- lib/webfuse/adapter/impl/filesystem.h | 2 +- lib/webfuse/adapter/impl/operation/close.c | 3 +- .../{operations.c => operation/context.c} | 2 +- .../{operations.h => operation/context.h} | 9 +- lib/webfuse/adapter/impl/operation/getattr.c | 2 +- lib/webfuse/adapter/impl/operation/lookup.c | 19 +- lib/webfuse/adapter/impl/operation/lookup.h | 36 +++ lib/webfuse/adapter/impl/operation/open.c | 2 +- lib/webfuse/adapter/impl/operation/read.c | 2 +- lib/webfuse/adapter/impl/operation/readdir.c | 2 +- test/webfuse/mocks/mock_fuse.cc | 2 +- test/webfuse/mocks/mock_fuse.hpp | 1 + .../webfuse/mocks/mock_operations_context.hpp | 2 +- .../tests/adapter/operation/test_context.cc | 23 ++ .../tests/adapter/operation/test_getattr.cc | 1 - .../tests/adapter/operation/test_lookup.cc | 255 ++++++++++++++++++ .../tests/adapter/operation/test_open.cc | 1 - .../tests/adapter/operation/test_read.cc | 1 - .../tests/adapter/operation/test_readdir.cc | 1 - 22 files changed, 339 insertions(+), 35 deletions(-) rename lib/webfuse/adapter/impl/{operations.c => operation/context.c} (88%) rename lib/webfuse/adapter/impl/{operations.h => operation/context.h} (69%) create mode 100644 lib/webfuse/adapter/impl/operation/lookup.h create mode 100644 test/webfuse/tests/adapter/operation/test_context.cc create mode 100644 test/webfuse/tests/adapter/operation/test_lookup.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 0e3f8dd..eaa8427 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -48,11 +48,13 @@ add_executable(alltests test/webfuse/tests/adapter/test_authenticators.cc test/webfuse/tests/adapter/test_mountpoint.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_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -83,6 +85,7 @@ target_link_libraries(alltests PUBLIC -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 diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index fab0f55..b15b655 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -13,9 +13,9 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/authenticator.c lib/webfuse/adapter/impl/authenticators.c lib/webfuse/adapter/impl/credentials.c - lib/webfuse/adapter/impl/operations.c lib/webfuse/adapter/impl/mountpoint.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/getattr.c lib/webfuse/adapter/impl/operation/readdir.c diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index d614cd4..0c321e9 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -1,10 +1,11 @@ #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/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/filesystem.h b/lib/webfuse/adapter/impl/filesystem.h index 83660d8..9ea6406 100644 --- a/lib/webfuse/adapter/impl/filesystem.h +++ b/lib/webfuse/adapter/impl/filesystem.h @@ -6,7 +6,7 @@ #endif #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" #ifdef __cplusplus diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index 5f6e49b..5e3c4e8 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -1,4 +1,5 @@ -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/close.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include diff --git a/lib/webfuse/adapter/impl/operations.c b/lib/webfuse/adapter/impl/operation/context.c similarity index 88% rename from lib/webfuse/adapter/impl/operations.c rename to lib/webfuse/adapter/impl/operation/context.c index 9ddad3e..1bde8b1 100644 --- a/lib/webfuse/adapter/impl/operations.c +++ b/lib/webfuse/adapter/impl/operation/context.c @@ -1,4 +1,4 @@ -#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.h" #include diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operation/context.h similarity index 69% rename from lib/webfuse/adapter/impl/operations.h rename to lib/webfuse/adapter/impl/operation/context.h index e52d09e..17f5f81 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operation/context.h @@ -1,5 +1,5 @@ -#ifndef WF_ADAPTER_IMPL_OPERATIONS_H -#define WF_ADAPTER_IMPL_OPERATIONS_H +#ifndef WF_ADAPTER_IMPL_OPERATION_CONTEXT_H +#define WF_ADAPTER_IMPL_OPERATION_CONTEXT_H #include "webfuse/adapter/impl/fuse_wrapper.h" @@ -17,11 +17,6 @@ struct wf_impl_operations_context char * name; }; -extern void wf_impl_operation_lookup ( - fuse_req_t req, - fuse_ino_t parent, - char const * name); - extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context); diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index 6185044..3c00840 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -1,5 +1,5 @@ #include "webfuse/adapter/impl/operation/getattr.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index 4b64320..ca778cd 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -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 #include @@ -14,15 +15,7 @@ #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" -struct wf_impl_operation_lookup_context -{ - fuse_req_t request; - double timeout; - uid_t uid; - gid_t gid; -}; - -static void wf_impl_operation_lookup_finished( +void wf_impl_operation_lookup_finished( void * user_data, json_t const * result, 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 * mode_holder = json_object_get(result, "mode"); json_t * type_holder = json_object_get(result, "type"); - if ((NULL != inode_holder) && (json_is_integer(inode_holder)) && - (NULL != mode_holder) && (json_is_integer(mode_holder)) && - (NULL != type_holder) && (json_is_string(type_holder))) + if ((json_is_integer(inode_holder)) && + (json_is_integer(mode_holder)) && + (json_is_string(type_holder))) { memset(&buffer, 0, sizeof(struct stat)); diff --git a/lib/webfuse/adapter/impl/operation/lookup.h b/lib/webfuse/adapter/impl/operation/lookup.h new file mode 100644 index 0000000..c43e864 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/lookup.h @@ -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 +#include + +#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 diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 630e9c8..712f240 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -1,5 +1,5 @@ #include "webfuse/adapter/impl/operation/open.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 59c3180..81b6928 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -1,5 +1,5 @@ #include "webfuse/adapter/impl/operation/read.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index d82fc62..8022440 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -1,5 +1,5 @@ #include "webfuse/adapter/impl/operation/readdir.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include diff --git a/test/webfuse/mocks/mock_fuse.cc b/test/webfuse/mocks/mock_fuse.cc index 96eb6fa..486c8ed 100644 --- a/test/webfuse/mocks/mock_fuse.cc +++ b/test/webfuse/mocks/mock_fuse.cc @@ -11,7 +11,7 @@ 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 diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp index 02f6e75..cc3fb71 100644 --- a/test/webfuse/mocks/mock_fuse.hpp +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -19,6 +19,7 @@ public: 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)); }; } diff --git a/test/webfuse/mocks/mock_operations_context.hpp b/test/webfuse/mocks/mock_operations_context.hpp index a12aa7b..1dee54c 100644 --- a/test/webfuse/mocks/mock_operations_context.hpp +++ b/test/webfuse/mocks/mock_operations_context.hpp @@ -1,7 +1,7 @@ #ifndef MOCK_OPERATIONS_CONTEXT_HPP #define MOCK_OPERATIONS_CONTEXT_HPP -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include namespace webfuse_test diff --git a/test/webfuse/tests/adapter/operation/test_context.cc b/test/webfuse/tests/adapter/operation/test_context.cc new file mode 100644 index 0000000..bd53241 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_context.cc @@ -0,0 +1,23 @@ +#include "webfuse/adapter/impl/operation/context.h" +#include "webfuse/adapter/impl/session.h" +#include + +TEST(wf_impl_operation_context, get_proxy) +{ + wf_jsonrpc_proxy * proxy = reinterpret_cast(42); + wf_impl_session session; + session.rpc = proxy; + wf_impl_operations_context context; + context.session = &session; + + ASSERT_EQ(proxy, wf_impl_operations_context_get_proxy(&context)); +} + +TEST(wf_impl_operation_context, get_proxy_fail_no_session) +{ + wf_impl_operations_context context; + context.session = nullptr; + + ASSERT_EQ(nullptr, wf_impl_operations_context_get_proxy(&context)); + +} \ No newline at end of file diff --git a/test/webfuse/tests/adapter/operation/test_getattr.cc b/test/webfuse/tests/adapter/operation/test_getattr.cc index cced583..4dc0081 100644 --- a/test/webfuse/tests/adapter/operation/test_getattr.cc +++ b/test/webfuse/tests/adapter/operation/test_getattr.cc @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/operation/getattr.h" -#include "webfuse/adapter/impl/operations.h" #include "webfuse/core/status.h" diff --git a/test/webfuse/tests/adapter/operation/test_lookup.cc b/test/webfuse/tests/adapter/operation/test_lookup.cc new file mode 100644 index 0000000..73c5774 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_lookup.cc @@ -0,0 +1,255 @@ +#include "webfuse/adapter/impl/operation/lookup.h" + +#include "webfuse/core/status.h" + +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" + +#include + +using webfuse_test::MockJsonRpcProxy; +using webfuse_test::MockOperationsContext; +using webfuse_test::FuseMock; +using testing::_; +using testing::Return; +using testing::Invoke; +using testing::StrEq; + +namespace +{ + +void free_context( + struct wf_jsonrpc_proxy * , + wf_jsonrpc_proxy_finished_fn * , + void * user_data, + char const * , + char const *) +{ + free(user_data); +} + +} + +TEST(wf_impl_operation_lookup, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("lookup"),StrEq("sis"))).Times(1) + .WillOnce(Invoke(free_context)); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&proxy))); + + wf_impl_operations_context op_context; + op_context.name = nullptr; + fuse_ctx fuse_context; + fuse_context.gid = 0; + fuse_context.uid = 0; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(&fuse_context)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + wf_impl_operation_lookup(request, inode, "some.file"); +} + +TEST(wf_impl_operation_lookup, fail_rpc_null) +{ + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + wf_impl_operation_lookup(request, inode, "some.file"); +} + +TEST(wf_impl_operation_lookup, finished_file) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_dir) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("dir")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_unknown_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("unknown")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_missing_inode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_invalid_inode_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_string("42")); + json_object_set_new(result, "mode", json_string("0755")); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_missing_mode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_invalid_mode_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_string("0755")); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_type_mode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_invalid_type_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_integer(42)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, nullptr, error); + json_decref(error); +} diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc index f82e81e..9670985 100644 --- a/test/webfuse/tests/adapter/operation/test_open.cc +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/operation/open.h" -#include "webfuse/adapter/impl/operations.h" #include "webfuse/core/status.h" diff --git a/test/webfuse/tests/adapter/operation/test_read.cc b/test/webfuse/tests/adapter/operation/test_read.cc index 85fcf34..934d060 100644 --- a/test/webfuse/tests/adapter/operation/test_read.cc +++ b/test/webfuse/tests/adapter/operation/test_read.cc @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/operation/read.h" -#include "webfuse/adapter/impl/operations.h" #include "webfuse/mocks/mock_fuse.hpp" #include "webfuse/mocks/mock_operations_context.hpp" diff --git a/test/webfuse/tests/adapter/operation/test_readdir.cc b/test/webfuse/tests/adapter/operation/test_readdir.cc index 3ae9df2..2875eca 100644 --- a/test/webfuse/tests/adapter/operation/test_readdir.cc +++ b/test/webfuse/tests/adapter/operation/test_readdir.cc @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/operation/readdir.h" -#include "webfuse/adapter/impl/operations.h" #include "webfuse/core/status.h" From 49469c73e30183b7d3cff0892619fe6ef8d4331a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 23:27:34 +0200 Subject: [PATCH 125/138] renamed operation_context --- cmake/unit_tests.cmake | 4 +-- lib/webfuse/adapter/impl/filesystem.h | 2 +- lib/webfuse/adapter/impl/operation/close.c | 4 +-- lib/webfuse/adapter/impl/operation/context.c | 4 +-- lib/webfuse/adapter/impl/operation/context.h | 6 ++--- lib/webfuse/adapter/impl/operation/getattr.c | 4 +-- lib/webfuse/adapter/impl/operation/lookup.c | 4 +-- lib/webfuse/adapter/impl/operation/open.c | 4 +-- lib/webfuse/adapter/impl/operation/read.c | 4 +-- lib/webfuse/adapter/impl/operation/readdir.c | 4 +-- test/webfuse/mocks/mock_operation_context.cc | 27 +++++++++++++++++++ test/webfuse/mocks/mock_operation_context.hpp | 22 +++++++++++++++ test/webfuse/mocks/mock_operations_context.cc | 27 ------------------- .../webfuse/mocks/mock_operations_context.hpp | 22 --------------- .../tests/adapter/operation/test_close.cc | 14 +++++----- .../tests/adapter/operation/test_context.cc | 8 +++--- .../tests/adapter/operation/test_getattr.cc | 14 +++++----- .../tests/adapter/operation/test_lookup.cc | 14 +++++----- .../tests/adapter/operation/test_open.cc | 14 +++++----- .../tests/adapter/operation/test_read.cc | 20 +++++++------- .../tests/adapter/operation/test_readdir.cc | 14 +++++----- 21 files changed, 118 insertions(+), 118 deletions(-) create mode 100644 test/webfuse/mocks/mock_operation_context.cc create mode 100644 test/webfuse/mocks/mock_operation_context.hpp delete mode 100644 test/webfuse/mocks/mock_operations_context.cc delete mode 100644 test/webfuse/mocks/mock_operations_context.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index eaa8427..43b9598 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -31,7 +31,7 @@ add_executable(alltests test/webfuse/mocks/mock_provider_client.cc test/webfuse/mocks/mock_provider.cc test/webfuse/mocks/mock_fuse.cc - test/webfuse/mocks/mock_operations_context.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_container_of.cc @@ -77,7 +77,7 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_dispose -Wl,--wrap=wf_timer_start -Wl,--wrap=wf_timer_cancel - -Wl,--wrap=wf_impl_operations_context_get_proxy + -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 diff --git a/lib/webfuse/adapter/impl/filesystem.h b/lib/webfuse/adapter/impl/filesystem.h index 9ea6406..791170a 100644 --- a/lib/webfuse/adapter/impl/filesystem.h +++ b/lib/webfuse/adapter/impl/filesystem.h @@ -24,7 +24,7 @@ struct wf_impl_filesystem struct fuse_args args; struct fuse_session * session; struct fuse_buf buffer; - struct wf_impl_operations_context user_data; + struct wf_impl_operation_context user_data; struct lws * wsi; struct wf_mountpoint * mountpoint; }; diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index 5e3c4e8..62d1ec3 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -13,8 +13,8 @@ void wf_impl_operation_close( fuse_ino_t inode, struct fuse_file_info * file_info) { - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/context.c b/lib/webfuse/adapter/impl/operation/context.c index 1bde8b1..a39978f 100644 --- a/lib/webfuse/adapter/impl/operation/context.c +++ b/lib/webfuse/adapter/impl/operation/context.c @@ -3,8 +3,8 @@ #include "webfuse/adapter/impl/session.h" #include -struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( - struct wf_impl_operations_context * context) +struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy( + struct wf_impl_operation_context * context) { struct wf_jsonrpc_proxy * proxy = NULL; diff --git a/lib/webfuse/adapter/impl/operation/context.h b/lib/webfuse/adapter/impl/operation/context.h index 17f5f81..51d886f 100644 --- a/lib/webfuse/adapter/impl/operation/context.h +++ b/lib/webfuse/adapter/impl/operation/context.h @@ -10,15 +10,15 @@ extern "C" { struct wf_impl_session; struct wf_jsonrpc_proxy; -struct wf_impl_operations_context +struct wf_impl_operation_context { struct wf_impl_session * session; double timeout; char * name; }; -extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( - struct wf_impl_operations_context * context); +extern struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy( + struct wf_impl_operation_context * context); #ifdef __cplusplus } diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index 3c00840..8318dc2 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -73,8 +73,8 @@ void wf_impl_operation_getattr ( struct fuse_file_info * WF_UNUSED_PARAM(file_info)) { struct fuse_ctx const * context = fuse_req_ctx(request); - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index ca778cd..4ebbe3c 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -84,8 +84,8 @@ void wf_impl_operation_lookup ( char const * name) { struct fuse_ctx const * context = fuse_req_ctx(request); - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 712f240..1b25d99 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -48,8 +48,8 @@ void wf_impl_operation_open( fuse_ino_t inode, struct fuse_file_info * file_info) { - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 81b6928..7e2e0f4 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -111,8 +111,8 @@ void wf_impl_operation_read( off_t offset, struct fuse_file_info * file_info) { - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index 8022440..6d54636 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -141,8 +141,8 @@ void wf_impl_operation_readdir ( off_t offset, struct fuse_file_info * WF_UNUSED_PARAM(file_info)) { - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/test/webfuse/mocks/mock_operation_context.cc b/test/webfuse/mocks/mock_operation_context.cc new file mode 100644 index 0000000..9537533 --- /dev/null +++ b/test/webfuse/mocks/mock_operation_context.cc @@ -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; +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_operation_context.hpp b/test/webfuse/mocks/mock_operation_context.hpp new file mode 100644 index 0000000..e692e76 --- /dev/null +++ b/test/webfuse/mocks/mock_operation_context.hpp @@ -0,0 +1,22 @@ +#ifndef MOCK_OPERATIONS_CONTEXT_HPP +#define MOCK_OPERATIONS_CONTEXT_HPP + +#include "webfuse/adapter/impl/operation/context.h" +#include + +namespace webfuse_test +{ + +class MockOperationContext +{ +public: + MockOperationContext(); + virtual ~MockOperationContext(); + MOCK_METHOD1(wf_impl_operation_context_get_proxy, wf_jsonrpc_proxy * ( + struct wf_impl_operation_context * context)); + +}; + +} + +#endif diff --git a/test/webfuse/mocks/mock_operations_context.cc b/test/webfuse/mocks/mock_operations_context.cc deleted file mode 100644 index 89498f7..0000000 --- a/test/webfuse/mocks/mock_operations_context.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "webfuse/mocks/mock_operations_context.hpp" -#include "webfuse/utils/wrap.hpp" - -extern "C" -{ -static webfuse_test::MockOperationsContext * webfuse_test_MockOperationsContext = nullptr; - -WF_WRAP_FUNC1(webfuse_test_MockOperationsContext, - struct wf_jsonrpc_proxy *, wf_impl_operations_context_get_proxy, - struct wf_impl_operations_context *); - -} - -namespace webfuse_test -{ - -MockOperationsContext::MockOperationsContext() -{ - webfuse_test_MockOperationsContext = this; -} - -MockOperationsContext::~MockOperationsContext() -{ - webfuse_test_MockOperationsContext = nullptr; -} - -} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_operations_context.hpp b/test/webfuse/mocks/mock_operations_context.hpp deleted file mode 100644 index 1dee54c..0000000 --- a/test/webfuse/mocks/mock_operations_context.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MOCK_OPERATIONS_CONTEXT_HPP -#define MOCK_OPERATIONS_CONTEXT_HPP - -#include "webfuse/adapter/impl/operation/context.h" -#include - -namespace webfuse_test -{ - -class MockOperationsContext -{ -public: - MockOperationsContext(); - virtual ~MockOperationsContext(); - MOCK_METHOD1(wf_impl_operations_context_get_proxy, wf_jsonrpc_proxy * ( - struct wf_impl_operations_context * context)); - -}; - -} - -#endif diff --git a/test/webfuse/tests/adapter/operation/test_close.cc b/test/webfuse/tests/adapter/operation/test_close.cc index 885e3bb..00e4763 100644 --- a/test/webfuse/tests/adapter/operation/test_close.cc +++ b/test/webfuse/tests/adapter/operation/test_close.cc @@ -2,13 +2,13 @@ #include #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -19,11 +19,11 @@ TEST(wf_impl_operation_close, notify_proxy) MockJsonRpcProxy proxy; EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,StrEq("close"),StrEq("siii"))).Times(1); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -41,8 +41,8 @@ TEST(wf_impl_operation_close, fail_rpc_null) MockJsonRpcProxy proxy; EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_)).Times(0); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_context.cc b/test/webfuse/tests/adapter/operation/test_context.cc index bd53241..77aa287 100644 --- a/test/webfuse/tests/adapter/operation/test_context.cc +++ b/test/webfuse/tests/adapter/operation/test_context.cc @@ -7,17 +7,17 @@ TEST(wf_impl_operation_context, get_proxy) wf_jsonrpc_proxy * proxy = reinterpret_cast(42); wf_impl_session session; session.rpc = proxy; - wf_impl_operations_context context; + wf_impl_operation_context context; context.session = &session; - ASSERT_EQ(proxy, wf_impl_operations_context_get_proxy(&context)); + ASSERT_EQ(proxy, wf_impl_operation_context_get_proxy(&context)); } TEST(wf_impl_operation_context, get_proxy_fail_no_session) { - wf_impl_operations_context context; + wf_impl_operation_context context; context.session = nullptr; - ASSERT_EQ(nullptr, wf_impl_operations_context_get_proxy(&context)); + ASSERT_EQ(nullptr, wf_impl_operation_context_get_proxy(&context)); } \ No newline at end of file diff --git a/test/webfuse/tests/adapter/operation/test_getattr.cc b/test/webfuse/tests/adapter/operation/test_getattr.cc index 4dc0081..8249692 100644 --- a/test/webfuse/tests/adapter/operation/test_getattr.cc +++ b/test/webfuse/tests/adapter/operation/test_getattr.cc @@ -3,13 +3,13 @@ #include "webfuse/core/status.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -37,11 +37,11 @@ TEST(wf_impl_operation_getattr, invoke_proxy) EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("getattr"),StrEq("si"))).Times(1) .WillOnce(Invoke(free_context)); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; fuse_ctx fuse_context; fuse_context.gid = 0; @@ -59,8 +59,8 @@ TEST(wf_impl_operation_getattr, invoke_proxy) TEST(wf_impl_operation_getattr, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_lookup.cc b/test/webfuse/tests/adapter/operation/test_lookup.cc index 73c5774..002fc30 100644 --- a/test/webfuse/tests/adapter/operation/test_lookup.cc +++ b/test/webfuse/tests/adapter/operation/test_lookup.cc @@ -3,13 +3,13 @@ #include "webfuse/core/status.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -37,11 +37,11 @@ TEST(wf_impl_operation_lookup, invoke_proxy) EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("lookup"),StrEq("sis"))).Times(1) .WillOnce(Invoke(free_context)); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; fuse_ctx fuse_context; fuse_context.gid = 0; @@ -58,8 +58,8 @@ TEST(wf_impl_operation_lookup, invoke_proxy) TEST(wf_impl_operation_lookup, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc index 9670985..e3d89bc 100644 --- a/test/webfuse/tests/adapter/operation/test_open.cc +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -3,13 +3,13 @@ #include "webfuse/core/status.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -20,11 +20,11 @@ TEST(wf_impl_operation_open, invoke_proxy) MockJsonRpcProxy proxy; EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"))).Times(1); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -39,8 +39,8 @@ TEST(wf_impl_operation_open, invoke_proxy) TEST(wf_impl_operation_open, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_read.cc b/test/webfuse/tests/adapter/operation/test_read.cc index 934d060..15b9f9c 100644 --- a/test/webfuse/tests/adapter/operation/test_read.cc +++ b/test/webfuse/tests/adapter/operation/test_read.cc @@ -1,13 +1,13 @@ #include "webfuse/adapter/impl/operation/read.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -18,11 +18,11 @@ TEST(wf_impl_operation_read, invoke_proxy) MockJsonRpcProxy proxy; EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -41,11 +41,11 @@ TEST(wf_impl_operation_read, invoke_proxy_limit_size) MockJsonRpcProxy proxy; EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -61,8 +61,8 @@ TEST(wf_impl_operation_read, invoke_proxy_limit_size) TEST(wf_impl_operation_read, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_readdir.cc b/test/webfuse/tests/adapter/operation/test_readdir.cc index 2875eca..c020c3d 100644 --- a/test/webfuse/tests/adapter/operation/test_readdir.cc +++ b/test/webfuse/tests/adapter/operation/test_readdir.cc @@ -3,13 +3,13 @@ #include "webfuse/core/status.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -37,11 +37,11 @@ TEST(wf_impl_operation_readdir, invoke_proxy) EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("readdir"),StrEq("si"))) .Times(1).WillOnce(Invoke(free_context)); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -58,8 +58,8 @@ TEST(wf_impl_operation_readdir, invoke_proxy) TEST(wf_impl_operation_readdir, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; From 810702c5a71f95fd1cc81a2374917010a3c4be55 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 5 Apr 2020 15:09:15 +0200 Subject: [PATCH 126/138] fixed memory leak --- lib/webfuse/provider/impl/client.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index f10450f..9f45a5a 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -43,14 +43,21 @@ struct wfp_client * wfp_impl_client_create( if ((NULL != config->cert_path) && (NULL != config->key_path)) { + client->info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS; + } + + client->context = lws_create_context(&client->info); + + if ((NULL != config->cert_path) && (NULL != config->key_path)) + { + struct lws_vhost * vhost = lws_create_vhost(client->context, &client->info); client->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; client->info.client_ssl_cert_filepath = config->cert_path; client->info.client_ssl_private_key_filepath = 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; } From ac855a73c8651b18b37402b2ec2755dec9c103e2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 5 Apr 2020 17:08:33 +0200 Subject: [PATCH 127/138] fix: make ctest fail on memcheck errors --- cmake/unit_tests.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 43b9598..00870d9 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -1,5 +1,6 @@ if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) +set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1") include (CTest) pkg_check_modules(GTEST gtest_main) From 7cea9828cb05be7b2e9a40ddca4b15338cbcac2f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 5 Apr 2020 20:11:07 +0200 Subject: [PATCH 128/138] replaces death tests by popen --- cmake/unit_tests.cmake | 6 +- test/webfuse/tests/integration/file.cc | 85 ++++++ test/webfuse/tests/integration/file.hpp | 26 ++ test/webfuse/tests/integration/fs_check.c | 288 ++++++++++++++++++ .../tests/integration/test_integration.cc | 87 +----- test/webfuse/utils/die_if.cc | 15 - test/webfuse/utils/die_if.hpp | 11 - 7 files changed, 418 insertions(+), 100 deletions(-) create mode 100644 test/webfuse/tests/integration/file.cc create mode 100644 test/webfuse/tests/integration/file.hpp create mode 100644 test/webfuse/tests/integration/fs_check.c delete mode 100644 test/webfuse/utils/die_if.cc delete mode 100644 test/webfuse/utils/die_if.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 00870d9..60023ee 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -3,6 +3,10 @@ if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1") include (CTest) +add_executable(fs_check + test/webfuse/tests/integration/fs_check.c +) + pkg_check_modules(GTEST gtest_main) include(GoogleTest) pkg_check_modules(GMOCK gmock) @@ -21,7 +25,6 @@ add_executable(alltests test/webfuse/tests/core/timer/test_timer.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc - test/webfuse/utils/die_if.cc test/webfuse/utils/timeout_watcher.cc test/webfuse/utils/path.c test/webfuse/utils/static_filesystem.c @@ -66,6 +69,7 @@ add_executable(alltests 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/file.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc ) diff --git a/test/webfuse/tests/integration/file.cc b/test/webfuse/tests/integration/file.cc new file mode 100644 index 0000000..5719382 --- /dev/null +++ b/test/webfuse/tests/integration/file.cc @@ -0,0 +1,85 @@ +#include "webfuse/tests/integration/file.hpp" +#include +#include + +namespace +{ + +bool invoke(std::string const & command) +{ + int exit_code = -1; + + FILE * file = ::popen(command.c_str(), "r"); + if (nullptr != file) + { + exit_code = ::pclose(file); + } + + return (0 == exit_code); +} + +} + +namespace webfuse_test +{ + +File::File(std::string const& path) +: path_(path) +{ + +} + +File::~File() +{ + +} + +bool File::isFile() +{ + std::stringstream command; + command << "./fs_check -c is_file -f " << path_; + + return invoke(command.str()); +} + +bool File::isDirectory() +{ + std::stringstream command; + command << "./fs_check -c is_dir -f " << path_; + + return invoke(command.str()); +} + +bool File::hasAccessRights(int accessRights) +{ + std::stringstream command; + command << "./fs_check -c has_mode -f " << path_ << " -a " << accessRights; + + return invoke(command.str()); +} + +bool File::hasSize(size_t size) +{ + std::stringstream command; + command << "./fs_check -c has_size -f " << path_ << " -a " << size; + + return invoke(command.str()); +} + +bool File::hasSubdirectory(std::string const & subdir) +{ + std::stringstream command; + command << "./fs_check -c has_subdir -f " << path_ << " -a " << subdir; + + return invoke(command.str()); +} + +bool File::hasContents(std::string const & contents) +{ + std::stringstream command; + command << "./fs_check -c has_contents -f " << path_ << " -a " << contents; + + return invoke(command.str()); +} + +} \ No newline at end of file diff --git a/test/webfuse/tests/integration/file.hpp b/test/webfuse/tests/integration/file.hpp new file mode 100644 index 0000000..e36e6ce --- /dev/null +++ b/test/webfuse/tests/integration/file.hpp @@ -0,0 +1,26 @@ +#ifndef WF_TEST_INTEGRATION_FILE_HPP +#define WF_TEST_INTEGRATION_FILE_HPP + +#include + +namespace webfuse_test +{ + +class File final +{ +public: + explicit File(std::string const& path); + ~File(); + bool isFile(); + bool isDirectory(); + bool hasAccessRights(int accessRights); + bool hasSize(size_t size); + bool hasSubdirectory(std::string const & subdir); + bool hasContents(std::string const & contents); +private: + std::string path_; +}; + +} + +#endif diff --git a/test/webfuse/tests/integration/fs_check.c b/test/webfuse/tests/integration/fs_check.c new file mode 100644 index 0000000..55d24c4 --- /dev/null +++ b/test/webfuse/tests/integration/fs_check.c @@ -0,0 +1,288 @@ +/* Why this tool is used: + * + * In order to test webfuse as a fuse filesystem, file system operations should be made. + * To check for memory leaks, valgind (memcheck) is used. + * + * Early tests discovered some ugly behavior of valgrind: + * - valgrind intercepts syscalls like open, read and write + * - valgrind does not expect that syscalls are handled within the process to be checked + * + * There is a more or less (un-) documented switch, which changes valgrind's bevahior, but + * this caused other problems. + * + * The second approach used GTests's death tests. Death tests were used quite a while, + * until we discovered a configuration bug when running CTest: + * - memory leaks did not lead to test error + * + * After fixing CTest configuration, memory leaks within the death tests were shown. + * Which is correct, since death tests pematurely exits the program an therefore no + * cleanup is done. + * + * Finally, it was decided to use good old popen together with this tool. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +struct command; + +typedef bool +command_invoke_fn( + struct command * command); + +struct command +{ + command_invoke_fn * invoke; + char * file; + char * arg; + bool success; + bool has_arg; +}; + +static bool print_usage( + struct command * command) +{ + printf( + "fs_check, (c) 2020 by Webfuse authors (https://github.com/falk-werner/webfuse)\n" + "Checks file information\n" + "\n" + "Usage:\n" + "\t./fs_check --command --file [--arg ]\n" + "\n" + "Options:\n" + "\t-c, --command - Check to perform (see below)\n" + "\t-f, --file - Path to file to check\n" + "\t-a, --arg - Argument, depending on command\n" + "\n" + "Commands:\n" + "\tis_file - checks, if is a regular file; no arg\n" + "\tis_dir - checks, if is a directory; no arg\n" + "\thas_mode - checks, if has the mode given in \n" + "\thas_size - checks, if has the size given in \n" + "\thas_subdir - checks, if contains the sub directory given in \n" + "\thas_contents - checks, if has the contents given in \n" + ); + + return command->success; +} + +static bool is_file( + struct command * command) +{ + struct stat buffer; + int rc = stat(command->file, &buffer); + + return ((0 == rc) && (S_ISREG(buffer.st_mode))); +} + +static bool is_dir( + struct command * command) +{ + struct stat buffer; + int rc = stat(command->file, &buffer); + + return ((0 == rc) && (S_ISDIR(buffer.st_mode))); +} + +static bool has_mode( + struct command * command) +{ + mode_t mode = (mode_t) atoi(command->arg); + struct stat buffer; + int rc = stat(command->file, &buffer); + + return ((0 == rc) && (mode == (buffer.st_mode & 0777))); +} + +static bool has_size( + struct command * command) +{ + int size = atoi(command->arg); + struct stat buffer; + int rc = stat(command->file, &buffer); + + return ((0 == rc) && (size == (buffer.st_size))); +} + +static bool has_subdir( + struct command * command) +{ + bool result = false; + char const * subdir = command->arg; + DIR * dir = opendir(command->file); + if (NULL != dir) + { + struct dirent * entry = readdir(dir); + while (NULL != entry) + { + if (0 == strcmp(subdir, entry->d_name)) + { + result = true; + break; + } + + entry = readdir(dir); + } + + closedir(dir); + } + + return result; +} + +static bool has_contents( + struct command * command) +{ + bool result = false; + char const * contents = command->arg; + size_t length = strlen(contents); + + char * buffer = malloc(length); + FILE * file = fopen(command->file, "rb"); + { + ssize_t count = fread(buffer, 1, length, file); + fclose(file); + + result = (count == (ssize_t) length) && (0 == strncmp(buffer, contents, length)); + } + + free(buffer); + return result; +} + +static bool get_command( + struct command * command, + char const * name) +{ + static struct { + char const * name; + command_invoke_fn * invoke; + bool has_arg; + } commands[] = + { + {"is_file" , &is_file , false}, + {"is_dir" , &is_dir , false}, + {"has_mode" , &has_mode , true}, + {"has_size" , &has_size , true}, + {"has_subdir" , &has_subdir , true}, + {"has_contents", &has_contents, true}, + {NULL, NULL, false} + }; + + for (int i = 0; NULL != commands[i].name; i++) + { + if (0 == strcmp(commands[i].name, name)) + { + command->invoke = commands[i].invoke; + command->has_arg = commands[i].has_arg; + return true; + } + } + + return false; +} + +static void command_init( + struct command * command, + int argc, + char * argv[]) +{ + static struct option const options[] = + { + {"file" , required_argument, NULL, 'f'}, + {"command", required_argument, NULL, 'c'}, + {"arg" , required_argument, NULL, 'a'}, + {"help" , no_argument , NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + + command->invoke = &print_usage; + command->file = NULL; + command->arg = NULL; + command->success = true; + command->has_arg = false; + + optind = 0; + bool is_finished = false; + while (!is_finished) + { + int option_index = 0; + int const c = getopt_long(argc, argv, "f:c:a:h", options, &option_index); + + switch(c) + { + case -1: + is_finished = true; + break; + case 'c': + if (!get_command(command, optarg)) + { + fprintf(stderr, "error: unknown command\n"); + command->invoke = &print_usage; + command->success = false; + is_finished = true; + } + break; + case 'f': + free(command->file); + command->file = strdup(optarg); + break; + case 'a': + free(command->arg); + command->arg = strdup(optarg); + break; + case 'h': + command->invoke = &print_usage; + break; + default: + fprintf(stderr, "error: unknown argument\n"); + command->invoke = &print_usage; + command->success = false; + is_finished = true; + break; + } + } + + if (command->success) + { + if (NULL == command->file) + { + fprintf(stderr, "error: missing required arg: -f\n"); + command->invoke = &print_usage; + command->success = false; + } + else if ((command->has_arg) && (NULL == command->arg)) + { + fprintf(stderr, "error: missing required arg: -a\n"); + command->invoke = &print_usage; + command->success = false; + } + } +} + +static void command_cleanup( + struct command * command) +{ + free(command->file); + free(command->arg); +} + +int main(int argc, char* argv[]) +{ + struct command command; + command_init(&command, argc, argv); + + bool success = command.invoke(&command); + + command_cleanup(&command); + return success ? EXIT_SUCCESS : EXIT_FAILURE; +} \ No newline at end of file diff --git a/test/webfuse/tests/integration/test_integration.cc b/test/webfuse/tests/integration/test_integration.cc index 57c1a91..e7e8215 100644 --- a/test/webfuse/tests/integration/test_integration.cc +++ b/test/webfuse/tests/integration/test_integration.cc @@ -1,6 +1,7 @@ #include #include "webfuse/tests/integration/server.hpp" #include "webfuse/tests/integration/provider.hpp" +#include "webfuse/tests/integration/file.hpp" #include #include @@ -15,11 +16,10 @@ #include #include "webfuse/core/lws_log.h" -#include "webfuse/utils/die_if.hpp" using webfuse_test::Server; using webfuse_test::Provider; -using webfuse_test::die_if; +using webfuse_test::File; namespace { @@ -70,87 +70,28 @@ TEST_F(IntegrationTest, ProvidesTextFile) { std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; - ASSERT_EXIT({ - struct stat buffer; - int rc = stat(file_name.c_str(), &buffer); - - die_if(0 != rc); - die_if(!S_ISREG(buffer.st_mode)); - die_if(0444 != (buffer.st_mode & 0777)); - die_if(12 != buffer.st_size); - - exit(0); - }, ::testing::ExitedWithCode(0), ".*"); + File file(file_name); + ASSERT_TRUE(file.isFile()); + ASSERT_TRUE(file.hasAccessRights(0444)); + ASSERT_TRUE(file.hasSize(12)); } TEST_F(IntegrationTest, ReadTextFile) { std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; - ASSERT_EXIT({ - FILE * file = fopen(file_name.c_str(), "rb"); - die_if(nullptr == file); - - char buffer[13]; - ssize_t count = fread(buffer, 1, 12, file); - int rc = fclose(file); - - die_if(12 != count); - die_if(0 != strncmp("Hello, World", buffer, 12)); - die_if(0 != rc); - - exit(0); - }, ::testing::ExitedWithCode(0), ".*"); - + File file(file_name); + ASSERT_TRUE(file.hasContents("Hello, World")); } TEST_F(IntegrationTest, ReadDir) { std::string dir_name = std::string(GetBaseDir()) + "/cprovider"; - ASSERT_EXIT({ - - DIR * dir = opendir(dir_name.c_str()); - die_if(nullptr == dir); - - bool found_self = false; - bool found_parent = false; - bool found_hello_txt = false; - bool found_other = false; - - dirent * entry = readdir(dir); - while (NULL != entry) - { - if (0 == strcmp(".", entry->d_name)) - { - found_self = true; - } - else if (0 == strcmp("..", entry->d_name)) - { - found_parent = true; - } - else if (0 == strcmp("hello.txt", entry->d_name)) - { - found_hello_txt = true; - } - else - { - found_other = true; - } - - - entry = readdir(dir); - } - - closedir(dir); - - die_if(!found_self); - die_if(!found_parent); - die_if(!found_hello_txt); - - die_if(found_other); - - exit(0); - }, ::testing::ExitedWithCode(0), ".*"); - + File dir(dir_name); + ASSERT_TRUE(dir.isDirectory()); + ASSERT_TRUE(dir.hasSubdirectory(".")); + ASSERT_TRUE(dir.hasSubdirectory("..")); + ASSERT_TRUE(dir.hasSubdirectory("hello.txt")); + ASSERT_FALSE(dir.hasSubdirectory("other")); } \ No newline at end of file diff --git a/test/webfuse/utils/die_if.cc b/test/webfuse/utils/die_if.cc deleted file mode 100644 index bd8dd70..0000000 --- a/test/webfuse/utils/die_if.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include "webfuse/utils/die_if.hpp" -#include - -namespace webfuse_test -{ - -void die_if(bool expression) -{ - if (expression) - { - exit(EXIT_FAILURE); - } -} - -} \ No newline at end of file diff --git a/test/webfuse/utils/die_if.hpp b/test/webfuse/utils/die_if.hpp deleted file mode 100644 index 95d3ff2..0000000 --- a/test/webfuse/utils/die_if.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef WF_TEST_DIE_IF_HPP -#define WF_TEST_DIE_IF_HPP - -namespace webfuse_test -{ - -extern void die_if(bool expression); - -} - -#endif From 485cc84148ac0b631d6c7b1de7833238593a628c Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 6 Apr 2020 19:36:02 +0200 Subject: [PATCH 129/138] updated libwebsockets to 4.0.1 --- Makefile | 4 ++-- build/amd64-alpine-builder.dockerfile | 7 +++++-- build/amd64-ubuntu-builder.dockerfile | 2 +- build/arm32v7-alpine-builder.dockerfile | 7 +++++-- build/arm32v7-ubuntu-builder.dockerfile | 2 +- doc/build.md | 6 +++--- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 4f45263..ad1d2f7 100644 --- a/Makefile +++ b/Makefile @@ -62,11 +62,11 @@ FETCH_TARGETS += $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz $(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 5f7c1062def710d8b60343524a18cc82 -WEBSOCKETS_VERSION ?= 3.2.0 +WEBSOCKETS_VERSION ?= 4.0.1 DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION) FETCH_TARGETS += $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: URL := https://github.com/warmcat/libwebsockets/archive/v$(WEBSOCKETS_VERSION).tar.gz -$(SKIP_MD5SUM)$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := 1d06f5602604e67e6f50cef9857c6b0c +$(SKIP_MD5SUM)$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := b5f90b470f398abbcf66e4639ad0273a JANSSON_VERSION ?= 2.12 DOCKER_BUILDARGS += JANSSON_VERSION=$(JANSSON_VERSION) diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index 6bd7713..6de467a 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -67,9 +67,11 @@ RUN set -x \ && rm -rf "$builddir" \ && apk del .build-deps -ARG WEBSOCKETS_VERSION=3.2.0 +ARG WEBSOCKETS_VERSION=4.0.1 RUN set -x \ + && builddeps="linux-headers" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && apk add --no-cache \ ca-certificates \ openssl \ @@ -79,7 +81,8 @@ RUN set -x \ && cd "$builddir" \ && cmake "/usr/local/src/libwebsockets-$WEBSOCKETS_VERSION" \ && make "$PARALLELMFLAGS" install \ - && rm -rf "$builddir" + && rm -rf "$builddir" \ + && apk del .build-deps ARG JANSSON_VERSION=2.12 diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index cbdc241..383de3a 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -65,7 +65,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apt purge -y $builddeps -ARG WEBSOCKETS_VERSION=3.2.0 +ARG WEBSOCKETS_VERSION=4.0.1 RUN set -x \ && apt install --yes --no-install-recommends \ diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index 4eca9a6..2e7c5a3 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -71,9 +71,11 @@ RUN set -x \ && rm -rf "$builddir" \ && apk del .build-deps -ARG WEBSOCKETS_VERSION=3.2.0 +ARG WEBSOCKETS_VERSION=4.0.1 RUN set -x \ + && builddeps="linux-headers" \ + && apk add --no-cache --virtual .build-deps $builddeps \ && apk add --no-cache \ ca-certificates \ openssl \ @@ -83,7 +85,8 @@ RUN set -x \ && cd "$builddir" \ && cmake "/usr/local/src/libwebsockets-$WEBSOCKETS_VERSION" \ && make "$PARALLELMFLAGS" install \ - && rm -rf "$builddir" + && rm -rf "$builddir" \ + && apk del .build-deps ARG JANSSON_VERSION=2.12 diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index a9da298..08e3c7d 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -68,7 +68,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apt purge -y $builddeps -ARG WEBSOCKETS_VERSION=3.2.0 +ARG WEBSOCKETS_VERSION=4.0.1 RUN set -x \ && apt install --yes --no-install-recommends \ diff --git a/doc/build.md b/doc/build.md index fe16a11..6adb6f2 100644 --- a/doc/build.md +++ b/doc/build.md @@ -58,9 +58,9 @@ To install libfuse, meson is needed. Please refer to [meson quick guide](https:/ #### libwebsockets - wget -O libwebsockets-3.2.0.tar.gz https://github.com/warmcat/libwebsockets/archive/v3.2.0.tar.gz - tar -xf libwebsockets-3.2.0.tar.gz - cd libwebsockets-3.2.0 + wget -O libwebsockets-4.0.1.tar.gz https://github.com/warmcat/libwebsockets/archive/v4.0.1.tar.gz + tar -xf libwebsockets-4.0.1.tar.gz + cd libwebsockets-4.0.1 mkdir .build cd .build cmake .. From 357ca12e65a30c88a8d133163fa8d372bc8c99ed Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 6 Apr 2020 20:44:18 +0200 Subject: [PATCH 130/138] removed server timeout (breaking change) --- include/webfuse/adapter/server.h | 6 +----- include/webfuse/provider/client.h | 6 +----- lib/webfuse/adapter/api.c | 3 +-- lib/webfuse/provider/api.c | 3 +-- test/webfuse/tests/integration/provider.cc | 4 ++-- test/webfuse/tests/integration/server.cc | 4 ++-- 6 files changed, 8 insertions(+), 18 deletions(-) diff --git a/include/webfuse/adapter/server.h b/include/webfuse/adapter/server.h index 150ded5..f46f3ef 100644 --- a/include/webfuse/adapter/server.h +++ b/include/webfuse/adapter/server.h @@ -46,16 +46,12 @@ extern WF_API void wf_server_dispose( /// This function must be invoked in a loop while the server is running. It /// makes the server wait for the next event and processes it. /// -/// \note timeout_ms is no longer used -/// /// \param server pointer to server -/// \param timeout_ms unused; set to 0; used for backward compatibility /// /// \see wf_server_interrupt //------------------------------------------------------------------------------ extern WF_API void wf_server_service( - struct wf_server * server, - int timeout_ms); + struct wf_server * server); //------------------------------------------------------------------------------ /// \brief Interrupts wf_server_service diff --git a/include/webfuse/provider/client.h b/include/webfuse/provider/client.h index 0f6ba4f..1848717 100644 --- a/include/webfuse/provider/client.h +++ b/include/webfuse/provider/client.h @@ -78,16 +78,12 @@ extern WFP_API void wfp_client_dispose( /// This function must be invoked in a loop while the client is running. It /// makes the server wait for the next event and processes it. /// -/// \note timeout is ignored -/// /// \param client pointer to client -/// \param timeout_ms unused; set to 0; for backward compatibilty /// /// \see wfp_client_interrupt //------------------------------------------------------------------------------ extern WFP_API void wfp_client_service( - struct wfp_client * client, - int timeout_ms); + struct wfp_client * client); //------------------------------------------------------------------------------ /// \brief interrupt wfp_client_service diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 72ab6bc..5049e16 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -23,8 +23,7 @@ void wf_server_dispose( } void wf_server_service( - struct wf_server * server, - int WF_UNUSED_PARAM(imeout_ms)) + struct wf_server * server) { wf_impl_server_service(server); } diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index dc42fba..0c5f164 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -231,8 +231,7 @@ void wfp_client_dispose( } void wfp_client_service( - struct wfp_client * client, - int WF_UNUSED_PARAM(timeout_ms)) + struct wfp_client * client) { wfp_impl_client_service(client); } diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index e635c9b..ada19b8 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -30,7 +30,7 @@ public: wfp_client_connect(client, url); while (!wfp_impl_client_is_connected(client)) { - wfp_client_service(client, 100); + wfp_client_service(client); } thread = std::thread(Run, this); @@ -65,7 +65,7 @@ private: { while (!context->IsShutdownRequested()) { - wfp_client_service(context->client, 100); + wfp_client_service(context->client); } } diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index 8f15161..50badcc 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -70,7 +70,7 @@ public: while (!wf_impl_server_is_operational(server)) { - wf_server_service(server, 100); + wf_server_service(server); } thread = std::thread(Run, this); @@ -104,7 +104,7 @@ private: { while (!context->IsShutdownRequested()) { - wf_server_service(context->server, 100); + wf_server_service(context->server); } } From 431e3c027bd173b06693ba04598bae0d76a663c6 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 6 Apr 2020 21:44:24 +0200 Subject: [PATCH 131/138] removed dead code --- lib/webfuse/adapter/impl/filesystem.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 0c321e9..a033190 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -130,9 +130,4 @@ void wf_impl_filesystem_process_request( { fuse_session_process_buf(filesystem->session, &filesystem->buffer); } - else if (-EINTR != result) - { - // ToDo - } - } From 8539ce9338193075b9f7d33a4f3a0a964ab6e959 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 19:34:19 +0200 Subject: [PATCH 132/138] clone mountpoint factory --- lib/webfuse/adapter/impl/mountpoint_factory.c | 5 +---- lib/webfuse/adapter/impl/mountpoint_factory.h | 2 +- lib/webfuse/adapter/impl/server_config.c | 4 +--- lib/webfuse/adapter/impl/server_protocol.c | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.c b/lib/webfuse/adapter/impl/mountpoint_factory.c index 2da5db3..3062888 100644 --- a/lib/webfuse/adapter/impl/mountpoint_factory.c +++ b/lib/webfuse/adapter/impl/mountpoint_factory.c @@ -20,15 +20,12 @@ wf_impl_mountpoint_factory_init( } void -wf_impl_mountpoint_factory_move( +wf_impl_mountpoint_factory_clone( struct wf_impl_mountpoint_factory * factory, struct wf_impl_mountpoint_factory * other) { other->create_mountpoint = factory->create_mountpoint; other->user_data = factory->user_data; - - factory->create_mountpoint = NULL; - factory->user_data = NULL; } bool diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.h b/lib/webfuse/adapter/impl/mountpoint_factory.h index 63bbbfc..8675879 100644 --- a/lib/webfuse/adapter/impl/mountpoint_factory.h +++ b/lib/webfuse/adapter/impl/mountpoint_factory.h @@ -26,7 +26,7 @@ wf_impl_mountpoint_factory_init( void * user_data); extern void -wf_impl_mountpoint_factory_move( +wf_impl_mountpoint_factory_clone( struct wf_impl_mountpoint_factory * factory, struct wf_impl_mountpoint_factory * other); diff --git a/lib/webfuse/adapter/impl/server_config.c b/lib/webfuse/adapter/impl/server_config.c index ab214f3..4233094 100644 --- a/lib/webfuse/adapter/impl/server_config.c +++ b/lib/webfuse/adapter/impl/server_config.c @@ -48,9 +48,7 @@ void wf_impl_server_config_clone( clone->port = config->port; wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators); - - // ToDo: remove this: move is not clone :-/ - wf_impl_mountpoint_factory_move(&config->mountpoint_factory, &clone->mountpoint_factory); + wf_impl_mountpoint_factory_clone(&config->mountpoint_factory, &clone->mountpoint_factory); } struct wf_server_config * wf_impl_server_config_create(void) diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index d97c9a8..1996c67 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -216,7 +216,7 @@ void wf_impl_server_protocol_init( { protocol->is_operational = false; - wf_impl_mountpoint_factory_move(mountpoint_factory, &protocol->mountpoint_factory); + wf_impl_mountpoint_factory_clone(mountpoint_factory, &protocol->mountpoint_factory); protocol->timer_manager = wf_timer_manager_create(); wf_impl_session_manager_init(&protocol->session_manager); From 36f2b82a67642d2ecf074129d819029b26455c8e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 19:43:10 +0200 Subject: [PATCH 133/138] fix: added missing call of mock object --- test/webfuse/tests/core/jsonrpc/test_proxy.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/test/webfuse/tests/core/jsonrpc/test_proxy.cc b/test/webfuse/tests/core/jsonrpc/test_proxy.cc index bdc8a15..e594e89 100644 --- a/test/webfuse/tests/core/jsonrpc/test_proxy.cc +++ b/test/webfuse/tests/core/jsonrpc/test_proxy.cc @@ -396,6 +396,7 @@ TEST(wf_jsonrpc_proxy, swallow_timeout_if_no_request_pending) EXPECT_CALL(timer_api, wf_timer_create(_, _, _)) .Times(1) .WillOnce(DoAll(SaveArg<1>(&on_timer), SaveArg<2>(&timer_context), Return(nullptr))); + EXPECT_CALL(timer_api, wf_timer_dispose(_)).Times(1); SendContext send_context; void * send_data = reinterpret_cast(&send_context); From 3eb5dc89a79d219d70edaaf6c3f046ecf672778a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 20:37:50 +0200 Subject: [PATCH 134/138] added implementation of wfp_client_disconnect --- include/webfuse/provider/client_protocol.h | 15 ++++++++++++++- lib/webfuse/provider/api.c | 6 ++++++ lib/webfuse/provider/impl/client.c | 4 +--- lib/webfuse/provider/impl/client_protocol.c | 14 ++++++++++++++ lib/webfuse/provider/impl/client_protocol.h | 3 +++ test/webfuse/tests/integration/provider.cc | 6 ++++++ .../tests/provider/test_client_protocol.cc | 18 +++++++++++++++++- 7 files changed, 61 insertions(+), 5 deletions(-) diff --git a/include/webfuse/provider/client_protocol.h b/include/webfuse/provider/client_protocol.h index ab1ba85..8108030 100644 --- a/include/webfuse/provider/client_protocol.h +++ b/include/webfuse/provider/client_protocol.h @@ -89,12 +89,25 @@ extern WFP_API void wfp_client_protocol_init_lws( /// \see wfp_connected_fn /// \see wfp_client_config_set_onconnected //------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ extern WFP_API void wfp_client_protocol_connect( struct wfp_client_protocol * protocol, struct lws_context * context, char const * url); +//------------------------------------------------------------------------------ +/// \brief Disconnects the protocol from a remote webfuse adapter server. +/// +/// \note This call starts to disconnect. A callback is invoked, +/// when the connection is estanlished. +/// +/// \param protocol pointer to protocol +/// +/// \see wfp_connected_fn +/// \see wfp_client_config_set_ondisconnected +//------------------------------------------------------------------------------ +extern WFP_API void wfp_client_protocol_disconnect( + struct wfp_client_protocol * protocol); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 0c5f164..0c916d2 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -202,6 +202,12 @@ void wfp_client_protocol_connect( wfp_impl_client_protocol_connect(protocol, context, url); } +void wfp_client_protocol_disconnect( + struct wfp_client_protocol * protocol) +{ + wfp_impl_client_protocol_disconnect(protocol); +} + // client diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index 9f45a5a..e7c6e81 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -79,9 +79,7 @@ void wfp_impl_client_connect( void wfp_impl_client_disconnect( struct wfp_client * client) { - (void) client; - - // ToDo: implement me + wfp_impl_client_protocol_disconnect(&client->protocol); } bool wfp_impl_client_is_connected( diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index a85514a..db78137 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -324,3 +324,17 @@ void wfp_impl_client_protocol_connect( } } + +void wfp_impl_client_protocol_disconnect( + struct wfp_client_protocol * protocol) +{ + if (protocol->is_connected) + { + protocol->is_shutdown_requested = true; + lws_callback_on_writable(protocol->wsi); + } + else + { + protocol->provider.disconnected(protocol->user_data); + } +} diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index af5c74b..d6dd8ab 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -53,6 +53,9 @@ extern void wfp_impl_client_protocol_connect( struct lws_context * context, char const * url); +extern void wfp_impl_client_protocol_disconnect( + struct wfp_client_protocol * protocol); + #ifdef __cplusplus } #endif diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index ada19b8..e813b4d 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -67,6 +67,12 @@ private: { wfp_client_service(context->client); } + + wfp_client_disconnect(context->client); + while (wfp_impl_client_is_connected(context->client)) + { + wfp_client_service(context->client); + } } std::mutex shutdown_lock; diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 3563949..2035b0f 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -52,6 +52,11 @@ public: server->waitForConnection(); } + void Disconnect() + { + wfp_client_protocol_disconnect(protocol); + } + void SendToClient(json_t * request) { server->sendMessage(request); @@ -166,6 +171,16 @@ TEST(client_protocol, connect) if (HasFatalFailure()) { return; } } +TEST(client_protocol, disconnect_without_connect) +{ + MockProviderClient provider; + ClientProtocolFixture fixture(provider); + + EXPECT_CALL(provider, OnDisconnected()).Times(1); + + fixture.Disconnect(); +} + TEST(client_protocol, connect_with_username_authentication) { MockProviderClient provider; @@ -184,7 +199,6 @@ TEST(client_protocol, connect_with_username_authentication) std::string filesystem; fixture.AwaitAddFilesystem(filesystem); if (HasFatalFailure()) { return; } - } TEST(client_protocol, getattr) @@ -216,4 +230,6 @@ TEST(client_protocol, getattr) ASSERT_TRUE(json_is_object(response)); json_decref(response); + + fixture.Disconnect(); } \ No newline at end of file From 69af19193aae8959a970804bc3e30ea89d147bd3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 20:52:50 +0200 Subject: [PATCH 135/138] removed wfp_client_ontimer (breaking change) --- include/webfuse/provider/client_config.h | 20 -------------------- lib/webfuse/provider/api.c | 7 ------- lib/webfuse/provider/impl/client_config.c | 7 ------- lib/webfuse/provider/impl/client_config.h | 4 ---- lib/webfuse/provider/impl/provider.c | 10 ---------- lib/webfuse/provider/impl/provider.h | 4 ---- test/webfuse/mocks/mock_provider.cc | 8 -------- test/webfuse/mocks/mock_provider_client.cc | 8 -------- test/webfuse/mocks/mock_provider_client.hpp | 2 -- 9 files changed, 70 deletions(-) diff --git a/include/webfuse/provider/client_config.h b/include/webfuse/provider/client_config.h index fe138f6..26654bc 100644 --- a/include/webfuse/provider/client_config.h +++ b/include/webfuse/provider/client_config.h @@ -45,14 +45,6 @@ typedef void wfp_connected_fn( typedef void wfp_disconnected_fn( void * user_data); -//------------------------------------------------------------------------------ -/// \brief Callback to signal when a timer event occued. -/// -/// \param user_data user defined context -//------------------------------------------------------------------------------ -typedef void wfp_ontimer_fn( - void * user_data); - //------------------------------------------------------------------------------ /// \brief Creates a new client configuration. /// @@ -145,18 +137,6 @@ extern WFP_API void wfp_client_config_set_ondisconnected( struct wfp_client_config * config, wfp_disconnected_fn * handler); -//------------------------------------------------------------------------------ -/// \brief Sets ontimer handler. -/// -/// The handler is invoked, when a timer event occured. -/// -/// \param config pointer to client configuration -/// \param handler pointer to handler -//------------------------------------------------------------------------------ -extern WFP_API void wfp_client_config_set_ontimer( - struct wfp_client_config * config, - wfp_ontimer_fn * handler); - //------------------------------------------------------------------------------ /// \brief Sets onlookup handler. /// diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 0c916d2..ad288bd 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -116,13 +116,6 @@ void wfp_client_config_set_ondisconnected( wfp_impl_client_config_set_ondisconnected(config, handler); } -void wfp_client_config_set_ontimer( - struct wfp_client_config * config, - wfp_ontimer_fn * handler) -{ - wfp_impl_client_config_set_ontimer(config, handler); -} - void wfp_client_config_set_onlookup( struct wfp_client_config * config, wfp_lookup_fn * handler) diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c index 9e6489b..cd7b015 100644 --- a/lib/webfuse/provider/impl/client_config.c +++ b/lib/webfuse/provider/impl/client_config.c @@ -69,13 +69,6 @@ void wfp_impl_client_config_set_ondisconnected( config->provider.disconnected = handler; } -void wfp_impl_client_config_set_ontimer( - struct wfp_client_config * config, - wfp_ontimer_fn * handler) -{ - config->provider.ontimer = handler; -} - void wfp_impl_client_config_set_onlookup( struct wfp_client_config * config, wfp_lookup_fn * handler) diff --git a/lib/webfuse/provider/impl/client_config.h b/lib/webfuse/provider/impl/client_config.h index a15ff87..9e588b0 100644 --- a/lib/webfuse/provider/impl/client_config.h +++ b/lib/webfuse/provider/impl/client_config.h @@ -47,10 +47,6 @@ extern void wfp_impl_client_config_set_ondisconnected( struct wfp_client_config * config, wfp_disconnected_fn * handler); -extern void wfp_impl_client_config_set_ontimer( - struct wfp_client_config * config, - wfp_ontimer_fn * handler); - extern void wfp_impl_client_config_set_onlookup( struct wfp_client_config * config, wfp_lookup_fn * handler); diff --git a/lib/webfuse/provider/impl/provider.c b/lib/webfuse/provider/impl/provider.c index c9c159f..397a563 100644 --- a/lib/webfuse/provider/impl/provider.c +++ b/lib/webfuse/provider/impl/provider.c @@ -66,7 +66,6 @@ void wfp_impl_provider_init( provider->read = &wfp_impl_read_default; provider->connected = &wfp_impl_connected_default; provider->disconnected = &wfp_impl_disconnected_default; - provider->ontimer = &wfp_impl_ontimer_default; provider->get_credentials = NULL; } @@ -82,7 +81,6 @@ void wfp_impl_provider_init_from_prototype( provider->read = prototype->read; provider->connected = prototype->connected; provider->disconnected = prototype->disconnected; - provider->ontimer = prototype->ontimer; provider->get_credentials = prototype->get_credentials; } @@ -119,14 +117,6 @@ void wfp_impl_disconnected_default( // empty } -void wfp_impl_ontimer_default( - void * user_data) -{ - (void) user_data; - - // empty -} - bool wfp_impl_provider_is_authentication_enabled( struct wfp_provider * provider) { diff --git a/lib/webfuse/provider/impl/provider.h b/lib/webfuse/provider/impl/provider.h index 1e8ec1f..aff4420 100644 --- a/lib/webfuse/provider/impl/provider.h +++ b/lib/webfuse/provider/impl/provider.h @@ -18,7 +18,6 @@ struct wfp_provider { wfp_connected_fn * connected; wfp_disconnected_fn * disconnected; - wfp_ontimer_fn * ontimer; wfp_lookup_fn * lookup; wfp_getattr_fn * getattr; wfp_readdir_fn * readdir; @@ -56,9 +55,6 @@ extern void wfp_impl_connected_default( extern void wfp_impl_disconnected_default( void * user_data); -extern void wfp_impl_ontimer_default( - void * user_data); - #ifdef __cplusplus } #endif diff --git a/test/webfuse/mocks/mock_provider.cc b/test/webfuse/mocks/mock_provider.cc index a81b302..1aab4cf 100644 --- a/test/webfuse/mocks/mock_provider.cc +++ b/test/webfuse/mocks/mock_provider.cc @@ -18,13 +18,6 @@ static void webfuse_test_MockProvider_disconnected( provider->disconnected(); } -static void webfuse_test_MockProvider_on_timer( - void * user_data) -{ - auto * provider = reinterpret_cast(user_data); - provider->on_timer(); -} - static void webfuse_test_MockProvider_lookup( wfp_request * request, ino_t parent, @@ -100,7 +93,6 @@ static wfp_provider const webfuse_test_MockProvider = { &webfuse_test_MockProvider_connected, &webfuse_test_MockProvider_disconnected, - &webfuse_test_MockProvider_on_timer, &webfuse_test_MockProvider_lookup, &webfuse_test_MockProvider_getattr, &webfuse_test_MockProvider_readdir, diff --git a/test/webfuse/mocks/mock_provider_client.cc b/test/webfuse/mocks/mock_provider_client.cc index ff73bd9..779c0ef 100644 --- a/test/webfuse/mocks/mock_provider_client.cc +++ b/test/webfuse/mocks/mock_provider_client.cc @@ -21,13 +21,6 @@ static void webfuse_test_iproviderclient_ondisconnected( self->OnDisconnected(); } -static void webfuse_test_iproviderclient_ontimer( - void * user_data) -{ - auto * self = reinterpret_cast(user_data); - self->OnTimer(); -} - static void webfuse_test_iproviderclient_onlookup( struct wfp_request * request, ino_t parent, @@ -207,7 +200,6 @@ void IProviderClient::AttachTo(wfp_client_config * config, bool enableAuthentica wfp_client_config_set_userdata(config, self); wfp_client_config_set_onconnected(config, &webfuse_test_iproviderclient_onconnected); wfp_client_config_set_ondisconnected(config, &webfuse_test_iproviderclient_ondisconnected); - wfp_client_config_set_ontimer(config, &webfuse_test_iproviderclient_ontimer); wfp_client_config_set_onlookup(config, &webfuse_test_iproviderclient_onlookup); wfp_client_config_set_ongetattr(config, &webfuse_test_iproviderclient_ongetattr); diff --git a/test/webfuse/mocks/mock_provider_client.hpp b/test/webfuse/mocks/mock_provider_client.hpp index 57db042..b60e743 100644 --- a/test/webfuse/mocks/mock_provider_client.hpp +++ b/test/webfuse/mocks/mock_provider_client.hpp @@ -23,7 +23,6 @@ namespace webfuse_test virtual ~IProviderClient() = default; virtual void OnConnected() = 0; virtual void OnDisconnected() = 0; - virtual void OnTimer() = 0; virtual void Lookup(ino_t parent, char const * name, struct stat * result) = 0; virtual void GetAttr(ino_t inode, struct stat * buffer) = 0; virtual void ReadDir(ino_t directory, wfp_dirbuffer * buffer) = 0; @@ -41,7 +40,6 @@ namespace webfuse_test ~MockProviderClient() override = default; MOCK_METHOD0( OnConnected, void()); MOCK_METHOD0( OnDisconnected, void()); - MOCK_METHOD0( OnTimer, void()); MOCK_METHOD3( Lookup, void(ino_t parent, char const * name, struct stat * result)); MOCK_METHOD2( GetAttr, void(ino_t inode, struct stat * buffer)); MOCK_METHOD2( ReadDir, void(ino_t directory, wfp_dirbuffer * buffer)); From e2e892740087b644debc99c4c801587e2b9495a1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 22 May 2020 22:39:40 +0200 Subject: [PATCH 136/138] added basic meson build info --- .gitignore | 2 ++ meson.build | 75 ++++++++++++++++++++++++++++++++++++++++ subprojects/jansson.wrap | 10 ++++++ 3 files changed, 87 insertions(+) create mode 100644 meson.build create mode 100644 subprojects/jansson.wrap diff --git a/.gitignore b/.gitignore index 3aba301..08038c6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /.deps/ /.settings/language.settings.xml /doc/api +/subprojects/* +!/subprojects/*.wrap \ No newline at end of file diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..1b467e6 --- /dev/null +++ b/meson.build @@ -0,0 +1,75 @@ +project('webfuse', 'c', 'cpp', version: '0.3.0', license: 'LGPL-3.0+') + +libwebsockets_dep = dependency('libwebsockets', version: '>=4.0.1') +jansson_dep = dependency('jansson', version: '>=2.11', fallback: ['jansson', 'jansson_dep']) + +pkg_config = import('pkgconfig') + +inc_dir = include_directories('include') +private_inc_dir = include_directories('include', 'lib') + +webfuse_core = static_library('webfuse_core', + 'lib/webfuse/core/slist.c', + 'lib/webfuse/core/message.c', + 'lib/webfuse/core/message_queue.c', + 'lib/webfuse/core/status.c', + 'lib/webfuse/core/string.c', + 'lib/webfuse/core/base64.c', + 'lib/webfuse/core/lws_log.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', + c_args: ['-fvisibility=hidden'], + include_directories: private_inc_dir, + dependencies: [jansson_dep, libwebsockets_dep]) + +webfuse_core_dep = declare_dependency( + include_directories: inc_dir, + link_with: webfuse_core) + +webfuse_provider_static = static_library('webfuse_provider', + 'lib/webfuse/provider/api.c', + 'lib/webfuse/provider/impl/url.c', + 'lib/webfuse/provider/impl/client.c', + 'lib/webfuse/provider/impl/client_config.c', + 'lib/webfuse/provider/impl/client_protocol.c', + 'lib/webfuse/provider/impl/provider.c', + 'lib/webfuse/provider/impl/request.c', + 'lib/webfuse/provider/impl/dirbuffer.c', + 'lib/webfuse/provider/impl/credentials.c', + 'lib/webfuse/provider/impl/operation/lookup.c', + 'lib/webfuse/provider/impl/operation/getattr.c', + 'lib/webfuse/provider/impl/operation/readdir.c', + 'lib/webfuse/provider/impl/operation/open.c', + 'lib/webfuse/provider/impl/operation/close.c', + 'lib/webfuse/provider/impl/operation/read.c', + c_args: ['-fvisibility=hidden'], + include_directories: private_inc_dir, + dependencies: [webfuse_core_dep]) + +webfuse_provider_static_dep = declare_dependency( + include_directories: inc_dir, + link_with: webfuse_provider_static) + +webfuse_provider = shared_library('webfuse_provider', + 'lib/webfuse/provider/api.c', + version: meson.project_version(), + c_args: ['-fvisibility=hidden', '-DWFP_API=WFP_EXPORT'], + include_directories: private_inc_dir, + dependencies: [webfuse_provider_static_dep]) + +pkg_config.generate( + libraries: [webfuse_provider, jansson_dep, libwebsockets_dep], + subdirs: '.', + version: meson.project_version(), + name: 'libwebfuse_provider', + filebase: 'webfuse_provider', + description: 'Provider library for websockets filesystem') \ No newline at end of file diff --git a/subprojects/jansson.wrap b/subprojects/jansson.wrap new file mode 100644 index 0000000..6282afd --- /dev/null +++ b/subprojects/jansson.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory = jansson-2.11 + +source_url = http://www.digip.org/jansson/releases/jansson-2.11.tar.bz2 +source_filename = jansson-2.11.tar.bz2 +source_hash = 783132e2fc970feefc2fa54199ef65ee020bd8e0e991a78ea44b8586353a0947 + +patch_url = https://wrapdb.mesonbuild.com/v1/projects/jansson/2.11/3/get_zip +patch_filename = jansson-2.11-3-wrap.zip +patch_hash = 0bcac510994890048d42658c674e33dd7d88715fc1e3bf49d10012f57b0e0020 \ No newline at end of file From a311f5b51755fb1a5a7f12613720e5a863fa9625 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 23 May 2020 18:45:34 +0200 Subject: [PATCH 137/138] added adapter and unit test to meson build --- doc/build.md | 10 +++ meson.build | 191 ++++++++++++++++++++++++++++++++++++++++- subprojects/fuse3.wrap | 7 ++ subprojects/gtest.wrap | 10 +++ 4 files changed, 215 insertions(+), 3 deletions(-) create mode 100644 subprojects/fuse3.wrap create mode 100644 subprojects/gtest.wrap diff --git a/doc/build.md b/doc/build.md index 6adb6f2..a82b31b 100644 --- a/doc/build.md +++ b/doc/build.md @@ -25,6 +25,16 @@ in order to reduce build dependencies. - **WIHTOU_PROVIDER**: omit provider library `cmake -DWITHOUT_PROVIDER=ON` +## Build using Meson (experimental) + +_Note: Meson build support is experimental. Do not rely on it._ + + meson .build + cd .build + ninja build + +_Note: Build options are not supported yet._ + ## Create API documentation To create API documentation, you must install doxygen and dot first. diff --git a/meson.build b/meson.build index 1b467e6..f2b8c01 100644 --- a/meson.build +++ b/meson.build @@ -2,9 +2,14 @@ project('webfuse', 'c', 'cpp', version: '0.3.0', license: 'LGPL-3.0+') libwebsockets_dep = dependency('libwebsockets', version: '>=4.0.1') jansson_dep = dependency('jansson', version: '>=2.11', fallback: ['jansson', 'jansson_dep']) +libfuse_dep = dependency('fuse3', version: '>=3.8.0', fallback: ['fuse3', 'libfuse_dep']) +gtest_dep = dependency('gtest', version: '>=1.10.0', fallback: ['gtest', 'gtest_dep']) +gmock_main_dep = dependency('gmock_main', version: '>=1.10.0', fallback: ['gtest', 'gmock_main_main_dep']) pkg_config = import('pkgconfig') +# Webfuse core + inc_dir = include_directories('include') private_inc_dir = include_directories('include', 'lib') @@ -33,7 +38,12 @@ webfuse_core = static_library('webfuse_core', webfuse_core_dep = declare_dependency( include_directories: inc_dir, - link_with: webfuse_core) + link_with: webfuse_core, + dependencies: [jansson_dep, libwebsockets_dep]) + +install_subdir('include/webfuse/core', install_dir: 'include/webfuse') + +# Webfuse provider webfuse_provider_static = static_library('webfuse_provider', 'lib/webfuse/provider/api.c', @@ -64,7 +74,16 @@ webfuse_provider = shared_library('webfuse_provider', version: meson.project_version(), c_args: ['-fvisibility=hidden', '-DWFP_API=WFP_EXPORT'], include_directories: private_inc_dir, - dependencies: [webfuse_provider_static_dep]) + dependencies: [webfuse_provider_static_dep], + install: true) + +webfuse_provider_dep = declare_dependency( + include_directories: inc_dir, + link_with: [webfuse_provider], + dependencies: [libwebsockets_dep, jansson_dep]) + +install_headers('include/webfuse_provider.h', subdir: 'webfuse') +install_subdir('include/webfuse/provider', install_dir: 'include/webfuse') pkg_config.generate( libraries: [webfuse_provider, jansson_dep, libwebsockets_dep], @@ -72,4 +91,170 @@ pkg_config.generate( version: meson.project_version(), name: 'libwebfuse_provider', filebase: 'webfuse_provider', - description: 'Provider library for websockets filesystem') \ No newline at end of file + description: 'Provider library for websockets filesystem') + +# Webfuse adapter + +webfuse_adapter_static = static_library('webfuse_adapter', + 'lib/webfuse/adapter/api.c', + 'lib/webfuse/adapter/impl/filesystem.c', + 'lib/webfuse/adapter/impl/server.c', + 'lib/webfuse/adapter/impl/server_config.c', + 'lib/webfuse/adapter/impl/server_protocol.c', + 'lib/webfuse/adapter/impl/session.c', + 'lib/webfuse/adapter/impl/session_manager.c', + 'lib/webfuse/adapter/impl/authenticator.c', + 'lib/webfuse/adapter/impl/authenticators.c', + 'lib/webfuse/adapter/impl/credentials.c', + 'lib/webfuse/adapter/impl/mountpoint.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/getattr.c', + 'lib/webfuse/adapter/impl/operation/readdir.c', + 'lib/webfuse/adapter/impl/operation/open.c', + 'lib/webfuse/adapter/impl/operation/close.c', + 'lib/webfuse/adapter/impl/operation/read.c', + c_args: ['-fvisibility=hidden'], + include_directories: private_inc_dir, + dependencies: [webfuse_core_dep, libfuse_dep]) + +webfuse_adapter_static_dep = declare_dependency( + include_directories: inc_dir, + link_with: [webfuse_adapter_static], + dependencies: [libfuse_dep]) + +webfuse_adapter = shared_library('webfuse_adapter', + 'lib/webfuse/adapter/api.c', + version: meson.project_version(), + c_args: ['-fvisibility=hidden', '-DWF_API=WF_EXPORT'], + include_directories: private_inc_dir, + dependencies: [webfuse_adapter_static_dep, libfuse_dep], + install: true) + +webfuse_adapter_dep = declare_dependency( + include_directories: inc_dir, + link_with: [webfuse_adapter], + dependencies: [libfuse_dep, libwebsockets_dep, jansson_dep]) + +install_headers('include/webfuse_adapter.h', subdir: 'webfuse') +install_subdir('include/webfuse/adapter', install_dir: 'include/webfuse') + +pkg_config.generate( + libraries: [webfuse_adapter, jansson_dep, libwebsockets_dep, libfuse_dep], + subdirs: '.', + version: meson.project_version(), + name: 'libwebfuse_adapter', + filebase: 'webfuse_adapter', + description: 'Websockets filesystem server library') + +# Unit Tests + +fscheck = executable('fs_check', + 'test/webfuse/tests/integration/fs_check.c') + +openssl = find_program('openssl') +test_server_certs = custom_target('test_server_certs', + output: ['server-key.pem', 'server-cert.pem'], + command: [openssl, 'req', '-x509', '-newkey', 'rsa:4096', '-keyout', 'server-key.pem', '-out', 'server-cert.pem', '-days', '365', '-nodes', '-batch', '-subj', '/CN=localhost']) +test_client_certs = custom_target('test_client_certs', + output: ['client-key.pem', 'client-cert.pem'], + command: [openssl, 'req', '-x509', '-newkey', 'rsa:4096', '-keyout', 'client-key.pem', '-out', 'client-cert.pem', '-days', '365', '-nodes', '-batch', '-subj', '/CN=localhost']) + +test_certs_dep = declare_dependency( + sources: [test_server_certs, test_client_certs]) + +alltests = executable('alltests', + 'test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc', + 'test/webfuse/tests/core/jsonrpc/mock_timer.cc', + 'test/webfuse/tests/core/jsonrpc/test_is_request.cc', + 'test/webfuse/tests/core/jsonrpc/test_request.cc', + 'test/webfuse/tests/core/jsonrpc/test_is_response.cc', + 'test/webfuse/tests/core/jsonrpc/test_response.cc', + 'test/webfuse/tests/core/jsonrpc/test_server.cc', + 'test/webfuse/tests/core/jsonrpc/test_proxy.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/file_utils.cc', + 'test/webfuse/utils/timeout_watcher.cc', + 'test/webfuse/utils/path.c', + 'test/webfuse/utils/static_filesystem.c', + 'test/webfuse/utils/ws_server.cc', + 'test/webfuse/mocks/fake_invokation_context.cc', + 'test/webfuse/mocks/mock_authenticator.cc', + 'test/webfuse/mocks/mock_request.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_container_of.cc', + 'test/webfuse/tests/core/test_string.cc', + 'test/webfuse/tests/core/test_slist.cc', + 'test/webfuse/tests/core/test_base64.cc', + 'test/webfuse/tests/core/test_status.cc', + 'test/webfuse/tests/core/test_message.cc', + 'test/webfuse/tests/core/test_message_queue.cc', + 'test/webfuse/tests/adapter/test_server.cc', + 'test/webfuse/tests/adapter/test_server_config.cc', + 'test/webfuse/tests/adapter/test_credentials.cc', + 'test/webfuse/tests/adapter/test_authenticator.cc', + 'test/webfuse/tests/adapter/test_authenticators.cc', + 'test/webfuse/tests/adapter/test_mountpoint.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_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/file.cc', + 'test/webfuse/tests/integration/server.cc', + 'test/webfuse/tests/integration/provider.cc', + link_args: [ + '-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' + ], + include_directories: [private_inc_dir, 'test'], + dependencies: [ + webfuse_adapter_static_dep, + webfuse_provider_static_dep, + webfuse_core_dep, + libwebsockets_dep, + libfuse_dep, + jansson_dep, + gtest_dep, + gmock_main_dep, + test_certs_dep + ]) + +test('alltests', alltests) diff --git a/subprojects/fuse3.wrap b/subprojects/fuse3.wrap new file mode 100644 index 0000000..ccb34f5 --- /dev/null +++ b/subprojects/fuse3.wrap @@ -0,0 +1,7 @@ +[wrap-file] +directory = libfuse-fuse-3.8.0 + +source_url = https://github.com/libfuse/libfuse/archive/fuse-3.8.0.tar.gz +source_filename = fuse-3.8.0.tar.gz +source_hash = 1781225ba4d11d76eb105e02e54976939974547eb40bab4b4e91167854224024 + diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap new file mode 100644 index 0000000..d52b0b3 --- /dev/null +++ b/subprojects/gtest.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory = googletest-release-1.10.0 + +source_url = https://github.com/google/googletest/archive/release-1.10.0.zip +source_filename = gtest-1.10.0.zip +source_hash = 94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91 + +patch_url = https://wrapdb.mesonbuild.com/v1/projects/gtest/1.10.0/1/get_zip +patch_filename = gtest-1.10.0-1-wrap.zip +patch_hash = 04ff14e8880e4e465f6260221e9dfd56fea6bc7cce4c4aff0dc528e4a2c8f514 \ No newline at end of file From e57516b9404cde0072bceda1e211b36751e16c86 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 24 May 2020 08:31:59 +0200 Subject: [PATCH 138/138] updated libwebsockets to v4.0.10 --- Makefile | 4 ++-- build/amd64-alpine-builder.dockerfile | 2 +- build/amd64-ubuntu-builder.dockerfile | 2 +- build/arm32v7-alpine-builder.dockerfile | 2 +- build/arm32v7-ubuntu-builder.dockerfile | 2 +- doc/build.md | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index ad1d2f7..a606d7c 100644 --- a/Makefile +++ b/Makefile @@ -62,11 +62,11 @@ FETCH_TARGETS += $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz $(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 5f7c1062def710d8b60343524a18cc82 -WEBSOCKETS_VERSION ?= 4.0.1 +WEBSOCKETS_VERSION ?= 4.0.10 DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION) FETCH_TARGETS += $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: URL := https://github.com/warmcat/libwebsockets/archive/v$(WEBSOCKETS_VERSION).tar.gz -$(SKIP_MD5SUM)$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := b5f90b470f398abbcf66e4639ad0273a +$(SKIP_MD5SUM)$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := a1ce5a279fd06b2ce132c02c292df7aa JANSSON_VERSION ?= 2.12 DOCKER_BUILDARGS += JANSSON_VERSION=$(JANSSON_VERSION) diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index 6de467a..4503181 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -67,7 +67,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apk del .build-deps -ARG WEBSOCKETS_VERSION=4.0.1 +ARG WEBSOCKETS_VERSION=4.0.10 RUN set -x \ && builddeps="linux-headers" \ diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index 383de3a..f242163 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -65,7 +65,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apt purge -y $builddeps -ARG WEBSOCKETS_VERSION=4.0.1 +ARG WEBSOCKETS_VERSION=4.0.10 RUN set -x \ && apt install --yes --no-install-recommends \ diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index 2e7c5a3..3544867 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -71,7 +71,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apk del .build-deps -ARG WEBSOCKETS_VERSION=4.0.1 +ARG WEBSOCKETS_VERSION=4.0.10 RUN set -x \ && builddeps="linux-headers" \ diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index 08e3c7d..7204795 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -68,7 +68,7 @@ RUN set -x \ && rm -rf "$builddir" \ && apt purge -y $builddeps -ARG WEBSOCKETS_VERSION=4.0.1 +ARG WEBSOCKETS_VERSION=4.0.10 RUN set -x \ && apt install --yes --no-install-recommends \ diff --git a/doc/build.md b/doc/build.md index a82b31b..3aa6bec 100644 --- a/doc/build.md +++ b/doc/build.md @@ -68,9 +68,9 @@ To install libfuse, meson is needed. Please refer to [meson quick guide](https:/ #### libwebsockets - wget -O libwebsockets-4.0.1.tar.gz https://github.com/warmcat/libwebsockets/archive/v4.0.1.tar.gz - tar -xf libwebsockets-4.0.1.tar.gz - cd libwebsockets-4.0.1 + wget -O libwebsockets-4.0.10.tar.gz https://github.com/warmcat/libwebsockets/archive/v4.0.10.tar.gz + tar -xf libwebsockets-4.0.10.tar.gz + cd libwebsockets-4.0.10 mkdir .build cd .build cmake ..