From 519ec3a178faf31fe47467adcef4c18a1d760b92 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 3 Mar 2019 16:29:02 +0100 Subject: [PATCH 01/10] added implemetation of open --- example/provider/main.c | 25 ++++++++++++++++++++----- lib/wsfs/provider/operation/open.c | 27 ++++++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/example/provider/main.c b/example/provider/main.c index dbe2576..15f7b94 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -4,6 +4,9 @@ #include #include +#include +#include + #include "wsfs_provider.h" enum fs_entry_type @@ -180,12 +183,24 @@ static void fs_open( int flags, void * user_data) { - (void) inode; - (void) flags; - (void) user_data; + struct fs * fs = (struct fs*) user_data; - puts("open"); - wsfsp_respond_error(request, -1); + struct fs_entry const * entry = fs_getentry(fs, inode); + if ((NULL != entry) && (FS_FILE == entry->type)) + { + if (O_RDONLY == (flags & O_ACCMODE)) + { + wsfsp_respond_open(request, 0U); + } + else + { + wsfsp_respond_error(request, -1); + } + } + else + { + wsfsp_respond_error(request, -1); + } } static void fs_read( diff --git a/lib/wsfs/provider/operation/open.c b/lib/wsfs/provider/operation/open.c index 8bb5573..1f4bcd4 100644 --- a/lib/wsfs/provider/operation/open.c +++ b/lib/wsfs/provider/operation/open.c @@ -1,6 +1,7 @@ #include "wsfs/provider/operation/open_intern.h" #include #include "wsfs/provider/operation/error.h" +#include "wsfs/provider/request.h" #include "wsfs/util.h" void wsfsp_open( @@ -8,11 +9,23 @@ void wsfsp_open( json_t * params, int id) { - (void) context; - (void) params; - (void) id; + size_t const count = json_array_size(params); + if (2 == count) + { + json_t * inode_holder = json_array_get(params, 0); + json_t * flags_holder = json_array_get(params, 1); - puts("open"); + if (json_is_integer(inode_holder) && + json_is_integer(flags_holder)) + { + 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); + + context->provider->open(request, inode, flags, context->user_data); + } + } } void wsfsp_open_default( @@ -28,8 +41,8 @@ void wsfsp_respond_open( struct wsfsp_request * request, uint32_t handle) { - (void) request; - (void) handle; + json_t * result = json_object(); + json_object_set_new(result, "handle", json_integer((int) handle)); - // ToDo: implement me + wsfsp_respond(request, result); } From de454516cbcb55488cd797859d25711bb0c35f83 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 3 Mar 2019 18:02:02 +0100 Subject: [PATCH 02/10] fixes invalid memory acceess --- lib/wsfs/adapter/operation/read.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/wsfs/adapter/operation/read.c b/lib/wsfs/adapter/operation/read.c index ebbd1ab..6104c4b 100644 --- a/lib/wsfs/adapter/operation/read.c +++ b/lib/wsfs/adapter/operation/read.c @@ -10,32 +10,32 @@ #define WSFS_MAX_READ_LENGTH 4096 -static wsfs_status wsfs_fill_buffer( - char * * buffer, - char const * format, +static char * wsfs_fill_buffer( char const * data, - size_t count) + char const * format, + size_t count, + wsfs_status * status) { - wsfs_status status = WSFS_GOOD; + *status = WSFS_GOOD; + char * buffer = malloc(count + 1); - if (0 < count) + if ((NULL != buffer) && (0 < count)) { - *buffer = malloc(count); if (0 == strcmp("identity", format)) { - memcpy(*buffer, data, count); /* Flawfinder: ignore */ + memcpy(buffer, data, count); /* Flawfinder: ignore */ } else if (0 == strcmp("base64", format)) { - lws_b64_decode_string(data, *buffer, count); + lws_b64_decode_string(data, buffer, count + 1); } else { - status = WSFS_BAD; + *status = WSFS_BAD; } } - return status; + return buffer; } static void wsfs_operation_read_finished(void * user_data, wsfs_status status, json_t const * data) @@ -50,15 +50,15 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j json_t * format_holder = json_object_get(data, "format"); json_t * count_holder = json_object_get(data, "count"); - if ((NULL != data_holder) && (json_is_string(data_holder)) && - (NULL != format_holder) && (json_is_string(format_holder)) && - (NULL != count_holder) && (json_is_integer(count_holder))) + if (json_is_string(data_holder) && + json_is_string(format_holder) && + json_is_integer(count_holder)) { char const * const data = json_string_value(data_holder); char const * const format = json_string_value(format_holder); length = (size_t) json_integer_value(count_holder); - status = wsfs_fill_buffer(&buffer, format, data, length); + buffer = wsfs_fill_buffer(data, format, length, &status); } else { From e4d95f5dc937bf549e7436a3c33ca3db9dcff185 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 3 Mar 2019 18:02:30 +0100 Subject: [PATCH 03/10] implements operation read --- example/provider/main.c | 30 +++++++++++--- lib/wsfs/provider/operation/read.c | 63 ++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 13 deletions(-) diff --git a/example/provider/main.c b/example/provider/main.c index 15f7b94..4cc21e1 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -203,6 +203,11 @@ static void fs_open( } } +static size_t min(size_t const a, size_t const b) +{ + return (a < b) ? a : b; +} + static void fs_read( struct wsfsp_request * request, ino_t inode, @@ -211,13 +216,28 @@ static void fs_read( size_t length, void * user_data) { - (void) inode; (void) handle; - (void) offset; - (void) length; - (void) user_data; - wsfsp_respond_error(request, -1); + struct fs * fs = (struct fs*) user_data; + struct fs_entry const * entry = fs_getentry(fs, inode); + if ((NULL != entry) && (FS_FILE == entry->type)) + { + if (entry->content_length > offset) + { + size_t const remaining = entry->content_length - offset; + size_t const count = min(remaining, length); + + wsfsp_respond_read(request, &entry->content[offset], count); + } + else + { + wsfsp_respond_error(request, -1); + } + } + else + { + wsfsp_respond_error(request, -1); + } } static struct wsfsp_provider fs_provider = diff --git a/lib/wsfs/provider/operation/read.c b/lib/wsfs/provider/operation/read.c index ac802d8..c7e4fec 100644 --- a/lib/wsfs/provider/operation/read.c +++ b/lib/wsfs/provider/operation/read.c @@ -1,5 +1,8 @@ #include "wsfs/provider/operation/read_intern.h" -#include + +#include +#include + #include "wsfs/provider/operation/error.h" #include "wsfs/util.h" @@ -8,11 +11,28 @@ void wsfsp_read( json_t * params, int id) { - (void) context; - (void) params; - (void) id; + size_t const count = json_array_size(params); + if (4 == count) + { + json_t * inode_holder = json_array_get(params, 0); + json_t * handle_holder = json_array_get(params, 1); + json_t * offset_holder = json_array_get(params, 2); + json_t * length_holder = json_array_get(params, 3); - puts("read"); + if (json_is_integer(inode_holder) && + json_is_integer(handle_holder) && + json_is_integer(offset_holder) && + json_is_integer(length_holder)) + { + ino_t inode = (ino_t) json_integer_value(inode_holder); + 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); + + context->provider->read(request, inode, handle, offset, length, context->user_data); + } + } } void wsfsp_read_default( @@ -31,7 +51,34 @@ void wsfsp_respond_read( char const * data, size_t length) { - (void) request; - (void) data; - (void) length; + if (0 < length) + { + size_t const size = 4 * ((length / 3) + 2); + char * buffer = malloc(size); + if (NULL != buffer) + { + lws_b64_encode_string(data, length, buffer, size); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string(buffer)); + json_object_set_new(result, "format", json_string("base64")); + json_object_set_new(result, "count", json_integer((int) length)); + + wsfsp_respond(request, result); + free(buffer); + } + else + { + wsfsp_respond_error(request, -1); + } + } + else + { + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("")); + json_object_set_new(result, "format", json_string("identitiy")); + json_object_set_new(result, "count", json_integer(0)); + + wsfsp_respond(request, result); + } } \ No newline at end of file From 4565e40fde8d444a4bdb97c4c927715dfac77b4a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 3 Mar 2019 18:17:00 +0100 Subject: [PATCH 04/10] removes unused structs --- example/provider/main.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/example/provider/main.c b/example/provider/main.c index 4cc21e1..4f3cb7e 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -26,23 +26,6 @@ struct fs_entry char const * content; }; -struct fs_dir -{ - ino_t parent; - ino_t inode; - char const * name; -}; - -struct fs_file -{ - ino_t parent; - ino_t inode; - char const * name; - char const * content; - size_t content_length; - bool is_executable; -}; - struct fs { struct fs_entry const * entries; From 2e858475c2ab3c616bbb59e3caaf621226780ef1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 3 Mar 2019 18:17:50 +0100 Subject: [PATCH 05/10] removed debug code --- lib/wsfs/message.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/wsfs/message.c b/lib/wsfs/message.c index b4431a3..73a756d 100644 --- a/lib/wsfs/message.c +++ b/lib/wsfs/message.c @@ -5,12 +5,6 @@ extern struct wsfs_message * wsfs_message_create(json_t const * value) { -#if 0 - char * msg = json_dumps(value, JSON_COMPACT); - puts(msg); - free(msg); -#endif - struct wsfs_message * message = NULL; size_t const length = json_dumpb(value, NULL, 0, JSON_COMPACT); From fff6d540462518744279f58f6764dfcc4ac34177 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 3 Mar 2019 18:20:33 +0100 Subject: [PATCH 06/10] removes unused includes of stdio.h --- lib/wsfs/provider/operation/getattr.c | 1 - lib/wsfs/provider/operation/lookup.c | 1 - lib/wsfs/provider/operation/open.c | 1 - lib/wsfs/provider/operation/readdir.c | 3 --- 4 files changed, 6 deletions(-) diff --git a/lib/wsfs/provider/operation/getattr.c b/lib/wsfs/provider/operation/getattr.c index 03425ef..c4be838 100644 --- a/lib/wsfs/provider/operation/getattr.c +++ b/lib/wsfs/provider/operation/getattr.c @@ -1,6 +1,5 @@ #include "wsfs/provider/operation/getattr_intern.h" -#include #include #include "wsfs/provider/operation/error.h" diff --git a/lib/wsfs/provider/operation/lookup.c b/lib/wsfs/provider/operation/lookup.c index 79ba9f4..646205b 100644 --- a/lib/wsfs/provider/operation/lookup.c +++ b/lib/wsfs/provider/operation/lookup.c @@ -1,6 +1,5 @@ #include "wsfs/provider/operation/lookup_intern.h" -#include #include #include "wsfs/provider/operation/error.h" diff --git a/lib/wsfs/provider/operation/open.c b/lib/wsfs/provider/operation/open.c index 1f4bcd4..a9670e7 100644 --- a/lib/wsfs/provider/operation/open.c +++ b/lib/wsfs/provider/operation/open.c @@ -1,5 +1,4 @@ #include "wsfs/provider/operation/open_intern.h" -#include #include "wsfs/provider/operation/error.h" #include "wsfs/provider/request.h" #include "wsfs/util.h" diff --git a/lib/wsfs/provider/operation/readdir.c b/lib/wsfs/provider/operation/readdir.c index 6c88aa5..87284d8 100644 --- a/lib/wsfs/provider/operation/readdir.c +++ b/lib/wsfs/provider/operation/readdir.c @@ -1,7 +1,4 @@ #include "wsfs/provider/operation/readdir_intern.h" - -#include - #include "wsfs/provider/operation/error.h" #include "wsfs/provider/dirbuffer_intern.h" #include "wsfs/provider/request.h" From 2781aadf55aed05302cf4478cff6f1d3c4ef2d0e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 4 Mar 2019 19:19:04 +0100 Subject: [PATCH 07/10] makes wsfs_status public (usable in provider example) --- CMakeLists.txt | 4 ++- example/provider/main.c | 14 +++++----- include/wsfs/provider/operation/error.h | 3 ++- include/wsfs_adapter.h | 2 ++ include/wsfs_provider.h | 2 ++ lib/wsfs/adapter/jsonrpc/method.h | 2 +- lib/wsfs/adapter/jsonrpc/response.h | 2 +- lib/wsfs/adapter/operation/open.c | 2 +- lib/wsfs/adapter/status.c | 34 ------------------------- lib/wsfs/adapter/status.h | 30 ---------------------- lib/wsfs/provider/operation/lookup.c | 2 +- lib/wsfs/provider/operation/open.c | 2 +- lib/wsfs/provider/operation/read.c | 4 +-- lib/wsfs/provider/operation/readdir.c | 2 +- lib/wsfs/provider/request.c | 2 +- 15 files changed, 25 insertions(+), 82 deletions(-) delete mode 100644 lib/wsfs/adapter/status.c delete mode 100644 lib/wsfs/adapter/status.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d078a34..36637ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,12 +46,14 @@ set(EXTRA_CFLAGS set(WSFS_COMMON_SOURCES lib/wsfs/message.c lib/wsfs/message_queue.c + lib/wsfs/status.c ) +install(FILES include/wsfs/status.h DESTINATION include/wsfs) + # libwsfs-adapter set(WSFS_ADAPTER_SOURCES - lib/wsfs/adapter/status.c lib/wsfs/adapter/filesystem.c lib/wsfs/adapter/server.c lib/wsfs/adapter/time/timepoint.c diff --git a/example/provider/main.c b/example/provider/main.c index 4f3cb7e..dcdfecd 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -102,7 +102,7 @@ static void fs_lookup( } else { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } } @@ -124,7 +124,7 @@ static void fs_getattr( } else { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } } @@ -156,7 +156,7 @@ static void fs_readdir( } else { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } } @@ -177,12 +177,12 @@ static void fs_open( } else { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOACCESS); } } else { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } } @@ -214,12 +214,12 @@ static void fs_read( } else { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD); } } else { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } } diff --git a/include/wsfs/provider/operation/error.h b/include/wsfs/provider/operation/error.h index c2a8567..be2dd19 100644 --- a/include/wsfs/provider/operation/error.h +++ b/include/wsfs/provider/operation/error.h @@ -2,6 +2,7 @@ #define WSFSP_OPERATION_ERROR_H #include "wsfs/provider/api.h" +#include "wsfs/status.h" struct wsfsp_request; @@ -12,7 +13,7 @@ extern "C" extern WSFSP_API void wsfsp_respond_error( struct wsfsp_request * request, - int status); + wsfs_status status); #ifdef __cplusplus } diff --git a/include/wsfs_adapter.h b/include/wsfs_adapter.h index c6f1d00..6a812a3 100644 --- a/include/wsfs_adapter.h +++ b/include/wsfs_adapter.h @@ -1,6 +1,8 @@ #ifndef WSFS_ADAPTER_H #define WSFS_ADAPTER_H +#include + #include #include #include diff --git a/include/wsfs_provider.h b/include/wsfs_provider.h index c6ff25f..9c033ec 100644 --- a/include/wsfs_provider.h +++ b/include/wsfs_provider.h @@ -1,6 +1,8 @@ #ifndef WSFS_PROVIDER_H #define WSFS_PROVIDER_H +#include + #include #include #include diff --git a/lib/wsfs/adapter/jsonrpc/method.h b/lib/wsfs/adapter/jsonrpc/method.h index 00f52c7..038bce4 100644 --- a/lib/wsfs/adapter/jsonrpc/method.h +++ b/lib/wsfs/adapter/jsonrpc/method.h @@ -6,7 +6,7 @@ #endif #include -#include "wsfs/adapter/status.h" +#include "wsfs/status.h" typedef bool wsfs_jsonrpc_method_invoke_fn( diff --git a/lib/wsfs/adapter/jsonrpc/response.h b/lib/wsfs/adapter/jsonrpc/response.h index 3e10022..4e6e34a 100644 --- a/lib/wsfs/adapter/jsonrpc/response.h +++ b/lib/wsfs/adapter/jsonrpc/response.h @@ -9,7 +9,7 @@ using std::size_t; #endif #include -#include "wsfs/adapter/status.h" +#include "wsfs/status.h" struct wsfs_jsonrpc_response { diff --git a/lib/wsfs/adapter/operation/open.c b/lib/wsfs/adapter/operation/open.c index ed86c69..27efc0c 100644 --- a/lib/wsfs/adapter/operation/open.c +++ b/lib/wsfs/adapter/operation/open.c @@ -6,7 +6,7 @@ #include "wsfs/adapter/jsonrpc/server.h" #include "wsfs/util.h" -#include "wsfs/adapter/status.h" +#include "wsfs/status.h" static void wsfs_operation_open_finished( void * user_data, diff --git a/lib/wsfs/adapter/status.c b/lib/wsfs/adapter/status.c deleted file mode 100644 index 44db17b..0000000 --- a/lib/wsfs/adapter/status.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "wsfs/adapter/status.h" - -#include - - int wsfs_status_to_rc(wsfs_status status) -{ - switch(status) - { - case WSFS_GOOD: return 0; - case WSFS_BAD_NOTIMPLEMENTED: return -ENOSYS; - case WSFS_BAD_TIMEOUT: return -ETIMEDOUT; - case WSFS_BAD_BUSY: return -ENOENT; - case WSFS_BAD_FORMAT: return -ENOENT; - case WSFS_BAD_NOENTRY: return -ENOENT; - case WSFS_BAD_NOACCESS: return -EACCES; - default: return -ENOENT; - } -} - -char const * wsfs_status_tostring(wsfs_status status) -{ - switch(status) - { - case WSFS_GOOD: return "Good"; - case WSFS_BAD: return "Bad"; - case WSFS_BAD_NOTIMPLEMENTED: return "Bad (not implelemted)"; - case WSFS_BAD_TIMEOUT: return "Bad (timeout)"; - case WSFS_BAD_BUSY: return "Bad (busy)"; - case WSFS_BAD_FORMAT: return "Bad (format)"; - case WSFS_BAD_NOENTRY: return "Bad (no entry)"; - case WSFS_BAD_NOACCESS: return "Bad (no access)"; - default: return "Bad (unknown)"; - } -} diff --git a/lib/wsfs/adapter/status.h b/lib/wsfs/adapter/status.h deleted file mode 100644 index 219a935..0000000 --- a/lib/wsfs/adapter/status.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef WSFS_ADAPTER_STATUS_H -#define WSFS_ADAPTER_STATUS_H - -#define WSFS_GOOD 0 -#define WSFS_BAD 1 - -#define WSFS_BAD_NOTIMPLEMENTED 2 -#define WSFS_BAD_TIMEOUT 3 -#define WSFS_BAD_BUSY 4 -#define WSFS_BAD_FORMAT 5 - -#define WSFS_BAD_NOENTRY 101 -#define WSFS_BAD_NOACCESS 102 - -typedef int wsfs_status; - -#ifdef __cplusplus -extern "C" { -#endif - -extern int wsfs_status_to_rc(wsfs_status status); - -extern char const * wsfs_status_tostring(wsfs_status status); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/lib/wsfs/provider/operation/lookup.c b/lib/wsfs/provider/operation/lookup.c index 646205b..900b901 100644 --- a/lib/wsfs/provider/operation/lookup.c +++ b/lib/wsfs/provider/operation/lookup.c @@ -62,6 +62,6 @@ void wsfsp_lookup_default( char const * WSFS_UNUSED_PARAM(name), void * WSFS_UNUSED_PARAM(user_data)) { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } diff --git a/lib/wsfs/provider/operation/open.c b/lib/wsfs/provider/operation/open.c index a9670e7..9602c71 100644 --- a/lib/wsfs/provider/operation/open.c +++ b/lib/wsfs/provider/operation/open.c @@ -33,7 +33,7 @@ void wsfsp_open_default( int WSFS_UNUSED_PARAM(flags), void * WSFS_UNUSED_PARAM(user_data)) { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } void wsfsp_respond_open( diff --git a/lib/wsfs/provider/operation/read.c b/lib/wsfs/provider/operation/read.c index c7e4fec..c738761 100644 --- a/lib/wsfs/provider/operation/read.c +++ b/lib/wsfs/provider/operation/read.c @@ -43,7 +43,7 @@ void wsfsp_read_default( size_t WSFS_UNUSED_PARAM(length), void * WSFS_UNUSED_PARAM(user_data)) { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } void wsfsp_respond_read( @@ -69,7 +69,7 @@ void wsfsp_respond_read( } else { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD); } } else diff --git a/lib/wsfs/provider/operation/readdir.c b/lib/wsfs/provider/operation/readdir.c index 87284d8..f94c0f3 100644 --- a/lib/wsfs/provider/operation/readdir.c +++ b/lib/wsfs/provider/operation/readdir.c @@ -29,7 +29,7 @@ void wsfsp_readdir_default( ino_t WSFS_UNUSED_PARAM(directory), void * WSFS_UNUSED_PARAM(user_data)) { - wsfsp_respond_error(request, -1); + wsfsp_respond_error(request, WSFS_BAD_NOENTRY); } void wsfsp_respond_readdir( diff --git a/lib/wsfs/provider/request.c b/lib/wsfs/provider/request.c index e5e8d5b..4f6d90f 100644 --- a/lib/wsfs/provider/request.c +++ b/lib/wsfs/provider/request.c @@ -40,7 +40,7 @@ extern void wsfsp_respond( void wsfsp_respond_error( struct wsfsp_request * request, - int status) + wsfs_status status) { json_t * response = json_object(); json_t * error = json_object(); From d205d2f127ec1ede08da03d577976dcf97b0a501 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 4 Mar 2019 21:17:37 +0100 Subject: [PATCH 08/10] refactors provider client api (introduces client_config) --- CMakeLists.txt | 1 + example/provider/main.c | 173 +++++++++++++++---- include/wsfs/provider/client.h | 13 +- include/wsfs/provider/provider.h | 34 ---- include/wsfs_provider.h | 2 +- lib/wsfs/provider/client.c | 25 ++- lib/wsfs/provider/client_protocol.c | 19 +- lib/wsfs/provider/operation/close_intern.h | 2 +- lib/wsfs/provider/operation/getattr_intern.h | 2 +- lib/wsfs/provider/operation/lookup_intern.h | 2 +- lib/wsfs/provider/operation/open_intern.h | 2 +- lib/wsfs/provider/operation/read_intern.h | 2 +- lib/wsfs/provider/operation/readdir_intern.h | 2 +- lib/wsfs/provider/provider.c | 31 +++- lib/wsfs/provider/provider_intern.h | 38 ---- 15 files changed, 198 insertions(+), 150 deletions(-) delete mode 100644 include/wsfs/provider/provider.h delete mode 100644 lib/wsfs/provider/provider_intern.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 36637ed..c017d3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,7 @@ install(FILES "${PROJECT_BINARY_DIR}/libwsfs-adapter.pc" DESTINATION lib${LIB_SU 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 diff --git a/example/provider/main.c b/example/provider/main.c index dcdfecd..07c62fb 100644 --- a/example/provider/main.c +++ b/example/provider/main.c @@ -6,9 +6,18 @@ #include #include +#include +#include #include "wsfs_provider.h" +struct config +{ + char * url; + struct wsfsp_client_config * client_config; + bool show_help; +}; + enum fs_entry_type { FS_FILE, @@ -31,6 +40,88 @@ struct fs struct fs_entry const * entries; }; +static void show_help() +{ + printf( + "wsfs-provider, Copyright (c) 2019 fuse-wsfs authors \n" + "Example for websocket file system provider\n" + "\n" + "Usage: wsfs-provider -u [-k ] [-c ]\n" + "\n" + "Options:\n" + "\t-u, --url URL of WSFS server (required)\n" + "\t-k, --key_path Path to private key of provider (default: not set, TLS disabled)\n" + "\t-c, --cert_path Path to certificate of provider (defautl: not set, TLS disabled)\n" + "\t-h, --help prints this message\n" + "\n" + "Example:\n" + "\twsfs-provider -u ws://localhost:8080/\n" + "\n" + ); +} + +static int parse_arguments( + int argc, + char* argv[], + struct config * config) +{ + static struct option const options[] = + { + {"url", required_argument, NULL, 'u'}, + {"key_path", required_argument, NULL, 'k'}, + {"cert_path", required_argument, NULL, 'c'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + + int result = EXIT_SUCCESS; + bool finished = false; + while (!finished) + { + int option_index = 0; + int const c = getopt_long(argc, argv, "u:k:c:h", options, &option_index); + + switch (c) + { + case -1: + finished = true; + break; + case 'h': + config->show_help = true; + finished = true; + break; + case 'u': + free(config->url); + config->url = strdup(optarg); + break; + case 'k': + wsfsp_client_config_set_keypath(config->client_config, optarg); + break; + case 'c': + wsfsp_client_config_set_certpath(config->client_config, optarg); + break; + default: + fprintf(stderr, "error: unknown argument\n"); + finished = true; + result = EXIT_FAILURE; + break; + } + + if (NULL == config->url) + { + fprintf(stderr, "error: missing required argument \"-u\"\n"); + result = EXIT_FAILURE; + } + + if (result != EXIT_SUCCESS) + { + config->show_help = true; + } + } + + return result; +} + static struct fs_entry const * fs_getentry( struct fs * fs, ino_t inode) @@ -223,15 +314,6 @@ static void fs_read( } } -static struct wsfsp_provider fs_provider = -{ - .lookup = &fs_lookup, - .getattr = &fs_getattr, - .readdir = &fs_readdir, - .open = &fs_open, - .read = &fs_read -}; - static struct wsfsp_client * client; static void on_interrupt(int signal_id) @@ -243,36 +325,57 @@ static void on_interrupt(int signal_id) int main(int argc, char* argv[]) { - (void) argc; - (void) argv; + struct config config; + config.url = NULL; + config.show_help = false; + config.client_config = wsfsp_client_config_create(); + int result = parse_arguments(argc, argv, &config); - static struct fs_entry const entries[]= + if (EXIT_SUCCESS == result) { - {.parent = 0, .inode = 1, .name = "", .mode = 0555, .type = FS_DIR}, + static struct fs_entry const entries[]= { - .parent = 1, - .inode = 2, - .name = "hello.txt", - .mode = 0555, - .type = FS_FILE, - .content="hello, world!", - .content_length = 13, - }, - {.parent = 0, .inode = 0, .name = NULL} - }; + {.parent = 0, .inode = 1, .name = "", .mode = 0555, .type = FS_DIR}, + { + .parent = 1, + .inode = 2, + .name = "hello.txt", + .mode = 0555, + .type = FS_FILE, + .content="hello, world!", + .content_length = 13, + }, + {.parent = 0, .inode = 0, .name = NULL} + }; - struct fs fs = + struct fs fs = + { + .entries = entries + }; + + signal(SIGINT, &on_interrupt); + + wsfsp_client_config_set_userdata(config.client_config, &fs); + wsfsp_client_config_set_onlookup(config.client_config, &fs_lookup); + wsfsp_client_config_set_ongetattr(config.client_config, &fs_getattr); + wsfsp_client_config_set_onreaddir(config.client_config, &fs_readdir); + wsfsp_client_config_set_onopen(config.client_config, &fs_open); + wsfsp_client_config_set_onread(config.client_config, &fs_read); + + client = wsfsp_client_create(config.client_config); + wsfsp_client_connect(client, config.url); + + wsfsp_client_run(client); + + wsfsp_client_dispose(client); + } + + if (config.show_help) { - .entries = entries - }; + show_help(); + } - signal(SIGINT, &on_interrupt); - - client = wsfsp_client_create(&fs_provider, &fs); - wsfsp_client_connect(client, "ws://localhost:8080/"); - - wsfsp_client_run(client); - - wsfsp_client_dispose(client); - return EXIT_SUCCESS; + free(config.url); + wsfsp_client_config_dispose(config.client_config); + return result; } \ No newline at end of file diff --git a/include/wsfs/provider/client.h b/include/wsfs/provider/client.h index 570679d..d62a855 100644 --- a/include/wsfs/provider/client.h +++ b/include/wsfs/provider/client.h @@ -3,8 +3,8 @@ #include "wsfs/provider/api.h" -struct wsfsp_provider; struct wsfsp_client; +struct wsfsp_client_config; #ifdef __cplusplus extern "C" @@ -12,8 +12,15 @@ extern "C" #endif extern WSFSP_API struct wsfsp_client * wsfsp_client_create( - struct wsfsp_provider * provider, - void * user_data); + 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, diff --git a/include/wsfs/provider/provider.h b/include/wsfs/provider/provider.h deleted file mode 100644 index 25d624d..0000000 --- a/include/wsfs/provider/provider.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef WSFS_PROVIDER_PROVIDER_H -#define WSFS_PROVIDER_PROVIDER_H - -#include -#include -#include -#include -#include -#include - -typedef void wsfsp_connected_fn( - void * user_data); - -typedef void wsfsp_disconnected_fn( -void * user_data); - -typedef void wsfsp_ontimer_fn( - void * user_data); - -struct wsfsp_provider -{ - wsfsp_connected_fn * connected; - wsfsp_disconnected_fn * disconnected; - wsfsp_ontimer_fn * ontimer; - wsfsp_lookup_fn * lookup; - wsfsp_getattr_fn * getattr; - wsfsp_readdir_fn * readdir; - wsfsp_open_fn * open; - wsfsp_close_fn * close; - wsfsp_read_fn * read; -}; - - -#endif diff --git a/include/wsfs_provider.h b/include/wsfs_provider.h index 9c033ec..63e09fc 100644 --- a/include/wsfs_provider.h +++ b/include/wsfs_provider.h @@ -5,8 +5,8 @@ #include #include +#include #include -#include #include #include diff --git a/lib/wsfs/provider/client.c b/lib/wsfs/provider/client.c index 7d0676c..886880c 100644 --- a/lib/wsfs/provider/client.c +++ b/lib/wsfs/provider/client.c @@ -8,6 +8,7 @@ #include "wsfs/provider/provider.h" #include "wsfs/provider/client_protocol_intern.h" +#include "wsfs/provider/client_config_intern.h" #include "wsfs/provider/url.h" #define WSFSP_PROTOCOL ("fs") @@ -18,17 +19,17 @@ struct wsfsp_client { volatile bool is_running; - struct wsfsp_provider provider; struct wsfsp_client_protocol protocol; struct lws_context_creation_info info; struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT]; struct lws_context * context; + char * key_path; + char * cert_path; }; struct wsfsp_client * wsfsp_client_create( - struct wsfsp_provider * provider, - void * user_data) + struct wsfsp_client_config * config) { lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL); @@ -36,7 +37,7 @@ struct wsfsp_client * wsfsp_client_create( if (NULL != client) { client->is_running = true; - wsfsp_client_protocol_init(&client->protocol, provider, user_data); + wsfsp_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"; @@ -48,6 +49,11 @@ struct wsfsp_client * wsfsp_client_create( client->info.uid = -1; client->info.gid = -1; + if ((NULL != config->cert_path) && (NULL != config->key_path)) + { + + } + client->context = lws_create_context(&client->info); } @@ -96,17 +102,6 @@ void wsfsp_client_disconnect( // ToDo: implement me } -void wsfsp_client_settimeout( - struct wsfsp_client * client, - unsigned int timepoint) -{ - (void) client; - (void) timepoint; - - // ToDo: implement me -} - - void wsfsp_client_run( struct wsfsp_client * client) { diff --git a/lib/wsfs/provider/client_protocol.c b/lib/wsfs/provider/client_protocol.c index 21685fa..f3c026e 100644 --- a/lib/wsfs/provider/client_protocol.c +++ b/lib/wsfs/provider/client_protocol.c @@ -7,14 +7,7 @@ #include -#include "wsfs/provider/provider_intern.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" - +#include "wsfs/provider/provider.h" #include "wsfs/util.h" #include "wsfs/message.h" @@ -117,15 +110,7 @@ void wsfsp_client_protocol_init( 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; - protocol->provider.readdir = (NULL != provider->readdir) ? provider->readdir : &wsfsp_readdir_default; - protocol->provider.open = (NULL != provider->open) ? provider->open : &wsfsp_open_default; - protocol->provider.close = (NULL != provider->close) ? provider->close : &wsfsp_close_default; - protocol->provider.read = (NULL != provider->read) ? provider->read : &wsfsp_read_default; - protocol->provider.connected = (NULL != provider->connected) ? provider->connected : &wsfsp_connected_default; - protocol->provider.disconnected = (NULL != provider->disconnected) ? provider->disconnected : &wsfsp_disconnected_default; - protocol->provider.ontimer = (NULL != provider->ontimer) ? provider->ontimer : &wsfsp_ontimer_default; + wsfsp_provider_init_from_prototype(&protocol->provider, provider); } void wsfsp_client_protocol_cleanup( diff --git a/lib/wsfs/provider/operation/close_intern.h b/lib/wsfs/provider/operation/close_intern.h index abb7968..ecc55e2 100644 --- a/lib/wsfs/provider/operation/close_intern.h +++ b/lib/wsfs/provider/operation/close_intern.h @@ -2,7 +2,7 @@ #define WSFS_PROVIDER_OPERATION_CLOSE_INTERN_H #include "wsfs/provider/operation/close.h" -#include "wsfs/provider/provider_intern.h" +#include "wsfs/provider/provider.h" #ifdef __cplusplus extern "C" diff --git a/lib/wsfs/provider/operation/getattr_intern.h b/lib/wsfs/provider/operation/getattr_intern.h index 784e013..2a92dc4 100644 --- a/lib/wsfs/provider/operation/getattr_intern.h +++ b/lib/wsfs/provider/operation/getattr_intern.h @@ -2,7 +2,7 @@ #define WSFS_PROVIDER_OPERATION_GETATTR_INTERN_H #include "wsfs/provider/operation/getattr.h" -#include "wsfs/provider/provider_intern.h" +#include "wsfs/provider/provider.h" #ifdef __cplusplus extern "C" diff --git a/lib/wsfs/provider/operation/lookup_intern.h b/lib/wsfs/provider/operation/lookup_intern.h index 061610b..86bccec 100644 --- a/lib/wsfs/provider/operation/lookup_intern.h +++ b/lib/wsfs/provider/operation/lookup_intern.h @@ -2,7 +2,7 @@ #define WSFS_PROVIDER_OPERATION_LOOKUP_INTERN_H #include "wsfs/provider/operation/lookup.h" -#include "wsfs/provider/provider_intern.h" +#include "wsfs/provider/provider.h" #ifdef __cplusplus extern "C" diff --git a/lib/wsfs/provider/operation/open_intern.h b/lib/wsfs/provider/operation/open_intern.h index bd03d3f..753ee46 100644 --- a/lib/wsfs/provider/operation/open_intern.h +++ b/lib/wsfs/provider/operation/open_intern.h @@ -2,7 +2,7 @@ #define WSFS_PROVIDER_OPERATION_OPEN_INTERN_H #include "wsfs/provider/operation/open.h" -#include "wsfs/provider/provider_intern.h" +#include "wsfs/provider/provider.h" #ifdef __cplusplus extern "C" diff --git a/lib/wsfs/provider/operation/read_intern.h b/lib/wsfs/provider/operation/read_intern.h index d8adcab..793572d 100644 --- a/lib/wsfs/provider/operation/read_intern.h +++ b/lib/wsfs/provider/operation/read_intern.h @@ -2,7 +2,7 @@ #define WSFS_PROVIDER_OPERATION_READ_INTERN_H #include "wsfs/provider/operation/read.h" -#include "wsfs/provider/provider_intern.h" +#include "wsfs/provider/provider.h" #ifdef __cplusplus extern "C" diff --git a/lib/wsfs/provider/operation/readdir_intern.h b/lib/wsfs/provider/operation/readdir_intern.h index 8266aa9..b8cc225 100644 --- a/lib/wsfs/provider/operation/readdir_intern.h +++ b/lib/wsfs/provider/operation/readdir_intern.h @@ -2,7 +2,7 @@ #define WSFS_PROVIDER_OPERATION_READDIR_INTERN_H #include "wsfs/provider/operation/readdir.h" -#include "wsfs/provider/provider_intern.h" +#include "wsfs/provider/provider.h" #ifdef __cplusplus extern "C" diff --git a/lib/wsfs/provider/provider.c b/lib/wsfs/provider/provider.c index f64dabd..5cb548a 100644 --- a/lib/wsfs/provider/provider.c +++ b/lib/wsfs/provider/provider.c @@ -1,4 +1,4 @@ -#include "wsfs/provider/provider_intern.h" +#include "wsfs/provider/provider.h" #include #include @@ -55,6 +55,35 @@ static void wsfsp_provider_invoke_method( } } +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) diff --git a/lib/wsfs/provider/provider_intern.h b/lib/wsfs/provider/provider_intern.h deleted file mode 100644 index 11c5ef0..0000000 --- a/lib/wsfs/provider/provider_intern.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef WSFS_PROVIDER_PROVIDER_INTERN_H -#define WSFS_PROVIDER_PROVIDER_INTERN_H - -#include "wsfs/provider/provider.h" -#include "wsfs/provider/request.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); - -extern void wsfsp_connected_default( - void * user_data); - -extern void wsfsp_disconnected_default( - void * user_data); - -extern void wsfsp_ontimer_default( - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file From 76713554eedd947eed5ed38fb94f499ca67e22df Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 4 Mar 2019 21:18:16 +0100 Subject: [PATCH 09/10] fixes missing files --- include/wsfs/provider/client_config.h | 88 ++++++++++++++++++ include/wsfs/status.h | 17 ++++ lib/wsfs/provider/client_config.c | 112 +++++++++++++++++++++++ lib/wsfs/provider/client_config_intern.h | 24 +++++ lib/wsfs/provider/provider.h | 65 +++++++++++++ lib/wsfs/status.c | 34 +++++++ lib/wsfs/status_intern.h | 19 ++++ 7 files changed, 359 insertions(+) create mode 100644 include/wsfs/provider/client_config.h create mode 100644 include/wsfs/status.h create mode 100644 lib/wsfs/provider/client_config.c create mode 100644 lib/wsfs/provider/client_config_intern.h create mode 100644 lib/wsfs/provider/provider.h create mode 100644 lib/wsfs/status.c create mode 100644 lib/wsfs/status_intern.h diff --git a/include/wsfs/provider/client_config.h b/include/wsfs/provider/client_config.h new file mode 100644 index 0000000..875c8dd --- /dev/null +++ b/include/wsfs/provider/client_config.h @@ -0,0 +1,88 @@ +#ifndef WSFS_PROVIDER_CLIENT_CONFIG_H +#define WSFS_PROVIDER_CLIENT_CONFIG_H + +#include + +#include +#include +#include +#include +#include +#include + +struct wsfsp_client_config; + +typedef void wsfsp_connected_fn( + void * user_data); + +typedef void wsfsp_disconnected_fn( +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( + struct wsfsp_client_config * config); + +extern WSFSP_API void wsfsp_client_config_set_userdata( + struct wsfsp_client_config * config, + void * user_data); + +extern WSFSP_API void wsfsp_client_config_set_keypath( + struct wsfsp_client_config * config, + char const * key_path); + +extern WSFSP_API void wsfsp_client_config_set_certpath( + struct wsfsp_client_config * config, + char const * cert_path); + +extern WSFSP_API void wsfsp_client_config_set_onconnected( + struct wsfsp_client_config * config, + wsfsp_connected_fn * handler); + +extern WSFSP_API void wsfsp_client_config_set_ondisconnected( + struct wsfsp_client_config * config, + wsfsp_disconnected_fn * handler); + +extern WSFSP_API void wsfsp_client_config_set_ontimer( + struct wsfsp_client_config * config, + wsfsp_ontimer_fn * handler); + + +extern WSFSP_API void wsfsp_client_config_set_onlookup( + struct wsfsp_client_config * config, + wsfsp_lookup_fn * handler); + +extern WSFSP_API void wsfsp_client_config_set_ongetattr( + struct wsfsp_client_config * config, + wsfsp_getattr_fn * handler); + +extern WSFSP_API void wsfsp_client_config_set_onreaddir( + struct wsfsp_client_config * config, + wsfsp_readdir_fn * handler); + +extern WSFSP_API void wsfsp_client_config_set_onopen( + struct wsfsp_client_config * config, + wsfsp_open_fn * handler); + +extern WSFSP_API void wsfsp_client_config_set_onclose( + struct wsfsp_client_config * config, + wsfsp_close_fn * handler); + +extern WSFSP_API void wsfsp_client_config_set_onread( + struct wsfsp_client_config * config, + wsfsp_read_fn * handler); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/wsfs/status.h b/include/wsfs/status.h new file mode 100644 index 0000000..7740f7f --- /dev/null +++ b/include/wsfs/status.h @@ -0,0 +1,17 @@ +#ifndef WSFS_STATUS_H +#define WSFS_STATUS_H + +#define WSFS_GOOD 0 +#define WSFS_BAD 1 + +#define WSFS_BAD_NOTIMPLEMENTED 2 +#define WSFS_BAD_TIMEOUT 3 +#define WSFS_BAD_BUSY 4 +#define WSFS_BAD_FORMAT 5 + +#define WSFS_BAD_NOENTRY 101 +#define WSFS_BAD_NOACCESS 102 + +typedef int wsfs_status; + +#endif diff --git a/lib/wsfs/provider/client_config.c b/lib/wsfs/provider/client_config.c new file mode 100644 index 0000000..3eb53b2 --- /dev/null +++ b/lib/wsfs/provider/client_config.c @@ -0,0 +1,112 @@ +#include "wsfs/provider/client_config_intern.h" +#include "wsfs/provider/provider.h" +#include +#include + +struct wsfsp_client_config * wsfsp_client_config_create(void) +{ + struct wsfsp_client_config * config = malloc(sizeof(struct wsfsp_client_config)); + if (NULL != config) + { + wsfsp_provider_init(&config->provider); + config->user_data = NULL; + config->key_path = NULL; + config->cert_path = NULL; + } + + return config; +} + +void wsfsp_client_config_dispose( + struct wsfsp_client_config * config) +{ + free(config->key_path); + free(config->cert_path); + free(config); +} + +void wsfsp_client_config_set_userdata( + struct wsfsp_client_config * config, + void * user_data) +{ + config->user_data = user_data; +} + +void wsfsp_client_config_set_keypath( + struct wsfsp_client_config * config, + char const * key_path) +{ + free(config->key_path); + config->key_path = strdup(key_path); +} + +void wsfsp_client_config_set_certpath( + struct wsfsp_client_config * config, + char const * cert_path) +{ + free(config->cert_path); + config->cert_path = strdup(cert_path); +} + +void wsfsp_client_config_set_onconnected( + struct wsfsp_client_config * config, + wsfsp_connected_fn * handler) +{ + config->provider.connected = handler; +} + +void wsfsp_client_config_set_ondisconnected( + struct wsfsp_client_config * config, + wsfsp_disconnected_fn * handler) +{ + config->provider.disconnected = handler; +} + +void wsfsp_client_config_set_ontimer( + struct wsfsp_client_config * config, + wsfsp_ontimer_fn * handler) +{ + config->provider.ontimer = handler; +} + +void wsfsp_client_config_set_onlookup( + struct wsfsp_client_config * config, + wsfsp_lookup_fn * handler) +{ + config->provider.lookup = handler; +} + +void wsfsp_client_config_set_ongetattr( + struct wsfsp_client_config * config, + wsfsp_getattr_fn * handler) +{ + config->provider.getattr = handler; +} + +void wsfsp_client_config_set_onreaddir( + struct wsfsp_client_config * config, + wsfsp_readdir_fn * handler) +{ + config->provider.readdir = handler; +} + +void wsfsp_client_config_set_onopen( + struct wsfsp_client_config * config, + wsfsp_open_fn * handler) +{ + config->provider.open = handler; +} + +void wsfsp_client_config_set_onclose( + struct wsfsp_client_config * config, + wsfsp_close_fn * handler) +{ + config->provider.close = handler; +} + +void wsfsp_client_config_set_onread( + struct wsfsp_client_config * config, + wsfsp_read_fn * handler) +{ + config->provider.read = handler; +} diff --git a/lib/wsfs/provider/client_config_intern.h b/lib/wsfs/provider/client_config_intern.h new file mode 100644 index 0000000..087e5de --- /dev/null +++ b/lib/wsfs/provider/client_config_intern.h @@ -0,0 +1,24 @@ +#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 diff --git a/lib/wsfs/provider/provider.h b/lib/wsfs/provider/provider.h new file mode 100644 index 0000000..e3594f6 --- /dev/null +++ b/lib/wsfs/provider/provider.h @@ -0,0 +1,65 @@ +#ifndef WSFS_PROVIDER_PROVIDER_H +#define WSFS_PROVIDER_PROVIDER_H + +#include "wsfs/provider/client_config.h" +#include "wsfs/provider/request.h" +#include +#include +#include +#include +#include +#include + +#include + +struct wsfsp_provider +{ + wsfsp_connected_fn * connected; + wsfsp_disconnected_fn * disconnected; + wsfsp_ontimer_fn * ontimer; + wsfsp_lookup_fn * lookup; + wsfsp_getattr_fn * getattr; + wsfsp_readdir_fn * readdir; + wsfsp_open_fn * open; + wsfsp_close_fn * close; + wsfsp_read_fn * read; +}; + +struct wsfsp_invokation_context +{ + struct wsfsp_provider * provider; + void * user_data; + struct wsfsp_request * request; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wsfsp_provider_init( + struct wsfsp_provider * provider); + +extern void wsfsp_provider_init_from_prototype( + struct wsfsp_provider * provider, + struct wsfsp_provider const * prototype); + + +extern void wsfsp_provider_invoke( + struct wsfsp_invokation_context * context, + json_t * request); + +extern void wsfsp_connected_default( + void * user_data); + +extern void wsfsp_disconnected_default( + void * user_data); + +extern void wsfsp_ontimer_default( + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/lib/wsfs/status.c b/lib/wsfs/status.c new file mode 100644 index 0000000..f2db1b2 --- /dev/null +++ b/lib/wsfs/status.c @@ -0,0 +1,34 @@ +#include "wsfs/status_intern.h" + +#include + + int wsfs_status_to_rc(wsfs_status status) +{ + switch(status) + { + case WSFS_GOOD: return 0; + case WSFS_BAD_NOTIMPLEMENTED: return -ENOSYS; + case WSFS_BAD_TIMEOUT: return -ETIMEDOUT; + case WSFS_BAD_BUSY: return -ENOENT; + case WSFS_BAD_FORMAT: return -ENOENT; + case WSFS_BAD_NOENTRY: return -ENOENT; + case WSFS_BAD_NOACCESS: return -EACCES; + default: return -ENOENT; + } +} + +char const * wsfs_status_tostring(wsfs_status status) +{ + switch(status) + { + case WSFS_GOOD: return "Good"; + case WSFS_BAD: return "Bad"; + case WSFS_BAD_NOTIMPLEMENTED: return "Bad (not implelemted)"; + case WSFS_BAD_TIMEOUT: return "Bad (timeout)"; + case WSFS_BAD_BUSY: return "Bad (busy)"; + case WSFS_BAD_FORMAT: return "Bad (format)"; + case WSFS_BAD_NOENTRY: return "Bad (no entry)"; + case WSFS_BAD_NOACCESS: return "Bad (no access)"; + default: return "Bad (unknown)"; + } +} diff --git a/lib/wsfs/status_intern.h b/lib/wsfs/status_intern.h new file mode 100644 index 0000000..a5f1880 --- /dev/null +++ b/lib/wsfs/status_intern.h @@ -0,0 +1,19 @@ +#ifndef WSFS_STATUS_INTERN_H +#define WSFS_STATUS_INTERN_H + +#include "wsfs/status.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern int wsfs_status_to_rc(wsfs_status status); + +extern char const * wsfs_status_tostring(wsfs_status status); + +#ifdef __cplusplus +} +#endif + +#endif + From c4ef4f126b6dad3e7fd3ac3017b2cc05e192aa34 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 4 Mar 2019 21:42:45 +0100 Subject: [PATCH 10/10] fixes flawfinder findings (ignores them) --- lib/wsfs/provider/operation/open.c | 2 +- lib/wsfs/provider/operation/read.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wsfs/provider/operation/open.c b/lib/wsfs/provider/operation/open.c index 9602c71..9196ded 100644 --- a/lib/wsfs/provider/operation/open.c +++ b/lib/wsfs/provider/operation/open.c @@ -22,7 +22,7 @@ void wsfsp_open( struct wsfsp_request * request = wsfsp_request_create(context->request, id); - context->provider->open(request, inode, flags, context->user_data); + context->provider->open(request, inode, flags, context->user_data); /* Flawfinder: ignore */ } } } diff --git a/lib/wsfs/provider/operation/read.c b/lib/wsfs/provider/operation/read.c index c738761..ff03702 100644 --- a/lib/wsfs/provider/operation/read.c +++ b/lib/wsfs/provider/operation/read.c @@ -30,7 +30,7 @@ void wsfsp_read( size_t length = json_integer_value(length_holder); struct wsfsp_request * request = wsfsp_request_create(context->request, id); - context->provider->read(request, inode, handle, offset, length, context->user_data); + context->provider->read(request, inode, handle, offset, length, context->user_data); /* Flawfinder: ignore */ } } }