aboutsummaryrefslogtreecommitdiffstats
path: root/src/cache/conf.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-07-16 01:51:04 +0000
committerLaurent Bercot <ska@appnovation.com>2024-07-16 01:51:04 +0000
commitd1c4602f80e395d1d6ab0453b8f0a6cc10aefadf (patch)
tree9e1410955b66e99d2284b0baa207d32264669716 /src/cache/conf.c
parent8b435b76d68dd8f11808f0cff4d8998d2be48f4c (diff)
downloadshibari-d1c4602f80e395d1d6ab0453b8f0a6cc10aefadf.tar.gz
Refactor dcache, add prep for shibari-cache
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/cache/conf.c')
-rw-r--r--src/cache/conf.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/cache/conf.c b/src/cache/conf.c
new file mode 100644
index 0000000..ea35646
--- /dev/null
+++ b/src/cache/conf.c
@@ -0,0 +1,36 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <string.h>
+
+#include <skalibs/uint32.h>
+#include <skalibs/cdb.h>
+
+#include "shibari-cache-internal.h"
+
+#include <skalibs/posixishard.h>
+
+int conf_getb (cdb const *c, char const *key, size_t keylen, cdb_data *data)
+{
+ if (keylen > 4096) return (errno = EINVAL, 0) ;
+ switch (cdb_find(c, data, key, keylen))
+ {
+ case -1 : return (errno = EILSEQ, 0) ;
+ case 0 : return (errno = ENOENT, 0) ;
+ default : return 1 ;
+ }
+}
+
+int conf_get (cdb const *c, char const *key, cdb_data *data)
+{
+ return conf_get(c, key, strlen(key), data) ;
+}
+
+int conf_get_uint32 (cdb const *c, char const *key, uint32_t *value)
+{
+ cdb_data data ;
+ if (!conf_get(conf, key, &data)) return 0 ;
+ if (data.len != 4) return (errno = EPROTO, 0) ;
+ uint32_unpack_big(data.s, value) ;
+ return 1 ;
+}