mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
introduces separation of public api and implementation of wsfs-provider library
This commit is contained in:
parent
11724ec792
commit
8dd3dd4950
@ -129,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)
|
||||
@ -154,7 +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 PUBLIC wsfs-core)
|
||||
target_link_libraries(wsfs-provider PRIVATE wsfs-provider-static wsfs-core)
|
||||
|
||||
file(WRITE "${PROJECT_BINARY_DIR}/libwsfs-provider.pc"
|
||||
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
|
||||
@ -260,12 +268,6 @@ pkg_check_modules(GTEST gtest_main)
|
||||
include(GoogleTest)
|
||||
pkg_check_modules(GMOCK gmock)
|
||||
|
||||
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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -10,22 +10,22 @@
|
||||
#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(
|
||||
void * user_data);
|
||||
|
||||
typedef void wsfsp_disconnected_fn(
|
||||
void * user_data);
|
||||
void * user_data);
|
||||
|
||||
typedef void wsfsp_ontimer_fn(
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern WSFSP_API struct wsfsp_client_config * wsfsp_client_config_create(void);
|
||||
|
||||
extern WSFSP_API void wsfsp_client_config_dispose(
|
||||
|
@ -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);
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -4,13 +4,13 @@
|
||||
#include "wsfs/provider/api.h"
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
wsfs_status status);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
240
lib/wsfs/provider/api.c
Normal file
240
lib/wsfs/provider/api.c
Normal 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);
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_CLIENT_CONFIG_INTERN_H
|
||||
#define WSFS_PROVIDER_CLIENT_CONFIG_INTERN_H
|
||||
|
||||
#include "wsfs/provider/client_config.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
struct wsfsp_client_config
|
||||
{
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,36 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_CLIENT_PROTOCOL_INTERN_H
|
||||
#define WSFS_PROVIDER_CLIENT_PROTOCOL_INTERN_H
|
||||
|
||||
#include "wsfs/provider/client_protocol.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
|
||||
#include "wsfs/core/message_queue.h"
|
||||
|
||||
struct wsfsp_client_protocol
|
||||
{
|
||||
struct wsfsp_request request;
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
struct lws * wsi;
|
||||
struct wsfs_message_queue queue;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_client_protocol_init(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_client_protocol_cleanup(
|
||||
struct wsfsp_client_protocol * protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,15 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_DIRBUFFER_INTERN_H
|
||||
#define WSFS_PROVIDER_DIRBUFFER_INTERN_H
|
||||
|
||||
#include "wsfs/provider/dirbuffer.h"
|
||||
#include <jansson.h>
|
||||
|
||||
struct wsfsp_dirbuffer
|
||||
{
|
||||
json_t * entries;
|
||||
};
|
||||
|
||||
extern json_t * wsfsp_dirbuffer_take(
|
||||
struct wsfsp_dirbuffer * buffer);
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
#include "wsfs/provider/client.h"
|
||||
#include "wsfs/provider/impl/client.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -6,10 +6,10 @@
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/provider/provider.h"
|
||||
#include "wsfs/provider/client_protocol_intern.h"
|
||||
#include "wsfs/provider/client_config_intern.h"
|
||||
#include "wsfs/provider/url.h"
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include "wsfs/provider/impl/client_protocol.h"
|
||||
#include "wsfs/provider/impl/client_config.h"
|
||||
#include "wsfs/provider/impl/url.h"
|
||||
|
||||
#define WSFSP_PROTOCOL ("fs")
|
||||
#define WSFSP_DISABLE_LWS_LOG 0
|
||||
@ -28,7 +28,7 @@ struct wsfsp_client
|
||||
};
|
||||
|
||||
|
||||
struct wsfsp_client * wsfsp_client_create(
|
||||
struct wsfsp_client * wsfsp_impl_client_create(
|
||||
struct wsfsp_client_config * config)
|
||||
{
|
||||
lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL);
|
||||
@ -37,11 +37,11 @@ struct wsfsp_client * wsfsp_client_create(
|
||||
if (NULL != client)
|
||||
{
|
||||
client->is_running = true;
|
||||
wsfsp_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
||||
wsfsp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
||||
|
||||
memset(client->protocols, 0, sizeof(struct lws_protocols) * WSFSP_CLIENT_PROTOCOL_COUNT);
|
||||
client->protocols[0].name = "fs";
|
||||
wsfsp_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||
wsfsp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||
|
||||
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
|
||||
client->info.port = CONTEXT_PORT_NO_LISTEN;
|
||||
@ -60,20 +60,20 @@ struct wsfsp_client * wsfsp_client_create(
|
||||
return client;
|
||||
}
|
||||
|
||||
void wsfsp_client_dispose(
|
||||
void wsfsp_impl_client_dispose(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
lws_context_destroy(client->context);
|
||||
wsfsp_client_protocol_cleanup(&client->protocol);
|
||||
wsfsp_impl_client_protocol_cleanup(&client->protocol);
|
||||
free(client);
|
||||
}
|
||||
|
||||
void wsfsp_client_connect(
|
||||
void wsfsp_impl_client_connect(
|
||||
struct wsfsp_client * client,
|
||||
char const * url)
|
||||
{
|
||||
struct wsfsp_url url_data;
|
||||
bool const success = wsfsp_url_init(&url_data, url);
|
||||
struct wsfsp_impl_url url_data;
|
||||
bool const success = wsfsp_impl_url_init(&url_data, url);
|
||||
if (success)
|
||||
{
|
||||
struct lws_client_connect_info info;
|
||||
@ -90,11 +90,11 @@ void wsfsp_client_connect(
|
||||
|
||||
lws_client_connect_via_info(&info);
|
||||
|
||||
wsfsp_url_cleanup(&url_data);
|
||||
wsfsp_impl_url_cleanup(&url_data);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_client_disconnect(
|
||||
void wsfsp_impl_client_disconnect(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
(void) client;
|
||||
@ -102,7 +102,7 @@ void wsfsp_client_disconnect(
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void wsfsp_client_run(
|
||||
void wsfsp_impl_client_run(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
while (client->is_running)
|
||||
@ -111,7 +111,7 @@ void wsfsp_client_run(
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_client_shutdown(
|
||||
void wsfsp_impl_client_shutdown(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
client->is_running = false;
|
49
lib/wsfs/provider/impl/client.h
Normal file
49
lib/wsfs/provider/impl/client.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_CLIENT_H
|
||||
#define WSFS_PROVIDER_IMPL_CLIENT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_client;
|
||||
struct wsfsp_client_config;
|
||||
|
||||
extern struct wsfsp_client * wsfsp_impl_client_create(
|
||||
struct wsfsp_client_config * config);
|
||||
|
||||
extern void wsfsp_impl_client_set_keypath(
|
||||
struct wsfsp_client * client,
|
||||
char * key_path);
|
||||
|
||||
extern void wsfsp_impl_client_set_certpath(
|
||||
struct wsfsp_client * client,
|
||||
char * cert_path);
|
||||
|
||||
extern void wsfsp_impl_client_connect(
|
||||
struct wsfsp_client * client,
|
||||
char const * url);
|
||||
|
||||
extern void wsfsp_impl_client_disconnect(
|
||||
struct wsfsp_client * client);
|
||||
|
||||
extern void wsfsp_impl_client_settimeout(
|
||||
struct wsfsp_client * client,
|
||||
unsigned int timepoint);
|
||||
|
||||
extern void wsfsp_impl_client_dispose(
|
||||
struct wsfsp_client * client);
|
||||
|
||||
extern void wsfsp_impl_client_run(
|
||||
struct wsfsp_client * client);
|
||||
|
||||
extern void wsfsp_impl_client_shutdown(
|
||||
struct wsfsp_client * client);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,14 +1,14 @@
|
||||
#include "wsfs/provider/client_config_intern.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
#include "wsfs/provider/impl/client_config.h"
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfsp_client_config * wsfsp_client_config_create(void)
|
||||
struct wsfsp_client_config * wsfsp_impl_client_config_create(void)
|
||||
{
|
||||
struct wsfsp_client_config * config = malloc(sizeof(struct wsfsp_client_config));
|
||||
if (NULL != config)
|
||||
{
|
||||
wsfsp_provider_init(&config->provider);
|
||||
wsfsp_impl_provider_init(&config->provider);
|
||||
config->user_data = NULL;
|
||||
config->key_path = NULL;
|
||||
config->cert_path = NULL;
|
||||
@ -17,7 +17,7 @@ struct wsfsp_client_config * wsfsp_client_config_create(void)
|
||||
return config;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_dispose(
|
||||
void wsfsp_impl_client_config_dispose(
|
||||
struct wsfsp_client_config * config)
|
||||
{
|
||||
free(config->key_path);
|
||||
@ -25,14 +25,14 @@ void wsfsp_client_config_dispose(
|
||||
free(config);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_userdata(
|
||||
void wsfsp_impl_client_config_set_userdata(
|
||||
struct wsfsp_client_config * config,
|
||||
void * user_data)
|
||||
{
|
||||
config->user_data = user_data;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_keypath(
|
||||
void wsfsp_impl_client_config_set_keypath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
@ -40,7 +40,7 @@ void wsfsp_client_config_set_keypath(
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_certpath(
|
||||
void wsfsp_impl_client_config_set_certpath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
@ -48,63 +48,63 @@ void wsfsp_client_config_set_certpath(
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onconnected(
|
||||
void wsfsp_impl_client_config_set_onconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_connected_fn * handler)
|
||||
{
|
||||
config->provider.connected = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ondisconnected(
|
||||
void wsfsp_impl_client_config_set_ondisconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_disconnected_fn * handler)
|
||||
{
|
||||
config->provider.disconnected = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ontimer(
|
||||
void wsfsp_impl_client_config_set_ontimer(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_ontimer_fn * handler)
|
||||
{
|
||||
config->provider.ontimer = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onlookup(
|
||||
void wsfsp_impl_client_config_set_onlookup(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_lookup_fn * handler)
|
||||
{
|
||||
config->provider.lookup = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ongetattr(
|
||||
void wsfsp_impl_client_config_set_ongetattr(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_getattr_fn * handler)
|
||||
{
|
||||
config->provider.getattr = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onreaddir(
|
||||
void wsfsp_impl_client_config_set_onreaddir(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_readdir_fn * handler)
|
||||
{
|
||||
config->provider.readdir = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onopen(
|
||||
void wsfsp_impl_client_config_set_onopen(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_open_fn * handler)
|
||||
{
|
||||
config->provider.open = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onclose(
|
||||
void wsfsp_impl_client_config_set_onclose(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_close_fn * handler)
|
||||
{
|
||||
config->provider.close = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onread(
|
||||
void wsfsp_impl_client_config_set_onread(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_read_fn * handler)
|
||||
{
|
77
lib/wsfs/provider/impl/client_config.h
Normal file
77
lib/wsfs/provider/impl/client_config.h
Normal file
@ -0,0 +1,77 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_CLIENT_CONFIG_H
|
||||
#define WSFS_PROVIDER_IMPL_CLIENT_CONFIG_H
|
||||
|
||||
#include "wsfs/provider/client_config.h"
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_client_config
|
||||
{
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
};
|
||||
|
||||
extern struct wsfsp_client_config * wsfsp_impl_client_config_create(void);
|
||||
|
||||
extern void wsfsp_impl_client_config_dispose(
|
||||
struct wsfsp_client_config * config);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_userdata(
|
||||
struct wsfsp_client_config * config,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_keypath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_certpath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_connected_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_ondisconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_disconnected_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_ontimer(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_ontimer_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onlookup(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_lookup_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_ongetattr(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_getattr_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onreaddir(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_readdir_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onopen(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_open_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onclose(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_close_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onread(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_read_fn * handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
#include "wsfs/provider/client_protocol_intern.h"
|
||||
#include "wsfs/provider/impl/client_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -7,11 +7,11 @@
|
||||
#include <jansson.h>
|
||||
|
||||
|
||||
#include "wsfs/provider/provider.h"
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "wsfs/core/message.h"
|
||||
|
||||
static void wsfsp_client_protocol_respond(
|
||||
static void wsfsp_impl_client_protocol_respond(
|
||||
json_t * response,
|
||||
void * user_data)
|
||||
{
|
||||
@ -25,7 +25,7 @@ static void wsfsp_client_protocol_respond(
|
||||
}
|
||||
}
|
||||
|
||||
static void wsfsp_client_protocol_process_request(
|
||||
static void wsfsp_impl_client_protocol_process_request(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
char const * message,
|
||||
size_t length)
|
||||
@ -33,20 +33,20 @@ static void wsfsp_client_protocol_process_request(
|
||||
json_t * request = json_loadb(message, length, 0, NULL);
|
||||
if (NULL != request)
|
||||
{
|
||||
struct wsfsp_invokation_context context =
|
||||
struct wsfsp_impl_invokation_context context =
|
||||
{
|
||||
.provider = &protocol->provider,
|
||||
.user_data = protocol->user_data,
|
||||
.request = &protocol->request
|
||||
};
|
||||
|
||||
wsfsp_provider_invoke(&context, request);
|
||||
wsfsp_impl_provider_invoke(&context, request);
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int wsfsp_client_protocol_callback(
|
||||
static int wsfsp_impl_client_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
@ -70,7 +70,7 @@ static int wsfsp_client_protocol_callback(
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||
wsfsp_client_protocol_process_request(protocol, in, len);
|
||||
wsfsp_impl_client_protocol_process_request(protocol, in, len);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
// fall-through
|
||||
@ -97,7 +97,7 @@ static int wsfsp_client_protocol_callback(
|
||||
}
|
||||
|
||||
|
||||
void wsfsp_client_protocol_init(
|
||||
void wsfsp_impl_client_protocol_init(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
@ -106,44 +106,44 @@ void wsfsp_client_protocol_init(
|
||||
|
||||
protocol->wsi = NULL;
|
||||
|
||||
protocol->request.respond = &wsfsp_client_protocol_respond;
|
||||
protocol->request.respond = &wsfsp_impl_client_protocol_respond;
|
||||
protocol->request.user_data = protocol;
|
||||
|
||||
protocol->user_data = user_data;
|
||||
wsfsp_provider_init_from_prototype(&protocol->provider, provider);
|
||||
wsfsp_impl_provider_init_from_prototype(&protocol->provider, provider);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_cleanup(
|
||||
void wsfsp_impl_client_protocol_cleanup(
|
||||
struct wsfsp_client_protocol * protocol)
|
||||
{
|
||||
wsfs_message_queue_cleanup(&protocol->queue);
|
||||
}
|
||||
|
||||
struct wsfsp_client_protocol * wsfsp_client_protocol_create(
|
||||
struct wsfsp_client_protocol * wsfsp_impl_client_protocol_create(
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfsp_client_protocol * protocol = malloc(sizeof(struct wsfsp_client_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
wsfsp_client_protocol_init(protocol, provider, user_data);
|
||||
wsfsp_impl_client_protocol_init(protocol, provider, user_data);
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_dispose(
|
||||
void wsfsp_impl_client_protocol_dispose(
|
||||
struct wsfsp_client_protocol * protocol)
|
||||
{
|
||||
wsfsp_client_protocol_cleanup(protocol);
|
||||
wsfsp_impl_client_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_init_lws(
|
||||
void wsfsp_impl_client_protocol_init_lws(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wsfsp_client_protocol_callback;
|
||||
lws_protocol->callback = &wsfsp_impl_client_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
49
lib/wsfs/provider/impl/client_protocol.h
Normal file
49
lib/wsfs/provider/impl/client_protocol.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_CLIENT_PROTOCOL_H
|
||||
#define WSFS_PROVIDER_IMPL_CLIENT_PROTOCOL_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
|
||||
#include "wsfs/core/message_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_provider;
|
||||
struct lws_protocols;
|
||||
|
||||
struct wsfsp_client_protocol
|
||||
{
|
||||
struct wsfsp_request request;
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
struct lws * wsi;
|
||||
struct wsfs_message_queue queue;
|
||||
};
|
||||
|
||||
extern void wsfsp_impl_client_protocol_init(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_impl_client_protocol_cleanup(
|
||||
struct wsfsp_client_protocol * protocol);
|
||||
|
||||
extern struct wsfsp_client_protocol * wsfsp_impl_client_protocol_create(
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_impl_client_protocol_dispose(
|
||||
struct wsfsp_client_protocol * protocol);
|
||||
|
||||
extern void wsfsp_impl_client_protocol_init_lws(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
#include "wsfs/provider/dirbuffer_intern.h"
|
||||
#include "wsfs/provider/impl/dirbuffer.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void)
|
||||
struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void)
|
||||
{
|
||||
struct wsfsp_dirbuffer * buffer = malloc(sizeof(struct wsfsp_dirbuffer));
|
||||
if (NULL != buffer)
|
||||
@ -12,7 +12,7 @@ struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void wsfsp_dirbuffer_dispose(
|
||||
void wsfsp_impl_dirbuffer_dispose(
|
||||
struct wsfsp_dirbuffer * buffer)
|
||||
{
|
||||
if (NULL != buffer->entries)
|
||||
@ -23,7 +23,7 @@ void wsfsp_dirbuffer_dispose(
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void wsfsp_dirbuffer_add(
|
||||
void wsfsp_impl_dirbuffer_add(
|
||||
struct wsfsp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode)
|
||||
@ -35,7 +35,7 @@ void wsfsp_dirbuffer_add(
|
||||
json_array_append_new(buffer->entries, entry);
|
||||
}
|
||||
|
||||
json_t * wsfsp_dirbuffer_take(
|
||||
json_t * wsfsp_impl_dirbuffer_take(
|
||||
struct wsfsp_dirbuffer * buffer)
|
||||
{
|
||||
json_t * entries = buffer->entries;
|
37
lib/wsfs/provider/impl/dirbuffer.h
Normal file
37
lib/wsfs/provider/impl/dirbuffer.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_DIRBUFFER_H
|
||||
#define WSFS_PROVIDER_IMPL_DIRBUFFER_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_dirbuffer
|
||||
{
|
||||
json_t * entries;
|
||||
};
|
||||
|
||||
extern struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void);
|
||||
|
||||
extern void wsfsp_impl_dirbuffer_dispose(
|
||||
struct wsfsp_dirbuffer * buffer);
|
||||
|
||||
extern void wsfsp_impl_dirbuffer_add(
|
||||
struct wsfsp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode);
|
||||
|
||||
extern json_t * wsfsp_impl_dirbuffer_take(
|
||||
struct wsfsp_dirbuffer * buffer);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,9 +1,9 @@
|
||||
#include "wsfs/provider/operation/close_intern.h"
|
||||
#include "wsfs/provider/impl/operation/close.h"
|
||||
#include <limits.h>
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfsp_close(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_close(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int WSFS_UNUSED_PARAM(id))
|
||||
{
|
||||
@ -28,7 +28,7 @@ void wsfsp_close(
|
||||
|
||||
}
|
||||
|
||||
void wsfsp_close_default(
|
||||
void wsfsp_impl_close_default(
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
uint32_t WSFS_UNUSED_PARAM(handle),
|
||||
int WSFS_UNUSED_PARAM(flags),
|
26
lib/wsfs/provider/impl/operation/close.h
Normal file
26
lib/wsfs/provider/impl/operation/close.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_CLOSE_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_CLOSE_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_close(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_close_default(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
22
lib/wsfs/provider/impl/operation/error.h
Normal file
22
lib/wsfs/provider/impl/operation/error.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef WSFSP_OPERATION_IMPL_ERROR_H
|
||||
#define WSFSP_OPERATION_IMPL_ERROR_H
|
||||
|
||||
#include "wsfs/provider/api.h"
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
extern WSFSP_API void wsfsp_impl_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
wsfs_status status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,14 +1,14 @@
|
||||
#include "wsfs/provider/operation/getattr_intern.h"
|
||||
#include "wsfs/provider/impl/operation/getattr.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
|
||||
void wsfsp_getattr(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_getattr(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@ -20,22 +20,22 @@ void wsfsp_getattr(
|
||||
if (json_is_integer(inode_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->getattr(request, inode, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_getattr_default(
|
||||
void wsfsp_impl_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_respond_getattr(
|
||||
void wsfsp_impl_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
@ -60,5 +60,5 @@ void wsfsp_respond_getattr(
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
}
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
wsfsp_impl_respond(request, result);
|
||||
}
|
29
lib/wsfs/provider/impl/operation/getattr.h
Normal file
29
lib/wsfs/provider/impl/operation/getattr.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_GETATTR_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_GETATTR_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern void wsfsp_impl_getattr(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,12 +1,13 @@
|
||||
#include "wsfs/provider/operation/lookup_intern.h"
|
||||
#include "wsfs/provider/impl/operation/lookup.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfsp_lookup(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_lookup(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@ -22,13 +23,13 @@ void wsfsp_lookup(
|
||||
ino_t inode = json_integer_value(inode_holder);
|
||||
char const * name = json_string_value(name_holder);
|
||||
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
context->provider->lookup(request, inode, name, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_respond_lookup(
|
||||
void wsfsp_impl_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
@ -53,15 +54,15 @@ void wsfsp_respond_lookup(
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
}
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
wsfsp_impl_respond(request, result);
|
||||
}
|
||||
|
||||
void wsfsp_lookup_default(
|
||||
void wsfsp_impl_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(parent),
|
||||
char const * WSFS_UNUSED_PARAM(name),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
}
|
||||
|
30
lib/wsfs/provider/impl/operation/lookup.h
Normal file
30
lib/wsfs/provider/impl/operation/lookup.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_LOOKUP_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_LOOKUP_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern void wsfsp_impl_lookup(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,10 +1,10 @@
|
||||
#include "wsfs/provider/operation/open_intern.h"
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
#include "wsfs/provider/impl/operation/open.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfsp_open(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_open(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@ -20,28 +20,28 @@ void wsfsp_open(
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
int flags = (ino_t) json_integer_value(flags_holder);
|
||||
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->open(request, inode, flags, context->user_data); /* Flawfinder: ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_open_default(
|
||||
void wsfsp_impl_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
int WSFS_UNUSED_PARAM(flags),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_respond_open(
|
||||
void wsfsp_impl_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "handle", json_integer((int) handle));
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
wsfsp_impl_respond(request, result);
|
||||
}
|
30
lib/wsfs/provider/impl/operation/open.h
Normal file
30
lib/wsfs/provider/impl/operation/open.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_OPEN_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_OPEN_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle);
|
||||
|
||||
extern void wsfsp_impl_open(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,13 +1,14 @@
|
||||
#include "wsfs/provider/operation/read_intern.h"
|
||||
#include "wsfs/provider/impl/operation/read.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfsp_read(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_read(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@ -28,14 +29,14 @@ void wsfsp_read(
|
||||
int handle = json_integer_value(handle_holder);
|
||||
size_t offset = json_integer_value(offset_holder);
|
||||
size_t length = json_integer_value(length_holder);
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->read(request, inode, handle, offset, length, context->user_data); /* Flawfinder: ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_read_default(
|
||||
void wsfsp_impl_read_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
uint32_t WSFS_UNUSED_PARAM(handle),
|
||||
@ -43,10 +44,10 @@ void wsfsp_read_default(
|
||||
size_t WSFS_UNUSED_PARAM(length),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_respond_read(
|
||||
void wsfsp_impl_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
char const * data,
|
||||
size_t length)
|
||||
@ -64,12 +65,12 @@ void wsfsp_respond_read(
|
||||
json_object_set_new(result, "format", json_string("base64"));
|
||||
json_object_set_new(result, "count", json_integer((int) length));
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
wsfsp_impl_respond(request, result);
|
||||
free(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -79,6 +80,6 @@ void wsfsp_respond_read(
|
||||
json_object_set_new(result, "format", json_string("identitiy"));
|
||||
json_object_set_new(result, "count", json_integer(0));
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
wsfsp_impl_respond(request, result);
|
||||
}
|
||||
}
|
33
lib/wsfs/provider/impl/operation/read.h
Normal file
33
lib/wsfs/provider/impl/operation/read.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_READ_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_READ_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
extern void wsfsp_impl_read(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_read_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,11 +1,11 @@
|
||||
#include "wsfs/provider/operation/readdir_intern.h"
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/dirbuffer_intern.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
#include "wsfs/provider/impl/operation/readdir.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/dirbuffer.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfsp_readdir(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_readdir(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@ -17,26 +17,26 @@ void wsfsp_readdir(
|
||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->readdir(request, inode, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_readdir_default(
|
||||
void wsfsp_impl_readdir_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(directory),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_respond_readdir(
|
||||
void wsfsp_impl_respond_readdir(
|
||||
struct wsfsp_request * request,
|
||||
struct wsfsp_dirbuffer * dirbuffer)
|
||||
{
|
||||
json_t * result = wsfsp_dirbuffer_take(dirbuffer);
|
||||
wsfsp_respond(request, result);
|
||||
json_t * result = wsfsp_impl_dirbuffer_take(dirbuffer);
|
||||
wsfsp_impl_respond(request, result);
|
||||
}
|
||||
|
29
lib/wsfs/provider/impl/operation/readdir.h
Normal file
29
lib/wsfs/provider/impl/operation/readdir.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_READDIR_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_READDIR_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_respond_readdir(
|
||||
struct wsfsp_request * request,
|
||||
struct wsfsp_dirbuffer * dirbuffer);
|
||||
|
||||
extern void wsfsp_impl_readdir(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_readdir_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
127
lib/wsfs/provider/impl/provider.c
Normal file
127
lib/wsfs/provider/impl/provider.c
Normal file
@ -0,0 +1,127 @@
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/provider/impl/operation/lookup.h"
|
||||
#include "wsfs/provider/impl/operation/getattr.h"
|
||||
#include "wsfs/provider/impl/operation/readdir.h"
|
||||
#include "wsfs/provider/impl/operation/open.h"
|
||||
#include "wsfs/provider/impl/operation/close.h"
|
||||
#include "wsfs/provider/impl/operation/read.h"
|
||||
|
||||
typedef void wsfsp_impl_invoke_fn(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
|
||||
struct wsfsp_impl_method
|
||||
{
|
||||
char const * name;
|
||||
wsfsp_impl_invoke_fn * invoke;
|
||||
bool is_notification;
|
||||
};
|
||||
|
||||
static void wsfsp_impl_provider_invoke_method(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
static struct wsfsp_impl_method const methods[] =
|
||||
{
|
||||
{"lookup", &wsfsp_impl_lookup, false},
|
||||
{"getattr", &wsfsp_impl_getattr, false},
|
||||
{"readdir", &wsfsp_impl_readdir, false},
|
||||
{"open", &wsfsp_impl_open, false},
|
||||
{"close", &wsfsp_impl_close, true},
|
||||
{"read", &wsfsp_impl_read, false}
|
||||
};
|
||||
static size_t const count = sizeof(methods) / sizeof(methods[0]);
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
struct wsfsp_impl_method const * method = &methods[i];
|
||||
if (0 == strcmp(method_name, method->name))
|
||||
{
|
||||
if ((0 < id) || (method->is_notification))
|
||||
{
|
||||
method->invoke(context, params, id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_impl_provider_init(
|
||||
struct wsfsp_provider * provider)
|
||||
{
|
||||
provider->lookup = &wsfsp_impl_lookup_default;
|
||||
provider->getattr = &wsfsp_impl_getattr_default;
|
||||
provider->readdir = &wsfsp_impl_readdir_default;
|
||||
provider->open = &wsfsp_impl_open_default;
|
||||
provider->close = &wsfsp_impl_close_default;
|
||||
provider->read = &wsfsp_impl_read_default;
|
||||
provider->connected = &wsfsp_impl_connected_default;
|
||||
provider->disconnected = &wsfsp_impl_disconnected_default;
|
||||
provider->ontimer = &wsfsp_impl_ontimer_default;
|
||||
}
|
||||
|
||||
void wsfsp_impl_provider_init_from_prototype(
|
||||
struct wsfsp_provider * provider,
|
||||
struct wsfsp_provider const * prototype)
|
||||
{
|
||||
provider->lookup = prototype->lookup;
|
||||
provider->getattr = prototype->getattr;
|
||||
provider->readdir = prototype->readdir;
|
||||
provider->open = prototype->open;
|
||||
provider->close = prototype->close;
|
||||
provider->read = prototype->read;
|
||||
provider->connected = prototype->connected;
|
||||
provider->disconnected = prototype->disconnected;
|
||||
provider->ontimer = prototype->ontimer;
|
||||
}
|
||||
|
||||
void wsfsp_impl_provider_invoke(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * request)
|
||||
{
|
||||
json_t * method_holder = json_object_get(request, "method");
|
||||
json_t * params = json_object_get(request, "params");
|
||||
json_t * id_holder = json_object_get(request, "id");
|
||||
|
||||
if ((NULL != method_holder) && (json_is_string(method_holder)) &&
|
||||
(NULL != params) && (json_is_array(params)))
|
||||
{
|
||||
char const * method = json_string_value(method_holder);
|
||||
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0;
|
||||
|
||||
wsfsp_impl_provider_invoke_method(context, method, params, id);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_impl_connected_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wsfsp_impl_disconnected_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wsfsp_impl_ontimer_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
@ -1,16 +1,13 @@
|
||||
#ifndef WSFS_PROVIDER_PROVIDER_H
|
||||
#define WSFS_PROVIDER_PROVIDER_H
|
||||
|
||||
#include "wsfs/provider/client_config.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
#include <wsfs/provider/operation/lookup.h>
|
||||
#include <wsfs/provider/operation/getattr.h>
|
||||
#include <wsfs/provider/operation/readdir.h>
|
||||
#include <wsfs/provider/operation/open.h>
|
||||
#include <wsfs/provider/operation/close.h>
|
||||
#include <wsfs/provider/operation/read.h>
|
||||
#ifndef WSFS_PROVIDER_IMPL_PROVIDER_H
|
||||
#define WSFS_PROVIDER_IMPL_PROVIDER_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/provider/client_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_provider
|
||||
{
|
||||
@ -25,37 +22,32 @@ struct wsfsp_provider
|
||||
wsfsp_read_fn * read;
|
||||
};
|
||||
|
||||
struct wsfsp_invokation_context
|
||||
struct wsfsp_impl_invokation_context
|
||||
{
|
||||
struct wsfsp_provider * provider;
|
||||
void * user_data;
|
||||
struct wsfsp_request * request;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_provider_init(
|
||||
extern void wsfsp_impl_provider_init(
|
||||
struct wsfsp_provider * provider);
|
||||
|
||||
extern void wsfsp_provider_init_from_prototype(
|
||||
extern void wsfsp_impl_provider_init_from_prototype(
|
||||
struct wsfsp_provider * provider,
|
||||
struct wsfsp_provider const * prototype);
|
||||
|
||||
|
||||
extern void wsfsp_provider_invoke(
|
||||
struct wsfsp_invokation_context * context,
|
||||
extern void wsfsp_impl_provider_invoke(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * request);
|
||||
|
||||
extern void wsfsp_connected_default(
|
||||
extern void wsfsp_impl_connected_default(
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_disconnected_default(
|
||||
extern void wsfsp_impl_disconnected_default(
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_ontimer_default(
|
||||
extern void wsfsp_impl_ontimer_default(
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
@ -1,9 +1,9 @@
|
||||
#include "wsfs/provider/request.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
|
||||
struct wsfsp_request * wsfsp_request_create(
|
||||
struct wsfsp_request * wsfsp_impl_request_create(
|
||||
struct wsfsp_request * prototype,
|
||||
int id)
|
||||
{
|
||||
@ -18,13 +18,13 @@ struct wsfsp_request * wsfsp_request_create(
|
||||
return request;
|
||||
}
|
||||
|
||||
void wsfsp_request_dispose(
|
||||
void wsfsp_impl_request_dispose(
|
||||
struct wsfsp_request * request)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
extern void wsfsp_respond(
|
||||
extern void wsfsp_impl_respond(
|
||||
struct wsfsp_request * request,
|
||||
json_t * result)
|
||||
{
|
||||
@ -35,10 +35,10 @@ extern void wsfsp_respond(
|
||||
request->respond(response, request->user_data);
|
||||
|
||||
json_decref(response);
|
||||
wsfsp_request_dispose(request);
|
||||
wsfsp_impl_request_dispose(request);
|
||||
}
|
||||
|
||||
void wsfsp_respond_error(
|
||||
void wsfsp_impl_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
wsfs_status status)
|
||||
{
|
||||
@ -51,5 +51,5 @@ void wsfsp_respond_error(
|
||||
request->respond(response, request->user_data);
|
||||
|
||||
json_decref(response);
|
||||
wsfsp_request_dispose(request);
|
||||
wsfsp_impl_request_dispose(request);
|
||||
}
|
43
lib/wsfs/provider/impl/request.h
Normal file
43
lib/wsfs/provider/impl/request.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_REQUEST_H
|
||||
#define WSFS_PROVIDER_IMPL_REQUEST_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void wsfsp_impl_request_respond_fn(
|
||||
json_t * response,
|
||||
void * user_data);
|
||||
|
||||
struct wsfsp_request
|
||||
{
|
||||
wsfsp_impl_request_respond_fn * respond;
|
||||
void * user_data;
|
||||
int id;
|
||||
};
|
||||
|
||||
extern void wsfsp_impl_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
wsfs_status status);
|
||||
|
||||
extern struct wsfsp_request * wsfsp_impl_request_create(
|
||||
struct wsfsp_request * prototype,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_request_dispose(
|
||||
struct wsfsp_request * request);
|
||||
|
||||
extern void wsfsp_impl_respond(
|
||||
struct wsfsp_request * request,
|
||||
json_t * result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,9 +1,9 @@
|
||||
#include "wsfs/provider/url.h"
|
||||
#include "wsfs/provider/impl/url.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfsp_url_protocol
|
||||
struct wsfsp_impl_url_protocol
|
||||
{
|
||||
char const * name;
|
||||
size_t name_length;
|
||||
@ -11,11 +11,11 @@ struct wsfsp_url_protocol
|
||||
bool use_tls;
|
||||
};
|
||||
|
||||
static bool wsfsp_url_readprotocol(
|
||||
struct wsfsp_url * url,
|
||||
static bool wsfsp_impl_url_readprotocol(
|
||||
struct wsfsp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
static struct wsfsp_url_protocol const known_protocols[] =
|
||||
static struct wsfsp_impl_url_protocol const known_protocols[] =
|
||||
{
|
||||
{"ws://", 5, 80, false},
|
||||
{"wss://", 6, 443, true}
|
||||
@ -25,7 +25,7 @@ static bool wsfsp_url_readprotocol(
|
||||
bool found = false;
|
||||
for(size_t i = 0; (!found) && (i < count); i++)
|
||||
{
|
||||
struct wsfsp_url_protocol const * protocol = &known_protocols[i];
|
||||
struct wsfsp_impl_url_protocol const * protocol = &known_protocols[i];
|
||||
if (0 == strncmp(*data, protocol->name, protocol->name_length))
|
||||
{
|
||||
url->port = protocol->default_port;
|
||||
@ -38,8 +38,8 @@ static bool wsfsp_url_readprotocol(
|
||||
return found;
|
||||
}
|
||||
|
||||
static bool wsfsp_url_readhost(
|
||||
struct wsfsp_url * url,
|
||||
static bool wsfsp_impl_url_readhost(
|
||||
struct wsfsp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
char * end = strpbrk(*data, ":/");
|
||||
@ -55,8 +55,8 @@ static bool wsfsp_url_readhost(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wsfsp_url_readport(
|
||||
struct wsfsp_url * url,
|
||||
static bool wsfsp_impl_url_readport(
|
||||
struct wsfsp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
bool result;
|
||||
@ -81,8 +81,8 @@ static bool wsfsp_url_readport(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wsfsp_url_readpath(
|
||||
struct wsfsp_url * url,
|
||||
static bool wsfsp_impl_url_readpath(
|
||||
struct wsfsp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
bool const result = ('/' == **data);
|
||||
@ -93,41 +93,33 @@ static bool wsfsp_url_readpath(
|
||||
}
|
||||
|
||||
|
||||
bool wsfsp_url_init(
|
||||
struct wsfsp_url * url,
|
||||
bool wsfsp_impl_url_init(
|
||||
struct wsfsp_impl_url * url,
|
||||
char const * value)
|
||||
{
|
||||
memset(url, 0, sizeof(struct wsfsp_url));
|
||||
memset(url, 0, sizeof(struct wsfsp_impl_url));
|
||||
char const * data = value;
|
||||
|
||||
bool const result =
|
||||
wsfsp_url_readprotocol(url, &data) &&
|
||||
wsfsp_url_readhost(url, &data) &&
|
||||
wsfsp_url_readport(url, &data) &&
|
||||
wsfsp_url_readpath(url, &data)
|
||||
wsfsp_impl_url_readprotocol(url, &data) &&
|
||||
wsfsp_impl_url_readhost(url, &data) &&
|
||||
wsfsp_impl_url_readport(url, &data) &&
|
||||
wsfsp_impl_url_readpath(url, &data)
|
||||
;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
wsfsp_url_cleanup(url);
|
||||
wsfsp_impl_url_cleanup(url);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfsp_url_cleanup(
|
||||
struct wsfsp_url * url)
|
||||
void wsfsp_impl_url_cleanup(
|
||||
struct wsfsp_impl_url * url)
|
||||
{
|
||||
free(url->host);
|
||||
free(url->path);
|
||||
memset(url, 0, sizeof(struct wsfsp_url));
|
||||
memset(url, 0, sizeof(struct wsfsp_impl_url));
|
||||
}
|
||||
|
||||
char const * wsfsp_url_gethost(
|
||||
struct wsfsp_url const * url);
|
||||
|
||||
int wsfsp_url_getport(
|
||||
struct wsfsp_url const * url);
|
||||
|
||||
char const * wsfsp_url_getpath(
|
||||
struct wsfsp_url const * url);
|
@ -1,11 +1,15 @@
|
||||
#ifndef WSFS_PROVIDER_URL_H
|
||||
#define WSFS_PROVIDER_URL_H
|
||||
#ifndef WSFS_PROVIDER_IMPL_URL_H
|
||||
#define WSFS_PROVIDER_IMPL_URL_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
struct wsfsp_url
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
struct wsfsp_impl_url
|
||||
{
|
||||
char * host;
|
||||
int port;
|
||||
@ -13,17 +17,12 @@ struct wsfsp_url
|
||||
bool use_tls;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wsfsp_url_init(
|
||||
struct wsfsp_url * url,
|
||||
extern bool wsfsp_impl_url_init(
|
||||
struct wsfsp_impl_url * url,
|
||||
char const * value);
|
||||
|
||||
extern void wsfsp_url_cleanup(
|
||||
struct wsfsp_url * url);
|
||||
extern void wsfsp_impl_url_cleanup(
|
||||
struct wsfsp_impl_url * url);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
@ -1,27 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_OPERATION_CLOSE_INTERN_H
|
||||
#define WSFS_PROVIDER_OPERATION_CLOSE_INTERN_H
|
||||
|
||||
#include "wsfs/provider/operation/close.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_close(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_close_default(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,26 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_OPERATION_GETATTR_INTERN_H
|
||||
#define WSFS_PROVIDER_OPERATION_GETATTR_INTERN_H
|
||||
|
||||
#include "wsfs/provider/operation/getattr.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_getattr(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,27 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_OPERATION_LOOKUP_INTERN_H
|
||||
#define WSFS_PROVIDER_OPERATION_LOOKUP_INTERN_H
|
||||
|
||||
#include "wsfs/provider/operation/lookup.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_lookup(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,27 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_OPERATION_OPEN_INTERN_H
|
||||
#define WSFS_PROVIDER_OPERATION_OPEN_INTERN_H
|
||||
|
||||
#include "wsfs/provider/operation/open.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_open(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_OPERATION_READ_INTERN_H
|
||||
#define WSFS_PROVIDER_OPERATION_READ_INTERN_H
|
||||
|
||||
#include "wsfs/provider/operation/read.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_read(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_read_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,26 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_OPERATION_READDIR_INTERN_H
|
||||
#define WSFS_PROVIDER_OPERATION_READDIR_INTERN_H
|
||||
|
||||
#include "wsfs/provider/operation/readdir.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_readdir(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_readdir_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,127 +0,0 @@
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/provider/request.h"
|
||||
#include "wsfs/provider/operation/lookup_intern.h"
|
||||
#include "wsfs/provider/operation/getattr_intern.h"
|
||||
#include "wsfs/provider/operation/readdir_intern.h"
|
||||
#include "wsfs/provider/operation/open_intern.h"
|
||||
#include "wsfs/provider/operation/close_intern.h"
|
||||
#include "wsfs/provider/operation/read_intern.h"
|
||||
|
||||
typedef void wsfsp_invoke_fn(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
|
||||
struct wsfsp_method
|
||||
{
|
||||
char const * name;
|
||||
wsfsp_invoke_fn * invoke;
|
||||
bool is_notification;
|
||||
};
|
||||
|
||||
static void wsfsp_provider_invoke_method(
|
||||
struct wsfsp_invokation_context * context,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
static struct wsfsp_method const methods[] =
|
||||
{
|
||||
{"lookup", &wsfsp_lookup, false},
|
||||
{"getattr", &wsfsp_getattr, false},
|
||||
{"readdir", &wsfsp_readdir, false},
|
||||
{"open", &wsfsp_open, false},
|
||||
{"close", &wsfsp_close, true},
|
||||
{"read", &wsfsp_read, false}
|
||||
};
|
||||
static size_t const count = sizeof(methods) / sizeof(methods[0]);
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
struct wsfsp_method const * method = &methods[i];
|
||||
if (0 == strcmp(method_name, method->name))
|
||||
{
|
||||
if ((0 < id) || (method->is_notification))
|
||||
{
|
||||
method->invoke(context, params, id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_provider_init(
|
||||
struct wsfsp_provider * provider)
|
||||
{
|
||||
provider->lookup = &wsfsp_lookup_default;
|
||||
provider->getattr = &wsfsp_getattr_default;
|
||||
provider->readdir = &wsfsp_readdir_default;
|
||||
provider->open = &wsfsp_open_default;
|
||||
provider->close = &wsfsp_close_default;
|
||||
provider->read = &wsfsp_read_default;
|
||||
provider->connected = &wsfsp_connected_default;
|
||||
provider->disconnected = &wsfsp_disconnected_default;
|
||||
provider->ontimer = &wsfsp_ontimer_default;
|
||||
}
|
||||
|
||||
void wsfsp_provider_init_from_prototype(
|
||||
struct wsfsp_provider * provider,
|
||||
struct wsfsp_provider const * prototype)
|
||||
{
|
||||
provider->lookup = prototype->lookup;
|
||||
provider->getattr = prototype->getattr;
|
||||
provider->readdir = prototype->readdir;
|
||||
provider->open = prototype->open;
|
||||
provider->close = prototype->close;
|
||||
provider->read = prototype->read;
|
||||
provider->connected = prototype->connected;
|
||||
provider->disconnected = prototype->disconnected;
|
||||
provider->ontimer = prototype->ontimer;
|
||||
}
|
||||
|
||||
void wsfsp_provider_invoke(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * request)
|
||||
{
|
||||
json_t * method_holder = json_object_get(request, "method");
|
||||
json_t * params = json_object_get(request, "params");
|
||||
json_t * id_holder = json_object_get(request, "id");
|
||||
|
||||
if ((NULL != method_holder) && (json_is_string(method_holder)) &&
|
||||
(NULL != params) && (json_is_array(params)))
|
||||
{
|
||||
char const * method = json_string_value(method_holder);
|
||||
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0;
|
||||
|
||||
wsfsp_provider_invoke_method(context, method, params, id);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_connected_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wsfsp_disconnected_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wsfsp_ontimer_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_REQUEST_H
|
||||
#define WSFS_PROVIDER_REQUEST_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
typedef void wsfsp_request_respond_fn(
|
||||
json_t * response,
|
||||
void * user_data);
|
||||
|
||||
struct wsfsp_request
|
||||
{
|
||||
wsfsp_request_respond_fn * respond;
|
||||
void * user_data;
|
||||
int id;
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wsfsp_request * wsfsp_request_create(
|
||||
struct wsfsp_request * prototype,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_request_dispose(
|
||||
struct wsfsp_request * request);
|
||||
|
||||
extern void wsfsp_respond(
|
||||
struct wsfsp_request * request,
|
||||
json_t * result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,69 +1,69 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wsfs/provider/url.h"
|
||||
#include "wsfs/provider/impl/url.h"
|
||||
|
||||
TEST(url, ParseWs)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://localhost/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_FALSE(url.use_tls);
|
||||
ASSERT_STREQ("localhost", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParswWss)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "wss://localhost/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "wss://localhost/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(443, url.port);
|
||||
ASSERT_TRUE(url.use_tls);
|
||||
ASSERT_STREQ("localhost", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseIPAdress)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://127.0.0.1/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://127.0.0.1/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_STREQ("127.0.0.1", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParsePort)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://localhost:54321/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost:54321/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(54321, url.port);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseNonEmptyPath)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://localhost/some_path?query");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost/some_path?query");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_STREQ("/some_path?query", url.path);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, FailToParseUnknownProtocol)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "unknown://localhost/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "unknown://localhost/");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
@ -72,8 +72,8 @@ TEST(url, FailToParseUnknownProtocol)
|
||||
|
||||
TEST(url, FailToParseMissingProtocol)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "unknown");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "unknown");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
@ -82,8 +82,8 @@ TEST(url, FailToParseMissingProtocol)
|
||||
|
||||
TEST(url, FailToParseMissingPath)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://localhost");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
|
Loading…
Reference in New Issue
Block a user