aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe little girl <yui@blekksprut.net>2014-09-05 14:24:25 +0200
committerthe little girl <yui@blekksprut.net>2014-09-05 14:24:25 +0200
commit65caed0a231c60a578f89fffd4347d6df0405cc5 (patch)
treea2aa0b32096d34caf2e9c8e73c7bf7515fba19d9
parentb1788b537345bd3742459f9d474d101b686d71d9 (diff)
downloadukulele-65caed0a231c60a578f89fffd4347d6df0405cc5.tar.xz
teit option som må få bedre navn
-rw-r--r--config.def.h1
-rw-r--r--wiki.c26
2 files changed, 18 insertions, 9 deletions
diff --git a/config.def.h b/config.def.h
index 12dd086..74bcc14 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,4 +1,5 @@
int orz = 0;
+int dirlist = 0;
static char *title = "a wiki";
static char *id = "anonymous";
diff --git a/wiki.c b/wiki.c
index c72b2db..ba854a5 100644
--- a/wiki.c
+++ b/wiki.c
@@ -88,7 +88,7 @@ int problem(int status, char *message) {
return 1;
}
-int redirect(char *path) {
+int redirect(char *path, char *prefix) {
printf("Status: 303\n");
switch(*path) {
case '?': printf("Location: %s\n\n", path); break;
@@ -96,7 +96,12 @@ int redirect(char *path) {
printf("Location: %s/%s?m=", script, path);
// skrive ut ++path
printf("\n");
- default: printf("Location: %s/%s\n\n", script, path); break;
+ default:
+ if(prefix) {
+ printf("Location: %s/%s/%s\n\n", script, prefix, path); break;
+ } else {
+ printf("Location: %s/%s\n\n", script, path); break;
+ }
}
return 0;
}
@@ -141,7 +146,7 @@ int store(char *raw, int len) {
int epoch = time(NULL);
snprintf(path, strlen(loft) + strlen(id) + 256, "%s/%s.%d", loft, id, epoch);
FILE *fp = fopen(path, "w");
- if(!fp) return redirect("FFFF");
+ if(!fp) return redirect("fff", NULL);
int pos = 0;
unsigned int decoded;
char buffer[3] = { 0 };
@@ -175,13 +180,13 @@ int post(char *path) {
char *header;
int clen;
header = getenv("CONTENT_LENGTH");
- if(!header) return redirect(path);
+ if(!header) return redirect(path, NULL);
clen = atoi(header);
while(clen > 1)
if(clen--, getchar() == 't')
if(clen--, getchar() == '=')
store(path, clen);
- return redirect(path);
+ return redirect(path, NULL);
}
// gjør denne penere!
@@ -273,10 +278,13 @@ void magic(FILE *out, char *line) {
int view(char *path) {
struct stat s;
stat(path, &s);
- if(S_ISDIR(s.st_mode))
- return list(path, 1, 0);
+ if(S_ISDIR(s.st_mode)) {
+ if(dirlist)
+ return list(path, 1, 0);
+ return redirect(home, path);
+ }
FILE *fp = fopen(path, "r");
- if(!fp) return redirect("?e");
+ if(!fp) return redirect("?e", NULL);
writable(path) ? head(path, "?e", "rediger") : head(path, NULL, NULL);
marxup(fp, stdout, magic);
foot(1);
@@ -298,7 +306,7 @@ int main(int argc, char **argv) {
if(!base) base = strdup(dirname(strdup(script)));
if(authenticate && !(id = authenticate())) return unauthorized(401);
- if(!legit(page++)) return redirect(home);
+ if(!legit(page++)) return redirect(home, NULL);
setenv("MARXUP_HEADER", "2", 1);
setenv("MARXUP_PREFIX", base, 1);