mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
separated client opertation stubs
This commit is contained in:
parent
75c80de1b9
commit
bc0dc2889d
@ -101,9 +101,16 @@ 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
|
||||
lib/wsfsp/url.c
|
||||
lib/wsfsp/provider.c
|
||||
lib/wsfsp/operation/error.c
|
||||
lib/wsfsp/operation/lookup.c
|
||||
lib/wsfsp/operation/getattr.c
|
||||
lib/wsfsp/operation/readdir.c
|
||||
lib/wsfsp/operation/open.c
|
||||
lib/wsfsp/operation/close.c
|
||||
lib/wsfsp/operation/read.c
|
||||
)
|
||||
|
||||
add_library(wsfs-provider SHARED ${WSFS_PROVIDER_SOURCES})
|
||||
|
@ -59,11 +59,9 @@ static void fs_getattr(
|
||||
static void fs_readdir(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
struct wsfsp_dirbuffer * dirbuffer,
|
||||
void * user_data)
|
||||
{
|
||||
(void) directory;
|
||||
(void) dirbuffer;
|
||||
(void) user_data;
|
||||
|
||||
puts("readdir");
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef WSFS_H
|
||||
#define WSFS_H
|
||||
|
||||
#include "wsfs/api.h"
|
||||
#include "wsfs/server.h"
|
||||
#include "wsfs/server_config.h"
|
||||
#include "wsfs/server_protocol.h"
|
||||
#include <wsfs/api.h>
|
||||
#include <wsfs/server.h>
|
||||
#include <wsfs/server_config.h>
|
||||
#include <wsfs/server_protocol.h>
|
||||
|
||||
#endif
|
||||
|
@ -1,9 +1,18 @@
|
||||
#ifndef WSFSP_H
|
||||
#define WSFSP_H
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
#include "wsfsp/provider.h"
|
||||
#include "wsfsp/client.h"
|
||||
#include "wsfsp/client_protocol.h"
|
||||
#include <wsfsp/api.h>
|
||||
#include <wsfsp/client.h>
|
||||
#include <wsfsp/client_protocol.h>
|
||||
#include <wsfsp/provider.h>
|
||||
#include <wsfsp/dirbuffer.h>
|
||||
|
||||
#include <wsfsp/operation/error.h>
|
||||
#include <wsfsp/operation/lookup.h>
|
||||
#include <wsfsp/operation/getattr.h>
|
||||
#include <wsfsp/operation/readdir.h>
|
||||
#include <wsfsp/operation/open.h>
|
||||
#include <wsfsp/operation/close.h>
|
||||
#include <wsfsp/operation/read.h>
|
||||
|
||||
#endif
|
||||
|
32
include/wsfsp/dirbuffer.h
Normal file
32
include/wsfsp/dirbuffer.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef WSFSP_DIRBUFFER_H
|
||||
#define WSFSP_DIRBUFFER_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_dirbuffer;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern WSFSP_API struct wsfsp_dirbuffer * wsfsp_dirbuffer_init(void);
|
||||
|
||||
extern WSFSP_API void wsfsp_dirbuffer_dispose(
|
||||
struct wsfsp_dirbuffer * buffer);
|
||||
|
||||
extern WSFSP_API void wsfsp_dirbuffer_add(
|
||||
struct wsfsp_dirbuffer * buffer,
|
||||
char const * name,
|
||||
ino_t inode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
31
include/wsfsp/operation/close.h
Normal file
31
include/wsfsp/operation/close.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef WSFSP_OPERATION_CLOSE_H
|
||||
#define WSFSP_OPERATION_CLOSE_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
typedef void wsfsp_close_fn(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
21
include/wsfsp/operation/error.h
Normal file
21
include/wsfsp/operation/error.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WSFSP_OPERATION_ERROR_H
|
||||
#define WSFSP_OPERATION_ERROR_H
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
int status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
32
include/wsfsp/operation/getattr.h
Normal file
32
include/wsfsp/operation/getattr.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef WSFSP_OPERATION_GETATTR_H
|
||||
#define WSFSP_OPERATION_GETATTR_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
typedef void wsfsp_getattr_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
32
include/wsfsp/operation/lookup.h
Normal file
32
include/wsfsp/operation/lookup.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef WSFSP_OPERATION_LOOKUP_H
|
||||
#define WSFSP_OPERATION_LOOKUP_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
typedef void wsfsp_lookup_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
38
include/wsfsp/operation/open.h
Normal file
38
include/wsfsp/operation/open.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef WSFSP_OPERATION_OPEN_H
|
||||
#define WSFSP_OPERATION_OPEN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
typedef void wsfsp_open_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
44
include/wsfsp/operation/read.h
Normal file
44
include/wsfsp/operation/read.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef WSFSP_OPERATION_READ_H
|
||||
#define WSFSP_OPERATION_READ_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
#include <cinttypes>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_request;
|
||||
|
||||
typedef void wsfsp_read_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
32
include/wsfsp/operation/readdir.h
Normal file
32
include/wsfsp/operation/readdir.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef WSFSP_OPERATION_READDIR_H
|
||||
#define WSFSP_OPERATION_READDIR_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_dirbuffer;
|
||||
struct wsfsp_request;
|
||||
|
||||
typedef void wsfsp_readdir_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
void * user_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_readdir(
|
||||
struct wsfsp_request * request,
|
||||
struct wsfsp_dirbuffer * dirbuffer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,60 +1,12 @@
|
||||
#ifndef WSFSP_PROVIDER_H
|
||||
#define WSFSP_PROVIDER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
#include <cinttypes>
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfsp/api.h"
|
||||
|
||||
struct wsfsp_request;
|
||||
struct wsfsp_dirbuffer;
|
||||
|
||||
typedef void wsfsp_lookup_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data);
|
||||
|
||||
typedef void wsfsp_getattr_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data);
|
||||
|
||||
typedef void wsfsp_readdir_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
struct wsfsp_dirbuffer * dirbuffer,
|
||||
void * user_data);
|
||||
|
||||
typedef void wsfsp_open_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
typedef void wsfsp_close_fn(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
typedef void wsfsp_read_fn(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data);
|
||||
#include <wsfsp/operation/lookup.h>
|
||||
#include <wsfsp/operation/getattr.h>
|
||||
#include <wsfsp/operation/readdir.h>
|
||||
#include <wsfsp/operation/open.h>
|
||||
#include <wsfsp/operation/close.h>
|
||||
#include <wsfsp/operation/read.h>
|
||||
|
||||
typedef void wsfsp_connected_fn(
|
||||
void * user_data);
|
||||
@ -78,38 +30,5 @@ struct wsfsp_provider
|
||||
wsfsp_read_fn * read;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
int status);
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_readdir(
|
||||
struct wsfsp_request * request,
|
||||
struct wsfsp_dirbuffer * dirbuffer);
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle);
|
||||
|
||||
extern WSFSP_API void wsfsp_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -40,7 +40,7 @@ struct wsfsp_client * wsfsp_client_create(
|
||||
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";
|
||||
client->protocols[0].name = "fs";
|
||||
wsfsp_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||
|
||||
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
|
||||
|
@ -4,31 +4,79 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "wsfsp/provider_default.h"
|
||||
#include "wsfsp/provider_intern.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
static void wsfsp_client_protocol_respond(
|
||||
json_t * response,
|
||||
void * user_data)
|
||||
{
|
||||
// ToDo: implment me
|
||||
(void) user_data;
|
||||
|
||||
char * value = json_dumps(response, 0);
|
||||
if (NULL != value)
|
||||
{
|
||||
puts(value);
|
||||
}
|
||||
free(value);
|
||||
}
|
||||
|
||||
static void wsfsp_client_protocol_process_request(
|
||||
struct wsfsp_client_protocol * protocol,
|
||||
char const * message,
|
||||
size_t length)
|
||||
{
|
||||
json_t * request = json_loadb(message, length, 0, NULL);
|
||||
if (NULL != request)
|
||||
{
|
||||
struct wsfsp_invokation_context context =
|
||||
{
|
||||
.provider = &protocol->provider,
|
||||
.user_data = protocol->user_data,
|
||||
.request = &protocol->request
|
||||
};
|
||||
|
||||
puts("wsfsp_provider_invoke");
|
||||
wsfsp_provider_invoke(&context, request);
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int wsfsp_client_protocol_callback(
|
||||
struct lws * WSFS_UNUSED_PARAM(wsi),
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
void * WSFS_UNUSED_PARAM(in),
|
||||
size_t WSFS_UNUSED_PARAM(len))
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wsfsp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL;
|
||||
|
||||
switch (reason)
|
||||
if (NULL != protocol)
|
||||
{
|
||||
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||
puts("established");
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||
puts("error: client could not connect");
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CLOSED:
|
||||
puts("client closed");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||
puts("established");
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||
protocol->provider.disconnected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CLOSED:
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||
wsfsp_client_protocol_process_request(protocol, in, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -40,6 +88,9 @@ void wsfsp_client_protocol_init(
|
||||
struct wsfsp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
protocol->request.respond = &wsfsp_client_protocol_respond;
|
||||
protocol->request.user_data = protocol;
|
||||
|
||||
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;
|
||||
|
@ -3,9 +3,11 @@
|
||||
|
||||
#include "wsfsp/client_protocol.h"
|
||||
#include "wsfsp/provider.h"
|
||||
#include "wsfsp/request.h"
|
||||
|
||||
struct wsfsp_client_protocol
|
||||
{
|
||||
struct wsfsp_request request;
|
||||
struct wsfsp_provider provider;
|
||||
void * user_data;
|
||||
};
|
||||
|
29
lib/wsfsp/operation/close.c
Normal file
29
lib/wsfsp/operation/close.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include "wsfsp/operation/close_intern.h"
|
||||
#include <limits.h>
|
||||
#include "wsfs/util.h"
|
||||
|
||||
void wsfsp_close(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int WSFS_UNUSED_PARAM(id))
|
||||
{
|
||||
size_t const param_count = json_array_size(params);
|
||||
if (3 == param_count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
json_t * handle_holder = json_array_get(params, 1);
|
||||
json_t * flags_holder = json_array_get(params, 2);
|
||||
|
||||
if (json_is_integer(inode_holder) &&
|
||||
json_is_integer(handle_holder) &&
|
||||
json_is_integer(flags_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
uint32_t handle = (uint32_t) (json_integer_value(handle_holder) & UINT32_MAX);
|
||||
int flags = json_integer_value(flags_holder);
|
||||
|
||||
context->provider->close(inode, handle, flags, context->user_data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
21
lib/wsfsp/operation/close_intern.h
Normal file
21
lib/wsfsp/operation/close_intern.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WSFSP_OPERATION_CLOSE_INTERN_H
|
||||
#define WSFSP_OPERATION_CLOSE_INTERN_H
|
||||
|
||||
#include "wsfsp/operation/close.h"
|
||||
#include "wsfsp/provider_intern.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_close(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
11
lib/wsfsp/operation/error.c
Normal file
11
lib/wsfsp/operation/error.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include "wsfsp/operation/error.h"
|
||||
|
||||
void wsfsp_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
int status)
|
||||
{
|
||||
(void) request;
|
||||
(void) status;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
24
lib/wsfsp/operation/getattr.c
Normal file
24
lib/wsfsp/operation/getattr.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "wsfsp/operation/getattr_intern.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void wsfsp_getattr(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
(void) context;
|
||||
(void) params;
|
||||
(void) id;
|
||||
|
||||
puts("getattr");
|
||||
}
|
||||
|
||||
void wsfsp_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
(void) request;
|
||||
(void) stat;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
21
lib/wsfsp/operation/getattr_intern.h
Normal file
21
lib/wsfsp/operation/getattr_intern.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WSFSP_OPERATION_GETATTR_INTERN_H
|
||||
#define WSFSP_OPERATION_GETATTR_INTERN_H
|
||||
|
||||
#include "wsfsp/operation/getattr.h"
|
||||
#include "wsfsp/provider_intern.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_getattr(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
24
lib/wsfsp/operation/lookup.c
Normal file
24
lib/wsfsp/operation/lookup.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "wsfsp/operation/lookup_intern.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void wsfsp_lookup(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
(void) context;
|
||||
(void) params;
|
||||
(void) id;
|
||||
|
||||
puts("lookup");
|
||||
}
|
||||
|
||||
void wsfsp_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
(void) request;
|
||||
(void) stat;
|
||||
|
||||
}
|
||||
|
21
lib/wsfsp/operation/lookup_intern.h
Normal file
21
lib/wsfsp/operation/lookup_intern.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WSFSP_OPERATION_LOOKUP_INTERN_H
|
||||
#define WSFSP_OPERATION_LOOKUP_INTERN_H
|
||||
|
||||
#include "wsfsp/operation/lookup.h"
|
||||
#include "wsfsp/provider_intern.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_lookup(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
24
lib/wsfsp/operation/open.c
Normal file
24
lib/wsfsp/operation/open.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "wsfsp/operation/open_intern.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void wsfsp_open(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
(void) context;
|
||||
(void) params;
|
||||
(void) id;
|
||||
|
||||
puts("open");
|
||||
}
|
||||
|
||||
void wsfsp_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
(void) request;
|
||||
(void) handle;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
21
lib/wsfsp/operation/open_intern.h
Normal file
21
lib/wsfsp/operation/open_intern.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WSFSP_OPERATION_OPEN_INTERN_H
|
||||
#define WSFSP_OPERATION_OPEN_INTERN_H
|
||||
|
||||
#include "wsfsp/operation/open.h"
|
||||
#include "wsfsp/provider_intern.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_open(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
24
lib/wsfsp/operation/read.c
Normal file
24
lib/wsfsp/operation/read.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "wsfsp/operation/read_intern.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void wsfsp_read(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
(void) context;
|
||||
(void) params;
|
||||
(void) id;
|
||||
|
||||
puts("read");
|
||||
}
|
||||
|
||||
void wsfsp_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
(void) request;
|
||||
(void) data;
|
||||
(void) length;
|
||||
}
|
21
lib/wsfsp/operation/read_intern.h
Normal file
21
lib/wsfsp/operation/read_intern.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WSFSP_OPERATION_READ_INTERN_H
|
||||
#define WSFSP_OPERATION_READ_INTERN_H
|
||||
|
||||
#include "wsfsp/operation/read.h"
|
||||
#include "wsfsp/provider_intern.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_read(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
25
lib/wsfsp/operation/readdir.c
Normal file
25
lib/wsfsp/operation/readdir.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include "wsfsp/operation/readdir_intern.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void wsfsp_readdir(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
(void) context;
|
||||
(void) params;
|
||||
(void) id;
|
||||
|
||||
puts("readdir");
|
||||
}
|
||||
|
||||
void wsfsp_respond_readdir(
|
||||
struct wsfsp_request * request,
|
||||
struct wsfsp_dirbuffer * dirbuffer)
|
||||
{
|
||||
(void) request;
|
||||
(void) dirbuffer;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
21
lib/wsfsp/operation/readdir_intern.h
Normal file
21
lib/wsfsp/operation/readdir_intern.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WSFSP_OPERATION_READDIR_INTERN_H
|
||||
#define WSFSP_OPERATION_READDIR_INTERN_H
|
||||
|
||||
#include "wsfsp/operation/readdir.h"
|
||||
#include "wsfsp/provider_intern.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_readdir(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,63 +1,74 @@
|
||||
#include "wsfsp/provider.h"
|
||||
#include "wsfsp/provider_intern.h"
|
||||
|
||||
void wsfsp_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
int status)
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsfsp/request.h"
|
||||
#include "wsfsp/operation/lookup_intern.h"
|
||||
#include "wsfsp/operation/getattr_intern.h"
|
||||
#include "wsfsp/operation/readdir_intern.h"
|
||||
#include "wsfsp/operation/open_intern.h"
|
||||
#include "wsfsp/operation/close_intern.h"
|
||||
#include "wsfsp/operation/read_intern.h"
|
||||
|
||||
typedef void wsfsp_invoke_fn(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
|
||||
struct wsfsp_method
|
||||
{
|
||||
(void) request;
|
||||
(void) status;
|
||||
char const * name;
|
||||
wsfsp_invoke_fn * invoke;
|
||||
bool is_notification;
|
||||
};
|
||||
|
||||
// ToDo: implement me
|
||||
static void wsfsp_provider_invoke_method(
|
||||
struct wsfsp_invokation_context * context,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
static struct wsfsp_method const methods[] =
|
||||
{
|
||||
{"lookup", &wsfsp_lookup, false},
|
||||
{"getattr", &wsfsp_getattr, false},
|
||||
{"readdir", &wsfsp_readdir, false},
|
||||
{"open", &wsfsp_open, false},
|
||||
{"close", &wsfsp_close, true},
|
||||
{"read", &wsfsp_read, false}
|
||||
};
|
||||
static size_t const count = sizeof(methods) / sizeof(methods[0]);
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
struct wsfsp_method const * method = &methods[i];
|
||||
if (0 == strcmp(method_name, method->name))
|
||||
{
|
||||
if ((0 < id) || (method->is_notification))
|
||||
{
|
||||
method->invoke(context, params, id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_respond_lookup(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
void wsfsp_provider_invoke(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * request)
|
||||
{
|
||||
(void) request;
|
||||
(void) stat;
|
||||
json_t * method_holder = json_object_get(request, "method");
|
||||
json_t * params = json_object_get(request, "params");
|
||||
json_t * id_holder = json_object_get(request, "id");
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
if ((NULL != method_holder) && (json_is_string(method_holder)) &&
|
||||
(NULL != params) && (json_is_array(params)))
|
||||
{
|
||||
char const * method = json_string_value(method_holder);
|
||||
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0;
|
||||
|
||||
void wsfsp_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
(void) request;
|
||||
(void) stat;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void wsfsp_respond_readdir(
|
||||
struct wsfsp_request * request,
|
||||
struct wsfsp_dirbuffer * dirbuffer)
|
||||
{
|
||||
(void) request;
|
||||
(void) dirbuffer;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void wsfsp_respond_open(
|
||||
struct wsfsp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
(void) request;
|
||||
(void) handle;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void wsfsp_respond_read(
|
||||
struct wsfsp_request * request,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
(void) request;
|
||||
(void) data;
|
||||
(void) length;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
wsfsp_provider_invoke_method(context, method, params, id);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#include "wsfsp/provider_default.h"
|
||||
#include "wsfsp/operation/error.h"
|
||||
|
||||
void wsfsp_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
@ -27,11 +28,9 @@ void wsfsp_getattr_default(
|
||||
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);
|
||||
|
@ -22,7 +22,6 @@ extern void wsfsp_getattr_default(
|
||||
extern void wsfsp_readdir_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
struct wsfsp_dirbuffer * dirbuffer,
|
||||
void * user_data);
|
||||
|
||||
extern void wsfsp_open_default(
|
||||
|
27
lib/wsfsp/provider_intern.h
Normal file
27
lib/wsfsp/provider_intern.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef WSFSP_PROVIDER_INTERN_H
|
||||
#define WSFSP_PROVIDER_INTERN_H
|
||||
|
||||
#include "wsfsp/provider.h"
|
||||
#include <jansson.h>
|
||||
|
||||
struct wsfsp_invokation_context
|
||||
{
|
||||
struct wsfsp_provider * provider;
|
||||
void * user_data;
|
||||
struct wsfsp_request * request;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wsfsp_provider_invoke(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * request);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
18
lib/wsfsp/request.h
Normal file
18
lib/wsfsp/request.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef WSFSP_REQUEST_H
|
||||
#define WSFSP_REQUEST_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "wsfsp/provider.h"
|
||||
|
||||
typedef void wsfsp_request_respond_fn(
|
||||
json_t * response,
|
||||
void * user_data);
|
||||
|
||||
struct wsfsp_request
|
||||
{
|
||||
wsfsp_request_respond_fn * respond;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user