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