2020-09-23 15:19:29 +00:00
|
|
|
#include <getopt.h>
|
2020-09-23 14:21:44 +00:00
|
|
|
#include <stdio.h>
|
2020-09-23 15:19:29 +00:00
|
|
|
#include "config.h"
|
2020-09-24 23:58:34 +00:00
|
|
|
#include "log.h"
|
2020-10-28 16:38:32 +00:00
|
|
|
#include "mime.h"
|
2020-09-23 16:40:28 +00:00
|
|
|
#include "server.h"
|
2020-09-24 21:51:29 +00:00
|
|
|
#include "tls.h"
|
2020-09-23 15:19:29 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage(const char *argv_0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s [-C path]\n", argv_0);
|
|
|
|
}
|
2020-09-23 14:21:44 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2020-09-23 15:19:29 +00:00
|
|
|
struct gmnisrv_config conf = {0};
|
|
|
|
|
|
|
|
char *confpath = SYSCONFDIR "/gmnisrv.ini";
|
|
|
|
int c;
|
|
|
|
while ((c = getopt(argc, argv, "C:h")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'C':
|
|
|
|
confpath = optarg;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unknown flag %c\n", c);
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (optind < argc) {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-10-28 16:38:32 +00:00
|
|
|
mime_init();
|
|
|
|
|
2020-09-23 15:19:29 +00:00
|
|
|
int r = load_config(&conf, confpath);
|
|
|
|
if (r != 0) {
|
2020-09-24 23:58:34 +00:00
|
|
|
server_error("Config load failed");
|
2020-09-26 20:10:10 +00:00
|
|
|
goto exit;
|
2020-09-23 15:19:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 20:10:10 +00:00
|
|
|
r = tls_init(&conf);
|
2020-09-24 21:51:29 +00:00
|
|
|
if (r != 0) {
|
2020-09-24 23:58:34 +00:00
|
|
|
server_error("TLS initialization failed");
|
2020-09-24 21:51:29 +00:00
|
|
|
goto exit_conf;
|
|
|
|
}
|
|
|
|
|
2020-09-23 16:40:28 +00:00
|
|
|
struct gmnisrv_server server = {0};
|
|
|
|
r = server_init(&server, &conf);
|
|
|
|
if (r != 0) {
|
2020-09-26 20:10:10 +00:00
|
|
|
goto exit_tls;
|
2020-09-23 16:40:28 +00:00
|
|
|
}
|
|
|
|
server_run(&server);
|
|
|
|
|
|
|
|
server_finish(&server);
|
2020-09-26 20:10:10 +00:00
|
|
|
exit_tls:
|
|
|
|
tls_finish(&conf);
|
2020-09-23 16:40:28 +00:00
|
|
|
exit_conf:
|
|
|
|
config_finish(&conf);
|
2020-09-26 20:10:10 +00:00
|
|
|
exit:
|
2020-10-28 16:38:32 +00:00
|
|
|
mime_finish();
|
2020-09-23 14:21:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|