work in progess

This commit is contained in:
Олег Бородин
2025-10-19 09:50:19 +02:00
parent a9541628be
commit 3e978a685f
9 changed files with 48 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
logpath = /var/log/helmet.log #logpath = /var/log/helmet.log
sockpath = /var/run/helmet.run sockpath = /var/run/helmet.run

View File

@@ -8,11 +8,11 @@
#include <massert.h> #include <massert.h>
int main(void) { int main(int argc, char** argv) {
int res = 0; int res = 0;
logger_init();
logger_dprintf("main start"); logger_dprintf("main start");
logger_init(argc, argv);
server_init(); server_init();
server_config(); server_config();

View File

@@ -102,7 +102,7 @@ int clcomp_parse(clcomp_t * comp) {
case 3:{ case 3:{
if (toktype == TOKEN_WORD) { if (toktype == TOKEN_WORD) {
comp->pos = 0; 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); val = strcopy(token);
DPRINTF("keyval = [%s], [%s]\n", key, val); DPRINTF("keyval = [%s], [%s]\n", key, val);
vmapper_set(comp->vmapper, key, val); vmapper_set(comp->vmapper, key, val);

View File

@@ -4,8 +4,6 @@
* *
*/ */
#define DEBUG 1
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>

View File

@@ -21,19 +21,15 @@ int main(void) {
char* src = "key1 = var1 # comment 1\nkey2 = var2 # comment 2 and 3\n# comment 4\nkey3 = var3"; char* src = "key1 = var1 # comment 1\nkey2 = var2 # comment 2 and 3\n# comment 4\nkey3 = var3";
bstream_t stream; bstream_t stream;
bstream_init(&stream); bstream_init(&stream);
tclexer_t lexer; tclexer_t lexer;
tclexer_init(&lexer, &stream); tclexer_init(&lexer, &stream);
vmapper_t vmapper; vmapper_t vmapper;
vmapper_init(&vmapper); vmapper_init(&vmapper);
tccomp_t comp; tccomp_t comp;
tccomp_init(&comp, &lexer, &vmapper); tccomp_init(&comp, &lexer, &vmapper);
bstream_write(&stream, src, strlen(src)); bstream_write(&stream, src, strlen(src));
@@ -51,7 +47,6 @@ int main(void) {
vmapper_set(&vmapper, "flag", "true"); vmapper_set(&vmapper, "flag", "true");
int res = tccomp_parse(&comp); int res = tccomp_parse(&comp);
if (res < 0) { if (res < 0) {
printf("parsing error pos %d line %d\n", comp.pos, comp.lnum); printf("parsing error pos %d line %d\n", comp.pos, comp.lnum);
} }

View File

@@ -8,16 +8,31 @@
#include <tconfig.h> #include <tconfig.h>
#include <massert.h> #include <massert.h>
/*
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 { typedef struct {
int argc;
char** argv;
char* logpath;
int port;
} server_t; } 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"); logger_dprintf("server initialization");
server.argc = argc;
server.argv = argv;
return 0; return 0;
} }
@@ -29,8 +44,12 @@ int server_config(void) {
tconfig_t tconfig; tconfig_t tconfig;
tconfig_init(&tconfig); tconfig_init(&tconfig);
char* logpath = NULL; server.logpath = "/var/log/helmetd.log";
tconfig_bind(&tconfig, TCONF_STR, "logpath", &logpath); 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"); ssize_t rsize = tconfig_read(&tconfig, "helmet.conf");
if (rsize < 0) { if (rsize < 0) {
return SERVER_CONFIG_ERROR; return SERVER_CONFIG_ERROR;
@@ -41,12 +60,23 @@ int server_config(void) {
logger_dprintf("tconfig parsing error: %s", errstr); logger_dprintf("tconfig parsing error: %s", errstr);
return SERVER_CONFIG_ERROR; return SERVER_CONFIG_ERROR;
} }
tconfig_destroy(&tconfig);
//tconfig_destroy(&tconfig); clconfig_t clconfig;
//logger_dprintf("logpath = %s", logpath); clconfig_init(&clconfig, server.argc, server.argv);
//clconfig_t clconfig; clconfig_bind(&clconfig, GCONF_INT, "port", &(server.port));
//clconfig_init(&clconfig); 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;
}
logger_dprintf("logpath = %s", server.logpath);
logger_dprintf("port = %d", server.port);
return 0; return 0;
} }

View File

@@ -2,7 +2,7 @@
#ifndef SERVER_H_QWERTY #ifndef SERVER_H_QWERTY
#define SERVER_H_QWERTY #define SERVER_H_QWERTY
int server_init(void); int server_init(int argc, char** argv);
int server_config(void); int server_config(void);
int server_run(void); int server_run(void);

View File

@@ -16,7 +16,10 @@ int main(int argc, char** argv) {
(void)argc; (void)argc;
(void)argv; (void)argv;
server_init(); char* _argv[] = { argv[0], "--log=/var/log/mylog", "--port=1029" };
int _argc = 2;
server_init(_argc, _argv);
int res = 0; int res = 0;
if ((res = server_config()) < 0) { if ((res = server_config()) < 0) {
return res; return res;

View File

@@ -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