mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
renamed to webfuse
This commit is contained in:
141
lib/webfuse/adapter/api.c
Normal file
141
lib/webfuse/adapter/api.c
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "webfuse_adapter.h"
|
||||
|
||||
#include "webfuse/adapter/impl/server.h"
|
||||
#include "webfuse/adapter/impl/server_protocol.h"
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
|
||||
// server
|
||||
|
||||
struct wf_server * wf_server_create(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
return wf_impl_server_create(config);
|
||||
}
|
||||
|
||||
void wf_server_dispose(
|
||||
struct wf_server * server)
|
||||
{
|
||||
wf_impl_server_dispose(server);
|
||||
}
|
||||
|
||||
void wf_server_run(
|
||||
struct wf_server * server)
|
||||
{
|
||||
wf_impl_server_run(server);
|
||||
}
|
||||
|
||||
void wf_server_shutdown(
|
||||
struct wf_server * server)
|
||||
{
|
||||
wf_impl_server_shutdown(server);
|
||||
}
|
||||
|
||||
// server protocol
|
||||
|
||||
struct wf_server_protocol * wf_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
return wf_impl_server_protocol_create(mount_point);
|
||||
}
|
||||
|
||||
void wf_server_protocol_dispose(
|
||||
struct wf_server_protocol * protocol)
|
||||
{
|
||||
wf_impl_server_protocol_dispose(protocol);
|
||||
}
|
||||
|
||||
void wf_server_protocol_init_lws(
|
||||
struct wf_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
wf_impl_server_protocol_init_lws(protocol, lws_protocol);
|
||||
}
|
||||
|
||||
void wf_server_protocol_add_authenticator(
|
||||
struct wf_server_protocol * protocol,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wf_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// server_config
|
||||
|
||||
struct wf_server_config * wf_server_config_create(void)
|
||||
{
|
||||
return wf_impl_server_config_create();
|
||||
}
|
||||
|
||||
void wf_server_config_dispose(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
wf_impl_server_config_dispose(config);
|
||||
}
|
||||
|
||||
void wf_server_config_set_mountpoint(
|
||||
struct wf_server_config * config,
|
||||
char const * mount_point)
|
||||
{
|
||||
wf_impl_server_config_set_mountpoint(config, mount_point);
|
||||
}
|
||||
|
||||
void wf_server_config_set_documentroot(
|
||||
struct wf_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
wf_impl_server_config_set_documentroot(config, document_root);
|
||||
}
|
||||
|
||||
void wf_server_config_set_keypath(
|
||||
struct wf_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wf_impl_server_config_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void wf_server_config_set_certpath(
|
||||
struct wf_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wf_impl_server_config_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void wf_server_config_set_vhostname(
|
||||
struct wf_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
wf_impl_server_config_set_vhostname(config, vhost_name);
|
||||
}
|
||||
|
||||
void wf_server_config_set_port(
|
||||
struct wf_server_config * config,
|
||||
int port)
|
||||
{
|
||||
wf_impl_server_config_set_port(config, port);
|
||||
}
|
||||
|
||||
void wf_server_config_add_authenticator(
|
||||
struct wf_server_config * config,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wf_impl_server_config_add_authenticator(config, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// credentials
|
||||
|
||||
char const * wf_credentials_type(
|
||||
struct wf_credentials const * credentials)
|
||||
{
|
||||
return wf_impl_credentials_type(credentials);
|
||||
}
|
||||
|
||||
char const * wf_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
return wf_impl_credentials_get(credentials, key);
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
|
||||
struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
|
||||
struct wf_impl_authenticator * wf_impl_authenticator_create(
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_impl_authenticator * authenticator = malloc(sizeof(struct wsfs_impl_authenticator));
|
||||
struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator));
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
authenticator->type = strdup(type);
|
||||
@@ -22,16 +22,16 @@ struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
|
||||
return authenticator;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticator_dispose(
|
||||
struct wsfs_impl_authenticator * authenticator)
|
||||
void wf_impl_authenticator_dispose(
|
||||
struct wf_impl_authenticator * authenticator)
|
||||
{
|
||||
free(authenticator->type);
|
||||
free(authenticator);
|
||||
}
|
||||
|
||||
bool wsfs_impl_authenticator_autenticate(
|
||||
struct wsfs_impl_authenticator * authenticator,
|
||||
struct wsfs_credentials * credentials)
|
||||
bool wf_impl_authenticator_autenticate(
|
||||
struct wf_impl_authenticator * authenticator,
|
||||
struct wf_credentials * credentials)
|
||||
{
|
||||
bool result;
|
||||
|
||||
42
lib/webfuse/adapter/impl/authenticator.h
Normal file
42
lib/webfuse/adapter/impl/authenticator.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef WF_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
#define WF_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_credentials;
|
||||
|
||||
struct wf_impl_authenticator
|
||||
{
|
||||
char * type;
|
||||
wf_authenticate_fn * authenticate;
|
||||
void * user_data;
|
||||
struct wf_impl_authenticator * next;
|
||||
};
|
||||
|
||||
extern struct wf_impl_authenticator * wf_impl_authenticator_create(
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_authenticator_dispose(
|
||||
struct wf_impl_authenticator * authenticator);
|
||||
|
||||
extern bool wf_impl_authenticator_autenticate(
|
||||
struct wf_impl_authenticator * authenticator,
|
||||
struct wf_credentials * credentials);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
101
lib/webfuse/adapter/impl/authenticators.c
Normal file
101
lib/webfuse/adapter/impl/authenticators.c
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
|
||||
static struct wf_impl_authenticator * wf_impl_authenticators_find(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
char const * type)
|
||||
{
|
||||
struct wf_impl_authenticator * result = NULL;
|
||||
|
||||
struct wf_impl_authenticator * actual = authenticators->first;
|
||||
while ((NULL == result) && (NULL != actual))
|
||||
{
|
||||
struct wf_impl_authenticator * next = actual->next;
|
||||
if (0 == strcmp(type, actual->type))
|
||||
{
|
||||
result = actual;
|
||||
}
|
||||
|
||||
actual = next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_authenticators_init(
|
||||
struct wf_impl_authenticators * authenticators)
|
||||
{
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_authenticators_cleanup(
|
||||
struct wf_impl_authenticators * authenticators)
|
||||
{
|
||||
struct wf_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wf_impl_authenticator * next = actual->next;
|
||||
wf_impl_authenticator_dispose(actual);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_authenticators_clone(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_authenticators * other)
|
||||
{
|
||||
wf_impl_authenticators_init(other);
|
||||
|
||||
struct wf_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wf_impl_authenticator * next = actual->next;
|
||||
wf_impl_authenticators_add(other,
|
||||
actual->type, actual->authenticate, actual->user_data);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern void wf_impl_authenticators_move(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_authenticators * other)
|
||||
{
|
||||
other->first = authenticators->first;
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_authenticators_add(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(type, authenticate, user_data);
|
||||
authenticator->next = authenticators->first;
|
||||
authenticators->first = authenticator;
|
||||
}
|
||||
|
||||
bool wf_impl_authenticators_authenticate(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_credentials * credentials)
|
||||
{
|
||||
bool result = (NULL == authenticators->first);
|
||||
|
||||
if (NULL != credentials)
|
||||
{
|
||||
struct wf_impl_authenticator * authenticator = wf_impl_authenticators_find(authenticators, credentials->type);
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
result = wf_impl_authenticator_autenticate(authenticator, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
51
lib/webfuse/adapter/impl/authenticators.h
Normal file
51
lib/webfuse/adapter/impl/authenticators.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef WF_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
#define WF_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_authenticator;
|
||||
struct wf_credentials;
|
||||
|
||||
struct wf_impl_authenticators
|
||||
{
|
||||
struct wf_impl_authenticator * first;
|
||||
};
|
||||
|
||||
extern void wf_impl_authenticators_init(
|
||||
struct wf_impl_authenticators * authenticators);
|
||||
|
||||
extern void wf_impl_authenticators_cleanup(
|
||||
struct wf_impl_authenticators * authenticators);
|
||||
|
||||
extern void wf_impl_authenticators_clone(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_authenticators * other);
|
||||
|
||||
extern void wf_impl_authenticators_move(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_authenticators * other);
|
||||
|
||||
extern void wf_impl_authenticators_add(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern bool wf_impl_authenticators_authenticate(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include <string.h>
|
||||
|
||||
void wsfs_impl_credentials_init(
|
||||
struct wsfs_credentials * credentials,
|
||||
void wf_impl_credentials_init(
|
||||
struct wf_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data)
|
||||
{
|
||||
@@ -11,21 +11,21 @@ void wsfs_impl_credentials_init(
|
||||
json_incref(credentials->data);
|
||||
}
|
||||
|
||||
void wsfs_impl_credentials_cleanup(
|
||||
struct wsfs_credentials * credentials)
|
||||
void wf_impl_credentials_cleanup(
|
||||
struct wf_credentials * credentials)
|
||||
{
|
||||
free(credentials->type);
|
||||
json_decref(credentials->data);
|
||||
}
|
||||
|
||||
char const * wsfs_impl_credentials_type(
|
||||
struct wsfs_credentials const * credentials)
|
||||
char const * wf_impl_credentials_type(
|
||||
struct wf_credentials const * credentials)
|
||||
{
|
||||
return credentials->type;
|
||||
}
|
||||
|
||||
char const * wsfs_impl_credentials_get(
|
||||
struct wsfs_credentials const * credentials,
|
||||
char const * wf_impl_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
char const * result = NULL;
|
||||
36
lib/webfuse/adapter/impl/credentials.h
Normal file
36
lib/webfuse/adapter/impl/credentials.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef WF_ADAPTER_IMPL_CREDENTIALS_H
|
||||
#define WF_ADAPTER_IMPL_CREDENTIALS_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_credentials
|
||||
{
|
||||
char * type;
|
||||
json_t * data;
|
||||
};
|
||||
|
||||
extern void wf_impl_credentials_init(
|
||||
struct wf_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data);
|
||||
|
||||
extern void wf_impl_credentials_cleanup(
|
||||
struct wf_credentials * credentials);
|
||||
|
||||
extern char const * wf_impl_credentials_type(
|
||||
struct wf_credentials const * credentials);
|
||||
|
||||
extern char const * wf_impl_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "wsfs/adapter/impl/filesystem.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@@ -8,18 +8,18 @@
|
||||
|
||||
static struct fuse_lowlevel_ops const filesystem_operations =
|
||||
{
|
||||
.lookup = &wsfs_impl_operation_lookup,
|
||||
.getattr = &wsfs_impl_operation_getattr,
|
||||
.readdir = &wsfs_impl_operation_readdir,
|
||||
.open = &wsfs_impl_operation_open,
|
||||
.release = &wsfs_impl_operation_close,
|
||||
.read = &wsfs_impl_operation_read
|
||||
.lookup = &wf_impl_operation_lookup,
|
||||
.getattr = &wf_impl_operation_getattr,
|
||||
.readdir = &wf_impl_operation_readdir,
|
||||
.open = &wf_impl_operation_open,
|
||||
.release = &wf_impl_operation_close,
|
||||
.read = &wf_impl_operation_read
|
||||
};
|
||||
|
||||
|
||||
bool wsfs_impl_filesystem_init(
|
||||
struct wsfs_impl_filesystem * filesystem,
|
||||
struct wsfs_impl_jsonrpc_server * rpc,
|
||||
bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct wf_impl_jsonrpc_server * rpc,
|
||||
char * mount_point)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -46,8 +46,8 @@ bool wsfs_impl_filesystem_init(
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_impl_filesystem_cleanup(
|
||||
struct wsfs_impl_filesystem * filesystem)
|
||||
void wf_impl_filesystem_cleanup(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
{
|
||||
if (NULL != filesystem->session)
|
||||
{
|
||||
@@ -61,14 +61,14 @@ void wsfs_impl_filesystem_cleanup(
|
||||
fuse_opt_free_args(&filesystem->args);
|
||||
}
|
||||
|
||||
int wsfs_impl_filesystem_get_fd(
|
||||
struct wsfs_impl_filesystem * filesystem)
|
||||
int wf_impl_filesystem_get_fd(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
{
|
||||
return fuse_session_fd(filesystem->session);
|
||||
}
|
||||
|
||||
void wsfs_impl_filesystem_process_request(
|
||||
struct wsfs_impl_filesystem * filesystem)
|
||||
void wf_impl_filesystem_process_request(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
{
|
||||
int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer);
|
||||
if (0 < result)
|
||||
45
lib/webfuse/adapter/impl/filesystem.h
Normal file
45
lib/webfuse/adapter/impl/filesystem.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef WF_ADAPTER_IMPL_FILESYSTEM_H
|
||||
#define WF_ADAPTER_IMPL_FILESYSTEM_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_server;
|
||||
|
||||
struct wf_impl_filesystem
|
||||
{
|
||||
struct fuse_args args;
|
||||
struct fuse_session * session;
|
||||
struct fuse_buf buffer;
|
||||
struct wf_impl_operations_context user_data;
|
||||
};
|
||||
|
||||
extern bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct wf_impl_jsonrpc_server * rpc,
|
||||
char * mount_point);
|
||||
|
||||
extern void wf_impl_filesystem_cleanup(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
extern int wf_impl_filesystem_get_fd(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
extern void wf_impl_filesystem_process_request(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_FUSE_H
|
||||
#define WSFS_ADAPTER_IMPL_FUSE_H
|
||||
#ifndef WF_ADAPTER_IMPL_FUSE_H
|
||||
#define WF_ADAPTER_IMPL_FUSE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
28
lib/webfuse/adapter/impl/jsonrpc/method.c
Normal file
28
lib/webfuse/adapter/impl/jsonrpc/method.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#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,25 +1,25 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/core/status.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef bool wsfs_impl_jsonrpc_method_invoke_fn(
|
||||
typedef bool wf_impl_jsonrpc_method_invoke_fn(
|
||||
void * user_data,
|
||||
struct json_t const * method_call);
|
||||
|
||||
typedef void wsfs_impl_jsonrpc_method_finished_fn(
|
||||
typedef void wf_impl_jsonrpc_method_finished_fn(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
wf_status status,
|
||||
struct json_t const * result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
31
lib/webfuse/adapter/impl/jsonrpc/method_intern.h
Normal file
31
lib/webfuse/adapter/impl/jsonrpc/method_intern.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#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,6 +1,6 @@
|
||||
#include "wsfs/adapter/impl/jsonrpc/request.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
|
||||
json_t * wsfs_impl_jsonrpc_request_create(
|
||||
json_t * wf_impl_jsonrpc_request_create(
|
||||
char const * method,
|
||||
int id,
|
||||
char const * param_info,
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_REQUEST_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_REQUEST_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
@@ -18,7 +18,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern json_t * wsfs_impl_jsonrpc_request_create(
|
||||
extern json_t * wf_impl_jsonrpc_request_create(
|
||||
char const * method,
|
||||
int id,
|
||||
char const * param_info,
|
||||
@@ -1,30 +1,30 @@
|
||||
#include "wsfs/adapter/impl/jsonrpc/response.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
void wsfs_impl_jsonrpc_response_init(
|
||||
struct wsfs_impl_jsonrpc_response * result,
|
||||
void wf_impl_jsonrpc_response_init(
|
||||
struct wf_impl_jsonrpc_response * result,
|
||||
char const * buffer,
|
||||
size_t length)
|
||||
{
|
||||
result->status = WSFS_BAD;
|
||||
result->status = WF_BAD;
|
||||
result->id = -1;
|
||||
result->result = NULL;
|
||||
|
||||
json_t * response = json_loadb(buffer, length, 0, NULL);
|
||||
if (NULL == response)
|
||||
{
|
||||
result->status = WSFS_BAD_FORMAT;
|
||||
result->status = WF_BAD_FORMAT;
|
||||
return;
|
||||
}
|
||||
|
||||
json_t * id_holder = json_object_get(response, "id");
|
||||
if ((NULL == id_holder) || (!json_is_integer(id_holder)))
|
||||
{
|
||||
result->status = WSFS_BAD_FORMAT;
|
||||
result->status = WF_BAD_FORMAT;
|
||||
json_decref(response);
|
||||
return;
|
||||
}
|
||||
|
||||
result->status = WSFS_GOOD;
|
||||
result->status = WF_GOOD;
|
||||
result->id = json_integer_value(id_holder);
|
||||
result->result = json_object_get(response, "result");
|
||||
if (NULL != result->result)
|
||||
@@ -33,7 +33,7 @@ void wsfs_impl_jsonrpc_response_init(
|
||||
}
|
||||
else
|
||||
{
|
||||
result->status = WSFS_BAD_FORMAT;
|
||||
result->status = WF_BAD_FORMAT;
|
||||
|
||||
json_t * error = json_object_get(response, "error");
|
||||
if (NULL != error)
|
||||
@@ -49,8 +49,8 @@ void wsfs_impl_jsonrpc_response_init(
|
||||
json_decref(response);
|
||||
}
|
||||
|
||||
void wsfs_impl_jsonrpc_response_cleanup(
|
||||
struct wsfs_impl_jsonrpc_response * response)
|
||||
void wf_impl_jsonrpc_response_cleanup(
|
||||
struct wf_impl_jsonrpc_response * response)
|
||||
{
|
||||
if (NULL != response->result)
|
||||
{
|
||||
38
lib/webfuse/adapter/impl/jsonrpc/response.h
Normal file
38
lib/webfuse/adapter/impl/jsonrpc/response.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_response
|
||||
{
|
||||
wf_status status;
|
||||
int id;
|
||||
json_t * result;
|
||||
};
|
||||
|
||||
extern void wf_impl_jsonrpc_response_init(
|
||||
struct wf_impl_jsonrpc_response * response,
|
||||
char const * buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
extern void wf_impl_jsonrpc_response_cleanup(
|
||||
struct wf_impl_jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
186
lib/webfuse/adapter/impl/jsonrpc/server.c
Normal file
186
lib/webfuse/adapter/impl/jsonrpc/server.c
Normal file
@@ -0,0 +1,186 @@
|
||||
#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)
|
||||
{
|
||||
struct wf_impl_jsonrpc_server * server = timer->user_data;
|
||||
|
||||
if (server->request.is_pending)
|
||||
{
|
||||
wf_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
|
||||
void * user_data = server->request.user_data;
|
||||
|
||||
server->request.is_pending = false;
|
||||
server->request.id = 0;
|
||||
server->request.user_data = NULL;
|
||||
server->request.finished = NULL;
|
||||
wf_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, WF_BAD_TIMEOUT, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_server_init(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
struct wf_impl_timeout_manager * timeout_manager)
|
||||
{
|
||||
server->methods = NULL;
|
||||
server->request.is_pending = false;
|
||||
|
||||
wf_impl_timer_init(&server->request.timer, timeout_manager);
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_server_cleanup(
|
||||
struct wf_impl_jsonrpc_server * server)
|
||||
{
|
||||
wf_impl_timer_cleanup(&server->request.timer);
|
||||
|
||||
if (server->request.is_pending)
|
||||
{
|
||||
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,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
finished(user_data, WF_BAD, NULL);
|
||||
}
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finished(user_data, WF_BAD_NOTIMPLEMENTED, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finished(user_data, WF_BAD_BUSY, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
extern void wf_impl_jsonrpc_server_notify(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_jsonrpc_server_onresult(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length)
|
||||
{
|
||||
struct wf_impl_jsonrpc_response response;
|
||||
wf_impl_jsonrpc_response_init(&response, message, length);
|
||||
|
||||
if ((server->request.is_pending) && (response.id == server->request.id))
|
||||
{
|
||||
wf_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
|
||||
void * user_data = server->request.user_data;
|
||||
|
||||
server->request.is_pending = false;
|
||||
server->request.id = 0;
|
||||
server->request.user_data = NULL;
|
||||
server->request.finished = NULL;
|
||||
wf_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, response.status, response.result);
|
||||
}
|
||||
|
||||
wf_impl_jsonrpc_response_cleanup(&response);
|
||||
}
|
||||
|
||||
77
lib/webfuse/adapter/impl/jsonrpc/server.h
Normal file
77
lib/webfuse/adapter/impl/jsonrpc/server.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
#define WF_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
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"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_impl_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wf_impl_jsonrpc_method_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wf_impl_timer timer;
|
||||
};
|
||||
|
||||
struct wf_impl_jsonrpc_server
|
||||
{
|
||||
struct wf_impl_jsonrpc_method * methods;
|
||||
struct wf_impl_jsonrpc_request request;
|
||||
};
|
||||
|
||||
extern void wf_impl_jsonrpc_server_init(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
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,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wf_impl_jsonrpc_server_notify(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wf_impl_jsonrpc_server_onresult(
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "wsfs/adapter/impl/jsonrpc/util.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
|
||||
int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
{
|
||||
int result = default_value;
|
||||
|
||||
17
lib/webfuse/adapter/impl/jsonrpc/util.h
Normal file
17
lib/webfuse/adapter/impl/jsonrpc/util.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef WF_ADAPTER_IMPL_JSON_UTIL_H
|
||||
#define WF_ADAPTER_IMPL_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int wf_impl_json_get_int(json_t const * object, char const * key, int default_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
21
lib/webfuse/adapter/impl/operation/close.c
Normal file
21
lib/webfuse/adapter/impl/operation/close.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wf_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@@ -7,11 +7,11 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/util.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
struct wsfs_impl_operation_getattr_context
|
||||
struct wf_impl_operation_getattr_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
double timeout;
|
||||
@@ -19,12 +19,12 @@ struct wsfs_impl_operation_getattr_context
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
static void wsfs_impl_operation_getattr_finished(
|
||||
static void wf_impl_operation_getattr_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
wf_status status,
|
||||
json_t const * data)
|
||||
{
|
||||
struct wsfs_impl_operation_getattr_context * context = user_data;
|
||||
struct wf_impl_operation_getattr_context * context = user_data;
|
||||
|
||||
struct stat buffer;
|
||||
if (NULL != data)
|
||||
@@ -50,19 +50,19 @@ static void wsfs_impl_operation_getattr_finished(
|
||||
buffer.st_uid = context->uid;
|
||||
buffer.st_gid = context->gid;
|
||||
buffer.st_nlink = 1;
|
||||
buffer.st_size = wsfs_impl_json_get_int(data, "size", 0);
|
||||
buffer.st_atime = wsfs_impl_json_get_int(data, "atime", 0);
|
||||
buffer.st_mtime = wsfs_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.st_ctime = wsfs_impl_json_get_int(data, "ctime", 0);
|
||||
buffer.st_size = wf_impl_json_get_int(data, "size", 0);
|
||||
buffer.st_atime = wf_impl_json_get_int(data, "atime", 0);
|
||||
buffer.st_mtime = wf_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.st_ctime = wf_impl_json_get_int(data, "ctime", 0);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WSFS_BAD_FORMAT;
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
if (WSFS_GOOD == status)
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
fuse_reply_attr(context->request, &buffer, context->timeout);
|
||||
}
|
||||
@@ -74,20 +74,20 @@ static void wsfs_impl_operation_getattr_finished(
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wsfs_impl_operation_getattr (
|
||||
void wf_impl_operation_getattr (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
|
||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
struct wsfs_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wsfs_impl_operation_getattr_context));
|
||||
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;
|
||||
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_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);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/util.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
struct wsfs_impl_operation_lookup_context
|
||||
struct wf_impl_operation_lookup_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
double timeout;
|
||||
@@ -22,13 +22,13 @@ struct wsfs_impl_operation_lookup_context
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
static void wsfs_impl_operation_lookup_finished(
|
||||
static void wf_impl_operation_lookup_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
wf_status status,
|
||||
json_t const * data
|
||||
)
|
||||
{
|
||||
struct wsfs_impl_operation_lookup_context * context = user_data;
|
||||
struct wf_impl_operation_lookup_context * context = user_data;
|
||||
struct fuse_entry_param buffer;
|
||||
|
||||
if (NULL != data)
|
||||
@@ -60,18 +60,18 @@ static void wsfs_impl_operation_lookup_finished(
|
||||
buffer.attr.st_uid = context->uid;
|
||||
buffer.attr.st_gid = context->gid;
|
||||
buffer.attr.st_nlink = 1;
|
||||
buffer.attr.st_size = wsfs_impl_json_get_int(data, "size", 0);
|
||||
buffer.attr.st_atime = wsfs_impl_json_get_int(data, "atime", 0);
|
||||
buffer.attr.st_mtime = wsfs_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.attr.st_ctime = wsfs_impl_json_get_int(data, "ctime", 0);
|
||||
buffer.attr.st_size = wf_impl_json_get_int(data, "size", 0);
|
||||
buffer.attr.st_atime = wf_impl_json_get_int(data, "atime", 0);
|
||||
buffer.attr.st_mtime = wf_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.attr.st_ctime = wf_impl_json_get_int(data, "ctime", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WSFS_BAD_FORMAT;
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
if (WSFS_GOOD == status)
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
fuse_reply_entry(context->request, &buffer);
|
||||
}
|
||||
@@ -83,20 +83,20 @@ static void wsfs_impl_operation_lookup_finished(
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wsfs_impl_operation_lookup (
|
||||
void wf_impl_operation_lookup (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t parent,
|
||||
char const * name)
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
struct wsfs_impl_operation_lookup_context * lookup_context = malloc(sizeof(struct wsfs_impl_operation_lookup_context));
|
||||
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;
|
||||
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_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);
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "wsfs/core/status.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
static void wsfs_impl_operation_open_finished(
|
||||
static void wf_impl_operation_open_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
wf_status status,
|
||||
json_t const * result)
|
||||
{
|
||||
fuse_req_t request = user_data;
|
||||
@@ -26,11 +26,11 @@ static void wsfs_impl_operation_open_finished(
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WSFS_BAD_FORMAT;
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
if (WSFS_GOOD == status)
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
fuse_reply_open(request, &file_info);
|
||||
}
|
||||
@@ -41,13 +41,13 @@ static void wsfs_impl_operation_open_finished(
|
||||
|
||||
}
|
||||
|
||||
void wsfs_impl_operation_open(
|
||||
void wf_impl_operation_open(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags);
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@@ -6,17 +6,17 @@
|
||||
#include <jansson.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#define WSFS_MAX_READ_LENGTH 4096
|
||||
#define WF_MAX_READ_LENGTH 4096
|
||||
|
||||
static char * wsfs_impl_fill_buffer(
|
||||
static char * wf_impl_fill_buffer(
|
||||
char const * data,
|
||||
char const * format,
|
||||
size_t count,
|
||||
wsfs_status * status)
|
||||
wf_status * status)
|
||||
{
|
||||
*status = WSFS_GOOD;
|
||||
*status = WF_GOOD;
|
||||
char * buffer = malloc(count + 1);
|
||||
|
||||
if ((NULL != buffer) && (0 < count))
|
||||
@@ -31,14 +31,14 @@ static char * wsfs_impl_fill_buffer(
|
||||
}
|
||||
else
|
||||
{
|
||||
*status = WSFS_BAD;
|
||||
*status = WF_BAD;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status status, json_t const * data)
|
||||
static void wf_impl_operation_read_finished(void * user_data, wf_status status, json_t const * data)
|
||||
{
|
||||
fuse_req_t request = user_data;
|
||||
|
||||
@@ -58,15 +58,15 @@ static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status stat
|
||||
char const * const format = json_string_value(format_holder);
|
||||
length = (size_t) json_integer_value(count_holder);
|
||||
|
||||
buffer = wsfs_impl_fill_buffer(data, format, length, &status);
|
||||
buffer = wf_impl_fill_buffer(data, format, length, &status);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WSFS_BAD_FORMAT;
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
if (WSFS_GOOD == status)
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
fuse_reply_buf(request, buffer, length);
|
||||
}
|
||||
@@ -79,17 +79,17 @@ static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status stat
|
||||
|
||||
}
|
||||
|
||||
void wsfs_impl_operation_read(
|
||||
void wf_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int const length = (size <= WSFS_MAX_READ_LENGTH) ? (int) size : WSFS_MAX_READ_LENGTH;
|
||||
int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH;
|
||||
int handle = (file_info->fh & INT_MAX);
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -8,43 +8,43 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
|
||||
#define WSFS_DIRBUFFER_INITIAL_SIZE 1024
|
||||
#define WF_DIRBUFFER_INITIAL_SIZE 1024
|
||||
|
||||
struct wsfs_impl_operation_readdir_context
|
||||
struct wf_impl_operation_readdir_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
size_t size;
|
||||
off_t offset;
|
||||
};
|
||||
|
||||
struct wsfs_impl_dirbuffer
|
||||
struct wf_impl_dirbuffer
|
||||
{
|
||||
char * data;
|
||||
size_t position;
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
static void wsfs_impl_dirbuffer_init(
|
||||
struct wsfs_impl_dirbuffer * buffer)
|
||||
static void wf_impl_dirbuffer_init(
|
||||
struct wf_impl_dirbuffer * buffer)
|
||||
{
|
||||
buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE);
|
||||
buffer->data = malloc(WF_DIRBUFFER_INITIAL_SIZE);
|
||||
buffer->position = 0;
|
||||
buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE;
|
||||
buffer->capacity = WF_DIRBUFFER_INITIAL_SIZE;
|
||||
}
|
||||
|
||||
static void wsfs_impl_dirbuffer_dispose(
|
||||
struct wsfs_impl_dirbuffer * buffer)
|
||||
static void wf_impl_dirbuffer_dispose(
|
||||
struct wf_impl_dirbuffer * buffer)
|
||||
{
|
||||
free(buffer->data);
|
||||
}
|
||||
|
||||
static void wsfs_impl_dirbuffer_add(
|
||||
static void wf_impl_dirbuffer_add(
|
||||
fuse_req_t request,
|
||||
struct wsfs_impl_dirbuffer * buffer,
|
||||
struct wf_impl_dirbuffer * buffer,
|
||||
char const * name,
|
||||
fuse_ino_t inode)
|
||||
{
|
||||
@@ -66,20 +66,20 @@ static void wsfs_impl_dirbuffer_add(
|
||||
buffer->position += size;
|
||||
}
|
||||
|
||||
static size_t wsfs_impl_min(size_t a, size_t b)
|
||||
static size_t wf_impl_min(size_t a, size_t b)
|
||||
{
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
static void wsfs_impl_operation_readdir_finished(
|
||||
static void wf_impl_operation_readdir_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
wf_status status,
|
||||
json_t const * result)
|
||||
{
|
||||
struct wsfs_impl_operation_readdir_context * context = user_data;
|
||||
struct wf_impl_operation_readdir_context * context = user_data;
|
||||
|
||||
struct wsfs_impl_dirbuffer buffer;
|
||||
wsfs_impl_dirbuffer_init(&buffer);
|
||||
struct wf_impl_dirbuffer buffer;
|
||||
wf_impl_dirbuffer_init(&buffer);
|
||||
|
||||
if (NULL != result)
|
||||
{
|
||||
@@ -100,19 +100,19 @@ static void wsfs_impl_operation_readdir_finished(
|
||||
{
|
||||
char const * name = json_string_value(name_holder);
|
||||
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
|
||||
wsfs_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
|
||||
wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (WSFS_GOOD == status)
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
if (((size_t) context->offset) < buffer.position)
|
||||
{
|
||||
fuse_reply_buf(context->request, &buffer.data[context->offset],
|
||||
wsfs_impl_min(buffer.position - context->offset, context->size));
|
||||
wf_impl_min(buffer.position - context->offset, context->size));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -125,23 +125,23 @@ static void wsfs_impl_operation_readdir_finished(
|
||||
fuse_reply_err(context->request, ENOENT);
|
||||
}
|
||||
|
||||
wsfs_impl_dirbuffer_dispose(&buffer);
|
||||
wf_impl_dirbuffer_dispose(&buffer);
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wsfs_impl_operation_readdir (
|
||||
void wf_impl_operation_readdir (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
|
||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wsfs_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_impl_operation_readdir_context));
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->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;
|
||||
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode);
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode);
|
||||
}
|
||||
@@ -1,48 +1,48 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_OPERATIONS_H
|
||||
#define WSFS_ADAPTER_IMPL_OPERATIONS_H
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATIONS_H
|
||||
#define WF_ADAPTER_IMPL_OPERATIONS_H
|
||||
|
||||
#include "wsfs/adapter/impl/fuse_wrapper.h"
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_server;
|
||||
struct wf_impl_jsonrpc_server;
|
||||
|
||||
struct wsfs_impl_operations_context
|
||||
struct wf_impl_operations_context
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_server * rpc;
|
||||
struct wf_impl_jsonrpc_server * rpc;
|
||||
double timeout;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_operation_lookup (
|
||||
extern void wf_impl_operation_lookup (
|
||||
fuse_req_t req,
|
||||
fuse_ino_t parent,
|
||||
char const * name);
|
||||
|
||||
extern void wsfs_impl_operation_getattr (
|
||||
extern void wf_impl_operation_getattr (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info *file_info);
|
||||
|
||||
extern void wsfs_impl_operation_readdir (
|
||||
extern void wf_impl_operation_readdir (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info *file_info);
|
||||
|
||||
extern void wsfs_impl_operation_open(
|
||||
extern void wf_impl_operation_open(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info);
|
||||
|
||||
extern void wsfs_impl_operation_close(
|
||||
extern void wf_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info);
|
||||
|
||||
extern void wsfs_impl_operation_read(
|
||||
extern void wf_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t ino, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/server.h"
|
||||
#include "webfuse/adapter/server.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
@@ -8,40 +8,40 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/adapter/impl/server_config.h"
|
||||
#include "wsfs/adapter/impl/server_protocol.h"
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
#include "webfuse/adapter/impl/server_protocol.h"
|
||||
|
||||
#define WSFS_DISABLE_LWS_LOG 0
|
||||
#define WSFS_SERVER_PROTOCOL_COUNT 3
|
||||
#define WSFS_SERVER_TIMEOUT (1 * 1000)
|
||||
#define WF_DISABLE_LWS_LOG 0
|
||||
#define WF_SERVER_PROTOCOL_COUNT 3
|
||||
#define WF_SERVER_TIMEOUT (1 * 1000)
|
||||
|
||||
struct wsfs_server
|
||||
struct wf_server
|
||||
{
|
||||
struct wsfs_server_config config;
|
||||
struct wsfs_server_protocol protocol;
|
||||
struct lws_protocols ws_protocols[WSFS_SERVER_PROTOCOL_COUNT];
|
||||
struct wf_server_config config;
|
||||
struct wf_server_protocol protocol;
|
||||
struct lws_protocols ws_protocols[WF_SERVER_PROTOCOL_COUNT];
|
||||
struct lws_context * context;
|
||||
volatile bool shutdown_requested;
|
||||
struct lws_http_mount mount;
|
||||
struct lws_context_creation_info info;
|
||||
};
|
||||
|
||||
static bool wsfs_impl_server_tls_enabled(
|
||||
struct wsfs_server * server)
|
||||
static bool wf_impl_server_tls_enabled(
|
||||
struct wf_server * server)
|
||||
{
|
||||
return ((server->config.key_path != NULL) && (server->config.cert_path != NULL));
|
||||
}
|
||||
|
||||
static struct lws_context * wsfs_impl_server_context_create(
|
||||
struct wsfs_server * server)
|
||||
static struct lws_context * wf_impl_server_context_create(
|
||||
struct wf_server * server)
|
||||
{
|
||||
lws_set_log_level(WSFS_DISABLE_LWS_LOG, NULL);
|
||||
lws_set_log_level(WF_DISABLE_LWS_LOG, NULL);
|
||||
|
||||
memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WSFS_SERVER_PROTOCOL_COUNT);
|
||||
memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT);
|
||||
server->ws_protocols[0].name = "http";
|
||||
server->ws_protocols[0].callback = lws_callback_http_dummy;
|
||||
server->ws_protocols[1].name = "fs";
|
||||
wsfs_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]);
|
||||
wf_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]);
|
||||
|
||||
memset(&server->mount, 0, sizeof(struct lws_http_mount));
|
||||
server->mount.mount_next = NULL,
|
||||
@@ -66,7 +66,7 @@ static struct lws_context * wsfs_impl_server_context_create(
|
||||
server->info.mounts = NULL;
|
||||
}
|
||||
|
||||
if (wsfs_impl_server_tls_enabled(server))
|
||||
if (wf_impl_server_tls_enabled(server))
|
||||
{
|
||||
server->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
server->info.ssl_cert_filepath = server->config.cert_path;
|
||||
@@ -78,8 +78,8 @@ static struct lws_context * wsfs_impl_server_context_create(
|
||||
|
||||
}
|
||||
|
||||
static bool wsfs_impl_server_check_mountpoint(
|
||||
struct wsfs_server_config * config)
|
||||
static bool wf_impl_server_check_mountpoint(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
@@ -98,22 +98,22 @@ static bool wsfs_impl_server_check_mountpoint(
|
||||
return result;
|
||||
}
|
||||
|
||||
struct wsfs_server * wsfs_impl_server_create(
|
||||
struct wsfs_server_config * config)
|
||||
struct wf_server * wf_impl_server_create(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
struct wsfs_server * server = NULL;
|
||||
struct wf_server * server = NULL;
|
||||
|
||||
if (wsfs_impl_server_check_mountpoint(config))
|
||||
if (wf_impl_server_check_mountpoint(config))
|
||||
{
|
||||
server = malloc(sizeof(struct wsfs_server));
|
||||
server = malloc(sizeof(struct wf_server));
|
||||
if (NULL != server)
|
||||
{
|
||||
if (wsfs_impl_server_protocol_init(&server->protocol, config->mount_point))
|
||||
if (wf_impl_server_protocol_init(&server->protocol, config->mount_point))
|
||||
{
|
||||
server->shutdown_requested = false;
|
||||
wsfs_impl_server_config_clone(config, &server->config);
|
||||
wsfs_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
||||
server->context = wsfs_impl_server_context_create(server);
|
||||
wf_impl_server_config_clone(config, &server->config);
|
||||
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
||||
server->context = wf_impl_server_context_create(server);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -126,27 +126,27 @@ struct wsfs_server * wsfs_impl_server_create(
|
||||
return server;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_dispose(
|
||||
struct wsfs_server * server)
|
||||
void wf_impl_server_dispose(
|
||||
struct wf_server * server)
|
||||
{
|
||||
lws_context_destroy(server->context);
|
||||
wsfs_impl_server_protocol_cleanup(&server->protocol);
|
||||
wsfs_impl_server_config_cleanup(&server->config);
|
||||
wf_impl_server_protocol_cleanup(&server->protocol);
|
||||
wf_impl_server_config_cleanup(&server->config);
|
||||
free(server);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_run(
|
||||
struct wsfs_server * server)
|
||||
void wf_impl_server_run(
|
||||
struct wf_server * server)
|
||||
{
|
||||
int n = 0;
|
||||
while ((0 <= n) && (!server->shutdown_requested))
|
||||
{
|
||||
n = lws_service(server->context, WSFS_SERVER_TIMEOUT);
|
||||
n = lws_service(server->context, WF_SERVER_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfs_impl_server_shutdown(
|
||||
struct wsfs_server * server)
|
||||
void wf_impl_server_shutdown(
|
||||
struct wf_server * server)
|
||||
{
|
||||
server->shutdown_requested = true;
|
||||
}
|
||||
29
lib/webfuse/adapter/impl/server.h
Normal file
29
lib/webfuse/adapter/impl/server.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_server;
|
||||
struct wf_server_config;
|
||||
|
||||
extern struct wf_server * wf_impl_server_create(
|
||||
struct wf_server_config * config);
|
||||
|
||||
extern void wf_impl_server_dispose(
|
||||
struct wf_server * server);
|
||||
|
||||
extern void wf_impl_server_run(
|
||||
struct wf_server * server);
|
||||
|
||||
extern void wf_impl_server_shutdown(
|
||||
struct wf_server * server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
127
lib/webfuse/adapter/impl/server_config.c
Normal file
127
lib/webfuse/adapter/impl/server_config.c
Normal file
@@ -0,0 +1,127 @@
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char * wf_impl_server_config_strdup(char const * value)
|
||||
{
|
||||
char * result = NULL;
|
||||
if (NULL != value)
|
||||
{
|
||||
result = strdup(value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_server_config_init(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
memset(config, 0, sizeof(struct wf_server_config));
|
||||
|
||||
wf_impl_authenticators_init(&config->authenticators);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_cleanup(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
wf_impl_authenticators_cleanup(&config->authenticators);
|
||||
|
||||
free(config->mount_point);
|
||||
free(config->document_root);
|
||||
free(config->key_path);
|
||||
free(config->cert_path);
|
||||
free(config->vhost_name);
|
||||
|
||||
wf_impl_server_config_init(config);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_clone(
|
||||
struct wf_server_config * config,
|
||||
struct wf_server_config * clone)
|
||||
{
|
||||
clone->mount_point = wf_impl_server_config_strdup(config->mount_point);
|
||||
clone->document_root = wf_impl_server_config_strdup(config->document_root);
|
||||
clone->key_path = wf_impl_server_config_strdup(config->key_path);
|
||||
clone->cert_path = wf_impl_server_config_strdup(config->cert_path);
|
||||
clone->vhost_name = wf_impl_server_config_strdup(config->vhost_name);
|
||||
clone->port = config->port;
|
||||
|
||||
wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators);
|
||||
}
|
||||
|
||||
struct wf_server_config * wf_impl_server_config_create(void)
|
||||
{
|
||||
struct wf_server_config * config = malloc(sizeof(struct wf_server_config));
|
||||
if (NULL != config)
|
||||
{
|
||||
wf_impl_server_config_init(config);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
void wf_impl_server_config_dispose(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
wf_impl_server_config_cleanup(config);
|
||||
free(config);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_mountpoint(
|
||||
struct wf_server_config * config,
|
||||
char const * mount_point)
|
||||
{
|
||||
free(config->mount_point);
|
||||
config->mount_point = strdup(mount_point);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_documentroot(
|
||||
struct wf_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
free(config->document_root);
|
||||
config->document_root = strdup(document_root);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_keypath(
|
||||
struct wf_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
free(config->key_path);
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_certpath(
|
||||
struct wf_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
free(config->cert_path);
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_vhostname(
|
||||
struct wf_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
free(config->vhost_name);
|
||||
config->vhost_name = strdup(vhost_name);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_port(
|
||||
struct wf_server_config * config,
|
||||
int port)
|
||||
{
|
||||
config->port = port;
|
||||
}
|
||||
|
||||
void wf_impl_server_config_add_authenticator(
|
||||
struct wf_server_config * config,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
)
|
||||
{
|
||||
wf_impl_authenticators_add(&config->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
72
lib/webfuse/adapter/impl/server_config.h
Normal file
72
lib/webfuse/adapter/impl/server_config.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_server_config
|
||||
{
|
||||
char * mount_point;
|
||||
char * document_root;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * vhost_name;
|
||||
int port;
|
||||
struct wf_impl_authenticators authenticators;
|
||||
};
|
||||
|
||||
extern struct wf_server_config * wf_impl_server_config_create(void);
|
||||
|
||||
extern void wf_impl_server_config_dispose(
|
||||
struct wf_server_config * config);
|
||||
|
||||
extern void wf_impl_server_config_init(
|
||||
struct wf_server_config * config);
|
||||
|
||||
extern void wf_impl_server_config_cleanup(
|
||||
struct wf_server_config * config);
|
||||
|
||||
extern void wf_impl_server_config_clone(
|
||||
struct wf_server_config * config,
|
||||
struct wf_server_config * clone);
|
||||
|
||||
extern void wf_impl_server_config_set_mountpoint(
|
||||
struct wf_server_config * config,
|
||||
char const * mount_point);
|
||||
|
||||
extern void wf_impl_server_config_set_documentroot(
|
||||
struct wf_server_config * config,
|
||||
char const * document_root);
|
||||
|
||||
extern void wf_impl_server_config_set_keypath(
|
||||
struct wf_server_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void wf_impl_server_config_set_certpath(
|
||||
struct wf_server_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void wf_impl_server_config_set_vhostname(
|
||||
struct wf_server_config * config,
|
||||
char const * vhost_name);
|
||||
|
||||
extern void wf_impl_server_config_set_port(
|
||||
struct wf_server_config * config,
|
||||
int port);
|
||||
|
||||
extern void wf_impl_server_config_add_authenticator(
|
||||
struct wf_server_config * config,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
166
lib/webfuse/adapter/impl/server_protocol.c
Normal file
166
lib/webfuse/adapter/impl/server_protocol.c
Normal file
@@ -0,0 +1,166 @@
|
||||
#include "webfuse/adapter/impl/server_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
|
||||
static int wf_impl_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WF_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wf_server_protocol * protocol = ws_protocol->user;
|
||||
|
||||
wf_impl_timeout_manager_check(&protocol->timeout_manager);
|
||||
struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi);
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
{
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = wf_impl_filesystem_get_fd(&protocol->filesystem);
|
||||
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
|
||||
{
|
||||
fprintf(stderr, "error: unable to adopt fd");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wf_impl_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->rpc);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_impl_session_authenticate(session, NULL);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
wf_impl_session_manager_remove(&protocol->session_manager, wsi);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_impl_session_onwritable(session);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_impl_session_receive(session, in, len);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
wf_impl_filesystem_process_request(&protocol->filesystem);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
if (!wf_impl_server_protocol_init(protocol, mount_point))
|
||||
{
|
||||
free(protocol);
|
||||
protocol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_dispose(
|
||||
struct wf_server_protocol * protocol)
|
||||
{
|
||||
wf_impl_server_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_init_lws(
|
||||
struct wf_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wf_impl_server_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
bool wf_impl_server_protocol_init(
|
||||
struct wf_server_protocol * protocol,
|
||||
char * mount_point)
|
||||
{
|
||||
wf_impl_timeout_manager_init(&protocol->timeout_manager);
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_add_authenticator(
|
||||
struct wf_server_protocol * protocol,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wf_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
53
lib/webfuse/adapter/impl/server_protocol.h
Normal file
53
lib/webfuse/adapter/impl/server_protocol.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws_protocols;
|
||||
|
||||
struct wf_server_protocol
|
||||
{
|
||||
struct wf_impl_timeout_manager timeout_manager;
|
||||
struct wf_impl_filesystem filesystem;
|
||||
struct wf_impl_jsonrpc_server rpc;
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_session_manager session_manager;
|
||||
};
|
||||
|
||||
extern bool wf_impl_server_protocol_init(
|
||||
struct wf_server_protocol * protocol,
|
||||
char * mount_point);
|
||||
|
||||
extern void wf_impl_server_protocol_cleanup(
|
||||
struct wf_server_protocol * protocol);
|
||||
|
||||
extern struct wf_server_protocol * wf_impl_server_protocol_create(
|
||||
char * mount_point);
|
||||
|
||||
extern void wf_impl_server_protocol_dispose(
|
||||
struct wf_server_protocol * protocol);
|
||||
|
||||
extern void wf_impl_server_protocol_init_lws(
|
||||
struct wf_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
extern void wf_impl_server_protocol_add_authenticator(
|
||||
struct wf_server_protocol * protocol,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
84
lib/webfuse/adapter/impl/session.c
Normal file
84
lib/webfuse/adapter/impl/session.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#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)
|
||||
{
|
||||
wf_message_queue_cleanup(&session->queue);
|
||||
session->is_authenticated = false;
|
||||
session->wsi = NULL;
|
||||
session->authenticators = NULL;
|
||||
session->rpc = 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);
|
||||
}
|
||||
|
||||
bool wf_impl_session_send(
|
||||
struct wf_impl_session * session,
|
||||
struct wf_message * message)
|
||||
{
|
||||
bool result = (session->is_authenticated) && (NULL != session->wsi);
|
||||
|
||||
if (result)
|
||||
{
|
||||
wf_message_queue_push(&session->queue, message);
|
||||
lws_callback_on_writable(session->wsi);
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
wf_message_dispose(message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_session_onwritable(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
if (!wf_message_queue_empty(&session->queue))
|
||||
{
|
||||
struct wf_message * message = wf_message_queue_pop(&session->queue);
|
||||
lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||
wf_message_dispose(message);
|
||||
|
||||
if (!wf_message_queue_empty(&session->queue))
|
||||
{
|
||||
lws_callback_on_writable(session->wsi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_session_receive(
|
||||
struct wf_impl_session * session,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
wf_impl_jsonrpc_server_onresult(session->rpc, data, length);
|
||||
}
|
||||
64
lib/webfuse/adapter/impl/session.h
Normal file
64
lib/webfuse/adapter/impl/session.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SESSION_H
|
||||
#define WF_ADAPTER_IMPL_SESSION_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "webfuse/core/message_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wf_message;
|
||||
struct wf_credentials;
|
||||
struct wf_impl_authenticators;
|
||||
struct wf_impl_jsonrpc_server;
|
||||
|
||||
struct wf_impl_session
|
||||
{
|
||||
struct lws * wsi;
|
||||
bool is_authenticated;
|
||||
struct wf_message_queue queue;
|
||||
struct wf_impl_authenticators * authenticators;
|
||||
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);
|
||||
|
||||
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,
|
||||
size_t length);
|
||||
|
||||
extern void wf_impl_session_onwritable(
|
||||
struct wf_impl_session * session);
|
||||
|
||||
extern void wf_impl_session_cleanup(
|
||||
struct wf_impl_session * session);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
54
lib/webfuse/adapter/impl/session_manager.c
Normal file
54
lib/webfuse/adapter/impl/session_manager.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void wf_impl_session_manager_init(
|
||||
struct wf_impl_session_manager * manager)
|
||||
{
|
||||
wf_impl_session_init(&manager->session, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void wf_impl_session_manager_cleanup(
|
||||
struct wf_impl_session_manager * manager)
|
||||
{
|
||||
wf_impl_session_cleanup(&manager->session);
|
||||
}
|
||||
|
||||
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_session * session = NULL;
|
||||
if (NULL == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
wf_impl_session_init(&manager->session, wsi, authenticators, rpc);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wf_impl_session * session = NULL;
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
void wf_impl_session_manager_remove(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
wf_impl_session_cleanup(&manager->session);
|
||||
manager->session.wsi = NULL;
|
||||
}
|
||||
}
|
||||
46
lib/webfuse/adapter/impl/session_manager.h
Normal file
46
lib/webfuse/adapter/impl/session_manager.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SESSION_MANAGER_H
|
||||
#define WF_ADAPTER_IMPL_SESSION_MANAGER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
|
||||
struct wf_impl_session_manager
|
||||
{
|
||||
struct wf_impl_session session;
|
||||
};
|
||||
|
||||
extern void wf_impl_session_manager_init(
|
||||
struct wf_impl_session_manager * manager);
|
||||
|
||||
extern void wf_impl_session_manager_cleanup(
|
||||
struct wf_impl_session_manager * manager);
|
||||
|
||||
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);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
extern void wf_impl_session_manager_remove(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
84
lib/webfuse/adapter/impl/time/timeout_manager.c
Normal file
84
lib/webfuse/adapter/impl/time/timeout_manager.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "webfuse/adapter/impl/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "webfuse/adapter/impl/time/timer_intern.h"
|
||||
#include "webfuse/adapter/impl/time/timepoint.h"
|
||||
|
||||
void wf_impl_timeout_manager_init(
|
||||
struct wf_impl_timeout_manager * manager)
|
||||
{
|
||||
manager->timers = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_timeout_manager_cleanup(
|
||||
struct wf_impl_timeout_manager * manager)
|
||||
{
|
||||
struct wf_impl_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wf_impl_timer * next = timer->next;
|
||||
|
||||
wf_impl_timer_trigger(timer);
|
||||
|
||||
timer = next;
|
||||
}
|
||||
|
||||
manager->timers = NULL;
|
||||
|
||||
}
|
||||
|
||||
void wf_impl_timeout_manager_check(
|
||||
struct wf_impl_timeout_manager * manager)
|
||||
{
|
||||
struct wf_impl_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wf_impl_timer * next = timer->next;
|
||||
|
||||
if (wf_impl_timer_is_timeout(timer))
|
||||
{
|
||||
wf_impl_timeout_manager_removetimer(manager, timer);
|
||||
wf_impl_timer_trigger(timer);
|
||||
}
|
||||
|
||||
timer = next;
|
||||
}
|
||||
}
|
||||
|
||||
void wf_impl_timeout_manager_addtimer(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
if (NULL != manager->timers)
|
||||
{
|
||||
manager->timers->prev = timer;
|
||||
}
|
||||
|
||||
timer->next = manager->timers;
|
||||
timer->prev = NULL;
|
||||
manager->timers = timer;
|
||||
}
|
||||
|
||||
void wf_impl_timeout_manager_removetimer(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
struct wf_impl_timer * prev = timer->prev;
|
||||
struct wf_impl_timer * next = timer->next;
|
||||
|
||||
if (NULL != prev)
|
||||
{
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
if (NULL != next)
|
||||
{
|
||||
next->prev = prev;
|
||||
}
|
||||
|
||||
if (manager->timers == timer)
|
||||
{
|
||||
manager->timers = next;
|
||||
}
|
||||
}
|
||||
|
||||
29
lib/webfuse/adapter/impl/time/timeout_manager.h
Normal file
29
lib/webfuse/adapter/impl/time/timeout_manager.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_timer;
|
||||
struct wf_impl_timeout_manager
|
||||
{
|
||||
struct wf_impl_timer * timers;
|
||||
};
|
||||
|
||||
extern void wf_impl_timeout_manager_init(
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
extern void wf_impl_timeout_manager_cleanup(
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
extern void wf_impl_timeout_manager_check(
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
24
lib/webfuse/adapter/impl/time/timeout_manager_intern.h
Normal file
24
lib/webfuse/adapter/impl/time/timeout_manager_intern.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wf_impl_timeout_manager_addtimer(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
extern void wf_impl_timeout_manager_removetimer(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
31
lib/webfuse/adapter/impl/time/timepoint.c
Normal file
31
lib/webfuse/adapter/impl/time/timepoint.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "webfuse/adapter/impl/time/timepoint.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define WF_MSEC_PER_SEC ((wf_impl_timepoint) 1000)
|
||||
#define WF_NSEC_PER_MSEC ((wf_impl_timepoint) 1000 * 1000)
|
||||
|
||||
wf_impl_timepoint wf_impl_timepoint_now(void)
|
||||
{
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
|
||||
wf_impl_timepoint const now = (tp.tv_sec * WF_MSEC_PER_SEC) + (tp.tv_nsec / WF_NSEC_PER_MSEC);
|
||||
return now;
|
||||
}
|
||||
|
||||
wf_impl_timepoint wf_impl_timepoint_in_msec(wf_impl_timediff value)
|
||||
{
|
||||
wf_impl_timepoint const now = wf_impl_timepoint_now();
|
||||
wf_impl_timepoint result = now + ((wf_impl_timepoint) value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool wf_impl_timepoint_is_elapsed(wf_impl_timepoint tp)
|
||||
{
|
||||
wf_impl_timepoint const now = wf_impl_timepoint_now();
|
||||
wf_impl_timediff const diff = (wf_impl_timediff) (tp - now);
|
||||
|
||||
return (0 > diff);
|
||||
}
|
||||
31
lib/webfuse/adapter/impl/time/timepoint.h
Normal file
31
lib/webfuse/adapter/impl/time/timepoint.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMEPOINT_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMEPOINT_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef uint64_t wf_impl_timepoint;
|
||||
typedef int64_t wf_impl_timediff;
|
||||
|
||||
extern wf_impl_timepoint wf_impl_timepoint_now(void);
|
||||
|
||||
extern wf_impl_timepoint wf_impl_timepoint_in_msec(
|
||||
wf_impl_timediff value);
|
||||
|
||||
extern bool wf_impl_timepoint_is_elapsed(
|
||||
wf_impl_timepoint timepoint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
65
lib/webfuse/adapter/impl/time/timer.c
Normal file
65
lib/webfuse/adapter/impl/time/timer.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "webfuse/adapter/impl/time/timer_intern.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void wf_impl_timer_init(
|
||||
struct wf_impl_timer * timer,
|
||||
struct wf_impl_timeout_manager * manager)
|
||||
{
|
||||
timer->manager = manager;
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_timer_cleanup(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
memset(timer, 0, sizeof(struct wf_impl_timer));
|
||||
}
|
||||
|
||||
void wf_impl_timer_start(
|
||||
struct wf_impl_timer * timer,
|
||||
wf_impl_timepoint absolute_timeout,
|
||||
wf_impl_timer_timeout_fn * handler,
|
||||
void * user_data)
|
||||
{
|
||||
timer->timeout = absolute_timeout;
|
||||
timer->timeout_handler = handler;
|
||||
timer->user_data = user_data;
|
||||
|
||||
wf_impl_timeout_manager_addtimer(timer->manager, timer);
|
||||
}
|
||||
|
||||
void wf_impl_timer_cancel(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
wf_impl_timeout_manager_removetimer(timer->manager, timer);
|
||||
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
}
|
||||
|
||||
bool wf_impl_timer_is_timeout(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
return wf_impl_timepoint_is_elapsed(timer->timeout);
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_timer_trigger(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
if (NULL != timer->timeout_handler)
|
||||
{
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
|
||||
timer->timeout_handler(timer);
|
||||
}
|
||||
}
|
||||
48
lib/webfuse/adapter/impl/time/timer.h
Normal file
48
lib/webfuse/adapter/impl/time/timer.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMER_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMER_H
|
||||
|
||||
#include "webfuse/adapter/impl/time/timepoint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_timer;
|
||||
struct wf_impl_timeout_manager;
|
||||
|
||||
typedef void wf_impl_timer_timeout_fn(struct wf_impl_timer * timer);
|
||||
|
||||
struct wf_impl_timer
|
||||
{
|
||||
struct wf_impl_timeout_manager * manager;
|
||||
wf_impl_timepoint timeout;
|
||||
wf_impl_timer_timeout_fn * timeout_handler;
|
||||
void * user_data;
|
||||
struct wf_impl_timer * next;
|
||||
struct wf_impl_timer * prev;
|
||||
};
|
||||
|
||||
extern void wf_impl_timer_init(
|
||||
struct wf_impl_timer * timer,
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
extern void wf_impl_timer_cleanup(
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
extern void wf_impl_timer_start(
|
||||
struct wf_impl_timer * timer,
|
||||
wf_impl_timepoint absolute_timeout,
|
||||
wf_impl_timer_timeout_fn * handler,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_timer_cancel(
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
25
lib/webfuse/adapter/impl/time/timer_intern.h
Normal file
25
lib/webfuse/adapter/impl/time/timer_intern.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMER_INTERN_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMER_INTERN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/impl/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wf_impl_timer_is_timeout(
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
extern void wf_impl_timer_trigger(
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
32
lib/webfuse/core/message.c
Normal file
32
lib/webfuse/core/message.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "webfuse/core/message.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
extern struct wf_message * wf_message_create(json_t const * value)
|
||||
{
|
||||
struct wf_message * message = NULL;
|
||||
size_t const length = json_dumpb(value, NULL, 0, JSON_COMPACT);
|
||||
|
||||
if (0 < length)
|
||||
{
|
||||
char * data = malloc(sizeof(struct wf_message) + LWS_PRE + length);
|
||||
message = (struct wf_message *) data;
|
||||
if (NULL != message)
|
||||
{
|
||||
message->data = &data[sizeof(struct wf_message) + LWS_PRE];
|
||||
message->length = length;
|
||||
message->next = NULL;
|
||||
|
||||
json_dumpb(value, message->data, length, JSON_COMPACT);
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
void wf_message_dispose(
|
||||
struct wf_message * message)
|
||||
{
|
||||
free(message);
|
||||
}
|
||||
34
lib/webfuse/core/message.h
Normal file
34
lib/webfuse/core/message.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef WF_MESSAGE_H
|
||||
#define WF_MESSAGE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
struct wf_message
|
||||
{
|
||||
struct wf_message * next;
|
||||
char * data;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wf_message * wf_message_create(json_t const * value);
|
||||
|
||||
extern void wf_message_dispose(
|
||||
struct wf_message * message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
63
lib/webfuse/core/message_queue.c
Normal file
63
lib/webfuse/core/message_queue.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/core/message.h"
|
||||
|
||||
void wf_message_queue_init(
|
||||
struct wf_message_queue * queue)
|
||||
{
|
||||
queue->first = NULL;
|
||||
queue->last = NULL;
|
||||
|
||||
}
|
||||
|
||||
void wf_message_queue_cleanup(
|
||||
struct wf_message_queue * queue)
|
||||
{
|
||||
struct wf_message * message = queue->first;
|
||||
while (NULL != message)
|
||||
{
|
||||
struct wf_message * next = message->next;
|
||||
wf_message_dispose(message);
|
||||
message = next;
|
||||
}
|
||||
wf_message_queue_init(queue);
|
||||
}
|
||||
|
||||
bool wf_message_queue_empty(
|
||||
struct wf_message_queue * queue)
|
||||
{
|
||||
return (NULL == queue->first);
|
||||
}
|
||||
|
||||
void wf_message_queue_push(
|
||||
struct wf_message_queue * queue,
|
||||
struct wf_message * message)
|
||||
{
|
||||
message->next = NULL;
|
||||
|
||||
if (NULL != queue->last)
|
||||
{
|
||||
queue->last->next = message;
|
||||
queue->last = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->first = message;
|
||||
queue->last = message;
|
||||
}
|
||||
}
|
||||
|
||||
struct wf_message * wf_message_queue_pop(
|
||||
struct wf_message_queue * queue)
|
||||
{
|
||||
struct wf_message * const result = queue->first;
|
||||
if (NULL != result)
|
||||
{
|
||||
queue->first = queue->first->next;
|
||||
if (NULL == queue->first)
|
||||
{
|
||||
queue->last = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
42
lib/webfuse/core/message_queue.h
Normal file
42
lib/webfuse/core/message_queue.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef WF_MESSAGE_QUEUE_H
|
||||
#define WF_MESSAGE_QUEUE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
struct wf_message_queue;
|
||||
struct wf_message;
|
||||
|
||||
struct wf_message_queue
|
||||
{
|
||||
struct wf_message * first;
|
||||
struct wf_message * last;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wf_message_queue_init(
|
||||
struct wf_message_queue * queue);
|
||||
|
||||
extern void wf_message_queue_cleanup(
|
||||
struct wf_message_queue * queue);
|
||||
|
||||
extern bool wf_message_queue_empty(
|
||||
struct wf_message_queue * queue);
|
||||
|
||||
extern void wf_message_queue_push(
|
||||
struct wf_message_queue * queue,
|
||||
struct wf_message * message);
|
||||
|
||||
extern struct wf_message * wf_message_queue_pop(
|
||||
struct wf_message_queue * queue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
34
lib/webfuse/core/status.c
Normal file
34
lib/webfuse/core/status.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "webfuse/core/status_intern.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
int wf_status_to_rc(wf_status status)
|
||||
{
|
||||
switch(status)
|
||||
{
|
||||
case WF_GOOD: return 0;
|
||||
case WF_BAD_NOTIMPLEMENTED: return -ENOSYS;
|
||||
case WF_BAD_TIMEOUT: return -ETIMEDOUT;
|
||||
case WF_BAD_BUSY: return -ENOENT;
|
||||
case WF_BAD_FORMAT: return -ENOENT;
|
||||
case WF_BAD_NOENTRY: return -ENOENT;
|
||||
case WF_BAD_NOACCESS: return -EACCES;
|
||||
default: return -ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
char const * wf_status_tostring(wf_status status)
|
||||
{
|
||||
switch(status)
|
||||
{
|
||||
case WF_GOOD: return "Good";
|
||||
case WF_BAD: return "Bad";
|
||||
case WF_BAD_NOTIMPLEMENTED: return "Bad (not implelemted)";
|
||||
case WF_BAD_TIMEOUT: return "Bad (timeout)";
|
||||
case WF_BAD_BUSY: return "Bad (busy)";
|
||||
case WF_BAD_FORMAT: return "Bad (format)";
|
||||
case WF_BAD_NOENTRY: return "Bad (no entry)";
|
||||
case WF_BAD_NOACCESS: return "Bad (no access)";
|
||||
default: return "Bad (unknown)";
|
||||
}
|
||||
}
|
||||
19
lib/webfuse/core/status_intern.h
Normal file
19
lib/webfuse/core/status_intern.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef WF_STATUS_INTERN_H
|
||||
#define WF_STATUS_INTERN_H
|
||||
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int wf_status_to_rc(wf_status status);
|
||||
|
||||
extern char const * wf_status_tostring(wf_status status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
10
lib/webfuse/core/util.h
Normal file
10
lib/webfuse/core/util.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef WF_UTIL_H
|
||||
#define WF_UTIL_H
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define WF_UNUSED_PARAM(param) param __attribute__((unused))
|
||||
#else
|
||||
#define WF_UNUSED_PARAM(param)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
240
lib/webfuse/provider/api.c
Normal file
240
lib/webfuse/provider/api.c
Normal file
@@ -0,0 +1,240 @@
|
||||
#include "webfuse_provider.h"
|
||||
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/provider/impl/operation/getattr.h"
|
||||
#include "webfuse/provider/impl/operation/lookup.h"
|
||||
#include "webfuse/provider/impl/operation/readdir.h"
|
||||
#include "webfuse/provider/impl/operation/open.h"
|
||||
#include "webfuse/provider/impl/operation/close.h"
|
||||
#include "webfuse/provider/impl/operation/read.h"
|
||||
#include "webfuse/provider/impl/client_protocol.h"
|
||||
#include "webfuse/provider/impl/client_config.h"
|
||||
#include "webfuse/provider/impl/client.h"
|
||||
#include "webfuse/provider/impl/dirbuffer.h"
|
||||
|
||||
// respond
|
||||
|
||||
void wfp_respond_error(
|
||||
struct wfp_request * request,
|
||||
wf_status status)
|
||||
{
|
||||
wfp_impl_respond_error(request, status);
|
||||
}
|
||||
|
||||
void wfp_respond_getattr(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
wfp_impl_respond_getattr(request, stat);
|
||||
}
|
||||
|
||||
void wfp_respond_lookup(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
wfp_impl_respond_lookup(request, stat);
|
||||
}
|
||||
|
||||
void wfp_respond_open(
|
||||
struct wfp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
wfp_impl_respond_open(request, handle);
|
||||
}
|
||||
|
||||
void wfp_respond_read(
|
||||
struct wfp_request * request,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
wfp_impl_respond_read(request, data, length);
|
||||
}
|
||||
|
||||
void wfp_respond_readdir(
|
||||
struct wfp_request * request,
|
||||
struct wfp_dirbuffer * dirbuffer)
|
||||
{
|
||||
wfp_impl_respond_readdir(request, dirbuffer);
|
||||
}
|
||||
|
||||
// config
|
||||
|
||||
|
||||
struct wfp_client_config * wfp_client_config_create(void)
|
||||
{
|
||||
return wfp_impl_client_config_create();
|
||||
}
|
||||
|
||||
void wfp_client_config_dispose(
|
||||
struct wfp_client_config * config)
|
||||
{
|
||||
wfp_impl_client_config_dispose(config);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_userdata(
|
||||
struct wfp_client_config * config,
|
||||
void * user_data)
|
||||
{
|
||||
wfp_impl_client_config_set_userdata(config, user_data);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_keypath(
|
||||
struct wfp_client_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wfp_impl_client_config_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_certpath(
|
||||
struct wfp_client_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wfp_impl_client_config_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_onconnected(
|
||||
struct wfp_client_config * config,
|
||||
wfp_connected_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_onconnected(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_ondisconnected(
|
||||
struct wfp_client_config * config,
|
||||
wfp_disconnected_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_ondisconnected(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_ontimer(
|
||||
struct wfp_client_config * config,
|
||||
wfp_ontimer_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_ontimer(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_onlookup(
|
||||
struct wfp_client_config * config,
|
||||
wfp_lookup_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_onlookup(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_ongetattr(
|
||||
struct wfp_client_config * config,
|
||||
wfp_getattr_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_ongetattr(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_onreaddir(
|
||||
struct wfp_client_config * config,
|
||||
wfp_readdir_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_onreaddir(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_onopen(
|
||||
struct wfp_client_config * config,
|
||||
wfp_open_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_onopen(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_onclose(
|
||||
struct wfp_client_config * config,
|
||||
wfp_close_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_onclose(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_onread(
|
||||
struct wfp_client_config * config,
|
||||
wfp_read_fn * handler)
|
||||
{
|
||||
wfp_impl_client_config_set_onread(config, handler);
|
||||
}
|
||||
|
||||
// protocol
|
||||
|
||||
|
||||
struct wfp_client_protocol * wfp_client_protocol_create(
|
||||
struct wfp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
return wfp_impl_client_protocol_create(provider, user_data);
|
||||
}
|
||||
|
||||
void wfp_client_protocol_dispose(
|
||||
struct wfp_client_protocol * protocol)
|
||||
{
|
||||
wfp_impl_client_protocol_dispose(protocol);
|
||||
}
|
||||
|
||||
void wfp_client_protocol_init_lws(
|
||||
struct wfp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
wfp_impl_client_protocol_init_lws(protocol, lws_protocol);
|
||||
}
|
||||
|
||||
// client
|
||||
|
||||
struct wfp_client * wfp_client_create(
|
||||
struct wfp_client_config * config)
|
||||
{
|
||||
return wfp_impl_client_create(config);
|
||||
}
|
||||
|
||||
void wfp_client_connect(
|
||||
struct wfp_client * client,
|
||||
char const * url)
|
||||
{
|
||||
wfp_impl_client_connect(client, url);
|
||||
}
|
||||
|
||||
void wfp_client_disconnect(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
wfp_impl_client_disconnect(client);
|
||||
}
|
||||
|
||||
void wfp_client_dispose(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
wfp_impl_client_dispose(client);
|
||||
}
|
||||
|
||||
void wfp_client_run(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
wfp_impl_client_run(client);
|
||||
}
|
||||
|
||||
void wfp_client_shutdown(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
wfp_impl_client_shutdown(client);
|
||||
}
|
||||
|
||||
// dirbuffer
|
||||
|
||||
struct wfp_dirbuffer * wfp_dirbuffer_create(void)
|
||||
{
|
||||
return wfp_impl_dirbuffer_create();
|
||||
}
|
||||
|
||||
void wfp_dirbuffer_dispose(
|
||||
struct wfp_dirbuffer * buffer)
|
||||
{
|
||||
wfp_impl_dirbuffer_dispose(buffer);
|
||||
}
|
||||
|
||||
void wfp_dirbuffer_add(
|
||||
struct wfp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode)
|
||||
{
|
||||
wfp_impl_dirbuffer_add(buffer, name, inode);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/provider/impl/client.h"
|
||||
#include "webfuse/provider/impl/client.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -6,42 +6,42 @@
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include "wsfs/provider/impl/client_protocol.h"
|
||||
#include "wsfs/provider/impl/client_config.h"
|
||||
#include "wsfs/provider/impl/url.h"
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
#include "webfuse/provider/impl/client_protocol.h"
|
||||
#include "webfuse/provider/impl/client_config.h"
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
|
||||
#define WSFSP_PROTOCOL ("fs")
|
||||
#define WSFSP_DISABLE_LWS_LOG 0
|
||||
#define WSFSP_CLIENT_PROTOCOL_COUNT 2
|
||||
#define WSFSP_CLIENT_TIMEOUT (1 * 1000)
|
||||
#define WFP_PROTOCOL ("fs")
|
||||
#define WFP_DISABLE_LWS_LOG 0
|
||||
#define WFP_CLIENT_PROTOCOL_COUNT 2
|
||||
#define WFP_CLIENT_TIMEOUT (1 * 1000)
|
||||
|
||||
struct wsfsp_client
|
||||
struct wfp_client
|
||||
{
|
||||
volatile bool is_running;
|
||||
struct wsfsp_client_protocol protocol;
|
||||
struct wfp_client_protocol protocol;
|
||||
struct lws_context_creation_info info;
|
||||
struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT];
|
||||
struct lws_protocols protocols[WFP_CLIENT_PROTOCOL_COUNT];
|
||||
struct lws_context * context;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
};
|
||||
|
||||
|
||||
struct wsfsp_client * wsfsp_impl_client_create(
|
||||
struct wsfsp_client_config * config)
|
||||
struct wfp_client * wfp_impl_client_create(
|
||||
struct wfp_client_config * config)
|
||||
{
|
||||
lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL);
|
||||
lws_set_log_level(WFP_DISABLE_LWS_LOG, NULL);
|
||||
|
||||
struct wsfsp_client * client = malloc(sizeof(struct wsfsp_client));
|
||||
struct wfp_client * client = malloc(sizeof(struct wfp_client));
|
||||
if (NULL != client)
|
||||
{
|
||||
client->is_running = true;
|
||||
wsfsp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
||||
wfp_impl_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) * WFP_CLIENT_PROTOCOL_COUNT);
|
||||
client->protocols[0].name = "fs";
|
||||
wsfsp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||
|
||||
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
|
||||
client->info.port = CONTEXT_PORT_NO_LISTEN;
|
||||
@@ -60,20 +60,20 @@ struct wsfsp_client * wsfsp_impl_client_create(
|
||||
return client;
|
||||
}
|
||||
|
||||
void wsfsp_impl_client_dispose(
|
||||
struct wsfsp_client * client)
|
||||
void wfp_impl_client_dispose(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
lws_context_destroy(client->context);
|
||||
wsfsp_impl_client_protocol_cleanup(&client->protocol);
|
||||
wfp_impl_client_protocol_cleanup(&client->protocol);
|
||||
free(client);
|
||||
}
|
||||
|
||||
void wsfsp_impl_client_connect(
|
||||
struct wsfsp_client * client,
|
||||
void wfp_impl_client_connect(
|
||||
struct wfp_client * client,
|
||||
char const * url)
|
||||
{
|
||||
struct wsfsp_impl_url url_data;
|
||||
bool const success = wsfsp_impl_url_init(&url_data, url);
|
||||
struct wfp_impl_url url_data;
|
||||
bool const success = wfp_impl_url_init(&url_data, url);
|
||||
if (success)
|
||||
{
|
||||
struct lws_client_connect_info info;
|
||||
@@ -85,34 +85,34 @@ void wsfsp_impl_client_connect(
|
||||
info.host = info.address;
|
||||
info.origin = info.address;
|
||||
info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0;
|
||||
info.protocol = WSFSP_PROTOCOL;
|
||||
info.protocol = WFP_PROTOCOL;
|
||||
info.pwsi = &client->protocol.wsi;
|
||||
|
||||
lws_client_connect_via_info(&info);
|
||||
|
||||
wsfsp_impl_url_cleanup(&url_data);
|
||||
wfp_impl_url_cleanup(&url_data);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_impl_client_disconnect(
|
||||
struct wsfsp_client * client)
|
||||
void wfp_impl_client_disconnect(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
(void) client;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void wsfsp_impl_client_run(
|
||||
struct wsfsp_client * client)
|
||||
void wfp_impl_client_run(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
while (client->is_running)
|
||||
{
|
||||
lws_service(client->context, WSFSP_CLIENT_TIMEOUT);
|
||||
lws_service(client->context, WFP_CLIENT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_impl_client_shutdown(
|
||||
struct wsfsp_client * client)
|
||||
void wfp_impl_client_shutdown(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
client->is_running = false;
|
||||
}
|
||||
49
lib/webfuse/provider/impl/client.h
Normal file
49
lib/webfuse/provider/impl/client.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef WF_PROVIDER_IMPL_CLIENT_H
|
||||
#define WF_PROVIDER_IMPL_CLIENT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_client;
|
||||
struct wfp_client_config;
|
||||
|
||||
extern struct wfp_client * wfp_impl_client_create(
|
||||
struct wfp_client_config * config);
|
||||
|
||||
extern void wfp_impl_client_set_keypath(
|
||||
struct wfp_client * client,
|
||||
char * key_path);
|
||||
|
||||
extern void wfp_impl_client_set_certpath(
|
||||
struct wfp_client * client,
|
||||
char * cert_path);
|
||||
|
||||
extern void wfp_impl_client_connect(
|
||||
struct wfp_client * client,
|
||||
char const * url);
|
||||
|
||||
extern void wfp_impl_client_disconnect(
|
||||
struct wfp_client * client);
|
||||
|
||||
extern void wfp_impl_client_settimeout(
|
||||
struct wfp_client * client,
|
||||
unsigned int timepoint);
|
||||
|
||||
extern void wfp_impl_client_dispose(
|
||||
struct wfp_client * client);
|
||||
|
||||
extern void wfp_impl_client_run(
|
||||
struct wfp_client * client);
|
||||
|
||||
extern void wfp_impl_client_shutdown(
|
||||
struct wfp_client * client);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
112
lib/webfuse/provider/impl/client_config.c
Normal file
112
lib/webfuse/provider/impl/client_config.c
Normal file
@@ -0,0 +1,112 @@
|
||||
#include "webfuse/provider/impl/client_config.h"
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wfp_client_config * wfp_impl_client_config_create(void)
|
||||
{
|
||||
struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config));
|
||||
if (NULL != config)
|
||||
{
|
||||
wfp_impl_provider_init(&config->provider);
|
||||
config->user_data = NULL;
|
||||
config->key_path = NULL;
|
||||
config->cert_path = NULL;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_dispose(
|
||||
struct wfp_client_config * config)
|
||||
{
|
||||
free(config->key_path);
|
||||
free(config->cert_path);
|
||||
free(config);
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_userdata(
|
||||
struct wfp_client_config * config,
|
||||
void * user_data)
|
||||
{
|
||||
config->user_data = user_data;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_keypath(
|
||||
struct wfp_client_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
free(config->key_path);
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_certpath(
|
||||
struct wfp_client_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
free(config->cert_path);
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_onconnected(
|
||||
struct wfp_client_config * config,
|
||||
wfp_connected_fn * handler)
|
||||
{
|
||||
config->provider.connected = handler;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_ondisconnected(
|
||||
struct wfp_client_config * config,
|
||||
wfp_disconnected_fn * handler)
|
||||
{
|
||||
config->provider.disconnected = handler;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_ontimer(
|
||||
struct wfp_client_config * config,
|
||||
wfp_ontimer_fn * handler)
|
||||
{
|
||||
config->provider.ontimer = handler;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_onlookup(
|
||||
struct wfp_client_config * config,
|
||||
wfp_lookup_fn * handler)
|
||||
{
|
||||
config->provider.lookup = handler;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_ongetattr(
|
||||
struct wfp_client_config * config,
|
||||
wfp_getattr_fn * handler)
|
||||
{
|
||||
config->provider.getattr = handler;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_onreaddir(
|
||||
struct wfp_client_config * config,
|
||||
wfp_readdir_fn * handler)
|
||||
{
|
||||
config->provider.readdir = handler;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_onopen(
|
||||
struct wfp_client_config * config,
|
||||
wfp_open_fn * handler)
|
||||
{
|
||||
config->provider.open = handler;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_onclose(
|
||||
struct wfp_client_config * config,
|
||||
wfp_close_fn * handler)
|
||||
{
|
||||
config->provider.close = handler;
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_onread(
|
||||
struct wfp_client_config * config,
|
||||
wfp_read_fn * handler)
|
||||
{
|
||||
config->provider.read = handler;
|
||||
}
|
||||
77
lib/webfuse/provider/impl/client_config.h
Normal file
77
lib/webfuse/provider/impl/client_config.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef WF_PROVIDER_IMPL_CLIENT_CONFIG_H
|
||||
#define WF_PROVIDER_IMPL_CLIENT_CONFIG_H
|
||||
|
||||
#include "webfuse/provider/client_config.h"
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_client_config
|
||||
{
|
||||
struct wfp_provider provider;
|
||||
void * user_data;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
};
|
||||
|
||||
extern struct wfp_client_config * wfp_impl_client_config_create(void);
|
||||
|
||||
extern void wfp_impl_client_config_dispose(
|
||||
struct wfp_client_config * config);
|
||||
|
||||
extern void wfp_impl_client_config_set_userdata(
|
||||
struct wfp_client_config * config,
|
||||
void * user_data);
|
||||
|
||||
extern void wfp_impl_client_config_set_keypath(
|
||||
struct wfp_client_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void wfp_impl_client_config_set_certpath(
|
||||
struct wfp_client_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void wfp_impl_client_config_set_onconnected(
|
||||
struct wfp_client_config * config,
|
||||
wfp_connected_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_ondisconnected(
|
||||
struct wfp_client_config * config,
|
||||
wfp_disconnected_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_ontimer(
|
||||
struct wfp_client_config * config,
|
||||
wfp_ontimer_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_onlookup(
|
||||
struct wfp_client_config * config,
|
||||
wfp_lookup_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_ongetattr(
|
||||
struct wfp_client_config * config,
|
||||
wfp_getattr_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_onreaddir(
|
||||
struct wfp_client_config * config,
|
||||
wfp_readdir_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_onopen(
|
||||
struct wfp_client_config * config,
|
||||
wfp_open_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_onclose(
|
||||
struct wfp_client_config * config,
|
||||
wfp_close_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_onread(
|
||||
struct wfp_client_config * config,
|
||||
wfp_read_fn * handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
149
lib/webfuse/provider/impl/client_protocol.c
Normal file
149
lib/webfuse/provider/impl/client_protocol.c
Normal file
@@ -0,0 +1,149 @@
|
||||
#include "webfuse/provider/impl/client_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <jansson.h>
|
||||
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/message.h"
|
||||
|
||||
static void wfp_impl_client_protocol_respond(
|
||||
json_t * response,
|
||||
void * user_data)
|
||||
{
|
||||
struct wfp_client_protocol * protocol = (struct wfp_client_protocol *) user_data;
|
||||
|
||||
struct wf_message * message = wf_message_create(response);
|
||||
if (NULL != message)
|
||||
{
|
||||
wf_message_queue_push(&protocol->queue, message);
|
||||
lws_callback_on_writable(protocol->wsi);
|
||||
}
|
||||
}
|
||||
|
||||
static void wfp_impl_client_protocol_process_request(
|
||||
struct wfp_client_protocol * protocol,
|
||||
char const * message,
|
||||
size_t length)
|
||||
{
|
||||
json_t * request = json_loadb(message, length, 0, NULL);
|
||||
if (NULL != request)
|
||||
{
|
||||
struct wfp_impl_invokation_context context =
|
||||
{
|
||||
.provider = &protocol->provider,
|
||||
.user_data = protocol->user_data,
|
||||
.request = &protocol->request
|
||||
};
|
||||
|
||||
wfp_impl_provider_invoke(&context, request);
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int wfp_impl_client_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WF_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wfp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL;
|
||||
|
||||
if (NULL != protocol)
|
||||
{
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||
protocol->provider.disconnected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CLOSED:
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||
wfp_impl_client_protocol_process_request(protocol, in, len);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
// fall-through
|
||||
case LWS_CALLBACK_CLIENT_WRITEABLE:
|
||||
if ((wsi == protocol->wsi) && (!wf_message_queue_empty(&protocol->queue)))
|
||||
{
|
||||
struct wf_message * message = wf_message_queue_pop(&protocol->queue);
|
||||
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||
wf_message_dispose(message);
|
||||
|
||||
if (!wf_message_queue_empty(&protocol->queue))
|
||||
{
|
||||
lws_callback_on_writable(wsi);
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void wfp_impl_client_protocol_init(
|
||||
struct wfp_client_protocol * protocol,
|
||||
struct wfp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
wf_message_queue_init(&protocol->queue);
|
||||
|
||||
protocol->wsi = NULL;
|
||||
|
||||
protocol->request.respond = &wfp_impl_client_protocol_respond;
|
||||
protocol->request.user_data = protocol;
|
||||
|
||||
protocol->user_data = user_data;
|
||||
wfp_impl_provider_init_from_prototype(&protocol->provider, provider);
|
||||
}
|
||||
|
||||
void wfp_impl_client_protocol_cleanup(
|
||||
struct wfp_client_protocol * protocol)
|
||||
{
|
||||
wf_message_queue_cleanup(&protocol->queue);
|
||||
}
|
||||
|
||||
struct wfp_client_protocol * wfp_impl_client_protocol_create(
|
||||
struct wfp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
wfp_impl_client_protocol_init(protocol, provider, user_data);
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wfp_impl_client_protocol_dispose(
|
||||
struct wfp_client_protocol * protocol)
|
||||
{
|
||||
wfp_impl_client_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wfp_impl_client_protocol_init_lws(
|
||||
struct wfp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wfp_impl_client_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
49
lib/webfuse/provider/impl/client_protocol.h
Normal file
49
lib/webfuse/provider/impl/client_protocol.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef WF_PROVIDER_IMPL_CLIENT_PROTOCOL_H
|
||||
#define WF_PROVIDER_IMPL_CLIENT_PROTOCOL_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
|
||||
#include "webfuse/core/message_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_provider;
|
||||
struct lws_protocols;
|
||||
|
||||
struct wfp_client_protocol
|
||||
{
|
||||
struct wfp_request request;
|
||||
struct wfp_provider provider;
|
||||
void * user_data;
|
||||
struct lws * wsi;
|
||||
struct wf_message_queue queue;
|
||||
};
|
||||
|
||||
extern void wfp_impl_client_protocol_init(
|
||||
struct wfp_client_protocol * protocol,
|
||||
struct wfp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wfp_impl_client_protocol_cleanup(
|
||||
struct wfp_client_protocol * protocol);
|
||||
|
||||
extern struct wfp_client_protocol * wfp_impl_client_protocol_create(
|
||||
struct wfp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wfp_impl_client_protocol_dispose(
|
||||
struct wfp_client_protocol * protocol);
|
||||
|
||||
extern void wfp_impl_client_protocol_init_lws(
|
||||
struct wfp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "wsfs/provider/impl/dirbuffer.h"
|
||||
#include "webfuse/provider/impl/dirbuffer.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void)
|
||||
struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void)
|
||||
{
|
||||
struct wsfsp_dirbuffer * buffer = malloc(sizeof(struct wsfsp_dirbuffer));
|
||||
struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer));
|
||||
if (NULL != buffer)
|
||||
{
|
||||
buffer->entries = json_array();
|
||||
@@ -12,8 +12,8 @@ struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void wsfsp_impl_dirbuffer_dispose(
|
||||
struct wsfsp_dirbuffer * buffer)
|
||||
void wfp_impl_dirbuffer_dispose(
|
||||
struct wfp_dirbuffer * buffer)
|
||||
{
|
||||
if (NULL != buffer->entries)
|
||||
{
|
||||
@@ -23,8 +23,8 @@ void wsfsp_impl_dirbuffer_dispose(
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void wsfsp_impl_dirbuffer_add(
|
||||
struct wsfsp_dirbuffer * buffer,
|
||||
void wfp_impl_dirbuffer_add(
|
||||
struct wfp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode)
|
||||
{
|
||||
@@ -35,8 +35,8 @@ void wsfsp_impl_dirbuffer_add(
|
||||
json_array_append_new(buffer->entries, entry);
|
||||
}
|
||||
|
||||
json_t * wsfsp_impl_dirbuffer_take(
|
||||
struct wsfsp_dirbuffer * buffer)
|
||||
json_t * wfp_impl_dirbuffer_take(
|
||||
struct wfp_dirbuffer * buffer)
|
||||
{
|
||||
json_t * entries = buffer->entries;
|
||||
|
||||
37
lib/webfuse/provider/impl/dirbuffer.h
Normal file
37
lib/webfuse/provider/impl/dirbuffer.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef WF_PROVIDER_IMPL_DIRBUFFER_H
|
||||
#define WF_PROVIDER_IMPL_DIRBUFFER_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_dirbuffer
|
||||
{
|
||||
json_t * entries;
|
||||
};
|
||||
|
||||
extern struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void);
|
||||
|
||||
extern void wfp_impl_dirbuffer_dispose(
|
||||
struct wfp_dirbuffer * buffer);
|
||||
|
||||
extern void wfp_impl_dirbuffer_add(
|
||||
struct wfp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode);
|
||||
|
||||
extern json_t * wfp_impl_dirbuffer_take(
|
||||
struct wfp_dirbuffer * buffer);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "wsfs/provider/impl/operation/close.h"
|
||||
#include "webfuse/provider/impl/operation/close.h"
|
||||
#include <limits.h>
|
||||
#include "wsfs/core/util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wsfsp_impl_close(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
void wfp_impl_close(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int WSFS_UNUSED_PARAM(id))
|
||||
int WF_UNUSED_PARAM(id))
|
||||
{
|
||||
size_t const param_count = json_array_size(params);
|
||||
if (3 == param_count)
|
||||
@@ -28,11 +28,11 @@ void wsfsp_impl_close(
|
||||
|
||||
}
|
||||
|
||||
void wsfsp_impl_close_default(
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
uint32_t WSFS_UNUSED_PARAM(handle),
|
||||
int WSFS_UNUSED_PARAM(flags),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
void wfp_impl_close_default(
|
||||
ino_t WF_UNUSED_PARAM(inode),
|
||||
uint32_t WF_UNUSED_PARAM(handle),
|
||||
int WF_UNUSED_PARAM(flags),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
// empty
|
||||
}
|
||||
26
lib/webfuse/provider/impl/operation/close.h
Normal file
26
lib/webfuse/provider/impl/operation/close.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_CLOSE_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_CLOSE_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_close(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_close_default(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
22
lib/webfuse/provider/impl/operation/error.h
Normal file
22
lib/webfuse/provider/impl/operation/error.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef WFP_OPERATION_IMPL_ERROR_H
|
||||
#define WFP_OPERATION_IMPL_ERROR_H
|
||||
|
||||
#include "webfuse/provider/api.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_request;
|
||||
|
||||
extern WFP_API void wfp_impl_respond_error(
|
||||
struct wfp_request * request,
|
||||
wf_status status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "wsfs/provider/impl/operation/getattr.h"
|
||||
#include "webfuse/provider/impl/operation/getattr.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
|
||||
void wsfsp_impl_getattr(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
void wfp_impl_getattr(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@@ -20,23 +20,23 @@ void wsfsp_impl_getattr(
|
||||
if (json_is_integer(inode_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->getattr(request, inode, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_impl_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
void wfp_impl_getattr_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(inode),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_impl_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
void wfp_impl_respond_getattr(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
bool const is_file = (0 != (stat->st_mode & S_IFREG));
|
||||
@@ -60,5 +60,5 @@ void wsfsp_impl_respond_getattr(
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
}
|
||||
|
||||
wsfsp_impl_respond(request, result);
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
29
lib/webfuse/provider/impl/operation/getattr.h
Normal file
29
lib/webfuse/provider/impl/operation/getattr.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_GETATTR_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_GETATTR_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_getattr(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern void wfp_impl_getattr(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_getattr_default(
|
||||
struct wfp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "wsfs/provider/impl/operation/lookup.h"
|
||||
#include "webfuse/provider/impl/operation/lookup.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wsfsp_impl_lookup(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
void wfp_impl_lookup(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@@ -23,14 +23,14 @@ void wsfsp_impl_lookup(
|
||||
ino_t inode = json_integer_value(inode_holder);
|
||||
char const * name = json_string_value(name_holder);
|
||||
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
context->provider->lookup(request, inode, name, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_impl_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
void wfp_impl_respond_lookup(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
bool const is_file = (0 != (stat->st_mode & S_IFREG));
|
||||
@@ -54,15 +54,15 @@ void wsfsp_impl_respond_lookup(
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
}
|
||||
|
||||
wsfsp_impl_respond(request, result);
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
|
||||
void wsfsp_impl_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(parent),
|
||||
char const * WSFS_UNUSED_PARAM(name),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
void wfp_impl_lookup_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(parent),
|
||||
char const * WF_UNUSED_PARAM(name),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
30
lib/webfuse/provider/impl/operation/lookup.h
Normal file
30
lib/webfuse/provider/impl/operation/lookup.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_LOOKUP_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_LOOKUP_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_lookup(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern void wfp_impl_lookup(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_lookup_default(
|
||||
struct wfp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "wsfs/provider/impl/operation/open.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "webfuse/provider/impl/operation/open.h"
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wsfsp_impl_open(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
void wfp_impl_open(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@@ -20,28 +20,28 @@ void wsfsp_impl_open(
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
int flags = (ino_t) json_integer_value(flags_holder);
|
||||
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->open(request, inode, flags, context->user_data); /* Flawfinder: ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_impl_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
int WSFS_UNUSED_PARAM(flags),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
void wfp_impl_open_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(inode),
|
||||
int WF_UNUSED_PARAM(flags),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_impl_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
void wfp_impl_respond_open(
|
||||
struct wfp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "handle", json_integer((int) handle));
|
||||
|
||||
wsfsp_impl_respond(request, result);
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
30
lib/webfuse/provider/impl/operation/open.h
Normal file
30
lib/webfuse/provider/impl/operation/open.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_OPEN_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_OPEN_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_open(
|
||||
struct wfp_request * request,
|
||||
uint32_t handle);
|
||||
|
||||
extern void wfp_impl_open(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_open_default(
|
||||
struct wfp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "wsfs/provider/impl/operation/read.h"
|
||||
#include "webfuse/provider/impl/operation/read.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wsfsp_impl_read(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
void wfp_impl_read(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@@ -29,26 +29,26 @@ void wsfsp_impl_read(
|
||||
int handle = json_integer_value(handle_holder);
|
||||
size_t offset = json_integer_value(offset_holder);
|
||||
size_t length = json_integer_value(length_holder);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->read(request, inode, handle, offset, length, context->user_data); /* Flawfinder: ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_impl_read_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
uint32_t WSFS_UNUSED_PARAM(handle),
|
||||
size_t WSFS_UNUSED_PARAM(offset),
|
||||
size_t WSFS_UNUSED_PARAM(length),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
void wfp_impl_read_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(inode),
|
||||
uint32_t WF_UNUSED_PARAM(handle),
|
||||
size_t WF_UNUSED_PARAM(offset),
|
||||
size_t WF_UNUSED_PARAM(length),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_impl_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
void wfp_impl_respond_read(
|
||||
struct wfp_request * request,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
@@ -65,12 +65,12 @@ void wsfsp_impl_respond_read(
|
||||
json_object_set_new(result, "format", json_string("base64"));
|
||||
json_object_set_new(result, "count", json_integer((int) length));
|
||||
|
||||
wsfsp_impl_respond(request, result);
|
||||
wfp_impl_respond(request, result);
|
||||
free(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD);
|
||||
wfp_impl_respond_error(request, WF_BAD);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -80,6 +80,6 @@ void wsfsp_impl_respond_read(
|
||||
json_object_set_new(result, "format", json_string("identitiy"));
|
||||
json_object_set_new(result, "count", json_integer(0));
|
||||
|
||||
wsfsp_impl_respond(request, result);
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
}
|
||||
33
lib/webfuse/provider/impl/operation/read.h
Normal file
33
lib/webfuse/provider/impl/operation/read.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_READ_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_READ_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_read(
|
||||
struct wfp_request * request,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
extern void wfp_impl_read(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_read_default(
|
||||
struct wfp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
42
lib/webfuse/provider/impl/operation/readdir.c
Normal file
42
lib/webfuse/provider/impl/operation/readdir.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "webfuse/provider/impl/operation/readdir.h"
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/dirbuffer.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wfp_impl_readdir(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
if (1 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
|
||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->readdir(request, inode, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wfp_impl_readdir_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(directory),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wfp_impl_respond_readdir(
|
||||
struct wfp_request * request,
|
||||
struct wfp_dirbuffer * dirbuffer)
|
||||
{
|
||||
json_t * result = wfp_impl_dirbuffer_take(dirbuffer);
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
|
||||
29
lib/webfuse/provider/impl/operation/readdir.h
Normal file
29
lib/webfuse/provider/impl/operation/readdir.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_READDIR_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_READDIR_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_readdir(
|
||||
struct wfp_request * request,
|
||||
struct wfp_dirbuffer * dirbuffer);
|
||||
|
||||
extern void wfp_impl_readdir(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_readdir_default(
|
||||
struct wfp_request * request,
|
||||
ino_t directory,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
127
lib/webfuse/provider/impl/provider.c
Normal file
127
lib/webfuse/provider/impl/provider.c
Normal file
@@ -0,0 +1,127 @@
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/provider/impl/operation/lookup.h"
|
||||
#include "webfuse/provider/impl/operation/getattr.h"
|
||||
#include "webfuse/provider/impl/operation/readdir.h"
|
||||
#include "webfuse/provider/impl/operation/open.h"
|
||||
#include "webfuse/provider/impl/operation/close.h"
|
||||
#include "webfuse/provider/impl/operation/read.h"
|
||||
|
||||
typedef void wfp_impl_invoke_fn(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
|
||||
struct wfp_impl_method
|
||||
{
|
||||
char const * name;
|
||||
wfp_impl_invoke_fn * invoke;
|
||||
bool is_notification;
|
||||
};
|
||||
|
||||
static void wfp_impl_provider_invoke_method(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
static struct wfp_impl_method const methods[] =
|
||||
{
|
||||
{"lookup", &wfp_impl_lookup, false},
|
||||
{"getattr", &wfp_impl_getattr, false},
|
||||
{"readdir", &wfp_impl_readdir, false},
|
||||
{"open", &wfp_impl_open, false},
|
||||
{"close", &wfp_impl_close, true},
|
||||
{"read", &wfp_impl_read, false}
|
||||
};
|
||||
static size_t const count = sizeof(methods) / sizeof(methods[0]);
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
struct wfp_impl_method const * method = &methods[i];
|
||||
if (0 == strcmp(method_name, method->name))
|
||||
{
|
||||
if ((0 < id) || (method->is_notification))
|
||||
{
|
||||
method->invoke(context, params, id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wfp_impl_provider_init(
|
||||
struct wfp_provider * provider)
|
||||
{
|
||||
provider->lookup = &wfp_impl_lookup_default;
|
||||
provider->getattr = &wfp_impl_getattr_default;
|
||||
provider->readdir = &wfp_impl_readdir_default;
|
||||
provider->open = &wfp_impl_open_default;
|
||||
provider->close = &wfp_impl_close_default;
|
||||
provider->read = &wfp_impl_read_default;
|
||||
provider->connected = &wfp_impl_connected_default;
|
||||
provider->disconnected = &wfp_impl_disconnected_default;
|
||||
provider->ontimer = &wfp_impl_ontimer_default;
|
||||
}
|
||||
|
||||
void wfp_impl_provider_init_from_prototype(
|
||||
struct wfp_provider * provider,
|
||||
struct wfp_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 wfp_impl_provider_invoke(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * request)
|
||||
{
|
||||
json_t * method_holder = json_object_get(request, "method");
|
||||
json_t * params = json_object_get(request, "params");
|
||||
json_t * id_holder = json_object_get(request, "id");
|
||||
|
||||
if ((NULL != method_holder) && (json_is_string(method_holder)) &&
|
||||
(NULL != params) && (json_is_array(params)))
|
||||
{
|
||||
char const * method = json_string_value(method_holder);
|
||||
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0;
|
||||
|
||||
wfp_impl_provider_invoke_method(context, method, params, id);
|
||||
}
|
||||
}
|
||||
|
||||
void wfp_impl_connected_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wfp_impl_disconnected_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wfp_impl_ontimer_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
57
lib/webfuse/provider/impl/provider.h
Normal file
57
lib/webfuse/provider/impl/provider.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef WF_PROVIDER_IMPL_PROVIDER_H
|
||||
#define WF_PROVIDER_IMPL_PROVIDER_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/provider/client_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_provider
|
||||
{
|
||||
wfp_connected_fn * connected;
|
||||
wfp_disconnected_fn * disconnected;
|
||||
wfp_ontimer_fn * ontimer;
|
||||
wfp_lookup_fn * lookup;
|
||||
wfp_getattr_fn * getattr;
|
||||
wfp_readdir_fn * readdir;
|
||||
wfp_open_fn * open;
|
||||
wfp_close_fn * close;
|
||||
wfp_read_fn * read;
|
||||
};
|
||||
|
||||
struct wfp_impl_invokation_context
|
||||
{
|
||||
struct wfp_provider * provider;
|
||||
void * user_data;
|
||||
struct wfp_request * request;
|
||||
};
|
||||
|
||||
extern void wfp_impl_provider_init(
|
||||
struct wfp_provider * provider);
|
||||
|
||||
extern void wfp_impl_provider_init_from_prototype(
|
||||
struct wfp_provider * provider,
|
||||
struct wfp_provider const * prototype);
|
||||
|
||||
|
||||
extern void wfp_impl_provider_invoke(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * request);
|
||||
|
||||
extern void wfp_impl_connected_default(
|
||||
void * user_data);
|
||||
|
||||
extern void wfp_impl_disconnected_default(
|
||||
void * user_data);
|
||||
|
||||
extern void wfp_impl_ontimer_default(
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
|
||||
struct wsfsp_request * wsfsp_impl_request_create(
|
||||
struct wsfsp_request * prototype,
|
||||
struct wfp_request * wfp_impl_request_create(
|
||||
struct wfp_request * prototype,
|
||||
int id)
|
||||
{
|
||||
struct wsfsp_request * request = malloc(sizeof(struct wsfsp_request));
|
||||
struct wfp_request * request = malloc(sizeof(struct wfp_request));
|
||||
if (NULL != request)
|
||||
{
|
||||
request->respond = prototype->respond;
|
||||
@@ -18,14 +18,14 @@ struct wsfsp_request * wsfsp_impl_request_create(
|
||||
return request;
|
||||
}
|
||||
|
||||
void wsfsp_impl_request_dispose(
|
||||
struct wsfsp_request * request)
|
||||
void wfp_impl_request_dispose(
|
||||
struct wfp_request * request)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
extern void wsfsp_impl_respond(
|
||||
struct wsfsp_request * request,
|
||||
extern void wfp_impl_respond(
|
||||
struct wfp_request * request,
|
||||
json_t * result)
|
||||
{
|
||||
json_t * response = json_object();
|
||||
@@ -35,12 +35,12 @@ extern void wsfsp_impl_respond(
|
||||
request->respond(response, request->user_data);
|
||||
|
||||
json_decref(response);
|
||||
wsfsp_impl_request_dispose(request);
|
||||
wfp_impl_request_dispose(request);
|
||||
}
|
||||
|
||||
void wsfsp_impl_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
wsfs_status status)
|
||||
void wfp_impl_respond_error(
|
||||
struct wfp_request * request,
|
||||
wf_status status)
|
||||
{
|
||||
json_t * response = json_object();
|
||||
json_t * error = json_object();
|
||||
@@ -51,5 +51,5 @@ void wsfsp_impl_respond_error(
|
||||
request->respond(response, request->user_data);
|
||||
|
||||
json_decref(response);
|
||||
wsfsp_impl_request_dispose(request);
|
||||
wfp_impl_request_dispose(request);
|
||||
}
|
||||
43
lib/webfuse/provider/impl/request.h
Normal file
43
lib/webfuse/provider/impl/request.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef WF_PROVIDER_IMPL_REQUEST_H
|
||||
#define WF_PROVIDER_IMPL_REQUEST_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void wfp_impl_request_respond_fn(
|
||||
json_t * response,
|
||||
void * user_data);
|
||||
|
||||
struct wfp_request
|
||||
{
|
||||
wfp_impl_request_respond_fn * respond;
|
||||
void * user_data;
|
||||
int id;
|
||||
};
|
||||
|
||||
extern void wfp_impl_respond_error(
|
||||
struct wfp_request * request,
|
||||
wf_status status);
|
||||
|
||||
extern struct wfp_request * wfp_impl_request_create(
|
||||
struct wfp_request * prototype,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_request_dispose(
|
||||
struct wfp_request * request);
|
||||
|
||||
extern void wfp_impl_respond(
|
||||
struct wfp_request * request,
|
||||
json_t * result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "wsfs/provider/impl/url.h"
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfsp_impl_url_protocol
|
||||
struct wfp_impl_url_protocol
|
||||
{
|
||||
char const * name;
|
||||
size_t name_length;
|
||||
@@ -11,11 +11,11 @@ struct wsfsp_impl_url_protocol
|
||||
bool use_tls;
|
||||
};
|
||||
|
||||
static bool wsfsp_impl_url_readprotocol(
|
||||
struct wsfsp_impl_url * url,
|
||||
static bool wfp_impl_url_readprotocol(
|
||||
struct wfp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
static struct wsfsp_impl_url_protocol const known_protocols[] =
|
||||
static struct wfp_impl_url_protocol const known_protocols[] =
|
||||
{
|
||||
{"ws://", 5, 80, false},
|
||||
{"wss://", 6, 443, true}
|
||||
@@ -25,7 +25,7 @@ static bool wsfsp_impl_url_readprotocol(
|
||||
bool found = false;
|
||||
for(size_t i = 0; (!found) && (i < count); i++)
|
||||
{
|
||||
struct wsfsp_impl_url_protocol const * protocol = &known_protocols[i];
|
||||
struct wfp_impl_url_protocol const * protocol = &known_protocols[i];
|
||||
if (0 == strncmp(*data, protocol->name, protocol->name_length))
|
||||
{
|
||||
url->port = protocol->default_port;
|
||||
@@ -38,8 +38,8 @@ static bool wsfsp_impl_url_readprotocol(
|
||||
return found;
|
||||
}
|
||||
|
||||
static bool wsfsp_impl_url_readhost(
|
||||
struct wsfsp_impl_url * url,
|
||||
static bool wfp_impl_url_readhost(
|
||||
struct wfp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
char * end = strpbrk(*data, ":/");
|
||||
@@ -55,8 +55,8 @@ static bool wsfsp_impl_url_readhost(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wsfsp_impl_url_readport(
|
||||
struct wsfsp_impl_url * url,
|
||||
static bool wfp_impl_url_readport(
|
||||
struct wfp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
bool result;
|
||||
@@ -81,8 +81,8 @@ static bool wsfsp_impl_url_readport(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wsfsp_impl_url_readpath(
|
||||
struct wsfsp_impl_url * url,
|
||||
static bool wfp_impl_url_readpath(
|
||||
struct wfp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
bool const result = ('/' == **data);
|
||||
@@ -93,33 +93,33 @@ static bool wsfsp_impl_url_readpath(
|
||||
}
|
||||
|
||||
|
||||
bool wsfsp_impl_url_init(
|
||||
struct wsfsp_impl_url * url,
|
||||
bool wfp_impl_url_init(
|
||||
struct wfp_impl_url * url,
|
||||
char const * value)
|
||||
{
|
||||
memset(url, 0, sizeof(struct wsfsp_impl_url));
|
||||
memset(url, 0, sizeof(struct wfp_impl_url));
|
||||
char const * data = value;
|
||||
|
||||
bool const result =
|
||||
wsfsp_impl_url_readprotocol(url, &data) &&
|
||||
wsfsp_impl_url_readhost(url, &data) &&
|
||||
wsfsp_impl_url_readport(url, &data) &&
|
||||
wsfsp_impl_url_readpath(url, &data)
|
||||
wfp_impl_url_readprotocol(url, &data) &&
|
||||
wfp_impl_url_readhost(url, &data) &&
|
||||
wfp_impl_url_readport(url, &data) &&
|
||||
wfp_impl_url_readpath(url, &data)
|
||||
;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
wsfsp_impl_url_cleanup(url);
|
||||
wfp_impl_url_cleanup(url);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfsp_impl_url_cleanup(
|
||||
struct wsfsp_impl_url * url)
|
||||
void wfp_impl_url_cleanup(
|
||||
struct wfp_impl_url * url)
|
||||
{
|
||||
free(url->host);
|
||||
free(url->path);
|
||||
memset(url, 0, sizeof(struct wsfsp_impl_url));
|
||||
memset(url, 0, sizeof(struct wfp_impl_url));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_URL_H
|
||||
#define WSFS_PROVIDER_IMPL_URL_H
|
||||
#ifndef WF_PROVIDER_IMPL_URL_H
|
||||
#define WF_PROVIDER_IMPL_URL_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
@@ -9,7 +9,7 @@
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
struct wsfsp_impl_url
|
||||
struct wfp_impl_url
|
||||
{
|
||||
char * host;
|
||||
int port;
|
||||
@@ -17,12 +17,12 @@ struct wsfsp_impl_url
|
||||
bool use_tls;
|
||||
};
|
||||
|
||||
extern bool wsfsp_impl_url_init(
|
||||
struct wsfsp_impl_url * url,
|
||||
extern bool wfp_impl_url_init(
|
||||
struct wfp_impl_url * url,
|
||||
char const * value);
|
||||
|
||||
extern void wsfsp_impl_url_cleanup(
|
||||
struct wsfsp_impl_url * url);
|
||||
extern void wfp_impl_url_cleanup(
|
||||
struct wfp_impl_url * url);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -1,141 +0,0 @@
|
||||
#include "wsfs_adapter.h"
|
||||
|
||||
#include "wsfs/adapter/impl/server.h"
|
||||
#include "wsfs/adapter/impl/server_protocol.h"
|
||||
#include "wsfs/adapter/impl/server_config.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
|
||||
// server
|
||||
|
||||
struct wsfs_server * wsfs_server_create(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
return wsfs_impl_server_create(config);
|
||||
}
|
||||
|
||||
void wsfs_server_dispose(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_dispose(server);
|
||||
}
|
||||
|
||||
void wsfs_server_run(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_run(server);
|
||||
}
|
||||
|
||||
void wsfs_server_shutdown(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_shutdown(server);
|
||||
}
|
||||
|
||||
// server protocol
|
||||
|
||||
struct wsfs_server_protocol * wsfs_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
return wsfs_impl_server_protocol_create(mount_point);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_dispose(protocol);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_init_lws(protocol, lws_protocol);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// server_config
|
||||
|
||||
struct wsfs_server_config * wsfs_server_config_create(void)
|
||||
{
|
||||
return wsfs_impl_server_config_create();
|
||||
}
|
||||
|
||||
void wsfs_server_config_dispose(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
wsfs_impl_server_config_dispose(config);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_mountpoint(
|
||||
struct wsfs_server_config * config,
|
||||
char const * mount_point)
|
||||
{
|
||||
wsfs_impl_server_config_set_mountpoint(config, mount_point);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_documentroot(
|
||||
struct wsfs_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
wsfs_impl_server_config_set_documentroot(config, document_root);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_keypath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wsfs_impl_server_config_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_certpath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wsfs_impl_server_config_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_vhostname(
|
||||
struct wsfs_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
wsfs_impl_server_config_set_vhostname(config, vhost_name);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_port(
|
||||
struct wsfs_server_config * config,
|
||||
int port)
|
||||
{
|
||||
wsfs_impl_server_config_set_port(config, port);
|
||||
}
|
||||
|
||||
void wsfs_server_config_add_authenticator(
|
||||
struct wsfs_server_config * config,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_server_config_add_authenticator(config, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// credentials
|
||||
|
||||
char const * wsfs_credentials_type(
|
||||
struct wsfs_credentials const * credentials)
|
||||
{
|
||||
return wsfs_impl_credentials_type(credentials);
|
||||
}
|
||||
|
||||
char const * wsfs_credentials_get(
|
||||
struct wsfs_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
return wsfs_impl_credentials_get(credentials, key);
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
#define WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_credentials;
|
||||
|
||||
struct wsfs_impl_authenticator
|
||||
{
|
||||
char * type;
|
||||
wsfs_authenticate_fn * authenticate;
|
||||
void * user_data;
|
||||
struct wsfs_impl_authenticator * next;
|
||||
};
|
||||
|
||||
extern struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_impl_authenticator_dispose(
|
||||
struct wsfs_impl_authenticator * authenticator);
|
||||
|
||||
extern bool wsfs_impl_authenticator_autenticate(
|
||||
struct wsfs_impl_authenticator * authenticator,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
|
||||
static struct wsfs_impl_authenticator * wsfs_impl_authenticators_find(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type)
|
||||
{
|
||||
struct wsfs_impl_authenticator * result = NULL;
|
||||
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while ((NULL == result) && (NULL != actual))
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
if (0 == strcmp(type, actual->type))
|
||||
{
|
||||
result = actual;
|
||||
}
|
||||
|
||||
actual = next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_init(
|
||||
struct wsfs_impl_authenticators * authenticators)
|
||||
{
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_cleanup(
|
||||
struct wsfs_impl_authenticators * authenticators)
|
||||
{
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
wsfs_impl_authenticator_dispose(actual);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_clone(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other)
|
||||
{
|
||||
wsfs_impl_authenticators_init(other);
|
||||
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
wsfs_impl_authenticators_add(other,
|
||||
actual->type, actual->authenticate, actual->user_data);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern void wsfs_impl_authenticators_move(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other)
|
||||
{
|
||||
other->first = authenticators->first;
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_add(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(type, authenticate, user_data);
|
||||
authenticator->next = authenticators->first;
|
||||
authenticators->first = authenticator;
|
||||
}
|
||||
|
||||
bool wsfs_impl_authenticators_authenticate(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials)
|
||||
{
|
||||
bool result = (NULL == authenticators->first);
|
||||
|
||||
if (NULL != credentials)
|
||||
{
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticators_find(authenticators, credentials->type);
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
result = wsfs_impl_authenticator_autenticate(authenticator, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
#define WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_authenticator;
|
||||
struct wsfs_credentials;
|
||||
|
||||
struct wsfs_impl_authenticators
|
||||
{
|
||||
struct wsfs_impl_authenticator * first;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_authenticators_init(
|
||||
struct wsfs_impl_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_impl_authenticators_cleanup(
|
||||
struct wsfs_impl_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_impl_authenticators_clone(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other);
|
||||
|
||||
extern void wsfs_impl_authenticators_move(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other);
|
||||
|
||||
extern void wsfs_impl_authenticators_add(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern bool wsfs_impl_authenticators_authenticate(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_CREDENTIALS_H
|
||||
#define WSFS_ADAPTER_IMPL_CREDENTIALS_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_credentials
|
||||
{
|
||||
char * type;
|
||||
json_t * data;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_credentials_init(
|
||||
struct wsfs_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data);
|
||||
|
||||
extern void wsfs_impl_credentials_cleanup(
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
extern char const * wsfs_impl_credentials_type(
|
||||
struct wsfs_credentials const * credentials);
|
||||
|
||||
extern char const * wsfs_impl_credentials_get(
|
||||
struct wsfs_credentials const * credentials,
|
||||
char const * key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,45 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_FILESYSTEM_H
|
||||
#define WSFS_ADAPTER_IMPL_FILESYSTEM_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/impl/fuse_wrapper.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_server;
|
||||
|
||||
struct wsfs_impl_filesystem
|
||||
{
|
||||
struct fuse_args args;
|
||||
struct fuse_session * session;
|
||||
struct fuse_buf buffer;
|
||||
struct wsfs_impl_operations_context user_data;
|
||||
};
|
||||
|
||||
extern bool wsfs_impl_filesystem_init(
|
||||
struct wsfs_impl_filesystem * filesystem,
|
||||
struct wsfs_impl_jsonrpc_server * rpc,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_filesystem_cleanup(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
extern int wsfs_impl_filesystem_get_fd(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
extern void wsfs_impl_filesystem_process_request(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,28 +0,0 @@
|
||||
#include "wsfs/adapter/impl/jsonrpc/method_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * method = malloc(sizeof(struct wsfs_impl_jsonrpc_method));
|
||||
if (NULL != method)
|
||||
{
|
||||
method->next = NULL;
|
||||
method->name = strdup(name);
|
||||
method->invoke = invoke;
|
||||
method->user_data = user_data;
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
void wsfs_impl_jsonrpc_method_dispose(
|
||||
struct wsfs_impl_jsonrpc_method * method)
|
||||
{
|
||||
free(method->name);
|
||||
free(method);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/method.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_method
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * next;
|
||||
char * name;
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_method_dispose(
|
||||
struct wsfs_impl_jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_response
|
||||
{
|
||||
wsfs_status status;
|
||||
int id;
|
||||
json_t * result;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_jsonrpc_response_init(
|
||||
struct wsfs_impl_jsonrpc_response * response,
|
||||
char const * buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_response_cleanup(
|
||||
struct wsfs_impl_jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/method_intern.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/request.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
#define WSFS_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
static struct wsfs_impl_jsonrpc_method const * wsfs_impl_jsonrpc_server_getmethod(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * name)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * method = server->methods;
|
||||
while ((NULL != method) && (0 == strcmp(name, method->name)))
|
||||
{
|
||||
method = method->next;
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
static void wsfs_impl_jsonrpc_server_timeout(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_server * server = timer->user_data;
|
||||
|
||||
if (server->request.is_pending)
|
||||
{
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
|
||||
void * user_data = server->request.user_data;
|
||||
|
||||
server->request.is_pending = false;
|
||||
server->request.id = 0;
|
||||
server->request.user_data = NULL;
|
||||
server->request.finished = NULL;
|
||||
wsfs_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, WSFS_BAD_TIMEOUT, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfs_impl_jsonrpc_server_init(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
struct wsfs_impl_timeout_manager * timeout_manager)
|
||||
{
|
||||
server->methods = NULL;
|
||||
server->request.is_pending = false;
|
||||
|
||||
wsfs_impl_timer_init(&server->request.timer, timeout_manager);
|
||||
}
|
||||
|
||||
void wsfs_impl_jsonrpc_server_cleanup(
|
||||
struct wsfs_impl_jsonrpc_server * server)
|
||||
{
|
||||
wsfs_impl_timer_cleanup(&server->request.timer);
|
||||
|
||||
if (server->request.is_pending)
|
||||
{
|
||||
server->request.finished(server->request.user_data, WSFS_BAD, NULL);
|
||||
server->request.is_pending = false;
|
||||
}
|
||||
|
||||
struct wsfs_impl_jsonrpc_method * method = server->methods;
|
||||
while (NULL != method)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * next = method->next;
|
||||
method->next = NULL;
|
||||
wsfs_impl_jsonrpc_method_dispose(method);
|
||||
method = next;
|
||||
}
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_jsonrpc_server_add(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * method = wsfs_impl_jsonrpc_method_create(name, invoke, user_data);
|
||||
method->next = server->methods;
|
||||
server->methods = method;
|
||||
}
|
||||
|
||||
void wsfs_impl_jsonrpc_server_invoke(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
if (!server->request.is_pending)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method const * method = wsfs_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;
|
||||
wsfs_impl_timer_start(&server->request.timer, wsfs_impl_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT),
|
||||
&wsfs_impl_jsonrpc_server_timeout, server);
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wsfs_impl_jsonrpc_request_create(method_name, server->request.id, param_info, args);
|
||||
va_end(args);
|
||||
if (NULL != request)
|
||||
{
|
||||
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;
|
||||
wsfs_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, WSFS_BAD, NULL);
|
||||
}
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finished(user_data, WSFS_BAD_NOTIMPLEMENTED, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finished(user_data, WSFS_BAD_BUSY, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_notify(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name);
|
||||
if (NULL != method)
|
||||
{
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wsfs_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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void wsfs_impl_jsonrpc_server_onresult(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_response response;
|
||||
wsfs_impl_jsonrpc_response_init(&response, message, length);
|
||||
|
||||
if ((server->request.is_pending) && (response.id == server->request.id))
|
||||
{
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
|
||||
void * user_data = server->request.user_data;
|
||||
|
||||
server->request.is_pending = false;
|
||||
server->request.id = 0;
|
||||
server->request.user_data = NULL;
|
||||
server->request.finished = NULL;
|
||||
wsfs_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, response.status, response.result);
|
||||
}
|
||||
|
||||
wsfs_impl_jsonrpc_response_cleanup(&response);
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/adapter/impl/jsonrpc/method.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/impl/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wsfs_impl_timer timer;
|
||||
};
|
||||
|
||||
struct wsfs_impl_jsonrpc_server
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * methods;
|
||||
struct wsfs_impl_jsonrpc_request request;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_init(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_cleanup(
|
||||
struct wsfs_impl_jsonrpc_server * server);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_add(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data );
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_invoke(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_notify(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_onresult(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSON_UTIL_H
|
||||
#define WSFS_ADAPTER_IMPL_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfs_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wsfs_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_server;
|
||||
struct wsfs_server_config;
|
||||
|
||||
extern struct wsfs_server * wsfs_impl_server_create(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_dispose(
|
||||
struct wsfs_server * server);
|
||||
|
||||
extern void wsfs_impl_server_run(
|
||||
struct wsfs_server * server);
|
||||
|
||||
extern void wsfs_impl_server_shutdown(
|
||||
struct wsfs_server * server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
#include "wsfs/adapter/impl/server_config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char * wsfs_impl_server_config_strdup(char const * value)
|
||||
{
|
||||
char * result = NULL;
|
||||
if (NULL != value)
|
||||
{
|
||||
result = strdup(value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_init(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
memset(config, 0, sizeof(struct wsfs_server_config));
|
||||
|
||||
wsfs_impl_authenticators_init(&config->authenticators);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_cleanup(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
wsfs_impl_authenticators_cleanup(&config->authenticators);
|
||||
|
||||
free(config->mount_point);
|
||||
free(config->document_root);
|
||||
free(config->key_path);
|
||||
free(config->cert_path);
|
||||
free(config->vhost_name);
|
||||
|
||||
wsfs_impl_server_config_init(config);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_clone(
|
||||
struct wsfs_server_config * config,
|
||||
struct wsfs_server_config * clone)
|
||||
{
|
||||
clone->mount_point = wsfs_impl_server_config_strdup(config->mount_point);
|
||||
clone->document_root = wsfs_impl_server_config_strdup(config->document_root);
|
||||
clone->key_path = wsfs_impl_server_config_strdup(config->key_path);
|
||||
clone->cert_path = wsfs_impl_server_config_strdup(config->cert_path);
|
||||
clone->vhost_name = wsfs_impl_server_config_strdup(config->vhost_name);
|
||||
clone->port = config->port;
|
||||
|
||||
wsfs_impl_authenticators_clone(&config->authenticators, &clone->authenticators);
|
||||
}
|
||||
|
||||
struct wsfs_server_config * wsfs_impl_server_config_create(void)
|
||||
{
|
||||
struct wsfs_server_config * config = malloc(sizeof(struct wsfs_server_config));
|
||||
if (NULL != config)
|
||||
{
|
||||
wsfs_impl_server_config_init(config);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_dispose(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
wsfs_impl_server_config_cleanup(config);
|
||||
free(config);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_set_mountpoint(
|
||||
struct wsfs_server_config * config,
|
||||
char const * mount_point)
|
||||
{
|
||||
free(config->mount_point);
|
||||
config->mount_point = strdup(mount_point);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_set_documentroot(
|
||||
struct wsfs_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
free(config->document_root);
|
||||
config->document_root = strdup(document_root);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_set_keypath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
free(config->key_path);
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_set_certpath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
free(config->cert_path);
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_set_vhostname(
|
||||
struct wsfs_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
free(config->vhost_name);
|
||||
config->vhost_name = strdup(vhost_name);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_set_port(
|
||||
struct wsfs_server_config * config,
|
||||
int port)
|
||||
{
|
||||
config->port = port;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_config_add_authenticator(
|
||||
struct wsfs_server_config * config,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
)
|
||||
{
|
||||
wsfs_impl_authenticators_add(&config->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_server_config
|
||||
{
|
||||
char * mount_point;
|
||||
char * document_root;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * vhost_name;
|
||||
int port;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
};
|
||||
|
||||
extern struct wsfs_server_config * wsfs_impl_server_config_create(void);
|
||||
|
||||
extern void wsfs_impl_server_config_dispose(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_init(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_cleanup(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_clone(
|
||||
struct wsfs_server_config * config,
|
||||
struct wsfs_server_config * clone);
|
||||
|
||||
extern void wsfs_impl_server_config_set_mountpoint(
|
||||
struct wsfs_server_config * config,
|
||||
char const * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_config_set_documentroot(
|
||||
struct wsfs_server_config * config,
|
||||
char const * document_root);
|
||||
|
||||
extern void wsfs_impl_server_config_set_keypath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void wsfs_impl_server_config_set_certpath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void wsfs_impl_server_config_set_vhostname(
|
||||
struct wsfs_server_config * config,
|
||||
char const * vhost_name);
|
||||
|
||||
extern void wsfs_impl_server_config_set_port(
|
||||
struct wsfs_server_config * config,
|
||||
int port);
|
||||
|
||||
extern void wsfs_impl_server_config_add_authenticator(
|
||||
struct wsfs_server_config * config,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,166 +0,0 @@
|
||||
#include "wsfs/adapter/impl/server_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/core/message.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
#include "wsfs/adapter/impl/filesystem.h"
|
||||
|
||||
static int wsfs_impl_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wsfs_server_protocol * protocol = ws_protocol->user;
|
||||
|
||||
wsfs_impl_timeout_manager_check(&protocol->timeout_manager);
|
||||
struct wsfs_impl_session * session = wsfs_impl_session_manager_get(&protocol->session_manager, wsi);
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
{
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = wsfs_impl_filesystem_get_fd(&protocol->filesystem);
|
||||
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
|
||||
{
|
||||
fprintf(stderr, "error: unable to adopt fd");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wsfs_impl_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->rpc);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_authenticate(session, NULL);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
wsfs_impl_session_manager_remove(&protocol->session_manager, wsi);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_onwritable(session);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_receive(session, in, len);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
wsfs_impl_filesystem_process_request(&protocol->filesystem);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool wsfs_impl_server_protocol_invoke(
|
||||
void * user_data,
|
||||
json_t const * request)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = user_data;
|
||||
struct wsfs_impl_session * session = &protocol->session_manager.session;
|
||||
struct wsfs_message * message = wsfs_message_create(request);
|
||||
|
||||
bool const result = wsfs_impl_session_send(session, message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
if (!wsfs_impl_server_protocol_init(protocol, mount_point))
|
||||
{
|
||||
free(protocol);
|
||||
protocol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wsfs_impl_server_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
bool wsfs_impl_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point)
|
||||
{
|
||||
wsfs_impl_timeout_manager_init(&protocol->timeout_manager);
|
||||
wsfs_impl_session_manager_init(&protocol->session_manager);
|
||||
wsfs_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
wsfs_impl_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
|
||||
bool const success = wsfs_impl_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
|
||||
|
||||
// cleanup on error
|
||||
if (!success)
|
||||
{
|
||||
wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_filesystem_cleanup(&protocol->filesystem);
|
||||
wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "wsfs/adapter/impl/filesystem.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include "wsfs/adapter/impl/session_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws_protocols;
|
||||
|
||||
struct wsfs_server_protocol
|
||||
{
|
||||
struct wsfs_impl_timeout_manager timeout_manager;
|
||||
struct wsfs_impl_filesystem filesystem;
|
||||
struct wsfs_impl_jsonrpc_server rpc;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_session_manager session_manager;
|
||||
};
|
||||
|
||||
extern bool wsfs_impl_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol);
|
||||
|
||||
extern struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol);
|
||||
|
||||
extern void wsfs_impl_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
extern void wsfs_impl_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,84 +0,0 @@
|
||||
#include "wsfs/adapter/impl/session.h"
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include "wsfs/core/message_queue.h"
|
||||
#include "wsfs/core/message.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void wsfs_impl_session_init(
|
||||
struct wsfs_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_jsonrpc_server * rpc)
|
||||
{
|
||||
session->wsi = wsi;
|
||||
session->is_authenticated = false;
|
||||
session->authenticators = authenticators;
|
||||
session->rpc = rpc;
|
||||
wsfs_message_queue_init(&session->queue);
|
||||
}
|
||||
|
||||
void wsfs_impl_session_cleanup(
|
||||
struct wsfs_impl_session * session)
|
||||
{
|
||||
wsfs_message_queue_cleanup(&session->queue);
|
||||
session->is_authenticated = false;
|
||||
session->wsi = NULL;
|
||||
session->authenticators = NULL;
|
||||
session->rpc = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_session_authenticate(
|
||||
struct wsfs_impl_session * session,
|
||||
struct wsfs_credentials * creds)
|
||||
{
|
||||
session->is_authenticated = wsfs_impl_authenticators_authenticate(session->authenticators, creds);
|
||||
}
|
||||
|
||||
bool wsfs_impl_session_send(
|
||||
struct wsfs_impl_session * session,
|
||||
struct wsfs_message * message)
|
||||
{
|
||||
bool result = (session->is_authenticated) && (NULL != session->wsi);
|
||||
|
||||
if (result)
|
||||
{
|
||||
wsfs_message_queue_push(&session->queue, message);
|
||||
lws_callback_on_writable(session->wsi);
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
wsfs_message_dispose(message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_impl_session_onwritable(
|
||||
struct wsfs_impl_session * session)
|
||||
{
|
||||
if (!wsfs_message_queue_empty(&session->queue))
|
||||
{
|
||||
struct wsfs_message * message = wsfs_message_queue_pop(&session->queue);
|
||||
lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||
wsfs_message_dispose(message);
|
||||
|
||||
if (!wsfs_message_queue_empty(&session->queue))
|
||||
{
|
||||
lws_callback_on_writable(session->wsi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wsfs_impl_session_receive(
|
||||
struct wsfs_impl_session * session,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
wsfs_impl_jsonrpc_server_onresult(session->rpc, data, length);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user