aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe little girl <yui@blekksprut.net>2016-11-11 02:22:25 +0900
committerbie <bie@blekksprut.net>2016-11-11 02:22:25 +0900
commit420d3d932b8529d97a6d8d0556853c34fc029a69 (patch)
treef7a130d6dae6c29f1d49bb2f8d5b4e6b07c6b3ca
parent61b02d283fd56077458b5ae3c58566c6dd2ee676 (diff)
downloadukulele-420d3d932b8529d97a6d8d0556853c34fc029a69.tar.xz
ukulele ryddet mot kyberwiki
-rw-r--r--ukulele.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/ukulele.c b/ukulele.c
index ba854a5..ce12dff 100644
--- a/ukulele.c
+++ b/ukulele.c
@@ -1,4 +1,4 @@
-#define _POSIX_C_SOURCE 200809L
+#define _DEFAULT_SOURCE
#define _GNU_SOURCE
#include <stdlib.h>
@@ -44,7 +44,7 @@ void head(char *page, char *link, char *what) {
printf("<a data-text='%s' href='%s'>%s</a>", what, link, page);
else if(link && what)
printf("<a data-text='%s' href='%s/%s'>%s</a>", what, base, link, page);
- else
+ else
printf("%s", page);
printf("</h1>\n");
}
@@ -53,6 +53,7 @@ void foot(int file) {
printf("<hr>\n");
printf("<p>");
for(int i = 0; *links[i]; i++) {
+ if(i > 0) printf("· ");
if(*links[i][1] == '/' || strstr(links[i][1], "://"))
printf("<a href='%s'>%s</a> ", links[i][1], links[i][0]);
else
@@ -77,7 +78,6 @@ int legit(char *page) {
if(!strcmp(page, "/")) return 0;
if(strstr(page, "..")) return 0;
if(strcspn(page, badchars) < strlen(page)) return 0;
- // strlen(page)
return 1;
}
@@ -96,12 +96,12 @@ int redirect(char *path, char *prefix) {
printf("Location: %s/%s?m=", script, path);
// skrive ut ++path
printf("\n");
- default:
- if(prefix) {
- printf("Location: %s/%s/%s\n\n", script, prefix, path); break;
- } else {
- 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;
}
@@ -118,7 +118,7 @@ int unauthorized(int status) {
int edit(char *path) {
if(!writable(path)) return unauthorized(403);
FILE *fp = fopen(path, "r");
- fp ? head(path, path, "vis") : head(path, NULL, NULL);
+ fp ? head(path, path, "vis") : head(path, 0, 0);
char buffer[sysconf(_SC_PAGESIZE)];
printf("<form method='post'>\n");
printf("<p class='edit'>\n");
@@ -136,17 +136,17 @@ int edit(char *path) {
return 0;
}
-// v fæl
int store(char *raw, int len) {
char *dir = dirname(strdup(raw));
char *id = basename(strdup(raw));
if(chdir(dir))
return problem(404, "Not found");
- char path[strlen(loft) + strlen(id) + 256];
- int epoch = time(NULL);
- snprintf(path, strlen(loft) + strlen(id) + 256, "%s/%s.%d", loft, id, epoch);
+ size_t len = strlen(loft) + strlen(id) + 256;
+ char path[len];
+ time_t epoch = time(0);
+ snprintf(path, len, "%s/%s.%d", loft, id, (int) epoch);
FILE *fp = fopen(path, "w");
- if(!fp) return redirect("fff", NULL);
+ if(!fp) return redirect("fff", 0);
int pos = 0;
unsigned int decoded;
char buffer[3] = { 0 };
@@ -180,13 +180,13 @@ int post(char *path) {
char *header;
int clen;
header = getenv("CONTENT_LENGTH");
- if(!header) return redirect(path, NULL);
+ if(!header) return redirect(path, 0);
clen = atoi(header);
while(clen > 1)
if(clen--, getchar() == 't')
if(clen--, getchar() == '=')
store(path, clen);
- return redirect(path, NULL);
+ return redirect(path, 0);
}
// gjør denne penere!
@@ -200,15 +200,15 @@ int list(char *raw, int dir, int inc) {
else
snprintf(pattern, len + 1, "%s", raw);
glob_t res;
- if(glob(pattern, GLOB_MARK, NULL, &res)) {
+ if(glob(pattern, GLOB_MARK, 0, &res)) {
if(!inc) {
- head("ingen treff", NULL, NULL);
+ head("ingen treff", 0, 0);
foot(0);
}
return 0;
}
if(!inc)
- head("treff", NULL, NULL);
+ head("treff", 0, 0);
char *path;
printf("<ul class='glob'>");
for(int i = 0; i < res.gl_pathc; i++) {
@@ -263,7 +263,7 @@ void include(FILE *out, char *path) {
}
printf("</pre>");
} else {
- marxup(fp, out, NULL);
+ marxup(fp, out, 0);
}
fclose(fp);
}
@@ -284,8 +284,8 @@ int view(char *path) {
return redirect(home, path);
}
FILE *fp = fopen(path, "r");
- if(!fp) return redirect("?e", NULL);
- writable(path) ? head(path, "?e", "rediger") : head(path, NULL, NULL);
+ if(!fp) return redirect("?e", 0);
+ writable(path) ? head(path, "?e", "rediger") : head(path, 0, 0);
marxup(fp, stdout, magic);
foot(1);
return 0;
@@ -306,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, NULL);
+ if(!legit(page++)) return redirect(home, 0);
setenv("MARXUP_HEADER", "2", 1);
setenv("MARXUP_PREFIX", base, 1);