From 39874f733aa693ecc0e258a40b123d62f1728e94 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 16 Feb 2019 16:08:17 +0100 Subject: [PATCH] added provider api --- CMakeLists.txt | 35 ++++++++++ include/wsfs_provider.h | 9 +++ include/wsfsp/api.h | 16 +++++ include/wsfsp/client.h | 44 ++++++++++++ include/wsfsp/client_protocol.h | 32 +++++++++ include/wsfsp/provider.h | 114 ++++++++++++++++++++++++++++++++ lib/wsfsp/client.c | 2 + 7 files changed, 252 insertions(+) create mode 100644 include/wsfs_provider.h create mode 100644 include/wsfsp/api.h create mode 100644 include/wsfsp/client.h create mode 100644 include/wsfsp/client_protocol.h create mode 100644 include/wsfsp/provider.h create mode 100644 lib/wsfsp/client.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ddc30b1..af48cf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,41 @@ install(FILES include/wsfs.h DESTINATION include) install(DIRECTORY include/wsfs DESTINATION include) install(FILES "${PROJECT_BINARY_DIR}/libfuse-wsfs.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) +#libwsfs-provider + +set(WSFS_PROVIDER_SOURCES + lib/wsfsp/client.c +) + +add_library(wsfs-provider SHARED ${WSFS_PROVIDER_SOURCES}) + +set_target_properties(wsfs-provider PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(wsfs-provider PROPERTIES SOVERSION 0) +set_target_properties(wsfs-provider PROPERTIES C_VISIBILITY_PRESET hidden) +set_target_properties(wsfs-provider PROPERTIES COMPILE_DEFINITIONS "WSFSP_API=WSFSP_EXPORT") + +target_include_directories(wsfs-provider PUBLIC lib ${EXTRA_INCLUDE_DIRS}) +target_compile_options(wsfs-provider PUBLIC ${EXTRA_CFLAGS}) + +file(WRITE "${PROJECT_BINARY_DIR}/libwsfs-provider.pc" +"prefix=\"${CMAKE_INSTALL_PREFIX}\" +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib${LIB_SUFFIX} +includedir=\${prefix}/include +Name: libwsfs-provider +Description: Provider library for websockets filesystem +Version: ${PROJECT_VERSION} + +Libs: -L\${libdir} -lwsfs-provider -l${LWS_LIBRARIES} -l${JANSSON_LIBRARIES} +Cflags: -I\${includedir}" +) + +install(TARGETS wsfs-provider DESTINATION lib${LIB_SUFFIX}) +install(FILES include/wsfs_provider.h DESTINATION include) +install(DIRECTORY include/wsfsp DESTINATION include) +install(FILES "${PROJECT_BINARY_DIR}/libwsfs-provider.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) + + # app if(NOT WITHOUT_EXAMPLE) diff --git a/include/wsfs_provider.h b/include/wsfs_provider.h new file mode 100644 index 0000000..6601a40 --- /dev/null +++ b/include/wsfs_provider.h @@ -0,0 +1,9 @@ +#ifndef _WSFSP_H +#define _WSFSP_H + +#include "wsfsp/api.h" +#include "wsfsp/provider.h" +#include "wsfsp/client.h" +#include "wsfsp/client_protocol.h" + +#endif diff --git a/include/wsfsp/api.h b/include/wsfsp/api.h new file mode 100644 index 0000000..c7e0554 --- /dev/null +++ b/include/wsfsp/api.h @@ -0,0 +1,16 @@ +#ifndef _WSFSP_API_H +#define _WSFSP_API_H + +#ifndef WSFSP_API +#define WSFSP_API +#endif + +#ifndef WSFSP_EXPORT +#ifdef __GNUC__ +#define WSFSP_EXPORT __attribute__ ((visibility ("default"))) +#else +#define WSFSP_EXPORT +#endif +#endif + +#endif diff --git a/include/wsfsp/client.h b/include/wsfsp/client.h new file mode 100644 index 0000000..4a08dd9 --- /dev/null +++ b/include/wsfsp/client.h @@ -0,0 +1,44 @@ +#ifndef _WSFSP_CLIENT_H +#define _WSFSP_CLIENT_H + +#include "wsfs/api.h" + +struct wsfs_provider; +struct wsfs_provider_client_config; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern WSFS_API struct wsfs_provider_client * wsfs_provider_client_create( + struct wsfs_provider * provider, + void * user_data); + +extern WSFS_API void wsfs_provider_client_connect( + struct wsfs_provider_client * client, + char const * url); + +extern WSFS_API void wsfs_provider_client_disconnect( + struct wsfs_provider_client * client); + +extern WSFS_API void wsfs_provider_client_settimeout( + struct wsfs_provider_client * client, + unsigned int timepoint); + +extern WSFS_API void wsfs_provider_client_dispose( + struct wsfs_provider_client * client); + +extern WSFS_API void wsfs_provider_client_run( + struct wsfs_provider_client * client); + +extern WSFS_API void wsfs_provider_client_shutdown( + struct wsfs_provider_client * client); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/wsfsp/client_protocol.h b/include/wsfsp/client_protocol.h new file mode 100644 index 0000000..1929b3e --- /dev/null +++ b/include/wsfsp/client_protocol.h @@ -0,0 +1,32 @@ +#ifndef _WSFSP_CLIENT_PROTOCOL_H +#define _WSFSP_CLIENT_PROTOCOL_H + +#include "wsfs/api.h" + +struct wsfsp_client_protocol; +struct wsfsp_provider; +struct lws_protocols; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern WSFSP_API struct wsfsp_client_protocol * wsfsp_client_protocol_create( + struct wsfsp_provider const * provider, + void * user_data); + +extern WSFSÜ_API void wsfsp_client_protocol_dispose( + struct wsfsp_client_protocol * protocol); + +extern WSFSÜ_API void wsfsp_client_protocol_init_lws( + struct wsfs_provider_client_protocol * protocol, + struct lws_protocols * lws_protocol); + +#ifdef __cplusplus +} +#endif + + + +#endif diff --git a/include/wsfsp/provider.h b/include/wsfsp/provider.h new file mode 100644 index 0000000..8556f4e --- /dev/null +++ b/include/wsfsp/provider.h @@ -0,0 +1,114 @@ +#ifndef _WSFSp_H +#define _WSFSp_H + +#ifndef __cplusplus +#include +#include +#else +#include +#include +using std::size_t; +#endif + +#include +#include +#include + + +struct wsfsp_request; +struct wsfs_dirbuffer; + +typedef void wsfsp_lookup_fn( + struct wsfsp_request * request, + ino_t parent, + char const * name, + void * user_data); + +typedef void wsfsp_getattr_fn( + struct wsfsp_request * request, + ino_t inode, + void * user_data); + +typedef void wsfsp_readdir_fn( + struct wsfsp_request * request, + ino_t directory, + struct wsfsp_dirbuffer * dirbuffer, + void * user_data); + +typedef void wsfsp_open_fn( + struct wsfsp_request * request, + ino_t inode, + int flags, + void * user_data); + +typedef void wsfsp_close_fn( + ino_t inode, + uint32_t handle, + int flags, + void * user_data); + +typedef void wsfsp_read_fn( + struct wsfsp_request * request, + ino_t inode, + uint32_t handle, + size_t offset, + size_t length, + void * user_data); + +typedef void wsfsp_connected_fn( + void * user_data); + +typedef void wsfsp_disconnected_fn( +void * user_data); + +typedef void wsfsp_ontimer_fn( + void * user_data); + +struct wsfsüp +{ + wsfsp_connected_fn * connected; + wsfsp_disconnected_fn * connected; + wsfsp_ontimer_fn * ontimer; + wsfsp_lookup_fn * lookup; + wsfsp_getattr_fn * getattr; + wsfsp_readdir_fn * readdir; + wsfsp_open_fn * open; + wsfsp_close_fn * close; + wsfsp_read_fn * read; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_respond_error( + struct wsfsp_request * request, + int status); + +extern void wsfsp_respond_lookup( + struct wsfsp_request * request, + struct wsfs_stat const * stat); + +extern void wsfsp_respond_getattr( + struct wsfsp_request * request, + struct stat const * stat); + +extern void wsfsp_respond_readdir( + struct wsfsp_request * request, + struct wsfsp_dirbuffer * dirbuffer); + +extern void wsfsp_respond_open( + struct wsfsp_request * request, + uint32_t handle); + +extern void wsfsp_respond_read( + struct wsfsp_request * request, + char const * data, + size_t length); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsfsp/client.c b/lib/wsfsp/client.c new file mode 100644 index 0000000..bd6577b --- /dev/null +++ b/lib/wsfsp/client.c @@ -0,0 +1,2 @@ +#include "wsfsp/client.h" +