aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/json.h
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-07-17 23:03:59 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-07-18 00:38:50 +0200
commite05f02acd583797ceb449fc501d371d45a4293c1 (patch)
tree491322cf633b67918f0361c1ce986f6b690844bc /src/json.h
parentdocker: sanitize package dependencies (diff)
downloadcimple-e05f02acd583797ceb449fc501d371d45a4293c1.tar.gz
cimple-e05f02acd583797ceb449fc501d371d45a4293c1.zip
switch to JSON-RPC as message format
Instead of the weird `struct msg` I had, I switched to the JSON-RPC format. It's basically the same, but has a well-defined semantics in case of errors.
Diffstat (limited to 'src/json.h')
-rw-r--r--src/json.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/json.h b/src/json.h
new file mode 100644
index 0000000..77bfde4
--- /dev/null
+++ b/src/json.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com>
+ * This file is part of the "cimple" project.
+ * For details, see https://github.com/egor-tensin/cimple.
+ * Distributed under the MIT License.
+ */
+
+#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)
+
+char *json_to_string(struct json_object *);
+struct json_object *json_from_string(const char *);
+
+int json_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 json_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 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 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);
+
+#endif