Skip to content

Commit c2176f9

Browse files
committed
Implement FS virtualization
1 parent 9346122 commit c2176f9

28 files changed

Lines changed: 668 additions & 741 deletions

File tree

.github/workflows/test.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Install packages
1919
run: sudo apt-get install libmbedtls-dev
2020
- name: examples
21-
run: make ex
21+
run: make clean examples
2222
macos:
2323
runs-on: macos-latest
2424
steps:
@@ -49,3 +49,21 @@ jobs:
4949
- uses: actions/checkout@v2
5050
- name: arm
5151
run: make arm
52+
esp32:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v2
56+
- name: esp32
57+
run: make -C examples/esp32 build
58+
esp8266:
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v2
62+
- name: esp8266
63+
run: make -C examples/esp8266 build
64+
stm32-freertos-tcp:
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v2
68+
- name: stm32-freertos-tcp
69+
run: make -C examples/stm32-freertos-tcp build

Makefile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SRCS = mongoose.c test/unit_test.c test/packed_fs.c
22
HDRS = $(wildcard src/*.h)
3-
DEFS ?= -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES -DMG_ENABLE_DIRECTORY_LISTING=1 -DMG_ENABLE_SSI=1
3+
DEFS ?= -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES
44
WARN ?= -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion
55
OPTS ?= -O3 -g3
66
INCS ?= -Isrc -I.
@@ -12,10 +12,9 @@ VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS)
1212
IPV6 ?= 1
1313
ASAN_OPTIONS ?=
1414
EXAMPLES := $(wildcard examples/*)
15-
EXAMPLE_TARGET ?= example
1615
PREFIX ?= /usr/local
1716
SOVERSION = 7.4
18-
.PHONY: ex test
17+
.PHONY: examples test
1918

2019
ifeq "$(SSL)" "MBEDTLS"
2120
MBEDTLS ?= /usr
@@ -28,10 +27,10 @@ CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include
2827
LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto
2928
endif
3029

31-
all: mg_prefix test test++ arm ex vc98 vc2017 mingw mingw++ linux linux++ fuzz
30+
all: mg_prefix test test++ arm examples vc98 vc2017 mingw mingw++ linux linux++ fuzz
3231

33-
ex:
34-
@for X in $(EXAMPLES); do $(MAKE) -C $$X $(EXAMPLE_TARGET) || break; done
32+
examples:
33+
@for X in $(EXAMPLES); do $(MAKE) -C $$X example || break; done
3534

3635
test/packed_fs.c:
3736
$(CC) $(CFLAGS) examples/complete/pack.c -o pack
@@ -73,10 +72,10 @@ infer:
7372
infer run -- cc test/unit_test.c -c -W -Wall -Werror -Isrc -I. -O2 -DMG_ENABLE_MBEDTLS=1 -DMG_ENABLE_LINES -I/usr/local/Cellar/mbedtls/2.23.0/include -DMG_ENABLE_IPV6=1 -g -o /dev/null
7473

7574
arm: mongoose.h $(SRCS)
76-
$(DOCKER) mdashnet/armgcc arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb $(SRCS) test/mongoose_custom.c -Itest -DMG_ARCH=MG_ARCH_CUSTOM $(OPTS) $(WARN) $(INCS) -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES -DMG_ENABLE_DIRECTORY_LISTING=0 -DMG_ENABLE_SSI=1 -o unit_test -nostartfiles --specs nosys.specs -e 0
75+
$(DOCKER) mdashnet/armgcc arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb $(SRCS) test/mongoose_custom.c -Itest -DMG_ARCH=MG_ARCH_CUSTOM $(OPTS) $(WARN) $(INCS) -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES=1 -o unit_test -nostartfiles --specs nosys.specs -e 0
7776

7877
riscv: mongoose.h $(SRCS)
79-
$(DOCKER) mdashnet/riscv riscv-none-elf-gcc -march=rv32imc -mabi=ilp32 $(SRCS) test/mongoose_custom.c -Itest -DMG_ARCH=MG_ARCH_CUSTOM $(OPTS) $(WARN) $(INCS) -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES -DMG_ENABLE_DIRECTORY_LISTING=0 -DMG_ENABLE_SSI=1 -o unit_test
78+
$(DOCKER) mdashnet/riscv riscv-none-elf-gcc -march=rv32imc -mabi=ilp32 $(SRCS) test/mongoose_custom.c -Itest -DMG_ARCH=MG_ARCH_CUSTOM $(OPTS) $(WARN) $(INCS) -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES=1 -o unit_test
8079

8180
#vc98: VCFLAGS += -DMG_ENABLE_IPV6=1
8281
vc98: Makefile mongoose.c mongoose.h test/unit_test.c
@@ -125,6 +124,6 @@ mongoose.c: Makefile $(wildcard src/*)
125124
mongoose.h: $(HDRS) Makefile
126125
(cat src/license.h src/version.h ; cat src/config.h src/arch.h src/arch_*.h src/str.h src/log.h src/timer.h src/util.h src/fs.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/ws.h src/sntp.h src/mqtt.h src/dns.h | sed -e 's,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
127126

128-
clean: EXAMPLE_TARGET = clean
129-
clean: ex
127+
clean:
130128
rm -rf $(PROG) *.o *.dSYM unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-* test/packed_fs.c pack
129+
@for X in $(EXAMPLES); do $(MAKE) -C $$X clean; done

docs/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ option during build time, use the `-D OPTION` compiler flag:
204204
$ cc app0.c mongoose.c # Use defaults!
205205
$ cc app1.c mongoose.c -D MG_ENABLE_IPV6=1 # Build with IPv6 enabled
206206
$ cc app2.c mongoose.c -D MG_ARCH=MG_ARCH_FREERTOS_LWIP # Set architecture
207-
$ cc app3.c mongoose.c -D MG_ENABLE_SSI=1 -D MG_ENABLE_LOG=0 # Multiple options
207+
$ cc app3.c mongoose.c -D MG_ENABLE_SSI=0 -D MG_ENABLE_LOG=0 # Multiple options
208208
```
209209

210210
The list of supported
@@ -240,12 +240,13 @@ Here is a list of build constants and their default values:
240240
|MG_ENABLE_IPV6 | 0 | Enable IPv6 |
241241
|MG_ENABLE_LOG | 1 | Enable `LOG()` macro |
242242
|MG_ENABLE_MD5 | 0 | Use native MD5 implementation |
243-
|MG_ENABLE_DIRECTORY_LISTING | 0 | Enable directory listing for HTTP server |
244243
|MG_ENABLE_SOCKETPAIR | 0 | Enable `mg_socketpair()` for multi-threading |
245-
|MG_ENABLE_SSI | 0 | Enable serving SSI files by `mg_http_serve_dir()` |
246-
|MG_IO_SIZE | 512 | Granularity of the send/recv IO buffer growth |
244+
|MG_ENABLE_SSI | 1 | Enable serving SSI files by `mg_http_serve_dir()` |
245+
|MG_ENABLE_DIRLIST | 0 | Enable directory listing |
246+
|MG_IO_SIZE | 2048 | Granularity of the send/recv IO buffer growth |
247247
|MG_MAX_RECV_BUF_SIZE | (3 * 1024 * 1024) | Maximum recv buffer size |
248248
|MG_MAX_HTTP_HEADERS | 40 | Maximum number of HTTP headers |
249+
|MG_ENABLE_LINES | undefined | If defined, show source file names in logs |
249250

250251

251252
NOTE: `MG_IO_SIZE` controls the maximum UDP message size, see
@@ -724,18 +725,20 @@ enable SSI, set a `-DMG_ENABLE_SSI=1` build flag.
724725

725726
```c
726727
void mg_http_serve_file(struct mg_connection *, struct mg_http_message *hm,
727-
const char *path, const char *mimetype,
728-
const char *extra_headers);
728+
const char *path, struct mg_http_serve_opts *opts);
729729
```
730730
731731
Serve static file. Note that the `extra_headers` must end with `\r\n`. Here
732732
is an example call:
733733
734734
```c
735-
mg_http_serve_file(c, hm, "a.png", "image/png", "AA: bb\r\nCC: dd\r\n");
735+
struct mg_http_serve_opts opts = {.mime_types = "png=image/png",
736+
.extra_headers = "AA: bb\r\nCC: dd\r\n"};
737+
mg_http_serve_file(c, hm, "a.png", &opts);
736738
```
737739

738740

741+
739742
### mg\_http\_reply()
740743

741744
```c

examples/complete/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ windows:
2020
$(DOCKER) $(PROG).exe
2121

2222
clean:
23-
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb log.txt fs.c pack
23+
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb log.txt packed_fs.c pack

examples/complete/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
119119
"Pragma: no-cache\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
120120
"Content-Type: multipart/x-mixed-replace; boundary=--foo\r\n\r\n");
121121
} else if (mg_http_match_uri(hm, "/api/log/static")) {
122-
mg_http_serve_file(c, hm, "log.txt", "text/plain", "");
122+
struct mg_http_serve_opts opts = {.root_dir = NULL};
123+
mg_http_serve_file(c, hm, "log.txt", &opts);
123124
} else if (mg_http_match_uri(hm, "/api/log/live")) {
124125
c->label[0] = 'L'; // Mark that connection as live log listener
125126
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");

examples/esp32/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ ROOTDIR = $(realpath $(CURDIR)/../..)
33

44
all: example
55

6-
example: main/main.c Makefile
6+
example:
7+
true
8+
9+
build: main/main.c Makefile
710
docker run --rm -v $(ROOTDIR):$(ROOTDIR) -w $(THISDIR) espressif/idf idf.py build
811

912
COMPORT ?= /dev/cu.SLAB_USBtoUART
@@ -12,4 +15,4 @@ flash:
1215
cd build && $(ESPTOOL) --chip esp32 -p $(COMPORT) -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 0x8000 partition_table/partition-table.bin 0x1000 bootloader/bootloader.bin 0x100000 mongoose-esp32-example.bin
1316

1417
clean:
15-
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.* build sdkconfig
18+
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.* build sdkconfig build

examples/esp32/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ idf_component_register(SRCS "main.c"
22
"wifi.c"
33
"../../../mongoose.c"
44
INCLUDE_DIRS "../../..")
5-
component_compile_options(-DMG_ENABLE_DIRECTORY_LISTING=1 -DMG_ENABLE_LINES)
5+
component_compile_options(-DMG_ENABLE_LINES)

examples/esp8266/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ ROOTDIR = $(realpath $(CURDIR)/../..)
33

44
all: example
55

6-
example: src/main/main.c src/main/wifi.c Makefile
6+
example:
7+
true
8+
9+
build: src/main/main.c src/main/wifi.c Makefile
710
docker run --rm -v $(ROOTDIR):$(ROOTDIR) -w $(THISDIR) docker.io/mdashnet/8266 make -C src defconfig app
811

912
clean:
10-
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.* src/build src/sdkconfig
13+
rm -rf build

examples/http-restful-server/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ all: $(PROG)
1212
$(DEBUGGER) ./$(PROG) $(ARGS)
1313

1414
$(PROG): main.c
15-
$(CC) ../../mongoose.c -I../.. -W -Wall -DMG_ENABLE_LINES=1 -DMG_ENABLE_DIRECTORY_LISTING=1 $(CFLAGS) -o $(PROG) main.c
15+
$(CC) ../../mongoose.c -I../.. -W -Wall -DMG_ENABLE_LINES=1 $(CFLAGS) -o $(PROG) main.c
1616

1717
clean:
1818
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb

examples/http-server/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PROG ?= example
22
ROOT ?= $(realpath $(CURDIR)/../..)
3-
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_DIRECTORY_LISTING=1 -DMG_ENABLE_SSI=1
3+
DEFS ?= -DMG_ENABLE_LINES=1
44
CFLAGS ?= -I../.. -W -Wall -DMG_ENABLE_IPV6=1 $(DEFS) $(EXTRA)
55
VCFLAGS = /nologo /W3 /O2 /I../.. $(DEFS) $(EXTRA) /link /incremental:no /machine:IX86
66
VC98 = docker run -it --rm -e Tmp=. -v $(ROOT):$(ROOT) -w $(CURDIR) mdashnet/vc98

0 commit comments

Comments
 (0)