From 4c1d58b509c83ff788fe1ad6b5bdd1073977622c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 29 Jun 2021 00:16:10 +0000 Subject: Some work on the db representation Signed-off-by: Laurent Bercot --- src/libs6rcd/s6rc_service_resolve.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/libs6rcd/s6rc_service_resolve.c (limited to 'src/libs6rcd/s6rc_service_resolve.c') diff --git a/src/libs6rcd/s6rc_service_resolve.c b/src/libs6rcd/s6rc_service_resolve.c new file mode 100644 index 0000000..a786542 --- /dev/null +++ b/src/libs6rcd/s6rc_service_resolve.c @@ -0,0 +1,33 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include + +#include "db.h" + +int s6rc_service_resolve (cdb_t *c, s6rc_sid_t *id, char const *s) +{ + size_t len = strlen(s) ; + char const *param = 0 ; + char pack[5] ; + int r = cdb_find(c, s, len) ; + if (r < 0) return r ; + if (!r) + { + size_t at = byte_chr(s, len, '@') ; + if (at == len) return 0 ; + if (at == len - 1) return (errno = EINVAL, -1) ; + r = cdb_find(c, s, at + 1) ; + if (r <= 0) return r ; + param = s + at + 1 ; + } + if (cdb_read(c, pack, 5, cdb_datapos(c)) < 0) return -1 ; + id->stype = pack[0] ; + uint32_unpack_big(pack + 1, &id->i) ; + id->param = param ; + return 1 ; +} -- cgit v1.3.1