summaryrefslogtreecommitdiff
path: root/src/config/node.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-07-02 18:54:34 +0000
committerLaurent Bercot <ska@appnovation.com>2024-07-02 18:54:34 +0000
commit8b435b76d68dd8f11808f0cff4d8998d2be48f4c (patch)
tree501e5a0047f48fc082b3ed505022a59919c9e716 /src/config/node.c
parent9879f5bf1c7bac2f0ae2e230694c9a86b1b567b0 (diff)
downloadshibari-8b435b76d68dd8f11808f0cff4d8998d2be48f4c.tar.xz
Prepare for 0.0.2.0; add shibari-cache-config
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/config/node.c')
-rw-r--r--src/config/node.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/config/node.c b/src/config/node.c
new file mode 100644
index 0000000..7e6cd4b
--- /dev/null
+++ b/src/config/node.c
@@ -0,0 +1,34 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <string.h>
+
+#include <skalibs/stralloc.h>
+#include <skalibs/strerr.h>
+
+#include "shibari-cache-config-internal.h"
+
+#define diestorage() strerr_diefu2x(100, "add node to configuration tree", ": too much data")
+#define diefilepos() strerr_diefu2x(100, "add node to configuration tree", ": file too large")
+
+void node_start (stralloc *storage, node *node, char const *key, size_t filepos, uint32_t line)
+{
+ size_t l = strlen(key) ;
+ size_t k = storage->len ;
+ if (!stralloc_catb(storage, key, l + 1)) dienomem() ;
+ if (storage->len >= UINT32_MAX) diestorage() ;
+ if (filepos > UINT32_MAX) diefilepos() ;
+ node->key = k ;
+ node->keylen = l ;
+ node->data = storage->len ;
+ node->datalen = 0 ;
+ node->filepos = filepos ;
+ node->line = line ;
+}
+
+void node_add (stralloc *storage, node *node, char const *s, size_t len)
+{
+ if (!stralloc_catb(storage, s, len)) dienomem() ;
+ if (storage->len >= UINT32_MAX) diestorage() ;
+ node->datalen += len ;
+}