88 lines
2.1 KiB
C
88 lines
2.1 KiB
C
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
#include <logger.h>
|
|
#include <clconfig.h>
|
|
#include <tconfig.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 {
|
|
int argc;
|
|
char** argv;
|
|
char* logpath;
|
|
int port;
|
|
} server_t;
|
|
|
|
|
|
static server_t server;
|
|
|
|
int server_init(int argc, char** argv) {
|
|
logger_dprintf("server initialization");
|
|
server.argc = argc;
|
|
server.argv = argv;
|
|
return 0;
|
|
}
|
|
|
|
#define SERVER_CONFIG_ERROR -1
|
|
|
|
int server_config(void) {
|
|
logger_dprintf("server configuration");
|
|
|
|
tconfig_t tconfig;
|
|
tconfig_init(&tconfig);
|
|
|
|
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;
|
|
}
|
|
int res = tconfig_parse(&tconfig);
|
|
if (res < 0) {
|
|
char* errstr = tconfig_geterr(&tconfig);
|
|
logger_dprintf("tconfig parsing error: %s", errstr);
|
|
return SERVER_CONFIG_ERROR;
|
|
}
|
|
tconfig_destroy(&tconfig);
|
|
|
|
clconfig_t clconfig;
|
|
clconfig_init(&clconfig, server.argc, server.argv);
|
|
|
|
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;
|
|
}
|
|
|
|
logger_dprintf("logpath = %s", server.logpath);
|
|
logger_dprintf("port = %d", server.port);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int server_run(void) {
|
|
logger_dprintf("start the server");
|
|
return 0;
|
|
}
|