mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
refactor: made jsonrpc an independent library
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
void wf_impl_operation_close(
|
||||
@@ -13,12 +13,12 @@ void wf_impl_operation_close(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
|
||||
jsonrpc_proxy_notify(rpc, "close", "siii", user_data->name, inode, handle, file_info->flags);
|
||||
}
|
||||
|
||||
fuse_reply_err(request, 0);
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
struct wf_impl_operation_getattr_context
|
||||
@@ -22,16 +22,17 @@ struct wf_impl_operation_getattr_context
|
||||
|
||||
static void wf_impl_operation_getattr_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * data)
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_getattr_context * context = user_data;
|
||||
|
||||
struct stat buffer;
|
||||
if (NULL != data)
|
||||
if (NULL != result)
|
||||
{
|
||||
json_t * mode_holder = json_object_get(data, "mode");
|
||||
json_t * type_holder = json_object_get(data, "type");
|
||||
json_t * mode_holder = json_object_get(result, "mode");
|
||||
json_t * type_holder = json_object_get(result, "type");
|
||||
if ((NULL != mode_holder) && (json_is_integer(mode_holder)) &&
|
||||
(NULL != type_holder) && (json_is_string(type_holder)))
|
||||
{
|
||||
@@ -52,10 +53,10 @@ static void wf_impl_operation_getattr_finished(
|
||||
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);
|
||||
buffer.st_size = wf_impl_json_get_int(result, "size", 0);
|
||||
buffer.st_atime = wf_impl_json_get_int(result, "atime", 0);
|
||||
buffer.st_mtime = wf_impl_json_get_int(result, "mtime", 0);
|
||||
buffer.st_ctime = wf_impl_json_get_int(result, "ctime", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -82,7 +83,7 @@ void wf_impl_operation_getattr (
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
@@ -93,7 +94,7 @@ void wf_impl_operation_getattr (
|
||||
getattr_context->gid = context->gid;
|
||||
getattr_context->timeout = user_data->timeout;
|
||||
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_getattr_finished, getattr_context, "getattr", "si", user_data->name, inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/util.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
struct wf_impl_operation_lookup_context
|
||||
@@ -24,18 +24,19 @@ struct wf_impl_operation_lookup_context
|
||||
|
||||
static void wf_impl_operation_lookup_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * data
|
||||
json_t const * result,
|
||||
json_t const * error
|
||||
)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_lookup_context * context = user_data;
|
||||
struct fuse_entry_param buffer;
|
||||
|
||||
if (NULL != data)
|
||||
if (NULL != result)
|
||||
{
|
||||
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");
|
||||
json_t * inode_holder = json_object_get(result, "inode");
|
||||
json_t * mode_holder = json_object_get(result, "mode");
|
||||
json_t * type_holder = json_object_get(result, "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)))
|
||||
@@ -61,10 +62,10 @@ static void wf_impl_operation_lookup_finished(
|
||||
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);
|
||||
buffer.attr.st_size = wf_impl_json_get_int(result, "size", 0);
|
||||
buffer.attr.st_atime = wf_impl_json_get_int(result, "atime", 0);
|
||||
buffer.attr.st_mtime = wf_impl_json_get_int(result, "mtime", 0);
|
||||
buffer.attr.st_ctime = wf_impl_json_get_int(result, "ctime", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -91,7 +92,7 @@ void wf_impl_operation_lookup (
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
@@ -101,7 +102,7 @@ void wf_impl_operation_lookup (
|
||||
lookup_context->gid = context->gid;
|
||||
lookup_context->timeout = user_data->timeout;
|
||||
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_lookup_finished, lookup_context, "lookup", "sis", user_data->name, (int) (parent & INT_MAX), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -4,15 +4,17 @@
|
||||
#include <errno.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/status.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
static void wf_impl_operation_open_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * result)
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
fuse_req_t request = user_data;
|
||||
struct fuse_file_info file_info;
|
||||
memset(&file_info, 0, sizeof(struct fuse_file_info));
|
||||
@@ -47,11 +49,11 @@ void wf_impl_operation_open(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_open_finished, request, "open", "sii", user_data->name, inode, file_info->flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
#include <limits.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/base64.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
#define WF_MAX_READ_LENGTH 4096
|
||||
|
||||
@@ -38,17 +39,21 @@ static char * wf_impl_fill_buffer(
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void wf_impl_operation_read_finished(void * user_data, wf_status status, json_t const * data)
|
||||
static void wf_impl_operation_read_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
fuse_req_t request = user_data;
|
||||
|
||||
char * buffer = NULL;
|
||||
size_t length = 0;
|
||||
if (NULL != data)
|
||||
if (NULL != result)
|
||||
{
|
||||
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");
|
||||
json_t * data_holder = json_object_get(result, "data");
|
||||
json_t * format_holder = json_object_get(result, "format");
|
||||
json_t * count_holder = json_object_get(result, "count");
|
||||
|
||||
if (json_is_string(data_holder) &&
|
||||
json_is_string(format_holder) &&
|
||||
@@ -87,13 +92,13 @@ void wf_impl_operation_read(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != 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_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/core/util.h"
|
||||
#include "webfuse/core/json_util.h"
|
||||
|
||||
|
||||
#define WF_DIRBUFFER_INITIAL_SIZE 1024
|
||||
@@ -73,9 +74,10 @@ static size_t wf_impl_min(size_t a, size_t b)
|
||||
|
||||
static void wf_impl_operation_readdir_finished(
|
||||
void * user_data,
|
||||
wf_status status,
|
||||
json_t const * result)
|
||||
json_t const * result,
|
||||
json_t const * error)
|
||||
{
|
||||
wf_status status = wf_impl_jsonrpc_get_status(error);
|
||||
struct wf_impl_operation_readdir_context * context = user_data;
|
||||
|
||||
struct wf_impl_dirbuffer buffer;
|
||||
@@ -137,7 +139,7 @@ void wf_impl_operation_readdir (
|
||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
struct jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
@@ -146,7 +148,7 @@ void wf_impl_operation_readdir (
|
||||
readdir_context->size = size;
|
||||
readdir_context->offset = offset;
|
||||
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode);
|
||||
jsonrpc_proxy_invoke(rpc, &wf_impl_operation_readdir_finished, readdir_context, "readdir", "si", user_data->name, inode);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user