Update packed fs

This commit is contained in:
Sergey Lyubka committed 2022-02-14 17:44:43 +00:00
1 parent 4fec149345
commit a76ade9bb2
6 files changed
+34 -13

No files matched your search

+9 -1
View File
@@ -37,6 +37,14 @@ test/packed_fs.c:
$(CC) $(CFLAGS) test/pack.c -o pack
./pack Makefile src/ssi.h test/fuzz.c test/data/a.txt -z 'gzip -c' test/data/range.txt > $@
DIR ?= test/data/
OUT ?= gui.c
ZIP ?= -z 'gzip -c'
mkfs:
$(CC) $(CFLAGS) test/pack.c -o pack
./pack $(ZIP) -s $(DIR) `find $(DIR) -type f` > $(OUT)
# find $(DIR) -type f | sed -e s,^$(DIR),,g -e s,^/,,g
# Check that all external (exported) symbols have "mg_" prefix
mg_prefix: mongoose.c mongoose.h
$(CC) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T' | grep -v 'mg_' ; test $$? = 1
@@ -62,7 +70,7 @@ fuzz: fuzzer
# make CC=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1
test: mongoose.h Makefile $(SRCS)
$(CC) $(SRCS) $(CFLAGS) -coverage $(LDFLAGS) -g -o unit_test
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test
ASAN1OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test
coverage: test
gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /'
+4 -3
View File
@@ -645,8 +645,9 @@ const char *mg_unlist(size_t no) {
#endif
static int is_dir_prefix(const char *prefix, size_t n, const char *path) {
return n < strlen(path) && memcmp(prefix, path, n) == 0 && path[n] == '/';
//(n == 0 || path[n] == MG_DIRSEP);
// MG_INFO(("[%.*s] [%s] %c", (int) n, prefix, path, path[n]));
return n < strlen(path) && strncmp(prefix, path, n) == 0 &&
(n == 0 || path[n] == '/' || path[n - 1] == '/');
}
static int packed_stat(const char *path, size_t *size, time_t *mtime) {
@@ -1377,7 +1378,7 @@ static void static_cb(struct mg_connection *c, int ev, void *ev_data,
// Read to send IO buffer directly, avoid extra on-stack buffer
size_t n, max = 2 * MG_IO_SIZE;
if (c->send.size < max) mg_iobuf_resize(&c->send, max);
if (c->send.len > 0) return; // Wait until drained: for some LWIP setups
if (c->send.len >= c->send.size) return; // Rate limit
n = fd->fs->rd(fd->fd, c->send.buf + c->send.len,
c->send.size - c->send.len);
c->send.len += n;
+3 -2
View File
@@ -22,8 +22,9 @@ const char *mg_unlist(size_t no) {
#endif
static int is_dir_prefix(const char *prefix, size_t n, const char *path) {
return n < strlen(path) && memcmp(prefix, path, n) == 0 && path[n] == '/';
//(n == 0 || path[n] == MG_DIRSEP);
// MG_INFO(("[%.*s] [%s] %c", (int) n, prefix, path, path[n]));
return n < strlen(path) && strncmp(prefix, path, n) == 0 &&
(n == 0 || path[n] == '/' || path[n - 1] == '/');
}
static int packed_stat(const char *path, size_t *size, time_t *mtime) {
+1 -1
View File
@@ -383,7 +383,7 @@ static void static_cb(struct mg_connection *c, int ev, void *ev_data,
// Read to send IO buffer directly, avoid extra on-stack buffer
size_t n, max = 2 * MG_IO_SIZE;
if (c->send.size < max) mg_iobuf_resize(&c->send, max);
if (c->send.len > 0) return; // Wait until drained: for some LWIP setups
if (c->send.len >= c->send.size) return; // Rate limit
n = fd->fs->rd(fd->fd, c->send.buf + c->send.len,
c->send.size - c->send.len);
c->send.len += n;
+16 -5
View File
@@ -28,7 +28,6 @@ static const char *code =
"const char *mg_unlist(size_t no) {\n"
" return packed_files[no].name;\n"
"}\n"
"const char *mg_unpack(const char *name, size_t *size, time_t *mtime);\n"
"const char *mg_unpack(const char *name, size_t *size, time_t *mtime) {\n"
" const struct packed_file *p;\n"
" for (p = packed_files; p->name != NULL; p++) {\n"
@@ -42,7 +41,7 @@ static const char *code =
int main(int argc, char *argv[]) {
int i, j, ch;
const char *zip_cmd = NULL;
const char *zip_cmd = NULL, *strip_prefix = "";
printf("%s", "#include <stddef.h>\n");
printf("%s", "#include <string.h>\n");
@@ -52,6 +51,12 @@ int main(int argc, char *argv[]) {
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-z") == 0 && i + 1 < argc) {
zip_cmd = argv[++i];
} else if (strcmp(argv[i], "-s") == 0) {
strip_prefix = argv[++i];
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
fprintf(stderr, "Usage: %s [-z ZIP_CMD] [-s STRIP_PREFIX] files...\n",
argv[0]);
exit(EXIT_FAILURE);
} else {
char ascii[12], cmd[2048];
FILE *fp;
@@ -96,10 +101,16 @@ int main(int argc, char *argv[]) {
for (i = 1; i < argc; i++) {
struct stat st;
if (strcmp(argv[i], "-z") == 0 && ++i + 1 < argc) continue;
const char *name = argv[i];
size_t n = strlen(strip_prefix);
if (strcmp(argv[i], "-z") == 0 || strcmp(argv[i], "-s") == 0) {
i++;
continue;
}
stat(argv[i], &st);
printf(" {\"/%s\", v%d, sizeof(v%d), %lu, %d},\n", argv[i], i, i,
st.st_mtime, zip_cmd == NULL ? 0 : 1);
if (strncmp(name, strip_prefix, n) == 0) name += n;
printf(" {\"/%s\", v%d, sizeof(v%d), %lu, %d},\n", name, i, i, st.st_mtime,
zip_cmd == NULL ? 0 : 1);
}
printf("%s", " {NULL, NULL, 0, 0, 0}\n");
printf("%s", "};\n\n");
+1 -1
View File
@@ -1559,7 +1559,7 @@ static void eh7(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
struct mg_http_serve_opts sopts;
memset(&sopts, 0, sizeof(sopts));
sopts.root_dir = "";
sopts.root_dir = "/";
sopts.fs = &mg_fs_packed;
mg_http_serve_dir(c, hm, &sopts);
}