2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/jsonrpc/response_intern.h"
|
|
|
|
#include "webfuse/impl/jsonrpc/error.h"
|
2020-06-28 13:51:34 +00:00
|
|
|
#include "webfuse/status.h"
|
2019-01-27 02:45:03 +00:00
|
|
|
|
2020-02-29 01:32:03 +00:00
|
|
|
bool
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_jsonrpc_is_response(
|
2019-04-01 20:15:12 +00:00
|
|
|
json_t * 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");
|
|
|
|
|
|
|
|
return (json_is_integer(id) &&
|
|
|
|
(json_is_object(err) || (NULL != result)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 01:32:03 +00:00
|
|
|
void
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_jsonrpc_response_init(
|
2020-03-01 15:55:58 +00:00
|
|
|
struct wf_jsonrpc_response * result,
|
2019-04-01 20:15:12 +00:00
|
|
|
json_t * response)
|
2019-01-27 02:45:03 +00:00
|
|
|
{
|
|
|
|
result->id = -1;
|
|
|
|
result->result = NULL;
|
2020-02-28 22:17:41 +00:00
|
|
|
result->error = NULL;
|
2019-01-27 02:45:03 +00:00
|
|
|
|
|
|
|
json_t * id_holder = json_object_get(response, "id");
|
2020-03-22 11:51:54 +00:00
|
|
|
if (!json_is_integer(id_holder))
|
2019-01-27 02:45:03 +00:00
|
|
|
{
|
2020-06-28 17:43:08 +00:00
|
|
|
result->error = wf_impl_jsonrpc_error(WF_BAD_FORMAT, "invalid format: missing id");
|
2019-01-27 02:45:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
result->id = json_integer_value(id_holder);
|
|
|
|
result->result = json_object_get(response, "result");
|
|
|
|
if (NULL != result->result)
|
|
|
|
{
|
|
|
|
json_incref(result->result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
json_t * error = json_object_get(response, "error");
|
2020-02-28 22:17:41 +00:00
|
|
|
if ((json_is_object(error)) && (json_is_integer(json_object_get(error, "code"))))
|
|
|
|
{
|
|
|
|
result->error = error;
|
|
|
|
json_incref(result->error);
|
|
|
|
}
|
|
|
|
else
|
2019-01-27 02:45:03 +00:00
|
|
|
{
|
2020-06-28 17:43:08 +00:00
|
|
|
result->error = wf_impl_jsonrpc_error(WF_BAD_FORMAT, "invalid format: invalid error object");
|
2019-01-27 02:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 01:32:03 +00:00
|
|
|
void
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_jsonrpc_response_cleanup(
|
2020-03-01 15:55:58 +00:00
|
|
|
struct wf_jsonrpc_response * response)
|
2019-02-09 02:08:02 +00:00
|
|
|
{
|
|
|
|
if (NULL != response->result)
|
|
|
|
{
|
|
|
|
json_decref(response->result);
|
|
|
|
}
|
2020-02-28 22:17:41 +00:00
|
|
|
|
|
|
|
if (NULL != response->error)
|
|
|
|
{
|
|
|
|
json_decref(response->error);
|
|
|
|
}
|
2019-02-09 02:08:02 +00:00
|
|
|
}
|