mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
refactor: replaced jansson by own json parser implementation
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "webfuse_provider/impl/client_config.h"
|
||||
#include "webfuse_provider/impl/provider.h"
|
||||
@@ -21,6 +20,7 @@
|
||||
#include "webfuse_provider/impl/jsonrpc/response.h"
|
||||
#include "webfuse_provider/impl/jsonrpc/request.h"
|
||||
#include "webfuse_provider/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse_provider/impl/json/parser.h"
|
||||
|
||||
#define WFP_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
@@ -36,12 +36,13 @@ static void wfp_impl_client_protocol_respond(
|
||||
|
||||
static void wfp_impl_client_protocol_process(
|
||||
struct wfp_client_protocol * protocol,
|
||||
char const * data,
|
||||
char * data,
|
||||
size_t length)
|
||||
{
|
||||
json_t * message = json_loadb(data, length, 0, NULL);
|
||||
if (NULL != message)
|
||||
struct wfp_json_doc * doc = wfp_impl_json_parse_buffer(data, length);
|
||||
if (NULL != doc)
|
||||
{
|
||||
struct wfp_json const * message = wfp_impl_json_root(doc);
|
||||
if (wfp_jsonrpc_is_response(message))
|
||||
{
|
||||
wfp_jsonrpc_proxy_onresult(protocol->proxy, message);
|
||||
@@ -59,15 +60,15 @@ static void wfp_impl_client_protocol_process(
|
||||
wfp_impl_provider_invoke(&context, message);
|
||||
}
|
||||
|
||||
json_decref(message);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wfp_impl_client_protocol_on_add_filesystem_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * WFP_UNUSED_PARAM(error))
|
||||
struct wfp_json const * result,
|
||||
struct wfp_jsonrpc_error const * WFP_UNUSED_PARAM(error))
|
||||
{
|
||||
struct wfp_client_protocol * protocol = user_data;
|
||||
if (NULL == protocol->wsi) { return; }
|
||||
@@ -99,8 +100,8 @@ static void wfp_impl_client_protocol_add_filesystem(
|
||||
static void
|
||||
wfp_impl_client_protocol_on_authenticate_finished(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * WFP_UNUSED_PARAM(error))
|
||||
struct wfp_json const * result,
|
||||
struct wfp_jsonrpc_error const * WFP_UNUSED_PARAM(error))
|
||||
{
|
||||
struct wfp_client_protocol * protocol = user_data;
|
||||
if (NULL == protocol->wsi) { return; }
|
||||
|
||||
@@ -8,35 +8,35 @@ bool
|
||||
wfp_impl_json_is_bool(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return (WFP_JSON_BOOL == json->type);
|
||||
return ((NULL != json) &&(WFP_JSON_BOOL == json->type));
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_int(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return (WFP_JSON_INT == json->type);
|
||||
return ((NULL != json) && (WFP_JSON_INT == json->type));
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_string(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return (WFP_JSON_STRING == json->type);
|
||||
return ((NULL != json) && (WFP_JSON_STRING == json->type));
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_array(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return (WFP_JSON_ARRAY == json->type);
|
||||
return ((NULL != json) && (WFP_JSON_ARRAY == json->type));
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_object(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return (WFP_JSON_OBJECT == json->type);
|
||||
return ((NULL != json) && (WFP_JSON_OBJECT == json->type));
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "webfuse_provider/impl/json/reader.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define WFP_IMPL_JSON_DEFAULT_CAPACITY 4
|
||||
|
||||
@@ -47,6 +48,14 @@ wfp_impl_json_parse_object(
|
||||
struct wfp_json_reader * reader,
|
||||
struct wfp_json * json);
|
||||
|
||||
|
||||
extern struct wfp_json_doc *
|
||||
wfp_impl_json_parse(
|
||||
char * data)
|
||||
{
|
||||
return wfp_impl_json_parse_buffer(data, strlen(data));
|
||||
}
|
||||
|
||||
struct wfp_json_doc *
|
||||
wfp_impl_json_parse_buffer(
|
||||
char * data,
|
||||
|
||||
@@ -15,6 +15,10 @@ extern "C"
|
||||
struct wfp_json;
|
||||
struct wfp_json_doc;
|
||||
|
||||
extern struct wfp_json_doc *
|
||||
wfp_impl_json_parse(
|
||||
char * data);
|
||||
|
||||
extern struct wfp_json_doc *
|
||||
wfp_impl_json_parse_buffer(
|
||||
char * data,
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
#include "webfuse_provider/impl/jsonrpc/error.h"
|
||||
|
||||
json_t *
|
||||
wfp_jsonrpc_error(
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wfp_jsonrpc_error *
|
||||
wfp_jsonrpc_error_create(
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
json_t * error = json_object();
|
||||
json_object_set_new(error, "code", json_integer(code));
|
||||
json_object_set_new(error, "message", json_string(message));
|
||||
struct wfp_jsonrpc_error * error = malloc(sizeof(struct wfp_jsonrpc_error));
|
||||
error->code = code;
|
||||
error->message = strdup(message);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void
|
||||
wfp_jsonrpc_error_dispose(
|
||||
struct wfp_jsonrpc_error * error)
|
||||
{
|
||||
free(error->message);
|
||||
free(error);
|
||||
}
|
||||
|
||||
void
|
||||
wfp_jsonrpc_propate_error(
|
||||
wfp_jsonrpc_proxy_finished_fn * finised,
|
||||
@@ -19,9 +30,10 @@ wfp_jsonrpc_propate_error(
|
||||
int code,
|
||||
char const * message)
|
||||
{
|
||||
json_t * error = wfp_jsonrpc_error(code, message);
|
||||
finised(user_data, NULL, error);
|
||||
struct wfp_jsonrpc_error error;
|
||||
error.code = code;
|
||||
error.message = (char*) message;
|
||||
|
||||
json_decref(error);
|
||||
finised(user_data, NULL, &error);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef WFP_JSONRPC_ERROR_H
|
||||
#define WFP_JSONRPC_ERROR_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse_provider/impl/jsonrpc/proxy_finished_fn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -9,11 +8,21 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern json_t *
|
||||
wfp_jsonrpc_error(
|
||||
struct wfp_jsonrpc_error
|
||||
{
|
||||
int code;
|
||||
char * message;
|
||||
};
|
||||
|
||||
extern struct wfp_jsonrpc_error *
|
||||
wfp_jsonrpc_error_create(
|
||||
int code,
|
||||
char const * message);
|
||||
|
||||
extern void
|
||||
wfp_jsonrpc_error_dispose(
|
||||
struct wfp_jsonrpc_error * error);
|
||||
|
||||
extern void
|
||||
wfp_jsonrpc_propate_error(
|
||||
wfp_jsonrpc_proxy_finished_fn * finised,
|
||||
|
||||
@@ -183,7 +183,7 @@ extern void wfp_jsonrpc_proxy_vnotify(
|
||||
|
||||
void wfp_jsonrpc_proxy_onresult(
|
||||
struct wfp_jsonrpc_proxy * proxy,
|
||||
json_t * message)
|
||||
struct wfp_json const * message)
|
||||
{
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, message);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
using std::size_t;
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse_provider/impl/jsonrpc/send_fn.h"
|
||||
#include "webfuse_provider/impl/jsonrpc/proxy_finished_fn.h"
|
||||
|
||||
@@ -22,6 +21,7 @@ extern "C" {
|
||||
struct wfp_jsonrpc_proxy;
|
||||
struct wfp_timer_manager;
|
||||
struct wfp_json_writer;
|
||||
struct wfp_json;
|
||||
|
||||
typedef void
|
||||
wfp_jsonrpc_custom_write_fn(
|
||||
@@ -70,7 +70,7 @@ extern void wfp_jsonrpc_proxy_notify(
|
||||
|
||||
extern void wfp_jsonrpc_proxy_onresult(
|
||||
struct wfp_jsonrpc_proxy * proxy,
|
||||
json_t * message);
|
||||
struct wfp_json const * message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
#ifndef WFP_JSONRPC_PROXY_FINISHED_FN_H
|
||||
#define WFP_JSONRPC_PROXY_FINISHED_FN_H
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_json;
|
||||
struct wfp_jsonrpc_error;
|
||||
|
||||
typedef void wfp_jsonrpc_proxy_finished_fn(
|
||||
void * user_data,
|
||||
json_t const * result,
|
||||
json_t const * error);
|
||||
struct wfp_json const * result,
|
||||
struct wfp_jsonrpc_error const * error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
#include "webfuse_provider/impl/jsonrpc/request.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
bool
|
||||
wfp_jsonrpc_is_request(
|
||||
json_t * message)
|
||||
struct wfp_json const * message)
|
||||
{
|
||||
json_t * id = json_object_get(message, "id");
|
||||
json_t * method = json_object_get(message, "method");
|
||||
json_t * params = json_object_get(message, "params");
|
||||
if (NULL == message) { return false; }
|
||||
|
||||
return (json_is_integer(id) && json_is_string(method) &&
|
||||
(json_is_array(params) || json_is_object(params)));
|
||||
struct wfp_json const * id = wfp_impl_json_object_get(message, "id");
|
||||
struct wfp_json const * method = wfp_impl_json_object_get(message, "method");
|
||||
struct wfp_json const * params = wfp_impl_json_object_get(message, "params");
|
||||
|
||||
return (wfp_impl_json_is_int(id) && wfp_impl_json_is_string(method) &&
|
||||
(wfp_impl_json_is_array(params) || wfp_impl_json_is_object(params)));
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_json;
|
||||
|
||||
extern bool wfp_jsonrpc_is_request(
|
||||
json_t * message);
|
||||
struct wfp_json const * message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,53 +1,57 @@
|
||||
#include "webfuse_provider/impl/jsonrpc/response_intern.h"
|
||||
#include "webfuse_provider/impl/jsonrpc/error.h"
|
||||
#include "webfuse_provider/status.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
|
||||
bool
|
||||
wfp_jsonrpc_is_response(
|
||||
json_t * message)
|
||||
struct wfp_json const * message)
|
||||
{
|
||||
json_t * id = json_object_get(message, "id");
|
||||
json_t * err = json_object_get(message, "error");
|
||||
json_t * result = json_object_get(message, "result");
|
||||
if (NULL == message) { return false; }
|
||||
|
||||
return (json_is_integer(id) &&
|
||||
(json_is_object(err) || (NULL != result)));
|
||||
struct wfp_json const * id = wfp_impl_json_object_get(message, "id");
|
||||
struct wfp_json const * err = wfp_impl_json_object_get(message, "error");
|
||||
struct wfp_json const * result = wfp_impl_json_object_get(message, "result");
|
||||
|
||||
return (wfp_impl_json_is_int(id) &&
|
||||
(wfp_impl_json_is_object(err) || (NULL != result)));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wfp_jsonrpc_response_init(
|
||||
struct wfp_jsonrpc_response * result,
|
||||
json_t * response)
|
||||
struct wfp_json const * response)
|
||||
{
|
||||
result->id = -1;
|
||||
result->result = NULL;
|
||||
result->error = NULL;
|
||||
|
||||
json_t * id_holder = json_object_get(response, "id");
|
||||
if (!json_is_integer(id_holder))
|
||||
struct wfp_json const * id_holder = wfp_impl_json_object_get(response, "id");
|
||||
if (!wfp_impl_json_is_int(id_holder))
|
||||
{
|
||||
result->error = wfp_jsonrpc_error(WFP_BAD_FORMAT, "invalid format: missing id");
|
||||
result->error = wfp_jsonrpc_error_create(WFP_BAD_FORMAT, "invalid format: missing id");
|
||||
return;
|
||||
}
|
||||
|
||||
result->id = json_integer_value(id_holder);
|
||||
result->result = json_object_get(response, "result");
|
||||
if (NULL != result->result)
|
||||
result->id = wfp_impl_json_get_int(id_holder);
|
||||
result->result = wfp_impl_json_object_get(response, "result");
|
||||
if (NULL == result->result)
|
||||
{
|
||||
json_incref(result->result);
|
||||
}
|
||||
else
|
||||
{
|
||||
json_t * error = json_object_get(response, "error");
|
||||
if ((json_is_object(error)) && (json_is_integer(json_object_get(error, "code"))))
|
||||
struct wfp_json const * error = wfp_impl_json_object_get(response, "error");
|
||||
if ((wfp_impl_json_is_object(error)) && (wfp_impl_json_is_int(wfp_impl_json_object_get(error, "code"))))
|
||||
{
|
||||
result->error = error;
|
||||
json_incref(result->error);
|
||||
int code = wfp_impl_json_get_int(wfp_impl_json_object_get(error, "code"));
|
||||
char const * message = "";
|
||||
if (wfp_impl_json_is_string(wfp_impl_json_object_get(error, "message")))
|
||||
{
|
||||
message = wfp_impl_json_get_string(wfp_impl_json_object_get(error, "message"));
|
||||
}
|
||||
result->error = wfp_jsonrpc_error_create(code, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
result->error = wfp_jsonrpc_error(WFP_BAD_FORMAT, "invalid format: invalid error object");
|
||||
result->error = wfp_jsonrpc_error_create(WFP_BAD_FORMAT, "invalid format: invalid error object");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,13 +60,8 @@ void
|
||||
wfp_jsonrpc_response_cleanup(
|
||||
struct wfp_jsonrpc_response * response)
|
||||
{
|
||||
if (NULL != response->result)
|
||||
{
|
||||
json_decref(response->result);
|
||||
}
|
||||
|
||||
if (NULL != response->error)
|
||||
{
|
||||
json_decref(response->error);
|
||||
}
|
||||
if (NULL != response->error)
|
||||
{
|
||||
wfp_jsonrpc_error_dispose(response->error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,16 @@
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wfp_jsonrpc_is_response(
|
||||
json_t * message);
|
||||
struct wfp_json;
|
||||
|
||||
extern bool
|
||||
wfp_jsonrpc_is_response(
|
||||
struct wfp_json const * message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -14,16 +14,19 @@ using std::size_t;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wfp_json;
|
||||
struct wfp_jsonrpc_error;
|
||||
|
||||
struct wfp_jsonrpc_response
|
||||
{
|
||||
json_t * result;
|
||||
json_t * error;
|
||||
struct wfp_json const * result;
|
||||
struct wfp_jsonrpc_error * error;
|
||||
int id;
|
||||
};
|
||||
|
||||
extern void wfp_jsonrpc_response_init(
|
||||
struct wfp_jsonrpc_response * response,
|
||||
json_t * message);
|
||||
struct wfp_json const * message);
|
||||
|
||||
extern void wfp_jsonrpc_response_cleanup(
|
||||
struct wfp_jsonrpc_response * response);
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
#include "webfuse_provider/impl/operation/close.h"
|
||||
#include <limits.h>
|
||||
#include "webfuse_provider/impl/util/util.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
|
||||
void wfp_impl_close(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int WFP_UNUSED_PARAM(id))
|
||||
{
|
||||
size_t const param_count = json_array_size(params);
|
||||
size_t const param_count = wfp_impl_json_array_size(params);
|
||||
if (4 == param_count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 1);
|
||||
json_t * handle_holder = json_array_get(params, 2);
|
||||
json_t * flags_holder = json_array_get(params, 3);
|
||||
struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
|
||||
struct wfp_json const * handle_holder = wfp_impl_json_array_get(params, 2);
|
||||
struct wfp_json const * flags_holder = wfp_impl_json_array_get(params, 3);
|
||||
|
||||
if (json_is_integer(inode_holder) &&
|
||||
json_is_integer(handle_holder) &&
|
||||
json_is_integer(flags_holder))
|
||||
if (wfp_impl_json_is_int(inode_holder) &&
|
||||
wfp_impl_json_is_int(handle_holder) &&
|
||||
wfp_impl_json_is_int(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);
|
||||
ino_t inode = (ino_t) wfp_impl_json_get_int(inode_holder);
|
||||
uint32_t handle = (uint32_t) (wfp_impl_json_get_int(handle_holder) & UINT32_MAX);
|
||||
int flags = wfp_impl_json_get_int(flags_holder);
|
||||
|
||||
context->provider->close(inode, handle, flags, context->user_data);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ extern "C"
|
||||
|
||||
extern void wfp_impl_close(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_close_default(
|
||||
|
||||
@@ -6,21 +6,22 @@
|
||||
#include "webfuse_provider/impl/request.h"
|
||||
#include "webfuse_provider/impl/message_writer.h"
|
||||
#include "webfuse_provider/impl/util/util.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
|
||||
|
||||
void wfp_impl_getattr(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
size_t const count = wfp_impl_json_array_size(params);
|
||||
if (2 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 1);
|
||||
struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
|
||||
|
||||
if (json_is_integer(inode_holder))
|
||||
if (wfp_impl_json_is_int(inode_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
ino_t inode = (ino_t) wfp_impl_json_get_int(inode_holder);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->getattr(request, inode, context->user_data);
|
||||
|
||||
@@ -14,7 +14,7 @@ extern void wfp_impl_respond_getattr(
|
||||
|
||||
extern void wfp_impl_getattr(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_getattr_default(
|
||||
|
||||
@@ -6,23 +6,24 @@
|
||||
#include "webfuse_provider/impl/request.h"
|
||||
#include "webfuse_provider/impl/message_writer.h"
|
||||
#include "webfuse_provider/impl/util/util.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
|
||||
void wfp_impl_lookup(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
size_t const count = wfp_impl_json_array_size(params);
|
||||
if (3 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 1);
|
||||
json_t * name_holder = json_array_get(params, 2);
|
||||
struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
|
||||
struct wfp_json const * name_holder = wfp_impl_json_array_get(params, 2);
|
||||
|
||||
if (json_is_integer(inode_holder) &&
|
||||
json_is_string(name_holder))
|
||||
if (wfp_impl_json_is_int(inode_holder) &&
|
||||
wfp_impl_json_is_string(name_holder))
|
||||
{
|
||||
ino_t inode = json_integer_value(inode_holder);
|
||||
char const * name = json_string_value(name_holder);
|
||||
ino_t inode = wfp_impl_json_get_int(inode_holder);
|
||||
char const * name = wfp_impl_json_get_string(name_holder);
|
||||
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
context->provider->lookup(request, inode, name, context->user_data);
|
||||
|
||||
@@ -14,7 +14,7 @@ extern void wfp_impl_respond_lookup(
|
||||
|
||||
extern void wfp_impl_lookup(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_lookup_default(
|
||||
|
||||
@@ -3,23 +3,24 @@
|
||||
#include "webfuse_provider/impl/request.h"
|
||||
#include "webfuse_provider/impl/message_writer.h"
|
||||
#include "webfuse_provider/impl/util/util.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
|
||||
void wfp_impl_open(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
size_t const count = wfp_impl_json_array_size(params);
|
||||
if (3 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 1);
|
||||
json_t * flags_holder = json_array_get(params, 2);
|
||||
struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
|
||||
struct wfp_json const * flags_holder = wfp_impl_json_array_get(params, 2);
|
||||
|
||||
if (json_is_integer(inode_holder) &&
|
||||
json_is_integer(flags_holder))
|
||||
if (wfp_impl_json_is_int(inode_holder) &&
|
||||
wfp_impl_json_is_int(flags_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
int flags = (ino_t) json_integer_value(flags_holder);
|
||||
ino_t inode = (ino_t) wfp_impl_json_get_int(inode_holder);
|
||||
int flags = (ino_t) wfp_impl_json_get_int(flags_holder);
|
||||
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ extern void wfp_impl_respond_open(
|
||||
|
||||
extern void wfp_impl_open(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_open_default(
|
||||
|
||||
@@ -6,29 +6,30 @@
|
||||
#include "webfuse_provider/impl/request.h"
|
||||
#include "webfuse_provider/impl/message_writer.h"
|
||||
#include "webfuse_provider/impl/util/util.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
|
||||
void wfp_impl_read(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
size_t const count = wfp_impl_json_array_size(params);
|
||||
if (5 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 1);
|
||||
json_t * handle_holder = json_array_get(params, 2);
|
||||
json_t * offset_holder = json_array_get(params, 3);
|
||||
json_t * length_holder = json_array_get(params, 4);
|
||||
struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
|
||||
struct wfp_json const * handle_holder = wfp_impl_json_array_get(params, 2);
|
||||
struct wfp_json const * offset_holder = wfp_impl_json_array_get(params, 3);
|
||||
struct wfp_json const * length_holder = wfp_impl_json_array_get(params, 4);
|
||||
|
||||
if (json_is_integer(inode_holder) &&
|
||||
json_is_integer(handle_holder) &&
|
||||
json_is_integer(offset_holder) &&
|
||||
json_is_integer(length_holder))
|
||||
if (wfp_impl_json_is_int(inode_holder) &&
|
||||
wfp_impl_json_is_int(handle_holder) &&
|
||||
wfp_impl_json_is_int(offset_holder) &&
|
||||
wfp_impl_json_is_int(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);
|
||||
ino_t inode = (ino_t) wfp_impl_json_get_int(inode_holder);
|
||||
int handle = wfp_impl_json_get_int(handle_holder);
|
||||
size_t offset = wfp_impl_json_get_int(offset_holder);
|
||||
size_t length = wfp_impl_json_get_int(length_holder);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->read(request, inode, handle, offset, length, context->user_data);
|
||||
|
||||
@@ -15,7 +15,7 @@ extern void wfp_impl_respond_read(
|
||||
|
||||
extern void wfp_impl_read(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_read_default(
|
||||
|
||||
@@ -4,20 +4,21 @@
|
||||
#include "webfuse_provider/impl/request.h"
|
||||
#include "webfuse_provider/impl/message_writer.h"
|
||||
#include "webfuse_provider/impl/util/util.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
|
||||
void wfp_impl_readdir(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id)
|
||||
{
|
||||
size_t const count = json_array_size(params);
|
||||
size_t const count = wfp_impl_json_array_size(params);
|
||||
if (2 == count)
|
||||
{
|
||||
json_t * inode_holder = json_array_get(params, 1);
|
||||
struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
|
||||
|
||||
if (json_is_integer(inode_holder))
|
||||
if (wfp_impl_json_is_int(inode_holder))
|
||||
{
|
||||
ino_t inode = (ino_t) json_integer_value(inode_holder);
|
||||
ino_t inode = (ino_t) wfp_impl_json_get_int(inode_holder);
|
||||
struct wfp_request * request = wfp_impl_request_create(context->request, id);
|
||||
|
||||
context->provider->readdir(request, inode, context->user_data);
|
||||
|
||||
@@ -14,7 +14,7 @@ extern void wfp_impl_respond_readdir(
|
||||
|
||||
extern void wfp_impl_readdir(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id);
|
||||
|
||||
extern void wfp_impl_readdir_default(
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "webfuse_provider/impl/provider.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webfuse_provider/impl/request.h"
|
||||
#include "webfuse_provider/impl/operation/lookup.h"
|
||||
#include "webfuse_provider/impl/operation/getattr.h"
|
||||
@@ -10,10 +7,16 @@
|
||||
#include "webfuse_provider/impl/operation/open.h"
|
||||
#include "webfuse_provider/impl/operation/close.h"
|
||||
#include "webfuse_provider/impl/operation/read.h"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wfp_json;
|
||||
|
||||
typedef void wfp_impl_invoke_fn(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id);
|
||||
|
||||
|
||||
@@ -27,7 +30,7 @@ struct wfp_impl_method
|
||||
static void wfp_impl_provider_invoke_method(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
char const * method_name,
|
||||
json_t * params,
|
||||
struct wfp_json const * params,
|
||||
int id)
|
||||
{
|
||||
static struct wfp_impl_method const methods[] =
|
||||
@@ -86,16 +89,16 @@ void wfp_impl_provider_init_from_prototype(
|
||||
|
||||
void wfp_impl_provider_invoke(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * request)
|
||||
struct wfp_json const * request)
|
||||
{
|
||||
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");
|
||||
struct wfp_json const * method_holder = wfp_impl_json_object_get(request, "method");
|
||||
struct wfp_json const * params = wfp_impl_json_object_get(request, "params");
|
||||
struct wfp_json const * id_holder = wfp_impl_json_object_get(request, "id");
|
||||
|
||||
if ((json_is_string(method_holder)) && (json_is_array(params)))
|
||||
if ((wfp_impl_json_is_string(method_holder)) && (wfp_impl_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;
|
||||
char const * method = wfp_impl_json_get_string(method_holder);
|
||||
int id = wfp_impl_json_is_int(id_holder) ? wfp_impl_json_get_int(id_holder) : 0;
|
||||
|
||||
wfp_impl_provider_invoke_method(context, method, params, id);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse_provider/client_config.h"
|
||||
|
||||
|
||||
@@ -14,6 +13,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfp_json;
|
||||
|
||||
struct wfp_provider
|
||||
{
|
||||
wfp_connected_fn * connected;
|
||||
@@ -44,7 +45,7 @@ extern void wfp_impl_provider_init_from_prototype(
|
||||
|
||||
extern void wfp_impl_provider_invoke(
|
||||
struct wfp_impl_invokation_context * context,
|
||||
json_t * request);
|
||||
struct wfp_json const * request);
|
||||
|
||||
extern bool wfp_impl_provider_is_authentication_enabled(
|
||||
struct wfp_provider * provider);
|
||||
|
||||
Reference in New Issue
Block a user