summaryrefslogtreecommitdiffstats
path: root/src/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index 31b13b6..2e60467 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,3 +1,29 @@
#pragma once
+#include <json-c/json.h>
+
+
#define NODE_NAME(c) (*(char **)&(c)->node.key)
+
+
+static inline struct json_object * neco_json_get_value(
+ struct json_object *obj,
+ const char *key,
+ enum json_type type
+) {
+ struct json_object *value;
+ if (!json_object_object_get_ex(obj, key, &value))
+ return NULL;
+ if (!json_object_is_type(value, type))
+ return NULL;
+
+ return value;
+}
+
+static inline const char * neco_json_get_string(struct json_object *obj, const char *key) {
+ struct json_object *value = neco_json_get_value(obj, key, json_type_string);
+ if (!value)
+ return NULL;
+
+ return json_object_get_string(value);
+}