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

adds prefix to internal symbols

This commit is contained in:
Falk Werner 2019-03-24 18:02:28 +01:00
parent 6282c7625d
commit bd1032c494
54 changed files with 780 additions and 805 deletions

View File

@ -4,32 +4,31 @@
#include "wsfs/adapter/impl/server_protocol.h" #include "wsfs/adapter/impl/server_protocol.h"
#include "wsfs/adapter/impl/server_config.h" #include "wsfs/adapter/impl/server_config.h"
#include "wsfs/adapter/impl/credentials.h" #include "wsfs/adapter/impl/credentials.h"
#include "wsfs/adapter/impl/authenticate.h"
// server // server
struct wsfs_server * wsfs_server_create( struct wsfs_server * wsfs_server_create(
struct wsfs_server_config * config) struct wsfs_server_config * config)
{ {
return (struct wsfs_server *) server_create((struct server_config*) config); return wsfs_impl_server_create(config);
} }
void wsfs_server_dispose( void wsfs_server_dispose(
struct wsfs_server * server) struct wsfs_server * server)
{ {
server_dispose((struct server *) server); wsfs_impl_server_dispose(server);
} }
void wsfs_server_run( void wsfs_server_run(
struct wsfs_server * server) struct wsfs_server * server)
{ {
server_run((struct server *) server); wsfs_impl_server_run(server);
} }
void wsfs_server_shutdown( void wsfs_server_shutdown(
struct wsfs_server * server) struct wsfs_server * server)
{ {
server_shutdown((struct server *) server); wsfs_impl_server_shutdown(server);
} }
// server protocol // server protocol
@ -37,20 +36,20 @@ void wsfs_server_shutdown(
struct wsfs_server_protocol * wsfs_server_protocol_create( struct wsfs_server_protocol * wsfs_server_protocol_create(
char * mount_point) char * mount_point)
{ {
return (struct wsfs_server_protocol *) server_protocol_create(mount_point); return wsfs_impl_server_protocol_create(mount_point);
} }
void wsfs_server_protocol_dispose( void wsfs_server_protocol_dispose(
struct wsfs_server_protocol * protocol) struct wsfs_server_protocol * protocol)
{ {
server_protocol_dispose((struct server_protocol *) protocol); wsfs_impl_server_protocol_dispose(protocol);
} }
void wsfs_server_protocol_init_lws( void wsfs_server_protocol_init_lws(
struct wsfs_server_protocol * protocol, struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol) struct lws_protocols * lws_protocol)
{ {
server_protocol_init_lws((struct server_protocol *) protocol, lws_protocol); wsfs_impl_server_protocol_init_lws(protocol, lws_protocol);
} }
void wsfs_server_protocol_add_authenticator( void wsfs_server_protocol_add_authenticator(
@ -59,63 +58,62 @@ void wsfs_server_protocol_add_authenticator(
wsfs_authenticate_fn * authenticate, wsfs_authenticate_fn * authenticate,
void * user_data) void * user_data)
{ {
server_protocol_add_authenticator((struct server_protocol *) protocol, wsfs_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data);
type, (authenticate_fn*) authenticate, user_data);
} }
// server_config // server_config
struct wsfs_server_config * wsfs_server_config_create(void) struct wsfs_server_config * wsfs_server_config_create(void)
{ {
return (struct wsfs_server_config*) server_config_create(); return wsfs_impl_server_config_create();
} }
void wsfs_server_config_dispose( void wsfs_server_config_dispose(
struct wsfs_server_config * config) struct wsfs_server_config * config)
{ {
server_config_dispose((struct server_config*) config); wsfs_impl_server_config_dispose(config);
} }
void wsfs_server_config_set_mountpoint( void wsfs_server_config_set_mountpoint(
struct wsfs_server_config * config, struct wsfs_server_config * config,
char const * mount_point) char const * mount_point)
{ {
server_config_set_mountpoint((struct server_config*) config, mount_point); wsfs_impl_server_config_set_mountpoint(config, mount_point);
} }
void wsfs_server_config_set_documentroot( void wsfs_server_config_set_documentroot(
struct wsfs_server_config * config, struct wsfs_server_config * config,
char const * document_root) char const * document_root)
{ {
server_config_set_documentroot((struct server_config*) config, document_root); wsfs_impl_server_config_set_documentroot(config, document_root);
} }
void wsfs_server_config_set_keypath( void wsfs_server_config_set_keypath(
struct wsfs_server_config * config, struct wsfs_server_config * config,
char const * key_path) char const * key_path)
{ {
server_config_set_keypath((struct server_config*) config, key_path); wsfs_impl_server_config_set_keypath(config, key_path);
} }
void wsfs_server_config_set_certpath( void wsfs_server_config_set_certpath(
struct wsfs_server_config * config, struct wsfs_server_config * config,
char const * cert_path) char const * cert_path)
{ {
server_config_set_certpath((struct server_config*) config, cert_path); wsfs_impl_server_config_set_certpath(config, cert_path);
} }
void wsfs_server_config_set_vhostname( void wsfs_server_config_set_vhostname(
struct wsfs_server_config * config, struct wsfs_server_config * config,
char const * vhost_name) char const * vhost_name)
{ {
server_config_set_vhostname((struct server_config*) config, vhost_name); wsfs_impl_server_config_set_vhostname(config, vhost_name);
} }
void wsfs_server_config_set_port( void wsfs_server_config_set_port(
struct wsfs_server_config * config, struct wsfs_server_config * config,
int port) int port)
{ {
server_config_set_port((struct server_config*) config, port); wsfs_impl_server_config_set_port(config, port);
} }
void wsfs_server_config_add_authenticator( void wsfs_server_config_add_authenticator(
@ -124,7 +122,7 @@ void wsfs_server_config_add_authenticator(
wsfs_authenticate_fn * authenticate, wsfs_authenticate_fn * authenticate,
void * user_data) void * user_data)
{ {
server_config_add_authenticator((struct server_config*) config, type, (authenticate_fn*) authenticate, user_data); wsfs_impl_server_config_add_authenticator(config, type, authenticate, user_data);
} }
// credentials // credentials
@ -132,12 +130,12 @@ void wsfs_server_config_add_authenticator(
char const * wsfs_credentials_type( char const * wsfs_credentials_type(
struct wsfs_credentials const * credentials) struct wsfs_credentials const * credentials)
{ {
return credentials_type((struct credentials *) credentials); return wsfs_impl_credentials_type(credentials);
} }
char const * wsfs_credentials_get( char const * wsfs_credentials_get(
struct wsfs_credentials const * credentials, struct wsfs_credentials const * credentials,
char const * key) char const * key)
{ {
return credentials_get((struct credentials *) credentials, key); return wsfs_impl_credentials_get(credentials, key);
} }

View File

@ -1,23 +0,0 @@
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATE_H
#define WSFS_ADAPTER_IMPL_AUTHENTICATE_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct credentials;
typedef bool authenticate_fn(
struct credentials * credentials,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

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

View File

@ -5,34 +5,34 @@
#include <stdbool.h> #include <stdbool.h>
#endif #endif
#include "wsfs/adapter/impl/authenticate.h" #include "wsfs/adapter/authenticate.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct credentials; struct wsfs_credentials;
struct authenticator struct wsfs_impl_authenticator
{ {
char * type; char * type;
authenticate_fn * authenticate; wsfs_authenticate_fn * authenticate;
void * user_data; void * user_data;
struct authenticator * next; struct wsfs_impl_authenticator * next;
}; };
extern struct authenticator * authenticator_create( extern struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
char const * type, char const * type,
authenticate_fn * authenticate, wsfs_authenticate_fn * authenticate,
void * user_data); void * user_data);
extern void authenticator_dispose( extern void wsfs_impl_authenticator_dispose(
struct authenticator * authenticator); struct wsfs_impl_authenticator * authenticator);
extern bool authenticator_autenticate( extern bool wsfs_impl_authenticator_autenticate(
struct authenticator * authenticator, struct wsfs_impl_authenticator * authenticator,
struct credentials * credentials); struct wsfs_credentials * credentials);

View File

@ -5,16 +5,16 @@
#include "wsfs/adapter/impl/authenticator.h" #include "wsfs/adapter/impl/authenticator.h"
#include "wsfs/adapter/impl/credentials.h" #include "wsfs/adapter/impl/credentials.h"
static struct authenticator * authenticators_find( static struct wsfs_impl_authenticator * wsfs_impl_authenticators_find(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
char const * type) char const * type)
{ {
struct authenticator * result = NULL; struct wsfs_impl_authenticator * result = NULL;
struct authenticator * actual = authenticators->first; struct wsfs_impl_authenticator * actual = authenticators->first;
while ((NULL == result) && (NULL != actual)) while ((NULL == result) && (NULL != actual))
{ {
struct authenticator * next = actual->next; struct wsfs_impl_authenticator * next = actual->next;
if (0 == strcmp(type, actual->type)) if (0 == strcmp(type, actual->type))
{ {
result = actual; result = actual;
@ -26,74 +26,74 @@ static struct authenticator * authenticators_find(
return result; return result;
} }
void authenticators_init( void wsfs_impl_authenticators_init(
struct authenticators * authenticators) struct wsfs_impl_authenticators * authenticators)
{ {
authenticators->first = NULL; authenticators->first = NULL;
} }
void authenticators_cleanup( void wsfs_impl_authenticators_cleanup(
struct authenticators * authenticators) struct wsfs_impl_authenticators * authenticators)
{ {
struct authenticator * actual = authenticators->first; struct wsfs_impl_authenticator * actual = authenticators->first;
while (NULL != actual) while (NULL != actual)
{ {
struct authenticator * next = actual->next; struct wsfs_impl_authenticator * next = actual->next;
authenticator_dispose(actual); wsfs_impl_authenticator_dispose(actual);
actual = next; actual = next;
} }
authenticators->first = NULL; authenticators->first = NULL;
} }
void authenticators_clone( void wsfs_impl_authenticators_clone(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct authenticators * other) struct wsfs_impl_authenticators * other)
{ {
authenticators_init(other); wsfs_impl_authenticators_init(other);
struct authenticator * actual = authenticators->first; struct wsfs_impl_authenticator * actual = authenticators->first;
while (NULL != actual) while (NULL != actual)
{ {
struct authenticator * next = actual->next; struct wsfs_impl_authenticator * next = actual->next;
authenticators_add(other, wsfs_impl_authenticators_add(other,
actual->type, actual->authenticate, actual->user_data); actual->type, actual->authenticate, actual->user_data);
actual = next; actual = next;
} }
} }
extern void authenticators_move( extern void wsfs_impl_authenticators_move(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct authenticators * other) struct wsfs_impl_authenticators * other)
{ {
other->first = authenticators->first; other->first = authenticators->first;
authenticators->first = NULL; authenticators->first = NULL;
} }
void authenticators_add( void wsfs_impl_authenticators_add(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
char const * type, char const * type,
authenticate_fn * authenticate, wsfs_authenticate_fn * authenticate,
void * user_data) void * user_data)
{ {
struct authenticator * authenticator = authenticator_create(type, authenticate, user_data); struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(type, authenticate, user_data);
authenticator->next = authenticators->first; authenticator->next = authenticators->first;
authenticators->first = authenticator; authenticators->first = authenticator;
} }
bool authenticators_authenticate( bool wsfs_impl_authenticators_authenticate(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct credentials * credentials) struct wsfs_credentials * credentials)
{ {
bool result = (NULL == authenticators->first); bool result = (NULL == authenticators->first);
if (NULL != credentials) if (NULL != credentials)
{ {
struct authenticator * authenticator = authenticators_find(authenticators, credentials->type); struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticators_find(authenticators, credentials->type);
if (NULL != authenticator) if (NULL != authenticator)
{ {
result = authenticator_autenticate(authenticator, credentials); result = wsfs_impl_authenticator_autenticate(authenticator, credentials);
} }
} }

View File

@ -5,44 +5,44 @@
#include <stdbool.h> #include <stdbool.h>
#endif #endif
#include "wsfs/adapter/impl/authenticate.h" #include "wsfs/adapter/authenticate.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct authenticator; struct wsfs_impl_authenticator;
struct credentials; struct wsfs_credentials;
struct authenticators struct wsfs_impl_authenticators
{ {
struct authenticator * first; struct wsfs_impl_authenticator * first;
}; };
extern void authenticators_init( extern void wsfs_impl_authenticators_init(
struct authenticators * authenticators); struct wsfs_impl_authenticators * authenticators);
extern void authenticators_cleanup( extern void wsfs_impl_authenticators_cleanup(
struct authenticators * authenticators); struct wsfs_impl_authenticators * authenticators);
extern void authenticators_clone( extern void wsfs_impl_authenticators_clone(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct authenticators * other); struct wsfs_impl_authenticators * other);
extern void authenticators_move( extern void wsfs_impl_authenticators_move(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct authenticators * other); struct wsfs_impl_authenticators * other);
extern void authenticators_add( extern void wsfs_impl_authenticators_add(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
char const * type, char const * type,
authenticate_fn * authenticate, wsfs_authenticate_fn * authenticate,
void * user_data); void * user_data);
extern bool authenticators_authenticate( extern bool wsfs_impl_authenticators_authenticate(
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct credentials * credentials); struct wsfs_credentials * credentials);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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

View File

@ -8,25 +8,25 @@ extern "C"
{ {
#endif #endif
struct credentials struct wsfs_credentials
{ {
char * type; char * type;
json_t * data; json_t * data;
}; };
extern void credentials_init( extern void wsfs_impl_credentials_init(
struct credentials * credentials, struct wsfs_credentials * credentials,
char const * type, char const * type,
json_t * data); json_t * data);
extern void credentials_cleanup( extern void wsfs_impl_credentials_cleanup(
struct credentials * credentials); struct wsfs_credentials * credentials);
extern char const * credentials_type( extern char const * wsfs_impl_credentials_type(
struct credentials const * credentials); struct wsfs_credentials const * credentials);
extern char const * credentials_get( extern char const * wsfs_impl_credentials_get(
struct credentials const * credentials, struct wsfs_credentials const * credentials,
char const * key); char const * key);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -8,18 +8,18 @@
static struct fuse_lowlevel_ops const filesystem_operations = static struct fuse_lowlevel_ops const filesystem_operations =
{ {
.lookup = &operation_lookup, .lookup = &wsfs_impl_operation_lookup,
.getattr = &operation_getattr, .getattr = &wsfs_impl_operation_getattr,
.readdir = &operation_readdir, .readdir = &wsfs_impl_operation_readdir,
.open = &operation_open, .open = &wsfs_impl_operation_open,
.release = &operation_close, .release = &wsfs_impl_operation_close,
.read = &operation_read .read = &wsfs_impl_operation_read
}; };
bool filesystem_init( bool wsfs_impl_filesystem_init(
struct filesystem * filesystem, struct wsfs_impl_filesystem * filesystem,
struct jsonrpc_server * rpc, struct wsfs_impl_jsonrpc_server * rpc,
char * mount_point) char * mount_point)
{ {
bool result = false; bool result = false;
@ -46,8 +46,8 @@ bool filesystem_init(
return result; return result;
} }
void filesystem_cleanup( void wsfs_impl_filesystem_cleanup(
struct filesystem * filesystem) struct wsfs_impl_filesystem * filesystem)
{ {
if (NULL != filesystem->session) if (NULL != filesystem->session)
{ {
@ -61,14 +61,14 @@ void filesystem_cleanup(
fuse_opt_free_args(&filesystem->args); fuse_opt_free_args(&filesystem->args);
} }
int filesystem_get_fd( int wsfs_impl_filesystem_get_fd(
struct filesystem * filesystem) struct wsfs_impl_filesystem * filesystem)
{ {
return fuse_session_fd(filesystem->session); return fuse_session_fd(filesystem->session);
} }
void filesystem_process_request( void wsfs_impl_filesystem_process_request(
struct filesystem * filesystem) struct wsfs_impl_filesystem * filesystem)
{ {
int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer); int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer);
if (0 < result) if (0 < result)

View File

@ -13,29 +13,29 @@ extern "C"
{ {
#endif #endif
struct jsonrpc_server; struct wsfs_impl_jsonrpc_server;
struct filesystem struct wsfs_impl_filesystem
{ {
struct fuse_args args; struct fuse_args args;
struct fuse_session * session; struct fuse_session * session;
struct fuse_buf buffer; struct fuse_buf buffer;
struct operations_context user_data; struct wsfs_impl_operations_context user_data;
}; };
extern bool filesystem_init( extern bool wsfs_impl_filesystem_init(
struct filesystem * filesystem, struct wsfs_impl_filesystem * filesystem,
struct jsonrpc_server * rpc, struct wsfs_impl_jsonrpc_server * rpc,
char * mount_point); char * mount_point);
extern void filesystem_cleanup( extern void wsfs_impl_filesystem_cleanup(
struct filesystem * filesystem); struct wsfs_impl_filesystem * filesystem);
extern int filesystem_get_fd( extern int wsfs_impl_filesystem_get_fd(
struct filesystem * filesystem); struct wsfs_impl_filesystem * filesystem);
extern void filesystem_process_request( extern void wsfs_impl_filesystem_process_request(
struct filesystem * filesystem); struct wsfs_impl_filesystem * filesystem);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,11 +7,11 @@
#define WSFS_DEFAULT_TIMEOUT (10 * 1000) #define WSFS_DEFAULT_TIMEOUT (10 * 1000)
static struct jsonrpc_method const * jsonrpc_server_getmethod( static struct wsfs_impl_jsonrpc_method const * wsfs_impl_jsonrpc_server_getmethod(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
char const * name) char const * name)
{ {
struct jsonrpc_method * method = server->methods; struct wsfs_impl_jsonrpc_method * method = server->methods;
while ((NULL != method) && (0 == strcmp(name, method->name))) while ((NULL != method) && (0 == strcmp(name, method->name)))
{ {
method = method->next; method = method->next;
@ -20,40 +20,40 @@ static struct jsonrpc_method const * jsonrpc_server_getmethod(
return method; return method;
} }
static void jsonrpc_server_timeout( static void wsfs_impl_jsonrpc_server_timeout(
struct timer * timer) struct wsfs_impl_timer * timer)
{ {
struct jsonrpc_server * server = timer->user_data; struct wsfs_impl_jsonrpc_server * server = timer->user_data;
if (server->request.is_pending) if (server->request.is_pending)
{ {
jsonrpc_method_finished_fn * finished = server->request.finished; wsfs_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
void * user_data = server->request.user_data; void * user_data = server->request.user_data;
server->request.is_pending = false; server->request.is_pending = false;
server->request.id = 0; server->request.id = 0;
server->request.user_data = NULL; server->request.user_data = NULL;
server->request.finished = NULL; server->request.finished = NULL;
timer_cancel(&server->request.timer); wsfs_impl_timer_cancel(&server->request.timer);
finished(user_data, WSFS_BAD_TIMEOUT, NULL); finished(user_data, WSFS_BAD_TIMEOUT, NULL);
} }
} }
void jsonrpc_server_init( void wsfs_impl_jsonrpc_server_init(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
struct timeout_manager * timeout_manager) struct wsfs_impl_timeout_manager * timeout_manager)
{ {
server->methods = NULL; server->methods = NULL;
server->request.is_pending = false; server->request.is_pending = false;
timer_init(&server->request.timer, timeout_manager); wsfs_impl_timer_init(&server->request.timer, timeout_manager);
} }
void jsonrpc_server_cleanup( void wsfs_impl_jsonrpc_server_cleanup(
struct jsonrpc_server * server) struct wsfs_impl_jsonrpc_server * server)
{ {
timer_cleanup(&server->request.timer); wsfs_impl_timer_cleanup(&server->request.timer);
if (server->request.is_pending) if (server->request.is_pending)
{ {
@ -61,31 +61,31 @@ void jsonrpc_server_cleanup(
server->request.is_pending = false; server->request.is_pending = false;
} }
struct jsonrpc_method * method = server->methods; struct wsfs_impl_jsonrpc_method * method = server->methods;
while (NULL != method) while (NULL != method)
{ {
struct jsonrpc_method * next = method->next; struct wsfs_impl_jsonrpc_method * next = method->next;
method->next = NULL; method->next = NULL;
jsonrpc_method_dispose(method); wsfs_impl_jsonrpc_method_dispose(method);
method = next; method = next;
} }
server->methods = NULL; server->methods = NULL;
} }
void jsonrpc_server_add( void wsfs_impl_jsonrpc_server_add(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
char const * name, char const * name,
jsonrpc_method_invoke_fn * invoke, wsfs_impl_jsonrpc_method_invoke_fn * invoke,
void * user_data) void * user_data)
{ {
struct jsonrpc_method * method = jsonrpc_method_create(name, invoke, user_data); struct wsfs_impl_jsonrpc_method * method = wsfs_impl_jsonrpc_method_create(name, invoke, user_data);
method->next = server->methods; method->next = server->methods;
server->methods = method; server->methods = method;
} }
void jsonrpc_server_invoke( void wsfs_impl_jsonrpc_server_invoke(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
jsonrpc_method_finished_fn * finished, wsfs_impl_jsonrpc_method_finished_fn * finished,
void * user_data, void * user_data,
char const * method_name, char const * method_name,
char const * param_info, char const * param_info,
@ -94,19 +94,19 @@ void jsonrpc_server_invoke(
{ {
if (!server->request.is_pending) if (!server->request.is_pending)
{ {
struct jsonrpc_method const * method = jsonrpc_server_getmethod(server, method_name); struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name);
if (NULL != method) if (NULL != method)
{ {
server->request.is_pending = true; server->request.is_pending = true;
server->request.finished = finished; server->request.finished = finished;
server->request.user_data = user_data; server->request.user_data = user_data;
server->request.id = 42; server->request.id = 42;
timer_start(&server->request.timer, timepoint_in_msec(WSFS_DEFAULT_TIMEOUT), wsfs_impl_timer_start(&server->request.timer, wsfs_impl_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT),
&jsonrpc_server_timeout, server); &wsfs_impl_jsonrpc_server_timeout, server);
va_list args; va_list args;
va_start(args, param_info); va_start(args, param_info);
json_t * request = jsonrpc_request_create(method_name, server->request.id, param_info, args); json_t * request = wsfs_impl_jsonrpc_request_create(method_name, server->request.id, param_info, args);
va_end(args); va_end(args);
if (NULL != request) if (NULL != request)
{ {
@ -116,7 +116,7 @@ void jsonrpc_server_invoke(
server->request.finished = NULL; server->request.finished = NULL;
server->request.user_data = NULL; server->request.user_data = NULL;
server->request.id = 0; server->request.id = 0;
timer_cancel(&server->request.timer); wsfs_impl_timer_cancel(&server->request.timer);
finished(user_data, WSFS_BAD, NULL); finished(user_data, WSFS_BAD, NULL);
} }
@ -134,20 +134,20 @@ void jsonrpc_server_invoke(
} }
} }
extern void jsonrpc_server_notify( extern void wsfs_impl_jsonrpc_server_notify(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
char const * method_name, char const * method_name,
char const * param_info, char const * param_info,
... ...
) )
{ {
struct jsonrpc_method const * method = jsonrpc_server_getmethod(server, method_name); struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name);
if (NULL != method) if (NULL != method)
{ {
va_list args; va_list args;
va_start(args, param_info); va_start(args, param_info);
json_t * request = jsonrpc_request_create(method_name, 0, param_info, args); json_t * request = wsfs_impl_jsonrpc_request_create(method_name, 0, param_info, args);
va_end(args); va_end(args);
if (NULL != request) if (NULL != request)
{ {
@ -159,28 +159,28 @@ extern void jsonrpc_server_notify(
} }
void jsonrpc_server_onresult( void wsfs_impl_jsonrpc_server_onresult(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
char const * message, char const * message,
size_t length) size_t length)
{ {
struct jsonrpc_response response; struct wsfs_impl_jsonrpc_response response;
jsonrpc_response_init(&response, message, length); wsfs_impl_jsonrpc_response_init(&response, message, length);
if ((server->request.is_pending) && (response.id == server->request.id)) if ((server->request.is_pending) && (response.id == server->request.id))
{ {
jsonrpc_method_finished_fn * finished = server->request.finished; wsfs_impl_jsonrpc_method_finished_fn * finished = server->request.finished;
void * user_data = server->request.user_data; void * user_data = server->request.user_data;
server->request.is_pending = false; server->request.is_pending = false;
server->request.id = 0; server->request.id = 0;
server->request.user_data = NULL; server->request.user_data = NULL;
server->request.finished = NULL; server->request.finished = NULL;
timer_cancel(&server->request.timer); wsfs_impl_timer_cancel(&server->request.timer);
finished(user_data, response.status, response.result); finished(user_data, response.status, response.result);
} }
jsonrpc_response_cleanup(&response); wsfs_impl_jsonrpc_response_cleanup(&response);
} }

View File

@ -20,52 +20,52 @@ using std::size_t;
extern "C" { extern "C" {
#endif #endif
struct jsonrpc_request struct wsfs_impl_jsonrpc_request
{ {
bool is_pending; bool is_pending;
jsonrpc_method_finished_fn * finished; wsfs_impl_jsonrpc_method_finished_fn * finished;
void * user_data; void * user_data;
int id; int id;
struct timer timer; struct wsfs_impl_timer timer;
}; };
struct jsonrpc_server struct wsfs_impl_jsonrpc_server
{ {
struct jsonrpc_method * methods; struct wsfs_impl_jsonrpc_method * methods;
struct jsonrpc_request request; struct wsfs_impl_jsonrpc_request request;
}; };
extern void jsonrpc_server_init( extern void wsfs_impl_jsonrpc_server_init(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
struct timeout_manager * manager); struct wsfs_impl_timeout_manager * manager);
extern void jsonrpc_server_cleanup( extern void wsfs_impl_jsonrpc_server_cleanup(
struct jsonrpc_server * server); struct wsfs_impl_jsonrpc_server * server);
extern void jsonrpc_server_add( extern void wsfs_impl_jsonrpc_server_add(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
char const * name, char const * name,
jsonrpc_method_invoke_fn * invoke, wsfs_impl_jsonrpc_method_invoke_fn * invoke,
void * user_data ); void * user_data );
extern void jsonrpc_server_invoke( extern void wsfs_impl_jsonrpc_server_invoke(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
jsonrpc_method_finished_fn * finished, wsfs_impl_jsonrpc_method_finished_fn * finished,
void * user_data, void * user_data,
char const * method_name, char const * method_name,
char const * param_info, char const * param_info,
... ...
); );
extern void jsonrpc_server_notify( extern void wsfs_impl_jsonrpc_server_notify(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
char const * method_name, char const * method_name,
char const * param_info, char const * param_info,
... ...
); );
extern void jsonrpc_server_onresult( extern void wsfs_impl_jsonrpc_server_onresult(
struct jsonrpc_server * server, struct wsfs_impl_jsonrpc_server * server,
char const * message, char const * message,
size_t length); size_t length);

View File

@ -1,6 +1,6 @@
#include "wsfs/adapter/impl/jsonrpc/util.h" #include "wsfs/adapter/impl/jsonrpc/util.h"
int 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; int result = default_value;

View File

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

View File

@ -7,15 +7,15 @@
#include "wsfs/adapter/impl/jsonrpc/server.h" #include "wsfs/adapter/impl/jsonrpc/server.h"
#include "wsfs/util.h" #include "wsfs/util.h"
void operation_close( void wsfs_impl_operation_close(
fuse_req_t request, fuse_req_t request,
fuse_ino_t inode, fuse_ino_t inode,
struct fuse_file_info * file_info) struct fuse_file_info * file_info)
{ {
struct operations_context * user_data = fuse_req_userdata(request); struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct jsonrpc_server * rpc = user_data->rpc; struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
int handle = (int) (file_info->fh & INT_MAX); int handle = (int) (file_info->fh & INT_MAX);
jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags); wsfs_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
fuse_reply_err(request, 0); fuse_reply_err(request, 0);
} }

View File

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

View File

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

View File

@ -8,7 +8,7 @@
#include "wsfs/util.h" #include "wsfs/util.h"
#include "wsfs/status.h" #include "wsfs/status.h"
static void operation_open_finished( static void wsfs_impl_operation_open_finished(
void * user_data, void * user_data,
wsfs_status status, wsfs_status status,
json_t const * result) json_t const * result)
@ -41,13 +41,13 @@ static void operation_open_finished(
} }
void operation_open( void wsfs_impl_operation_open(
fuse_req_t request, fuse_req_t request,
fuse_ino_t inode, fuse_ino_t inode,
struct fuse_file_info * file_info) struct fuse_file_info * file_info)
{ {
struct operations_context * user_data = fuse_req_userdata(request); struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct jsonrpc_server * rpc = user_data->rpc; struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
jsonrpc_server_invoke(rpc, &operation_open_finished, request, "open", "ii", inode, file_info->flags); wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags);
} }

View File

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

View File

@ -14,37 +14,37 @@
#define WSFS_DIRBUFFER_INITIAL_SIZE 1024 #define WSFS_DIRBUFFER_INITIAL_SIZE 1024
struct operation_readdir_context struct wsfs_impl_operation_readdir_context
{ {
fuse_req_t request; fuse_req_t request;
size_t size; size_t size;
off_t offset; off_t offset;
}; };
struct dirbuffer struct wsfs_impl_dirbuffer
{ {
char * data; char * data;
size_t position; size_t position;
size_t capacity; size_t capacity;
}; };
static void dirbuffer_init( static void wsfs_impl_dirbuffer_init(
struct dirbuffer * buffer) struct wsfs_impl_dirbuffer * buffer)
{ {
buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE); buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE);
buffer->position = 0; buffer->position = 0;
buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE; buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE;
} }
static void dirbuffer_dispose( static void wsfs_impl_dirbuffer_dispose(
struct dirbuffer * buffer) struct wsfs_impl_dirbuffer * buffer)
{ {
free(buffer->data); free(buffer->data);
} }
static void dirbuffer_add( static void wsfs_impl_dirbuffer_add(
fuse_req_t request, fuse_req_t request,
struct dirbuffer * buffer, struct wsfs_impl_dirbuffer * buffer,
char const * name, char const * name,
fuse_ino_t inode) fuse_ino_t inode)
{ {
@ -66,20 +66,20 @@ static void dirbuffer_add(
buffer->position += size; buffer->position += size;
} }
static size_t min(size_t a, size_t b) static size_t wsfs_impl_min(size_t a, size_t b)
{ {
return (a < b) ? a : b; return (a < b) ? a : b;
} }
static void operation_readdir_finished( static void wsfs_impl_operation_readdir_finished(
void * user_data, void * user_data,
wsfs_status status, wsfs_status status,
json_t const * result) json_t const * result)
{ {
struct operation_readdir_context * context = user_data; struct wsfs_impl_operation_readdir_context * context = user_data;
struct dirbuffer buffer; struct wsfs_impl_dirbuffer buffer;
dirbuffer_init(&buffer); wsfs_impl_dirbuffer_init(&buffer);
if (NULL != result) if (NULL != result)
{ {
@ -100,7 +100,7 @@ static void operation_readdir_finished(
{ {
char const * name = json_string_value(name_holder); char const * name = json_string_value(name_holder);
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder); fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
dirbuffer_add(context->request, &buffer, name, entry_inode); wsfs_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
} }
} }
} }
@ -112,7 +112,7 @@ static void operation_readdir_finished(
if (((size_t) context->offset) < buffer.position) if (((size_t) context->offset) < buffer.position)
{ {
fuse_reply_buf(context->request, &buffer.data[context->offset], fuse_reply_buf(context->request, &buffer.data[context->offset],
min(buffer.position - context->offset, context->size)); wsfs_impl_min(buffer.position - context->offset, context->size));
} }
else else
{ {
@ -125,23 +125,23 @@ static void operation_readdir_finished(
fuse_reply_err(context->request, ENOENT); fuse_reply_err(context->request, ENOENT);
} }
dirbuffer_dispose(&buffer); wsfs_impl_dirbuffer_dispose(&buffer);
free(context); free(context);
} }
void operation_readdir ( void wsfs_impl_operation_readdir (
fuse_req_t request, fuse_req_t request,
fuse_ino_t inode, fuse_ino_t inode,
size_t size, size_t size,
off_t offset, off_t offset,
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info)) struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{ {
struct operations_context * user_data = fuse_req_userdata(request); struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
struct jsonrpc_server * rpc = user_data->rpc; struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
struct operation_readdir_context * readdir_context = malloc(sizeof(struct operation_readdir_context)); struct wsfs_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_impl_operation_readdir_context));
readdir_context->request = request; readdir_context->request = request;
readdir_context->size = size; readdir_context->size = size;
readdir_context->offset = offset; readdir_context->offset = offset;
jsonrpc_server_invoke(rpc, &operation_readdir_finished, readdir_context, "readdir", "i", inode); wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode);
} }

View File

@ -7,42 +7,42 @@
extern "C" { extern "C" {
#endif #endif
struct jsonrpc_server; struct wsfs_impl_jsonrpc_server;
struct operations_context struct wsfs_impl_operations_context
{ {
struct jsonrpc_server * rpc; struct wsfs_impl_jsonrpc_server * rpc;
double timeout; double timeout;
}; };
extern void operation_lookup ( extern void wsfs_impl_operation_lookup (
fuse_req_t req, fuse_req_t req,
fuse_ino_t parent, fuse_ino_t parent,
char const * name); char const * name);
extern void operation_getattr ( extern void wsfs_impl_operation_getattr (
fuse_req_t request, fuse_req_t request,
fuse_ino_t inode, fuse_ino_t inode,
struct fuse_file_info *file_info); struct fuse_file_info *file_info);
extern void operation_readdir ( extern void wsfs_impl_operation_readdir (
fuse_req_t request, fuse_req_t request,
fuse_ino_t inode, fuse_ino_t inode,
size_t size, size_t size,
off_t offset, off_t offset,
struct fuse_file_info *file_info); struct fuse_file_info *file_info);
extern void operation_open( extern void wsfs_impl_operation_open(
fuse_req_t request, fuse_req_t request,
fuse_ino_t inode, fuse_ino_t inode,
struct fuse_file_info * file_info); struct fuse_file_info * file_info);
extern void operation_close( extern void wsfs_impl_operation_close(
fuse_req_t request, fuse_req_t request,
fuse_ino_t inode, fuse_ino_t inode,
struct fuse_file_info * file_info); struct fuse_file_info * file_info);
extern void operation_read( extern void wsfs_impl_operation_read(
fuse_req_t request, fuse_req_t request,
fuse_ino_t ino, size_t size, off_t off, fuse_ino_t ino, size_t size, off_t off,
struct fuse_file_info *fi); struct fuse_file_info *fi);

View File

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

View File

@ -6,20 +6,20 @@ extern "C"
{ {
#endif #endif
struct server; struct wsfs_server;
struct server_config; struct wsfs_server_config;
extern struct server * server_create( extern struct wsfs_server * wsfs_impl_server_create(
struct server_config * config); struct wsfs_server_config * config);
extern void server_dispose( extern void wsfs_impl_server_dispose(
struct server * server); struct wsfs_server * server);
extern void server_run( extern void wsfs_impl_server_run(
struct server * server); struct wsfs_server * server);
extern void server_shutdown( extern void wsfs_impl_server_shutdown(
struct server * server); struct wsfs_server * server);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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

View File

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

View File

@ -8,7 +8,7 @@
#include "wsfs/adapter/impl/filesystem.h" #include "wsfs/adapter/impl/filesystem.h"
static int server_protocol_callback( static int wsfs_impl_server_protocol_callback(
struct lws * wsi, struct lws * wsi,
enum lws_callback_reasons reason, enum lws_callback_reasons reason,
void * WSFS_UNUSED_PARAM(user), void * WSFS_UNUSED_PARAM(user),
@ -16,17 +16,17 @@ static int server_protocol_callback(
size_t len) size_t len)
{ {
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
struct server_protocol * protocol = ws_protocol->user; struct wsfs_server_protocol * protocol = ws_protocol->user;
timeout_manager_check(&protocol->timeout_manager); wsfs_impl_timeout_manager_check(&protocol->timeout_manager);
struct session * session = session_manager_get(&protocol->session_manager, wsi); struct wsfs_impl_session * session = wsfs_impl_session_manager_get(&protocol->session_manager, wsi);
switch (reason) switch (reason)
{ {
case LWS_CALLBACK_PROTOCOL_INIT: case LWS_CALLBACK_PROTOCOL_INIT:
{ {
lws_sock_file_fd_type fd; lws_sock_file_fd_type fd;
fd.filefd = filesystem_get_fd(&protocol->filesystem); 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)) 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"); fprintf(stderr, "error: unable to adopt fd");
@ -34,7 +34,7 @@ static int server_protocol_callback(
} }
break; break;
case LWS_CALLBACK_ESTABLISHED: case LWS_CALLBACK_ESTABLISHED:
session = session_manager_add( session = wsfs_impl_session_manager_add(
&protocol->session_manager, &protocol->session_manager,
wsi, wsi,
&protocol->authenticators, &protocol->authenticators,
@ -42,26 +42,26 @@ static int server_protocol_callback(
if (NULL != session) if (NULL != session)
{ {
session_authenticate(session, NULL); wsfs_impl_session_authenticate(session, NULL);
} }
break; break;
case LWS_CALLBACK_CLOSED: case LWS_CALLBACK_CLOSED:
session_manager_remove(&protocol->session_manager, wsi); wsfs_impl_session_manager_remove(&protocol->session_manager, wsi);
break; break;
case LWS_CALLBACK_SERVER_WRITEABLE: case LWS_CALLBACK_SERVER_WRITEABLE:
if (NULL != session) if (NULL != session)
{ {
session_onwritable(session); wsfs_impl_session_onwritable(session);
} }
break; break;
case LWS_CALLBACK_RECEIVE: case LWS_CALLBACK_RECEIVE:
if (NULL != session) if (NULL != session)
{ {
session_receive(session, in, len); wsfs_impl_session_receive(session, in, len);
} }
break; break;
case LWS_CALLBACK_RAW_RX_FILE: case LWS_CALLBACK_RAW_RX_FILE:
filesystem_process_request(&protocol->filesystem); wsfs_impl_filesystem_process_request(&protocol->filesystem);
break; break;
default: default:
break; break;
@ -70,27 +70,27 @@ static int server_protocol_callback(
return 0; return 0;
} }
static bool server_protocol_invoke( static bool wsfs_impl_server_protocol_invoke(
void * user_data, void * user_data,
json_t const * request) json_t const * request)
{ {
struct server_protocol * protocol = user_data; struct wsfs_server_protocol * protocol = user_data;
struct session * session = &protocol->session_manager.session; struct wsfs_impl_session * session = &protocol->session_manager.session;
struct wsfs_message * message = wsfs_message_create(request); struct wsfs_message * message = wsfs_message_create(request);
bool const result = session_send(session, message); bool const result = wsfs_impl_session_send(session, message);
return result; return result;
} }
struct server_protocol * server_protocol_create( struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
char * mount_point) char * mount_point)
{ {
struct server_protocol * protocol = malloc(sizeof(struct server_protocol)); struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol));
if (NULL != protocol) if (NULL != protocol)
{ {
if (!server_protocol_init(protocol, mount_point)) if (!wsfs_impl_server_protocol_init(protocol, mount_point))
{ {
free(protocol); free(protocol);
protocol = NULL; protocol = NULL;
@ -100,67 +100,67 @@ struct server_protocol * server_protocol_create(
return protocol; return protocol;
} }
void server_protocol_dispose( void wsfs_impl_server_protocol_dispose(
struct server_protocol * protocol) struct wsfs_server_protocol * protocol)
{ {
server_protocol_cleanup(protocol); wsfs_impl_server_protocol_cleanup(protocol);
free(protocol); free(protocol);
} }
void server_protocol_init_lws( void wsfs_impl_server_protocol_init_lws(
struct server_protocol * protocol, struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol) struct lws_protocols * lws_protocol)
{ {
lws_protocol->callback = &server_protocol_callback; lws_protocol->callback = &wsfs_impl_server_protocol_callback;
lws_protocol->per_session_data_size = 0; lws_protocol->per_session_data_size = 0;
lws_protocol->user = protocol; lws_protocol->user = protocol;
} }
bool server_protocol_init( bool wsfs_impl_server_protocol_init(
struct server_protocol * protocol, struct wsfs_server_protocol * protocol,
char * mount_point) char * mount_point)
{ {
timeout_manager_init(&protocol->timeout_manager); wsfs_impl_timeout_manager_init(&protocol->timeout_manager);
session_manager_init(&protocol->session_manager); wsfs_impl_session_manager_init(&protocol->session_manager);
authenticators_init(&protocol->authenticators); wsfs_impl_authenticators_init(&protocol->authenticators);
jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager); wsfs_impl_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
jsonrpc_server_add(&protocol->rpc, "lookup", &server_protocol_invoke, protocol); wsfs_impl_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_impl_server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "getattr", &server_protocol_invoke, protocol); wsfs_impl_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_impl_server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "readdir", &server_protocol_invoke, protocol); wsfs_impl_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_impl_server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "open", &server_protocol_invoke, protocol); wsfs_impl_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_impl_server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "close", &server_protocol_invoke, protocol); wsfs_impl_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_impl_server_protocol_invoke, protocol);
jsonrpc_server_add(&protocol->rpc, "read", &server_protocol_invoke, protocol); wsfs_impl_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_impl_server_protocol_invoke, protocol);
bool const success = filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point); bool const success = wsfs_impl_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
// cleanup on error // cleanup on error
if (!success) if (!success)
{ {
jsonrpc_server_cleanup(&protocol->rpc); wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
authenticators_cleanup(&protocol->authenticators); wsfs_impl_authenticators_cleanup(&protocol->authenticators);
timeout_manager_cleanup(&protocol->timeout_manager); wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
session_manager_cleanup(&protocol->session_manager); wsfs_impl_session_manager_cleanup(&protocol->session_manager);
} }
return success; return success;
} }
void server_protocol_cleanup( void wsfs_impl_server_protocol_cleanup(
struct server_protocol * protocol) struct wsfs_server_protocol * protocol)
{ {
filesystem_cleanup(&protocol->filesystem); wsfs_impl_filesystem_cleanup(&protocol->filesystem);
jsonrpc_server_cleanup(&protocol->rpc); wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
timeout_manager_cleanup(&protocol->timeout_manager); wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
authenticators_cleanup(&protocol->authenticators); wsfs_impl_authenticators_cleanup(&protocol->authenticators);
session_manager_cleanup(&protocol->session_manager); wsfs_impl_session_manager_cleanup(&protocol->session_manager);
} }
void server_protocol_add_authenticator( void wsfs_impl_server_protocol_add_authenticator(
struct server_protocol * protocol, struct wsfs_server_protocol * protocol,
char const * type, char const * type,
authenticate_fn * authenticate, wsfs_authenticate_fn * authenticate,
void * user_data) void * user_data)
{ {
authenticators_add(&protocol->authenticators, type, authenticate, user_data); wsfs_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
} }

View File

@ -14,36 +14,36 @@ extern "C"
struct lws_protocols; struct lws_protocols;
struct server_protocol struct wsfs_server_protocol
{ {
struct timeout_manager timeout_manager; struct wsfs_impl_timeout_manager timeout_manager;
struct filesystem filesystem; struct wsfs_impl_filesystem filesystem;
struct jsonrpc_server rpc; struct wsfs_impl_jsonrpc_server rpc;
struct authenticators authenticators; struct wsfs_impl_authenticators authenticators;
struct session_manager session_manager; struct wsfs_impl_session_manager session_manager;
}; };
extern bool server_protocol_init( extern bool wsfs_impl_server_protocol_init(
struct server_protocol * protocol, struct wsfs_server_protocol * protocol,
char * mount_point); char * mount_point);
extern void server_protocol_cleanup( extern void wsfs_impl_server_protocol_cleanup(
struct server_protocol * protocol); struct wsfs_server_protocol * protocol);
extern struct server_protocol * server_protocol_create( extern struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
char * mount_point); char * mount_point);
extern void server_protocol_dispose( extern void wsfs_impl_server_protocol_dispose(
struct server_protocol * protocol); struct wsfs_server_protocol * protocol);
extern void server_protocol_init_lws( extern void wsfs_impl_server_protocol_init_lws(
struct server_protocol * protocol, struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol); struct lws_protocols * lws_protocol);
extern void server_protocol_add_authenticator( extern void wsfs_impl_server_protocol_add_authenticator(
struct server_protocol * protocol, struct wsfs_server_protocol * protocol,
char const * type, char const * type,
authenticate_fn * authenticate, wsfs_authenticate_fn * authenticate,
void * user_data); void * user_data);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -7,11 +7,11 @@
#include <libwebsockets.h> #include <libwebsockets.h>
#include <stddef.h> #include <stddef.h>
void session_init( void wsfs_impl_session_init(
struct session * session, struct wsfs_impl_session * session,
struct lws * wsi, struct lws * wsi,
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct jsonrpc_server * rpc) struct wsfs_impl_jsonrpc_server * rpc)
{ {
session->wsi = wsi; session->wsi = wsi;
session->is_authenticated = false; session->is_authenticated = false;
@ -20,8 +20,8 @@ void session_init(
wsfs_message_queue_init(&session->queue); wsfs_message_queue_init(&session->queue);
} }
void session_cleanup( void wsfs_impl_session_cleanup(
struct session * session) struct wsfs_impl_session * session)
{ {
wsfs_message_queue_cleanup(&session->queue); wsfs_message_queue_cleanup(&session->queue);
session->is_authenticated = false; session->is_authenticated = false;
@ -30,15 +30,15 @@ void session_cleanup(
session->rpc = NULL; session->rpc = NULL;
} }
void session_authenticate( void wsfs_impl_session_authenticate(
struct session * session, struct wsfs_impl_session * session,
struct credentials * creds) struct wsfs_credentials * creds)
{ {
session->is_authenticated = authenticators_authenticate(session->authenticators, creds); session->is_authenticated = wsfs_impl_authenticators_authenticate(session->authenticators, creds);
} }
bool session_send( bool wsfs_impl_session_send(
struct session * session, struct wsfs_impl_session * session,
struct wsfs_message * message) struct wsfs_message * message)
{ {
bool result = (session->is_authenticated) && (NULL != session->wsi); bool result = (session->is_authenticated) && (NULL != session->wsi);
@ -58,8 +58,8 @@ bool session_send(
return result; return result;
} }
void session_onwritable( void wsfs_impl_session_onwritable(
struct session * session) struct wsfs_impl_session * session)
{ {
if (!wsfs_message_queue_empty(&session->queue)) if (!wsfs_message_queue_empty(&session->queue))
{ {
@ -75,10 +75,10 @@ void session_onwritable(
} }
void session_receive( void wsfs_impl_session_receive(
struct session * session, struct wsfs_impl_session * session,
char const * data, char const * data,
size_t length) size_t length)
{ {
jsonrpc_server_onresult(session->rpc, data, length); wsfs_impl_jsonrpc_server_onresult(session->rpc, data, length);
} }

View File

@ -18,43 +18,43 @@ extern "C"
struct lws; struct lws;
struct wsfs_message; struct wsfs_message;
struct credentials; struct wsfs_credentials;
struct authenticators; struct wsfs_impl_authenticators;
struct jsonrpc_server; struct wsfs_impl_jsonrpc_server;
struct session struct wsfs_impl_session
{ {
struct lws * wsi; struct lws * wsi;
bool is_authenticated; bool is_authenticated;
struct wsfs_message_queue queue; struct wsfs_message_queue queue;
struct authenticators * authenticators; struct wsfs_impl_authenticators * authenticators;
struct jsonrpc_server * rpc; struct wsfs_impl_jsonrpc_server * rpc;
}; };
extern void session_init( extern void wsfs_impl_session_init(
struct session * session, struct wsfs_impl_session * session,
struct lws * wsi, struct lws * wsi,
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct jsonrpc_server * rpc); struct wsfs_impl_jsonrpc_server * rpc);
extern void session_authenticate( extern void wsfs_impl_session_authenticate(
struct session * session, struct wsfs_impl_session * session,
struct credentials * creds); struct wsfs_credentials * creds);
extern bool session_send( extern bool wsfs_impl_session_send(
struct session * session, struct wsfs_impl_session * session,
struct wsfs_message * message); struct wsfs_message * message);
extern void session_receive( extern void wsfs_impl_session_receive(
struct session * session, struct wsfs_impl_session * session,
char const * data, char const * data,
size_t length); size_t length);
extern void session_onwritable( extern void wsfs_impl_session_onwritable(
struct session * session); struct wsfs_impl_session * session);
extern void session_cleanup( extern void wsfs_impl_session_cleanup(
struct session * session); struct wsfs_impl_session * session);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,39 +1,39 @@
#include "wsfs/adapter/impl/session_manager.h" #include "wsfs/adapter/impl/session_manager.h"
#include <stddef.h> #include <stddef.h>
void session_manager_init( void wsfs_impl_session_manager_init(
struct session_manager * manager) struct wsfs_impl_session_manager * manager)
{ {
session_init(&manager->session, NULL, NULL, NULL); wsfs_impl_session_init(&manager->session, NULL, NULL, NULL);
} }
void session_manager_cleanup( void wsfs_impl_session_manager_cleanup(
struct session_manager * manager) struct wsfs_impl_session_manager * manager)
{ {
session_cleanup(&manager->session); wsfs_impl_session_cleanup(&manager->session);
} }
struct session * session_manager_add( struct wsfs_impl_session * wsfs_impl_session_manager_add(
struct session_manager * manager, struct wsfs_impl_session_manager * manager,
struct lws * wsi, struct lws * wsi,
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct jsonrpc_server * rpc) struct wsfs_impl_jsonrpc_server * rpc)
{ {
struct session * session = NULL; struct wsfs_impl_session * session = NULL;
if (NULL == manager->session.wsi) if (NULL == manager->session.wsi)
{ {
session = &manager->session; session = &manager->session;
session_init(&manager->session, wsi, authenticators, rpc); wsfs_impl_session_init(&manager->session, wsi, authenticators, rpc);
} }
return session; return session;
} }
struct session * session_manager_get( struct wsfs_impl_session * wsfs_impl_session_manager_get(
struct session_manager * manager, struct wsfs_impl_session_manager * manager,
struct lws * wsi) struct lws * wsi)
{ {
struct session * session = NULL; struct wsfs_impl_session * session = NULL;
if (wsi == manager->session.wsi) if (wsi == manager->session.wsi)
{ {
session = &manager->session; session = &manager->session;
@ -42,13 +42,13 @@ struct session * session_manager_get(
return session; return session;
} }
void session_manager_remove( void wsfs_impl_session_manager_remove(
struct session_manager * manager, struct wsfs_impl_session_manager * manager,
struct lws * wsi) struct lws * wsi)
{ {
if (wsi == manager->session.wsi) if (wsi == manager->session.wsi)
{ {
session_cleanup(&manager->session); wsfs_impl_session_cleanup(&manager->session);
manager->session.wsi = NULL; manager->session.wsi = NULL;
} }
} }

View File

@ -14,29 +14,29 @@ extern "C"
struct lws; struct lws;
struct session_manager struct wsfs_impl_session_manager
{ {
struct session session; struct wsfs_impl_session session;
}; };
extern void session_manager_init( extern void wsfs_impl_session_manager_init(
struct session_manager * manager); struct wsfs_impl_session_manager * manager);
extern void session_manager_cleanup( extern void wsfs_impl_session_manager_cleanup(
struct session_manager * manager); struct wsfs_impl_session_manager * manager);
extern struct session * session_manager_add( extern struct wsfs_impl_session * wsfs_impl_session_manager_add(
struct session_manager * manager, struct wsfs_impl_session_manager * manager,
struct lws * wsi, struct lws * wsi,
struct authenticators * authenticators, struct wsfs_impl_authenticators * authenticators,
struct jsonrpc_server * rpc); struct wsfs_impl_jsonrpc_server * rpc);
extern struct session * session_manager_get( extern struct wsfs_impl_session * wsfs_impl_session_manager_get(
struct session_manager * manager, struct wsfs_impl_session_manager * manager,
struct lws * wsi); struct lws * wsi);
extern void session_manager_remove( extern void wsfs_impl_session_manager_remove(
struct session_manager * manager, struct wsfs_impl_session_manager * manager,
struct lws * wsi); struct lws * wsi);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -4,21 +4,21 @@
#include "wsfs/adapter/impl/time/timer_intern.h" #include "wsfs/adapter/impl/time/timer_intern.h"
#include "wsfs/adapter/impl/time/timepoint.h" #include "wsfs/adapter/impl/time/timepoint.h"
void timeout_manager_init( void wsfs_impl_timeout_manager_init(
struct timeout_manager * manager) struct wsfs_impl_timeout_manager * manager)
{ {
manager->timers = NULL; manager->timers = NULL;
} }
void timeout_manager_cleanup( void wsfs_impl_timeout_manager_cleanup(
struct timeout_manager * manager) struct wsfs_impl_timeout_manager * manager)
{ {
struct timer * timer = manager->timers; struct wsfs_impl_timer * timer = manager->timers;
while (NULL != timer) while (NULL != timer)
{ {
struct timer * next = timer->next; struct wsfs_impl_timer * next = timer->next;
timer_trigger(timer); wsfs_impl_timer_trigger(timer);
timer = next; timer = next;
} }
@ -27,27 +27,27 @@ void timeout_manager_cleanup(
} }
void timeout_manager_check( void wsfs_impl_timeout_manager_check(
struct timeout_manager * manager) struct wsfs_impl_timeout_manager * manager)
{ {
struct timer * timer = manager->timers; struct wsfs_impl_timer * timer = manager->timers;
while (NULL != timer) while (NULL != timer)
{ {
struct timer * next = timer->next; struct wsfs_impl_timer * next = timer->next;
if (timer_is_timeout(timer)) if (wsfs_impl_timer_is_timeout(timer))
{ {
timeout_manager_removetimer(manager, timer); wsfs_impl_timeout_manager_removetimer(manager, timer);
timer_trigger(timer); wsfs_impl_timer_trigger(timer);
} }
timer = next; timer = next;
} }
} }
void timeout_manager_addtimer( void wsfs_impl_timeout_manager_addtimer(
struct timeout_manager * manager, struct wsfs_impl_timeout_manager * manager,
struct timer * timer) struct wsfs_impl_timer * timer)
{ {
if (NULL != manager->timers) if (NULL != manager->timers)
{ {
@ -59,12 +59,12 @@ void timeout_manager_addtimer(
manager->timers = timer; manager->timers = timer;
} }
void timeout_manager_removetimer( void wsfs_impl_timeout_manager_removetimer(
struct timeout_manager * manager, struct wsfs_impl_timeout_manager * manager,
struct timer * timer) struct wsfs_impl_timer * timer)
{ {
struct timer * prev = timer->prev; struct wsfs_impl_timer * prev = timer->prev;
struct timer * next = timer->next; struct wsfs_impl_timer * next = timer->next;
if (NULL != prev) if (NULL != prev)
{ {

View File

@ -6,20 +6,20 @@ extern "C"
{ {
#endif #endif
struct timer; struct wsfs_impl_timer;
struct timeout_manager struct wsfs_impl_timeout_manager
{ {
struct timer * timers; struct wsfs_impl_timer * timers;
}; };
extern void timeout_manager_init( extern void wsfs_impl_timeout_manager_init(
struct timeout_manager * manager); struct wsfs_impl_timeout_manager * manager);
extern void timeout_manager_cleanup( extern void wsfs_impl_timeout_manager_cleanup(
struct timeout_manager * manager); struct wsfs_impl_timeout_manager * manager);
extern void timeout_manager_check( extern void wsfs_impl_timeout_manager_check(
struct timeout_manager * manager); struct wsfs_impl_timeout_manager * manager);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -8,13 +8,13 @@ extern "C"
{ {
#endif #endif
extern void timeout_manager_addtimer( extern void wsfs_impl_timeout_manager_addtimer(
struct timeout_manager * manager, struct wsfs_impl_timeout_manager * manager,
struct timer * timer); struct wsfs_impl_timer * timer);
extern void timeout_manager_removetimer( extern void wsfs_impl_timeout_manager_removetimer(
struct timeout_manager * manager, struct wsfs_impl_timeout_manager * manager,
struct timer * timer); struct wsfs_impl_timer * timer);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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

View File

@ -13,16 +13,16 @@ extern "C"
{ {
#endif #endif
typedef uint64_t timepoint; typedef uint64_t wsfs_impl_timepoint;
typedef int64_t timediff; typedef int64_t wsfs_impl_timediff;
extern timepoint timepoint_now(void); extern wsfs_impl_timepoint wsfs_impl_timepoint_now(void);
extern timepoint timepoint_in_msec( extern wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(
timediff value); wsfs_impl_timediff value);
extern bool timepoint_is_elapsed( extern bool wsfs_impl_timepoint_is_elapsed(
timepoint timepoint); wsfs_impl_timepoint timepoint);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -4,9 +4,9 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
void timer_init( void wsfs_impl_timer_init(
struct timer * timer, struct wsfs_impl_timer * timer,
struct timeout_manager * manager) struct wsfs_impl_timeout_manager * manager)
{ {
timer->manager = manager; timer->manager = manager;
timer->timeout = 0; timer->timeout = 0;
@ -16,44 +16,44 @@ void timer_init(
timer->next = NULL; timer->next = NULL;
} }
void timer_cleanup( void wsfs_impl_timer_cleanup(
struct timer * timer) struct wsfs_impl_timer * timer)
{ {
memset(timer, 0, sizeof(struct timer)); memset(timer, 0, sizeof(struct wsfs_impl_timer));
} }
void timer_start( void wsfs_impl_timer_start(
struct timer * timer, struct wsfs_impl_timer * timer,
timepoint absolute_timeout, wsfs_impl_timepoint absolute_timeout,
timer_timeout_fn * handler, wsfs_impl_timer_timeout_fn * handler,
void * user_data) void * user_data)
{ {
timer->timeout = absolute_timeout; timer->timeout = absolute_timeout;
timer->timeout_handler = handler; timer->timeout_handler = handler;
timer->user_data = user_data; timer->user_data = user_data;
timeout_manager_addtimer(timer->manager, timer); wsfs_impl_timeout_manager_addtimer(timer->manager, timer);
} }
void timer_cancel( void wsfs_impl_timer_cancel(
struct timer * timer) struct wsfs_impl_timer * timer)
{ {
timeout_manager_removetimer(timer->manager, timer); wsfs_impl_timeout_manager_removetimer(timer->manager, timer);
timer->timeout = 0; timer->timeout = 0;
timer->timeout_handler = NULL; timer->timeout_handler = NULL;
timer->user_data = NULL; timer->user_data = NULL;
} }
bool timer_is_timeout( bool wsfs_impl_timer_is_timeout(
struct timer * timer) struct wsfs_impl_timer * timer)
{ {
return timepoint_is_elapsed(timer->timeout); return wsfs_impl_timepoint_is_elapsed(timer->timeout);
} }
void timer_trigger( void wsfs_impl_timer_trigger(
struct timer * timer) struct wsfs_impl_timer * timer)
{ {
if (NULL != timer->timeout_handler) if (NULL != timer->timeout_handler)
{ {

View File

@ -8,36 +8,36 @@ extern "C"
{ {
#endif #endif
struct timer; struct wsfs_impl_timer;
struct timeout_manager; struct wsfs_impl_timeout_manager;
typedef void timer_timeout_fn(struct timer * timer); typedef void wsfs_impl_timer_timeout_fn(struct wsfs_impl_timer * timer);
struct timer struct wsfs_impl_timer
{ {
struct timeout_manager * manager; struct wsfs_impl_timeout_manager * manager;
timepoint timeout; wsfs_impl_timepoint timeout;
timer_timeout_fn * timeout_handler; wsfs_impl_timer_timeout_fn * timeout_handler;
void * user_data; void * user_data;
struct timer * next; struct wsfs_impl_timer * next;
struct timer * prev; struct wsfs_impl_timer * prev;
}; };
extern void timer_init( extern void wsfs_impl_timer_init(
struct timer * timer, struct wsfs_impl_timer * timer,
struct timeout_manager * manager); struct wsfs_impl_timeout_manager * manager);
extern void timer_cleanup( extern void wsfs_impl_timer_cleanup(
struct timer * timer); struct wsfs_impl_timer * timer);
extern void timer_start( extern void wsfs_impl_timer_start(
struct timer * timer, struct wsfs_impl_timer * timer,
timepoint absolute_timeout, wsfs_impl_timepoint absolute_timeout,
timer_timeout_fn * handler, wsfs_impl_timer_timeout_fn * handler,
void * user_data); void * user_data);
extern void timer_cancel( extern void wsfs_impl_timer_cancel(
struct timer * timer); struct wsfs_impl_timer * timer);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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

View File

@ -23,17 +23,17 @@ void set_authenticator(size_t i, Authenticator * authenticator)
g_authenticators[i] = authenticator; g_authenticators[i] = authenticator;
} }
bool authenticate(struct credentials * creds, void * user_data) bool authenticate(struct wsfs_credentials * creds, void * user_data)
{ {
return g_authenticators[0]->authenticate(creds, user_data); return g_authenticators[0]->authenticate(creds, user_data);
} }
bool authenticate_1(struct credentials * creds, void * user_data) bool authenticate_1(struct wsfs_credentials * creds, void * user_data)
{ {
return g_authenticators[1]->authenticate(creds, user_data); return g_authenticators[1]->authenticate(creds, user_data);
} }
bool authenticate_2(struct credentials * creds, void * user_data) bool authenticate_2(struct wsfs_credentials * creds, void * user_data)
{ {
return g_authenticators[2]->authenticate(creds, user_data); return g_authenticators[2]->authenticate(creds, user_data);
} }

View File

@ -12,22 +12,22 @@ class Authenticator
public: public:
virtual ~Authenticator() { } virtual ~Authenticator() { }
virtual bool authenticate( virtual bool authenticate(
struct credentials * credentials, struct wsfs_credentials * credentials,
void * user_data) = 0; void * user_data) = 0;
}; };
class MockAuthenticator: public Authenticator class MockAuthenticator: public Authenticator
{ {
public: public:
MOCK_METHOD2(authenticate, bool (struct credentials * credentials, void * user_data)); MOCK_METHOD2(authenticate, bool (struct wsfs_credentials * credentials, void * user_data));
}; };
void set_authenticator(Authenticator * authenticator); void set_authenticator(Authenticator * authenticator);
void set_authenticator(size_t index, Authenticator * authenticator); void set_authenticator(size_t index, Authenticator * authenticator);
bool authenticate(struct credentials * creds, void * user_data); bool authenticate(struct wsfs_credentials * creds, void * user_data);
bool authenticate_1(struct credentials * creds, void * user_data); bool authenticate_1(struct wsfs_credentials * creds, void * user_data);
bool authenticate_2(struct credentials * creds, void * user_data); bool authenticate_2(struct wsfs_credentials * creds, void * user_data);
} }

View File

@ -19,8 +19,8 @@ TEST(Authenticator, Authenticate)
MockAuthenticator mock; MockAuthenticator mock;
set_authenticator(&mock); set_authenticator(&mock);
struct credentials creds; struct wsfs_credentials creds;
credentials_init(&creds, "username", nullptr); wsfs_impl_credentials_init(&creds, "username", nullptr);
char dummy[] = "usr_data"; char dummy[] = "usr_data";
void * user_data = reinterpret_cast<void*>(dummy); void * user_data = reinterpret_cast<void*>(dummy);
@ -28,16 +28,16 @@ TEST(Authenticator, Authenticate)
.Times(1) .Times(1)
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
struct authenticator * authenticator = authenticator_create( struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(
"username", "username",
&authenticate, &authenticate,
user_data); user_data);
bool result = authenticator_autenticate(authenticator, &creds); bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds);
ASSERT_TRUE(result); ASSERT_TRUE(result);
authenticator_dispose(authenticator); wsfs_impl_authenticator_dispose(authenticator);
credentials_cleanup(&creds); wsfs_impl_credentials_cleanup(&creds);
} }
TEST(Authenticator, SkipAuthenticationWithWrongType) TEST(Authenticator, SkipAuthenticationWithWrongType)
@ -45,19 +45,19 @@ TEST(Authenticator, SkipAuthenticationWithWrongType)
MockAuthenticator mock; MockAuthenticator mock;
set_authenticator(&mock); set_authenticator(&mock);
struct credentials creds; struct wsfs_credentials creds;
credentials_init(&creds, "username", nullptr); wsfs_impl_credentials_init(&creds, "username", nullptr);
EXPECT_CALL(mock, authenticate(_, _)) EXPECT_CALL(mock, authenticate(_, _))
.Times(0); .Times(0);
struct authenticator * authenticator = authenticator_create( struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(
"certificate", "certificate",
&authenticate, &authenticate,
nullptr); nullptr);
bool result = authenticator_autenticate(authenticator, &creds); bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds);
ASSERT_FALSE(result); ASSERT_FALSE(result);
authenticator_dispose(authenticator); wsfs_impl_authenticator_dispose(authenticator);
credentials_cleanup(&creds); wsfs_impl_credentials_cleanup(&creds);
} }

View File

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

View File

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

View File

@ -6,14 +6,14 @@
static void response_parse_str( static void response_parse_str(
std::string const & buffer, std::string const & buffer,
struct jsonrpc_response * response) struct wsfs_impl_jsonrpc_response * response)
{ {
jsonrpc_response_init(response, buffer.c_str(), buffer.size()); wsfs_impl_jsonrpc_response_init(response, buffer.c_str(), buffer.size());
} }
TEST(response_parser, test) TEST(response_parser, test)
{ {
struct jsonrpc_response response; struct wsfs_impl_jsonrpc_response response;
// invalid json // invalid json
response_parse_str("", &response); response_parse_str("", &response);

View File

@ -7,9 +7,9 @@ using wsfs_test::msleep;
TEST(timepoint, now) TEST(timepoint, now)
{ {
timepoint start = timepoint_now(); wsfs_impl_timepoint start = wsfs_impl_timepoint_now();
msleep(42); msleep(42);
timepoint end = timepoint_now(); wsfs_impl_timepoint end = wsfs_impl_timepoint_now();
ASSERT_LT(start, end); ASSERT_LT(start, end);
ASSERT_LT(end, start + 500); ASSERT_LT(end, start + 500);
@ -17,20 +17,20 @@ TEST(timepoint, now)
TEST(timepoint, in_msec) TEST(timepoint, in_msec)
{ {
timepoint now = timepoint_now(); wsfs_impl_timepoint now = wsfs_impl_timepoint_now();
timepoint later = timepoint_in_msec(42); wsfs_impl_timepoint later = wsfs_impl_timepoint_in_msec(42);
ASSERT_LT(now, later); ASSERT_LT(now, later);
ASSERT_LT(later, now + 500); ASSERT_LT(later, now + 500);
} }
TEST(timepoint, elapsed) TEST(wsfs_impl_timepoint, elapsed)
{ {
timepoint now; wsfs_impl_timepoint now;
now = timepoint_now(); now = wsfs_impl_timepoint_now();
ASSERT_TRUE(timepoint_is_elapsed(now - 1)); ASSERT_TRUE(wsfs_impl_timepoint_is_elapsed(now - 1));
now = timepoint_now(); now =wsfs_impl_timepoint_now();
ASSERT_FALSE(timepoint_is_elapsed(now + 500)); ASSERT_FALSE(wsfs_impl_timepoint_is_elapsed(now + 500));
} }

View File

@ -11,7 +11,7 @@ using wsfs_test::msleep;
namespace namespace
{ {
void on_timeout(struct timer * timer) void on_timeout(struct wsfs_impl_timer * timer)
{ {
bool * triggered = reinterpret_cast<bool*>(timer->user_data); bool * triggered = reinterpret_cast<bool*>(timer->user_data);
*triggered = true; *triggered = true;
@ -20,82 +20,82 @@ namespace
TEST(timer, init) TEST(timer, init)
{ {
struct timeout_manager manager; struct wsfs_impl_timeout_manager manager;
struct timer timer; struct wsfs_impl_timer timer;
timeout_manager_init(&manager); wsfs_impl_timeout_manager_init(&manager);
timer_init(&timer, &manager); wsfs_impl_timer_init(&timer, &manager);
timer_cleanup(&timer); wsfs_impl_timer_cleanup(&timer);
timeout_manager_cleanup(&manager); wsfs_impl_timeout_manager_cleanup(&manager);
} }
TEST(timer, trigger) TEST(timer, trigger)
{ {
struct timeout_manager manager; struct wsfs_impl_timeout_manager manager;
struct timer timer; struct wsfs_impl_timer timer;
timeout_manager_init(&manager); wsfs_impl_timeout_manager_init(&manager);
timer_init(&timer, &manager); wsfs_impl_timer_init(&timer, &manager);
bool triggered = false; bool triggered = false;
timer_start(&timer, timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered)); wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
msleep(500); msleep(500);
timeout_manager_check(&manager); wsfs_impl_timeout_manager_check(&manager);
ASSERT_TRUE(triggered); ASSERT_TRUE(triggered);
timer_cleanup(&timer); wsfs_impl_timer_cleanup(&timer);
timeout_manager_cleanup(&manager); wsfs_impl_timeout_manager_cleanup(&manager);
} }
TEST(timer, cancel) TEST(timer, cancel)
{ {
struct timeout_manager manager; struct wsfs_impl_timeout_manager manager;
struct timer timer; struct wsfs_impl_timer timer;
timeout_manager_init(&manager); wsfs_impl_timeout_manager_init(&manager);
timer_init(&timer, &manager); wsfs_impl_timer_init(&timer, &manager);
bool triggered = false; bool triggered = false;
timer_start(&timer, timepoint_in_msec(250), &on_timeout, &triggered); wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, &triggered);
msleep(500); msleep(500);
timer_cancel(&timer); wsfs_impl_timer_cancel(&timer);
timeout_manager_check(&manager); wsfs_impl_timeout_manager_check(&manager);
ASSERT_FALSE(triggered); ASSERT_FALSE(triggered);
timer_cleanup(&timer); wsfs_impl_timer_cleanup(&timer);
timeout_manager_cleanup(&manager); wsfs_impl_timeout_manager_cleanup(&manager);
} }
TEST(timer, multiple_timers) TEST(timer, multiple_timers)
{ {
static size_t const count = 5; static size_t const count = 5;
struct timeout_manager manager; struct wsfs_impl_timeout_manager manager;
struct timer timer[count]; struct wsfs_impl_timer timer[count];
bool triggered[count]; bool triggered[count];
timeout_manager_init(&manager); wsfs_impl_timeout_manager_init(&manager);
for(size_t i = 0; i < count; i++) for(size_t i = 0; i < count; i++)
{ {
timer_init(&timer[i], &manager); wsfs_impl_timer_init(&timer[i], &manager);
triggered[i] = false; triggered[i] = false;
timer_start(&timer[i], timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]); wsfs_impl_timer_start(&timer[i], wsfs_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
} }
for(size_t i = 0; i < count; i++) for(size_t i = 0; i < count; i++)
{ {
msleep(100); msleep(100);
timeout_manager_check(&manager); wsfs_impl_timeout_manager_check(&manager);
} }
for(size_t i = 0; i < count; i++) for(size_t i = 0; i < count; i++)
{ {
ASSERT_TRUE(triggered[i]); ASSERT_TRUE(triggered[i]);
timer_cleanup(&timer[i]); wsfs_impl_timer_cleanup(&timer[i]);
} }
timeout_manager_cleanup(&manager); wsfs_impl_timeout_manager_cleanup(&manager);
} }