mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
renamed to webfuse
This commit is contained in:
38
lib/webfuse/provider/impl/operation/close.c
Normal file
38
lib/webfuse/provider/impl/operation/close.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "webfuse/provider/impl/operation/close.h"
|
||||
#include <limits.h>
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wfp_impl_close(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int WF_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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void wfp_impl_close_default(
|
||||
ino_t WF_UNUSED_PARAM(inode),
|
||||
uint32_t WF_UNUSED_PARAM(handle),
|
||||
int WF_UNUSED_PARAM(flags),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
// empty
|
||||
}
|
||||
26
lib/webfuse/provider/impl/operation/close.h
Normal file
26
lib/webfuse/provider/impl/operation/close.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_CLOSE_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_CLOSE_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_close(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_close_default(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
22
lib/webfuse/provider/impl/operation/error.h
Normal file
22
lib/webfuse/provider/impl/operation/error.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef WFP_OPERATION_IMPL_ERROR_H
|
||||
#define WFP_OPERATION_IMPL_ERROR_H
|
||||
|
||||
#include "webfuse/provider/api.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_request;
|
||||
|
||||
extern WFP_API void wfp_impl_respond_error(
|
||||
struct wfp_request * request,
|
||||
wf_status status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
64
lib/webfuse/provider/impl/operation/getattr.c
Normal file
64
lib/webfuse/provider/impl/operation/getattr.c
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "webfuse/provider/impl/operation/getattr.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
|
||||
void wfp_impl_getattr(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
if (1 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
|
||||
if (json_is_integer(inode_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->getattr(request, inode, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wfp_impl_getattr_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(inode),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wfp_impl_respond_getattr(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
bool const is_file = (0 != (stat->st_mode & S_IFREG));
|
||||
bool const is_dir = (0 != (stat->st_mode & S_IFDIR));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(stat->st_ino));
|
||||
json_object_set_new(result, "mode", json_integer(stat->st_mode & 0777));
|
||||
json_object_set_new(result, "atime", json_integer(stat->st_atime));
|
||||
json_object_set_new(result, "mtime", json_integer(stat->st_mtime));
|
||||
json_object_set_new(result, "ctime", json_integer(stat->st_ctime));
|
||||
|
||||
if (is_file)
|
||||
{
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
json_object_set_new(result, "size", json_integer(stat->st_size));
|
||||
}
|
||||
|
||||
if (is_dir)
|
||||
{
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
}
|
||||
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
29
lib/webfuse/provider/impl/operation/getattr.h
Normal file
29
lib/webfuse/provider/impl/operation/getattr.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_GETATTR_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_GETATTR_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_getattr(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern void wfp_impl_getattr(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_getattr_default(
|
||||
struct wfp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
68
lib/webfuse/provider/impl/operation/lookup.c
Normal file
68
lib/webfuse/provider/impl/operation/lookup.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "webfuse/provider/impl/operation/lookup.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wfp_impl_lookup(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
if (2 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
json_t * name_holder = json_array_get(params, 1);
|
||||
|
||||
if (json_is_integer(inode_holder) &&
|
||||
json_is_string(name_holder))
|
||||
{
|
||||
ino_t inode = json_integer_value(inode_holder);
|
||||
char const * name = json_string_value(name_holder);
|
||||
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
context->provider->lookup(request, inode, name, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wfp_impl_respond_lookup(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
bool const is_file = (0 != (stat->st_mode & S_IFREG));
|
||||
bool const is_dir = (0 != (stat->st_mode & S_IFDIR));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(stat->st_ino));
|
||||
json_object_set_new(result, "mode", json_integer(stat->st_mode & 0777));
|
||||
json_object_set_new(result, "atime", json_integer(stat->st_atime));
|
||||
json_object_set_new(result, "mtime", json_integer(stat->st_mtime));
|
||||
json_object_set_new(result, "ctime", json_integer(stat->st_ctime));
|
||||
|
||||
if (is_file)
|
||||
{
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
json_object_set_new(result, "size", json_integer(stat->st_size));
|
||||
}
|
||||
|
||||
if (is_dir)
|
||||
{
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
}
|
||||
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
|
||||
void wfp_impl_lookup_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(parent),
|
||||
char const * WF_UNUSED_PARAM(name),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
30
lib/webfuse/provider/impl/operation/lookup.h
Normal file
30
lib/webfuse/provider/impl/operation/lookup.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_LOOKUP_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_LOOKUP_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_lookup(
|
||||
struct wfp_request * request,
|
||||
struct stat const * stat);
|
||||
|
||||
extern void wfp_impl_lookup(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_lookup_default(
|
||||
struct wfp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
47
lib/webfuse/provider/impl/operation/open.c
Normal file
47
lib/webfuse/provider/impl/operation/open.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "webfuse/provider/impl/operation/open.h"
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wfp_impl_open(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
if (2 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
json_t * flags_holder = json_array_get(params, 1);
|
||||
|
||||
if (json_is_integer(inode_holder) &&
|
||||
json_is_integer(flags_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
int flags = (ino_t) json_integer_value(flags_holder);
|
||||
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->open(request, inode, flags, context->user_data); /* Flawfinder: ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wfp_impl_open_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(inode),
|
||||
int WF_UNUSED_PARAM(flags),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wfp_impl_respond_open(
|
||||
struct wfp_request * request,
|
||||
uint32_t handle)
|
||||
{
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "handle", json_integer((int) handle));
|
||||
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
30
lib/webfuse/provider/impl/operation/open.h
Normal file
30
lib/webfuse/provider/impl/operation/open.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_OPEN_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_OPEN_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_open(
|
||||
struct wfp_request * request,
|
||||
uint32_t handle);
|
||||
|
||||
extern void wfp_impl_open(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_open_default(
|
||||
struct wfp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
85
lib/webfuse/provider/impl/operation/read.c
Normal file
85
lib/webfuse/provider/impl/operation/read.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "webfuse/provider/impl/operation/read.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wfp_impl_read(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
if (4 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
json_t * handle_holder = json_array_get(params, 1);
|
||||
json_t * offset_holder = json_array_get(params, 2);
|
||||
json_t * length_holder = json_array_get(params, 3);
|
||||
|
||||
if (json_is_integer(inode_holder) &&
|
||||
json_is_integer(handle_holder) &&
|
||||
json_is_integer(offset_holder) &&
|
||||
json_is_integer(length_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
int handle = json_integer_value(handle_holder);
|
||||
size_t offset = json_integer_value(offset_holder);
|
||||
size_t length = json_integer_value(length_holder);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->read(request, inode, handle, offset, length, context->user_data); /* Flawfinder: ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wfp_impl_read_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(inode),
|
||||
uint32_t WF_UNUSED_PARAM(handle),
|
||||
size_t WF_UNUSED_PARAM(offset),
|
||||
size_t WF_UNUSED_PARAM(length),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wfp_impl_respond_read(
|
||||
struct wfp_request * request,
|
||||
char const * data,
|
||||
size_t length)
|
||||
{
|
||||
if (0 < length)
|
||||
{
|
||||
size_t const size = 4 * ((length / 3) + 2);
|
||||
char * buffer = malloc(size);
|
||||
if (NULL != buffer)
|
||||
{
|
||||
lws_b64_encode_string(data, length, buffer, size);
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_string(buffer));
|
||||
json_object_set_new(result, "format", json_string("base64"));
|
||||
json_object_set_new(result, "count", json_integer((int) length));
|
||||
|
||||
wfp_impl_respond(request, result);
|
||||
free(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfp_impl_respond_error(request, WF_BAD);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_string(""));
|
||||
json_object_set_new(result, "format", json_string("identitiy"));
|
||||
json_object_set_new(result, "count", json_integer(0));
|
||||
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
}
|
||||
33
lib/webfuse/provider/impl/operation/read.h
Normal file
33
lib/webfuse/provider/impl/operation/read.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_READ_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_READ_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_read(
|
||||
struct wfp_request * request,
|
||||
char const * data,
|
||||
size_t length);
|
||||
|
||||
extern void wfp_impl_read(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_read_default(
|
||||
struct wfp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
42
lib/webfuse/provider/impl/operation/readdir.c
Normal file
42
lib/webfuse/provider/impl/operation/readdir.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "webfuse/provider/impl/operation/readdir.h"
|
||||
#include "webfuse/provider/impl/operation/error.h"
|
||||
#include "webfuse/provider/impl/dirbuffer.h"
|
||||
#include "webfuse/provider/impl/request.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wfp_impl_readdir(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
if (1 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
|
||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->readdir(request, inode, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wfp_impl_readdir_default(
|
||||
struct wfp_request * request,
|
||||
ino_t WF_UNUSED_PARAM(directory),
|
||||
void * WF_UNUSED_PARAM(user_data))
|
||||
{
|
||||
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
|
||||
}
|
||||
|
||||
void wfp_impl_respond_readdir(
|
||||
struct wfp_request * request,
|
||||
struct wfp_dirbuffer * dirbuffer)
|
||||
{
|
||||
json_t * result = wfp_impl_dirbuffer_take(dirbuffer);
|
||||
wfp_impl_respond(request, result);
|
||||
}
|
||||
|
||||
29
lib/webfuse/provider/impl/operation/readdir.h
Normal file
29
lib/webfuse/provider/impl/operation/readdir.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WF_PROVIDER_IMPL_OPERATION_READDIR_H
|
||||
#define WF_PROVIDER_IMPL_OPERATION_READDIR_H
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wfp_impl_respond_readdir(
|
||||
struct wfp_request * request,
|
||||
struct wfp_dirbuffer * dirbuffer);
|
||||
|
||||
extern void wfp_impl_readdir(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_readdir_default(
|
||||
struct wfp_request * request,
|
||||
ino_t directory,
|
||||
void * user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user