2020-02-28 22:17:41 +00:00
|
|
|
#include "webfuse/core/json_util.h"
|
2020-03-01 15:55:58 +00:00
|
|
|
#include "wf/jsonrpc/status.h"
|
2020-02-28 22:17:41 +00:00
|
|
|
|
|
|
|
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
|
|
|
|
{
|
|
|
|
int result = default_value;
|
|
|
|
|
|
|
|
json_t * holder = json_object_get(object, key);
|
|
|
|
if ((NULL != holder) && (json_is_integer(holder)))
|
|
|
|
{
|
|
|
|
result = json_integer_value(holder);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static wf_status wf_impl_jsonrc_code_to_status(int code)
|
|
|
|
{
|
|
|
|
switch (code)
|
|
|
|
{
|
2020-03-01 15:55:58 +00:00
|
|
|
case WF_JSONRPC_GOOD:
|
2020-02-28 22:17:41 +00:00
|
|
|
return WF_GOOD;
|
2020-03-01 15:55:58 +00:00
|
|
|
case WF_JSONRPC_BAD:
|
2020-02-28 22:17:41 +00:00
|
|
|
return WF_BAD;
|
2020-03-01 15:55:58 +00:00
|
|
|
case WF_JSONRPC_BAD_BUSY:
|
2020-02-28 22:17:41 +00:00
|
|
|
return WF_BAD_BUSY;
|
2020-03-01 15:55:58 +00:00
|
|
|
case WF_JSONRPC_BAD_TIMEOUT:
|
2020-02-28 22:17:41 +00:00
|
|
|
return WF_BAD_TIMEOUT;
|
2020-03-01 15:55:58 +00:00
|
|
|
case WF_JSONRPC_BAD_FORMAT:
|
2020-02-28 22:17:41 +00:00
|
|
|
return WF_BAD_FORMAT;
|
|
|
|
default:
|
|
|
|
return (wf_status) code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wf_status
|
|
|
|
wf_impl_jsonrpc_get_status(
|
|
|
|
json_t const * error)
|
|
|
|
{
|
|
|
|
wf_status status = WF_GOOD;
|
|
|
|
if (NULL != error)
|
|
|
|
{
|
|
|
|
int code = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT);
|
|
|
|
status = wf_impl_jsonrc_code_to_status(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|