From 6c26e4ce46dae71531f46fe9b217ed38a5cf7c58 Mon Sep 17 00:00:00 2001 From: nishi Date: Sat, 17 Feb 2024 02:35:29 +0000 Subject: [PATCH] httpd git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@237 d27a3e52-49c5-7645-884c-6793ebffc270 --- Example/httpd/httpd.c | 39 +++++++++++++++++++++++++++++++++++---- W3Version.h.m4 | 2 +- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Example/httpd/httpd.c b/Example/httpd/httpd.c index 33167e7..0c88528 100644 --- a/Example/httpd/httpd.c +++ b/Example/httpd/httpd.c @@ -152,13 +152,44 @@ int main(int argc, char** argv) { if(f != NULL){ struct stat s; stat(configfile, &s); - char* file = malloc(s.st_size + 1); - file[s.st_size] = 0; - fread(file, s.st_size, 1, f); + char* buf = malloc(s.st_size + 1); + buf[s.st_size] = 0; + fread(buf, s.st_size, 1, f); /* TODO: Parse the config file */ + char* line = malloc(1); + line[0] = 0; + char* cbuf = malloc(2); + cbuf[1] = 0; + for(i = 0;; i++){ + if(buf[i] == '\n' || buf[i] == 0){ + if(line[0] != '#' && strcmp(line, "") != 0){ + int j; + bool hasparam = false; + for(j = 0; line[j] != 0; j++){ + if(line[j] == ' '){ + line[j] = 0; + hasparam = true; + break; + } + } + } + free(line); + line = malloc(1); + line[0] = 0; + if(buf[i] == 0) break; + }else if(buf[i] != '\r'){ + /* Rejecting \r is a good idea for the time when I add the Windows support. */ + cbuf[0] = buf[i]; + char* tmp = line; + line = __W3_Concat(tmp, cbuf); + free(tmp); + } + } + free(cbuf); + free(line); - free(file); + free(buf); fclose(f); }else{ free(badreq_header); diff --git a/W3Version.h.m4 b/W3Version.h.m4 index 9b438e0..159dcd0 100644 --- a/W3Version.h.m4 +++ b/W3Version.h.m4 @@ -6,7 +6,7 @@ extern "C" { #endif -#define LIBW3_VERSION "2.16B" \ +#define LIBW3_VERSION "2.16C" \ SUFFIX ifdef(`HTTP_SUPPORT', `#define LIBW3_HTTP_SUPPORT', `') -- 2.43.0