author | Tero Marttila <terom@fixme.fi> |
Sat, 09 Aug 2008 14:42:59 +0300 | |
changeset 36 | b4023990811e |
parent 27 | 1e79b4cc8f1b |
permissions | -rw-r--r-- |
27
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
#include <sys/types.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
#include <sys/stat.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
#include <dirent.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
#include <fcntl.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
#include <unistd.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
#include <sys/mman.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
#include <stdio.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
#include <string.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
#include <event2/http.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
#include <event2/buffer.h> |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
#include "static.h" |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
#include "common.h" |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
static void _static_hit (struct evhttp_request *request, void *arg) { |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
struct static_file *ctx = arg; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
struct evbuffer *buf = NULL; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
int err = -1; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
// create the new buffer |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
22 |
if ((buf = evbuffer_new()) == NULL) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
ERROR("evbuffer_new"); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
24 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
// XXX: this is so very, very wasteful... |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
if (evbuffer_add(buf, ctx->mmap_addr, ctx->size)) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
ERROR("evbuffer_add %zu", ctx->size); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
// send the reply... |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
evhttp_send_reply(request, HTTP_OK, "OK", buf); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
err = 0; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
33 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
34 |
error : |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
// free the buffer |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
36 |
if (buf) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
evbuffer_free(buf); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
38 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
39 |
if (err) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
40 |
evhttp_send_error(request, 505, "Internal Server Error"); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
41 |
} |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
42 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
43 |
int static_init (struct static_file *ctx, struct evhttp *http_server, const char *url, const char *path) { |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
struct stat stat_buf; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
45 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
46 |
// clear the ctx |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
47 |
memset(ctx, 0, sizeof(*ctx)); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
48 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
49 |
// open the file... |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
50 |
if ((ctx->fh = open(path, O_RDONLY)) == -1) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
51 |
PERROR("open(O_RDONLY): %s", path); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
52 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
// stat the file to get its size |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
if (fstat(ctx->fh, &stat_buf)) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
PERROR("fstat: %s", path); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
57 |
ctx->size = stat_buf.st_size; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
59 |
// then mmap the file. MAP_POPULATE so that we block now, not later... |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
if ((ctx->mmap_addr = mmap(NULL, ctx->size, PROT_READ, MAP_SHARED | MAP_POPULATE, ctx->fh, 0)) == MAP_FAILED) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
PERROR("mmap: %s 0 -> %zu", path, ctx->size); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
63 |
// finally, add the HTTP request handler |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
64 |
evhttp_set_cb(http_server, url, &_static_hit, ctx); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
INFO("%s -> %s", url, path); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
67 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
// return |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
return 0; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
error : |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
72 |
static_deinit(ctx); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
return -1; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
} |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
void static_deinit (struct static_file *ctx) { |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
if (ctx->fh) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
if (close(ctx->fh)) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
PWARNING("close"); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
if (ctx->mmap_addr && ctx->mmap_addr != MAP_FAILED) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
83 |
if (munmap(ctx->mmap_addr, ctx->size)) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
84 |
PWARNING("munmap"); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
} |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
86 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
87 |
int static_dir_init (struct static_dir *ctx, struct evhttp *http_server, const char *url_prefix, const char *dir_path) { |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
88 |
DIR *dir = NULL; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
89 |
struct dirent *ent; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
int i = 0; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
char url_buf[STATIC_PATH_MAX], path_buf[STATIC_PATH_MAX]; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
92 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
93 |
// init the ctx |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
94 |
ctx->file_count = 0; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
// open the dir |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
97 |
if ((dir = opendir(dir_path)) == NULL) |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
98 |
PERROR("opendir: %s", dir_path); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
99 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
100 |
// scan the files |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
101 |
while ((ent = readdir(dir)) != NULL) { |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
102 |
// skip dotfiles |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
103 |
if (ent->d_name[0] == '.') |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
104 |
continue; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
105 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
106 |
// check we still have space |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
107 |
if (i >= STATIC_DIR_MAX) { |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
108 |
PWARNING("static_dir is full: %d", i); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
109 |
break; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
110 |
} |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
111 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
112 |
// format the url/path bufs |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
113 |
snprintf(url_buf, STATIC_PATH_MAX, "%s/%s", url_prefix, ent->d_name); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
114 |
snprintf(path_buf, STATIC_PATH_MAX, "%s/%s", dir_path, ent->d_name); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
115 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
116 |
// init the static_file |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
117 |
static_init(&ctx->files[i], http_server, url_buf, path_buf); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
118 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
119 |
// remember how many files are in use and move on to the next one |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
120 |
ctx->file_count = ++i; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
121 |
} |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
122 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
123 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
124 |
// ok |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
125 |
return 0; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
126 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
127 |
error: |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
128 |
static_dir_deinit(ctx); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
129 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
130 |
return -1; |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
131 |
} |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
132 |
|
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
133 |
void static_dir_deinit (struct static_dir *ctx) { |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
134 |
for (int i = 0; i < ctx->file_count; i++) { |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
135 |
static_deinit(&ctx->files[i]); |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
136 |
} |
1e79b4cc8f1b
support for static files (.css, .html, .js), and tiles - serves up a full viewer at / now, but the JS code needs cleaning up
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
137 |
} |