aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe little girl <yui@blekksprut.net>2014-01-09 14:20:39 +0100
committerthe little girl <yui@blekksprut.net>2014-01-09 14:20:39 +0100
commitad648f235d7643ff78c6eaaf9291ce5c96ac99ae (patch)
tree201bd72f5856cbb3feb251490f60cbf9bb5d73ab
parent2fc72187ec46064ee9d96570851993ff13f2fe49 (diff)
downloadukulele-ad648f235d7643ff78c6eaaf9291ce5c96ac99ae.tar.xz
loft loft loft
-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);
}