1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

refactor: replaced jansson by own json parser implementation

This commit is contained in:
Falk Werner 2020-07-12 00:39:55 +02:00
parent 63ca5d5a6d
commit 63cc5b5388
35 changed files with 443 additions and 423 deletions

View File

@ -4,7 +4,6 @@
#include <string.h> #include <string.h>
#include <libwebsockets.h> #include <libwebsockets.h>
#include <jansson.h>
#include "webfuse_provider/impl/client_config.h" #include "webfuse_provider/impl/client_config.h"
#include "webfuse_provider/impl/provider.h" #include "webfuse_provider/impl/provider.h"
@ -21,6 +20,7 @@
#include "webfuse_provider/impl/jsonrpc/response.h" #include "webfuse_provider/impl/jsonrpc/response.h"
#include "webfuse_provider/impl/jsonrpc/request.h" #include "webfuse_provider/impl/jsonrpc/request.h"
#include "webfuse_provider/impl/jsonrpc/proxy.h" #include "webfuse_provider/impl/jsonrpc/proxy.h"
#include "webfuse_provider/impl/json/parser.h"
#define WFP_DEFAULT_TIMEOUT (10 * 1000) #define WFP_DEFAULT_TIMEOUT (10 * 1000)
@ -36,12 +36,13 @@ static void wfp_impl_client_protocol_respond(
static void wfp_impl_client_protocol_process( static void wfp_impl_client_protocol_process(
struct wfp_client_protocol * protocol, struct wfp_client_protocol * protocol,
char const * data, char * data,
size_t length) size_t length)
{ {
json_t * message = json_loadb(data, length, 0, NULL); struct wfp_json_doc * doc = wfp_impl_json_parse_buffer(data, length);
if (NULL != message) if (NULL != doc)
{ {
struct wfp_json const * message = wfp_impl_json_root(doc);
if (wfp_jsonrpc_is_response(message)) if (wfp_jsonrpc_is_response(message))
{ {
wfp_jsonrpc_proxy_onresult(protocol->proxy, 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); wfp_impl_provider_invoke(&context, message);
} }
json_decref(message); wfp_impl_json_dispose(doc);
} }
} }
static void static void
wfp_impl_client_protocol_on_add_filesystem_finished( wfp_impl_client_protocol_on_add_filesystem_finished(
void * user_data, void * user_data,
json_t const * result, struct wfp_json const * result,
json_t const * WFP_UNUSED_PARAM(error)) struct wfp_jsonrpc_error const * WFP_UNUSED_PARAM(error))
{ {
struct wfp_client_protocol * protocol = user_data; struct wfp_client_protocol * protocol = user_data;
if (NULL == protocol->wsi) { return; } if (NULL == protocol->wsi) { return; }
@ -99,8 +100,8 @@ static void wfp_impl_client_protocol_add_filesystem(
static void static void
wfp_impl_client_protocol_on_authenticate_finished( wfp_impl_client_protocol_on_authenticate_finished(
void * user_data, void * user_data,
json_t const * result, struct wfp_json const * result,
json_t const * WFP_UNUSED_PARAM(error)) struct wfp_jsonrpc_error const * WFP_UNUSED_PARAM(error))
{ {
struct wfp_client_protocol * protocol = user_data; struct wfp_client_protocol * protocol = user_data;
if (NULL == protocol->wsi) { return; } if (NULL == protocol->wsi) { return; }

View File

@ -8,35 +8,35 @@ bool
wfp_impl_json_is_bool( wfp_impl_json_is_bool(
struct wfp_json const * json) struct wfp_json const * json)
{ {
return (WFP_JSON_BOOL == json->type); return ((NULL != json) &&(WFP_JSON_BOOL == json->type));
} }
bool bool
wfp_impl_json_is_int( wfp_impl_json_is_int(
struct wfp_json const * json) struct wfp_json const * json)
{ {
return (WFP_JSON_INT == json->type); return ((NULL != json) && (WFP_JSON_INT == json->type));
} }
bool bool
wfp_impl_json_is_string( wfp_impl_json_is_string(
struct wfp_json const * json) struct wfp_json const * json)
{ {
return (WFP_JSON_STRING == json->type); return ((NULL != json) && (WFP_JSON_STRING == json->type));
} }
bool bool
wfp_impl_json_is_array( wfp_impl_json_is_array(
struct wfp_json const * json) struct wfp_json const * json)
{ {
return (WFP_JSON_ARRAY == json->type); return ((NULL != json) && (WFP_JSON_ARRAY == json->type));
} }
bool bool
wfp_impl_json_is_object( wfp_impl_json_is_object(
struct wfp_json const * json) struct wfp_json const * json)
{ {
return (WFP_JSON_OBJECT == json->type); return ((NULL != json) && (WFP_JSON_OBJECT == json->type));
} }
bool bool

View File

@ -3,6 +3,7 @@
#include "webfuse_provider/impl/json/reader.h" #include "webfuse_provider/impl/json/reader.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#define WFP_IMPL_JSON_DEFAULT_CAPACITY 4 #define WFP_IMPL_JSON_DEFAULT_CAPACITY 4
@ -47,6 +48,14 @@ wfp_impl_json_parse_object(
struct wfp_json_reader * reader, struct wfp_json_reader * reader,
struct wfp_json * json); 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 * struct wfp_json_doc *
wfp_impl_json_parse_buffer( wfp_impl_json_parse_buffer(
char * data, char * data,

View File

@ -15,6 +15,10 @@ extern "C"
struct wfp_json; struct wfp_json;
struct wfp_json_doc; struct wfp_json_doc;
extern struct wfp_json_doc *
wfp_impl_json_parse(
char * data);
extern struct wfp_json_doc * extern struct wfp_json_doc *
wfp_impl_json_parse_buffer( wfp_impl_json_parse_buffer(
char * data, char * data,

View File

@ -1,17 +1,28 @@
#include "webfuse_provider/impl/jsonrpc/error.h" #include "webfuse_provider/impl/jsonrpc/error.h"
json_t * #include <stdlib.h>
wfp_jsonrpc_error( #include <string.h>
struct wfp_jsonrpc_error *
wfp_jsonrpc_error_create(
int code, int code,
char const * message) char const * message)
{ {
json_t * error = json_object(); struct wfp_jsonrpc_error * error = malloc(sizeof(struct wfp_jsonrpc_error));
json_object_set_new(error, "code", json_integer(code)); error->code = code;
json_object_set_new(error, "message", json_string(message)); error->message = strdup(message);
return error; return error;
} }
void
wfp_jsonrpc_error_dispose(
struct wfp_jsonrpc_error * error)
{
free(error->message);
free(error);
}
void void
wfp_jsonrpc_propate_error( wfp_jsonrpc_propate_error(
wfp_jsonrpc_proxy_finished_fn * finised, wfp_jsonrpc_proxy_finished_fn * finised,
@ -19,9 +30,10 @@ wfp_jsonrpc_propate_error(
int code, int code,
char const * message) char const * message)
{ {
json_t * error = wfp_jsonrpc_error(code, message); struct wfp_jsonrpc_error error;
finised(user_data, NULL, error); error.code = code;
error.message = (char*) message;
json_decref(error); finised(user_data, NULL, &error);
} }

View File

@ -1,7 +1,6 @@
#ifndef WFP_JSONRPC_ERROR_H #ifndef WFP_JSONRPC_ERROR_H
#define WFP_JSONRPC_ERROR_H #define WFP_JSONRPC_ERROR_H
#include <jansson.h>
#include "webfuse_provider/impl/jsonrpc/proxy_finished_fn.h" #include "webfuse_provider/impl/jsonrpc/proxy_finished_fn.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -9,11 +8,21 @@ extern "C"
{ {
#endif #endif
extern json_t * struct wfp_jsonrpc_error
wfp_jsonrpc_error( {
int code;
char * message;
};
extern struct wfp_jsonrpc_error *
wfp_jsonrpc_error_create(
int code, int code,
char const * message); char const * message);
extern void
wfp_jsonrpc_error_dispose(
struct wfp_jsonrpc_error * error);
extern void extern void
wfp_jsonrpc_propate_error( wfp_jsonrpc_propate_error(
wfp_jsonrpc_proxy_finished_fn * finised, wfp_jsonrpc_proxy_finished_fn * finised,

View File

@ -183,7 +183,7 @@ extern void wfp_jsonrpc_proxy_vnotify(
void wfp_jsonrpc_proxy_onresult( void wfp_jsonrpc_proxy_onresult(
struct wfp_jsonrpc_proxy * proxy, struct wfp_jsonrpc_proxy * proxy,
json_t * message) struct wfp_json const * message)
{ {
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, message);

View File

@ -11,7 +11,6 @@
using std::size_t; using std::size_t;
#endif #endif
#include <jansson.h>
#include "webfuse_provider/impl/jsonrpc/send_fn.h" #include "webfuse_provider/impl/jsonrpc/send_fn.h"
#include "webfuse_provider/impl/jsonrpc/proxy_finished_fn.h" #include "webfuse_provider/impl/jsonrpc/proxy_finished_fn.h"
@ -22,6 +21,7 @@ extern "C" {
struct wfp_jsonrpc_proxy; struct wfp_jsonrpc_proxy;
struct wfp_timer_manager; struct wfp_timer_manager;
struct wfp_json_writer; struct wfp_json_writer;
struct wfp_json;
typedef void typedef void
wfp_jsonrpc_custom_write_fn( wfp_jsonrpc_custom_write_fn(
@ -70,7 +70,7 @@ extern void wfp_jsonrpc_proxy_notify(
extern void wfp_jsonrpc_proxy_onresult( extern void wfp_jsonrpc_proxy_onresult(
struct wfp_jsonrpc_proxy * proxy, struct wfp_jsonrpc_proxy * proxy,
json_t * message); struct wfp_json const * message);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,17 +1,18 @@
#ifndef WFP_JSONRPC_PROXY_FINISHED_FN_H #ifndef WFP_JSONRPC_PROXY_FINISHED_FN_H
#define WFP_JSONRPC_PROXY_FINISHED_FN_H #define WFP_JSONRPC_PROXY_FINISHED_FN_H
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct wfp_json;
struct wfp_jsonrpc_error;
typedef void wfp_jsonrpc_proxy_finished_fn( typedef void wfp_jsonrpc_proxy_finished_fn(
void * user_data, void * user_data,
json_t const * result, struct wfp_json const * result,
json_t const * error); struct wfp_jsonrpc_error const * error);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,14 +1,17 @@
#include "webfuse_provider/impl/jsonrpc/request.h" #include "webfuse_provider/impl/jsonrpc/request.h"
#include "webfuse_provider/impl/json/node.h"
#include <stdlib.h> #include <stdlib.h>
bool bool
wfp_jsonrpc_is_request( wfp_jsonrpc_is_request(
json_t * message) struct wfp_json const * message)
{ {
json_t * id = json_object_get(message, "id"); if (NULL == message) { return false; }
json_t * method = json_object_get(message, "method");
json_t * params = json_object_get(message, "params");
return (json_is_integer(id) && json_is_string(method) && struct wfp_json const * id = wfp_impl_json_object_get(message, "id");
(json_is_array(params) || json_is_object(params))); 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)));
} }

View File

@ -5,15 +5,15 @@
#include <stdbool.h> #include <stdbool.h>
#endif #endif
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct wfp_json;
extern bool wfp_jsonrpc_is_request( extern bool wfp_jsonrpc_is_request(
json_t * message); struct wfp_json const * message);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,53 +1,57 @@
#include "webfuse_provider/impl/jsonrpc/response_intern.h" #include "webfuse_provider/impl/jsonrpc/response_intern.h"
#include "webfuse_provider/impl/jsonrpc/error.h" #include "webfuse_provider/impl/jsonrpc/error.h"
#include "webfuse_provider/status.h" #include "webfuse_provider/status.h"
#include "webfuse_provider/impl/json/node.h"
bool bool
wfp_jsonrpc_is_response( wfp_jsonrpc_is_response(
json_t * message) struct wfp_json const * message)
{ {
json_t * id = json_object_get(message, "id"); if (NULL == message) { return false; }
json_t * err = json_object_get(message, "error");
json_t * result = json_object_get(message, "result");
return (json_is_integer(id) && struct wfp_json const * id = wfp_impl_json_object_get(message, "id");
(json_is_object(err) || (NULL != result))); 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 void
wfp_jsonrpc_response_init( wfp_jsonrpc_response_init(
struct wfp_jsonrpc_response * result, struct wfp_jsonrpc_response * result,
json_t * response) struct wfp_json const * response)
{ {
result->id = -1; result->id = -1;
result->result = NULL; result->result = NULL;
result->error = NULL; result->error = NULL;
json_t * id_holder = json_object_get(response, "id"); struct wfp_json const * id_holder = wfp_impl_json_object_get(response, "id");
if (!json_is_integer(id_holder)) 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; return;
} }
result->id = json_integer_value(id_holder); result->id = wfp_impl_json_get_int(id_holder);
result->result = json_object_get(response, "result"); result->result = wfp_impl_json_object_get(response, "result");
if (NULL != result->result) if (NULL == result->result)
{ {
json_incref(result->result); 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"))))
{
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 else
{ {
json_t * error = json_object_get(response, "error"); result->error = wfp_jsonrpc_error_create(WFP_BAD_FORMAT, "invalid format: invalid error object");
if ((json_is_object(error)) && (json_is_integer(json_object_get(error, "code"))))
{
result->error = error;
json_incref(result->error);
}
else
{
result->error = wfp_jsonrpc_error(WFP_BAD_FORMAT, "invalid format: invalid error object");
} }
} }
} }
@ -56,13 +60,8 @@ void
wfp_jsonrpc_response_cleanup( wfp_jsonrpc_response_cleanup(
struct wfp_jsonrpc_response * response) struct wfp_jsonrpc_response * response)
{ {
if (NULL != response->result)
{
json_decref(response->result);
}
if (NULL != response->error) if (NULL != response->error)
{ {
json_decref(response->error); wfp_jsonrpc_error_dispose(response->error);
} }
} }

View File

@ -5,15 +5,16 @@
#include <stdbool.h> #include <stdbool.h>
#endif #endif
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
extern bool wfp_jsonrpc_is_response( struct wfp_json;
json_t * message);
extern bool
wfp_jsonrpc_is_response(
struct wfp_json const * message);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -14,16 +14,19 @@ using std::size_t;
extern "C" { extern "C" {
#endif #endif
struct wfp_json;
struct wfp_jsonrpc_error;
struct wfp_jsonrpc_response struct wfp_jsonrpc_response
{ {
json_t * result; struct wfp_json const * result;
json_t * error; struct wfp_jsonrpc_error * error;
int id; int id;
}; };
extern void wfp_jsonrpc_response_init( extern void wfp_jsonrpc_response_init(
struct wfp_jsonrpc_response * response, struct wfp_jsonrpc_response * response,
json_t * message); struct wfp_json const * message);
extern void wfp_jsonrpc_response_cleanup( extern void wfp_jsonrpc_response_cleanup(
struct wfp_jsonrpc_response * response); struct wfp_jsonrpc_response * response);

View File

@ -1,26 +1,27 @@
#include "webfuse_provider/impl/operation/close.h" #include "webfuse_provider/impl/operation/close.h"
#include <limits.h> #include <limits.h>
#include "webfuse_provider/impl/util/util.h" #include "webfuse_provider/impl/util/util.h"
#include "webfuse_provider/impl/json/node.h"
void wfp_impl_close( void wfp_impl_close(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int WFP_UNUSED_PARAM(id)) 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) if (4 == param_count)
{ {
json_t * inode_holder = json_array_get(params, 1); struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
json_t * handle_holder = json_array_get(params, 2); struct wfp_json const * handle_holder = wfp_impl_json_array_get(params, 2);
json_t * flags_holder = json_array_get(params, 3); struct wfp_json const * flags_holder = wfp_impl_json_array_get(params, 3);
if (json_is_integer(inode_holder) && if (wfp_impl_json_is_int(inode_holder) &&
json_is_integer(handle_holder) && wfp_impl_json_is_int(handle_holder) &&
json_is_integer(flags_holder)) wfp_impl_json_is_int(flags_holder))
{ {
ino_t inode = (ino_t) json_integer_value(inode_holder); ino_t inode = (ino_t) wfp_impl_json_get_int(inode_holder);
uint32_t handle = (uint32_t) (json_integer_value(handle_holder) & UINT32_MAX); uint32_t handle = (uint32_t) (wfp_impl_json_get_int(handle_holder) & UINT32_MAX);
int flags = json_integer_value(flags_holder); int flags = wfp_impl_json_get_int(flags_holder);
context->provider->close(inode, handle, flags, context->user_data); context->provider->close(inode, handle, flags, context->user_data);
} }

View File

@ -10,7 +10,7 @@ extern "C"
extern void wfp_impl_close( extern void wfp_impl_close(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id); int id);
extern void wfp_impl_close_default( extern void wfp_impl_close_default(

View File

@ -6,21 +6,22 @@
#include "webfuse_provider/impl/request.h" #include "webfuse_provider/impl/request.h"
#include "webfuse_provider/impl/message_writer.h" #include "webfuse_provider/impl/message_writer.h"
#include "webfuse_provider/impl/util/util.h" #include "webfuse_provider/impl/util/util.h"
#include "webfuse_provider/impl/json/node.h"
void wfp_impl_getattr( void wfp_impl_getattr(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id) int id)
{ {
size_t const count = json_array_size(params); size_t const count = wfp_impl_json_array_size(params);
if (2 == count) 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); struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->getattr(request, inode, context->user_data); context->provider->getattr(request, inode, context->user_data);

View File

@ -14,7 +14,7 @@ extern void wfp_impl_respond_getattr(
extern void wfp_impl_getattr( extern void wfp_impl_getattr(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id); int id);
extern void wfp_impl_getattr_default( extern void wfp_impl_getattr_default(

View File

@ -6,23 +6,24 @@
#include "webfuse_provider/impl/request.h" #include "webfuse_provider/impl/request.h"
#include "webfuse_provider/impl/message_writer.h" #include "webfuse_provider/impl/message_writer.h"
#include "webfuse_provider/impl/util/util.h" #include "webfuse_provider/impl/util/util.h"
#include "webfuse_provider/impl/json/node.h"
void wfp_impl_lookup( void wfp_impl_lookup(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id) int id)
{ {
size_t const count = json_array_size(params); size_t const count = wfp_impl_json_array_size(params);
if (3 == count) if (3 == count)
{ {
json_t * inode_holder = json_array_get(params, 1); struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
json_t * name_holder = json_array_get(params, 2); struct wfp_json const * name_holder = wfp_impl_json_array_get(params, 2);
if (json_is_integer(inode_holder) && if (wfp_impl_json_is_int(inode_holder) &&
json_is_string(name_holder)) wfp_impl_json_is_string(name_holder))
{ {
ino_t inode = json_integer_value(inode_holder); ino_t inode = wfp_impl_json_get_int(inode_holder);
char const * name = json_string_value(name_holder); char const * name = wfp_impl_json_get_string(name_holder);
struct wfp_request * request = wfp_impl_request_create(context->request, id); struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->lookup(request, inode, name, context->user_data); context->provider->lookup(request, inode, name, context->user_data);

View File

@ -14,7 +14,7 @@ extern void wfp_impl_respond_lookup(
extern void wfp_impl_lookup( extern void wfp_impl_lookup(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id); int id);
extern void wfp_impl_lookup_default( extern void wfp_impl_lookup_default(

View File

@ -3,23 +3,24 @@
#include "webfuse_provider/impl/request.h" #include "webfuse_provider/impl/request.h"
#include "webfuse_provider/impl/message_writer.h" #include "webfuse_provider/impl/message_writer.h"
#include "webfuse_provider/impl/util/util.h" #include "webfuse_provider/impl/util/util.h"
#include "webfuse_provider/impl/json/node.h"
void wfp_impl_open( void wfp_impl_open(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id) int id)
{ {
size_t const count = json_array_size(params); size_t const count = wfp_impl_json_array_size(params);
if (3 == count) if (3 == count)
{ {
json_t * inode_holder = json_array_get(params, 1); struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
json_t * flags_holder = json_array_get(params, 2); struct wfp_json const * flags_holder = wfp_impl_json_array_get(params, 2);
if (json_is_integer(inode_holder) && if (wfp_impl_json_is_int(inode_holder) &&
json_is_integer(flags_holder)) wfp_impl_json_is_int(flags_holder))
{ {
ino_t inode = (ino_t) json_integer_value(inode_holder); ino_t inode = (ino_t) wfp_impl_json_get_int(inode_holder);
int flags = (ino_t) json_integer_value(flags_holder); int flags = (ino_t) wfp_impl_json_get_int(flags_holder);
struct wfp_request * request = wfp_impl_request_create(context->request, id); struct wfp_request * request = wfp_impl_request_create(context->request, id);

View File

@ -14,7 +14,7 @@ extern void wfp_impl_respond_open(
extern void wfp_impl_open( extern void wfp_impl_open(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id); int id);
extern void wfp_impl_open_default( extern void wfp_impl_open_default(

View File

@ -6,29 +6,30 @@
#include "webfuse_provider/impl/request.h" #include "webfuse_provider/impl/request.h"
#include "webfuse_provider/impl/message_writer.h" #include "webfuse_provider/impl/message_writer.h"
#include "webfuse_provider/impl/util/util.h" #include "webfuse_provider/impl/util/util.h"
#include "webfuse_provider/impl/json/node.h"
void wfp_impl_read( void wfp_impl_read(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id) int id)
{ {
size_t const count = json_array_size(params); size_t const count = wfp_impl_json_array_size(params);
if (5 == count) if (5 == count)
{ {
json_t * inode_holder = json_array_get(params, 1); struct wfp_json const * inode_holder = wfp_impl_json_array_get(params, 1);
json_t * handle_holder = json_array_get(params, 2); struct wfp_json const * handle_holder = wfp_impl_json_array_get(params, 2);
json_t * offset_holder = json_array_get(params, 3); struct wfp_json const * offset_holder = wfp_impl_json_array_get(params, 3);
json_t * length_holder = json_array_get(params, 4); struct wfp_json const * length_holder = wfp_impl_json_array_get(params, 4);
if (json_is_integer(inode_holder) && if (wfp_impl_json_is_int(inode_holder) &&
json_is_integer(handle_holder) && wfp_impl_json_is_int(handle_holder) &&
json_is_integer(offset_holder) && wfp_impl_json_is_int(offset_holder) &&
json_is_integer(length_holder)) wfp_impl_json_is_int(length_holder))
{ {
ino_t inode = (ino_t) json_integer_value(inode_holder); ino_t inode = (ino_t) wfp_impl_json_get_int(inode_holder);
int handle = json_integer_value(handle_holder); int handle = wfp_impl_json_get_int(handle_holder);
size_t offset = json_integer_value(offset_holder); size_t offset = wfp_impl_json_get_int(offset_holder);
size_t length = json_integer_value(length_holder); size_t length = wfp_impl_json_get_int(length_holder);
struct wfp_request * request = wfp_impl_request_create(context->request, id); struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->read(request, inode, handle, offset, length, context->user_data); context->provider->read(request, inode, handle, offset, length, context->user_data);

View File

@ -15,7 +15,7 @@ extern void wfp_impl_respond_read(
extern void wfp_impl_read( extern void wfp_impl_read(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id); int id);
extern void wfp_impl_read_default( extern void wfp_impl_read_default(

View File

@ -4,20 +4,21 @@
#include "webfuse_provider/impl/request.h" #include "webfuse_provider/impl/request.h"
#include "webfuse_provider/impl/message_writer.h" #include "webfuse_provider/impl/message_writer.h"
#include "webfuse_provider/impl/util/util.h" #include "webfuse_provider/impl/util/util.h"
#include "webfuse_provider/impl/json/node.h"
void wfp_impl_readdir( void wfp_impl_readdir(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id) int id)
{ {
size_t const count = json_array_size(params); size_t const count = wfp_impl_json_array_size(params);
if (2 == count) 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); struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->readdir(request, inode, context->user_data); context->provider->readdir(request, inode, context->user_data);

View File

@ -14,7 +14,7 @@ extern void wfp_impl_respond_readdir(
extern void wfp_impl_readdir( extern void wfp_impl_readdir(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id); int id);
extern void wfp_impl_readdir_default( extern void wfp_impl_readdir_default(

View File

@ -1,8 +1,5 @@
#include "webfuse_provider/impl/provider.h" #include "webfuse_provider/impl/provider.h"
#include <stdbool.h>
#include <string.h>
#include "webfuse_provider/impl/request.h" #include "webfuse_provider/impl/request.h"
#include "webfuse_provider/impl/operation/lookup.h" #include "webfuse_provider/impl/operation/lookup.h"
#include "webfuse_provider/impl/operation/getattr.h" #include "webfuse_provider/impl/operation/getattr.h"
@ -10,10 +7,16 @@
#include "webfuse_provider/impl/operation/open.h" #include "webfuse_provider/impl/operation/open.h"
#include "webfuse_provider/impl/operation/close.h" #include "webfuse_provider/impl/operation/close.h"
#include "webfuse_provider/impl/operation/read.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( typedef void wfp_impl_invoke_fn(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * params, struct wfp_json const * params,
int id); int id);
@ -27,7 +30,7 @@ struct wfp_impl_method
static void wfp_impl_provider_invoke_method( static void wfp_impl_provider_invoke_method(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
char const * method_name, char const * method_name,
json_t * params, struct wfp_json const * params,
int id) int id)
{ {
static struct wfp_impl_method const methods[] = static struct wfp_impl_method const methods[] =
@ -86,16 +89,16 @@ void wfp_impl_provider_init_from_prototype(
void wfp_impl_provider_invoke( void wfp_impl_provider_invoke(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * request) struct wfp_json const * request)
{ {
json_t * method_holder = json_object_get(request, "method"); struct wfp_json const * method_holder = wfp_impl_json_object_get(request, "method");
json_t * params = json_object_get(request, "params"); struct wfp_json const * params = wfp_impl_json_object_get(request, "params");
json_t * id_holder = json_object_get(request, "id"); 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); char const * method = wfp_impl_json_get_string(method_holder);
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0; 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); wfp_impl_provider_invoke_method(context, method, params, id);
} }

View File

@ -5,7 +5,6 @@
#include <stdbool.h> #include <stdbool.h>
#endif #endif
#include <jansson.h>
#include "webfuse_provider/client_config.h" #include "webfuse_provider/client_config.h"
@ -14,6 +13,8 @@ extern "C"
{ {
#endif #endif
struct wfp_json;
struct wfp_provider struct wfp_provider
{ {
wfp_connected_fn * connected; wfp_connected_fn * connected;
@ -44,7 +45,7 @@ extern void wfp_impl_provider_init_from_prototype(
extern void wfp_impl_provider_invoke( extern void wfp_impl_provider_invoke(
struct wfp_impl_invokation_context * context, struct wfp_impl_invokation_context * context,
json_t * request); struct wfp_json const * request);
extern bool wfp_impl_provider_is_authentication_enabled( extern bool wfp_impl_provider_is_authentication_enabled(
struct wfp_provider * provider); struct wfp_provider * provider);

View File

@ -1,28 +1,26 @@
#include <gtest/gtest.h>
#include "webfuse_provider/impl/jsonrpc/request.h" #include "webfuse_provider/impl/jsonrpc/request.h"
#include "webfuse_provider/impl/json/parser.h"
#include <gtest/gtest.h>
TEST(wfp_jsonrpc_is_request, request_with_object_params) TEST(wfp_jsonrpc_is_request, request_with_object_params)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"method\", \"params\": {}, \"id\": 42}";
json_object_set_new(request, "method", json_string("method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wfp_jsonrpc_is_request(request)); ASSERT_TRUE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_request, request_with_array_params) TEST(wfp_jsonrpc_is_request, request_with_array_params)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"method\", \"params\": [], \"id\": 42}";
json_object_set_new(request, "method", json_string("method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wfp_jsonrpc_is_request(request)); ASSERT_TRUE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_request, null_request) TEST(wfp_jsonrpc_is_request, null_request)
@ -32,81 +30,70 @@ TEST(wfp_jsonrpc_is_request, null_request)
TEST(wfp_jsonrpc_is_request, invalid_request) TEST(wfp_jsonrpc_is_request, invalid_request)
{ {
json_t * request = json_array(); char text[] = "[\"method\", { }, 42]";
json_array_append_new(request, json_string("method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_array_append_new(request, json_object());
json_array_append_new(request, json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_request, invalid_request_without_id) TEST(wfp_jsonrpc_is_request, invalid_request_without_id)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"method\", \"params\": { }}";
json_object_set_new(request, "method", json_string("method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "params", json_object());
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_id) TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_id)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"method\", \"params\": { }, \"id\": \"42\"}";
json_object_set_new(request, "method", json_string("method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_string("42"));
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_request, invalid_request_without_method) TEST(wfp_jsonrpc_is_request, invalid_request_without_method)
{ {
json_t * request = json_object(); char text[] = "{\"params\": { }, \"id\": 42}";
json_object_set_new(request, "params", json_object()); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_method) TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_method)
{ {
json_t * request = json_object(); char text[] = "{\"method\": 42, \"params\": {}, \"id\": 42}";
json_object_set_new(request, "method", json_integer(42)); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_request, invalid_request_without_params) TEST(wfp_jsonrpc_is_request, invalid_request_without_params)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"method\", \"id\": 42}";
json_object_set_new(request, "method", json_string("method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_params) TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_params)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"method\", \"params\": \"params\", \"id\": 42}";
json_object_set_new(request, "methdo", json_string("method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "params", json_string("params"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }

View File

@ -1,37 +1,35 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "webfuse_provider/impl/jsonrpc/response.h" #include "webfuse_provider/impl/jsonrpc/response.h"
#include "webfuse_provider/impl/json/parser.h"
TEST(wfp_jsonrpc_is_response, valid_result) TEST(wfp_jsonrpc_is_response, valid_result)
{ {
json_t * message = json_object(); char text[] = "{\"result\": {}, \"id\": 42}";
json_object_set_new(message, "result", json_object()); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wfp_jsonrpc_is_response(message)); ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_response, valid_result_string) TEST(wfp_jsonrpc_is_response, valid_result_string)
{ {
json_t * message = json_object(); char text[] = "{\"result\": \"also valid\", \"id\": 42}";
json_object_set_new(message, "result", json_string("also valid")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wfp_jsonrpc_is_response(message)); ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_response, valid_error) TEST(wfp_jsonrpc_is_response, valid_error)
{ {
json_t * message = json_object(); char text[] = "{\"error\": { }, \"id\": 42}";
json_object_set_new(message, "error", json_object()); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wfp_jsonrpc_is_response(message)); ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_response, invalid_null) TEST(wfp_jsonrpc_is_response, invalid_null)
@ -41,54 +39,51 @@ TEST(wfp_jsonrpc_is_response, invalid_null)
TEST(wfp_jsonrpc_is_response, invalid_message) TEST(wfp_jsonrpc_is_response, invalid_message)
{ {
json_t * message = json_array(); char text[] = "[{ }, 42]";
json_array_append_new(message, json_object()); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_array_append_new(message, json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_response(message)); ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_response, invalid_missing_id) TEST(wfp_jsonrpc_is_response, invalid_missing_id)
{ {
json_t * message = json_object(); char text[] = "{\"result\": { } }";
json_object_set_new(message, "result", json_object()); wfp_json_doc * doc = wfp_impl_json_parse(text);
ASSERT_FALSE(wfp_jsonrpc_is_response(message)); ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_response, invalid_id_wrong_type) TEST(wfp_jsonrpc_is_response, invalid_id_wrong_type)
{ {
json_t * message = json_object(); char text[] = "{\"result\": { }, \"id\": \"42\"}";
json_object_set_new(message, "result", json_object()); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(message, "id", json_string("42"));
ASSERT_FALSE(wfp_jsonrpc_is_response(message)); ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_response, invalid_missing_result_and_error) TEST(wfp_jsonrpc_is_response, invalid_missing_result_and_error)
{ {
json_t * message = json_object(); char text[] = "{\"id\": \"42\"}";
json_object_set_new(message, "id", json_integer(42)); wfp_json_doc * doc = wfp_impl_json_parse(text);
ASSERT_FALSE(wfp_jsonrpc_is_response(message)); ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_is_response, invalid_error_wrong_type) TEST(wfp_jsonrpc_is_response, invalid_error_wrong_type)
{ {
json_t * message = json_object(); char text[] = "{\"error\": [], \"id\": \"42\"}";
json_object_set_new(message, "error", json_array()); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(message, "id", json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_response(message)); ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
json_decref(message); wfp_impl_json_dispose(doc);
} }

View File

@ -1,5 +1,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "webfuse_provider/impl/jsonrpc/proxy.h" #include "webfuse_provider/impl/jsonrpc/proxy.h"
#include "webfuse_provider/impl/jsonrpc/error.h"
#include "webfuse_provider/impl/json/parser.h"
#include "webfuse_provider/status.h" #include "webfuse_provider/status.h"
#include "webfuse_provider/impl/timer/manager.h" #include "webfuse_provider/impl/timer/manager.h"
@ -21,12 +23,6 @@ using testing::SaveArg;
namespace namespace
{ {
int jsonrpc_get_status(json_t * error)
{
json_t * code = json_object_get(error, "code");
return (json_is_integer(code)) ? json_integer_value(code) : WFP_BAD_FORMAT;
}
struct SendContext struct SendContext
{ {
std::string response; std::string response;
@ -58,8 +54,8 @@ namespace
struct FinishedContext struct FinishedContext
{ {
bool is_called; bool is_called;
json_t * result; wfp_json const * result;
json_t * error; wfp_jsonrpc_error * error;
FinishedContext() FinishedContext()
: is_called(false) : is_called(false)
@ -71,27 +67,25 @@ namespace
~FinishedContext() ~FinishedContext()
{ {
if (nullptr != result)
{
json_decref(result);
}
if (nullptr != error) if (nullptr != error)
{ {
json_decref(error); wfp_jsonrpc_error_dispose(error);
} }
} }
}; };
void jsonrpc_finished( void jsonrpc_finished(
void * user_data, void * user_data,
json_t const * result, wfp_json const * result,
json_t const * error) wfp_jsonrpc_error const * error)
{ {
FinishedContext * context = reinterpret_cast<FinishedContext*>(user_data); FinishedContext * context = reinterpret_cast<FinishedContext*>(user_data);
context->is_called = true; context->is_called = true;
context->result = json_deep_copy(result); context->result = result;
context->error = json_deep_copy(error); if (nullptr != error)
{
context->error = wfp_jsonrpc_error_create(error->code, error->message);
}
} }
} }
@ -154,7 +148,7 @@ TEST(wfp_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
ASSERT_FALSE(finished_context.is_called); ASSERT_FALSE(finished_context.is_called);
ASSERT_TRUE(finished_context2.is_called); ASSERT_TRUE(finished_context2.is_called);
ASSERT_EQ(WFP_BAD_BUSY, jsonrpc_get_status(finished_context2.error)); ASSERT_EQ(WFP_BAD_BUSY, finished_context2.error->code);
wfp_jsonrpc_proxy_dispose(proxy); wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager); wfp_timer_manager_dispose(timer_manager);
@ -194,17 +188,15 @@ TEST(wfp_jsonrpc_proxy, on_result)
ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(send_context.is_called);
json_t * response = json_object(); char response_text[] = "{\"result\": \"okay\", \"id\": 42}";
json_object_set_new(response, "result", json_string("okay")); wfp_json_doc * doc = wfp_impl_json_parse(response_text);
json_object_set_new(response, "id", json_integer(42));
wfp_jsonrpc_proxy_onresult(proxy, response); wfp_jsonrpc_proxy_onresult(proxy, wfp_impl_json_root(doc));
json_decref(response); wfp_impl_json_dispose(doc);
ASSERT_TRUE(finished_context.is_called); ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(nullptr, finished_context.error); ASSERT_EQ(nullptr, finished_context.error);
ASSERT_TRUE(json_is_string(finished_context.result)); ASSERT_NE(nullptr, finished_context.result);
ASSERT_STREQ("okay", json_string_value(finished_context.result));
wfp_jsonrpc_proxy_dispose(proxy); wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager); wfp_timer_manager_dispose(timer_manager);
@ -224,12 +216,11 @@ TEST(wfp_jsonrpc_proxy, on_result_reject_response_with_unknown_id)
ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(send_context.is_called);
json_t * response = json_object(); char response_text[] = "{\"result\": \"okay\", \"id\": 1234}";
json_object_set_new(response, "result", json_string("okay")); wfp_json_doc * doc = wfp_impl_json_parse(response_text);
json_object_set_new(response, "id", json_integer(1234));
wfp_jsonrpc_proxy_onresult(proxy, response); wfp_jsonrpc_proxy_onresult(proxy, wfp_impl_json_root(doc));
json_decref(response); wfp_impl_json_dispose(doc);
ASSERT_FALSE(finished_context.is_called); ASSERT_FALSE(finished_context.is_called);
@ -255,7 +246,7 @@ TEST(wfp_jsonrpc_proxy, timeout)
wfp_timer_manager_check(timer_manager); wfp_timer_manager_check(timer_manager);
ASSERT_TRUE(finished_context.is_called); ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(WFP_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error)); ASSERT_EQ(WFP_BAD_TIMEOUT, finished_context.error->code);
wfp_jsonrpc_proxy_dispose(proxy); wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager); wfp_timer_manager_dispose(timer_manager);
@ -349,12 +340,11 @@ TEST(wfp_jsonrpc_proxy, on_result_swallow_if_no_request_pending)
void * send_data = reinterpret_cast<void*>(&send_context); void * send_data = reinterpret_cast<void*>(&send_context);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
json_t * response = json_object(); char response_text[] = "{\"result\": \"okay\", \"id\": 42}";
json_object_set_new(response, "result", json_string("okay")); wfp_json_doc * doc = wfp_impl_json_parse(response_text);
json_object_set_new(response, "id", json_integer(42));
wfp_jsonrpc_proxy_onresult(proxy, response); wfp_jsonrpc_proxy_onresult(proxy, wfp_impl_json_root(doc));
json_decref(response); wfp_impl_json_dispose(doc);
wfp_jsonrpc_proxy_dispose(proxy); wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager); wfp_timer_manager_dispose(timer_manager);

View File

@ -1,37 +1,33 @@
#include "webfuse_provider/impl/jsonrpc/request.h" #include "webfuse_provider/impl/jsonrpc/request.h"
#include "webfuse_provider/impl/json/parser.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
TEST(wfp_jsonrpc_request, is_request_object_params) TEST(wfp_jsonrpc_request, is_request_object_params)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"some_method\", \"params\": { }, \"id\": 42}";
json_object_set_new(request, "method", json_string("some_method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wfp_jsonrpc_is_request(request)); ASSERT_TRUE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_request, is_request_fail_missing_params) TEST(wfp_jsonrpc_request, is_request_fail_missing_params)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"some_method\", \"id\": 42}";
json_object_set_new(request, "method", json_string("some_method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }
TEST(wfp_jsonrpc_request, is_request_fail_params_wrong_type) TEST(wfp_jsonrpc_request, is_request_fail_params_wrong_type)
{ {
json_t * request = json_object(); char text[] = "{\"method\": \"some_method\", \"params\": \"invalid_params\", \"id\": 42}";
json_object_set_new(request, "method", json_string("some_method")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(request, "params", json_string("invalid_params"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wfp_jsonrpc_is_request(request)); ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
json_decref(request); wfp_impl_json_dispose(doc);
} }

View File

@ -1,147 +1,136 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "webfuse_provider/impl/jsonrpc/response_intern.h" #include "webfuse_provider/impl/jsonrpc/response_intern.h"
#include "webfuse_provider/status.h" #include "webfuse_provider/status.h"
#include "webfuse_provider/impl/json/parser.h"
#include "webfuse_provider/impl/json/node.h"
#include "webfuse_provider/impl/jsonrpc/error.h"
TEST(wfp_json_response, init_result) TEST(wfp_json_response, init_result)
{ {
json_t * message = json_object(); char text[] = "{\"result\": 47, \"id\": 11}";
json_object_set_new(message, "result", json_integer(47)); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(message, "id", json_integer(11));
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(nullptr, response.error); ASSERT_EQ(nullptr, response.error);
ASSERT_TRUE(json_is_integer(response.result)); ASSERT_TRUE(wfp_impl_json_is_int(response.result));
ASSERT_EQ(47, json_integer_value(response.result)); ASSERT_EQ(47, wfp_impl_json_get_int(response.result));
ASSERT_EQ(11, response.id); ASSERT_EQ(11, response.id);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_json_response, init_error) TEST(wfp_json_response, init_error)
{ {
json_t * message = json_object(); char text[] = "{\"error\": {\"code\": 42, \"message\": \"Don't Panic!\"}, \"id\": 23}";
json_t * err = json_object(); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(err, "code", json_integer(42));
json_object_set_new(err, "message", json_string("Don't Panic!"));
json_object_set_new(message, "error", err);
json_object_set_new(message, "id", json_integer(23));
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, response.error->code);
ASSERT_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message"))); ASSERT_STREQ("Don't Panic!", response.error->message);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id); ASSERT_EQ(23, response.id);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_json_response, init_fail_missing_result_and_error) TEST(wfp_json_response, init_fail_missing_result_and_error)
{ {
json_t * message = json_object(); char text[] = "{\"id\": 12}";
json_object_set_new(message, "id", json_integer(12)); wfp_json_doc * doc = wfp_impl_json_parse(text);
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(12, response.id); ASSERT_EQ(12, response.id);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_json_response, init_fail_missing_id) TEST(wfp_json_response, init_fail_missing_id)
{ {
json_t * message = json_object(); char text[] = "{\"result\": 47}";
json_object_set_new(message, "result", json_integer(47)); wfp_json_doc * doc = wfp_impl_json_parse(text);
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(-1, response.id); ASSERT_EQ(-1, response.id);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_json_response, init_fail_wrong_id_type) TEST(wfp_json_response, init_fail_wrong_id_type)
{ {
json_t * message = json_object(); char text[] = "{\"result\": 47, \"id\": \"42\"}";
json_object_set_new(message, "result", json_integer(47)); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(message, "id", json_string("42"));
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(-1, response.id); ASSERT_EQ(-1, response.id);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_json_response, init_fail_error_missing_code) TEST(wfp_json_response, init_fail_error_missing_code)
{ {
json_t * message = json_object(); char text[] = "{\"error\": {\"message\": \"Don't Panic!\"}, \"id\": 23}";
json_t * err = json_object(); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(err, "message", json_string("Don't Panic!"));
json_object_set_new(message, "error", err);
json_object_set_new(message, "id", json_integer(23));
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WFP_BAD_FORMAT,response.error->code);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id); ASSERT_EQ(23, response.id);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_json_response, init_fail_error_wrong_code_type) TEST(wfp_json_response, init_fail_error_wrong_code_type)
{ {
json_t * message = json_object(); char text[] = "{\"error\": {\"code\": \"42\", \"message\": \"Don't Panic!\"}, \"id\": 23}";
json_t * err = json_object(); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(err, "code", json_string("42"));
json_object_set_new(err, "message", json_string("Don't Panic!"));
json_object_set_new(message, "error", err);
json_object_set_new(message, "id", json_integer(23));
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id); ASSERT_EQ(23, response.id);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
json_decref(message); wfp_impl_json_dispose(doc);
} }
TEST(wfp_json_response, init_fail_error_wrong_type) TEST(wfp_json_response, init_fail_error_wrong_type)
{ {
json_t * message = json_object(); char text[] = "{\"error\": \"invalid error type\", \"id\": 23}";
json_object_set_new(message, "error", json_string("invalid error type")); wfp_json_doc * doc = wfp_impl_json_parse(text);
json_object_set_new(message, "id", json_integer(23));
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message); wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id); ASSERT_EQ(23, response.id);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
json_decref(message); wfp_impl_json_dispose(doc);
} }

View File

@ -1,58 +1,82 @@
#include <string> #include "webfuse_provider/impl/jsonrpc/response_intern.h"
#include "webfuse_provider/impl/jsonrpc/error.h"
#include "webfuse_provider/impl/json/parser.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "webfuse_provider/impl/jsonrpc/response_intern.h"
TEST(response_parser, fail_no_object)
static void response_parse_str(
std::string const & buffer,
struct wfp_jsonrpc_response * response)
{
json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr);
if (nullptr != message)
{
wfp_jsonrpc_response_init(response, message);
json_decref(message);
}
}
TEST(response_parser, test)
{ {
char text[] = "[]";
wfp_json_doc * doc = wfp_impl_json_parse(text);
struct wfp_jsonrpc_response response; struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
// no object
response_parse_str("[]", &response);
ASSERT_NE(nullptr, response.error); ASSERT_NE(nullptr, response.error);
ASSERT_EQ(-1, response.id); ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
wfp_jsonrpc_response_cleanup(&response);
// empty wfp_jsonrpc_response_cleanup(&response);
response_parse_str("{}", &response); wfp_impl_json_dispose(doc);
}
TEST(response_error, fail_empty_object)
{
char text[] = "{}";
wfp_json_doc * doc = wfp_impl_json_parse(text);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_NE(nullptr, response.error); ASSERT_NE(nullptr, response.error);
ASSERT_EQ(-1, response.id); ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
wfp_jsonrpc_response_cleanup(&response);
// no data wfp_jsonrpc_response_cleanup(&response);
response_parse_str("{\"id\":42}", &response); wfp_impl_json_dispose(doc);
}
TEST(response_error, fail_no_data)
{
char text[] = "{\"id\":42}";
wfp_json_doc * doc = wfp_impl_json_parse(text);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_NE(nullptr, response.error); ASSERT_NE(nullptr, response.error);
ASSERT_EQ(42, response.id); ASSERT_EQ(42, response.id);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
wfp_jsonrpc_response_cleanup(&response);
// custom error code wfp_jsonrpc_response_cleanup(&response);
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); wfp_impl_json_dispose(doc);
}
TEST(response_error, fail_with_custom_error_code)
{
char text[] = "{\"error\":{\"code\": 42}, \"id\": 42}";
wfp_json_doc * doc = wfp_impl_json_parse(text);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_NE(nullptr, response.error); ASSERT_NE(nullptr, response.error);
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, response.error->code);
ASSERT_EQ(42, response.id); ASSERT_EQ(42, response.id);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
wfp_jsonrpc_response_cleanup(&response);
// valid response wfp_jsonrpc_response_cleanup(&response);
response_parse_str("{\"result\": true, \"id\": 42}", &response); wfp_impl_json_dispose(doc);
}
TEST(response_parser, fail_invalid_response)
{
char text[] = "{\"result\": true, \"id\": 42}";
wfp_json_doc * doc = wfp_impl_json_parse(text);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
ASSERT_EQ(nullptr, response.error); ASSERT_EQ(nullptr, response.error);
ASSERT_EQ(42, response.id); ASSERT_EQ(42, response.id);
ASSERT_NE(nullptr, response.result); ASSERT_NE(nullptr, response.result);
wfp_jsonrpc_response_cleanup(&response); wfp_jsonrpc_response_cleanup(&response);
wfp_impl_json_dispose(doc);
} }

View File

@ -1,4 +1,5 @@
#include "webfuse_provider/impl/operation/close.h" #include "webfuse_provider/impl/operation/close.h"
#include "webfuse_provider/impl/json/parser.h"
#include "webfuse_provider/mocks/mock_provider.hpp" #include "webfuse_provider/mocks/mock_provider.hpp"
#include "webfuse_provider/mocks/fake_invokation_context.hpp" #include "webfuse_provider/mocks/fake_invokation_context.hpp"
@ -10,23 +11,16 @@ using ::testing::_;
TEST(wfp_close, close) TEST(wfp_close, close)
{ {
int inode = 42;
int handle = 0xdeadbeef;
int flags = 23;
MockProvider provider; MockProvider provider;
EXPECT_CALL(provider, close(inode, handle, flags)).Times(1); EXPECT_CALL(provider, close(42, 101, 23)).Times(1);
wfp_impl_invokation_context context = create_context(provider); wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array(); char params[] = "[\"test.filesystem\", 42, 101, 23]";
json_array_append_new(params, json_string("test.filesystem")); wfp_json_doc * doc = wfp_impl_json_parse(params);
json_array_append_new(params, json_integer(inode));
json_array_append_new(params, json_integer(handle));
json_array_append_new(params, json_integer(flags));
wfp_impl_close(&context, params, 42); wfp_impl_close(&context, wfp_impl_json_root(doc), 42);
json_decref(params); wfp_impl_json_dispose(doc);
} }
TEST(wfp_close, close_fail_invalid_param_count) TEST(wfp_close, close_fail_invalid_param_count)
@ -36,9 +30,11 @@ TEST(wfp_close, close_fail_invalid_param_count)
wfp_impl_invokation_context context = create_context(provider); wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array(); char params[] = "[]";
wfp_impl_close(&context, params, 42); wfp_json_doc * doc = wfp_impl_json_parse(params);
json_decref(params);
wfp_impl_close(&context, wfp_impl_json_root(doc), 42);
wfp_impl_json_dispose(doc);
} }
TEST(wfp_close, close_fail_inode_invalid_type) TEST(wfp_close, close_fail_inode_invalid_type)
@ -48,14 +44,11 @@ TEST(wfp_close, close_fail_inode_invalid_type)
wfp_impl_invokation_context context = create_context(provider); wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array(); char params[] = "[\"test.filesystem\", \"42\", 0, 0]";
json_array_append_new(params, json_string("test.filesystem")); wfp_json_doc * doc = wfp_impl_json_parse(params);
json_array_append_new(params, json_string("42"));
json_array_append_new(params, json_integer(0));
json_array_append_new(params, json_integer(0));
wfp_impl_close(&context, params, 42); wfp_impl_close(&context, wfp_impl_json_root(doc), 42);
json_decref(params); wfp_impl_json_dispose(doc);
} }
TEST(wfp_close, close_fail_handle_invalid_type) TEST(wfp_close, close_fail_handle_invalid_type)
@ -65,14 +58,11 @@ TEST(wfp_close, close_fail_handle_invalid_type)
wfp_impl_invokation_context context = create_context(provider); wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array(); char params[] = "[\"test.filesystem\", 0, \"42\", 0]";
json_array_append_new(params, json_string("test.filesystem")); wfp_json_doc * doc = wfp_impl_json_parse(params);
json_array_append_new(params, json_integer(0));
json_array_append_new(params, json_string("42"));
json_array_append_new(params, json_integer(0));
wfp_impl_close(&context, params, 42); wfp_impl_close(&context, wfp_impl_json_root(doc), 42);
json_decref(params); wfp_impl_json_dispose(doc);
} }
TEST(wfp_close, close_fail_flags_invalid_type) TEST(wfp_close, close_fail_flags_invalid_type)
@ -82,14 +72,11 @@ TEST(wfp_close, close_fail_flags_invalid_type)
wfp_impl_invokation_context context = create_context(provider); wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array(); char params[] = "[\"test.filesystem\", 0, 0, \"42\"]";
json_array_append_new(params, json_string("test.filesystem")); wfp_json_doc * doc = wfp_impl_json_parse(params);
json_array_append_new(params, json_integer(0));
json_array_append_new(params, json_integer(0));
json_array_append_new(params, json_string("42"));
wfp_impl_close(&context, params, 42); wfp_impl_close(&context, wfp_impl_json_root(doc), 42);
json_decref(params); wfp_impl_json_dispose(doc);
} }