aboutsummaryrefslogtreecommitdiffstats
path: root/include/dbs/util.h
diff options
context:
space:
mode:
authorturret <turret@duck.com>2025-06-22 19:09:48 -0500
committerturret <turret@duck.com>2025-06-22 19:09:48 -0500
commitcee855bcc38f35250d597553ce09e315b26d3efe (patch)
treee9cadd597b142f833072cacaa29417618f70b2d4 /include/dbs/util.h
parentda7d23e5c131dceb0ad3f3fa2b157960b797e69c (diff)
downloaddiscord-bot-skeleton-cee855bcc38f35250d597553ce09e315b26d3efe.tar.gz
discord-bot-skeleton-cee855bcc38f35250d597553ce09e315b26d3efe.tar.bz2
discord-bot-skeleton-cee855bcc38f35250d597553ce09e315b26d3efe.zip
util: add json abstraction helper functions
Diffstat (limited to 'include/dbs/util.h')
-rw-r--r--include/dbs/util.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/dbs/util.h b/include/dbs/util.h
index bad4a33..bda2c32 100644
--- a/include/dbs/util.h
+++ b/include/dbs/util.h
@@ -1,3 +1,29 @@
+#ifndef __UTIL_H
+#define __UTIL_H
+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define writeputs(str) write(STDOUT_FILENO, str, strlen(str));
+
+#ifdef cJSON__h
+
+static inline int js_getInt(cJSON *js, char *name)
+{
+ cJSON *number = cJSON_GetObjectItemCaseSensitive(js, name);
+ if(cJSON_IsNumber(number))
+ return number->valueint;
+
+ return -1;
+}
+
+static inline char *js_getStr(cJSON *js, char *name)
+{
+ cJSON *str = cJSON_GetObjectItemCaseSensitive(js, name);
+ if(cJSON_IsString(str))
+ return str->valuestring;
+ return NULL;
+}
+
+#endif
+
+#endif