mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
refactored message creation; enhanced implementation of some operations
This commit is contained in:
@@ -29,15 +29,10 @@ void wsfsp_close(
|
||||
}
|
||||
|
||||
void wsfsp_close_default(
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
int flags,
|
||||
void * user_data)
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
uint32_t WSFS_UNUSED_PARAM(handle),
|
||||
int WSFS_UNUSED_PARAM(flags),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
(void) inode;
|
||||
(void) handle;
|
||||
(void) flags;
|
||||
(void) user_data;
|
||||
|
||||
// empty
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include <jansson.h>
|
||||
#include "wsfs/provider/request.h"
|
||||
|
||||
void wsfsp_respond_error(
|
||||
struct wsfsp_request * request,
|
||||
int status)
|
||||
{
|
||||
json_t * response = json_object();
|
||||
json_t * error = json_object();
|
||||
json_object_set_new(error, "code", json_integer(status));
|
||||
json_object_set_new(response, "error", error);
|
||||
json_object_set_new(response, "id", json_integer(request->id));
|
||||
|
||||
request->respond(response, request->user_data);
|
||||
|
||||
json_decref(response);
|
||||
wsfsp_request_dispose(request);
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
#include "wsfs/provider/operation/getattr_intern.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/provider/request.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
|
||||
void wsfsp_getattr(
|
||||
@@ -14,7 +18,7 @@ void wsfsp_getattr(
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
|
||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)))
|
||||
if (json_is_integer(inode_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
@@ -26,12 +30,9 @@ void wsfsp_getattr(
|
||||
|
||||
void wsfsp_getattr_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
void * user_data)
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
(void) inode;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
@@ -39,8 +40,26 @@ void wsfsp_respond_getattr(
|
||||
struct wsfsp_request * request,
|
||||
struct stat const * stat)
|
||||
{
|
||||
(void) request;
|
||||
(void) stat;
|
||||
bool const is_file = (0 != (stat->st_mode & S_IFREG));
|
||||
bool const is_dir = (0 != (stat->st_mode & S_IFDIR));
|
||||
|
||||
// ToDo: implement me
|
||||
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"));
|
||||
}
|
||||
|
||||
wsfsp_respond(request, result);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
#include "wsfs/provider/operation/lookup_intern.h"
|
||||
#include <stdio.h>
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
void wsfsp_lookup(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
(void) context;
|
||||
(void) params;
|
||||
(void) 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);
|
||||
|
||||
puts("lookup");
|
||||
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 wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
context->provider->lookup(request, inode, name, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_respond_lookup(
|
||||
@@ -21,18 +33,15 @@ void wsfsp_respond_lookup(
|
||||
(void) request;
|
||||
(void) stat;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
void wsfsp_lookup_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t parent,
|
||||
char const * name,
|
||||
void * user_data)
|
||||
ino_t WSFS_UNUSED_PARAM(parent),
|
||||
char const * WSFS_UNUSED_PARAM(name),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
(void) parent;
|
||||
(void) name;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "wsfs/provider/operation/open_intern.h"
|
||||
#include <stdio.h>
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
void wsfsp_open(
|
||||
struct wsfsp_invokation_context * context,
|
||||
@@ -16,14 +17,10 @@ void wsfsp_open(
|
||||
|
||||
void wsfsp_open_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
int flags,
|
||||
void * user_data)
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
int WSFS_UNUSED_PARAM(flags),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
(void) inode;
|
||||
(void) flags;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "wsfs/provider/operation/read_intern.h"
|
||||
#include <stdio.h>
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
void wsfsp_read(
|
||||
struct wsfsp_invokation_context * context,
|
||||
@@ -11,23 +12,17 @@ void wsfsp_read(
|
||||
(void) params;
|
||||
(void) id;
|
||||
|
||||
puts("read");
|
||||
puts("read");
|
||||
}
|
||||
|
||||
void wsfsp_read_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t inode,
|
||||
uint32_t handle,
|
||||
size_t offset,
|
||||
size_t length,
|
||||
void * user_data)
|
||||
ino_t WSFS_UNUSED_PARAM(inode),
|
||||
uint32_t WSFS_UNUSED_PARAM(handle),
|
||||
size_t WSFS_UNUSED_PARAM(offset),
|
||||
size_t WSFS_UNUSED_PARAM(length),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
(void) inode;
|
||||
(void) handle;
|
||||
(void) offset;
|
||||
(void) length;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,35 @@
|
||||
#include "wsfs/provider/operation/readdir_intern.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "wsfs/provider/operation/error.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
void wsfsp_readdir(
|
||||
struct wsfsp_invokation_context * context,
|
||||
json_t * params,
|
||||
int id)
|
||||
{
|
||||
(void) context;
|
||||
(void) params;
|
||||
(void) id;
|
||||
size_t const count = json_array_size(params);
|
||||
if (1 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 0);
|
||||
|
||||
puts("readdir");
|
||||
if ((NULL != inode_holder) && (json_is_integer(inode_holder)))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
struct wsfsp_request * request = wsfsp_request_create(context->request, id);
|
||||
|
||||
context->provider->readdir(request, inode, context->user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wsfsp_readdir_default(
|
||||
struct wsfsp_request * request,
|
||||
ino_t directory,
|
||||
void * user_data)
|
||||
ino_t WSFS_UNUSED_PARAM(directory),
|
||||
void * WSFS_UNUSED_PARAM(user_data))
|
||||
{
|
||||
(void) directory;
|
||||
(void) user_data;
|
||||
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
@@ -33,5 +41,6 @@ void wsfsp_respond_readdir(
|
||||
(void) dirbuffer;
|
||||
|
||||
// ToDo: implement me
|
||||
wsfsp_respond_error(request, -1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user