diff options
author | the little girl <yui@blekksprut.net> | 2014-09-05 14:24:25 +0200 |
---|---|---|
committer | the little girl <yui@blekksprut.net> | 2014-09-05 14:24:25 +0200 |
commit | 65caed0a231c60a578f89fffd4347d6df0405cc5 (patch) | |
tree | a2aa0b32096d34caf2e9c8e73c7bf7515fba19d9 /wiki.c | |
parent | b1788b537345bd3742459f9d474d101b686d71d9 (diff) | |
download | ukulele-65caed0a231c60a578f89fffd4347d6df0405cc5.tar.xz |
teit option som må få bedre navn
Diffstat (limited to 'wiki.c')
-rw-r--r-- | wiki.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -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); |