From bdc6f610d04ef20b54ff3e0ac292523933ad8f15 Mon Sep 17 00:00:00 2001 From: Nishi Date: Sat, 21 Sep 2024 08:47:51 +0000 Subject: [PATCH] logfile works git-svn-id: file:///raid/svn-personal/tewi/trunk@117 8739d7e6-ffea-ec47-b151-bdff447c6205 --- Server/main.c | 14 ++++++++++++++ Server/server.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Server/main.c b/Server/main.c index 433449e..aabee6c 100644 --- a/Server/main.c +++ b/Server/main.c @@ -112,6 +112,20 @@ int startup(int argc, char** argv) { return 1; } confpath = argv[i]; + } else if(strcmp(argv[i], "--logfile") == 0 || strcmp(argv[i], "-l") == 0) { + i++; + if(argv[i] == NULL) { + fprintf(stderr, "Missing argument\n"); + return 1; + } + if(logfile != NULL && logfile != stderr) { + fclose(logfile); + } + logfile = fopen(argv[i], "a"); + if(logfile == NULL) { + fprintf(stderr, "Failed to open logfile\n"); + return 1; + } } else if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) { printf("Tewi HTTPd Tewi/%s\n", tw_get_version()); printf("Under public domain.\n"); diff --git a/Server/server.c b/Server/server.c index 6f4fda0..2525ea3 100644 --- a/Server/server.c +++ b/Server/server.c @@ -456,8 +456,8 @@ int32_t tw_server_pass(void* ptr) { char* useragent = cm_strdup(""); int i; - for(i = 0; req.headers[i] != NULL; i += 2){ - if(cm_strcaseequ(req.headers[i], "User-Agent")){ + for(i = 0; req.headers[i] != NULL; i += 2) { + if(cm_strcaseequ(req.headers[i], "User-Agent")) { free(useragent); useragent = cm_strdup(req.headers[i + 1]); } -- 2.43.0