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

fixes include guards; adds server and server_protocol to api; fixes some extern "C" issues

This commit is contained in:
Falk Werner 2019-03-24 02:03:31 +01:00
parent 5ff1d5e6a3
commit d94729c185
29 changed files with 181 additions and 122 deletions

View File

@ -5,11 +5,19 @@
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_credentials;
typedef bool wsfs_authenticate_fn(
struct wsfs_credentials * credentials,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -3,13 +3,13 @@
#include "wsfs/adapter/api.h"
struct wsfs_credentials;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_credentials;
extern WSFSA_API char const * wsfs_credentials_type(
struct wsfs_credentials const * credentials);

View File

@ -3,14 +3,14 @@
#include "wsfs/adapter/api.h"
struct wsfs_server;
struct wsfs_server_config;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_server;
struct wsfs_server_config;
extern WSFSA_API struct wsfs_server * wsfs_server_create(
struct wsfs_server_config * config);

View File

@ -4,13 +4,13 @@
#include "wsfs/adapter/api.h"
#include "wsfs/adapter/authenticate.h"
struct wsfs_server_config;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_server_config;
extern WSFSA_API struct wsfs_server_config * wsfs_server_config_create(void);
extern WSFSA_API void wsfs_server_config_dispose(

View File

@ -4,14 +4,14 @@
#include <wsfs/adapter/api.h>
#include <wsfs/adapter/authenticate.h>
struct wsfs_server_protocol;
struct lws_protocols;
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_server_protocol;
struct lws_protocols;
extern WSFSA_API struct wsfs_server_protocol * wsfs_server_protocol_create(
char * mount_point);

View File

@ -1,6 +1,65 @@
#include "wsfs_adapter.h"
#include "wsfs/adapter/impl/credentials.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

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_AUTHENTICATOR_H
#define WSFS_ADAPTER_AUTHENTICATOR_H
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
#define WSFS_ADAPTER_IMPL_AUTHENTICATOR_H
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_AUTHENTICATORS_H
#define WSFS_ADAPTER_AUTHENTICATORS_H
#ifndef WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
#define WSFS_ADAPTER_IMPL_AUTHENTICATORS_H
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_FILESYSTEM_H
#define WSFS_ADAPTER_FILESYSTEM_H
#ifndef WSFS_ADAPTER_IMPL_FILESYSTEM_H
#define WSFS_ADAPTER_IMPL_FILESYSTEM_H
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -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" {

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_JSONRPC_METHOD_H
#define WSFS_ADAPTER_JSONRPC_METHOD_H
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_H
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H
#define WSFS_ADAPTER_JSONRPC_METHOD_INTERN_H
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
#define WSFS_ADAPTER_IMPL_JSONRPC_METHOD_INTERN_H
#include "wsfs/adapter/impl/jsonrpc/method.h"

View File

@ -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>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_JSONRPC_RESPONSE_H
#define WSFS_ADAPTER_JSONRPC_RESPONSE_H
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
#define WSFS_ADAPTER_IMPL_JSONRPC_RESPONSE_H
#ifndef __cplusplus
#include <stddef.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_JSONRPC_SERVER_H
#define WSFS_ADAPTER_JSONRPC_SERVER_H
#ifndef WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
#define WSFS_ADAPTER_IMPL_JSONRPC_SERVER_H
#ifndef __cplusplus
#include <stdarg.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_JSON_UTIL_H
#define WSFS_ADAPTER_JSON_UTIL_H
#ifndef WSFS_ADAPTER_IMPL_JSON_UTIL_H
#define WSFS_ADAPTER_IMPL_JSON_UTIL_H
#include <jansson.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_OPERATIONS
#define WSFS_ADAPTER_OPERATIONS
#ifndef WSFS_ADAPTER_IMPL_OPERATIONS_H
#define WSFS_ADAPTER_IMPL_OPERATIONS_H
#include "wsfs/adapter/impl/fuse_wrapper.h"

View File

@ -9,7 +9,7 @@
#include <unistd.h>
#include "wsfs/adapter/impl/server_config.h"
#include "wsfs/adapter/impl/server_protocol_intern.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_impl_server_config_clone(config, &server->config);
wsfs_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = wsfs_server_context_create(server);
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_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;

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_SERVER_H
#define WSFS_ADAPTER_SERVER_H
#ifndef WSFS_ADAPTER_IMPL_SERVER_H
#define WSFS_ADAPTER_IMPL_SERVER_H
struct wsfs_server;
struct wsfs_server_config;
@ -9,16 +9,16 @@ extern "C"
{
#endif
extern struct wsfs_server * wsfs_server_create(
extern struct wsfs_server * wsfs_impl_server_create(
struct wsfs_server_config * config);
extern void wsfs_server_dispose(
extern void wsfs_impl_server_dispose(
struct wsfs_server * server);
extern void wsfs_server_run(
extern void wsfs_impl_server_run(
struct wsfs_server * server);
extern void wsfs_server_shutdown(
extern void wsfs_impl_server_shutdown(
struct wsfs_server * server);
#ifdef __cplusplus

View File

@ -1,4 +1,4 @@
#include "wsfs/adapter/impl/server_protocol_intern.h"
#include "wsfs/adapter/impl/server_protocol.h"
#include <stdlib.h>
#include <libwebsockets.h>
@ -8,7 +8,7 @@
#include "wsfs/adapter/impl/filesystem.h"
static int wsfs_server_protocol_callback(
static int wsfs_impl_server_protocol_callback(
struct lws * wsi,
enum lws_callback_reasons reason,
void * WSFS_UNUSED_PARAM(user),
@ -70,7 +70,7 @@ static int wsfs_server_protocol_callback(
return 0;
}
static bool wsfs_server_protocol_invoke(
static bool wsfs_impl_server_protocol_invoke(
void * user_data,
json_t const * request)
{
@ -84,13 +84,13 @@ static bool wsfs_server_protocol_invoke(
}
struct wsfs_server_protocol * wsfs_server_protocol_create(
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_server_protocol_init(protocol, mount_point))
if (!wsfs_impl_server_protocol_init(protocol, mount_point))
{
free(protocol);
protocol = NULL;
@ -100,23 +100,23 @@ struct wsfs_server_protocol * wsfs_server_protocol_create(
return protocol;
}
void wsfs_server_protocol_dispose(
void wsfs_impl_server_protocol_dispose(
struct wsfs_server_protocol * protocol)
{
wsfs_server_protocol_cleanup(protocol);
wsfs_impl_server_protocol_cleanup(protocol);
free(protocol);
}
void wsfs_server_protocol_init_lws(
void wsfs_impl_server_protocol_init_lws(
struct wsfs_server_protocol * protocol,
struct lws_protocols * lws_protocol)
{
lws_protocol->callback = &wsfs_server_protocol_callback;
lws_protocol->callback = &wsfs_impl_server_protocol_callback;
lws_protocol->per_session_data_size = 0;
lws_protocol->user = protocol;
}
bool wsfs_server_protocol_init(
bool wsfs_impl_server_protocol_init(
struct wsfs_server_protocol * protocol,
char * mount_point)
{
@ -125,12 +125,12 @@ bool wsfs_server_protocol_init(
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);
wsfs_jsonrpc_server_add(&protocol->rpc, "lookup", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "getattr", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "readdir", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "open", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "close", &wsfs_impl_server_protocol_invoke, protocol);
wsfs_jsonrpc_server_add(&protocol->rpc, "read", &wsfs_impl_server_protocol_invoke, protocol);
bool const success = wsfs_filesystem_init(&protocol->filesystem, &protocol->rpc, mount_point);
@ -146,7 +146,7 @@ bool wsfs_server_protocol_init(
return success;
}
void wsfs_server_protocol_cleanup(
void wsfs_impl_server_protocol_cleanup(
struct wsfs_server_protocol * protocol)
{
wsfs_filesystem_cleanup(&protocol->filesystem);
@ -156,7 +156,7 @@ void wsfs_server_protocol_cleanup(
wsfs_session_manager_cleanup(&protocol->session_manager);
}
void wsfs_server_protocol_add_authenticator(
void wsfs_impl_server_protocol_add_authenticator(
struct wsfs_server_protocol * protocol,
char const * type,
wsfs_authenticate_fn * authenticate,

View File

@ -1,27 +1,46 @@
#ifndef WSFS_ADAPTER_SERVER_PROTOCOL_H
#define WSFS_ADAPTER_SERVER_PROTOCOL_H
#ifndef WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
#define WSFS_ADAPTER_IMPL_SERVER_PROTOCOL_H
#include "wsfs/adapter/authenticate.h"
struct wsfs_server_protocol;
struct lws_protocols;
#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
extern struct wsfs_server_protocol * wsfs_server_protocol_create(
struct lws_protocols;
struct wsfs_server_protocol
{
struct wsfs_timeout_manager timeout_manager;
struct wsfs_filesystem filesystem;
struct wsfs_jsonrpc_server rpc;
struct wsfs_authenticators authenticators;
struct wsfs_session_manager session_manager;
};
extern bool wsfs_impl_server_protocol_init(
struct wsfs_server_protocol * protocol,
char * mount_point);
extern void wsfs_server_protocol_dispose(
extern void wsfs_impl_server_protocol_cleanup(
struct wsfs_server_protocol * protocol);
extern void wsfs_server_protocol_init_lws(
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_server_protocol_add_authenticator(
extern void wsfs_impl_server_protocol_add_authenticator(
struct wsfs_server_protocol * protocol,
char const * type,
wsfs_authenticate_fn * authenticate,

View File

@ -1,27 +0,0 @@
#ifndef WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H
#define WSFS_ADAPTER_SERVER_PROTOCOL_INTERN_H
#include "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"
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

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_SESSION_H
#define WSFS_ADAPTER_SESSION_H
#ifndef WSFS_ADAPTER_IMPL_SESSION_H
#define WSFS_ADAPTER_IMPL_SESSION_H
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_SESSION_MANAGER_H
#define WSFS_ADAPTER_SESSION_MANAGER_H
#ifndef WSFS_ADAPTER_IMPL_SESSION_MANAGER_H
#define WSFS_ADAPTER_IMPL_SESSION_MANAGER_H
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H
#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_H
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
struct wsfs_timer;
struct wsfs_timeout_manager

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H
#define WSFS_ADAPTER_TIME_TIMEOUT_MANAGER_INTERN_H
#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"

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_TIME_TIMEPOINT_H
#define WSFS_ADAPTER_TIME_TIMEPOINT_H
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H
#define WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H
#ifndef __cplusplus
#include <stdbool.h>

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_TIME_TIMER_H
#define WSFS_ADAPTER_TIME_TIMER_H
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_H
#define WSFS_ADAPTER_IMPL_TIME_TIMER_H
#include "wsfs/adapter/impl/time/timepoint.h"

View File

@ -1,5 +1,5 @@
#ifndef WSFS_ADAPTER_TIME_TIMER_INTERN_H
#define WSFS_ADAPTER_TIME_TIMER_INTERN_H
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
#define WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
#ifndef __cplusplus
#include <stdbool.h>