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

removed library prefix for implementations

This commit is contained in:
Falk Werner 2019-03-24 03:25:29 +01:00
parent 6ed438e028
commit feed9751d3
51 changed files with 684 additions and 685 deletions

View File

@ -10,25 +10,25 @@
struct wsfs_server * wsfs_server_create(
struct wsfs_server_config * config)
{
return wsfs_impl_server_create(config);
return server_create(config);
}
void wsfs_server_dispose(
struct wsfs_server * server)
{
wsfs_impl_server_dispose(server);
server_dispose(server);
}
void wsfs_server_run(
struct wsfs_server * server)
{
wsfs_impl_server_run(server);
server_run(server);
}
void wsfs_server_shutdown(
struct wsfs_server * server)
{
wsfs_impl_server_shutdown(server);
server_shutdown(server);
}
// server protocol
@ -36,20 +36,20 @@ void wsfs_server_shutdown(
struct wsfs_server_protocol * wsfs_server_protocol_create(
char * mount_point)
{
return wsfs_impl_server_protocol_create(mount_point);
return server_protocol_create(mount_point);
}
void wsfs_server_protocol_dispose(
struct wsfs_server_protocol * protocol)
{
wsfs_impl_server_protocol_dispose(protocol);
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);
server_protocol_init_lws(protocol, lws_protocol);
}
void wsfs_server_protocol_add_authenticator(
@ -58,62 +58,62 @@ void wsfs_server_protocol_add_authenticator(
wsfs_authenticate_fn * authenticate,
void * user_data)
{
wsfs_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data);
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();
return server_config_create();
}
void wsfs_server_config_dispose(
struct wsfs_server_config * config)
{
wsfs_impl_server_config_dispose(config);
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);
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);
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);
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);
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);
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);
server_config_set_port(config, port);
}
void wsfs_server_config_add_authenticator(
@ -122,7 +122,7 @@ void wsfs_server_config_add_authenticator(
wsfs_authenticate_fn * authenticate,
void * user_data)
{
wsfs_impl_server_config_add_authenticator(config, type, authenticate, user_data);
server_config_add_authenticator(config, type, authenticate, user_data);
}
// credentials
@ -130,12 +130,12 @@ void wsfs_server_config_add_authenticator(
char const * wsfs_credentials_type(
struct wsfs_credentials const * credentials)
{
return wsfs_impl_credentials_type(credentials);
return credentials_type(credentials);
}
char const * wsfs_credentials_get(
struct wsfs_credentials const * credentials,
char const * key)
{
return wsfs_impl_credentials_get(credentials, key);
return credentials_get(credentials, key);
}

View File

@ -5,12 +5,12 @@
#include "wsfs/adapter/impl/credentials.h"
struct wsfs_authenticator * wsfs_authenticator_create(
struct authenticator * authenticator_create(
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
struct wsfs_authenticator * authenticator = malloc(sizeof(struct wsfs_authenticator));
struct authenticator * authenticator = malloc(sizeof(struct authenticator));
if (NULL != authenticator)
{
authenticator->type = strdup(type);
@ -22,15 +22,15 @@ struct wsfs_authenticator * wsfs_authenticator_create(
return authenticator;
}
void wsfs_authenticator_dispose(
struct wsfs_authenticator * authenticator)
void authenticator_dispose(
struct authenticator * authenticator)
{
free(authenticator->type);
free(authenticator);
}
bool wsfs_authenticator_autenticate(
struct wsfs_authenticator * authenticator,
bool authenticator_autenticate(
struct authenticator * authenticator,
struct wsfs_credentials * credentials)
{
bool result;

View File

@ -12,24 +12,24 @@ extern "C"
{
#endif
struct wsfs_authenticator
struct authenticator
{
char * type;
wsfs_authenticate_fn * authenticate;
void * user_data;
struct wsfs_authenticator * next;
struct authenticator * next;
};
extern struct wsfs_authenticator * wsfs_authenticator_create(
extern struct authenticator * authenticator_create(
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data);
extern void wsfs_authenticator_dispose(
struct wsfs_authenticator * authenticator);
extern void authenticator_dispose(
struct authenticator * authenticator);
extern bool wsfs_authenticator_autenticate(
struct wsfs_authenticator * authenticator,
extern bool authenticator_autenticate(
struct authenticator * authenticator,
struct wsfs_credentials * credentials);

View File

@ -5,16 +5,16 @@
#include "wsfs/adapter/impl/authenticator.h"
#include "wsfs/adapter/impl/credentials.h"
static struct wsfs_authenticator * wsfs_authenticators_find(
struct wsfs_authenticators * authenticators,
static struct authenticator * authenticators_find(
struct authenticators * authenticators,
char const * type)
{
struct wsfs_authenticator * result = NULL;
struct authenticator * result = NULL;
struct wsfs_authenticator * actual = authenticators->first;
struct authenticator * actual = authenticators->first;
while ((NULL == result) && (NULL != actual))
{
struct wsfs_authenticator * next = actual->next;
struct authenticator * next = actual->next;
if (0 == strcmp(type, actual->type))
{
result = actual;
@ -26,74 +26,74 @@ static struct wsfs_authenticator * wsfs_authenticators_find(
return result;
}
void wsfs_authenticators_init(
struct wsfs_authenticators * authenticators)
void authenticators_init(
struct authenticators * authenticators)
{
authenticators->first = NULL;
}
void wsfs_authenticators_cleanup(
struct wsfs_authenticators * authenticators)
void authenticators_cleanup(
struct authenticators * authenticators)
{
struct wsfs_authenticator * actual = authenticators->first;
struct authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wsfs_authenticator * next = actual->next;
wsfs_authenticator_dispose(actual);
struct authenticator * next = actual->next;
authenticator_dispose(actual);
actual = next;
}
authenticators->first = NULL;
}
void wsfs_authenticators_clone(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other)
void authenticators_clone(
struct authenticators * authenticators,
struct authenticators * other)
{
wsfs_authenticators_init(other);
authenticators_init(other);
struct wsfs_authenticator * actual = authenticators->first;
struct authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wsfs_authenticator * next = actual->next;
wsfs_authenticators_add(other,
struct authenticator * next = actual->next;
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)
extern void authenticators_move(
struct authenticators * authenticators,
struct authenticators * other)
{
other->first = authenticators->first;
authenticators->first = NULL;
}
void wsfs_authenticators_add(
struct wsfs_authenticators * authenticators,
void authenticators_add(
struct authenticators * authenticators,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data)
{
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(type, authenticate, user_data);
struct authenticator * authenticator = authenticator_create(type, authenticate, user_data);
authenticator->next = authenticators->first;
authenticators->first = authenticator;
}
bool wsfs_authenticators_authenticate(
struct wsfs_authenticators * authenticators,
bool authenticators_authenticate(
struct authenticators * authenticators,
struct wsfs_credentials * credentials)
{
bool result = (NULL == authenticators->first);
if (NULL != credentials)
{
struct wsfs_authenticator * authenticator = wsfs_authenticators_find(authenticators, credentials->type);
struct authenticator * authenticator = authenticators_find(authenticators, credentials->type);
if (NULL != authenticator)
{
result = wsfs_authenticator_autenticate(authenticator, credentials);
result = authenticator_autenticate(authenticator, credentials);
}
}

View File

@ -12,36 +12,36 @@ extern "C"
{
#endif
struct wsfs_authenticator;
struct authenticator;
struct wsfs_credentials;
struct wsfs_authenticators
struct authenticators
{
struct wsfs_authenticator * first;
struct authenticator * first;
};
extern void wsfs_authenticators_init(
struct wsfs_authenticators * authenticators);
extern void authenticators_init(
struct authenticators * authenticators);
extern void wsfs_authenticators_cleanup(
struct wsfs_authenticators * authenticators);
extern void authenticators_cleanup(
struct authenticators * authenticators);
extern void wsfs_authenticators_clone(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other);
extern void authenticators_clone(
struct authenticators * authenticators,
struct authenticators * other);
extern void wsfs_authenticators_move(
struct wsfs_authenticators * authenticators,
struct wsfs_authenticators * other);
extern void authenticators_move(
struct authenticators * authenticators,
struct authenticators * other);
extern void wsfs_authenticators_add(
struct wsfs_authenticators * authenticators,
extern void authenticators_add(
struct authenticators * authenticators,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data);
extern bool wsfs_authenticators_authenticate(
struct wsfs_authenticators * authenticators,
extern bool authenticators_authenticate(
struct authenticators * authenticators,
struct wsfs_credentials * credentials);
#ifdef __cplusplus

View File

@ -1,7 +1,7 @@
#include "wsfs/adapter/impl/credentials.h"
#include <string.h>
void wsfs_impl_credentials_init(
void credentials_init(
struct wsfs_credentials * credentials,
char const * type,
json_t * data)
@ -11,20 +11,20 @@ void wsfs_impl_credentials_init(
json_incref(credentials->data);
}
void wsfs_impl_credentials_cleanup(
void credentials_cleanup(
struct wsfs_credentials * credentials)
{
free(credentials->type);
json_decref(credentials->data);
}
char const * wsfs_impl_credentials_type(
char const * credentials_type(
struct wsfs_credentials const * credentials)
{
return credentials->type;
}
char const * wsfs_impl_credentials_get(
char const * credentials_get(
struct wsfs_credentials const * credentials,
char const * key)
{

View File

@ -14,18 +14,18 @@ struct wsfs_credentials
json_t * data;
};
extern void wsfs_impl_credentials_init(
extern void credentials_init(
struct wsfs_credentials * credentials,
char const * type,
json_t * data);
extern void wsfs_impl_credentials_cleanup(
extern void credentials_cleanup(
struct wsfs_credentials * credentials);
extern char const * wsfs_impl_credentials_type(
extern char const * credentials_type(
struct wsfs_credentials const * credentials);
extern char const * wsfs_impl_credentials_get(
extern char const * credentials_get(
struct wsfs_credentials const * credentials,
char const * key);

View File

@ -6,20 +6,20 @@
#include <string.h>
#include <errno.h>
static struct fuse_lowlevel_ops const wsfs_filesystem_operations =
static struct fuse_lowlevel_ops const filesystem_operations =
{
.lookup = &wsfs_operation_lookup,
.getattr = &wsfs_operation_getattr,
.readdir = &wsfs_operation_readdir,
.open = &wsfs_operation_open,
.release = &wsfs_operation_close,
.read = &wsfs_operation_read
.lookup = &operation_lookup,
.getattr = &operation_getattr,
.readdir = &operation_readdir,
.open = &operation_open,
.release = &operation_close,
.read = &operation_read
};
bool wsfs_filesystem_init(
struct wsfs_filesystem * filesystem,
struct wsfs_jsonrpc_server * rpc,
bool filesystem_init(
struct filesystem * filesystem,
struct jsonrpc_server * rpc,
char * mount_point)
{
bool result = false;
@ -35,8 +35,8 @@ bool wsfs_filesystem_init(
filesystem->session = fuse_session_new(
&filesystem->args,
&wsfs_filesystem_operations,
sizeof(wsfs_filesystem_operations),
&filesystem_operations,
sizeof(filesystem_operations),
&filesystem->user_data);
if (NULL != filesystem->session)
{
@ -46,8 +46,8 @@ bool wsfs_filesystem_init(
return result;
}
void wsfs_filesystem_cleanup(
struct wsfs_filesystem * filesystem)
void filesystem_cleanup(
struct filesystem * filesystem)
{
if (NULL != filesystem->session)
{
@ -61,14 +61,14 @@ void wsfs_filesystem_cleanup(
fuse_opt_free_args(&filesystem->args);
}
int wsfs_filesystem_get_fd(
struct wsfs_filesystem * filesystem)
int filesystem_get_fd(
struct filesystem * filesystem)
{
return fuse_session_fd(filesystem->session);
}
void wsfs_filesystem_process_request(
struct wsfs_filesystem * filesystem)
void filesystem_process_request(
struct filesystem * filesystem)
{
int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer);
if (0 < result)

View File

@ -13,29 +13,29 @@ extern "C"
{
#endif
struct wsfs_jsonrpc_server;
struct jsonrpc_server;
struct wsfs_filesystem
struct filesystem
{
struct fuse_args args;
struct fuse_session * session;
struct fuse_buf buffer;
struct wsfs_operations_context user_data;
struct operations_context user_data;
};
extern bool wsfs_filesystem_init(
struct wsfs_filesystem * filesystem,
struct wsfs_jsonrpc_server * rpc,
extern bool filesystem_init(
struct filesystem * filesystem,
struct jsonrpc_server * rpc,
char * mount_point);
extern void wsfs_filesystem_cleanup(
struct wsfs_filesystem * filesystem);
extern void filesystem_cleanup(
struct filesystem * filesystem);
extern int wsfs_filesystem_get_fd(
struct wsfs_filesystem * filesystem);
extern int filesystem_get_fd(
struct filesystem * filesystem);
extern void wsfs_filesystem_process_request(
struct wsfs_filesystem * filesystem);
extern void filesystem_process_request(
struct filesystem * filesystem);
#ifdef __cplusplus
}

View File

@ -3,12 +3,12 @@
#include <stdlib.h>
#include <string.h>
struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
struct jsonrpc_method * jsonrpc_method_create(
char const * name,
wsfs_jsonrpc_method_invoke_fn * invoke,
jsonrpc_method_invoke_fn * invoke,
void * user_data)
{
struct wsfs_jsonrpc_method * method = malloc(sizeof(struct wsfs_jsonrpc_method));
struct jsonrpc_method * method = malloc(sizeof(struct jsonrpc_method));
if (NULL != method)
{
method->next = NULL;
@ -20,8 +20,8 @@ struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
return method;
}
void wsfs_jsonrpc_method_dispose(
struct wsfs_jsonrpc_method * method)
void jsonrpc_method_dispose(
struct jsonrpc_method * method)
{
free(method->name);
free(method);

View File

@ -13,11 +13,11 @@ extern "C"
{
#endif
typedef bool wsfs_jsonrpc_method_invoke_fn(
typedef bool jsonrpc_method_invoke_fn(
void * user_data,
struct json_t const * method_call);
typedef void wsfs_jsonrpc_method_finished_fn(
typedef void jsonrpc_method_finished_fn(
void * user_data,
wsfs_status status,
struct json_t const * result);

View File

@ -8,21 +8,21 @@ extern "C"
{
#endif
struct wsfs_jsonrpc_method
struct jsonrpc_method
{
struct wsfs_jsonrpc_method * next;
struct jsonrpc_method * next;
char * name;
wsfs_jsonrpc_method_invoke_fn * invoke;
jsonrpc_method_invoke_fn * invoke;
void * user_data;
};
extern struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
extern struct jsonrpc_method * jsonrpc_method_create(
char const * name,
wsfs_jsonrpc_method_invoke_fn * invoke,
jsonrpc_method_invoke_fn * invoke,
void * user_data);
extern void wsfs_jsonrpc_method_dispose(
struct wsfs_jsonrpc_method * method);
extern void jsonrpc_method_dispose(
struct jsonrpc_method * method);
#ifdef __cplusplus
}

View File

@ -1,6 +1,6 @@
#include "wsfs/adapter/impl/jsonrpc/request.h"
json_t * wsfs_jsonrpc_request_create(
json_t * jsonrpc_request_create(
char const * method,
int id,
char const * param_info,

View File

@ -18,7 +18,7 @@ extern "C"
{
#endif
extern json_t * wsfs_jsonrpc_request_create(
extern json_t * jsonrpc_request_create(
char const * method,
int id,
char const * param_info,

View File

@ -1,7 +1,7 @@
#include "wsfs/adapter/impl/jsonrpc/response.h"
void wsfs_jsonrpc_response_init(
struct wsfs_jsonrpc_response * result,
void jsonrpc_response_init(
struct jsonrpc_response * result,
char const * buffer,
size_t length)
{
@ -49,8 +49,8 @@ void wsfs_jsonrpc_response_init(
json_decref(response);
}
void wsfs_jsonrpc_response_cleanup(
struct wsfs_jsonrpc_response * response)
void jsonrpc_response_cleanup(
struct jsonrpc_response * response)
{
if (NULL != response->result)
{

View File

@ -15,20 +15,20 @@ using std::size_t;
extern "C" {
#endif
struct wsfs_jsonrpc_response
struct jsonrpc_response
{
wsfs_status status;
int id;
json_t * result;
};
extern void wsfs_jsonrpc_response_init(
struct wsfs_jsonrpc_response * response,
extern void jsonrpc_response_init(
struct jsonrpc_response * response,
char const * buffer,
size_t buffer_length);
extern void wsfs_jsonrpc_response_cleanup(
struct wsfs_jsonrpc_response * response);
extern void jsonrpc_response_cleanup(
struct jsonrpc_response * response);
#ifdef __cplusplus
}

View File

@ -7,11 +7,11 @@
#define WSFS_DEFAULT_TIMEOUT (10 * 1000)
static struct wsfs_jsonrpc_method const * wsfs_jsonrpc_server_getmethod(
struct wsfs_jsonrpc_server * server,
static struct jsonrpc_method const * jsonrpc_server_getmethod(
struct jsonrpc_server * server,
char const * name)
{
struct wsfs_jsonrpc_method * method = server->methods;
struct jsonrpc_method * method = server->methods;
while ((NULL != method) && (0 == strcmp(name, method->name)))
{
method = method->next;
@ -20,40 +20,40 @@ static struct wsfs_jsonrpc_method const * wsfs_jsonrpc_server_getmethod(
return method;
}
static void wsfs_jsonrpc_server_timeout(
struct wsfs_timer * timer)
static void jsonrpc_server_timeout(
struct timer * timer)
{
struct wsfs_jsonrpc_server * server = timer->user_data;
struct jsonrpc_server * server = timer->user_data;
if (server->request.is_pending)
{
wsfs_jsonrpc_method_finished_fn * finished = server->request.finished;
jsonrpc_method_finished_fn * finished = server->request.finished;
void * user_data = server->request.user_data;
server->request.is_pending = false;
server->request.id = 0;
server->request.user_data = NULL;
server->request.finished = NULL;
wsfs_timer_cancel(&server->request.timer);
timer_cancel(&server->request.timer);
finished(user_data, WSFS_BAD_TIMEOUT, NULL);
}
}
void wsfs_jsonrpc_server_init(
struct wsfs_jsonrpc_server * server,
struct wsfs_timeout_manager * timeout_manager)
void jsonrpc_server_init(
struct jsonrpc_server * server,
struct timeout_manager * timeout_manager)
{
server->methods = NULL;
server->request.is_pending = false;
wsfs_timer_init(&server->request.timer, timeout_manager);
timer_init(&server->request.timer, timeout_manager);
}
void wsfs_jsonrpc_server_cleanup(
struct wsfs_jsonrpc_server * server)
void jsonrpc_server_cleanup(
struct jsonrpc_server * server)
{
wsfs_timer_cleanup(&server->request.timer);
timer_cleanup(&server->request.timer);
if (server->request.is_pending)
{
@ -61,31 +61,31 @@ void wsfs_jsonrpc_server_cleanup(
server->request.is_pending = false;
}
struct wsfs_jsonrpc_method * method = server->methods;
struct jsonrpc_method * method = server->methods;
while (NULL != method)
{
struct wsfs_jsonrpc_method * next = method->next;
struct jsonrpc_method * next = method->next;
method->next = NULL;
wsfs_jsonrpc_method_dispose(method);
jsonrpc_method_dispose(method);
method = next;
}
server->methods = NULL;
}
void wsfs_jsonrpc_server_add(
struct wsfs_jsonrpc_server * server,
void jsonrpc_server_add(
struct jsonrpc_server * server,
char const * name,
wsfs_jsonrpc_method_invoke_fn * invoke,
jsonrpc_method_invoke_fn * invoke,
void * user_data)
{
struct wsfs_jsonrpc_method * method = wsfs_jsonrpc_method_create(name, invoke, user_data);
struct jsonrpc_method * method = jsonrpc_method_create(name, invoke, user_data);
method->next = server->methods;
server->methods = method;
}
void wsfs_jsonrpc_server_invoke(
struct wsfs_jsonrpc_server * server,
wsfs_jsonrpc_method_finished_fn * finished,
void jsonrpc_server_invoke(
struct jsonrpc_server * server,
jsonrpc_method_finished_fn * finished,
void * user_data,
char const * method_name,
char const * param_info,
@ -94,19 +94,19 @@ void wsfs_jsonrpc_server_invoke(
{
if (!server->request.is_pending)
{
struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name);
struct jsonrpc_method const * method = jsonrpc_server_getmethod(server, method_name);
if (NULL != method)
{
server->request.is_pending = true;
server->request.finished = finished;
server->request.user_data = user_data;
server->request.id = 42;
wsfs_timer_start(&server->request.timer, wsfs_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT),
&wsfs_jsonrpc_server_timeout, server);
timer_start(&server->request.timer, timepoint_in_msec(WSFS_DEFAULT_TIMEOUT),
&jsonrpc_server_timeout, server);
va_list args;
va_start(args, param_info);
json_t * request = wsfs_jsonrpc_request_create(method_name, server->request.id, param_info, args);
json_t * request = jsonrpc_request_create(method_name, server->request.id, param_info, args);
va_end(args);
if (NULL != request)
{
@ -116,7 +116,7 @@ void wsfs_jsonrpc_server_invoke(
server->request.finished = NULL;
server->request.user_data = NULL;
server->request.id = 0;
wsfs_timer_cancel(&server->request.timer);
timer_cancel(&server->request.timer);
finished(user_data, WSFS_BAD, NULL);
}
@ -134,20 +134,20 @@ void wsfs_jsonrpc_server_invoke(
}
}
extern void wsfs_jsonrpc_server_notify(
struct wsfs_jsonrpc_server * server,
extern void jsonrpc_server_notify(
struct jsonrpc_server * server,
char const * method_name,
char const * param_info,
...
)
{
struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name);
struct jsonrpc_method const * method = jsonrpc_server_getmethod(server, method_name);
if (NULL != method)
{
va_list args;
va_start(args, param_info);
json_t * request = wsfs_jsonrpc_request_create(method_name, 0, param_info, args);
json_t * request = jsonrpc_request_create(method_name, 0, param_info, args);
va_end(args);
if (NULL != request)
{
@ -159,28 +159,28 @@ extern void wsfs_jsonrpc_server_notify(
}
void wsfs_jsonrpc_server_onresult(
struct wsfs_jsonrpc_server * server,
void jsonrpc_server_onresult(
struct jsonrpc_server * server,
char const * message,
size_t length)
{
struct wsfs_jsonrpc_response response;
wsfs_jsonrpc_response_init(&response, message, length);
struct jsonrpc_response response;
jsonrpc_response_init(&response, message, length);
if ((server->request.is_pending) && (response.id == server->request.id))
{
wsfs_jsonrpc_method_finished_fn * finished = server->request.finished;
jsonrpc_method_finished_fn * finished = server->request.finished;
void * user_data = server->request.user_data;
server->request.is_pending = false;
server->request.id = 0;
server->request.user_data = NULL;
server->request.finished = NULL;
wsfs_timer_cancel(&server->request.timer);
timer_cancel(&server->request.timer);
finished(user_data, response.status, response.result);
}
wsfs_jsonrpc_response_cleanup(&response);
jsonrpc_response_cleanup(&response);
}

View File

@ -20,52 +20,52 @@ using std::size_t;
extern "C" {
#endif
struct wsfs_jsonrpc_request
struct jsonrpc_request
{
bool is_pending;
wsfs_jsonrpc_method_finished_fn * finished;
jsonrpc_method_finished_fn * finished;
void * user_data;
int id;
struct wsfs_timer timer;
struct timer timer;
};
struct wsfs_jsonrpc_server
struct jsonrpc_server
{
struct wsfs_jsonrpc_method * methods;
struct wsfs_jsonrpc_request request;
struct jsonrpc_method * methods;
struct jsonrpc_request request;
};
extern void wsfs_jsonrpc_server_init(
struct wsfs_jsonrpc_server * server,
struct wsfs_timeout_manager * manager);
extern void jsonrpc_server_init(
struct jsonrpc_server * server,
struct timeout_manager * manager);
extern void wsfs_jsonrpc_server_cleanup(
struct wsfs_jsonrpc_server * server);
extern void jsonrpc_server_cleanup(
struct jsonrpc_server * server);
extern void wsfs_jsonrpc_server_add(
struct wsfs_jsonrpc_server * server,
extern void jsonrpc_server_add(
struct jsonrpc_server * server,
char const * name,
wsfs_jsonrpc_method_invoke_fn * invoke,
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,
extern void jsonrpc_server_invoke(
struct jsonrpc_server * server,
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,
extern void jsonrpc_server_notify(
struct jsonrpc_server * server,
char const * method_name,
char const * param_info,
...
);
extern void wsfs_jsonrpc_server_onresult(
struct wsfs_jsonrpc_server * server,
extern void jsonrpc_server_onresult(
struct jsonrpc_server * server,
char const * message,
size_t length);

View File

@ -1,6 +1,6 @@
#include "wsfs/adapter/impl/jsonrpc/util.h"
int wsfs_json_get_int(json_t const * object, char const * key, int default_value)
int json_get_int(json_t const * object, char const * key, int default_value)
{
int result = default_value;

View File

@ -8,7 +8,7 @@ extern "C"
{
#endif
extern int wsfs_json_get_int(json_t const * object, char const * key, int default_value);
extern int json_get_int(json_t const * object, char const * key, int default_value);
#ifdef __cplusplus
}

View File

@ -7,15 +7,15 @@
#include "wsfs/adapter/impl/jsonrpc/server.h"
#include "wsfs/util.h"
void wsfs_operation_close(
void 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;
struct operations_context * user_data = fuse_req_userdata(request);
struct 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);
jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
fuse_reply_err(request, 0);
}

View File

@ -11,7 +11,7 @@
#include "wsfs/adapter/impl/jsonrpc/util.h"
#include "wsfs/util.h"
struct wsfs_operation_getattr_context
struct operation_getattr_context
{
fuse_req_t request;
double timeout;
@ -19,12 +19,12 @@ struct wsfs_operation_getattr_context
gid_t gid;
};
static void wsfs_operation_getattr_finished(
static void operation_getattr_finished(
void * user_data,
wsfs_status status,
json_t const * data)
{
struct wsfs_operation_getattr_context * context = user_data;
struct operation_getattr_context * context = user_data;
struct stat buffer;
if (NULL != data)
@ -50,10 +50,10 @@ static void wsfs_operation_getattr_finished(
buffer.st_uid = context->uid;
buffer.st_gid = context->gid;
buffer.st_nlink = 1;
buffer.st_size = wsfs_json_get_int(data, "size", 0);
buffer.st_atime = wsfs_json_get_int(data, "atime", 0);
buffer.st_mtime = wsfs_json_get_int(data, "mtime", 0);
buffer.st_ctime = wsfs_json_get_int(data, "ctime", 0);
buffer.st_size = json_get_int(data, "size", 0);
buffer.st_atime = json_get_int(data, "atime", 0);
buffer.st_mtime = json_get_int(data, "mtime", 0);
buffer.st_ctime = json_get_int(data, "ctime", 0);
}
else
@ -74,20 +74,20 @@ static void wsfs_operation_getattr_finished(
free(context);
}
void wsfs_operation_getattr (
void operation_getattr (
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{
struct fuse_ctx const * context = fuse_req_ctx(request);
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct operations_context * user_data = fuse_req_userdata(request);
struct jsonrpc_server * rpc = user_data->rpc;
struct wsfs_operation_getattr_context * getattr_context = malloc(sizeof(struct wsfs_operation_getattr_context));
struct operation_getattr_context * getattr_context = malloc(sizeof(struct operation_getattr_context));
getattr_context->request = request;
getattr_context->uid = context->uid;
getattr_context->gid = context->gid;
getattr_context->timeout = user_data->timeout;
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_getattr_finished, getattr_context, "getattr", "i", inode);
jsonrpc_server_invoke(rpc, &operation_getattr_finished, getattr_context, "getattr", "i", inode);
}

View File

@ -14,7 +14,7 @@
#include "wsfs/adapter/impl/jsonrpc/util.h"
#include "wsfs/util.h"
struct wsfs_operation_lookup_context
struct operation_lookup_context
{
fuse_req_t request;
double timeout;
@ -22,13 +22,13 @@ struct wsfs_operation_lookup_context
gid_t gid;
};
static void wsfs_operation_lookup_finished(
static void operation_lookup_finished(
void * user_data,
wsfs_status status,
json_t const * data
)
{
struct wsfs_operation_lookup_context * context = user_data;
struct operation_lookup_context * context = user_data;
struct fuse_entry_param buffer;
if (NULL != data)
@ -60,10 +60,10 @@ static void wsfs_operation_lookup_finished(
buffer.attr.st_uid = context->uid;
buffer.attr.st_gid = context->gid;
buffer.attr.st_nlink = 1;
buffer.attr.st_size = wsfs_json_get_int(data, "size", 0);
buffer.attr.st_atime = wsfs_json_get_int(data, "atime", 0);
buffer.attr.st_mtime = wsfs_json_get_int(data, "mtime", 0);
buffer.attr.st_ctime = wsfs_json_get_int(data, "ctime", 0);
buffer.attr.st_size = json_get_int(data, "size", 0);
buffer.attr.st_atime = json_get_int(data, "atime", 0);
buffer.attr.st_mtime = json_get_int(data, "mtime", 0);
buffer.attr.st_ctime = json_get_int(data, "ctime", 0);
}
else
{
@ -83,21 +83,20 @@ static void wsfs_operation_lookup_finished(
free(context);
}
void wsfs_operation_lookup (
void operation_lookup (
fuse_req_t request,
fuse_ino_t parent,
char const * name)
{
struct fuse_ctx const * context = fuse_req_ctx(request);
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct operations_context * user_data = fuse_req_userdata(request);
struct jsonrpc_server * rpc = user_data->rpc;
struct wsfs_operation_lookup_context * lookup_context = malloc(sizeof(struct wsfs_operation_lookup_context));
struct operation_lookup_context * lookup_context = malloc(sizeof(struct operation_lookup_context));
lookup_context->request = request;
lookup_context->uid = context->uid;
lookup_context->gid = context->gid;
lookup_context->timeout = user_data->timeout;
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
jsonrpc_server_invoke(rpc, &operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
}

View File

@ -8,7 +8,7 @@
#include "wsfs/util.h"
#include "wsfs/status.h"
static void wsfs_operation_open_finished(
static void operation_open_finished(
void * user_data,
wsfs_status status,
json_t const * result)
@ -41,13 +41,13 @@ static void wsfs_operation_open_finished(
}
void wsfs_operation_open(
void operation_open(
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;
struct operations_context * user_data = fuse_req_userdata(request);
struct jsonrpc_server * rpc = user_data->rpc;
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_open_finished, request, "open", "ii", inode, file_info->flags);
jsonrpc_server_invoke(rpc, &operation_open_finished, request, "open", "ii", inode, file_info->flags);
}

View File

@ -10,7 +10,7 @@
#define WSFS_MAX_READ_LENGTH 4096
static char * wsfs_fill_buffer(
static char * fill_buffer(
char const * data,
char const * format,
size_t count,
@ -38,7 +38,7 @@ static char * wsfs_fill_buffer(
return buffer;
}
static void wsfs_operation_read_finished(void * user_data, wsfs_status status, json_t const * data)
static void operation_read_finished(void * user_data, wsfs_status status, json_t const * data)
{
fuse_req_t request = user_data;
@ -58,7 +58,7 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j
char const * const format = json_string_value(format_holder);
length = (size_t) json_integer_value(count_holder);
buffer = wsfs_fill_buffer(data, format, length, &status);
buffer = fill_buffer(data, format, length, &status);
}
else
{
@ -79,17 +79,17 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j
}
void wsfs_operation_read(
void operation_read(
fuse_req_t request,
fuse_ino_t inode,
size_t size,
off_t offset,
struct fuse_file_info * file_info)
{
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct operations_context * user_data = fuse_req_userdata(request);
struct jsonrpc_server * rpc = user_data->rpc;
int const length = (size <= WSFS_MAX_READ_LENGTH) ? (int) size : WSFS_MAX_READ_LENGTH;
int handle = (file_info->fh & INT_MAX);
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
jsonrpc_server_invoke(rpc, &operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
}

View File

@ -14,37 +14,37 @@
#define WSFS_DIRBUFFER_INITIAL_SIZE 1024
struct wsfs_operation_readdir_context
struct operation_readdir_context
{
fuse_req_t request;
size_t size;
off_t offset;
};
struct wsfs_dirbuffer
struct dirbuffer
{
char * data;
size_t position;
size_t capacity;
};
static void wsfs_dirbuffer_init(
struct wsfs_dirbuffer * buffer)
static void dirbuffer_init(
struct dirbuffer * buffer)
{
buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE);
buffer->position = 0;
buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE;
}
static void wsfs_dirbuffer_dispose(
struct wsfs_dirbuffer * buffer)
static void dirbuffer_dispose(
struct dirbuffer * buffer)
{
free(buffer->data);
}
static void wsfs_dirbuffer_add(
static void dirbuffer_add(
fuse_req_t request,
struct wsfs_dirbuffer * buffer,
struct dirbuffer * buffer,
char const * name,
fuse_ino_t inode)
{
@ -71,15 +71,15 @@ static size_t min(size_t a, size_t b)
return (a < b) ? a : b;
}
static void wsfs_operation_readdir_finished(
static void operation_readdir_finished(
void * user_data,
wsfs_status status,
json_t const * result)
{
struct wsfs_operation_readdir_context * context = user_data;
struct operation_readdir_context * context = user_data;
struct wsfs_dirbuffer buffer;
wsfs_dirbuffer_init(&buffer);
struct dirbuffer buffer;
dirbuffer_init(&buffer);
if (NULL != result)
{
@ -100,7 +100,7 @@ static void wsfs_operation_readdir_finished(
{
char const * name = json_string_value(name_holder);
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
wsfs_dirbuffer_add(context->request, &buffer, name, entry_inode);
dirbuffer_add(context->request, &buffer, name, entry_inode);
}
}
}
@ -125,23 +125,23 @@ static void wsfs_operation_readdir_finished(
fuse_reply_err(context->request, ENOENT);
}
wsfs_dirbuffer_dispose(&buffer);
dirbuffer_dispose(&buffer);
free(context);
}
void wsfs_operation_readdir (
void operation_readdir (
fuse_req_t request,
fuse_ino_t inode,
size_t size,
off_t offset,
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
struct wsfs_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_operation_readdir_context));
struct operations_context * user_data = fuse_req_userdata(request);
struct jsonrpc_server * rpc = user_data->rpc;
struct operation_readdir_context * readdir_context = malloc(sizeof(struct operation_readdir_context));
readdir_context->request = request;
readdir_context->size = size;
readdir_context->offset = offset;
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_readdir_finished, readdir_context, "readdir", "i", inode);
jsonrpc_server_invoke(rpc, &operation_readdir_finished, readdir_context, "readdir", "i", inode);
}

View File

@ -7,42 +7,42 @@
extern "C" {
#endif
struct wsfs_jsonrpc_server;
struct jsonrpc_server;
struct wsfs_operations_context
struct operations_context
{
struct wsfs_jsonrpc_server * rpc;
struct jsonrpc_server * rpc;
double timeout;
};
extern void wsfs_operation_lookup (
extern void operation_lookup (
fuse_req_t req,
fuse_ino_t parent,
char const * name);
extern void wsfs_operation_getattr (
extern void operation_getattr (
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info *file_info);
extern void wsfs_operation_readdir (
extern void 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 operation_open(
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * file_info);
extern void wsfs_operation_close(
extern void operation_close(
fuse_req_t request,
fuse_ino_t inode,
struct fuse_file_info * file_info);
extern void wsfs_operation_read(
extern void operation_read(
fuse_req_t request,
fuse_ino_t ino, size_t size, off_t off,
struct fuse_file_info *fi);

View File

@ -26,13 +26,13 @@ struct wsfs_server
struct lws_context_creation_info info;
};
static bool wsfs_impl_server_tls_enabled(
static bool server_tls_enabled(
struct wsfs_server * server)
{
return ((server->config.key_path != NULL) && (server->config.cert_path != NULL));
}
static struct lws_context * wsfs_impl_server_context_create(
static struct lws_context * server_context_create(
struct wsfs_server * server)
{
lws_set_log_level(WSFS_DISABLE_LWS_LOG, NULL);
@ -41,7 +41,7 @@ static struct lws_context * wsfs_impl_server_context_create(
server->ws_protocols[0].name = "http";
server->ws_protocols[0].callback = lws_callback_http_dummy;
server->ws_protocols[1].name = "fs";
wsfs_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]);
server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]);
memset(&server->mount, 0, sizeof(struct lws_http_mount));
server->mount.mount_next = NULL,
@ -66,7 +66,7 @@ static struct lws_context * wsfs_impl_server_context_create(
server->info.mounts = NULL;
}
if (wsfs_impl_server_tls_enabled(server))
if (server_tls_enabled(server))
{
server->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
server->info.ssl_cert_filepath = server->config.cert_path;
@ -78,7 +78,7 @@ static struct lws_context * wsfs_impl_server_context_create(
}
static bool wsfs_impl_server_check_mountpoint(
static bool server_check_mountpoint(
struct wsfs_server_config * config)
{
bool result = false;
@ -98,22 +98,22 @@ static bool wsfs_impl_server_check_mountpoint(
return result;
}
struct wsfs_server * wsfs_impl_server_create(
struct wsfs_server * server_create(
struct wsfs_server_config * config)
{
struct wsfs_server * server = NULL;
if (wsfs_impl_server_check_mountpoint(config))
if (server_check_mountpoint(config))
{
server = malloc(sizeof(struct wsfs_server));
if (NULL != server)
{
if (wsfs_impl_server_protocol_init(&server->protocol, config->mount_point))
if (server_protocol_init(&server->protocol, config->mount_point))
{
server->shutdown_requested = false;
wsfs_impl_server_config_clone(config, &server->config);
wsfs_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = wsfs_impl_server_context_create(server);
server_config_clone(config, &server->config);
authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = server_context_create(server);
}
else
{
@ -126,16 +126,16 @@ struct wsfs_server * wsfs_impl_server_create(
return server;
}
void wsfs_impl_server_dispose(
void server_dispose(
struct wsfs_server * server)
{
lws_context_destroy(server->context);
wsfs_impl_server_protocol_cleanup(&server->protocol);
wsfs_impl_server_config_cleanup(&server->config);
server_protocol_cleanup(&server->protocol);
server_config_cleanup(&server->config);
free(server);
}
void wsfs_impl_server_run(
void server_run(
struct wsfs_server * server)
{
int n = 0;
@ -145,7 +145,7 @@ void wsfs_impl_server_run(
}
}
void wsfs_impl_server_shutdown(
void server_shutdown(
struct wsfs_server * server)
{
server->shutdown_requested = true;

View File

@ -9,16 +9,16 @@ extern "C"
struct wsfs_server;
struct wsfs_server_config;
extern struct wsfs_server * wsfs_impl_server_create(
extern struct wsfs_server * server_create(
struct wsfs_server_config * config);
extern void wsfs_impl_server_dispose(
extern void server_dispose(
struct wsfs_server * server);
extern void wsfs_impl_server_run(
extern void server_run(
struct wsfs_server * server);
extern void wsfs_impl_server_shutdown(
extern void server_shutdown(
struct wsfs_server * server);
#ifdef __cplusplus

View File

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
static char * wsfs_server_config_strdup(char const * value)
static char * server_config_strdup(char const * value)
{
char * result = NULL;
if (NULL != value)
@ -14,18 +14,18 @@ static char * wsfs_server_config_strdup(char const * value)
return result;
}
void wsfs_impl_server_config_init(
void server_config_init(
struct wsfs_server_config * config)
{
memset(config, 0, sizeof(struct wsfs_server_config));
wsfs_authenticators_init(&config->authenticators);
authenticators_init(&config->authenticators);
}
void wsfs_impl_server_config_cleanup(
void server_config_cleanup(
struct wsfs_server_config * config)
{
wsfs_authenticators_cleanup(&config->authenticators);
authenticators_cleanup(&config->authenticators);
free(config->mount_point);
free(config->document_root);
@ -33,42 +33,42 @@ void wsfs_impl_server_config_cleanup(
free(config->cert_path);
free(config->vhost_name);
wsfs_impl_server_config_init(config);
server_config_init(config);
}
void wsfs_impl_server_config_clone(
void server_config_clone(
struct wsfs_server_config * config,
struct wsfs_server_config * clone)
{
clone->mount_point = wsfs_server_config_strdup(config->mount_point);
clone->document_root = wsfs_server_config_strdup(config->document_root);
clone->key_path = wsfs_server_config_strdup(config->key_path);
clone->cert_path = wsfs_server_config_strdup(config->cert_path);
clone->vhost_name = wsfs_server_config_strdup(config->vhost_name);
clone->mount_point = server_config_strdup(config->mount_point);
clone->document_root = server_config_strdup(config->document_root);
clone->key_path = server_config_strdup(config->key_path);
clone->cert_path = server_config_strdup(config->cert_path);
clone->vhost_name = server_config_strdup(config->vhost_name);
clone->port = config->port;
wsfs_authenticators_clone(&config->authenticators, &clone->authenticators);
authenticators_clone(&config->authenticators, &clone->authenticators);
}
struct wsfs_server_config * wsfs_impl_server_config_create(void)
struct wsfs_server_config * server_config_create(void)
{
struct wsfs_server_config * config = malloc(sizeof(struct wsfs_server_config));
if (NULL != config)
{
wsfs_impl_server_config_init(config);
server_config_init(config);
}
return config;
}
void wsfs_impl_server_config_dispose(
void server_config_dispose(
struct wsfs_server_config * config)
{
wsfs_impl_server_config_cleanup(config);
server_config_cleanup(config);
free(config);
}
void wsfs_impl_server_config_set_mountpoint(
void server_config_set_mountpoint(
struct wsfs_server_config * config,
char const * mount_point)
{
@ -76,7 +76,7 @@ void wsfs_impl_server_config_set_mountpoint(
config->mount_point = strdup(mount_point);
}
void wsfs_impl_server_config_set_documentroot(
void server_config_set_documentroot(
struct wsfs_server_config * config,
char const * document_root)
{
@ -84,7 +84,7 @@ void wsfs_impl_server_config_set_documentroot(
config->document_root = strdup(document_root);
}
void wsfs_impl_server_config_set_keypath(
void server_config_set_keypath(
struct wsfs_server_config * config,
char const * key_path)
{
@ -92,7 +92,7 @@ void wsfs_impl_server_config_set_keypath(
config->key_path = strdup(key_path);
}
void wsfs_impl_server_config_set_certpath(
void server_config_set_certpath(
struct wsfs_server_config * config,
char const * cert_path)
{
@ -100,7 +100,7 @@ void wsfs_impl_server_config_set_certpath(
config->cert_path = strdup(cert_path);
}
void wsfs_impl_server_config_set_vhostname(
void server_config_set_vhostname(
struct wsfs_server_config * config,
char const * vhost_name)
{
@ -108,20 +108,20 @@ void wsfs_impl_server_config_set_vhostname(
config->vhost_name = strdup(vhost_name);
}
void wsfs_impl_server_config_set_port(
void server_config_set_port(
struct wsfs_server_config * config,
int port)
{
config->port = port;
}
void wsfs_impl_server_config_add_authenticator(
void server_config_add_authenticator(
struct wsfs_server_config * config,
char const * type,
wsfs_authenticate_fn * authenticate,
void * user_data
)
{
wsfs_authenticators_add(&config->authenticators, type, authenticate, user_data);
authenticators_add(&config->authenticators, type, authenticate, user_data);
}

View File

@ -15,49 +15,49 @@ struct wsfs_server_config
char * cert_path;
char * vhost_name;
int port;
struct wsfs_authenticators authenticators;
struct authenticators authenticators;
};
extern struct wsfs_server_config * wsfs_impl_server_config_create(void);
extern struct wsfs_server_config * server_config_create(void);
extern void wsfs_impl_server_config_dispose(
extern void server_config_dispose(
struct wsfs_server_config * config);
extern void wsfs_impl_server_config_init(
extern void server_config_init(
struct wsfs_server_config * config);
extern void wsfs_impl_server_config_cleanup(
extern void server_config_cleanup(
struct wsfs_server_config * config);
extern void wsfs_impl_server_config_clone(
extern void server_config_clone(
struct wsfs_server_config * config,
struct wsfs_server_config * clone);
extern void wsfs_impl_server_config_set_mountpoint(
extern void server_config_set_mountpoint(
struct wsfs_server_config * config,
char const * mount_point);
extern void wsfs_impl_server_config_set_documentroot(
extern void server_config_set_documentroot(
struct wsfs_server_config * config,
char const * document_root);
extern void wsfs_impl_server_config_set_keypath(
extern void server_config_set_keypath(
struct wsfs_server_config * config,
char const * key_path);
extern void wsfs_impl_server_config_set_certpath(
extern void server_config_set_certpath(
struct wsfs_server_config * config,
char const * cert_path);
extern void wsfs_impl_server_config_set_vhostname(
extern void server_config_set_vhostname(
struct wsfs_server_config * config,
char const * vhost_name);
extern void wsfs_impl_server_config_set_port(
extern void server_config_set_port(
struct wsfs_server_config * config,
int port);
extern void wsfs_impl_server_config_add_authenticator(
extern void server_config_add_authenticator(
struct wsfs_server_config * config,
char const * type,
wsfs_authenticate_fn * authenticate,

View File

@ -8,7 +8,7 @@
#include "wsfs/adapter/impl/filesystem.h"
static int wsfs_impl_server_protocol_callback(
static int server_protocol_callback(
struct lws * wsi,
enum lws_callback_reasons reason,
void * WSFS_UNUSED_PARAM(user),
@ -18,15 +18,15 @@ static int wsfs_impl_server_protocol_callback(
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);
timeout_manager_check(&protocol->timeout_manager);
struct session * session = 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);
fd.filefd = 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");
@ -34,7 +34,7 @@ static int wsfs_impl_server_protocol_callback(
}
break;
case LWS_CALLBACK_ESTABLISHED:
session = wsfs_session_manager_add(
session = session_manager_add(
&protocol->session_manager,
wsi,
&protocol->authenticators,
@ -42,26 +42,26 @@ static int wsfs_impl_server_protocol_callback(
if (NULL != session)
{
wsfs_session_authenticate(session, NULL);
session_authenticate(session, NULL);
}
break;
case LWS_CALLBACK_CLOSED:
wsfs_session_manager_remove(&protocol->session_manager, wsi);
session_manager_remove(&protocol->session_manager, wsi);
break;
case LWS_CALLBACK_SERVER_WRITEABLE:
if (NULL != session)
{
wsfs_session_onwritable(session);
session_onwritable(session);
}
break;
case LWS_CALLBACK_RECEIVE:
if (NULL != session)
{
wsfs_session_receive(session, in, len);
session_receive(session, in, len);
}
break;
case LWS_CALLBACK_RAW_RX_FILE:
wsfs_filesystem_process_request(&protocol->filesystem);
filesystem_process_request(&protocol->filesystem);
break;
default:
break;
@ -70,27 +70,27 @@ static int wsfs_impl_server_protocol_callback(
return 0;
}
static bool wsfs_impl_server_protocol_invoke(
static bool 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 session * session = &protocol->session_manager.session;
struct wsfs_message * message = wsfs_message_create(request);
bool const result = wsfs_session_send(session, message);
bool const result = session_send(session, message);
return result;
}
struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
struct wsfs_server_protocol * 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))
if (!server_protocol_init(protocol, mount_point))
{
free(protocol);
protocol = NULL;
@ -100,67 +100,67 @@ struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
return protocol;
}
void wsfs_impl_server_protocol_dispose(
void server_protocol_dispose(
struct wsfs_server_protocol * protocol)
{
wsfs_impl_server_protocol_cleanup(protocol);
server_protocol_cleanup(protocol);
free(protocol);
}
void wsfs_impl_server_protocol_init_lws(
void server_protocol_init_lws(
struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol)
{
lws_protocol->callback = &wsfs_impl_server_protocol_callback;
lws_protocol->callback = &server_protocol_callback;
lws_protocol->per_session_data_size = 0;
lws_protocol->user = protocol;
}
bool wsfs_impl_server_protocol_init(
bool 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);
timeout_manager_init(&protocol->timeout_manager);
session_manager_init(&protocol->session_manager);
authenticators_init(&protocol->authenticators);
wsfs_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
wsfs_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_impl_server_protocol_invoke, protocol);
jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
jsonrpc_server_add(&protocol->rpc, "lookup", &server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "getattr", &server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "readdir", &server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "open", &server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "close", &server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "read", &server_protocol_invoke, protocol);
bool const success = wsfs_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
bool const success = 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);
jsonrpc_server_cleanup(&protocol->rpc);
authenticators_cleanup(&protocol->authenticators);
timeout_manager_cleanup(&protocol->timeout_manager);
session_manager_cleanup(&protocol->session_manager);
}
return success;
}
void wsfs_impl_server_protocol_cleanup(
void 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);
filesystem_cleanup(&protocol->filesystem);
jsonrpc_server_cleanup(&protocol->rpc);
timeout_manager_cleanup(&protocol->timeout_manager);
authenticators_cleanup(&protocol->authenticators);
session_manager_cleanup(&protocol->session_manager);
}
void wsfs_impl_server_protocol_add_authenticator(
void 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);
authenticators_add(&protocol->authenticators, type, authenticate, user_data);
}

View File

@ -16,31 +16,31 @@ struct lws_protocols;
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;
struct timeout_manager timeout_manager;
struct filesystem filesystem;
struct jsonrpc_server rpc;
struct authenticators authenticators;
struct session_manager session_manager;
};
extern bool wsfs_impl_server_protocol_init(
extern bool server_protocol_init(
struct wsfs_server_protocol * protocol,
char * mount_point);
extern void wsfs_impl_server_protocol_cleanup(
extern void server_protocol_cleanup(
struct wsfs_server_protocol * protocol);
extern struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
extern struct wsfs_server_protocol * server_protocol_create(
char * mount_point);
extern void wsfs_impl_server_protocol_dispose(
extern void server_protocol_dispose(
struct wsfs_server_protocol * protocol);
extern void wsfs_impl_server_protocol_init_lws(
extern void server_protocol_init_lws(
struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol);
extern void wsfs_impl_server_protocol_add_authenticator(
extern void server_protocol_add_authenticator(
struct wsfs_server_protocol * protocol,
char const * type,
wsfs_authenticate_fn * authenticate,

View File

@ -7,11 +7,11 @@
#include <libwebsockets.h>
#include <stddef.h>
void wsfs_session_init(
struct wsfs_session * session,
void session_init(
struct session * session,
struct lws * wsi,
struct wsfs_authenticators * authenticators,
struct wsfs_jsonrpc_server * rpc)
struct authenticators * authenticators,
struct jsonrpc_server * rpc)
{
session->wsi = wsi;
session->is_authenticated = false;
@ -20,8 +20,8 @@ void wsfs_session_init(
wsfs_message_queue_init(&session->queue);
}
void wsfs_session_cleanup(
struct wsfs_session * session)
void session_cleanup(
struct session * session)
{
wsfs_message_queue_cleanup(&session->queue);
session->is_authenticated = false;
@ -30,15 +30,15 @@ void wsfs_session_cleanup(
session->rpc = NULL;
}
void wsfs_session_authenticate(
struct wsfs_session * session,
void session_authenticate(
struct session * session,
struct wsfs_credentials * creds)
{
session->is_authenticated = wsfs_authenticators_authenticate(session->authenticators, creds);
session->is_authenticated = authenticators_authenticate(session->authenticators, creds);
}
bool wsfs_session_send(
struct wsfs_session * session,
bool session_send(
struct session * session,
struct wsfs_message * message)
{
bool result = (session->is_authenticated) && (NULL != session->wsi);
@ -58,8 +58,8 @@ bool wsfs_session_send(
return result;
}
void wsfs_session_onwritable(
struct wsfs_session * session)
void session_onwritable(
struct session * session)
{
if (!wsfs_message_queue_empty(&session->queue))
{
@ -75,10 +75,10 @@ void wsfs_session_onwritable(
}
void wsfs_session_receive(
struct wsfs_session * session,
void session_receive(
struct session * session,
char const * data,
size_t length)
{
wsfs_jsonrpc_server_onresult(session->rpc, data, length);
jsonrpc_server_onresult(session->rpc, data, length);
}

View File

@ -19,42 +19,42 @@ extern "C"
struct lws;
struct wsfs_message;
struct wsfs_credentials;
struct wsfs_authenticators;
struct wsfs_jsonrpc_server;
struct authenticators;
struct jsonrpc_server;
struct wsfs_session
struct session
{
struct lws * wsi;
bool is_authenticated;
struct wsfs_message_queue queue;
struct wsfs_authenticators * authenticators;
struct wsfs_jsonrpc_server * rpc;
struct authenticators * authenticators;
struct jsonrpc_server * rpc;
};
extern void wsfs_session_init(
struct wsfs_session * session,
extern void session_init(
struct session * session,
struct lws * wsi,
struct wsfs_authenticators * authenticators,
struct wsfs_jsonrpc_server * rpc);
struct authenticators * authenticators,
struct jsonrpc_server * rpc);
extern void wsfs_session_authenticate(
struct wsfs_session * session,
extern void session_authenticate(
struct session * session,
struct wsfs_credentials * creds);
extern bool wsfs_session_send(
struct wsfs_session * session,
extern bool session_send(
struct session * session,
struct wsfs_message * message);
extern void wsfs_session_receive(
struct wsfs_session * session,
extern void session_receive(
struct session * session,
char const * data,
size_t length);
extern void wsfs_session_onwritable(
struct wsfs_session * session);
extern void session_onwritable(
struct session * session);
extern void wsfs_session_cleanup(
struct wsfs_session * session);
extern void session_cleanup(
struct session * session);
#ifdef __cplusplus
}

View File

@ -1,39 +1,39 @@
#include "wsfs/adapter/impl/session_manager.h"
#include <stddef.h>
void wsfs_session_manager_init(
struct wsfs_session_manager * manager)
void session_manager_init(
struct session_manager * manager)
{
wsfs_session_init(&manager->session, NULL, NULL, NULL);
session_init(&manager->session, NULL, NULL, NULL);
}
void wsfs_session_manager_cleanup(
struct wsfs_session_manager * manager)
void session_manager_cleanup(
struct session_manager * manager)
{
wsfs_session_cleanup(&manager->session);
session_cleanup(&manager->session);
}
struct wsfs_session * wsfs_session_manager_add(
struct wsfs_session_manager * manager,
struct session * session_manager_add(
struct session_manager * manager,
struct lws * wsi,
struct wsfs_authenticators * authenticators,
struct wsfs_jsonrpc_server * rpc)
struct authenticators * authenticators,
struct jsonrpc_server * rpc)
{
struct wsfs_session * session = NULL;
struct session * session = NULL;
if (NULL == manager->session.wsi)
{
session = &manager->session;
wsfs_session_init(&manager->session, wsi, authenticators, rpc);
session_init(&manager->session, wsi, authenticators, rpc);
}
return session;
}
struct wsfs_session * wsfs_session_manager_get(
struct wsfs_session_manager * manager,
struct session * session_manager_get(
struct session_manager * manager,
struct lws * wsi)
{
struct wsfs_session * session = NULL;
struct session * session = NULL;
if (wsi == manager->session.wsi)
{
session = &manager->session;
@ -42,13 +42,13 @@ struct wsfs_session * wsfs_session_manager_get(
return session;
}
void wsfs_session_manager_remove(
struct wsfs_session_manager * manager,
void session_manager_remove(
struct session_manager * manager,
struct lws * wsi)
{
if (wsi == manager->session.wsi)
{
wsfs_session_cleanup(&manager->session);
session_cleanup(&manager->session);
manager->session.wsi = NULL;
}
}

View File

@ -14,29 +14,29 @@ extern "C"
struct lws;
struct wsfs_session_manager
struct session_manager
{
struct wsfs_session session;
struct session session;
};
extern void wsfs_session_manager_init(
struct wsfs_session_manager * manager);
extern void session_manager_init(
struct session_manager * manager);
extern void wsfs_session_manager_cleanup(
struct wsfs_session_manager * manager);
extern void session_manager_cleanup(
struct session_manager * manager);
extern struct wsfs_session * wsfs_session_manager_add(
struct wsfs_session_manager * manager,
extern struct session * session_manager_add(
struct session_manager * manager,
struct lws * wsi,
struct wsfs_authenticators * authenticators,
struct wsfs_jsonrpc_server * rpc);
struct authenticators * authenticators,
struct jsonrpc_server * rpc);
extern struct wsfs_session * wsfs_session_manager_get(
struct wsfs_session_manager * manager,
extern struct session * session_manager_get(
struct session_manager * manager,
struct lws * wsi);
extern void wsfs_session_manager_remove(
struct wsfs_session_manager * manager,
extern void session_manager_remove(
struct session_manager * manager,
struct lws * wsi);
#ifdef __cplusplus

View File

@ -4,21 +4,21 @@
#include "wsfs/adapter/impl/time/timer_intern.h"
#include "wsfs/adapter/impl/time/timepoint.h"
void wsfs_timeout_manager_init(
struct wsfs_timeout_manager * manager)
void timeout_manager_init(
struct timeout_manager * manager)
{
manager->timers = NULL;
}
void wsfs_timeout_manager_cleanup(
struct wsfs_timeout_manager * manager)
void timeout_manager_cleanup(
struct timeout_manager * manager)
{
struct wsfs_timer * timer = manager->timers;
struct timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_timer * next = timer->next;
struct timer * next = timer->next;
wsfs_timer_trigger(timer);
timer_trigger(timer);
timer = next;
}
@ -27,27 +27,27 @@ void wsfs_timeout_manager_cleanup(
}
void wsfs_timeout_manager_check(
struct wsfs_timeout_manager * manager)
void timeout_manager_check(
struct timeout_manager * manager)
{
struct wsfs_timer * timer = manager->timers;
struct timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_timer * next = timer->next;
struct timer * next = timer->next;
if (wsfs_timer_is_timeout(timer))
if (timer_is_timeout(timer))
{
wsfs_timeout_manager_removetimer(manager, timer);
wsfs_timer_trigger(timer);
timeout_manager_removetimer(manager, timer);
timer_trigger(timer);
}
timer = next;
}
}
void wsfs_timeout_manager_addtimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer)
void timeout_manager_addtimer(
struct timeout_manager * manager,
struct timer * timer)
{
if (NULL != manager->timers)
{
@ -59,12 +59,12 @@ void wsfs_timeout_manager_addtimer(
manager->timers = timer;
}
void wsfs_timeout_manager_removetimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer)
void timeout_manager_removetimer(
struct timeout_manager * manager,
struct timer * timer)
{
struct wsfs_timer * prev = timer->prev;
struct wsfs_timer * next = timer->next;
struct timer * prev = timer->prev;
struct timer * next = timer->next;
if (NULL != prev)
{

View File

@ -6,20 +6,20 @@ extern "C"
{
#endif
struct wsfs_timer;
struct wsfs_timeout_manager
struct timer;
struct timeout_manager
{
struct wsfs_timer * timers;
struct timer * timers;
};
extern void wsfs_timeout_manager_init(
struct wsfs_timeout_manager * manager);
extern void timeout_manager_init(
struct timeout_manager * manager);
extern void wsfs_timeout_manager_cleanup(
struct wsfs_timeout_manager * manager);
extern void timeout_manager_cleanup(
struct timeout_manager * manager);
extern void wsfs_timeout_manager_check(
struct wsfs_timeout_manager * manager);
extern void timeout_manager_check(
struct timeout_manager * manager);
#ifdef __cplusplus

View File

@ -8,13 +8,13 @@ extern "C"
{
#endif
extern void wsfs_timeout_manager_addtimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer);
extern void timeout_manager_addtimer(
struct timeout_manager * manager,
struct timer * timer);
extern void wsfs_timeout_manager_removetimer(
struct wsfs_timeout_manager * manager,
struct wsfs_timer * timer);
extern void timeout_manager_removetimer(
struct timeout_manager * manager,
struct timer * timer);
#ifdef __cplusplus
}

View File

@ -2,30 +2,30 @@
#include <time.h>
#define WSFS_MSEC_PER_SEC ((wsfs_timepoint) 1000)
#define WSFS_NSEC_PER_MSEC ((wsfs_timepoint) 1000 * 1000)
#define WSFS_MSEC_PER_SEC ((timepoint) 1000)
#define WSFS_NSEC_PER_MSEC ((timepoint) 1000 * 1000)
wsfs_timepoint wsfs_timepoint_now(void)
timepoint timepoint_now(void)
{
struct timespec timepoint;
clock_gettime(CLOCK_MONOTONIC, &timepoint);
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
wsfs_timepoint const now = (timepoint.tv_sec * WSFS_MSEC_PER_SEC) + (timepoint.tv_nsec / WSFS_NSEC_PER_MSEC);
timepoint const now = (tp.tv_sec * WSFS_MSEC_PER_SEC) + (tp.tv_nsec / WSFS_NSEC_PER_MSEC);
return now;
}
wsfs_timepoint wsfs_timepoint_in_msec(wsfs_timediff value)
timepoint timepoint_in_msec(timediff value)
{
wsfs_timepoint const now = wsfs_timepoint_now();
wsfs_timepoint result = now + ((wsfs_timepoint) value);
timepoint const now = timepoint_now();
timepoint result = now + ((timepoint) value);
return result;
}
bool wsfs_timepoint_is_elapsed(wsfs_timepoint timepoint)
bool timepoint_is_elapsed(timepoint tp)
{
wsfs_timepoint const now = wsfs_timepoint_now();
wsfs_timediff const diff = (wsfs_timediff) (timepoint - now);
timepoint const now = timepoint_now();
timediff const diff = (timediff) (tp - now);
return (0 > diff);
}

View File

@ -13,16 +13,16 @@ extern "C"
{
#endif
typedef uint64_t wsfs_timepoint;
typedef int64_t wsfs_timediff;
typedef uint64_t timepoint;
typedef int64_t timediff;
extern wsfs_timepoint wsfs_timepoint_now(void);
extern timepoint timepoint_now(void);
extern wsfs_timepoint wsfs_timepoint_in_msec(
wsfs_timediff value);
extern timepoint timepoint_in_msec(
timediff value);
extern bool wsfs_timepoint_is_elapsed(
wsfs_timepoint timepoint);
extern bool timepoint_is_elapsed(
timepoint timepoint);
#ifdef __cplusplus
}

View File

@ -4,9 +4,9 @@
#include <stddef.h>
#include <string.h>
void wsfs_timer_init(
struct wsfs_timer * timer,
struct wsfs_timeout_manager * manager)
void timer_init(
struct timer * timer,
struct timeout_manager * manager)
{
timer->manager = manager;
timer->timeout = 0;
@ -16,44 +16,44 @@ void wsfs_timer_init(
timer->next = NULL;
}
void wsfs_timer_cleanup(
struct wsfs_timer * timer)
void timer_cleanup(
struct timer * timer)
{
memset(timer, 0, sizeof(struct wsfs_timer));
memset(timer, 0, sizeof(struct timer));
}
void wsfs_timer_start(
struct wsfs_timer * timer,
wsfs_timepoint absolute_timeout,
wsfs_timer_timeout_fn * handler,
void timer_start(
struct timer * timer,
timepoint absolute_timeout,
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);
timeout_manager_addtimer(timer->manager, timer);
}
void wsfs_timer_cancel(
struct wsfs_timer * timer)
void timer_cancel(
struct timer * timer)
{
wsfs_timeout_manager_removetimer(timer->manager, timer);
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)
bool timer_is_timeout(
struct timer * timer)
{
return wsfs_timepoint_is_elapsed(timer->timeout);
return timepoint_is_elapsed(timer->timeout);
}
void wsfs_timer_trigger(
struct wsfs_timer * timer)
void timer_trigger(
struct timer * timer)
{
if (NULL != timer->timeout_handler)
{

View File

@ -8,36 +8,36 @@ extern "C"
{
#endif
struct wsfs_timer;
struct wsfs_timeout_manager;
struct timer;
struct timeout_manager;
typedef void wsfs_timer_timeout_fn(struct wsfs_timer * timer);
typedef void timer_timeout_fn(struct timer * timer);
struct wsfs_timer
struct timer
{
struct wsfs_timeout_manager * manager;
wsfs_timepoint timeout;
wsfs_timer_timeout_fn * timeout_handler;
struct timeout_manager * manager;
timepoint timeout;
timer_timeout_fn * timeout_handler;
void * user_data;
struct wsfs_timer * next;
struct wsfs_timer * prev;
struct timer * next;
struct timer * prev;
};
extern void wsfs_timer_init(
struct wsfs_timer * timer,
struct wsfs_timeout_manager * manager);
extern void timer_init(
struct timer * timer,
struct timeout_manager * manager);
extern void wsfs_timer_cleanup(
struct wsfs_timer * timer);
extern void timer_cleanup(
struct timer * timer);
extern void wsfs_timer_start(
struct wsfs_timer * timer,
wsfs_timepoint absolute_timeout,
wsfs_timer_timeout_fn * handler,
extern void timer_start(
struct timer * timer,
timepoint absolute_timeout,
timer_timeout_fn * handler,
void * user_data);
extern void wsfs_timer_cancel(
struct wsfs_timer * timer);
extern void timer_cancel(
struct timer * timer);
#ifdef __cplusplus
}

View File

@ -12,11 +12,11 @@ extern "C"
{
#endif
extern bool wsfs_timer_is_timeout(
struct wsfs_timer * timer);
extern bool timer_is_timeout(
struct timer * timer);
extern void wsfs_timer_trigger(
struct wsfs_timer * timer);
extern void timer_trigger(
struct timer * timer);
#ifdef __cplusplus
}

View File

@ -20,7 +20,7 @@ TEST(Authenticator, Authenticate)
set_authenticator(&mock);
struct wsfs_credentials creds;
wsfs_impl_credentials_init(&creds, "username", nullptr);
credentials_init(&creds, "username", nullptr);
char dummy[] = "usr_data";
void * user_data = reinterpret_cast<void*>(dummy);
@ -28,16 +28,16 @@ TEST(Authenticator, Authenticate)
.Times(1)
.WillRepeatedly(Return(true));
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(
struct authenticator * authenticator = authenticator_create(
"username",
&authenticate,
user_data);
bool result = wsfs_authenticator_autenticate(authenticator, &creds);
bool result = authenticator_autenticate(authenticator, &creds);
ASSERT_TRUE(result);
wsfs_authenticator_dispose(authenticator);
wsfs_impl_credentials_cleanup(&creds);
authenticator_dispose(authenticator);
credentials_cleanup(&creds);
}
TEST(Authenticator, SkipAuthenticationWithWrongType)
@ -46,18 +46,18 @@ TEST(Authenticator, SkipAuthenticationWithWrongType)
set_authenticator(&mock);
struct wsfs_credentials creds;
wsfs_impl_credentials_init(&creds, "username", nullptr);
credentials_init(&creds, "username", nullptr);
EXPECT_CALL(mock, authenticate(_, _))
.Times(0);
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(
struct authenticator * authenticator = authenticator_create(
"certificate",
&authenticate,
nullptr);
bool result = wsfs_authenticator_autenticate(authenticator, &creds);
bool result = authenticator_autenticate(authenticator, &creds);
ASSERT_FALSE(result);
wsfs_authenticator_dispose(authenticator);
wsfs_impl_credentials_cleanup(&creds);
authenticator_dispose(authenticator);
credentials_cleanup(&creds);
}

View File

@ -16,71 +16,71 @@ using ::wsfs_test::authenticate_2;
TEST(Authenticators, CloneEmpty)
{
struct wsfs_authenticators authenticators;
struct wsfs_authenticators clone;
struct authenticators authenticators;
struct authenticators clone;
wsfs_authenticators_init(&authenticators);
authenticators_init(&authenticators);
ASSERT_EQ(nullptr, authenticators.first);
wsfs_authenticators_clone(&authenticators, &clone);
authenticators_clone(&authenticators, &clone);
ASSERT_EQ(nullptr, clone.first);
wsfs_authenticators_cleanup(&authenticators);
wsfs_authenticators_cleanup(&clone);
authenticators_cleanup(&authenticators);
authenticators_cleanup(&clone);
}
TEST(Authenticators, Clone)
{
struct wsfs_authenticators authenticators;
struct wsfs_authenticators clone;
struct authenticators authenticators;
struct authenticators clone;
wsfs_authenticators_init(&authenticators);
wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr);
authenticators_init(&authenticators);
authenticators_add(&authenticators, "username", &authenticate, nullptr);
ASSERT_NE(nullptr, authenticators.first);
wsfs_authenticators_clone(&authenticators, &clone);
authenticators_clone(&authenticators, &clone);
ASSERT_NE(nullptr, clone.first);
ASSERT_NE(nullptr, authenticators.first);
ASSERT_NE(authenticators.first, clone.first);
wsfs_authenticators_cleanup(&authenticators);
wsfs_authenticators_cleanup(&clone);
authenticators_cleanup(&authenticators);
authenticators_cleanup(&clone);
}
TEST(Authenticators, Move)
{
struct wsfs_authenticators authenticators;
struct wsfs_authenticators clone;
struct authenticators authenticators;
struct authenticators clone;
wsfs_authenticators_init(&authenticators);
wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr);
authenticators_init(&authenticators);
authenticators_add(&authenticators, "username", &authenticate, nullptr);
ASSERT_NE(nullptr, authenticators.first);
wsfs_authenticators_move(&authenticators, &clone);
authenticators_move(&authenticators, &clone);
ASSERT_NE(nullptr, clone.first);
ASSERT_EQ(nullptr, authenticators.first);
ASSERT_NE(authenticators.first, clone.first);
wsfs_authenticators_cleanup(&authenticators);
wsfs_authenticators_cleanup(&clone);
authenticators_cleanup(&authenticators);
authenticators_cleanup(&clone);
}
TEST(Authenticators, AuthenticateWithoutAuthenticators)
{
struct wsfs_credentials creds;
wsfs_impl_credentials_init(&creds, "username", nullptr);
credentials_init(&creds, "username", nullptr);
struct wsfs_authenticators authenticators;
wsfs_authenticators_init(&authenticators);
struct authenticators authenticators;
authenticators_init(&authenticators);
bool result = wsfs_authenticators_authenticate(&authenticators, &creds);
bool result =authenticators_authenticate(&authenticators, &creds);
ASSERT_TRUE(result);
result = wsfs_authenticators_authenticate(&authenticators, nullptr);
result = authenticators_authenticate(&authenticators, nullptr);
ASSERT_TRUE(result);
wsfs_authenticators_cleanup(&authenticators);
wsfs_impl_credentials_cleanup(&creds);
authenticators_cleanup(&authenticators);
credentials_cleanup(&creds);
}
TEST(Authenticators, FailToAuthenticateWithoutCredentials)
@ -88,20 +88,20 @@ TEST(Authenticators, FailToAuthenticateWithoutCredentials)
MockAuthenticator mock;
set_authenticator(&mock);
struct wsfs_authenticators authenticators;
wsfs_authenticators_init(&authenticators);
wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr);
struct authenticators authenticators;
authenticators_init(&authenticators);
authenticators_add(&authenticators, "username", &authenticate, nullptr);
bool result = wsfs_authenticators_authenticate(&authenticators, nullptr);
bool result = authenticators_authenticate(&authenticators, nullptr);
ASSERT_FALSE(result);
wsfs_authenticators_cleanup(&authenticators);
authenticators_cleanup(&authenticators);
}
TEST(Authenticators, AuthenticateWithMultipleCredentials)
{
struct wsfs_credentials creds;
wsfs_impl_credentials_init(&creds, "username", nullptr);
credentials_init(&creds, "username", nullptr);
MockAuthenticator username_mock;
set_authenticator(1, &username_mock);
@ -114,22 +114,22 @@ TEST(Authenticators, AuthenticateWithMultipleCredentials)
EXPECT_CALL(certificate_mock, authenticate(_, _))
.Times(0);
struct wsfs_authenticators authenticators;
wsfs_authenticators_init(&authenticators);
wsfs_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
wsfs_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
struct authenticators authenticators;
authenticators_init(&authenticators);
authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
bool result = wsfs_authenticators_authenticate(&authenticators, &creds);
bool result = authenticators_authenticate(&authenticators, &creds);
ASSERT_TRUE(result);
wsfs_authenticators_cleanup(&authenticators);
wsfs_impl_credentials_cleanup(&creds);
authenticators_cleanup(&authenticators);
credentials_cleanup(&creds);
}
TEST(Authenticators, FailedAuthenticateWithWrongType)
{
struct wsfs_credentials creds;
wsfs_impl_credentials_init(&creds, "token", nullptr);
credentials_init(&creds, "token", nullptr);
MockAuthenticator username_mock;
set_authenticator(1, &username_mock);
@ -141,14 +141,14 @@ TEST(Authenticators, FailedAuthenticateWithWrongType)
EXPECT_CALL(certificate_mock, authenticate(_, _))
.Times(0);
struct wsfs_authenticators authenticators;
wsfs_authenticators_init(&authenticators);
wsfs_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
wsfs_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
struct authenticators authenticators;
authenticators_init(&authenticators);
authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
bool result = wsfs_authenticators_authenticate(&authenticators, &creds);
bool result = authenticators_authenticate(&authenticators, &creds);
ASSERT_FALSE(result);
wsfs_authenticators_cleanup(&authenticators);
wsfs_impl_credentials_cleanup(&creds);
authenticators_cleanup(&authenticators);
credentials_cleanup(&creds);
}

View File

@ -7,9 +7,9 @@ TEST(Credentials, Type)
{
struct wsfs_credentials creds;
wsfs_impl_credentials_init(&creds, "test", nullptr);
ASSERT_STREQ("test", wsfs_impl_credentials_type(&creds));
wsfs_impl_credentials_cleanup(&creds);
credentials_init(&creds, "test", nullptr);
ASSERT_STREQ("test", credentials_type(&creds));
credentials_cleanup(&creds);
}
TEST(Credentials, Get)
@ -19,12 +19,12 @@ TEST(Credentials, Get)
json_object_set_new(data, "username", json_string("bob"));
json_object_set_new(data, "password", json_string("<secret>"));
wsfs_impl_credentials_init(&creds, "username", data);
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
ASSERT_STREQ("bob", wsfs_impl_credentials_get(&creds, "username"));
ASSERT_STREQ("<secret>", wsfs_impl_credentials_get(&creds, "password"));
credentials_init(&creds, "username", data);
ASSERT_STREQ("username", credentials_type(&creds));
ASSERT_STREQ("bob", credentials_get(&creds, "username"));
ASSERT_STREQ("<secret>", credentials_get(&creds, "password"));
wsfs_impl_credentials_cleanup(&creds);
credentials_cleanup(&creds);
json_decref(data);
}
@ -33,12 +33,12 @@ TEST(Credentials, FailedToGetNonexistingValue)
struct wsfs_credentials creds;
json_t * data = json_object();
wsfs_impl_credentials_init(&creds, "username", data);
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
credentials_init(&creds, "username", data);
ASSERT_STREQ("username", credentials_type(&creds));
ASSERT_STREQ(nullptr, credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, credentials_get(&creds, "password"));
wsfs_impl_credentials_cleanup(&creds);
credentials_cleanup(&creds);
json_decref(data);
}
@ -46,12 +46,12 @@ TEST(Credentials, FailedToGetWithoutData)
{
struct wsfs_credentials creds;
wsfs_impl_credentials_init(&creds, "username", nullptr);
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
credentials_init(&creds, "username", nullptr);
ASSERT_STREQ("username",credentials_type(&creds));
ASSERT_STREQ(nullptr, credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, credentials_get(&creds, "password"));
wsfs_impl_credentials_cleanup(&creds);
credentials_cleanup(&creds);
}
TEST(Credentials, FailedToGetWrongDataType)
@ -59,12 +59,12 @@ TEST(Credentials, FailedToGetWrongDataType)
struct wsfs_credentials creds;
json_t * data = json_string("invalid_creds");
wsfs_impl_credentials_init(&creds, "username", data);
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
credentials_init(&creds, "username", data);
ASSERT_STREQ("username", credentials_type(&creds));
ASSERT_STREQ(nullptr, credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, credentials_get(&creds, "password"));
wsfs_impl_credentials_cleanup(&creds);
credentials_cleanup(&creds);
json_decref(data);
}

View File

@ -4,56 +4,56 @@
#include "wsfs/adapter/impl/jsonrpc/response.h"
static void wsfs_response_parse_str(
static void response_parse_str(
std::string const & buffer,
struct wsfs_jsonrpc_response * response)
struct jsonrpc_response * response)
{
wsfs_jsonrpc_response_init(response, buffer.c_str(), buffer.size());
jsonrpc_response_init(response, buffer.c_str(), buffer.size());
}
TEST(response_parser, test)
{
struct wsfs_jsonrpc_response response;
struct jsonrpc_response response;
// invalid json
wsfs_response_parse_str("", &response);
response_parse_str("", &response);
ASSERT_NE(WSFS_GOOD, response.status);
ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result);
// invalid json
wsfs_response_parse_str("invalid_json", &response);
response_parse_str("invalid_json", &response);
ASSERT_NE(WSFS_GOOD, response.status);
ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result);
// no object
wsfs_response_parse_str("[]", &response);
response_parse_str("[]", &response);
ASSERT_NE(WSFS_GOOD, response.status);
ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result);
// empty
wsfs_response_parse_str("{}", &response);
response_parse_str("{}", &response);
ASSERT_NE(WSFS_GOOD, response.status);
ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result);
// no data
wsfs_response_parse_str("{\"id\":42}", &response);
response_parse_str("{\"id\":42}", &response);
ASSERT_NE(WSFS_GOOD, response.status);
ASSERT_EQ(42, response.id);
ASSERT_EQ(nullptr, response.result);
// custom error code
wsfs_response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
ASSERT_NE(WSFS_GOOD, response.status);
ASSERT_EQ(42, response.status);
ASSERT_EQ(42, response.id);
ASSERT_EQ(nullptr, response.result);
// valid response
wsfs_response_parse_str("{\"result\": true, \"id\": 42}", &response);
response_parse_str("{\"result\": true, \"id\": 42}", &response);
ASSERT_EQ(WSFS_GOOD, response.status);
ASSERT_EQ(42, response.id);
ASSERT_NE(nullptr, response.result);

View File

@ -7,9 +7,9 @@ using wsfs_test::msleep;
TEST(timepoint, now)
{
wsfs_timepoint start = wsfs_timepoint_now();
timepoint start = timepoint_now();
msleep(42);
wsfs_timepoint end = wsfs_timepoint_now();
timepoint end = timepoint_now();
ASSERT_LT(start, end);
ASSERT_LT(end, start + 500);
@ -17,8 +17,8 @@ TEST(timepoint, now)
TEST(timepoint, in_msec)
{
wsfs_timepoint now = wsfs_timepoint_now();
wsfs_timepoint later = wsfs_timepoint_in_msec(42);
timepoint now = timepoint_now();
timepoint later = timepoint_in_msec(42);
ASSERT_LT(now, later);
ASSERT_LT(later, now + 500);
@ -26,11 +26,11 @@ TEST(timepoint, in_msec)
TEST(timepoint, elapsed)
{
wsfs_timepoint now;
timepoint now;
now = wsfs_timepoint_now();
ASSERT_TRUE(wsfs_timepoint_is_elapsed(now - 1));
now = timepoint_now();
ASSERT_TRUE(timepoint_is_elapsed(now - 1));
now = wsfs_timepoint_now();
ASSERT_FALSE(wsfs_timepoint_is_elapsed(now + 500));
now = timepoint_now();
ASSERT_FALSE(timepoint_is_elapsed(now + 500));
}

View File

@ -11,7 +11,7 @@ using wsfs_test::msleep;
namespace
{
void on_timeout(struct wsfs_timer * timer)
void on_timeout(struct timer * timer)
{
bool * triggered = reinterpret_cast<bool*>(timer->user_data);
*triggered = true;
@ -20,82 +20,82 @@ namespace
TEST(timer, init)
{
struct wsfs_timeout_manager manager;
struct wsfs_timer timer;
struct timeout_manager manager;
struct timer timer;
wsfs_timeout_manager_init(&manager);
wsfs_timer_init(&timer, &manager);
timeout_manager_init(&manager);
timer_init(&timer, &manager);
wsfs_timer_cleanup(&timer);
wsfs_timeout_manager_cleanup(&manager);
timer_cleanup(&timer);
timeout_manager_cleanup(&manager);
}
TEST(timer, trigger)
{
struct wsfs_timeout_manager manager;
struct wsfs_timer timer;
struct timeout_manager manager;
struct timer timer;
wsfs_timeout_manager_init(&manager);
wsfs_timer_init(&timer, &manager);
timeout_manager_init(&manager);
timer_init(&timer, &manager);
bool triggered = false;
wsfs_timer_start(&timer, wsfs_timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
timer_start(&timer, timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
msleep(500);
wsfs_timeout_manager_check(&manager);
timeout_manager_check(&manager);
ASSERT_TRUE(triggered);
wsfs_timer_cleanup(&timer);
wsfs_timeout_manager_cleanup(&manager);
timer_cleanup(&timer);
timeout_manager_cleanup(&manager);
}
TEST(timer, cancel)
{
struct wsfs_timeout_manager manager;
struct wsfs_timer timer;
struct timeout_manager manager;
struct timer timer;
wsfs_timeout_manager_init(&manager);
wsfs_timer_init(&timer, &manager);
timeout_manager_init(&manager);
timer_init(&timer, &manager);
bool triggered = false;
wsfs_timer_start(&timer, wsfs_timepoint_in_msec(250), &on_timeout, &triggered);
timer_start(&timer, timepoint_in_msec(250), &on_timeout, &triggered);
msleep(500);
wsfs_timer_cancel(&timer);
wsfs_timeout_manager_check(&manager);
timer_cancel(&timer);
timeout_manager_check(&manager);
ASSERT_FALSE(triggered);
wsfs_timer_cleanup(&timer);
wsfs_timeout_manager_cleanup(&manager);
timer_cleanup(&timer);
timeout_manager_cleanup(&manager);
}
TEST(timer, multiple_timers)
{
static size_t const count = 5;
struct wsfs_timeout_manager manager;
struct wsfs_timer timer[count];
struct timeout_manager manager;
struct timer timer[count];
bool triggered[count];
wsfs_timeout_manager_init(&manager);
timeout_manager_init(&manager);
for(size_t i = 0; i < count; i++)
{
wsfs_timer_init(&timer[i], &manager);
timer_init(&timer[i], &manager);
triggered[i] = false;
wsfs_timer_start(&timer[i], wsfs_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
timer_start(&timer[i], timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
}
for(size_t i = 0; i < count; i++)
{
msleep(100);
wsfs_timeout_manager_check(&manager);
timeout_manager_check(&manager);
}
for(size_t i = 0; i < count; i++)
{
ASSERT_TRUE(triggered[i]);
wsfs_timer_cleanup(&timer[i]);
timer_cleanup(&timer[i]);
}
wsfs_timeout_manager_cleanup(&manager);
timeout_manager_cleanup(&manager);
}