mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
feat(API wrapper): separates implementation from public API
* moves implementation to impl subdirectory * adds prefix _impl to implementation symbols * removes double compilation for shared and static libraries * fixes include guards * fixes usage of extern "C"
This commit is contained in:
141
lib/wsfs/adapter/api.c
Normal file
141
lib/wsfs/adapter/api.c
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "wsfs_adapter.h"
|
||||
|
||||
#include "wsfs/adapter/impl/server.h"
|
||||
#include "wsfs/adapter/impl/server_protocol.h"
|
||||
#include "wsfs/adapter/impl/server_config.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
|
||||
// server
|
||||
|
||||
struct wsfs_server * wsfs_server_create(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
return wsfs_impl_server_create(config);
|
||||
}
|
||||
|
||||
void wsfs_server_dispose(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_dispose(server);
|
||||
}
|
||||
|
||||
void wsfs_server_run(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_run(server);
|
||||
}
|
||||
|
||||
void wsfs_server_shutdown(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
wsfs_impl_server_shutdown(server);
|
||||
}
|
||||
|
||||
// server protocol
|
||||
|
||||
struct wsfs_server_protocol * wsfs_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
return wsfs_impl_server_protocol_create(mount_point);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_dispose(protocol);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_init_lws(protocol, lws_protocol);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// server_config
|
||||
|
||||
struct wsfs_server_config * wsfs_server_config_create(void)
|
||||
{
|
||||
return wsfs_impl_server_config_create();
|
||||
}
|
||||
|
||||
void wsfs_server_config_dispose(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
wsfs_impl_server_config_dispose(config);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_mountpoint(
|
||||
struct wsfs_server_config * config,
|
||||
char const * mount_point)
|
||||
{
|
||||
wsfs_impl_server_config_set_mountpoint(config, mount_point);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_documentroot(
|
||||
struct wsfs_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
wsfs_impl_server_config_set_documentroot(config, document_root);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_keypath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wsfs_impl_server_config_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_certpath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wsfs_impl_server_config_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_vhostname(
|
||||
struct wsfs_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
wsfs_impl_server_config_set_vhostname(config, vhost_name);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_port(
|
||||
struct wsfs_server_config * config,
|
||||
int port)
|
||||
{
|
||||
wsfs_impl_server_config_set_port(config, port);
|
||||
}
|
||||
|
||||
void wsfs_server_config_add_authenticator(
|
||||
struct wsfs_server_config * config,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_server_config_add_authenticator(config, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// credentials
|
||||
|
||||
char const * wsfs_credentials_type(
|
||||
struct wsfs_credentials const * credentials)
|
||||
{
|
||||
return wsfs_impl_credentials_type(credentials);
|
||||
}
|
||||
|
||||
char const * wsfs_credentials_get(
|
||||
struct wsfs_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
return wsfs_impl_credentials_get(credentials, key);
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_AUTHENTICATOR_H
|
||||
#define WSFS_ADAPTER_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
struct wsfs_authenticator
|
||||
{
|
||||
char * type;
|
||||
wsfs_authenticate_fn * authenticate;
|
||||
void * user_data;
|
||||
struct wsfs_authenticator * next;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wsfs_authenticator * wsfs_authenticator_create(
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_authenticator_dispose(
|
||||
struct wsfs_authenticator * authenticator);
|
||||
|
||||
extern bool wsfs_authenticator_autenticate(
|
||||
struct wsfs_authenticator * authenticator,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
#include "wsfs/adapter/authenticators.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/authenticator.h"
|
||||
#include "wsfs/adapter/credentials_intern.h"
|
||||
|
||||
static struct wsfs_authenticator * wsfs_authenticators_find(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
char const * type)
|
||||
{
|
||||
struct wsfs_authenticator * result = NULL;
|
||||
|
||||
struct wsfs_authenticator * actual = authenticators->first;
|
||||
while ((NULL == result) && (NULL != actual))
|
||||
{
|
||||
struct wsfs_authenticator * next = actual->next;
|
||||
if (0 == strcmp(type, actual->type))
|
||||
{
|
||||
result = actual;
|
||||
}
|
||||
|
||||
actual = next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_authenticators_init(
|
||||
struct wsfs_authenticators * authenticators)
|
||||
{
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_authenticators_cleanup(
|
||||
struct wsfs_authenticators * authenticators)
|
||||
{
|
||||
struct wsfs_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_authenticator * next = actual->next;
|
||||
wsfs_authenticator_dispose(actual);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_authenticators_clone(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_authenticators * other)
|
||||
{
|
||||
wsfs_authenticators_init(other);
|
||||
|
||||
struct wsfs_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_authenticator * next = actual->next;
|
||||
wsfs_authenticators_add(other,
|
||||
actual->type, actual->authenticate, actual->user_data);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern void wsfs_authenticators_move(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_authenticators * other)
|
||||
{
|
||||
other->first = authenticators->first;
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_authenticators_add(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(type, authenticate, user_data);
|
||||
authenticator->next = authenticators->first;
|
||||
authenticators->first = authenticator;
|
||||
}
|
||||
|
||||
bool wsfs_authenticators_authenticate(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials)
|
||||
{
|
||||
bool result = (NULL == authenticators->first);
|
||||
|
||||
if (NULL != credentials)
|
||||
{
|
||||
struct wsfs_authenticator * authenticator = wsfs_authenticators_find(authenticators, credentials->type);
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
result = wsfs_authenticator_autenticate(authenticator, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_AUTHENTICATORS_H
|
||||
#define WSFS_ADAPTER_AUTHENTICATORS_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
struct wsfs_authenticator;
|
||||
struct wsfs_credentials;
|
||||
|
||||
struct wsfs_authenticators
|
||||
{
|
||||
struct wsfs_authenticator * first;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_authenticators_init(
|
||||
struct wsfs_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_authenticators_cleanup(
|
||||
struct wsfs_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_authenticators_clone(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_authenticators * other);
|
||||
|
||||
extern void wsfs_authenticators_move(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_authenticators * other);
|
||||
|
||||
extern void wsfs_authenticators_add(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern bool wsfs_authenticators_authenticate(
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_CREDENTIALS_INTERN_H
|
||||
#define WSFS_ADAPTER_CREDENTIALS_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/credentials.h"
|
||||
#include <jansson.h>
|
||||
|
||||
struct wsfs_credentials
|
||||
{
|
||||
char * type;
|
||||
json_t * data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_credentials_init(
|
||||
struct wsfs_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data);
|
||||
|
||||
extern void wsfs_credentials_cleanup(
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,45 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_FILESYSTEM_H
|
||||
#define WSFS_ADAPTER_FILESYSTEM_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/fuse_wrapper.h"
|
||||
#include "wsfs/adapter/operations.h"
|
||||
|
||||
struct wsfs_jsonrpc_server;
|
||||
|
||||
struct wsfs_filesystem
|
||||
{
|
||||
struct fuse_args args;
|
||||
struct fuse_session * session;
|
||||
struct fuse_buf buffer;
|
||||
struct wsfs_operations_context user_data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wsfs_filesystem_init(
|
||||
struct wsfs_filesystem * filesystem,
|
||||
struct wsfs_jsonrpc_server * rpc,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_filesystem_cleanup(
|
||||
struct wsfs_filesystem * filesystem);
|
||||
|
||||
extern int wsfs_filesystem_get_fd(
|
||||
struct wsfs_filesystem * filesystem);
|
||||
|
||||
extern void wsfs_filesystem_process_request(
|
||||
struct wsfs_filesystem * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "wsfs/adapter/authenticator.h"
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/credentials_intern.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
|
||||
struct wsfs_authenticator * wsfs_authenticator_create(
|
||||
struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_authenticator * authenticator = malloc(sizeof(struct wsfs_authenticator));
|
||||
struct wsfs_impl_authenticator * authenticator = malloc(sizeof(struct wsfs_impl_authenticator));
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
authenticator->type = strdup(type);
|
||||
@@ -22,15 +22,15 @@ struct wsfs_authenticator * wsfs_authenticator_create(
|
||||
return authenticator;
|
||||
}
|
||||
|
||||
void wsfs_authenticator_dispose(
|
||||
struct wsfs_authenticator * authenticator)
|
||||
void wsfs_impl_authenticator_dispose(
|
||||
struct wsfs_impl_authenticator * authenticator)
|
||||
{
|
||||
free(authenticator->type);
|
||||
free(authenticator);
|
||||
}
|
||||
|
||||
bool wsfs_authenticator_autenticate(
|
||||
struct wsfs_authenticator * authenticator,
|
||||
bool wsfs_impl_authenticator_autenticate(
|
||||
struct wsfs_impl_authenticator * authenticator,
|
||||
struct wsfs_credentials * credentials)
|
||||
{
|
||||
bool result;
|
||||
42
lib/wsfs/adapter/impl/authenticator.h
Normal file
42
lib/wsfs/adapter/impl/authenticator.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
#define WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_credentials;
|
||||
|
||||
struct wsfs_impl_authenticator
|
||||
{
|
||||
char * type;
|
||||
wsfs_authenticate_fn * authenticate;
|
||||
void * user_data;
|
||||
struct wsfs_impl_authenticator * next;
|
||||
};
|
||||
|
||||
extern struct wsfs_impl_authenticator * wsfs_impl_authenticator_create(
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_impl_authenticator_dispose(
|
||||
struct wsfs_impl_authenticator * authenticator);
|
||||
|
||||
extern bool wsfs_impl_authenticator_autenticate(
|
||||
struct wsfs_impl_authenticator * authenticator,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
101
lib/wsfs/adapter/impl/authenticators.c
Normal file
101
lib/wsfs/adapter/impl/authenticators.c
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
|
||||
static struct wsfs_impl_authenticator * wsfs_impl_authenticators_find(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type)
|
||||
{
|
||||
struct wsfs_impl_authenticator * result = NULL;
|
||||
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while ((NULL == result) && (NULL != actual))
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
if (0 == strcmp(type, actual->type))
|
||||
{
|
||||
result = actual;
|
||||
}
|
||||
|
||||
actual = next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_init(
|
||||
struct wsfs_impl_authenticators * authenticators)
|
||||
{
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_cleanup(
|
||||
struct wsfs_impl_authenticators * authenticators)
|
||||
{
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
wsfs_impl_authenticator_dispose(actual);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_clone(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other)
|
||||
{
|
||||
wsfs_impl_authenticators_init(other);
|
||||
|
||||
struct wsfs_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wsfs_impl_authenticator * next = actual->next;
|
||||
wsfs_impl_authenticators_add(other,
|
||||
actual->type, actual->authenticate, actual->user_data);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern void wsfs_impl_authenticators_move(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other)
|
||||
{
|
||||
other->first = authenticators->first;
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_authenticators_add(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(type, authenticate, user_data);
|
||||
authenticator->next = authenticators->first;
|
||||
authenticators->first = authenticator;
|
||||
}
|
||||
|
||||
bool wsfs_impl_authenticators_authenticate(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials)
|
||||
{
|
||||
bool result = (NULL == authenticators->first);
|
||||
|
||||
if (NULL != credentials)
|
||||
{
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticators_find(authenticators, credentials->type);
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
result = wsfs_impl_authenticator_autenticate(authenticator, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
51
lib/wsfs/adapter/impl/authenticators.h
Normal file
51
lib/wsfs/adapter/impl/authenticators.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
#define WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_authenticator;
|
||||
struct wsfs_credentials;
|
||||
|
||||
struct wsfs_impl_authenticators
|
||||
{
|
||||
struct wsfs_impl_authenticator * first;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_authenticators_init(
|
||||
struct wsfs_impl_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_impl_authenticators_cleanup(
|
||||
struct wsfs_impl_authenticators * authenticators);
|
||||
|
||||
extern void wsfs_impl_authenticators_clone(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other);
|
||||
|
||||
extern void wsfs_impl_authenticators_move(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_authenticators * other);
|
||||
|
||||
extern void wsfs_impl_authenticators_add(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern bool wsfs_impl_authenticators_authenticate(
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "wsfs/adapter/credentials_intern.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
#include <string.h>
|
||||
|
||||
void wsfs_credentials_init(
|
||||
void wsfs_impl_credentials_init(
|
||||
struct wsfs_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data)
|
||||
@@ -11,20 +11,20 @@ void wsfs_credentials_init(
|
||||
json_incref(credentials->data);
|
||||
}
|
||||
|
||||
void wsfs_credentials_cleanup(
|
||||
void wsfs_impl_credentials_cleanup(
|
||||
struct wsfs_credentials * credentials)
|
||||
{
|
||||
free(credentials->type);
|
||||
json_decref(credentials->data);
|
||||
}
|
||||
|
||||
char const * wsfs_credentials_type(
|
||||
char const * wsfs_impl_credentials_type(
|
||||
struct wsfs_credentials const * credentials)
|
||||
{
|
||||
return credentials->type;
|
||||
}
|
||||
|
||||
char const * wsfs_credentials_get(
|
||||
char const * wsfs_impl_credentials_get(
|
||||
struct wsfs_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
36
lib/wsfs/adapter/impl/credentials.h
Normal file
36
lib/wsfs/adapter/impl/credentials.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_CREDENTIALS_H
|
||||
#define WSFS_ADAPTER_IMPL_CREDENTIALS_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_credentials
|
||||
{
|
||||
char * type;
|
||||
json_t * data;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_credentials_init(
|
||||
struct wsfs_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data);
|
||||
|
||||
extern void wsfs_impl_credentials_cleanup(
|
||||
struct wsfs_credentials * credentials);
|
||||
|
||||
extern char const * wsfs_impl_credentials_type(
|
||||
struct wsfs_credentials const * credentials);
|
||||
|
||||
extern char const * wsfs_impl_credentials_get(
|
||||
struct wsfs_credentials const * credentials,
|
||||
char const * key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,25 +1,25 @@
|
||||
#include "wsfs/adapter/filesystem.h"
|
||||
#include "wsfs/adapter/operations.h"
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/filesystem.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static struct fuse_lowlevel_ops const wsfs_filesystem_operations =
|
||||
static struct fuse_lowlevel_ops const filesystem_operations =
|
||||
{
|
||||
.lookup = &wsfs_operation_lookup,
|
||||
.getattr = &wsfs_operation_getattr,
|
||||
.readdir = &wsfs_operation_readdir,
|
||||
.open = &wsfs_operation_open,
|
||||
.release = &wsfs_operation_close,
|
||||
.read = &wsfs_operation_read
|
||||
.lookup = &wsfs_impl_operation_lookup,
|
||||
.getattr = &wsfs_impl_operation_getattr,
|
||||
.readdir = &wsfs_impl_operation_readdir,
|
||||
.open = &wsfs_impl_operation_open,
|
||||
.release = &wsfs_impl_operation_close,
|
||||
.read = &wsfs_impl_operation_read
|
||||
};
|
||||
|
||||
|
||||
bool wsfs_filesystem_init(
|
||||
struct wsfs_filesystem * filesystem,
|
||||
struct wsfs_jsonrpc_server * rpc,
|
||||
bool wsfs_impl_filesystem_init(
|
||||
struct wsfs_impl_filesystem * filesystem,
|
||||
struct wsfs_impl_jsonrpc_server * rpc,
|
||||
char * mount_point)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -35,8 +35,8 @@ bool wsfs_filesystem_init(
|
||||
|
||||
filesystem->session = fuse_session_new(
|
||||
&filesystem->args,
|
||||
&wsfs_filesystem_operations,
|
||||
sizeof(wsfs_filesystem_operations),
|
||||
&filesystem_operations,
|
||||
sizeof(filesystem_operations),
|
||||
&filesystem->user_data);
|
||||
if (NULL != filesystem->session)
|
||||
{
|
||||
@@ -46,8 +46,8 @@ bool wsfs_filesystem_init(
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_filesystem_cleanup(
|
||||
struct wsfs_filesystem * filesystem)
|
||||
void wsfs_impl_filesystem_cleanup(
|
||||
struct wsfs_impl_filesystem * filesystem)
|
||||
{
|
||||
if (NULL != filesystem->session)
|
||||
{
|
||||
@@ -61,14 +61,14 @@ void wsfs_filesystem_cleanup(
|
||||
fuse_opt_free_args(&filesystem->args);
|
||||
}
|
||||
|
||||
int wsfs_filesystem_get_fd(
|
||||
struct wsfs_filesystem * filesystem)
|
||||
int wsfs_impl_filesystem_get_fd(
|
||||
struct wsfs_impl_filesystem * filesystem)
|
||||
{
|
||||
return fuse_session_fd(filesystem->session);
|
||||
}
|
||||
|
||||
void wsfs_filesystem_process_request(
|
||||
struct wsfs_filesystem * filesystem)
|
||||
void wsfs_impl_filesystem_process_request(
|
||||
struct wsfs_impl_filesystem * filesystem)
|
||||
{
|
||||
int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer);
|
||||
if (0 < result)
|
||||
45
lib/wsfs/adapter/impl/filesystem.h
Normal file
45
lib/wsfs/adapter/impl/filesystem.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_FILESYSTEM_H
|
||||
#define WSFS_ADAPTER_IMPL_FILESYSTEM_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/impl/fuse_wrapper.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_server;
|
||||
|
||||
struct wsfs_impl_filesystem
|
||||
{
|
||||
struct fuse_args args;
|
||||
struct fuse_session * session;
|
||||
struct fuse_buf buffer;
|
||||
struct wsfs_impl_operations_context user_data;
|
||||
};
|
||||
|
||||
extern bool wsfs_impl_filesystem_init(
|
||||
struct wsfs_impl_filesystem * filesystem,
|
||||
struct wsfs_impl_jsonrpc_server * rpc,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_filesystem_cleanup(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
extern int wsfs_impl_filesystem_get_fd(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
extern void wsfs_impl_filesystem_process_request(
|
||||
struct wsfs_impl_filesystem * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef WSFS_ADAPTER_FUSE_H
|
||||
#define WSFS_ADAPTER_FUSE_H
|
||||
#ifndef WSFS_ADAPTER_IMPL_FUSE_H
|
||||
#define WSFS_ADAPTER_IMPL_FUSE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
28
lib/wsfs/adapter/impl/jsonrpc/method.c
Normal file
28
lib/wsfs/adapter/impl/jsonrpc/method.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "wsfs/adapter/impl/jsonrpc/method_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * method = malloc(sizeof(struct wsfs_impl_jsonrpc_method));
|
||||
if (NULL != method)
|
||||
{
|
||||
method->next = NULL;
|
||||
method->name = strdup(name);
|
||||
method->invoke = invoke;
|
||||
method->user_data = user_data;
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
void wsfs_impl_jsonrpc_method_dispose(
|
||||
struct wsfs_impl_jsonrpc_method * method)
|
||||
{
|
||||
free(method->name);
|
||||
free(method);
|
||||
}
|
||||
31
lib/wsfs/adapter/impl/jsonrpc/method.h
Normal file
31
lib/wsfs/adapter/impl/jsonrpc/method.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef bool wsfs_impl_jsonrpc_method_invoke_fn(
|
||||
void * user_data,
|
||||
struct json_t const * method_call);
|
||||
|
||||
typedef void wsfs_impl_jsonrpc_method_finished_fn(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
struct json_t const * result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
31
lib/wsfs/adapter/impl/jsonrpc/method_intern.h
Normal file
31
lib/wsfs/adapter/impl/jsonrpc/method_intern.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/method.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_method
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * next;
|
||||
char * name;
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern struct wsfs_impl_jsonrpc_method * wsfs_impl_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_method_dispose(
|
||||
struct wsfs_impl_jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "wsfs/adapter/jsonrpc/request.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/request.h"
|
||||
|
||||
json_t * wsfs_jsonrpc_request_create(
|
||||
json_t * wsfs_impl_jsonrpc_request_create(
|
||||
char const * method,
|
||||
int id,
|
||||
char const * param_info,
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_REQUEST_H
|
||||
#define WSFS_ADAPTER_JSONRPC_REQUEST_H
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_REQUEST_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
@@ -18,7 +18,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern json_t * wsfs_jsonrpc_request_create(
|
||||
extern json_t * wsfs_impl_jsonrpc_request_create(
|
||||
char const * method,
|
||||
int id,
|
||||
char const * param_info,
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "wsfs/adapter/jsonrpc/response.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
void wsfs_jsonrpc_response_init(
|
||||
struct wsfs_jsonrpc_response * result,
|
||||
void wsfs_impl_jsonrpc_response_init(
|
||||
struct wsfs_impl_jsonrpc_response * result,
|
||||
char const * buffer,
|
||||
size_t length)
|
||||
{
|
||||
@@ -49,8 +49,8 @@ void wsfs_jsonrpc_response_init(
|
||||
json_decref(response);
|
||||
}
|
||||
|
||||
void wsfs_jsonrpc_response_cleanup(
|
||||
struct wsfs_jsonrpc_response * response)
|
||||
void wsfs_impl_jsonrpc_response_cleanup(
|
||||
struct wsfs_impl_jsonrpc_response * response)
|
||||
{
|
||||
if (NULL != response->result)
|
||||
{
|
||||
38
lib/wsfs/adapter/impl/jsonrpc/response.h
Normal file
38
lib/wsfs/adapter/impl/jsonrpc/response.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_response
|
||||
{
|
||||
wsfs_status status;
|
||||
int id;
|
||||
json_t * result;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_jsonrpc_response_init(
|
||||
struct wsfs_impl_jsonrpc_response * response,
|
||||
char const * buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_response_cleanup(
|
||||
struct wsfs_impl_jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/method_intern.h"
|
||||
#include "wsfs/adapter/jsonrpc/request.h"
|
||||
#include "wsfs/adapter/jsonrpc/response.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/method_intern.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/request.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
#define WSFS_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
static struct wsfs_jsonrpc_method const * wsfs_jsonrpc_server_getmethod(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
static struct wsfs_impl_jsonrpc_method const * wsfs_impl_jsonrpc_server_getmethod(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * name)
|
||||
{
|
||||
struct wsfs_jsonrpc_method * method = server->methods;
|
||||
struct wsfs_impl_jsonrpc_method * method = server->methods;
|
||||
while ((NULL != method) && (0 == strcmp(name, method->name)))
|
||||
{
|
||||
method = method->next;
|
||||
@@ -20,40 +20,40 @@ static struct wsfs_jsonrpc_method const * wsfs_jsonrpc_server_getmethod(
|
||||
return method;
|
||||
}
|
||||
|
||||
static void wsfs_jsonrpc_server_timeout(
|
||||
struct wsfs_timer * timer)
|
||||
static void wsfs_impl_jsonrpc_server_timeout(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
struct wsfs_jsonrpc_server * server = timer->user_data;
|
||||
struct wsfs_impl_jsonrpc_server * server = timer->user_data;
|
||||
|
||||
if (server->request.is_pending)
|
||||
{
|
||||
wsfs_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;
|
||||
|
||||
server->request.is_pending = false;
|
||||
server->request.id = 0;
|
||||
server->request.user_data = NULL;
|
||||
server->request.finished = NULL;
|
||||
wsfs_timer_cancel(&server->request.timer);
|
||||
wsfs_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, WSFS_BAD_TIMEOUT, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfs_jsonrpc_server_init(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
struct wsfs_timeout_manager * timeout_manager)
|
||||
void wsfs_impl_jsonrpc_server_init(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
struct wsfs_impl_timeout_manager * timeout_manager)
|
||||
{
|
||||
server->methods = NULL;
|
||||
server->request.is_pending = false;
|
||||
|
||||
wsfs_timer_init(&server->request.timer, timeout_manager);
|
||||
wsfs_impl_timer_init(&server->request.timer, timeout_manager);
|
||||
}
|
||||
|
||||
void wsfs_jsonrpc_server_cleanup(
|
||||
struct wsfs_jsonrpc_server * server)
|
||||
void wsfs_impl_jsonrpc_server_cleanup(
|
||||
struct wsfs_impl_jsonrpc_server * server)
|
||||
{
|
||||
wsfs_timer_cleanup(&server->request.timer);
|
||||
wsfs_impl_timer_cleanup(&server->request.timer);
|
||||
|
||||
if (server->request.is_pending)
|
||||
{
|
||||
@@ -61,31 +61,31 @@ void wsfs_jsonrpc_server_cleanup(
|
||||
server->request.is_pending = false;
|
||||
}
|
||||
|
||||
struct wsfs_jsonrpc_method * method = server->methods;
|
||||
struct wsfs_impl_jsonrpc_method * method = server->methods;
|
||||
while (NULL != method)
|
||||
{
|
||||
struct wsfs_jsonrpc_method * next = method->next;
|
||||
struct wsfs_impl_jsonrpc_method * next = method->next;
|
||||
method->next = NULL;
|
||||
wsfs_jsonrpc_method_dispose(method);
|
||||
wsfs_impl_jsonrpc_method_dispose(method);
|
||||
method = next;
|
||||
}
|
||||
server->methods = NULL;
|
||||
}
|
||||
|
||||
void wsfs_jsonrpc_server_add(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
void wsfs_impl_jsonrpc_server_add(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_jsonrpc_method * method = wsfs_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;
|
||||
server->methods = method;
|
||||
}
|
||||
|
||||
void wsfs_jsonrpc_server_invoke(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
wsfs_jsonrpc_method_finished_fn * finished,
|
||||
void wsfs_impl_jsonrpc_server_invoke(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
@@ -94,19 +94,19 @@ void wsfs_jsonrpc_server_invoke(
|
||||
{
|
||||
if (!server->request.is_pending)
|
||||
{
|
||||
struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name);
|
||||
struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name);
|
||||
if (NULL != method)
|
||||
{
|
||||
server->request.is_pending = true;
|
||||
server->request.finished = finished;
|
||||
server->request.user_data = user_data;
|
||||
server->request.id = 42;
|
||||
wsfs_timer_start(&server->request.timer, wsfs_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT),
|
||||
&wsfs_jsonrpc_server_timeout, server);
|
||||
wsfs_impl_timer_start(&server->request.timer, wsfs_impl_timepoint_in_msec(WSFS_DEFAULT_TIMEOUT),
|
||||
&wsfs_impl_jsonrpc_server_timeout, server);
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wsfs_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);
|
||||
if (NULL != request)
|
||||
{
|
||||
@@ -116,7 +116,7 @@ void wsfs_jsonrpc_server_invoke(
|
||||
server->request.finished = NULL;
|
||||
server->request.user_data = NULL;
|
||||
server->request.id = 0;
|
||||
wsfs_timer_cancel(&server->request.timer);
|
||||
wsfs_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, WSFS_BAD, NULL);
|
||||
}
|
||||
@@ -134,20 +134,20 @@ void wsfs_jsonrpc_server_invoke(
|
||||
}
|
||||
}
|
||||
|
||||
extern void wsfs_jsonrpc_server_notify(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
extern void wsfs_impl_jsonrpc_server_notify(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name);
|
||||
struct wsfs_impl_jsonrpc_method const * method = wsfs_impl_jsonrpc_server_getmethod(server, method_name);
|
||||
if (NULL != method)
|
||||
{
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wsfs_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);
|
||||
if (NULL != request)
|
||||
{
|
||||
@@ -159,28 +159,28 @@ extern void wsfs_jsonrpc_server_notify(
|
||||
}
|
||||
|
||||
|
||||
void wsfs_jsonrpc_server_onresult(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
void wsfs_impl_jsonrpc_server_onresult(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length)
|
||||
{
|
||||
struct wsfs_jsonrpc_response response;
|
||||
wsfs_jsonrpc_response_init(&response, message, length);
|
||||
struct wsfs_impl_jsonrpc_response response;
|
||||
wsfs_impl_jsonrpc_response_init(&response, message, length);
|
||||
|
||||
if ((server->request.is_pending) && (response.id == server->request.id))
|
||||
{
|
||||
wsfs_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;
|
||||
|
||||
server->request.is_pending = false;
|
||||
server->request.id = 0;
|
||||
server->request.user_data = NULL;
|
||||
server->request.finished = NULL;
|
||||
wsfs_timer_cancel(&server->request.timer);
|
||||
wsfs_impl_timer_cancel(&server->request.timer);
|
||||
|
||||
finished(user_data, response.status, response.result);
|
||||
}
|
||||
|
||||
wsfs_jsonrpc_response_cleanup(&response);
|
||||
wsfs_impl_jsonrpc_response_cleanup(&response);
|
||||
}
|
||||
|
||||
77
lib/wsfs/adapter/impl/jsonrpc/server.h
Normal file
77
lib/wsfs/adapter/impl/jsonrpc/server.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
#define WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/adapter/impl/jsonrpc/method.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/impl/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wsfs_impl_timer timer;
|
||||
};
|
||||
|
||||
struct wsfs_impl_jsonrpc_server
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_method * methods;
|
||||
struct wsfs_impl_jsonrpc_request request;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_init(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_cleanup(
|
||||
struct wsfs_impl_jsonrpc_server * server);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_add(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wsfs_impl_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data );
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_invoke(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
wsfs_impl_jsonrpc_method_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_notify(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_impl_jsonrpc_server_onresult(
|
||||
struct wsfs_impl_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "wsfs/adapter/jsonrpc/util.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/util.h"
|
||||
|
||||
int wsfs_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
||||
{
|
||||
int result = default_value;
|
||||
|
||||
17
lib/wsfs/adapter/impl/jsonrpc/util.h
Normal file
17
lib/wsfs/adapter/impl/jsonrpc/util.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_JSON_UTIL_H
|
||||
#define WSFS_ADAPTER_IMPL_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int wsfs_impl_json_get_int(json_t const * object, char const * key, int default_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
21
lib/wsfs/adapter/impl/operation/close.c
Normal file
21
lib/wsfs/adapter/impl/operation/close.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfs_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wsfs_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/operations.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@@ -7,11 +7,11 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/jsonrpc/util.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/util.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
struct wsfs_operation_getattr_context
|
||||
struct wsfs_impl_operation_getattr_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
double timeout;
|
||||
@@ -19,12 +19,12 @@ struct wsfs_operation_getattr_context
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
static void wsfs_operation_getattr_finished(
|
||||
static void wsfs_impl_operation_getattr_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
json_t const * data)
|
||||
{
|
||||
struct wsfs_operation_getattr_context * context = user_data;
|
||||
struct wsfs_impl_operation_getattr_context * context = user_data;
|
||||
|
||||
struct stat buffer;
|
||||
if (NULL != data)
|
||||
@@ -50,10 +50,10 @@ static void wsfs_operation_getattr_finished(
|
||||
buffer.st_uid = context->uid;
|
||||
buffer.st_gid = context->gid;
|
||||
buffer.st_nlink = 1;
|
||||
buffer.st_size = wsfs_json_get_int(data, "size", 0);
|
||||
buffer.st_atime = wsfs_json_get_int(data, "atime", 0);
|
||||
buffer.st_mtime = wsfs_json_get_int(data, "mtime", 0);
|
||||
buffer.st_ctime = wsfs_json_get_int(data, "ctime", 0);
|
||||
buffer.st_size = wsfs_impl_json_get_int(data, "size", 0);
|
||||
buffer.st_atime = wsfs_impl_json_get_int(data, "atime", 0);
|
||||
buffer.st_mtime = wsfs_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.st_ctime = wsfs_impl_json_get_int(data, "ctime", 0);
|
||||
|
||||
}
|
||||
else
|
||||
@@ -74,20 +74,20 @@ static void wsfs_operation_getattr_finished(
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wsfs_operation_getattr (
|
||||
void wsfs_impl_operation_getattr (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
struct wsfs_operation_getattr_context * getattr_context = malloc(sizeof(struct wsfs_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->uid = context->uid;
|
||||
getattr_context->gid = context->gid;
|
||||
getattr_context->timeout = user_data->timeout;
|
||||
|
||||
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_getattr_finished, getattr_context, "getattr", "i", inode);
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_getattr_finished, getattr_context, "getattr", "i", inode);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/operations.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/jsonrpc/util.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/util.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
struct wsfs_operation_lookup_context
|
||||
struct wsfs_impl_operation_lookup_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
double timeout;
|
||||
@@ -22,13 +22,13 @@ struct wsfs_operation_lookup_context
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
static void wsfs_operation_lookup_finished(
|
||||
static void wsfs_impl_operation_lookup_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
json_t const * data
|
||||
)
|
||||
{
|
||||
struct wsfs_operation_lookup_context * context = user_data;
|
||||
struct wsfs_impl_operation_lookup_context * context = user_data;
|
||||
struct fuse_entry_param buffer;
|
||||
|
||||
if (NULL != data)
|
||||
@@ -60,10 +60,10 @@ static void wsfs_operation_lookup_finished(
|
||||
buffer.attr.st_uid = context->uid;
|
||||
buffer.attr.st_gid = context->gid;
|
||||
buffer.attr.st_nlink = 1;
|
||||
buffer.attr.st_size = wsfs_json_get_int(data, "size", 0);
|
||||
buffer.attr.st_atime = wsfs_json_get_int(data, "atime", 0);
|
||||
buffer.attr.st_mtime = wsfs_json_get_int(data, "mtime", 0);
|
||||
buffer.attr.st_ctime = wsfs_json_get_int(data, "ctime", 0);
|
||||
buffer.attr.st_size = wsfs_impl_json_get_int(data, "size", 0);
|
||||
buffer.attr.st_atime = wsfs_impl_json_get_int(data, "atime", 0);
|
||||
buffer.attr.st_mtime = wsfs_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.attr.st_ctime = wsfs_impl_json_get_int(data, "ctime", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -83,21 +83,20 @@ static void wsfs_operation_lookup_finished(
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wsfs_operation_lookup (
|
||||
void wsfs_impl_operation_lookup (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t parent,
|
||||
char const * name)
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
struct wsfs_operation_lookup_context * lookup_context = malloc(sizeof(struct wsfs_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->uid = context->uid;
|
||||
lookup_context->gid = context->gid;
|
||||
lookup_context->timeout = user_data->timeout;
|
||||
|
||||
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
|
||||
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "wsfs/adapter/operations.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/status.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
static void wsfs_operation_open_finished(
|
||||
static void wsfs_impl_operation_open_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
json_t const * result)
|
||||
@@ -41,13 +41,13 @@ static void wsfs_operation_open_finished(
|
||||
|
||||
}
|
||||
|
||||
void wsfs_operation_open(
|
||||
void wsfs_impl_operation_open(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
wsfs_jsonrpc_server_invoke(rpc, &wsfs_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);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/operations.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@@ -6,11 +6,11 @@
|
||||
#include <jansson.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#define WSFS_MAX_READ_LENGTH 4096
|
||||
|
||||
static char * wsfs_fill_buffer(
|
||||
static char * wsfs_impl_fill_buffer(
|
||||
char const * data,
|
||||
char const * format,
|
||||
size_t count,
|
||||
@@ -38,7 +38,7 @@ static char * wsfs_fill_buffer(
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void wsfs_operation_read_finished(void * user_data, wsfs_status status, json_t const * data)
|
||||
static void wsfs_impl_operation_read_finished(void * user_data, wsfs_status status, json_t const * data)
|
||||
{
|
||||
fuse_req_t request = user_data;
|
||||
|
||||
@@ -58,7 +58,7 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j
|
||||
char const * const format = json_string_value(format_holder);
|
||||
length = (size_t) json_integer_value(count_holder);
|
||||
|
||||
buffer = wsfs_fill_buffer(data, format, length, &status);
|
||||
buffer = wsfs_impl_fill_buffer(data, format, length, &status);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,17 +79,17 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j
|
||||
|
||||
}
|
||||
|
||||
void wsfs_operation_read(
|
||||
void wsfs_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int const length = (size <= WSFS_MAX_READ_LENGTH) ? (int) size : WSFS_MAX_READ_LENGTH;
|
||||
int handle = (file_info->fh & INT_MAX);
|
||||
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/adapter/operations.h"
|
||||
#include "wsfs/adapter/impl/operations.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -8,43 +8,43 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
|
||||
#define WSFS_DIRBUFFER_INITIAL_SIZE 1024
|
||||
|
||||
struct wsfs_operation_readdir_context
|
||||
struct wsfs_impl_operation_readdir_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
size_t size;
|
||||
off_t offset;
|
||||
};
|
||||
|
||||
struct wsfs_dirbuffer
|
||||
struct wsfs_impl_dirbuffer
|
||||
{
|
||||
char * data;
|
||||
size_t position;
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
static void wsfs_dirbuffer_init(
|
||||
struct wsfs_dirbuffer * buffer)
|
||||
static void wsfs_impl_dirbuffer_init(
|
||||
struct wsfs_impl_dirbuffer * buffer)
|
||||
{
|
||||
buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE);
|
||||
buffer->position = 0;
|
||||
buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE;
|
||||
}
|
||||
|
||||
static void wsfs_dirbuffer_dispose(
|
||||
struct wsfs_dirbuffer * buffer)
|
||||
static void wsfs_impl_dirbuffer_dispose(
|
||||
struct wsfs_impl_dirbuffer * buffer)
|
||||
{
|
||||
free(buffer->data);
|
||||
}
|
||||
|
||||
static void wsfs_dirbuffer_add(
|
||||
static void wsfs_impl_dirbuffer_add(
|
||||
fuse_req_t request,
|
||||
struct wsfs_dirbuffer * buffer,
|
||||
struct wsfs_impl_dirbuffer * buffer,
|
||||
char const * name,
|
||||
fuse_ino_t inode)
|
||||
{
|
||||
@@ -66,20 +66,20 @@ static void wsfs_dirbuffer_add(
|
||||
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;
|
||||
}
|
||||
|
||||
static void wsfs_operation_readdir_finished(
|
||||
static void wsfs_impl_operation_readdir_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
json_t const * result)
|
||||
{
|
||||
struct wsfs_operation_readdir_context * context = user_data;
|
||||
struct wsfs_impl_operation_readdir_context * context = user_data;
|
||||
|
||||
struct wsfs_dirbuffer buffer;
|
||||
wsfs_dirbuffer_init(&buffer);
|
||||
struct wsfs_impl_dirbuffer buffer;
|
||||
wsfs_impl_dirbuffer_init(&buffer);
|
||||
|
||||
if (NULL != result)
|
||||
{
|
||||
@@ -100,7 +100,7 @@ static void wsfs_operation_readdir_finished(
|
||||
{
|
||||
char const * name = json_string_value(name_holder);
|
||||
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
|
||||
wsfs_dirbuffer_add(context->request, &buffer, name, entry_inode);
|
||||
wsfs_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ static void wsfs_operation_readdir_finished(
|
||||
if (((size_t) context->offset) < buffer.position)
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -125,23 +125,23 @@ static void wsfs_operation_readdir_finished(
|
||||
fuse_reply_err(context->request, ENOENT);
|
||||
}
|
||||
|
||||
wsfs_dirbuffer_dispose(&buffer);
|
||||
wsfs_impl_dirbuffer_dispose(&buffer);
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wsfs_operation_readdir (
|
||||
void wsfs_impl_operation_readdir (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wsfs_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_operation_readdir_context));
|
||||
struct wsfs_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
struct wsfs_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wsfs_impl_operation_readdir_context));
|
||||
readdir_context->request = request;
|
||||
readdir_context->size = size;
|
||||
readdir_context->offset = offset;
|
||||
|
||||
wsfs_jsonrpc_server_invoke(rpc, &wsfs_operation_readdir_finished, readdir_context, "readdir", "i", inode);
|
||||
wsfs_impl_jsonrpc_server_invoke(rpc, &wsfs_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode);
|
||||
}
|
||||
@@ -1,48 +1,48 @@
|
||||
#ifndef WSFS_ADAPTER_OPERATIONS
|
||||
#define WSFS_ADAPTER_OPERATIONS
|
||||
#ifndef WSFS_ADAPTER_IMPL_OPERATIONS_H
|
||||
#define WSFS_ADAPTER_IMPL_OPERATIONS_H
|
||||
|
||||
#include "wsfs/adapter/fuse_wrapper.h"
|
||||
|
||||
struct wsfs_jsonrpc_server;
|
||||
|
||||
struct wsfs_operations_context
|
||||
{
|
||||
struct wsfs_jsonrpc_server * rpc;
|
||||
double timeout;
|
||||
};
|
||||
#include "wsfs/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void wsfs_operation_lookup (
|
||||
struct wsfs_impl_jsonrpc_server;
|
||||
|
||||
struct wsfs_impl_operations_context
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_server * rpc;
|
||||
double timeout;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_operation_lookup (
|
||||
fuse_req_t req,
|
||||
fuse_ino_t parent,
|
||||
char const * name);
|
||||
|
||||
extern void wsfs_operation_getattr (
|
||||
extern void wsfs_impl_operation_getattr (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info *file_info);
|
||||
|
||||
extern void wsfs_operation_readdir (
|
||||
extern void wsfs_impl_operation_readdir (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info *file_info);
|
||||
|
||||
extern void wsfs_operation_open(
|
||||
extern void wsfs_impl_operation_open(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info);
|
||||
|
||||
extern void wsfs_operation_close(
|
||||
extern void wsfs_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info);
|
||||
|
||||
extern void wsfs_operation_read(
|
||||
extern void wsfs_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t ino, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
||||
@@ -8,8 +8,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/adapter/server_config_intern.h"
|
||||
#include "wsfs/adapter/server_protocol_intern.h"
|
||||
#include "wsfs/adapter/impl/server_config.h"
|
||||
#include "wsfs/adapter/impl/server_protocol.h"
|
||||
|
||||
#define WSFS_DISABLE_LWS_LOG 0
|
||||
#define WSFS_SERVER_PROTOCOL_COUNT 3
|
||||
@@ -26,13 +26,13 @@ struct wsfs_server
|
||||
struct lws_context_creation_info info;
|
||||
};
|
||||
|
||||
static bool wsfs_server_tls_enabled(
|
||||
static bool wsfs_impl_server_tls_enabled(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
return ((server->config.key_path != NULL) && (server->config.cert_path != NULL));
|
||||
}
|
||||
|
||||
static struct lws_context * wsfs_server_context_create(
|
||||
static struct lws_context * wsfs_impl_server_context_create(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
lws_set_log_level(WSFS_DISABLE_LWS_LOG, NULL);
|
||||
@@ -41,7 +41,7 @@ static struct lws_context * wsfs_server_context_create(
|
||||
server->ws_protocols[0].name = "http";
|
||||
server->ws_protocols[0].callback = lws_callback_http_dummy;
|
||||
server->ws_protocols[1].name = "fs";
|
||||
wsfs_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));
|
||||
server->mount.mount_next = NULL,
|
||||
@@ -66,7 +66,7 @@ static struct lws_context * wsfs_server_context_create(
|
||||
server->info.mounts = NULL;
|
||||
}
|
||||
|
||||
if (wsfs_server_tls_enabled(server))
|
||||
if (wsfs_impl_server_tls_enabled(server))
|
||||
{
|
||||
server->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
server->info.ssl_cert_filepath = server->config.cert_path;
|
||||
@@ -78,7 +78,7 @@ static struct lws_context * wsfs_server_context_create(
|
||||
|
||||
}
|
||||
|
||||
static bool wsfs_server_check_mountpoint(
|
||||
static bool wsfs_impl_server_check_mountpoint(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -98,22 +98,22 @@ static bool wsfs_server_check_mountpoint(
|
||||
return result;
|
||||
}
|
||||
|
||||
struct wsfs_server * wsfs_server_create(
|
||||
struct wsfs_server * wsfs_impl_server_create(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
struct wsfs_server * server = NULL;
|
||||
|
||||
if (wsfs_server_check_mountpoint(config))
|
||||
if (wsfs_impl_server_check_mountpoint(config))
|
||||
{
|
||||
server = malloc(sizeof(struct wsfs_server));
|
||||
if (NULL != server)
|
||||
{
|
||||
if (wsfs_server_protocol_init(&server->protocol, config->mount_point))
|
||||
if (wsfs_impl_server_protocol_init(&server->protocol, config->mount_point))
|
||||
{
|
||||
server->shutdown_requested = false;
|
||||
wsfs_server_config_clone(config, &server->config);
|
||||
wsfs_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
||||
server->context = wsfs_server_context_create(server);
|
||||
wsfs_impl_server_config_clone(config, &server->config);
|
||||
wsfs_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
||||
server->context = wsfs_impl_server_context_create(server);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -126,16 +126,16 @@ struct wsfs_server * wsfs_server_create(
|
||||
return server;
|
||||
}
|
||||
|
||||
void wsfs_server_dispose(
|
||||
void wsfs_impl_server_dispose(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
lws_context_destroy(server->context);
|
||||
wsfs_server_protocol_cleanup(&server->protocol);
|
||||
wsfs_server_config_cleanup(&server->config);
|
||||
wsfs_impl_server_protocol_cleanup(&server->protocol);
|
||||
wsfs_impl_server_config_cleanup(&server->config);
|
||||
free(server);
|
||||
}
|
||||
|
||||
void wsfs_server_run(
|
||||
void wsfs_impl_server_run(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
int n = 0;
|
||||
@@ -145,7 +145,7 @@ void wsfs_server_run(
|
||||
}
|
||||
}
|
||||
|
||||
void wsfs_server_shutdown(
|
||||
void wsfs_impl_server_shutdown(
|
||||
struct wsfs_server * server)
|
||||
{
|
||||
server->shutdown_requested = true;
|
||||
29
lib/wsfs/adapter/impl/server.h
Normal file
29
lib/wsfs/adapter/impl/server.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_server;
|
||||
struct wsfs_server_config;
|
||||
|
||||
extern struct wsfs_server * wsfs_impl_server_create(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_dispose(
|
||||
struct wsfs_server * server);
|
||||
|
||||
extern void wsfs_impl_server_run(
|
||||
struct wsfs_server * server);
|
||||
|
||||
extern void wsfs_impl_server_shutdown(
|
||||
struct wsfs_server * server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "wsfs/adapter/server_config_intern.h"
|
||||
#include "wsfs/adapter/impl/server_config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char * wsfs_server_config_strdup(char const * value)
|
||||
static char * wsfs_impl_server_config_strdup(char const * value)
|
||||
{
|
||||
char * result = NULL;
|
||||
if (NULL != value)
|
||||
@@ -14,18 +14,18 @@ static char * wsfs_server_config_strdup(char const * value)
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_server_config_init(
|
||||
void wsfs_impl_server_config_init(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
memset(config, 0, sizeof(struct wsfs_server_config));
|
||||
|
||||
wsfs_authenticators_init(&config->authenticators);
|
||||
wsfs_impl_authenticators_init(&config->authenticators);
|
||||
}
|
||||
|
||||
void wsfs_server_config_cleanup(
|
||||
void wsfs_impl_server_config_cleanup(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
wsfs_authenticators_cleanup(&config->authenticators);
|
||||
wsfs_impl_authenticators_cleanup(&config->authenticators);
|
||||
|
||||
free(config->mount_point);
|
||||
free(config->document_root);
|
||||
@@ -33,42 +33,42 @@ void wsfs_server_config_cleanup(
|
||||
free(config->cert_path);
|
||||
free(config->vhost_name);
|
||||
|
||||
wsfs_server_config_init(config);
|
||||
wsfs_impl_server_config_init(config);
|
||||
}
|
||||
|
||||
void wsfs_server_config_clone(
|
||||
void wsfs_impl_server_config_clone(
|
||||
struct wsfs_server_config * config,
|
||||
struct wsfs_server_config * clone)
|
||||
{
|
||||
clone->mount_point = wsfs_server_config_strdup(config->mount_point);
|
||||
clone->document_root = wsfs_server_config_strdup(config->document_root);
|
||||
clone->key_path = wsfs_server_config_strdup(config->key_path);
|
||||
clone->cert_path = wsfs_server_config_strdup(config->cert_path);
|
||||
clone->vhost_name = wsfs_server_config_strdup(config->vhost_name);
|
||||
clone->mount_point = wsfs_impl_server_config_strdup(config->mount_point);
|
||||
clone->document_root = wsfs_impl_server_config_strdup(config->document_root);
|
||||
clone->key_path = wsfs_impl_server_config_strdup(config->key_path);
|
||||
clone->cert_path = wsfs_impl_server_config_strdup(config->cert_path);
|
||||
clone->vhost_name = wsfs_impl_server_config_strdup(config->vhost_name);
|
||||
clone->port = config->port;
|
||||
|
||||
wsfs_authenticators_clone(&config->authenticators, &clone->authenticators);
|
||||
wsfs_impl_authenticators_clone(&config->authenticators, &clone->authenticators);
|
||||
}
|
||||
|
||||
struct wsfs_server_config * wsfs_server_config_create(void)
|
||||
struct wsfs_server_config * wsfs_impl_server_config_create(void)
|
||||
{
|
||||
struct wsfs_server_config * config = malloc(sizeof(struct wsfs_server_config));
|
||||
if (NULL != config)
|
||||
{
|
||||
wsfs_server_config_init(config);
|
||||
wsfs_impl_server_config_init(config);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
void wsfs_server_config_dispose(
|
||||
void wsfs_impl_server_config_dispose(
|
||||
struct wsfs_server_config * config)
|
||||
{
|
||||
wsfs_server_config_cleanup(config);
|
||||
wsfs_impl_server_config_cleanup(config);
|
||||
free(config);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_mountpoint(
|
||||
void wsfs_impl_server_config_set_mountpoint(
|
||||
struct wsfs_server_config * config,
|
||||
char const * mount_point)
|
||||
{
|
||||
@@ -76,7 +76,7 @@ void wsfs_server_config_set_mountpoint(
|
||||
config->mount_point = strdup(mount_point);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_documentroot(
|
||||
void wsfs_impl_server_config_set_documentroot(
|
||||
struct wsfs_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
@@ -84,7 +84,7 @@ void wsfs_server_config_set_documentroot(
|
||||
config->document_root = strdup(document_root);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_keypath(
|
||||
void wsfs_impl_server_config_set_keypath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
@@ -92,7 +92,7 @@ void wsfs_server_config_set_keypath(
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_certpath(
|
||||
void wsfs_impl_server_config_set_certpath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
@@ -100,7 +100,7 @@ void wsfs_server_config_set_certpath(
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_vhostname(
|
||||
void wsfs_impl_server_config_set_vhostname(
|
||||
struct wsfs_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
@@ -108,20 +108,20 @@ void wsfs_server_config_set_vhostname(
|
||||
config->vhost_name = strdup(vhost_name);
|
||||
}
|
||||
|
||||
void wsfs_server_config_set_port(
|
||||
void wsfs_impl_server_config_set_port(
|
||||
struct wsfs_server_config * config,
|
||||
int port)
|
||||
{
|
||||
config->port = port;
|
||||
}
|
||||
|
||||
void wsfs_server_config_add_authenticator(
|
||||
void wsfs_impl_server_config_add_authenticator(
|
||||
struct wsfs_server_config * config,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
)
|
||||
{
|
||||
wsfs_authenticators_add(&config->authenticators, type, authenticate, user_data);
|
||||
wsfs_impl_authenticators_add(&config->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
72
lib/wsfs/adapter/impl/server_config.h
Normal file
72
lib/wsfs/adapter/impl/server_config.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wsfs_server_config
|
||||
{
|
||||
char * mount_point;
|
||||
char * document_root;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * vhost_name;
|
||||
int port;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
};
|
||||
|
||||
extern struct wsfs_server_config * wsfs_impl_server_config_create(void);
|
||||
|
||||
extern void wsfs_impl_server_config_dispose(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_init(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_cleanup(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_impl_server_config_clone(
|
||||
struct wsfs_server_config * config,
|
||||
struct wsfs_server_config * clone);
|
||||
|
||||
extern void wsfs_impl_server_config_set_mountpoint(
|
||||
struct wsfs_server_config * config,
|
||||
char const * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_config_set_documentroot(
|
||||
struct wsfs_server_config * config,
|
||||
char const * document_root);
|
||||
|
||||
extern void wsfs_impl_server_config_set_keypath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void wsfs_impl_server_config_set_certpath(
|
||||
struct wsfs_server_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void wsfs_impl_server_config_set_vhostname(
|
||||
struct wsfs_server_config * config,
|
||||
char const * vhost_name);
|
||||
|
||||
extern void wsfs_impl_server_config_set_port(
|
||||
struct wsfs_server_config * config,
|
||||
int port);
|
||||
|
||||
extern void wsfs_impl_server_config_add_authenticator(
|
||||
struct wsfs_server_config * config,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
166
lib/wsfs/adapter/impl/server_protocol.c
Normal file
166
lib/wsfs/adapter/impl/server_protocol.c
Normal file
@@ -0,0 +1,166 @@
|
||||
#include "wsfs/adapter/impl/server_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/core/message.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
#include "wsfs/adapter/impl/filesystem.h"
|
||||
|
||||
static int wsfs_impl_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wsfs_server_protocol * protocol = ws_protocol->user;
|
||||
|
||||
wsfs_impl_timeout_manager_check(&protocol->timeout_manager);
|
||||
struct wsfs_impl_session * session = wsfs_impl_session_manager_get(&protocol->session_manager, wsi);
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
{
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = wsfs_impl_filesystem_get_fd(&protocol->filesystem);
|
||||
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
|
||||
{
|
||||
fprintf(stderr, "error: unable to adopt fd");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wsfs_impl_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->rpc);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_authenticate(session, NULL);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
wsfs_impl_session_manager_remove(&protocol->session_manager, wsi);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_onwritable(session);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_impl_session_receive(session, in, len);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
wsfs_impl_filesystem_process_request(&protocol->filesystem);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool wsfs_impl_server_protocol_invoke(
|
||||
void * user_data,
|
||||
json_t const * request)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = user_data;
|
||||
struct wsfs_impl_session * session = &protocol->session_manager.session;
|
||||
struct wsfs_message * message = wsfs_message_create(request);
|
||||
|
||||
bool const result = wsfs_impl_session_send(session, message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
if (!wsfs_impl_server_protocol_init(protocol, mount_point))
|
||||
{
|
||||
free(protocol);
|
||||
protocol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_server_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wsfs_impl_server_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
bool wsfs_impl_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point)
|
||||
{
|
||||
wsfs_impl_timeout_manager_init(&protocol->timeout_manager);
|
||||
wsfs_impl_session_manager_init(&protocol->session_manager);
|
||||
wsfs_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
wsfs_impl_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
wsfs_impl_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_impl_server_protocol_invoke, protocol);
|
||||
|
||||
bool const success = wsfs_impl_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
|
||||
|
||||
// cleanup on error
|
||||
if (!success)
|
||||
{
|
||||
wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_impl_filesystem_cleanup(&protocol->filesystem);
|
||||
wsfs_impl_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
void wsfs_impl_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
53
lib/wsfs/adapter/impl/server_protocol.h
Normal file
53
lib/wsfs/adapter/impl/server_protocol.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
#define WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "wsfs/adapter/impl/filesystem.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include "wsfs/adapter/impl/session_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws_protocols;
|
||||
|
||||
struct wsfs_server_protocol
|
||||
{
|
||||
struct wsfs_impl_timeout_manager timeout_manager;
|
||||
struct wsfs_impl_filesystem filesystem;
|
||||
struct wsfs_impl_jsonrpc_server rpc;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_session_manager session_manager;
|
||||
};
|
||||
|
||||
extern bool wsfs_impl_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol);
|
||||
|
||||
extern struct wsfs_server_protocol * wsfs_impl_server_protocol_create(
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_impl_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol);
|
||||
|
||||
extern void wsfs_impl_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
extern void wsfs_impl_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,17 +1,17 @@
|
||||
#include "wsfs/adapter/session.h"
|
||||
#include "wsfs/adapter/authenticators.h"
|
||||
#include "wsfs/message_queue.h"
|
||||
#include "wsfs/message.h"
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/impl/session.h"
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include "wsfs/core/message_queue.h"
|
||||
#include "wsfs/core/message.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void wsfs_session_init(
|
||||
struct wsfs_session * session,
|
||||
void wsfs_impl_session_init(
|
||||
struct wsfs_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_jsonrpc_server * rpc)
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_jsonrpc_server * rpc)
|
||||
{
|
||||
session->wsi = wsi;
|
||||
session->is_authenticated = false;
|
||||
@@ -20,8 +20,8 @@ void wsfs_session_init(
|
||||
wsfs_message_queue_init(&session->queue);
|
||||
}
|
||||
|
||||
void wsfs_session_cleanup(
|
||||
struct wsfs_session * session)
|
||||
void wsfs_impl_session_cleanup(
|
||||
struct wsfs_impl_session * session)
|
||||
{
|
||||
wsfs_message_queue_cleanup(&session->queue);
|
||||
session->is_authenticated = false;
|
||||
@@ -30,15 +30,15 @@ void wsfs_session_cleanup(
|
||||
session->rpc = NULL;
|
||||
}
|
||||
|
||||
void wsfs_session_authenticate(
|
||||
struct wsfs_session * session,
|
||||
void wsfs_impl_session_authenticate(
|
||||
struct wsfs_impl_session * session,
|
||||
struct wsfs_credentials * creds)
|
||||
{
|
||||
session->is_authenticated = wsfs_authenticators_authenticate(session->authenticators, creds);
|
||||
session->is_authenticated = wsfs_impl_authenticators_authenticate(session->authenticators, creds);
|
||||
}
|
||||
|
||||
bool wsfs_session_send(
|
||||
struct wsfs_session * session,
|
||||
bool wsfs_impl_session_send(
|
||||
struct wsfs_impl_session * session,
|
||||
struct wsfs_message * message)
|
||||
{
|
||||
bool result = (session->is_authenticated) && (NULL != session->wsi);
|
||||
@@ -58,8 +58,8 @@ bool wsfs_session_send(
|
||||
return result;
|
||||
}
|
||||
|
||||
void wsfs_session_onwritable(
|
||||
struct wsfs_session * session)
|
||||
void wsfs_impl_session_onwritable(
|
||||
struct wsfs_impl_session * session)
|
||||
{
|
||||
if (!wsfs_message_queue_empty(&session->queue))
|
||||
{
|
||||
@@ -75,10 +75,10 @@ void wsfs_session_onwritable(
|
||||
}
|
||||
|
||||
|
||||
void wsfs_session_receive(
|
||||
struct wsfs_session * session,
|
||||
void wsfs_impl_session_receive(
|
||||
struct wsfs_impl_session * session,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
wsfs_jsonrpc_server_onresult(session->rpc, data, length);
|
||||
wsfs_impl_jsonrpc_server_onresult(session->rpc, data, length);
|
||||
}
|
||||
64
lib/wsfs/adapter/impl/session.h
Normal file
64
lib/wsfs/adapter/impl/session.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SESSION_H
|
||||
#define WSFS_ADAPTER_IMPL_SESSION_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "wsfs/core/message_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wsfs_message;
|
||||
struct wsfs_credentials;
|
||||
struct wsfs_impl_authenticators;
|
||||
struct wsfs_impl_jsonrpc_server;
|
||||
|
||||
struct wsfs_impl_session
|
||||
{
|
||||
struct lws * wsi;
|
||||
bool is_authenticated;
|
||||
struct wsfs_message_queue queue;
|
||||
struct wsfs_impl_authenticators * authenticators;
|
||||
struct wsfs_impl_jsonrpc_server * rpc;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_session_init(
|
||||
struct wsfs_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_jsonrpc_server * rpc);
|
||||
|
||||
extern void wsfs_impl_session_authenticate(
|
||||
struct wsfs_impl_session * session,
|
||||
struct wsfs_credentials * creds);
|
||||
|
||||
extern bool wsfs_impl_session_send(
|
||||
struct wsfs_impl_session * session,
|
||||
struct wsfs_message * message);
|
||||
|
||||
extern void wsfs_impl_session_receive(
|
||||
struct wsfs_impl_session * session,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
extern void wsfs_impl_session_onwritable(
|
||||
struct wsfs_impl_session * session);
|
||||
|
||||
extern void wsfs_impl_session_cleanup(
|
||||
struct wsfs_impl_session * session);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
54
lib/wsfs/adapter/impl/session_manager.c
Normal file
54
lib/wsfs/adapter/impl/session_manager.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "wsfs/adapter/impl/session_manager.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void wsfs_impl_session_manager_init(
|
||||
struct wsfs_impl_session_manager * manager)
|
||||
{
|
||||
wsfs_impl_session_init(&manager->session, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void wsfs_impl_session_manager_cleanup(
|
||||
struct wsfs_impl_session_manager * manager)
|
||||
{
|
||||
wsfs_impl_session_cleanup(&manager->session);
|
||||
}
|
||||
|
||||
struct wsfs_impl_session * wsfs_impl_session_manager_add(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_jsonrpc_server * rpc)
|
||||
{
|
||||
struct wsfs_impl_session * session = NULL;
|
||||
if (NULL == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
wsfs_impl_session_init(&manager->session, wsi, authenticators, rpc);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
struct wsfs_impl_session * wsfs_impl_session_manager_get(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wsfs_impl_session * session = NULL;
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
void wsfs_impl_session_manager_remove(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
wsfs_impl_session_cleanup(&manager->session);
|
||||
manager->session.wsi = NULL;
|
||||
}
|
||||
}
|
||||
46
lib/wsfs/adapter/impl/session_manager.h
Normal file
46
lib/wsfs/adapter/impl/session_manager.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_SESSION_MANAGER_H
|
||||
#define WSFS_ADAPTER_IMPL_SESSION_MANAGER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/impl/session.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
|
||||
struct wsfs_impl_session_manager
|
||||
{
|
||||
struct wsfs_impl_session session;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_session_manager_init(
|
||||
struct wsfs_impl_session_manager * manager);
|
||||
|
||||
extern void wsfs_impl_session_manager_cleanup(
|
||||
struct wsfs_impl_session_manager * manager);
|
||||
|
||||
extern struct wsfs_impl_session * wsfs_impl_session_manager_add(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wsfs_impl_authenticators * authenticators,
|
||||
struct wsfs_impl_jsonrpc_server * rpc);
|
||||
|
||||
extern struct wsfs_impl_session * wsfs_impl_session_manager_get(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
extern void wsfs_impl_session_manager_remove(
|
||||
struct wsfs_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
84
lib/wsfs/adapter/impl/time/timeout_manager.c
Normal file
84
lib/wsfs/adapter/impl/time/timeout_manager.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "wsfs/adapter/impl/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "wsfs/adapter/impl/time/timer_intern.h"
|
||||
#include "wsfs/adapter/impl/time/timepoint.h"
|
||||
|
||||
void wsfs_impl_timeout_manager_init(
|
||||
struct wsfs_impl_timeout_manager * manager)
|
||||
{
|
||||
manager->timers = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_timeout_manager_cleanup(
|
||||
struct wsfs_impl_timeout_manager * manager)
|
||||
{
|
||||
struct wsfs_impl_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wsfs_impl_timer * next = timer->next;
|
||||
|
||||
wsfs_impl_timer_trigger(timer);
|
||||
|
||||
timer = next;
|
||||
}
|
||||
|
||||
manager->timers = NULL;
|
||||
|
||||
}
|
||||
|
||||
void wsfs_impl_timeout_manager_check(
|
||||
struct wsfs_impl_timeout_manager * manager)
|
||||
{
|
||||
struct wsfs_impl_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wsfs_impl_timer * next = timer->next;
|
||||
|
||||
if (wsfs_impl_timer_is_timeout(timer))
|
||||
{
|
||||
wsfs_impl_timeout_manager_removetimer(manager, timer);
|
||||
wsfs_impl_timer_trigger(timer);
|
||||
}
|
||||
|
||||
timer = next;
|
||||
}
|
||||
}
|
||||
|
||||
void wsfs_impl_timeout_manager_addtimer(
|
||||
struct wsfs_impl_timeout_manager * manager,
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
if (NULL != manager->timers)
|
||||
{
|
||||
manager->timers->prev = timer;
|
||||
}
|
||||
|
||||
timer->next = manager->timers;
|
||||
timer->prev = NULL;
|
||||
manager->timers = timer;
|
||||
}
|
||||
|
||||
void wsfs_impl_timeout_manager_removetimer(
|
||||
struct wsfs_impl_timeout_manager * manager,
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
struct wsfs_impl_timer * prev = timer->prev;
|
||||
struct wsfs_impl_timer * next = timer->next;
|
||||
|
||||
if (NULL != prev)
|
||||
{
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
if (NULL != next)
|
||||
{
|
||||
next->prev = prev;
|
||||
}
|
||||
|
||||
if (manager->timers == timer)
|
||||
{
|
||||
manager->timers = next;
|
||||
}
|
||||
}
|
||||
|
||||
29
lib/wsfs/adapter/impl/time/timeout_manager.h
Normal file
29
lib/wsfs/adapter/impl/time/timeout_manager.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_timer;
|
||||
struct wsfs_impl_timeout_manager
|
||||
{
|
||||
struct wsfs_impl_timer * timers;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_timeout_manager_init(
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_timeout_manager_cleanup(
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_timeout_manager_check(
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
24
lib/wsfs/adapter/impl/time/timeout_manager_intern.h
Normal file
24
lib/wsfs/adapter/impl/time/timeout_manager_intern.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_impl_timeout_manager_addtimer(
|
||||
struct wsfs_impl_timeout_manager * manager,
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
extern void wsfs_impl_timeout_manager_removetimer(
|
||||
struct wsfs_impl_timeout_manager * manager,
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
31
lib/wsfs/adapter/impl/time/timepoint.c
Normal file
31
lib/wsfs/adapter/impl/time/timepoint.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "wsfs/adapter/impl/time/timepoint.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define WSFS_MSEC_PER_SEC ((wsfs_impl_timepoint) 1000)
|
||||
#define WSFS_NSEC_PER_MSEC ((wsfs_impl_timepoint) 1000 * 1000)
|
||||
|
||||
wsfs_impl_timepoint wsfs_impl_timepoint_now(void)
|
||||
{
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
|
||||
wsfs_impl_timepoint const now = (tp.tv_sec * WSFS_MSEC_PER_SEC) + (tp.tv_nsec / WSFS_NSEC_PER_MSEC);
|
||||
return now;
|
||||
}
|
||||
|
||||
wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(wsfs_impl_timediff value)
|
||||
{
|
||||
wsfs_impl_timepoint const now = wsfs_impl_timepoint_now();
|
||||
wsfs_impl_timepoint result = now + ((wsfs_impl_timepoint) value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool wsfs_impl_timepoint_is_elapsed(wsfs_impl_timepoint tp)
|
||||
{
|
||||
wsfs_impl_timepoint const now = wsfs_impl_timepoint_now();
|
||||
wsfs_impl_timediff const diff = (wsfs_impl_timediff) (tp - now);
|
||||
|
||||
return (0 > diff);
|
||||
}
|
||||
31
lib/wsfs/adapter/impl/time/timepoint.h
Normal file
31
lib/wsfs/adapter/impl/time/timepoint.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef uint64_t wsfs_impl_timepoint;
|
||||
typedef int64_t wsfs_impl_timediff;
|
||||
|
||||
extern wsfs_impl_timepoint wsfs_impl_timepoint_now(void);
|
||||
|
||||
extern wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(
|
||||
wsfs_impl_timediff value);
|
||||
|
||||
extern bool wsfs_impl_timepoint_is_elapsed(
|
||||
wsfs_impl_timepoint timepoint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
65
lib/wsfs/adapter/impl/time/timer.c
Normal file
65
lib/wsfs/adapter/impl/time/timer.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "wsfs/adapter/impl/time/timer_intern.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void wsfs_impl_timer_init(
|
||||
struct wsfs_impl_timer * timer,
|
||||
struct wsfs_impl_timeout_manager * manager)
|
||||
{
|
||||
timer->manager = manager;
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
}
|
||||
|
||||
void wsfs_impl_timer_cleanup(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
memset(timer, 0, sizeof(struct wsfs_impl_timer));
|
||||
}
|
||||
|
||||
void wsfs_impl_timer_start(
|
||||
struct wsfs_impl_timer * timer,
|
||||
wsfs_impl_timepoint absolute_timeout,
|
||||
wsfs_impl_timer_timeout_fn * handler,
|
||||
void * user_data)
|
||||
{
|
||||
timer->timeout = absolute_timeout;
|
||||
timer->timeout_handler = handler;
|
||||
timer->user_data = user_data;
|
||||
|
||||
wsfs_impl_timeout_manager_addtimer(timer->manager, timer);
|
||||
}
|
||||
|
||||
void wsfs_impl_timer_cancel(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
wsfs_impl_timeout_manager_removetimer(timer->manager, timer);
|
||||
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
}
|
||||
|
||||
bool wsfs_impl_timer_is_timeout(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
return wsfs_impl_timepoint_is_elapsed(timer->timeout);
|
||||
}
|
||||
|
||||
|
||||
void wsfs_impl_timer_trigger(
|
||||
struct wsfs_impl_timer * timer)
|
||||
{
|
||||
if (NULL != timer->timeout_handler)
|
||||
{
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
|
||||
timer->timeout_handler(timer);
|
||||
}
|
||||
}
|
||||
48
lib/wsfs/adapter/impl/time/timer.h
Normal file
48
lib/wsfs/adapter/impl/time/timer.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMER_H
|
||||
|
||||
#include "wsfs/adapter/impl/time/timepoint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfs_impl_timer;
|
||||
struct wsfs_impl_timeout_manager;
|
||||
|
||||
typedef void wsfs_impl_timer_timeout_fn(struct wsfs_impl_timer * timer);
|
||||
|
||||
struct wsfs_impl_timer
|
||||
{
|
||||
struct wsfs_impl_timeout_manager * manager;
|
||||
wsfs_impl_timepoint timeout;
|
||||
wsfs_impl_timer_timeout_fn * timeout_handler;
|
||||
void * user_data;
|
||||
struct wsfs_impl_timer * next;
|
||||
struct wsfs_impl_timer * prev;
|
||||
};
|
||||
|
||||
extern void wsfs_impl_timer_init(
|
||||
struct wsfs_impl_timer * timer,
|
||||
struct wsfs_impl_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_impl_timer_cleanup(
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
extern void wsfs_impl_timer_start(
|
||||
struct wsfs_impl_timer * timer,
|
||||
wsfs_impl_timepoint absolute_timeout,
|
||||
wsfs_impl_timer_timeout_fn * handler,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_impl_timer_cancel(
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
25
lib/wsfs/adapter/impl/time/timer_intern.h
Normal file
25
lib/wsfs/adapter/impl/time/timer_intern.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
|
||||
#define WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/impl/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wsfs_impl_timer_is_timeout(
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
extern void wsfs_impl_timer_trigger(
|
||||
struct wsfs_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,28 +0,0 @@
|
||||
#include "wsfs/adapter/jsonrpc/method_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfs_jsonrpc_method * method = malloc(sizeof(struct wsfs_jsonrpc_method));
|
||||
if (NULL != method)
|
||||
{
|
||||
method->next = NULL;
|
||||
method->name = strdup(name);
|
||||
method->invoke = invoke;
|
||||
method->user_data = user_data;
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
void wsfs_jsonrpc_method_dispose(
|
||||
struct wsfs_jsonrpc_method * method)
|
||||
{
|
||||
free(method->name);
|
||||
free(method);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_METHOD_H
|
||||
#define WSFS_ADAPTER_JSONRPC_METHOD_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/status.h"
|
||||
|
||||
|
||||
typedef bool wsfs_jsonrpc_method_invoke_fn(
|
||||
void * user_data,
|
||||
struct json_t const * method_call);
|
||||
|
||||
typedef void wsfs_jsonrpc_method_finished_fn(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
struct json_t const * result);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H
|
||||
#define WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/method.h"
|
||||
|
||||
struct wsfs_jsonrpc_method
|
||||
{
|
||||
struct wsfs_jsonrpc_method * next;
|
||||
char * name;
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wsfs_jsonrpc_method * wsfs_jsonrpc_method_create(
|
||||
char const * name,
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_jsonrpc_method_dispose(
|
||||
struct wsfs_jsonrpc_method * method);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_RESPONSE_H
|
||||
#define WSFS_ADAPTER_JSONRPC_RESPONSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/status.h"
|
||||
|
||||
struct wsfs_jsonrpc_response
|
||||
{
|
||||
wsfs_status status;
|
||||
int id;
|
||||
json_t * result;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void wsfs_jsonrpc_response_init(
|
||||
struct wsfs_jsonrpc_response * response,
|
||||
char const * buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
extern void wsfs_jsonrpc_response_cleanup(
|
||||
struct wsfs_jsonrpc_response * response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSONRPC_SERVER_H
|
||||
#define WSFS_ADAPTER_JSONRPC_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfs/adapter/jsonrpc/method.h"
|
||||
#include "wsfs/adapter/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/time/timer.h"
|
||||
|
||||
|
||||
struct wsfs_jsonrpc_request
|
||||
{
|
||||
bool is_pending;
|
||||
wsfs_jsonrpc_method_finished_fn * finished;
|
||||
void * user_data;
|
||||
int id;
|
||||
struct wsfs_timer timer;
|
||||
};
|
||||
|
||||
struct wsfs_jsonrpc_server
|
||||
{
|
||||
struct wsfs_jsonrpc_method * methods;
|
||||
struct wsfs_jsonrpc_request request;
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_jsonrpc_server_init(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_jsonrpc_server_cleanup(
|
||||
struct wsfs_jsonrpc_server * server);
|
||||
|
||||
extern void wsfs_jsonrpc_server_add(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * name,
|
||||
wsfs_jsonrpc_method_invoke_fn * invoke,
|
||||
void * user_data );
|
||||
|
||||
extern void wsfs_jsonrpc_server_invoke(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
wsfs_jsonrpc_method_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_jsonrpc_server_notify(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_jsonrpc_server_onresult(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * message,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_JSON_UTIL_H
|
||||
#define WSFS_ADAPTER_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int wsfs_json_get_int(json_t const * object, char const * key, int default_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "wsfs/adapter/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
void wsfs_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wsfs_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_SERVER_CONFIG_INTERN_H
|
||||
#define WSFS_ADAPTER_SERVER_CONFIG_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/server_config.h"
|
||||
#include "wsfs/adapter/authenticators.h"
|
||||
|
||||
struct wsfs_server_config
|
||||
{
|
||||
char * mount_point;
|
||||
char * document_root;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * vhost_name;
|
||||
int port;
|
||||
struct wsfs_authenticators authenticators;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_server_config_init(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_server_config_cleanup(
|
||||
struct wsfs_server_config * config);
|
||||
|
||||
extern void wsfs_server_config_clone(
|
||||
struct wsfs_server_config * config,
|
||||
struct wsfs_server_config * clone);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,166 +0,0 @@
|
||||
#include "wsfs/adapter/server_protocol_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/message.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
#include "wsfs/adapter/filesystem.h"
|
||||
|
||||
static int wsfs_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wsfs_server_protocol * protocol = ws_protocol->user;
|
||||
|
||||
wsfs_timeout_manager_check(&protocol->timeout_manager);
|
||||
struct wsfs_session * session = wsfs_session_manager_get(&protocol->session_manager, wsi);
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
{
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = wsfs_filesystem_get_fd(&protocol->filesystem);
|
||||
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
|
||||
{
|
||||
fprintf(stderr, "error: unable to adopt fd");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wsfs_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->rpc);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_session_authenticate(session, NULL);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
wsfs_session_manager_remove(&protocol->session_manager, wsi);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_session_onwritable(session);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wsfs_session_receive(session, in, len);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
wsfs_filesystem_process_request(&protocol->filesystem);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool wsfs_server_protocol_invoke(
|
||||
void * user_data,
|
||||
json_t const * request)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = user_data;
|
||||
struct wsfs_session * session = &protocol->session_manager.session;
|
||||
struct wsfs_message * message = wsfs_message_create(request);
|
||||
|
||||
bool const result = wsfs_session_send(session, message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct wsfs_server_protocol * wsfs_server_protocol_create(
|
||||
char * mount_point)
|
||||
{
|
||||
struct wsfs_server_protocol * protocol = malloc(sizeof(struct wsfs_server_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
if (!wsfs_server_protocol_init(protocol, mount_point))
|
||||
{
|
||||
free(protocol);
|
||||
protocol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_dispose(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_server_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_init_lws(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wsfs_server_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
bool wsfs_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point)
|
||||
{
|
||||
wsfs_timeout_manager_init(&protocol->timeout_manager);
|
||||
wsfs_session_manager_init(&protocol->session_manager);
|
||||
wsfs_authenticators_init(&protocol->authenticators);
|
||||
|
||||
wsfs_jsonrpc_server_init(&protocol->rpc, &protocol->timeout_manager);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_server_protocol_invoke, protocol);
|
||||
wsfs_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_server_protocol_invoke, protocol);
|
||||
|
||||
bool const success = wsfs_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
|
||||
|
||||
// cleanup on error
|
||||
if (!success)
|
||||
{
|
||||
wsfs_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol)
|
||||
{
|
||||
wsfs_filesystem_cleanup(&protocol->filesystem);
|
||||
wsfs_jsonrpc_server_cleanup(&protocol->rpc);
|
||||
wsfs_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wsfs_authenticators_cleanup(&protocol->authenticators);
|
||||
wsfs_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
void wsfs_server_protocol_add_authenticator(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char const * type,
|
||||
wsfs_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wsfs_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H
|
||||
#define WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/server_protocol.h"
|
||||
#include "wsfs/adapter/filesystem.h"
|
||||
#include "wsfs/adapter/jsonrpc/server.h"
|
||||
#include "wsfs/adapter/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/authenticators.h"
|
||||
#include "wsfs/adapter/session_manager.h"
|
||||
|
||||
struct wsfs_server_protocol
|
||||
{
|
||||
struct wsfs_timeout_manager timeout_manager;
|
||||
struct wsfs_filesystem filesystem;
|
||||
struct wsfs_jsonrpc_server rpc;
|
||||
struct wsfs_authenticators authenticators;
|
||||
struct wsfs_session_manager session_manager;
|
||||
};
|
||||
|
||||
extern bool wsfs_server_protocol_init(
|
||||
struct wsfs_server_protocol * protocol,
|
||||
char * mount_point);
|
||||
|
||||
extern void wsfs_server_protocol_cleanup(
|
||||
struct wsfs_server_protocol * protocol);
|
||||
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_SESSION_H
|
||||
#define WSFS_ADAPTER_SESSION_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "wsfs/message_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wsfs_message;
|
||||
struct wsfs_credentials;
|
||||
struct wsfs_authenticators;
|
||||
struct wsfs_jsonrpc_server;
|
||||
|
||||
struct wsfs_session
|
||||
{
|
||||
struct lws * wsi;
|
||||
bool is_authenticated;
|
||||
struct wsfs_message_queue queue;
|
||||
struct wsfs_authenticators * authenticators;
|
||||
struct wsfs_jsonrpc_server * rpc;
|
||||
};
|
||||
|
||||
extern void wsfs_session_init(
|
||||
struct wsfs_session * session,
|
||||
struct lws * wsi,
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_jsonrpc_server * rpc);
|
||||
|
||||
extern void wsfs_session_authenticate(
|
||||
struct wsfs_session * session,
|
||||
struct wsfs_credentials * creds);
|
||||
|
||||
extern bool wsfs_session_send(
|
||||
struct wsfs_session * session,
|
||||
struct wsfs_message * message);
|
||||
|
||||
extern void wsfs_session_receive(
|
||||
struct wsfs_session * session,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
extern void wsfs_session_onwritable(
|
||||
struct wsfs_session * session);
|
||||
|
||||
extern void wsfs_session_cleanup(
|
||||
struct wsfs_session * session);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,54 +0,0 @@
|
||||
#include "wsfs/adapter/session_manager.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void wsfs_session_manager_init(
|
||||
struct wsfs_session_manager * manager)
|
||||
{
|
||||
wsfs_session_init(&manager->session, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void wsfs_session_manager_cleanup(
|
||||
struct wsfs_session_manager * manager)
|
||||
{
|
||||
wsfs_session_cleanup(&manager->session);
|
||||
}
|
||||
|
||||
struct wsfs_session * wsfs_session_manager_add(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_jsonrpc_server * rpc)
|
||||
{
|
||||
struct wsfs_session * session = NULL;
|
||||
if (NULL == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
wsfs_session_init(&manager->session, wsi, authenticators, rpc);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
struct wsfs_session * wsfs_session_manager_get(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wsfs_session * session = NULL;
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
void wsfs_session_manager_remove(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
if (wsi == manager->session.wsi)
|
||||
{
|
||||
wsfs_session_cleanup(&manager->session);
|
||||
manager->session.wsi = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_SESSION_MANAGER_H
|
||||
#define WSFS_ADAPTER_SESSION_MANAGER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/session.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
|
||||
struct wsfs_session_manager
|
||||
{
|
||||
struct wsfs_session session;
|
||||
};
|
||||
|
||||
extern void wsfs_session_manager_init(
|
||||
struct wsfs_session_manager * manager);
|
||||
|
||||
extern void wsfs_session_manager_cleanup(
|
||||
struct wsfs_session_manager * manager);
|
||||
|
||||
extern struct wsfs_session * wsfs_session_manager_add(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wsfs_authenticators * authenticators,
|
||||
struct wsfs_jsonrpc_server * rpc);
|
||||
|
||||
extern struct wsfs_session * wsfs_session_manager_get(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
extern void wsfs_session_manager_remove(
|
||||
struct wsfs_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,84 +0,0 @@
|
||||
#include "wsfs/adapter/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "wsfs/adapter/time/timer_intern.h"
|
||||
#include "wsfs/adapter/time/timepoint.h"
|
||||
|
||||
void wsfs_timeout_manager_init(
|
||||
struct wsfs_timeout_manager * manager)
|
||||
{
|
||||
manager->timers = NULL;
|
||||
}
|
||||
|
||||
void wsfs_timeout_manager_cleanup(
|
||||
struct wsfs_timeout_manager * manager)
|
||||
{
|
||||
struct wsfs_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wsfs_timer * next = timer->next;
|
||||
|
||||
wsfs_timer_trigger(timer);
|
||||
|
||||
timer = next;
|
||||
}
|
||||
|
||||
manager->timers = NULL;
|
||||
|
||||
}
|
||||
|
||||
void wsfs_timeout_manager_check(
|
||||
struct wsfs_timeout_manager * manager)
|
||||
{
|
||||
struct wsfs_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wsfs_timer * next = timer->next;
|
||||
|
||||
if (wsfs_timer_is_timeout(timer))
|
||||
{
|
||||
wsfs_timeout_manager_removetimer(manager, timer);
|
||||
wsfs_timer_trigger(timer);
|
||||
}
|
||||
|
||||
timer = next;
|
||||
}
|
||||
}
|
||||
|
||||
void wsfs_timeout_manager_addtimer(
|
||||
struct wsfs_timeout_manager * manager,
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
if (NULL != manager->timers)
|
||||
{
|
||||
manager->timers->prev = timer;
|
||||
}
|
||||
|
||||
timer->next = manager->timers;
|
||||
timer->prev = NULL;
|
||||
manager->timers = timer;
|
||||
}
|
||||
|
||||
void wsfs_timeout_manager_removetimer(
|
||||
struct wsfs_timeout_manager * manager,
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
struct wsfs_timer * prev = timer->prev;
|
||||
struct wsfs_timer * next = timer->next;
|
||||
|
||||
if (NULL != prev)
|
||||
{
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
if (NULL != next)
|
||||
{
|
||||
next->prev = prev;
|
||||
}
|
||||
|
||||
if (manager->timers == timer)
|
||||
{
|
||||
manager->timers = next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H
|
||||
#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H
|
||||
|
||||
struct wsfs_timer;
|
||||
struct wsfs_timeout_manager
|
||||
{
|
||||
struct wsfs_timer * timers;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_timeout_manager_init(
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_timeout_manager_cleanup(
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_timeout_manager_check(
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
|
||||
#include "wsfs/adapter/time/timeout_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_timeout_manager_addtimer(
|
||||
struct wsfs_timeout_manager * manager,
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
extern void wsfs_timeout_manager_removetimer(
|
||||
struct wsfs_timeout_manager * manager,
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "wsfs/adapter/time/timepoint.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define WSFS_MSEC_PER_SEC ((wsfs_timepoint) 1000)
|
||||
#define WSFS_NSEC_PER_MSEC ((wsfs_timepoint) 1000 * 1000)
|
||||
|
||||
wsfs_timepoint wsfs_timepoint_now(void)
|
||||
{
|
||||
struct timespec timepoint;
|
||||
clock_gettime(CLOCK_MONOTONIC, &timepoint);
|
||||
|
||||
wsfs_timepoint const now = (timepoint.tv_sec * WSFS_MSEC_PER_SEC) + (timepoint.tv_nsec / WSFS_NSEC_PER_MSEC);
|
||||
return now;
|
||||
}
|
||||
|
||||
wsfs_timepoint wsfs_timepoint_in_msec(wsfs_timediff value)
|
||||
{
|
||||
wsfs_timepoint const now = wsfs_timepoint_now();
|
||||
wsfs_timepoint result = now + ((wsfs_timepoint) value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool wsfs_timepoint_is_elapsed(wsfs_timepoint timepoint)
|
||||
{
|
||||
wsfs_timepoint const now = wsfs_timepoint_now();
|
||||
wsfs_timediff const diff = (wsfs_timediff) (timepoint - now);
|
||||
|
||||
return (0 > diff);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMEPOINT_H
|
||||
#define WSFS_ADAPTER_TIME_TIMEPOINT_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
typedef uint64_t wsfs_timepoint;
|
||||
typedef int64_t wsfs_timediff;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern wsfs_timepoint wsfs_timepoint_now(void);
|
||||
|
||||
extern wsfs_timepoint wsfs_timepoint_in_msec(
|
||||
wsfs_timediff value);
|
||||
|
||||
extern bool wsfs_timepoint_is_elapsed(
|
||||
wsfs_timepoint timepoint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,65 +0,0 @@
|
||||
#include "wsfs/adapter/time/timer_intern.h"
|
||||
#include "wsfs/adapter/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void wsfs_timer_init(
|
||||
struct wsfs_timer * timer,
|
||||
struct wsfs_timeout_manager * manager)
|
||||
{
|
||||
timer->manager = manager;
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
}
|
||||
|
||||
void wsfs_timer_cleanup(
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
memset(timer, 0, sizeof(struct wsfs_timer));
|
||||
}
|
||||
|
||||
void wsfs_timer_start(
|
||||
struct wsfs_timer * timer,
|
||||
wsfs_timepoint absolute_timeout,
|
||||
wsfs_timer_timeout_fn * handler,
|
||||
void * user_data)
|
||||
{
|
||||
timer->timeout = absolute_timeout;
|
||||
timer->timeout_handler = handler;
|
||||
timer->user_data = user_data;
|
||||
|
||||
wsfs_timeout_manager_addtimer(timer->manager, timer);
|
||||
}
|
||||
|
||||
void wsfs_timer_cancel(
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
wsfs_timeout_manager_removetimer(timer->manager, timer);
|
||||
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
}
|
||||
|
||||
bool wsfs_timer_is_timeout(
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
return wsfs_timepoint_is_elapsed(timer->timeout);
|
||||
}
|
||||
|
||||
|
||||
void wsfs_timer_trigger(
|
||||
struct wsfs_timer * timer)
|
||||
{
|
||||
if (NULL != timer->timeout_handler)
|
||||
{
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
|
||||
timer->timeout_handler(timer);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMER_H
|
||||
#define WSFS_ADAPTER_TIME_TIMER_H
|
||||
|
||||
#include "wsfs/adapter/time/timepoint.h"
|
||||
|
||||
struct wsfs_timer;
|
||||
struct wsfs_timeout_manager;
|
||||
|
||||
typedef void wsfs_timer_timeout_fn(struct wsfs_timer * timer);
|
||||
|
||||
struct wsfs_timer
|
||||
{
|
||||
struct wsfs_timeout_manager * manager;
|
||||
wsfs_timepoint timeout;
|
||||
wsfs_timer_timeout_fn * timeout_handler;
|
||||
void * user_data;
|
||||
struct wsfs_timer * next;
|
||||
struct wsfs_timer * prev;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfs_timer_init(
|
||||
struct wsfs_timer * timer,
|
||||
struct wsfs_timeout_manager * manager);
|
||||
|
||||
extern void wsfs_timer_cleanup(
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
extern void wsfs_timer_start(
|
||||
struct wsfs_timer * timer,
|
||||
wsfs_timepoint absolute_timeout,
|
||||
wsfs_timer_timeout_fn * handler,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfs_timer_cancel(
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef WSFS_ADAPTER_TIME_TIMER_INTERN_H
|
||||
#define WSFS_ADAPTER_TIME_TIMER_INTERN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "wsfs/adapter/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wsfs_timer_is_timeout(
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
extern void wsfs_timer_trigger(
|
||||
struct wsfs_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/message.h"
|
||||
#include "wsfs/core/message.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "wsfs/message_queue.h"
|
||||
#include "wsfs/message.h"
|
||||
#include "wsfs/core/message_queue.h"
|
||||
#include "wsfs/core/message.h"
|
||||
|
||||
void wsfs_message_queue_init(
|
||||
struct wsfs_message_queue * queue)
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/status_intern.h"
|
||||
#include "wsfs/core/status_intern.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef WSFS_STATUS_INTERN_H
|
||||
#define WSFS_STATUS_INTERN_H
|
||||
|
||||
#include "wsfs/status.h"
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
240
lib/wsfs/provider/api.c
Normal file
240
lib/wsfs/provider/api.c
Normal file
@@ -0,0 +1,240 @@
|
||||
#include "wsfs_provider.h"
|
||||
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/provider/impl/operation/getattr.h"
|
||||
#include "wsfs/provider/impl/operation/lookup.h"
|
||||
#include "wsfs/provider/impl/operation/readdir.h"
|
||||
#include "wsfs/provider/impl/operation/open.h"
|
||||
#include "wsfs/provider/impl/operation/close.h"
|
||||
#include "wsfs/provider/impl/operation/read.h"
|
||||
#include "wsfs/provider/impl/client_protocol.h"
|
||||
#include "wsfs/provider/impl/client_config.h"
|
||||
#include "wsfs/provider/impl/client.h"
|
||||
#include "wsfs/provider/impl/dirbuffer.h"
|
||||
|
||||
// respond
|
||||
|
||||
void wsfsp_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
wsfs_status status)
|
||||
{
|
||||
wsfsp_impl_respond_error(request, status);
|
||||
}
|
||||
|
||||
void wsfsp_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
wsfsp_impl_respond_getattr(request, stat);
|
||||
}
|
||||
|
||||
void wsfsp_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
wsfsp_impl_respond_lookup(request, stat);
|
||||
}
|
||||
|
||||
void wsfsp_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
wsfsp_impl_respond_open(request, handle);
|
||||
}
|
||||
|
||||
void wsfsp_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
wsfsp_impl_respond_read(request, data, length);
|
||||
}
|
||||
|
||||
void wsfsp_respond_readdir(
|
||||
struct wsfsp_request * request,
|
||||
struct wsfsp_dirbuffer * dirbuffer)
|
||||
{
|
||||
wsfsp_impl_respond_readdir(request, dirbuffer);
|
||||
}
|
||||
|
||||
// config
|
||||
|
||||
|
||||
struct wsfsp_client_config * wsfsp_client_config_create(void)
|
||||
{
|
||||
return wsfsp_impl_client_config_create();
|
||||
}
|
||||
|
||||
void wsfsp_client_config_dispose(
|
||||
struct wsfsp_client_config * config)
|
||||
{
|
||||
wsfsp_impl_client_config_dispose(config);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_userdata(
|
||||
struct wsfsp_client_config * config,
|
||||
void * user_data)
|
||||
{
|
||||
wsfsp_impl_client_config_set_userdata(config, user_data);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_keypath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wsfsp_impl_client_config_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_certpath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wsfsp_impl_client_config_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_connected_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onconnected(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ondisconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_disconnected_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_ondisconnected(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ontimer(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_ontimer_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_ontimer(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onlookup(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_lookup_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onlookup(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ongetattr(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_getattr_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_ongetattr(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onreaddir(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_readdir_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onreaddir(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onopen(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_open_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onopen(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onclose(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_close_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onclose(config, handler);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onread(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_read_fn * handler)
|
||||
{
|
||||
wsfsp_impl_client_config_set_onread(config, handler);
|
||||
}
|
||||
|
||||
// protocol
|
||||
|
||||
|
||||
struct wsfsp_client_protocol * wsfsp_client_protocol_create(
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
return wsfsp_impl_client_protocol_create(provider, user_data);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_dispose(
|
||||
struct wsfsp_client_protocol * protocol)
|
||||
{
|
||||
wsfsp_impl_client_protocol_dispose(protocol);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_init_lws(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
wsfsp_impl_client_protocol_init_lws(protocol, lws_protocol);
|
||||
}
|
||||
|
||||
// client
|
||||
|
||||
struct wsfsp_client * wsfsp_client_create(
|
||||
struct wsfsp_client_config * config)
|
||||
{
|
||||
return wsfsp_impl_client_create(config);
|
||||
}
|
||||
|
||||
void wsfsp_client_connect(
|
||||
struct wsfsp_client * client,
|
||||
char const * url)
|
||||
{
|
||||
wsfsp_impl_client_connect(client, url);
|
||||
}
|
||||
|
||||
void wsfsp_client_disconnect(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
wsfsp_impl_client_disconnect(client);
|
||||
}
|
||||
|
||||
void wsfsp_client_dispose(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
wsfsp_impl_client_dispose(client);
|
||||
}
|
||||
|
||||
void wsfsp_client_run(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
wsfsp_impl_client_run(client);
|
||||
}
|
||||
|
||||
void wsfsp_client_shutdown(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
wsfsp_impl_client_shutdown(client);
|
||||
}
|
||||
|
||||
// dirbuffer
|
||||
|
||||
struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void)
|
||||
{
|
||||
return wsfsp_impl_dirbuffer_create();
|
||||
}
|
||||
|
||||
void wsfsp_dirbuffer_dispose(
|
||||
struct wsfsp_dirbuffer * buffer)
|
||||
{
|
||||
wsfsp_impl_dirbuffer_dispose(buffer);
|
||||
}
|
||||
|
||||
void wsfsp_dirbuffer_add(
|
||||
struct wsfsp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode)
|
||||
{
|
||||
wsfsp_impl_dirbuffer_add(buffer, name, inode);
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_CLIENT_CONFIG_INTERN_H
|
||||
#define WSFS_PROVIDER_CLIENT_CONFIG_INTERN_H
|
||||
|
||||
#include "wsfs/provider/client_config.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
|
||||
struct wsfsp_client_config
|
||||
{
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_CLIENT_PROTOCOL_INTERN_H
|
||||
#define WSFS_PROVIDER_CLIENT_PROTOCOL_INTERN_H
|
||||
|
||||
#include "wsfs/provider/client_protocol.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
|
||||
#include "wsfs/message_queue.h"
|
||||
|
||||
struct wsfsp_client_protocol
|
||||
{
|
||||
struct wsfsp_request request;
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
struct lws * wsi;
|
||||
struct wsfs_message_queue queue;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_client_protocol_init(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_client_protocol_cleanup(
|
||||
struct wsfsp_client_protocol * protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef WSFS_PROVIDER_DIRBUFFER_INTERN_H
|
||||
#define WSFS_PROVIDER_DIRBUFFER_INTERN_H
|
||||
|
||||
#include "wsfs/provider/dirbuffer.h"
|
||||
#include <jansson.h>
|
||||
|
||||
struct wsfsp_dirbuffer
|
||||
{
|
||||
json_t * entries;
|
||||
};
|
||||
|
||||
extern json_t * wsfsp_dirbuffer_take(
|
||||
struct wsfsp_dirbuffer * buffer);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/provider/client.h"
|
||||
#include "wsfs/provider/impl/client.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfs/provider/provider.h"
|
||||
#include "wsfs/provider/client_protocol_intern.h"
|
||||
#include "wsfs/provider/client_config_intern.h"
|
||||
#include "wsfs/provider/url.h"
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include "wsfs/provider/impl/client_protocol.h"
|
||||
#include "wsfs/provider/impl/client_config.h"
|
||||
#include "wsfs/provider/impl/url.h"
|
||||
|
||||
#define WSFSP_PROTOCOL ("fs")
|
||||
#define WSFSP_DISABLE_LWS_LOG 0
|
||||
@@ -28,7 +28,7 @@ struct wsfsp_client
|
||||
};
|
||||
|
||||
|
||||
struct wsfsp_client * wsfsp_client_create(
|
||||
struct wsfsp_client * wsfsp_impl_client_create(
|
||||
struct wsfsp_client_config * config)
|
||||
{
|
||||
lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL);
|
||||
@@ -37,11 +37,11 @@ struct wsfsp_client * wsfsp_client_create(
|
||||
if (NULL != client)
|
||||
{
|
||||
client->is_running = true;
|
||||
wsfsp_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
||||
wsfsp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
||||
|
||||
memset(client->protocols, 0, sizeof(struct lws_protocols) * WSFSP_CLIENT_PROTOCOL_COUNT);
|
||||
client->protocols[0].name = "fs";
|
||||
wsfsp_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||
wsfsp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||
|
||||
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
|
||||
client->info.port = CONTEXT_PORT_NO_LISTEN;
|
||||
@@ -60,20 +60,20 @@ struct wsfsp_client * wsfsp_client_create(
|
||||
return client;
|
||||
}
|
||||
|
||||
void wsfsp_client_dispose(
|
||||
void wsfsp_impl_client_dispose(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
lws_context_destroy(client->context);
|
||||
wsfsp_client_protocol_cleanup(&client->protocol);
|
||||
wsfsp_impl_client_protocol_cleanup(&client->protocol);
|
||||
free(client);
|
||||
}
|
||||
|
||||
void wsfsp_client_connect(
|
||||
void wsfsp_impl_client_connect(
|
||||
struct wsfsp_client * client,
|
||||
char const * url)
|
||||
{
|
||||
struct wsfsp_url url_data;
|
||||
bool const success = wsfsp_url_init(&url_data, url);
|
||||
struct wsfsp_impl_url url_data;
|
||||
bool const success = wsfsp_impl_url_init(&url_data, url);
|
||||
if (success)
|
||||
{
|
||||
struct lws_client_connect_info info;
|
||||
@@ -90,11 +90,11 @@ void wsfsp_client_connect(
|
||||
|
||||
lws_client_connect_via_info(&info);
|
||||
|
||||
wsfsp_url_cleanup(&url_data);
|
||||
wsfsp_impl_url_cleanup(&url_data);
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_client_disconnect(
|
||||
void wsfsp_impl_client_disconnect(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
(void) client;
|
||||
@@ -102,7 +102,7 @@ void wsfsp_client_disconnect(
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void wsfsp_client_run(
|
||||
void wsfsp_impl_client_run(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
while (client->is_running)
|
||||
@@ -111,7 +111,7 @@ void wsfsp_client_run(
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_client_shutdown(
|
||||
void wsfsp_impl_client_shutdown(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
client->is_running = false;
|
||||
49
lib/wsfs/provider/impl/client.h
Normal file
49
lib/wsfs/provider/impl/client.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_CLIENT_H
|
||||
#define WSFS_PROVIDER_IMPL_CLIENT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_client;
|
||||
struct wsfsp_client_config;
|
||||
|
||||
extern struct wsfsp_client * wsfsp_impl_client_create(
|
||||
struct wsfsp_client_config * config);
|
||||
|
||||
extern void wsfsp_impl_client_set_keypath(
|
||||
struct wsfsp_client * client,
|
||||
char * key_path);
|
||||
|
||||
extern void wsfsp_impl_client_set_certpath(
|
||||
struct wsfsp_client * client,
|
||||
char * cert_path);
|
||||
|
||||
extern void wsfsp_impl_client_connect(
|
||||
struct wsfsp_client * client,
|
||||
char const * url);
|
||||
|
||||
extern void wsfsp_impl_client_disconnect(
|
||||
struct wsfsp_client * client);
|
||||
|
||||
extern void wsfsp_impl_client_settimeout(
|
||||
struct wsfsp_client * client,
|
||||
unsigned int timepoint);
|
||||
|
||||
extern void wsfsp_impl_client_dispose(
|
||||
struct wsfsp_client * client);
|
||||
|
||||
extern void wsfsp_impl_client_run(
|
||||
struct wsfsp_client * client);
|
||||
|
||||
extern void wsfsp_impl_client_shutdown(
|
||||
struct wsfsp_client * client);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "wsfs/provider/client_config_intern.h"
|
||||
#include "wsfs/provider/provider.h"
|
||||
#include "wsfs/provider/impl/client_config.h"
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wsfsp_client_config * wsfsp_client_config_create(void)
|
||||
struct wsfsp_client_config * wsfsp_impl_client_config_create(void)
|
||||
{
|
||||
struct wsfsp_client_config * config = malloc(sizeof(struct wsfsp_client_config));
|
||||
if (NULL != config)
|
||||
{
|
||||
wsfsp_provider_init(&config->provider);
|
||||
wsfsp_impl_provider_init(&config->provider);
|
||||
config->user_data = NULL;
|
||||
config->key_path = NULL;
|
||||
config->cert_path = NULL;
|
||||
@@ -17,7 +17,7 @@ struct wsfsp_client_config * wsfsp_client_config_create(void)
|
||||
return config;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_dispose(
|
||||
void wsfsp_impl_client_config_dispose(
|
||||
struct wsfsp_client_config * config)
|
||||
{
|
||||
free(config->key_path);
|
||||
@@ -25,14 +25,14 @@ void wsfsp_client_config_dispose(
|
||||
free(config);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_userdata(
|
||||
void wsfsp_impl_client_config_set_userdata(
|
||||
struct wsfsp_client_config * config,
|
||||
void * user_data)
|
||||
{
|
||||
config->user_data = user_data;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_keypath(
|
||||
void wsfsp_impl_client_config_set_keypath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
@@ -40,7 +40,7 @@ void wsfsp_client_config_set_keypath(
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_certpath(
|
||||
void wsfsp_impl_client_config_set_certpath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
@@ -48,63 +48,63 @@ void wsfsp_client_config_set_certpath(
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onconnected(
|
||||
void wsfsp_impl_client_config_set_onconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_connected_fn * handler)
|
||||
{
|
||||
config->provider.connected = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ondisconnected(
|
||||
void wsfsp_impl_client_config_set_ondisconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_disconnected_fn * handler)
|
||||
{
|
||||
config->provider.disconnected = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ontimer(
|
||||
void wsfsp_impl_client_config_set_ontimer(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_ontimer_fn * handler)
|
||||
{
|
||||
config->provider.ontimer = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onlookup(
|
||||
void wsfsp_impl_client_config_set_onlookup(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_lookup_fn * handler)
|
||||
{
|
||||
config->provider.lookup = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_ongetattr(
|
||||
void wsfsp_impl_client_config_set_ongetattr(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_getattr_fn * handler)
|
||||
{
|
||||
config->provider.getattr = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onreaddir(
|
||||
void wsfsp_impl_client_config_set_onreaddir(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_readdir_fn * handler)
|
||||
{
|
||||
config->provider.readdir = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onopen(
|
||||
void wsfsp_impl_client_config_set_onopen(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_open_fn * handler)
|
||||
{
|
||||
config->provider.open = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onclose(
|
||||
void wsfsp_impl_client_config_set_onclose(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_close_fn * handler)
|
||||
{
|
||||
config->provider.close = handler;
|
||||
}
|
||||
|
||||
void wsfsp_client_config_set_onread(
|
||||
void wsfsp_impl_client_config_set_onread(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_read_fn * handler)
|
||||
{
|
||||
77
lib/wsfs/provider/impl/client_config.h
Normal file
77
lib/wsfs/provider/impl/client_config.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_CLIENT_CONFIG_H
|
||||
#define WSFS_PROVIDER_IMPL_CLIENT_CONFIG_H
|
||||
|
||||
#include "wsfs/provider/client_config.h"
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_client_config
|
||||
{
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
};
|
||||
|
||||
extern struct wsfsp_client_config * wsfsp_impl_client_config_create(void);
|
||||
|
||||
extern void wsfsp_impl_client_config_dispose(
|
||||
struct wsfsp_client_config * config);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_userdata(
|
||||
struct wsfsp_client_config * config,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_keypath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_certpath(
|
||||
struct wsfsp_client_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_connected_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_ondisconnected(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_disconnected_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_ontimer(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_ontimer_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onlookup(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_lookup_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_ongetattr(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_getattr_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onreaddir(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_readdir_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onopen(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_open_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onclose(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_close_fn * handler);
|
||||
|
||||
extern void wsfsp_impl_client_config_set_onread(
|
||||
struct wsfsp_client_config * config,
|
||||
wsfsp_read_fn * handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "wsfs/provider/client_protocol_intern.h"
|
||||
#include "wsfs/provider/impl/client_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -7,11 +7,11 @@
|
||||
#include <jansson.h>
|
||||
|
||||
|
||||
#include "wsfs/provider/provider.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/message.h"
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include "wsfs/core/util.h"
|
||||
#include "wsfs/core/message.h"
|
||||
|
||||
static void wsfsp_client_protocol_respond(
|
||||
static void wsfsp_impl_client_protocol_respond(
|
||||
json_t * response,
|
||||
void * user_data)
|
||||
{
|
||||
@@ -25,7 +25,7 @@ static void wsfsp_client_protocol_respond(
|
||||
}
|
||||
}
|
||||
|
||||
static void wsfsp_client_protocol_process_request(
|
||||
static void wsfsp_impl_client_protocol_process_request(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
char const * message,
|
||||
size_t length)
|
||||
@@ -33,20 +33,20 @@ static void wsfsp_client_protocol_process_request(
|
||||
json_t * request = json_loadb(message, length, 0, NULL);
|
||||
if (NULL != request)
|
||||
{
|
||||
struct wsfsp_invokation_context context =
|
||||
struct wsfsp_impl_invokation_context context =
|
||||
{
|
||||
.provider = &protocol->provider,
|
||||
.user_data = protocol->user_data,
|
||||
.request = &protocol->request
|
||||
};
|
||||
|
||||
wsfsp_provider_invoke(&context, request);
|
||||
wsfsp_impl_provider_invoke(&context, request);
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int wsfsp_client_protocol_callback(
|
||||
static int wsfsp_impl_client_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
@@ -70,7 +70,7 @@ static int wsfsp_client_protocol_callback(
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||
wsfsp_client_protocol_process_request(protocol, in, len);
|
||||
wsfsp_impl_client_protocol_process_request(protocol, in, len);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
// fall-through
|
||||
@@ -97,7 +97,7 @@ static int wsfsp_client_protocol_callback(
|
||||
}
|
||||
|
||||
|
||||
void wsfsp_client_protocol_init(
|
||||
void wsfsp_impl_client_protocol_init(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
@@ -106,44 +106,44 @@ void wsfsp_client_protocol_init(
|
||||
|
||||
protocol->wsi = NULL;
|
||||
|
||||
protocol->request.respond = &wsfsp_client_protocol_respond;
|
||||
protocol->request.respond = &wsfsp_impl_client_protocol_respond;
|
||||
protocol->request.user_data = protocol;
|
||||
|
||||
protocol->user_data = user_data;
|
||||
wsfsp_provider_init_from_prototype(&protocol->provider, provider);
|
||||
wsfsp_impl_provider_init_from_prototype(&protocol->provider, provider);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_cleanup(
|
||||
void wsfsp_impl_client_protocol_cleanup(
|
||||
struct wsfsp_client_protocol * protocol)
|
||||
{
|
||||
wsfs_message_queue_cleanup(&protocol->queue);
|
||||
}
|
||||
|
||||
struct wsfsp_client_protocol * wsfsp_client_protocol_create(
|
||||
struct wsfsp_client_protocol * wsfsp_impl_client_protocol_create(
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfsp_client_protocol * protocol = malloc(sizeof(struct wsfsp_client_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
wsfsp_client_protocol_init(protocol, provider, user_data);
|
||||
wsfsp_impl_client_protocol_init(protocol, provider, user_data);
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_dispose(
|
||||
void wsfsp_impl_client_protocol_dispose(
|
||||
struct wsfsp_client_protocol * protocol)
|
||||
{
|
||||
wsfsp_client_protocol_cleanup(protocol);
|
||||
wsfsp_impl_client_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_init_lws(
|
||||
void wsfsp_impl_client_protocol_init_lws(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wsfsp_client_protocol_callback;
|
||||
lws_protocol->callback = &wsfsp_impl_client_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
49
lib/wsfs/provider/impl/client_protocol.h
Normal file
49
lib/wsfs/provider/impl/client_protocol.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_CLIENT_PROTOCOL_H
|
||||
#define WSFS_PROVIDER_IMPL_CLIENT_PROTOCOL_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
|
||||
#include "wsfs/core/message_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_provider;
|
||||
struct lws_protocols;
|
||||
|
||||
struct wsfsp_client_protocol
|
||||
{
|
||||
struct wsfsp_request request;
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
struct lws * wsi;
|
||||
struct wsfs_message_queue queue;
|
||||
};
|
||||
|
||||
extern void wsfsp_impl_client_protocol_init(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_impl_client_protocol_cleanup(
|
||||
struct wsfsp_client_protocol * protocol);
|
||||
|
||||
extern struct wsfsp_client_protocol * wsfsp_impl_client_protocol_create(
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_impl_client_protocol_dispose(
|
||||
struct wsfsp_client_protocol * protocol);
|
||||
|
||||
extern void wsfsp_impl_client_protocol_init_lws(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "wsfs/provider/dirbuffer_intern.h"
|
||||
#include "wsfs/provider/impl/dirbuffer.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void)
|
||||
struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void)
|
||||
{
|
||||
struct wsfsp_dirbuffer * buffer = malloc(sizeof(struct wsfsp_dirbuffer));
|
||||
if (NULL != buffer)
|
||||
@@ -12,7 +12,7 @@ struct wsfsp_dirbuffer * wsfsp_dirbuffer_create(void)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void wsfsp_dirbuffer_dispose(
|
||||
void wsfsp_impl_dirbuffer_dispose(
|
||||
struct wsfsp_dirbuffer * buffer)
|
||||
{
|
||||
if (NULL != buffer->entries)
|
||||
@@ -23,7 +23,7 @@ void wsfsp_dirbuffer_dispose(
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void wsfsp_dirbuffer_add(
|
||||
void wsfsp_impl_dirbuffer_add(
|
||||
struct wsfsp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode)
|
||||
@@ -35,7 +35,7 @@ void wsfsp_dirbuffer_add(
|
||||
json_array_append_new(buffer->entries, entry);
|
||||
}
|
||||
|
||||
json_t * wsfsp_dirbuffer_take(
|
||||
json_t * wsfsp_impl_dirbuffer_take(
|
||||
struct wsfsp_dirbuffer * buffer)
|
||||
{
|
||||
json_t * entries = buffer->entries;
|
||||
37
lib/wsfs/provider/impl/dirbuffer.h
Normal file
37
lib/wsfs/provider/impl/dirbuffer.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_DIRBUFFER_H
|
||||
#define WSFS_PROVIDER_IMPL_DIRBUFFER_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_dirbuffer
|
||||
{
|
||||
json_t * entries;
|
||||
};
|
||||
|
||||
extern struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void);
|
||||
|
||||
extern void wsfsp_impl_dirbuffer_dispose(
|
||||
struct wsfsp_dirbuffer * buffer);
|
||||
|
||||
extern void wsfsp_impl_dirbuffer_add(
|
||||
struct wsfsp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode);
|
||||
|
||||
extern json_t * wsfsp_impl_dirbuffer_take(
|
||||
struct wsfsp_dirbuffer * buffer);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "wsfs/provider/operation/close_intern.h"
|
||||
#include "wsfs/provider/impl/operation/close.h"
|
||||
#include <limits.h>
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfsp_close(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_close(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int WSFS_UNUSED_PARAM(id))
|
||||
{
|
||||
@@ -28,7 +28,7 @@ void wsfsp_close(
|
||||
|
||||
}
|
||||
|
||||
void wsfsp_close_default(
|
||||
void wsfsp_impl_close_default(
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
uint32_t WSFS_UNUSED_PARAM(handle),
|
||||
int WSFS_UNUSED_PARAM(flags),
|
||||
26
lib/wsfs/provider/impl/operation/close.h
Normal file
26
lib/wsfs/provider/impl/operation/close.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_CLOSE_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_CLOSE_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_close(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_close_default(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
22
lib/wsfs/provider/impl/operation/error.h
Normal file
22
lib/wsfs/provider/impl/operation/error.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef WSFSP_OPERATION_IMPL_ERROR_H
|
||||
#define WSFSP_OPERATION_IMPL_ERROR_H
|
||||
|
||||
#include "wsfs/provider/api.h"
|
||||
#include "wsfs/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
extern WSFSP_API void wsfsp_impl_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
wsfs_status status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "wsfs/provider/operation/getattr_intern.h"
|
||||
#include "wsfs/provider/impl/operation/getattr.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
|
||||
void wsfsp_getattr(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_getattr(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@@ -20,22 +20,22 @@ void wsfsp_getattr(
|
||||
if (json_is_integer(inode_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->getattr(request, inode, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_getattr_default(
|
||||
void wsfsp_impl_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_respond_getattr(
|
||||
void wsfsp_impl_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
@@ -60,5 +60,5 @@ void wsfsp_respond_getattr(
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
}
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
wsfsp_impl_respond(request, result);
|
||||
}
|
||||
29
lib/wsfs/provider/impl/operation/getattr.h
Normal file
29
lib/wsfs/provider/impl/operation/getattr.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_GETATTR_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_GETATTR_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern void wsfsp_impl_getattr(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "wsfs/provider/operation/lookup_intern.h"
|
||||
#include "wsfs/provider/impl/operation/lookup.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfsp_lookup(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_lookup(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@@ -22,13 +23,13 @@ void wsfsp_lookup(
|
||||
ino_t inode = json_integer_value(inode_holder);
|
||||
char const * name = json_string_value(name_holder);
|
||||
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
context->provider->lookup(request, inode, name, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_respond_lookup(
|
||||
void wsfsp_impl_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
@@ -53,15 +54,15 @@ void wsfsp_respond_lookup(
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
}
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
wsfsp_impl_respond(request, result);
|
||||
}
|
||||
|
||||
void wsfsp_lookup_default(
|
||||
void wsfsp_impl_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(parent),
|
||||
char const * WSFS_UNUSED_PARAM(name),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
30
lib/wsfs/provider/impl/operation/lookup.h
Normal file
30
lib/wsfs/provider/impl/operation/lookup.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_LOOKUP_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_LOOKUP_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern void wsfsp_impl_lookup(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "wsfs/provider/operation/open_intern.h"
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/provider/impl/operation/open.h"
|
||||
#include "wsfs/provider/impl/operation/error.h"
|
||||
#include "wsfs/provider/impl/request.h"
|
||||
#include "wsfs/core/util.h"
|
||||
|
||||
void wsfsp_open(
|
||||
struct wsfsp_invokation_context * context,
|
||||
void wsfsp_impl_open(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
@@ -20,28 +20,28 @@ void wsfsp_open(
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
int flags = (ino_t) json_integer_value(flags_holder);
|
||||
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
struct wsfsp_request * request = wsfsp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->open(request, inode, flags, context->user_data); /* Flawfinder: ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_open_default(
|
||||
void wsfsp_impl_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
int WSFS_UNUSED_PARAM(flags),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wsfsp_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
wsfsp_impl_respond_error(request, WSFS_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wsfsp_respond_open(
|
||||
void wsfsp_impl_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "handle", json_integer((int) handle));
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
wsfsp_impl_respond(request, result);
|
||||
}
|
||||
30
lib/wsfs/provider/impl/operation/open.h
Normal file
30
lib/wsfs/provider/impl/operation/open.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WSFS_PROVIDER_IMPL_OPERATION_OPEN_H
|
||||
#define WSFS_PROVIDER_IMPL_OPERATION_OPEN_H
|
||||
|
||||
#include "wsfs/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_impl_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle);
|
||||
|
||||
extern void wsfsp_impl_open(
|
||||
struct wsfsp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wsfsp_impl_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user