mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
removed dobuild and adapter stuff
This commit is contained in:
@@ -1,298 +0,0 @@
|
||||
#include "webfuse_adapter.h"
|
||||
|
||||
#include "webfuse/adapter/impl/server.h"
|
||||
#include "webfuse/adapter/impl/server_protocol.h"
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include "webfuse/adapter/impl/client.h"
|
||||
#include "webfuse/adapter/impl/client_tlsconfig.h"
|
||||
|
||||
// server
|
||||
|
||||
struct wf_server * wf_server_create(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
return wf_impl_server_create(config);
|
||||
}
|
||||
|
||||
void wf_server_dispose(
|
||||
struct wf_server * server)
|
||||
{
|
||||
wf_impl_server_dispose(server);
|
||||
}
|
||||
|
||||
void wf_server_service(
|
||||
struct wf_server * server)
|
||||
{
|
||||
wf_impl_server_service(server);
|
||||
}
|
||||
|
||||
void wf_server_interrupt(
|
||||
struct wf_server * server)
|
||||
{
|
||||
wf_impl_server_interrupt(server);
|
||||
}
|
||||
|
||||
int wf_server_get_port(
|
||||
struct wf_server const * server)
|
||||
{
|
||||
return wf_impl_server_get_port(server);
|
||||
}
|
||||
|
||||
// server protocol
|
||||
|
||||
struct wf_server_protocol * wf_server_protocol_create(
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * create_mountpoint_context)
|
||||
{
|
||||
return wf_impl_server_protocol_create(create_mountpoint, create_mountpoint_context);
|
||||
}
|
||||
|
||||
void wf_server_protocol_dispose(
|
||||
struct wf_server_protocol * protocol)
|
||||
{
|
||||
wf_impl_server_protocol_dispose(protocol);
|
||||
}
|
||||
|
||||
void wf_server_protocol_init_lws(
|
||||
struct wf_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
wf_impl_server_protocol_init_lws(protocol, lws_protocol);
|
||||
}
|
||||
|
||||
void wf_server_protocol_add_authenticator(
|
||||
struct wf_server_protocol * protocol,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wf_impl_server_protocol_add_authenticator(protocol, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// server_config
|
||||
|
||||
struct wf_server_config * wf_server_config_create(void)
|
||||
{
|
||||
return wf_impl_server_config_create();
|
||||
}
|
||||
|
||||
void wf_server_config_dispose(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
wf_impl_server_config_dispose(config);
|
||||
}
|
||||
|
||||
void wf_server_config_set_mountpoint_factory(
|
||||
struct wf_server_config * config,
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * user_data)
|
||||
{
|
||||
wf_impl_server_config_set_mountpoint_factory(
|
||||
config, create_mountpoint, user_data);
|
||||
}
|
||||
|
||||
void wf_server_config_set_documentroot(
|
||||
struct wf_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
wf_impl_server_config_set_documentroot(config, document_root);
|
||||
}
|
||||
|
||||
void wf_server_config_set_keypath(
|
||||
struct wf_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wf_impl_server_config_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void wf_server_config_set_certpath(
|
||||
struct wf_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wf_impl_server_config_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void wf_server_config_set_vhostname(
|
||||
struct wf_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
wf_impl_server_config_set_vhostname(config, vhost_name);
|
||||
}
|
||||
|
||||
void wf_server_config_set_port(
|
||||
struct wf_server_config * config,
|
||||
int port)
|
||||
{
|
||||
wf_impl_server_config_set_port(config, port);
|
||||
}
|
||||
|
||||
void wf_server_config_add_authenticator(
|
||||
struct wf_server_config * config,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wf_impl_server_config_add_authenticator(config, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
// credentials
|
||||
|
||||
char const * wf_credentials_type(
|
||||
struct wf_credentials const * credentials)
|
||||
{
|
||||
return wf_impl_credentials_type(credentials);
|
||||
}
|
||||
|
||||
char const * wf_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
return wf_impl_credentials_get(credentials, key);
|
||||
}
|
||||
|
||||
void wf_credentials_set_type(
|
||||
struct wf_credentials * credentials,
|
||||
char const * type)
|
||||
{
|
||||
wf_impl_credentials_set_type(credentials, type);
|
||||
}
|
||||
|
||||
void wf_credentials_add(
|
||||
struct wf_credentials * credentials,
|
||||
char const * key,
|
||||
char const * value)
|
||||
{
|
||||
wf_impl_credentials_add(credentials, key, value);
|
||||
}
|
||||
|
||||
// mountpoint
|
||||
|
||||
struct wf_mountpoint *
|
||||
wf_mountpoint_create(
|
||||
char const * path)
|
||||
{
|
||||
return wf_impl_mountpoint_create(path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_mountpoint_dispose(
|
||||
struct wf_mountpoint * mountpoint)
|
||||
{
|
||||
wf_impl_mountpoint_dispose(mountpoint);
|
||||
}
|
||||
|
||||
char const *
|
||||
wf_mountpoint_get_path(
|
||||
struct wf_mountpoint const * mountpoint)
|
||||
{
|
||||
return wf_impl_mountpoint_get_path(mountpoint);
|
||||
}
|
||||
|
||||
void
|
||||
wf_mountpoint_set_userdata(
|
||||
struct wf_mountpoint * mountpoint,
|
||||
void * user_data,
|
||||
wf_mountpoint_userdata_dispose_fn * dispose)
|
||||
{
|
||||
wf_impl_mountpoint_set_userdata(mountpoint, user_data, dispose);
|
||||
}
|
||||
|
||||
// client
|
||||
|
||||
struct wf_client *
|
||||
wf_client_create(
|
||||
wf_client_callback_fn * callback,
|
||||
void * user_data)
|
||||
{
|
||||
return wf_impl_client_create(callback, user_data);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_dispose(
|
||||
struct wf_client * client)
|
||||
{
|
||||
wf_impl_client_dispose(client);
|
||||
}
|
||||
|
||||
void *
|
||||
wf_client_get_userdata(
|
||||
struct wf_client * client)
|
||||
{
|
||||
return wf_impl_client_get_userdata(client);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_service(
|
||||
struct wf_client * client)
|
||||
{
|
||||
wf_impl_client_service(client);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_interrupt(
|
||||
struct wf_client * client)
|
||||
{
|
||||
wf_impl_client_interrupt(client);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_connect(
|
||||
struct wf_client * client,
|
||||
char const * url)
|
||||
{
|
||||
wf_impl_client_connect(client, url);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_disconnect(
|
||||
struct wf_client * client)
|
||||
{
|
||||
wf_impl_client_disconnect(client);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_authenticate(
|
||||
struct wf_client * client)
|
||||
{
|
||||
wf_impl_client_authenticate(client);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_add_filesystem(
|
||||
struct wf_client * client,
|
||||
char const * local_path,
|
||||
char const * name)
|
||||
{
|
||||
wf_impl_client_add_filesystem(client, local_path, name);
|
||||
}
|
||||
|
||||
// client_tlsconfig
|
||||
|
||||
void
|
||||
wf_client_tlsconfig_set_keypath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * key_path)
|
||||
{
|
||||
wf_impl_client_tlsconfig_set_keypath(config, key_path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_tlsconfig_set_certpath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
wf_impl_client_tlsconfig_set_certpath(config, cert_path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_client_tlsconfig_set_cafilepath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cafile_path)
|
||||
{
|
||||
wf_impl_client_tlsconfig_set_cafilepath(config, cafile_path);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
|
||||
struct wf_impl_authenticator * wf_impl_authenticator_create(
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator));
|
||||
authenticator->type = strdup(type);
|
||||
authenticator->authenticate = authenticate;
|
||||
authenticator->user_data = user_data;
|
||||
authenticator->next = NULL;
|
||||
|
||||
return authenticator;
|
||||
}
|
||||
|
||||
void wf_impl_authenticator_dispose(
|
||||
struct wf_impl_authenticator * authenticator)
|
||||
{
|
||||
free(authenticator->type);
|
||||
free(authenticator);
|
||||
}
|
||||
|
||||
bool wf_impl_authenticator_autenticate(
|
||||
struct wf_impl_authenticator * authenticator,
|
||||
struct wf_credentials * credentials)
|
||||
{
|
||||
bool result;
|
||||
|
||||
if (0 == strcmp(authenticator->type, credentials->type))
|
||||
{
|
||||
result = authenticator->authenticate(credentials, authenticator->user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
#define WF_ADAPTER_IMPL_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_credentials;
|
||||
|
||||
struct wf_impl_authenticator
|
||||
{
|
||||
char * type;
|
||||
wf_authenticate_fn * authenticate;
|
||||
void * user_data;
|
||||
struct wf_impl_authenticator * next;
|
||||
};
|
||||
|
||||
extern struct wf_impl_authenticator * wf_impl_authenticator_create(
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_authenticator_dispose(
|
||||
struct wf_impl_authenticator * authenticator);
|
||||
|
||||
extern bool wf_impl_authenticator_autenticate(
|
||||
struct wf_impl_authenticator * authenticator,
|
||||
struct wf_credentials * credentials);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
|
||||
static struct wf_impl_authenticator * wf_impl_authenticators_find(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
char const * type)
|
||||
{
|
||||
struct wf_impl_authenticator * result = NULL;
|
||||
|
||||
struct wf_impl_authenticator * actual = authenticators->first;
|
||||
while ((NULL == result) && (NULL != actual))
|
||||
{
|
||||
struct wf_impl_authenticator * next = actual->next;
|
||||
if (0 == strcmp(type, actual->type))
|
||||
{
|
||||
result = actual;
|
||||
}
|
||||
|
||||
actual = next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_authenticators_init(
|
||||
struct wf_impl_authenticators * authenticators)
|
||||
{
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_authenticators_cleanup(
|
||||
struct wf_impl_authenticators * authenticators)
|
||||
{
|
||||
struct wf_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wf_impl_authenticator * next = actual->next;
|
||||
wf_impl_authenticator_dispose(actual);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_authenticators_clone(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_authenticators * other)
|
||||
{
|
||||
wf_impl_authenticators_init(other);
|
||||
|
||||
struct wf_impl_authenticator * actual = authenticators->first;
|
||||
while (NULL != actual)
|
||||
{
|
||||
struct wf_impl_authenticator * next = actual->next;
|
||||
wf_impl_authenticators_add(other,
|
||||
actual->type, actual->authenticate, actual->user_data);
|
||||
actual = next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern void wf_impl_authenticators_move(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_authenticators * other)
|
||||
{
|
||||
other->first = authenticators->first;
|
||||
authenticators->first = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_authenticators_add(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(type, authenticate, user_data);
|
||||
authenticator->next = authenticators->first;
|
||||
authenticators->first = authenticator;
|
||||
}
|
||||
|
||||
bool wf_impl_authenticators_authenticate(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_credentials * credentials)
|
||||
{
|
||||
bool result = (NULL == authenticators->first);
|
||||
|
||||
if (NULL != credentials)
|
||||
{
|
||||
struct wf_impl_authenticator * authenticator = wf_impl_authenticators_find(authenticators, credentials->type);
|
||||
if (NULL != authenticator)
|
||||
{
|
||||
result = wf_impl_authenticator_autenticate(authenticator, credentials);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
#define WF_ADAPTER_IMPL_AUTHENTICATORS_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_authenticator;
|
||||
struct wf_credentials;
|
||||
|
||||
struct wf_impl_authenticators
|
||||
{
|
||||
struct wf_impl_authenticator * first;
|
||||
};
|
||||
|
||||
extern void wf_impl_authenticators_init(
|
||||
struct wf_impl_authenticators * authenticators);
|
||||
|
||||
extern void wf_impl_authenticators_cleanup(
|
||||
struct wf_impl_authenticators * authenticators);
|
||||
|
||||
extern void wf_impl_authenticators_clone(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_authenticators * other);
|
||||
|
||||
extern void wf_impl_authenticators_move(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_authenticators * other);
|
||||
|
||||
extern void wf_impl_authenticators_add(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
extern bool wf_impl_authenticators_authenticate(
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
#include "webfuse/adapter/impl/client.h"
|
||||
#include "webfuse/adapter/impl/client_protocol.h"
|
||||
#include "webfuse/adapter/impl/client_tlsconfig.h"
|
||||
#include "webfuse/core/lws_log.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define WF_CLIENT_PROTOCOL_COUNT 2
|
||||
|
||||
struct wf_client
|
||||
{
|
||||
struct wf_client_protocol protocol;
|
||||
struct lws_context_creation_info info;
|
||||
struct lws_protocols protocols[WF_CLIENT_PROTOCOL_COUNT];
|
||||
struct wf_client_tlsconfig tls;
|
||||
struct lws_context * context;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
struct wf_client *
|
||||
wf_impl_client_create(
|
||||
wf_client_callback_fn * callback,
|
||||
void * user_data)
|
||||
{
|
||||
wf_lwslog_disable();
|
||||
|
||||
struct wf_client * client = malloc(sizeof(struct wf_client));
|
||||
wf_impl_client_tlsconfig_init(&client->tls);
|
||||
client->user_data = user_data;
|
||||
wf_impl_client_protocol_init(&client->protocol,
|
||||
(wf_client_protocol_callback_fn*) callback, (void*) client);
|
||||
|
||||
memset(client->protocols, 0, sizeof(struct lws_protocols) * WF_CLIENT_PROTOCOL_COUNT);
|
||||
wf_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;
|
||||
client->info.protocols = client->protocols;
|
||||
client->info.uid = -1;
|
||||
client->info.gid = -1;
|
||||
|
||||
wf_impl_client_protocol_callback(&client->protocol, WF_CLIENT_GET_TLS_CONFIG, &client->tls);
|
||||
if (wf_impl_client_tlsconfig_isset(&client->tls))
|
||||
{
|
||||
client->info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
|
||||
}
|
||||
|
||||
client->context = lws_create_context(&client->info);
|
||||
|
||||
if (wf_impl_client_tlsconfig_isset(&client->tls))
|
||||
{
|
||||
struct lws_vhost * vhost = lws_create_vhost(client->context, &client->info);
|
||||
client->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
client->info.client_ssl_cert_filepath = client->tls.cert_path;
|
||||
client->info.client_ssl_private_key_filepath = client->tls.key_path;
|
||||
client->info.client_ssl_ca_filepath = client->tls.cafile_path;
|
||||
lws_init_vhost_client_ssl(&client->info, vhost);
|
||||
}
|
||||
|
||||
wf_impl_client_protocol_callback(&client->protocol, WF_CLIENT_CREATED ,NULL);
|
||||
return client;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_dispose(
|
||||
struct wf_client * client)
|
||||
{
|
||||
lws_context_destroy(client->context);
|
||||
wf_impl_client_protocol_cleanup(&client->protocol);
|
||||
wf_impl_client_tlsconfig_cleanup(&client->tls);
|
||||
free(client);
|
||||
}
|
||||
|
||||
void *
|
||||
wf_impl_client_get_userdata(
|
||||
struct wf_client * client)
|
||||
{
|
||||
return client->user_data;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_service(
|
||||
struct wf_client * client)
|
||||
{
|
||||
lws_service(client->context, 0);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_interrupt(
|
||||
struct wf_client * client)
|
||||
{
|
||||
lws_cancel_service(client->context);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_connect(
|
||||
struct wf_client * client,
|
||||
char const * url)
|
||||
{
|
||||
wf_impl_client_protocol_connect(&client->protocol, client->context, url);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_disconnect(
|
||||
struct wf_client * client)
|
||||
{
|
||||
wf_impl_client_protocol_disconnect(&client->protocol);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_authenticate(
|
||||
struct wf_client * client)
|
||||
{
|
||||
wf_impl_client_protocol_authenticate(&client->protocol);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_add_filesystem(
|
||||
struct wf_client * client,
|
||||
char const * local_path,
|
||||
char const * name)
|
||||
{
|
||||
wf_impl_client_protocol_add_filesystem(&client->protocol, local_path, name);
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_CLIENT_H
|
||||
#define WF_ADAPTER_IMPL_CLIENT_H
|
||||
|
||||
|
||||
#include "webfuse/adapter/client_callback.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wf_client *
|
||||
wf_impl_client_create(
|
||||
wf_client_callback_fn * callback,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
wf_impl_client_dispose(
|
||||
struct wf_client * client);
|
||||
|
||||
extern void *
|
||||
wf_impl_client_get_userdata(
|
||||
struct wf_client * client);
|
||||
|
||||
extern void
|
||||
wf_impl_client_service(
|
||||
struct wf_client * client);
|
||||
|
||||
extern void
|
||||
wf_impl_client_interrupt(
|
||||
struct wf_client * client);
|
||||
|
||||
extern void
|
||||
wf_impl_client_connect(
|
||||
struct wf_client * client,
|
||||
char const * url);
|
||||
|
||||
extern void
|
||||
wf_impl_client_disconnect(
|
||||
struct wf_client * client);
|
||||
|
||||
extern void
|
||||
wf_impl_client_authenticate(
|
||||
struct wf_client * client);
|
||||
|
||||
extern void
|
||||
wf_impl_client_add_filesystem(
|
||||
struct wf_client * client,
|
||||
char const * local_path,
|
||||
char const * name);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,336 +0,0 @@
|
||||
#include "webfuse/adapter/impl/client_protocol.h"
|
||||
#include "webfuse/adapter/client_callback.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
#include "webfuse/core/url.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/timer/manager.h"
|
||||
#include "webfuse/core/jsonrpc/response.h"
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/core/container_of.h"
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
struct wf_impl_client_protocol_add_filesystem_context
|
||||
{
|
||||
struct wf_client_protocol * protocol;
|
||||
char * local_path;
|
||||
};
|
||||
|
||||
static void
|
||||
wf_impl_client_protocol_process(
|
||||
struct wf_client_protocol * protocol,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
json_t * message = json_loadb(data, length, 0, NULL);
|
||||
if (NULL != message)
|
||||
{
|
||||
if (wf_jsonrpc_is_response(message))
|
||||
{
|
||||
wf_jsonrpc_proxy_onresult(protocol->proxy, message);
|
||||
}
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
wf_impl_client_protocol_send(
|
||||
json_t * request,
|
||||
void * user_data)
|
||||
{
|
||||
bool result = false;
|
||||
struct wf_client_protocol * protocol = user_data;
|
||||
|
||||
if (NULL != protocol->wsi)
|
||||
{
|
||||
struct wf_message * message = wf_message_create(request);
|
||||
if (NULL != message)
|
||||
{
|
||||
wf_slist_append(&protocol->messages, &message->item);
|
||||
lws_callback_on_writable(protocol->wsi);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wf_impl_client_protocol_on_authenticate_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * WF_UNUSED_PARAM(error))
|
||||
{
|
||||
struct wf_client_protocol * protocol = user_data;
|
||||
int const reason = (NULL != result) ? WF_CLIENT_AUTHENTICATED : WF_CLIENT_AUTHENTICATION_FAILED;
|
||||
|
||||
protocol->callback(protocol->user_data, reason, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
wf_impl_client_protocol_on_add_filesystem_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * WF_UNUSED_PARAM(error))
|
||||
{
|
||||
struct wf_impl_client_protocol_add_filesystem_context * context = user_data;
|
||||
struct wf_client_protocol * protocol = context->protocol;
|
||||
|
||||
int reason = WF_CLIENT_FILESYSTEM_ADD_FAILED;
|
||||
if (NULL == protocol->filesystem)
|
||||
{
|
||||
json_t * id = json_object_get(result, "id");
|
||||
if (json_is_string(id))
|
||||
{
|
||||
char const * name = json_string_value(id);
|
||||
struct wf_mountpoint * mountpoint = wf_mountpoint_create(context->local_path);
|
||||
protocol->filesystem = wf_impl_filesystem_create(protocol->wsi,protocol->proxy, name, mountpoint);
|
||||
if (NULL != protocol->filesystem)
|
||||
{
|
||||
reason = WF_CLIENT_FILESYSTEM_ADDED;
|
||||
}
|
||||
else
|
||||
{
|
||||
wf_mountpoint_dispose(mountpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(context->local_path);
|
||||
free(context);
|
||||
protocol->callback(protocol->user_data, reason, NULL);
|
||||
}
|
||||
|
||||
static int wf_impl_client_protocol_lws_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WF_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t WF_UNUSED_PARAM(len))
|
||||
{
|
||||
int result = 0;
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wf_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user : NULL;
|
||||
|
||||
if (NULL != protocol)
|
||||
{
|
||||
wf_timer_manager_check(protocol->timer_manager);
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||
protocol->is_connected = true;
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_CONNECTED, NULL);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||
protocol->is_connected = false;
|
||||
protocol->wsi = NULL;
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_DISCONNECTED, NULL);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CLOSED:
|
||||
protocol->is_connected = false;
|
||||
protocol->wsi = NULL;
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_DISCONNECTED, NULL);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||
wf_impl_client_protocol_process(protocol, in, len);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
// fall-through
|
||||
case LWS_CALLBACK_CLIENT_WRITEABLE:
|
||||
if (wsi == protocol->wsi)
|
||||
{
|
||||
if (protocol->is_shutdown_requested)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
else if (!wf_slist_empty(&protocol->messages))
|
||||
{
|
||||
struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages);
|
||||
struct wf_message * message = wf_container_of(item, struct wf_message, item);
|
||||
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||
wf_message_dispose(message);
|
||||
|
||||
if (!wf_slist_empty(&protocol->messages))
|
||||
{
|
||||
lws_callback_on_writable(wsi);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
if ((NULL != protocol->filesystem) && (wsi == protocol->filesystem->wsi))
|
||||
{
|
||||
wf_impl_filesystem_process_request(protocol->filesystem);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_init(
|
||||
struct wf_client_protocol * protocol,
|
||||
wf_client_protocol_callback_fn * callback,
|
||||
void * user_data)
|
||||
{
|
||||
protocol->is_connected = false,
|
||||
protocol->is_shutdown_requested = false;
|
||||
protocol->wsi = NULL;
|
||||
protocol->callback = callback;
|
||||
protocol->user_data = user_data;
|
||||
protocol->filesystem = NULL;
|
||||
|
||||
wf_slist_init(&protocol->messages);
|
||||
protocol->timer_manager = wf_timer_manager_create();
|
||||
protocol->proxy = wf_jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_client_protocol_send, protocol);
|
||||
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_INIT, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_cleanup(
|
||||
struct wf_client_protocol * protocol)
|
||||
{
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_CLEANUP, NULL);
|
||||
|
||||
wf_jsonrpc_proxy_dispose(protocol->proxy);
|
||||
wf_timer_manager_dispose(protocol->timer_manager);
|
||||
wf_message_queue_cleanup(&protocol->messages);
|
||||
|
||||
if (NULL != protocol->filesystem)
|
||||
{
|
||||
wf_impl_filesystem_dispose(protocol->filesystem);
|
||||
protocol->filesystem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_callback(
|
||||
struct wf_client_protocol * protocol,
|
||||
int reason,
|
||||
void * arg)
|
||||
{
|
||||
protocol->callback(protocol->user_data, reason, arg);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_init_lws(
|
||||
struct wf_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->name = WF_PROTOCOL_NAME_ADAPTER_CLIENT;
|
||||
lws_protocol->callback = &wf_impl_client_protocol_lws_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_connect(
|
||||
struct wf_client_protocol * protocol,
|
||||
struct lws_context * context,
|
||||
char const * url)
|
||||
{
|
||||
struct wf_url url_data;
|
||||
bool const success = wf_url_init(&url_data, url);
|
||||
if (success)
|
||||
{
|
||||
struct lws_client_connect_info info;
|
||||
memset(&info, 0 ,sizeof(struct lws_client_connect_info));
|
||||
info.context = context;
|
||||
info.port = url_data.port;
|
||||
info.address = url_data.host;
|
||||
info.path = url_data.path;
|
||||
info.host = info.address;
|
||||
info.origin = info.address;
|
||||
info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0;
|
||||
info.protocol = WF_PROTOCOL_NAME_PROVIDER_SERVER;
|
||||
info.local_protocol_name = WF_PROTOCOL_NAME_ADAPTER_CLIENT;
|
||||
info.pwsi = &protocol->wsi;
|
||||
|
||||
lws_client_connect_via_info(&info);
|
||||
wf_url_cleanup(&url_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_DISCONNECTED, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_disconnect(
|
||||
struct wf_client_protocol * protocol)
|
||||
{
|
||||
if (protocol->is_connected)
|
||||
{
|
||||
protocol->is_shutdown_requested = true;
|
||||
lws_callback_on_writable(protocol->wsi);
|
||||
}
|
||||
else
|
||||
{
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_DISCONNECTED, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_authenticate(
|
||||
struct wf_client_protocol * protocol)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init_default(&creds);
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, &creds);
|
||||
|
||||
json_incref(creds.data);
|
||||
wf_jsonrpc_proxy_invoke(
|
||||
protocol->proxy,
|
||||
&wf_impl_client_protocol_on_authenticate_finished,
|
||||
protocol,
|
||||
"authenticate",
|
||||
"sj",
|
||||
creds.type, creds.data);
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_add_filesystem(
|
||||
struct wf_client_protocol * protocol,
|
||||
char const * local_path,
|
||||
char const * name)
|
||||
{
|
||||
if (NULL == protocol->filesystem)
|
||||
{
|
||||
struct wf_impl_client_protocol_add_filesystem_context * context = malloc(sizeof(struct wf_impl_client_protocol_add_filesystem_context));
|
||||
context->protocol = protocol;
|
||||
context->local_path = strdup(local_path);
|
||||
|
||||
wf_jsonrpc_proxy_invoke(
|
||||
protocol->proxy,
|
||||
&wf_impl_client_protocol_on_add_filesystem_finished,
|
||||
context,
|
||||
"add_filesystem",
|
||||
"s",
|
||||
name);
|
||||
}
|
||||
else
|
||||
{
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_FILESYSTEM_ADD_FAILED, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_CLIENT_PROTOCOL_H
|
||||
#define WF_ADAPTER_IMPL_CLIENT_PROTOCOL_H
|
||||
|
||||
#include "webfuse/adapter/client_callback.h"
|
||||
#include "webfuse/core/slist.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws_protocols;
|
||||
struct lws_context;
|
||||
|
||||
struct wf_impl_filesystem;
|
||||
struct wf_jsonrpc_proxy;
|
||||
struct wf_timer_manager;
|
||||
|
||||
typedef void
|
||||
wf_client_protocol_callback_fn(
|
||||
void * user_data,
|
||||
int reason,
|
||||
void * arg);
|
||||
|
||||
struct wf_client_protocol
|
||||
{
|
||||
bool is_connected;
|
||||
bool is_shutdown_requested;
|
||||
struct lws * wsi;
|
||||
wf_client_protocol_callback_fn * callback;
|
||||
struct wf_impl_filesystem * filesystem;
|
||||
void * user_data;
|
||||
struct wf_timer_manager * timer_manager;
|
||||
struct wf_jsonrpc_proxy * proxy;
|
||||
struct wf_slist messages;
|
||||
};
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_init(
|
||||
struct wf_client_protocol * protocol,
|
||||
wf_client_protocol_callback_fn * callback,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_cleanup(
|
||||
struct wf_client_protocol * protocol);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_callback(
|
||||
struct wf_client_protocol * protocol,
|
||||
int reason,
|
||||
void * arg);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_init_lws(
|
||||
struct wf_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_connect(
|
||||
struct wf_client_protocol * protocol,
|
||||
struct lws_context * conext,
|
||||
char const * url);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_disconnect(
|
||||
struct wf_client_protocol * protocol);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_authenticate(
|
||||
struct wf_client_protocol * protocol);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_add_filesystem(
|
||||
struct wf_client_protocol * protocol,
|
||||
char const * local_path,
|
||||
char const * name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
#include "webfuse/adapter/impl/client_tlsconfig.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_init(
|
||||
struct wf_client_tlsconfig * config)
|
||||
{
|
||||
config->key_path = NULL;
|
||||
config->cert_path = NULL;
|
||||
config->cafile_path = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_cleanup(
|
||||
struct wf_client_tlsconfig * config)
|
||||
{
|
||||
free(config->key_path);
|
||||
free(config->cert_path);
|
||||
free(config->cafile_path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_set_keypath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * key_path)
|
||||
{
|
||||
free(config->key_path);
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_set_certpath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
free(config->cert_path);
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_set_cafilepath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cafile_path)
|
||||
{
|
||||
free(config->cafile_path);
|
||||
config->cafile_path = strdup(cafile_path);
|
||||
}
|
||||
|
||||
bool
|
||||
wf_impl_client_tlsconfig_isset(
|
||||
struct wf_client_tlsconfig const * config)
|
||||
{
|
||||
return (NULL != config->cert_path) && (NULL != config->key_path);
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_CLIENT_TLSCONFIG_H
|
||||
#define WF_ADAPTER_IMPL_CLIENT_TLSCONFIG_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_client_tlsconfig
|
||||
{
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * cafile_path;
|
||||
};
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_init(
|
||||
struct wf_client_tlsconfig * config);
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_cleanup(
|
||||
struct wf_client_tlsconfig * config);
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_set_keypath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_set_certpath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_set_cafilepath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cafile_path);
|
||||
|
||||
extern bool
|
||||
wf_impl_client_tlsconfig_isset(
|
||||
struct wf_client_tlsconfig const * config);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include <string.h>
|
||||
|
||||
void wf_impl_credentials_init_default(
|
||||
struct wf_credentials * credentials)
|
||||
{
|
||||
credentials->type = NULL;
|
||||
credentials->data = json_object();
|
||||
}
|
||||
|
||||
void wf_impl_credentials_init(
|
||||
struct wf_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data)
|
||||
{
|
||||
credentials->type = strdup(type);
|
||||
credentials->data = data;
|
||||
json_incref(credentials->data);
|
||||
}
|
||||
|
||||
void wf_impl_credentials_cleanup(
|
||||
struct wf_credentials * credentials)
|
||||
{
|
||||
free(credentials->type);
|
||||
json_decref(credentials->data);
|
||||
}
|
||||
|
||||
char const * wf_impl_credentials_type(
|
||||
struct wf_credentials const * credentials)
|
||||
{
|
||||
return credentials->type;
|
||||
}
|
||||
|
||||
char const * wf_impl_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
char const * result = NULL;
|
||||
|
||||
json_t * value_holder = json_object_get(credentials->data, key);
|
||||
if (json_is_string(value_holder))
|
||||
{
|
||||
result = json_string_value(value_holder);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_credentials_set_type(
|
||||
struct wf_credentials * credentials,
|
||||
char const * type)
|
||||
{
|
||||
free(credentials->type);
|
||||
credentials->type = strdup(type);
|
||||
}
|
||||
|
||||
void wf_impl_credentials_add(
|
||||
struct wf_credentials * credentials,
|
||||
char const * key,
|
||||
char const * value)
|
||||
{
|
||||
json_object_set_new(credentials->data, key, json_string(value));
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_CREDENTIALS_H
|
||||
#define WF_ADAPTER_IMPL_CREDENTIALS_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_credentials
|
||||
{
|
||||
char * type;
|
||||
json_t * data;
|
||||
};
|
||||
|
||||
extern void wf_impl_credentials_init(
|
||||
struct wf_credentials * credentials,
|
||||
char const * type,
|
||||
json_t * data);
|
||||
|
||||
extern void wf_impl_credentials_init_default(
|
||||
struct wf_credentials * credentials);
|
||||
|
||||
extern void wf_impl_credentials_cleanup(
|
||||
struct wf_credentials * credentials);
|
||||
|
||||
extern char const * wf_impl_credentials_type(
|
||||
struct wf_credentials const * credentials);
|
||||
|
||||
extern char const * wf_impl_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key);
|
||||
|
||||
extern void wf_impl_credentials_set_type(
|
||||
struct wf_credentials * credentials,
|
||||
char const * type);
|
||||
|
||||
extern void wf_impl_credentials_add(
|
||||
struct wf_credentials * credentials,
|
||||
char const * key,
|
||||
char const * value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,133 +0,0 @@
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
#include "webfuse/adapter/impl/operation/open.h"
|
||||
#include "webfuse/adapter/impl/operation/close.h"
|
||||
#include "webfuse/adapter/impl/operation/read.h"
|
||||
#include "webfuse/adapter/impl/operation/readdir.h"
|
||||
#include "webfuse/adapter/impl/operation/getattr.h"
|
||||
#include "webfuse/adapter/impl/operation/lookup.h"
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static struct fuse_lowlevel_ops const filesystem_operations =
|
||||
{
|
||||
.lookup = &wf_impl_operation_lookup,
|
||||
.getattr = &wf_impl_operation_getattr,
|
||||
.readdir = &wf_impl_operation_readdir,
|
||||
.open = &wf_impl_operation_open,
|
||||
.release = &wf_impl_operation_close,
|
||||
.read = &wf_impl_operation_read
|
||||
};
|
||||
|
||||
static void wf_impl_filesystem_cleanup(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
{
|
||||
fuse_session_reset(filesystem->session);
|
||||
fuse_session_unmount(filesystem->session);
|
||||
fuse_session_destroy(filesystem->session);
|
||||
filesystem->session = NULL;
|
||||
|
||||
free(filesystem->buffer.mem);
|
||||
fuse_opt_free_args(&filesystem->args);
|
||||
|
||||
wf_mountpoint_dispose(filesystem->mountpoint);
|
||||
|
||||
free(filesystem->user_data.name);
|
||||
}
|
||||
|
||||
|
||||
static bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct lws * session_wsi,
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
char const * name,
|
||||
struct wf_mountpoint * mountpoint)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
char * argv[] = {"", NULL};
|
||||
filesystem->args.argc = 1;
|
||||
filesystem->args.argv = argv;
|
||||
filesystem->args.allocated = 0;
|
||||
|
||||
filesystem->user_data.proxy = proxy;
|
||||
filesystem->user_data.timeout = 1.0;
|
||||
filesystem->user_data.name = strdup(name);
|
||||
memset(&filesystem->buffer, 0, sizeof(struct fuse_buf));
|
||||
|
||||
filesystem->mountpoint = mountpoint;
|
||||
|
||||
filesystem->session = fuse_session_new(
|
||||
&filesystem->args,
|
||||
&filesystem_operations,
|
||||
sizeof(filesystem_operations),
|
||||
&filesystem->user_data);
|
||||
if (NULL != filesystem->session)
|
||||
{
|
||||
char const * path = wf_mountpoint_get_path(filesystem->mountpoint);
|
||||
result = (0 == fuse_session_mount(filesystem->session, path));
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = fuse_session_fd(filesystem->session);
|
||||
struct lws_protocols const * protocol = lws_get_protocol(session_wsi);
|
||||
filesystem->wsi = lws_adopt_descriptor_vhost(lws_get_vhost(session_wsi), LWS_ADOPT_RAW_FILE_DESC, fd, protocol->name, session_wsi);
|
||||
|
||||
if (NULL == filesystem->wsi)
|
||||
{
|
||||
wf_impl_filesystem_cleanup(filesystem);
|
||||
result = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct wf_impl_filesystem * wf_impl_filesystem_create(
|
||||
struct lws * session_wsi,
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
char const * name,
|
||||
struct wf_mountpoint * mountpoint)
|
||||
{
|
||||
struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem));
|
||||
bool success = wf_impl_filesystem_init(filesystem, session_wsi, proxy, name, mountpoint);
|
||||
if (!success)
|
||||
{
|
||||
free(filesystem);
|
||||
filesystem = NULL;
|
||||
}
|
||||
|
||||
return filesystem;
|
||||
}
|
||||
|
||||
void wf_impl_filesystem_dispose(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
{
|
||||
wf_impl_filesystem_cleanup(filesystem);
|
||||
free(filesystem);
|
||||
}
|
||||
|
||||
void wf_impl_filesystem_process_request(
|
||||
struct wf_impl_filesystem * filesystem)
|
||||
{
|
||||
int const result = fuse_session_receive_buf(filesystem->session, &filesystem->buffer);
|
||||
if (0 < result)
|
||||
{
|
||||
fuse_session_process_buf(filesystem->session, &filesystem->buffer);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_FILESYSTEM_H
|
||||
#define WF_ADAPTER_IMPL_FILESYSTEM_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
#include "webfuse/core/slist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_mountpoint;
|
||||
struct wf_jsonrpc_proxy;
|
||||
struct lws;
|
||||
|
||||
struct wf_impl_filesystem
|
||||
{
|
||||
struct wf_slist_item item;
|
||||
struct fuse_args args;
|
||||
struct fuse_session * session;
|
||||
struct fuse_buf buffer;
|
||||
struct wf_impl_operation_context user_data;
|
||||
struct lws * wsi;
|
||||
struct wf_mountpoint * mountpoint;
|
||||
};
|
||||
|
||||
extern struct wf_impl_filesystem * wf_impl_filesystem_create(
|
||||
struct lws * session_wsi,
|
||||
struct wf_jsonrpc_proxy * proxy,
|
||||
char const * name,
|
||||
struct wf_mountpoint * mountpoint);
|
||||
|
||||
extern void wf_impl_filesystem_dispose(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
extern void wf_impl_filesystem_process_request(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_FUSE_H
|
||||
#define WF_ADAPTER_IMPL_FUSE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FUSE_USE_VERSION 31
|
||||
#include <fuse_lowlevel.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wf_mountpoint
|
||||
{
|
||||
char * path;
|
||||
void * user_data;
|
||||
wf_mountpoint_userdata_dispose_fn * dispose;
|
||||
};
|
||||
|
||||
struct wf_mountpoint *
|
||||
wf_impl_mountpoint_create(
|
||||
char const * path)
|
||||
{
|
||||
struct wf_mountpoint * mountpoint = malloc(sizeof(struct wf_mountpoint));
|
||||
mountpoint->path = strdup(path);
|
||||
mountpoint->user_data = NULL;
|
||||
mountpoint->dispose = NULL;
|
||||
|
||||
return mountpoint;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_dispose(
|
||||
struct wf_mountpoint * mountpoint)
|
||||
{
|
||||
if (NULL != mountpoint->dispose)
|
||||
{
|
||||
mountpoint->dispose(mountpoint->user_data);
|
||||
}
|
||||
|
||||
free(mountpoint->path);
|
||||
free(mountpoint);
|
||||
}
|
||||
|
||||
char const *
|
||||
wf_impl_mountpoint_get_path(
|
||||
struct wf_mountpoint const * mountpoint)
|
||||
{
|
||||
return mountpoint->path;
|
||||
}
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_set_userdata(
|
||||
struct wf_mountpoint * mountpoint,
|
||||
void * user_data,
|
||||
wf_mountpoint_userdata_dispose_fn * dispose)
|
||||
{
|
||||
mountpoint->user_data = user_data;
|
||||
mountpoint->dispose = dispose;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef WF_IMPL_MOUNTPOINT_H
|
||||
#define WF_IMPL_MOUNTPOINT_H
|
||||
|
||||
#include "webfuse/adapter/mountpoint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wf_mountpoint *
|
||||
wf_impl_mountpoint_create(
|
||||
char const * path);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_dispose(
|
||||
struct wf_mountpoint * mountpoint);
|
||||
|
||||
extern char const *
|
||||
wf_impl_mountpoint_get_path(
|
||||
struct wf_mountpoint const * mountpoint);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_set_userdata(
|
||||
struct wf_mountpoint * mountpoint,
|
||||
void * user_data,
|
||||
wf_mountpoint_userdata_dispose_fn * dispose);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,54 +0,0 @@
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_factory_init_default(
|
||||
struct wf_impl_mountpoint_factory * factory)
|
||||
{
|
||||
factory->create_mountpoint = NULL;
|
||||
factory->user_data = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_factory_init(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * user_data)
|
||||
{
|
||||
factory->create_mountpoint = create_mountpoint;
|
||||
factory->user_data = user_data;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_factory_clone(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
struct wf_impl_mountpoint_factory * other)
|
||||
{
|
||||
other->create_mountpoint = factory->create_mountpoint;
|
||||
other->user_data = factory->user_data;
|
||||
}
|
||||
|
||||
bool
|
||||
wf_impl_mountpoint_factory_isvalid(
|
||||
struct wf_impl_mountpoint_factory * factory)
|
||||
{
|
||||
return (NULL != factory->create_mountpoint);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_factory_cleanup(
|
||||
struct wf_impl_mountpoint_factory * factory)
|
||||
{
|
||||
|
||||
factory->create_mountpoint = NULL;
|
||||
factory->user_data = NULL;
|
||||
}
|
||||
|
||||
struct wf_mountpoint *
|
||||
wf_impl_mountpoint_factory_create_mountpoint(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
char const * filesystem)
|
||||
{
|
||||
return factory->create_mountpoint(filesystem, factory->user_data);
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_MOUNTPOINT_FACTORY_H
|
||||
#define WF_ADAPTER_IMPL_MOUNTPOINT_FACTORY_H
|
||||
|
||||
#include "webfuse/adapter/mountpoint_factory.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_mountpoint_factory
|
||||
{
|
||||
wf_create_mountpoint_fn * create_mountpoint;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_init_default(
|
||||
struct wf_impl_mountpoint_factory * factory);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_init(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_clone(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
struct wf_impl_mountpoint_factory * other);
|
||||
|
||||
extern bool
|
||||
wf_impl_mountpoint_factory_isvalid(
|
||||
struct wf_impl_mountpoint_factory * factory);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_init_from(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
struct wf_impl_mountpoint_factory * other);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_cleanup(
|
||||
struct wf_impl_mountpoint_factory * factory);
|
||||
|
||||
extern struct wf_mountpoint *
|
||||
wf_impl_mountpoint_factory_create_mountpoint(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
char const * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/close.h"
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wf_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wf_jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
|
||||
}
|
||||
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATION_CLOSE_H
|
||||
#define WF_ADAPTER_IMPL_OPERATION_CLOSE_H
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wf_impl_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include <stddef.h>
|
||||
|
||||
struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy(
|
||||
struct wf_impl_operation_context * context)
|
||||
{
|
||||
return context->proxy;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATION_CONTEXT_H
|
||||
#define WF_ADAPTER_IMPL_OPERATION_CONTEXT_H
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_jsonrpc_proxy;
|
||||
|
||||
struct wf_impl_operation_context
|
||||
{
|
||||
struct wf_jsonrpc_proxy * proxy;
|
||||
double timeout;
|
||||
char * name;
|
||||
};
|
||||
|
||||
extern struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy(
|
||||
struct wf_impl_operation_context * context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/getattr.h"
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wf_impl_operation_getattr_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_getattr_context * context = user_data;
|
||||
|
||||
struct stat buffer;
|
||||
if (NULL != result)
|
||||
{
|
||||
json_t * mode_holder = json_object_get(result, "mode");
|
||||
json_t * type_holder = json_object_get(result, "type");
|
||||
if ((json_is_integer(mode_holder)) && (json_is_string(type_holder)))
|
||||
{
|
||||
memset(&buffer, 0, sizeof(struct stat));
|
||||
|
||||
buffer.st_ino = context->inode;
|
||||
buffer.st_mode = json_integer_value(mode_holder) & 0555;
|
||||
char const * type = json_string_value(type_holder);
|
||||
if (0 == strcmp("file", type))
|
||||
{
|
||||
buffer.st_mode |= S_IFREG;
|
||||
}
|
||||
else if (0 == strcmp("dir", type))
|
||||
{
|
||||
buffer.st_mode |= S_IFDIR;
|
||||
}
|
||||
|
||||
buffer.st_uid = context->uid;
|
||||
buffer.st_gid = context->gid;
|
||||
buffer.st_nlink = 1;
|
||||
buffer.st_size = wf_impl_json_get_int(result, "size", 0);
|
||||
buffer.st_atime = wf_impl_json_get_int(result, "atime", 0);
|
||||
buffer.st_mtime = wf_impl_json_get_int(result, "mtime", 0);
|
||||
buffer.st_ctime = wf_impl_json_get_int(result, "ctime", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
fuse_reply_attr(context->request, &buffer, context->timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(context->request, ENOENT);
|
||||
}
|
||||
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wf_impl_operation_getattr (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
struct wf_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wf_impl_operation_getattr_context));
|
||||
getattr_context->request = request;
|
||||
getattr_context->inode = inode;
|
||||
getattr_context->uid = context->uid;
|
||||
getattr_context->gid = context->gid;
|
||||
getattr_context->timeout = user_data->timeout;
|
||||
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATION_GETATTR_H
|
||||
#define WF_ADAPTER_IMPL_OPERATION_GETATTR_H
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
#include <jansson.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_operation_getattr_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
fuse_ino_t inode;
|
||||
double timeout;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
extern void wf_impl_operation_getattr_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
|
||||
extern void wf_impl_operation_getattr (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info *file_info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,104 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/lookup.h"
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wf_impl_operation_lookup_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error
|
||||
)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_lookup_context * context = user_data;
|
||||
struct fuse_entry_param buffer;
|
||||
|
||||
if (NULL != result)
|
||||
{
|
||||
json_t * inode_holder = json_object_get(result, "inode");
|
||||
json_t * mode_holder = json_object_get(result, "mode");
|
||||
json_t * type_holder = json_object_get(result, "type");
|
||||
if ((json_is_integer(inode_holder)) &&
|
||||
(json_is_integer(mode_holder)) &&
|
||||
(json_is_string(type_holder)))
|
||||
{
|
||||
memset(&buffer, 0, sizeof(struct stat));
|
||||
|
||||
buffer.ino = json_integer_value(inode_holder);
|
||||
buffer.attr.st_ino = buffer.ino;
|
||||
buffer.attr.st_mode = json_integer_value(mode_holder) & 0555;
|
||||
char const * type = json_string_value(type_holder);
|
||||
if (0 == strcmp("file", type))
|
||||
{
|
||||
buffer.attr.st_mode |= S_IFREG;
|
||||
}
|
||||
else if (0 == strcmp("dir", type))
|
||||
{
|
||||
buffer.attr.st_mode |= S_IFDIR;
|
||||
}
|
||||
|
||||
|
||||
buffer.attr_timeout = context->timeout;
|
||||
buffer.entry_timeout = context->timeout;
|
||||
buffer.attr.st_uid = context->uid;
|
||||
buffer.attr.st_gid = context->gid;
|
||||
buffer.attr.st_nlink = 1;
|
||||
buffer.attr.st_size = wf_impl_json_get_int(result, "size", 0);
|
||||
buffer.attr.st_atime = wf_impl_json_get_int(result, "atime", 0);
|
||||
buffer.attr.st_mtime = wf_impl_json_get_int(result, "mtime", 0);
|
||||
buffer.attr.st_ctime = wf_impl_json_get_int(result, "ctime", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
fuse_reply_entry(context->request, &buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(context->request, ENOENT);
|
||||
}
|
||||
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wf_impl_operation_lookup (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t parent,
|
||||
char const * name)
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
struct wf_impl_operation_lookup_context * lookup_context = malloc(sizeof(struct wf_impl_operation_lookup_context));
|
||||
lookup_context->request = request;
|
||||
lookup_context->uid = context->uid;
|
||||
lookup_context->gid = context->gid;
|
||||
lookup_context->timeout = user_data->timeout;
|
||||
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATION_LOOKUP_H
|
||||
#define WF_ADAPTER_IMPL_OPERATION_LOOKUP_H
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
#include <jansson.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_operation_lookup_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
double timeout;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
extern void wf_impl_operation_lookup_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
|
||||
extern void wf_impl_operation_lookup (
|
||||
fuse_req_t req,
|
||||
fuse_ino_t parent,
|
||||
char const * name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,62 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/open.h"
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/status.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
void wf_impl_operation_open_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
fuse_req_t request = user_data;
|
||||
struct fuse_file_info file_info;
|
||||
memset(&file_info, 0, sizeof(struct fuse_file_info));
|
||||
|
||||
if (NULL != result)
|
||||
{
|
||||
json_t * handle_holder = json_object_get(result, "handle");
|
||||
if (json_is_integer(handle_holder))
|
||||
{
|
||||
file_info.fh = json_integer_value(handle_holder);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
fuse_reply_open(request, &file_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void wf_impl_operation_open(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATION_OPEN_H
|
||||
#define WF_ADAPTER_IMPL_OPERATION_OPEN_H
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wf_impl_operation_open(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
struct fuse_file_info * file_info);
|
||||
|
||||
extern void wf_impl_operation_open_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/read.h"
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/base64.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
#define WF_MAX_READ_LENGTH 4096
|
||||
|
||||
char * wf_impl_fill_buffer(
|
||||
char const * data,
|
||||
size_t data_size,
|
||||
char const * format,
|
||||
size_t count,
|
||||
wf_status * status)
|
||||
{
|
||||
*status = WF_GOOD;
|
||||
char * buffer = malloc(count);
|
||||
|
||||
if (0 < count)
|
||||
{
|
||||
if (0 == strcmp("identity", format))
|
||||
{
|
||||
if (count == data_size)
|
||||
{
|
||||
memcpy(buffer, data, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
*status = WF_BAD;
|
||||
}
|
||||
}
|
||||
else if (0 == strcmp("base64", format))
|
||||
{
|
||||
size_t result = wf_base64_decode(data, data_size, (uint8_t *) buffer, count);
|
||||
if (result != count)
|
||||
{
|
||||
*status = WF_BAD;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*status = WF_BAD;
|
||||
}
|
||||
}
|
||||
|
||||
if (WF_GOOD != *status)
|
||||
{
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void wf_impl_operation_read_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
fuse_req_t request = user_data;
|
||||
|
||||
char * buffer = NULL;
|
||||
size_t length = 0;
|
||||
if (NULL != result)
|
||||
{
|
||||
json_t * data_holder = json_object_get(result, "data");
|
||||
json_t * format_holder = json_object_get(result, "format");
|
||||
json_t * count_holder = json_object_get(result, "count");
|
||||
|
||||
if (json_is_string(data_holder) &&
|
||||
json_is_string(format_holder) &&
|
||||
json_is_integer(count_holder))
|
||||
{
|
||||
char const * const data = json_string_value(data_holder);
|
||||
size_t const data_size = json_string_length(data_holder);
|
||||
char const * const format = json_string_value(format_holder);
|
||||
length = (size_t) json_integer_value(count_holder);
|
||||
|
||||
buffer = wf_impl_fill_buffer(data, data_size, format, length, &status);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
fuse_reply_buf(request, buffer, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
}
|
||||
|
||||
void wf_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH;
|
||||
int handle = (file_info->fh & INT_MAX);
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATION_READ_H
|
||||
#define WF_ADAPTER_IMPL_OPERATION_READ_H
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wf_impl_operation_read(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t ino, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
extern char * wf_impl_fill_buffer(
|
||||
char const * data,
|
||||
size_t data_size,
|
||||
char const * format,
|
||||
size_t count,
|
||||
wf_status * status);
|
||||
|
||||
extern void wf_impl_operation_read_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,160 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/readdir.h"
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
|
||||
#define WF_DIRBUFFER_INITIAL_SIZE 1024
|
||||
|
||||
struct wf_impl_dirbuffer
|
||||
{
|
||||
char * data;
|
||||
size_t position;
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
static void wf_impl_dirbuffer_init(
|
||||
struct wf_impl_dirbuffer * buffer)
|
||||
{
|
||||
buffer->data = malloc(WF_DIRBUFFER_INITIAL_SIZE);
|
||||
buffer->position = 0;
|
||||
buffer->capacity = WF_DIRBUFFER_INITIAL_SIZE;
|
||||
}
|
||||
|
||||
static void wf_impl_dirbuffer_dispose(
|
||||
struct wf_impl_dirbuffer * buffer)
|
||||
{
|
||||
free(buffer->data);
|
||||
}
|
||||
|
||||
static void wf_impl_dirbuffer_add(
|
||||
fuse_req_t request,
|
||||
struct wf_impl_dirbuffer * buffer,
|
||||
char const * name,
|
||||
fuse_ino_t inode)
|
||||
{
|
||||
size_t const size = fuse_add_direntry(request, NULL, 0, name, NULL, 0);
|
||||
size_t remaining = buffer->capacity - buffer->position;
|
||||
while (remaining < size)
|
||||
{
|
||||
buffer->capacity *= 2;
|
||||
buffer->data = realloc(buffer->data, buffer->capacity);
|
||||
remaining = buffer->capacity - buffer->position;
|
||||
}
|
||||
|
||||
struct stat stat_buffer;
|
||||
memset(&stat_buffer, 0, sizeof(struct stat));
|
||||
stat_buffer.st_ino = inode;
|
||||
fuse_add_direntry(request,
|
||||
&buffer->data[buffer->position], remaining, name,
|
||||
&stat_buffer, buffer->position + size);
|
||||
buffer->position += size;
|
||||
}
|
||||
|
||||
static size_t wf_impl_min(size_t a, size_t b)
|
||||
{
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
void wf_impl_operation_readdir_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_readdir_context * context = user_data;
|
||||
|
||||
struct wf_impl_dirbuffer buffer;
|
||||
wf_impl_dirbuffer_init(&buffer);
|
||||
|
||||
if (json_is_array(result))
|
||||
{
|
||||
size_t const count = json_array_size(result);
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
json_t * entry =json_array_get(result, i);
|
||||
if (json_is_object(entry))
|
||||
{
|
||||
json_t * name_holder = json_object_get(entry, "name");
|
||||
json_t * inode_holder = json_object_get(entry, "inode");
|
||||
|
||||
if ((json_is_string(name_holder)) && (json_is_integer(inode_holder)))
|
||||
{
|
||||
char const * name = json_string_value(name_holder);
|
||||
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
|
||||
wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (WF_GOOD == status)
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
if (((size_t) context->offset) < buffer.position)
|
||||
{
|
||||
fuse_reply_buf(context->request, &buffer.data[context->offset],
|
||||
wf_impl_min(buffer.position - context->offset, context->size));
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_buf(context->request, NULL, 0);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(context->request, ENOENT);
|
||||
}
|
||||
|
||||
wf_impl_dirbuffer_dispose(&buffer);
|
||||
free(context);
|
||||
}
|
||||
|
||||
void wf_impl_operation_readdir (
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct wf_impl_operation_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
struct wf_impl_operation_readdir_context * readdir_context = malloc(sizeof(struct wf_impl_operation_readdir_context));
|
||||
readdir_context->request = request;
|
||||
readdir_context->size = size;
|
||||
readdir_context->offset = offset;
|
||||
|
||||
wf_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse_reply_err(request, ENOENT);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_OPERATION_READDIR_H
|
||||
#define WF_ADAPTER_IMPL_OPERATION_READDIR_H
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_operation_readdir_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
size_t size;
|
||||
off_t offset;
|
||||
};
|
||||
|
||||
extern void wf_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 wf_impl_operation_readdir_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,131 +0,0 @@
|
||||
#include "webfuse/adapter/server.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
#include "webfuse/adapter/impl/server_protocol.h"
|
||||
#include "webfuse/core/lws_log.h"
|
||||
|
||||
#define WF_SERVER_PROTOCOL_COUNT 3
|
||||
|
||||
struct wf_server
|
||||
{
|
||||
struct wf_server_config config;
|
||||
struct wf_server_protocol protocol;
|
||||
struct lws_protocols ws_protocols[WF_SERVER_PROTOCOL_COUNT];
|
||||
struct lws_context * context;
|
||||
struct lws_http_mount mount;
|
||||
struct lws_context_creation_info info;
|
||||
int port;
|
||||
};
|
||||
|
||||
static bool wf_impl_server_tls_enabled(
|
||||
struct wf_server * server)
|
||||
{
|
||||
return ((server->config.key_path != NULL) && (server->config.cert_path != NULL));
|
||||
}
|
||||
|
||||
static struct lws_context * wf_impl_server_context_create(
|
||||
struct wf_server * server)
|
||||
{
|
||||
wf_lwslog_disable();
|
||||
|
||||
memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT);
|
||||
server->ws_protocols[0].name = "http";
|
||||
server->ws_protocols[0].callback = lws_callback_http_dummy;
|
||||
wf_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,
|
||||
server->mount.mountpoint = "/",
|
||||
server->mount.origin = server->config.document_root,
|
||||
server->mount.def = "index.html",
|
||||
server->mount.origin_protocol = LWSMPRO_FILE,
|
||||
server->mount.mountpoint_len = 1,
|
||||
|
||||
memset(&server->info, 0, sizeof(struct lws_context_creation_info));
|
||||
server->info.port = server->config.port;
|
||||
server->info.mounts = &server->mount;
|
||||
server->info.protocols = server->ws_protocols;
|
||||
server->info.vhost_name = server->config.vhost_name;
|
||||
server->info.ws_ping_pong_interval = 10;
|
||||
server->info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
|
||||
server->info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
|
||||
|
||||
if (NULL == server->config.document_root)
|
||||
{
|
||||
// disable http
|
||||
server->info.protocols = &server->ws_protocols[1];
|
||||
server->info.mounts = NULL;
|
||||
}
|
||||
|
||||
if (wf_impl_server_tls_enabled(server))
|
||||
{
|
||||
server->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
server->info.ssl_cert_filepath = server->config.cert_path;
|
||||
server->info.ssl_private_key_filepath = server->config.key_path;
|
||||
}
|
||||
|
||||
struct lws_context * const context = lws_create_context(&server->info);
|
||||
|
||||
struct lws_vhost * const vhost = lws_create_vhost(context, &server->info);
|
||||
server->port = lws_get_vhost_port(vhost);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
struct wf_server * wf_impl_server_create(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
struct wf_server * server = NULL;
|
||||
|
||||
if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory))
|
||||
{
|
||||
server = malloc(sizeof(struct wf_server));
|
||||
wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory);
|
||||
wf_impl_server_config_clone(config, &server->config);
|
||||
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
||||
server->context = wf_impl_server_context_create(server);
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
void wf_impl_server_dispose(
|
||||
struct wf_server * server)
|
||||
{
|
||||
lws_context_destroy(server->context);
|
||||
wf_impl_server_protocol_cleanup(&server->protocol);
|
||||
wf_impl_server_config_cleanup(&server->config);
|
||||
free(server);
|
||||
}
|
||||
|
||||
bool wf_impl_server_is_operational(
|
||||
struct wf_server * server)
|
||||
{
|
||||
return server->protocol.is_operational;
|
||||
}
|
||||
|
||||
void wf_impl_server_service(
|
||||
struct wf_server * server)
|
||||
{
|
||||
lws_service(server->context, 0);
|
||||
}
|
||||
|
||||
void wf_impl_server_interrupt(
|
||||
struct wf_server * server)
|
||||
{
|
||||
lws_cancel_service(server->context);
|
||||
}
|
||||
|
||||
extern int wf_impl_server_get_port(
|
||||
struct wf_server const * server)
|
||||
{
|
||||
return server->port;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_server;
|
||||
struct wf_server_config;
|
||||
|
||||
extern struct wf_server * wf_impl_server_create(
|
||||
struct wf_server_config * config);
|
||||
|
||||
extern void wf_impl_server_dispose(
|
||||
struct wf_server * server);
|
||||
|
||||
extern bool wf_impl_server_is_operational(
|
||||
struct wf_server * server);
|
||||
|
||||
extern void wf_impl_server_service(
|
||||
struct wf_server * server);
|
||||
|
||||
extern void wf_impl_server_interrupt(
|
||||
struct wf_server * server);
|
||||
|
||||
extern int wf_impl_server_get_port(
|
||||
struct wf_server const * server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char * wf_impl_server_config_strdup(char const * value)
|
||||
{
|
||||
char * result = NULL;
|
||||
if (NULL != value)
|
||||
{
|
||||
result = strdup(value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_server_config_init(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
memset(config, 0, sizeof(struct wf_server_config));
|
||||
|
||||
wf_impl_authenticators_init(&config->authenticators);
|
||||
wf_impl_mountpoint_factory_init_default(&config->mountpoint_factory);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_cleanup(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
wf_impl_authenticators_cleanup(&config->authenticators);
|
||||
wf_impl_mountpoint_factory_cleanup(&config->mountpoint_factory);
|
||||
|
||||
free(config->document_root);
|
||||
free(config->key_path);
|
||||
free(config->cert_path);
|
||||
free(config->vhost_name);
|
||||
|
||||
wf_impl_server_config_init(config);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_clone(
|
||||
struct wf_server_config * config,
|
||||
struct wf_server_config * clone)
|
||||
{
|
||||
clone->document_root = wf_impl_server_config_strdup(config->document_root);
|
||||
clone->key_path = wf_impl_server_config_strdup(config->key_path);
|
||||
clone->cert_path = wf_impl_server_config_strdup(config->cert_path);
|
||||
clone->vhost_name = wf_impl_server_config_strdup(config->vhost_name);
|
||||
clone->port = config->port;
|
||||
|
||||
wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators);
|
||||
wf_impl_mountpoint_factory_clone(&config->mountpoint_factory, &clone->mountpoint_factory);
|
||||
}
|
||||
|
||||
struct wf_server_config * wf_impl_server_config_create(void)
|
||||
{
|
||||
struct wf_server_config * config = malloc(sizeof(struct wf_server_config));
|
||||
wf_impl_server_config_init(config);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
void wf_impl_server_config_dispose(
|
||||
struct wf_server_config * config)
|
||||
{
|
||||
wf_impl_server_config_cleanup(config);
|
||||
free(config);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_mountpoint_factory(
|
||||
struct wf_server_config * config,
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * create_mountpoint_context)
|
||||
{
|
||||
wf_impl_mountpoint_factory_init(&config->mountpoint_factory,
|
||||
create_mountpoint, create_mountpoint_context);
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_server_config_set_documentroot(
|
||||
struct wf_server_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
free(config->document_root);
|
||||
config->document_root = strdup(document_root);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_keypath(
|
||||
struct wf_server_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
free(config->key_path);
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_certpath(
|
||||
struct wf_server_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
free(config->cert_path);
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_vhostname(
|
||||
struct wf_server_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
free(config->vhost_name);
|
||||
config->vhost_name = strdup(vhost_name);
|
||||
}
|
||||
|
||||
void wf_impl_server_config_set_port(
|
||||
struct wf_server_config * config,
|
||||
int port)
|
||||
{
|
||||
config->port = port;
|
||||
}
|
||||
|
||||
void wf_impl_server_config_add_authenticator(
|
||||
struct wf_server_config * config,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
)
|
||||
{
|
||||
wf_impl_authenticators_add(&config->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_CONFIG_H
|
||||
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_server_config
|
||||
{
|
||||
char * document_root;
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * vhost_name;
|
||||
int port;
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_mountpoint_factory mountpoint_factory;
|
||||
};
|
||||
|
||||
extern struct wf_server_config * wf_impl_server_config_create(void);
|
||||
|
||||
extern void wf_impl_server_config_dispose(
|
||||
struct wf_server_config * config);
|
||||
|
||||
extern void wf_impl_server_config_init(
|
||||
struct wf_server_config * config);
|
||||
|
||||
extern void wf_impl_server_config_cleanup(
|
||||
struct wf_server_config * config);
|
||||
|
||||
extern void wf_impl_server_config_clone(
|
||||
struct wf_server_config * config,
|
||||
struct wf_server_config * clone);
|
||||
|
||||
extern void wf_impl_server_config_set_mountpoint_factory(
|
||||
struct wf_server_config * config,
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * create_mountpoint_context);
|
||||
|
||||
extern void wf_impl_server_config_set_documentroot(
|
||||
struct wf_server_config * config,
|
||||
char const * document_root);
|
||||
|
||||
extern void wf_impl_server_config_set_keypath(
|
||||
struct wf_server_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void wf_impl_server_config_set_certpath(
|
||||
struct wf_server_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void wf_impl_server_config_set_vhostname(
|
||||
struct wf_server_config * config,
|
||||
char const * vhost_name);
|
||||
|
||||
extern void wf_impl_server_config_set_port(
|
||||
struct wf_server_config * config,
|
||||
int port);
|
||||
|
||||
extern void wf_impl_server_config_add_authenticator(
|
||||
struct wf_server_config * config,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data
|
||||
);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,249 +0,0 @@
|
||||
#include "webfuse/adapter/impl/server_protocol.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include "webfuse/core/status_intern.h"
|
||||
|
||||
#include "webfuse/core/jsonrpc/request.h"
|
||||
#include "webfuse/core/timer/manager.h"
|
||||
#include "webfuse/core/timer/timer.h"
|
||||
|
||||
static int wf_impl_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WF_UNUSED_PARAM(user),
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
if (NULL == ws_protocol) { return 0; }
|
||||
if (ws_protocol->callback != &wf_impl_server_protocol_callback) { return 0; }
|
||||
|
||||
struct wf_server_protocol * protocol = ws_protocol->user;
|
||||
wf_timer_manager_check(protocol->timer_manager);
|
||||
struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi);
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
protocol->is_operational = true;
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wf_impl_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->mountpoint_factory,
|
||||
protocol->timer_manager,
|
||||
protocol->server);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_impl_session_authenticate(session, NULL);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
wf_impl_session_manager_remove(&protocol->session_manager, wsi);
|
||||
break;
|
||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_impl_session_onwritable(session);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_impl_session_receive(session, in, len);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_impl_session_process_filesystem_request(session, wsi);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct wf_server_protocol * wf_impl_server_protocol_create(
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * create_mountpoint_context)
|
||||
{
|
||||
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
|
||||
struct wf_impl_mountpoint_factory mountpoint_factory;
|
||||
wf_impl_mountpoint_factory_init(&mountpoint_factory,
|
||||
create_mountpoint, create_mountpoint_context);
|
||||
|
||||
wf_impl_server_protocol_init(protocol, &mountpoint_factory);
|
||||
|
||||
return protocol;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_server_protocol_dispose(
|
||||
struct wf_server_protocol * protocol)
|
||||
{
|
||||
wf_impl_server_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_init_lws(
|
||||
struct wf_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->name = WF_PROTOCOL_NAME_ADAPTER_SERVER;
|
||||
lws_protocol->callback = &wf_impl_server_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
static void wf_impl_server_protocol_authenticate(
|
||||
struct wf_jsonrpc_request * request,
|
||||
char const * WF_UNUSED_PARAM(method_name),
|
||||
json_t * params,
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
json_t * type_holder = json_array_get(params, 0);
|
||||
json_t * creds_holder = json_array_get(params, 1);
|
||||
|
||||
if (json_is_string(type_holder) && json_is_object(creds_holder))
|
||||
{
|
||||
char const * type = json_string_value(type_holder);
|
||||
struct wf_credentials creds;
|
||||
|
||||
wf_impl_credentials_init(&creds, type, creds_holder);
|
||||
struct wf_impl_session * session = wf_jsonrpc_request_get_userdata(request);
|
||||
result = wf_impl_session_authenticate(session, &creds);
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
|
||||
if (result)
|
||||
{
|
||||
json_t * result = json_object();
|
||||
wf_jsonrpc_respond(request, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
wf_jsonrpc_respond_error(request, WF_BAD_ACCESS_DENIED, wf_status_tostring(WF_BAD_ACCESS_DENIED));
|
||||
}
|
||||
}
|
||||
|
||||
static bool wf_impl_server_protocol_check_name(char const * value)
|
||||
{
|
||||
while ('\0' != *value)
|
||||
{
|
||||
char const c = * value;
|
||||
if (!isalpha(c) && !isdigit(c) && ('_' != c))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
value++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wf_impl_server_protocol_add_filesystem(
|
||||
struct wf_jsonrpc_request * request,
|
||||
char const * WF_UNUSED_PARAM(method_name),
|
||||
json_t * params,
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
struct wf_impl_session * session = wf_jsonrpc_request_get_userdata(request);
|
||||
wf_status status = (session->is_authenticated) ? WF_GOOD : WF_BAD_ACCESS_DENIED;
|
||||
|
||||
char const * name = NULL;
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
json_t * name_holder = json_array_get(params, 0);
|
||||
if (json_is_string(name_holder))
|
||||
{
|
||||
name = json_string_value(name_holder);
|
||||
if (wf_impl_server_protocol_check_name(name))
|
||||
{
|
||||
bool const success = wf_impl_session_add_filesystem(session, name);
|
||||
if (!success)
|
||||
{
|
||||
status = WF_BAD;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = WF_BAD_FORMAT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (WF_GOOD == status)
|
||||
{
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "id", json_string(name));
|
||||
wf_jsonrpc_respond(request, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
wf_jsonrpc_respond_error(request, status, wf_status_tostring(status));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_init(
|
||||
struct wf_server_protocol * protocol,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory)
|
||||
{
|
||||
protocol->is_operational = false;
|
||||
|
||||
wf_impl_mountpoint_factory_clone(mountpoint_factory, &protocol->mountpoint_factory);
|
||||
|
||||
protocol->timer_manager = wf_timer_manager_create();
|
||||
wf_impl_session_manager_init(&protocol->session_manager);
|
||||
wf_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
protocol->server = wf_jsonrpc_server_create();
|
||||
wf_jsonrpc_server_add(protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol);
|
||||
wf_jsonrpc_server_add(protocol->server, "add_filesystem", &wf_impl_server_protocol_add_filesystem, protocol);
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_cleanup(
|
||||
struct wf_server_protocol * protocol)
|
||||
{
|
||||
protocol->is_operational = false;
|
||||
|
||||
wf_jsonrpc_server_dispose(protocol->server);
|
||||
wf_timer_manager_dispose(protocol->timer_manager);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wf_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
wf_impl_mountpoint_factory_cleanup(&protocol->mountpoint_factory);
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_add_authenticator(
|
||||
struct wf_server_protocol * protocol,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data)
|
||||
{
|
||||
wf_impl_authenticators_add(&protocol->authenticators, type, authenticate, user_data);
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/jsonrpc/server.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws_protocols;
|
||||
struct wf_timer_manager;
|
||||
|
||||
struct wf_server_protocol
|
||||
{
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_mountpoint_factory mountpoint_factory;
|
||||
struct wf_impl_session_manager session_manager;
|
||||
struct wf_jsonrpc_server * server;
|
||||
struct wf_timer_manager * timer_manager;
|
||||
bool is_operational;
|
||||
};
|
||||
|
||||
extern void wf_impl_server_protocol_init(
|
||||
struct wf_server_protocol * protocol,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory);
|
||||
|
||||
extern void wf_impl_server_protocol_cleanup(
|
||||
struct wf_server_protocol * protocol);
|
||||
|
||||
extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create(
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * create_mountpoint_context);
|
||||
|
||||
extern void wf_impl_server_protocol_dispose(
|
||||
struct wf_server_protocol * protocol);
|
||||
|
||||
extern void wf_impl_server_protocol_init_lws(
|
||||
struct wf_server_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
extern void wf_impl_server_protocol_add_authenticator(
|
||||
struct wf_server_protocol * protocol,
|
||||
char const * type,
|
||||
wf_authenticate_fn * authenticate,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,214 +0,0 @@
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
#include "webfuse/core/container_of.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/jsonrpc/request.h"
|
||||
#include "webfuse/core/jsonrpc/response.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
static bool wf_impl_session_send(
|
||||
json_t * request,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_session * session = user_data;
|
||||
struct wf_message * message = wf_message_create(request);
|
||||
|
||||
bool result = (session->is_authenticated || wf_jsonrpc_is_response(request)) && (NULL != session->wsi);
|
||||
|
||||
if (result)
|
||||
{
|
||||
wf_slist_append(&session->messages, &message->item);
|
||||
lws_callback_on_writable(session->wsi);
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
wf_message_dispose(message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct wf_impl_session * wf_impl_session_create(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct wf_jsonrpc_server * server,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory)
|
||||
{
|
||||
|
||||
struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session));
|
||||
wf_slist_init(&session->filesystems);
|
||||
|
||||
session->wsi = wsi;
|
||||
session->is_authenticated = false;
|
||||
session->authenticators = authenticators;
|
||||
session->server = server;
|
||||
session->mountpoint_factory = mountpoint_factory;
|
||||
session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||
wf_slist_init(&session->messages);
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
static void wf_impl_session_dispose_filesystems(
|
||||
struct wf_slist * filesystems)
|
||||
{
|
||||
struct wf_slist_item * item = wf_slist_first(filesystems);
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_filesystem * filesystem = wf_container_of(item, struct wf_impl_filesystem, item);
|
||||
wf_impl_filesystem_dispose(filesystem);
|
||||
|
||||
item = next;
|
||||
}
|
||||
}
|
||||
|
||||
void wf_impl_session_dispose(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
wf_jsonrpc_proxy_dispose(session->rpc);
|
||||
wf_message_queue_cleanup(&session->messages);
|
||||
|
||||
wf_impl_session_dispose_filesystems(&session->filesystems);
|
||||
free(session);
|
||||
}
|
||||
|
||||
bool wf_impl_session_authenticate(
|
||||
struct wf_impl_session * session,
|
||||
struct wf_credentials * creds)
|
||||
{
|
||||
session->is_authenticated = wf_impl_authenticators_authenticate(session->authenticators, creds);
|
||||
|
||||
return session->is_authenticated;
|
||||
}
|
||||
|
||||
bool wf_impl_session_add_filesystem(
|
||||
struct wf_impl_session * session,
|
||||
char const * name)
|
||||
{
|
||||
bool result;
|
||||
|
||||
struct wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(session->mountpoint_factory, name);
|
||||
result = (NULL != mountpoint);
|
||||
|
||||
if (result)
|
||||
{
|
||||
struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session->wsi, session->rpc, name, mountpoint);
|
||||
result = (NULL != filesystem);
|
||||
if (result)
|
||||
{
|
||||
wf_slist_append(&session->filesystems, &filesystem->item);
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup on error
|
||||
if (!result)
|
||||
{
|
||||
if (NULL != mountpoint)
|
||||
{
|
||||
wf_impl_mountpoint_dispose(mountpoint);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_session_onwritable(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
if (!wf_slist_empty(&session->messages))
|
||||
{
|
||||
struct wf_slist_item * item = wf_slist_remove_first(&session->messages);
|
||||
struct wf_message * message = wf_container_of(item, struct wf_message, item);
|
||||
lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||
wf_message_dispose(message);
|
||||
|
||||
if (!wf_slist_empty(&session->messages))
|
||||
{
|
||||
lws_callback_on_writable(session->wsi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_session_receive(
|
||||
struct wf_impl_session * session,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
json_t * message = json_loadb(data, length, 0, NULL);
|
||||
if (NULL != message)
|
||||
{
|
||||
if (wf_jsonrpc_is_response(message))
|
||||
{
|
||||
wf_jsonrpc_proxy_onresult(session->rpc, message);
|
||||
}
|
||||
else if (wf_jsonrpc_is_request(message))
|
||||
{
|
||||
wf_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
|
||||
}
|
||||
|
||||
json_decref(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static struct wf_impl_filesystem * wf_impl_session_get_filesystem(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wf_impl_filesystem * result = NULL;
|
||||
|
||||
struct wf_slist_item * item = wf_slist_first(&session->filesystems);
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_filesystem * filesystem = wf_container_of(item, struct wf_impl_filesystem, item);
|
||||
if (wsi == filesystem->wsi)
|
||||
{
|
||||
result = filesystem;
|
||||
break;
|
||||
}
|
||||
|
||||
item = next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool wf_impl_session_contains_wsi(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi)
|
||||
{
|
||||
bool const result = (NULL != wsi) && ((wsi == session->wsi) || (NULL != wf_impl_session_get_filesystem(session, wsi)));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_session_process_filesystem_request(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wf_impl_filesystem * filesystem = wf_impl_session_get_filesystem(session, wsi);
|
||||
if (NULL != filesystem)
|
||||
{
|
||||
wf_impl_filesystem_process_request(filesystem);
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SESSION_H
|
||||
#define WF_ADAPTER_IMPL_SESSION_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/core/slist.h"
|
||||
|
||||
#include "webfuse/core/jsonrpc/proxy.h"
|
||||
#include "webfuse/core/jsonrpc/server.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wf_message;
|
||||
struct wf_credentials;
|
||||
struct wf_impl_authenticators;
|
||||
struct wf_impl_mountpoint_factory;
|
||||
|
||||
struct wf_impl_session
|
||||
{
|
||||
struct wf_slist_item item;
|
||||
struct lws * wsi;
|
||||
bool is_authenticated;
|
||||
struct wf_slist messages;
|
||||
struct wf_impl_authenticators * authenticators;
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory;
|
||||
struct wf_jsonrpc_server * server;
|
||||
struct wf_jsonrpc_proxy * rpc;
|
||||
struct wf_slist filesystems;
|
||||
};
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_create(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct wf_jsonrpc_server * server,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory);
|
||||
|
||||
extern void wf_impl_session_dispose(
|
||||
struct wf_impl_session * session);
|
||||
|
||||
extern bool wf_impl_session_authenticate(
|
||||
struct wf_impl_session * session,
|
||||
struct wf_credentials * creds);
|
||||
|
||||
extern bool wf_impl_session_add_filesystem(
|
||||
struct wf_impl_session * session,
|
||||
char const * name);
|
||||
|
||||
extern void wf_impl_session_receive(
|
||||
struct wf_impl_session * session,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
extern void wf_impl_session_onwritable(
|
||||
struct wf_impl_session * session);
|
||||
|
||||
extern bool wf_impl_session_contains_wsi(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi);
|
||||
|
||||
extern void wf_impl_session_process_filesystem_request(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,82 +0,0 @@
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/container_of.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void wf_impl_session_manager_init(
|
||||
struct wf_impl_session_manager * manager)
|
||||
{
|
||||
wf_slist_init(&manager->sessions);
|
||||
}
|
||||
|
||||
void wf_impl_session_manager_cleanup(
|
||||
struct wf_impl_session_manager * manager)
|
||||
{
|
||||
struct wf_slist_item * item = wf_slist_first(&manager->sessions);
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
|
||||
wf_impl_session_dispose(session);
|
||||
|
||||
item = next;
|
||||
}
|
||||
}
|
||||
|
||||
struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct wf_jsonrpc_server * server)
|
||||
{
|
||||
struct wf_impl_session * session = wf_impl_session_create(
|
||||
wsi, authenticators, timer_manager, server, mountpoint_factory);
|
||||
wf_slist_append(&manager->sessions, &session->item);
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wf_impl_session * session = NULL;
|
||||
|
||||
struct wf_slist_item * item = wf_slist_first(&manager->sessions);
|
||||
while (NULL != item)
|
||||
{
|
||||
struct wf_slist_item * next = item->next;
|
||||
struct wf_impl_session * current = wf_container_of(item, struct wf_impl_session, item);
|
||||
|
||||
if (wf_impl_session_contains_wsi(current, wsi)) {
|
||||
session = current;
|
||||
break;
|
||||
}
|
||||
|
||||
item = next;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
void wf_impl_session_manager_remove(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wf_slist_item * prev = &manager->sessions.head;
|
||||
while (NULL != prev->next)
|
||||
{
|
||||
struct wf_slist_item * item = prev->next;
|
||||
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
|
||||
if (wsi == session->wsi)
|
||||
{
|
||||
wf_slist_remove_after(&manager->sessions, prev);
|
||||
wf_impl_session_dispose(session);
|
||||
break;
|
||||
}
|
||||
|
||||
prev = prev->next;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SESSION_MANAGER_H
|
||||
#define WF_ADAPTER_IMPL_SESSION_MANAGER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
#include "webfuse/core/slist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wf_timer_manager;
|
||||
struct wf_jsonrpc_server;
|
||||
|
||||
struct wf_impl_session_manager
|
||||
{
|
||||
struct wf_slist sessions;
|
||||
};
|
||||
|
||||
extern void wf_impl_session_manager_init(
|
||||
struct wf_impl_session_manager * manager);
|
||||
|
||||
extern void wf_impl_session_manager_cleanup(
|
||||
struct wf_impl_session_manager * manager);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct wf_jsonrpc_server * server);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
extern void wf_impl_session_manager_remove(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user