Files
cworker/cworker.c
2023-08-14 23:54:18 +02:00

81 lines
1.5 KiB
C

/*
*
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
*
*/
#include <config.h>
#include <cworker.h>
#include <logger.h>
#include <fcntl.h>
#include <cflexer.h>
#include <cfparser.h>
#include <massert.h>
#include <rcache.h>
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;
}
int cworker_configure(cworker_t* worker) {
log_debug("configure service");
return 0;
}
int cworker_build(cworker_t* worker) {
log_debug("build service");
return 0;
}
int cworker_run(cworker_t* worker) {
log_debug("run service");
return 0;
}