parent
1c9d1c8420
commit
7447fb5dff
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef WF_ADAPTER_API_H
|
||||||
|
#define WF_ADAPTER_API_H
|
||||||
|
|
||||||
|
#ifndef WF_API
|
||||||
|
#define WF_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WF_EXPORT
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define WF_EXPORT __attribute__ ((visibility ("default")))
|
||||||
|
#else
|
||||||
|
#define WF_EXPORT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef WF_ADAPTER_AUTHENTICATE_H
|
||||||
|
#define WF_ADAPTER_AUTHENTICATE_H
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
#include <stdbool.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_credentials;
|
||||||
|
|
||||||
|
typedef bool wf_authenticate_fn(
|
||||||
|
struct wf_credentials * credentials,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef WF_ADAPTER_CREDENTIALS_H
|
||||||
|
#define WF_ADAPTER_CREDENTIALS_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_credentials;
|
||||||
|
|
||||||
|
extern WF_API char const * wf_credentials_type(
|
||||||
|
struct wf_credentials const * credentials);
|
||||||
|
|
||||||
|
extern WF_API char const * wf_credentials_get(
|
||||||
|
struct wf_credentials const * credentials,
|
||||||
|
char const * key);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef WF_ADAPTER_SERVER_H
|
||||||
|
#define WF_ADAPTER_SERVER_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_server;
|
||||||
|
struct wf_server_config;
|
||||||
|
|
||||||
|
extern WF_API struct wf_server * wf_server_create(
|
||||||
|
struct wf_server_config * config);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_dispose(
|
||||||
|
struct wf_server * server);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_run(
|
||||||
|
struct wf_server * server);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_shutdown(
|
||||||
|
struct wf_server * server);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,55 @@
|
|||||||
|
#ifndef WF_ADAPTER_SERVER_CONFIG_H
|
||||||
|
#define WF_ADAPTER_SERVER_CONFIG_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/api.h"
|
||||||
|
#include "webfuse/adapter/authenticate.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_server_config;
|
||||||
|
|
||||||
|
extern WF_API struct wf_server_config * wf_server_config_create(void);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_config_dispose(
|
||||||
|
struct wf_server_config * config);
|
||||||
|
|
||||||
|
|
||||||
|
extern WF_API void wf_server_config_set_mountpoint(
|
||||||
|
struct wf_server_config * config,
|
||||||
|
char const * mount_point);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_config_set_documentroot(
|
||||||
|
struct wf_server_config * config,
|
||||||
|
char const * document_root);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_config_set_keypath(
|
||||||
|
struct wf_server_config * config,
|
||||||
|
char const * key_path);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_config_set_certpath(
|
||||||
|
struct wf_server_config * config,
|
||||||
|
char const * cert_path);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_config_set_vhostname(
|
||||||
|
struct wf_server_config * config,
|
||||||
|
char const * vhost_name);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_config_set_port(
|
||||||
|
struct wf_server_config * config,
|
||||||
|
int port);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_config_add_authenticator(
|
||||||
|
struct wf_server_config * config,
|
||||||
|
char const * type,
|
||||||
|
wf_authenticate_fn * authenticate,
|
||||||
|
void * user_data
|
||||||
|
);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef WF_ADAPTER_SERVER_PROTOCOL_H
|
||||||
|
#define WF_ADAPTER_SERVER_PROTOCOL_H
|
||||||
|
|
||||||
|
#include <webfuse/adapter/api.h>
|
||||||
|
#include <webfuse/adapter/authenticate.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wf_server_protocol;
|
||||||
|
struct lws_protocols;
|
||||||
|
|
||||||
|
extern WF_API struct wf_server_protocol * wf_server_protocol_create(
|
||||||
|
char * mount_point);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_protocol_dispose(
|
||||||
|
struct wf_server_protocol * protocol);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_protocol_init_lws(
|
||||||
|
struct wf_server_protocol * protocol,
|
||||||
|
struct lws_protocols * lws_protocol);
|
||||||
|
|
||||||
|
extern WF_API void wf_server_protocol_add_authenticator(
|
||||||
|
struct wf_server_protocol * protocol,
|
||||||
|
char const * type,
|
||||||
|
wf_authenticate_fn * authenticate,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef WF_STATUS_H
|
||||||
|
#define WF_STATUS_H
|
||||||
|
|
||||||
|
#define WF_GOOD 0
|
||||||
|
#define WF_BAD 1
|
||||||
|
|
||||||
|
#define WF_BAD_NOTIMPLEMENTED 2
|
||||||
|
#define WF_BAD_TIMEOUT 3
|
||||||
|
#define WF_BAD_BUSY 4
|
||||||
|
#define WF_BAD_FORMAT 5
|
||||||
|
|
||||||
|
#define WF_BAD_NOENTRY 101
|
||||||
|
#define WF_BAD_NOACCESS 102
|
||||||
|
|
||||||
|
typedef int wf_status;
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef WFP_PROVIDER_API_H
|
||||||
|
#define WFP_PROVIDER_API_H
|
||||||
|
|
||||||
|
#ifndef WFP_API
|
||||||
|
#define WFP_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WFP_EXPORT
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define WFP_EXPORT __attribute__ ((visibility ("default")))
|
||||||
|
#else
|
||||||
|
#define WFP_EXPORT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef WF_PROVIDER_CLIENT_H
|
||||||
|
#define WF_PROVIDER_CLIENT_H
|
||||||
|
|
||||||
|
#include "webfuse/provider/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfp_client;
|
||||||
|
struct wfp_client_config;
|
||||||
|
|
||||||
|
extern WFP_API struct wfp_client * wfp_client_create(
|
||||||
|
struct wfp_client_config * config);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_connect(
|
||||||
|
struct wfp_client * client,
|
||||||
|
char const * url);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_disconnect(
|
||||||
|
struct wfp_client * client);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_dispose(
|
||||||
|
struct wfp_client * client);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_run(
|
||||||
|
struct wfp_client * client);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_shutdown(
|
||||||
|
struct wfp_client * client);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,88 @@
|
|||||||
|
#ifndef WF_PROVIDER_CLIENT_CONFIG_H
|
||||||
|
#define WF_PROVIDER_CLIENT_CONFIG_H
|
||||||
|
|
||||||
|
#include <webfuse/provider/api.h>
|
||||||
|
|
||||||
|
#include <webfuse/provider/operation/lookup.h>
|
||||||
|
#include <webfuse/provider/operation/getattr.h>
|
||||||
|
#include <webfuse/provider/operation/readdir.h>
|
||||||
|
#include <webfuse/provider/operation/open.h>
|
||||||
|
#include <webfuse/provider/operation/close.h>
|
||||||
|
#include <webfuse/provider/operation/read.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfp_client_config;
|
||||||
|
|
||||||
|
typedef void wfp_connected_fn(
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
typedef void wfp_disconnected_fn(
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
typedef void wfp_ontimer_fn(
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
extern WFP_API struct wfp_client_config * wfp_client_config_create(void);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_dispose(
|
||||||
|
struct wfp_client_config * config);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_userdata(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_keypath(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
char const * key_path);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_certpath(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
char const * cert_path);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_onconnected(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_connected_fn * handler);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_ondisconnected(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_disconnected_fn * handler);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_ontimer(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_ontimer_fn * handler);
|
||||||
|
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_onlookup(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_lookup_fn * handler);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_ongetattr(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_getattr_fn * handler);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_onreaddir(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_readdir_fn * handler);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_onopen(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_open_fn * handler);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_onclose(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_close_fn * handler);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_config_set_onread(
|
||||||
|
struct wfp_client_config * config,
|
||||||
|
wfp_read_fn * handler);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef WF_PROVIDER_CLIENT_PROTOCOL_H
|
||||||
|
#define WF_PROVIDER_CLIENT_PROTOCOL_H
|
||||||
|
|
||||||
|
#include "webfuse/provider/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfp_client_protocol;
|
||||||
|
struct wfp_provider;
|
||||||
|
struct lws_protocols;
|
||||||
|
|
||||||
|
extern WFP_API struct wfp_client_protocol * wfp_client_protocol_create(
|
||||||
|
struct wfp_provider const * provider,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_protocol_dispose(
|
||||||
|
struct wfp_client_protocol * protocol);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_client_protocol_init_lws(
|
||||||
|
struct wfp_client_protocol * protocol,
|
||||||
|
struct lws_protocols * lws_protocol);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef WF_PROVIDER_DIRBUFFER_H
|
||||||
|
#define WF_PROVIDER_DIRBUFFER_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "webfuse/provider/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfp_dirbuffer;
|
||||||
|
|
||||||
|
extern WFP_API struct wfp_dirbuffer * wfp_dirbuffer_create(void);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_dirbuffer_dispose(
|
||||||
|
struct wfp_dirbuffer * buffer);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_dirbuffer_add(
|
||||||
|
struct wfp_dirbuffer * buffer,
|
||||||
|
char const * name,
|
||||||
|
ino_t inode);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef WFP_OPERATION_ERROR_H
|
||||||
|
#define WFP_OPERATION_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_respond_error(
|
||||||
|
struct wfp_request * request,
|
||||||
|
wf_status status);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef WFP_OPERATION_GETATTR_H
|
||||||
|
#define WFP_OPERATION_GETATTR_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "webfuse/provider/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfp_request;
|
||||||
|
|
||||||
|
typedef void wfp_getattr_fn(
|
||||||
|
struct wfp_request * request,
|
||||||
|
ino_t inode,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_respond_getattr(
|
||||||
|
struct wfp_request * request,
|
||||||
|
struct stat const * stat);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef WFP_OPERATION_LOOKUP_H
|
||||||
|
#define WFP_OPERATION_LOOKUP_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "webfuse/provider/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfp_request;
|
||||||
|
|
||||||
|
typedef void wfp_lookup_fn(
|
||||||
|
struct wfp_request * request,
|
||||||
|
ino_t parent,
|
||||||
|
char const * name,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_respond_lookup(
|
||||||
|
struct wfp_request * request,
|
||||||
|
struct stat const * stat);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef WFP_OPERATION_READDIR_H
|
||||||
|
#define WFP_OPERATION_READDIR_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "webfuse/provider/api.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfp_dirbuffer;
|
||||||
|
struct wfp_request;
|
||||||
|
|
||||||
|
typedef void wfp_readdir_fn(
|
||||||
|
struct wfp_request * request,
|
||||||
|
ino_t directory,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
extern WFP_API void wfp_respond_readdir(
|
||||||
|
struct wfp_request * request,
|
||||||
|
struct wfp_dirbuffer * dirbuffer);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef WF_ADAPTER_H
|
||||||
|
#define WF_ADAPTER_H
|
||||||
|
|
||||||
|
#include <webfuse/core/status.h>
|
||||||
|
|
||||||
|
#include <webfuse/adapter/api.h>
|
||||||
|
#include <webfuse/adapter/server.h>
|
||||||
|
#include <webfuse/adapter/server_config.h>
|
||||||
|
#include <webfuse/adapter/server_protocol.h>
|
||||||
|
#include <webfuse/adapter/authenticate.h>
|
||||||
|
#include <webfuse/adapter/credentials.h>
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef WF_PROVIDER_H
|
||||||
|
#define WF_PROVIDER_H
|
||||||
|
|
||||||
|
#include <webfuse/core/status.h>
|
||||||
|
|
||||||
|
#include <webfuse/provider/api.h>
|
||||||
|
#include <webfuse/provider/client.h>
|
||||||
|
#include <webfuse/provider/client_config.h>
|
||||||
|
#include <webfuse/provider/client_protocol.h>
|
||||||
|
#include <webfuse/provider/dirbuffer.h>
|
||||||
|
|
||||||
|
#include <webfuse/provider/operation/error.h>
|
||||||
|
#include <webfuse/provider/operation/lookup.h>
|
||||||
|
#include <webfuse/provider/operation/getattr.h>
|
||||||
|
#include <webfuse/provider/operation/readdir.h>
|
||||||
|
#include <webfuse/provider/operation/open.h>
|
||||||
|
#include <webfuse/provider/operation/close.h>
|
||||||
|
#include <webfuse/provider/operation/read.h>
|
||||||
|
|
||||||
|
#endif
|
@ -1,16 +0,0 @@
|
|||||||
#ifndef WSFS_ADAPTER_API_H
|
|
||||||
#define WSFS_ADAPTER_API_H
|
|
||||||
|
|
||||||
#ifndef WSFSA_API
|
|
||||||
#define WSFSA_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WSFSA_EXPORT
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define WSFSA_EXPORT __attribute__ ((visibility ("default")))
|
|
||||||
#else
|
|
||||||
#define WSFSA_EXPORT
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,23 +0,0 @@
|
|||||||
#ifndef WSFS_ADAPTER_AUTHENTICATE_H
|
|
||||||
#define WSFS_ADAPTER_AUTHENTICATE_H
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfs_credentials;
|
|
||||||
|
|
||||||
typedef bool wsfs_authenticate_fn(
|
|
||||||
struct wsfs_credentials * credentials,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,25 +0,0 @@
|
|||||||
#ifndef WSFS_ADAPTER_CREDENTIALS_H
|
|
||||||
#define WSFS_ADAPTER_CREDENTIALS_H
|
|
||||||
|
|
||||||
#include "wsfs/adapter/api.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfs_credentials;
|
|
||||||
|
|
||||||
extern WSFSA_API char const * wsfs_credentials_type(
|
|
||||||
struct wsfs_credentials const * credentials);
|
|
||||||
|
|
||||||
extern WSFSA_API char const * wsfs_credentials_get(
|
|
||||||
struct wsfs_credentials const * credentials,
|
|
||||||
char const * key);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||||||
#ifndef WSFS_ADAPTER_SERVER_H
|
|
||||||
#define WSFS_ADAPTER_SERVER_H
|
|
||||||
|
|
||||||
#include "wsfs/adapter/api.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfs_server;
|
|
||||||
struct wsfs_server_config;
|
|
||||||
|
|
||||||
extern WSFSA_API struct wsfs_server * wsfs_server_create(
|
|
||||||
struct wsfs_server_config * config);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_dispose(
|
|
||||||
struct wsfs_server * server);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_run(
|
|
||||||
struct wsfs_server * server);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_shutdown(
|
|
||||||
struct wsfs_server * server);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,55 +0,0 @@
|
|||||||
#ifndef WSFS_ADAPTER_SERVER_CONFIG_H
|
|
||||||
#define WSFS_ADAPTER_SERVER_CONFIG_H
|
|
||||||
|
|
||||||
#include "wsfs/adapter/api.h"
|
|
||||||
#include "wsfs/adapter/authenticate.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfs_server_config;
|
|
||||||
|
|
||||||
extern WSFSA_API struct wsfs_server_config * wsfs_server_config_create(void);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_config_dispose(
|
|
||||||
struct wsfs_server_config * config);
|
|
||||||
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_config_set_mountpoint(
|
|
||||||
struct wsfs_server_config * config,
|
|
||||||
char const * mount_point);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_config_set_documentroot(
|
|
||||||
struct wsfs_server_config * config,
|
|
||||||
char const * document_root);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_config_set_keypath(
|
|
||||||
struct wsfs_server_config * config,
|
|
||||||
char const * key_path);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_config_set_certpath(
|
|
||||||
struct wsfs_server_config * config,
|
|
||||||
char const * cert_path);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_config_set_vhostname(
|
|
||||||
struct wsfs_server_config * config,
|
|
||||||
char const * vhost_name);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_config_set_port(
|
|
||||||
struct wsfs_server_config * config,
|
|
||||||
int port);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_config_add_authenticator(
|
|
||||||
struct wsfs_server_config * config,
|
|
||||||
char const * type,
|
|
||||||
wsfs_authenticate_fn * authenticate,
|
|
||||||
void * user_data
|
|
||||||
);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,35 +0,0 @@
|
|||||||
#ifndef WSFS_ADAPTER_SERVER_PROTOCOL_H
|
|
||||||
#define WSFS_ADAPTER_SERVER_PROTOCOL_H
|
|
||||||
|
|
||||||
#include <wsfs/adapter/api.h>
|
|
||||||
#include <wsfs/adapter/authenticate.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfs_server_protocol;
|
|
||||||
struct lws_protocols;
|
|
||||||
|
|
||||||
extern WSFSA_API struct wsfs_server_protocol * wsfs_server_protocol_create(
|
|
||||||
char * mount_point);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_protocol_dispose(
|
|
||||||
struct wsfs_server_protocol * protocol);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_protocol_init_lws(
|
|
||||||
struct wsfs_server_protocol * protocol,
|
|
||||||
struct lws_protocols * lws_protocol);
|
|
||||||
|
|
||||||
extern WSFSA_API void wsfs_server_protocol_add_authenticator(
|
|
||||||
struct wsfs_server_protocol * protocol,
|
|
||||||
char const * type,
|
|
||||||
wsfs_authenticate_fn * authenticate,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,17 +0,0 @@
|
|||||||
#ifndef WSFS_STATUS_H
|
|
||||||
#define WSFS_STATUS_H
|
|
||||||
|
|
||||||
#define WSFS_GOOD 0
|
|
||||||
#define WSFS_BAD 1
|
|
||||||
|
|
||||||
#define WSFS_BAD_NOTIMPLEMENTED 2
|
|
||||||
#define WSFS_BAD_TIMEOUT 3
|
|
||||||
#define WSFS_BAD_BUSY 4
|
|
||||||
#define WSFS_BAD_FORMAT 5
|
|
||||||
|
|
||||||
#define WSFS_BAD_NOENTRY 101
|
|
||||||
#define WSFS_BAD_NOACCESS 102
|
|
||||||
|
|
||||||
typedef int wsfs_status;
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,16 +0,0 @@
|
|||||||
#ifndef WSFSP_PROVIDER_API_H
|
|
||||||
#define WSFSP_PROVIDER_API_H
|
|
||||||
|
|
||||||
#ifndef WSFSP_API
|
|
||||||
#define WSFSP_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WSFSP_EXPORT
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define WSFSP_EXPORT __attribute__ ((visibility ("default")))
|
|
||||||
#else
|
|
||||||
#define WSFSP_EXPORT
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,39 +0,0 @@
|
|||||||
#ifndef WSFS_PROVIDER_CLIENT_H
|
|
||||||
#define WSFS_PROVIDER_CLIENT_H
|
|
||||||
|
|
||||||
#include "wsfs/provider/api.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfsp_client;
|
|
||||||
struct wsfsp_client_config;
|
|
||||||
|
|
||||||
extern WSFSP_API struct wsfsp_client * wsfsp_client_create(
|
|
||||||
struct wsfsp_client_config * config);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_connect(
|
|
||||||
struct wsfsp_client * client,
|
|
||||||
char const * url);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_disconnect(
|
|
||||||
struct wsfsp_client * client);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_dispose(
|
|
||||||
struct wsfsp_client * client);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_run(
|
|
||||||
struct wsfsp_client * client);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_shutdown(
|
|
||||||
struct wsfsp_client * client);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,88 +0,0 @@
|
|||||||
#ifndef WSFS_PROVIDER_CLIENT_CONFIG_H
|
|
||||||
#define WSFS_PROVIDER_CLIENT_CONFIG_H
|
|
||||||
|
|
||||||
#include <wsfs/provider/api.h>
|
|
||||||
|
|
||||||
#include <wsfs/provider/operation/lookup.h>
|
|
||||||
#include <wsfs/provider/operation/getattr.h>
|
|
||||||
#include <wsfs/provider/operation/readdir.h>
|
|
||||||
#include <wsfs/provider/operation/open.h>
|
|
||||||
#include <wsfs/provider/operation/close.h>
|
|
||||||
#include <wsfs/provider/operation/read.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfsp_client_config;
|
|
||||||
|
|
||||||
typedef void wsfsp_connected_fn(
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
typedef void wsfsp_disconnected_fn(
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
typedef void wsfsp_ontimer_fn(
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern WSFSP_API struct wsfsp_client_config * wsfsp_client_config_create(void);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_dispose(
|
|
||||||
struct wsfsp_client_config * config);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_userdata(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_keypath(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
char const * key_path);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_certpath(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
char const * cert_path);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_onconnected(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_connected_fn * handler);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_ondisconnected(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_disconnected_fn * handler);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_ontimer(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_ontimer_fn * handler);
|
|
||||||
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_onlookup(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_lookup_fn * handler);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_ongetattr(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_getattr_fn * handler);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_onreaddir(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_readdir_fn * handler);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_onopen(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_open_fn * handler);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_onclose(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_close_fn * handler);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_config_set_onread(
|
|
||||||
struct wsfsp_client_config * config,
|
|
||||||
wsfsp_read_fn * handler);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||||||
#ifndef WSFS_PROVIDER_CLIENT_PROTOCOL_H
|
|
||||||
#define WSFS_PROVIDER_CLIENT_PROTOCOL_H
|
|
||||||
|
|
||||||
#include "wsfs/provider/api.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfsp_client_protocol;
|
|
||||||
struct wsfsp_provider;
|
|
||||||
struct lws_protocols;
|
|
||||||
|
|
||||||
extern WSFSP_API struct wsfsp_client_protocol * wsfsp_client_protocol_create(
|
|
||||||
struct wsfsp_provider const * provider,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_protocol_dispose(
|
|
||||||
struct wsfsp_client_protocol * protocol);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_client_protocol_init_lws(
|
|
||||||
struct wsfsp_client_protocol * protocol,
|
|
||||||
struct lws_protocols * lws_protocol);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||||||
#ifndef WSFS_PROVIDER_DIRBUFFER_H
|
|
||||||
#define WSFS_PROVIDER_DIRBUFFER_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "wsfs/provider/api.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfsp_dirbuffer;
|
|
||||||
|
|
||||||
extern WSFSP_API struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_dirbuffer_dispose(
|
|
||||||
struct wsfsp_dirbuffer * buffer);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_dirbuffer_add(
|
|
||||||
struct wsfsp_dirbuffer * buffer,
|
|
||||||
char const * name,
|
|
||||||
ino_t inode);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,22 +0,0 @@
|
|||||||
#ifndef WSFSP_OPERATION_ERROR_H
|
|
||||||
#define WSFSP_OPERATION_ERROR_H
|
|
||||||
|
|
||||||
#include "wsfs/provider/api.h"
|
|
||||||
#include "wsfs/core/status.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfsp_request;
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_respond_error(
|
|
||||||
struct wsfsp_request * request,
|
|
||||||
wsfs_status status);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||||||
#ifndef WSFSP_OPERATION_GETATTR_H
|
|
||||||
#define WSFSP_OPERATION_GETATTR_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "wsfs/provider/api.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfsp_request;
|
|
||||||
|
|
||||||
typedef void wsfsp_getattr_fn(
|
|
||||||
struct wsfsp_request * request,
|
|
||||||
ino_t inode,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_respond_getattr(
|
|
||||||
struct wsfsp_request * request,
|
|
||||||
struct stat const * stat);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||||||
#ifndef WSFSP_OPERATION_LOOKUP_H
|
|
||||||
#define WSFSP_OPERATION_LOOKUP_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "wsfs/provider/api.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfsp_request;
|
|
||||||
|
|
||||||
typedef void wsfsp_lookup_fn(
|
|
||||||
struct wsfsp_request * request,
|
|
||||||
ino_t parent,
|
|
||||||
char const * name,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_respond_lookup(
|
|
||||||
struct wsfsp_request * request,
|
|
||||||
struct stat const * stat);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||||||
#ifndef WSFSP_OPERATION_READDIR_H
|
|
||||||
#define WSFSP_OPERATION_READDIR_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "wsfs/provider/api.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wsfsp_dirbuffer;
|
|
||||||
struct wsfsp_request;
|
|
||||||
|
|
||||||
typedef void wsfsp_readdir_fn(
|
|
||||||
struct wsfsp_request * request,
|
|
||||||
ino_t directory,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
extern WSFSP_API void wsfsp_respond_readdir(
|
|
||||||
struct wsfsp_request * request,
|
|
||||||
struct wsfsp_dirbuffer * dirbuffer);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,13 +0,0 @@
|
|||||||
#ifndef WSFS_ADAPTER_H
|
|
||||||
#define WSFS_ADAPTER_H
|
|
||||||
|
|
||||||
#include <wsfs/core/status.h>
|
|
||||||
|
|
||||||
#include <wsfs/adapter/api.h>
|
|
||||||
#include <wsfs/adapter/server.h>
|
|
||||||
#include <wsfs/adapter/server_config.h>
|
|
||||||
#include <wsfs/adapter/server_protocol.h>
|
|
||||||
#include <wsfs/adapter/authenticate.h>
|
|
||||||
#include <wsfs/adapter/credentials.h>
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,20 +0,0 @@
|
|||||||
#ifndef WSFS_PROVIDER_H
|
|
||||||
#define WSFS_PROVIDER_H
|
|
||||||
|
|
||||||
#include <wsfs/core/status.h>
|
|
||||||
|
|
||||||
#include <wsfs/provider/api.h>
|
|
||||||
#include <wsfs/provider/client.h>
|
|
||||||
#include <wsfs/provider/client_config.h>
|
|
||||||
#include <wsfs/provider/client_protocol.h>
|
|
||||||
#include <wsfs/provider/dirbuffer.h>
|
|
||||||
|
|
||||||
#include <wsfs/provider/operation/error.h>
|
|
||||||
#include <wsfs/provider/operation/lookup.h>
|
|
||||||
#include <wsfs/provider/operation/getattr.h>
|
|
||||||
#include <wsfs/provider/operation/readdir.h>
|
|
||||||
#include <wsfs/provider/operation/open.h>
|
|
||||||
#include <wsfs/provider/operation/close.h>
|
|
||||||
#include <wsfs/provider/operation/read.h>
|
|
||||||
|
|
||||||
#endif
|
|
@ -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);
|
||||||
|
}
|
@ -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
|
@ -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;
|
||||||
|
}
|
@ -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
|
@ -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
|
@ -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
|
#ifndef WF_ADAPTER_IMPL_FUSE_H
|
||||||
#define WSFS_ADAPTER_IMPL_FUSE_H
|
#define WF_ADAPTER_IMPL_FUSE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
@ -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
|
#ifndef WF_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||||
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
|
#define WF_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include "wsfs/core/status.h"
|
#include "webfuse/core/status.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef bool wsfs_impl_jsonrpc_method_invoke_fn(
|
typedef bool wf_impl_jsonrpc_method_invoke_fn(
|
||||||
void * user_data,
|
void * user_data,
|
||||||
struct json_t const * method_call);
|
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,
|
void * user_data,
|
||||||
wsfs_status status,
|
wf_status status,
|
||||||
struct json_t const * result);
|
struct json_t const * result);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
@ -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,
|
char const * method,
|
||||||
int id,
|
int id,
|
||||||
char const * param_info,
|
char const * param_info,
|
@ -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
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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;
|
int result = default_value;
|
||||||
|
|
@ -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
|
@ -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,48 +1,48 @@
|
|||||||
#ifndef WSFS_ADAPTER_IMPL_OPERATIONS_H
|
#ifndef WF_ADAPTER_IMPL_OPERATIONS_H
|
||||||
#define WSFS_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
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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;
|
double timeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void wsfs_impl_operation_lookup (
|
extern void wf_impl_operation_lookup (
|
||||||
fuse_req_t req,
|
fuse_req_t req,
|
||||||
fuse_ino_t parent,
|
fuse_ino_t parent,
|
||||||
char const * name);
|
char const * name);
|
||||||
|
|
||||||
extern void wsfs_impl_operation_getattr (
|
extern void wf_impl_operation_getattr (
|
||||||
fuse_req_t request,
|
fuse_req_t request,
|
||||||
fuse_ino_t inode,
|
fuse_ino_t inode,
|
||||||
struct fuse_file_info *file_info);
|
struct fuse_file_info *file_info);
|
||||||
|
|
||||||
extern void wsfs_impl_operation_readdir (
|
extern void wf_impl_operation_readdir (
|
||||||
fuse_req_t request,
|
fuse_req_t request,
|
||||||
fuse_ino_t inode,
|
fuse_ino_t inode,
|
||||||
size_t size,
|
size_t size,
|
||||||
off_t offset,
|
off_t offset,
|
||||||
struct fuse_file_info *file_info);
|
struct fuse_file_info *file_info);
|
||||||
|
|
||||||
extern void wsfs_impl_operation_open(
|
extern void wf_impl_operation_open(
|
||||||
fuse_req_t request,
|
fuse_req_t request,
|
||||||
fuse_ino_t inode,
|
fuse_ino_t inode,
|
||||||
struct fuse_file_info * file_info);
|
struct fuse_file_info * file_info);
|
||||||
|
|
||||||
extern void wsfs_impl_operation_close(
|
extern void wf_impl_operation_close(
|
||||||
fuse_req_t request,
|
fuse_req_t request,
|
||||||
fuse_ino_t inode,
|
fuse_ino_t inode,
|
||||||
struct fuse_file_info * file_info);
|
struct fuse_file_info * file_info);
|
||||||
|
|
||||||
extern void wsfs_impl_operation_read(
|
extern void wf_impl_operation_read(
|
||||||
fuse_req_t request,
|
fuse_req_t request,
|
||||||
fuse_ino_t ino, size_t size, off_t off,
|
fuse_ino_t ino, size_t size, off_t off,
|
||||||
struct fuse_file_info *fi);
|
struct fuse_file_info *fi);
|
@ -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
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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
|
@ -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);
|
||||||
|
}
|
@ -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
|
@ -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);
|
||||||
|
}
|
@ -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
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
@ -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
|
@ -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);
|
||||||
|
}
|
@ -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
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
@ -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
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue