* moves implementation to impl subdirectory * adds prefix _impl to implementation symbols * removes double compilation for shared and static libraries * fixes include guards * fixes usage of extern "C"pull/2/head
parent
48185776b6
commit
1c9d1c8420
@ -0,0 +1,141 @@
|
||||
#include "wsfs_adapter.h"
|
||||
|
||||
#include "wsfs/adapter/impl/server.h"
|
||||
#include "wsfs/adapter/impl/server_protocol.h"
|
||||
#include "wsfs/adapter/impl/server_config.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
|
||||
// server
|
||||
|
||||
struct wsfs_server * wsfs_server_create(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
return wsfs_impl_server_create(config);
|
||||
}
|
||||
|
||||
void wsfs_server_dispose(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_dispose(server);
|
||||
}
|
||||
|
||||
void wsfs_server_run(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_run(server);
|
||||
}
|
||||
|
||||
void wsfs_server_shutdown(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_shutdown(server);
|
||||
}
|
||||
|
||||
// server protocol
|
||||
|
||||
struct wsfs_server_protocol * wsfs_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
return wsfs_impl_server_protocol_create(mount_point);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_dispose(protocol);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_init_lws(protocol, lws_protocol);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// server_config
|
||||
|
||||
struct wsfs_server_config * wsfs_server_config_create(void)
|
||||
{
|
||||
return wsfs_impl_server_config_create();
|
||||
}
|
||||
|
||||
void wsfs_server_config_dispose(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
wsfs_impl_server_config_dispose(config);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_mountpoint(
|
||||
struct wsfs_server_config * config,
|
||||
char const * mount_point)
|
||||
{
|
||||
wsfs_impl_server_config_set_mountpoint(config, mount_point);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_documentroot(
|
||||
struct wsfs_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
wsfs_impl_server_config_set_documentroot(config, document_root);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_keypath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wsfs_impl_server_config_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_certpath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wsfs_impl_server_config_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_vhostname(
|
||||
struct wsfs_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
wsfs_impl_server_config_set_vhostname(config, vhost_name);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_port(
|
||||
struct wsfs_server_config * config,
|
||||
int port)
|
||||
{
|
||||
wsfs_impl_server_config_set_port(config, port);
|
||||
}
|
||||
|
||||
void wsfs_server_config_add_authenticator(
|
||||
struct wsfs_server_config * config,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_server_config_add_authenticator(config, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// credentials
|
||||
|
||||
char const * wsfs_credentials_type(
|
||||
struct wsfs_credentials const * credentials)
|
||||
{
|
||||
return wsfs_impl_credentials_type(credentials);
|
||||
}
|
||||
|
||||
char const * wsfs_credentials_get(
|
||||
struct wsfs_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
return wsfs_impl_credentials_get(credentials, key);
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_AUTHENTICATOR_H
|
||||
#define WSFS_ADAPTER_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
struct wsfs_authenticator
|
||||
{
|
||||
char * type;
|
||||
wsfs_authenticate_fn * authenticate;
|
||||
void * user_data;
|
||||
struct wsfs_authenticator * next;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wsfs_authenticator * wsfs_authenticator_create(
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_authenticator_dispose(
|
||||
struct wsfs_authenticator * authenticator);
|
||||
|
||||
extern bool wsfs_authenticator_autenticate(
|
||||
struct wsfs_authenticator * authenticator,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -1,101 +0,0 @@
|
||||
#include "wsfs/adapter/authenticators.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/authenticator.h"
|
||||
#include "wsfs/adapter/credentials_intern.h"
|
||||
|
||||
static struct wsfs_authenticator * wsfs_authenticators_find(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
char const * type)
|
||||
{
|
||||
struct wsfs_authenticator * result = NULL;
|
||||
|
||||
struct wsfs_authenticator * actual = authenticators->first;
|
||||
while ((NULL == result) && (NULL != actual))
|
||||
{
|
||||
struct wsfs_authenticator * next = actual->next;
|
||||
if (0 == strcmp(type, actual->type))
|
||||
{
|
||||
result = actual;
|
||||
}
|
||||
|
||||
actual = next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_authenticators_init(
|
||||
struct wsfs_authenticators * authenticators)
|
||||
{
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_authenticators_cleanup(
|
||||
struct wsfs_authenticators * authenticators)
|
||||
{
|
||||
struct wsfs_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_authenticator * next = actual->next;
|
||||
wsfs_authenticator_dispose(actual);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_authenticators_clone(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_authenticators * other)
|
||||
{
|
||||
wsfs_authenticators_init(other);
|
||||
|
||||
struct wsfs_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_authenticator * next = actual->next;
|
||||
wsfs_authenticators_add(other,
|
||||
actual->type, actual->authenticate, actual->user_data);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern void wsfs_authenticators_move(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_authenticators * other)
|
||||
{
|
||||
other->first = authenticators->first;
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_authenticators_add(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(type, authenticate, user_data);
|
||||
authenticator->next = authenticators->first;
|
||||
authenticators->first = authenticator;
|
||||
}
|
||||
|
||||
bool wsfs_authenticators_authenticate(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials)
|
||||
{
|
||||
bool result = (NULL == authenticators->first);
|
||||
|
||||
if (NULL != credentials)
|
||||
{
|
||||
struct wsfs_authenticator * authenticator = wsfs_authenticators_find(authenticators, credentials->type);
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
result = wsfs_authenticator_autenticate(authenticator, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_AUTHENTICATORS_H
|
||||
#define WSFS_ADAPTER_AUTHENTICATORS_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
struct wsfs_authenticator;
|
||||
struct wsfs_credentials;
|
||||
|
||||
struct wsfs_authenticators
|
||||
{
|
||||
struct wsfs_authenticator * first;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_authenticators_init(
|
||||
struct wsfs_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_authenticators_cleanup(
|
||||
struct wsfs_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_authenticators_clone(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_authenticators * other);
|
||||
|
||||
extern void wsfs_authenticators_move(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_authenticators * other);
|
||||
|
||||
extern void wsfs_authenticators_add(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern bool wsfs_authenticators_authenticate(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,30 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_CREDENTIALS_INTERN_H
|
||||
#define WSFS_ADAPTER_CREDENTIALS_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/credentials.h"
|
||||
#include <jansson.h>
|
||||
|
||||
struct wsfs_credentials
|
||||
{
|
||||
char * type;
|
||||
json_t * data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_credentials_init(
|
||||
struct wsfs_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data);
|
||||
|
||||
extern void wsfs_credentials_cleanup(
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,45 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_FILESYSTEM_H
|
||||
#define WSFS_ADAPTER_FILESYSTEM_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/fuse_wrapper.h"
|
||||
#include "wsfs/adapter/operations.h"
|
||||
|
||||
struct wsfs_jsonrpc_server;
|
||||
|
||||
struct wsfs_filesystem
|
||||
{
|
||||
struct fuse_args args;
|
||||
struct fuse_session * session;
|
||||
struct fuse_buf buffer;
|
||||
struct wsfs_operations_context user_data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wsfs_filesystem_init(
|
||||
struct wsfs_filesystem * filesystem,
|
||||
struct wsfs_jsonrpc_server * rpc,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_filesystem_cleanup(
|
||||
struct wsfs_filesystem * filesystem);
|
||||
|
||||
extern int wsfs_filesystem_get_fd(
|
||||
struct wsfs_filesystem * filesystem);
|
||||
|
||||
extern void wsfs_filesystem_process_request(
|
||||
struct wsfs_filesystem * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,42 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
#define WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_credentials;
|
||||
|
||||
struct wsfs_impl_authenticator
|
||||
{
|
||||
char * type;
|
||||
wsfs_authenticate_fn * authenticate;
|
||||
void * user_data;
|
||||
struct wsfs_impl_authenticator * next;
|
||||
};
|
||||
|
||||
extern struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_impl_authenticator_dispose(
|
||||
struct wsfs_impl_authenticator * authenticator);
|
||||
|
||||
extern bool wsfs_impl_authenticator_autenticate(
|
||||
struct wsfs_impl_authenticator * authenticator,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -0,0 +1,101 @@
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
|
||||
static struct wsfs_impl_authenticator * wsfs_impl_authenticators_find(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type)
|
||||
{
|
||||
struct wsfs_impl_authenticator * result = NULL;
|
||||
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while ((NULL == result) && (NULL != actual))
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
if (0 == strcmp(type, actual->type))
|
||||
{
|
||||
result = actual;
|
||||
}
|
||||
|
||||
actual = next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_init(
|
||||
struct wsfs_impl_authenticators * authenticators)
|
||||
{
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_cleanup(
|
||||
struct wsfs_impl_authenticators * authenticators)
|
||||
{
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
wsfs_impl_authenticator_dispose(actual);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_clone(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other)
|
||||
{
|
||||
wsfs_impl_authenticators_init(other);
|
||||
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
wsfs_impl_authenticators_add(other,
|
||||
actual->type, actual->authenticate, actual->user_data);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern void wsfs_impl_authenticators_move(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other)
|
||||
{
|
||||
other->first = authenticators->first;
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_add(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(type, authenticate, user_data);
|
||||
authenticator->next = authenticators->first;
|
||||
authenticators->first = authenticator;
|
||||
}
|
||||
|
||||
bool wsfs_impl_authenticators_authenticate(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials)
|
||||
{
|
||||
bool result = (NULL == authenticators->first);
|
||||
|
||||
if (NULL != credentials)
|
||||
{
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticators_find(authenticators, credentials->type);
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
result = wsfs_impl_authenticator_autenticate(authenticator, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
#define WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_authenticator;
|
||||
struct wsfs_credentials;
|
||||
|
||||
struct wsfs_impl_authenticators
|
||||
{
|
||||
struct wsfs_impl_authenticator * first;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_authenticators_init(
|
||||
struct wsfs_impl_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_impl_authenticators_cleanup(
|
||||
struct wsfs_impl_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_impl_authenticators_clone(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other);
|
||||
|
||||
extern void wsfs_impl_authenticators_move(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other);
|
||||
|
||||
extern void wsfs_impl_authenticators_add(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern bool wsfs_impl_authenticators_authenticate(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,36 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_CREDENTIALS_H
|
||||
#define WSFS_ADAPTER_IMPL_CREDENTIALS_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_credentials
|
||||
{
|
||||
char * type;
|
||||
json_t * data;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_credentials_init(
|
||||
struct wsfs_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data);
|
||||
|
||||
extern void wsfs_impl_credentials_cleanup(
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
extern char const * wsfs_impl_credentials_type(
|
||||
struct wsfs_credentials const * credentials);
|
||||
|
||||
extern char const * wsfs_impl_credentials_get(
|
||||
struct wsfs_credentials const * credentials,
|
||||
char const * key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,45 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_FILESYSTEM_H
|
||||
#define WSFS_ADAPTER_IMPL_FILESYSTEM_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/impl/fuse_wrapper.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_server;
|
||||
|
||||
struct wsfs_impl_filesystem
|
||||
{
|
||||
struct fuse_args args;
|
||||
struct fuse_session * session;
|
||||
struct fuse_buf buffer;
|
||||
struct wsfs_impl_operations_context user_data;
|
||||
};
|
||||
|
||||
extern bool wsfs_impl_filesystem_init(
|
||||
struct wsfs_impl_filesystem * filesystem,
|
||||
struct wsfs_impl_jsonrpc_server * rpc,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_filesystem_cleanup(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
extern int wsfs_impl_filesystem_get_fd(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
extern void wsfs_impl_filesystem_process_request(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
#ifndef WSFS_ADAPTER_FUSE_H
|
||||
#define WSFS_ADAPTER_FUSE_H
|
||||
#ifndef WSFS_ADAPTER_IMPL_FUSE_H
|
||||
#define WSFS_ADAPTER_IMPL_FUSE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
@ -0,0 +1,28 @@
|
||||
#include "wsfs/adapter/impl/jsonrpc/method_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * method = malloc(sizeof(struct wsfs_impl_jsonrpc_method));
|
||||
if (NULL != method)
|
||||
{
|
||||
method->next = NULL;
|
||||
method->name = strdup(name);
|
||||
method->invoke = invoke;
|
||||
method->user_data = user_data;
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
void wsfs_impl_jsonrpc_method_dispose(
|
||||
struct wsfs_impl_jsonrpc_method * method)
|
||||
{
|
||||
free(method->name);
|
||||
free(method);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef bool wsfs_impl_jsonrpc_method_invoke_fn(
|
||||
void * user_data,
|
||||
struct json_t const * method_call);
|
||||
|
||||
typedef void wsfs_impl_jsonrpc_method_finished_fn(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
struct json_t const * result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,31 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/method.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_method
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * next;
|
||||
char * name;
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_method_dispose(
|
||||
struct wsfs_impl_jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
#include "wsfs/adapter/jsonrpc/request.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/request.h"
|
||||
|
||||
json_t * wsfs_jsonrpc_request_create(
|
||||
json_t * wsfs_impl_jsonrpc_request_create(
|
||||
char const * method,
|
||||
int id,
|
||||
char const * param_info,
|
@ -0,0 +1,38 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_response
|
||||
{
|
||||
wsfs_status status;
|
||||
int id;
|
||||
json_t * result;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_jsonrpc_response_init(
|
||||
struct wsfs_impl_jsonrpc_response * response,
|
||||
char const * buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_response_cleanup(
|
||||
struct wsfs_impl_jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,77 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/adapter/impl/jsonrpc/method.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/impl/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wsfs_impl_timer timer;
|
||||
};
|
||||
|
||||
struct wsfs_impl_jsonrpc_server
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * methods;
|
||||
struct wsfs_impl_jsonrpc_request request;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_init(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_cleanup(
|
||||
struct wsfs_impl_jsonrpc_server * server);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_add(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data );
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_invoke(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_notify(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_onresult(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
#include "wsfs/adapter/jsonrpc/util.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/util.h"
|
||||
|
||||
int wsfs_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
{
|
||||
int result = default_value;
|
||||
|
@ -0,0 +1,17 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSON_UTIL_H
|
||||
#define WSFS_ADAPTER_IMPL_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,21 @@
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfs_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wsfs_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
@ -1,48 +1,48 @@
|
||||
#ifndef WSFS_ADAPTER_OPERATIONS
|
||||
#define WSFS_ADAPTER_OPERATIONS
|
||||
#ifndef WSFS_ADAPTER_IMPL_OPERATIONS_H
|
||||
#define WSFS_ADAPTER_IMPL_OPERATIONS_H
|
||||
|
||||
#include "wsfs/adapter/fuse_wrapper.h"
|
||||
#include "wsfs/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
struct wsfs_jsonrpc_server;
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_server;
|
||||
|
||||
struct wsfs_operations_context
|
||||
struct wsfs_impl_operations_context
|
||||
{
|
||||
struct wsfs_jsonrpc_server * rpc;
|
||||
struct wsfs_impl_jsonrpc_server * rpc;
|
||||
double timeout;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void wsfs_operation_lookup (
|
||||
extern void wsfs_impl_operation_lookup (
|
||||
fuse_req_t req,
|
||||
fuse_ino_t parent,
|
||||
char const * name);
|
||||
|
||||
extern void wsfs_operation_getattr (
|
||||
extern void wsfs_impl_operation_getattr (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info *file_info);
|
||||
|
||||
extern void wsfs_operation_readdir (
|
||||
extern void wsfs_impl_operation_readdir (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info *file_info);
|
||||
|
||||
extern void wsfs_operation_open(
|
||||
extern void wsfs_impl_operation_open(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info);
|
||||
|
||||
extern void wsfs_operation_close(
|
||||
extern void wsfs_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info);
|
||||
|
||||
extern void wsfs_operation_read(
|
||||
extern void wsfs_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t ino, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
@ -0,0 +1,29 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_server;
|
||||
struct wsfs_server_config;
|
||||
|
||||
extern struct wsfs_server * wsfs_impl_server_create(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_dispose(
|
||||
struct wsfs_server * server);
|
||||
|
||||
extern void wsfs_impl_server_run(
|
||||
struct wsfs_server * server);
|
||||
|
||||
extern void wsfs_impl_server_shutdown(
|
||||
struct wsfs_server * server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,72 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_server_config
|
||||
{
|
||||
char * mount_point;
|
||||
char * document_root;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * vhost_name;
|
||||
int port;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
};
|
||||
|
||||
extern struct wsfs_server_config * wsfs_impl_server_config_create(void);
|
||||
|
||||
extern void wsfs_impl_server_config_dispose(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_init(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_cleanup(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_clone(
|
||||
struct wsfs_server_config * config,
|
||||
struct wsfs_server_config * clone);
|
||||
|
||||
extern void wsfs_impl_server_config_set_mountpoint(
|
||||
struct wsfs_server_config * config,
|
||||
char const * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_config_set_documentroot(
|
||||
struct wsfs_server_config * config,
|
||||
char const * document_root);
|
||||
|
||||
extern void wsfs_impl_server_config_set_keypath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void wsfs_impl_server_config_set_certpath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void wsfs_impl_server_config_set_vhostname(
|
||||
struct wsfs_server_config * config,
|
||||
char const * vhost_name);
|
||||
|
||||
extern void wsfs_impl_server_config_set_port(
|
||||
struct wsfs_server_config * config,
|
||||
int port);
|
||||
|
||||
extern void wsfs_impl_server_config_add_authenticator(
|
||||
struct wsfs_server_config * config,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,166 @@
|
||||
#include "wsfs/adapter/impl/server_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/core/message.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
#include "wsfs/adapter/impl/filesystem.h"
|
||||
|
||||
static int wsfs_impl_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wsfs_server_protocol * protocol = ws_protocol->user;
|
||||
|
||||
wsfs_impl_timeout_manager_check(&protocol->timeout_manager);
|
||||
struct wsfs_impl_session * session = wsfs_impl_session_manager_get(&protocol->session_manager, wsi);
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
{
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = wsfs_impl_filesystem_get_fd(&protocol->filesystem);
|
||||
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
|
||||
{
|
||||
fprintf(stderr, "error: unable to adopt fd");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wsfs_impl_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->rpc);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_authenticate(session, NULL);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
wsfs_impl_session_manager_remove(&protocol->session_manager, wsi);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_onwritable(session);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_receive(session, in, len);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
wsfs_impl_filesystem_process_request(&protocol->filesystem);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool wsfs_impl_server_protocol_invoke(
|
||||
void * user_data,
|
||||
json_t const * request)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = user_data;
|
||||
struct wsfs_impl_session * session = &protocol->session_manager.session;
|
||||
struct wsfs_message * message = wsfs_message_create(request);
|
||||
|
||||
bool const result = wsfs_impl_session_send(session, message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
if (!wsfs_impl_server_protocol_init(protocol, mount_point))
|
||||
{
|
||||
free(protocol);
|
||||
protocol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wsfs_impl_server_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
bool wsfs_impl_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point)
|
||||
{
|
||||
wsfs_impl_timeout_manager_init(&protocol->timeout_manager);
|
||||
wsfs_impl_session_manager_init(&protocol->session_manager);
|
||||
wsfs_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
wsfs_impl_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
|
||||
bool const success = wsfs_impl_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
|
||||
|
||||
// cleanup on error
|
||||
if (!success)
|
||||
{
|
||||
wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_filesystem_cleanup(&protocol->filesystem);
|
||||
wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "wsfs/adapter/impl/filesystem.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include "wsfs/adapter/impl/session_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws_protocols;
|
||||
|
||||
struct wsfs_server_protocol
|
||||
{
|
||||
struct wsfs_impl_timeout_manager timeout_manager;
|
||||
struct wsfs_impl_filesystem filesystem;
|
||||
struct wsfs_impl_jsonrpc_server rpc;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_session_manager session_manager;
|
||||
};
|
||||
|
||||
extern bool wsfs_impl_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol);
|
||||
|
||||
extern struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol);
|
||||
|
||||
extern void wsfs_impl_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
extern void wsfs_impl_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,64 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SESSION_H
|
||||
#define WSFS_ADAPTER_IMPL_SESSION_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "wsfs/core/message_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wsfs_message;
|
||||
struct wsfs_credentials;
|
||||
struct wsfs_impl_authenticators;
|
||||
struct wsfs_impl_jsonrpc_server;
|
||||
|
||||
struct wsfs_impl_session
|
||||
{
|
||||
struct lws * wsi;
|
||||
bool is_authenticated;
|
||||
struct wsfs_message_queue queue;
|
||||
struct wsfs_impl_authenticators * authenticators;
|
||||
struct wsfs_impl_jsonrpc_server * rpc;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_session_init(
|
||||
struct wsfs_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_jsonrpc_server * rpc);
|
||||
|
||||
extern void wsfs_impl_session_authenticate(
|
||||
struct wsfs_impl_session * session,
|
||||
struct wsfs_credentials * creds);
|
||||
|
||||
extern bool wsfs_impl_session_send(
|
||||
struct wsfs_impl_session * session,
|
||||
struct wsfs_message * message);
|
||||
|
||||
extern void wsfs_impl_session_receive(
|
||||
struct wsfs_impl_session * session,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
extern void wsfs_impl_session_onwritable(
|
||||
struct wsfs_impl_session * session);
|
||||
|
||||
extern void wsfs_impl_session_cleanup(
|
||||
struct wsfs_impl_session * session);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,54 @@
|
||||
#include "wsfs/adapter/impl/session_manager.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void wsfs_impl_session_manager_init(
|
||||
struct wsfs_impl_session_manager * manager)
|
||||
{
|
||||
wsfs_impl_session_init(&manager->session, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void wsfs_impl_session_manager_cleanup(
|
||||
struct wsfs_impl_session_manager * manager)
|
||||
{
|
||||
wsfs_impl_session_cleanup(&manager->session);
|
||||
}
|
||||
|
||||
struct wsfs_impl_session * wsfs_impl_session_manager_add(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_jsonrpc_server * rpc)
|
||||
{
|
||||
struct wsfs_impl_session * session = NULL;
|
||||
if (NULL == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
wsfs_impl_session_init(&manager->session, wsi, authenticators, rpc);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
struct wsfs_impl_session * wsfs_impl_session_manager_get(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wsfs_impl_session * session = NULL;
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
void wsfs_impl_session_manager_remove(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
wsfs_impl_session_cleanup(&manager->session);
|
||||
manager->session.wsi = NULL;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SESSION_MANAGER_H
|
||||
#define WSFS_ADAPTER_IMPL_SESSION_MANAGER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/impl/session.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
|
||||
struct wsfs_impl_session_manager
|
||||
{
|
||||
struct wsfs_impl_session session;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_session_manager_init(
|
||||
struct wsfs_impl_session_manager * manager);
|
||||
|
||||
extern void wsfs_impl_session_manager_cleanup(
|
||||
struct wsfs_impl_session_manager * manager);
|
||||
|
||||
extern struct wsfs_impl_session * wsfs_impl_session_manager_add(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_jsonrpc_server * rpc);
|
||||
|
||||
extern struct wsfs_impl_session * wsfs_impl_session_manager_get(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
extern void wsfs_impl_session_manager_remove(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,84 @@
|
||||
#include "wsfs/adapter/impl/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "wsfs/adapter/impl/time/timer_intern.h"
|
||||
#include "wsfs/adapter/impl/time/timepoint.h"
|
||||
|
||||
void wsfs_impl_timeout_manager_init(
|
||||
struct wsfs_impl_timeout_manager * manager)
|
||||
{
|
||||
manager->timers = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_timeout_manager_cleanup(
|
||||
struct wsfs_impl_timeout_manager * manager)
|
||||
{
|
||||
struct wsfs_impl_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wsfs_impl_timer * next = timer->next;
|
||||
|
||||
wsfs_impl_timer_trigger(timer);
|
||||
|
||||
timer = next;
|
||||
}
|
||||
|
||||
manager->timers = NULL;
|
||||
|
||||
}
|
||||
|
||||
void wsfs_impl_timeout_manager_check(
|
||||
struct wsfs_impl_timeout_manager * manager)
|
||||
{
|
||||
struct wsfs_impl_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wsfs_impl_timer * next = timer->next;
|
||||
|
||||
if (wsfs_impl_timer_is_timeout(timer))
|
||||
{
|
||||
wsfs_impl_timeout_manager_removetimer(manager, timer);
|
||||
wsfs_impl_timer_trigger(timer);
|
||||
}
|
||||
|
||||
timer = next;
|
||||
}
|
||||
}
|
||||
|
||||
void wsfs_impl_timeout_manager_addtimer(
|
||||
struct wsfs_impl_timeout_manager * manager,
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
if (NULL != manager->timers)
|
||||
{
|
||||
manager->timers->prev = timer;
|
||||
}
|
||||
|
||||
timer->next = manager->timers;
|
||||
timer->prev = NULL;
|
||||
manager->timers = timer;
|
||||
}
|
||||
|
||||
void wsfs_impl_timeout_manager_removetimer(
|
||||
struct wsfs_impl_timeout_manager * manager,
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
struct wsfs_impl_timer * prev = timer->prev;
|
||||
struct wsfs_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 WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_timer;
|
||||
struct wsfs_impl_timeout_manager
|
||||
{
|
||||
struct wsfs_impl_timer * timers;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_timeout_manager_init(
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_timeout_manager_cleanup(
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_timeout_manager_check(
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,24 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_impl_timeout_manager_addtimer(
|
||||
struct wsfs_impl_timeout_manager * manager,
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
extern void wsfs_impl_timeout_manager_removetimer(
|
||||
struct wsfs_impl_timeout_manager * manager,
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,31 @@
|
||||
#include "wsfs/adapter/impl/time/timepoint.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define WSFS_MSEC_PER_SEC ((wsfs_impl_timepoint) 1000)
|
||||
#define WSFS_NSEC_PER_MSEC ((wsfs_impl_timepoint) 1000 * 1000)
|
||||
|
||||
wsfs_impl_timepoint wsfs_impl_timepoint_now(void)
|
||||
{
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
|
||||
wsfs_impl_timepoint const now = (tp.tv_sec * WSFS_MSEC_PER_SEC) + (tp.tv_nsec / WSFS_NSEC_PER_MSEC);
|
||||
return now;
|
||||
}
|
||||
|
||||
wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(wsfs_impl_timediff value)
|
||||
{
|
||||
wsfs_impl_timepoint const now = wsfs_impl_timepoint_now();
|
||||
wsfs_impl_timepoint result = now + ((wsfs_impl_timepoint) value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool wsfs_impl_timepoint_is_elapsed(wsfs_impl_timepoint tp)
|
||||
{
|
||||
wsfs_impl_timepoint const now = wsfs_impl_timepoint_now();
|
||||
wsfs_impl_timediff const diff = (wsfs_impl_timediff) (tp - now);
|
||||
|
||||
return (0 > diff);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H
|
||||
#define WSFS_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 wsfs_impl_timepoint;
|
||||
typedef int64_t wsfs_impl_timediff;
|
||||
|
||||
extern wsfs_impl_timepoint wsfs_impl_timepoint_now(void);
|
||||
|
||||
extern wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(
|
||||
wsfs_impl_timediff value);
|
||||
|
||||
extern bool wsfs_impl_timepoint_is_elapsed(
|
||||
wsfs_impl_timepoint timepoint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,65 @@
|
||||
#include "wsfs/adapter/impl/time/timer_intern.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void wsfs_impl_timer_init(
|
||||
struct wsfs_impl_timer * timer,
|
||||
struct wsfs_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 wsfs_impl_timer_cleanup(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
memset(timer, 0, sizeof(struct wsfs_impl_timer));
|
||||
}
|
||||
|
||||
void wsfs_impl_timer_start(
|
||||
struct wsfs_impl_timer * timer,
|
||||
wsfs_impl_timepoint absolute_timeout,
|
||||
wsfs_impl_timer_timeout_fn * handler,
|
||||
void * user_data)
|
||||
{
|
||||
timer->timeout = absolute_timeout;
|
||||
timer->timeout_handler = handler;
|
||||
timer->user_data = user_data;
|
||||
|
||||
wsfs_impl_timeout_manager_addtimer(timer->manager, timer);
|
||||
}
|
||||
|
||||
void wsfs_impl_timer_cancel(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
wsfs_impl_timeout_manager_removetimer(timer->manager, timer);
|
||||
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
}
|
||||
|
||||
bool wsfs_impl_timer_is_timeout(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
return wsfs_impl_timepoint_is_elapsed(timer->timeout);
|
||||
}
|
||||
|
||||
|
||||
void wsfs_impl_timer_trigger(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
if (NULL != timer->timeout_handler)
|
||||
{
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
|
||||
timer->timeout_handler(timer);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMER_H
|
||||
|
||||
#include "wsfs/adapter/impl/time/timepoint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_timer;
|
||||
struct wsfs_impl_timeout_manager;
|
||||
|
||||
typedef void wsfs_impl_timer_timeout_fn(struct wsfs_impl_timer * timer);
|
||||
|
||||
struct wsfs_impl_timer
|
||||
{
|
||||
struct wsfs_impl_timeout_manager * manager;
|
||||
wsfs_impl_timepoint timeout;
|
||||
wsfs_impl_timer_timeout_fn * timeout_handler;
|
||||
void * user_data;
|
||||
struct wsfs_impl_timer * next;
|
||||
struct wsfs_impl_timer * prev;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_timer_init(
|
||||
struct wsfs_impl_timer * timer,
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_timer_cleanup(
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
extern void wsfs_impl_timer_start(
|
||||
struct wsfs_impl_timer * timer,
|
||||
wsfs_impl_timepoint absolute_timeout,
|
||||
wsfs_impl_timer_timeout_fn * handler,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_impl_timer_cancel(
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,25 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/impl/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wsfs_impl_timer_is_timeout(
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
extern void wsfs_impl_timer_trigger(
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,28 +0,0 @@
|
||||
#include "wsfs/adapter/jsonrpc/method_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_jsonrpc_method * method = malloc(sizeof(struct wsfs_jsonrpc_method));
|
||||
if (NULL != method)
|
||||
{
|
||||
method->next = NULL;
|
||||
method->name = strdup(name);
|
||||
method->invoke = invoke;
|
||||
method->user_data = user_data;
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
void wsfs_jsonrpc_method_dispose(
|
||||
struct wsfs_jsonrpc_method * method)
|
||||
{
|
||||
free(method->name);
|
||||
free(method);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_METHOD_H
|
||||
#define WSFS_ADAPTER_JSONRPC_METHOD_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/status.h"
|
||||
|
||||
|
||||
typedef bool wsfs_jsonrpc_method_invoke_fn(
|
||||
void * user_data,
|
||||
struct json_t const * method_call);
|
||||
|
||||
typedef void wsfs_jsonrpc_method_finished_fn(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
struct json_t const * result);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H
|
||||
#define WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/method.h"
|
||||
|
||||
struct wsfs_jsonrpc_method
|
||||
{
|
||||
struct wsfs_jsonrpc_method * next;
|
||||
char * name;
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_jsonrpc_method_dispose(
|
||||
struct wsfs_jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,38 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_RESPONSE_H
|
||||
#define WSFS_ADAPTER_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/status.h"
|
||||
|
||||
struct wsfs_jsonrpc_response
|
||||
{
|
||||
wsfs_status status;
|
||||
int id;
|
||||
json_t * result;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void wsfs_jsonrpc_response_init(
|
||||
struct wsfs_jsonrpc_response * response,
|
||||
char const * buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
extern void wsfs_jsonrpc_response_cleanup(
|
||||
struct wsfs_jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,80 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_SERVER_H
|
||||
#define WSFS_ADAPTER_JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/adapter/jsonrpc/method.h"
|
||||
#include "wsfs/adapter/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/time/timer.h"
|
||||
|
||||
|
||||
struct wsfs_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wsfs_jsonrpc_method_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wsfs_timer timer;
|
||||
};
|
||||
|
||||
struct wsfs_jsonrpc_server
|
||||
{
|
||||
struct wsfs_jsonrpc_method * methods;
|
||||
struct wsfs_jsonrpc_request request;
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_jsonrpc_server_init(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_jsonrpc_server_cleanup(
|
||||
struct wsfs_jsonrpc_server * server);
|
||||
|
||||
extern void wsfs_jsonrpc_server_add(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data );
|
||||
|
||||
extern void wsfs_jsonrpc_server_invoke(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
wsfs_jsonrpc_method_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_jsonrpc_server_notify(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_jsonrpc_server_onresult(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,17 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSON_UTIL_H
|
||||
#define WSFS_ADAPTER_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int wsfs_json_get_int(json_t const * object, char const * key, int default_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,21 +0,0 @@
|
||||
#include "wsfs/adapter/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
void wsfs_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wsfs_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_SERVER_CONFIG_INTERN_H
|
||||
#define WSFS_ADAPTER_SERVER_CONFIG_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/server_config.h"
|
||||
#include "wsfs/adapter/authenticators.h"
|
||||
|
||||
struct wsfs_server_config
|
||||
{
|
||||
char * mount_point;
|
||||
char * document_root;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * vhost_name;
|
||||
int port;
|
||||
struct wsfs_authenticators authenticators;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_server_config_init(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_server_config_cleanup(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_server_config_clone(
|
||||
struct wsfs_server_config * config,
|
||||
struct wsfs_server_config * clone);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,166 +0,0 @@
|
||||
#include "wsfs/adapter/server_protocol_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/message.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
#include "wsfs/adapter/filesystem.h"
|
||||
|
||||
static int wsfs_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wsfs_server_protocol * protocol = ws_protocol->user;
|
||||
|
||||
wsfs_timeout_manager_check(&protocol->timeout_manager);
|
||||
struct wsfs_session * session = wsfs_session_manager_get(&protocol->session_manager, wsi);
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
{
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = wsfs_filesystem_get_fd(&protocol->filesystem);
|
||||
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
|
||||
{
|
||||
fprintf(stderr, "error: unable to adopt fd");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wsfs_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->rpc);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_session_authenticate(session, NULL);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
wsfs_session_manager_remove(&protocol->session_manager, wsi);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_session_onwritable(session);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_session_receive(session, in, len);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
wsfs_filesystem_process_request(&protocol->filesystem);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool wsfs_server_protocol_invoke(
|
||||
void * user_data,
|
||||
json_t const * request)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = user_data;
|
||||
struct wsfs_session * session = &protocol->session_manager.session;
|
||||
struct wsfs_message * message = wsfs_message_create(request);
|
||||
|
||||
bool const result = wsfs_session_send(session, message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct wsfs_server_protocol * wsfs_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
if (!wsfs_server_protocol_init(protocol, mount_point))
|
||||
{
|
||||
free(protocol);
|
||||
protocol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_server_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wsfs_server_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
bool wsfs_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point)
|
||||
{
|
||||
wsfs_timeout_manager_init(&protocol->timeout_manager);
|
||||
wsfs_session_manager_init(&protocol->session_manager);
|
||||
wsfs_authenticators_init(&protocol->authenticators);
|
||||
|
||||
wsfs_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_server_protocol_invoke, protocol);
|
||||
|
||||
bool const success = wsfs_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
|
||||
|
||||
// cleanup on error
|
||||
if (!success)
|
||||
{
|
||||
wsfs_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_filesystem_cleanup(&protocol->filesystem);
|
||||
wsfs_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H
|
||||
#define WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/server_protocol.h"
|
||||
#include "wsfs/adapter/filesystem.h"
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/authenticators.h"
|
||||
#include "wsfs/adapter/session_manager.h"
|
||||
|
||||
struct wsfs_server_protocol
|
||||
{
|
||||
struct wsfs_timeout_manager timeout_manager;
|
||||
struct wsfs_filesystem filesystem;
|
||||
struct wsfs_jsonrpc_server rpc;
|
||||
struct wsfs_authenticators authenticators;
|
||||
struct wsfs_session_manager session_manager;
|
||||
};
|
||||
|
||||
extern bool wsfs_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol);
|
||||
|
||||
#endif
|
@ -1,64 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_SESSION_H
|
||||
#define WSFS_ADAPTER_SESSION_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "wsfs/message_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wsfs_message;
|
||||
struct wsfs_credentials;
|
||||
struct wsfs_authenticators;
|
||||
struct wsfs_jsonrpc_server;
|
||||
|
||||
struct wsfs_session
|
||||
{
|
||||
struct lws * wsi;
|
||||
bool is_authenticated;
|
||||
struct wsfs_message_queue queue;
|
||||
struct wsfs_authenticators * authenticators;
|
||||
struct wsfs_jsonrpc_server * rpc;
|
||||
};
|
||||
|
||||
extern void wsfs_session_init(
|
||||
struct wsfs_session * session,
|
||||
struct lws * wsi,
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_jsonrpc_server * rpc);
|
||||
|
||||
extern void wsfs_session_authenticate(
|
||||
struct wsfs_session * session,
|
||||
struct wsfs_credentials * creds);
|
||||
|
||||
extern bool wsfs_session_send(
|
||||
struct wsfs_session * session,
|
||||
struct wsfs_message * message);
|
||||
|
||||
extern void wsfs_session_receive(
|
||||
struct wsfs_session * session,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
extern void wsfs_session_onwritable(
|
||||
struct wsfs_session * session);
|
||||
|
||||
extern void wsfs_session_cleanup(
|
||||
struct wsfs_session * session);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,54 +0,0 @@
|
||||
#include "wsfs/adapter/session_manager.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void wsfs_session_manager_init(
|
||||
struct wsfs_session_manager * manager)
|
||||
{
|
||||
wsfs_session_init(&manager->session, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void wsfs_session_manager_cleanup(
|
||||
struct wsfs_session_manager * manager)
|
||||
{
|
||||
wsfs_session_cleanup(&manager->session);
|
||||
}
|
||||
|
||||
struct wsfs_session * wsfs_session_manager_add(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_jsonrpc_server * rpc)
|
||||
{
|
||||
struct wsfs_session * session = NULL;
|
||||
if (NULL == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
wsfs_session_init(&manager->session, wsi, authenticators, rpc);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
struct wsfs_session * wsfs_session_manager_get(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wsfs_session * session = NULL;
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
void wsfs_session_manager_remove(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
wsfs_session_cleanup(&manager->session);
|
||||
manager->session.wsi = NULL;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_SESSION_MANAGER_H
|
||||
#define WSFS_ADAPTER_SESSION_MANAGER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/session.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
|
||||
struct wsfs_session_manager
|
||||
{
|
||||
struct wsfs_session session;
|
||||
};
|
||||
|
||||
extern void wsfs_session_manager_init(
|
||||
struct wsfs_session_manager * manager);
|
||||
|
||||
extern void wsfs_session_manager_cleanup(
|
||||
struct wsfs_session_manager * manager);
|
||||
|
||||
extern struct wsfs_session * wsfs_session_manager_add(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_jsonrpc_server * rpc);
|
||||
|
||||
extern struct wsfs_session * wsfs_session_manager_get(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
extern void wsfs_session_manager_remove(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,84 +0,0 @@
|
||||
#include "wsfs/adapter/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "wsfs/adapter/time/timer_intern.h"
|
||||
#include "wsfs/adapter/time/timepoint.h"
|
||||
|
||||
void wsfs_timeout_manager_init(
|
||||
struct wsfs_timeout_manager * manager)
|
||||
{
|
||||
manager->timers = NULL;
|
||||
}
|
||||
|
||||
void wsfs_timeout_manager_cleanup(
|
||||
struct wsfs_timeout_manager * manager)
|
||||
{
|
||||
struct wsfs_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wsfs_timer * next = timer->next;
|
||||
|
||||
wsfs_timer_trigger(timer);
|
||||
|
||||
timer = next;
|
||||
}
|
||||
|
||||
manager->timers = NULL;
|
||||
|
||||
}
|
||||
|
||||
void wsfs_timeout_manager_check(
|
||||
struct wsfs_timeout_manager * manager)
|
||||
{
|
||||
struct wsfs_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wsfs_timer * next = timer->next;
|
||||
|
||||
if (wsfs_timer_is_timeout(timer))
|
||||
{
|
||||
wsfs_timeout_manager_removetimer(manager, timer);
|
||||
wsfs_timer_trigger(timer);
|
||||
}
|
||||
|
||||
timer = next;
|
||||
}
|
||||
}
|
||||
|
||||
void wsfs_timeout_manager_addtimer(
|
||||
struct wsfs_timeout_manager * manager,
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
if (NULL != manager->timers)
|
||||
{
|
||||
manager->timers->prev = timer;
|
||||
}
|
||||
|
||||
timer->next = manager->timers;
|
||||
timer->prev = NULL;
|
||||
manager->timers = timer;
|
||||
}
|
||||
|
||||
void wsfs_timeout_manager_removetimer(
|
||||
struct wsfs_timeout_manager * manager,
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
struct wsfs_timer * prev = timer->prev;
|
||||
struct wsfs_timer * next = timer->next;
|
||||
|
||||
if (NULL != prev)
|
||||
{
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
if (NULL != next)
|
||||
{
|
||||
next->prev = prev;
|
||||
}
|
||||
|
||||
if (manager->timers == timer)
|
||||
{
|
||||
manager->timers = next;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H
|
||||
#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H
|
||||
|
||||
struct wsfs_timer;
|
||||
struct wsfs_timeout_manager
|
||||
{
|
||||
struct wsfs_timer * timers;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_timeout_manager_init(
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_timeout_manager_cleanup(
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_timeout_manager_check(
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,24 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/time/timeout_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_timeout_manager_addtimer(
|
||||
struct wsfs_timeout_manager * manager,
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
extern void wsfs_timeout_manager_removetimer(
|
||||
struct wsfs_timeout_manager * manager,
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
#include "wsfs/adapter/time/timepoint.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define WSFS_MSEC_PER_SEC ((wsfs_timepoint) 1000)
|
||||
#define WSFS_NSEC_PER_MSEC ((wsfs_timepoint) 1000 * 1000)
|
||||
|
||||
wsfs_timepoint wsfs_timepoint_now(void)
|
||||
{
|
||||
struct timespec timepoint;
|
||||
clock_gettime(CLOCK_MONOTONIC, &timepoint);
|
||||
|
||||
wsfs_timepoint const now = (timepoint.tv_sec * WSFS_MSEC_PER_SEC) + (timepoint.tv_nsec / WSFS_NSEC_PER_MSEC);
|
||||
return now;
|
||||
}
|
||||
|
||||
wsfs_timepoint wsfs_timepoint_in_msec(wsfs_timediff value)
|
||||
{
|
||||
wsfs_timepoint const now = wsfs_timepoint_now();
|
||||
wsfs_timepoint result = now + ((wsfs_timepoint) value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool wsfs_timepoint_is_elapsed(wsfs_timepoint timepoint)
|
||||
{
|
||||
wsfs_timepoint const now = wsfs_timepoint_now();
|
||||
wsfs_timediff const diff = (wsfs_timediff) (timepoint - now);
|
||||
|
||||
return (0 > diff);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMEPOINT_H
|
||||
#define WSFS_ADAPTER_TIME_TIMEPOINT_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
typedef uint64_t wsfs_timepoint;
|
||||
typedef int64_t wsfs_timediff;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern wsfs_timepoint wsfs_timepoint_now(void);
|
||||
|
||||
extern wsfs_timepoint wsfs_timepoint_in_msec(
|
||||
wsfs_timediff value);
|
||||
|
||||
extern bool wsfs_timepoint_is_elapsed(
|
||||
wsfs_timepoint timepoint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,65 +0,0 @@
|
||||
#include "wsfs/adapter/time/timer_intern.h"
|
||||
#include "wsfs/adapter/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void wsfs_timer_init(
|
||||
struct wsfs_timer * timer,
|
||||
struct wsfs_timeout_manager * manager)
|
||||
{
|
||||
timer->manager = manager;
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
}
|
||||
|
||||
void wsfs_timer_cleanup(
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
memset(timer, 0, sizeof(struct wsfs_timer));
|
||||
}
|
||||
|
||||
void wsfs_timer_start(
|
||||
struct wsfs_timer * timer,
|
||||
wsfs_timepoint absolute_timeout,
|
||||
wsfs_timer_timeout_fn * handler,
|
||||
void * user_data)
|
||||
{
|
||||
timer->timeout = absolute_timeout;
|
||||
timer->timeout_handler = handler;
|
||||
timer->user_data = user_data;
|
||||
|
||||
wsfs_timeout_manager_addtimer(timer->manager, timer);
|
||||
}
|
||||
|
||||
void wsfs_timer_cancel(
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
wsfs_timeout_manager_removetimer(timer->manager, timer);
|
||||
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
}
|
||||
|
||||
bool wsfs_timer_is_timeout(
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
return wsfs_timepoint_is_elapsed(timer->timeout);
|
||||
}
|
||||
|
||||
|
||||
void wsfs_timer_trigger(
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
if (NULL != timer->timeout_handler)
|
||||
{
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
|
||||
timer->timeout_handler(timer);
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMER_H
|
||||
#define WSFS_ADAPTER_TIME_TIMER_H
|
||||
|
||||
#include "wsfs/adapter/time/timepoint.h"
|
||||
|
||||
struct wsfs_timer;
|
||||
struct wsfs_timeout_manager;
|
||||
|
||||
typedef void wsfs_timer_timeout_fn(struct wsfs_timer * timer);
|
||||
|
||||
struct wsfs_timer
|
||||
{
|
||||
struct wsfs_timeout_manager * manager;
|
||||
wsfs_timepoint timeout;
|
||||
wsfs_timer_timeout_fn * timeout_handler;
|
||||
void * user_data;
|
||||
struct wsfs_timer * next;
|
||||
struct wsfs_timer * prev;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_timer_init(
|
||||
struct wsfs_timer * timer,
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_timer_cleanup(
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
extern void wsfs_timer_start(
|
||||
struct wsfs_timer * timer,
|
||||
wsfs_timepoint absolute_timeout,
|
||||
wsfs_timer_timeout_fn * handler,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_timer_cancel(
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,25 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMER_INTERN_H
|
||||
#define WSFS_ADAPTER_TIME_TIMER_INTERN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wsfs_timer_is_timeout(
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
extern void wsfs_timer_trigger(
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
#include "wsfs/message.h"
|
||||
#include "wsfs/core/message.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
@ -1,5 +1,5 @@
|
||||
#include "wsfs/message_queue.h"
|
||||
#include "wsfs/message.h"
|
||||
#include "wsfs/core/message_queue.h"
|
||||
#include "wsfs/core/message.h"
|
||||
|
||||
void wsfs_message_queue_init(
|
||||
struct wsfs_message_queue * queue)
|
@ -1,4 +1,4 @@
|
||||
#include "wsfs/status_intern.h"
|
||||
#include "wsfs/core/status_intern.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef WSFS_STATUS_INTERN_H
|
||||
#define WSFS_STATUS_INTERN_H
|
||||
|
||||
#include "wsfs/status.h"
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
@ -0,0 +1,240 @@
|
||||
#include "wsfs_provider.h"
|
||||
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/provider/impl/operation/getattr.h"
|
||||
#include "wsfs/provider/impl/operation/lookup.h"
|
||||
#include "wsfs/provider/impl/operation/readdir.h"
|
||||
#include "wsfs/provider/impl/operation/open.h"
|
||||
#include "wsfs/provider/impl/operation/close.h"
|
||||
#include "wsfs/provider/impl/operation/read.h"
|
||||
#include "wsfs/provider/impl/client_protocol.h"
|
||||
#include "wsfs/provider/impl/client_config.h"
|
||||
#include "wsfs/provider/impl/client.h"
|
||||
#include "wsfs/provider/impl/dirbuffer.h"
|
||||
|
||||
// respond
|
||||
|
||||
void wsfsp_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
wsfs_status status)
|
||||
{
|
||||
wsfsp_impl_respond_error(request, status);
|
||||
}
|
||||
|
||||
void wsfsp_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
wsfsp_impl_respond_getattr(request, stat);
|
||||
}
|
||||
|
||||
void wsfsp_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
wsfsp_impl_respond_lookup(request, stat);
|
||||
}
|
||||
|
||||
void wsfsp_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
wsfsp_impl_respond_open(request, handle);
|
||||
}
|
||||
|
||||
void wsfsp_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
wsfsp_impl_respond_read(request, data, length);
|
||||
}
|
||||
|
||||
void wsfsp_respond_readdir(
|
||||
struct wsfsp_request * request,
|
||||
struct wsfsp_dirbuffer * dirbuffer)
|
||||
{
|
||||
wsfsp_impl_respond_readdir(request, dirbuffer);
|
||||
}
|
||||
|
||||
// config
|
||||
|
||||
|
||||
struct wsfsp_client_config * wsfsp_client_config_create(void)
|
||||
{
|
||||
return wsfsp_impl_client_config_create();
|
||||
}
|
||||
|
||||
void wsfsp_client_config_dispose(
|
||||
struct wsfsp_client_config * config)
|
||||
{
|
||||
wsfsp_impl_client_config_dispose(config);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_userdata(
|
||||
struct wsfsp_client_config * config,
|
||||
void * user_data)
|
||||
{
|
||||
wsfsp_impl_client_config_set_userdata(config, user_data);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_keypath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wsfsp_impl_client_config_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_certpath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wsfsp_impl_client_config_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_connected_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onconnected(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ondisconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_disconnected_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_ondisconnected(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ontimer(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_ontimer_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_ontimer(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onlookup(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_lookup_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onlookup(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ongetattr(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_getattr_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_ongetattr(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onreaddir(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_readdir_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onreaddir(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onopen(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_open_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onopen(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onclose(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_close_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onclose(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onread(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_read_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onread(config, handler);
|
||||
}
|
||||
|
||||
// protocol
|
||||
|
||||
|
||||
struct wsfsp_client_protocol * wsfsp_client_protocol_create(
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
return wsfsp_impl_client_protocol_create(provider, user_data);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_dispose(
|
||||
struct wsfsp_client_protocol * protocol)
|
||||
{
|
||||
wsfsp_impl_client_protocol_dispose(protocol);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_init_lws(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
wsfsp_impl_client_protocol_init_lws(protocol, lws_protocol);
|
||||
}
|
||||
|
||||
// client
|
||||
|
||||
struct wsfsp_client * wsfsp_client_create(
|
||||
struct wsfsp_client_config * config)
|
||||
{
|
||||
return wsfsp_impl_client_create(config);
|
||||
}
|
||||
|
||||
void wsfsp_client_connect(
|
||||
struct wsfsp_client * client,
|
||||
char const * url)
|
||||
{
|
||||
wsfsp_impl_client_connect(client, url);
|
||||
}
|
||||
|
||||
void wsfsp_client_disconnect(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
wsfsp_impl_client_disconnect(client);
|
||||
}
|
||||
|
||||
void wsfsp_client_dispose(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
wsfsp_impl_client_dispose(client);
|
||||
}
|
||||
|
||||
void wsfsp_client_run(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
wsfsp_impl_client_run(client);
|
||||
}
|
||||
|
||||
void wsfsp_client_shutdown(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
wsfsp_impl_client_shutdown(client);
|
||||
}
|
||||
|
||||
// dirbuffer
|
||||
|
||||
struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void)
|
||||
{
|
||||
return wsfsp_impl_dirbuffer_create();
|
||||
}
|
||||
|
||||
void wsfsp_dirbuffer_dispose(
|
||||
struct wsfsp_dirbuffer * buffer)
|
||||
{
|
||||
wsfsp_impl_dirbuffer_dispose(buffer);
|
||||
}
|
||||
|
||||
void wsfsp_dirbuffer_add(
|
||||
struct wsfsp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode)
|
||||
{
|
||||
wsfsp_impl_dirbuffer_add(buffer, name, inode);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue