fixnuta buga v remove_last (nesnizovala grow ptr, ktery tak ubiral znaky a nemenil...
[httpfs.git] / canonize.c
blobe73afc42a87c78060415ec92744b14e543b85ea0
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/time.h>
4 #include <sys/stat.h>
5 #include <fuse.h>
6 #include "grow.h"
7 #include "parser.h"
8 #include "cache.h"
9 #include "canonize.h"
10 #include "urlencode.h"
12 /*
13 * url canonization process
16 /* terrible code, FIXME
18 * few ideas for making ordinary web pages more-or-less browsable
20 * 1) if occurs dir1/dir2/page as url in current pake, mark dir1 as directory
21 * 2) if occurs /dir1/dir2/dir3/page as url, and we are in /dir1/dir2/dir3 add page
22 * 3) what about symlinks to different part of the site?
26 char *prefixes[] = { "http://", "ftp://", "https://", "mailto:", "/", NULL };
29 static inline int bad_prefix(char *s)
31 int i;
32 for (i=0; prefixes[i]; i++) {
33 if (!strncasecmp(prefixes[i], s, strlen(prefixes[i])))
34 return 1;
36 return 0;
40 void canonize(void *ctx, char *par, time_t time, size_t size)
42 struct canon *c = ctx;
43 struct stat stb;
44 struct grow g;
46 memset(&stb, 0, sizeof(stb));
48 if (bad_prefix(par))
49 return;
51 if (par[strlen(par)-1] == '/') {
52 stb.st_mode = S_IFDIR | 0555;
53 par[strlen(par)-1] = 0;
54 } else {
55 stb.st_mode = S_IFREG | 0444;
58 if (strchr(par, '/') || strchr(par, '#') || par[0] == '?')
59 return;
60 if (par[0] == 0)
61 return;
63 grow_init(&g);
64 path_decode(&g, par);
65 grow_put(&g, 0);
66 c->filler(c->h, g.s, &stb);
67 grow_free(&g);