aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2023-12-30 23:29:43 +0100
committerEgor Tensin <egor@tensin.name>2023-12-30 23:38:25 +0100
commit2d2869ce6060f974004ef98020b38b67366166d1 (patch)
tree534dcf35770b785ed2947c27f0e9387f941a17c4
parentstring: stpecpy -> string_append (diff)
downloadcimple-2d2869ce6060f974004ef98020b38b67366166d1.tar.gz
cimple-2d2869ce6060f974004ef98020b38b67366166d1.zip
json: add the lib prefix to wrapper functions
It makes it easier to audit for non-wrapped json-c usage.
Diffstat (limited to '')
-rw-r--r--src/json.c107
-rw-r--r--src/json.h47
-rw-r--r--src/json_rpc.c102
-rw-r--r--src/protocol.c2
-rw-r--r--src/run_queue.c20
5 files changed, 138 insertions, 140 deletions
diff --git a/src/json.c b/src/json.c
index 9a38e4e..06bb57d 100644
--- a/src/json.c
+++ b/src/json.c
@@ -18,38 +18,43 @@
#include <stdlib.h>
#include <string.h>
-void json_free(struct json_object *obj)
+#define libjson_errno(fn) \
+ do { \
+ log_err("JSON: %s failed\n", fn); \
+ } while (0)
+
+void libjson_free(struct json_object *obj)
{
json_object_put(obj);
}
-static const char *json_to_string_internal(struct json_object *obj, int flags)
+static const char *libjson_to_string_internal(struct json_object *obj, int flags)
{
const char *result = json_object_to_json_string_ext(obj, flags);
if (!result) {
- json_errno("json_object_to_json_string");
+ libjson_errno("json_object_to_json_string");
return NULL;
}
return result;
}
-const char *json_to_string(struct json_object *obj)
+const char *libjson_to_string(struct json_object *obj)
{
- return json_to_string_internal(obj, JSON_C_TO_STRING_SPACED);
+ return libjson_to_string_internal(obj, JSON_C_TO_STRING_SPACED);
}
-const char *json_to_string_pretty(struct json_object *obj)
+const char *libjson_to_string_pretty(struct json_object *obj)
{
- return json_to_string_internal(obj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ return libjson_to_string_internal(obj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
}
-struct json_object *json_from_string(const char *src)
+struct json_object *libjson_from_string(const char *src)
{
enum json_tokener_error error;
struct json_object *result = json_tokener_parse_verbose(src, &error);
if (!result) {
- json_errno("json_tokener_parse_verbose");
+ libjson_errno("json_tokener_parse_verbose");
log_err("JSON: parsing failed: %s\n", json_tokener_error_desc(error));
return NULL;
}
@@ -57,12 +62,12 @@ struct json_object *json_from_string(const char *src)
return result;
}
-int json_clone(const struct json_object *obj, const char *key, struct json_object **_value)
+int libjson_clone(const struct json_object *obj, const char *key, struct json_object **_value)
{
int ret = 0;
struct json_object *old_value = NULL;
- ret = json_get(obj, key, &old_value);
+ ret = libjson_get(obj, key, &old_value);
if (ret < 0)
return ret;
@@ -75,11 +80,11 @@ int json_clone(const struct json_object *obj, const char *key, struct json_objec
return ret;
}
-int json_send(struct json_object *obj, int fd)
+int libjson_send(struct json_object *obj, int fd)
{
int ret = 0;
- const char *str = json_to_string(obj);
+ const char *str = libjson_to_string(obj);
if (!str)
return -1;
@@ -93,7 +98,7 @@ int json_send(struct json_object *obj, int fd)
return ret;
}
-struct json_object *json_recv(int fd)
+struct json_object *libjson_recv(int fd)
{
struct json_object *result = NULL;
int ret = 0;
@@ -103,7 +108,7 @@ struct json_object *json_recv(int fd)
if (ret < 0)
return NULL;
- result = json_from_string((const char *)buf_get_data(buf));
+ result = libjson_from_string((const char *)buf_get_data(buf));
if (!result)
goto destroy_buf;
@@ -114,36 +119,36 @@ destroy_buf:
return result;
}
-int json_new_object(struct json_object **_obj)
+int libjson_new_object(struct json_object **_obj)
{
struct json_object *obj = json_object_new_object();
if (!obj) {
- json_errno("json_object_new_object");
+ libjson_errno("json_object_new_object");
return -1;
}
*_obj = obj;
return 0;
}
-int json_new_array(struct json_object **_arr)
+int libjson_new_array(struct json_object **_arr)
{
struct json_object *arr = json_object_new_array();
if (!arr) {
- json_errno("json_object_new_array");
+ libjson_errno("json_object_new_array");
return -1;
}
*_arr = arr;
return 0;
}
-int json_has(const struct json_object *obj, const char *key)
+int libjson_has(const struct json_object *obj, const char *key)
{
return json_object_object_get_ex(obj, key, NULL);
}
-int json_get(const struct json_object *obj, const char *key, struct json_object **value)
+int libjson_get(const struct json_object *obj, const char *key, struct json_object **value)
{
- if (!json_has(obj, key)) {
+ if (!libjson_has(obj, key)) {
log_err("JSON: key is missing: %s\n", key);
return -1;
}
@@ -151,11 +156,11 @@ int json_get(const struct json_object *obj, const char *key, struct json_object
return json_object_object_get_ex(obj, key, value);
}
-int json_get_string(const struct json_object *obj, const char *key, const char **_value)
+int libjson_get_string(const struct json_object *obj, const char *key, const char **_value)
{
struct json_object *value = NULL;
- int ret = json_get(obj, key, &value);
+ int ret = libjson_get(obj, key, &value);
if (ret < 0)
return ret;
@@ -168,11 +173,11 @@ int json_get_string(const struct json_object *obj, const char *key, const char *
return 0;
}
-int json_get_int(const struct json_object *obj, const char *key, int64_t *_value)
+int libjson_get_int(const struct json_object *obj, const char *key, int64_t *_value)
{
struct json_object *value = NULL;
- int ret = json_get(obj, key, &value);
+ int ret = libjson_get(obj, key, &value);
if (ret < 0)
return ret;
@@ -192,30 +197,30 @@ int json_get_int(const struct json_object *obj, const char *key, int64_t *_value
return 0;
}
-static int json_set_internal(struct json_object *obj, const char *key, struct json_object *value,
- unsigned flags)
+static int libjson_set_internal(struct json_object *obj, const char *key, struct json_object *value,
+ unsigned flags)
{
int ret = 0;
ret = json_object_object_add_ex(obj, key, value, flags);
if (ret < 0) {
- json_errno("json_object_object_add_ex");
+ libjson_errno("json_object_object_add_ex");
return ret;
}
return 0;
}
-static int json_set_string_internal(struct json_object *obj, const char *key, const char *_value,
- unsigned flags)
+static int libjson_set_string_internal(struct json_object *obj, const char *key, const char *_value,
+ unsigned flags)
{
struct json_object *value = json_object_new_string(_value);
if (!value) {
- json_errno("json_object_new_string");
+ libjson_errno("json_object_new_string");
return -1;
}
- int ret = json_set_internal(obj, key, value, flags);
+ int ret = libjson_set_internal(obj, key, value, flags);
if (ret < 0)
goto free_value;
@@ -227,16 +232,16 @@ free_value:
return ret;
}
-static int json_set_int_internal(struct json_object *obj, const char *key, int64_t _value,
- unsigned flags)
+static int libjson_set_int_internal(struct json_object *obj, const char *key, int64_t _value,
+ unsigned flags)
{
struct json_object *value = json_object_new_int64(_value);
if (!value) {
- json_errno("json_object_new_int");
+ libjson_errno("json_object_new_int");
return -1;
}
- int ret = json_set_internal(obj, key, value, flags);
+ int ret = libjson_set_internal(obj, key, value, flags);
if (ret < 0)
goto free_value;
@@ -248,19 +253,19 @@ free_value:
return ret;
}
-int json_set(struct json_object *obj, const char *key, struct json_object *value)
+int libjson_set(struct json_object *obj, const char *key, struct json_object *value)
{
- return json_set_internal(obj, key, value, 0);
+ return libjson_set_internal(obj, key, value, 0);
}
-int json_set_string(struct json_object *obj, const char *key, const char *value)
+int libjson_set_string(struct json_object *obj, const char *key, const char *value)
{
- return json_set_string_internal(obj, key, value, 0);
+ return libjson_set_string_internal(obj, key, value, 0);
}
-int json_set_int(struct json_object *obj, const char *key, int64_t value)
+int libjson_set_int(struct json_object *obj, const char *key, int64_t value)
{
- return json_set_int_internal(obj, key, value, 0);
+ return libjson_set_int_internal(obj, key, value, 0);
}
#ifndef JSON_C_OBJECT_ADD_CONSTANT_KEY
@@ -268,26 +273,26 @@ int json_set_int(struct json_object *obj, const char *key, int64_t value)
#endif
static const unsigned json_const_key_flags = JSON_C_OBJECT_ADD_CONSTANT_KEY;
-int json_set_const_key(struct json_object *obj, const char *key, struct json_object *value)
+int libjson_set_const_key(struct json_object *obj, const char *key, struct json_object *value)
{
- return json_set_internal(obj, key, value, json_const_key_flags);
+ return libjson_set_internal(obj, key, value, json_const_key_flags);
}
-int json_set_string_const_key(struct json_object *obj, const char *key, const char *value)
+int libjson_set_string_const_key(struct json_object *obj, const char *key, const char *value)
{
- return json_set_string_internal(obj, key, value, json_const_key_flags);
+ return libjson_set_string_internal(obj, key, value, json_const_key_flags);
}
-int json_set_int_const_key(struct json_object *obj, const char *key, int64_t value)
+int libjson_set_int_const_key(struct json_object *obj, const char *key, int64_t value)
{
- return json_set_int_internal(obj, key, value, json_const_key_flags);
+ return libjson_set_int_internal(obj, key, value, json_const_key_flags);
}
-int json_append(struct json_object *arr, struct json_object *elem)
+int libjson_append(struct json_object *arr, struct json_object *elem)
{
int ret = json_object_array_add(arr, elem);
if (ret < 0) {
- json_errno("json_object_array_add");
+ libjson_errno("json_object_array_add");
return ret;
}
return ret;
diff --git a/src/json.h b/src/json.h
index 2d496c1..175a41c 100644
--- a/src/json.h
+++ b/src/json.h
@@ -8,45 +8,38 @@
#ifndef __JSON_H__
#define __JSON_H__
-#include "log.h"
-
#include <json-c/json_object.h>
#include <stdint.h>
-#define json_errno(fn) \
- do { \
- log_err("JSON: %s failed\n", fn); \
- } while (0)
-
-void json_free(struct json_object *);
+void libjson_free(struct json_object *);
-const char *json_to_string(struct json_object *);
-const char *json_to_string_pretty(struct json_object *);
-struct json_object *json_from_string(const char *);
+const char *libjson_to_string(struct json_object *);
+const char *libjson_to_string_pretty(struct json_object *);
+struct json_object *libjson_from_string(const char *);
-int json_clone(const struct json_object *, const char *key, struct json_object **value);
+int libjson_clone(const struct json_object *, const char *key, struct json_object **value);
-int json_send(struct json_object *, int fd);
-struct json_object *json_recv(int fd);
+int libjson_send(struct json_object *, int fd);
+struct json_object *libjson_recv(int fd);
-int json_new_object(struct json_object **);
-int json_new_array(struct json_object **);
+int libjson_new_object(struct json_object **);
+int libjson_new_array(struct json_object **);
-int json_has(const struct json_object *, const char *key);
+int libjson_has(const struct json_object *, const char *key);
-int json_get(const struct json_object *, const char *key, struct json_object **value);
-int json_get_string(const struct json_object *, const char *key, const char **value);
-int json_get_int(const struct json_object *, const char *key, int64_t *value);
+int libjson_get(const struct json_object *, const char *key, struct json_object **value);
+int libjson_get_string(const struct json_object *, const char *key, const char **value);
+int libjson_get_int(const struct json_object *, const char *key, int64_t *value);
-int json_set(struct json_object *, const char *key, struct json_object *value);
-int json_set_string(struct json_object *, const char *key, const char *value);
-int json_set_int(struct json_object *, const char *key, int64_t value);
+int libjson_set(struct json_object *, const char *key, struct json_object *value);
+int libjson_set_string(struct json_object *, const char *key, const char *value);
+int libjson_set_int(struct json_object *, const char *key, int64_t value);
-int json_set_const_key(struct json_object *, const char *, struct json_object *value);
-int json_set_string_const_key(struct json_object *, const char *, const char *value);
-int json_set_int_const_key(struct json_object *, const char *, int64_t value);
+int libjson_set_const_key(struct json_object *, const char *, struct json_object *value);
+int libjson_set_string_const_key(struct json_object *, const char *, const char *value);
+int libjson_set_int_const_key(struct json_object *, const char *, int64_t value);
-int json_append(struct json_object *arr, struct json_object *elem);
+int libjson_append(struct json_object *arr, struct json_object *elem);
#endif
diff --git a/src/json_rpc.c b/src/json_rpc.c
index 4a8879a..b81a5a0 100644
--- a/src/json_rpc.c
+++ b/src/json_rpc.c
@@ -36,7 +36,7 @@ static int jsonrpc_check_version(struct json_object *obj)
const char *key = jsonrpc_key_version;
const char *version = NULL;
- int ret = json_get_string(obj, key, &version);
+ int ret = libjson_get_string(obj, key, &version);
if (ret < 0)
return ret;
@@ -50,7 +50,7 @@ static int jsonrpc_check_version(struct json_object *obj)
static int jsonrpc_set_version(struct json_object *obj)
{
- return json_set_string_const_key(obj, jsonrpc_key_version, jsonrpc_value_version);
+ return libjson_set_string_const_key(obj, jsonrpc_key_version, jsonrpc_value_version);
}
static _Atomic int jsonrpc_id_counter = 1;
@@ -74,7 +74,7 @@ static int jsonrpc_check_id(struct json_object *obj, int required)
{
const char *key = jsonrpc_key_id;
- if (!json_has(obj, key)) {
+ if (!libjson_has(obj, key)) {
if (!required)
return 0;
log_err("JSON-RPC: key is missing: %s\n", key);
@@ -83,7 +83,7 @@ static int jsonrpc_check_id(struct json_object *obj, int required)
struct json_object *id = NULL;
- int ret = json_get(obj, key, &id);
+ int ret = libjson_get(obj, key, &id);
if (ret < 0)
return ret;
return jsonrpc_check_id_type(id);
@@ -91,19 +91,19 @@ static int jsonrpc_check_id(struct json_object *obj, int required)
static int jsonrpc_set_id(struct json_object *obj, int id)
{
- return json_set_int_const_key(obj, jsonrpc_key_id, id);
+ return libjson_set_int_const_key(obj, jsonrpc_key_id, id);
}
static int jsonrpc_check_method(struct json_object *obj)
{
const char *key = jsonrpc_key_method;
const char *method = NULL;
- return json_get_string(obj, key, &method);
+ return libjson_get_string(obj, key, &method);
}
static int jsonrpc_set_method(struct json_object *obj, const char *method)
{
- return json_set_string_const_key(obj, jsonrpc_key_method, method);
+ return libjson_set_string_const_key(obj, jsonrpc_key_method, method);
}
static int jsonrpc_check_params_type(struct json_object *params)
@@ -121,12 +121,12 @@ static int jsonrpc_check_params(struct json_object *obj)
{
const char *key = jsonrpc_key_params;
- if (!json_has(obj, key))
+ if (!libjson_has(obj, key))
return 0;
struct json_object *params = NULL;
- int ret = json_get(obj, key, &params);
+ int ret = libjson_get(obj, key, &params);
if (ret < 0)
return ret;
return jsonrpc_check_params_type(params);
@@ -139,7 +139,7 @@ static int jsonrpc_set_params(struct json_object *obj, struct json_object *param
int ret = jsonrpc_check_params_type(params);
if (ret < 0)
return ret;
- return json_set_const_key(obj, key, params);
+ return libjson_set_const_key(obj, key, params);
}
static const char *const jsonrpc_key_result = "result";
@@ -153,13 +153,13 @@ static int jsonrpc_check_error(struct json_object *obj)
const char *key = jsonrpc_key_error;
struct json_object *error = NULL;
- int ret = json_get(obj, key, &error);
+ int ret = libjson_get(obj, key, &error);
if (ret < 0)
return ret;
int64_t code = -1;
- ret = json_get_int(error, jsonrpc_key_code, &code);
+ ret = libjson_get_int(error, jsonrpc_key_code, &code);
if (ret < 0) {
log_err("JSON-RPC: key is missing or not an integer: %s\n", jsonrpc_key_code);
return -1;
@@ -167,7 +167,7 @@ static int jsonrpc_check_error(struct json_object *obj)
const char *message = NULL;
- ret = json_get_string(error, jsonrpc_key_message, &message);
+ ret = libjson_get_string(error, jsonrpc_key_message, &message);
if (ret < 0) {
log_err("JSON-RPC: key is missing or not a string: %s\n", jsonrpc_key_message);
return -1;
@@ -181,12 +181,12 @@ static int jsonrpc_check_result_or_error(struct json_object *obj)
const char *key_result = jsonrpc_key_result;
const char *key_error = jsonrpc_key_error;
- if (!json_has(obj, key_result) && !json_has(obj, key_error)) {
+ if (!libjson_has(obj, key_result) && !libjson_has(obj, key_error)) {
log_err("JSON-RPC: either '%s' or '%s' must be present\n", key_result, key_error);
return -1;
}
- if (json_has(obj, key_result))
+ if (libjson_has(obj, key_result))
return 0;
return jsonrpc_check_error(obj);
@@ -204,7 +204,7 @@ static int jsonrpc_request_create_internal(struct jsonrpc_request **_request, in
goto exit;
}
- ret = json_new_object(&request->impl);
+ ret = libjson_new_object(&request->impl);
if (ret < 0)
goto free;
@@ -232,7 +232,7 @@ static int jsonrpc_request_create_internal(struct jsonrpc_request **_request, in
goto exit;
free_impl:
- json_free(request->impl);
+ libjson_free(request->impl);
free:
free(request);
exit:
@@ -247,7 +247,7 @@ int jsonrpc_request_create(struct jsonrpc_request **_request, int id, const char
void jsonrpc_request_destroy(struct jsonrpc_request *request)
{
- json_free(request->impl);
+ libjson_free(request->impl);
free(request);
}
@@ -259,7 +259,7 @@ int jsonrpc_notification_create(struct jsonrpc_request **_request, const char *m
int jsonrpc_request_is_notification(const struct jsonrpc_request *request)
{
- return !json_has(request->impl, jsonrpc_key_id);
+ return !libjson_has(request->impl, jsonrpc_key_id);
}
static int jsonrpc_request_from_json(struct jsonrpc_request **_request, struct json_object *impl)
@@ -292,12 +292,12 @@ static int jsonrpc_request_from_json(struct jsonrpc_request **_request, struct j
int jsonrpc_request_send(const struct jsonrpc_request *request, int fd)
{
- return json_send(request->impl, fd);
+ return libjson_send(request->impl, fd);
}
int jsonrpc_request_recv(struct jsonrpc_request **request, int fd)
{
- struct json_object *impl = json_recv(fd);
+ struct json_object *impl = libjson_recv(fd);
if (!impl) {
log_err("JSON-RPC: failed to receive request\n");
return -1;
@@ -310,7 +310,7 @@ int jsonrpc_request_recv(struct jsonrpc_request **request, int fd)
return ret;
free_impl:
- json_free(impl);
+ libjson_free(impl);
return ret;
}
@@ -318,7 +318,7 @@ free_impl:
const char *jsonrpc_request_get_method(const struct jsonrpc_request *request)
{
const char *method = NULL;
- int ret = json_get_string(request->impl, jsonrpc_key_method, &method);
+ int ret = libjson_get_string(request->impl, jsonrpc_key_method, &method);
if (ret < 0) {
/* Should never happen. */
return NULL;
@@ -331,23 +331,23 @@ static struct json_object *jsonrpc_request_create_params(struct jsonrpc_request
int ret = 0;
const char *const key = jsonrpc_key_params;
- if (!json_has(request->impl, key)) {
+ if (!libjson_has(request->impl, key)) {
struct json_object *params = NULL;
- ret = json_new_object(&params);
+ ret = libjson_new_object(&params);
if (ret < 0)
return NULL;
- ret = json_set(request->impl, key, params);
+ ret = libjson_set(request->impl, key, params);
if (ret < 0) {
- json_free(params);
+ libjson_free(params);
return NULL;
}
return params;
}
struct json_object *params = NULL;
- ret = json_get(request->impl, key, &params);
+ ret = libjson_get(request->impl, key, &params);
if (ret < 0)
return NULL;
return params;
@@ -357,10 +357,10 @@ int jsonrpc_request_get_param_string(const struct jsonrpc_request *request, cons
const char **value)
{
struct json_object *params = NULL;
- int ret = json_get(request->impl, jsonrpc_key_params, &params);
+ int ret = libjson_get(request->impl, jsonrpc_key_params, &params);
if (ret < 0)
return ret;
- return json_get_string(params, name, value);
+ return libjson_get_string(params, name, value);
}
int jsonrpc_request_set_param_string(struct jsonrpc_request *request, const char *name,
@@ -369,17 +369,17 @@ int jsonrpc_request_set_param_string(struct jsonrpc_request *request, const char
struct json_object *params = jsonrpc_request_create_params(request);
if (!params)
return -1;
- return json_set_string(params, name, value);
+ return libjson_set_string(params, name, value);
}
int jsonrpc_request_get_param_int(const struct jsonrpc_request *request, const char *name,
int64_t *value)
{
struct json_object *params = NULL;
- int ret = json_get(request->impl, jsonrpc_key_params, &params);
+ int ret = libjson_get(request->impl, jsonrpc_key_params, &params);
if (ret < 0)
return ret;
- return json_get_int(params, name, value);
+ return libjson_get_int(params, name, value);
}
int jsonrpc_request_set_param_int(struct jsonrpc_request *request, const char *name, int64_t value)
@@ -387,12 +387,12 @@ int jsonrpc_request_set_param_int(struct jsonrpc_request *request, const char *n
struct json_object *params = jsonrpc_request_create_params(request);
if (!params)
return -1;
- return json_set_int(params, name, value);
+ return libjson_set_int(params, name, value);
}
const char *jsonrpc_response_to_string(const struct jsonrpc_response *response)
{
- return json_to_string_pretty(response->impl);
+ return libjson_to_string_pretty(response->impl);
}
int jsonrpc_response_create_internal(struct jsonrpc_response **_response,
@@ -408,7 +408,7 @@ int jsonrpc_response_create_internal(struct jsonrpc_response **_response,
goto exit;
}
- ret = json_new_object(&response->impl);
+ ret = libjson_new_object(&response->impl);
if (ret < 0)
goto free;
@@ -417,22 +417,22 @@ int jsonrpc_response_create_internal(struct jsonrpc_response **_response,
goto free_impl;
struct json_object *id = NULL;
- ret = json_clone(request->impl, jsonrpc_key_id, &id);
+ ret = libjson_clone(request->impl, jsonrpc_key_id, &id);
if (ret < 0)
goto free_impl;
- ret = json_set(response->impl, jsonrpc_key_id, id);
+ ret = libjson_set(response->impl, jsonrpc_key_id, id);
if (ret < 0) {
- json_free(id);
+ libjson_free(id);
goto free_impl;
}
if (error) {
- ret = json_set_const_key(response->impl, jsonrpc_key_error, error);
+ ret = libjson_set_const_key(response->impl, jsonrpc_key_error, error);
if (ret < 0)
goto free_impl;
} else {
- ret = json_set_const_key(response->impl, jsonrpc_key_result, result);
+ ret = libjson_set_const_key(response->impl, jsonrpc_key_result, result);
if (ret < 0)
goto free_impl;
}
@@ -441,7 +441,7 @@ int jsonrpc_response_create_internal(struct jsonrpc_response **_response,
goto exit;
free_impl:
- json_free(response->impl);
+ libjson_free(response->impl);
free:
free(response);
exit:
@@ -456,7 +456,7 @@ int jsonrpc_response_create(struct jsonrpc_response **response,
void jsonrpc_response_destroy(struct jsonrpc_response *response)
{
- json_free(response->impl);
+ libjson_free(response->impl);
free(response);
}
@@ -466,14 +466,14 @@ int jsonrpc_error_create(struct jsonrpc_response **response, struct jsonrpc_requ
int ret = 0;
struct json_object *error = NULL;
- ret = json_new_object(&error);
+ ret = libjson_new_object(&error);
if (ret < 0)
return ret;
- ret = json_set_int_const_key(error, jsonrpc_key_code, code);
+ ret = libjson_set_int_const_key(error, jsonrpc_key_code, code);
if (ret < 0)
goto free;
- ret = json_set_string_const_key(error, jsonrpc_key_message, message);
+ ret = libjson_set_string_const_key(error, jsonrpc_key_message, message);
if (ret < 0)
goto free;
@@ -484,14 +484,14 @@ int jsonrpc_error_create(struct jsonrpc_response **response, struct jsonrpc_requ
return ret;
free:
- json_free(error);
+ libjson_free(error);
return ret;
}
int jsonrpc_response_is_error(const struct jsonrpc_response *response)
{
- return json_has(response->impl, jsonrpc_key_error);
+ return libjson_has(response->impl, jsonrpc_key_error);
}
static int jsonrpc_response_from_json(struct jsonrpc_response **_response, struct json_object *impl)
@@ -521,12 +521,12 @@ static int jsonrpc_response_from_json(struct jsonrpc_response **_response, struc
int jsonrpc_response_send(const struct jsonrpc_response *response, int fd)
{
- return json_send(response->impl, fd);
+ return libjson_send(response->impl, fd);
}
int jsonrpc_response_recv(struct jsonrpc_response **response, int fd)
{
- struct json_object *impl = json_recv(fd);
+ struct json_object *impl = libjson_recv(fd);
if (!impl) {
log_err("JSON-RPC: failed to receive response\n");
return -1;
@@ -539,7 +539,7 @@ int jsonrpc_response_recv(struct jsonrpc_response **response, int fd)
return ret;
free_impl:
- json_free(impl);
+ libjson_free(impl);
return ret;
}
diff --git a/src/protocol.c b/src/protocol.c
index c45b869..d950004 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -219,7 +219,7 @@ int response_create_get_runs(struct jsonrpc_response **response,
return ret;
free_json:
- json_free(runs_json);
+ libjson_free(runs_json);
return ret;
}
diff --git a/src/run_queue.c b/src/run_queue.c
index 4374797..2f50f92 100644
--- a/src/run_queue.c
+++ b/src/run_queue.c
@@ -87,19 +87,19 @@ int run_to_json(const struct run *entry, struct json_object **_json)
struct json_object *json = NULL;
int ret = 0;
- ret = json_new_object(&json);
+ ret = libjson_new_object(&json);
if (ret < 0)
return -1;
- ret = json_set_int_const_key(json, "id", entry->id);
+ ret = libjson_set_int_const_key(json, "id", entry->id);
if (ret < 0)
goto free;
- ret = json_set_int_const_key(json, "exit_code", entry->exit_code);
+ ret = libjson_set_int_const_key(json, "exit_code", entry->exit_code);
if (ret < 0)
goto free;
- ret = json_set_string_const_key(json, "repo_url", entry->repo_url);
+ ret = libjson_set_string_const_key(json, "repo_url", entry->repo_url);
if (ret < 0)
goto free;
- ret = json_set_string_const_key(json, "repo_rev", entry->repo_rev);
+ ret = libjson_set_string_const_key(json, "repo_rev", entry->repo_rev);
if (ret < 0)
goto free;
@@ -107,7 +107,7 @@ int run_to_json(const struct run *entry, struct json_object **_json)
return ret;
free:
- json_free(json);
+ libjson_free(json);
return ret;
}
@@ -153,7 +153,7 @@ int run_queue_to_json(const struct run_queue *queue, struct json_object **_json)
struct json_object *json = NULL;
int ret = 0;
- ret = json_new_array(&json);
+ ret = libjson_new_array(&json);
if (ret < 0)
return ret;
@@ -165,9 +165,9 @@ int run_queue_to_json(const struct run_queue *queue, struct json_object **_json)
if (ret < 0)
goto free;
- ret = json_append(json, entry_json);
+ ret = libjson_append(json, entry_json);
if (ret < 0) {
- json_free(entry_json);
+ libjson_free(entry_json);
goto free;
}
}
@@ -176,7 +176,7 @@ int run_queue_to_json(const struct run_queue *queue, struct json_object **_json)
return ret;
free:
- json_free(json);
+ libjson_free(json);
return ret;
}