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

Merge pull request #9 from falk-werner/feature-provider

integrates provider
This commit is contained in:
Falk Werner 2019-03-05 15:35:04 +01:00 committed by GitHub
commit 7934319d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 664 additions and 248 deletions

View File

@ -46,12 +46,14 @@ set(EXTRA_CFLAGS
set(WSFS_COMMON_SOURCES set(WSFS_COMMON_SOURCES
lib/wsfs/message.c lib/wsfs/message.c
lib/wsfs/message_queue.c lib/wsfs/message_queue.c
lib/wsfs/status.c
) )
install(FILES include/wsfs/status.h DESTINATION include/wsfs)
# libwsfs-adapter # libwsfs-adapter
set(WSFS_ADAPTER_SOURCES set(WSFS_ADAPTER_SOURCES
lib/wsfs/adapter/status.c
lib/wsfs/adapter/filesystem.c lib/wsfs/adapter/filesystem.c
lib/wsfs/adapter/server.c lib/wsfs/adapter/server.c
lib/wsfs/adapter/time/timepoint.c lib/wsfs/adapter/time/timepoint.c
@ -106,6 +108,7 @@ install(FILES "${PROJECT_BINARY_DIR}/libwsfs-adapter.pc" DESTINATION lib${LIB_SU
set(WSFS_PROVIDER_SOURCES set(WSFS_PROVIDER_SOURCES
lib/wsfs/provider/url.c lib/wsfs/provider/url.c
lib/wsfs/provider/client.c lib/wsfs/provider/client.c
lib/wsfs/provider/client_config.c
lib/wsfs/provider/client_protocol.c lib/wsfs/provider/client_protocol.c
lib/wsfs/provider/provider.c lib/wsfs/provider/provider.c
lib/wsfs/provider/request.c lib/wsfs/provider/request.c

View File

@ -4,8 +4,20 @@
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include "wsfs_provider.h" #include "wsfs_provider.h"
struct config
{
char * url;
struct wsfsp_client_config * client_config;
bool show_help;
};
enum fs_entry_type enum fs_entry_type
{ {
FS_FILE, FS_FILE,
@ -23,28 +35,93 @@ struct fs_entry
char const * content; 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
{ {
struct fs_entry const * entries; struct fs_entry const * entries;
}; };
static void show_help()
{
printf(
"wsfs-provider, Copyright (c) 2019 fuse-wsfs authors <https://github.com/falk-werner/fuse-wsfs>\n"
"Example for websocket file system provider\n"
"\n"
"Usage: wsfs-provider -u <url> [-k <key_path>] [-c <cert_path>]\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( static struct fs_entry const * fs_getentry(
struct fs * fs, struct fs * fs,
ino_t inode) ino_t inode)
@ -116,7 +193,7 @@ static void fs_lookup(
} }
else else
{ {
wsfsp_respond_error(request, -1); wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
} }
} }
@ -138,7 +215,7 @@ static void fs_getattr(
} }
else else
{ {
wsfsp_respond_error(request, -1); wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
} }
} }
@ -170,7 +247,7 @@ static void fs_readdir(
} }
else else
{ {
wsfsp_respond_error(request, -1); wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
} }
} }
@ -180,12 +257,29 @@ static void fs_open(
int flags, int flags,
void * user_data) void * user_data)
{ {
(void) inode; struct fs * fs = (struct fs*) user_data;
(void) flags;
(void) user_data;
puts("open"); struct fs_entry const * entry = fs_getentry(fs, inode);
wsfsp_respond_error(request, -1); if ((NULL != entry) && (FS_FILE == entry->type))
{
if (O_RDONLY == (flags & O_ACCMODE))
{
wsfsp_respond_open(request, 0U);
}
else
{
wsfsp_respond_error(request, WSFS_BAD_NOACCESS);
}
}
else
{
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
}
}
static size_t min(size_t const a, size_t const b)
{
return (a < b) ? a : b;
} }
static void fs_read( static void fs_read(
@ -196,24 +290,30 @@ static void fs_read(
size_t length, size_t length,
void * user_data) void * user_data)
{ {
(void) inode;
(void) handle; (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, WSFS_BAD);
}
}
else
{
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
}
} }
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 struct wsfsp_client * client;
static void on_interrupt(int signal_id) static void on_interrupt(int signal_id)
@ -225,36 +325,57 @@ static void on_interrupt(int signal_id)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
(void) argc; struct config config;
(void) argv; 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 = "<root>", .mode = 0555, .type = FS_DIR}, static struct fs_entry const entries[]=
{ {
.parent = 1, {.parent = 0, .inode = 1, .name = "<root>", .mode = 0555, .type = FS_DIR},
.inode = 2, {
.name = "hello.txt", .parent = 1,
.mode = 0555, .inode = 2,
.type = FS_FILE, .name = "hello.txt",
.content="hello, world!", .mode = 0555,
.content_length = 13, .type = FS_FILE,
}, .content="hello, world!",
{.parent = 0, .inode = 0, .name = NULL} .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); free(config.url);
wsfsp_client_config_dispose(config.client_config);
client = wsfsp_client_create(&fs_provider, &fs); return result;
wsfsp_client_connect(client, "ws://localhost:8080/");
wsfsp_client_run(client);
wsfsp_client_dispose(client);
return EXIT_SUCCESS;
} }

