mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
moves server into session
This commit is contained in:
parent
1d413456a2
commit
7176fa80f6
@ -74,6 +74,7 @@ add_library(webfuse-adapter-static STATIC
|
||||
lib/webfuse/adapter/impl/authenticator.c
|
||||
lib/webfuse/adapter/impl/authenticators.c
|
||||
lib/webfuse/adapter/impl/credentials.c
|
||||
lib/webfuse/adapter/impl/operations.c
|
||||
lib/webfuse/adapter/impl/time/timepoint.c
|
||||
lib/webfuse/adapter/impl/time/timer.c
|
||||
lib/webfuse/adapter/impl/time/timeout_manager.c
|
||||
@ -84,7 +85,6 @@ add_library(webfuse-adapter-static STATIC
|
||||
lib/webfuse/adapter/impl/operation/close.c
|
||||
lib/webfuse/adapter/impl/operation/read.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/server.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/method.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/request.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/response.c
|
||||
lib/webfuse/adapter/impl/jsonrpc/util.c
|
||||
|
@ -19,7 +19,7 @@ static struct fuse_lowlevel_ops const filesystem_operations =
|
||||
|
||||
bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct wf_impl_jsonrpc_server * rpc,
|
||||
struct wf_impl_session_manager * session_manager,
|
||||
char * mount_point)
|
||||
{
|
||||
bool result = false;
|
||||
@ -29,7 +29,7 @@ bool wf_impl_filesystem_init(
|
||||
filesystem->args.argv = argv;
|
||||
filesystem->args.allocated = 0;
|
||||
|
||||
filesystem->user_data.rpc = rpc;
|
||||
filesystem->user_data.session_manager = session_manager;
|
||||
filesystem->user_data.timeout = 1.0;
|
||||
memset(&filesystem->buffer, 0, sizeof(struct fuse_buf));
|
||||
|
||||
|
@ -13,7 +13,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_server;
|
||||
struct wf_impl_session_manager;
|
||||
|
||||
struct wf_impl_filesystem
|
||||
{
|
||||
@ -25,7 +25,7 @@ struct wf_impl_filesystem
|
||||
|
||||
extern bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct wf_impl_jsonrpc_server * rpc,
|
||||
struct wf_impl_session_manager * session_manager,
|
||||
char * mount_point);
|
||||
|
||||
extern void wf_impl_filesystem_cleanup(
|
||||
|
@ -1,28 +0,0 @@
|
||||
#include "webfuse/adapter/impl/jsonrpc/method_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * method = malloc(sizeof(struct wf_impl_jsonrpc_method));
|
||||
if (NULL != method)
|
||||
{
|
||||
method->next = NULL;
|
||||
method->name = strdup(name);
|
||||
method->invoke = invoke;
|
||||
method->user_data = user_data;
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_method_dispose(
|
||||
struct wf_impl_jsonrpc_method * method)
|
||||
{
|
||||
free(method->name);
|
||||
free(method);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef bool wf_impl_jsonrpc_method_invoke_fn(
|
||||
void * user_data,
|
||||
struct json_t const * method_call);
|
||||
|
||||
typedef void wf_impl_jsonrpc_method_finished_fn(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
struct json_t const * result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/method.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_method
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * next;
|
||||
char * name;
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct wf_impl_jsonrpc_method * wf_impl_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_jsonrpc_method_dispose(
|
||||
struct wf_impl_jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,25 +1,11 @@
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/method_intern.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
static struct wf_impl_jsonrpc_method const * wf_impl_jsonrpc_server_getmethod(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * name)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * method = server->methods;
|
||||
while ((NULL != method) && (0 == strcmp(name, method->name)))
|
||||
{
|
||||
method = method->next;
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
static void wf_impl_jsonrpc_server_timeout(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
@ -27,7 +13,7 @@ static void wf_impl_jsonrpc_server_timeout(
|
||||
|
||||
if (server->request.is_pending)
|
||||
{
|
||||
wf_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
|
||||
wf_impl_jsonrpc_server_finished_fn * finished = server->request.finished;
|
||||
void * user_data = server->request.user_data;
|
||||
|
||||
server->request.is_pending = false;
|
||||
@ -42,9 +28,12 @@ static void wf_impl_jsonrpc_server_timeout(
|
||||
|
||||
void wf_impl_jsonrpc_server_init(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
struct wf_impl_timeout_manager * timeout_manager)
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
wf_impl_jsonrpc_server_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
server->methods = NULL;
|
||||
server->send = send;
|
||||
server->user_data = user_data;
|
||||
server->request.is_pending = false;
|
||||
|
||||
wf_impl_timer_init(&server->request.timer, timeout_manager);
|
||||
@ -60,32 +49,11 @@ void wf_impl_jsonrpc_server_cleanup(
|
||||
server->request.finished(server->request.user_data, WF_BAD, NULL);
|
||||
server->request.is_pending = false;
|
||||
}
|
||||
|
||||
struct wf_impl_jsonrpc_method * method = server->methods;
|
||||
while (NULL != method)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * next = method->next;
|
||||
method->next = NULL;
|
||||
wf_impl_jsonrpc_method_dispose(method);
|
||||
method = next;
|
||||
}
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_server_add(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * method = wf_impl_jsonrpc_method_create(name, invoke, user_data);
|
||||
method->next = server->methods;
|
||||
server->methods = method;
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_server_invoke(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
wf_impl_jsonrpc_method_finished_fn * finished,
|
||||
wf_impl_jsonrpc_server_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
@ -94,39 +62,31 @@ void wf_impl_jsonrpc_server_invoke(
|
||||
{
|
||||
if (!server->request.is_pending)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method const * method = wf_impl_jsonrpc_server_getmethod(server, method_name);
|
||||
if (NULL != method)
|
||||
server->request.is_pending = true;
|
||||
server->request.finished = finished;
|
||||
server->request.user_data = user_data;
|
||||
server->request.id = 42;
|
||||
wf_impl_timer_start(&server->request.timer, wf_impl_timepoint_in_msec(WF_DEFAULT_TIMEOUT),
|
||||
&wf_impl_jsonrpc_server_timeout, server);
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wf_impl_jsonrpc_request_create(method_name, server->request.id, param_info, args);
|
||||
va_end(args);
|
||||
if (NULL != request)
|
||||
{
|
||||
server->request.is_pending = true;
|
||||
server->request.finished = finished;
|
||||
server->request.user_data = user_data;
|
||||
server->request.id = 42;
|
||||
wf_impl_timer_start(&server->request.timer, wf_impl_timepoint_in_msec(WF_DEFAULT_TIMEOUT),
|
||||
&wf_impl_jsonrpc_server_timeout, server);
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wf_impl_jsonrpc_request_create(method_name, server->request.id, param_info, args);
|
||||
va_end(args);
|
||||
if (NULL != request)
|
||||
if (!server->send(request, server->user_data))
|
||||
{
|
||||
if (!method->invoke(method->user_data, request))
|
||||
{
|
||||
server->request.is_pending = false;
|
||||
server->request.finished = NULL;
|
||||
server->request.user_data = NULL;
|
||||
server->request.id = 0;
|
||||
wf_impl_timer_cancel(&server->request.timer);
|
||||
server->request.is_pending = false;
|
||||
server->request.finished = NULL;
|
||||
server->request.user_data = NULL;
|
||||
server->request.id = 0;
|
||||
wf_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, WF_BAD, NULL);
|
||||
}
|
||||
json_decref(request);
|
||||
finished(user_data, WF_BAD, NULL);
|
||||
}
|
||||
json_decref(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
finished(user_data, WF_BAD_NOTIMPLEMENTED, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -140,22 +100,16 @@ extern void wf_impl_jsonrpc_server_notify(
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
struct wf_impl_jsonrpc_method const * method = wf_impl_jsonrpc_server_getmethod(server, method_name);
|
||||
if (NULL != method)
|
||||
{
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wf_impl_jsonrpc_request_create(method_name, 0, param_info, args);
|
||||
va_end(args);
|
||||
if (NULL != request)
|
||||
{
|
||||
method->invoke(method->user_data, request);
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wf_impl_jsonrpc_request_create(method_name, 0, param_info, args);
|
||||
va_end(args);
|
||||
if (NULL != request)
|
||||
{
|
||||
server->send(request, server->user_data);
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +123,7 @@ void wf_impl_jsonrpc_server_onresult(
|
||||
|
||||
if ((server->request.is_pending) && (response.id == server->request.id))
|
||||
{
|
||||
wf_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
|
||||
wf_impl_jsonrpc_server_finished_fn * finished = server->request.finished;
|
||||
void * user_data = server->request.user_data;
|
||||
|
||||
server->request.is_pending = false;
|
||||
|
@ -12,18 +12,29 @@ using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/adapter/impl/jsonrpc/method.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/time/timer.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef bool wf_impl_jsonrpc_server_send_fn(
|
||||
json_t * request,
|
||||
void * user_data);
|
||||
|
||||
|
||||
typedef void wf_impl_jsonrpc_server_finished_fn(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
struct json_t const * result);
|
||||
|
||||
|
||||
struct wf_impl_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wf_impl_jsonrpc_method_finished_fn * finished;
|
||||
wf_impl_jsonrpc_server_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wf_impl_timer timer;
|
||||
@ -31,26 +42,23 @@ struct wf_impl_jsonrpc_request
|
||||
|
||||
struct wf_impl_jsonrpc_server
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * methods;
|
||||
struct wf_impl_jsonrpc_request request;
|
||||
wf_impl_jsonrpc_server_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void wf_impl_jsonrpc_server_init(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
wf_impl_jsonrpc_server_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_jsonrpc_server_cleanup(
|
||||
struct wf_impl_jsonrpc_server * server);
|
||||
|
||||
extern void wf_impl_jsonrpc_server_add(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wf_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data );
|
||||
|
||||
extern void wf_impl_jsonrpc_server_invoke(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
wf_impl_jsonrpc_method_finished_fn * finished,
|
||||
wf_impl_jsonrpc_server_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
|
@ -13,9 +13,13 @@ void wf_impl_operation_close(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_jsonrpc_server * rpc = wf_impl_operations_context_get_server(user_data, inode);
|
||||
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
if (NULL != rpc)
|
||||
{
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
}
|
||||
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
||||
|
@ -81,13 +81,20 @@ void wf_impl_operation_getattr (
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_jsonrpc_server * rpc = wf_impl_operations_context_get_server(user_data, inode);
|
||||
|
||||
struct wf_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wf_impl_operation_getattr_context));
|
||||
getattr_context->request = request;
|
||||
getattr_context->uid = context->uid;
|
||||
getattr_context->gid = context->gid;
|
||||
getattr_context->timeout = user_data->timeout;
|
||||
if (NULL != rpc)
|
||||
{
|
||||
struct wf_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wf_impl_operation_getattr_context));
|
||||
getattr_context->request = request;
|
||||
getattr_context->uid = context->uid;
|
||||
getattr_context->gid = context->gid;
|
||||
getattr_context->timeout = user_data->timeout;
|
||||
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "i", inode);
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "i", inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
|
@ -90,13 +90,20 @@ void wf_impl_operation_lookup (
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_jsonrpc_server * rpc = wf_impl_operations_context_get_server(user_data, parent);
|
||||
|
||||
struct wf_impl_operation_lookup_context * lookup_context = malloc(sizeof(struct wf_impl_operation_lookup_context));
|
||||
lookup_context->request = request;
|
||||
lookup_context->uid = context->uid;
|
||||
lookup_context->gid = context->gid;
|
||||
lookup_context->timeout = user_data->timeout;
|
||||
if (NULL != rpc)
|
||||
{
|
||||
struct wf_impl_operation_lookup_context * lookup_context = malloc(sizeof(struct wf_impl_operation_lookup_context));
|
||||
lookup_context->request = request;
|
||||
lookup_context->uid = context->uid;
|
||||
lookup_context->gid = context->gid;
|
||||
lookup_context->timeout = user_data->timeout;
|
||||
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,14 @@ void wf_impl_operation_open(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_jsonrpc_server * rpc = wf_impl_operations_context_get_server(user_data, inode);
|
||||
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags);
|
||||
if (NULL != rpc)
|
||||
{
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
|
@ -87,9 +87,16 @@ void wf_impl_operation_read(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_jsonrpc_server * rpc = wf_impl_operations_context_get_server(user_data, inode);
|
||||
|
||||
int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH;
|
||||
int handle = (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
|
||||
if (NULL != rpc)
|
||||
{
|
||||
int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH;
|
||||
int handle = (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
|
@ -137,11 +137,19 @@ void wf_impl_operation_readdir (
|
||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_jsonrpc_server * rpc = wf_impl_operations_context_get_server(user_data, inode);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
struct wf_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wf_impl_operation_readdir_context));
|
||||
readdir_context->request = request;
|
||||
readdir_context->size = size;
|
||||
readdir_context->offset = offset;
|
||||
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
|
20
lib/webfuse/adapter/impl/operations.c
Normal file
20
lib/webfuse/adapter/impl/operations.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include <stddef.h>
|
||||
|
||||
struct wf_impl_jsonrpc_server * wf_impl_operations_context_get_server(
|
||||
struct wf_impl_operations_context * context,
|
||||
fuse_ino_t inode)
|
||||
{
|
||||
struct wf_impl_jsonrpc_server * server = NULL;
|
||||
|
||||
struct wf_impl_session_manager * session_manger = context->session_manager;
|
||||
struct wf_impl_session * session = wf_impl_session_manager_get_by_inode(session_manger, inode);
|
||||
if (NULL != session)
|
||||
{
|
||||
server = &session->rpc;
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
@ -7,11 +7,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_server;
|
||||
struct wf_impl_session_manager;
|
||||
|
||||
struct wf_impl_operations_context
|
||||
{
|
||||
struct wf_impl_jsonrpc_server * rpc;
|
||||
struct wf_impl_session_manager * session_manager;
|
||||
double timeout;
|
||||
};
|
||||
|
||||
@ -47,6 +47,10 @@ extern void wf_impl_operation_read(
|
||||
fuse_ino_t ino, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
extern struct wf_impl_jsonrpc_server * wf_impl_operations_context_get_server(
|
||||
struct wf_impl_operations_context * context,
|
||||
fuse_ino_t inode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -38,7 +38,7 @@ static int wf_impl_server_protocol_callback(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->rpc);
|
||||
&protocol->timeout_manager);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
@ -70,20 +70,6 @@ static int wf_impl_server_protocol_callback(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool wf_impl_server_protocol_invoke(
|
||||
void * user_data,
|
||||
json_t const * request)
|
||||
{
|
||||
struct wf_server_protocol * protocol = user_data;
|
||||
struct wf_impl_session * session = &protocol->session_manager.session;
|
||||
struct wf_message * message = wf_message_create(request);
|
||||
|
||||
bool const result = wf_impl_session_send(session, message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct wf_server_protocol * wf_impl_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
@ -124,20 +110,11 @@ bool wf_impl_server_protocol_init(
|
||||
wf_impl_session_manager_init(&protocol->session_manager);
|
||||
wf_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
wf_impl_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
|
||||
wf_impl_jsonrpc_server_add(&protocol->rpc, "lookup", &wf_impl_server_protocol_invoke, protocol);
|
||||
wf_impl_jsonrpc_server_add(&protocol->rpc, "getattr", &wf_impl_server_protocol_invoke, protocol);
|
||||
wf_impl_jsonrpc_server_add(&protocol->rpc, "readdir", &wf_impl_server_protocol_invoke, protocol);
|
||||
wf_impl_jsonrpc_server_add(&protocol->rpc, "open", &wf_impl_server_protocol_invoke, protocol);
|
||||
wf_impl_jsonrpc_server_add(&protocol->rpc, "close", &wf_impl_server_protocol_invoke, protocol);
|
||||
wf_impl_jsonrpc_server_add(&protocol->rpc, "read", &wf_impl_server_protocol_invoke, protocol);
|
||||
|
||||
bool const success = wf_impl_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
|
||||
bool const success = wf_impl_filesystem_init(&protocol->filesystem, &protocol->session_manager, mount_point);
|
||||
|
||||
// cleanup on error
|
||||
if (!success)
|
||||
{
|
||||
wf_impl_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wf_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
@ -150,7 +127,6 @@ void wf_impl_server_protocol_cleanup(
|
||||
struct wf_server_protocol * protocol)
|
||||
{
|
||||
wf_impl_filesystem_cleanup(&protocol->filesystem);
|
||||
wf_impl_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wf_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
|
@ -7,40 +7,13 @@
|
||||
#include <libwebsockets.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void wf_impl_session_init(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_jsonrpc_server * rpc)
|
||||
{
|
||||
session->wsi = wsi;
|
||||
session->is_authenticated = false;
|
||||
session->authenticators = authenticators;
|
||||
session->rpc = rpc;
|
||||
wf_message_queue_init(&session->queue);
|
||||
}
|
||||
|
||||
void wf_impl_session_cleanup(
|
||||
struct wf_impl_session * session)
|
||||
static bool wf_impl_session_send(
|
||||
json_t * request,
|
||||
void * user_data)
|
||||
{
|
||||
wf_message_queue_cleanup(&session->queue);
|
||||
session->is_authenticated = false;
|
||||
session->wsi = NULL;
|
||||
session->authenticators = NULL;
|
||||
session->rpc = NULL;
|
||||
}
|
||||
struct wf_impl_session * session = user_data;
|
||||
struct wf_message * message = wf_message_create(request);
|
||||
|
||||
void wf_impl_session_authenticate(
|
||||
struct wf_impl_session * session,
|
||||
struct wf_credentials * creds)
|
||||
{
|
||||
session->is_authenticated = wf_impl_authenticators_authenticate(session->authenticators, creds);
|
||||
}
|
||||
|
||||
bool wf_impl_session_send(
|
||||
struct wf_impl_session * session,
|
||||
struct wf_message * message)
|
||||
{
|
||||
bool result = (session->is_authenticated) && (NULL != session->wsi);
|
||||
|
||||
if (result)
|
||||
@ -58,6 +31,36 @@ bool wf_impl_session_send(
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_session_init(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager)
|
||||
{
|
||||
session->wsi = wsi;
|
||||
session->is_authenticated = false;
|
||||
session->authenticators = authenticators;
|
||||
wf_impl_jsonrpc_server_init(&session->rpc, timeout_manager, &wf_impl_session_send, session);
|
||||
wf_message_queue_init(&session->queue);
|
||||
}
|
||||
|
||||
void wf_impl_session_cleanup(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
wf_impl_jsonrpc_server_cleanup(&session->rpc);
|
||||
wf_message_queue_cleanup(&session->queue);
|
||||
session->is_authenticated = false;
|
||||
session->wsi = NULL;
|
||||
session->authenticators = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_session_authenticate(
|
||||
struct wf_impl_session * session,
|
||||
struct wf_credentials * creds)
|
||||
{
|
||||
session->is_authenticated = wf_impl_authenticators_authenticate(session->authenticators, creds);
|
||||
}
|
||||
|
||||
void wf_impl_session_onwritable(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
@ -80,5 +83,5 @@ void wf_impl_session_receive(
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
wf_impl_jsonrpc_server_onresult(session->rpc, data, length);
|
||||
wf_impl_jsonrpc_server_onresult(&session->rpc, data, length);
|
||||
}
|
@ -10,6 +10,7 @@ using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -20,7 +21,7 @@ struct lws;
|
||||
struct wf_message;
|
||||
struct wf_credentials;
|
||||
struct wf_impl_authenticators;
|
||||
struct wf_impl_jsonrpc_server;
|
||||
struct wf_impl_timeout_manager;
|
||||
|
||||
struct wf_impl_session
|
||||
{
|
||||
@ -28,23 +29,19 @@ struct wf_impl_session
|
||||
bool is_authenticated;
|
||||
struct wf_message_queue queue;
|
||||
struct wf_impl_authenticators * authenticators;
|
||||
struct wf_impl_jsonrpc_server * rpc;
|
||||
struct wf_impl_jsonrpc_server rpc;
|
||||
};
|
||||
|
||||
extern void wf_impl_session_init(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_jsonrpc_server * rpc);
|
||||
struct wf_impl_timeout_manager * timeout_manager);
|
||||
|
||||
extern void wf_impl_session_authenticate(
|
||||
struct wf_impl_session * session,
|
||||
struct wf_credentials * creds);
|
||||
|
||||
extern bool wf_impl_session_send(
|
||||
struct wf_impl_session * session,
|
||||
struct wf_message * message);
|
||||
|
||||
extern void wf_impl_session_receive(
|
||||
struct wf_impl_session * session,
|
||||
char const * data,
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void wf_impl_session_manager_init(
|
||||
@ -17,13 +18,13 @@ struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_jsonrpc_server * rpc)
|
||||
struct wf_impl_timeout_manager * timeout_manager)
|
||||
{
|
||||
struct wf_impl_session * session = NULL;
|
||||
if (NULL == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
wf_impl_session_init(&manager->session, wsi, authenticators, rpc);
|
||||
wf_impl_session_init(&manager->session, wsi, authenticators, timeout_manager);
|
||||
}
|
||||
|
||||
return session;
|
||||
@ -42,6 +43,22 @@ struct wf_impl_session * wf_impl_session_manager_get(
|
||||
return session;
|
||||
}
|
||||
|
||||
struct wf_impl_session * wf_impl_session_manager_get_by_inode(
|
||||
struct wf_impl_session_manager * manager,
|
||||
fuse_ino_t WF_UNUSED_PARAM(inode))
|
||||
{
|
||||
// ToDo: use inode to determine session manager
|
||||
|
||||
struct wf_impl_session * session = NULL;
|
||||
if (NULL != manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_session_manager_remove(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -13,6 +14,7 @@ extern "C"
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wf_impl_timeout_manager;
|
||||
|
||||
struct wf_impl_session_manager
|
||||
{
|
||||
@ -29,12 +31,16 @@ extern struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_jsonrpc_server * rpc);
|
||||
struct wf_impl_timeout_manager * timeout_manager);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get_by_inode(
|
||||
struct wf_impl_session_manager * session_manger,
|
||||
fuse_ino_t inode);
|
||||
|
||||
extern void wf_impl_session_manager_remove(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
Loading…
Reference in New Issue
Block a user