mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
added more client stub (not functional yet)
This commit is contained in:
parent
9d2502952f
commit
b1c72dab3c
@ -100,7 +100,9 @@ install(FILES "${PROJECT_BINARY_DIR}/libwsfs.pc" DESTINATION lib${LIB_SUFFIX}/pk
|
||||
|
||||
set(WSFS_PROVIDER_SOURCES
|
||||
lib/wsfsp/client.c
|
||||
lib/wsfsp/client_protocol.c
|
||||
lib/wsfsp/provider.c
|
||||
lib/wsfsp/provider_default.c
|
||||
)
|
||||
|
||||
add_library(wsfs-provider SHARED ${WSFS_PROVIDER_SOURCES})
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef _WSFSP_CLIENT_PROTOCOL_H
|
||||
#define _WSFSP_CLIENT_PROTOCOL_H
|
||||
|
||||
#include "wsfs/api.h"
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_client_protocol;
|
||||
struct wsfsp_provider;
|
||||
|
@ -4,13 +4,23 @@
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfsp/provider.h"
|
||||
#include "wsfsp/client_protocol_intern.h"
|
||||
|
||||
#define WSFSP_DISABLE_LWS_LOG 0
|
||||
#define WSFSP_CLIENT_PROTOCOL_COUNT 2
|
||||
#define WSFSP_CLIENT_TIMEOUT (1 * 1000)
|
||||
|
||||
struct wsfsp_client
|
||||
{
|
||||
volatile bool is_running;
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
struct wsfsp_client_protocol protocol;
|
||||
struct lws_context_creation_info info;
|
||||
struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT];
|
||||
struct lws_context * context;
|
||||
};
|
||||
|
||||
|
||||
@ -18,12 +28,25 @@ struct wsfsp_client * wsfsp_client_create(
|
||||
struct wsfsp_provider * provider,
|
||||
void * user_data)
|
||||
{
|
||||
lws_set_log_level(WSFSP_DISABLE_LWS_LOG, NULL);
|
||||
|
||||
struct wsfsp_client * client = malloc(sizeof(struct wsfsp_client));
|
||||
if (NULL != client)
|
||||
{
|
||||
client->is_running = true;
|
||||
client->user_data = user_data;
|
||||
memcpy(&client->provider, provider, sizeof(struct wsfsp_provider));
|
||||
wsfsp_client_protocol_init(&client->protocol, provider, user_data);
|
||||
|
||||
memset(client->protocols, 0, sizeof(struct lws_protocols) * WSFSP_CLIENT_PROTOCOL_COUNT);
|
||||
client->protocols[0].name = "fs-provider";
|
||||
wsfsp_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;
|
||||
|
||||
client->context = lws_create_context(&client->info);
|
||||
}
|
||||
|
||||
return client;
|
||||
@ -32,6 +55,8 @@ struct wsfsp_client * wsfsp_client_create(
|
||||
void wsfsp_client_dispose(
|
||||
struct wsfsp_client * client)
|
||||
{
|
||||
lws_context_destroy(client->context);
|
||||
wsfsp_client_protocol_cleanup(&client->protocol);
|
||||
free(client);
|
||||
}
|
||||
|
||||
@ -69,8 +94,7 @@ void wsfsp_client_run(
|
||||
{
|
||||
while (client->is_running)
|
||||
{
|
||||
// ToDo: implement me
|
||||
break;
|
||||
lws_service(client->context, WSFSP_CLIENT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
72
lib/wsfsp/client_protocol.c
Normal file
72
lib/wsfsp/client_protocol.c
Normal file
@ -0,0 +1,72 @@
|
||||
#include "wsfsp/client_protocol_intern.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "wsfsp/provider_default.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
static int wsfsp_client_protocol_callback(
|
||||
struct lws * WSFS_UNUSED_PARAM(wsi),
|
||||
enum lws_callback_reasons WSFS_UNUSED_PARAM(reason),
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
void * WSFS_UNUSED_PARAM(in),
|
||||
size_t WSFS_UNUSED_PARAM(len))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void wsfsp_client_protocol_init(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
protocol->user_data = user_data;
|
||||
protocol->provider.lookup = (NULL != provider->lookup) ? provider->lookup : &wsfsp_lookup_default;
|
||||
protocol->provider.getattr = (NULL != provider->getattr) ? provider->getattr : &wsfsp_getattr_default;
|
||||
protocol->provider.readdir = (NULL != provider->readdir) ? provider->readdir : &wsfsp_readdir_default;
|
||||
protocol->provider.open = (NULL != provider->open) ? provider->open : &wsfsp_open_default;
|
||||
protocol->provider.close = (NULL != provider->close) ? provider->close : &wsfsp_close_default;
|
||||
protocol->provider.read = (NULL != provider->read) ? provider->read : &wsfsp_read_default;
|
||||
protocol->provider.connected = (NULL != provider->connected) ? provider->connected : &wsfsp_connected_default;
|
||||
protocol->provider.disconnected = (NULL != provider->disconnected) ? provider->disconnected : &wsfsp_disconnected_default;
|
||||
protocol->provider.ontimer = (NULL != provider->ontimer) ? provider->ontimer : &wsfsp_ontimer_default;
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_cleanup(
|
||||
struct wsfsp_client_protocol * protocol)
|
||||
{
|
||||
(void) protocol;
|
||||
}
|
||||
|
||||
struct wsfsp_client_protocol * wsfsp_client_protocol_create(
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
struct wsfsp_client_protocol * protocol = malloc(sizeof(struct wsfsp_client_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
wsfsp_client_protocol_init(protocol, provider, user_data);
|
||||
}
|
||||
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_dispose(
|
||||
struct wsfsp_client_protocol * protocol)
|
||||
{
|
||||
wsfsp_client_protocol_cleanup(protocol);
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void wsfsp_client_protocol_init_lws(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->callback = &wsfsp_client_protocol_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
30
lib/wsfsp/client_protocol_intern.h
Normal file
30
lib/wsfsp/client_protocol_intern.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef _WSFSP_CLIENT_PROTOCOL_INTERN_H
|
||||
#define _WSFSP_CLIENT_PROTOCOL_INTERN_H
|
||||
|
||||
#include "wsfsp/client_protocol.h"
|
||||
#include "wsfsp/provider.h"
|
||||
|
||||
struct wsfsp_client_protocol
|
||||
{
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_client_protocol_init(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_client_protocol_cleanup(
|
||||
struct wsfsp_client_protocol * protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
106
lib/wsfsp/provider_default.c
Normal file
106
lib/wsfsp/provider_default.c
Normal file
@ -0,0 +1,106 @@
|
||||
#include "wsfsp/provider_default.h"
|
||||
|
||||
void wsfsp_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data)
|
||||
{
|
||||
(void) parent;
|
||||
(void) name;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
void wsfsp_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data)
|
||||
{
|
||||
(void) inode;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
void wsfsp_readdir_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
struct wsfsp_dirbuffer * dirbuffer,
|
||||
void * user_data)
|
||||
{
|
||||
(void) directory;
|
||||
(void) dirbuffer;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
void wsfsp_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data)
|
||||
{
|
||||
(void) inode;
|
||||
(void) flags;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
void wsfsp_close_default(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data)
|
||||
{
|
||||
(void) inode;
|
||||
(void) handle;
|
||||
(void) flags;
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wsfsp_read_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data)
|
||||
{
|
||||
(void) inode;
|
||||
(void) handle;
|
||||
(void) offset;
|
||||
(void) length;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
void wsfsp_connected_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wsfsp_disconnected_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void wsfsp_ontimer_default(
|
||||
void * user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
62
lib/wsfsp/provider_default.h
Normal file
62
lib/wsfsp/provider_default.h
Normal file
@ -0,0 +1,62 @@
|
||||
#ifndef _WSFSP_PROVIDER_DEFAULT_H
|
||||
#define _WSFSP_PROVIDER_DEFAULT_H
|
||||
|
||||
#include "wsfsp/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_readdir_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
struct wsfsp_dirbuffer * dirbuffer,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_close_default(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_read_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_connected_default(
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_disconnected_default(
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_ontimer_default(
|
||||
void * user_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user