View File

@ -3,8 +3,8 @@
#include "wsfs/provider/api.h" #include "wsfs/provider/api.h"
struct wsfsp_provider;
struct wsfsp_client; struct wsfsp_client;
struct wsfsp_client_config;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -12,8 +12,15 @@ extern "C"
#endif #endif
extern WSFSP_API struct wsfsp_client * wsfsp_client_create( extern WSFSP_API struct wsfsp_client * wsfsp_client_create(
struct wsfsp_provider * provider, struct wsfsp_client_config * config);
void * user_data);
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( extern WSFSP_API void wsfsp_client_connect(
struct wsfsp_client * client, struct wsfsp_client * client,

View File

@ -0,0 +1,88 @@
#ifndef WSFS_PROVIDER_CLIENT_CONFIG_H
#define WSFS_PROVIDER_CLIENT_CONFIG_H
#include <wsfs/provider/api.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>
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

View File

@ -2,6 +2,7 @@
#define WSFSP_OPERATION_ERROR_H #define WSFSP_OPERATION_ERROR_H
#include "wsfs/provider/api.h" #include "wsfs/provider/api.h"
#include "wsfs/status.h"
struct wsfsp_request; struct wsfsp_request;
@ -12,7 +13,7 @@ extern "C"
extern WSFSP_API void wsfsp_respond_error( extern WSFSP_API void wsfsp_respond_error(
struct wsfsp_request * request, struct wsfsp_request * request,
int status); wsfs_status status);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,34 +0,0 @@
#ifndef WSFS_PROVIDER_PROVIDER_H
#define WSFS_PROVIDER_PROVIDER_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>
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

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_STATUS_H #ifndef WSFS_STATUS_H
#define WSFS_ADAPTER_STATUS_H #define WSFS_STATUS_H
#define WSFS_GOOD 0 #define WSFS_GOOD 0
#define WSFS_BAD 1 #define WSFS_BAD 1
@ -14,17 +14,4 @@
typedef int wsfs_status; typedef int wsfs_status;
#ifdef __cplusplus
extern "C" {
#endif #endif
extern int wsfs_status_to_rc(wsfs_status status);
extern char const * wsfs_status_tostring(wsfs_status status);
#ifdef __cplusplus
}
#endif
#endif

View File

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

View File

@ -1,10 +1,12 @@
#ifndef WSFS_PROVIDER_H #ifndef WSFS_PROVIDER_H
#define WSFS_PROVIDER_H #define WSFS_PROVIDER_H
#include <wsfs/status.h>
#include <wsfs/provider/api.h> #include <wsfs/provider/api.h>
#include <wsfs/provider/client.h> #include <wsfs/provider/client.h>
#include <wsfs/provider/client_config.h>
#include <wsfs/provider/client_protocol.h> #include <wsfs/provider/client_protocol.h>
#include <wsfs/provider/provider.h>
#include <wsfs/provider/dirbuffer.h> #include <wsfs/provider/dirbuffer.h>
#include <wsfs/provider/operation/error.h> #include <wsfs/provider/operation/error.h>

View File

@ -6,7 +6,7 @@
#endif #endif
#include <jansson.h> #include <jansson.h>
#include "wsfs/adapter/status.h" #include "wsfs/status.h"
typedef bool wsfs_jsonrpc_method_invoke_fn( typedef bool wsfs_jsonrpc_method_invoke_fn(

View File

@ -9,7 +9,7 @@ using std::size_t;
#endif #endif
#include <jansson.h> #include <jansson.h>
#include "wsfs/adapter/status.h" #include "wsfs/status.h"
struct wsfs_jsonrpc_response struct wsfs_jsonrpc_response
{ {

View File

@ -6,7 +6,7 @@
#include "wsfs/adapter/jsonrpc/server.h" #include "wsfs/adapter/jsonrpc/server.h"
#include "wsfs/util.h" #include "wsfs/util.h"
#include "wsfs/adapter/status.h" #include "wsfs/status.h"
static void wsfs_operation_open_finished( static void wsfs_operation_open_finished(
void * user_data, void * user_data,

View File

@ -10,32 +10,32 @@
#define WSFS_MAX_READ_LENGTH 4096 #define WSFS_MAX_READ_LENGTH 4096
static wsfs_status wsfs_fill_buffer( static char * wsfs_fill_buffer(
char * * buffer,
char const * format,
char const * data, 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)) if (0 == strcmp("identity", format))
{ {
memcpy(*buffer, data, count); /* Flawfinder: ignore */ memcpy(buffer, data, count); /* Flawfinder: ignore */
} }
else if (0 == strcmp("base64", format)) else if (0 == strcmp("base64", format))
{ {
lws_b64_decode_string(data, *buffer, count); lws_b64_decode_string(data, buffer, count + 1);
} }
else 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) 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 * format_holder = json_object_get(data, "format");
json_t * count_holder = json_object_get(data, "count"); json_t * count_holder = json_object_get(data, "count");
if ((NULL != data_holder) && (json_is_string(data_holder)) && if (json_is_string(data_holder) &&
(NULL != format_holder) && (json_is_string(format_holder)) && json_is_string(format_holder) &&
(NULL != count_holder) && (json_is_integer(count_holder))) json_is_integer(count_holder))
{ {
char const * const data = json_string_value(data_holder); char const * const data = json_string_value(data_holder);
char const * const format = json_string_value(format_holder); char const * const format = json_string_value(format_holder);
length = (size_t) json_integer_value(count_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 else
{ {

View File

@ -5,12 +5,6 @@
extern struct wsfs_message * wsfs_message_create(json_t const * value) 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; struct wsfs_message * message = NULL;
size_t const length = json_dumpb(value, NULL, 0, JSON_COMPACT); size_t const length = json_dumpb(value, NULL, 0, JSON_COMPACT);

View File

@ -8,6 +8,7 @@
#include "wsfs/provider/provider.h" #include "wsfs/provider/provider.h"
#include "wsfs/provider/client_protocol_intern.h" #include "wsfs/provider/client_protocol_intern.h"
#include "wsfs/provider/client_config_intern.h"
#include "wsfs/provider/url.h" #include "wsfs/provider/url.h"
#define WSFSP_PROTOCOL ("fs") #define WSFSP_PROTOCOL ("fs")
@ -18,17 +19,17 @@
struct wsfsp_client struct wsfsp_client
{ {
volatile bool is_running; volatile bool is_running;
struct wsfsp_provider provider;
struct wsfsp_client_protocol protocol; struct wsfsp_client_protocol protocol;
struct lws_context_creation_info info; struct lws_context_creation_info info;
struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT]; struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT];
struct lws_context * context; struct lws_context * context;
char * key_path;
char * cert_path;
}; };
struct wsfsp_client * wsfsp_client_create( struct wsfsp_client * wsfsp_client_create(
struct wsfsp_provider * provider, struct wsfsp_client_config * config)
void * user_data)
{ {
lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL); lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL);
@ -36,7 +37,7 @@ struct wsfsp_client * wsfsp_client_create(
if (NULL != client) if (NULL != client)
{ {
client->is_running = true; 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); memset(client->protocols, 0, sizeof(struct lws_protocols) * WSFSP_CLIENT_PROTOCOL_COUNT);
client->protocols[0].name = "fs"; client->protocols[0].name = "fs";
@ -48,6 +49,11 @@ struct wsfsp_client * wsfsp_client_create(
client->info.uid = -1; client->info.uid = -1;
client->info.gid = -1; client->info.gid = -1;
if ((NULL != config->cert_path) && (NULL != config->key_path))
{
}
client->context = lws_create_context(&client->info); client->context = lws_create_context(&client->info);
} }
@ -96,17 +102,6 @@ void wsfsp_client_disconnect(
// ToDo: implement me // 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( void wsfsp_client_run(
struct wsfsp_client * client) struct wsfsp_client * client)
{ {

View File

@ -0,0 +1,112 @@
#include "wsfs/provider/client_config_intern.h"
#include "wsfs/provider/provider.h"
#include <stdlib.h>
#include <string.h>
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;
}

View File

@ -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

View File

@ -7,14 +7,7 @@
#include <jansson.h> #include <jansson.h>
#include "wsfs/provider/provider_intern.h" #include "wsfs/provider/provider.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/util.h" #include "wsfs/util.h"
#include "wsfs/message.h" #include "wsfs/message.h"
@ -117,15 +110,7 @@ void wsfsp_client_protocol_init(
protocol->request.user_data = protocol; protocol->request.user_data = protocol;
protocol->user_data = user_data; protocol->user_data = user_data;
protocol->provider.lookup = (NULL != provider->lookup) ? provider->lookup : &wsfsp_lookup_default; wsfsp_provider_init_from_prototype(&protocol->provider, provider);
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;
} }
void wsfsp_client_protocol_cleanup( void wsfsp_client_protocol_cleanup(

View File

@ -2,7 +2,7 @@
#define WSFS_PROVIDER_OPERATION_CLOSE_INTERN_H #define WSFS_PROVIDER_OPERATION_CLOSE_INTERN_H
#include "wsfs/provider/operation/close.h" #include "wsfs/provider/operation/close.h"
#include "wsfs/provider/provider_intern.h" #include "wsfs/provider/provider.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -1,6 +1,5 @@
#include "wsfs/provider/operation/getattr_intern.h" #include "wsfs/provider/operation/getattr_intern.h"
#include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include "wsfs/provider/operation/error.h" #include "wsfs/provider/operation/error.h"

View File

@ -2,7 +2,7 @@
#define WSFS_PROVIDER_OPERATION_GETATTR_INTERN_H #define WSFS_PROVIDER_OPERATION_GETATTR_INTERN_H
#include "wsfs/provider/operation/getattr.h" #include "wsfs/provider/operation/getattr.h"
#include "wsfs/provider/provider_intern.h" #include "wsfs/provider/provider.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -1,6 +1,5 @@
#include "wsfs/provider/operation/lookup_intern.h" #include "wsfs/provider/operation/lookup_intern.h"
#include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include "wsfs/provider/operation/error.h" #include "wsfs/provider/operation/error.h"
@ -63,6 +62,6 @@ void wsfsp_lookup_default(
char const * WSFS_UNUSED_PARAM(name), char const * WSFS_UNUSED_PARAM(name),
void * WSFS_UNUSED_PARAM(user_data)) void * WSFS_UNUSED_PARAM(user_data))
{ {
wsfsp_respond_error(request, -1); wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
} }

View File

@ -2,7 +2,7 @@
#define WSFS_PROVIDER_OPERATION_LOOKUP_INTERN_H #define WSFS_PROVIDER_OPERATION_LOOKUP_INTERN_H
#include "wsfs/provider/operation/lookup.h" #include "wsfs/provider/operation/lookup.h"
#include "wsfs/provider/provider_intern.h" #include "wsfs/provider/provider.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -1,6 +1,6 @@
#include "wsfs/provider/operation/open_intern.h" #include "wsfs/provider/operation/open_intern.h"
#include <stdio.h>
#include "wsfs/provider/operation/error.h" #include "wsfs/provider/operation/error.h"
#include "wsfs/provider/request.h"
#include "wsfs/util.h" #include "wsfs/util.h"
void wsfsp_open( void wsfsp_open(
@ -8,11 +8,23 @@ void wsfsp_open(
json_t * params, json_t * params,
int id) int id)
{ {
(void) context; size_t const count = json_array_size(params);
(void) params; if (2 == count)
(void) id; {
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); /* Flawfinder: ignore */
}
}
} }
void wsfsp_open_default( void wsfsp_open_default(
@ -21,15 +33,15 @@ void wsfsp_open_default(
int WSFS_UNUSED_PARAM(flags), int WSFS_UNUSED_PARAM(flags),
void * WSFS_UNUSED_PARAM(user_data)) void * WSFS_UNUSED_PARAM(user_data))
{ {
wsfsp_respond_error(request, -1); wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
} }
void wsfsp_respond_open( void wsfsp_respond_open(
struct wsfsp_request * request, struct wsfsp_request * request,
uint32_t handle) uint32_t handle)
{ {
(void) request; json_t * result = json_object();
(void) handle; json_object_set_new(result, "handle", json_integer((int) handle));
// ToDo: implement me wsfsp_respond(request, result);
} }

View File

@ -2,7 +2,7 @@
#define WSFS_PROVIDER_OPERATION_OPEN_INTERN_H #define WSFS_PROVIDER_OPERATION_OPEN_INTERN_H
#include "wsfs/provider/operation/open.h" #include "wsfs/provider/operation/open.h"
#include "wsfs/provider/provider_intern.h" #include "wsfs/provider/provider.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -1,5 +1,8 @@
#include "wsfs/provider/operation/read_intern.h" #include "wsfs/provider/operation/read_intern.h"
#include <stdio.h>
#include <stdlib.h>
#include <libwebsockets.h>
#include "wsfs/provider/operation/error.h" #include "wsfs/provider/operation/error.h"
#include "wsfs/util.h" #include "wsfs/util.h"
@ -8,11 +11,28 @@ void wsfsp_read(
json_t * params, json_t * params,
int id) int id)
{ {
(void) context; size_t const count = json_array_size(params);
(void) params; if (4 == count)
(void) id; {
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); /* Flawfinder: ignore */
}
}
} }
void wsfsp_read_default( void wsfsp_read_default(
@ -23,7 +43,7 @@ void wsfsp_read_default(
size_t WSFS_UNUSED_PARAM(length), size_t WSFS_UNUSED_PARAM(length),
void * WSFS_UNUSED_PARAM(user_data)) void * WSFS_UNUSED_PARAM(user_data))
{ {
wsfsp_respond_error(request, -1); wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
} }
void wsfsp_respond_read( void wsfsp_respond_read(
@ -31,7 +51,34 @@ void wsfsp_respond_read(
char const * data, char const * data,
size_t length) size_t length)
{ {
(void) request; if (0 < length)
(void) data; {
(void) 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, WSFS_BAD);
}
}
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);
}
} }

View File

@ -2,7 +2,7 @@
#define WSFS_PROVIDER_OPERATION_READ_INTERN_H #define WSFS_PROVIDER_OPERATION_READ_INTERN_H
#include "wsfs/provider/operation/read.h" #include "wsfs/provider/operation/read.h"
#include "wsfs/provider/provider_intern.h" #include "wsfs/provider/provider.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -1,7 +1,4 @@
#include "wsfs/provider/operation/readdir_intern.h" #include "wsfs/provider/operation/readdir_intern.h"
#include <stdio.h>
#include "wsfs/provider/operation/error.h" #include "wsfs/provider/operation/error.h"
#include "wsfs/provider/dirbuffer_intern.h" #include "wsfs/provider/dirbuffer_intern.h"
#include "wsfs/provider/request.h" #include "wsfs/provider/request.h"
@ -32,7 +29,7 @@ void wsfsp_readdir_default(
ino_t WSFS_UNUSED_PARAM(directory), ino_t WSFS_UNUSED_PARAM(directory),
void * WSFS_UNUSED_PARAM(user_data)) void * WSFS_UNUSED_PARAM(user_data))
{ {
wsfsp_respond_error(request, -1); wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
} }
void wsfsp_respond_readdir( void wsfsp_respond_readdir(

View File

@ -2,7 +2,7 @@
#define WSFS_PROVIDER_OPERATION_READDIR_INTERN_H #define WSFS_PROVIDER_OPERATION_READDIR_INTERN_H
#include "wsfs/provider/operation/readdir.h" #include "wsfs/provider/operation/readdir.h"
#include "wsfs/provider/provider_intern.h" #include "wsfs/provider/provider.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -1,4 +1,4 @@
#include "wsfs/provider/provider_intern.h" #include "wsfs/provider/provider.h"
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
@ -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( void wsfsp_provider_invoke(
struct wsfsp_invokation_context * context, struct wsfsp_invokation_context * context,
json_t * request) json_t * request)

View File

@ -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 <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>
#include <jansson.h>
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

View File

@ -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 <jansson.h>
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

View File

@ -40,7 +40,7 @@ extern void wsfsp_respond(
void wsfsp_respond_error( void wsfsp_respond_error(
struct wsfsp_request * request, struct wsfsp_request * request,
int status) wsfs_status status)
{ {
json_t * response = json_object(); json_t * response = json_object();
json_t * error = json_object(); json_t * error = json_object();

View File

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

19
lib/wsfs/status_intern.h Normal file
View File

@ -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