aboutsummaryrefslogtreecommitdiff
path: root/wiki.c
diff options
context:
space:
mode:
Diffstat (limited to 'wiki.c')
-rw-r--r--wiki.c26
1 files 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <fcntl.h>
#include <glob.h>
#include <libgen.h>
+#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -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);
}