source: Main/trunk/Server/main.c@ 45

Last change on this file since 45 was 43, checked in by Nishi, on Sep 18, 2024 at 6:19:03 PM

add NO_SSL

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