bunkum

an old and silly c99 web server with some fun features
Log | Files | Refs | README

commit 9a07959db251f9824d005d5d350eccdf15e339ea
parent 8b6ed5c1e69634b16639ebd28fe7c00954a1dcc5
Author: quantumish <freifeld.david@gmail.com>
Date:   Sun,  9 Apr 2023 17:47:28 -0700

Add Docker isolation, bugfixes

Diffstat:
M.gitignore | 2+-
ADockerfile | 19+++++++++++++++++++
MMakefile | 6+++++-
Mhttp.c | 19++++++++++---------
Mutils/shitvec.c | 1+
5 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,5 +1,5 @@ serv -public/ +build/ *.o diff --git a/Dockerfile b/Dockerfile @@ -0,0 +1,19 @@ + +FROM ubuntu:latest +RUN apt-get update +# RUN apt-get install -y zlib1g +# RUN apt-get install -y zlib1g-dev + +WORKDIR /root +COPY public public + +# # for compilation +# COPY utils utils +# COPY http http +# COPY Makefile . +# COPY http.c . +# RUN make + +COPY serv . +RUN chmod +x ./serv +ENTRYPOINT ["./serv"] diff --git a/Makefile b/Makefile @@ -3,12 +3,16 @@ LIBS:=-lz -lpthread SOURCES = $(wildcard utils/*.c) $(wildcard http/*.c) http.c OBJ = $(wildcard build/*.o) -.PHONY: all clean +.PHONY: all clean run all: serv serv: $(SOURCES) $(CC) -o $@ $^ $(CFLAGS) $(LIBS) +run: serv + sudo docker build -t bunkum-dev . + sudo docker run -it -p "8080:8082" bunkum-dev + clean: rm serv diff --git a/http.c b/http.c @@ -82,20 +82,20 @@ void* handle_conn(void* ctxt) { bool escape = false; bool compression = true; - char* ext = strchr(pathbuf+1, '.')+1; - // TODO clean this up some - if (strcmp(ext, "html") == 0) { + char* ext = strchr(pathbuf+1, '.'); + // TODO clean this up some + if (ext == NULL) { resp_add_hdr(&r, "Content-Type", "text/html"); - } else if (strcmp(ext, "png") == 0) { + escape = true; + } else if (strcmp(ext+1, "html") == 0) { + resp_add_hdr(&r, "Content-Type", "text/html"); + } else if (strcmp(ext+1, "png") == 0) { compression = false; resp_add_hdr(&r, "Content-Type", "image/png"); - } else if (strcmp(ext, "svg") == 0) { + } else if (strcmp(ext+1, "svg") == 0) { resp_add_hdr(&r, "Content-Type", "image/svg+xml"); - } else if (strcmp(ext, "jpeg") == 0) { + } else if (strcmp(ext+1, "jpeg") == 0) { resp_add_hdr(&r, "Content-Type", "image/jpeg"); - } else { - resp_add_hdr(&r, "Content-Type", "text/html"); - escape = true; } char datebuf[32]; @@ -148,6 +148,7 @@ int main() { die("bind"); } } + log_debug("Open on port 8082."); int namelen; char pathbuf[MAX_PATH_SZ]; diff --git a/utils/shitvec.c b/utils/shitvec.c @@ -23,6 +23,7 @@ void shitvec_push(shitvec_t* sv, void* item) { // FIXME sketchy af if ((sv->arr+(2 * sv->e_sz * sv->vec_sz)) > sv->arr+sv->alloc_sz) { sv->arr = realloc(sv->arr, sv->alloc_sz * 2); + sv->alloc_sz *= 2; } memcpy(sv->arr+(sv->vec_sz * sv->e_sz), item, sv->e_sz); sv->vec_sz += 1;