mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
refactor: made jsonrpc an independent library
This commit is contained in:
48
lib/webfuse/core/json_util.c
Normal file
48
lib/webfuse/core/json_util.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "webfuse/core/json_util.h"
|
||||
#include "jsonrpc/status.h"
|
||||
|
||||
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)
|
||||
{
|
||||
case JSONRPC_GOOD:
|
||||
return WF_GOOD;
|
||||
case JSONRPC_BAD:
|
||||
return WF_BAD;
|
||||
case JSONRPC_BAD_BUSY:
|
||||
return WF_BAD_BUSY;
|
||||
case JSONRPC_BAD_TIMEOUT:
|
||||
return WF_BAD_TIMEOUT;
|
||||
case JSONRPC_BAD_FORMAT:
|
||||
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;
|
||||
}
|
||||
26
lib/webfuse/core/json_util.h
Normal file
26
lib/webfuse/core/json_util.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef WF_JSON_UTIL_H
|
||||
#define WF_JSON_UTIL_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern int
|
||||
wf_impl_json_get_int(
|
||||
json_t const * object,
|
||||
char const * key,
|
||||
int default_value);
|
||||
|
||||
extern wf_status
|
||||
wf_impl_jsonrpc_get_status(
|
||||
json_t const * error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user