From ad648f235d7643ff78c6eaaf9291ce5c96ac99ae Mon Sep 17 00:00:00 2001 From: the little girl Date: Thu, 9 Jan 2014 14:20:39 +0100 Subject: loft loft loft --- wiki.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/wiki.c b/wiki.c index 1c5b59d..843278b 100644 --- a/wiki.c +++ b/wiki.c @@ -3,8 +3,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -12,7 +14,6 @@ #include "config.h" - static const char *badchars = "\\?%:|\"<> "; int writable(char *path) { @@ -119,6 +120,20 @@ int edit(char *path) { return 0; } +char *loft = "loft"; +int store(char *id, char *data, int len) { + char path[strlen(id) + strlen(loft) + 256]; + time_t epoch = time(NULL); + snprintf(path, 512, "%s/%s.%d", loft, id, epoch); + FILE *fp = fopen(path, "w"); + if(!fp) return redirect(id); + fwrite(data + 5, len - 5, 1, fp); + fputc('\0', fp); + fclose(fp); + unlink(id); + symlink(path, id); +} + int post(char *path) { char *header, *data; int clen; @@ -129,11 +144,10 @@ int post(char *path) { fread(data, clen, 1, stdin); if(strncmp(data, "text=", 5)) return redirect(path); - FILE *fp = fopen(path, "w"); - if(!fp) return redirect(path); - fwrite(data + 5, clen - 5, 1, fp); - fputc('\0', fp); - fclose(fp); + + if(store(path, data, clen)) { + + } return redirect(path); } -- cgit v1.0