diff --git a/CMakeLists.txt b/CMakeLists.txt index 97c4c4a..8157263 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,9 +101,16 @@ install(FILES "${PROJECT_BINARY_DIR}/libwsfs.pc" DESTINATION lib${LIB_SUFFIX}/pk set(WSFS_PROVIDER_SOURCES lib/wsfsp/client.c lib/wsfsp/client_protocol.c - lib/wsfsp/provider.c lib/wsfsp/provider_default.c lib/wsfsp/url.c + lib/wsfsp/provider.c + lib/wsfsp/operation/error.c + lib/wsfsp/operation/lookup.c + lib/wsfsp/operation/getattr.c + lib/wsfsp/operation/readdir.c + lib/wsfsp/operation/open.c + lib/wsfsp/operation/close.c + lib/wsfsp/operation/read.c ) add_library(wsfs-provider SHARED ${WSFS_PROVIDER_SOURCES}) diff --git a/example/provider/main.c b/example/provider/main.c index 799f8de..15a4fdb 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -59,11 +59,9 @@ static void fs_getattr( static void fs_readdir( struct wsfsp_request * request, ino_t directory, - struct wsfsp_dirbuffer * dirbuffer, void * user_data) { (void) directory; - (void) dirbuffer; (void) user_data; puts("readdir"); diff --git a/include/wsfs.h b/include/wsfs.h index c91c007..cd12a2e 100644 --- a/include/wsfs.h +++ b/include/wsfs.h @@ -1,9 +1,9 @@ #ifndef WSFS_H #define WSFS_H -#include "wsfs/api.h" -#include "wsfs/server.h" -#include "wsfs/server_config.h" -#include "wsfs/server_protocol.h" +#include +#include +#include +#include #endif diff --git a/include/wsfs_provider.h b/include/wsfs_provider.h index a9377ea..f925e6f 100644 --- a/include/wsfs_provider.h +++ b/include/wsfs_provider.h @@ -1,9 +1,18 @@ #ifndef WSFSP_H #define WSFSP_H -#include "wsfsp/api.h" -#include "wsfsp/provider.h" -#include "wsfsp/client.h" -#include "wsfsp/client_protocol.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include #endif diff --git a/include/wsfsp/dirbuffer.h b/include/wsfsp/dirbuffer.h new file mode 100644 index 0000000..282d6e0 --- /dev/null +++ b/include/wsfsp/dirbuffer.h @@ -0,0 +1,32 @@ +#ifndef WSFSP_DIRBUFFER_H +#define WSFSP_DIRBUFFER_H + +#include +#include +#include + +#include "wsfsp/api.h" + +struct wsfsp_dirbuffer; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern WSFSP_API struct wsfsp_dirbuffer * wsfsp_dirbuffer_init(void); + +extern WSFSP_API void wsfsp_dirbuffer_dispose( + struct wsfsp_dirbuffer * buffer); + +extern WSFSP_API void wsfsp_dirbuffer_add( + struct wsfsp_dirbuffer * buffer, + char const * name, + ino_t inode); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/wsfsp/operation/close.h b/include/wsfsp/operation/close.h new file mode 100644 index 0000000..95f79b6 --- /dev/null +++ b/include/wsfsp/operation/close.h @@ -0,0 +1,31 @@ +#ifndef WSFSP_OPERATION_CLOSE_H +#define WSFSP_OPERATION_CLOSE_H + +#ifndef __cplusplus +#include +#else +#include +#endif + +#include +#include +#include + +#include "wsfsp/api.h" + +typedef void wsfsp_close_fn( + ino_t inode, + uint32_t handle, + int flags, + void * user_data); + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/wsfsp/operation/error.h b/include/wsfsp/operation/error.h new file mode 100644 index 0000000..c29f4b7 --- /dev/null +++ b/include/wsfsp/operation/error.h @@ -0,0 +1,21 @@ +#ifndef WSFSP_OPERATION_ERROR_H +#define WSFSP_OPERATION_ERROR_H + +#include "wsfsp/api.h" + +struct wsfsp_request; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern WSFSP_API void wsfsp_respond_error( + struct wsfsp_request * request, + int status); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/wsfsp/operation/getattr.h b/include/wsfsp/operation/getattr.h new file mode 100644 index 0000000..c4a66e8 --- /dev/null +++ b/include/wsfsp/operation/getattr.h @@ -0,0 +1,32 @@ +#ifndef WSFSP_OPERATION_GETATTR_H +#define WSFSP_OPERATION_GETATTR_H + +#include +#include +#include + +#include "wsfsp/api.h" + +struct wsfsp_request; + +typedef void wsfsp_getattr_fn( + struct wsfsp_request * request, + 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); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/wsfsp/operation/lookup.h b/include/wsfsp/operation/lookup.h new file mode 100644 index 0000000..4007f18 --- /dev/null +++ b/include/wsfsp/operation/lookup.h @@ -0,0 +1,32 @@ +#ifndef WSFSP_OPERATION_LOOKUP_H +#define WSFSP_OPERATION_LOOKUP_H + +#include +#include +#include + +#include "wsfsp/api.h" + +struct wsfsp_request; + +typedef void wsfsp_lookup_fn( + struct wsfsp_request * request, + ino_t parent, + 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); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/wsfsp/operation/open.h b/include/wsfsp/operation/open.h new file mode 100644 index 0000000..70b3eff --- /dev/null +++ b/include/wsfsp/operation/open.h @@ -0,0 +1,38 @@ +#ifndef WSFSP_OPERATION_OPEN_H +#define WSFSP_OPERATION_OPEN_H + +#ifndef __cplusplus +#include +#else +#include +#endif + +#include +#include +#include + +#include "wsfsp/api.h" + +struct wsfsp_request; + +typedef void wsfsp_open_fn( + struct wsfsp_request * request, + ino_t inode, + int flags, + void * user_data); + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern WSFSP_API void wsfsp_respond_open( + struct wsfsp_request * request, + uint32_t handle); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/wsfsp/operation/read.h b/include/wsfsp/operation/read.h new file mode 100644 index 0000000..cf01335 --- /dev/null +++ b/include/wsfsp/operation/read.h @@ -0,0 +1,44 @@ +#ifndef WSFSP_OPERATION_READ_H +#define WSFSP_OPERATION_READ_H + +#ifndef __cplusplus +#include +#include +#else +#include +#include +using std::size_t; +#endif + +#include +#include +#include + +#include "wsfsp/api.h" + +struct wsfsp_request; + +typedef void wsfsp_read_fn( + struct wsfsp_request * request, + ino_t inode, + uint32_t handle, + size_t offset, + 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, + size_t length); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/wsfsp/operation/readdir.h b/include/wsfsp/operation/readdir.h new file mode 100644 index 0000000..9eb20a5 --- /dev/null +++ b/include/wsfsp/operation/readdir.h @@ -0,0 +1,32 @@ +#ifndef WSFSP_OPERATION_READDIR_H +#define WSFSP_OPERATION_READDIR_H + +#include +#include +#include + +#include "wsfsp/api.h" + +struct wsfsp_dirbuffer; +struct wsfsp_request; + +typedef void wsfsp_readdir_fn( + struct wsfsp_request * request, + 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); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/wsfsp/provider.h b/include/wsfsp/provider.h index 3274780..75cf92b 100644 --- a/include/wsfsp/provider.h +++ b/include/wsfsp/provider.h @@ -1,60 +1,12 @@ #ifndef WSFSP_PROVIDER_H #define WSFSP_PROVIDER_H -#ifndef __cplusplus -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include -#include - -#include "wsfsp/api.h" - -struct wsfsp_request; -struct wsfsp_dirbuffer; - -typedef void wsfsp_lookup_fn( - struct wsfsp_request * request, - ino_t parent, - char const * name, - void * user_data); - -typedef void wsfsp_getattr_fn( - struct wsfsp_request * request, - ino_t inode, - void * user_data); - -typedef void wsfsp_readdir_fn( - struct wsfsp_request * request, - ino_t directory, - struct wsfsp_dirbuffer * dirbuffer, - void * user_data); - -typedef void wsfsp_open_fn( - struct wsfsp_request * request, - ino_t inode, - int flags, - void * user_data); - -typedef void wsfsp_close_fn( - ino_t inode, - uint32_t handle, - int flags, - void * user_data); - -typedef void wsfsp_read_fn( - struct wsfsp_request * request, - ino_t inode, - uint32_t handle, - size_t offset, - size_t length, - void * user_data); +#include +#include +#include +#include +#include +#include typedef void wsfsp_connected_fn( void * user_data); @@ -78,38 +30,5 @@ struct wsfsp_provider wsfsp_read_fn * read; }; -#ifdef __cplusplus -extern "C" -{ -#endif - -extern WSFSP_API void wsfsp_respond_error( - struct wsfsp_request * request, - int status); - -extern WSFSP_API void wsfsp_respond_lookup( - struct wsfsp_request * request, - struct stat const * stat); - -extern WSFSP_API void wsfsp_respond_getattr( - struct wsfsp_request * request, - struct stat const * stat); - -extern WSFSP_API void wsfsp_respond_readdir( - struct wsfsp_request * request, - struct wsfsp_dirbuffer * dirbuffer); - -extern WSFSP_API void wsfsp_respond_open( - struct wsfsp_request * request, - uint32_t handle); - -extern WSFSP_API void wsfsp_respond_read( - struct wsfsp_request * request, - char const * data, - size_t length); - -#ifdef __cplusplus -} -#endif #endif diff --git a/lib/wsfsp/client.c b/lib/wsfsp/client.c index 297ce72..4a2777d 100644 --- a/lib/wsfsp/client.c +++ b/lib/wsfsp/client.c @@ -40,7 +40,7 @@ struct wsfsp_client * wsfsp_client_create( wsfsp_client_protocol_init(&client->protocol, provider, user_data); memset(client->protocols, 0, sizeof(struct lws_protocols) * WSFSP_CLIENT_PROTOCOL_COUNT); - client->protocols[0].name = "fs-provider"; + client->protocols[0].name = "fs"; wsfsp_client_protocol_init_lws(&client->protocol, &client->protocols[0]); memset(&client->info, 0, sizeof(struct lws_context_creation_info)); diff --git a/lib/wsfsp/client_protocol.c b/lib/wsfsp/client_protocol.c index c1ea02d..c633015 100644 --- a/lib/wsfsp/client_protocol.c +++ b/lib/wsfsp/client_protocol.c @@ -4,31 +4,79 @@ #include #include +#include #include "wsfsp/provider_default.h" +#include "wsfsp/provider_intern.h" #include "wsfs/util.h" +static void wsfsp_client_protocol_respond( + json_t * response, + void * user_data) +{ + // ToDo: implment me + (void) user_data; + + char * value = json_dumps(response, 0); + if (NULL != value) + { + puts(value); + } + free(value); +} + +static void wsfsp_client_protocol_process_request( + struct wsfsp_client_protocol * protocol, + char const * message, + size_t length) +{ + json_t * request = json_loadb(message, length, 0, NULL); + if (NULL != request) + { + struct wsfsp_invokation_context context = + { + .provider = &protocol->provider, + .user_data = protocol->user_data, + .request = &protocol->request + }; + + puts("wsfsp_provider_invoke"); + wsfsp_provider_invoke(&context, request); + json_decref(request); + } +} + + static int wsfsp_client_protocol_callback( - struct lws * WSFS_UNUSED_PARAM(wsi), + struct lws * wsi, enum lws_callback_reasons reason, void * WSFS_UNUSED_PARAM(user), - void * WSFS_UNUSED_PARAM(in), - size_t WSFS_UNUSED_PARAM(len)) + void * in, + size_t len) { + struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); + struct wsfsp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL; - switch (reason) + if (NULL != protocol) { - case LWS_CALLBACK_CLIENT_ESTABLISHED: - puts("established"); - break; - case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: - puts("error: client could not connect"); - break; - case LWS_CALLBACK_CLIENT_CLOSED: - puts("client closed"); - break; - default: - break; + switch (reason) + { + case LWS_CALLBACK_CLIENT_ESTABLISHED: + puts("established"); + protocol->provider.connected(protocol->user_data); + break; + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + protocol->provider.disconnected(protocol->user_data); + break; + case LWS_CALLBACK_CLIENT_CLOSED: + protocol->provider.connected(protocol->user_data); + break; + case LWS_CALLBACK_CLIENT_RECEIVE: + wsfsp_client_protocol_process_request(protocol, in, len); + break; + default: + break; + } } return 0; @@ -40,6 +88,9 @@ void wsfsp_client_protocol_init( struct wsfsp_provider const * provider, void * user_data) { + protocol->request.respond = &wsfsp_client_protocol_respond; + protocol->request.user_data = protocol; + protocol->user_data = user_data; protocol->provider.lookup = (NULL != provider->lookup) ? provider->lookup : &wsfsp_lookup_default; protocol->provider.getattr = (NULL != provider->getattr) ? provider->getattr : &wsfsp_getattr_default; diff --git a/lib/wsfsp/client_protocol_intern.h b/lib/wsfsp/client_protocol_intern.h index 4fda97f..6a77951 100644 --- a/lib/wsfsp/client_protocol_intern.h +++ b/lib/wsfsp/client_protocol_intern.h @@ -3,9 +3,11 @@ #include "wsfsp/client_protocol.h" #include "wsfsp/provider.h" +#include "wsfsp/request.h" struct wsfsp_client_protocol { + struct wsfsp_request request; struct wsfsp_provider provider; void * user_data; }; diff --git a/lib/wsfsp/operation/close.c b/lib/wsfsp/operation/close.c new file mode 100644 index 0000000..126924a --- /dev/null +++ b/lib/wsfsp/operation/close.c @@ -0,0 +1,29 @@ +#include "wsfsp/operation/close_intern.h" +#include +#include "wsfs/util.h" + +void wsfsp_close( + struct wsfsp_invokation_context * context, + json_t * params, + int WSFS_UNUSED_PARAM(id)) +{ + size_t const param_count = json_array_size(params); + if (3 == param_count) + { + json_t * inode_holder = json_array_get(params, 0); + json_t * handle_holder = json_array_get(params, 1); + json_t * flags_holder = json_array_get(params, 2); + + if (json_is_integer(inode_holder) && + json_is_integer(handle_holder) && + json_is_integer(flags_holder)) + { + ino_t inode = (ino_t) json_integer_value(inode_holder); + uint32_t handle = (uint32_t) (json_integer_value(handle_holder) & UINT32_MAX); + int flags = json_integer_value(flags_holder); + + context->provider->close(inode, handle, flags, context->user_data); + } + } + +} \ No newline at end of file diff --git a/lib/wsfsp/operation/close_intern.h b/lib/wsfsp/operation/close_intern.h new file mode 100644 index 0000000..c74d5f7 --- /dev/null +++ b/lib/wsfsp/operation/close_intern.h @@ -0,0 +1,21 @@ +#ifndef WSFSP_OPERATION_CLOSE_INTERN_H +#define WSFSP_OPERATION_CLOSE_INTERN_H + +#include "wsfsp/operation/close.h" +#include "wsfsp/provider_intern.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_close( + struct wsfsp_invokation_context * context, + json_t * params, + int id); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfsp/operation/error.c b/lib/wsfsp/operation/error.c new file mode 100644 index 0000000..4614e95 --- /dev/null +++ b/lib/wsfsp/operation/error.c @@ -0,0 +1,11 @@ +#include "wsfsp/operation/error.h" + +void wsfsp_respond_error( + struct wsfsp_request * request, + int status) +{ + (void) request; + (void) status; + + // ToDo: implement me +} diff --git a/lib/wsfsp/operation/getattr.c b/lib/wsfsp/operation/getattr.c new file mode 100644 index 0000000..12b0c38 --- /dev/null +++ b/lib/wsfsp/operation/getattr.c @@ -0,0 +1,24 @@ +#include "wsfsp/operation/getattr_intern.h" +#include + +void wsfsp_getattr( + struct wsfsp_invokation_context * context, + json_t * params, + int id) +{ + (void) context; + (void) params; + (void) id; + + puts("getattr"); +} + +void wsfsp_respond_getattr( + struct wsfsp_request * request, + struct stat const * stat) +{ + (void) request; + (void) stat; + + // ToDo: implement me +} diff --git a/lib/wsfsp/operation/getattr_intern.h b/lib/wsfsp/operation/getattr_intern.h new file mode 100644 index 0000000..7c67dff --- /dev/null +++ b/lib/wsfsp/operation/getattr_intern.h @@ -0,0 +1,21 @@ +#ifndef WSFSP_OPERATION_GETATTR_INTERN_H +#define WSFSP_OPERATION_GETATTR_INTERN_H + +#include "wsfsp/operation/getattr.h" +#include "wsfsp/provider_intern.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_getattr( + struct wsfsp_invokation_context * context, + json_t * params, + int id); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfsp/operation/lookup.c b/lib/wsfsp/operation/lookup.c new file mode 100644 index 0000000..efee473 --- /dev/null +++ b/lib/wsfsp/operation/lookup.c @@ -0,0 +1,24 @@ +#include "wsfsp/operation/lookup_intern.h" +#include + +void wsfsp_lookup( + struct wsfsp_invokation_context * context, + json_t * params, + int id) +{ + (void) context; + (void) params; + (void) id; + + puts("lookup"); +} + +void wsfsp_respond_lookup( + struct wsfsp_request * request, + struct stat const * stat) +{ + (void) request; + (void) stat; + +} + diff --git a/lib/wsfsp/operation/lookup_intern.h b/lib/wsfsp/operation/lookup_intern.h new file mode 100644 index 0000000..cc36cc3 --- /dev/null +++ b/lib/wsfsp/operation/lookup_intern.h @@ -0,0 +1,21 @@ +#ifndef WSFSP_OPERATION_LOOKUP_INTERN_H +#define WSFSP_OPERATION_LOOKUP_INTERN_H + +#include "wsfsp/operation/lookup.h" +#include "wsfsp/provider_intern.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_lookup( + struct wsfsp_invokation_context * context, + json_t * params, + int id); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfsp/operation/open.c b/lib/wsfsp/operation/open.c new file mode 100644 index 0000000..0d92523 --- /dev/null +++ b/lib/wsfsp/operation/open.c @@ -0,0 +1,24 @@ +#include "wsfsp/operation/open_intern.h" +#include + +void wsfsp_open( + struct wsfsp_invokation_context * context, + json_t * params, + int id) +{ + (void) context; + (void) params; + (void) id; + + puts("open"); +} + +void wsfsp_respond_open( + struct wsfsp_request * request, + uint32_t handle) +{ + (void) request; + (void) handle; + + // ToDo: implement me +} diff --git a/lib/wsfsp/operation/open_intern.h b/lib/wsfsp/operation/open_intern.h new file mode 100644 index 0000000..ac5a1d7 --- /dev/null +++ b/lib/wsfsp/operation/open_intern.h @@ -0,0 +1,21 @@ +#ifndef WSFSP_OPERATION_OPEN_INTERN_H +#define WSFSP_OPERATION_OPEN_INTERN_H + +#include "wsfsp/operation/open.h" +#include "wsfsp/provider_intern.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_open( + struct wsfsp_invokation_context * context, + json_t * params, + int id); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfsp/operation/read.c b/lib/wsfsp/operation/read.c new file mode 100644 index 0000000..ac87f63 --- /dev/null +++ b/lib/wsfsp/operation/read.c @@ -0,0 +1,24 @@ +#include "wsfsp/operation/read_intern.h" +#include + +void wsfsp_read( + struct wsfsp_invokation_context * context, + json_t * params, + int id) +{ + (void) context; + (void) params; + (void) id; + + puts("read"); +} + +void wsfsp_respond_read( + struct wsfsp_request * request, + char const * data, + size_t length) +{ + (void) request; + (void) data; + (void) length; +} \ No newline at end of file diff --git a/lib/wsfsp/operation/read_intern.h b/lib/wsfsp/operation/read_intern.h new file mode 100644 index 0000000..bc3a44f --- /dev/null +++ b/lib/wsfsp/operation/read_intern.h @@ -0,0 +1,21 @@ +#ifndef WSFSP_OPERATION_READ_INTERN_H +#define WSFSP_OPERATION_READ_INTERN_H + +#include "wsfsp/operation/read.h" +#include "wsfsp/provider_intern.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_read( + struct wsfsp_invokation_context * context, + json_t * params, + int id); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfsp/operation/readdir.c b/lib/wsfsp/operation/readdir.c new file mode 100644 index 0000000..226465c --- /dev/null +++ b/lib/wsfsp/operation/readdir.c @@ -0,0 +1,25 @@ +#include "wsfsp/operation/readdir_intern.h" +#include + +void wsfsp_readdir( + struct wsfsp_invokation_context * context, + json_t * params, + int id) +{ + (void) context; + (void) params; + (void) id; + + puts("readdir"); +} + +void wsfsp_respond_readdir( + struct wsfsp_request * request, + struct wsfsp_dirbuffer * dirbuffer) +{ + (void) request; + (void) dirbuffer; + + // ToDo: implement me +} + diff --git a/lib/wsfsp/operation/readdir_intern.h b/lib/wsfsp/operation/readdir_intern.h new file mode 100644 index 0000000..09142f5 --- /dev/null +++ b/lib/wsfsp/operation/readdir_intern.h @@ -0,0 +1,21 @@ +#ifndef WSFSP_OPERATION_READDIR_INTERN_H +#define WSFSP_OPERATION_READDIR_INTERN_H + +#include "wsfsp/operation/readdir.h" +#include "wsfsp/provider_intern.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_readdir( + struct wsfsp_invokation_context * context, + json_t * params, + int id); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfsp/provider.c b/lib/wsfsp/provider.c index 4810400..e1c42bc 100644 --- a/lib/wsfsp/provider.c +++ b/lib/wsfsp/provider.c @@ -1,63 +1,74 @@ -#include "wsfsp/provider.h" +#include "wsfsp/provider_intern.h" -void wsfsp_respond_error( - struct wsfsp_request * request, - int status) +#include +#include + +#include "wsfsp/request.h" +#include "wsfsp/operation/lookup_intern.h" +#include "wsfsp/operation/getattr_intern.h" +#include "wsfsp/operation/readdir_intern.h" +#include "wsfsp/operation/open_intern.h" +#include "wsfsp/operation/close_intern.h" +#include "wsfsp/operation/read_intern.h" + +typedef void wsfsp_invoke_fn( + struct wsfsp_invokation_context * context, + json_t * params, + int id); + + +struct wsfsp_method { - (void) request; - (void) status; + char const * name; + wsfsp_invoke_fn * invoke; + bool is_notification; +}; - // ToDo: implement me +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_respond_lookup( - struct wsfsp_request * request, - struct stat const * stat) +void wsfsp_provider_invoke( + struct wsfsp_invokation_context * context, + json_t * request) { - (void) request; - (void) stat; + 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"); - // ToDo: implement me -} + 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; -void wsfsp_respond_getattr( - struct wsfsp_request * request, - struct stat const * stat) -{ - (void) request; - (void) stat; - - // ToDo: implement me -} - -void wsfsp_respond_readdir( - struct wsfsp_request * request, - struct wsfsp_dirbuffer * dirbuffer) -{ - (void) request; - (void) dirbuffer; - - // ToDo: implement me -} - -void wsfsp_respond_open( - struct wsfsp_request * request, - uint32_t handle) -{ - (void) request; - (void) handle; - - // ToDo: implement me -} - -void wsfsp_respond_read( - struct wsfsp_request * request, - char const * data, - size_t length) -{ - (void) request; - (void) data; - (void) length; - - // ToDo: implement me -} + wsfsp_provider_invoke_method(context, method, params, id); + } +} \ No newline at end of file diff --git a/lib/wsfsp/provider_default.c b/lib/wsfsp/provider_default.c index f38e576..6bfe1d6 100644 --- a/lib/wsfsp/provider_default.c +++ b/lib/wsfsp/provider_default.c @@ -1,4 +1,5 @@ #include "wsfsp/provider_default.h" +#include "wsfsp/operation/error.h" void wsfsp_lookup_default( struct wsfsp_request * request, @@ -27,11 +28,9 @@ void wsfsp_getattr_default( void wsfsp_readdir_default( struct wsfsp_request * request, ino_t directory, - struct wsfsp_dirbuffer * dirbuffer, void * user_data) { (void) directory; - (void) dirbuffer; (void) user_data; wsfsp_respond_error(request, -1); diff --git a/lib/wsfsp/provider_default.h b/lib/wsfsp/provider_default.h index 96d3671..32106c6 100644 --- a/lib/wsfsp/provider_default.h +++ b/lib/wsfsp/provider_default.h @@ -22,7 +22,6 @@ extern void wsfsp_getattr_default( extern void wsfsp_readdir_default( struct wsfsp_request * request, ino_t directory, - struct wsfsp_dirbuffer * dirbuffer, void * user_data); extern void wsfsp_open_default( diff --git a/lib/wsfsp/provider_intern.h b/lib/wsfsp/provider_intern.h new file mode 100644 index 0000000..f3a7b26 --- /dev/null +++ b/lib/wsfsp/provider_intern.h @@ -0,0 +1,27 @@ +#ifndef WSFSP_PROVIDER_INTERN_H +#define WSFSP_PROVIDER_INTERN_H + +#include "wsfsp/provider.h" +#include + +struct wsfsp_invokation_context +{ + struct wsfsp_provider * provider; + void * user_data; + struct wsfsp_request * request; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_provider_invoke( + struct wsfsp_invokation_context * context, + json_t * request); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfsp/request.h b/lib/wsfsp/request.h new file mode 100644 index 0000000..2165099 --- /dev/null +++ b/lib/wsfsp/request.h @@ -0,0 +1,18 @@ +#ifndef WSFSP_REQUEST_H +#define WSFSP_REQUEST_H + +#include +#include "wsfsp/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; +}; + + +#endif