about summary refs log tree commit diff
path: root/src/config/resattr.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-30 11:16:55 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-30 11:16:55 +0000
commit1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c (patch)
tree9c5ac88f1c430686d45de44ee36f29fe26be42b1 /src/config/resattr.c
parentad88c5ec68b1cfd47017face422132ab8c7b2874 (diff)
downloadtipidee-1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c.tar.gz
tipidee-1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c.tar.xz
tipidee-1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c.zip
Revamp (and hopefully fix) resattr management
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/config/resattr.c')
-rw-r--r--src/config/resattr.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/config/resattr.c b/src/config/resattr.c
new file mode 100644
index 0000000..80bd0e0
--- /dev/null
+++ b/src/config/resattr.c
@@ -0,0 +1,56 @@
+/* ISC license. */
+
+#include <skalibs/genalloc.h>
+#include <skalibs/avltree.h>
+#include <skalibs/cdbmake.h>
+
+#include "tipidee-config-internal.h"
+
+static repo resattr = \
+{ \
+  .ga = GENALLOC_ZERO, \
+  .tree = AVLTREE_INIT(8, 3, 8, &node_dtok, &node_cmp, &resattr.ga), \
+  .storage = &g.storage \
+} ;
+
+void confnode_start (node *node, char const *key, size_t filepos, uint32_t line)
+{
+  return node_start(&g.storage, node, key, filepos, line) ;
+}
+
+void confnode_add (node *node, char const *s, size_t len)
+{
+  return node_add(&g.storage, node, s, len) ;
+}
+
+node const *conftree_search (char const *key)
+{
+  return repo_search(&conftree, key) ;
+}
+
+void conftree_add (node const *node)
+{
+  return repo_add(&conftree, node) ;
+}
+
+void conftree_update (node const *node)
+{
+  return repo_update(&conftree, node) ;
+}
+
+static int confnode_write (uint32_t d, unsigned int h, void *data)
+{
+  node *nod = genalloc_s(node, &conftree.ga) + d ;
+  (void)h ;
+  if ((conftree.storage->s[nod->key] & ~0x20) == 'A')
+  {
+    conftree.storage->s[++nod->data] |= '@' ;
+    nod->datalen-- ;
+  }
+  return cdbmake_add((cdbmaker *)data, conftree.storage->s + nod->key, nod->keylen, conftree.storage->s + nod->data, nod->datalen) ;
+}
+
+int conftree_write (cdbmaker *cm)
+{
+  return avltree_iter(&conftree.tree, &confnode_write, cm) ;
+}