1 | /* $Id: main.c 20 2024-09-14 09:59:15Z nishi $ */
|
---|
2 |
|
---|
3 | #define SOURCE
|
---|
4 |
|
---|
5 | #include <stdio.h>
|
---|
6 | #include <stdbool.h>
|
---|
7 | #include <string.h>
|
---|
8 | #include <signal.h>
|
---|
9 |
|
---|
10 | #include <openssl/opensslv.h>
|
---|
11 |
|
---|
12 | #include <cm_log.h>
|
---|
13 |
|
---|
14 | #include "tw_config.h"
|
---|
15 | #include "tw_server.h"
|
---|
16 | #include "tw_version.h"
|
---|
17 |
|
---|
18 | extern bool cm_do_log;
|
---|
19 | extern struct tw_config config;
|
---|
20 |
|
---|
21 | char tw_server[2048];
|
---|
22 |
|
---|
23 | int main(int argc, char** argv) {
|
---|
24 | int i;
|
---|
25 | const char* confpath = PREFIX "/etc/tewi.conf";
|
---|
26 | for(i = 1; i < argc; i++) {
|
---|
27 | if(argv[i][0] == '-') {
|
---|
28 | if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
|
---|
29 | if(!cm_do_log) {
|
---|
30 | cm_do_log = true;
|
---|
31 | cm_log("", "This is Tewi HTTPd, version %s, using %s", tw_get_version(), OPENSSL_VERSION_TEXT);
|
---|
32 | } else {
|
---|
33 | cm_do_log = true;
|
---|
34 | }
|
---|
35 | } else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) {
|
---|
36 | i++;
|
---|
37 | if(argv[i] == NULL) {
|
---|
38 | fprintf(stderr, "Missing argument\n");
|
---|
39 | return 1;
|
---|
40 | }
|
---|
41 | confpath = argv[i];
|
---|
42 | } else {
|
---|
43 | fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
---|
44 | return 1;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 | tw_config_init();
|
---|
49 | if(tw_config_read(confpath) != 0) {
|
---|
50 | fprintf(stderr, "Could not read the config\n");
|
---|
51 | return 1;
|
---|
52 | }
|
---|
53 | if(tw_server_init() != 0) {
|
---|
54 | fprintf(stderr, "Could not initialize the server\n");
|
---|
55 | return 1;
|
---|
56 | }
|
---|
57 | sprintf(tw_server, "Tewi/%s (%s)%s", tw_get_version(), tw_get_platform(), config.extension == NULL ? "" : config.extension);
|
---|
58 | cm_log("Daemon", "Ready, server: %s", tw_server);
|
---|
59 | #ifndef __MINGW32__
|
---|
60 | signal(SIGCHLD, SIG_IGN);
|
---|
61 | #endif
|
---|
62 | tw_server_loop();
|
---|
63 | }
|
---|