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:
21
lib/webfuse/adapter/impl/operation/close.c
Normal file
21
lib/webfuse/adapter/impl/operation/close.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.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_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
||||
93
lib/webfuse/adapter/impl/operation/getattr.c
Normal file
93
lib/webfuse/adapter/impl/operation/getattr.c
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
struct wf_impl_operation_getattr_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
double timeout;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
static void wf_impl_operation_getattr_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * data)
|
||||
{
|
||||
struct wf_impl_operation_getattr_context * context = user_data;
|
||||
|
||||
struct stat buffer;
|
||||
if (NULL != data)
|
||||
{
|
||||
json_t * mode_holder = json_object_get(data, "mode");
|
||||
json_t * type_holder = json_object_get(data, "type");
|
||||
if ((NULL != mode_holder) && (json_is_integer(mode_holder)) &&
|
||||
(NULL != type_holder) && (json_is_string(type_holder)))
|
||||
{
|
||||
memset(&buffer, 0, sizeof(struct stat));
|
||||
|
||||
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(data, "size", 0);
|
||||
buffer.st_atime = wf_impl_json_get_int(data, "atime", 0);
|
||||
buffer.st_mtime = wf_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.st_ctime = wf_impl_json_get_int(data, "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_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
struct wf_impl_operation_getattr_context * getattr_context = malloc(sizeof(struct wf_impl_operation_getattr_context));
|
||||
getattr_context->request = request;
|
||||
getattr_context->uid = context->uid;
|
||||
getattr_context->gid = context->gid;
|
||||
getattr_context->timeout = user_data->timeout;
|
||||
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "i", inode);
|
||||
}
|
||||
102
lib/webfuse/adapter/impl/operation/lookup.c
Normal file
102
lib/webfuse/adapter/impl/operation/lookup.c
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "webfuse/adapter/impl/operations.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/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
struct wf_impl_operation_lookup_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
double timeout;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
static void wf_impl_operation_lookup_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * data
|
||||
)
|
||||
{
|
||||
struct wf_impl_operation_lookup_context * context = user_data;
|
||||
struct fuse_entry_param buffer;
|
||||
|
||||
if (NULL != data)
|
||||
{
|
||||
json_t * inode_holder = json_object_get(data, "inode");
|
||||
json_t * mode_holder = json_object_get(data, "mode");
|
||||
json_t * type_holder = json_object_get(data, "type");
|
||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)) &&
|
||||
(NULL != mode_holder) && (json_is_integer(mode_holder)) &&
|
||||
(NULL != type_holder) && (json_is_string(type_holder)))
|
||||
{
|
||||
memset(&buffer, 0, sizeof(struct stat));
|
||||
|
||||
buffer.ino = json_integer_value(inode_holder);
|
||||
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(data, "size", 0);
|
||||
buffer.attr.st_atime = wf_impl_json_get_int(data, "atime", 0);
|
||||
buffer.attr.st_mtime = wf_impl_json_get_int(data, "mtime", 0);
|
||||
buffer.attr.st_ctime = wf_impl_json_get_int(data, "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_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->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_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "is", (int) (parent & INT_MAX), name);
|
||||
}
|
||||
53
lib/webfuse/adapter/impl/operation/open.c
Normal file
53
lib/webfuse/adapter/impl/operation/open.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
static void wf_impl_operation_open_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * result)
|
||||
{
|
||||
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 ((NULL != handle_holder) && (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_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "ii", inode, file_info->flags);
|
||||
}
|
||||
95
lib/webfuse/adapter/impl/operation/read.c
Normal file
95
lib/webfuse/adapter/impl/operation/read.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <jansson.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#define WF_MAX_READ_LENGTH 4096
|
||||
|
||||
static char * wf_impl_fill_buffer(
|
||||
char const * data,
|
||||
char const * format,
|
||||
size_t count,
|
||||
wf_status * status)
|
||||
{
|
||||
*status = WF_GOOD;
|
||||
char * buffer = malloc(count + 1);
|
||||
|
||||
if ((NULL != buffer) && (0 < count))
|
||||
{
|
||||
if (0 == strcmp("identity", format))
|
||||
{
|
||||
memcpy(buffer, data, count); /* Flawfinder: ignore */
|
||||
}
|
||||
else if (0 == strcmp("base64", format))
|
||||
{
|
||||
lws_b64_decode_string(data, buffer, count + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
*status = WF_BAD;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void wf_impl_operation_read_finished(void * user_data, wf_status status, json_t const * data)
|
||||
{
|
||||
fuse_req_t request = user_data;
|
||||
|
||||
char * buffer = NULL;
|
||||
size_t length = 0;
|
||||
if (NULL != data)
|
||||
{
|
||||
json_t * data_holder = json_object_get(data, "data");
|
||||
json_t * format_holder = json_object_get(data, "format");
|
||||
json_t * count_holder = json_object_get(data, "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);
|
||||
char const * const format = json_string_value(format_holder);
|
||||
length = (size_t) json_integer_value(count_holder);
|
||||
|
||||
buffer = wf_impl_fill_buffer(data, 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_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH;
|
||||
int handle = (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "iiii", inode, handle, (int) offset, length);
|
||||
}
|
||||
147
lib/webfuse/adapter/impl/operation/readdir.c
Normal file
147
lib/webfuse/adapter/impl/operation/readdir.c
Normal file
@@ -0,0 +1,147 @@
|
||||
#include "webfuse/adapter/impl/operations.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
|
||||
#define WF_DIRBUFFER_INITIAL_SIZE 1024
|
||||
|
||||
struct wf_impl_operation_readdir_context
|
||||
{
|
||||
fuse_req_t request;
|
||||
size_t size;
|
||||
off_t offset;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static void wf_impl_operation_readdir_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * result)
|
||||
{
|
||||
struct wf_impl_operation_readdir_context * context = user_data;
|
||||
|
||||
struct wf_impl_dirbuffer buffer;
|
||||
wf_impl_dirbuffer_init(&buffer);
|
||||
|
||||
if (NULL != result)
|
||||
{
|
||||
if (json_is_array(result))
|
||||
{
|
||||
bool buffer_full = false;
|
||||
size_t const count = json_array_size(result);
|
||||
for(size_t i = 0; (!buffer_full) && (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 ((NULL != name_holder) && (json_is_string(name_holder)) &&
|
||||
(NULL != inode_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_server * rpc = user_data->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_impl_jsonrpc_server_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "i", inode);
|
||||
}
|
||||
Reference in New Issue
Block a user