/* * * Copyright 2023 Oleg Borodin * */ #include #include #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) < 0) { log_error("parse config error\n"); return -1; } cfparser_bind(&parser, CFVALTYPE_INT, "port", (void *)&(worker->port)); cfparser_destroy(&parser); cflexer_destroy(&lexer); rcache_destroy(&cache); return 0; } int cworker_readopts(cworker_t* worker, char** argv, int argc) { log_debug("reading options"); cllexer_t lexer; clparser_t parser; cllexer_init(&lexer); clparser_init(&parser, &lexer); clparser_bind(&parser, CLVALTYPE_INT, "port", (void *)&(worker->port)); if (clparser_parse(&parser, &argv[1], argc - 1) < 0) { log_error("parse args error\n"); return -1; } return 0; } const int64_t default_port = 9701; int cworker_init(cworker_t* worker, char** argv, int argc) { log_debug("init service"); worker->port = default_port; if (cworker_readconf(worker) < 0) { log_error("reading config error\n"); return -1; } if (cworker_readopts(worker, argv, argc) < 0) { log_error("reading config error\n"); return -1; } log_debug("port: %d", worker->port); 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; }