smol_http

A simple http server supporting GET requests. Written in less than 400 lines of C.
Log | Files | Refs | README | LICENSE

commit bf9bad237100fa58ac3711857cf3a2c98bada24a
parent 94d4c90827c3c0445bb6714f36664b41b474e91b
Author: Anton Kling <anton@kling.gg>
Date:   Fri,  4 Mar 2022 21:52:28 +0100

Move certain settings into config.h. This makes it easier to pull newly
updated code from a git repo while keeping personal changes seperatly in
config.h.

Diffstat:
MMakefile | 7++++++-
Aconfig.def.h | 12++++++++++++
Msmol_http.c | 14+-------------
3 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,11 +1,16 @@ CFLAGS=-Wall -pedantic -Werror -Wimplicit-fallthrough +all: config.h smol_http + +config.h: + cp config.def.h $@ + smol_http: smol_http.c $(CC) $(CFLAGS) $^ -o $@ chown root:root $@ chmod u+s $@ -install: all +install: smol_http config.h mkdir -p /usr/bin cp -f smol_http /usr/bin chmod 755 /usr/bin/smol_http diff --git a/config.def.h b/config.def.h @@ -0,0 +1,12 @@ +// Should xxx.html not exist these will be supplied instead. +#define DEFAULT_404_SITE "404 - Not Found\0" +#define DEFAULT_400_SITE "400 - Bad Request\0" + +// Default port should -p not be supplied. +#define DEFAULT_PORT 1337 + +// Default directory should -d not be supplied. +#define WEBSITE_ROOT "./site/" + +#define TIMEOUT_SECOND 3 +#define TIMEOUT_USECOND 0 diff --git a/smol_http.c b/smol_http.c @@ -12,6 +12,7 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "config.h" #include <arpa/inet.h> #include <assert.h> #include <dirent.h> @@ -30,19 +31,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <sys/time.h> #include <unistd.h> -// Should xxx.html not exist these will be supplied instead. -#define DEFAULT_404_SITE "404 - Not Found\0" -#define DEFAULT_400_SITE "400 - Bad Request\0" - -// Default port should -p not be supplied. -#define DEFAULT_PORT 1337 - -// Default directory should -d not be supplied. -#define WEBSITE_ROOT "./site/" - -#define TIMEOUT_SECOND 3 -#define TIMEOUT_USECOND 0 - #define MAX_BUFFER 4096 // Size of the read buffer #ifndef PATH_MAX