mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
introduced json null object
This commit is contained in:
parent
ea15d8c5cf
commit
fd70fa73ac
@ -4,39 +4,52 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static struct wfp_json const wfp_json_null =
|
||||
{
|
||||
.type = WFP_JSON_NULL,
|
||||
.value = { .b = false }
|
||||
};
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_null(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return (WFP_JSON_NULL == json->type);
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_bool(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return ((NULL != json) &&(WFP_JSON_BOOL == json->type));
|
||||
return (WFP_JSON_BOOL == json->type);
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_int(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return ((NULL != json) && (WFP_JSON_INT == json->type));
|
||||
return (WFP_JSON_INT == json->type);
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_string(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return ((NULL != json) && (WFP_JSON_STRING == json->type));
|
||||
return (WFP_JSON_STRING == json->type);
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_array(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return ((NULL != json) && (WFP_JSON_ARRAY == json->type));
|
||||
return (WFP_JSON_ARRAY == json->type);
|
||||
}
|
||||
|
||||
bool
|
||||
wfp_impl_json_is_object(
|
||||
struct wfp_json const * json)
|
||||
{
|
||||
return ((NULL != json) && (WFP_JSON_OBJECT == json->type));
|
||||
return (WFP_JSON_OBJECT == json->type);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -102,7 +115,7 @@ wfp_impl_json_object_get(
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return &wfp_json_null;
|
||||
}
|
||||
|
||||
char const *
|
||||
@ -130,7 +143,7 @@ wfp_impl_json_object_value(
|
||||
return &(json->value.o.items[pos].json);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return &wfp_json_null;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -15,6 +15,10 @@ extern "C"
|
||||
|
||||
struct wfp_json;
|
||||
|
||||
extern bool
|
||||
wfp_impl_json_is_null(
|
||||
struct wfp_json const * json);
|
||||
|
||||
extern bool
|
||||
wfp_impl_json_is_bool(
|
||||
struct wfp_json const * json);
|
||||
|
@ -20,6 +20,7 @@ extern "C"
|
||||
|
||||
enum wfp_json_type
|
||||
{
|
||||
WFP_JSON_NULL,
|
||||
WFP_JSON_BOOL,
|
||||
WFP_JSON_INT,
|
||||
WFP_JSON_STRING,
|
||||
|
@ -36,23 +36,24 @@ wfp_jsonrpc_response_init(
|
||||
|
||||
result->id = wfp_impl_json_int_get(id_holder);
|
||||
result->result = wfp_impl_json_object_get(response, "result");
|
||||
if (NULL == result->result)
|
||||
if (wfp_impl_json_is_null(result->result))
|
||||
{
|
||||
result->result = NULL;
|
||||
int code = WFP_BAD_FORMAT;
|
||||
char const * message = "invalid format: invalid error object";
|
||||
|
||||
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_int_get(wfp_impl_json_object_get(error, "code"));
|
||||
char const * message = "";
|
||||
code = wfp_impl_json_int_get(wfp_impl_json_object_get(error, "code"));
|
||||
message = "";
|
||||
if (wfp_impl_json_is_string(wfp_impl_json_object_get(error, "message")))
|
||||
{
|
||||
message = wfp_impl_json_string_get(wfp_impl_json_object_get(error, "message"));
|
||||
}
|
||||
result->error = wfp_jsonrpc_error_create(code, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
result->error = wfp_jsonrpc_error_create(WFP_BAD_FORMAT, "invalid format: invalid error object");
|
||||
}
|
||||
|
||||
result->error = wfp_jsonrpc_error_create(code, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ static void webfuse_test_MockRequest_respond(
|
||||
id = wfp_impl_json_int_get(id_holder);
|
||||
}
|
||||
|
||||
if (nullptr != result)
|
||||
if (!wfp_impl_json_is_null(result))
|
||||
{
|
||||
error_code = WFP_GOOD;
|
||||
request->respond(result, id);
|
||||
|
Loading…
Reference in New Issue
Block a user