From 1ec38509b329c49476b5f9dfae4e1889899d1d52 Mon Sep 17 00:00:00 2001 From: the little girl Date: Sat, 29 Jun 2013 08:11:13 +0200 Subject: config.def.h, oppdatert makefile --- .gitignore | 1 + Makefile | 11 +++++++++-- config.def.h | 13 +++++++++++++ wiki.c | 39 +++++++++++++++++++-------------------- 4 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 config.def.h diff --git a/.gitignore b/.gitignore index 006d339..c3ae088 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ pages wiki.cgi +config.h diff --git a/Makefile b/Makefile index 65b2c57..fdf45bc 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,9 @@ -wiki.cgi: wiki.c - ${CC} -std=c11 -Os -o wiki.cgi wiki.c -lmarxup +wiki.cgi: config.h wiki.c + ${CC} -std=c11 -Os -o $@ wiki.c -lmarxup + +config.h: + cp config.def.h $@ + +clean: + rm wiki.cgi + diff --git a/config.def.h b/config.def.h new file mode 100644 index 0000000..a83aa8e --- /dev/null +++ b/config.def.h @@ -0,0 +1,13 @@ +static char *title = "a wiki"; +static char *id = "anonymous"; + +static char *links[][2] = { + { "home", "home" }, + { "planer", "planer" }, + 0 +}; + +static char *(*authenticate)() = NULL; + +static char *script; +static char *base; diff --git a/wiki.c b/wiki.c index 035eac8..36b86cb 100644 --- a/wiki.c +++ b/wiki.c @@ -10,17 +10,8 @@ #include -static char *wikititle = "a wiki"; -static char *id = "anonymous"; -static char *links[][2] = { - { "home", "home" }, - { "planer", "planer" }, - 0 -}; -static char *(*authenticate)() = NULL; - -static char *script; -static char *base; +#include "config.h" + static const char *badchars = "\\?%:|\"<> "; @@ -40,15 +31,15 @@ int writable(char *path) { return 0; } -void head(char *title, char *link, char *what) { +void head(char *page, char *link, char *what) { printf("Content-Type: text/html; charset=utf-8\n\n"); printf("\n"); - printf("%s · %s\n", wikititle, title); + printf("%s · %s\n", title, page); printf("\n", base); if(link && what) - printf("

%s

", what, link, title); + printf("

%s

", what, link, page); else - printf("

%s

", title); + printf("

%s

", page); } void foot(int file) { @@ -82,6 +73,13 @@ int legit(char *page) { return 1; } +int problem(int status, char *message) { + printf("Status: %d\n", status); + printf("Content-Type: text/plain\n\n"); + printf("%s\n", message); + return 1; +} + int redirect(char *path) { printf("Status: 303\n"); if(*path == '?') @@ -103,8 +101,8 @@ int unauthorized(int status) { int edit(char *path) { if(!writable(path)) return unauthorized(403); FILE *fp = fopen(path, "r"); - char *title = clean(path); - fp ? head(title, path, "vis") : head(title, NULL, NULL); + char *page = clean(path); + fp ? head(page, path, "vis") : head(page, NULL, NULL); char buffer[sysconf(_SC_PAGESIZE)]; printf("
\n"); printf("