From 3e978a685f2367bde7d74ec98322720efd4c4c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Sun, 19 Oct 2025 09:50:19 +0200 Subject: [PATCH] work in progess --- helmet.conf | 2 +- helmetd.c | 4 ++-- libxtools/clcomp.c | 2 +- libxtools/tccomp.c | 2 -- libxtools/tccomp_test.c | 5 ----- server.c | 48 +++++++++++++++++++++++++++++++-------- server.h | 2 +- server_test.c | 5 ++++- test_clconfig_out.txt | 50 ----------------------------------------- 9 files changed, 48 insertions(+), 72 deletions(-) delete mode 100644 test_clconfig_out.txt diff --git a/helmet.conf b/helmet.conf index 43b77b4..58b7bc5 100644 --- a/helmet.conf +++ b/helmet.conf @@ -1,5 +1,5 @@ -logpath = /var/log/helmet.log +#logpath = /var/log/helmet.log sockpath = /var/run/helmet.run diff --git a/helmetd.c b/helmetd.c index a184311..99eab53 100644 --- a/helmetd.c +++ b/helmetd.c @@ -8,11 +8,11 @@ #include -int main(void) { +int main(int argc, char** argv) { int res = 0; - logger_init(); logger_dprintf("main start"); + logger_init(argc, argv); server_init(); server_config(); diff --git a/libxtools/clcomp.c b/libxtools/clcomp.c index 65c3dd9..dd71b4a 100644 --- a/libxtools/clcomp.c +++ b/libxtools/clcomp.c @@ -102,7 +102,7 @@ int clcomp_parse(clcomp_t * comp) { case 3:{ if (toktype == TOKEN_WORD) { comp->pos = 0; - printf("pos %d: TOKEN_WORD %s\n", comp->pos, token); + DPRINTF("pos %d: TOKEN_WORD %s\n", comp->pos, token); val = strcopy(token); DPRINTF("keyval = [%s], [%s]\n", key, val); vmapper_set(comp->vmapper, key, val); diff --git a/libxtools/tccomp.c b/libxtools/tccomp.c index 64cc950..87467f9 100644 --- a/libxtools/tccomp.c +++ b/libxtools/tccomp.c @@ -4,8 +4,6 @@ * */ -#define DEBUG 1 - #include #include #include diff --git a/libxtools/tccomp_test.c b/libxtools/tccomp_test.c index 92466cb..3b06e0b 100644 --- a/libxtools/tccomp_test.c +++ b/libxtools/tccomp_test.c @@ -21,19 +21,15 @@ int main(void) { char* src = "key1 = var1 # comment 1\nkey2 = var2 # comment 2 and 3\n# comment 4\nkey3 = var3"; bstream_t stream; - bstream_init(&stream); tclexer_t lexer; - tclexer_init(&lexer, &stream); vmapper_t vmapper; - vmapper_init(&vmapper); tccomp_t comp; - tccomp_init(&comp, &lexer, &vmapper); bstream_write(&stream, src, strlen(src)); @@ -51,7 +47,6 @@ int main(void) { vmapper_set(&vmapper, "flag", "true"); int res = tccomp_parse(&comp); - if (res < 0) { printf("parsing error pos %d line %d\n", comp.pos, comp.lnum); } diff --git a/server.c b/server.c index cfb8fab..27fbcd2 100644 --- a/server.c +++ b/server.c @@ -8,16 +8,31 @@ #include #include +/* +static char* strcopy(char* src) { + size_t srcsize = strlen(src) + 1; + char* dst = malloc(srcsize); + + memset(dst, '\0', srcsize); + strcpy(dst, src); + return dst; +} +*/ typedef struct { - + int argc; + char** argv; + char* logpath; + int port; } server_t; -//static server_t server; +static server_t server; -int server_init(void) { +int server_init(int argc, char** argv) { logger_dprintf("server initialization"); + server.argc = argc; + server.argv = argv; return 0; } @@ -29,8 +44,12 @@ int server_config(void) { tconfig_t tconfig; tconfig_init(&tconfig); - char* logpath = NULL; - tconfig_bind(&tconfig, TCONF_STR, "logpath", &logpath); + server.logpath = "/var/log/helmetd.log"; + server.port = 1025; + + tconfig_bind(&tconfig, TCONF_STR, "logpath", &server.logpath); + tconfig_bind(&tconfig, TCONF_INT, "port", &server.port); + ssize_t rsize = tconfig_read(&tconfig, "helmet.conf"); if (rsize < 0) { return SERVER_CONFIG_ERROR; @@ -41,12 +60,23 @@ int server_config(void) { logger_dprintf("tconfig parsing error: %s", errstr); return SERVER_CONFIG_ERROR; } + tconfig_destroy(&tconfig); + + clconfig_t clconfig; + clconfig_init(&clconfig, server.argc, server.argv); - //tconfig_destroy(&tconfig); - //logger_dprintf("logpath = %s", logpath); + clconfig_bind(&clconfig, GCONF_INT, "port", &(server.port)); + clconfig_bind(&clconfig, GCONF_STR, "log", &(server.logpath)); + + res = clconfig_parse(&clconfig); + if (res < 0) { + char* errstr = clconfig_geterr(&clconfig); + logger_dprintf("clconfig parsing error: %s", errstr); + return SERVER_CONFIG_ERROR; + } - //clconfig_t clconfig; - //clconfig_init(&clconfig); + logger_dprintf("logpath = %s", server.logpath); + logger_dprintf("port = %d", server.port); return 0; } diff --git a/server.h b/server.h index 239d5e0..b8f3ccc 100644 --- a/server.h +++ b/server.h @@ -2,7 +2,7 @@ #ifndef SERVER_H_QWERTY #define SERVER_H_QWERTY -int server_init(void); +int server_init(int argc, char** argv); int server_config(void); int server_run(void); diff --git a/server_test.c b/server_test.c index 52b0672..479300d 100644 --- a/server_test.c +++ b/server_test.c @@ -16,7 +16,10 @@ int main(int argc, char** argv) { (void)argc; (void)argv; - server_init(); + char* _argv[] = { argv[0], "--log=/var/log/mylog", "--port=1029" }; + int _argc = 2; + + server_init(_argc, _argv); int res = 0; if ((res = server_config()) < 0) { return res; diff --git a/test_clconfig_out.txt b/test_clconfig_out.txt deleted file mode 100644 index 591a573..0000000 --- a/test_clconfig_out.txt +++ /dev/null @@ -1,50 +0,0 @@ -cd libxtools && ./cllexer_test -cllexer_gettok res: 0: 4 [--] -cllexer_gettok res: 1: 2 [qwerty] -cllexer_gettok res: 2: 3 [=] -cllexer_gettok res: 3: 2 [-num-12345] -cllexer_gettok res: 4: 5 [EOF] -cd libxtools && ./clcomp_test -cllexer_parse res: 1: 4 [--] -pos 1: TOKEN_PREF -- -cllexer_parse res: 2: 2 [qwerty] -pos 2: TOKEN_WORD qwerty -cllexer_parse res: 3: 3 [=] -pos 3: TOKEN_DELIM = -cllexer_parse res: 4: 2 [12345] -pos 0: TOKEN_WORD 12345 -keyval = [qwerty], [12345] -cllexer_parse res: 5: 6 [space] -cllexer_parse res: 6: 4 [--] -pos 1: TOKEN_PREF -- -cllexer_parse res: 7: 2 [foo] -pos 2: TOKEN_WORD foo -cllexer_parse res: 8: 3 [=] -pos 3: TOKEN_DELIM = -cllexer_parse res: 9: 2 [bar] -pos 0: TOKEN_WORD bar -keyval = [foo], [bar] -cllexer_parse res: 10: 5 [EOF] -cd libxtools && ./clconfig_test -cllexer_parse res: 1: 4 [--] -pos 1: TOKEN_PREF -- -cllexer_parse res: 2: 2 [strkey] -pos 2: TOKEN_WORD strkey -cllexer_parse res: 3: 3 [=] -pos 3: TOKEN_DELIM = -cllexer_parse res: 4: 2 [num5678] -pos 0: TOKEN_WORD num5678 -keyval = [strkey], [num5678] -cllexer_parse res: 5: 6 [space] -cllexer_parse res: 6: 4 [--] -pos 1: TOKEN_PREF -- -cllexer_parse res: 7: 2 [intkey] -pos 2: TOKEN_WORD intkey -cllexer_parse res: 8: 3 [=] -pos 3: TOKEN_DELIM = -cllexer_parse res: 9: 2 [12345] -pos 0: TOKEN_WORD 12345 -keyval = [intkey], [12345] -cllexer_parse res: 10: 5 [EOF] -int key = 12345 -str key = num5678