From 00bd68d09f547077dbd22e4190ae37ab28968ad9 Mon Sep 17 00:00:00 2001 From: Oleg Borodin Date: Mon, 14 Aug 2023 23:54:18 +0200 Subject: [PATCH] at work --- cworker.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ cworker.conf | 0 cworker.h | 3 +++ 3 files changed, 50 insertions(+) create mode 100644 cworker.conf diff --git a/cworker.c b/cworker.c index 3158675..471d3b2 100644 --- a/cworker.c +++ b/cworker.c @@ -4,14 +4,61 @@ * */ +#include #include #include +#include + +#include +#include +#include +#include + +int cworker_readconf(cworker_t* worker) { + log_debug("reading configiration"); + + int conf_fd = -1; + if ((conf_fd = open(srv_configpath, O_RDONLY)) < 0) { + log_error("cannot open config file %s", srv_configpath); + return -1; + } + + rcache_t cache; + cflexer_t lexer; + cfparser_t parser; + + rcache_init(&cache, conf_fd); + cflexer_init(&lexer, &cache); + cfparser_init(&parser, &lexer); + + if (cfparser_parse(&parser)) { + log_error("parse args error\n"); + return -1; + } + + cfparser_bind(&parser, CFVALTYPE_STR, "port", (void *)&(worker->port)); + + cfparser_destroy(&parser); + cflexer_destroy(&lexer); + rcache_destroy(&cache); + + return 0; +} int cworker_init(cworker_t* worker) { log_debug("init service"); + + worker->port = 9701; + + if (cworker_readconf(worker) < 0) { + log_error("reading config error\n"); + return -1; + } + return 0; } + int cworker_detach(cworker_t* worker) { log_debug("detach service"); return 0; diff --git a/cworker.conf b/cworker.conf new file mode 100644 index 0000000..e69de29 diff --git a/cworker.h b/cworker.h index 18028b3..524e32e 100644 --- a/cworker.h +++ b/cworker.h @@ -2,7 +2,10 @@ #ifndef CWORKER_H_QWERTY #define CWORKER_H_QWERTY +#include + typedef struct { + int64_t port; } cworker_t; int cworker_init(cworker_t* worker);