1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

feat(API wrapper): separates implementation from public API

* moves implementation to impl subdirectory
* adds prefix _impl to implementation symbols
* removes double compilation for shared and static libraries
* fixes include guards
* fixes usage of extern "C"
This commit is contained in:
Falk Werner 2019-03-26 15:35:33 +01:00 committed by GitHub
parent 48185776b6
commit 1c9d1c8420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
146 changed files with 3043 additions and 2390 deletions

View File

@ -43,45 +43,61 @@ set(EXTRA_CFLAGS
${JANSSON_CFLAGS_OTHER}
"-pthread"
)
# libwsfs-common
set(WSFS_COMMON_SOURCES
lib/wsfs/message.c
lib/wsfs/message_queue.c
lib/wsfs/status.c
# libwsfs-core
add_library(wsfs-core STATIC
lib/wsfs/core/message.c
lib/wsfs/core/message_queue.c
lib/wsfs/core/status.c
)
install(FILES include/wsfs/status.h DESTINATION include/wsfs)
set_target_properties(wsfs-core PROPERTIES OUTPUT_NAME wsfs-core)
target_include_directories(wsfs-core PUBLIC lib ${EXTRA_INCLUDE_DIRS})
target_compile_options(wsfs-core PUBLIC ${EXTRA_CFLAGS})
set_target_properties(wsfs-core PROPERTIES C_VISIBILITY_PRESET hidden)
install(DIRECTORY include/wsfs/core DESTINATION include/wsfs)
# libwsfs-adapter
set(WSFS_ADAPTER_SOURCES
lib/wsfs/adapter/filesystem.c
lib/wsfs/adapter/server.c
lib/wsfs/adapter/server_config.c
lib/wsfs/adapter/server_protocol.c
lib/wsfs/adapter/session.c
lib/wsfs/adapter/session_manager.c
lib/wsfs/adapter/authenticator.c
lib/wsfs/adapter/authenticators.c
lib/wsfs/adapter/credentials.c
lib/wsfs/adapter/time/timepoint.c
lib/wsfs/adapter/time/timer.c
lib/wsfs/adapter/time/timeout_manager.c
lib/wsfs/adapter/operation/lookup.c
lib/wsfs/adapter/operation/getattr.c
lib/wsfs/adapter/operation/readdir.c
lib/wsfs/adapter/operation/open.c
lib/wsfs/adapter/operation/close.c
lib/wsfs/adapter/operation/read.c
lib/wsfs/adapter/jsonrpc/server.c
lib/wsfs/adapter/jsonrpc/method.c
lib/wsfs/adapter/jsonrpc/request.c
lib/wsfs/adapter/jsonrpc/response.c
lib/wsfs/adapter/jsonrpc/util.c
add_library(wsfs-adapter-static STATIC
lib/wsfs/adapter/api.c
lib/wsfs/adapter/impl/filesystem.c
lib/wsfs/adapter/impl/server.c
lib/wsfs/adapter/impl/server_config.c
lib/wsfs/adapter/impl/server_protocol.c
lib/wsfs/adapter/impl/session.c
lib/wsfs/adapter/impl/session_manager.c
lib/wsfs/adapter/impl/authenticator.c
lib/wsfs/adapter/impl/authenticators.c
lib/wsfs/adapter/impl/credentials.c
lib/wsfs/adapter/impl/time/timepoint.c
lib/wsfs/adapter/impl/time/timer.c
lib/wsfs/adapter/impl/time/timeout_manager.c
lib/wsfs/adapter/impl/operation/lookup.c
lib/wsfs/adapter/impl/operation/getattr.c
lib/wsfs/adapter/impl/operation/readdir.c
lib/wsfs/adapter/impl/operation/open.c
lib/wsfs/adapter/impl/operation/close.c
lib/wsfs/adapter/impl/operation/read.c
lib/wsfs/adapter/impl/jsonrpc/server.c
lib/wsfs/adapter/impl/jsonrpc/method.c
lib/wsfs/adapter/impl/jsonrpc/request.c
lib/wsfs/adapter/impl/jsonrpc/response.c
lib/wsfs/adapter/impl/jsonrpc/util.c
)
add_library(wsfs-adapter SHARED ${WSFS_ADAPTER_SOURCES} ${WSFS_COMMON_SOURCES})
set_target_properties(wsfs-adapter-static PROPERTIES OUTPUT_NAME wsfs-adapter)
target_include_directories(wsfs-adapter-static PUBLIC lib ${EXTRA_INCLUDE_DIRS})
target_compile_options(wsfs-adapter-static PUBLIC ${EXTRA_CFLAGS})
set_target_properties(wsfs-adapter-static PROPERTIES C_VISIBILITY_PRESET hidden)
add_library(wsfs-adapter SHARED
lib/wsfs/adapter/api.c
)
set_target_properties(wsfs-adapter PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(wsfs-adapter PROPERTIES SOVERSION 0)
@ -90,6 +106,7 @@ set_target_properties(wsfs-adapter PROPERTIES COMPILE_DEFINITIONS "WSFSA_API=WSF
target_include_directories(wsfs-adapter PUBLIC lib ${EXTRA_INCLUDE_DIRS})
target_compile_options(wsfs-adapter PUBLIC ${EXTRA_CFLAGS})
target_link_libraries(wsfs-adapter PRIVATE wsfs-adapter-static wsfs-core)
file(WRITE "${PROJECT_BINARY_DIR}/libwsfs-adapter.pc"
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
@ -112,23 +129,31 @@ install(FILES "${PROJECT_BINARY_DIR}/libwsfs-adapter.pc" DESTINATION lib${LIB_SU
#libwsfs-provider
set(WSFS_PROVIDER_SOURCES
lib/wsfs/provider/url.c
lib/wsfs/provider/client.c
lib/wsfs/provider/client_config.c
lib/wsfs/provider/client_protocol.c
lib/wsfs/provider/provider.c
lib/wsfs/provider/request.c
lib/wsfs/provider/dirbuffer.c
lib/wsfs/provider/operation/lookup.c
lib/wsfs/provider/operation/getattr.c
lib/wsfs/provider/operation/readdir.c
lib/wsfs/provider/operation/open.c
lib/wsfs/provider/operation/close.c
lib/wsfs/provider/operation/read.c
add_library(wsfs-provider-static STATIC
lib/wsfs/provider/api.c
lib/wsfs/provider/impl/url.c
lib/wsfs/provider/impl/client.c
lib/wsfs/provider/impl/client_config.c
lib/wsfs/provider/impl/client_protocol.c
lib/wsfs/provider/impl/provider.c
lib/wsfs/provider/impl/request.c
lib/wsfs/provider/impl/dirbuffer.c
lib/wsfs/provider/impl/operation/lookup.c
lib/wsfs/provider/impl/operation/getattr.c
lib/wsfs/provider/impl/operation/readdir.c
lib/wsfs/provider/impl/operation/open.c
lib/wsfs/provider/impl/operation/close.c
lib/wsfs/provider/impl/operation/read.c
)
add_library(wsfs-provider SHARED ${WSFS_PROVIDER_SOURCES} ${WSFS_COMMON_SOURCES})
set_target_properties(wsfs-provider-static PROPERTIES OUTPUT_NAME wsfs-provider)
target_include_directories(wsfs-provider-static PUBLIC lib ${EXTRA_INCLUDE_DIRS})
target_compile_options(wsfs-provider-static PUBLIC ${EXTRA_CFLAGS})
set_target_properties(wsfs-provider-static PROPERTIES C_VISIBILITY_PRESET hidden)
add_library(wsfs-provider SHARED
lib/wsfs/provider/api.c
)
set_target_properties(wsfs-provider PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(wsfs-provider PROPERTIES SOVERSION 0)
@ -137,6 +162,7 @@ set_target_properties(wsfs-provider PROPERTIES COMPILE_DEFINITIONS "WSFSP_API=WS
target_include_directories(wsfs-provider PUBLIC lib ${EXTRA_INCLUDE_DIRS})
target_compile_options(wsfs-provider PUBLIC ${EXTRA_CFLAGS})
target_link_libraries(wsfs-provider PRIVATE wsfs-provider-static wsfs-core)
file(WRITE "${PROJECT_BINARY_DIR}/libwsfs-provider.pc"
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
@ -242,17 +268,6 @@ pkg_check_modules(GTEST gtest_main)
include(GoogleTest)
pkg_check_modules(GMOCK gmock)
add_library(wsfs-adapter-static STATIC ${WSFS_ADAPTER_SOURCES})
set_target_properties(wsfs-adapter-static PROPERTIES OUTPUT_NAME wsfs-adapter)
target_include_directories(wsfs-adapter-static PUBLIC lib ${EXTRA_INCLUDE_DIRS})
target_compile_options(wsfs-adapter-static PUBLIC ${EXTRA_CFLAGS})
add_library(wsfs-provider-static STATIC ${WSFS_PROVIDER_SOURCES})
set_target_properties(wsfs-provider-static PROPERTIES OUTPUT_NAME wsfs-provider)
target_include_directories(wsfs-provider-static PUBLIC lib ${EXTRA_INCLUDE_DIRS})
target_compile_options(wsfs-provider-static PUBLIC ${EXTRA_CFLAGS})
add_executable(alltests
test/msleep.cc
test/mock_authenticator.cc
@ -264,10 +279,9 @@ add_executable(alltests
test/test_credentials.cc
test/test_authenticator.cc
test/test_authenticators.cc
${WSFS_COMMON_SOURCES}
)
target_link_libraries(alltests PUBLIC wsfs-adapter-static wsfs-provider-static ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES})
target_link_libraries(alltests PUBLIC wsfs-adapter-static wsfs-provider-static wsfs-core ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES})
target_include_directories(alltests PUBLIC lib ${EXTRA_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS})
target_compile_options(alltests PUBLIC ${EXTRA_CFLAGS} ${GMOCK_CFLAGS} ${GTEST_CFLAGS})

View File

@ -5,11 +5,19 @@
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_credentials;
typedef bool wsfs_authenticate_fn(
struct wsfs_credentials * credentials,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -3,13 +3,13 @@
#include "wsfs/adapter/api.h"
struct wsfs_credentials;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_credentials;
extern WSFSA_API char const * wsfs_credentials_type(
struct wsfs_credentials const * credentials);

View File

@ -3,14 +3,14 @@
#include "wsfs/adapter/api.h"
struct wsfs_server;
struct wsfs_server_config;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_server;
struct wsfs_server_config;
extern WSFSA_API struct wsfs_server * wsfs_server_create(
struct wsfs_server_config * config);

View File

@ -4,13 +4,13 @@
#include "wsfs/adapter/api.h"
#include "wsfs/adapter/authenticate.h"
struct wsfs_server_config;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_server_config;
extern WSFSA_API struct wsfs_server_config * wsfs_server_config_create(void);
extern WSFSA_API void wsfs_server_config_dispose(

View File

@ -4,14 +4,14 @@
#include <wsfs/adapter/api.h>
#include <wsfs/adapter/authenticate.h>
struct wsfs_server_protocol;
struct lws_protocols;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_server_protocol;
struct lws_protocols;
extern WSFSA_API struct wsfs_server_protocol * wsfs_server_protocol_create(
char * mount_point);

View File

@ -3,25 +3,17 @@
#include "wsfs/provider/api.h"
struct wsfsp_client;
struct wsfsp_client_config;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_client;
struct wsfsp_client_config;
extern WSFSP_API struct wsfsp_client * wsfsp_client_create(
struct wsfsp_client_config * config);
extern WSFSP_API void wsfsp_client_set_keypath(
struct wsfsp_client * client,
char * key_path);
extern WSFSP_API void wsfsp_client_set_certpath(
struct wsfsp_client * client,
char * cert_path);
extern WSFSP_API void wsfsp_client_connect(
struct wsfsp_client * client,
char const * url);
@ -29,10 +21,6 @@ extern WSFSP_API void wsfsp_client_connect(
extern WSFSP_API void wsfsp_client_disconnect(
struct wsfsp_client * client);
extern WSFSP_API void wsfsp_client_settimeout(
struct wsfsp_client * client,
unsigned int timepoint);
extern WSFSP_API void wsfsp_client_dispose(
struct wsfsp_client * client);

View File

@ -10,6 +10,11 @@
#include <wsfs/provider/operation/close.h>
#include <wsfs/provider/operation/read.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_client_config;
typedef void wsfsp_connected_fn(
@ -21,11 +26,6 @@ void * user_data);
typedef void wsfsp_ontimer_fn(
void * user_data);
#ifdef __cplusplus
extern "C"
{
#endif
extern WSFSP_API struct wsfsp_client_config * wsfsp_client_config_create(void);
extern WSFSP_API void wsfsp_client_config_dispose(

View File

@ -3,15 +3,15 @@
#include "wsfs/provider/api.h"
struct wsfsp_client_protocol;
struct wsfsp_provider;
struct lws_protocols;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_client_protocol;
struct wsfsp_provider;
struct lws_protocols;
extern WSFSP_API struct wsfsp_client_protocol * wsfsp_client_protocol_create(
struct wsfsp_provider const * provider,
void * user_data);

View File

@ -7,13 +7,13 @@
#include "wsfs/provider/api.h"
struct wsfsp_dirbuffer;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_dirbuffer;
extern WSFSP_API struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void);
extern WSFSP_API void wsfsp_dirbuffer_dispose(

View File

@ -13,17 +13,17 @@
#include "wsfs/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef void wsfsp_close_fn(
ino_t inode,
uint32_t handle,
int flags,
void * user_data);
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __cplusplus
}
#endif

View File

@ -2,15 +2,15 @@
#define WSFSP_OPERATION_ERROR_H
#include "wsfs/provider/api.h"
#include "wsfs/status.h"
struct wsfsp_request;
#include "wsfs/core/status.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_request;
extern WSFSP_API void wsfsp_respond_error(
struct wsfsp_request * request,
wsfs_status status);

View File

@ -7,6 +7,11 @@
#include "wsfs/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_request;
typedef void wsfsp_getattr_fn(
@ -14,12 +19,6 @@ typedef void wsfsp_getattr_fn(
ino_t inode,
void * user_data);
#ifdef __cplusplus
extern "C"
{
#endif
extern WSFSP_API void wsfsp_respond_getattr(
struct wsfsp_request * request,
struct stat const * stat);

View File

@ -7,6 +7,11 @@
#include "wsfs/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_request;
typedef void wsfsp_lookup_fn(
@ -15,11 +20,6 @@ typedef void wsfsp_lookup_fn(
char const * name,
void * user_data);
#ifdef __cplusplus
extern "C"
{
#endif
extern WSFSP_API void wsfsp_respond_lookup(
struct wsfsp_request * request,
struct stat const * stat);

View File

@ -13,6 +13,11 @@
#include "wsfs/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_request;
typedef void wsfsp_open_fn(
@ -21,11 +26,6 @@ typedef void wsfsp_open_fn(
int flags,
void * user_data);
#ifdef __cplusplus
extern "C"
{
#endif
extern WSFSP_API void wsfsp_respond_open(
struct wsfsp_request * request,
uint32_t handle);

View File

@ -16,6 +16,11 @@ using std::size_t;
#include "wsfs/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_request;
typedef void wsfsp_read_fn(
@ -26,11 +31,6 @@ typedef void wsfsp_read_fn(
size_t length,
void * user_data);
#ifdef __cplusplus
extern "C"
{
#endif
extern WSFSP_API void wsfsp_respond_read(
struct wsfsp_request * request,
char const * data,

View File

@ -7,6 +7,11 @@
#include "wsfs/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfsp_dirbuffer;
struct wsfsp_request;
@ -15,12 +20,6 @@ typedef void wsfsp_readdir_fn(
ino_t directory,
void * user_data);
#ifdef __cplusplus
extern "C"
{
#endif
extern WSFSP_API void wsfsp_respond_readdir(
struct wsfsp_request * request,
struct wsfsp_dirbuffer * dirbuffer);

View File

@ -1,7 +1,7 @@
#ifndef WSFS_ADAPTER_H
#define WSFS_ADAPTER_H
#include <wsfs/status.h>
#include <wsfs/core/status.h>
#include <wsfs/adapter/api.h>
#include <wsfs/adapter/server.h>

View File

@ -1,7 +1,7 @@
#ifndef WSFS_PROVIDER_H
#define WSFS_PROVIDER_H
#include <wsfs/status.h>
#include <wsfs/core/status.h>
#include <wsfs/provider/api.h>
#include <wsfs/provider/client.h>

141
lib/wsfs/adapter/api.c Normal file
View File

@ -0,0 +1,141 @@
#include "wsfs_adapter.h"
#include "wsfs/adapter/impl/server.h"
#include "wsfs/adapter/impl/server_protocol.h"
#include "wsfs/adapter/impl/server_config.h"
#include "wsfs/adapter/impl/credentials.h"
// server
struct wsfs_server * wsfs_server_create(
struct wsfs_server_config * config)
{
return wsfs_impl_server_create(config);
}
void wsfs_server_dispose(
struct wsfs_server * server)
{
wsfs_impl_server_dispose(server);
}
void wsfs_server_run(
struct wsfs_server * server)
{
wsfs_impl_server_run(server);
}
void wsfs_server_shutdown(
struct wsfs_server * server)
{
wsfs_impl_server_shutdown(server);
}
// server protocol
struct wsfs_server_protocol * wsfs_server_protocol_create(
char * mount_point)
{
return wsfs_impl_server_protocol_create(mount_point);
}
void wsfs_server_protocol_dispose(
struct wsfs_server_protocol * protocol)
{
wsfs_impl_server_protocol_dispose(protocol);
}
void wsfs_server_protocol_init_lws(
struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol)
{
wsfs_impl_server_protocol_init_lws(protocol, lws_protocol);
}
void wsfs_server_protocol_add_authenticator(
struct wsfs_server_protocol * protocol,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
wsfs_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data);
}
// server_config
struct wsfs_server_config * wsfs_server_config_create(void)
{
return wsfs_impl_server_config_create();
}
void wsfs_server_config_dispose(
struct wsfs_server_config * config)
{
wsfs_impl_server_config_dispose(config);
}
void wsfs_server_config_set_mountpoint(
struct wsfs_server_config * config,
char const * mount_point)
{
wsfs_impl_server_config_set_mountpoint(config, mount_point);
}
void wsfs_server_config_set_documentroot(
struct wsfs_server_config * config,
char const * document_root)
{
wsfs_impl_server_config_set_documentroot(config, document_root);
}
void wsfs_server_config_set_keypath(
struct wsfs_server_config * config,
char const * key_path)
{
wsfs_impl_server_config_set_keypath(config, key_path);
}
void wsfs_server_config_set_certpath(
struct wsfs_server_config * config,
char const * cert_path)
{
wsfs_impl_server_config_set_certpath(config, cert_path);
}
void wsfs_server_config_set_vhostname(
struct wsfs_server_config * config,
char const * vhost_name)
{
wsfs_impl_server_config_set_vhostname(config, vhost_name);
}
void wsfs_server_config_set_port(
struct wsfs_server_config * config,
int port)
{
wsfs_impl_server_config_set_port(config, port);
}
void wsfs_server_config_add_authenticator(
struct wsfs_server_config * config,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
wsfs_impl_server_config_add_authenticator(config, type, authenticate, user_data);
}
// credentials
char const * wsfs_credentials_type(
struct wsfs_credentials const * credentials)
{
return wsfs_impl_credentials_type(credentials);
}
char const * wsfs_credentials_get(
struct wsfs_credentials const * credentials,
char const * key)
{
return wsfs_impl_credentials_get(credentials, key);
}

View File

@ -1,40 +0,0 @@
#ifndef WSFS_ADAPTER_AUTHENTICATOR_H
#define WSFS_ADAPTER_AUTHENTICATOR_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/authenticate.h"
struct wsfs_authenticator
{
char * type;
wsfs_authenticate_fn * authenticate;
void * user_data;
struct wsfs_authenticator * next;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern struct wsfs_authenticator * wsfs_authenticator_create(
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data);
extern void wsfs_authenticator_dispose(
struct wsfs_authenticator * authenticator);
extern bool wsfs_authenticator_autenticate(
struct wsfs_authenticator * authenticator,
struct wsfs_credentials * credentials);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,101 +0,0 @@
#include "wsfs/adapter/authenticators.h"
#include <stddef.h>
#include <string.h>
#include "wsfs/adapter/authenticator.h"
#include "wsfs/adapter/credentials_intern.h"
static struct wsfs_authenticator * wsfs_authenticators_find(
struct wsfs_authenticators * authenticators,
char const * type)
{
struct wsfs_authenticator * result = NULL;
struct wsfs_authenticator * actual = authenticators->first;
while ((NULL == result) && (NULL != actual))
{
struct wsfs_authenticator * next = actual->next;
if (0 == strcmp(type, actual->type))
{
result = actual;
}
actual = next;
}
return result;
}
void wsfs_authenticators_init(
struct wsfs_authenticators * authenticators)
{
authenticators->first = NULL;
}
void wsfs_authenticators_cleanup(
struct wsfs_authenticators * authenticators)
{
struct wsfs_authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wsfs_authenticator * next = actual->next;
wsfs_authenticator_dispose(actual);
actual = next;
}
authenticators->first = NULL;
}
void wsfs_authenticators_clone(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other)
{
wsfs_authenticators_init(other);
struct wsfs_authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wsfs_authenticator * next = actual->next;
wsfs_authenticators_add(other,
actual->type, actual->authenticate, actual->user_data);
actual = next;
}
}
extern void wsfs_authenticators_move(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other)
{
other->first = authenticators->first;
authenticators->first = NULL;
}
void wsfs_authenticators_add(
struct wsfs_authenticators * authenticators,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(type, authenticate, user_data);
authenticator->next = authenticators->first;
authenticators->first = authenticator;
}
bool wsfs_authenticators_authenticate(
struct wsfs_authenticators * authenticators,
struct wsfs_credentials * credentials)
{
bool result = (NULL == authenticators->first);
if (NULL != credentials)
{
struct wsfs_authenticator * authenticator = wsfs_authenticators_find(authenticators, credentials->type);
if (NULL != authenticator)
{
result = wsfs_authenticator_autenticate(authenticator, credentials);
}
}
return result;
}

View File

@ -1,51 +0,0 @@
#ifndef WSFS_ADAPTER_AUTHENTICATORS_H
#define WSFS_ADAPTER_AUTHENTICATORS_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/authenticate.h"
struct wsfs_authenticator;
struct wsfs_credentials;
struct wsfs_authenticators
{
struct wsfs_authenticator * first;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_authenticators_init(
struct wsfs_authenticators * authenticators);
extern void wsfs_authenticators_cleanup(
struct wsfs_authenticators * authenticators);
extern void wsfs_authenticators_clone(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other);
extern void wsfs_authenticators_move(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other);
extern void wsfs_authenticators_add(
struct wsfs_authenticators * authenticators,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data);
extern bool wsfs_authenticators_authenticate(
struct wsfs_authenticators * authenticators,
struct wsfs_credentials * credentials);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,30 +0,0 @@
#ifndef WSFS_ADAPTER_CREDENTIALS_INTERN_H
#define WSFS_ADAPTER_CREDENTIALS_INTERN_H
#include "wsfs/adapter/credentials.h"
#include <jansson.h>
struct wsfs_credentials
{
char * type;
json_t * data;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_credentials_init(
struct wsfs_credentials * credentials,
char const * type,
json_t * data);
extern void wsfs_credentials_cleanup(
struct wsfs_credentials * credentials);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,45 +0,0 @@
#ifndef WSFS_ADAPTER_FILESYSTEM_H
#define WSFS_ADAPTER_FILESYSTEM_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/fuse_wrapper.h"
#include "wsfs/adapter/operations.h"
struct wsfs_jsonrpc_server;
struct wsfs_filesystem
{
struct fuse_args args;
struct fuse_session * session;
struct fuse_buf buffer;
struct wsfs_operations_context user_data;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern bool wsfs_filesystem_init(
struct wsfs_filesystem * filesystem,
struct wsfs_jsonrpc_server * rpc,
char * mount_point);
extern void wsfs_filesystem_cleanup(
struct wsfs_filesystem * filesystem);
extern int wsfs_filesystem_get_fd(
struct wsfs_filesystem * filesystem);
extern void wsfs_filesystem_process_request(
struct wsfs_filesystem * filesystem);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,16 +1,16 @@
#include "wsfs/adapter/authenticator.h"
#include "wsfs/adapter/impl/authenticator.h"
#include <stdlib.h>
#include <string.h>
#include "wsfs/adapter/credentials_intern.h"
#include "wsfs/adapter/impl/credentials.h"
struct wsfs_authenticator * wsfs_authenticator_create(
struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
struct wsfs_authenticator * authenticator = malloc(sizeof(struct wsfs_authenticator));
struct wsfs_impl_authenticator * authenticator = malloc(sizeof(struct wsfs_impl_authenticator));
if (NULL != authenticator)
{
authenticator->type = strdup(type);
@ -22,15 +22,15 @@ struct wsfs_authenticator * wsfs_authenticator_create(
return authenticator;
}
void wsfs_authenticator_dispose(
struct wsfs_authenticator * authenticator)
void wsfs_impl_authenticator_dispose(
struct wsfs_impl_authenticator * authenticator)
{
free(authenticator->type);
free(authenticator);
}
bool wsfs_authenticator_autenticate(
struct wsfs_authenticator * authenticator,
bool wsfs_impl_authenticator_autenticate(
struct wsfs_impl_authenticator * authenticator,
struct wsfs_credentials * credentials)
{
bool result;

View File

@ -0,0 +1,42 @@
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
#define WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/authenticate.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_credentials;
struct wsfs_impl_authenticator
{
char * type;
wsfs_authenticate_fn * authenticate;
void * user_data;
struct wsfs_impl_authenticator * next;
};
extern struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data);
extern void wsfs_impl_authenticator_dispose(
struct wsfs_impl_authenticator * authenticator);
extern bool wsfs_impl_authenticator_autenticate(
struct wsfs_impl_authenticator * authenticator,
struct wsfs_credentials * credentials);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,101 @@
#include "wsfs/adapter/impl/authenticators.h"
#include <stddef.h>
#include <string.h>
#include "wsfs/adapter/impl/authenticator.h"
#include "wsfs/adapter/impl/credentials.h"
static struct wsfs_impl_authenticator * wsfs_impl_authenticators_find(
struct wsfs_impl_authenticators * authenticators,
char const * type)
{
struct wsfs_impl_authenticator * result = NULL;
struct wsfs_impl_authenticator * actual = authenticators->first;
while ((NULL == result) && (NULL != actual))
{
struct wsfs_impl_authenticator * next = actual->next;
if (0 == strcmp(type, actual->type))
{
result = actual;
}
actual = next;
}
return result;
}
void wsfs_impl_authenticators_init(
struct wsfs_impl_authenticators * authenticators)
{
authenticators->first = NULL;
}
void wsfs_impl_authenticators_cleanup(
struct wsfs_impl_authenticators * authenticators)
{
struct wsfs_impl_authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wsfs_impl_authenticator * next = actual->next;
wsfs_impl_authenticator_dispose(actual);
actual = next;
}
authenticators->first = NULL;
}
void wsfs_impl_authenticators_clone(
struct wsfs_impl_authenticators * authenticators,
struct wsfs_impl_authenticators * other)
{
wsfs_impl_authenticators_init(other);
struct wsfs_impl_authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wsfs_impl_authenticator * next = actual->next;
wsfs_impl_authenticators_add(other,
actual->type, actual->authenticate, actual->user_data);
actual = next;
}
}
extern void wsfs_impl_authenticators_move(
struct wsfs_impl_authenticators * authenticators,
struct wsfs_impl_authenticators * other)
{
other->first = authenticators->first;
authenticators->first = NULL;
}
void wsfs_impl_authenticators_add(
struct wsfs_impl_authenticators * authenticators,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(type, authenticate, user_data);
authenticator->next = authenticators->first;
authenticators->first = authenticator;
}
bool wsfs_impl_authenticators_authenticate(
struct wsfs_impl_authenticators * authenticators,
struct wsfs_credentials * credentials)
{
bool result = (NULL == authenticators->first);
if (NULL != credentials)
{
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticators_find(authenticators, credentials->type);
if (NULL != authenticator)
{
result = wsfs_impl_authenticator_autenticate(authenticator, credentials);
}
}
return result;
}

View File

@ -0,0 +1,51 @@
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
#define WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/authenticate.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_impl_authenticator;
struct wsfs_credentials;
struct wsfs_impl_authenticators
{
struct wsfs_impl_authenticator * first;
};
extern void wsfs_impl_authenticators_init(
struct wsfs_impl_authenticators * authenticators);
extern void wsfs_impl_authenticators_cleanup(
struct wsfs_impl_authenticators * authenticators);
extern void wsfs_impl_authenticators_clone(
struct wsfs_impl_authenticators * authenticators,
struct wsfs_impl_authenticators * other);
extern void wsfs_impl_authenticators_move(
struct wsfs_impl_authenticators * authenticators,
struct wsfs_impl_authenticators * other);
extern void wsfs_impl_authenticators_add(
struct wsfs_impl_authenticators * authenticators,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data);
extern bool wsfs_impl_authenticators_authenticate(
struct wsfs_impl_authenticators * authenticators,
struct wsfs_credentials * credentials);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,7 +1,7 @@
#include "wsfs/adapter/credentials_intern.h"
#include "wsfs/adapter/impl/credentials.h"
#include <string.h>
void wsfs_credentials_init(
void wsfs_impl_credentials_init(
struct wsfs_credentials * credentials,
char const * type,
json_t * data)
@ -11,20 +11,20 @@ void wsfs_credentials_init(
json_incref(credentials->data);
}
void wsfs_credentials_cleanup(
void wsfs_impl_credentials_cleanup(
struct wsfs_credentials * credentials)
{
free(credentials->type);
json_decref(credentials->data);
}
char const * wsfs_credentials_type(
char const * wsfs_impl_credentials_type(
struct wsfs_credentials const * credentials)
{
return credentials->type;
}
char const * wsfs_credentials_get(
char const * wsfs_impl_credentials_get(
struct wsfs_credentials const * credentials,
char const * key)
{

View File

@ -0,0 +1,36 @@
#ifndef WSFS_ADAPTER_IMPL_CREDENTIALS_H
#define WSFS_ADAPTER_IMPL_CREDENTIALS_H
#include <jansson.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_credentials
{
char * type;
json_t * data;
};
extern void wsfs_impl_credentials_init(
struct wsfs_credentials * credentials,
char const * type,
json_t * data);
extern void wsfs_impl_credentials_cleanup(
struct wsfs_credentials * credentials);
extern char const * wsfs_impl_credentials_type(
struct wsfs_credentials const * credentials);
extern char const * wsfs_impl_credentials_get(
struct wsfs_credentials const * credentials,
char const * key);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,25 +1,25 @@
#include "wsfs/adapter/filesystem.h"
#include "wsfs/adapter/operations.h"
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/adapter/impl/filesystem.h"
#include "wsfs/adapter/impl/operations.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include <stddef.h>
#include <string.h>
#include <errno.h>
static struct fuse_lowlevel_ops const wsfs_filesystem_operations =
static struct fuse_lowlevel_ops const filesystem_operations =
{
.lookup = &wsfs_operation_lookup,
.getattr = &wsfs_operation_getattr,
.readdir = &wsfs_operation_readdir,
.open = &wsfs_operation_open,
.release = &wsfs_operation_close,
.read = &wsfs_operation_read
.lookup = &wsfs_impl_operation_lookup,
.getattr = &wsfs_impl_operation_getattr,
.readdir = &wsfs_impl_operation_readdir,
.open = &wsfs_impl_operation_open,
.release = &wsfs_impl_operation_close,
.read = &wsfs_impl_operation_read
};
bool wsfs_filesystem_init(
struct wsfs_filesystem * filesystem,
struct wsfs_jsonrpc_server * rpc,
bool wsfs_impl_filesystem_init(
struct wsfs_impl_filesystem * filesystem,
struct wsfs_impl_jsonrpc_server * rpc,
char * mount_point)
{
bool result = false;
@ -35,8 +35,8 @@ bool wsfs_filesystem_init(
filesystem->session = fuse_session_new(
&filesystem->args,
&wsfs_filesystem_operations,
sizeof(wsfs_filesystem_operations),
&filesystem_operations,
sizeof(filesystem_operations),
&filesystem->user_data);
if (NULL != filesystem->session)
{
@ -46,8 +46,8 @@ bool wsfs_filesystem_init(
return result;
}
void wsfs_filesystem_cleanup(
struct wsfs_filesystem * filesystem)
void wsfs_impl_filesystem_cleanup(
struct wsfs_impl_filesystem * filesystem)
{
if (NULL != filesystem->session)
{
@ -61,14 +61,14 @@ void wsfs_filesystem_cleanup(
fuse_opt_free_args(&filesystem->args);
}
int wsfs_filesystem_get_fd(
struct wsfs_filesystem * filesystem)
int wsfs_impl_filesystem_get_fd(
struct wsfs_impl_filesystem * filesystem)
{
return fuse_session_fd(filesystem->session);
}
void wsfs_filesystem_process_request(
struct wsfs_filesystem * filesystem)
void wsfs_impl_filesystem_process_request(
struct wsfs_impl_filesystem * filesystem)
{
int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer);
if (0 < result)

View File

@ -0,0 +1,45 @@
#ifndef WSFS_ADAPTER_IMPL_FILESYSTEM_H
#define WSFS_ADAPTER_IMPL_FILESYSTEM_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/impl/fuse_wrapper.h"
#include "wsfs/adapter/impl/operations.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_impl_jsonrpc_server;
struct wsfs_impl_filesystem
{
struct fuse_args args;
struct fuse_session * session;
struct fuse_buf buffer;
struct wsfs_impl_operations_context user_data;
};
extern bool wsfs_impl_filesystem_init(
struct wsfs_impl_filesystem * filesystem,
struct wsfs_impl_jsonrpc_server * rpc,
char * mount_point);
extern void wsfs_impl_filesystem_cleanup(
struct wsfs_impl_filesystem * filesystem);
extern int wsfs_impl_filesystem_get_fd(
struct wsfs_impl_filesystem * filesystem);
extern void wsfs_impl_filesystem_process_request(
struct wsfs_impl_filesystem * filesystem);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_FUSE_H
#define WSFS_ADAPTER_FUSE_H
#ifndef WSFS_ADAPTER_IMPL_FUSE_H
#define WSFS_ADAPTER_IMPL_FUSE_H
#ifdef __cplusplus
extern "C" {

View File

@ -0,0 +1,28 @@
#include "wsfs/adapter/impl/jsonrpc/method_intern.h"
#include <stdlib.h>
#include <string.h>
struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create(
char const * name,
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
void * user_data)
{
struct wsfs_impl_jsonrpc_method * method = malloc(sizeof(struct wsfs_impl_jsonrpc_method));
if (NULL != method)
{
method->next = NULL;
method->name = strdup(name);
method->invoke = invoke;
method->user_data = user_data;
}
return method;
}
void wsfs_impl_jsonrpc_method_dispose(
struct wsfs_impl_jsonrpc_method * method)
{
free(method->name);
free(method);
}

View File

@ -0,0 +1,31 @@
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include <jansson.h>
#include "wsfs/core/status.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef bool wsfs_impl_jsonrpc_method_invoke_fn(
void * user_data,
struct json_t const * method_call);
typedef void wsfs_impl_jsonrpc_method_finished_fn(
void * user_data,
wsfs_status status,
struct json_t const * result);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,31 @@
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
#include "wsfs/adapter/impl/jsonrpc/method.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_impl_jsonrpc_method
{
struct wsfs_impl_jsonrpc_method * next;
char * name;
wsfs_impl_jsonrpc_method_invoke_fn * invoke;
void * user_data;
};
extern struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create(
char const * name,
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
void * user_data);
extern void wsfs_impl_jsonrpc_method_dispose(
struct wsfs_impl_jsonrpc_method * method);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,6 @@
#include "wsfs/adapter/jsonrpc/request.h"
#include "wsfs/adapter/impl/jsonrpc/request.h"
json_t * wsfs_jsonrpc_request_create(
json_t * wsfs_impl_jsonrpc_request_create(
char const * method,
int id,
char const * param_info,

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_JSONRPC_REQUEST_H
#define WSFS_ADAPTER_JSONRPC_REQUEST_H
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H
#define WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H
#ifndef __cplusplus
#include <stdarg.h>
@ -18,7 +18,7 @@ extern "C"
{
#endif
extern json_t * wsfs_jsonrpc_request_create(
extern json_t * wsfs_impl_jsonrpc_request_create(
char const * method,
int id,
char const * param_info,

View File

@ -1,7 +1,7 @@
#include "wsfs/adapter/jsonrpc/response.h"
#include "wsfs/adapter/impl/jsonrpc/response.h"
void wsfs_jsonrpc_response_init(
struct wsfs_jsonrpc_response * result,
void wsfs_impl_jsonrpc_response_init(
struct wsfs_impl_jsonrpc_response * result,
char const * buffer,
size_t length)
{
@ -49,8 +49,8 @@ void wsfs_jsonrpc_response_init(
json_decref(response);
}
void wsfs_jsonrpc_response_cleanup(
struct wsfs_jsonrpc_response * response)
void wsfs_impl_jsonrpc_response_cleanup(
struct wsfs_impl_jsonrpc_response * response)
{
if (NULL != response->result)
{

View File

@ -0,0 +1,38 @@
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
#define WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
using std::size_t;
#endif
#include <jansson.h>
#include "wsfs/core/status.h"
#ifdef __cplusplus
extern "C" {
#endif
struct wsfs_impl_jsonrpc_response
{
wsfs_status status;
int id;
json_t * result;
};
extern void wsfs_impl_jsonrpc_response_init(
struct wsfs_impl_jsonrpc_response * response,
char const * buffer,
size_t buffer_length);
extern void wsfs_impl_jsonrpc_response_cleanup(
struct wsfs_impl_jsonrpc_response * response);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,17 +1,17 @@
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include <string.h>
#include "wsfs/adapter/jsonrpc/method_intern.h"
#include "wsfs/adapter/jsonrpc/request.h"
#include "wsfs/adapter/jsonrpc/response.h"
#include "wsfs/adapter/impl/jsonrpc/method_intern.h"
#include "wsfs/adapter/impl/jsonrpc/request.h"
#include "wsfs/adapter/impl/jsonrpc/response.h"
#define WSFS_DEFAULT_TIMEOUT (10 * 1000)
static struct wsfs_jsonrpc_method const * wsfs_jsonrpc_server_getmethod(
struct wsfs_jsonrpc_server * server,
static struct wsfs_impl_jsonrpc_method const * wsfs_impl_jsonrpc_server_getmethod(
struct wsfs_impl_jsonrpc_server * server,
char const * name)
{
struct wsfs_jsonrpc_method * method = server->methods;
struct wsfs_impl_jsonrpc_method * method = server->methods;
while ((NULL != method) && (0 == strcmp(name, method->name)))
{
method = method->next;
@ -20,40 +20,40 @@ static struct wsfs_jsonrpc_method const * wsfs_jsonrpc_server_getmethod(
return method;
}
static void wsfs_jsonrpc_server_timeout(
struct wsfs_timer * timer)
static void wsfs_impl_jsonrpc_server_timeout(
struct wsfs_impl_timer * timer)
{
struct wsfs_jsonrpc_server * server = timer->user_data;
struct wsfs_impl_jsonrpc_server * server = timer->user_data;
if (server->request.is_pending)
{
wsfs_jsonrpc_method_finished_fn * finished = server->request.finished;
wsfs_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
void * user_data = server->request.user_data;
server->request.is_pending = false;
server->request.id = 0;
server->request.user_data = NULL;
server->request.finished = NULL;
wsfs_timer_cancel(&server->request.timer);
wsfs_impl_timer_cancel(&server->request.timer);
finished(user_data, WSFS_BAD_TIMEOUT, NULL);
}
}
void wsfs_jsonrpc_server_init(
struct wsfs_jsonrpc_server * server,
struct wsfs_timeout_manager * timeout_manager)
void wsfs_impl_jsonrpc_server_init(
struct wsfs_impl_jsonrpc_server * server,
struct wsfs_impl_timeout_manager * timeout_manager)
{
server->methods = NULL;
server->request.is_pending = false;
wsfs_timer_init(&server->request.timer, timeout_manager);
wsfs_impl_timer_init(&server->request.timer, timeout_manager);
}
void wsfs_jsonrpc_server_cleanup(
struct wsfs_jsonrpc_server * server)
void wsfs_impl_jsonrpc_server_cleanup(
struct wsfs_impl_jsonrpc_server * server)
{
wsfs_timer_cleanup(&server->request.timer);
wsfs_impl_timer_cleanup(&server->request.timer);
if (server->request.is_pending)
{
@ -61,31 +61,31 @@ void wsfs_jsonrpc_server_cleanup(
server->request.is_pending = false;
}
struct wsfs_jsonrpc_method * method = server->methods;
struct wsfs_impl_jsonrpc_method * method = server->methods;
while (NULL != method)
{
struct wsfs_jsonrpc_method * next = method->next;
struct wsfs_impl_jsonrpc_method * next = method->next;
method->next = NULL;
wsfs_jsonrpc_method_dispose(method);
wsfs_impl_jsonrpc_method_dispose(method);
method = next;
}
server->methods = NULL;
}
void wsfs_jsonrpc_server_add(
struct wsfs_jsonrpc_server * server,
void wsfs_impl_jsonrpc_server_add(
struct wsfs_impl_jsonrpc_server * server,
char const * name,
wsfs_jsonrpc_method_invoke_fn * invoke,
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
void * user_data)
{
struct wsfs_jsonrpc_method * method = wsfs_jsonrpc_method_create(name, invoke, user_data);
struct wsfs_impl_jsonrpc_method * method = wsfs_impl_jsonrpc_method_create(name, invoke, user_data);
method->next = server->methods;
server->methods = method;
}
void wsfs_jsonrpc_server_invoke(
struct wsfs_jsonrpc_server * server,
wsfs_jsonrpc_method_finished_fn * finished,
void wsfs_impl_jsonrpc_server_invoke(
struct wsfs_impl_jsonrpc_server * server,
wsfs_impl_jsonrpc_method_finished_fn * finished,
void * user_data,
char const * method_name,
char const * param_info,
@ -94,19 +94,19 @@ void wsfs_jsonrpc_server_invoke(
{
if (!server->request.is_pending)
{
struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name);
struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name);
if (NULL != method)
{
server->request.is_pending = true;
server->request.finished = finished;
server->request.user_data = user_data;
server->request.id = 42;
wsfs_timer_start(&server->request.timer, wsfs_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT),
&wsfs_jsonrpc_server_timeout, server);
wsfs_impl_timer_start(&server->request.timer, wsfs_impl_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT),
&wsfs_impl_jsonrpc_server_timeout, server);
va_list args;
va_start(args, param_info);
json_t * request = wsfs_jsonrpc_request_create(method_name, server->request.id, param_info, args);
json_t * request = wsfs_impl_jsonrpc_request_create(method_name, server->request.id, param_info, args);
va_end(args);
if (NULL != request)
{
@ -116,7 +116,7 @@ void wsfs_jsonrpc_server_invoke(
server->request.finished = NULL;
server->request.user_data = NULL;
server->request.id = 0;
wsfs_timer_cancel(&server->request.timer);
wsfs_impl_timer_cancel(&server->request.timer);
finished(user_data, WSFS_BAD, NULL);
}
@ -134,20 +134,20 @@ void wsfs_jsonrpc_server_invoke(
}
}
extern void wsfs_jsonrpc_server_notify(
struct wsfs_jsonrpc_server * server,
extern void wsfs_impl_jsonrpc_server_notify(
struct wsfs_impl_jsonrpc_server * server,
char const * method_name,
char const * param_info,
...
)
{
struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name);
struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name);
if (NULL != method)
{
va_list args;
va_start(args, param_info);
json_t * request = wsfs_jsonrpc_request_create(method_name, 0, param_info, args);
json_t * request = wsfs_impl_jsonrpc_request_create(method_name, 0, param_info, args);
va_end(args);
if (NULL != request)
{
@ -159,28 +159,28 @@ extern void wsfs_jsonrpc_server_notify(
}
void wsfs_jsonrpc_server_onresult(
struct wsfs_jsonrpc_server * server,
void wsfs_impl_jsonrpc_server_onresult(
struct wsfs_impl_jsonrpc_server * server,
char const * message,
size_t length)
{
struct wsfs_jsonrpc_response response;
wsfs_jsonrpc_response_init(&response, message, length);
struct wsfs_impl_jsonrpc_response response;
wsfs_impl_jsonrpc_response_init(&response, message, length);
if ((server->request.is_pending) && (response.id == server->request.id))
{
wsfs_jsonrpc_method_finished_fn * finished = server->request.finished;
wsfs_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
void * user_data = server->request.user_data;
server->request.is_pending = false;
server->request.id = 0;
server->request.user_data = NULL;
server->request.finished = NULL;
wsfs_timer_cancel(&server->request.timer);
wsfs_impl_timer_cancel(&server->request.timer);
finished(user_data, response.status, response.result);
}
wsfs_jsonrpc_response_cleanup(&response);
wsfs_impl_jsonrpc_response_cleanup(&response);
}

View File

@ -0,0 +1,77 @@
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
#define WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
#ifndef __cplusplus
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
#else
#include <cstdarg>
#include <cstddef>
using std::size_t;
#endif
#include <jansson.h>
#include "wsfs/adapter/impl/jsonrpc/method.h"
#include "wsfs/adapter/impl/time/timeout_manager.h"
#include "wsfs/adapter/impl/time/timer.h"
#ifdef __cplusplus
extern "C" {
#endif
struct wsfs_impl_jsonrpc_request
{
bool is_pending;
wsfs_impl_jsonrpc_method_finished_fn * finished;
void * user_data;
int id;
struct wsfs_impl_timer timer;
};
struct wsfs_impl_jsonrpc_server
{
struct wsfs_impl_jsonrpc_method * methods;
struct wsfs_impl_jsonrpc_request request;
};
extern void wsfs_impl_jsonrpc_server_init(
struct wsfs_impl_jsonrpc_server * server,
struct wsfs_impl_timeout_manager * manager);
extern void wsfs_impl_jsonrpc_server_cleanup(
struct wsfs_impl_jsonrpc_server * server);
extern void wsfs_impl_jsonrpc_server_add(
struct wsfs_impl_jsonrpc_server * server,
char const * name,
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
void * user_data );
extern void wsfs_impl_jsonrpc_server_invoke(
struct wsfs_impl_jsonrpc_server * server,
wsfs_impl_jsonrpc_method_finished_fn * finished,
void * user_data,
char const * method_name,
char const * param_info,
...
);
extern void wsfs_impl_jsonrpc_server_notify(
struct wsfs_impl_jsonrpc_server * server,
char const * method_name,
char const * param_info,
...
);
extern void wsfs_impl_jsonrpc_server_onresult(
struct wsfs_impl_jsonrpc_server * server,
char const * message,
size_t length);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,6 @@
#include "wsfs/adapter/jsonrpc/util.h"
#include "wsfs/adapter/impl/jsonrpc/util.h"
int wsfs_json_get_int(json_t const * object, char const * key, int default_value)
int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value)
{
int result = default_value;

View File

@ -0,0 +1,17 @@
#ifndef WSFS_ADAPTER_IMPL_JSON_UTIL_H
#define WSFS_ADAPTER_IMPL_JSON_UTIL_H
#include <jansson.h>
#ifdef __cplusplus
extern "C"
{
#endif
extern int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,21 @@
#include "wsfs/adapter/impl/operations.h"
#include <limits.h>
#include <errno.h>
#include <jansson.h>
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include "wsfs/core/util.h"
void wsfs_impl_operation_close(
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * file_info)
{
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
int handle = (int) (file_info->fh & INT_MAX);
wsfs_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
fuse_reply_err(request, 0);
}

View File

@ -1,4 +1,4 @@
#include "wsfs/adapter/operations.h"
#include "wsfs/adapter/impl/operations.h"
#include <errno.h>
#include <string.h>
@ -7,11 +7,11 @@
#include <sys/stat.h>
#include <unistd.h>
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/adapter/jsonrpc/util.h"
#include "wsfs/util.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include "wsfs/adapter/impl/jsonrpc/util.h"
#include "wsfs/core/util.h"
struct wsfs_operation_getattr_context
struct wsfs_impl_operation_getattr_context
{
fuse_req_t request;
double timeout;
@ -19,12 +19,12 @@ struct wsfs_operation_getattr_context
gid_t gid;
};
static void wsfs_operation_getattr_finished(
static void wsfs_impl_operation_getattr_finished(
void * user_data,
wsfs_status status,
json_t const * data)
{
struct wsfs_operation_getattr_context * context = user_data;
struct wsfs_impl_operation_getattr_context * context = user_data;
struct stat buffer;
if (NULL != data)
@ -50,10 +50,10 @@ static void wsfs_operation_getattr_finished(
buffer.st_uid = context->uid;
buffer.st_gid = context->gid;
buffer.st_nlink = 1;
buffer.st_size = wsfs_json_get_int(data, "size", 0);
buffer.st_atime = wsfs_json_get_int(data, "atime", 0);
buffer.st_mtime = wsfs_json_get_int(data, "mtime", 0);
buffer.st_ctime = wsfs_json_get_int(data, "ctime", 0);
buffer.st_size = wsfs_impl_json_get_int(data, "size", 0);
buffer.st_atime = wsfs_impl_json_get_int(data, "atime", 0);
buffer.st_mtime = wsfs_impl_json_get_int(data, "mtime", 0);
buffer.st_ctime = wsfs_impl_json_get_int(data, "ctime", 0);
}
else
@ -74,20 +74,20 @@ static void wsfs_operation_getattr_finished(
free(context);
}
void wsfs_operation_getattr (
void wsfs_impl_operation_getattr (
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{
struct fuse_ctx const * context = fuse_req_ctx(request);
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_operation_getattr_context * getattr_context = malloc(sizeof(struct wsfs_operation_getattr_context));
struct wsfs_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wsfs_impl_operation_getattr_context));
getattr_context->request = request;
getattr_context->uid = context->uid;
getattr_context->gid = context->gid;
getattr_context->timeout = user_data->timeout;
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_getattr_finished, getattr_context, "getattr", "i", inode);
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_getattr_finished, getattr_context, "getattr", "i", inode);
}

View File

@ -1,4 +1,4 @@
#include "wsfs/adapter/operations.h"
#include "wsfs/adapter/impl/operations.h"
#include <limits.h>
#include <errno.h>
@ -10,11 +10,11 @@
#include <stdlib.h>
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/adapter/jsonrpc/util.h"
#include "wsfs/util.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include "wsfs/adapter/impl/jsonrpc/util.h"
#include "wsfs/core/util.h"
struct wsfs_operation_lookup_context
struct wsfs_impl_operation_lookup_context
{
fuse_req_t request;
double timeout;
@ -22,13 +22,13 @@ struct wsfs_operation_lookup_context
gid_t gid;
};
static void wsfs_operation_lookup_finished(
static void wsfs_impl_operation_lookup_finished(
void * user_data,
wsfs_status status,
json_t const * data
)
{
struct wsfs_operation_lookup_context * context = user_data;
struct wsfs_impl_operation_lookup_context * context = user_data;
struct fuse_entry_param buffer;
if (NULL != data)
@ -60,10 +60,10 @@ static void wsfs_operation_lookup_finished(
buffer.attr.st_uid = context->uid;
buffer.attr.st_gid = context->gid;
buffer.attr.st_nlink = 1;
buffer.attr.st_size = wsfs_json_get_int(data, "size", 0);
buffer.attr.st_atime = wsfs_json_get_int(data, "atime", 0);
buffer.attr.st_mtime = wsfs_json_get_int(data, "mtime", 0);
buffer.attr.st_ctime = wsfs_json_get_int(data, "ctime", 0);
buffer.attr.st_size = wsfs_impl_json_get_int(data, "size", 0);
buffer.attr.st_atime = wsfs_impl_json_get_int(data, "atime", 0);
buffer.attr.st_mtime = wsfs_impl_json_get_int(data, "mtime", 0);
buffer.attr.st_ctime = wsfs_impl_json_get_int(data, "ctime", 0);
}
else
{
@ -83,21 +83,20 @@ static void wsfs_operation_lookup_finished(
free(context);
}
void wsfs_operation_lookup (
void wsfs_impl_operation_lookup (
fuse_req_t request,
fuse_ino_t parent,
char const * name)
{
struct fuse_ctx const * context = fuse_req_ctx(request);
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_operation_lookup_context * lookup_context = malloc(sizeof(struct wsfs_operation_lookup_context));
struct wsfs_impl_operation_lookup_context * lookup_context = malloc(sizeof(struct wsfs_impl_operation_lookup_context));
lookup_context->request = request;
lookup_context->uid = context->uid;
lookup_context->gid = context->gid;
lookup_context->timeout = user_data->timeout;
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
}

View File

@ -1,14 +1,14 @@
#include "wsfs/adapter/operations.h"
#include "wsfs/adapter/impl/operations.h"
#include <string.h>
#include <errno.h>
#include <jansson.h>
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/util.h"
#include "wsfs/status.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include "wsfs/core/util.h"
#include "wsfs/core/status.h"
static void wsfs_operation_open_finished(
static void wsfs_impl_operation_open_finished(
void * user_data,
wsfs_status status,
json_t const * result)
@ -41,13 +41,13 @@ static void wsfs_operation_open_finished(
}
void wsfs_operation_open(
void wsfs_impl_operation_open(
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * file_info)
{
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_open_finished, request, "open", "ii", inode, file_info->flags);
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags);
}

View File

@ -1,4 +1,4 @@
#include "wsfs/adapter/operations.h"
#include "wsfs/adapter/impl/operations.h"
#include <errno.h>
#include <string.h>
@ -6,11 +6,11 @@
#include <jansson.h>
#include <libwebsockets.h>
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#define WSFS_MAX_READ_LENGTH 4096
static char * wsfs_fill_buffer(
static char * wsfs_impl_fill_buffer(
char const * data,
char const * format,
size_t count,
@ -38,7 +38,7 @@ static char * wsfs_fill_buffer(
return buffer;
}
static void wsfs_operation_read_finished(void * user_data, wsfs_status status, json_t const * data)
static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status status, json_t const * data)
{
fuse_req_t request = user_data;
@ -58,7 +58,7 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j
char const * const format = json_string_value(format_holder);
length = (size_t) json_integer_value(count_holder);
buffer = wsfs_fill_buffer(data, format, length, &status);
buffer = wsfs_impl_fill_buffer(data, format, length, &status);
}
else
{
@ -79,17 +79,17 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j
}
void wsfs_operation_read(
void wsfs_impl_operation_read(
fuse_req_t request,
fuse_ino_t inode,
size_t size,
off_t offset,
struct fuse_file_info * file_info)
{
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
int const length = (size <= WSFS_MAX_READ_LENGTH) ? (int) size : WSFS_MAX_READ_LENGTH;
int handle = (file_info->fh & INT_MAX);
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
}

View File

@ -1,4 +1,4 @@
#include "wsfs/adapter/operations.h"
#include "wsfs/adapter/impl/operations.h"
#include <stdlib.h>
#include <string.h>
@ -8,43 +8,43 @@
#include <sys/stat.h>
#include <unistd.h>
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/util.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include "wsfs/core/util.h"
#define WSFS_DIRBUFFER_INITIAL_SIZE 1024
struct wsfs_operation_readdir_context
struct wsfs_impl_operation_readdir_context
{
fuse_req_t request;
size_t size;
off_t offset;
};
struct wsfs_dirbuffer
struct wsfs_impl_dirbuffer
{
char * data;
size_t position;
size_t capacity;
};
static void wsfs_dirbuffer_init(
struct wsfs_dirbuffer * buffer)
static void wsfs_impl_dirbuffer_init(
struct wsfs_impl_dirbuffer * buffer)
{
buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE);
buffer->position = 0;
buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE;
}
static void wsfs_dirbuffer_dispose(
struct wsfs_dirbuffer * buffer)
static void wsfs_impl_dirbuffer_dispose(
struct wsfs_impl_dirbuffer * buffer)
{
free(buffer->data);
}
static void wsfs_dirbuffer_add(
static void wsfs_impl_dirbuffer_add(
fuse_req_t request,
struct wsfs_dirbuffer * buffer,
struct wsfs_impl_dirbuffer * buffer,
char const * name,
fuse_ino_t inode)
{
@ -66,20 +66,20 @@ static void wsfs_dirbuffer_add(
buffer->position += size;
}
static size_t min(size_t a, size_t b)
static size_t wsfs_impl_min(size_t a, size_t b)
{
return (a < b) ? a : b;
}
static void wsfs_operation_readdir_finished(
static void wsfs_impl_operation_readdir_finished(
void * user_data,
wsfs_status status,
json_t const * result)
{
struct wsfs_operation_readdir_context * context = user_data;
struct wsfs_impl_operation_readdir_context * context = user_data;
struct wsfs_dirbuffer buffer;
wsfs_dirbuffer_init(&buffer);
struct wsfs_impl_dirbuffer buffer;
wsfs_impl_dirbuffer_init(&buffer);
if (NULL != result)
{
@ -100,7 +100,7 @@ static void wsfs_operation_readdir_finished(
{
char const * name = json_string_value(name_holder);
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
wsfs_dirbuffer_add(context->request, &buffer, name, entry_inode);
wsfs_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
}
}
}
@ -112,7 +112,7 @@ static void wsfs_operation_readdir_finished(
if (((size_t) context->offset) < buffer.position)
{
fuse_reply_buf(context->request, &buffer.data[context->offset],
min(buffer.position - context->offset, context->size));
wsfs_impl_min(buffer.position - context->offset, context->size));
}
else
{
@ -125,23 +125,23 @@ static void wsfs_operation_readdir_finished(
fuse_reply_err(context->request, ENOENT);
}
wsfs_dirbuffer_dispose(&buffer);
wsfs_impl_dirbuffer_dispose(&buffer);
free(context);
}
void wsfs_operation_readdir (
void wsfs_impl_operation_readdir (
fuse_req_t request,
fuse_ino_t inode,
size_t size,
off_t offset,
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_operation_readdir_context));
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_impl_operation_readdir_context));
readdir_context->request = request;
readdir_context->size = size;
readdir_context->offset = offset;
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_readdir_finished, readdir_context, "readdir", "i", inode);
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode);
}

View File

@ -1,48 +1,48 @@
#ifndef WSFS_ADAPTER_OPERATIONS
#define WSFS_ADAPTER_OPERATIONS
#ifndef WSFS_ADAPTER_IMPL_OPERATIONS_H
#define WSFS_ADAPTER_IMPL_OPERATIONS_H
#include "wsfs/adapter/fuse_wrapper.h"
struct wsfs_jsonrpc_server;
struct wsfs_operations_context
{
struct wsfs_jsonrpc_server * rpc;
double timeout;
};
#include "wsfs/adapter/impl/fuse_wrapper.h"
#ifdef __cplusplus
extern "C" {
#endif
extern void wsfs_operation_lookup (
struct wsfs_impl_jsonrpc_server;
struct wsfs_impl_operations_context
{
struct wsfs_impl_jsonrpc_server * rpc;
double timeout;
};
extern void wsfs_impl_operation_lookup (
fuse_req_t req,
fuse_ino_t parent,
char const * name);
extern void wsfs_operation_getattr (
extern void wsfs_impl_operation_getattr (
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info *file_info);
extern void wsfs_operation_readdir (
extern void wsfs_impl_operation_readdir (
fuse_req_t request,
fuse_ino_t inode,
size_t size,
off_t offset,
struct fuse_file_info *file_info);
extern void wsfs_operation_open(
extern void wsfs_impl_operation_open(
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * file_info);
extern void wsfs_operation_close(
extern void wsfs_impl_operation_close(
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * file_info);
extern void wsfs_operation_read(
extern void wsfs_impl_operation_read(
fuse_req_t request,
fuse_ino_t ino, size_t size, off_t off,
struct fuse_file_info *fi);

View File

@ -8,8 +8,8 @@
#include <sys/stat.h>
#include <unistd.h>
#include "wsfs/adapter/server_config_intern.h"
#include "wsfs/adapter/server_protocol_intern.h"
#include "wsfs/adapter/impl/server_config.h"
#include "wsfs/adapter/impl/server_protocol.h"
#define WSFS_DISABLE_LWS_LOG 0
#define WSFS_SERVER_PROTOCOL_COUNT 3
@ -26,13 +26,13 @@ struct wsfs_server
struct lws_context_creation_info info;
};
static bool wsfs_server_tls_enabled(
static bool wsfs_impl_server_tls_enabled(
struct wsfs_server * server)
{
return ((server->config.key_path != NULL) && (server->config.cert_path != NULL));
}
static struct lws_context * wsfs_server_context_create(
static struct lws_context * wsfs_impl_server_context_create(
struct wsfs_server * server)
{
lws_set_log_level(WSFS_DISABLE_LWS_LOG, NULL);
@ -41,7 +41,7 @@ static struct lws_context * wsfs_server_context_create(
server->ws_protocols[0].name = "http";
server->ws_protocols[0].callback = lws_callback_http_dummy;
server->ws_protocols[1].name = "fs";
wsfs_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]);
wsfs_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]);
memset(&server->mount, 0, sizeof(struct lws_http_mount));
server->mount.mount_next = NULL,
@ -66,7 +66,7 @@ static struct lws_context * wsfs_server_context_create(
server->info.mounts = NULL;
}
if (wsfs_server_tls_enabled(server))
if (wsfs_impl_server_tls_enabled(server))
{
server->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
server->info.ssl_cert_filepath = server->config.cert_path;
@ -78,7 +78,7 @@ static struct lws_context * wsfs_server_context_create(
}
static bool wsfs_server_check_mountpoint(
static bool wsfs_impl_server_check_mountpoint(
struct wsfs_server_config * config)
{
bool result = false;
@ -98,22 +98,22 @@ static bool wsfs_server_check_mountpoint(
return result;
}
struct wsfs_server * wsfs_server_create(
struct wsfs_server * wsfs_impl_server_create(
struct wsfs_server_config * config)
{
struct wsfs_server * server = NULL;
if (wsfs_server_check_mountpoint(config))
if (wsfs_impl_server_check_mountpoint(config))
{
server = malloc(sizeof(struct wsfs_server));
if (NULL != server)
{
if (wsfs_server_protocol_init(&server->protocol, config->mount_point))
if (wsfs_impl_server_protocol_init(&server->protocol, config->mount_point))
{
server->shutdown_requested = false;
wsfs_server_config_clone(config, &server->config);
wsfs_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = wsfs_server_context_create(server);
wsfs_impl_server_config_clone(config, &server->config);
wsfs_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = wsfs_impl_server_context_create(server);
}
else
{
@ -126,16 +126,16 @@ struct wsfs_server * wsfs_server_create(
return server;
}
void wsfs_server_dispose(
void wsfs_impl_server_dispose(
struct wsfs_server * server)
{
lws_context_destroy(server->context);
wsfs_server_protocol_cleanup(&server->protocol);
wsfs_server_config_cleanup(&server->config);
wsfs_impl_server_protocol_cleanup(&server->protocol);
wsfs_impl_server_config_cleanup(&server->config);
free(server);
}
void wsfs_server_run(
void wsfs_impl_server_run(
struct wsfs_server * server)
{
int n = 0;
@ -145,7 +145,7 @@ void wsfs_server_run(
}
}
void wsfs_server_shutdown(
void wsfs_impl_server_shutdown(
struct wsfs_server * server)
{
server->shutdown_requested = true;

View File

@ -0,0 +1,29 @@
#ifndef WSFS_ADAPTER_IMPL_SERVER_H
#define WSFS_ADAPTER_IMPL_SERVER_H
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_server;
struct wsfs_server_config;
extern struct wsfs_server * wsfs_impl_server_create(
struct wsfs_server_config * config);
extern void wsfs_impl_server_dispose(
struct wsfs_server * server);
extern void wsfs_impl_server_run(
struct wsfs_server * server);
extern void wsfs_impl_server_shutdown(
struct wsfs_server * server);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,9 +1,9 @@
#include "wsfs/adapter/server_config_intern.h"
#include "wsfs/adapter/impl/server_config.h"
#include <stdlib.h>
#include <string.h>
static char * wsfs_server_config_strdup(char const * value)
static char * wsfs_impl_server_config_strdup(char const * value)
{
char * result = NULL;
if (NULL != value)
@ -14,18 +14,18 @@ static char * wsfs_server_config_strdup(char const * value)
return result;
}
void wsfs_server_config_init(
void wsfs_impl_server_config_init(
struct wsfs_server_config * config)
{
memset(config, 0, sizeof(struct wsfs_server_config));
wsfs_authenticators_init(&config->authenticators);
wsfs_impl_authenticators_init(&config->authenticators);
}
void wsfs_server_config_cleanup(
void wsfs_impl_server_config_cleanup(
struct wsfs_server_config * config)
{
wsfs_authenticators_cleanup(&config->authenticators);
wsfs_impl_authenticators_cleanup(&config->authenticators);
free(config->mount_point);
free(config->document_root);
@ -33,42 +33,42 @@ void wsfs_server_config_cleanup(
free(config->cert_path);
free(config->vhost_name);
wsfs_server_config_init(config);
wsfs_impl_server_config_init(config);
}
void wsfs_server_config_clone(
void wsfs_impl_server_config_clone(
struct wsfs_server_config * config,
struct wsfs_server_config * clone)
{
clone->mount_point = wsfs_server_config_strdup(config->mount_point);
clone->document_root = wsfs_server_config_strdup(config->document_root);
clone->key_path = wsfs_server_config_strdup(config->key_path);
clone->cert_path = wsfs_server_config_strdup(config->cert_path);
clone->vhost_name = wsfs_server_config_strdup(config->vhost_name);
clone->mount_point = wsfs_impl_server_config_strdup(config->mount_point);
clone->document_root = wsfs_impl_server_config_strdup(config->document_root);
clone->key_path = wsfs_impl_server_config_strdup(config->key_path);
clone->cert_path = wsfs_impl_server_config_strdup(config->cert_path);
clone->vhost_name = wsfs_impl_server_config_strdup(config->vhost_name);
clone->port = config->port;
wsfs_authenticators_clone(&config->authenticators, &clone->authenticators);
wsfs_impl_authenticators_clone(&config->authenticators, &clone->authenticators);
}
struct wsfs_server_config * wsfs_server_config_create(void)
struct wsfs_server_config * wsfs_impl_server_config_create(void)
{
struct wsfs_server_config * config = malloc(sizeof(struct wsfs_server_config));
if (NULL != config)
{
wsfs_server_config_init(config);
wsfs_impl_server_config_init(config);
}
return config;
}
void wsfs_server_config_dispose(
void wsfs_impl_server_config_dispose(
struct wsfs_server_config * config)
{
wsfs_server_config_cleanup(config);
wsfs_impl_server_config_cleanup(config);
free(config);
}
void wsfs_server_config_set_mountpoint(
void wsfs_impl_server_config_set_mountpoint(
struct wsfs_server_config * config,
char const * mount_point)
{
@ -76,7 +76,7 @@ void wsfs_server_config_set_mountpoint(
config->mount_point = strdup(mount_point);
}
void wsfs_server_config_set_documentroot(
void wsfs_impl_server_config_set_documentroot(
struct wsfs_server_config * config,
char const * document_root)
{
@ -84,7 +84,7 @@ void wsfs_server_config_set_documentroot(
config->document_root = strdup(document_root);
}
void wsfs_server_config_set_keypath(
void wsfs_impl_server_config_set_keypath(
struct wsfs_server_config * config,
char const * key_path)
{
@ -92,7 +92,7 @@ void wsfs_server_config_set_keypath(
config->key_path = strdup(key_path);
}
void wsfs_server_config_set_certpath(
void wsfs_impl_server_config_set_certpath(
struct wsfs_server_config * config,
char const * cert_path)
{
@ -100,7 +100,7 @@ void wsfs_server_config_set_certpath(
config->cert_path = strdup(cert_path);
}
void wsfs_server_config_set_vhostname(
void wsfs_impl_server_config_set_vhostname(
struct wsfs_server_config * config,
char const * vhost_name)
{
@ -108,20 +108,20 @@ void wsfs_server_config_set_vhostname(
config->vhost_name = strdup(vhost_name);
}
void wsfs_server_config_set_port(
void wsfs_impl_server_config_set_port(
struct wsfs_server_config * config,
int port)
{
config->port = port;
}
void wsfs_server_config_add_authenticator(
void wsfs_impl_server_config_add_authenticator(
struct wsfs_server_config * config,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data
)
{
wsfs_authenticators_add(&config->authenticators, type, authenticate, user_data);
wsfs_impl_authenticators_add(&config->authenticators, type, authenticate, user_data);
}

View File

@ -0,0 +1,72 @@
#ifndef WSFS_ADAPTER_IMPL_SERVER_CONFIG_H
#define WSFS_ADAPTER_IMPL_SERVER_CONFIG_H
#include "wsfs/adapter/impl/authenticators.h"
#ifdef __cplusplus
extern "C" {
#endif
struct wsfs_server_config
{
char * mount_point;
char * document_root;
char * key_path;
char * cert_path;
char * vhost_name;
int port;
struct wsfs_impl_authenticators authenticators;
};
extern struct wsfs_server_config * wsfs_impl_server_config_create(void);
extern void wsfs_impl_server_config_dispose(
struct wsfs_server_config * config);
extern void wsfs_impl_server_config_init(
struct wsfs_server_config * config);
extern void wsfs_impl_server_config_cleanup(
struct wsfs_server_config * config);
extern void wsfs_impl_server_config_clone(
struct wsfs_server_config * config,
struct wsfs_server_config * clone);
extern void wsfs_impl_server_config_set_mountpoint(
struct wsfs_server_config * config,
char const * mount_point);
extern void wsfs_impl_server_config_set_documentroot(
struct wsfs_server_config * config,
char const * document_root);
extern void wsfs_impl_server_config_set_keypath(
struct wsfs_server_config * config,
char const * key_path);
extern void wsfs_impl_server_config_set_certpath(
struct wsfs_server_config * config,
char const * cert_path);
extern void wsfs_impl_server_config_set_vhostname(
struct wsfs_server_config * config,
char const * vhost_name);
extern void wsfs_impl_server_config_set_port(
struct wsfs_server_config * config,
int port);
extern void wsfs_impl_server_config_add_authenticator(
struct wsfs_server_config * config,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data
);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,166 @@
#include "wsfs/adapter/impl/server_protocol.h"
#include <stdlib.h>
#include <libwebsockets.h>
#include "wsfs/core/message.h"
#include "wsfs/core/util.h"
#include "wsfs/adapter/impl/filesystem.h"
static int wsfs_impl_server_protocol_callback(
struct lws * wsi,
enum lws_callback_reasons reason,
void * WSFS_UNUSED_PARAM(user),
void * in,
size_t len)
{
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
struct wsfs_server_protocol * protocol = ws_protocol->user;
wsfs_impl_timeout_manager_check(&protocol->timeout_manager);
struct wsfs_impl_session * session = wsfs_impl_session_manager_get(&protocol->session_manager, wsi);
switch (reason)
{
case LWS_CALLBACK_PROTOCOL_INIT:
{
lws_sock_file_fd_type fd;
fd.filefd = wsfs_impl_filesystem_get_fd(&protocol->filesystem);
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
{
fprintf(stderr, "error: unable to adopt fd");
}
}
break;
case LWS_CALLBACK_ESTABLISHED:
session = wsfs_impl_session_manager_add(
&protocol->session_manager,
wsi,
&protocol->authenticators,
&protocol->rpc);
if (NULL != session)
{
wsfs_impl_session_authenticate(session, NULL);
}
break;
case LWS_CALLBACK_CLOSED:
wsfs_impl_session_manager_remove(&protocol->session_manager, wsi);
break;
case LWS_CALLBACK_SERVER_WRITEABLE:
if (NULL != session)
{
wsfs_impl_session_onwritable(session);
}
break;
case LWS_CALLBACK_RECEIVE:
if (NULL != session)
{
wsfs_impl_session_receive(session, in, len);
}
break;
case LWS_CALLBACK_RAW_RX_FILE:
wsfs_impl_filesystem_process_request(&protocol->filesystem);
break;
default:
break;
}
return 0;
}
static bool wsfs_impl_server_protocol_invoke(
void * user_data,
json_t const * request)
{
struct wsfs_server_protocol * protocol = user_data;
struct wsfs_impl_session * session = &protocol->session_manager.session;
struct wsfs_message * message = wsfs_message_create(request);
bool const result = wsfs_impl_session_send(session, message);
return result;
}
struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
char * mount_point)
{
struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol));
if (NULL != protocol)
{
if (!wsfs_impl_server_protocol_init(protocol, mount_point))
{
free(protocol);
protocol = NULL;
}
}
return protocol;
}
void wsfs_impl_server_protocol_dispose(
struct wsfs_server_protocol * protocol)
{
wsfs_impl_server_protocol_cleanup(protocol);
free(protocol);
}
void wsfs_impl_server_protocol_init_lws(
struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol)
{
lws_protocol->callback = &wsfs_impl_server_protocol_callback;
lws_protocol->per_session_data_size = 0;
lws_protocol->user = protocol;
}
bool wsfs_impl_server_protocol_init(
struct wsfs_server_protocol * protocol,
char * mount_point)
{
wsfs_impl_timeout_manager_init(&protocol->timeout_manager);
wsfs_impl_session_manager_init(&protocol->session_manager);
wsfs_impl_authenticators_init(&protocol->authenticators);
wsfs_impl_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_impl_server_protocol_invoke, protocol);
bool const success = wsfs_impl_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
// cleanup on error
if (!success)
{
wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
wsfs_impl_authenticators_cleanup(&protocol->authenticators);
wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
wsfs_impl_session_manager_cleanup(&protocol->session_manager);
}
return success;
}
void wsfs_impl_server_protocol_cleanup(
struct wsfs_server_protocol * protocol)
{
wsfs_impl_filesystem_cleanup(&protocol->filesystem);
wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
wsfs_impl_authenticators_cleanup(&protocol->authenticators);
wsfs_impl_session_manager_cleanup(&protocol->session_manager);
}
void wsfs_impl_server_protocol_add_authenticator(
struct wsfs_server_protocol * protocol,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
wsfs_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
}

View File

@ -0,0 +1,53 @@
#ifndef WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
#define WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
#include "wsfs/adapter/impl/filesystem.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include "wsfs/adapter/impl/time/timeout_manager.h"
#include "wsfs/adapter/impl/authenticators.h"
#include "wsfs/adapter/impl/session_manager.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct lws_protocols;
struct wsfs_server_protocol
{
struct wsfs_impl_timeout_manager timeout_manager;
struct wsfs_impl_filesystem filesystem;
struct wsfs_impl_jsonrpc_server rpc;
struct wsfs_impl_authenticators authenticators;
struct wsfs_impl_session_manager session_manager;
};
extern bool wsfs_impl_server_protocol_init(
struct wsfs_server_protocol * protocol,
char * mount_point);
extern void wsfs_impl_server_protocol_cleanup(
struct wsfs_server_protocol * protocol);
extern struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
char * mount_point);
extern void wsfs_impl_server_protocol_dispose(
struct wsfs_server_protocol * protocol);
extern void wsfs_impl_server_protocol_init_lws(
struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol);
extern void wsfs_impl_server_protocol_add_authenticator(
struct wsfs_server_protocol * protocol,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,17 +1,17 @@
#include "wsfs/adapter/session.h"
#include "wsfs/adapter/authenticators.h"
#include "wsfs/message_queue.h"
#include "wsfs/message.h"
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/adapter/impl/session.h"
#include "wsfs/adapter/impl/authenticators.h"
#include "wsfs/core/message_queue.h"
#include "wsfs/core/message.h"
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include <libwebsockets.h>
#include <stddef.h>
void wsfs_session_init(
struct wsfs_session * session,
void wsfs_impl_session_init(
struct wsfs_impl_session * session,
struct lws * wsi,
struct wsfs_authenticators * authenticators,
struct wsfs_jsonrpc_server * rpc)
struct wsfs_impl_authenticators * authenticators,
struct wsfs_impl_jsonrpc_server * rpc)
{
session->wsi = wsi;
session->is_authenticated = false;
@ -20,8 +20,8 @@ void wsfs_session_init(
wsfs_message_queue_init(&session->queue);
}
void wsfs_session_cleanup(
struct wsfs_session * session)
void wsfs_impl_session_cleanup(
struct wsfs_impl_session * session)
{
wsfs_message_queue_cleanup(&session->queue);
session->is_authenticated = false;
@ -30,15 +30,15 @@ void wsfs_session_cleanup(
session->rpc = NULL;
}
void wsfs_session_authenticate(
struct wsfs_session * session,
void wsfs_impl_session_authenticate(
struct wsfs_impl_session * session,
struct wsfs_credentials * creds)
{
session->is_authenticated = wsfs_authenticators_authenticate(session->authenticators, creds);
session->is_authenticated = wsfs_impl_authenticators_authenticate(session->authenticators, creds);
}
bool wsfs_session_send(
struct wsfs_session * session,
bool wsfs_impl_session_send(
struct wsfs_impl_session * session,
struct wsfs_message * message)
{
bool result = (session->is_authenticated) && (NULL != session->wsi);
@ -58,8 +58,8 @@ bool wsfs_session_send(
return result;
}
void wsfs_session_onwritable(
struct wsfs_session * session)
void wsfs_impl_session_onwritable(
struct wsfs_impl_session * session)
{
if (!wsfs_message_queue_empty(&session->queue))
{
@ -75,10 +75,10 @@ void wsfs_session_onwritable(
}
void wsfs_session_receive(
struct wsfs_session * session,
void wsfs_impl_session_receive(
struct wsfs_impl_session * session,
char const * data,
size_t length)
{
wsfs_jsonrpc_server_onresult(session->rpc, data, length);
wsfs_impl_jsonrpc_server_onresult(session->rpc, data, length);
}

View File

@ -0,0 +1,64 @@
#ifndef WSFS_ADAPTER_IMPL_SESSION_H
#define WSFS_ADAPTER_IMPL_SESSION_H
#ifndef __cplusplus
#include <stdbool.h>
#include <stddef.h>
#else
#include <cstddef>
using std::size_t;
#endif
#include "wsfs/core/message_queue.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct lws;
struct wsfs_message;
struct wsfs_credentials;
struct wsfs_impl_authenticators;
struct wsfs_impl_jsonrpc_server;
struct wsfs_impl_session
{
struct lws * wsi;
bool is_authenticated;
struct wsfs_message_queue queue;
struct wsfs_impl_authenticators * authenticators;
struct wsfs_impl_jsonrpc_server * rpc;
};
extern void wsfs_impl_session_init(
struct wsfs_impl_session * session,
struct lws * wsi,
struct wsfs_impl_authenticators * authenticators,
struct wsfs_impl_jsonrpc_server * rpc);
extern void wsfs_impl_session_authenticate(
struct wsfs_impl_session * session,
struct wsfs_credentials * creds);
extern bool wsfs_impl_session_send(
struct wsfs_impl_session * session,
struct wsfs_message * message);
extern void wsfs_impl_session_receive(
struct wsfs_impl_session * session,
char const * data,
size_t length);
extern void wsfs_impl_session_onwritable(
struct wsfs_impl_session * session);
extern void wsfs_impl_session_cleanup(
struct wsfs_impl_session * session);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,54 @@
#include "wsfs/adapter/impl/session_manager.h"
#include <stddef.h>
void wsfs_impl_session_manager_init(
struct wsfs_impl_session_manager * manager)
{
wsfs_impl_session_init(&manager->session, NULL, NULL, NULL);
}
void wsfs_impl_session_manager_cleanup(
struct wsfs_impl_session_manager * manager)
{
wsfs_impl_session_cleanup(&manager->session);
}
struct wsfs_impl_session * wsfs_impl_session_manager_add(
struct wsfs_impl_session_manager * manager,
struct lws * wsi,
struct wsfs_impl_authenticators * authenticators,
struct wsfs_impl_jsonrpc_server * rpc)
{
struct wsfs_impl_session * session = NULL;
if (NULL == manager->session.wsi)
{
session = &manager->session;
wsfs_impl_session_init(&manager->session, wsi, authenticators, rpc);
}
return session;
}
struct wsfs_impl_session * wsfs_impl_session_manager_get(
struct wsfs_impl_session_manager * manager,
struct lws * wsi)
{
struct wsfs_impl_session * session = NULL;
if (wsi == manager->session.wsi)
{
session = &manager->session;
}
return session;
}
void wsfs_impl_session_manager_remove(
struct wsfs_impl_session_manager * manager,
struct lws * wsi)
{
if (wsi == manager->session.wsi)
{
wsfs_impl_session_cleanup(&manager->session);
manager->session.wsi = NULL;
}
}

View File

@ -0,0 +1,46 @@
#ifndef WSFS_ADAPTER_IMPL_SESSION_MANAGER_H
#define WSFS_ADAPTER_IMPL_SESSION_MANAGER_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/impl/session.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct lws;
struct wsfs_impl_session_manager
{
struct wsfs_impl_session session;
};
extern void wsfs_impl_session_manager_init(
struct wsfs_impl_session_manager * manager);
extern void wsfs_impl_session_manager_cleanup(
struct wsfs_impl_session_manager * manager);
extern struct wsfs_impl_session * wsfs_impl_session_manager_add(
struct wsfs_impl_session_manager * manager,
struct lws * wsi,
struct wsfs_impl_authenticators * authenticators,
struct wsfs_impl_jsonrpc_server * rpc);
extern struct wsfs_impl_session * wsfs_impl_session_manager_get(
struct wsfs_impl_session_manager * manager,
struct lws * wsi);
extern void wsfs_impl_session_manager_remove(
struct wsfs_impl_session_manager * manager,
struct lws * wsi);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,84 @@
#include "wsfs/adapter/impl/time/timeout_manager_intern.h"
#include <stddef.h>
#include "wsfs/adapter/impl/time/timer_intern.h"
#include "wsfs/adapter/impl/time/timepoint.h"
void wsfs_impl_timeout_manager_init(
struct wsfs_impl_timeout_manager * manager)
{
manager->timers = NULL;
}
void wsfs_impl_timeout_manager_cleanup(
struct wsfs_impl_timeout_manager * manager)
{
struct wsfs_impl_timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_impl_timer * next = timer->next;
wsfs_impl_timer_trigger(timer);
timer = next;
}
manager->timers = NULL;
}
void wsfs_impl_timeout_manager_check(
struct wsfs_impl_timeout_manager * manager)
{
struct wsfs_impl_timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_impl_timer * next = timer->next;
if (wsfs_impl_timer_is_timeout(timer))
{
wsfs_impl_timeout_manager_removetimer(manager, timer);
wsfs_impl_timer_trigger(timer);
}
timer = next;
}
}
void wsfs_impl_timeout_manager_addtimer(
struct wsfs_impl_timeout_manager * manager,
struct wsfs_impl_timer * timer)
{
if (NULL != manager->timers)
{
manager->timers->prev = timer;
}
timer->next = manager->timers;
timer->prev = NULL;
manager->timers = timer;
}
void wsfs_impl_timeout_manager_removetimer(
struct wsfs_impl_timeout_manager * manager,
struct wsfs_impl_timer * timer)
{
struct wsfs_impl_timer * prev = timer->prev;
struct wsfs_impl_timer * next = timer->next;
if (NULL != prev)
{
prev->next = next;
}
if (NULL != next)
{
next->prev = prev;
}
if (manager->timers == timer)
{
manager->timers = next;
}
}

View File

@ -0,0 +1,29 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_impl_timer;
struct wsfs_impl_timeout_manager
{
struct wsfs_impl_timer * timers;
};
extern void wsfs_impl_timeout_manager_init(
struct wsfs_impl_timeout_manager * manager);
extern void wsfs_impl_timeout_manager_cleanup(
struct wsfs_impl_timeout_manager * manager);
extern void wsfs_impl_timeout_manager_check(
struct wsfs_impl_timeout_manager * manager);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,24 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
#include "wsfs/adapter/impl/time/timeout_manager.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_impl_timeout_manager_addtimer(
struct wsfs_impl_timeout_manager * manager,
struct wsfs_impl_timer * timer);
extern void wsfs_impl_timeout_manager_removetimer(
struct wsfs_impl_timeout_manager * manager,
struct wsfs_impl_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,31 @@
#include "wsfs/adapter/impl/time/timepoint.h"
#include <time.h>
#define WSFS_MSEC_PER_SEC ((wsfs_impl_timepoint) 1000)
#define WSFS_NSEC_PER_MSEC ((wsfs_impl_timepoint) 1000 * 1000)
wsfs_impl_timepoint wsfs_impl_timepoint_now(void)
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
wsfs_impl_timepoint const now = (tp.tv_sec * WSFS_MSEC_PER_SEC) + (tp.tv_nsec / WSFS_NSEC_PER_MSEC);
return now;
}
wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(wsfs_impl_timediff value)
{
wsfs_impl_timepoint const now = wsfs_impl_timepoint_now();
wsfs_impl_timepoint result = now + ((wsfs_impl_timepoint) value);
return result;
}
bool wsfs_impl_timepoint_is_elapsed(wsfs_impl_timepoint tp)
{
wsfs_impl_timepoint const now = wsfs_impl_timepoint_now();
wsfs_impl_timediff const diff = (wsfs_impl_timediff) (tp - now);
return (0 > diff);
}

View File

@ -0,0 +1,31 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H
#define WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H
#ifndef __cplusplus
#include <stdbool.h>
#include <inttypes.h>
#else
#include <cinttypes>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
typedef uint64_t wsfs_impl_timepoint;
typedef int64_t wsfs_impl_timediff;
extern wsfs_impl_timepoint wsfs_impl_timepoint_now(void);
extern wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(
wsfs_impl_timediff value);
extern bool wsfs_impl_timepoint_is_elapsed(
wsfs_impl_timepoint timepoint);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,65 @@
#include "wsfs/adapter/impl/time/timer_intern.h"
#include "wsfs/adapter/impl/time/timeout_manager_intern.h"
#include <stddef.h>
#include <string.h>
void wsfs_impl_timer_init(
struct wsfs_impl_timer * timer,
struct wsfs_impl_timeout_manager * manager)
{
timer->manager = manager;
timer->timeout = 0;
timer->timeout_handler = NULL;
timer->user_data = NULL;
timer->prev = NULL;
timer->next = NULL;
}
void wsfs_impl_timer_cleanup(
struct wsfs_impl_timer * timer)
{
memset(timer, 0, sizeof(struct wsfs_impl_timer));
}
void wsfs_impl_timer_start(
struct wsfs_impl_timer * timer,
wsfs_impl_timepoint absolute_timeout,
wsfs_impl_timer_timeout_fn * handler,
void * user_data)
{
timer->timeout = absolute_timeout;
timer->timeout_handler = handler;
timer->user_data = user_data;
wsfs_impl_timeout_manager_addtimer(timer->manager, timer);
}
void wsfs_impl_timer_cancel(
struct wsfs_impl_timer * timer)
{
wsfs_impl_timeout_manager_removetimer(timer->manager, timer);
timer->timeout = 0;
timer->timeout_handler = NULL;
timer->user_data = NULL;
}
bool wsfs_impl_timer_is_timeout(
struct wsfs_impl_timer * timer)
{
return wsfs_impl_timepoint_is_elapsed(timer->timeout);
}
void wsfs_impl_timer_trigger(
struct wsfs_impl_timer * timer)
{
if (NULL != timer->timeout_handler)
{
timer->prev = NULL;
timer->next = NULL;
timer->timeout_handler(timer);
}
}

View File

@ -0,0 +1,48 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_H
#define WSFS_ADAPTER_IMPL_TIME_TIMER_H
#include "wsfs/adapter/impl/time/timepoint.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_impl_timer;
struct wsfs_impl_timeout_manager;
typedef void wsfs_impl_timer_timeout_fn(struct wsfs_impl_timer * timer);
struct wsfs_impl_timer
{
struct wsfs_impl_timeout_manager * manager;
wsfs_impl_timepoint timeout;
wsfs_impl_timer_timeout_fn * timeout_handler;
void * user_data;
struct wsfs_impl_timer * next;
struct wsfs_impl_timer * prev;
};
extern void wsfs_impl_timer_init(
struct wsfs_impl_timer * timer,
struct wsfs_impl_timeout_manager * manager);
extern void wsfs_impl_timer_cleanup(
struct wsfs_impl_timer * timer);
extern void wsfs_impl_timer_start(
struct wsfs_impl_timer * timer,
wsfs_impl_timepoint absolute_timeout,
wsfs_impl_timer_timeout_fn * handler,
void * user_data);
extern void wsfs_impl_timer_cancel(
struct wsfs_impl_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,25 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
#define WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/impl/time/timer.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern bool wsfs_impl_timer_is_timeout(
struct wsfs_impl_timer * timer);
extern void wsfs_impl_timer_trigger(
struct wsfs_impl_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,28 +0,0 @@
#include "wsfs/adapter/jsonrpc/method_intern.h"
#include <stdlib.h>
#include <string.h>
struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
char const * name,
wsfs_jsonrpc_method_invoke_fn * invoke,
void * user_data)
{
struct wsfs_jsonrpc_method * method = malloc(sizeof(struct wsfs_jsonrpc_method));
if (NULL != method)
{
method->next = NULL;
method->name = strdup(name);
method->invoke = invoke;
method->user_data = user_data;
}
return method;
}
void wsfs_jsonrpc_method_dispose(
struct wsfs_jsonrpc_method * method)
{
free(method->name);
free(method);
}

View File

@ -1,24 +0,0 @@
#ifndef WSFS_ADAPTER_JSONRPC_METHOD_H
#define WSFS_ADAPTER_JSONRPC_METHOD_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include <jansson.h>
#include "wsfs/status.h"
typedef bool wsfs_jsonrpc_method_invoke_fn(
void * user_data,
struct json_t const * method_call);
typedef void wsfs_jsonrpc_method_finished_fn(
void * user_data,
wsfs_status status,
struct json_t const * result);
#endif

View File

@ -1,31 +0,0 @@
#ifndef WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H
#define WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H
#include "wsfs/adapter/jsonrpc/method.h"
struct wsfs_jsonrpc_method
{
struct wsfs_jsonrpc_method * next;
char * name;
wsfs_jsonrpc_method_invoke_fn * invoke;
void * user_data;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
char const * name,
wsfs_jsonrpc_method_invoke_fn * invoke,
void * user_data);
extern void wsfs_jsonrpc_method_dispose(
struct wsfs_jsonrpc_method * method);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,38 +0,0 @@
#ifndef WSFS_ADAPTER_JSONRPC_RESPONSE_H
#define WSFS_ADAPTER_JSONRPC_RESPONSE_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
using std::size_t;
#endif
#include <jansson.h>
#include "wsfs/status.h"
struct wsfs_jsonrpc_response
{
wsfs_status status;
int id;
json_t * result;
};
#ifdef __cplusplus
extern "C" {
#endif
extern void wsfs_jsonrpc_response_init(
struct wsfs_jsonrpc_response * response,
char const * buffer,
size_t buffer_length);
extern void wsfs_jsonrpc_response_cleanup(
struct wsfs_jsonrpc_response * response);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,80 +0,0 @@
#ifndef WSFS_ADAPTER_JSONRPC_SERVER_H
#define WSFS_ADAPTER_JSONRPC_SERVER_H
#ifndef __cplusplus
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
#else
#include <cstdarg>
#include <cstddef>
using std::size_t;
#endif
#include <jansson.h>
#include "wsfs/adapter/jsonrpc/method.h"
#include "wsfs/adapter/time/timeout_manager.h"
#include "wsfs/adapter/time/timer.h"
struct wsfs_jsonrpc_request
{
bool is_pending;
wsfs_jsonrpc_method_finished_fn * finished;
void * user_data;
int id;
struct wsfs_timer timer;
};
struct wsfs_jsonrpc_server
{
struct wsfs_jsonrpc_method * methods;
struct wsfs_jsonrpc_request request;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_jsonrpc_server_init(
struct wsfs_jsonrpc_server * server,
struct wsfs_timeout_manager * manager);
extern void wsfs_jsonrpc_server_cleanup(
struct wsfs_jsonrpc_server * server);
extern void wsfs_jsonrpc_server_add(
struct wsfs_jsonrpc_server * server,
char const * name,
wsfs_jsonrpc_method_invoke_fn * invoke,
void * user_data );
extern void wsfs_jsonrpc_server_invoke(
struct wsfs_jsonrpc_server * server,
wsfs_jsonrpc_method_finished_fn * finished,
void * user_data,
char const * method_name,
char const * param_info,
...
);
extern void wsfs_jsonrpc_server_notify(
struct wsfs_jsonrpc_server * server,
char const * method_name,
char const * param_info,
...
);
extern void wsfs_jsonrpc_server_onresult(
struct wsfs_jsonrpc_server * server,
char const * message,
size_t length);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,17 +0,0 @@
#ifndef WSFS_ADAPTER_JSON_UTIL_H
#define WSFS_ADAPTER_JSON_UTIL_H
#include <jansson.h>
#ifdef __cplusplus
extern "C"
{
#endif
extern int wsfs_json_get_int(json_t const * object, char const * key, int default_value);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,21 +0,0 @@
#include "wsfs/adapter/operations.h"
#include <limits.h>
#include <errno.h>
#include <jansson.h>
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/util.h"
void wsfs_operation_close(
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * file_info)
{
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
int handle = (int) (file_info->fh & INT_MAX);
wsfs_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
fuse_reply_err(request, 0);
}

View File

@ -1,37 +0,0 @@
#ifndef WSFS_ADAPTER_SERVER_CONFIG_INTERN_H
#define WSFS_ADAPTER_SERVER_CONFIG_INTERN_H
#include "wsfs/adapter/server_config.h"
#include "wsfs/adapter/authenticators.h"
struct wsfs_server_config
{
char * mount_point;
char * document_root;
char * key_path;
char * cert_path;
char * vhost_name;
int port;
struct wsfs_authenticators authenticators;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_server_config_init(
struct wsfs_server_config * config);
extern void wsfs_server_config_cleanup(
struct wsfs_server_config * config);
extern void wsfs_server_config_clone(
struct wsfs_server_config * config,
struct wsfs_server_config * clone);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,166 +0,0 @@
#include "wsfs/adapter/server_protocol_intern.h"
#include <stdlib.h>
#include <libwebsockets.h>
#include "wsfs/message.h"
#include "wsfs/util.h"
#include "wsfs/adapter/filesystem.h"
static int wsfs_server_protocol_callback(
struct lws * wsi,
enum lws_callback_reasons reason,
void * WSFS_UNUSED_PARAM(user),
void * in,
size_t len)
{
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
struct wsfs_server_protocol * protocol = ws_protocol->user;
wsfs_timeout_manager_check(&protocol->timeout_manager);
struct wsfs_session * session = wsfs_session_manager_get(&protocol->session_manager, wsi);
switch (reason)
{
case LWS_CALLBACK_PROTOCOL_INIT:
{
lws_sock_file_fd_type fd;
fd.filefd = wsfs_filesystem_get_fd(&protocol->filesystem);
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
{
fprintf(stderr, "error: unable to adopt fd");
}
}
break;
case LWS_CALLBACK_ESTABLISHED:
session = wsfs_session_manager_add(
&protocol->session_manager,
wsi,
&protocol->authenticators,
&protocol->rpc);
if (NULL != session)
{
wsfs_session_authenticate(session, NULL);
}
break;
case LWS_CALLBACK_CLOSED:
wsfs_session_manager_remove(&protocol->session_manager, wsi);
break;
case LWS_CALLBACK_SERVER_WRITEABLE:
if (NULL != session)
{
wsfs_session_onwritable(session);
}
break;
case LWS_CALLBACK_RECEIVE:
if (NULL != session)
{
wsfs_session_receive(session, in, len);
}
break;
case LWS_CALLBACK_RAW_RX_FILE:
wsfs_filesystem_process_request(&protocol->filesystem);
break;
default:
break;
}
return 0;
}
static bool wsfs_server_protocol_invoke(
void * user_data,
json_t const * request)
{
struct wsfs_server_protocol * protocol = user_data;
struct wsfs_session * session = &protocol->session_manager.session;
struct wsfs_message * message = wsfs_message_create(request);
bool const result = wsfs_session_send(session, message);
return result;
}
struct wsfs_server_protocol * wsfs_server_protocol_create(
char * mount_point)
{
struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol));
if (NULL != protocol)
{
if (!wsfs_server_protocol_init(protocol, mount_point))
{
free(protocol);
protocol = NULL;
}
}
return protocol;
}
void wsfs_server_protocol_dispose(
struct wsfs_server_protocol * protocol)
{
wsfs_server_protocol_cleanup(protocol);
free(protocol);
}
void wsfs_server_protocol_init_lws(
struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol)
{
lws_protocol->callback = &wsfs_server_protocol_callback;
lws_protocol->per_session_data_size = 0;
lws_protocol->user = protocol;
}
bool wsfs_server_protocol_init(
struct wsfs_server_protocol * protocol,
char * mount_point)
{
wsfs_timeout_manager_init(&protocol->timeout_manager);
wsfs_session_manager_init(&protocol->session_manager);
wsfs_authenticators_init(&protocol->authenticators);
wsfs_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
wsfs_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_server_protocol_invoke, protocol);
bool const success = wsfs_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
// cleanup on error
if (!success)
{
wsfs_jsonrpc_server_cleanup(&protocol->rpc);
wsfs_authenticators_cleanup(&protocol->authenticators);
wsfs_timeout_manager_cleanup(&protocol->timeout_manager);
wsfs_session_manager_cleanup(&protocol->session_manager);
}
return success;
}
void wsfs_server_protocol_cleanup(
struct wsfs_server_protocol * protocol)
{
wsfs_filesystem_cleanup(&protocol->filesystem);
wsfs_jsonrpc_server_cleanup(&protocol->rpc);
wsfs_timeout_manager_cleanup(&protocol->timeout_manager);
wsfs_authenticators_cleanup(&protocol->authenticators);
wsfs_session_manager_cleanup(&protocol->session_manager);
}
void wsfs_server_protocol_add_authenticator(
struct wsfs_server_protocol * protocol,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
wsfs_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
}

View File

@ -1,27 +0,0 @@
#ifndef WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H
#define WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H
#include "wsfs/adapter/server_protocol.h"
#include "wsfs/adapter/filesystem.h"
#include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/adapter/time/timeout_manager.h"
#include "wsfs/adapter/authenticators.h"
#include "wsfs/adapter/session_manager.h"
struct wsfs_server_protocol
{
struct wsfs_timeout_manager timeout_manager;
struct wsfs_filesystem filesystem;
struct wsfs_jsonrpc_server rpc;
struct wsfs_authenticators authenticators;
struct wsfs_session_manager session_manager;
};
extern bool wsfs_server_protocol_init(
struct wsfs_server_protocol * protocol,
char * mount_point);
extern void wsfs_server_protocol_cleanup(
struct wsfs_server_protocol * protocol);
#endif

View File

@ -1,64 +0,0 @@
#ifndef WSFS_ADAPTER_SESSION_H
#define WSFS_ADAPTER_SESSION_H
#ifndef __cplusplus
#include <stdbool.h>
#include <stddef.h>
#else
#include <cstddef>
using std::size_t;
#endif
#include "wsfs/message_queue.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct lws;
struct wsfs_message;
struct wsfs_credentials;
struct wsfs_authenticators;
struct wsfs_jsonrpc_server;
struct wsfs_session
{
struct lws * wsi;
bool is_authenticated;
struct wsfs_message_queue queue;
struct wsfs_authenticators * authenticators;
struct wsfs_jsonrpc_server * rpc;
};
extern void wsfs_session_init(
struct wsfs_session * session,
struct lws * wsi,
struct wsfs_authenticators * authenticators,
struct wsfs_jsonrpc_server * rpc);
extern void wsfs_session_authenticate(
struct wsfs_session * session,
struct wsfs_credentials * creds);
extern bool wsfs_session_send(
struct wsfs_session * session,
struct wsfs_message * message);
extern void wsfs_session_receive(
struct wsfs_session * session,
char const * data,
size_t length);
extern void wsfs_session_onwritable(
struct wsfs_session * session);
extern void wsfs_session_cleanup(
struct wsfs_session * session);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,54 +0,0 @@
#include "wsfs/adapter/session_manager.h"
#include <stddef.h>
void wsfs_session_manager_init(
struct wsfs_session_manager * manager)
{
wsfs_session_init(&manager->session, NULL, NULL, NULL);
}
void wsfs_session_manager_cleanup(
struct wsfs_session_manager * manager)
{
wsfs_session_cleanup(&manager->session);
}
struct wsfs_session * wsfs_session_manager_add(
struct wsfs_session_manager * manager,
struct lws * wsi,
struct wsfs_authenticators * authenticators,
struct wsfs_jsonrpc_server * rpc)
{
struct wsfs_session * session = NULL;
if (NULL == manager->session.wsi)
{
session = &manager->session;
wsfs_session_init(&manager->session, wsi, authenticators, rpc);
}
return session;
}
struct wsfs_session * wsfs_session_manager_get(
struct wsfs_session_manager * manager,
struct lws * wsi)
{
struct wsfs_session * session = NULL;
if (wsi == manager->session.wsi)
{
session = &manager->session;
}
return session;
}
void wsfs_session_manager_remove(
struct wsfs_session_manager * manager,
struct lws * wsi)
{
if (wsi == manager->session.wsi)
{
wsfs_session_cleanup(&manager->session);
manager->session.wsi = NULL;
}
}

View File

@ -1,46 +0,0 @@
#ifndef WSFS_ADAPTER_SESSION_MANAGER_H
#define WSFS_ADAPTER_SESSION_MANAGER_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/session.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct lws;
struct wsfs_session_manager
{
struct wsfs_session session;
};
extern void wsfs_session_manager_init(
struct wsfs_session_manager * manager);
extern void wsfs_session_manager_cleanup(
struct wsfs_session_manager * manager);
extern struct wsfs_session * wsfs_session_manager_add(
struct wsfs_session_manager * manager,
struct lws * wsi,
struct wsfs_authenticators * authenticators,
struct wsfs_jsonrpc_server * rpc);
extern struct wsfs_session * wsfs_session_manager_get(
struct wsfs_session_manager * manager,
struct lws * wsi);
extern void wsfs_session_manager_remove(
struct wsfs_session_manager * manager,
struct lws * wsi);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,84 +0,0 @@
#include "wsfs/adapter/time/timeout_manager_intern.h"
#include <stddef.h>
#include "wsfs/adapter/time/timer_intern.h"
#include "wsfs/adapter/time/timepoint.h"
void wsfs_timeout_manager_init(
struct wsfs_timeout_manager * manager)
{
manager->timers = NULL;
}
void wsfs_timeout_manager_cleanup(
struct wsfs_timeout_manager * manager)
{
struct wsfs_timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_timer * next = timer->next;
wsfs_timer_trigger(timer);
timer = next;
}
manager->timers = NULL;
}
void wsfs_timeout_manager_check(
struct wsfs_timeout_manager * manager)
{
struct wsfs_timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_timer * next = timer->next;
if (wsfs_timer_is_timeout(timer))
{
wsfs_timeout_manager_removetimer(manager, timer);
wsfs_timer_trigger(timer);
}
timer = next;
}
}
void wsfs_timeout_manager_addtimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer)
{
if (NULL != manager->timers)
{
manager->timers->prev = timer;
}
timer->next = manager->timers;
timer->prev = NULL;
manager->timers = timer;
}
void wsfs_timeout_manager_removetimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer)
{
struct wsfs_timer * prev = timer->prev;
struct wsfs_timer * next = timer->next;
if (NULL != prev)
{
prev->next = next;
}
if (NULL != next)
{
next->prev = prev;
}
if (manager->timers == timer)
{
manager->timers = next;
}
}

View File

@ -1,29 +0,0 @@
#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H
#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H
struct wsfs_timer;
struct wsfs_timeout_manager
{
struct wsfs_timer * timers;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_timeout_manager_init(
struct wsfs_timeout_manager * manager);
extern void wsfs_timeout_manager_cleanup(
struct wsfs_timeout_manager * manager);
extern void wsfs_timeout_manager_check(
struct wsfs_timeout_manager * manager);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,24 +0,0 @@
#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H
#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H
#include "wsfs/adapter/time/timeout_manager.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_timeout_manager_addtimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer);
extern void wsfs_timeout_manager_removetimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,31 +0,0 @@
#include "wsfs/adapter/time/timepoint.h"
#include <time.h>
#define WSFS_MSEC_PER_SEC ((wsfs_timepoint) 1000)
#define WSFS_NSEC_PER_MSEC ((wsfs_timepoint) 1000 * 1000)
wsfs_timepoint wsfs_timepoint_now(void)
{
struct timespec timepoint;
clock_gettime(CLOCK_MONOTONIC, &timepoint);
wsfs_timepoint const now = (timepoint.tv_sec * WSFS_MSEC_PER_SEC) + (timepoint.tv_nsec / WSFS_NSEC_PER_MSEC);
return now;
}
wsfs_timepoint wsfs_timepoint_in_msec(wsfs_timediff value)
{
wsfs_timepoint const now = wsfs_timepoint_now();
wsfs_timepoint result = now + ((wsfs_timepoint) value);
return result;
}
bool wsfs_timepoint_is_elapsed(wsfs_timepoint timepoint)
{
wsfs_timepoint const now = wsfs_timepoint_now();
wsfs_timediff const diff = (wsfs_timediff) (timepoint - now);
return (0 > diff);
}

View File

@ -1,31 +0,0 @@
#ifndef WSFS_ADAPTER_TIME_TIMEPOINT_H
#define WSFS_ADAPTER_TIME_TIMEPOINT_H
#ifndef __cplusplus
#include <stdbool.h>
#include <inttypes.h>
#else
#include <cinttypes>
#endif
typedef uint64_t wsfs_timepoint;
typedef int64_t wsfs_timediff;
#ifdef __cplusplus
extern "C"
{
#endif
extern wsfs_timepoint wsfs_timepoint_now(void);
extern wsfs_timepoint wsfs_timepoint_in_msec(
wsfs_timediff value);
extern bool wsfs_timepoint_is_elapsed(
wsfs_timepoint timepoint);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,65 +0,0 @@
#include "wsfs/adapter/time/timer_intern.h"
#include "wsfs/adapter/time/timeout_manager_intern.h"
#include <stddef.h>
#include <string.h>
void wsfs_timer_init(
struct wsfs_timer * timer,
struct wsfs_timeout_manager * manager)
{
timer->manager = manager;
timer->timeout = 0;
timer->timeout_handler = NULL;
timer->user_data = NULL;
timer->prev = NULL;
timer->next = NULL;
}
void wsfs_timer_cleanup(
struct wsfs_timer * timer)
{
memset(timer, 0, sizeof(struct wsfs_timer));
}
void wsfs_timer_start(
struct wsfs_timer * timer,
wsfs_timepoint absolute_timeout,
wsfs_timer_timeout_fn * handler,
void * user_data)
{
timer->timeout = absolute_timeout;
timer->timeout_handler = handler;
timer->user_data = user_data;
wsfs_timeout_manager_addtimer(timer->manager, timer);
}
void wsfs_timer_cancel(
struct wsfs_timer * timer)
{
wsfs_timeout_manager_removetimer(timer->manager, timer);
timer->timeout = 0;
timer->timeout_handler = NULL;
timer->user_data = NULL;
}
bool wsfs_timer_is_timeout(
struct wsfs_timer * timer)
{
return wsfs_timepoint_is_elapsed(timer->timeout);
}
void wsfs_timer_trigger(
struct wsfs_timer * timer)
{
if (NULL != timer->timeout_handler)
{
timer->prev = NULL;
timer->next = NULL;
timer->timeout_handler(timer);
}
}

View File

@ -1,48 +0,0 @@
#ifndef WSFS_ADAPTER_TIME_TIMER_H
#define WSFS_ADAPTER_TIME_TIMER_H
#include "wsfs/adapter/time/timepoint.h"
struct wsfs_timer;
struct wsfs_timeout_manager;
typedef void wsfs_timer_timeout_fn(struct wsfs_timer * timer);
struct wsfs_timer
{
struct wsfs_timeout_manager * manager;
wsfs_timepoint timeout;
wsfs_timer_timeout_fn * timeout_handler;
void * user_data;
struct wsfs_timer * next;
struct wsfs_timer * prev;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_timer_init(
struct wsfs_timer * timer,
struct wsfs_timeout_manager * manager);
extern void wsfs_timer_cleanup(
struct wsfs_timer * timer);
extern void wsfs_timer_start(
struct wsfs_timer * timer,
wsfs_timepoint absolute_timeout,
wsfs_timer_timeout_fn * handler,
void * user_data);
extern void wsfs_timer_cancel(
struct wsfs_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,25 +0,0 @@
#ifndef WSFS_ADAPTER_TIME_TIMER_INTERN_H
#define WSFS_ADAPTER_TIME_TIMER_INTERN_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/time/timer.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern bool wsfs_timer_is_timeout(
struct wsfs_timer * timer);
extern void wsfs_timer_trigger(
struct wsfs_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,4 +1,4 @@
#include "wsfs/message.h"
#include "wsfs/core/message.h"
#include <stdlib.h>
#include <libwebsockets.h>

View File

@ -1,5 +1,5 @@
#include "wsfs/message_queue.h"
#include "wsfs/message.h"
#include "wsfs/core/message_queue.h"
#include "wsfs/core/message.h"
void wsfs_message_queue_init(
struct wsfs_message_queue * queue)

View File

@ -1,4 +1,4 @@
#include "wsfs/status_intern.h"
#include "wsfs/core/status_intern.h"
#include <errno.h>

View File

@ -1,7 +1,7 @@
#ifndef WSFS_STATUS_INTERN_H
#define WSFS_STATUS_INTERN_H
#include "wsfs/status.h"
#include "wsfs/core/status.h"
#ifdef __cplusplus
extern "C" {

240
lib/wsfs/provider/api.c Normal file
View File

@ -0,0 +1,240 @@
#include "wsfs_provider.h"
#include "wsfs/provider/impl/request.h"
#include "wsfs/provider/impl/operation/getattr.h"
#include "wsfs/provider/impl/operation/lookup.h"
#include "wsfs/provider/impl/operation/readdir.h"
#include "wsfs/provider/impl/operation/open.h"
#include "wsfs/provider/impl/operation/close.h"
#include "wsfs/provider/impl/operation/read.h"
#include "wsfs/provider/impl/client_protocol.h"
#include "wsfs/provider/impl/client_config.h"
#include "wsfs/provider/impl/client.h"
#include "wsfs/provider/impl/dirbuffer.h"
// respond
void wsfsp_respond_error(
struct wsfsp_request * request,
wsfs_status status)
{
wsfsp_impl_respond_error(request, status);
}
void wsfsp_respond_getattr(
struct wsfsp_request * request,
struct stat const * stat)
{
wsfsp_impl_respond_getattr(request, stat);
}
void wsfsp_respond_lookup(
struct wsfsp_request * request,
struct stat const * stat)
{
wsfsp_impl_respond_lookup(request, stat);
}
void wsfsp_respond_open(
struct wsfsp_request * request,
uint32_t handle)
{
wsfsp_impl_respond_open(request, handle);
}
void wsfsp_respond_read(
struct wsfsp_request * request,
char const * data,
size_t length)
{
wsfsp_impl_respond_read(request, data, length);
}
void wsfsp_respond_readdir(
struct wsfsp_request * request,
struct wsfsp_dirbuffer * dirbuffer)
{
wsfsp_impl_respond_readdir(request, dirbuffer);
}
// config
struct wsfsp_client_config * wsfsp_client_config_create(void)
{
return wsfsp_impl_client_config_create();
}
void wsfsp_client_config_dispose(
struct wsfsp_client_config * config)
{
wsfsp_impl_client_config_dispose(config);
}
void wsfsp_client_config_set_userdata(
struct wsfsp_client_config * config,
void * user_data)
{
wsfsp_impl_client_config_set_userdata(config, user_data);
}
void wsfsp_client_config_set_keypath(
struct wsfsp_client_config * config,
char const * key_path)
{
wsfsp_impl_client_config_set_keypath(config, key_path);
}
void wsfsp_client_config_set_certpath(
struct wsfsp_client_config * config,
char const * cert_path)
{
wsfsp_impl_client_config_set_certpath(config, cert_path);
}
void wsfsp_client_config_set_onconnected(
struct wsfsp_client_config * config,
wsfsp_connected_fn * handler)
{
wsfsp_impl_client_config_set_onconnected(config, handler);
}
void wsfsp_client_config_set_ondisconnected(
struct wsfsp_client_config * config,
wsfsp_disconnected_fn * handler)
{
wsfsp_impl_client_config_set_ondisconnected(config, handler);
}
void wsfsp_client_config_set_ontimer(
struct wsfsp_client_config * config,
wsfsp_ontimer_fn * handler)
{
wsfsp_impl_client_config_set_ontimer(config, handler);
}
void wsfsp_client_config_set_onlookup(
struct wsfsp_client_config * config,
wsfsp_lookup_fn * handler)
{
wsfsp_impl_client_config_set_onlookup(config, handler);
}
void wsfsp_client_config_set_ongetattr(
struct wsfsp_client_config * config,
wsfsp_getattr_fn * handler)
{
wsfsp_impl_client_config_set_ongetattr(config, handler);
}
void wsfsp_client_config_set_onreaddir(
struct wsfsp_client_config * config,
wsfsp_readdir_fn * handler)
{
wsfsp_impl_client_config_set_onreaddir(config, handler);
}
void wsfsp_client_config_set_onopen(
struct wsfsp_client_config * config,
wsfsp_open_fn * handler)
{
wsfsp_impl_client_config_set_onopen(config, handler);
}
void wsfsp_client_config_set_onclose(
struct wsfsp_client_config * config,
wsfsp_close_fn * handler)
{
wsfsp_impl_client_config_set_onclose(config, handler);
}
void wsfsp_client_config_set_onread(
struct wsfsp_client_config * config,
wsfsp_read_fn * handler)
{
wsfsp_impl_client_config_set_onread(config, handler);
}
// protocol
struct wsfsp_client_protocol * wsfsp_client_protocol_create(
struct wsfsp_provider const * provider,
void * user_data)
{
return wsfsp_impl_client_protocol_create(provider, user_data);
}
void wsfsp_client_protocol_dispose(
struct wsfsp_client_protocol * protocol)
{
wsfsp_impl_client_protocol_dispose(protocol);
}
void wsfsp_client_protocol_init_lws(
struct wsfsp_client_protocol * protocol,
struct lws_protocols * lws_protocol)
{
wsfsp_impl_client_protocol_init_lws(protocol, lws_protocol);
}
// client
struct wsfsp_client * wsfsp_client_create(
struct wsfsp_client_config * config)
{
return wsfsp_impl_client_create(config);
}
void wsfsp_client_connect(
struct wsfsp_client * client,
char const * url)
{
wsfsp_impl_client_connect(client, url);
}
void wsfsp_client_disconnect(
struct wsfsp_client * client)
{
wsfsp_impl_client_disconnect(client);
}
void wsfsp_client_dispose(
struct wsfsp_client * client)
{
wsfsp_impl_client_dispose(client);
}
void wsfsp_client_run(
struct wsfsp_client * client)
{
wsfsp_impl_client_run(client);
}
void wsfsp_client_shutdown(
struct wsfsp_client * client)
{
wsfsp_impl_client_shutdown(client);
}
// dirbuffer
struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void)
{
return wsfsp_impl_dirbuffer_create();
}
void wsfsp_dirbuffer_dispose(
struct wsfsp_dirbuffer * buffer)
{
wsfsp_impl_dirbuffer_dispose(buffer);
}
void wsfsp_dirbuffer_add(
struct wsfsp_dirbuffer * buffer,
char const * name,
ino_t inode)
{
wsfsp_impl_dirbuffer_add(buffer, name, inode);
}

Some files were not shown because too many files have changed in this diff Show More