diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 57be75be..d89615b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,6 @@ jobs: env: IPV6: 0 CC: ${{ matrix.targets.toolchain }}-gcc - SSL: ASAN: ASAN_OPTIONS: RUN: ${{ matrix.targets.qemu }} -L /usr/${{ matrix.targets.toolchain }} @@ -55,7 +54,7 @@ jobs: steps: - uses: actions/checkout@v3 - run: sudo apt-get update ; sudo apt-get install libmbedtls-dev valgrind - - run: make unamalgamated SSL= + - run: make unamalgamated - run: make valgrind IPV6=0 - run: make mg_prefix examples: diff --git a/Makefile b/Makefile index 5ab3dacf..e9cebb7a 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ DEFS ?= -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -DMG_E WARN ?= -pedantic -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef OPTS ?= -O3 -g3 INCS ?= -Isrc -I. -SSL ?= MBEDTLS +SSL ?= CWD ?= $(realpath $(CURDIR)) ENV ?= -e Tmp=. -e WINEDEBUG=-all DOCKER ?= docker run --platform linux/amd64 --rm $(ENV) -v $(CWD):$(CWD) -w $(CWD) diff --git a/mongoose.c b/mongoose.c index 49a70a21..303b219b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1349,6 +1349,7 @@ struct mg_fs mg_fs_posix = {p_stat, p_list, p_open, p_close, p_read, + // Chunk deletion marker is the MSB in the "processed" counter #define MG_DMARK ((size_t) 1 << (sizeof(size_t) * 8 - 1)) @@ -2237,7 +2238,7 @@ static void deliver_chunked_chunks(struct mg_connection *c, size_t hlen, ofs += pl + dl + 2, del += pl + 2; // 2 is for \r\n suffix processed += dl; if (c->recv.len != saved) processed -= dl, buf -= dl; - //mg_hexdump(c->recv.buf, hlen + processed); + // mg_hexdump(c->recv.buf, hlen + processed); last = (dl == 0); } mg_iobuf_del(&c->recv, hlen + processed, del); @@ -2310,6 +2311,34 @@ static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { (void) evd, (void) fnd; } +static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) { + if (ev == MG_EV_HTTP_MSG) { + struct mg_http_message *hm = (struct mg_http_message *) ev_data; + if (mg_http_match_uri(hm, "/quit")) { + mg_http_reply(c, 200, "", "ok\n"); + c->is_draining = 1; + c->label[0] = 'X'; + } else if (mg_http_match_uri(hm, "/debug")) { + int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); + mg_log_set(level); + mg_http_reply(c, 200, "", "Debug level set to %d\n", level); + } else { + mg_http_reply(c, 200, "", "hi\n"); + } + } else if (ev == MG_EV_CLOSE) { + if (c->label[0] == 'X') *(bool *) fnd = true; + } +} + +void mg_hello(const char *url) { + struct mg_mgr mgr; + bool done = false; + mg_mgr_init(&mgr); + if (mg_http_listen(&mgr, url, mg_hfn, &done) == NULL) done = true; + while (done == false) mg_mgr_poll(&mgr, 100); + mg_mgr_free(&mgr); +} + struct mg_connection *mg_http_connect(struct mg_mgr *mgr, const char *url, mg_event_handler_t fn, void *fn_data) { struct mg_connection *c = mg_connect(mgr, url, fn, fn_data); @@ -3488,34 +3517,6 @@ struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds, return t; } -static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) { - if (ev == MG_EV_HTTP_MSG) { - struct mg_http_message *hm = (struct mg_http_message *) ev_data; - if (mg_http_match_uri(hm, "/quit")) { - mg_http_reply(c, 200, "", "ok\n"); - c->is_draining = 1; - c->label[0] = 'X'; - } else if (mg_http_match_uri(hm, "/debug")) { - int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); - mg_log_set(level); - mg_http_reply(c, 200, "", "Debug level set to %d\n", level); - } else { - mg_http_reply(c, 200, "", "hi\n"); - } - } else if (ev == MG_EV_CLOSE) { - if (c->label[0] == 'X') *(bool *) fnd = true; - } -} - -void mg_hello(const char *url) { - struct mg_mgr mgr; - bool done = false; - mg_mgr_init(&mgr); - if (mg_http_listen(&mgr, url, mg_hfn, &done) == NULL) done = true; - while (done == false) mg_mgr_poll(&mgr, 100); - mg_mgr_free(&mgr); -} - void mg_mgr_free(struct mg_mgr *mgr) { struct mg_connection *c; struct mg_timer *tmp, *t = mgr->timers; diff --git a/mongoose.h b/mongoose.h index 45431248..3be7a093 100644 --- a/mongoose.h +++ b/mongoose.h @@ -1103,7 +1103,6 @@ char *mg_straddr(struct mg_addr *, char *, size_t); bool mg_aton(struct mg_str str, struct mg_addr *addr); char *mg_ntoa(const struct mg_addr *addr, char *buf, size_t len); int mg_mkpipe(struct mg_mgr *, mg_event_handler_t, void *, bool udp); -void mg_hello(const char *url); // These functions are used to integrate with custom network stacks struct mg_connection *mg_alloc_conn(struct mg_mgr *); @@ -1183,6 +1182,7 @@ void mg_http_bauth(struct mg_connection *, const char *user, const char *pass); struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v); size_t mg_http_next_multipart(struct mg_str, size_t, struct mg_http_part *); int mg_http_status(const struct mg_http_message *hm); +void mg_hello(const char *url); void mg_http_serve_ssi(struct mg_connection *c, const char *root, diff --git a/src/http.c b/src/http.c index 86cbe0ea..b46ebfe4 100644 --- a/src/http.c +++ b/src/http.c @@ -2,6 +2,7 @@ #include "base64.h" #include "fmt.h" #include "http.h" +#include "json.h" #include "log.h" #include "net.h" #include "ssi.h" @@ -897,7 +898,7 @@ static void deliver_chunked_chunks(struct mg_connection *c, size_t hlen, ofs += pl + dl + 2, del += pl + 2; // 2 is for \r\n suffix processed += dl; if (c->recv.len != saved) processed -= dl, buf -= dl; - //mg_hexdump(c->recv.buf, hlen + processed); + // mg_hexdump(c->recv.buf, hlen + processed); last = (dl == 0); } mg_iobuf_del(&c->recv, hlen + processed, del); @@ -970,6 +971,34 @@ static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { (void) evd, (void) fnd; } +static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) { + if (ev == MG_EV_HTTP_MSG) { + struct mg_http_message *hm = (struct mg_http_message *) ev_data; + if (mg_http_match_uri(hm, "/quit")) { + mg_http_reply(c, 200, "", "ok\n"); + c->is_draining = 1; + c->label[0] = 'X'; + } else if (mg_http_match_uri(hm, "/debug")) { + int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); + mg_log_set(level); + mg_http_reply(c, 200, "", "Debug level set to %d\n", level); + } else { + mg_http_reply(c, 200, "", "hi\n"); + } + } else if (ev == MG_EV_CLOSE) { + if (c->label[0] == 'X') *(bool *) fnd = true; + } +} + +void mg_hello(const char *url) { + struct mg_mgr mgr; + bool done = false; + mg_mgr_init(&mgr); + if (mg_http_listen(&mgr, url, mg_hfn, &done) == NULL) done = true; + while (done == false) mg_mgr_poll(&mgr, 100); + mg_mgr_free(&mgr); +} + struct mg_connection *mg_http_connect(struct mg_mgr *mgr, const char *url, mg_event_handler_t fn, void *fn_data) { struct mg_connection *c = mg_connect(mgr, url, fn, fn_data); diff --git a/src/http.h b/src/http.h index 61acc4be..619f36be 100644 --- a/src/http.h +++ b/src/http.h @@ -65,3 +65,4 @@ void mg_http_bauth(struct mg_connection *, const char *user, const char *pass); struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v); size_t mg_http_next_multipart(struct mg_str, size_t, struct mg_http_part *); int mg_http_status(const struct mg_http_message *hm); +void mg_hello(const char *url); diff --git a/src/net.c b/src/net.c index b8dcb286..412b894b 100644 --- a/src/net.c +++ b/src/net.c @@ -230,34 +230,6 @@ struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds, return t; } -static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) { - if (ev == MG_EV_HTTP_MSG) { - struct mg_http_message *hm = (struct mg_http_message *) ev_data; - if (mg_http_match_uri(hm, "/quit")) { - mg_http_reply(c, 200, "", "ok\n"); - c->is_draining = 1; - c->label[0] = 'X'; - } else if (mg_http_match_uri(hm, "/debug")) { - int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); - mg_log_set(level); - mg_http_reply(c, 200, "", "Debug level set to %d\n", level); - } else { - mg_http_reply(c, 200, "", "hi\n"); - } - } else if (ev == MG_EV_CLOSE) { - if (c->label[0] == 'X') *(bool *) fnd = true; - } -} - -void mg_hello(const char *url) { - struct mg_mgr mgr; - bool done = false; - mg_mgr_init(&mgr); - if (mg_http_listen(&mgr, url, mg_hfn, &done) == NULL) done = true; - while (done == false) mg_mgr_poll(&mgr, 100); - mg_mgr_free(&mgr); -} - void mg_mgr_free(struct mg_mgr *mgr) { struct mg_connection *c; struct mg_timer *tmp, *t = mgr->timers; diff --git a/src/net.h b/src/net.h index d58a6f5e..b01b0fbf 100644 --- a/src/net.h +++ b/src/net.h @@ -90,7 +90,6 @@ char *mg_straddr(struct mg_addr *, char *, size_t); bool mg_aton(struct mg_str str, struct mg_addr *addr); char *mg_ntoa(const struct mg_addr *addr, char *buf, size_t len); int mg_mkpipe(struct mg_mgr *, mg_event_handler_t, void *, bool udp); -void mg_hello(const char *url); // These functions are used to integrate with custom network stacks struct mg_connection *mg_alloc_conn(struct mg_mgr *);